Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
SugarHelper
Compiler Version
v0.7.6+commit.7338295f
Optimization Enabled:
Yes with 200 runs
Other Settings:
default 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 {Math} from "@openzeppelin/contracts/math/Math.sol";
import {SqrtPriceMath} from "../core/libraries/SqrtPriceMath.sol";
import {LiquidityAmounts} from "./libraries/LiquidityAmounts.sol";
import {PositionValue} from "./libraries/PositionValue.sol";
import {FullMath} from "../core/libraries/FullMath.sol";
import {TickMath} from "../core/libraries/TickMath.sol";
import {FixedPoint128} from "../core/libraries/FixedPoint128.sol";
import {ICLPool} from "../core/interfaces/ICLPool.sol";
import {INonfungiblePositionManager} from "./interfaces/INonfungiblePositionManager.sol";
import {ISugarHelper} from "./interfaces/ISugarHelper.sol";
/// @notice Expose on-chain helpers for liquidity math
contract SugarHelper is ISugarHelper {
/// @dev Maximum number of Bitmaps that can be processed per call
uint256 constant MAX_BITMAPS = 5;
///
/// Wrappers for LiquidityAmounts
///
function getAmountsForLiquidity(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) external pure override returns (uint256 amount0, uint256 amount1) {
return LiquidityAmounts.getAmountsForLiquidity({
sqrtRatioX96: sqrtRatioX96,
sqrtRatioAX96: sqrtRatioAX96,
sqrtRatioBX96: sqrtRatioBX96,
liquidity: liquidity
});
}
function getLiquidityForAmounts(
uint256 amount0,
uint256 amount1,
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96
) external pure returns (uint256 liquidity) {
return LiquidityAmounts.getLiquidityForAmounts(sqrtRatioX96, sqrtRatioAX96, sqrtRatioBX96, amount0, amount1);
}
/// @notice Computes the amount of token0 for a given amount of token1 and price range
/// @param amount1 Amount of token1 to estimate liquidity
/// @param pool Address of the pool to be used
/// @param sqrtRatioX96 A sqrt price representing the current pool prices
/// @param tickLow Lower tick boundary
/// @param tickLow Upper tick boundary
/// @dev If the given pool address is not the zero address, will fetch `sqrtRatioX96` from pool
/// @return amount0 Estimated amounnt of token0
function estimateAmount0(uint256 amount1, address pool, uint160 sqrtRatioX96, int24 tickLow, int24 tickHigh)
external
view
override
returns (uint256 amount0)
{
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLow);
uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickHigh);
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioX96 <= sqrtRatioAX96 && sqrtRatioX96 >= sqrtRatioBX96) {
return 0;
}
// @dev If a pool is provided, fetch updated `sqrtPriceX96`
if (pool != address(0)) {
(sqrtRatioX96,,,,,) = ICLPool(pool).slot0();
}
uint128 liquidity = LiquidityAmounts.getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);
amount0 = SqrtPriceMath.getAmount0Delta(sqrtRatioX96, sqrtRatioBX96, liquidity, false);
}
/// @notice Computes the amount of token1 for a given amount of token0 and price range
/// @param amount0 Amount of token0 to estimate liquidity
/// @param pool Address of the pool to be used
/// @param sqrtRatioX96 A sqrt price representing the current pool prices
/// @param tickLow Lower tick boundary
/// @param tickLow Upper tick boundary
/// @dev If the given pool address is not the zero address, will fetch `sqrtRatioX96` from pool
/// @return amount1 Estimated amounnt of token0
function estimateAmount1(uint256 amount0, address pool, uint160 sqrtRatioX96, int24 tickLow, int24 tickHigh)
external
view
override
returns (uint256 amount1)
{
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLow);
uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickHigh);
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioX96 <= sqrtRatioAX96 && sqrtRatioX96 >= sqrtRatioBX96) {
return 0;
}
// @dev If a pool is provided, fetch updated `sqrtPriceX96`
if (pool != address(0)) {
(sqrtRatioX96,,,,,) = ICLPool(pool).slot0();
}
uint128 liquidity = LiquidityAmounts.getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
amount1 = SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioX96, liquidity, false);
}
///
/// Wrappers for SqrtPriceMath
///
function getAmount0Delta(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity, bool roundUp)
external
pure
returns (uint256)
{
return SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp);
}
function getAmount1Delta(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity, bool roundUp)
external
pure
returns (uint256)
{
return SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity, roundUp);
}
function getAmount0Delta(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, int128 liquidity)
external
pure
returns (int256)
{
return SqrtPriceMath.getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity);
}
function getAmount1Delta(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, int128 liquidity)
external
pure
returns (int256)
{
return SqrtPriceMath.getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, liquidity);
}
///
/// Wrappers for PositionValue
///
function principal(INonfungiblePositionManager positionManager, uint256 tokenId, uint160 sqrtRatioX96)
external
view
override
returns (uint256 amount0, uint256 amount1)
{
return PositionValue.principal({positionManager: positionManager, tokenId: tokenId, sqrtRatioX96: sqrtRatioX96});
}
function fees(INonfungiblePositionManager positionManager, uint256 tokenId)
external
view
override
returns (uint256 amount0, uint256 amount1)
{
return PositionValue.fees({positionManager: positionManager, tokenId: tokenId});
}
///
/// Wrappers for TickMath
///
function getSqrtRatioAtTick(int24 tick) external pure override returns (uint160 sqrtRatioX96) {
return TickMath.getSqrtRatioAtTick(tick);
}
function getTickAtSqrtRatio(uint160 sqrtPriceX96) external pure override returns (int24 tick) {
return TickMath.getTickAtSqrtRatio(sqrtPriceX96);
}
///
/// PoolFees Helper
///
function poolFees(address pool, uint128 liquidity, int24 tickCurrent, int24 tickLower, int24 tickUpper)
external
view
returns (uint256 amount0, uint256 amount1)
{
(,,, uint256 lowerFeeGrowthOutside0X128, uint256 lowerFeeGrowthOutside1X128,,,,,) =
ICLPool(pool).ticks(tickLower);
(,,, uint256 upperFeeGrowthOutside0X128, uint256 upperFeeGrowthOutside1X128,,,,,) =
ICLPool(pool).ticks(tickUpper);
uint256 feeGrowthInside0X128;
uint256 feeGrowthInside1X128;
if (tickCurrent < tickLower) {
feeGrowthInside0X128 = lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;
feeGrowthInside1X128 = lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;
} else if (tickCurrent < tickUpper) {
uint256 feeGrowthGlobal0X128 = ICLPool(pool).feeGrowthGlobal0X128();
uint256 feeGrowthGlobal1X128 = ICLPool(pool).feeGrowthGlobal1X128();
feeGrowthInside0X128 = feeGrowthGlobal0X128 - lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;
feeGrowthInside1X128 = feeGrowthGlobal1X128 - lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;
} else {
feeGrowthInside0X128 = upperFeeGrowthOutside0X128 - lowerFeeGrowthOutside0X128;
feeGrowthInside1X128 = upperFeeGrowthOutside1X128 - lowerFeeGrowthOutside1X128;
}
amount0 = FullMath.mulDiv(feeGrowthInside0X128, liquidity, FixedPoint128.Q128);
amount1 = FullMath.mulDiv(feeGrowthInside1X128, liquidity, FixedPoint128.Q128);
}
///
/// TickLens Helper
///
/// @notice Fetches Tick Data for all populated Ticks in given bitmaps
/// @param pool Address of the pool from which to fetch data
/// @param startTick Tick from which the first bitmap will be fetched
/// @dev The number of bitmaps fetched by this function should always be `MAX_BITMAPS`,
/// unless there are less than `MAX_BITMAPS` left to iterate through
/// @return populatedTicks Array of all Populated Ticks in the provided bitmaps
function getPopulatedTicks(address pool, int24 startTick)
external
view
override
returns (PopulatedTick[] memory populatedTicks)
{
// fetch all bitmaps, starting at bitmap where the given `startTick` is located
int24 tickSpacing = ICLPool(pool).tickSpacing();
int16 startBitmapIndex = int16((startTick / tickSpacing) >> 8);
uint256 maxBitmaps = Math.min(MAX_BITMAPS, uint256(type(int16).max - startBitmapIndex) + 1);
// get all `maxBitmaps` starting from the given tick's bitmap index
uint256 bitmap;
uint256 numberOfPopulatedTicks;
uint256[] memory bitmaps = new uint256[](maxBitmaps);
for (uint256 j = 0; j < maxBitmaps; j++) {
// calculate the number of populated ticks
bitmap = ICLPool(pool).tickBitmap(startBitmapIndex + int16(j));
numberOfPopulatedTicks += countSetBits(bitmap);
bitmaps[j] = bitmap;
}
// fetch populated tick data
populatedTicks = new PopulatedTick[](numberOfPopulatedTicks);
int24 populatedTick;
int24 tickBitmapIndex;
for (uint256 j = 0; j < maxBitmaps; j++) {
bitmap = bitmaps[j];
tickBitmapIndex = startBitmapIndex + int16(j);
for (uint256 i = 0; i < 256; i++) {
if (bitmap & (1 << i) > 0) {
populatedTick = ((tickBitmapIndex << 8) + int24(i)) * tickSpacing;
(uint128 liquidityGross, int128 liquidityNet,,,,,,,,) = ICLPool(pool).ticks(populatedTick);
populatedTicks[--numberOfPopulatedTicks] = PopulatedTick({
tick: populatedTick,
sqrtRatioX96: TickMath.getSqrtRatioAtTick(populatedTick),
liquidityNet: liquidityNet,
liquidityGross: liquidityGross
});
}
}
}
}
function countSetBits(uint256 bitmap) private pure returns (uint256 count) {
while (bitmap != 0) {
bitmap &= (bitmap - 1);
count++;
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {IVoter} from "contracts/core/interfaces/IVoter.sol";
import {IFactoryRegistry} from "contracts/core/interfaces/IFactoryRegistry.sol";
/// @title The interface for the CL Factory
/// @notice The CL Factory facilitates creation of CL pools and control over the protocol fees
interface ICLFactory {
/// @notice Emitted when the owner of the factory is changed
/// @param oldOwner The owner before the owner was changed
/// @param newOwner The owner after the owner was changed
event OwnerChanged(address indexed oldOwner, address indexed newOwner);
event VoterChanged(address indexed oldVoter, address indexed newVoter);
/// @notice Emitted when the swapFeeManager of the factory is changed
/// @param oldFeeManager The swapFeeManager before the swapFeeManager was changed
/// @param newFeeManager The swapFeeManager after the swapFeeManager was changed
event SwapFeeManagerChanged(address indexed oldFeeManager, address indexed newFeeManager);
/// @notice Emitted when the swapFeeModule of the factory is changed
/// @param oldFeeModule The swapFeeModule before the swapFeeModule was changed
/// @param newFeeModule The swapFeeModule after the swapFeeModule was changed
event SwapFeeModuleChanged(address indexed oldFeeModule, address indexed newFeeModule);
/// @notice Emitted when the unstakedFeeManager of the factory is changed
/// @param oldFeeManager The unstakedFeeManager before the unstakedFeeManager was changed
/// @param newFeeManager The unstakedFeeManager after the unstakedFeeManager was changed
event UnstakedFeeManagerChanged(address indexed oldFeeManager, address indexed newFeeManager);
/// @notice Emitted when the unstakedFeeModule of the factory is changed
/// @param oldFeeModule The unstakedFeeModule before the unstakedFeeModule was changed
/// @param newFeeModule The unstakedFeeModule after the unstakedFeeModule was changed
event UnstakedFeeModuleChanged(address indexed oldFeeModule, address indexed newFeeModule);
/// @notice Emitted when the defaultUnstakedFee of the factory is changed
/// @param oldUnstakedFee The defaultUnstakedFee before the defaultUnstakedFee was changed
/// @param newUnstakedFee The defaultUnstakedFee after the unstakedFeeModule was changed
event DefaultUnstakedFeeChanged(uint24 indexed oldUnstakedFee, uint24 indexed newUnstakedFee);
/// @notice Emitted when a pool is created
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param pool The address of the created pool
event PoolCreated(address indexed token0, address indexed token1, int24 indexed tickSpacing, address pool);
/// @notice Emitted when a new tick spacing is enabled for pool creation via the factory
/// @param tickSpacing The minimum number of ticks between initialized ticks for pools
/// @param fee The default fee for a pool created with a given tickSpacing
event TickSpacingEnabled(int24 indexed tickSpacing, uint24 indexed fee);
/// @notice The voter contract, used to create gauges
/// @return The address of the voter contract
function voter() external view returns (IVoter);
/// @notice The address of the pool implementation contract used to deploy proxies / clones
/// @return The address of the pool implementation contract
function poolImplementation() external view returns (address);
/// @notice Factory registry for valid pool / gauge / rewards factories
/// @return The address of the factory registry
function factoryRegistry() external view returns (IFactoryRegistry);
/// @notice Returns the current owner of the factory
/// @dev Can be changed by the current owner via setOwner
/// @return The address of the factory owner
function owner() external view returns (address);
/// @notice Returns the current swapFeeManager of the factory
/// @dev Can be changed by the current swap fee manager via setSwapFeeManager
/// @return The address of the factory swapFeeManager
function swapFeeManager() external view returns (address);
/// @notice Returns the current swapFeeModule of the factory
/// @dev Can be changed by the current swap fee manager via setSwapFeeModule
/// @return The address of the factory swapFeeModule
function swapFeeModule() external view returns (address);
/// @notice Returns the current unstakedFeeManager of the factory
/// @dev Can be changed by the current unstaked fee manager via setUnstakedFeeManager
/// @return The address of the factory unstakedFeeManager
function unstakedFeeManager() external view returns (address);
/// @notice Returns the current unstakedFeeModule of the factory
/// @dev Can be changed by the current unstaked fee manager via setUnstakedFeeModule
/// @return The address of the factory unstakedFeeModule
function unstakedFeeModule() external view returns (address);
/// @notice Returns the current defaultUnstakedFee of the factory
/// @dev Can be changed by the current unstaked fee manager via setDefaultUnstakedFee
/// @return The default Unstaked Fee of the factory
function defaultUnstakedFee() external view returns (uint24);
/// @notice Returns a default fee for a tick spacing.
/// @dev Use getFee for the most up to date fee for a given pool.
/// A tick spacing can never be removed, so this value should be hard coded or cached in the calling context
/// @param tickSpacing The enabled tick spacing. Returns 0 if not enabled
/// @return fee The default fee for the given tick spacing
function tickSpacingToFee(int24 tickSpacing) external view returns (uint24 fee);
/// @notice Returns a list of enabled tick spacings. Used to iterate through pools created by the factory
/// @dev Tick spacings cannot be removed. Tick spacings are not ordered
/// @return List of enabled tick spacings
function tickSpacings() external view returns (int24[] memory);
/// @notice Returns the pool address for a given pair of tokens and a tick spacing, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param tickSpacing The tick spacing of the pool
/// @return pool The pool address
function getPool(address tokenA, address tokenB, int24 tickSpacing) external view returns (address pool);
/// @notice Return address of pool created by this factory given its `index`
/// @param index Index of the pool
/// @return The pool address in the given index
function allPools(uint256 index) external view returns (address);
/// @notice Returns the number of pools created from this factory
/// @return Number of pools created from this factory
function allPoolsLength() external view returns (uint256);
/// @notice Used in VotingEscrow to determine if a contract is a valid pool of the factory
/// @param pool The address of the pool to check
/// @return Whether the pool is a valid pool of the factory
function isPair(address pool) external view returns (bool);
/// @notice Get swap & flash fee for a given pool. Accounts for default and dynamic fees
/// @dev Swap & flash fee is denominated in pips. i.e. 1e-6
/// @param pool The pool to get the swap & flash fee for
/// @return The swap & flash fee for the given pool
function getSwapFee(address pool) external view returns (uint24);
/// @notice Get unstaked fee for a given pool. Accounts for default and dynamic fees
/// @dev Unstaked fee is denominated in pips. i.e. 1e-6
/// @param pool The pool to get the unstaked fee for
/// @return The unstaked fee for the given pool
function getUnstakedFee(address pool) external view returns (uint24);
/// @notice Creates a pool for the given two tokens and fee
/// @param tokenA One of the two tokens in the desired pool
/// @param tokenB The other of the two tokens in the desired pool
/// @param tickSpacing The desired tick spacing for the pool
/// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
/// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. The call will
/// revert if the pool already exists, the tick spacing is invalid, or the token arguments are invalid
/// @return pool The address of the newly created pool
function createPool(address tokenA, address tokenB, int24 tickSpacing, uint160 sqrtPriceX96)
external
returns (address pool);
/// @notice Updates the owner of the factory
/// @dev Must be called by the current owner
/// @param _owner The new owner of the factory
function setOwner(address _owner) external;
/// @notice Updates the swapFeeManager of the factory
/// @dev Must be called by the current swap fee manager
/// @param _swapFeeManager The new swapFeeManager of the factory
function setSwapFeeManager(address _swapFeeManager) external;
/// @notice Updates the swapFeeModule of the factory
/// @dev Must be called by the current swap fee manager
/// @param _swapFeeModule The new swapFeeModule of the factory
function setSwapFeeModule(address _swapFeeModule) external;
/// @notice Updates the unstakedFeeManager of the factory
/// @dev Must be called by the current unstaked fee manager
/// @param _unstakedFeeManager The new unstakedFeeManager of the factory
function setUnstakedFeeManager(address _unstakedFeeManager) external;
/// @notice Updates the unstakedFeeModule of the factory
/// @dev Must be called by the current unstaked fee manager
/// @param _unstakedFeeModule The new unstakedFeeModule of the factory
function setUnstakedFeeModule(address _unstakedFeeModule) external;
/// @notice Updates the defaultUnstakedFee of the factory
/// @dev Must be called by the current unstaked fee manager
/// @param _defaultUnstakedFee The new defaultUnstakedFee of the factory
function setDefaultUnstakedFee(uint24 _defaultUnstakedFee) external;
/// @notice Enables a certain tickSpacing
/// @dev Tick spacings may never be removed once enabled
/// @param tickSpacing The spacing between ticks to be enforced in the pool
/// @param fee The default fee associated with a given tick spacing
function enableTickSpacing(int24 tickSpacing, uint24 fee) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import "./pool/ICLPoolConstants.sol";
import "./pool/ICLPoolState.sol";
import "./pool/ICLPoolDerivedState.sol";
import "./pool/ICLPoolActions.sol";
import "./pool/ICLPoolOwnerActions.sol";
import "./pool/ICLPoolEvents.sol";
/// @title The interface for a CL Pool
/// @notice A CL 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 ICLPool is
ICLPoolConstants,
ICLPoolState,
ICLPoolDerivedState,
ICLPoolActions,
ICLPoolEvents,
ICLPoolOwnerActions
{}// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
interface IFactoryRegistry {
function approve(address poolFactory, address votingRewardsFactory, address gaugeFactory) external;
function isPoolFactoryApproved(address poolFactory) external returns (bool);
function factoriesToPoolFactory(address poolFactory)
external
returns (address votingRewardsFactory, address gaugeFactory);
}// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
pragma abicoder v2;
import {IVotingEscrow} from "contracts/core/interfaces/IVotingEscrow.sol";
import {IFactoryRegistry} from "contracts/core/interfaces/IFactoryRegistry.sol";
interface IVoter {
function ve() external view returns (IVotingEscrow);
function vote(uint256 _tokenId, address[] calldata _poolVote, uint256[] calldata _weights) external;
function gauges(address _pool) external view returns (address);
function gaugeToFees(address _gauge) external view returns (address);
function gaugeToBribes(address _gauge) external view returns (address);
function createGauge(address _poolFactory, address _pool) external returns (address);
function distribute(address gauge) external;
function factoryRegistry() external view returns (IFactoryRegistry);
/// @dev Utility to distribute to gauges of pools in array.
/// @param _gauges Array of gauges to distribute to.
function distribute(address[] memory _gauges) external;
function isAlive(address _gauge) external view returns (bool);
function killGauge(address _gauge) external;
function emergencyCouncil() external view returns (address);
/// @notice Claim emissions from gauges.
/// @param _gauges Array of gauges to collect emissions from.
function claimRewards(address[] memory _gauges) external;
/// @notice Claim fees for a given NFT.
/// @dev Utility to help batch fee claims.
/// @param _fees Array of FeesVotingReward contracts to collect from.
/// @param _tokens Array of tokens that are used as fees.
/// @param _tokenId Id of veNFT that you wish to claim fees for.
function claimFees(address[] memory _fees, address[][] memory _tokens, uint256 _tokenId) external;
}// SPDX-License-Identifier: MIT
pragma solidity =0.7.6;
interface IVotingEscrow {
function team() external returns (address);
/// @notice Deposit `_value` tokens for `msg.sender` and lock for `_lockDuration`
/// @param _value Amount to deposit
/// @param _lockDuration Number of seconds to lock tokens for (rounded down to nearest week)
/// @return TokenId of created veNFT
function createLock(uint256 _value, uint256 _lockDuration) external returns (uint256);
}// 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 ICLPoolActions {
/// @notice Initialize function used in proxy deployment
/// @dev Can be called once only
/// Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @dev not locked because it initializes unlocked
/// @param _factory The CL factory contract address
/// @param _token0 The first token of the pool by address sort order
/// @param _token1 The second token of the pool by address sort order
/// @param _tickSpacing The pool tick spacing
/// @param _sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
function initialize(
address _factory,
address _token0,
address _token1,
int24 _tickSpacing,
uint160 _sqrtPriceX96
) external;
/// @notice Initialize gauge and nft manager
/// @dev Callable only once, by the gauge factory
/// @param _gauge The gauge corresponding to this pool
/// @param _nft The position manager used for position management
function setGaugeAndPositionManager(address _gauge, address _nft) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of ICLMintCallback#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 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
/// @param owner Owner of the position in the pool (nft manager or gauge)
/// @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,
address owner
) 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 Burn liquidity from the supplied owner 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
/// @param owner Owner of the position in the pool (nft manager or gauge)
/// @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, address owner)
external
returns (uint256 amount0, uint256 amount1);
/// @notice Convert existing liquidity into staked liquidity
/// @notice Only callable by the gauge associated with this pool
/// @param stakedLiquidityDelta The amount by which to increase or decrease the staked liquidity
/// @param tickLower The lower tick of the position for which to stake liquidity
/// @param tickUpper The upper tick of the position for which to stake liquidity
/// @param positionUpdate If the nft and gauge position should be updated
function stake(int128 stakedLiquidityDelta, int24 tickLower, int24 tickUpper, bool positionUpdate) external;
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of ICLSwapCallback#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 ICLFlashCallback#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;
/// @notice Updates rewardGrowthGlobalX128 every time when any tick is crossed,
/// or when any position is staked/unstaked from the gauge
function updateRewardsGrowthGlobal() external;
/// @notice Syncs rewards with gauge
/// @param rewardRate the rate rewards being distributed during the epoch
/// @param rewardReserve the available rewards to be distributed during the epoch
/// @param periodFinish the end of the current period of rewards, updated once per epoch
function syncReward(uint256 rewardRate, uint256 rewardReserve, uint256 periodFinish) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that never changes
/// @notice These parameters are not defined as immutable (due to proxy pattern) but are effectively immutable.
/// @notice i.e., the methods will always return the same values
interface ICLPoolConstants {
/// @notice The contract that deployed the pool, which must adhere to the ICLFactory 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 gauge corresponding to this pool
/// @return The gauge contract address
function gauge() external view returns (address);
/// @notice The nft manager
/// @return The nft manager contract address
function nft() external view returns (address);
// /// @notice The factory registry that manages pool <> gauge <> reward factory relationships
// /// @return The factory registry contract address
// function factoryRegistry() external view returns (address);
/// @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 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 ICLPoolDerivedState {
/// @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 ICLPoolEvents {
/// @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 gauge
/// @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 CollectFees(address indexed recipient, uint128 amount0, uint128 amount1);
}// 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 ICLPoolOwnerActions {
/// @notice Collect the gauge fee accrued to the pool
/// @return amount0 The gauge fee collected in token0
/// @return amount1 The gauge fee collected in token1
function collectFees() 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 ICLPoolState {
/// @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.
/// unlocked Whether the pool is currently locked to reentrancy
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
bool unlocked
);
/// @notice The pool's swap & flash fee in pips, i.e. 1e-6
/// @dev Can be modified in PoolFactory on a pool basis or upgraded to be dynamic.
/// @return The swap & flash fee
function fee() external view returns (uint24);
/// @notice The pool's unstaked fee in pips, i.e. 1e-6
/// @dev Can be modified in PoolFactory on a pool basis or upgraded to be dynamic.
/// @return The unstaked fee
function unstakedFee() external view returns (uint24);
/// @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 reward growth as a Q128.128 rewards of emission collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function rewardGrowthGlobalX128() external view returns (uint256);
/// @notice The amounts of token0 and token1 that are owed to the gauge
/// @dev Gauge fees will never exceed uint128 max in either token
function gaugeFees() external view returns (uint128 token0, uint128 token1);
/// @notice the emission rate of time-based farming
function rewardRate() external view returns (uint256);
/// @notice acts as a virtual reserve that holds information on how many rewards are yet to be distributed
function rewardReserve() external view returns (uint256);
/// @notice timestamp of the end of the current epoch's rewards
function periodFinish() external view returns (uint256);
/// @notice last time the rewardReserve and rewardRate were updated
function lastUpdated() external view returns (uint32);
/// @notice tracks total rewards distributed when no staked liquidity in active tick for epoch ending at periodFinish
/// @notice this amount is rolled over on the next call to notifyRewardAmount
/// @dev rollover will always be smaller than the rewards distributed that epoch
function rollover() 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
/// @dev This value includes staked liquidity
function liquidity() external view returns (uint128);
/// @notice The currently in range staked liquidity available to the pool
/// @dev This value has no relationship to the total staked liquidity across all ticks
function stakedLiquidity() 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,
/// stakedLiquidityNet how much staked 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,
/// rewardGrowthOutsideX128 the reward growth on the other side of the tick from the current tick in emission token
/// 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,
int128 stakedLiquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128,
uint256 rewardGrowthOutsideX128,
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
);
/// @notice Returns data about reward growth within a tick range.
/// RewardGrowthGlobalX128 can be supplied as a parameter for claimable reward calculations.
/// @dev Used in gauge reward/earned calculations
/// @param tickLower The lower tick of the range
/// @param tickUpper The upper tick of the range
/// @param _rewardGrowthGlobalX128 a calculated rewardGrowthGlobalX128 or 0 (in case of 0 it means we use the rewardGrowthGlobalX128 from state)
/// @return rewardGrowthInsideX128 The reward growth in the range
function getRewardGrowthInside(int24 tickLower, int24 tickUpper, uint256 _rewardGrowthGlobalX128)
external
view
returns (uint256 rewardGrowthInsideX128);
}// 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: GPL-2.0-or-later
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: GPL-2.0-or-later
pragma solidity >=0.5.0 <0.8.0;
import "./LowGasSafeMath.sol";
import "./SafeCast.sol";
import "./TickMath.sol";
import "./LiquidityMath.sol";
/// @title Tick
/// @notice Contains functions for managing tick processes and relevant calculations
library Tick {
using LowGasSafeMath for int256;
using SafeCast for int256;
// info stored for each initialized individual tick
struct Info {
// the total position liquidity that references this tick
// includes both staked and unstaked liquidity
uint128 liquidityGross;
// amount of net liquidity added (subtracted) when tick is crossed from left to right (right to left)
// includes both staked and unstaked liquidity
int128 liquidityNet;
// amount of net staked liquidity added (subtracted) when tick is crossed from left to right (right to left)
int128 stakedLiquidityNet;
// fee growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
// only has relative meaning, not absolute — the value depends on when the tick is initialized
uint256 feeGrowthOutside0X128;
uint256 feeGrowthOutside1X128;
// reward growth per unit of liquidity on the _other_ side of this tick (relative to the current tick)
// only has relative meaning, not absolute — the value depends on when the tick is initialized
uint256 rewardGrowthOutsideX128;
// the cumulative tick value on the other side of the tick
int56 tickCumulativeOutside;
// the seconds per unit of liquidity on the _other_ side of this tick (relative to the current tick)
// only has relative meaning, not absolute — the value depends on when the tick is initialized
uint160 secondsPerLiquidityOutsideX128;
// the seconds spent on the other side of the tick (relative to the current tick)
// only has relative meaning, not absolute — the value depends on when the tick is initialized
uint32 secondsOutside;
// true iff the tick is initialized, i.e. the value is exactly equivalent to the expression liquidityGross != 0
// these 8 bits are set to prevent fresh sstores when crossing newly initialized ticks
bool initialized;
}
struct LiquidityNets {
int128 liquidityNet;
int128 stakedLiquidityNet;
}
/// @notice Derives max liquidity per tick from given tick spacing
/// @dev Executed within the pool constructor
/// @param tickSpacing The amount of required tick separation, realized in multiples of `tickSpacing`
/// e.g., a tickSpacing of 3 requires ticks to be initialized every 3rd tick i.e., ..., -6, -3, 0, 3, 6, ...
/// @return The max liquidity per tick
function tickSpacingToMaxLiquidityPerTick(int24 tickSpacing) internal pure returns (uint128) {
int24 minTick = (TickMath.MIN_TICK / tickSpacing) * tickSpacing;
int24 maxTick = (TickMath.MAX_TICK / tickSpacing) * tickSpacing;
uint24 numTicks = uint24((maxTick - minTick) / tickSpacing) + 1;
return type(uint128).max / numTicks;
}
/// @notice Retrieves fee growth data
/// @param self The mapping containing all tick information for initialized ticks
/// @param tickLower The lower tick boundary of the position
/// @param tickUpper The upper tick boundary of the position
/// @param tickCurrent The current tick
/// @param feeGrowthGlobal0X128 The all-time global fee growth, per unit of liquidity, in token0
/// @param feeGrowthGlobal1X128 The all-time global fee growth, per unit of liquidity, in token1
/// @return feeGrowthInside0X128 The all-time fee growth in token0, per unit of liquidity, inside the position's tick boundaries
/// @return feeGrowthInside1X128 The all-time fee growth in token1, per unit of liquidity, inside the position's tick boundaries
function getFeeGrowthInside(
mapping(int24 => Tick.Info) storage self,
int24 tickLower,
int24 tickUpper,
int24 tickCurrent,
uint256 feeGrowthGlobal0X128,
uint256 feeGrowthGlobal1X128
) internal view returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) {
Info storage lower = self[tickLower];
Info storage upper = self[tickUpper];
// calculate fee growth below
uint256 feeGrowthBelow0X128;
uint256 feeGrowthBelow1X128;
if (tickCurrent >= tickLower) {
feeGrowthBelow0X128 = lower.feeGrowthOutside0X128;
feeGrowthBelow1X128 = lower.feeGrowthOutside1X128;
} else {
feeGrowthBelow0X128 = feeGrowthGlobal0X128 - lower.feeGrowthOutside0X128;
feeGrowthBelow1X128 = feeGrowthGlobal1X128 - lower.feeGrowthOutside1X128;
}
// calculate fee growth above
uint256 feeGrowthAbove0X128;
uint256 feeGrowthAbove1X128;
if (tickCurrent < tickUpper) {
feeGrowthAbove0X128 = upper.feeGrowthOutside0X128;
feeGrowthAbove1X128 = upper.feeGrowthOutside1X128;
} else {
feeGrowthAbove0X128 = feeGrowthGlobal0X128 - upper.feeGrowthOutside0X128;
feeGrowthAbove1X128 = feeGrowthGlobal1X128 - upper.feeGrowthOutside1X128;
}
feeGrowthInside0X128 = feeGrowthGlobal0X128 - feeGrowthBelow0X128 - feeGrowthAbove0X128;
feeGrowthInside1X128 = feeGrowthGlobal1X128 - feeGrowthBelow1X128 - feeGrowthAbove1X128;
}
function getRewardGrowthInside(
mapping(int24 => Tick.Info) storage self,
int24 tickLower,
int24 tickUpper,
int24 tickCurrent,
uint256 rewardGrowthGlobalX128
) internal view returns (uint256 rewardGrowthInsideX128) {
Info storage lower = self[tickLower];
Info storage upper = self[tickUpper];
// calculate reward growth below
uint256 rewardGrowthBelowX128;
if (tickCurrent >= tickLower) {
rewardGrowthBelowX128 = lower.rewardGrowthOutsideX128;
} else {
rewardGrowthBelowX128 = rewardGrowthGlobalX128 - lower.rewardGrowthOutsideX128;
}
// calculate reward growth above
uint256 rewardGrowthAboveX128;
if (tickCurrent < tickUpper) {
rewardGrowthAboveX128 = upper.rewardGrowthOutsideX128;
} else {
rewardGrowthAboveX128 = rewardGrowthGlobalX128 - upper.rewardGrowthOutsideX128;
}
rewardGrowthInsideX128 = rewardGrowthGlobalX128 - rewardGrowthBelowX128 - rewardGrowthAboveX128;
}
/// @notice Updates a tick and returns true if the tick was flipped from initialized to uninitialized, or vice versa
/// @param self The mapping containing all tick information for initialized ticks
/// @param tick The tick that will be updated
/// @param tickCurrent The current tick
/// @param liquidityDelta A new amount of liquidity to be added (subtracted) when tick is crossed from left to right (right to left)
/// @param feeGrowthGlobal0X128 The all-time global fee growth, per unit of liquidity, in token0
/// @param feeGrowthGlobal1X128 The all-time global fee growth, per unit of liquidity, in token1
/// @param rewardGrowthGlobalX128 The all-time global reward growth, per unit of liquidity
/// @param secondsPerLiquidityCumulativeX128 The all-time seconds per max(1, liquidity) of the pool
/// @param tickCumulative The tick * time elapsed since the pool was first initialized
/// @param time The current block timestamp cast to a uint32
/// @param upper true for updating a position's upper tick, or false for updating a position's lower tick
/// @param maxLiquidity The maximum liquidity allocation for a single tick
/// @return flipped Whether the tick was flipped from initialized to uninitialized, or vice versa
function update(
mapping(int24 => Tick.Info) storage self,
int24 tick,
int24 tickCurrent,
int128 liquidityDelta,
uint256 feeGrowthGlobal0X128,
uint256 feeGrowthGlobal1X128,
uint256 rewardGrowthGlobalX128,
uint160 secondsPerLiquidityCumulativeX128,
int56 tickCumulative,
uint32 time,
bool upper,
uint128 maxLiquidity
) internal returns (bool flipped) {
Tick.Info storage info = self[tick];
uint128 liquidityGrossBefore = info.liquidityGross;
uint128 liquidityGrossAfter = LiquidityMath.addDelta(liquidityGrossBefore, liquidityDelta);
require(liquidityGrossAfter <= maxLiquidity, "LO");
flipped = (liquidityGrossAfter == 0) != (liquidityGrossBefore == 0);
if (liquidityGrossBefore == 0) {
// by convention, we assume that all growth before a tick was initialized happened _below_ the tick
if (tick <= tickCurrent) {
info.feeGrowthOutside0X128 = feeGrowthGlobal0X128;
info.feeGrowthOutside1X128 = feeGrowthGlobal1X128;
info.rewardGrowthOutsideX128 = rewardGrowthGlobalX128;
info.secondsPerLiquidityOutsideX128 = secondsPerLiquidityCumulativeX128;
info.tickCumulativeOutside = tickCumulative;
info.secondsOutside = time;
}
info.initialized = true;
}
info.liquidityGross = liquidityGrossAfter;
// when the lower (upper) tick is crossed left to right (right to left), liquidity must be added (removed)
info.liquidityNet = upper
? int256(info.liquidityNet).sub(liquidityDelta).toInt128()
: int256(info.liquidityNet).add(liquidityDelta).toInt128();
}
/// @notice Updates the staked liquidity component of a tick. Assumes tick is already initialized with an existing position.
/// @notice We reuse existing liquidity for staking, so there is no change in liquidity
/// @param self The mapping containing all tick information for initialized ticks
/// @param tick The tick that will be updated
/// @param stakedLiquidityDelta The amount of staked liquidity to be added (subtracted) when tick is crossed from left to right (right to left)
/// @param upper true for updating a position's upper tick, or false for updating a position's lower tick
function updateStake(mapping(int24 => Tick.Info) storage self, int24 tick, int128 stakedLiquidityDelta, bool upper)
internal
{
Tick.Info storage info = self[tick];
// when the lower (upper) tick is crossed left to right (right to left), staked liquidity must be added (removed)
info.stakedLiquidityNet = upper
? int256(info.stakedLiquidityNet).sub(stakedLiquidityDelta).toInt128()
: int256(info.stakedLiquidityNet).add(stakedLiquidityDelta).toInt128();
}
/// @notice Clears tick data
/// @param self The mapping containing all initialized tick information for initialized ticks
/// @param tick The tick that will be cleared
function clear(mapping(int24 => Tick.Info) storage self, int24 tick) internal {
delete self[tick];
}
/// @notice Transitions to next tick as needed by price movement
/// @param self The mapping containing all tick information for initialized ticks
/// @param tick The destination tick of the transition
/// @param feeGrowthGlobal0X128 The all-time global fee growth, per unit of liquidity, in token0
/// @param feeGrowthGlobal1X128 The all-time global fee growth, per unit of liquidity, in token1
/// @param secondsPerLiquidityCumulativeX128 The current seconds per liquidity
/// @param tickCumulative The tick * time elapsed since the pool was first initialized
/// @param time The current block.timestamp
/// @param rewardGrowthGlobalX128 The all-time global reward growth, per unit of liquidity
/// @return nets The amount of liquidity and staked liquidity added (subtracted) when tick is crossed from left to right (right to left)
function cross(
mapping(int24 => Tick.Info) storage self,
int24 tick,
uint256 feeGrowthGlobal0X128,
uint256 feeGrowthGlobal1X128,
uint160 secondsPerLiquidityCumulativeX128,
int56 tickCumulative,
uint32 time,
uint256 rewardGrowthGlobalX128
) internal returns (LiquidityNets memory nets) {
Tick.Info storage info = self[tick];
info.feeGrowthOutside0X128 = feeGrowthGlobal0X128 - info.feeGrowthOutside0X128;
info.feeGrowthOutside1X128 = feeGrowthGlobal1X128 - info.feeGrowthOutside1X128;
info.rewardGrowthOutsideX128 = rewardGrowthGlobalX128 - info.rewardGrowthOutsideX128;
info.secondsPerLiquidityOutsideX128 = secondsPerLiquidityCumulativeX128 - info.secondsPerLiquidityOutsideX128;
info.tickCumulativeOutside = tickCumulative - info.tickCumulativeOutside;
info.secondsOutside = time - info.secondsOutside;
nets.liquidityNet = info.liquidityNet;
nets.stakedLiquidityNet = info.stakedLiquidityNet;
}
}// 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: MIT
pragma solidity >=0.7.5;
/// @title EIP-721 Metadata Update Extension
interface IERC4906 {
/// @dev This event emits when the metadata of a token is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFT.
event MetadataUpdate(uint256 _tokenId);
/// @dev This event emits when the metadata of a range of tokens is changed.
/// So that the third-party platforms such as NFT market could
/// timely update the images and related attributes of the NFTs.
event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
/// @title ERC721 with permit
/// @notice Extension to ERC721 that includes a permit function for signature based approvals
interface IERC721Permit is IERC721 {
/// @notice The permit typehash used in the permit signature
/// @return The typehash for the permit
function PERMIT_TYPEHASH() external pure returns (bytes32);
/// @notice The domain separator used in the permit signature
/// @return The domain seperator used in encoding of permit signature
function DOMAIN_SEPARATOR() external view returns (bytes32);
/// @notice Approve of a specific token ID for spending by spender via signature
/// @param spender The account that is being approved
/// @param tokenId The ID of the token that is being approved for spending
/// @param deadline The deadline timestamp by which the call must be mined for the approve to work
/// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
/// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
/// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external
payable;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import "@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Enumerable.sol";
import "./IERC721Permit.sol";
import "./IERC4906.sol";
import "./IPeripheryPayments.sol";
import "./IPeripheryImmutableState.sol";
import "../libraries/PoolAddress.sol";
/// @title Non-fungible token for positions
/// @notice Wraps CL positions in a non-fungible token interface which allows for them to be transferred
/// and authorized.
interface INonfungiblePositionManager is
IPeripheryPayments,
IPeripheryImmutableState,
IERC721Metadata,
IERC721Enumerable,
IERC721Permit,
IERC4906
{
/// @notice Emitted when liquidity is increased for a position NFT
/// @dev Also emitted when a token is minted
/// @param tokenId The ID of the token for which liquidity was increased
/// @param liquidity The amount by which liquidity for the NFT position was increased
/// @param amount0 The amount of token0 that was paid for the increase in liquidity
/// @param amount1 The amount of token1 that was paid for the increase in liquidity
event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Emitted when liquidity is decreased for a position NFT
/// @param tokenId The ID of the token for which liquidity was decreased
/// @param liquidity The amount by which liquidity for the NFT position was decreased
/// @param amount0 The amount of token0 that was accounted for the decrease in liquidity
/// @param amount1 The amount of token1 that was accounted for the decrease in liquidity
event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
/// @notice Emitted when tokens are collected for a position NFT
/// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior
/// @param tokenId The ID of the token for which underlying tokens were collected
/// @param recipient The address of the account that received the collected tokens
/// @param amount0 The amount of token0 owed to the position that was collected
/// @param amount1 The amount of token1 owed to the position that was collected
event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1);
/// @notice Emitted when a new Token Descriptor is set
/// @param tokenDescriptor Address of the new Token Descriptor
event TokenDescriptorChanged(address indexed tokenDescriptor);
/// @notice Emitted when a new Owner is set
/// @param owner Address of the new Owner
event TransferOwnership(address indexed owner);
/// @notice Returns the position information associated with a given token ID.
/// @dev Throws if the token ID is not valid.
/// @param tokenId The ID of the token that represents the position
/// @return nonce The nonce for permits
/// @return operator The address that is approved for spending
/// @return token0 The address of the token0 for a specific pool
/// @return token1 The address of the token1 for a specific pool
/// @return tickSpacing The tick spacing associated with the pool
/// @return tickLower The lower end of the tick range for the position
/// @return tickUpper The higher end of the tick range for the position
/// @return liquidity The liquidity of the position
/// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position
/// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position
/// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation
/// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation
function positions(uint256 tokenId)
external
view
returns (
uint96 nonce,
address operator,
address token0,
address token1,
int24 tickSpacing,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
/// @notice Returns the address of the Token Descriptor, that handles generating token URIs for Positions
function tokenDescriptor() external view returns (address);
/// @notice Returns the address of the Owner, that is allowed to set a new TokenDescriptor
function owner() external view returns (address);
struct MintParams {
address token0;
address token1;
int24 tickSpacing;
int24 tickLower;
int24 tickUpper;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
address recipient;
uint256 deadline;
uint160 sqrtPriceX96;
}
/// @notice Creates a new position wrapped in a NFT
/// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized
/// a method does not exist, i.e. the pool is assumed to be initialized.
/// @param params The params necessary to mint a position, encoded as `MintParams` in calldata
/// @return tokenId The ID of the token that represents the minted position
/// @return liquidity The amount of liquidity for this position
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function mint(MintParams calldata params)
external
payable
returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1);
struct IncreaseLiquidityParams {
uint256 tokenId;
uint256 amount0Desired;
uint256 amount1Desired;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender`
/// @param params tokenId The ID of the token for which liquidity is being increased,
/// amount0Desired The desired amount of token0 to be spent,
/// amount1Desired The desired amount of token1 to be spent,
/// amount0Min The minimum amount of token0 to spend, which serves as a slippage check,
/// amount1Min The minimum amount of token1 to spend, which serves as a slippage check,
/// deadline The time by which the transaction must be included to effect the change
/// @return liquidity The new liquidity amount as a result of the increase
/// @return amount0 The amount of token0 to acheive resulting liquidity
/// @return amount1 The amount of token1 to acheive resulting liquidity
function increaseLiquidity(IncreaseLiquidityParams calldata params)
external
payable
returns (uint128 liquidity, uint256 amount0, uint256 amount1);
struct DecreaseLiquidityParams {
uint256 tokenId;
uint128 liquidity;
uint256 amount0Min;
uint256 amount1Min;
uint256 deadline;
}
/// @notice Decreases the amount of liquidity in a position and accounts it to the position
/// @param params tokenId The ID of the token for which liquidity is being decreased,
/// amount The amount by which liquidity will be decreased,
/// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity,
/// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity,
/// deadline The time by which the transaction must be included to effect the change
/// @return amount0 The amount of token0 accounted to the position's tokens owed
/// @return amount1 The amount of token1 accounted to the position's tokens owed
/// @dev The use of this function can cause a loss to users of the NonfungiblePositionManager
/// @dev for tokens that have very high decimals.
/// @dev The amount of tokens necessary for the loss is: 3.4028237e+38.
/// @dev This is equivalent to 1e20 value with 18 decimals.
function decreaseLiquidity(DecreaseLiquidityParams calldata params)
external
payable
returns (uint256 amount0, uint256 amount1);
struct CollectParams {
uint256 tokenId;
address recipient;
uint128 amount0Max;
uint128 amount1Max;
}
/// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient
/// @notice Used to update staked positions before deposit and withdraw
/// @param params tokenId The ID of the NFT for which tokens are being collected,
/// recipient The account that should receive the tokens,
/// amount0Max The maximum amount of token0 to collect,
/// amount1Max The maximum amount of token1 to collect
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1);
/// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens
/// must be collected first.
/// @param tokenId The ID of the token that is being burned
function burn(uint256 tokenId) external payable;
/// @notice Sets a new Token Descriptor
/// @param _tokenDescriptor Address of the new Token Descriptor to be chosen
function setTokenDescriptor(address _tokenDescriptor) external;
/// @notice Sets a new Owner address
/// @param _owner Address of the new Owner to be chosen
function setOwner(address _owner) external;
}// 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 CL 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
pragma solidity >=0.7.5;
/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of ETH
interface IPeripheryPayments {
/// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
/// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
/// @param amountMinimum The minimum amount of WETH9 to unwrap
/// @param recipient The address receiving ETH
function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;
/// @notice Refunds any ETH balance held by this contract to the `msg.sender`
/// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
/// that use ether for the input amount
function refundETH() external payable;
/// @notice Transfers the full amount of a token held by this contract to recipient
/// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
/// @param token The contract address of the token which will be transferred to `recipient`
/// @param amountMinimum The minimum amount of token required for a transfer
/// @param recipient The destination address of the token
function sweepToken(address token, uint256 amountMinimum, address recipient) external payable;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
pragma abicoder v2;
import {INonfungiblePositionManager} from "./INonfungiblePositionManager.sol";
interface ISugarHelper {
struct PopulatedTick {
int24 tick;
uint160 sqrtRatioX96;
int128 liquidityNet;
uint128 liquidityGross;
}
///
/// Wrappers for LiquidityAmounts
///
function getAmountsForLiquidity(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) external pure returns (uint256 amount0, uint256 amount1);
function estimateAmount0(uint256 amount1, address pool, uint160 sqrtRatioX96, int24 tickLow, int24 tickHigh)
external
view
returns (uint256 amount0);
function estimateAmount1(uint256 amount0, address pool, uint160 sqrtRatioX96, int24 tickLow, int24 tickHigh)
external
view
returns (uint256 amount1);
///
/// Wrappers for PositionValue
///
function principal(INonfungiblePositionManager positionManager, uint256 tokenId, uint160 sqrtRatioX96)
external
view
returns (uint256 amount0, uint256 amount1);
function fees(INonfungiblePositionManager positionManager, uint256 tokenId)
external
view
returns (uint256 amount0, uint256 amount1);
///
/// Wrappers for TickMath
///
function getSqrtRatioAtTick(int24 tick) external pure returns (uint160 sqrtRatioX96);
function getTickAtSqrtRatio(uint160 sqrtRatioX96) external pure returns (int24 tick);
///
/// TickLens Helper
///
function getPopulatedTicks(address pool, int24 startTick)
external
view
returns (PopulatedTick[] memory populatedTicks);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import "contracts/core/libraries/FullMath.sol";
import "contracts/core/libraries/FixedPoint96.sol";
/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
/// @notice Downcasts uint256 to uint128
/// @param x The uint258 to be downcasted
/// @return y The passed value, downcasted to uint128
function toUint128(uint256 x) private pure returns (uint128 y) {
require((y = uint128(x)) == x);
}
/// @notice Computes the amount of liquidity received for a given amount of token0 and price range
/// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount0 The amount0 being sent in
/// @return liquidity The amount of returned liquidity
function getLiquidityForAmount0(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0)
internal
pure
returns (uint128 liquidity)
{
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);
return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96));
}
/// @notice Computes the amount of liquidity received for a given amount of token1 and price range
/// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount1 The amount1 being sent in
/// @return liquidity The amount of returned liquidity
function getLiquidityForAmount1(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount1)
internal
pure
returns (uint128 liquidity)
{
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96));
}
/// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
/// pool prices and the prices at the tick boundaries
/// @param sqrtRatioX96 A sqrt price representing the current pool prices
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param amount0 The amount of token0 being sent in
/// @param amount1 The amount of token1 being sent in
/// @return liquidity The maximum amount of liquidity received
function getLiquidityForAmounts(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint256 amount0,
uint256 amount1
) internal pure returns (uint128 liquidity) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioX96 <= sqrtRatioAX96) {
liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
} else if (sqrtRatioX96 < sqrtRatioBX96) {
uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);
liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
} else {
liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);
}
}
/// @notice Computes the amount of token0 for a given amount of liquidity and a price range
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount0 The amount of token0
function getAmount0ForLiquidity(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity)
internal
pure
returns (uint256 amount0)
{
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
return FullMath.mulDiv(
uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96 - sqrtRatioAX96, sqrtRatioBX96
) / sqrtRatioAX96;
}
/// @notice Computes the amount of token1 for a given amount of liquidity and a price range
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount1 The amount of token1
function getAmount1ForLiquidity(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity)
internal
pure
returns (uint256 amount1)
{
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
}
/// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
/// pool prices and the prices at the tick boundaries
/// @param sqrtRatioX96 A sqrt price representing the current pool prices
/// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
/// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
/// @param liquidity The liquidity being valued
/// @return amount0 The amount of token0
/// @return amount1 The amount of token1
function getAmountsForLiquidity(
uint160 sqrtRatioX96,
uint160 sqrtRatioAX96,
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 amount0, uint256 amount1) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioX96 <= sqrtRatioAX96) {
amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
} else if (sqrtRatioX96 < sqrtRatioBX96) {
amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity);
amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity);
} else {
amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import "contracts/core/interfaces/ICLFactory.sol";
import "@openzeppelin/contracts/proxy/Clones.sol";
/// @title Provides functions for deriving a pool address from the factory, tokens, and the fee
library PoolAddress {
/// @notice The identifying key of the pool
struct PoolKey {
address token0;
address token1;
int24 tickSpacing;
}
/// @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 tickSpacing The tick spacing of the pool
/// @return Poolkey The pool details with ordered token0 and token1 assignments
function getPoolKey(address tokenA, address tokenB, int24 tickSpacing) internal pure returns (PoolKey memory) {
if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
return PoolKey({token0: tokenA, token1: tokenB, tickSpacing: tickSpacing});
}
/// @notice Deterministically computes the pool address given the factory and PoolKey
/// @param factory The CL factory contract address
/// @param key The PoolKey
/// @return pool The contract address of the V3 pool
function computeAddress(address factory, PoolKey memory key) internal view returns (address pool) {
require(key.token0 < key.token1);
pool = Clones.predictDeterministicAddress({
master: ICLFactory(factory).poolImplementation(),
salt: keccak256(abi.encode(key.token0, key.token1, key.tickSpacing)),
deployer: factory
});
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
library PositionKey {
/// @dev Returns the key of the position in the core library
function compute(address owner, int24 tickLower, int24 tickUpper) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(owner, tickLower, tickUpper));
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.8 <0.8.0;
import "contracts/core/interfaces/ICLPool.sol";
import "contracts/core/libraries/FixedPoint128.sol";
import "contracts/core/libraries/TickMath.sol";
import "contracts/core/libraries/Tick.sol";
import "../interfaces/INonfungiblePositionManager.sol";
import "./LiquidityAmounts.sol";
import "./PoolAddress.sol";
import "./PositionKey.sol";
/// @title Returns information about the token value held in a CL NFT
library PositionValue {
/// @notice Returns the total amounts of token0 and token1, i.e. the sum of fees and principal
/// that a given nonfungible position manager token is worth
/// @param positionManager The CL NonfungiblePositionManager
/// @param tokenId The tokenId of the token for which to get the total value
/// @param sqrtRatioX96 The square root price X96 for which to calculate the principal amounts
/// @return amount0 The total amount of token0 including principal and fees
/// @return amount1 The total amount of token1 including principal and fees
function total(INonfungiblePositionManager positionManager, uint256 tokenId, uint160 sqrtRatioX96)
internal
view
returns (uint256 amount0, uint256 amount1)
{
(uint256 amount0Principal, uint256 amount1Principal) = principal(positionManager, tokenId, sqrtRatioX96);
(uint256 amount0Fee, uint256 amount1Fee) = fees(positionManager, tokenId);
return (amount0Principal + amount0Fee, amount1Principal + amount1Fee);
}
/// @notice Calculates the principal (currently acting as liquidity) owed to the token owner in the event
/// that the position is burned
/// @param positionManager The CL NonfungiblePositionManager
/// @param tokenId The tokenId of the token for which to get the total principal owed
/// @param sqrtRatioX96 The square root price X96 for which to calculate the principal amounts
/// @return amount0 The principal amount of token0
/// @return amount1 The principal amount of token1
function principal(INonfungiblePositionManager positionManager, uint256 tokenId, uint160 sqrtRatioX96)
internal
view
returns (uint256 amount0, uint256 amount1)
{
(,,,,, int24 tickLower, int24 tickUpper, uint128 liquidity,,,,) = positionManager.positions(tokenId);
return LiquidityAmounts.getAmountsForLiquidity(
sqrtRatioX96, TickMath.getSqrtRatioAtTick(tickLower), TickMath.getSqrtRatioAtTick(tickUpper), liquidity
);
}
struct FeeParams {
address token0;
address token1;
int24 tickSpacing;
int24 tickLower;
int24 tickUpper;
uint128 liquidity;
uint256 positionFeeGrowthInside0LastX128;
uint256 positionFeeGrowthInside1LastX128;
uint256 tokensOwed0;
uint256 tokensOwed1;
}
/// @notice Calculates the total fees owed to the token owner
/// @param positionManager The CL NonfungiblePositionManager
/// @param tokenId The tokenId of the token for which to get the total fees owed
/// @return amount0 The amount of fees owed in token0
/// @return amount1 The amount of fees owed in token1
function fees(INonfungiblePositionManager positionManager, uint256 tokenId)
internal
view
returns (uint256 amount0, uint256 amount1)
{
(
,
,
address token0,
address token1,
int24 tickSpacing,
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
uint256 positionFeeGrowthInside0LastX128,
uint256 positionFeeGrowthInside1LastX128,
uint256 tokensOwed0,
uint256 tokensOwed1
) = positionManager.positions(tokenId);
return _fees(
positionManager,
FeeParams({
token0: token0,
token1: token1,
tickSpacing: tickSpacing,
tickLower: tickLower,
tickUpper: tickUpper,
liquidity: liquidity,
positionFeeGrowthInside0LastX128: positionFeeGrowthInside0LastX128,
positionFeeGrowthInside1LastX128: positionFeeGrowthInside1LastX128,
tokensOwed0: tokensOwed0,
tokensOwed1: tokensOwed1
})
);
}
function _fees(INonfungiblePositionManager positionManager, FeeParams memory feeParams)
private
view
returns (uint256 amount0, uint256 amount1)
{
(uint256 poolFeeGrowthInside0LastX128, uint256 poolFeeGrowthInside1LastX128) = _getFeeGrowthInside(
ICLPool(
PoolAddress.computeAddress(
positionManager.factory(),
PoolAddress.PoolKey({
token0: feeParams.token0,
token1: feeParams.token1,
tickSpacing: feeParams.tickSpacing
})
)
),
feeParams.tickLower,
feeParams.tickUpper
);
amount0 = FullMath.mulDiv(
poolFeeGrowthInside0LastX128 - feeParams.positionFeeGrowthInside0LastX128,
feeParams.liquidity,
FixedPoint128.Q128
) + feeParams.tokensOwed0;
amount1 = FullMath.mulDiv(
poolFeeGrowthInside1LastX128 - feeParams.positionFeeGrowthInside1LastX128,
feeParams.liquidity,
FixedPoint128.Q128
) + feeParams.tokensOwed1;
}
function _getFeeGrowthInside(ICLPool pool, int24 tickLower, int24 tickUpper)
private
view
returns (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128)
{
(, int24 tickCurrent,,,,) = pool.slot0();
(,,, uint256 lowerFeeGrowthOutside0X128, uint256 lowerFeeGrowthOutside1X128,,,,,) = pool.ticks(tickLower);
(,,, uint256 upperFeeGrowthOutside0X128, uint256 upperFeeGrowthOutside1X128,,,,,) = pool.ticks(tickUpper);
if (tickCurrent < tickLower) {
feeGrowthInside0X128 = lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;
feeGrowthInside1X128 = lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;
} else if (tickCurrent < tickUpper) {
uint256 feeGrowthGlobal0X128 = pool.feeGrowthGlobal0X128();
uint256 feeGrowthGlobal1X128 = pool.feeGrowthGlobal1X128();
feeGrowthInside0X128 = feeGrowthGlobal0X128 - lowerFeeGrowthOutside0X128 - upperFeeGrowthOutside0X128;
feeGrowthInside1X128 = feeGrowthGlobal1X128 - lowerFeeGrowthOutside1X128 - upperFeeGrowthOutside1X128;
} else {
feeGrowthInside0X128 = upperFeeGrowthOutside0X128 - lowerFeeGrowthOutside0X128;
feeGrowthInside1X128 = upperFeeGrowthOutside1X128 - lowerFeeGrowthOutside1X128;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow, so we distribute
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.8.0;
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*
* _Available since v3.4._
*/
library Clones {
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `master`.
*
* This function uses the create opcode, which should never revert.
*/
function clone(address master) internal returns (address instance) {
// solhint-disable-next-line no-inline-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, master))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create(0, ptr, 0x37)
}
require(instance != address(0), "ERC1167: create failed");
}
/**
* @dev Deploys and returns the address of a clone that mimics the behaviour of `master`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `master` and `salt` multiple time will revert, since
* the clones cannot be deployed twice at the same address.
*/
function cloneDeterministic(address master, bytes32 salt) internal returns (address instance) {
// solhint-disable-next-line no-inline-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, master))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
instance := create2(0, ptr, 0x37, salt)
}
require(instance != address(0), "ERC1167: create2 failed");
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(address master, bytes32 salt, address deployer) internal pure returns (address predicted) {
// solhint-disable-next-line no-inline-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(add(ptr, 0x14), shl(0x60, master))
mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)
mstore(add(ptr, 0x38), shl(0x60, deployer))
mstore(add(ptr, 0x4c), salt)
mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))
predicted := keccak256(add(ptr, 0x37), 0x55)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(address master, bytes32 salt) internal view returns (address predicted) {
return predictDeterministicAddress(master, salt, address(this));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../../introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": [
"@nomad-xyz/=lib/ExcessivelySafeCall/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@uniswap/=lib/solidity-lib/",
"ExcessivelySafeCall/=lib/ExcessivelySafeCall/src/",
"base64-sol/=lib/base64/",
"base64/=lib/base64/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
"solidity-lib/=lib/solidity-lib/contracts/"
],
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint160","name":"sqrtRatioX96","type":"uint160"},{"internalType":"int24","name":"tickLow","type":"int24"},{"internalType":"int24","name":"tickHigh","type":"int24"}],"name":"estimateAmount0","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint160","name":"sqrtRatioX96","type":"uint160"},{"internalType":"int24","name":"tickLow","type":"int24"},{"internalType":"int24","name":"tickHigh","type":"int24"}],"name":"estimateAmount1","outputs":[{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"positionManager","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"fees","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtRatioAX96","type":"uint160"},{"internalType":"uint160","name":"sqrtRatioBX96","type":"uint160"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"bool","name":"roundUp","type":"bool"}],"name":"getAmount0Delta","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtRatioAX96","type":"uint160"},{"internalType":"uint160","name":"sqrtRatioBX96","type":"uint160"},{"internalType":"int128","name":"liquidity","type":"int128"}],"name":"getAmount0Delta","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtRatioAX96","type":"uint160"},{"internalType":"uint160","name":"sqrtRatioBX96","type":"uint160"},{"internalType":"int128","name":"liquidity","type":"int128"}],"name":"getAmount1Delta","outputs":[{"internalType":"int256","name":"","type":"int256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtRatioAX96","type":"uint160"},{"internalType":"uint160","name":"sqrtRatioBX96","type":"uint160"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"bool","name":"roundUp","type":"bool"}],"name":"getAmount1Delta","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtRatioX96","type":"uint160"},{"internalType":"uint160","name":"sqrtRatioAX96","type":"uint160"},{"internalType":"uint160","name":"sqrtRatioBX96","type":"uint160"},{"internalType":"uint128","name":"liquidity","type":"uint128"}],"name":"getAmountsForLiquidity","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint160","name":"sqrtRatioX96","type":"uint160"},{"internalType":"uint160","name":"sqrtRatioAX96","type":"uint160"},{"internalType":"uint160","name":"sqrtRatioBX96","type":"uint160"}],"name":"getLiquidityForAmounts","outputs":[{"internalType":"uint256","name":"liquidity","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"int24","name":"startTick","type":"int24"}],"name":"getPopulatedTicks","outputs":[{"components":[{"internalType":"int24","name":"tick","type":"int24"},{"internalType":"uint160","name":"sqrtRatioX96","type":"uint160"},{"internalType":"int128","name":"liquidityNet","type":"int128"},{"internalType":"uint128","name":"liquidityGross","type":"uint128"}],"internalType":"struct ISugarHelper.PopulatedTick[]","name":"populatedTicks","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"tick","type":"int24"}],"name":"getSqrtRatioAtTick","outputs":[{"internalType":"uint160","name":"sqrtRatioX96","type":"uint160"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"name":"getTickAtSqrtRatio","outputs":[{"internalType":"int24","name":"tick","type":"int24"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"int24","name":"tickCurrent","type":"int24"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"}],"name":"poolFees","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"positionManager","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint160","name":"sqrtRatioX96","type":"uint160"}],"name":"principal","outputs":[{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"}],"stateMutability":"view","type":"function"}]Contract Creation Code
608060405234801561001057600080fd5b5061245d806100206000396000f3fe608060405234801561001057600080fd5b50600436106100e95760003560e01c80634f76c0581161008c578063c72e160b11610066578063c72e160b146101ea578063c932699b146101fd578063e5f46fac14610210578063fe07023d14610223576100e9565b80634f76c05814610197578063986cfba3146101b7578063bafcf68e146101d7576100e9565b8063255d36ef116100c8578063255d36ef1461014b578063263a53621461015e5780632c32d4b61461017157806348a0c5bd14610184576100e9565b8062c11862146100ee5780630556496414610117578063226353971461012a575b600080fd5b6101016100fc3660046121a9565b610243565b60405161010e91906123cc565b60405180910390f35b6101016101253660046122ab565b61025a565b61013d610138366004611fd5565b610389565b60405161010e9291906123e9565b61013d610159366004611f3a565b6103a3565b61013d61016c366004611faa565b610636565b61010161017f3660046121e8565b61064e565b6101016101923660046121e8565b61065c565b6101aa6101a5366004612111565b61066a565b60405161010e91906123be565b6101ca6101c5366004612016565b61067d565b60405161010e91906123d5565b6101016101e53660046122e4565b610688565b61013d6101f8366004612243565b6106aa565b61010161020b3660046121a9565b6106c7565b61010161021e3660046122ab565b6106d4565b610236610231366004611f02565b6107f4565b60405161010e9190612334565b6000610250848484610b55565b90505b9392505050565b60008061026684610b99565b9050600061027384610b99565b9050806001600160a01b0316826001600160a01b0316111561029157905b816001600160a01b0316866001600160a01b0316111580156102c55750806001600160a01b0316866001600160a01b031610155b156102d557600092505050610380565b6001600160a01b0387161561035e57866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160c06040518083038186803b15801561031d57600080fd5b505afa158015610331573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610355919061212d565b50939950505050505b600061036b87838b610ecb565b905061037a8388836000610f2e565b93505050505b95945050505050565b600080610397858585610f9e565b91509150935093915050565b600080600080886001600160a01b031663f30dba93876040518263ffffffff1660e01b81526004016103d591906123be565b6101406040518083038186803b1580156103ee57600080fd5b505afa158015610402573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610426919061204e565b5050505050945094505050506000808a6001600160a01b031663f30dba93886040518263ffffffff1660e01b815260040161046191906123be565b6101406040518083038186803b15801561047a57600080fd5b505afa15801561048e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104b2919061204e565b5050505050945094505050506000808960020b8b60020b12156104dc5750508184038184036105f2565b8860020b8b60020b12156105e95760008d6001600160a01b031663f30583996040518163ffffffff1660e01b815260040160206040518083038186803b15801561052557600080fd5b505afa158015610539573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061055d9190612293565b905060008e6001600160a01b031663461413196040518163ffffffff1660e01b815260040160206040518083038186803b15801561059a57600080fd5b505afa1580156105ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d29190612293565b9050858883030393508487820303925050506105f2565b50508382038382035b61060a828d6001600160801b0316600160801b61105a565b9750610624818d6001600160801b0316600160801b61105a565b96505050505050509550959350505050565b6000806106438484611109565b915091509250929050565b6000610380858585856112ba565b600061038085858585610f2e565b60006106758261136e565b90505b919050565b600061067582610b99565b6000610697848484898961168d565b6001600160801b03169695505050505050565b6000806106b98686868661174f565b915091505b94509492505050565b60006102508484846117ea565b6000806106e084610b99565b905060006106ed84610b99565b9050806001600160a01b0316826001600160a01b0316111561070b57905b816001600160a01b0316866001600160a01b03161115801561073f5750806001600160a01b0316866001600160a01b031610155b1561074f57600092505050610380565b6001600160a01b038716156107d857866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160c06040518083038186803b15801561079757600080fd5b505afa1580156107ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107cf919061212d565b50939950505050505b60006107e583888b611819565b905061037a87838360006112ba565b60606000836001600160a01b031663d0c93a7c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561083157600080fd5b505afa158015610845573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108699190612032565b9050600060088260020b8560020b8161087e57fe5b0560020b901d9050600061089d600583617fff0360010b600101611856565b905060008060008367ffffffffffffffff811180156108bb57600080fd5b506040519080825280602002602001820160405280156108e5578160200160208202803683370190505b50905060005b848110156109a05760405163299ce14b60e11b81526001600160a01b038b1690635339c2969061092190898501906004016123b0565b60206040518083038186803b15801561093957600080fd5b505afa15801561094d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109719190612293565b935061097c8461186c565b830192508382828151811061098d57fe5b60209081029190910101526001016108eb565b508167ffffffffffffffff811180156109b857600080fd5b506040519080825280602002602001820160405280156109f257816020015b6109df611ebe565b8152602001906001900390816109d75790505b50965060008060005b86811015610b4657838181518110610a0f57fe5b6020026020010151955080880160010b915060005b610100811015610b3d576001811b871615610b3557898160088560020b901b010293506000808e6001600160a01b031663f30dba93876040518263ffffffff1660e01b8152600401610a7691906123be565b6101406040518083038186803b158015610a8f57600080fd5b505afa158015610aa3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac7919061204e565b50505050505050509150915060405180608001604052808760020b8152602001610af088610b99565b6001600160a01b0316815260200182600f0b8152602001836001600160801b03168152508d896001900399508981518110610b2757fe5b602002602001018190525050505b600101610a24565b506001016109fb565b50505050505050505092915050565b60008082600f0b12610b7b57610b76610b718585856001610f2e565b611886565b610250565b610b8e610b718585856000036000610f2e565b600003949350505050565b60008060008360020b12610bb0578260020b610bb8565b8260020b6000035b9050620d89e8811115610bf6576040805162461bcd60e51b81526020600482015260016024820152601560fa1b604482015290519081900360640190fd5b600060018216610c0a57600160801b610c1c565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615610c50576ffff97272373d413259a46990580e213a0260801c5b6004821615610c6f576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615610c8e576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615610cad576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615610ccc576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615610ceb576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615610d0a576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615610d2a576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615610d4a576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615610d6a576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615610d8a576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615610daa576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615610dca576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615610dea576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615610e0a576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615610e2b576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615610e4b576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615610e6a576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615610e87576b048a170391f7dc42444e8fa20260801c5b60008460020b1315610ea2578060001981610e9e57fe5b0490505b640100000000810615610eb6576001610eb9565b60005b60ff16602082901c0192505050919050565b6000826001600160a01b0316846001600160a01b03161115610eeb579192915b6000610f0e856001600160a01b0316856001600160a01b0316600160601b61105a565b9050610380610f2984838888036001600160a01b031661105a565b61189c565b6000836001600160a01b0316856001600160a01b03161115610f4e579293925b81610f7b57610f76836001600160801b03168686036001600160a01b0316600160601b61105a565b610380565b610380836001600160801b03168686036001600160a01b0316600160601b6118b2565b6000806000806000876001600160a01b03166399fbab88886040518263ffffffff1660e01b8152600401808281526020019150506101806040518083038186803b158015610feb57600080fd5b505afa158015610fff573d6000803e3d6000fd5b505050506040513d61018081101561101657600080fd5b5060a081015160c082015160e090920151909450909250905061104b8661103c85610b99565b61104585610b99565b8461174f565b94509450505050935093915050565b6000808060001985870986860292508281109083900303905080611090576000841161108557600080fd5b508290049050610253565b80841161109c57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000806000806000806000806000806000808d6001600160a01b03166399fbab888e6040518263ffffffff1660e01b8152600401808281526020019150506101806040518083038186803b15801561116057600080fd5b505afa158015611174573d6000803e3d6000fd5b505050506040513d61018081101561118b57600080fd5b810190808051906020019092919080519060200190929190805190602001909291908051906020019092919080519060200190929190805190602001909291908051906020019092919080519060200190929190805190602001909291908051906020019092919080519060200190929190805190602001909291905050506001600160801b03169b506001600160801b03169b509b509b509b509b509b509b509b509b5050506112a58e6040518061014001604052808d6001600160a01b031681526020018c6001600160a01b031681526020018b60020b81526020018a60020b81526020018960020b8152602001886001600160801b03168152602001878152602001868152602001858152602001848152506118ec565b9b509b50505050505050505050509250929050565b6000836001600160a01b0316856001600160a01b031611156112da579293925b6fffffffffffffffffffffffffffffffff60601b606084901b166001600160a01b03868603811690871661130d57600080fd5b8361133d57866001600160a01b03166113308383896001600160a01b031661105a565b8161133757fe5b04611363565b6113636113548383896001600160a01b03166118b2565b886001600160a01b0316611a08565b979650505050505050565b60006401000276a36001600160a01b038316108015906113aa575073fffd8963efd1fc6a506488495d951d5263988d266001600160a01b038316105b6113df576040805162461bcd60e51b81526020600482015260016024820152602960f91b604482015290519081900360640190fd5b640100000000600160c01b03602083901b166001600160801b03811160071b81811c67ffffffffffffffff811160061b90811c63ffffffff811160051b90811c61ffff811160041b90811c60ff8111600390811b91821c600f811160021b90811c918211600190811b92831c9790881196179094179092171790911717176080811061147357607f810383901c915061147d565b80607f0383901b91505b908002607f81811c60ff83811c9190911c800280831c81831c1c800280841c81841c1c800280851c81851c1c800280861c81861c1c800280871c81871c1c800280881c81881c1c800280891c81891c1c8002808a1c818a1c1c8002808b1c818b1c1c8002808c1c818c1c1c8002808d1c818d1c1c8002808e1c9c81901c9c909c1c80029c8d901c9e9d607f198f0160401b60c09190911c678000000000000000161760c19b909b1c674000000000000000169a909a1760c29990991c672000000000000000169890981760c39790971c671000000000000000169690961760c49590951c670800000000000000169490941760c59390931c670400000000000000169290921760c69190911c670200000000000000161760c79190911c670100000000000000161760c89190911c6680000000000000161760c99190911c6640000000000000161760ca9190911c6620000000000000161760cb9190911c6610000000000000161760cc9190911c6608000000000000161760cd9190911c66040000000000001617693627a301d71055774c8581026f028f6481ab7f045a5af012a19d003aa9198101608090811d906fdb2df09e81959a81455e260799a0632f8301901d600281810b9083900b1461167e57886001600160a01b031661166282610b99565b6001600160a01b031611156116775781611679565b805b611680565b815b9998505050505050505050565b6000836001600160a01b0316856001600160a01b031611156116ad579293925b846001600160a01b0316866001600160a01b0316116116d8576116d1858585610ecb565b9050610380565b836001600160a01b0316866001600160a01b0316101561173a5760006116ff878686610ecb565b9050600061170e878986611819565b9050806001600160801b0316826001600160801b03161061172f5780611731565b815b92505050610380565b611745858584611819565b9695505050505050565b600080836001600160a01b0316856001600160a01b03161115611770579293925b846001600160a01b0316866001600160a01b03161161179b57611794858585611a13565b91506106be565b836001600160a01b0316866001600160a01b031610156117d4576117c0868585611a13565b91506117cd858785611a7c565b90506106be565b6117df858585611a7c565b905094509492505050565b60008082600f0b1261180657610b76610b7185858560016112ba565b610b8e610b7185858560000360006112ba565b6000826001600160a01b0316846001600160a01b03161115611839579192915b610250610f2983600160601b8787036001600160a01b031661105a565b60008183106118655781610253565b5090919050565b60005b81156106785760001982019091169060010161186f565b6000600160ff1b821061189857600080fd5b5090565b806001600160801b038116811461067857600080fd5b60006118bf84848461105a565b9050600082806118cb57fe5b84860911156102535760001981106118e257600080fd5b6001019392505050565b6000806000806119a5611996876001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b15801561193157600080fd5b505afa158015611945573d6000803e3d6000fd5b505050506040513d602081101561195b57600080fd5b50516040805160608101825289516001600160a01b03908116825260208b810151909116908201528982015160020b91810191909152611abf565b86606001518760800151611ba1565b915091508461010001516119d18660c0015184038760a001516001600160801b0316600160801b61105a565b0193508461012001516119fc8660e0015183038760a001516001600160801b0316600160801b61105a565b01925050509250929050565b808204910615150190565b6000826001600160a01b0316846001600160a01b03161115611a33579192915b836001600160a01b0316611a6c606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b031661105a565b81611a7357fe5b04949350505050565b6000826001600160a01b0316846001600160a01b03161115611a9c579192915b610250826001600160801b03168585036001600160a01b0316600160601b61105a565b600081602001516001600160a01b031682600001516001600160a01b031610611ae757600080fd5b610253836001600160a01b031663cefa77996040518163ffffffff1660e01b815260040160206040518083038186803b158015611b2357600080fd5b505afa158015611b37573d6000803e3d6000fd5b505050506040513d6020811015611b4d57600080fd5b5051835160208581015160408088015181516001600160a01b0395861681860152949092168482015260029190910b6060808501919091528151808503909101815260809093019052815191012085611e60565b6000806000856001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160c06040518083038186803b158015611bdf57600080fd5b505afa158015611bf3573d6000803e3d6000fd5b505050506040513d60c0811015611c0957600080fd5b50602001516040805163f30dba9360e01b8152600288900b6004820152905191925060009182916001600160a01b038a169163f30dba939160248082019261014092909190829003018186803b158015611c6257600080fd5b505afa158015611c76573d6000803e3d6000fd5b505050506040513d610140811015611c8d57600080fd5b5060608101516080909101516040805163f30dba9360e01b815260028a900b6004820152905192945090925060009182916001600160a01b038c169163f30dba939160248082019261014092909190829003018186803b158015611cf057600080fd5b505afa158015611d04573d6000803e3d6000fd5b505050506040513d610140811015611d1b57600080fd5b5060608101516080909101519092509050600289810b9086900b1215611d4a5781840396508083039550611e53565b8760020b8560020b1215611e485760008a6001600160a01b031663f30583996040518163ffffffff1660e01b815260040160206040518083038186803b158015611d9357600080fd5b505afa158015611da7573d6000803e3d6000fd5b505050506040513d6020811015611dbd57600080fd5b505160408051634614131960e01b815290519192506000916001600160a01b038e16916346141319916004808301926020929190829003018186803b158015611e0557600080fd5b505afa158015611e19573d6000803e3d6000fd5b505050506040513d6020811015611e2f57600080fd5b5051918690038490039850508390038190039550611e53565b838203965082810395505b5050505050935093915050565b604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b8152606093841b60148201526f5af43d82803e903d91602b57fd5bf3ff60801b6028820152921b6038830152604c8201526037808220606c830152605591012090565b60408051608081018252600080825260208201819052918101829052606081019190915290565b80516106788161240f565b805161ffff8116811461067857600080fd5b60008060408385031215611f14578182fd5b8235611f1f816123f7565b91506020830135611f2f8161242c565b809150509250929050565b600080600080600060a08688031215611f51578081fd5b8535611f5c816123f7565b94506020860135611f6c8161243b565b93506040860135611f7c8161242c565b92506060860135611f8c8161242c565b91506080860135611f9c8161242c565b809150509295509295909350565b60008060408385031215611fbc578182fd5b8235611fc7816123f7565b946020939093013593505050565b600080600060608486031215611fe9578283fd5b8335611ff4816123f7565b925060208401359150604084013561200b816123f7565b809150509250925092565b600060208284031215612027578081fd5b81356102538161242c565b600060208284031215612043578081fd5b81516102538161242c565b6000806000806000806000806000806101408b8d03121561206d578485fd5b8a516120788161243b565b60208c0151909a506120898161241d565b60408c015190995061209a8161241d565b8098505060608b0151965060808b0151955060a08b0151945060c08b01518060060b81146120c6578485fd5b60e08c01519094506120d7816123f7565b6101008c015190935063ffffffff811681146120f1578283fd5b91506121006101208c01611ee5565b90509295989b9194979a5092959850565b600060208284031215612122578081fd5b8135610253816123f7565b60008060008060008060c08789031215612145578384fd5b8651612150816123f7565b60208801519096506121618161242c565b945061216f60408801611ef0565b935061217d60608801611ef0565b925061218b60808801611ef0565b915060a087015161219b8161240f565b809150509295509295509295565b6000806000606084860312156121bd578081fd5b83356121c8816123f7565b925060208401356121d8816123f7565b9150604084013561200b8161241d565b600080600080608085870312156121fd578182fd5b8435612208816123f7565b93506020850135612218816123f7565b925060408501356122288161243b565b915060608501356122388161240f565b939692955090935050565b60008060008060808587031215612258578182fd5b8435612263816123f7565b93506020850135612273816123f7565b92506040850135612283816123f7565b915060608501356122388161243b565b6000602082840312156122a4578081fd5b5051919050565b600080600080600060a086880312156122c2578283fd5b8535945060208601356122d4816123f7565b93506040860135611f7c816123f7565b600080600080600060a086880312156122fb578283fd5b85359450602086013593506040860135612314816123f7565b92506060860135612324816123f7565b91506080860135611f9c816123f7565b602080825282518282018190526000919060409081850190868401855b828110156123a3578151805160020b8552868101516001600160a01b03168786015285810151600f0b868601526060908101516001600160801b03169085015260809093019290850190600101612351565b5091979650505050505050565b60019190910b815260200190565b60029190910b815260200190565b90815260200190565b6001600160a01b0391909116815260200190565b918252602082015260400190565b6001600160a01b038116811461240c57600080fd5b50565b801515811461240c57600080fd5b80600f0b811461240c57600080fd5b8060020b811461240c57600080fd5b6001600160801b038116811461240c57600080fdfea164736f6c6343000706000a
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100e95760003560e01c80634f76c0581161008c578063c72e160b11610066578063c72e160b146101ea578063c932699b146101fd578063e5f46fac14610210578063fe07023d14610223576100e9565b80634f76c05814610197578063986cfba3146101b7578063bafcf68e146101d7576100e9565b8063255d36ef116100c8578063255d36ef1461014b578063263a53621461015e5780632c32d4b61461017157806348a0c5bd14610184576100e9565b8062c11862146100ee5780630556496414610117578063226353971461012a575b600080fd5b6101016100fc3660046121a9565b610243565b60405161010e91906123cc565b60405180910390f35b6101016101253660046122ab565b61025a565b61013d610138366004611fd5565b610389565b60405161010e9291906123e9565b61013d610159366004611f3a565b6103a3565b61013d61016c366004611faa565b610636565b61010161017f3660046121e8565b61064e565b6101016101923660046121e8565b61065c565b6101aa6101a5366004612111565b61066a565b60405161010e91906123be565b6101ca6101c5366004612016565b61067d565b60405161010e91906123d5565b6101016101e53660046122e4565b610688565b61013d6101f8366004612243565b6106aa565b61010161020b3660046121a9565b6106c7565b61010161021e3660046122ab565b6106d4565b610236610231366004611f02565b6107f4565b60405161010e9190612334565b6000610250848484610b55565b90505b9392505050565b60008061026684610b99565b9050600061027384610b99565b9050806001600160a01b0316826001600160a01b0316111561029157905b816001600160a01b0316866001600160a01b0316111580156102c55750806001600160a01b0316866001600160a01b031610155b156102d557600092505050610380565b6001600160a01b0387161561035e57866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160c06040518083038186803b15801561031d57600080fd5b505afa158015610331573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610355919061212d565b50939950505050505b600061036b87838b610ecb565b905061037a8388836000610f2e565b93505050505b95945050505050565b600080610397858585610f9e565b91509150935093915050565b600080600080886001600160a01b031663f30dba93876040518263ffffffff1660e01b81526004016103d591906123be565b6101406040518083038186803b1580156103ee57600080fd5b505afa158015610402573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610426919061204e565b5050505050945094505050506000808a6001600160a01b031663f30dba93886040518263ffffffff1660e01b815260040161046191906123be565b6101406040518083038186803b15801561047a57600080fd5b505afa15801561048e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104b2919061204e565b5050505050945094505050506000808960020b8b60020b12156104dc5750508184038184036105f2565b8860020b8b60020b12156105e95760008d6001600160a01b031663f30583996040518163ffffffff1660e01b815260040160206040518083038186803b15801561052557600080fd5b505afa158015610539573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061055d9190612293565b905060008e6001600160a01b031663461413196040518163ffffffff1660e01b815260040160206040518083038186803b15801561059a57600080fd5b505afa1580156105ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d29190612293565b9050858883030393508487820303925050506105f2565b50508382038382035b61060a828d6001600160801b0316600160801b61105a565b9750610624818d6001600160801b0316600160801b61105a565b96505050505050509550959350505050565b6000806106438484611109565b915091509250929050565b6000610380858585856112ba565b600061038085858585610f2e565b60006106758261136e565b90505b919050565b600061067582610b99565b6000610697848484898961168d565b6001600160801b03169695505050505050565b6000806106b98686868661174f565b915091505b94509492505050565b60006102508484846117ea565b6000806106e084610b99565b905060006106ed84610b99565b9050806001600160a01b0316826001600160a01b0316111561070b57905b816001600160a01b0316866001600160a01b03161115801561073f5750806001600160a01b0316866001600160a01b031610155b1561074f57600092505050610380565b6001600160a01b038716156107d857866001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160c06040518083038186803b15801561079757600080fd5b505afa1580156107ab573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107cf919061212d565b50939950505050505b60006107e583888b611819565b905061037a87838360006112ba565b60606000836001600160a01b031663d0c93a7c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561083157600080fd5b505afa158015610845573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108699190612032565b9050600060088260020b8560020b8161087e57fe5b0560020b901d9050600061089d600583617fff0360010b600101611856565b905060008060008367ffffffffffffffff811180156108bb57600080fd5b506040519080825280602002602001820160405280156108e5578160200160208202803683370190505b50905060005b848110156109a05760405163299ce14b60e11b81526001600160a01b038b1690635339c2969061092190898501906004016123b0565b60206040518083038186803b15801561093957600080fd5b505afa15801561094d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109719190612293565b935061097c8461186c565b830192508382828151811061098d57fe5b60209081029190910101526001016108eb565b508167ffffffffffffffff811180156109b857600080fd5b506040519080825280602002602001820160405280156109f257816020015b6109df611ebe565b8152602001906001900390816109d75790505b50965060008060005b86811015610b4657838181518110610a0f57fe5b6020026020010151955080880160010b915060005b610100811015610b3d576001811b871615610b3557898160088560020b901b010293506000808e6001600160a01b031663f30dba93876040518263ffffffff1660e01b8152600401610a7691906123be565b6101406040518083038186803b158015610a8f57600080fd5b505afa158015610aa3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ac7919061204e565b50505050505050509150915060405180608001604052808760020b8152602001610af088610b99565b6001600160a01b0316815260200182600f0b8152602001836001600160801b03168152508d896001900399508981518110610b2757fe5b602002602001018190525050505b600101610a24565b506001016109fb565b50505050505050505092915050565b60008082600f0b12610b7b57610b76610b718585856001610f2e565b611886565b610250565b610b8e610b718585856000036000610f2e565b600003949350505050565b60008060008360020b12610bb0578260020b610bb8565b8260020b6000035b9050620d89e8811115610bf6576040805162461bcd60e51b81526020600482015260016024820152601560fa1b604482015290519081900360640190fd5b600060018216610c0a57600160801b610c1c565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615610c50576ffff97272373d413259a46990580e213a0260801c5b6004821615610c6f576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615610c8e576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615610cad576fffcb9843d60f6159c9db58835c9266440260801c5b6020821615610ccc576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615610ceb576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615610d0a576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615610d2a576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615610d4a576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615610d6a576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615610d8a576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615610daa576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615610dca576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615610dea576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615610e0a576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615610e2b576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615610e4b576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615610e6a576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615610e87576b048a170391f7dc42444e8fa20260801c5b60008460020b1315610ea2578060001981610e9e57fe5b0490505b640100000000810615610eb6576001610eb9565b60005b60ff16602082901c0192505050919050565b6000826001600160a01b0316846001600160a01b03161115610eeb579192915b6000610f0e856001600160a01b0316856001600160a01b0316600160601b61105a565b9050610380610f2984838888036001600160a01b031661105a565b61189c565b6000836001600160a01b0316856001600160a01b03161115610f4e579293925b81610f7b57610f76836001600160801b03168686036001600160a01b0316600160601b61105a565b610380565b610380836001600160801b03168686036001600160a01b0316600160601b6118b2565b6000806000806000876001600160a01b03166399fbab88886040518263ffffffff1660e01b8152600401808281526020019150506101806040518083038186803b158015610feb57600080fd5b505afa158015610fff573d6000803e3d6000fd5b505050506040513d61018081101561101657600080fd5b5060a081015160c082015160e090920151909450909250905061104b8661103c85610b99565b61104585610b99565b8461174f565b94509450505050935093915050565b6000808060001985870986860292508281109083900303905080611090576000841161108557600080fd5b508290049050610253565b80841161109c57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6000806000806000806000806000806000808d6001600160a01b03166399fbab888e6040518263ffffffff1660e01b8152600401808281526020019150506101806040518083038186803b15801561116057600080fd5b505afa158015611174573d6000803e3d6000fd5b505050506040513d61018081101561118b57600080fd5b810190808051906020019092919080519060200190929190805190602001909291908051906020019092919080519060200190929190805190602001909291908051906020019092919080519060200190929190805190602001909291908051906020019092919080519060200190929190805190602001909291905050506001600160801b03169b506001600160801b03169b509b509b509b509b509b509b509b509b5050506112a58e6040518061014001604052808d6001600160a01b031681526020018c6001600160a01b031681526020018b60020b81526020018a60020b81526020018960020b8152602001886001600160801b03168152602001878152602001868152602001858152602001848152506118ec565b9b509b50505050505050505050509250929050565b6000836001600160a01b0316856001600160a01b031611156112da579293925b6fffffffffffffffffffffffffffffffff60601b606084901b166001600160a01b03868603811690871661130d57600080fd5b8361133d57866001600160a01b03166113308383896001600160a01b031661105a565b8161133757fe5b04611363565b6113636113548383896001600160a01b03166118b2565b886001600160a01b0316611a08565b979650505050505050565b60006401000276a36001600160a01b038316108015906113aa575073fffd8963efd1fc6a506488495d951d5263988d266001600160a01b038316105b6113df576040805162461bcd60e51b81526020600482015260016024820152602960f91b604482015290519081900360640190fd5b640100000000600160c01b03602083901b166001600160801b03811160071b81811c67ffffffffffffffff811160061b90811c63ffffffff811160051b90811c61ffff811160041b90811c60ff8111600390811b91821c600f811160021b90811c918211600190811b92831c9790881196179094179092171790911717176080811061147357607f810383901c915061147d565b80607f0383901b91505b908002607f81811c60ff83811c9190911c800280831c81831c1c800280841c81841c1c800280851c81851c1c800280861c81861c1c800280871c81871c1c800280881c81881c1c800280891c81891c1c8002808a1c818a1c1c8002808b1c818b1c1c8002808c1c818c1c1c8002808d1c818d1c1c8002808e1c9c81901c9c909c1c80029c8d901c9e9d607f198f0160401b60c09190911c678000000000000000161760c19b909b1c674000000000000000169a909a1760c29990991c672000000000000000169890981760c39790971c671000000000000000169690961760c49590951c670800000000000000169490941760c59390931c670400000000000000169290921760c69190911c670200000000000000161760c79190911c670100000000000000161760c89190911c6680000000000000161760c99190911c6640000000000000161760ca9190911c6620000000000000161760cb9190911c6610000000000000161760cc9190911c6608000000000000161760cd9190911c66040000000000001617693627a301d71055774c8581026f028f6481ab7f045a5af012a19d003aa9198101608090811d906fdb2df09e81959a81455e260799a0632f8301901d600281810b9083900b1461167e57886001600160a01b031661166282610b99565b6001600160a01b031611156116775781611679565b805b611680565b815b9998505050505050505050565b6000836001600160a01b0316856001600160a01b031611156116ad579293925b846001600160a01b0316866001600160a01b0316116116d8576116d1858585610ecb565b9050610380565b836001600160a01b0316866001600160a01b0316101561173a5760006116ff878686610ecb565b9050600061170e878986611819565b9050806001600160801b0316826001600160801b03161061172f5780611731565b815b92505050610380565b611745858584611819565b9695505050505050565b600080836001600160a01b0316856001600160a01b03161115611770579293925b846001600160a01b0316866001600160a01b03161161179b57611794858585611a13565b91506106be565b836001600160a01b0316866001600160a01b031610156117d4576117c0868585611a13565b91506117cd858785611a7c565b90506106be565b6117df858585611a7c565b905094509492505050565b60008082600f0b1261180657610b76610b7185858560016112ba565b610b8e610b7185858560000360006112ba565b6000826001600160a01b0316846001600160a01b03161115611839579192915b610250610f2983600160601b8787036001600160a01b031661105a565b60008183106118655781610253565b5090919050565b60005b81156106785760001982019091169060010161186f565b6000600160ff1b821061189857600080fd5b5090565b806001600160801b038116811461067857600080fd5b60006118bf84848461105a565b9050600082806118cb57fe5b84860911156102535760001981106118e257600080fd5b6001019392505050565b6000806000806119a5611996876001600160a01b031663c45a01556040518163ffffffff1660e01b815260040160206040518083038186803b15801561193157600080fd5b505afa158015611945573d6000803e3d6000fd5b505050506040513d602081101561195b57600080fd5b50516040805160608101825289516001600160a01b03908116825260208b810151909116908201528982015160020b91810191909152611abf565b86606001518760800151611ba1565b915091508461010001516119d18660c0015184038760a001516001600160801b0316600160801b61105a565b0193508461012001516119fc8660e0015183038760a001516001600160801b0316600160801b61105a565b01925050509250929050565b808204910615150190565b6000826001600160a01b0316846001600160a01b03161115611a33579192915b836001600160a01b0316611a6c606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b031661105a565b81611a7357fe5b04949350505050565b6000826001600160a01b0316846001600160a01b03161115611a9c579192915b610250826001600160801b03168585036001600160a01b0316600160601b61105a565b600081602001516001600160a01b031682600001516001600160a01b031610611ae757600080fd5b610253836001600160a01b031663cefa77996040518163ffffffff1660e01b815260040160206040518083038186803b158015611b2357600080fd5b505afa158015611b37573d6000803e3d6000fd5b505050506040513d6020811015611b4d57600080fd5b5051835160208581015160408088015181516001600160a01b0395861681860152949092168482015260029190910b6060808501919091528151808503909101815260809093019052815191012085611e60565b6000806000856001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160c06040518083038186803b158015611bdf57600080fd5b505afa158015611bf3573d6000803e3d6000fd5b505050506040513d60c0811015611c0957600080fd5b50602001516040805163f30dba9360e01b8152600288900b6004820152905191925060009182916001600160a01b038a169163f30dba939160248082019261014092909190829003018186803b158015611c6257600080fd5b505afa158015611c76573d6000803e3d6000fd5b505050506040513d610140811015611c8d57600080fd5b5060608101516080909101516040805163f30dba9360e01b815260028a900b6004820152905192945090925060009182916001600160a01b038c169163f30dba939160248082019261014092909190829003018186803b158015611cf057600080fd5b505afa158015611d04573d6000803e3d6000fd5b505050506040513d610140811015611d1b57600080fd5b5060608101516080909101519092509050600289810b9086900b1215611d4a5781840396508083039550611e53565b8760020b8560020b1215611e485760008a6001600160a01b031663f30583996040518163ffffffff1660e01b815260040160206040518083038186803b158015611d9357600080fd5b505afa158015611da7573d6000803e3d6000fd5b505050506040513d6020811015611dbd57600080fd5b505160408051634614131960e01b815290519192506000916001600160a01b038e16916346141319916004808301926020929190829003018186803b158015611e0557600080fd5b505afa158015611e19573d6000803e3d6000fd5b505050506040513d6020811015611e2f57600080fd5b5051918690038490039850508390038190039550611e53565b838203965082810395505b5050505050935093915050565b604051733d602d80600a3d3981f3363d3d373d3d3d363d7360601b8152606093841b60148201526f5af43d82803e903d91602b57fd5bf3ff60801b6028820152921b6038830152604c8201526037808220606c830152605591012090565b60408051608081018252600080825260208201819052918101829052606081019190915290565b80516106788161240f565b805161ffff8116811461067857600080fd5b60008060408385031215611f14578182fd5b8235611f1f816123f7565b91506020830135611f2f8161242c565b809150509250929050565b600080600080600060a08688031215611f51578081fd5b8535611f5c816123f7565b94506020860135611f6c8161243b565b93506040860135611f7c8161242c565b92506060860135611f8c8161242c565b91506080860135611f9c8161242c565b809150509295509295909350565b60008060408385031215611fbc578182fd5b8235611fc7816123f7565b946020939093013593505050565b600080600060608486031215611fe9578283fd5b8335611ff4816123f7565b925060208401359150604084013561200b816123f7565b809150509250925092565b600060208284031215612027578081fd5b81356102538161242c565b600060208284031215612043578081fd5b81516102538161242c565b6000806000806000806000806000806101408b8d03121561206d578485fd5b8a516120788161243b565b60208c0151909a506120898161241d565b60408c015190995061209a8161241d565b8098505060608b0151965060808b0151955060a08b0151945060c08b01518060060b81146120c6578485fd5b60e08c01519094506120d7816123f7565b6101008c015190935063ffffffff811681146120f1578283fd5b91506121006101208c01611ee5565b90509295989b9194979a5092959850565b600060208284031215612122578081fd5b8135610253816123f7565b60008060008060008060c08789031215612145578384fd5b8651612150816123f7565b60208801519096506121618161242c565b945061216f60408801611ef0565b935061217d60608801611ef0565b925061218b60808801611ef0565b915060a087015161219b8161240f565b809150509295509295509295565b6000806000606084860312156121bd578081fd5b83356121c8816123f7565b925060208401356121d8816123f7565b9150604084013561200b8161241d565b600080600080608085870312156121fd578182fd5b8435612208816123f7565b93506020850135612218816123f7565b925060408501356122288161243b565b915060608501356122388161240f565b939692955090935050565b60008060008060808587031215612258578182fd5b8435612263816123f7565b93506020850135612273816123f7565b92506040850135612283816123f7565b915060608501356122388161243b565b6000602082840312156122a4578081fd5b5051919050565b600080600080600060a086880312156122c2578283fd5b8535945060208601356122d4816123f7565b93506040860135611f7c816123f7565b600080600080600060a086880312156122fb578283fd5b85359450602086013593506040860135612314816123f7565b92506060860135612324816123f7565b91506080860135611f9c816123f7565b602080825282518282018190526000919060409081850190868401855b828110156123a3578151805160020b8552868101516001600160a01b03168786015285810151600f0b868601526060908101516001600160801b03169085015260809093019290850190600101612351565b5091979650505050505050565b60019190910b815260200190565b60029190910b815260200190565b90815260200190565b6001600160a01b0391909116815260200190565b918252602082015260400190565b6001600160a01b038116811461240c57600080fd5b50565b801515811461240c57600080fd5b80600f0b811461240c57600080fd5b8060020b811461240c57600080fd5b6001600160801b038116811461240c57600080fdfea164736f6c6343000706000a
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.