Post #1028
807

ИЗ @solidityset
Showing posts older than #1029 · Back to latest



uint amount0In = balance0 > _reserve0 - amount0Out ? balance0 - (_reserve0 - amount0Out) : 0;
uint amount1In = balance1 > _reserve1 - amount1Out ? balance1 - (_reserve1 - amount1Out) : 0;
require(amount0Out < _reserve0 && amount1Out < _reserve1, 'UniswapV2: INSUFFICIENT_LIQUIDITY');
function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external;


Solidity
library CounterLib {
struct Counter { uint i; }
function incremented(Counter storage self) internal returns (uint) {
return ++self.i;
}
}
contract CounterContract {
using CounterLib for CounterLib.Counter;
CounterLib.Counter public counter;
function increment() public returns (uint) {
return counter.incremented();
}
}
Solidity
library EventEmitterLib {
function emitEvent(string memory s) internal{
emit Emit(s);
}
event Emit(string s);
}
contract EventEmitterContract {
using EventEmitterLib for string;
function emitEvent(string memory s) public {
s.emitEvent();
}
}
Solidity
library Library {
struct data {
uint val;
bool isValue;
}
}
contract Array{
using Library for Library.data;
mapping(address => Library.data) clusterContract;
function addCluster(address id) public view returns(bool){
if(clusterContract[id].isValue) revert();
return true;
}
}
Solidity
library TickBitmap {
...
function flipTick(
mapping(int16 => uint256) storage self,
int24 tick,
int24 tickSpacing
) internal {
unchecked {
require(tick % tickSpacing == 0); // ensure that the tick is spaced
(int16 wordPos, uint8 bitPos) = position(tick / tickSpacing);
uint256 mask = 1 << bitPos;
self[wordPos] ^= mask;
}
}
...
}
contract UniswapV3Pool is IUniswapV3Pool, NoDelegateCall {
using TickBitmap for mapping(int16 => uint256);
mapping(int16 => uint256) public override tickBitmap;
function _updatePosition(
...
) private returns (Position.Info storage position) {
...
if (flippedLower) {
tickBitmap.flipTick(tickLower, tickSpacing);
}
if (flippedUpper) {
tickBitmap.flipTick(tickUpper, tickSpacing);
}
...
}
}
function pow(uint256 a, uint256 b) pure returns (uint256 result) {
/// @solidity memory-safe-assembly
assembly {
switch b
case 0x00 {
result := 0x01
}
case 0x01 {
result := a
}
default {
switch a
case 0x00 {
// do nothing, result already zero
}
case 0x01 {
result := 0x01
}
case 0x02 {
if gt(b, 0xff) {
mstore(0x00, 0x35278d12)
revert(0x1c, 0x04)
}
result := shl(b, 0x01)
}
default {
switch or(
and(lt(a, 0x0b), lt(b, 0x4e)),
and(lt(a, 0x133), lt(b, 0x20))
)
case 0x01 {
result := exp(a, b)
}
default {
let maxUint256 := not(0x00)
let helper := 0x01
for {
let one := helper
} one {
} {
if gt(a, div(maxUint256, a)) {
mstore(0x00, 0x35278d12)
revert(0x1c, 0x04)
}
switch and(b, one)
case 0x00 {
b := shr(one, b)
}
case 0x01 {
helper := mul(a, helper)
b := shr(one, b)
}
a := mul(a, a)
if gt(b, one) {
continue
}
break
}
if gt(helper, div(maxUint256, a)) {
mstore(0x00, 0x35278d12)
revert(0x1c, 0x04)
}
result := mul(helper, a)
}
}
}
}
}