Overview
APE Balance
0 APE
APE Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
0x60a06040 | 60235 | 37 days ago | IN | 0 APE | 0.05835166 |
Loading...
Loading
Contract Name:
AlgebraStaticQuoter
Compiler Version
v0.7.6+commit.7338295f
Optimization Enabled:
Yes with 1000000 runs
Other Settings:
istanbul EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; pragma abicoder v2; import '@uniswap/v3-periphery/contracts/base/PeripheryImmutableState.sol'; import '@uniswap/v3-periphery/contracts/libraries/PoolAddress.sol'; import './interfaces/IAlgebraStaticQuoter.sol'; import './interfaces/IAlgebraFactory.sol'; import './lib/PathNoFee.sol'; import './AlgebraQuoterCore.sol'; contract AlgebraStaticQuoter is AlgebraQuoterCore { using LowGasSafeMath for uint256; using LowGasSafeMath for int256; using SafeCast for uint256; using SafeCast for int256; using PathNoFee for bytes; address immutable factory; constructor(address _factory) { factory = _factory; } function getPool( address tokenA, address tokenB ) private view returns (address) { return IAlgebraFactory(factory).poolByPair(tokenA, tokenB); } function quoteExactInputSingle(QuoteExactInputSingleParams memory params) public view returns (uint256 amountOut) { bool zeroForOne = params.tokenIn < params.tokenOut; address pool = getPool(params.tokenIn, params.tokenOut); require(pool != address(0), 'Pool not found'); (int256 amount0, int256 amount1) = quote( pool, zeroForOne, params.amountIn.toInt256(), params.sqrtPriceLimitX96 == 0 ? (zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1) : params.sqrtPriceLimitX96 ); return zeroForOne ? uint256(-amount1) : uint256(-amount0); } function quoteExactInput(bytes memory path, uint256 amountIn) public view returns (uint256 amountOut) { uint256 i = 0; while (true) { (address tokenIn, address tokenOut) = path.decodeFirstPool(); // the outputs of prior swaps become the inputs to subsequent ones uint256 _amountOut = quoteExactInputSingle( QuoteExactInputSingleParams({ tokenIn: tokenIn, tokenOut: tokenOut, amountIn: amountIn, sqrtPriceLimitX96: 0 }) ); amountIn = _amountOut; i++; // decide whether to continue or terminate if (path.hasMultiplePools()) { path = path.skipToken(); } else { return amountIn; } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import './pool/IUniswapV3PoolImmutables.sol'; import './pool/IUniswapV3PoolState.sol'; import './pool/IUniswapV3PoolDerivedState.sol'; import './pool/IUniswapV3PoolActions.sol'; import './pool/IUniswapV3PoolOwnerActions.sol'; import './pool/IUniswapV3PoolEvents.sol'; /// @title The interface for a Uniswap V3 Pool /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform /// to the ERC20 specification /// @dev The pool interface is broken up into many smaller pieces interface IUniswapV3Pool is IUniswapV3PoolImmutables, IUniswapV3PoolState, IUniswapV3PoolDerivedState, IUniswapV3PoolActions, IUniswapV3PoolOwnerActions, IUniswapV3PoolEvents { }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissionless pool actions /// @notice Contains pool methods that can be called by anyone interface IUniswapV3PoolActions { /// @notice Sets the initial price for the pool /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 function initialize(uint160 sqrtPriceX96) external; /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends /// on tickLower, tickUpper, the amount of liquidity, and the current price. /// @param recipient The address for which the liquidity will be created /// @param tickLower The lower tick of the position in which to add liquidity /// @param tickUpper The upper tick of the position in which to add liquidity /// @param amount The amount of liquidity to mint /// @param data Any data that should be passed through to the callback /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data ) external returns (uint256 amount0, uint256 amount1); /// @notice Collects tokens owed to a position /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity. /// @param recipient The address which should receive the fees collected /// @param tickLower The lower tick of the position for which to collect fees /// @param tickUpper The upper tick of the position for which to collect fees /// @param amount0Requested How much token0 should be withdrawn from the fees owed /// @param amount1Requested How much token1 should be withdrawn from the fees owed /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0 /// @dev Fees must be collected separately via a call to #collect /// @param tickLower The lower tick of the position for which to burn liquidity /// @param tickUpper The upper tick of the position for which to burn liquidity /// @param amount How much liquidity to burn /// @return amount0 The amount of token0 sent to the recipient /// @return amount1 The amount of token1 sent to the recipient function burn( int24 tickLower, int24 tickUpper, uint128 amount ) external returns (uint256 amount0, uint256 amount1); /// @notice Swap token0 for token1, or token1 for token0 /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback /// @param recipient The address to receive the output of the swap /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this /// value after the swap. If one for zero, the price cannot be greater than this value after the swap /// @param data Any data to be passed through to the callback /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling /// with 0 amount{0,1} and sending the donation amount(s) from the callback /// @param recipient The address which will receive the token0 and token1 amounts /// @param amount0 The amount of token0 to send /// @param amount1 The amount of token1 to send /// @param data Any data to be passed through to the callback function flash( address recipient, uint256 amount0, uint256 amount1, bytes calldata data ) external; /// @notice Increase the maximum number of price and liquidity observations that this pool will store /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to /// the input observationCardinalityNext. /// @param observationCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that is not stored /// @notice Contains view functions to provide information about the pool that is computed rather than stored on the /// blockchain. The functions here may have variable gas costs. interface IUniswapV3PoolDerivedState { /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, /// you must call it with secondsAgos = [3600, 0]. /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio. /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block /// timestamp function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed. /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first /// snapshot is taken and the second snapshot is taken. /// @param tickLower The lower tick of the range /// @param tickUpper The upper tick of the range /// @return tickCumulativeInside The snapshot of the tick accumulator for the range /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range /// @return secondsInside The snapshot of seconds per liquidity for the range function snapshotCumulativesInside(int24 tickLower, int24 tickUpper) external view returns ( int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Events emitted by a pool /// @notice Contains all events emitted by the pool interface IUniswapV3PoolEvents { /// @notice Emitted exactly once by a pool when #initialize is first called on the pool /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96 /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool event Initialize(uint160 sqrtPriceX96, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @param sender The address that minted the liquidity /// @param owner The owner of the position and recipient of any minted liquidity /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity minted to the position range /// @param amount0 How much token0 was required for the minted liquidity /// @param amount1 How much token1 was required for the minted liquidity event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees are collected by the owner of a position /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees /// @param owner The owner of the position for which fees are collected /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount0 The amount of token0 fees collected /// @param amount1 The amount of token1 fees collected event Collect( address indexed owner, address recipient, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount0, uint128 amount1 ); /// @notice Emitted when a position's liquidity is removed /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect /// @param owner The owner of the position for which liquidity is removed /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity to remove /// @param amount0 The amount of token0 withdrawn /// @param amount1 The amount of token1 withdrawn event Burn( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted by the pool for any swaps between token0 and token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the output of the swap /// @param amount0 The delta of the token0 balance of the pool /// @param amount1 The delta of the token1 balance of the pool /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of price of the pool after the swap event Swap( address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick ); /// @notice Emitted by the pool for any flashes of token0/token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the tokens from flash /// @param amount0 The amount of token0 that was flashed /// @param amount1 The amount of token1 that was flashed /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee event Flash( address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1 ); /// @notice Emitted by the pool for increases to the number of observations that can be stored /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index /// just before a mint/swap/burn. /// @param observationCardinalityNextOld The previous value of the next observation cardinality /// @param observationCardinalityNextNew The updated value of the next observation cardinality event IncreaseObservationCardinalityNext( uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); /// @notice Emitted when the protocol fee is changed by the pool /// @param feeProtocol0Old The previous value of the token0 protocol fee /// @param feeProtocol1Old The previous value of the token1 protocol fee /// @param feeProtocol0New The updated value of the token0 protocol fee /// @param feeProtocol1New The updated value of the token1 protocol fee event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New); /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner /// @param sender The address that collects the protocol fees /// @param recipient The address that receives the collected protocol fees /// @param amount0 The amount of token0 protocol fees that is withdrawn /// @param amount0 The amount of token1 protocol fees that is withdrawn event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that never changes /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values interface IUniswapV3PoolImmutables { /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface /// @return The contract address function factory() external view returns (address); /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (address); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (address); /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 /// @return The fee function fee() external view returns (uint24); /// @notice The pool tick spacing /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... /// This value is an int24 to avoid casting even though it is always positive. /// @return The tick spacing function tickSpacing() external view returns (int24); /// @notice The maximum amount of position liquidity that can use any tick in the range /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool /// @return The max amount of liquidity per tick function maxLiquidityPerTick() external view returns (uint128); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissioned pool actions /// @notice Contains pool methods that may only be called by the factory owner interface IUniswapV3PoolOwnerActions { /// @notice Set the denominator of the protocol's % share of the fees /// @param feeProtocol0 new protocol fee for token0 of the pool /// @param feeProtocol1 new protocol fee for token1 of the pool function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; /// @notice Collect the protocol fee accrued to the pool /// @param recipient The address to which collected protocol fees should be sent /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 /// @return amount0 The protocol fee collected in token0 /// @return amount1 The protocol fee collected in token1 function collectProtocol( address recipient, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that can change /// @notice These methods compose the pool's state, and can change with any frequency including multiple times /// per transaction interface IUniswapV3PoolState { /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas /// when accessed externally. /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value /// tick The current tick of the pool, i.e. according to the last tick transition that was run. /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick /// boundary. /// observationIndex The index of the last oracle observation that was written, /// observationCardinality The current maximum number of observations stored in the pool, /// observationCardinalityNext The next maximum number of observations, to be updated when the observation. /// feeProtocol The protocol fee for both tokens of the pool. /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. /// unlocked Whether the pool is currently locked to reentrancy function slot0() external view returns ( uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked ); /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal0X128() external view returns (uint256); /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal1X128() external view returns (uint256); /// @notice The amounts of token0 and token1 that are owed to the protocol /// @dev Protocol fees will never exceed uint128 max in either token function protocolFees() external view returns (uint128 token0, uint128 token1); /// @notice The currently in range liquidity available to the pool /// @dev This value has no relationship to the total liquidity across all ticks function liquidity() external view returns (uint128); /// @notice Look up information about a specific tick in the pool /// @param tick The tick to look up /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or /// tick upper, /// liquidityNet how much liquidity changes when the pool price crosses the tick, /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0, /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1, /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick, /// secondsOutside the seconds spent on the other side of the tick from the current tick, /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false. /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0. /// In addition, these values are only relative and must be used only in comparison to previous snapshots for /// a specific position. function ticks(int24 tick) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized ); /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information function tickBitmap(int16 wordPosition) external view returns (uint256); /// @notice Returns the information about a position by the position's key /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper /// @return _liquidity The amount of liquidity in the position, /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke, /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke, /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke, /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke function positions(bytes32 key) external view returns ( uint128 _liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); /// @notice Returns data about a specific observation index /// @param index The element of the observations array to fetch /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time /// ago, rather than at a specific index in the array. /// @return blockTimestamp The timestamp of the observation, /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp, /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp, /// Returns initialized whether the observation has been initialized and the values are safe to use function observations(uint256 index) external view returns ( uint32 blockTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, bool initialized ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title BitMath /// @dev This library provides functionality for computing bit properties of an unsigned integer library BitMath { /// @notice Returns the index of the most significant bit of the number, /// where the least significant bit is at index 0 and the most significant bit is at index 255 /// @dev The function satisfies the property: /// x >= 2**mostSignificantBit(x) and x < 2**(mostSignificantBit(x)+1) /// @param x the value for which to compute the most significant bit, must be greater than 0 /// @return r the index of the most significant bit function mostSignificantBit(uint256 x) internal pure returns (uint8 r) { require(x > 0); if (x >= 0x100000000000000000000000000000000) { x >>= 128; r += 128; } if (x >= 0x10000000000000000) { x >>= 64; r += 64; } if (x >= 0x100000000) { x >>= 32; r += 32; } if (x >= 0x10000) { x >>= 16; r += 16; } if (x >= 0x100) { x >>= 8; r += 8; } if (x >= 0x10) { x >>= 4; r += 4; } if (x >= 0x4) { x >>= 2; r += 2; } if (x >= 0x2) r += 1; } /// @notice Returns the index of the least significant bit of the number, /// where the least significant bit is at index 0 and the most significant bit is at index 255 /// @dev The function satisfies the property: /// (x & 2**leastSignificantBit(x)) != 0 and (x & (2**(leastSignificantBit(x)) - 1)) == 0) /// @param x the value for which to compute the least significant bit, must be greater than 0 /// @return r the index of the least significant bit function leastSignificantBit(uint256 x) internal pure returns (uint8 r) { require(x > 0); r = 255; if (x & type(uint128).max > 0) { r -= 128; } else { x >>= 128; } if (x & type(uint64).max > 0) { r -= 64; } else { x >>= 64; } if (x & type(uint32).max > 0) { r -= 32; } else { x >>= 32; } if (x & type(uint16).max > 0) { r -= 16; } else { x >>= 16; } if (x & type(uint8).max > 0) { r -= 8; } else { x >>= 8; } if (x & 0xf > 0) { r -= 4; } else { x >>= 4; } if (x & 0x3 > 0) { r -= 2; } else { x >>= 2; } if (x & 0x1 > 0) r -= 1; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title FixedPoint128 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) library FixedPoint128 { uint256 internal constant Q128 = 0x100000000000000000000000000000000; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title FixedPoint96 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) /// @dev Used in SqrtPriceMath.sol library FixedPoint96 { uint8 internal constant RESOLUTION = 96; uint256 internal constant Q96 = 0x1000000000000000000000000; }
// SPDX-License-Identifier: MIT pragma solidity >=0.4.0 <0.8.0; /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2**256 + prod0 uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(a, b, not(0)) prod0 := mul(a, b) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { require(denominator > 0); assembly { result := div(prod0, denominator) } return result; } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. uint256 twos = -denominator & denominator; // Divide denominator by power of two assembly { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly { twos := add(div(sub(0, twos), twos), 1) } prod0 |= prod1 * twos; // Invert denominator mod 2**256 // Now that denominator is an odd number, it has an inverse // modulo 2**256 such that denominator * inv = 1 mod 2**256. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // inverse mod 2**256 // Because the division is now exact we can divide by multiplying // with the modular inverse of denominator. This will give us the // correct result modulo 2**256. Since the precoditions guarantee // that the outcome is less than 2**256, this is the final result. // We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inv; return result; } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max); result++; } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Math library for liquidity library LiquidityMath { /// @notice Add a signed liquidity delta to liquidity and revert if it overflows or underflows /// @param x The liquidity before change /// @param y The delta by which liquidity should be changed /// @return z The liquidity delta function addDelta(uint128 x, int128 y) internal pure returns (uint128 z) { if (y < 0) { require((z = x - uint128(-y)) < x, 'LS'); } else { require((z = x + uint128(y)) >= x, 'LA'); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.0; /// @title Optimized overflow and underflow safe math operations /// @notice Contains methods for doing math operations that revert on overflow or underflow for minimal gas cost library LowGasSafeMath { /// @notice Returns x + y, reverts if sum overflows uint256 /// @param x The augend /// @param y The addend /// @return z The sum of x and y function add(uint256 x, uint256 y) internal pure returns (uint256 z) { require((z = x + y) >= x); } /// @notice Returns x - y, reverts if underflows /// @param x The minuend /// @param y The subtrahend /// @return z The difference of x and y function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { require((z = x - y) <= x); } /// @notice Returns x * y, reverts if overflows /// @param x The multiplicand /// @param y The multiplier /// @return z The product of x and y function mul(uint256 x, uint256 y) internal pure returns (uint256 z) { require(x == 0 || (z = x * y) / x == y); } /// @notice Returns x + y, reverts if overflows or underflows /// @param x The augend /// @param y The addend /// @return z The sum of x and y function add(int256 x, int256 y) internal pure returns (int256 z) { require((z = x + y) >= x == (y >= 0)); } /// @notice Returns x - y, reverts if overflows or underflows /// @param x The minuend /// @param y The subtrahend /// @return z The difference of x and y function sub(int256 x, int256 y) internal pure returns (int256 z) { require((z = x - y) <= x == (y >= 0)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Safe casting methods /// @notice Contains methods for safely casting between types library SafeCast { /// @notice Cast a uint256 to a uint160, revert on overflow /// @param y The uint256 to be downcasted /// @return z The downcasted integer, now type uint160 function toUint160(uint256 y) internal pure returns (uint160 z) { require((z = uint160(y)) == y); } /// @notice Cast a int256 to a int128, revert on overflow or underflow /// @param y The int256 to be downcasted /// @return z The downcasted integer, now type int128 function toInt128(int256 y) internal pure returns (int128 z) { require((z = int128(y)) == y); } /// @notice Cast a uint256 to a int256, revert on overflow /// @param y The uint256 to be casted /// @return z The casted integer, now type int256 function toInt256(uint256 y) internal pure returns (int256 z) { require(y < 2**255); z = int256(y); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.5.0; import './LowGasSafeMath.sol'; import './SafeCast.sol'; import './FullMath.sol'; import './UnsafeMath.sol'; import './FixedPoint96.sol'; /// @title Functions based on Q64.96 sqrt price and liquidity /// @notice Contains the math that uses square root of price as a Q64.96 and liquidity to compute deltas library SqrtPriceMath { using LowGasSafeMath for uint256; using SafeCast for uint256; /// @notice Gets the next sqrt price given a delta of token0 /// @dev Always rounds up, because in the exact output case (increasing price) we need to move the price at least /// far enough to get the desired output amount, and in the exact input case (decreasing price) we need to move the /// price less in order to not send too much output. /// The most precise formula for this is liquidity * sqrtPX96 / (liquidity +- amount * sqrtPX96), /// if this is impossible because of overflow, we calculate liquidity / (liquidity / sqrtPX96 +- amount). /// @param sqrtPX96 The starting price, i.e. before accounting for the token0 delta /// @param liquidity The amount of usable liquidity /// @param amount How much of token0 to add or remove from virtual reserves /// @param add Whether to add or remove the amount of token0 /// @return The price after adding or removing amount, depending on add function getNextSqrtPriceFromAmount0RoundingUp( uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add ) internal pure returns (uint160) { // we short circuit amount == 0 because the result is otherwise not guaranteed to equal the input price if (amount == 0) return sqrtPX96; uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION; if (add) { uint256 product; if ((product = amount * sqrtPX96) / amount == sqrtPX96) { uint256 denominator = numerator1 + product; if (denominator >= numerator1) // always fits in 160 bits return uint160(FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator)); } return uint160(UnsafeMath.divRoundingUp(numerator1, (numerator1 / sqrtPX96).add(amount))); } else { uint256 product; // if the product overflows, we know the denominator underflows // in addition, we must check that the denominator does not underflow require((product = amount * sqrtPX96) / amount == sqrtPX96 && numerator1 > product); uint256 denominator = numerator1 - product; return FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator).toUint160(); } } /// @notice Gets the next sqrt price given a delta of token1 /// @dev Always rounds down, because in the exact output case (decreasing price) we need to move the price at least /// far enough to get the desired output amount, and in the exact input case (increasing price) we need to move the /// price less in order to not send too much output. /// The formula we compute is within <1 wei of the lossless version: sqrtPX96 +- amount / liquidity /// @param sqrtPX96 The starting price, i.e., before accounting for the token1 delta /// @param liquidity The amount of usable liquidity /// @param amount How much of token1 to add, or remove, from virtual reserves /// @param add Whether to add, or remove, the amount of token1 /// @return The price after adding or removing `amount` function getNextSqrtPriceFromAmount1RoundingDown( uint160 sqrtPX96, uint128 liquidity, uint256 amount, bool add ) internal pure returns (uint160) { // if we're adding (subtracting), rounding down requires rounding the quotient down (up) // in both cases, avoid a mulDiv for most inputs if (add) { uint256 quotient = ( amount <= type(uint160).max ? (amount << FixedPoint96.RESOLUTION) / liquidity : FullMath.mulDiv(amount, FixedPoint96.Q96, liquidity) ); return uint256(sqrtPX96).add(quotient).toUint160(); } else { uint256 quotient = ( amount <= type(uint160).max ? UnsafeMath.divRoundingUp(amount << FixedPoint96.RESOLUTION, liquidity) : FullMath.mulDivRoundingUp(amount, FixedPoint96.Q96, liquidity) ); require(sqrtPX96 > quotient); // always fits 160 bits return uint160(sqrtPX96 - quotient); } } /// @notice Gets the next sqrt price given an input amount of token0 or token1 /// @dev Throws if price or liquidity are 0, or if the next price is out of bounds /// @param sqrtPX96 The starting price, i.e., before accounting for the input amount /// @param liquidity The amount of usable liquidity /// @param amountIn How much of token0, or token1, is being swapped in /// @param zeroForOne Whether the amount in is token0 or token1 /// @return sqrtQX96 The price after adding the input amount to token0 or token1 function getNextSqrtPriceFromInput( uint160 sqrtPX96, uint128 liquidity, uint256 amountIn, bool zeroForOne ) internal pure returns (uint160 sqrtQX96) { require(sqrtPX96 > 0); require(liquidity > 0); // round to make sure that we don't pass the target price return zeroForOne ? getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true) : getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, true); } /// @notice Gets the next sqrt price given an output amount of token0 or token1 /// @dev Throws if price or liquidity are 0 or the next price is out of bounds /// @param sqrtPX96 The starting price before accounting for the output amount /// @param liquidity The amount of usable liquidity /// @param amountOut How much of token0, or token1, is being swapped out /// @param zeroForOne Whether the amount out is token0 or token1 /// @return sqrtQX96 The price after removing the output amount of token0 or token1 function getNextSqrtPriceFromOutput( uint160 sqrtPX96, uint128 liquidity, uint256 amountOut, bool zeroForOne ) internal pure returns (uint160 sqrtQX96) { require(sqrtPX96 > 0); require(liquidity > 0); // round to make sure that we pass the target price return zeroForOne ? getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false) : getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, false); } /// @notice Gets the amount0 delta between two prices /// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper), /// i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The amount of usable liquidity /// @param roundUp Whether to round the amount up or down /// @return amount0 Amount of token0 required to cover a position of size liquidity between the two passed prices function getAmount0Delta( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity, bool roundUp ) internal pure returns (uint256 amount0) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION; uint256 numerator2 = sqrtRatioBX96 - sqrtRatioAX96; require(sqrtRatioAX96 > 0); return roundUp ? UnsafeMath.divRoundingUp( FullMath.mulDivRoundingUp(numerator1, numerator2, sqrtRatioBX96), sqrtRatioAX96 ) : FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96) / sqrtRatioAX96; } /// @notice Gets the amount1 delta between two prices /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The amount of usable liquidity /// @param roundUp Whether to round the amount up, or down /// @return amount1 Amount of token1 required to cover a position of size liquidity between the two passed prices function getAmount1Delta( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity, bool roundUp ) internal pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return roundUp ? FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96) : FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96); } /// @notice Helper that gets signed token0 delta /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The change in liquidity for which to compute the amount0 delta /// @return amount0 Amount of token0 corresponding to the passed liquidityDelta between the two prices function getAmount0Delta( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, int128 liquidity ) internal pure returns (int256 amount0) { return liquidity < 0 ? -getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256() : getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256(); } /// @notice Helper that gets signed token1 delta /// @param sqrtRatioAX96 A sqrt price /// @param sqrtRatioBX96 Another sqrt price /// @param liquidity The change in liquidity for which to compute the amount1 delta /// @return amount1 Amount of token1 corresponding to the passed liquidityDelta between the two prices function getAmount1Delta( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, int128 liquidity ) internal pure returns (int256 amount1) { return liquidity < 0 ? -getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256() : getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256(); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.5.0; import './FullMath.sol'; import './SqrtPriceMath.sol'; /// @title Computes the result of a swap within ticks /// @notice Contains methods for computing the result of a swap within a single tick price range, i.e., a single tick. library SwapMath { /// @notice Computes the result of swapping some amount in, or amount out, given the parameters of the swap /// @dev The fee, plus the amount in, will never exceed the amount remaining if the swap's `amountSpecified` is positive /// @param sqrtRatioCurrentX96 The current sqrt price of the pool /// @param sqrtRatioTargetX96 The price that cannot be exceeded, from which the direction of the swap is inferred /// @param liquidity The usable liquidity /// @param amountRemaining How much input or output amount is remaining to be swapped in/out /// @param feePips The fee taken from the input amount, expressed in hundredths of a bip /// @return sqrtRatioNextX96 The price after swapping the amount in/out, not to exceed the price target /// @return amountIn The amount to be swapped in, of either token0 or token1, based on the direction of the swap /// @return amountOut The amount to be received, of either token0 or token1, based on the direction of the swap /// @return feeAmount The amount of input that will be taken as a fee function computeSwapStep( uint160 sqrtRatioCurrentX96, uint160 sqrtRatioTargetX96, uint128 liquidity, int256 amountRemaining, uint24 feePips ) internal pure returns ( uint160 sqrtRatioNextX96, uint256 amountIn, uint256 amountOut, uint256 feeAmount ) { bool zeroForOne = sqrtRatioCurrentX96 >= sqrtRatioTargetX96; bool exactIn = amountRemaining >= 0; if (exactIn) { uint256 amountRemainingLessFee = FullMath.mulDiv(uint256(amountRemaining), 1e6 - feePips, 1e6); amountIn = zeroForOne ? SqrtPriceMath.getAmount0Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, true) : SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, true); if (amountRemainingLessFee >= amountIn) sqrtRatioNextX96 = sqrtRatioTargetX96; else sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromInput( sqrtRatioCurrentX96, liquidity, amountRemainingLessFee, zeroForOne ); } else { amountOut = zeroForOne ? SqrtPriceMath.getAmount1Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, false) : SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, false); if (uint256(-amountRemaining) >= amountOut) sqrtRatioNextX96 = sqrtRatioTargetX96; else sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromOutput( sqrtRatioCurrentX96, liquidity, uint256(-amountRemaining), zeroForOne ); } bool max = sqrtRatioTargetX96 == sqrtRatioNextX96; // get the input/output amounts if (zeroForOne) { amountIn = max && exactIn ? amountIn : SqrtPriceMath.getAmount0Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, true); amountOut = max && !exactIn ? amountOut : SqrtPriceMath.getAmount1Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, false); } else { amountIn = max && exactIn ? amountIn : SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, true); amountOut = max && !exactIn ? amountOut : SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, false); } // cap the output amount to not exceed the remaining output amount if (!exactIn && amountOut > uint256(-amountRemaining)) { amountOut = uint256(-amountRemaining); } if (exactIn && sqrtRatioNextX96 != sqrtRatioTargetX96) { // we didn't reach the target, so take the remainder of the maximum input as fee feeAmount = uint256(amountRemaining) - amountIn; } else { feeAmount = FullMath.mulDivRoundingUp(amountIn, feePips, 1e6 - feePips); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0 <0.8.0; /// @title Math library for computing sqrt prices from ticks and vice versa /// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports /// prices between 2**-128 and 2**128 library TickMath { /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 int24 internal constant MIN_TICK = -887272; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 4295128739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342; /// @notice Calculates sqrt(1.0001^tick) * 2^96 /// @dev Throws if |tick| > max tick /// @param tick The input tick for the above formula /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) /// at the given tick function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); require(absTick <= uint256(MAX_TICK), 'T'); uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000; if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128; if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128; if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128; if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128; if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128; if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128; if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128; if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128; if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128; if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128; if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128; if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128; if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128; if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128; if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128; if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128; if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128; if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128; if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128; if (tick > 0) ratio = type(uint256).max / ratio; // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96. // we then downcast because we know the result always fits within 160 bits due to our tick input constraint // we round up in the division so getTickAtSqrtRatio of the output price is always consistent sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1)); } /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may /// ever return. /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) { // second inequality must be < because the price can never reach the price at the max tick require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R'); uint256 ratio = uint256(sqrtPriceX96) << 32; uint256 r = ratio; uint256 msb = 0; assembly { let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(5, gt(r, 0xFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(4, gt(r, 0xFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(3, gt(r, 0xFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(2, gt(r, 0xF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(1, gt(r, 0x3)) msb := or(msb, f) r := shr(f, r) } assembly { let f := gt(r, 0x1) msb := or(msb, f) } if (msb >= 128) r = ratio >> (msb - 127); else r = ratio << (127 - msb); int256 log_2 = (int256(msb) - 128) << 64; assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(63, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(62, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(61, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(60, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(59, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(58, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(57, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(56, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(55, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(54, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(53, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(52, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(51, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(50, f)) } int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128); int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128); tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Math functions that do not check inputs or outputs /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks library UnsafeMath { /// @notice Returns ceil(x / y) /// @dev division by 0 has unspecified behavior, and must be checked externally /// @param x The dividend /// @param y The divisor /// @return z The quotient, ceil(x / y) function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { assembly { z := add(div(x, y), gt(mod(x, y), 0)) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; import '../interfaces/IPeripheryImmutableState.sol'; /// @title Immutable state /// @notice Immutable state used by periphery contracts abstract contract PeripheryImmutableState is IPeripheryImmutableState { /// @inheritdoc IPeripheryImmutableState address public immutable override factory; /// @inheritdoc IPeripheryImmutableState address public immutable override WETH9; constructor(address _factory, address _WETH9) { factory = _factory; WETH9 = _WETH9; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Immutable state /// @notice Functions that return immutable state of the router interface IPeripheryImmutableState { /// @return Returns the address of the Uniswap V3 factory function factory() external view returns (address); /// @return Returns the address of WETH9 function WETH9() external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later /* * @title Solidity Bytes Arrays Utils * @author Gonçalo Sá <[email protected]> * * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage. */ pragma solidity >=0.5.0 <0.8.0; library BytesLib { function slice( bytes memory _bytes, uint256 _start, uint256 _length ) internal pure returns (bytes memory) { require(_length + 31 >= _length, 'slice_overflow'); require(_start + _length >= _start, 'slice_overflow'); require(_bytes.length >= _start + _length, 'slice_outOfBounds'); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) //zero out the 32 bytes slice we are about to return //we need to do it because Solidity does not garbage collect mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_start + 20 >= _start, 'toAddress_overflow'); require(_bytes.length >= _start + 20, 'toAddress_outOfBounds'); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000) } return tempAddress; } function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) { require(_start + 3 >= _start, 'toUint24_overflow'); require(_bytes.length >= _start + 3, 'toUint24_outOfBounds'); uint24 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x3), _start)) } return tempUint; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Provides functions for deriving a pool address from the factory, tokens, and the fee library PoolAddress { bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; /// @notice The identifying key of the pool struct PoolKey { address token0; address token1; uint24 fee; } /// @notice Returns PoolKey: the ordered tokens with the matched fee levels /// @param tokenA The first token of a pool, unsorted /// @param tokenB The second token of a pool, unsorted /// @param fee The fee level of the pool /// @return Poolkey The pool details with ordered token0 and token1 assignments function getPoolKey( address tokenA, address tokenB, uint24 fee ) internal pure returns (PoolKey memory) { if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); return PoolKey({token0: tokenA, token1: tokenB, fee: fee}); } /// @notice Deterministically computes the pool address given the factory and PoolKey /// @param factory The Uniswap V3 factory contract address /// @param key The PoolKey /// @return pool The contract address of the V3 pool function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { require(key.token0 < key.token1); pool = address( uint256( keccak256( abi.encodePacked( hex'ff', factory, keccak256(abi.encode(key.token0, key.token1, key.fee)), POOL_INIT_CODE_HASH ) ) ) ); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; import './interfaces/IAlgebraPool.sol'; import './lib/TickBitmapAlgebra.sol'; import '../UniV3likeQuoterCore.sol'; contract AlgebraQuoterCore is UniV3likeQuoterCore { function getPoolGlobalState(address pool) internal override view returns (GlobalState memory gs) { (gs.startPrice, gs.startTick, gs.fee,,,,) = IAlgebraPool(pool).globalState(); } function getTickSpacing( address pool ) internal override view returns (int24) { return 1; } function getLiquidity(address pool) internal override view returns (uint128) { return IAlgebraPool(pool).liquidity(); } function nextInitializedTickWithinOneWord( address poolAddress, int24 tick, int24 tickSpacing, bool zeroForOne ) internal override view returns (int24 next, bool initialized) { return TickBitmap.nextInitializedTickWithinOneWord( poolAddress, tick, tickSpacing, zeroForOne ); } function getTicks(address pool, int24 tick) internal override view returns ( uint128 liquidityTotal, int128 liquidityDelta, uint256 outerFeeGrowth0Token, uint256 outerFeeGrowth1Token, int56 outerTickCumulative, uint160 outerSecondsPerLiquidity, uint32 outerSecondsSpent, bool initialized ) { return IAlgebraPool(pool).ticks(tick); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; interface IAlgebraFactory { function poolByPair(address, address) external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; interface IAlgebraPool { /** * @notice The globalState structure in the pool stores many values but requires only one slot * and is exposed as a single method to save gas when accessed externally. * @return price The current price of the pool as a sqrt(token1/token0) Q64.96 value; * Returns tick The current tick of the pool, i.e. according to the last tick transition that was run; * Returns This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(price) if the price is on a tick * boundary; * Returns fee The last pool fee value in hundredths of a bip, i.e. 1e-6; * Returns timepointIndex The index of the last written timepoint; * Returns communityFeeToken0 The community fee percentage of the swap fee in thousandths (1e-3) for token0; * Returns communityFeeToken1 The community fee percentage of the swap fee in thousandths (1e-3) for token1; * Returns unlocked Whether the pool is currently locked to reentrancy; */ function globalState() external view returns ( uint160 price, int24 tick, uint16 fee, uint16 timepointIndex, uint8 communityFeeToken0, uint8 communityFeeToken1, bool unlocked ); /** * @notice The pool tick spacing * @dev Ticks can only be used at multiples of this value * e.g.: a tickSpacing of 60 means ticks can be initialized every 60th tick, i.e., ..., -120, -60, 0, 60, 120, ... * This value is an int24 to avoid casting even though it is always positive. * @return The tick spacing */ function tickSpacing() external view returns (int24); /** * @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool * @dev This value can overflow the uint256 */ function totalFeeGrowth0Token() external view returns (uint256); /** * @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool * @dev This value can overflow the uint256 */ function totalFeeGrowth1Token() external view returns (uint256); /** * @notice The currently in range liquidity available to the pool * @dev This value has no relationship to the total liquidity across all ticks. * Returned value cannot exceed type(uint128).max */ function liquidity() external view returns (uint128); /** * @notice Look up information about a specific tick in the pool * @dev This is a public structure, so the `return` natspec tags are omitted. * @param tick The tick to look up * @return liquidityTotal the total amount of position liquidity that uses the pool either as tick lower or * tick upper * @return liquidityDelta how much liquidity changes when the pool price crosses the tick; * Returns outerFeeGrowth0Token the fee growth on the other side of the tick from the current tick in token0; * Returns outerFeeGrowth1Token the fee growth on the other side of the tick from the current tick in token1; * Returns outerTickCumulative the cumulative tick value on the other side of the tick from the current tick; * Returns outerSecondsPerLiquidity the seconds spent per liquidity on the other side of the tick from the current tick; * Returns outerSecondsSpent the seconds spent on the other side of the tick from the current tick; * Returns initialized Set to true if the tick is initialized, i.e. liquidityTotal is greater than 0 * otherwise equal to false. Outside values can only be used if the tick is initialized. * In addition, these values are only relative and must be used only in comparison to previous snapshots for * a specific position. */ function ticks(int24 tick) external view returns ( uint128 liquidityTotal, int128 liquidityDelta, uint256 outerFeeGrowth0Token, uint256 outerFeeGrowth1Token, int56 outerTickCumulative, uint160 outerSecondsPerLiquidity, uint32 outerSecondsSpent, bool initialized ); /** @notice Returns 256 packed tick initialized boolean values. See TickTable for more information */ function tickTable(int16 wordPosition) external view returns (uint256); /** * @notice Swap token0 for token1, or token1 for token0 * @dev The caller of this method receives a callback in the form of IAlgebraSwapCallback# AlgebraSwapCallback * @param recipient The address to receive the output of the swap * @param zeroToOne The direction of the swap, true for token0 to token1, false for token1 to token0 * @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) * @param limitSqrtPrice The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this * value after the swap. If one for zero, the price cannot be greater than this value after the swap * @param data Any data to be passed through to the callback. If using the Router it should contain * SwapRouter#SwapCallbackData * Return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive * Return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive */ function swap( address recipient, bool zeroToOne, int256 amountSpecified, uint160 limitSqrtPrice, bytes calldata data ) external returns (int256 amount0, int256 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; pragma abicoder v2; import '../../IUniV3likeQuoterCore.sol'; struct QuoteExactInputSingleParams { address tokenIn; address tokenOut; uint256 amountIn; uint160 sqrtPriceLimitX96; } interface IAlgebraStaticQuoter is IUniV3likeQuoterCore { function quoteExactInputSingle( QuoteExactInputSingleParams memory params ) external view returns (uint256 amountOut); function quoteExactInput( bytes memory path, uint256 amountIn ) external view returns (uint256 amountOut); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; import '@uniswap/v3-periphery/contracts/libraries/BytesLib.sol'; library PathNoFee { using BytesLib for bytes; uint256 constant ADDR_SIZE = 20; uint256 constant MULTIPLE_POOLS_MIN_LENGTH = 3*ADDR_SIZE; function decodeFirstPool( bytes memory path ) pure internal returns (address, address) { return (path.toAddress(0), path.toAddress(ADDR_SIZE)); } function hasMultiplePools( bytes memory path ) internal pure returns (bool) { return path.length >= MULTIPLE_POOLS_MIN_LENGTH; } function skipToken(bytes memory path) internal pure returns (bytes memory) { return path.slice(ADDR_SIZE, path.length - ADDR_SIZE); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol'; import '@uniswap/v3-core/contracts/libraries/BitMath.sol'; import '../interfaces/IAlgebraPool.sol'; /// @title Packed tick initialized state library /// @notice Stores a packed mapping of tick index to its initialized state /// @dev The mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word. library TickBitmap { /// @notice Computes the position in the mapping where the initialized bit for a tick lives /// @param tick The tick for which to compute the position /// @return wordPos The key in the mapping containing the word in which the bit is stored /// @return bitPos The bit position in the word where the flag is stored function position(int24 tick) private pure returns (int16 wordPos, uint8 bitPos) { wordPos = int16(tick >> 8); bitPos = uint8(tick % 256); } /// @notice Returns the next initialized tick contained in the same word (or adjacent word) as the tick that is either /// to the left (less than or equal to) or right (greater than) of the given tick /// @param poolAddress Pool containing the mapping in which to compute the next initialized tick /// @param tick The starting tick /// @param tickSpacing The spacing between usable ticks /// @param lte Whether to search for the next initialized tick to the left (less than or equal to the starting tick) /// @return next The next initialized or uninitialized tick up to 256 ticks away from the current tick /// @return initialized Whether the next tick is initialized, as the function only searches within up to 256 ticks function nextInitializedTickWithinOneWord( address poolAddress, int24 tick, int24 tickSpacing, bool lte ) internal view returns (int24 next, bool initialized) { IAlgebraPool pool = IAlgebraPool(poolAddress); int24 compressed = tick / tickSpacing; if (tick < 0 && tick % tickSpacing != 0) compressed--; // round towards negative infinity if (lte) { (int16 wordPos, uint8 bitPos) = position(compressed); // all the 1s at or to the right of the current bitPos uint256 mask = (1 << bitPos) - 1 + (1 << bitPos); uint256 masked = pool.tickTable(wordPos) & mask; // if there are no initialized ticks to the right of or at the current tick, return rightmost in the word initialized = masked != 0; // overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick next = initialized ? (compressed - int24(bitPos - BitMath.mostSignificantBit(masked))) * tickSpacing : (compressed - int24(bitPos)) * tickSpacing; } else { // start from the word of the next tick, since the current tick state doesn't matter (int16 wordPos, uint8 bitPos) = position(compressed + 1); // all the 1s at or to the left of the bitPos uint256 mask = ~((1 << bitPos) - 1); uint256 masked = pool.tickTable(wordPos) & mask; // if there are no initialized ticks to the left of the current tick, return leftmost in the word initialized = masked != 0; // overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick next = initialized ? (compressed + 1 + int24(BitMath.leastSignificantBit(masked) - bitPos)) * tickSpacing : (compressed + 1 + int24(type(uint8).max - bitPos)) * tickSpacing; } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; struct GlobalState { uint160 startPrice; int24 startTick; uint16 fee; } // the top level state of the swap, the results of which are recorded in storage at the end struct SwapState { // the amount remaining to be swapped in/out of the input/output asset int256 amountSpecifiedRemaining; // the amount already swapped out/in of the output/input asset int256 amountCalculated; // current sqrt(price) uint160 sqrtPriceX96; // the tick associated with the current price int24 tick; // the current liquidity in range uint128 liquidity; } struct StepComputations { // the price at the beginning of the step uint160 sqrtPriceStartX96; // the next tick to swap to from the current tick in the swap direction int24 tickNext; // whether tickNext is initialized or not bool initialized; // sqrt(price) for the next tick (1/0) uint160 sqrtPriceNextX96; // how much is being swapped in in this step uint256 amountIn; // how much is being swapped out uint256 amountOut; // how much fee is being paid in uint256 feeAmount; } interface IUniV3likeQuoterCore { function quote( address poolAddress, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96 ) external view returns (int256 amount0, int256 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; import '@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol'; import '@uniswap/v3-core/contracts/libraries/LiquidityMath.sol'; import '@uniswap/v3-core/contracts/libraries/FixedPoint128.sol'; import '@uniswap/v3-core/contracts/libraries/SafeCast.sol'; import '@uniswap/v3-core/contracts/libraries/TickMath.sol'; import '@uniswap/v3-core/contracts/libraries/FullMath.sol'; import '@uniswap/v3-core/contracts/libraries/SwapMath.sol'; import './IUniV3likeQuoterCore.sol'; abstract contract UniV3likeQuoterCore { using LowGasSafeMath for int256; using SafeCast for uint256; using SafeCast for int256; function quote( address poolAddress, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96 ) public virtual view returns (int256 amount0, int256 amount1) { require(amountSpecified != 0, 'amountSpecified cannot be zero'); bool exactInput = amountSpecified > 0; (int24 tickSpacing, uint16 fee, SwapState memory state) = getInitState( poolAddress, zeroForOne, amountSpecified, sqrtPriceLimitX96 ); // continue swapping as long as we haven't used the entire input/output and haven't reached the price limit while (state.amountSpecifiedRemaining != 0 && state.sqrtPriceX96 != sqrtPriceLimitX96) { StepComputations memory step; step.sqrtPriceStartX96 = state.sqrtPriceX96; (step.tickNext, step.initialized, step.sqrtPriceNextX96) = nextInitializedTickAndPrice( poolAddress, state.tick, tickSpacing, zeroForOne ); // compute values to swap to the target tick, price limit, or point where input/output amount is exhausted (state.sqrtPriceX96, step.amountIn, step.amountOut, step.feeAmount) = SwapMath.computeSwapStep( state.sqrtPriceX96, getSqrtRatioTargetX96(zeroForOne, step.sqrtPriceNextX96, sqrtPriceLimitX96), state.liquidity, state.amountSpecifiedRemaining, fee ); if (exactInput) { state.amountSpecifiedRemaining -= (step.amountIn + step.feeAmount).toInt256(); state.amountCalculated = state.amountCalculated.sub(step.amountOut.toInt256()); } else { state.amountSpecifiedRemaining += step.amountOut.toInt256(); state.amountCalculated = state.amountCalculated.add((step.amountIn + step.feeAmount).toInt256()); } // shift tick if we reached the next price if (state.sqrtPriceX96 == step.sqrtPriceNextX96) { // if the tick is initialized, run the tick transition if (step.initialized) { (,int128 liquidityNet,,,,,,) = getTicks(poolAddress, step.tickNext); // if we're moving leftward, we interpret liquidityNet as the opposite sign // safe because liquidityNet cannot be type(int128).min if (zeroForOne) liquidityNet = -liquidityNet; state.liquidity = LiquidityMath.addDelta(state.liquidity, liquidityNet); } state.tick = zeroForOne ? step.tickNext - 1 : step.tickNext; } else if (state.sqrtPriceX96 != step.sqrtPriceStartX96) { // recompute unless we're on a lower tick boundary (i.e. already transitioned ticks), and haven't moved state.tick = TickMath.getTickAtSqrtRatio(state.sqrtPriceX96); } } (amount0, amount1) = zeroForOne == exactInput ? (amountSpecified - state.amountSpecifiedRemaining, state.amountCalculated) : (state.amountCalculated, amountSpecified - state.amountSpecifiedRemaining); } function getInitState( address poolAddress, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96 ) internal view returns (int24 ts, uint16 fee, SwapState memory state) { GlobalState memory gs = getPoolGlobalState(poolAddress); checkSqrtPriceLimitWithinAllowed(zeroForOne, sqrtPriceLimitX96, gs.startPrice); ts = getTickSpacing(poolAddress); fee = gs.fee; state = SwapState({ amountSpecifiedRemaining: amountSpecified, liquidity: getLiquidity(poolAddress), sqrtPriceX96: gs.startPrice, amountCalculated: 0, tick: gs.startTick }); } function checkSqrtPriceLimitWithinAllowed( bool zeroForOne, uint160 sqrtPriceLimit, uint160 startPrice ) internal pure { bool withinAllowed = zeroForOne ? sqrtPriceLimit < startPrice && sqrtPriceLimit > TickMath.MIN_SQRT_RATIO : sqrtPriceLimit > startPrice && sqrtPriceLimit < TickMath.MAX_SQRT_RATIO; require(withinAllowed, 'sqrtPriceLimit out of bounds'); } function nextInitializedTickAndPrice( address pool, int24 tick, int24 tickSpacing, bool zeroForOne ) internal view returns (int24 tickNext, bool initialized, uint160 sqrtPriceNextX96) { (tickNext, initialized) = nextInitializedTickWithinOneWord(pool, tick, tickSpacing, zeroForOne); // ensure that we do not overshoot the min/max tick, as the tick bitmap is not aware of these bounds if (tickNext < TickMath.MIN_TICK) tickNext = TickMath.MIN_TICK; else if (tickNext > TickMath.MAX_TICK) tickNext = TickMath.MAX_TICK; // get the price for the next tick sqrtPriceNextX96 = TickMath.getSqrtRatioAtTick(tickNext); } function getSqrtRatioTargetX96( bool zeroForOne, uint160 sqrtPriceNextX96, uint160 sqrtPriceLimitX96 ) internal pure returns (uint160) { return (zeroForOne ? sqrtPriceNextX96<sqrtPriceLimitX96 : sqrtPriceNextX96>sqrtPriceLimitX96) ? sqrtPriceLimitX96 : sqrtPriceNextX96; } function getPoolGlobalState(address pool) internal virtual view returns (GlobalState memory); function getLiquidity(address pool) internal virtual view returns (uint128); function getTickSpacing(address pool) internal virtual view returns (int24); function nextInitializedTickWithinOneWord( address poolAddress, int24 tick, int24 tickSpacing, bool zeroForOne ) internal virtual view returns (int24 next, bool initialized); function getTicks(address pool, int24 tick) internal virtual view returns ( uint128 liquidityTotal, int128 liquidityDelta, uint256 outerFeeGrowth0Token, uint256 outerFeeGrowth1Token, int56 outerTickCumulative, uint160 outerSecondsPerLiquidity, uint32 outerSecondsSpent, bool initialized ); }
{ "evmVersion": "istanbul", "optimizer": { "enabled": true, "runs": 1000000 }, "metadata": { "bytecodeHash": "none", "useLiteralContent": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_factory","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"poolAddress","type":"address"},{"internalType":"bool","name":"zeroForOne","type":"bool"},{"internalType":"int256","name":"amountSpecified","type":"int256"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"name":"quote","outputs":[{"internalType":"int256","name":"amount0","type":"int256"},{"internalType":"int256","name":"amount1","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"path","type":"bytes"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"name":"quoteExactInput","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"}],"internalType":"struct QuoteExactInputSingleParams","name":"params","type":"tuple"}],"name":"quoteExactInputSingle","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60a06040523480156200001157600080fd5b50604051620029453803806200294583398101604081905262000034916200004a565b60601b6001600160601b0319166080526200007a565b6000602082840312156200005c578081fd5b81516001600160a01b038116811462000073578182fd5b9392505050565b60805160601c6128ad620000986000398061061452506128ad6000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80635e5e6e0f1461004657806390405d361461006f578063cdca175314610090575b600080fd5b61005961005436600461276d565b6100a3565b604051610066919061284e565b60405180910390f35b61008261007d36600461266b565b6101ba565b604051610066929190612809565b61005961009e3660046126c1565b610510565b6020810151815160009173ffffffffffffffffffffffffffffffffffffffff808216908316109183916100d691906105d4565b905073ffffffffffffffffffffffffffffffffffffffff811661012e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012590612817565b60405180910390fd5b600080610197838561014389604001516106a2565b60608a015173ffffffffffffffffffffffffffffffffffffffff161561016d57896060015161007d565b8761018c5773fffd8963efd1fc6a506488495d951d5263988d2561007d565b6401000276a46101ba565b91509150836101a957816000036101ae565b806000035b9450505050505b919050565b6000808361022957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f616d6f756e745370656369666965642063616e6e6f74206265207a65726f0000604482015290519081900360640190fd5b600080851390808061023d8a8a8a8a6106d4565b9250925092505b80511580159061028457508673ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff1614155b156104d9576102916125c5565b604082015173ffffffffffffffffffffffffffffffffffffffff16815260608201516102c0908c90868d61077d565b73ffffffffffffffffffffffffffffffffffffffff1660608401819052901515604080850191909152600292830b90920b60208401529083015161031b9161030a908d908c610812565b6080850151855161ffff8816610891565b60c085015260a0840152608083015273ffffffffffffffffffffffffffffffffffffffff166040830152841561038a5761035e8160c001518260800151016106a2565b825103825260a081015161038090610375906106a2565b602084015190610ab7565b60208301526103c5565b6103978160a001516106a2565b825101825260c081015160808201516103bf916103b491016106a2565b602084015190610acd565b60208301525b806060015173ffffffffffffffffffffffffffffffffffffffff16826040015173ffffffffffffffffffffffffffffffffffffffff16141561047e5780604001511561045557600061041b8c8360200151610ae3565b5050505050509150508a1561042e576000035b61043c836080015182610bb7565b6fffffffffffffffffffffffffffffffff166080840152505b8961046457806020015161046d565b60018160200151035b600290810b900b60608301526104d3565b806000015173ffffffffffffffffffffffffffffffffffffffff16826040015173ffffffffffffffffffffffffffffffffffffffff16146104d3576104c68260400151610cfb565b600290810b900b60608301525b50610244565b831515891515146104f2576020810151815189036104ff565b8060000151880381602001515b909b909a5098505050505050505050565b6000805b600080610520866110c7565b91509150600061059260405180608001604052808573ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff168152602001888152602001600073ffffffffffffffffffffffffffffffffffffffff168152506100a3565b955050600190920191846105a5876110e8565b156105ba576105b3876110f0565b96506105c6565b859450505050506105ce565b505050610514565b92915050565b6040517fd9a641e100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169063d9a641e19061064b90869086906004016127e2565b60206040518083038186803b15801561066357600080fd5b505afa158015610677573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061069b919061264f565b9392505050565b60007f800000000000000000000000000000000000000000000000000000000000000082106106d057600080fd5b5090565b6000806106df612601565b60006106ea8861110b565b90506106fb878683600001516111c9565b61070488611302565b9350806040015192506040518060a0016040528087815260200160008152602001826000015173ffffffffffffffffffffffffffffffffffffffff168152602001826020015160020b815260200161075b8a611308565b6fffffffffffffffffffffffffffffffff168152509150509450945094915050565b600080600061078e87878787611382565b90935091507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618600284900b12156107e7577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2761892506107fd565b620d89e8600284900b13156107fd57620d89e892505b6108068361139e565b90509450945094915050565b60008361084d578173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161161087d565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16105b6108875782610889565b815b949350505050565b600080808073ffffffffffffffffffffffffffffffffffffffff808916908a1610158187128015906109235760006108d78989620f42400362ffffff16620f4240611731565b9050826108f0576108eb8c8c8c60016117fe565b6108fd565b6108fd8b8d8c60016118cf565b955085811061090e578a965061091d565b61091a8c8b83866119e7565b96505b5061096d565b8161093a576109358b8b8b60006118cf565b610947565b6109478a8c8b60006117fe565b935083886000031061095b5789955061096d565b61096a8b8a8a60000385611a49565b95505b73ffffffffffffffffffffffffffffffffffffffff8a81169087161482156109dd578080156109995750815b6109af576109aa878d8c60016118cf565b6109b1565b855b95508080156109be575081155b6109d4576109cf878d8c60006117fe565b6109d6565b845b9450610a27565b8080156109e75750815b6109fd576109f88c888c60016117fe565b6109ff565b855b9550808015610a0c575081155b610a2257610a1d8c888c60006118cf565b610a24565b845b94505b81158015610a3757508860000385115b15610a43578860000394505b818015610a7c57508a73ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff1614155b15610a8b578589039350610aa8565b610aa5868962ffffff168a620f42400362ffffff16611aab565b93505b50505095509550955095915050565b808203828113156000831215146105ce57600080fd5b818101828112156000831215146105ce57600080fd5b6000806000806000806000808973ffffffffffffffffffffffffffffffffffffffff1663f30dba938a6040518263ffffffff1660e01b8152600401808260020b81526020019150506101006040518083038186803b158015610b4457600080fd5b505afa158015610b58573d6000803e3d6000fd5b505050506040513d610100811015610b6f57600080fd5b508051602082015160408301516060840151608085015160a086015160c087015160e090970151959e50939c50919a5098509650945090925090509295985092959890939650565b60008082600f0b1215610c6357826fffffffffffffffffffffffffffffffff168260000384039150816fffffffffffffffffffffffffffffffff1610610c5e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c53000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6105ce565b826fffffffffffffffffffffffffffffffff168284019150816fffffffffffffffffffffffffffffffff1610156105ce57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c41000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b60006401000276a373ffffffffffffffffffffffffffffffffffffffff831610801590610d51575073fffd8963efd1fc6a506488495d951d5263988d2673ffffffffffffffffffffffffffffffffffffffff8316105b610dbc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600160248201527f5200000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b77ffffffffffffffffffffffffffffffffffffffff00000000602083901b166fffffffffffffffffffffffffffffffff811160071b81811c67ffffffffffffffff811160061b90811c63ffffffff811160051b90811c61ffff811160041b90811c60ff8111600390811b91821c600f811160021b90811c918211600190811b92831c97908811961790941790921717909117171760808110610e6657607f810383901c9150610e70565b80607f0383901b91505b908002607f81811c60ff83811c9190911c800280831c81831c1c800280841c81841c1c800280851c81851c1c800280861c81861c1c800280871c81871c1c800280881c81881c1c800280891c81891c1c8002808a1c818a1c1c8002808b1c818b1c1c8002808c1c818c1c1c8002808d1c818d1c1c8002808e1c9c81901c9c909c1c80029c8d901c9e9d7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff808f0160401b60c09190911c678000000000000000161760c19b909b1c674000000000000000169a909a1760c29990991c672000000000000000169890981760c39790971c671000000000000000169690961760c49590951c670800000000000000169490941760c59390931c670400000000000000169290921760c69190911c670200000000000000161760c79190911c670100000000000000161760c89190911c6680000000000000161760c99190911c6640000000000000161760ca9190911c6620000000000000161760cb9190911c6610000000000000161760cc9190911c6608000000000000161760cd9190911c66040000000000001617693627a301d71055774c8581027ffffffffffffffffffffffffffffffffffd709b7e5480fba5a50fed5e62ffc5568101608090811d906fdb2df09e81959a81455e260799a0632f8301901d600281810b9083900b146110b8578873ffffffffffffffffffffffffffffffffffffffff1661108f8261139e565b73ffffffffffffffffffffffffffffffffffffffff1611156110b157816110b3565b805b6110ba565b815b9998505050505050505050565b6000806110d48382611b03565b6110df846014611b03565b91509150915091565b51603c111590565b60606105ce60148084510384611c039092919063ffffffff16565b61111361262f565b8173ffffffffffffffffffffffffffffffffffffffff1663e76c01e46040518163ffffffff1660e01b815260040160e06040518083038186803b15801561115957600080fd5b505afa15801561116d573d6000803e3d6000fd5b505050506040513d60e081101561118357600080fd5b50805160208083015160409384015161ffff1693850193909352600292830b90920b9183019190915273ffffffffffffffffffffffffffffffffffffffff168152919050565b600083611239578173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16118015611234575073fffd8963efd1fc6a506488495d951d5263988d2673ffffffffffffffffffffffffffffffffffffffff8416105b61128e565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1610801561128e57506401000276a373ffffffffffffffffffffffffffffffffffffffff8416115b9050806112fc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f7371727450726963654c696d6974206f7574206f6620626f756e647300000000604482015290519081900360640190fd5b50505050565b50600190565b60008173ffffffffffffffffffffffffffffffffffffffff16631a6865026040518163ffffffff1660e01b815260040160206040518083038186803b15801561135057600080fd5b505afa158015611364573d6000803e3d6000fd5b505050506040513d602081101561137a57600080fd5b505192915050565b60008061139186868686611dea565b9150915094509492505050565b60008060008360020b126113b5578260020b6113bd565b8260020b6000035b9050620d89e881111561143157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600160248201527f5400000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b60006001821661145257700100000000000000000000000000000000611464565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615611498576ffff97272373d413259a46990580e213a0260801c5b60048216156114b7576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b60088216156114d6576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b60108216156114f5576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615611514576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615611533576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615611552576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615611572576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615611592576ff987a7253ac413176f2b074cf7815e540260801c5b6104008216156115b2576ff3392b0822b70005940c7a398e4b70f30260801c5b6108008216156115d2576fe7159475a2c29b7443b29c7fa6e889d90260801c5b6110008216156115f2576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615611612576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615611632576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615611652576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615611673576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615611693576e5d6af8dedb81196699c329225ee6040260801c5b620400008216156116b2576d2216e584f5fa1ea926041bedfe980260801c5b620800008216156116cf576b048a170391f7dc42444e8fa20260801c5b60008460020b131561170857807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8161170457fe5b0490505b64010000000081061561171c57600161171f565b60005b60ff16602082901c0192505050919050565b600080807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870986860292508281109083900303905080611785576000841161177a57600080fd5b50829004905061069b565b80841161179157600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b60008373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161115611838579293925b816118845761187f836fffffffffffffffffffffffffffffffff1686860373ffffffffffffffffffffffffffffffffffffffff166c01000000000000000000000000611731565b6118c6565b6118c6836fffffffffffffffffffffffffffffffff1686860373ffffffffffffffffffffffffffffffffffffffff166c01000000000000000000000000611aab565b95945050505050565b60008373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161115611909579293925b7bffffffffffffffffffffffffffffffff000000000000000000000000606084901b1673ffffffffffffffffffffffffffffffffffffffff868603811690871661195257600080fd5b8361199c578673ffffffffffffffffffffffffffffffffffffffff1661198f83838973ffffffffffffffffffffffffffffffffffffffff16611731565b8161199657fe5b046119dc565b6119dc6119c083838973ffffffffffffffffffffffffffffffffffffffff16611aab565b8873ffffffffffffffffffffffffffffffffffffffff16612057565b979650505050505050565b6000808573ffffffffffffffffffffffffffffffffffffffff1611611a0b57600080fd5b6000846fffffffffffffffffffffffffffffffff1611611a2a57600080fd5b81611a3c5761187f8585856001612062565b6118c685858560016121ba565b6000808573ffffffffffffffffffffffffffffffffffffffff1611611a6d57600080fd5b6000846fffffffffffffffffffffffffffffffff1611611a8c57600080fd5b81611a9e5761187f85858560006121ba565b6118c68585856000612062565b6000611ab8848484611731565b905060008280611ac457fe5b848609111561069b577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110611af957600080fd5b6001019392505050565b600081826014011015611b7757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f746f416464726573735f6f766572666c6f770000000000000000000000000000604482015290519081900360640190fd5b8160140183511015611bea57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f746f416464726573735f6f75744f66426f756e64730000000000000000000000604482015290519081900360640190fd5b5001602001516c01000000000000000000000000900490565b60608182601f011015611c7757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f736c6963655f6f766572666c6f77000000000000000000000000000000000000604482015290519081900360640190fd5b828284011015611ce857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f736c6963655f6f766572666c6f77000000000000000000000000000000000000604482015290519081900360640190fd5b81830184511015611d5a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f736c6963655f6f75744f66426f756e6473000000000000000000000000000000604482015290519081900360640190fd5b606082158015611d795760405191506000825260208201604052611de1565b6040519150601f8416801560200281840101858101878315602002848b0101015b81831015611db2578051835260209283019201611d9a565b5050858452601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016604052505b50949350505050565b6000808581600286810b9088900b81611dff57fe5b05905060008760020b128015611e2657508560020b8760020b81611e1f57fe5b0760020b15155b15611e4e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff015b8415611f6957600080611e60836122f0565b604080517fc677e3e0000000000000000000000000000000000000000000000000000000008152600184810b6004830152915193955091935060ff84161b80017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0191600091839173ffffffffffffffffffffffffffffffffffffffff89169163c677e3e0916024808301926020929190829003018186803b158015611f0557600080fd5b505afa158015611f19573d6000803e3d6000fd5b505050506040513d6020811015611f2f57600080fd5b5051168015159750905086611f4b57898360ff16860302611f5e565b89611f5582612302565b840360ff168603025b97505050505061204c565b600080611f78836001016122f0565b91509150600060018260ff166001901b031990506000818673ffffffffffffffffffffffffffffffffffffffff1663c677e3e0866040518263ffffffff1660e01b8152600401808260010b815260200191505060206040518083038186803b158015611fe357600080fd5b505afa158015611ff7573d6000803e3d6000fd5b505050506040513d602081101561200d57600080fd5b505116801515975090508661202f57898360ff0360ff16866001010102612045565b898361203a836123af565b0360ff168660010101025b9750505050505b505094509492505050565b808204910615150190565b6000811561210a57600073ffffffffffffffffffffffffffffffffffffffff8411156120b7576120b2846c01000000000000000000000000876fffffffffffffffffffffffffffffffff16611731565b6120d8565b6fffffffffffffffffffffffffffffffff8516606085901b816120d657fe5b045b90506121026120fd73ffffffffffffffffffffffffffffffffffffffff881683612592565b6125a2565b915050610889565b600073ffffffffffffffffffffffffffffffffffffffff84111561215757612152846c01000000000000000000000000876fffffffffffffffffffffffffffffffff16611aab565b612177565b612177606085901b6fffffffffffffffffffffffffffffffff8716612057565b9050808673ffffffffffffffffffffffffffffffffffffffff161161219b57600080fd5b73ffffffffffffffffffffffffffffffffffffffff8616039050610889565b6000826121c8575083610889565b7bffffffffffffffffffffffffffffffff000000000000000000000000606085901b16821561228f5773ffffffffffffffffffffffffffffffffffffffff86168481029085828161221557fe5b0414156122535781810182811061225157612247838973ffffffffffffffffffffffffffffffffffffffff1683611aab565b9350505050610889565b505b61228682612281878a73ffffffffffffffffffffffffffffffffffffffff16868161227a57fe5b0490612592565b612057565b92505050610889565b73ffffffffffffffffffffffffffffffffffffffff8616848102908582816122b357fe5b041480156122c057508082115b6122c957600080fd5b8082036122476120fd8473ffffffffffffffffffffffffffffffffffffffff8b1684611aab565b60020b600881901d9161010090910790565b600080821161231057600080fd5b700100000000000000000000000000000000821061233057608091821c91015b68010000000000000000821061234857604091821c91015b640100000000821061235c57602091821c91015b62010000821061236e57601091821c91015b610100821061237f57600891821c91015b6010821061238f57600491821c91015b6004821061239f57600291821c91015b600282106101b557600101919050565b60008082116123bd57600080fd5b5060ff6fffffffffffffffffffffffffffffffff8216156123ff577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8001612407565b608082901c91505b67ffffffffffffffff82161561243e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc001612446565b604082901c91505b63ffffffff821615612479577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001612481565b602082901c91505b61ffff8216156124b2577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016124ba565b601082901c91505b60ff8216156124ea577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8016124f2565b600882901c91505b600f821615612522577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0161252a565b600482901c91505b600382161561255a577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01612562565b600282901c91505b60018216156101b5577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01919050565b808201828110156105ce57600080fd5b8073ffffffffffffffffffffffffffffffffffffffff811681146101b557600080fd5b6040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c081019190915290565b6040805160a08101825260008082526020820181905291810182905260608101829052608081019190915290565b604080516060810182526000808252602082018190529181019190915290565b600060208284031215612660578081fd5b815161069b8161287b565b60008060008060808587031215612680578283fd5b843561268b8161287b565b93506020850135801515811461269f578384fd5b92506040850135915060608501356126b68161287b565b939692955090935050565b600080604083850312156126d3578182fd5b823567ffffffffffffffff808211156126ea578384fd5b818501915085601f8301126126fd578384fd5b813560208282111561270b57fe5b61273b817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f85011601612857565b92508183528781838601011115612750578586fd5b818185018285013790820181019490945295939092013593505050565b60006080828403121561277e578081fd5b6040516080810181811067ffffffffffffffff8211171561279b57fe5b60405282356127a98161287b565b815260208301356127b98161287b565b60208201526040838101359082015260608301356127d68161287b565b60608201529392505050565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b918252602082015260400190565b6020808252600e908201527f506f6f6c206e6f7420666f756e64000000000000000000000000000000000000604082015260600190565b90815260200190565b60405181810167ffffffffffffffff8111828210171561287357fe5b604052919050565b73ffffffffffffffffffffffffffffffffffffffff8116811461289d57600080fd5b5056fea164736f6c6343000706000a00000000000000000000000010aa510d94e094bd643677bd2964c3ee085daffc
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100415760003560e01c80635e5e6e0f1461004657806390405d361461006f578063cdca175314610090575b600080fd5b61005961005436600461276d565b6100a3565b604051610066919061284e565b60405180910390f35b61008261007d36600461266b565b6101ba565b604051610066929190612809565b61005961009e3660046126c1565b610510565b6020810151815160009173ffffffffffffffffffffffffffffffffffffffff808216908316109183916100d691906105d4565b905073ffffffffffffffffffffffffffffffffffffffff811661012e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012590612817565b60405180910390fd5b600080610197838561014389604001516106a2565b60608a015173ffffffffffffffffffffffffffffffffffffffff161561016d57896060015161007d565b8761018c5773fffd8963efd1fc6a506488495d951d5263988d2561007d565b6401000276a46101ba565b91509150836101a957816000036101ae565b806000035b9450505050505b919050565b6000808361022957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601e60248201527f616d6f756e745370656369666965642063616e6e6f74206265207a65726f0000604482015290519081900360640190fd5b600080851390808061023d8a8a8a8a6106d4565b9250925092505b80511580159061028457508673ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff1614155b156104d9576102916125c5565b604082015173ffffffffffffffffffffffffffffffffffffffff16815260608201516102c0908c90868d61077d565b73ffffffffffffffffffffffffffffffffffffffff1660608401819052901515604080850191909152600292830b90920b60208401529083015161031b9161030a908d908c610812565b6080850151855161ffff8816610891565b60c085015260a0840152608083015273ffffffffffffffffffffffffffffffffffffffff166040830152841561038a5761035e8160c001518260800151016106a2565b825103825260a081015161038090610375906106a2565b602084015190610ab7565b60208301526103c5565b6103978160a001516106a2565b825101825260c081015160808201516103bf916103b491016106a2565b602084015190610acd565b60208301525b806060015173ffffffffffffffffffffffffffffffffffffffff16826040015173ffffffffffffffffffffffffffffffffffffffff16141561047e5780604001511561045557600061041b8c8360200151610ae3565b5050505050509150508a1561042e576000035b61043c836080015182610bb7565b6fffffffffffffffffffffffffffffffff166080840152505b8961046457806020015161046d565b60018160200151035b600290810b900b60608301526104d3565b806000015173ffffffffffffffffffffffffffffffffffffffff16826040015173ffffffffffffffffffffffffffffffffffffffff16146104d3576104c68260400151610cfb565b600290810b900b60608301525b50610244565b831515891515146104f2576020810151815189036104ff565b8060000151880381602001515b909b909a5098505050505050505050565b6000805b600080610520866110c7565b91509150600061059260405180608001604052808573ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff168152602001888152602001600073ffffffffffffffffffffffffffffffffffffffff168152506100a3565b955050600190920191846105a5876110e8565b156105ba576105b3876110f0565b96506105c6565b859450505050506105ce565b505050610514565b92915050565b6040517fd9a641e100000000000000000000000000000000000000000000000000000000815260009073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000010aa510d94e094bd643677bd2964c3ee085daffc169063d9a641e19061064b90869086906004016127e2565b60206040518083038186803b15801561066357600080fd5b505afa158015610677573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061069b919061264f565b9392505050565b60007f800000000000000000000000000000000000000000000000000000000000000082106106d057600080fd5b5090565b6000806106df612601565b60006106ea8861110b565b90506106fb878683600001516111c9565b61070488611302565b9350806040015192506040518060a0016040528087815260200160008152602001826000015173ffffffffffffffffffffffffffffffffffffffff168152602001826020015160020b815260200161075b8a611308565b6fffffffffffffffffffffffffffffffff168152509150509450945094915050565b600080600061078e87878787611382565b90935091507ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff27618600284900b12156107e7577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2761892506107fd565b620d89e8600284900b13156107fd57620d89e892505b6108068361139e565b90509450945094915050565b60008361084d578173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161161087d565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16105b6108875782610889565b815b949350505050565b600080808073ffffffffffffffffffffffffffffffffffffffff808916908a1610158187128015906109235760006108d78989620f42400362ffffff16620f4240611731565b9050826108f0576108eb8c8c8c60016117fe565b6108fd565b6108fd8b8d8c60016118cf565b955085811061090e578a965061091d565b61091a8c8b83866119e7565b96505b5061096d565b8161093a576109358b8b8b60006118cf565b610947565b6109478a8c8b60006117fe565b935083886000031061095b5789955061096d565b61096a8b8a8a60000385611a49565b95505b73ffffffffffffffffffffffffffffffffffffffff8a81169087161482156109dd578080156109995750815b6109af576109aa878d8c60016118cf565b6109b1565b855b95508080156109be575081155b6109d4576109cf878d8c60006117fe565b6109d6565b845b9450610a27565b8080156109e75750815b6109fd576109f88c888c60016117fe565b6109ff565b855b9550808015610a0c575081155b610a2257610a1d8c888c60006118cf565b610a24565b845b94505b81158015610a3757508860000385115b15610a43578860000394505b818015610a7c57508a73ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff1614155b15610a8b578589039350610aa8565b610aa5868962ffffff168a620f42400362ffffff16611aab565b93505b50505095509550955095915050565b808203828113156000831215146105ce57600080fd5b818101828112156000831215146105ce57600080fd5b6000806000806000806000808973ffffffffffffffffffffffffffffffffffffffff1663f30dba938a6040518263ffffffff1660e01b8152600401808260020b81526020019150506101006040518083038186803b158015610b4457600080fd5b505afa158015610b58573d6000803e3d6000fd5b505050506040513d610100811015610b6f57600080fd5b508051602082015160408301516060840151608085015160a086015160c087015160e090970151959e50939c50919a5098509650945090925090509295985092959890939650565b60008082600f0b1215610c6357826fffffffffffffffffffffffffffffffff168260000384039150816fffffffffffffffffffffffffffffffff1610610c5e57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c53000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b6105ce565b826fffffffffffffffffffffffffffffffff168284019150816fffffffffffffffffffffffffffffffff1610156105ce57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600260248201527f4c41000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b60006401000276a373ffffffffffffffffffffffffffffffffffffffff831610801590610d51575073fffd8963efd1fc6a506488495d951d5263988d2673ffffffffffffffffffffffffffffffffffffffff8316105b610dbc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600160248201527f5200000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b77ffffffffffffffffffffffffffffffffffffffff00000000602083901b166fffffffffffffffffffffffffffffffff811160071b81811c67ffffffffffffffff811160061b90811c63ffffffff811160051b90811c61ffff811160041b90811c60ff8111600390811b91821c600f811160021b90811c918211600190811b92831c97908811961790941790921717909117171760808110610e6657607f810383901c9150610e70565b80607f0383901b91505b908002607f81811c60ff83811c9190911c800280831c81831c1c800280841c81841c1c800280851c81851c1c800280861c81861c1c800280871c81871c1c800280881c81881c1c800280891c81891c1c8002808a1c818a1c1c8002808b1c818b1c1c8002808c1c818c1c1c8002808d1c818d1c1c8002808e1c9c81901c9c909c1c80029c8d901c9e9d7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff808f0160401b60c09190911c678000000000000000161760c19b909b1c674000000000000000169a909a1760c29990991c672000000000000000169890981760c39790971c671000000000000000169690961760c49590951c670800000000000000169490941760c59390931c670400000000000000169290921760c69190911c670200000000000000161760c79190911c670100000000000000161760c89190911c6680000000000000161760c99190911c6640000000000000161760ca9190911c6620000000000000161760cb9190911c6610000000000000161760cc9190911c6608000000000000161760cd9190911c66040000000000001617693627a301d71055774c8581027ffffffffffffffffffffffffffffffffffd709b7e5480fba5a50fed5e62ffc5568101608090811d906fdb2df09e81959a81455e260799a0632f8301901d600281810b9083900b146110b8578873ffffffffffffffffffffffffffffffffffffffff1661108f8261139e565b73ffffffffffffffffffffffffffffffffffffffff1611156110b157816110b3565b805b6110ba565b815b9998505050505050505050565b6000806110d48382611b03565b6110df846014611b03565b91509150915091565b51603c111590565b60606105ce60148084510384611c039092919063ffffffff16565b61111361262f565b8173ffffffffffffffffffffffffffffffffffffffff1663e76c01e46040518163ffffffff1660e01b815260040160e06040518083038186803b15801561115957600080fd5b505afa15801561116d573d6000803e3d6000fd5b505050506040513d60e081101561118357600080fd5b50805160208083015160409384015161ffff1693850193909352600292830b90920b9183019190915273ffffffffffffffffffffffffffffffffffffffff168152919050565b600083611239578173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16118015611234575073fffd8963efd1fc6a506488495d951d5263988d2673ffffffffffffffffffffffffffffffffffffffff8416105b61128e565b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1610801561128e57506401000276a373ffffffffffffffffffffffffffffffffffffffff8416115b9050806112fc57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f7371727450726963654c696d6974206f7574206f6620626f756e647300000000604482015290519081900360640190fd5b50505050565b50600190565b60008173ffffffffffffffffffffffffffffffffffffffff16631a6865026040518163ffffffff1660e01b815260040160206040518083038186803b15801561135057600080fd5b505afa158015611364573d6000803e3d6000fd5b505050506040513d602081101561137a57600080fd5b505192915050565b60008061139186868686611dea565b9150915094509492505050565b60008060008360020b126113b5578260020b6113bd565b8260020b6000035b9050620d89e881111561143157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600160248201527f5400000000000000000000000000000000000000000000000000000000000000604482015290519081900360640190fd5b60006001821661145257700100000000000000000000000000000000611464565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615611498576ffff97272373d413259a46990580e213a0260801c5b60048216156114b7576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b60088216156114d6576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b60108216156114f5576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615611514576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615611533576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615611552576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615611572576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615611592576ff987a7253ac413176f2b074cf7815e540260801c5b6104008216156115b2576ff3392b0822b70005940c7a398e4b70f30260801c5b6108008216156115d2576fe7159475a2c29b7443b29c7fa6e889d90260801c5b6110008216156115f2576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615611612576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615611632576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615611652576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615611673576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615611693576e5d6af8dedb81196699c329225ee6040260801c5b620400008216156116b2576d2216e584f5fa1ea926041bedfe980260801c5b620800008216156116cf576b048a170391f7dc42444e8fa20260801c5b60008460020b131561170857807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8161170457fe5b0490505b64010000000081061561171c57600161171f565b60005b60ff16602082901c0192505050919050565b600080807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870986860292508281109083900303905080611785576000841161177a57600080fd5b50829004905061069b565b80841161179157600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b60008373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161115611838579293925b816118845761187f836fffffffffffffffffffffffffffffffff1686860373ffffffffffffffffffffffffffffffffffffffff166c01000000000000000000000000611731565b6118c6565b6118c6836fffffffffffffffffffffffffffffffff1686860373ffffffffffffffffffffffffffffffffffffffff166c01000000000000000000000000611aab565b95945050505050565b60008373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff161115611909579293925b7bffffffffffffffffffffffffffffffff000000000000000000000000606084901b1673ffffffffffffffffffffffffffffffffffffffff868603811690871661195257600080fd5b8361199c578673ffffffffffffffffffffffffffffffffffffffff1661198f83838973ffffffffffffffffffffffffffffffffffffffff16611731565b8161199657fe5b046119dc565b6119dc6119c083838973ffffffffffffffffffffffffffffffffffffffff16611aab565b8873ffffffffffffffffffffffffffffffffffffffff16612057565b979650505050505050565b6000808573ffffffffffffffffffffffffffffffffffffffff1611611a0b57600080fd5b6000846fffffffffffffffffffffffffffffffff1611611a2a57600080fd5b81611a3c5761187f8585856001612062565b6118c685858560016121ba565b6000808573ffffffffffffffffffffffffffffffffffffffff1611611a6d57600080fd5b6000846fffffffffffffffffffffffffffffffff1611611a8c57600080fd5b81611a9e5761187f85858560006121ba565b6118c68585856000612062565b6000611ab8848484611731565b905060008280611ac457fe5b848609111561069b577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110611af957600080fd5b6001019392505050565b600081826014011015611b7757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f746f416464726573735f6f766572666c6f770000000000000000000000000000604482015290519081900360640190fd5b8160140183511015611bea57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f746f416464726573735f6f75744f66426f756e64730000000000000000000000604482015290519081900360640190fd5b5001602001516c01000000000000000000000000900490565b60608182601f011015611c7757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f736c6963655f6f766572666c6f77000000000000000000000000000000000000604482015290519081900360640190fd5b828284011015611ce857604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f736c6963655f6f766572666c6f77000000000000000000000000000000000000604482015290519081900360640190fd5b81830184511015611d5a57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f736c6963655f6f75744f66426f756e6473000000000000000000000000000000604482015290519081900360640190fd5b606082158015611d795760405191506000825260208201604052611de1565b6040519150601f8416801560200281840101858101878315602002848b0101015b81831015611db2578051835260209283019201611d9a565b5050858452601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016604052505b50949350505050565b6000808581600286810b9088900b81611dff57fe5b05905060008760020b128015611e2657508560020b8760020b81611e1f57fe5b0760020b15155b15611e4e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff015b8415611f6957600080611e60836122f0565b604080517fc677e3e0000000000000000000000000000000000000000000000000000000008152600184810b6004830152915193955091935060ff84161b80017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0191600091839173ffffffffffffffffffffffffffffffffffffffff89169163c677e3e0916024808301926020929190829003018186803b158015611f0557600080fd5b505afa158015611f19573d6000803e3d6000fd5b505050506040513d6020811015611f2f57600080fd5b5051168015159750905086611f4b57898360ff16860302611f5e565b89611f5582612302565b840360ff168603025b97505050505061204c565b600080611f78836001016122f0565b91509150600060018260ff166001901b031990506000818673ffffffffffffffffffffffffffffffffffffffff1663c677e3e0866040518263ffffffff1660e01b8152600401808260010b815260200191505060206040518083038186803b158015611fe357600080fd5b505afa158015611ff7573d6000803e3d6000fd5b505050506040513d602081101561200d57600080fd5b505116801515975090508661202f57898360ff0360ff16866001010102612045565b898361203a836123af565b0360ff168660010101025b9750505050505b505094509492505050565b808204910615150190565b6000811561210a57600073ffffffffffffffffffffffffffffffffffffffff8411156120b7576120b2846c01000000000000000000000000876fffffffffffffffffffffffffffffffff16611731565b6120d8565b6fffffffffffffffffffffffffffffffff8516606085901b816120d657fe5b045b90506121026120fd73ffffffffffffffffffffffffffffffffffffffff881683612592565b6125a2565b915050610889565b600073ffffffffffffffffffffffffffffffffffffffff84111561215757612152846c01000000000000000000000000876fffffffffffffffffffffffffffffffff16611aab565b612177565b612177606085901b6fffffffffffffffffffffffffffffffff8716612057565b9050808673ffffffffffffffffffffffffffffffffffffffff161161219b57600080fd5b73ffffffffffffffffffffffffffffffffffffffff8616039050610889565b6000826121c8575083610889565b7bffffffffffffffffffffffffffffffff000000000000000000000000606085901b16821561228f5773ffffffffffffffffffffffffffffffffffffffff86168481029085828161221557fe5b0414156122535781810182811061225157612247838973ffffffffffffffffffffffffffffffffffffffff1683611aab565b9350505050610889565b505b61228682612281878a73ffffffffffffffffffffffffffffffffffffffff16868161227a57fe5b0490612592565b612057565b92505050610889565b73ffffffffffffffffffffffffffffffffffffffff8616848102908582816122b357fe5b041480156122c057508082115b6122c957600080fd5b8082036122476120fd8473ffffffffffffffffffffffffffffffffffffffff8b1684611aab565b60020b600881901d9161010090910790565b600080821161231057600080fd5b700100000000000000000000000000000000821061233057608091821c91015b68010000000000000000821061234857604091821c91015b640100000000821061235c57602091821c91015b62010000821061236e57601091821c91015b610100821061237f57600891821c91015b6010821061238f57600491821c91015b6004821061239f57600291821c91015b600282106101b557600101919050565b60008082116123bd57600080fd5b5060ff6fffffffffffffffffffffffffffffffff8216156123ff577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8001612407565b608082901c91505b67ffffffffffffffff82161561243e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc001612446565b604082901c91505b63ffffffff821615612479577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001612481565b602082901c91505b61ffff8216156124b2577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016124ba565b601082901c91505b60ff8216156124ea577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8016124f2565b600882901c91505b600f821615612522577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc0161252a565b600482901c91505b600382161561255a577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01612562565b600282901c91505b60018216156101b5577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01919050565b808201828110156105ce57600080fd5b8073ffffffffffffffffffffffffffffffffffffffff811681146101b557600080fd5b6040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c081019190915290565b6040805160a08101825260008082526020820181905291810182905260608101829052608081019190915290565b604080516060810182526000808252602082018190529181019190915290565b600060208284031215612660578081fd5b815161069b8161287b565b60008060008060808587031215612680578283fd5b843561268b8161287b565b93506020850135801515811461269f578384fd5b92506040850135915060608501356126b68161287b565b939692955090935050565b600080604083850312156126d3578182fd5b823567ffffffffffffffff808211156126ea578384fd5b818501915085601f8301126126fd578384fd5b813560208282111561270b57fe5b61273b817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f85011601612857565b92508183528781838601011115612750578586fd5b818185018285013790820181019490945295939092013593505050565b60006080828403121561277e578081fd5b6040516080810181811067ffffffffffffffff8211171561279b57fe5b60405282356127a98161287b565b815260208301356127b98161287b565b60208201526040838101359082015260608301356127d68161287b565b60608201529392505050565b73ffffffffffffffffffffffffffffffffffffffff92831681529116602082015260400190565b918252602082015260400190565b6020808252600e908201527f506f6f6c206e6f7420666f756e64000000000000000000000000000000000000604082015260600190565b90815260200190565b60405181810167ffffffffffffffff8111828210171561287357fe5b604052919050565b73ffffffffffffffffffffffffffffffffffffffff8116811461289d57600080fd5b5056fea164736f6c6343000706000a
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000010aa510d94e094bd643677bd2964c3ee085daffc
-----Decoded View---------------
Arg [0] : _factory (address): 0x10aA510d94E094Bd643677bd2964c3EE085Daffc
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000010aa510d94e094bd643677bd2964c3ee085daffc
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.