Overview
SOPH Balance
SOPH Value
-More Info
Private Name Tags
ContractCreator
Latest 7 from a total of 7 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Create Pool | 3469256 | 13 days ago | IN | 0 SOPH | 1.06651198 | ||||
Create Pool | 3311928 | 15 days ago | IN | 0 SOPH | 0.76096719 | ||||
Create Pool | 3311874 | 15 days ago | IN | 0 SOPH | 1.00812927 | ||||
Create Pool | 3207350 | 16 days ago | IN | 0 SOPH | 1.02444224 | ||||
Create Pool | 3152002 | 17 days ago | IN | 0 SOPH | 1.10584822 | ||||
Create Pool | 3148023 | 17 days ago | IN | 0 SOPH | 1.23448749 | ||||
Create Pool | 3147552 | 17 days ago | IN | 0 SOPH | 1.00767818 |
Latest 8 internal transactions
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
3469256 | 13 days ago | Contract Creation | 0 SOPH | |||
3311928 | 15 days ago | Contract Creation | 0 SOPH | |||
3311874 | 15 days ago | Contract Creation | 0 SOPH | |||
3207350 | 16 days ago | Contract Creation | 0 SOPH | |||
3152002 | 17 days ago | Contract Creation | 0 SOPH | |||
3148023 | 17 days ago | Contract Creation | 0 SOPH | |||
3147552 | 17 days ago | Contract Creation | 0 SOPH | |||
3145805 | 17 days ago | Contract Creation | 0 SOPH |
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:
SyncSwapRangePoolFactoryZKSync
Compiler Version
v0.7.6+commit.7338295f
ZkSolc Version
v1.5.7
Optimization Enabled:
Yes with Mode 3
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 "./interfaces/ISyncSwapRangePoolFactory.sol"; import "./interfaces/IVoter.sol"; import "./interfaces/IFeeProvider.sol"; import "./interfaces/IFeeManagerV3.sol"; import "./libraries/external/Clones.sol"; import "./libraries/external/Ownable.sol"; import "./libraries/external/ExcessivelySafeCall.sol"; import "./SyncSwapRangePool.sol"; /// @title Canonical CL factory /// @notice Deploys CL pools and manages ownership and control over pool protocol fees contract SyncSwapRangePoolFactoryZKSync is ISyncSwapRangePoolFactory, Ownable { using ExcessivelySafeCall for address; /// @dev the pool master address public immutable override master; /// @dev the pool implementation address public immutable override poolImplementation; /// @dev the fee manager address public override feeManager; /// @dev the fee collector address public override feeCollector; /// @dev the pool creatorl address public override poolCreator; /// @dev the gauge factory address public override gaugeFactory; /// @inheritdoc ISyncSwapRangePoolFactory mapping(int24 => uint24) public override defaultSwapFeeByTickSpacing; /// @inheritdoc ISyncSwapRangePoolFactory mapping(address => mapping(address => mapping(int24 => address))) public override getPool; struct PoolInfo { address pool; int24 tickSpacing; } mapping(address => mapping(address => PoolInfo[])) public pairPools; /// @dev Returns if an address is a pool created by the factory mapping(address => bool) public override isPool; /// @inheritdoc ISyncSwapRangePoolFactory address[] public override allPools; int24[] public _tickSpacings; event SetFeeCollector(address indexed previousValue, address indexed newValue); event SetPoolCreator(address indexed previousValue, address indexed newValue); event SetGaugeFactory(address indexed previousValue, address indexed newValue); //event SetFeeProvider(address indexed previousValue, address indexed newValue); event SetFeeManager(address indexed previousValue, address indexed newValue); event SetTickSpacingDefaultSwapFee(int24 indexed tickSpacing, uint24 indexed fee); constructor(address _master, address _poolImplementation, address _feeManager) { require(_master != address(0) && _poolImplementation != address(0), "Invalid address"); master = _master; poolImplementation = _poolImplementation; feeCollector = msg.sender; poolCreator = msg.sender; // set fee manager _setFeeManager(_feeManager); // enable default tick spacings // 1 - 0.01% _enableTickSpacing(1, 100); // 50 - 0.05% _enableTickSpacing(50, 500); // 100 - 0.05% _enableTickSpacing(100, 500); // 200 - 0.3% _enableTickSpacing(200, 3000); // 2000 - 0.1% _enableTickSpacing(2000, 10000); } function tickSpacings() external view override returns (int24[] memory) { return _tickSpacings; } function tickSpacingsLength() external view returns (uint) { return _tickSpacings.length; } function allPoolsLength() external view override returns (uint) { return allPools.length; } function getPairPools(address tokenA, address tokenB) external view returns (PoolInfo[] memory) { return pairPools[tokenA][tokenB]; } function pairPoolsLength(address tokenA, address tokenB) external view returns (uint) { return pairPools[tokenA][tokenB].length; } function isPair(address pool) external view override returns (bool) { return isPool[pool]; } function createPool( bytes calldata data ) external returns (address pool) { (address tokenA, address tokenB, int24 tickSpacing, uint160 sqrtPriceX96) = abi.decode(data, (address, address, int24, uint160)); pool = createPool(tokenA, tokenB, tickSpacing, sqrtPriceX96); } /// @dev Creates a pool function createPool( address tokenA, address tokenB, int24 tickSpacing, uint160 sqrtPriceX96 ) public override returns (address pool) { // check creator require(msg.sender == poolCreator, "Not pool creator"); // check tokens require(tokenA != tokenB, "Identical token"); (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); require(token0 != address(0), "Invalid token"); // check tick spacing require(defaultSwapFeeByTickSpacing[tickSpacing] != 0, "Tick spacing not enabled"); // check pool require(getPool[token0][token1][tickSpacing] == address(0)); // create pool contract via clone /* pool = Clones.cloneDeterministic({ master: poolImplementation, salt: keccak256(abi.encode(token0, token1, tickSpacing)) }); */ bytes32 salt = keccak256(abi.encode(token0, token1, tickSpacing)); pool = address(new SyncSwapRangePool{salt: salt}()); // initialize pool SyncSwapRangePool(pool).initialize({ _factory: address(this), _token0: token0, _token1: token1, _tickSpacing: tickSpacing, _sqrtPriceX96: sqrtPriceX96 }); // add to all pools list allPools.push(pool); // update mappings isPool[pool] = true; getPool[token0][token1][tickSpacing] = pool; getPool[token1][token0][tickSpacing] = pool; // populate mapping in the reverse direction PoolInfo memory info = PoolInfo(pool, tickSpacing); pairPools[token0][token1].push(info); pairPools[token1][token0].push(info); // populate mapping in the reverse direction // register with pool master IPoolMaster(master).registerPool( pool, 4, // pool type abi.encode(token0, token1, tickSpacing), token0, token1 ); emit PoolCreated(token0, token1, tickSpacing, pool); } function getProtocolFee(address _pool) external view override returns (uint24) { return IFeeManagerV3(feeManager).getProtocolFee(_pool); } /// @dev Returns swap fee for a pool function getSwapFee( address _pool, address _sender, address _tokenIn, address _tokenOut, bytes memory _data ) external view override returns (uint24) { address _feeManager = feeManager; if (_feeManager != address(0)) { try IFeeManagerV3(_feeManager).getSwapFee( _pool, _sender, _tokenIn, _tokenOut, _data ) returns (uint24 _fee) { return _fee; } catch {} } // use default fee of tick spacing int24 poolTickSpacing = SyncSwapRangePool(_pool).tickSpacing(); return defaultSwapFeeByTickSpacing[poolTickSpacing]; } /// @dev Updates fee collector function setFeeCollector(address _feeCollector) external onlyOwner { address _previous = feeCollector; feeCollector = _feeCollector; emit SetFeeCollector(_previous, _feeCollector); } /// @dev Updates pool creator function setPoolCreator(address _poolCreator) external onlyOwner { address _previous = poolCreator; poolCreator = _poolCreator; emit SetPoolCreator(_previous, _poolCreator); } /// @dev Updates fee manager function setFeeManager(address _feeManager) external onlyOwner { _setFeeManager(_feeManager); } function _setFeeManager(address _feeManager) private { address _previous = _feeManager; feeManager = _feeManager; emit SetFeeManager(_previous, _feeManager); } /// @dev Enables a tick spacing function enableTickSpacing(int24 _tickSpacing, uint24 _fee) public onlyOwner { _enableTickSpacing(_tickSpacing, _fee); } function _enableTickSpacing(int24 _tickSpacing, uint24 _fee) private { // tick spacing is capped at 16384 to prevent the situation where tickSpacing is so large that // TickBitmap#nextInitializedTickWithinOneWord overflows int24 container from a valid tick // 16384 ticks represents a >5x price change with ticks of 1 bips require(_tickSpacing > 0 && _tickSpacing < 16384, "Invalid tick spacing"); require(defaultSwapFeeByTickSpacing[_tickSpacing] == 0, "Already enabled"); _tickSpacings.push(_tickSpacing); _setDefaultSwapFeeForTickSpacing(_tickSpacing, _fee); emit TickSpacingEnabled(_tickSpacing, _fee); } /// @dev Updates default swap fee for a tick spacing function setDefaultSwapFeeForTickSpacing(int24 _tickSpacing, uint24 _fee) external onlyOwner { require(defaultSwapFeeByTickSpacing[_tickSpacing] != 0, "Tick spacing not enabled"); _setDefaultSwapFeeForTickSpacing(_tickSpacing, _fee); } function _setDefaultSwapFeeForTickSpacing(int24 _tickSpacing, uint24 _fee) private { require(_fee > 0 && _fee <= 100000, "Invalid fee"); defaultSwapFeeByTickSpacing[_tickSpacing] = _fee; emit SetTickSpacingDefaultSwapFee(_tickSpacing, _fee); } /// @dev Updates gauge factory function setGaugeFactory(address _gaugeFactory) external onlyOwner { address _previous = gaugeFactory; gaugeFactory = _gaugeFactory; emit SetGaugeFactory(_previous, _gaugeFactory); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.7.6; pragma abicoder v2; import "./interfaces/external/IERC20Minimal.sol"; import "./interfaces/callback/ICLMintCallback.sol"; import "./interfaces/callback/ICLSwapCallback.sol"; import "./interfaces/callback/ICLFlashCallback.sol"; import "./interfaces/callback/ISyncSwapBaseCallback.sol"; import "./interfaces/IFeeRecipient.sol"; import "./interfaces/ISyncSwapRangePoolFactory.sol"; import "./interfaces/ISyncSwapRangePool.sol"; import "./interfaces/IPoolMaster.sol"; import "./libraries/external/LowGasSafeMath.sol"; import "./libraries/external/SafeCast.sol"; import "./libraries/external/FullMath.sol"; import "./libraries/external/FixedPoint128.sol"; import "./libraries/external/TransferHelper.sol"; import "./libraries/TickMath.sol"; import "./libraries/Tick.sol"; import "./libraries/TickBitmap.sol"; import "./libraries/Position.sol"; import "./libraries/Oracle.sol"; import "./libraries/LiquidityMath.sol"; import "./libraries/SqrtPriceMath.sol"; import "./libraries/SwapMath.sol"; contract SyncSwapRangePool is ISyncSwapRangePool { using LowGasSafeMath for uint256; using LowGasSafeMath for int256; using SafeCast for uint256; using SafeCast for int256; using Tick for mapping(int24 => Tick.Info); using TickBitmap for mapping(int16 => uint256); using Position for mapping(bytes32 => Position.Info); using Position for Position.Info; using Oracle for Oracle.Observation[65535]; /// @dev Pool type `4` for concentrated pools. uint16 public constant poolType = 4; /// @dev Protocol version 3. uint public constant poolVersion = 3; /// @inheritdoc ICLPoolConstants address public override master; /// @inheritdoc ICLPoolConstants address public override factory; /// @inheritdoc ICLPoolConstants address public override token0; /// @inheritdoc ICLPoolConstants address public override token1; /// @inheritdoc ICLPoolConstants address public override gauge; /// @inheritdoc ICLPoolConstants address public override nft; struct Slot0 { // the current price uint160 sqrtPriceX96; // the current tick int24 tick; // the most-recently updated index of the observations array uint16 observationIndex; // the current maximum number of observations that are being stored uint16 observationCardinality; // the next maximum number of observations to store, triggered in observations.write uint16 observationCardinalityNext; // whether the pool is locked bool unlocked; } /// @inheritdoc ICLPoolState Slot0 public override slot0; /// @inheritdoc ICLPoolState uint256 public override feeGrowthGlobal0X128; /// @inheritdoc ICLPoolState uint256 public override feeGrowthGlobal1X128; /// @inheritdoc ICLPoolState uint256 public override rewardGrowthGlobalX128; // accumulated gauge fees in token0/token1 units struct GaugeFees { uint128 token0; uint128 token1; } /// @inheritdoc ICLPoolState GaugeFees public override gaugeFees; /// @inheritdoc ICLPoolState uint256 public override rewardRate; /// @inheritdoc ICLPoolState uint256 public override rewardReserve; /// @inheritdoc ICLPoolState uint256 public override periodFinish; /// @inheritdoc ICLPoolState uint256 public override rollover; /// @inheritdoc ICLPoolState uint128 public override stakedLiquidity; /// @inheritdoc ICLPoolState uint32 public override lastUpdated; /// @inheritdoc ICLPoolConstants int24 public override tickSpacing; /// @inheritdoc ICLPoolState uint128 public override liquidity; /// @inheritdoc ICLPoolConstants uint128 public override maxLiquidityPerTick; /// @inheritdoc ICLPoolState mapping(int24 => Tick.Info) public override ticks; /// @inheritdoc ICLPoolState mapping(int16 => uint256) public override tickBitmap; /// @inheritdoc ICLPoolState mapping(bytes32 => Position.Info) public override positions; /// @inheritdoc ICLPoolState Oracle.Observation[65535] public override observations; /// @dev Mutually exclusive reentrancy protection into the pool to/from a method. This method also prevents entrance /// to a function before the pool is initialized. The reentrancy guard is required throughout the contract because /// we use balance checks to determine the payment status of interactions such as mint, swap and flash. modifier lock() { require(slot0.unlocked, "K"); slot0.unlocked = false; _; slot0.unlocked = true; } modifier onlyGauge() { require(msg.sender == gauge); _; } modifier onlyNFTManager() { require(msg.sender == nft); _; } /// @inheritdoc ICLPoolActions function initialize( address _factory, address _token0, address _token1, int24 _tickSpacing, uint160 _sqrtPriceX96 ) external override { require(factory == address(0)); factory = _factory; master = ISyncSwapRangePoolFactory(_factory).master(); token0 = _token0; token1 = _token1; tickSpacing = _tickSpacing; maxLiquidityPerTick = Tick.tickSpacingToMaxLiquidityPerTick(_tickSpacing); int24 tick = TickMath.getTickAtSqrtRatio(_sqrtPriceX96); (uint16 cardinality, uint16 cardinalityNext) = observations.initialize(_blockTimestamp()); slot0 = Slot0({ sqrtPriceX96: _sqrtPriceX96, tick: tick, observationIndex: 0, observationCardinality: cardinality, observationCardinalityNext: cardinalityNext, unlocked: true }); emit Initialize(_sqrtPriceX96, tick); } /* function fee() public view override returns (uint24) { return ISyncSwapRangePoolFactory(factory).getSwapFee(address(this)); } */ function getProtocolFee() public view override returns (uint24) { try ISyncSwapRangePoolFactory(factory).getProtocolFee(address(this)) returns (uint24 _protocolFee) { return _protocolFee; } catch { return 30000; // 30% } } /// @dev Common checks for valid tick inputs. function checkTicks(int24 tickLower, int24 tickUpper) private pure { require(tickLower < tickUpper, "U"); require(tickLower >= TickMath.MIN_TICK); require(tickUpper <= TickMath.MAX_TICK); } /// @dev Returns the block timestamp truncated to 32 bits, i.e. mod 2**32. This method is overridden in tests. function _blockTimestamp() private view returns (uint32) { return uint32(block.timestamp); // truncation is desired } /// @dev Get the pool's balance of token0 /// @dev This function is gas optimized to avoid a redundant extcodesize check in addition to the returndatasize /// check function balance0() private view returns (uint256) { return _getBalance(token0); } /// @dev Get the pool's balance of token1 /// @dev This function is gas optimized to avoid a redundant extcodesize check in addition to the returndatasize /// check function balance1() private view returns (uint256) { return _getBalance(token1); } function _getBalance(address _token) private view returns (uint256) { (bool success, bytes memory data) = _token.staticcall(abi.encodeWithSelector(IERC20Minimal.balanceOf.selector, address(this))); require(success && data.length >= 32); return abi.decode(data, (uint256)); } /// @inheritdoc ICLPoolDerivedState function snapshotCumulativesInside(int24 tickLower, int24 tickUpper) external view override returns (int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside) { checkTicks(tickLower, tickUpper); int56 tickCumulativeLower; int56 tickCumulativeUpper; uint160 secondsPerLiquidityOutsideLowerX128; uint160 secondsPerLiquidityOutsideUpperX128; uint32 secondsOutsideLower; uint32 secondsOutsideUpper; { Tick.Info storage lower = ticks[tickLower]; Tick.Info storage upper = ticks[tickUpper]; bool initializedLower; (tickCumulativeLower, secondsPerLiquidityOutsideLowerX128, secondsOutsideLower, initializedLower) = ( lower.tickCumulativeOutside, lower.secondsPerLiquidityOutsideX128, lower.secondsOutside, lower.initialized ); require(initializedLower); bool initializedUpper; (tickCumulativeUpper, secondsPerLiquidityOutsideUpperX128, secondsOutsideUpper, initializedUpper) = ( upper.tickCumulativeOutside, upper.secondsPerLiquidityOutsideX128, upper.secondsOutside, upper.initialized ); require(initializedUpper); } Slot0 memory _slot0 = slot0; if (_slot0.tick < tickLower) { return ( tickCumulativeLower - tickCumulativeUpper, secondsPerLiquidityOutsideLowerX128 - secondsPerLiquidityOutsideUpperX128, secondsOutsideLower - secondsOutsideUpper ); } else if (_slot0.tick < tickUpper) { uint32 time = _blockTimestamp(); (int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128) = observations.observeSingle( time, 0, _slot0.tick, _slot0.observationIndex, liquidity, _slot0.observationCardinality ); return ( tickCumulative - tickCumulativeLower - tickCumulativeUpper, secondsPerLiquidityCumulativeX128 - secondsPerLiquidityOutsideLowerX128 - secondsPerLiquidityOutsideUpperX128, time - secondsOutsideLower - secondsOutsideUpper ); } else { return ( tickCumulativeUpper - tickCumulativeLower, secondsPerLiquidityOutsideUpperX128 - secondsPerLiquidityOutsideLowerX128, secondsOutsideUpper - secondsOutsideLower ); } } /// @inheritdoc ICLPoolDerivedState function observe(uint32[] calldata secondsAgos) external view override returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) { return observations.observe( _blockTimestamp(), secondsAgos, slot0.tick, slot0.observationIndex, liquidity, slot0.observationCardinality ); } /// @inheritdoc ICLPoolActions function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external override lock { uint16 observationCardinalityNextOld = slot0.observationCardinalityNext; // for the event uint16 observationCardinalityNextNew = observations.grow(observationCardinalityNextOld, observationCardinalityNext); slot0.observationCardinalityNext = observationCardinalityNextNew; if (observationCardinalityNextOld != observationCardinalityNextNew) { emit IncreaseObservationCardinalityNext(observationCardinalityNextOld, observationCardinalityNextNew); } } struct ModifyPositionParams { // the address that owns the position address owner; // the lower and upper tick of the position int24 tickLower; int24 tickUpper; // any change in liquidity int128 liquidityDelta; } /// @dev Effect some changes to a position /// @param params the position details and the change to the position's liquidity to effect /// @return position a storage pointer referencing the position with the given owner and tick range /// @return amount0 the amount of token0 owed to the pool, negative if the pool should pay the recipient /// @return amount1 the amount of token1 owed to the pool, negative if the pool should pay the recipient function _modifyPosition(ModifyPositionParams memory params) private returns (Position.Info storage position, int256 amount0, int256 amount1) { checkTicks(params.tickLower, params.tickUpper); Slot0 memory _slot0 = slot0; // SLOAD for gas optimization position = _updatePosition(params.owner, params.tickLower, params.tickUpper, params.liquidityDelta, _slot0.tick); if (params.liquidityDelta != 0) { if (_slot0.tick < params.tickLower) { // current tick is below the passed range; liquidity can only become in range by crossing from left to // right, when we'll need _more_ token0 (it's becoming more valuable) so user must provide it amount0 = SqrtPriceMath.getAmount0Delta( TickMath.getSqrtRatioAtTick(params.tickLower), TickMath.getSqrtRatioAtTick(params.tickUpper), params.liquidityDelta ); } else if (_slot0.tick < params.tickUpper) { // current tick is inside the passed range uint128 liquidityBefore = liquidity; // SLOAD for gas optimization // write an oracle entry (slot0.observationIndex, slot0.observationCardinality) = observations.write( _slot0.observationIndex, _blockTimestamp(), _slot0.tick, liquidityBefore, _slot0.observationCardinality, _slot0.observationCardinalityNext ); amount0 = SqrtPriceMath.getAmount0Delta( _slot0.sqrtPriceX96, TickMath.getSqrtRatioAtTick(params.tickUpper), params.liquidityDelta ); amount1 = SqrtPriceMath.getAmount1Delta( TickMath.getSqrtRatioAtTick(params.tickLower), _slot0.sqrtPriceX96, params.liquidityDelta ); liquidity = LiquidityMath.addDelta(liquidityBefore, params.liquidityDelta); } else { // current tick is above the passed range; liquidity can only become in range by crossing from right to // left, when we'll need _more_ token1 (it's becoming more valuable) so user must provide it amount1 = SqrtPriceMath.getAmount1Delta( TickMath.getSqrtRatioAtTick(params.tickLower), TickMath.getSqrtRatioAtTick(params.tickUpper), params.liquidityDelta ); } } } /// @dev Gets and updates a position with the given liquidity delta /// @param owner the owner of the position /// @param tickLower the lower tick of the position's tick range /// @param tickUpper the upper tick of the position's tick range /// @param tick the current tick, passed to avoid sloads function _updatePosition(address owner, int24 tickLower, int24 tickUpper, int128 liquidityDelta, int24 tick) private returns (Position.Info storage position) { position = positions.get(owner, tickLower, tickUpper); uint256 _feeGrowthGlobal0X128 = feeGrowthGlobal0X128; // SLOAD for gas optimization uint256 _feeGrowthGlobal1X128 = feeGrowthGlobal1X128; // SLOAD for gas optimization uint256 _rewardGrowthGlobalX128 = rewardGrowthGlobalX128; // SLOAD for gas optimization // if we need to update the ticks, do it bool flippedLower; bool flippedUpper; if (liquidityDelta != 0) { uint32 time = _blockTimestamp(); (int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128) = observations.observeSingle( time, 0, slot0.tick, slot0.observationIndex, liquidity, slot0.observationCardinality ); flippedLower = ticks.update( tickLower, tick, liquidityDelta, _feeGrowthGlobal0X128, _feeGrowthGlobal1X128, _rewardGrowthGlobalX128, secondsPerLiquidityCumulativeX128, tickCumulative, time, false, maxLiquidityPerTick ); flippedUpper = ticks.update( tickUpper, tick, liquidityDelta, _feeGrowthGlobal0X128, _feeGrowthGlobal1X128, _rewardGrowthGlobalX128, secondsPerLiquidityCumulativeX128, tickCumulative, time, true, maxLiquidityPerTick ); if (flippedLower) { tickBitmap.flipTick(tickLower, tickSpacing); } if (flippedUpper) { tickBitmap.flipTick(tickUpper, tickSpacing); } } (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) = ticks.getFeeGrowthInside(tickLower, tickUpper, tick, _feeGrowthGlobal0X128, _feeGrowthGlobal1X128); bool staked = (owner == gauge) && (owner != address(0)); position.update(liquidityDelta, feeGrowthInside0X128, feeGrowthInside1X128, staked); // clear any tick data that is no longer needed if (liquidityDelta < 0) { if (flippedLower) { ticks.clear(tickLower); } if (flippedUpper) { ticks.clear(tickUpper); } } } /// @inheritdoc ICLPoolActions function mint(address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data) external override lock returns (uint256 amount0, uint256 amount1) { require(amount != 0); (, int256 amount0Int, int256 amount1Int) = _modifyPosition( ModifyPositionParams({ owner: recipient, tickLower: tickLower, tickUpper: tickUpper, liquidityDelta: int256(amount).toInt128() }) ); amount0 = uint256(amount0Int); amount1 = uint256(amount1Int); uint256 balance0Before; uint256 balance1Before; if (amount0 != 0) { balance0Before = balance0(); } if (amount1 != 0) { balance1Before = balance1(); } ICLMintCallback(msg.sender).uniswapV3MintCallback(amount0, amount1, data); if (amount0 != 0) { require(balance0Before.add(amount0) <= balance0(), "0"); } if (amount1 != 0) { require(balance1Before.add(amount1) <= balance1(), "1"); } emit Mint(msg.sender, recipient, tickLower, tickUpper, amount, amount0, amount1); } /// @inheritdoc ICLPoolActions function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external override returns (uint128 amount0, uint128 amount1) { (amount0, amount1) = _collect({ recipient: recipient, tickLower: tickLower, tickUpper: tickUpper, amount0Requested: amount0Requested, amount1Requested: amount1Requested, owner: msg.sender }); } /// @inheritdoc ICLPoolActions function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested, address owner ) external override onlyNFTManager returns (uint128 amount0, uint128 amount1) { (amount0, amount1) = _collect({ recipient: recipient, tickLower: tickLower, tickUpper: tickUpper, amount0Requested: amount0Requested, amount1Requested: amount1Requested, owner: owner }); } function _collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested, address owner ) private lock returns (uint128 amount0, uint128 amount1) { // we don't need to checkTicks here, because invalid positions will never have non-zero tokensOwed{0,1} Position.Info storage position = positions.get(owner, tickLower, tickUpper); amount0 = amount0Requested > position.tokensOwed0 ? position.tokensOwed0 : amount0Requested; amount1 = amount1Requested > position.tokensOwed1 ? position.tokensOwed1 : amount1Requested; if (amount0 != 0) { position.tokensOwed0 -= amount0; TransferHelper.safeTransfer(token0, recipient, amount0); } if (amount1 != 0) { position.tokensOwed1 -= amount1; TransferHelper.safeTransfer(token1, recipient, amount1); } emit Collect(owner, recipient, tickLower, tickUpper, amount0, amount1); } /// @inheritdoc ICLPoolActions function burn(int24 tickLower, int24 tickUpper, uint128 amount) external override lock returns (uint256 amount0, uint256 amount1) { (amount0, amount1) = _burn({tickLower: tickLower, tickUpper: tickUpper, amount: amount, owner: msg.sender}); } /// @inheritdoc ICLPoolActions function burn(int24 tickLower, int24 tickUpper, uint128 amount, address owner) external override lock onlyNFTManager returns (uint256 amount0, uint256 amount1) { (amount0, amount1) = _burn({tickLower: tickLower, tickUpper: tickUpper, amount: amount, owner: owner}); } function _burn(int24 tickLower, int24 tickUpper, uint128 amount, address owner) private returns (uint256 amount0, uint256 amount1) { (Position.Info storage position, int256 amount0Int, int256 amount1Int) = _modifyPosition( ModifyPositionParams({ owner: owner, tickLower: tickLower, tickUpper: tickUpper, liquidityDelta: -int256(amount).toInt128() }) ); amount0 = uint256(-amount0Int); amount1 = uint256(-amount1Int); if (amount0 != 0 || amount1 != 0) { (position.tokensOwed0, position.tokensOwed1) = (position.tokensOwed0 + uint128(amount0), position.tokensOwed1 + uint128(amount1)); } emit Burn(owner, tickLower, tickUpper, amount, amount0, amount1); } /// @inheritdoc ICLPoolActions function stake(int128 stakedLiquidityDelta, int24 tickLower, int24 tickUpper, bool positionUpdate) external override lock onlyGauge { int24 tick = slot0.tick; // Increase staked liquidity in the current tick if (tick >= tickLower && tick < tickUpper) { _updateRewardsGrowthGlobal(); stakedLiquidity = LiquidityMath.addDelta(stakedLiquidity, stakedLiquidityDelta); } if (positionUpdate) { Position.Info storage nftPosition = positions.get(nft, tickLower, tickUpper); Position.Info storage gaugePosition = positions.get(gauge, tickLower, tickUpper); (uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128) = ticks.getFeeGrowthInside(tickLower, tickUpper, tick, feeGrowthGlobal0X128, feeGrowthGlobal1X128); // Assign the staked positions virtually to the gauge nftPosition.update(-stakedLiquidityDelta, feeGrowthInside0X128, feeGrowthInside1X128, false); gaugePosition.update(stakedLiquidityDelta, feeGrowthInside0X128, feeGrowthInside1X128, true); } // Update tick locations where staked liquidity needs to be added or subtracted // Only update ticks if current tick is initialized if (ticks[tickLower].initialized) { ticks.updateStake(tickLower, stakedLiquidityDelta, false); } if (ticks[tickUpper].initialized) { ticks.updateStake(tickUpper, stakedLiquidityDelta, true); } } struct SwapCache { // liquidity at the beginning of the swap uint128 liquidityStart; // staked liquidity at the beginning of the swap uint128 stakedLiquidityStart; // the timestamp of the current block uint32 blockTimestamp; // the current value of the tick accumulator, computed only if we cross an initialized tick int56 tickCumulative; // the current value of seconds per liquidity accumulator, computed only if we cross an initialized tick uint160 secondsPerLiquidityCumulativeX128; // whether we've computed and cached the above two accumulators bool computedLatestObservation; } // the top level state of the swap, the results of which are recorded in storage at the end struct SwapState { // the amount remaining to be swapped in/out of the input/output asset int256 amountSpecifiedRemaining; // the amount already swapped out/in of the output/input asset int256 amountCalculated; // current sqrt(price) uint160 sqrtPriceX96; // the tick associated with the current price int24 tick; // the fee associated with the pool uint24 fee; // wether we've updated the fees in the current swap bool hasUpdatedFees; // the global fee growth of the input token uint256 feeGrowthGlobalX128; // amount of input token paid as gauge fee uint128 gaugeFee; // the current liquidity in range uint128 liquidity; // the current staked liquidity in range uint128 stakedLiquidity; // whether the swap is using exact input bool exactInput; // how much fee is being paid in total uint256 totalFeeAmount; // balance of token0 before swap transfers uint256 balance0Before; // balance of token1 before swap transfers uint256 balance1Before; // balance of swap input token after swap transfers uint256 balanceAfter; } struct StepComputations { // the price at the beginning of the step uint160 sqrtPriceStartX96; // the next tick to swap to from the current tick in the swap direction int24 tickNext; // whether tickNext is initialized or not bool initialized; // sqrt(price) for the next tick (1/0) uint160 sqrtPriceNextX96; // how much is being swapped in in this step uint256 amountIn; // how much is being swapped out uint256 amountOut; // how much fee is being paid in uint256 feeAmount; } struct SwapParams { address recipient; bool zeroForOne; int256 amountSpecified; uint160 sqrtPriceLimitX96; address sender; bytes data; address callback; bytes callbackData; } /// @inheritdoc ICLPoolActions function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external override returns (int256 amount0, int256 amount1) { (amount0, amount1) = swap(SwapParams({ recipient: recipient, zeroForOne: zeroForOne, amountSpecified: amountSpecified, sqrtPriceLimitX96: sqrtPriceLimitX96, sender: msg.sender, data: data, callback: address(0), callbackData: "" })); } function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data, address sender, address callback, bytes calldata callbackData ) external override returns (int256 amount0, int256 amount1) { (amount0, amount1) = swap( SwapParams({ recipient: recipient, zeroForOne: zeroForOne, amountSpecified: amountSpecified, sqrtPriceLimitX96: sqrtPriceLimitX96, sender: sender, data: data, callback: callback, callbackData: callbackData }) ); } function swap(SwapParams memory params) public returns (int256 amount0, int256 amount1) { require(params.amountSpecified != 0); Slot0 memory slot0Start = slot0; require(slot0Start.unlocked, "K"); require( params.zeroForOne ? params.sqrtPriceLimitX96 < slot0Start.sqrtPriceX96 && params.sqrtPriceLimitX96 > TickMath.MIN_SQRT_RATIO : params.sqrtPriceLimitX96 > slot0Start.sqrtPriceX96 && params.sqrtPriceLimitX96 < TickMath.MAX_SQRT_RATIO, "P" ); slot0.unlocked = false; SwapCache memory cache = SwapCache({ liquidityStart: liquidity, stakedLiquidityStart: stakedLiquidity, blockTimestamp: _blockTimestamp(), secondsPerLiquidityCumulativeX128: 0, tickCumulative: 0, computedLatestObservation: false }); //bool exactInput = amountSpecified > 0; params.sender = _getVerifiedSender(params.sender); SwapState memory state = SwapState({ amountSpecifiedRemaining: params.amountSpecified, amountCalculated: 0, sqrtPriceX96: slot0Start.sqrtPriceX96, tick: slot0Start.tick, //fee: fee(), fee: params.zeroForOne ? _getSwapFee(params.sender, token0, token1) : _getSwapFee(params.sender, token1, token0), hasUpdatedFees: false, feeGrowthGlobalX128: params.zeroForOne ? feeGrowthGlobal0X128 : feeGrowthGlobal1X128, gaugeFee: 0, liquidity: cache.liquidityStart, stakedLiquidity: cache.stakedLiquidityStart, exactInput: params.amountSpecified > 0, totalFeeAmount: 0, balance0Before: 0, balance1Before: 0, balanceAfter: 0 }); // continue swapping as long as we haven't used the entire input/output and haven't reached the price limit while (state.amountSpecifiedRemaining != 0 && state.sqrtPriceX96 != params.sqrtPriceLimitX96) { StepComputations memory step; step.sqrtPriceStartX96 = state.sqrtPriceX96; (step.tickNext, step.initialized) = tickBitmap.nextInitializedTickWithinOneWord(state.tick, tickSpacing, params.zeroForOne); // ensure that we do not overshoot the min/max tick, as the tick bitmap is not aware of these bounds if (step.tickNext < TickMath.MIN_TICK) { step.tickNext = TickMath.MIN_TICK; } else if (step.tickNext > TickMath.MAX_TICK) { step.tickNext = TickMath.MAX_TICK; } // get the price for the next tick step.sqrtPriceNextX96 = TickMath.getSqrtRatioAtTick(step.tickNext); // compute values to swap to the target tick, price limit, or point where input/output amount is exhausted (state.sqrtPriceX96, step.amountIn, step.amountOut, step.feeAmount) = SwapMath.computeSwapStep( state.sqrtPriceX96, (params.zeroForOne ? step.sqrtPriceNextX96 < params.sqrtPriceLimitX96 : step.sqrtPriceNextX96 > params.sqrtPriceLimitX96) ? params.sqrtPriceLimitX96 : step.sqrtPriceNextX96, state.liquidity, state.amountSpecifiedRemaining, state.fee ); if (state.exactInput) { state.amountSpecifiedRemaining -= (step.amountIn + step.feeAmount).toInt256(); state.amountCalculated = state.amountCalculated.sub(step.amountOut.toInt256()); } else { state.amountSpecifiedRemaining += step.amountOut.toInt256(); state.amountCalculated = state.amountCalculated.add((step.amountIn + step.feeAmount).toInt256()); } // update global fee tracker and gauge fee if (state.liquidity != 0) { (uint256 _feeGrowthGlobalX128, uint256 _protocolFeeAmount) = _calculateFees(step.feeAmount, state.liquidity); state.feeGrowthGlobalX128 += _feeGrowthGlobalX128; state.gaugeFee += uint128(_protocolFeeAmount); state.totalFeeAmount += step.feeAmount; } // shift tick if we reached the next price if (state.sqrtPriceX96 == step.sqrtPriceNextX96) { // if the tick is initialized, run the tick transition if (step.initialized) { // check for the placeholder value, which we replace with the actual value the first time the swap // crosses an initialized tick if (!cache.computedLatestObservation) { (cache.tickCumulative, cache.secondsPerLiquidityCumulativeX128) = observations.observeSingle( cache.blockTimestamp, 0, slot0Start.tick, slot0Start.observationIndex, cache.liquidityStart, slot0Start.observationCardinality ); cache.computedLatestObservation = true; } if (!state.hasUpdatedFees) { _updateRewardsGrowthGlobal(); state.hasUpdatedFees = true; } Tick.LiquidityNets memory nets = ticks.cross( step.tickNext, (params.zeroForOne ? state.feeGrowthGlobalX128 : feeGrowthGlobal0X128), (params.zeroForOne ? feeGrowthGlobal1X128 : state.feeGrowthGlobalX128), cache.secondsPerLiquidityCumulativeX128, cache.tickCumulative, cache.blockTimestamp, rewardGrowthGlobalX128 ); // if we're moving leftward, we interpret liquidityNet & stakedLiquidityNet as the opposite sign // safe because liquidityNet & stakedLiquidityNet cannot be type(int128).min if (params.zeroForOne) { nets.liquidityNet = -nets.liquidityNet; nets.stakedLiquidityNet = -nets.stakedLiquidityNet; } state.liquidity = LiquidityMath.addDelta(state.liquidity, nets.liquidityNet); state.stakedLiquidity = LiquidityMath.addDelta(state.stakedLiquidity, nets.stakedLiquidityNet); } state.tick = params.zeroForOne ? step.tickNext - 1 : step.tickNext; } else if (state.sqrtPriceX96 != step.sqrtPriceStartX96) { // recompute unless we're on a lower tick boundary (i.e. already transitioned ticks), and haven't moved state.tick = TickMath.getTickAtSqrtRatio(state.sqrtPriceX96); } } // update tick and write an oracle entry if the tick change if (state.tick != slot0Start.tick) { (uint16 observationIndex, uint16 observationCardinality) = observations.write( slot0Start.observationIndex, cache.blockTimestamp, slot0Start.tick, cache.liquidityStart, slot0Start.observationCardinality, slot0Start.observationCardinalityNext ); (slot0.sqrtPriceX96, slot0.tick, slot0.observationIndex, slot0.observationCardinality) = (state.sqrtPriceX96, state.tick, observationIndex, observationCardinality); } else { // otherwise just update the price slot0.sqrtPriceX96 = state.sqrtPriceX96; } // update liquidity and stakedLiquidity if it changed if (cache.liquidityStart != state.liquidity) liquidity = state.liquidity; if (cache.stakedLiquidityStart != state.stakedLiquidity) stakedLiquidity = state.stakedLiquidity; // update fee growth global and, if necessary, gauge fees // overflow is acceptable, protocol has to withdraw before it hits type(uint128).max fees if (params.zeroForOne) { feeGrowthGlobal0X128 = state.feeGrowthGlobalX128; if (state.gaugeFee != 0) { gaugeFees.token0 += state.gaugeFee; } _notifyFeeAmount(token0, state.fee, state.totalFeeAmount, state.gaugeFee); // notify fee amount } else { feeGrowthGlobal1X128 = state.feeGrowthGlobalX128; if (state.gaugeFee != 0) { gaugeFees.token1 += state.gaugeFee; } _notifyFeeAmount(token1, state.fee, state.totalFeeAmount, state.gaugeFee); // notify fee amount } (amount0, amount1) = params.zeroForOne == state.exactInput ? (params.amountSpecified - state.amountSpecifiedRemaining, state.amountCalculated) : (state.amountCalculated, params.amountSpecified - state.amountSpecifiedRemaining); // do the transfers and collect payment if (params.zeroForOne) { if (amount1 < 0) { TransferHelper.safeTransfer(token1, params.recipient, uint256(-amount1)); } if (params.callback != address(0)) { state.balance1Before = balance1(); } state.balance0Before = balance0(); ICLSwapCallback(msg.sender).uniswapV3SwapCallback(amount0, amount1, params.data); state.balanceAfter = balance0(); require(state.balance0Before.add(uint256(amount0)) <= state.balanceAfter, "I"); } else { if (amount0 < 0) { TransferHelper.safeTransfer(token0, params.recipient, uint256(-amount0)); } if (params.callback != address(0)) { state.balance0Before = balance0(); } state.balance1Before = balance1(); ICLSwapCallback(msg.sender).uniswapV3SwapCallback(amount0, amount1, params.data); state.balanceAfter = balance1(); require(state.balance1Before.add(uint256(amount1)) <= state.balanceAfter, "I"); } // execute callback if (params.callback != address(0)) { ISyncSwapBaseCallback(params.callback).syncSwapBaseSwapCallback( ISyncSwapBaseCallback.BaseSwapCallbackParams({ sender: params.sender, to: params.recipient, tokenIn: params.zeroForOne ? token0 : token1, tokenOut: params.zeroForOne ? token1 : token0, reserve0: state.balance0Before, reserve1: state.balance1Before, balance0: params.zeroForOne ? state.balanceAfter : balance0(), balance1: params.zeroForOne ? balance1() : state.balanceAfter, amountIn: params.amountSpecified > 0 ? uint256(params.amountSpecified) : 0, amountOut: params.zeroForOne ? uint256(-amount1) : uint256(-amount0), feeIn: state.totalFeeAmount, swapFee: state.fee, withdrawMode: 3, callbackData: params.callbackData }) ); } emit Swap(msg.sender, params.recipient, amount0, amount1, state.sqrtPriceX96, state.liquidity, state.tick); slot0.unlocked = true; } /// @inheritdoc ICLPoolActions function flash( address recipient, uint256 amount0, uint256 amount1, bytes calldata data ) external override lock { uint128 _liquidity = liquidity; require(_liquidity != 0); uint24 feeRate0 = getSwapFee(msg.sender, token1, token0, abi.encode(msg.sender, amount0)); uint24 feeRate1 = getSwapFee(msg.sender, token0, token1, abi.encode(msg.sender, amount1)); uint256 fee0 = FullMath.mulDivRoundingUp(amount0, feeRate0, 1e6); uint256 fee1 = FullMath.mulDivRoundingUp(amount1, feeRate1, 1e6); uint256 balance0Before = balance0(); uint256 balance1Before = balance1(); if (amount0 != 0) { TransferHelper.safeTransfer(token0, recipient, amount0); } if (amount1 != 0) { TransferHelper.safeTransfer(token1, recipient, amount1); } ICLFlashCallback(msg.sender).uniswapV3FlashCallback(fee0, fee1, data); uint256 paid0; uint256 paid1; { uint256 balance0After = balance0(); uint256 balance1After = balance1(); require(balance0Before.add(fee0) <= balance0After, "0"); require(balance1Before.add(fee1) <= balance1After, "1"); // sub is safe because we know balanceAfter is gt balanceBefore by at least fee paid0 = balance0After - balance0Before; paid1 = balance1After - balance1Before; } if (paid0 != 0) { (uint256 _feeGrowthGlobalX128, uint256 _protocolFeeAmount) = _calculateFees(paid0, _liquidity); if (_feeGrowthGlobalX128 != 0) { feeGrowthGlobal0X128 += _feeGrowthGlobalX128; } if (uint128(_protocolFeeAmount) != 0) { gaugeFees.token0 += uint128(_protocolFeeAmount); } _notifyFeeAmount(token0, feeRate0, fee0, _protocolFeeAmount); // notify fee amount } if (paid1 != 0) { (uint256 _feeGrowthGlobalX128, uint256 _protocolFeeAmount) = _calculateFees(paid1, _liquidity); if (_feeGrowthGlobalX128 != 0) { feeGrowthGlobal1X128 += _feeGrowthGlobalX128; } if (uint128(_protocolFeeAmount) != 0) { gaugeFees.token1 += uint128(_protocolFeeAmount); } _notifyFeeAmount(token1, feeRate1, fee1, _protocolFeeAmount); // notify fee amount } emit Flash(msg.sender, recipient, amount0, amount1, paid0, paid1); } /// @inheritdoc ICLPoolState function getRewardGrowthInside(int24 tickLower, int24 tickUpper, uint256 _rewardGrowthGlobalX128) external view override returns (uint256 rewardGrowthInside) { checkTicks(tickLower, tickUpper); if (_rewardGrowthGlobalX128 == 0) { _rewardGrowthGlobalX128 = rewardGrowthGlobalX128; } return ticks.getRewardGrowthInside(tickLower, tickUpper, slot0.tick, _rewardGrowthGlobalX128); } /// @inheritdoc ICLPoolActions function updateRewardsGrowthGlobal() external override lock onlyGauge { _updateRewardsGrowthGlobal(); } /// @dev timeDelta != 0 handles case when function is called twice in the same block. /// @dev stakedLiquidity > 0 handles case when depositing staked liquidity and there is no liquidity staked yet, /// @dev or when notifying rewards when there is no liquidity stake function _updateRewardsGrowthGlobal() internal { uint32 timestamp = _blockTimestamp(); uint256 _lastUpdated = lastUpdated; uint256 timeDelta = timestamp - _lastUpdated; // skip if second call in same block if (timeDelta != 0) { uint256 _rewardReserve = rewardReserve; if (_rewardReserve != 0) { uint256 reward = rewardRate * timeDelta; if (reward > _rewardReserve) { reward = _rewardReserve; rewardReserve = 0; } else { rewardReserve -= reward; } uint128 _stakedLiquidity = stakedLiquidity; if (_stakedLiquidity != 0) { rewardGrowthGlobalX128 += FullMath.mulDiv(reward, FixedPoint128.Q128, _stakedLiquidity); } else { rollover += reward; } } lastUpdated = timestamp; } } /// @inheritdoc ICLPoolActions function syncReward( uint256 _rewardRate, uint256 _rewardReserve, uint256 _periodFinish ) external override lock onlyGauge { rewardRate = _rewardRate; rewardReserve = _rewardReserve; periodFinish = _periodFinish; delete rollover; } /* /// @notice Calculates the fees owed to staked liquidity, then calculates fee levied on unstaked liquidity /// @param feeAmount Total fees /// @param _liquidity Current liquidity in active tick /// @param _stakedLiquidity Current staked liquidity in active tick /// @return unstakedFeeAmount Fee amount for unstaked LPs after accounting for staked liquidity contribution and unstaked fee /// @return stakedFeeAmount Fee amount for staked LPs consisting of staked liquidity contribution and unstaked fee function splitFees(uint256 feeAmount, uint128 _liquidity, uint128 _stakedLiquidity) internal view returns (uint256 unstakedFeeAmount, uint256 stakedFeeAmount) { stakedFeeAmount = FullMath.mulDivRoundingUp(feeAmount, _stakedLiquidity, _liquidity); (unstakedFeeAmount, stakedFeeAmount) = applyUnstakedFees(feeAmount - stakedFeeAmount, stakedFeeAmount); } */ /* /// @notice Calculates fee for levied on unstaked liquidity only /// @param _unstakedFeeAmount Fee amount for unstaked LPs net of staked liquidity contribution /// @param _stakedFeeAmount Fee amount for staked LPs consisting of staked liquidity contribution /// @return unstakedFeeAmount Fee amount for unstaked LPs after accounting for staked liquidity contribution and unstaked fee /// @return stakedFeeAmount Fee amount for staked LPs consisting of staked liquidity contribution and unstaked fee function applyUnstakedFees(uint256 _unstakedFeeAmount, uint256 _stakedFeeAmount) internal view returns (uint256 unstakedFeeAmount, uint256 stakedFeeAmount) { uint256 _stakedFee = FullMath.mulDivRoundingUp(_unstakedFeeAmount, unstakedFee(), 1e6); unstakedFeeAmount = _unstakedFeeAmount - _stakedFee; stakedFeeAmount = _stakedFeeAmount + _stakedFee; } */ // calculates the protocol fee amount and fee growths function _calculateFees( uint256 _feeAmount, uint128 _liquidity/*, uint128 _stakedLiquidity*/ ) private view returns (uint256 _feeGrowthGlobalX128, uint256 _protocolFeeAmount) { // amount of protocol fees _protocolFeeAmount = FullMath.mulDivRoundingUp(_feeAmount, getProtocolFee(), 1e5); // amount of position accrued fees uint256 _positionFeeAmount = _feeAmount.sub(_protocolFeeAmount); // calculate fee growth _feeGrowthGlobalX128 = FullMath.mulDiv(_positionFeeAmount, FixedPoint128.Q128, _liquidity); /* // if there is only staked liquidity if (_liquidity == _stakedLiquidity) { stakedFeeAmount = _feeAmount; } // if there is only unstaked liquidity else if (_stakedLiquidity == 0) { (uint256 unstakedFeeAmount, uint256 _stakedFeeAmount) = applyUnstakedFees(_feeAmount, 0); feeGrowthGlobalX128 = FullMath.mulDiv(unstakedFeeAmount, FixedPoint128.Q128, _liquidity); stakedFeeAmount = _stakedFeeAmount; } // if there are staked and unstaked liquidities else { (uint256 unstakedFeeAmount, uint256 _stakedFeeAmount) = splitFees(_feeAmount, _liquidity, _stakedLiquidity); feeGrowthGlobalX128 = FullMath.mulDiv(unstakedFeeAmount, FixedPoint128.Q128, _liquidity - _stakedLiquidity); stakedFeeAmount = _stakedFeeAmount; } */ } /// @inheritdoc ICLPoolOwnerActions function collectFee(bool isTokenZero) external override lock returns (uint128 amount) { require(msg.sender == gauge || msg.sender == ISyncSwapRangePoolFactory(factory).feeCollector()); amount = isTokenZero ? gaugeFees.token0 : gaugeFees.token1; if (amount > 1) { // ensure that the slot is not cleared, for gas savings if (isTokenZero) { gaugeFees.token0 = 1; } else { gaugeFees.token1 = 1; } TransferHelper.safeTransfer(isTokenZero ? token0 : token1, msg.sender, --amount); } emit CollectFees(msg.sender, isTokenZero ? amount : 0, isTokenZero ? 0 : amount); } /// @inheritdoc ICLPoolActions function setGaugeAndPositionManager(address _gauge, address _nft) external override lock { require(gauge == address(0)); // ensures not initialized require(msg.sender == ISyncSwapRangePoolFactory(factory).gaugeFactory()); // only gauge factory gauge = _gauge; nft = _nft; } /// @dev Returns the verified sender address otherwise `address(0)`. function _getVerifiedSender(address _sender) private view returns (address) { if (_sender != msg.sender) { // The sender from non-forwarder is invalid. try IPoolMaster(master).isForwarder(msg.sender) returns (bool _isTrustedForwarder) { return _isTrustedForwarder ? _sender : msg.sender; } catch {} } return msg.sender; } function _getSwapFee(address _sender, address _tokenIn, address _tokenOut) private view returns (uint24 _swapFee) { _swapFee = getSwapFee(_sender, _tokenIn, _tokenOut, abi.encode(msg.sender)); } /// @dev This function doesn't check the forwarder. function getSwapFee(address _sender, address _tokenIn, address _tokenOut, bytes memory _data) public view override returns (uint24) { try ISyncSwapRangePoolFactory(factory).getSwapFee( address(this), _sender, _tokenIn, _tokenOut, _data ) returns (uint24 _swapFee) { return _swapFee; } catch { return 1000; // 0.1% } } /// @dev Compatibility function. Directional fee and sender forwarder is not supported. Use `getSwapFee()` instead. function fee() external view override returns (uint24) { return _getSwapFee(msg.sender, token0, token1); } function _notifyFeeAmount(address token, uint24 feeRate, uint256 tokenAmount, uint256 protocolFeeAmount) private { address _feeRecipient = _getFeeRecipient(); if (_feeRecipient != address(0)) { try IFeeRecipient(_feeRecipient).notifyFees(4, token, tokenAmount, feeRate, abi.encode(4)) {} catch {} emit FeeAmount(token, feeRate, tokenAmount, protocolFeeAmount); } } function _getFeeRecipient() private view returns (address) { try IPoolMaster(master).getFeeRecipient() returns (address _feeRecipient) { return _feeRecipient; } catch { return address(0); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import "./IVoter.sol"; /// @title The interface for the CL Factory /// @notice The CL Factory facilitates creation of CL pools and control over the protocol fees interface ISyncSwapRangePoolFactory { /// @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 ); function master() external view returns (address); /// @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); //function feeProvider() external view returns (address); function feeManager() external view returns (address); function feeCollector() external view returns (address); function poolCreator() external view returns (address); function gaugeFactory() external view returns (address); /// @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 defaultSwapFeeByTickSpacing(int24 tickSpacing) external view returns (uint24 fee); /// @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 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 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); function isPool(address pool) external view returns (bool); /// @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, address sender, address tokenIn, address tokenOut, bytes memory data ) external view returns (uint24); function getProtocolFee(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); }
// SPDX-License-Identifier: MIT pragma solidity =0.7.6; interface IFeeProvider { /// @dev Returns swap fee for the pool function getSwapFee( address master, address pool, address sender, address tokenIn, address tokenOut, bytes memory data ) external view returns (uint24); }
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity >=0.5.0; /// @notice The manager contract to control fees. /// Management functions are omitted. interface IFeeManagerV3 { struct FeeData { uint64 gamma; uint24 minFee; uint24 maxFee; } function getSwapFee( address pool, address sender, address tokenIn, address tokenOut, bytes calldata data ) external view returns (uint24); function getProtocolFee(address pool) external view returns (uint24); }
// SPDX-License-Identifier: MIT pragma solidity =0.7.6; pragma abicoder v2; import "./IVotingEscrow.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 (address); /// @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.6.0 <0.8.0; import "./Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
// SPDX-License-Identifier: MIT OR Apache-2.0 pragma solidity >=0.7.6; library ExcessivelySafeCall { uint256 constant LOW_28_MASK = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff; /// @notice Use when you _really_ really _really_ don't trust the called /// contract. This prevents the called contract from causing reversion of /// the caller in as many ways as we can. /// @dev The main difference between this and a solidity low-level call is /// that we limit the number of bytes that the callee can cause to be /// copied to caller memory. This prevents stupid things like malicious /// contracts returning 10,000,000 bytes causing a local OOG when copying /// to memory. /// @param _target The address to call /// @param _gas The amount of gas to forward to the remote contract /// @param _value The value in wei to send to the remote contract /// @param _maxCopy The maximum number of bytes of returndata to copy /// to memory. /// @param _calldata The data to send to the remote contract /// @return success and returndata, as `.call()`. Returndata is capped to /// `_maxCopy` bytes. function excessivelySafeCall( address _target, uint256 _gas, uint256 _value, uint16 _maxCopy, bytes memory _calldata ) internal returns (bool, bytes memory) { // set up for assembly call uint256 _toCopy; bool _success; bytes memory _returnData = new bytes(_maxCopy); // dispatch message to recipient // by assembly calling "handle" function // we call via assembly to avoid memcopying a very large returndata // returned by a malicious contract assembly { _success := call( _gas, // gas _target, // recipient _value, // ether value add(_calldata, 0x20), // inloc mload(_calldata), // inlen 0, // outloc 0 // outlen ) // limit our copy to 256 bytes _toCopy := returndatasize() if gt(_toCopy, _maxCopy) { _toCopy := _maxCopy } // Store the length of the copied bytes mstore(_returnData, _toCopy) // copy the bytes from returndata[0:_toCopy] returndatacopy(add(_returnData, 0x20), 0, _toCopy) } return (_success, _returnData); } /// @notice Use when you _really_ really _really_ don't trust the called /// contract. This prevents the called contract from causing reversion of /// the caller in as many ways as we can. /// @dev The main difference between this and a solidity low-level call is /// that we limit the number of bytes that the callee can cause to be /// copied to caller memory. This prevents stupid things like malicious /// contracts returning 10,000,000 bytes causing a local OOG when copying /// to memory. /// @param _target The address to call /// @param _gas The amount of gas to forward to the remote contract /// @param _maxCopy The maximum number of bytes of returndata to copy /// to memory. /// @param _calldata The data to send to the remote contract /// @return success and returndata, as `.call()`. Returndata is capped to /// `_maxCopy` bytes. function excessivelySafeStaticCall( address _target, uint256 _gas, uint16 _maxCopy, bytes memory _calldata ) internal view returns (bool, bytes memory) { // set up for assembly call uint256 _toCopy; bool _success; bytes memory _returnData = new bytes(_maxCopy); // dispatch message to recipient // by assembly calling "handle" function // we call via assembly to avoid memcopying a very large returndata // returned by a malicious contract assembly { _success := staticcall( _gas, // gas _target, // recipient add(_calldata, 0x20), // inloc mload(_calldata), // inlen 0, // outloc 0 // outlen ) // limit our copy to 256 bytes _toCopy := returndatasize() if gt(_toCopy, _maxCopy) { _toCopy := _maxCopy } // Store the length of the copied bytes mstore(_returnData, _toCopy) // copy the bytes from returndata[0:_toCopy] returndatacopy(add(_returnData, 0x20), 0, _toCopy) } return (_success, _returnData); } /** * @notice Swaps function selectors in encoded contract calls * @dev Allows reuse of encoded calldata for functions with identical * argument types but different names. It simply swaps out the first 4 bytes * for the new selector. This function modifies memory in place, and should * only be used with caution. * @param _newSelector The new 4-byte selector * @param _buf The encoded contract args */ function swapSelector(bytes4 _newSelector, bytes memory _buf) internal pure { require(_buf.length >= 4); uint256 _mask = LOW_28_MASK; assembly { // load the first word of let _word := mload(add(_buf, 0x20)) // mask out the top 4 bytes // /x _word := and(_word, _mask) _word := or(_newSelector, _word) mstore(add(_buf, 0x20), _word) } } }
// 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: GPL-2.0-or-later pragma solidity >=0.5.0; import "./ICLPoolConstants.sol"; import "./ICLPoolState.sol"; import "./ICLPoolDerivedState.sol"; import "./ICLPoolActions.sol"; import "./ICLPoolOwnerActions.sol"; import "./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 ISyncSwapRangePool is ICLPoolConstants, ICLPoolState, ICLPoolDerivedState, ICLPoolActions, ICLPoolEvents, ICLPoolOwnerActions {}
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity >=0.5.0; import "./IFeeManager.sol"; import "./IForwarderRegistry.sol"; /// @dev The master contract to create pools and manage whitelisted factories. /// Inheriting the fee manager interface to support fee queries. interface IPoolMaster is IFeeManager, IForwarderRegistry { event SetFactoryWhitelisted(address indexed factory, bool whitelisted); event RegisterPool( address indexed factory, address indexed pool, uint16 indexed poolType, bytes data ); event UpdateForwarderRegistry(address indexed newForwarderRegistry); event UpdateFeeManager(address indexed newFeeManager); function wETH() external view returns (address); function feeManager() external view returns (address); function pools(uint) external view returns (address); function poolsLength() external view returns (uint); // Forwarder Registry function setForwarderRegistry(address) external; // Fees function setFeeManager(address) external; // Factories function isFactoryWhitelisted(address) external view returns (bool); function setFactoryWhitelisted(address factory, bool whitelisted) external; // Pools function isPool(address) external view returns (bool); function getPool(bytes32) external view returns (address); function createPool(address factory, bytes calldata data) external returns (address pool); function registerPool(address pool, uint16 poolType, bytes calldata data, address token0, address token1) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0 <0.8.0; import "./external/LowGasSafeMath.sol"; import "./external/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, "G"); 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 <0.8.0; import "./external/FullMath.sol"; import "./external/FixedPoint128.sol"; import "./LiquidityMath.sol"; /// @title Position /// @notice Positions represent an owner address' liquidity between a lower and upper tick boundary /// @dev Positions store additional state for tracking fees owed to the position library Position { // info stored for each user's position struct Info { // the amount of liquidity owned by this position uint128 liquidity; // fee growth per unit of liquidity as of the last update to liquidity or fees owed uint256 feeGrowthInside0LastX128; uint256 feeGrowthInside1LastX128; // the fees owed to the position owner in token0/token1 uint128 tokensOwed0; uint128 tokensOwed1; } /// @notice Returns the Info struct of a position, given an owner and position boundaries /// @param self The mapping containing all user positions /// @param owner The address of the position owner /// @param tickLower The lower tick boundary of the position /// @param tickUpper The upper tick boundary of the position /// @return position The position info struct of the given owners' position function get(mapping(bytes32 => Info) storage self, address owner, int24 tickLower, int24 tickUpper) internal view returns (Position.Info storage position) { position = self[keccak256(abi.encodePacked(owner, tickLower, tickUpper))]; } /// @notice Credits accumulated fees to a user's position /// @param self The individual position to update /// @param liquidityDelta The change in pool liquidity as a result of the position update /// @param feeGrowthInside0X128 The all-time fee growth in token0, per unit of liquidity, inside the position's tick boundaries /// @param feeGrowthInside1X128 The all-time fee growth in token1, per unit of liquidity, inside the position's tick boundaries /// @param staked Signifies if the position is staked in the gauge or not function update( Info storage self, int128 liquidityDelta, uint256 feeGrowthInside0X128, uint256 feeGrowthInside1X128, bool staked ) internal { Info memory _self = self; uint128 liquidityNext; if (liquidityDelta == 0) { require(_self.liquidity != 0); // disallow pokes for 0 liquidity positions liquidityNext = _self.liquidity; } else { liquidityNext = LiquidityMath.addDelta(_self.liquidity, liquidityDelta); } uint128 tokensOwed0; uint128 tokensOwed1; if (!staked) { // calculate accumulated fees tokensOwed0 = uint128( FullMath.mulDiv( feeGrowthInside0X128 - _self.feeGrowthInside0LastX128, _self.liquidity, FixedPoint128.Q128 ) ); tokensOwed1 = uint128( FullMath.mulDiv( feeGrowthInside1X128 - _self.feeGrowthInside1LastX128, _self.liquidity, FixedPoint128.Q128 ) ); } // update the position if (liquidityDelta != 0) self.liquidity = liquidityNext; self.feeGrowthInside0LastX128 = feeGrowthInside0X128; self.feeGrowthInside1LastX128 = feeGrowthInside1X128; if (tokensOwed0 > 0 || tokensOwed1 > 0) { // overflow is acceptable, have to withdraw before you hit type(uint128).max fees self.tokensOwed0 += tokensOwed0; self.tokensOwed1 += tokensOwed1; } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import "./external/BitMath.sol"; /// @title Packed tick initialized state library /// @notice Stores a packed mapping of tick index to its initialized state /// @dev The mapping uses int16 for keys since ticks are represented as int24 and there are 256 (2^8) values per word. library TickBitmap { /// @notice Computes the position in the mapping where the initialized bit for a tick lives /// @param tick The tick for which to compute the position /// @return wordPos The key in the mapping containing the word in which the bit is stored /// @return bitPos The bit position in the word where the flag is stored function position(int24 tick) private pure returns (int16 wordPos, uint8 bitPos) { wordPos = int16(tick >> 8); bitPos = uint8(tick % 256); } /// @notice Flips the initialized state for a given tick from false to true, or vice versa /// @param self The mapping in which to flip the tick /// @param tick The tick to flip /// @param tickSpacing The spacing between usable ticks function flipTick(mapping(int16 => uint256) storage self, int24 tick, int24 tickSpacing) internal { require(tick % tickSpacing == 0); // ensure that the tick is spaced (int16 wordPos, uint8 bitPos) = position(tick / tickSpacing); uint256 mask = 1 << bitPos; self[wordPos] ^= mask; } /// @notice Returns the next initialized tick contained in the same word (or adjacent word) as the tick that is either /// to the left (less than or equal to) or right (greater than) of the given tick /// @param self The mapping in which to compute the next initialized tick /// @param tick The starting tick /// @param tickSpacing The spacing between usable ticks /// @param lte Whether to search for the next initialized tick to the left (less than or equal to the starting tick) /// @return next The next initialized or uninitialized tick up to 256 ticks away from the current tick /// @return initialized Whether the next tick is initialized, as the function only searches within up to 256 ticks function nextInitializedTickWithinOneWord( mapping(int16 => uint256) storage self, int24 tick, int24 tickSpacing, bool lte ) internal view returns (int24 next, bool initialized) { int24 compressed = tick / tickSpacing; if (tick < 0 && tick % tickSpacing != 0) compressed--; // round towards negative infinity if (lte) { (int16 wordPos, uint8 bitPos) = position(compressed); // all the 1s at or to the right of the current bitPos uint256 mask = (1 << bitPos) - 1 + (1 << bitPos); uint256 masked = self[wordPos] & mask; // if there are no initialized ticks to the right of or at the current tick, return rightmost in the word initialized = masked != 0; // overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick next = initialized ? (compressed - int24(bitPos - BitMath.mostSignificantBit(masked))) * tickSpacing : (compressed - int24(bitPos)) * tickSpacing; } else { // start from the word of the next tick, since the current tick state doesn't matter (int16 wordPos, uint8 bitPos) = position(compressed + 1); // all the 1s at or to the left of the bitPos uint256 mask = ~((1 << bitPos) - 1); uint256 masked = self[wordPos] & mask; // if there are no initialized ticks to the left of the current tick, return leftmost in the word initialized = masked != 0; // overflow/underflow is possible, but prevented externally by limiting both tickSpacing and tick next = initialized ? (compressed + 1 + int24(BitMath.leastSignificantBit(masked) - bitPos)) * tickSpacing : (compressed + 1 + int24(type(uint8).max - bitPos)) * tickSpacing; } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0 <0.8.0; /// @title Oracle /// @notice Provides price and liquidity data useful for a wide variety of system designs /// @dev Instances of stored oracle data, "observations", are collected in the oracle array /// Every pool is initialized with an oracle array length of 1. Anyone can pay the SSTOREs to increase the /// maximum length of the oracle array. New slots will be added when the array is fully populated. /// Observations are overwritten when the full length of the oracle array is populated. /// The most recent observation is available, independent of the length of the oracle array, by passing 0 to observe() library Oracle { struct Observation { // the block timestamp of the observation uint32 blockTimestamp; // the tick accumulator, i.e. tick * time elapsed since the pool was first initialized int56 tickCumulative; // the seconds per liquidity, i.e. seconds elapsed / max(1, liquidity) since the pool was first initialized uint160 secondsPerLiquidityCumulativeX128; // whether or not the observation is initialized bool initialized; } /// @notice Transforms a previous observation into a new observation, given the passage of time and the current tick and liquidity values /// @dev blockTimestamp _must_ be chronologically equal to or greater than last.blockTimestamp, safe for 0 or 1 overflows /// @param last The specified observation to be transformed /// @param blockTimestamp The timestamp of the new observation /// @param tick The active tick at the time of the new observation /// @param liquidity The total in-range liquidity at the time of the new observation /// @return Observation The newly populated observation function transform(Observation memory last, uint32 blockTimestamp, int24 tick, uint128 liquidity) private pure returns (Observation memory) { uint32 delta = blockTimestamp - last.blockTimestamp; return Observation({ blockTimestamp: blockTimestamp, tickCumulative: last.tickCumulative + int56(tick) * delta, secondsPerLiquidityCumulativeX128: last.secondsPerLiquidityCumulativeX128 + ((uint160(delta) << 128) / (liquidity > 0 ? liquidity : 1)), initialized: true }); } /// @notice Initialize the oracle array by writing the first slot. Called once for the lifecycle of the observations array /// @param self The stored oracle array /// @param time The time of the oracle initialization, via block.timestamp truncated to uint32 /// @return cardinality The number of populated elements in the oracle array /// @return cardinalityNext The new length of the oracle array, independent of population function initialize(Observation[65535] storage self, uint32 time) internal returns (uint16 cardinality, uint16 cardinalityNext) { self[0] = Observation({ blockTimestamp: time, tickCumulative: 0, secondsPerLiquidityCumulativeX128: 0, initialized: true }); return (1, 1); } /// @notice Writes an oracle observation to the array /// @dev Writable at most once per block. Index represents the most recently written element. cardinality and index must be tracked externally. /// If the index is at the end of the allowable array length (according to cardinality), and the next cardinality /// is greater than the current one, cardinality may be increased. This restriction is created to preserve ordering. /// @param self The stored oracle array /// @param index The index of the observation that was most recently written to the observations array /// @param blockTimestamp The timestamp of the new observation /// @param tick The active tick at the time of the new observation /// @param liquidity The total in-range liquidity at the time of the new observation /// @param cardinality The number of populated elements in the oracle array /// @param cardinalityNext The new length of the oracle array, independent of population /// @return indexUpdated The new index of the most recently written element in the oracle array /// @return cardinalityUpdated The new cardinality of the oracle array function write( Observation[65535] storage self, uint16 index, uint32 blockTimestamp, int24 tick, uint128 liquidity, uint16 cardinality, uint16 cardinalityNext ) internal returns (uint16 indexUpdated, uint16 cardinalityUpdated) { Observation memory last = self[index]; // early return if we've already written an observation this block if (last.blockTimestamp == blockTimestamp) return (index, cardinality); // if the conditions are right, we can bump the cardinality if (cardinalityNext > cardinality && index == (cardinality - 1)) { cardinalityUpdated = cardinalityNext; } else { cardinalityUpdated = cardinality; } indexUpdated = (index + 1) % cardinalityUpdated; self[indexUpdated] = transform(last, blockTimestamp, tick, liquidity); } /// @notice Prepares the oracle array to store up to `next` observations /// @param self The stored oracle array /// @param current The current next cardinality of the oracle array /// @param next The proposed next cardinality which will be populated in the oracle array /// @return next The next cardinality which will be populated in the oracle array function grow(Observation[65535] storage self, uint16 current, uint16 next) internal returns (uint16) { require(current != 0); // no-op if the passed next value isn't greater than the current next value if (next <= current) return current; // store in each slot to prevent fresh SSTOREs in swaps // this data will not be used because the initialized boolean is still false for (uint16 i = current; i < next; i++) { self[i].blockTimestamp = 1; } return next; } /// @notice comparator for 32-bit timestamps /// @dev safe for 0 or 1 overflows, a and b _must_ be chronologically before or equal to time /// @param time A timestamp truncated to 32 bits /// @param a A comparison timestamp from which to determine the relative position of `time` /// @param b From which to determine the relative position of `time` /// @return bool Whether `a` is chronologically <= `b` function lte(uint32 time, uint32 a, uint32 b) private pure returns (bool) { // if there hasn't been overflow, no need to adjust if (a <= time && b <= time) return a <= b; uint256 aAdjusted = a > time ? a : a + 2 ** 32; uint256 bAdjusted = b > time ? b : b + 2 ** 32; return aAdjusted <= bAdjusted; } /// @notice Fetches the observations beforeOrAt and atOrAfter a target, i.e. where [beforeOrAt, atOrAfter] is satisfied. /// The result may be the same observation, or adjacent observations. /// @dev The answer must be contained in the array, used when the target is located within the stored observation /// boundaries: older than the most recent observation and younger, or the same age as, the oldest observation /// @param self The stored oracle array /// @param time The current block.timestamp /// @param target The timestamp at which the reserved observation should be for /// @param index The index of the observation that was most recently written to the observations array /// @param cardinality The number of populated elements in the oracle array /// @return beforeOrAt The observation recorded before, or at, the target /// @return atOrAfter The observation recorded at, or after, the target function binarySearch(Observation[65535] storage self, uint32 time, uint32 target, uint16 index, uint16 cardinality) private view returns (Observation memory beforeOrAt, Observation memory atOrAfter) { uint256 l = (index + 1) % cardinality; // oldest observation uint256 r = l + cardinality - 1; // newest observation uint256 i; while (true) { i = (l + r) / 2; beforeOrAt = self[i % cardinality]; // we've landed on an uninitialized tick, keep searching higher (more recently) if (!beforeOrAt.initialized) { l = i + 1; continue; } atOrAfter = self[(i + 1) % cardinality]; bool targetAtOrAfter = lte(time, beforeOrAt.blockTimestamp, target); // check if we've found the answer! if (targetAtOrAfter && lte(time, target, atOrAfter.blockTimestamp)) break; if (!targetAtOrAfter) r = i - 1; else l = i + 1; } } /// @notice Fetches the observations beforeOrAt and atOrAfter a given target, i.e. where [beforeOrAt, atOrAfter] is satisfied /// @dev Assumes there is at least 1 initialized observation. /// Used by observeSingle() to compute the counterfactual accumulator values as of a given block timestamp. /// @param self The stored oracle array /// @param time The current block.timestamp /// @param target The timestamp at which the reserved observation should be for /// @param tick The active tick at the time of the returned or simulated observation /// @param index The index of the observation that was most recently written to the observations array /// @param liquidity The total pool liquidity at the time of the call /// @param cardinality The number of populated elements in the oracle array /// @return beforeOrAt The observation which occurred at, or before, the given timestamp /// @return atOrAfter The observation which occurred at, or after, the given timestamp function getSurroundingObservations( Observation[65535] storage self, uint32 time, uint32 target, int24 tick, uint16 index, uint128 liquidity, uint16 cardinality ) private view returns (Observation memory beforeOrAt, Observation memory atOrAfter) { // optimistically set before to the newest observation beforeOrAt = self[index]; // if the target is chronologically at or after the newest observation, we can early return if (lte(time, beforeOrAt.blockTimestamp, target)) { if (beforeOrAt.blockTimestamp == target) { // if newest observation equals target, we're in the same block, so we can ignore atOrAfter return (beforeOrAt, atOrAfter); } else { // otherwise, we need to transform return (beforeOrAt, transform(beforeOrAt, target, tick, liquidity)); } } // now, set before to the oldest observation beforeOrAt = self[(index + 1) % cardinality]; if (!beforeOrAt.initialized) beforeOrAt = self[0]; // ensure that the target is chronologically at or after the oldest observation require(lte(time, beforeOrAt.blockTimestamp, target), "O"); // if we've reached this point, we have to binary search return binarySearch(self, time, target, index, cardinality); } /// @dev Reverts if an observation at or before the desired observation timestamp does not exist. /// 0 may be passed as `secondsAgo' to return the current cumulative values. /// If called with a timestamp falling between two observations, returns the counterfactual accumulator values /// at exactly the timestamp between the two observations. /// @param self The stored oracle array /// @param time The current block timestamp /// @param secondsAgo The amount of time to look back, in seconds, at which point to return an observation /// @param tick The current tick /// @param index The index of the observation that was most recently written to the observations array /// @param liquidity The current in-range pool liquidity /// @param cardinality The number of populated elements in the oracle array /// @return tickCumulative The tick * time elapsed since the pool was first initialized, as of `secondsAgo` /// @return secondsPerLiquidityCumulativeX128 The time elapsed / max(1, liquidity) since the pool was first initialized, as of `secondsAgo` function observeSingle( Observation[65535] storage self, uint32 time, uint32 secondsAgo, int24 tick, uint16 index, uint128 liquidity, uint16 cardinality ) internal view returns (int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128) { if (secondsAgo == 0) { Observation memory last = self[index]; if (last.blockTimestamp != time) last = transform(last, time, tick, liquidity); return (last.tickCumulative, last.secondsPerLiquidityCumulativeX128); } uint32 target = time - secondsAgo; (Observation memory beforeOrAt, Observation memory atOrAfter) = getSurroundingObservations(self, time, target, tick, index, liquidity, cardinality); if (target == beforeOrAt.blockTimestamp) { // we're at the left boundary return (beforeOrAt.tickCumulative, beforeOrAt.secondsPerLiquidityCumulativeX128); } else if (target == atOrAfter.blockTimestamp) { // we're at the right boundary return (atOrAfter.tickCumulative, atOrAfter.secondsPerLiquidityCumulativeX128); } else { // we're in the middle uint32 observationTimeDelta = atOrAfter.blockTimestamp - beforeOrAt.blockTimestamp; uint32 targetDelta = target - beforeOrAt.blockTimestamp; return ( beforeOrAt.tickCumulative + ((atOrAfter.tickCumulative - beforeOrAt.tickCumulative) / observationTimeDelta) * targetDelta, beforeOrAt.secondsPerLiquidityCumulativeX128 + uint160( ( uint256( atOrAfter.secondsPerLiquidityCumulativeX128 - beforeOrAt.secondsPerLiquidityCumulativeX128 ) * targetDelta ) / observationTimeDelta ) ); } } /// @notice Returns the accumulator values as of each time seconds ago from the given time in the array of `secondsAgos` /// @dev Reverts if `secondsAgos` > oldest observation /// @param self The stored oracle array /// @param time The current block.timestamp /// @param secondsAgos Each amount of time to look back, in seconds, at which point to return an observation /// @param tick The current tick /// @param index The index of the observation that was most recently written to the observations array /// @param liquidity The current in-range pool liquidity /// @param cardinality The number of populated elements in the oracle array /// @return tickCumulatives The tick * time elapsed since the pool was first initialized, as of each `secondsAgo` /// @return secondsPerLiquidityCumulativeX128s The cumulative seconds / max(1, liquidity) since the pool was first initialized, as of each `secondsAgo` function observe( Observation[65535] storage self, uint32 time, uint32[] memory secondsAgos, int24 tick, uint16 index, uint128 liquidity, uint16 cardinality ) internal view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) { require(cardinality != 0); tickCumulatives = new int56[](secondsAgos.length); secondsPerLiquidityCumulativeX128s = new uint160[](secondsAgos.length); for (uint256 i = 0; i < secondsAgos.length; i++) { (tickCumulatives[i], secondsPerLiquidityCumulativeX128s[i]) = observeSingle(self, time, secondsAgos[i], tick, index, liquidity, cardinality); } } }
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity >=0.5.0; interface IFeeRecipient { /// @dev Notifies the fee recipient after sent fees. function notifyFees( uint16 feeType, address token, uint amount, uint feeRate, bytes calldata data ) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Callback for ICLPoolActions#mint /// @notice Any contract that calls ICLPoolActions#mint must implement this interface interface ICLMintCallback { /// @notice Called to `msg.sender` after minting liquidity to a position from ICLPool#mint. /// @dev In the implementation you must pay the pool tokens owed for the minted liquidity. /// The caller of this method must be checked to be a CLPool deployed by the canonical SyncSwapRangePoolFactory. /// @param amount0Owed The amount of token0 due to the pool for the minted liquidity /// @param amount1Owed The amount of token1 due to the pool for the minted liquidity /// @param data Any data passed through by the caller via the ICLPoolActions#mint call function uniswapV3MintCallback(uint256 amount0Owed, uint256 amount1Owed, bytes calldata data) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import "./external/LowGasSafeMath.sol"; import "./external/SafeCast.sol"; import "./external/FullMath.sol"; import "./external/UnsafeMath.sol"; import "./external/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; import "./external/FullMath.sol"; import "./SqrtPriceMath.sol"; /// @title Computes the result of a swap within ticks /// @notice Contains methods for computing the result of a swap within a single tick price range, i.e., a single tick. library SwapMath { /// @notice Computes the result of swapping some amount in, or amount out, given the parameters of the swap /// @dev The fee, plus the amount in, will never exceed the amount remaining if the swap's `amountSpecified` is positive /// @param sqrtRatioCurrentX96 The current sqrt price of the pool /// @param sqrtRatioTargetX96 The price that cannot be exceeded, from which the direction of the swap is inferred /// @param liquidity The usable liquidity /// @param amountRemaining How much input or output amount is remaining to be swapped in/out /// @param feePips The fee taken from the input amount, expressed in pips /// @return sqrtRatioNextX96 The price after swapping the amount in/out, not to exceed the price target /// @return amountIn The amount to be swapped in, of either token0 or token1, based on the direction of the swap /// @return amountOut The amount to be received, of either token0 or token1, based on the direction of the swap /// @return feeAmount The amount of input that will be taken as a fee function computeSwapStep( uint160 sqrtRatioCurrentX96, uint160 sqrtRatioTargetX96, uint128 liquidity, int256 amountRemaining, uint24 feePips ) internal pure returns (uint160 sqrtRatioNextX96, uint256 amountIn, uint256 amountOut, uint256 feeAmount) { bool zeroForOne = sqrtRatioCurrentX96 >= sqrtRatioTargetX96; bool exactIn = amountRemaining >= 0; if (exactIn) { uint256 amountRemainingLessFee = FullMath.mulDiv(uint256(amountRemaining), 1e6 - feePips, 1e6); amountIn = zeroForOne ? SqrtPriceMath.getAmount0Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, true) : SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, true); if (amountRemainingLessFee >= amountIn) { sqrtRatioNextX96 = sqrtRatioTargetX96; } else { sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromInput( sqrtRatioCurrentX96, liquidity, amountRemainingLessFee, zeroForOne ); } } else { amountOut = zeroForOne ? SqrtPriceMath.getAmount1Delta(sqrtRatioTargetX96, sqrtRatioCurrentX96, liquidity, false) : SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioTargetX96, liquidity, false); if (uint256(-amountRemaining) >= amountOut) { sqrtRatioNextX96 = sqrtRatioTargetX96; } else { sqrtRatioNextX96 = SqrtPriceMath.getNextSqrtPriceFromOutput( sqrtRatioCurrentX96, liquidity, uint256(-amountRemaining), zeroForOne ); } } bool max = sqrtRatioTargetX96 == sqrtRatioNextX96; // get the input/output amounts if (zeroForOne) { amountIn = max && exactIn ? amountIn : SqrtPriceMath.getAmount0Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, true); amountOut = max && !exactIn ? amountOut : SqrtPriceMath.getAmount1Delta(sqrtRatioNextX96, sqrtRatioCurrentX96, liquidity, false); } else { amountIn = max && exactIn ? amountIn : SqrtPriceMath.getAmount1Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, true); amountOut = max && !exactIn ? amountOut : SqrtPriceMath.getAmount0Delta(sqrtRatioCurrentX96, sqrtRatioNextX96, liquidity, false); } // cap the output amount to not exceed the remaining output amount if (!exactIn && amountOut > uint256(-amountRemaining)) { amountOut = uint256(-amountRemaining); } if (exactIn && sqrtRatioNextX96 != sqrtRatioTargetX96) { // we didn't reach the target, so take the remainder of the maximum input as fee feeAmount = uint256(amountRemaining) - amountIn; } else { feeAmount = FullMath.mulDivRoundingUp(amountIn, feePips, 1e6 - feePips); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Minimal ERC20 interface for CL /// @notice Contains a subset of the full ERC20 interface that is used in CL interface IERC20Minimal { /// @notice Returns the balance of a token /// @param account The account for which to look up the number of tokens it has, i.e. its balance /// @return The number of tokens held by the account function balanceOf(address account) external view returns (uint256); /// @notice Transfers the amount of token from the `msg.sender` to the recipient /// @param recipient The account that will receive the amount transferred /// @param amount The number of tokens to send from the sender to the recipient /// @return Returns true for a successful transfer, false for an unsuccessful transfer function transfer(address recipient, uint256 amount) external returns (bool); /// @notice Returns the current allowance given to a spender by an owner /// @param owner The account of the token owner /// @param spender The account of the token spender /// @return The current allowance granted by `owner` to `spender` function allowance(address owner, address spender) external view returns (uint256); /// @notice Sets the allowance of a spender from the `msg.sender` to the value `amount` /// @param spender The account which will be allowed to spend a given amount of the owners tokens /// @param amount The amount of tokens allowed to be used by `spender` /// @return Returns true for a successful approval, false for unsuccessful function approve(address spender, uint256 amount) external returns (bool); /// @notice Transfers `amount` tokens from `sender` to `recipient` up to the allowance given to the `msg.sender` /// @param sender The account from which the transfer will be initiated /// @param recipient The recipient of the transfer /// @param amount The amount of the transfer /// @return Returns true for a successful transfer, false for unsuccessful function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /// @notice Event emitted when tokens are transferred from one address to another, either via `#transfer` or `#transferFrom`. /// @param from The account from which the tokens were sent, i.e. the balance decreased /// @param to The account to which the tokens were sent, i.e. the balance increased /// @param value The amount of tokens that were transferred event Transfer(address indexed from, address indexed to, uint256 value); /// @notice Event emitted when the approval amount for the spender of a given owner's tokens changes. /// @param owner The account that approved spending of its tokens /// @param spender The account for which the spending allowance was modified /// @param value The new allowance from the owner to the spender event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Callback for ICLPoolActions#flash /// @notice Any contract that calls ICLPoolActions#flash must implement this interface interface ICLFlashCallback { /// @notice Called to `msg.sender` after transferring to the recipient from ICLPool#flash. /// @dev In the implementation you must repay the pool the tokens sent by flash plus the computed fee amounts. /// The caller of this method must be checked to be a CLPool deployed by the canonical SyncSwapRangePoolFactory. /// @param fee0 The fee amount in token0 due to the pool by the end of the flash /// @param fee1 The fee amount in token1 due to the pool by the end of the flash /// @param data Any data passed through by the caller via the ICLPoolActions#flash call function uniswapV3FlashCallback(uint256 fee0, uint256 fee1, bytes calldata data) external; }
// 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, "S"); } else { require((z = x + uint128(y)) >= x, "A"); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Callback for ICLPoolActions#swap /// @notice Any contract that calls ICLPoolActions#swap must implement this interface interface ICLSwapCallback { /// @notice Called to `msg.sender` after executing a swap via ICLPool#swap. /// @dev In the implementation you must pay the pool tokens owed for the swap. /// The caller of this method must be checked to be a CLPool deployed by the canonical SyncSwapRangePoolFactory. /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped. /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token0 to the pool. /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token1 to the pool. /// @param data Any data passed through by the caller via the ICLPoolActions#swap call function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external; }
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity >=0.5.0; pragma abicoder v2; /// @dev The callback interface for SyncSwap base pool operations. /// Note additional checks will be required for some callbacks, see below for more information. /// Visit the documentation https://syncswap.gitbook.io/api-documentation/ for more details. interface ISyncSwapBaseCallback { struct BaseSwapCallbackParams { address sender; address to; address tokenIn; address tokenOut; uint reserve0; uint reserve1; uint balance0; uint balance1; uint amountIn; uint amountOut; uint feeIn; uint24 swapFee; uint8 withdrawMode; bytes callbackData; } function syncSwapBaseSwapCallback(BaseSwapCallbackParams calldata params) external; }
// 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); } /// @notice Cast a uint128 to an int128, revert on overflow /// @param y The uint128 to be cast /// @return z The cast integer, now type int128 function toInt128(uint128 y) internal pure returns (int128 z) { require(y < 2 ** 127); z = int128(y); } }
// 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: 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.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.6.0; import "../../interfaces/external/IERC20Minimal.sol"; /// @title TransferHelper /// @notice Contains helper methods for interacting with ERC20 tokens that do not consistently return true/false library TransferHelper { /// @notice Transfers tokens from msg.sender to a recipient /// @dev Calls transfer on token contract, errors with TF if transfer fails /// @param token The contract address of the token which will be transferred /// @param to The recipient of the transfer /// @param value The value of the transfer function safeTransfer(address token, address to, uint256 value) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20Minimal.transfer.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), "TF"); } /// @notice Transfers tokens from the targeted address to the given destination /// @notice Errors with 'STF' if transfer fails /// @param token The contract address of the token to be transferred /// @param from The originating address from which the tokens will be transferred /// @param to The destination address of the transfer /// @param value The amount to be transferred function safeTransferFrom(address token, address from, address to, uint256 value) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20Minimal.transferFrom.selector, from, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), "STF"); } /// @notice Approves the stipulated contract to spend the given allowance in the given token /// @dev Errors with 'SA' if transfer fails /// @param token The contract address of the token to be approved /// @param to The target of the approval /// @param value The amount of the given token the target will be allowed to spend function safeApprove(address token, address to, uint256 value) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20Minimal.approve.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), "SA"); } /// @notice Transfers ETH to the recipient address /// @dev Fails with `STE` /// @param to The destination of the transfer /// @param value The value to be transferred function safeTransferETH(address to, uint256 value) internal { (bool success,) = to.call{value: value}(""); require(success, "STE"); } }
// 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: MIT pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
// 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 { function factory() external view returns (address); function master() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function gauge() external view returns (address); function nft() 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 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 getSwapFee(address sender, address tokenIn, address tokenOut, bytes memory data) external view returns (uint24); 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 getProtocolFee() 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.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 amount The gauge fee collected in token function collectFee(bool isTokenZero) external returns (uint128 amount); }
// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity >=0.5.0; interface IForwarderRegistry { function isForwarder(address forwarder) external view returns (bool); }
// 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); event FeeAmount(address indexed token, uint24 indexed feeRate, uint256 totalFeeAmount, uint256 protocolFeeAmount); }
// 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); function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data, address sender, address callback, bytes calldata callbackData ) 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 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: AGPL-3.0-or-later pragma solidity >=0.5.0; /// @notice The manager contract to control fees. /// Management functions are omitted. interface IFeeManager { function getSwapFee( address pool, address sender, address tokenIn, address tokenOut, bytes calldata data ) external view returns (uint24); function getProtocolFee(address pool) external view returns (uint24); function getFeeRecipient() external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Math functions that do not check inputs or outputs /// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks library UnsafeMath { /// @notice Returns ceil(x / y) /// @dev division by 0 has unspecified behavior, and must be checked externally /// @param x The dividend /// @param y The divisor /// @return z The quotient, ceil(x / y) function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) { assembly { z := add(div(x, y), gt(mod(x, y), 0)) } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title BitMath /// @dev This library provides functionality for computing bit properties of an unsigned integer library BitMath { /// @notice Returns the index of the most significant bit of the number, /// where the least significant bit is at index 0 and the most significant bit is at index 255 /// @dev The function satisfies the property: /// x >= 2**mostSignificantBit(x) and x < 2**(mostSignificantBit(x)+1) /// @param x the value for which to compute the most significant bit, must be greater than 0 /// @return r the index of the most significant bit function mostSignificantBit(uint256 x) internal pure returns (uint8 r) { require(x > 0); if (x >= 0x100000000000000000000000000000000) { x >>= 128; r += 128; } if (x >= 0x10000000000000000) { x >>= 64; r += 64; } if (x >= 0x100000000) { x >>= 32; r += 32; } if (x >= 0x10000) { x >>= 16; r += 16; } if (x >= 0x100) { x >>= 8; r += 8; } if (x >= 0x10) { x >>= 4; r += 4; } if (x >= 0x4) { x >>= 2; r += 2; } if (x >= 0x2) r += 1; } /// @notice Returns the index of the least significant bit of the number, /// where the least significant bit is at index 0 and the most significant bit is at index 255 /// @dev The function satisfies the property: /// (x & 2**leastSignificantBit(x)) != 0 and (x & (2**(leastSignificantBit(x)) - 1)) == 0) /// @param x the value for which to compute the least significant bit, must be greater than 0 /// @return r the index of the least significant bit function leastSignificantBit(uint256 x) internal pure returns (uint8 r) { require(x > 0); r = 255; if (x & type(uint128).max > 0) { r -= 128; } else { x >>= 128; } if (x & type(uint64).max > 0) { r -= 64; } else { x >>= 64; } if (x & type(uint32).max > 0) { r -= 32; } else { x >>= 32; } if (x & type(uint16).max > 0) { r -= 16; } else { x >>= 16; } if (x & type(uint8).max > 0) { r -= 8; } else { x >>= 8; } if (x & 0xf > 0) { r -= 4; } else { x >>= 4; } if (x & 0x3 > 0) { r -= 2; } else { x >>= 2; } if (x & 0x1 > 0) r -= 1; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title 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; }
{ "viaIR": false, "optimizer": { "enabled": true, "mode": "3" }, "outputSelection": { "*": { "*": [ "abi", "metadata" ], "": [ "ast" ] } }, "isSystem": false, "forceEvmla": false }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_master","type":"address"},{"internalType":"address","name":"_poolImplementation","type":"address"},{"internalType":"address","name":"_feeManager","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token0","type":"address"},{"indexed":true,"internalType":"address","name":"token1","type":"address"},{"indexed":true,"internalType":"int24","name":"tickSpacing","type":"int24"},{"indexed":false,"internalType":"address","name":"pool","type":"address"}],"name":"PoolCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousValue","type":"address"},{"indexed":true,"internalType":"address","name":"newValue","type":"address"}],"name":"SetFeeCollector","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousValue","type":"address"},{"indexed":true,"internalType":"address","name":"newValue","type":"address"}],"name":"SetFeeManager","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousValue","type":"address"},{"indexed":true,"internalType":"address","name":"newValue","type":"address"}],"name":"SetGaugeFactory","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousValue","type":"address"},{"indexed":true,"internalType":"address","name":"newValue","type":"address"}],"name":"SetPoolCreator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"int24","name":"tickSpacing","type":"int24"},{"indexed":true,"internalType":"uint24","name":"fee","type":"uint24"}],"name":"SetTickSpacingDefaultSwapFee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"int24","name":"tickSpacing","type":"int24"},{"indexed":true,"internalType":"uint24","name":"fee","type":"uint24"}],"name":"TickSpacingEnabled","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"_tickSpacings","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allPools","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allPoolsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"createPool","outputs":[{"internalType":"address","name":"pool","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"int24","name":"tickSpacing","type":"int24"},{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"name":"createPool","outputs":[{"internalType":"address","name":"pool","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"","type":"int24"}],"name":"defaultSwapFeeByTickSpacing","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"_tickSpacing","type":"int24"},{"internalType":"uint24","name":"_fee","type":"uint24"}],"name":"enableTickSpacing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeCollector","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gaugeFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"getPairPools","outputs":[{"components":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"int24","name":"tickSpacing","type":"int24"}],"internalType":"struct SyncSwapRangePoolFactoryZKSync.PoolInfo[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"int24","name":"","type":"int24"}],"name":"getPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"}],"name":"getProtocolFee","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"address","name":"_sender","type":"address"},{"internalType":"address","name":"_tokenIn","type":"address"},{"internalType":"address","name":"_tokenOut","type":"address"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"getSwapFee","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"isPair","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isPool","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"master","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"pairPools","outputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"int24","name":"tickSpacing","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"pairPoolsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolCreator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"_tickSpacing","type":"int24"},{"internalType":"uint24","name":"_fee","type":"uint24"}],"name":"setDefaultSwapFeeForTickSpacing","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeCollector","type":"address"}],"name":"setFeeCollector","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeManager","type":"address"}],"name":"setFeeManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_gaugeFactory","type":"address"}],"name":"setGaugeFactory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_poolCreator","type":"address"}],"name":"setPoolCreator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"tickSpacings","outputs":[{"internalType":"int24[]","name":"","type":"int24[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tickSpacingsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
9c4d535b000000000000000000000000000000000000000000000000000000000000000001000451e615b0032cf9c95b8e3fcd65daac9170fc03bc9929df1d60238b1a58000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000600000000000000000000000009012c7ce4d1f677aaf9241cf7d4d05fc596556e8000000000000000000000000000000000000000000000000000000000000000100000000000000000000000061bafc2f483cdb6c6710426d15cf11fb6acf49f7
Deployed Bytecode
0x000400000000000200030000000000020000006004100270000003db0340019700030000003103550002000000010355000003db0040019d00000001002001900000000b0000c13d00000000010000190f6801d80000040f000000c004000039000000400040043f0000000002000416000000000002004b000001bc0000c13d0000001f0530018f000003dc06300198000000c002600039000000190000613d000000000701034f000000007807043c0000000004840436000000000024004b000000150000c13d000000000005004b000000260000613d000000000161034f0000000304500210000000000502043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000120435000000c001300039000000400010043f0000005f0030008c000001bc0000a13d000000c00200043d000003de0020009c000001bc0000813d000000e00300043d000003dd0030009c000001bc0000213d000001000400043d000003dd0040009c000001bc0000213d000300000002001d000000000200041a000003df02200197000100000004001d0000000004000411000003dd06400197000000000262019f000000000020041b000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d02000039000200000003001d0000000303000039000003e10400004100000000050000190f680f5e0000040f0000000104000029000000020300002900000001002001900000000302000029000001bc0000613d000003dd00200198000000400100043d000001be0000613d000003dd00300198000001be0000613d000003dd054001970000006002200210000000800020043f0000006002300210000000a00020043f0000000203000039000000000203041a000003df022001970000000004000411000000000242019f000000000023041b0000000303000039000000000203041a000003df02200197000000000242019f000000000023041b0000000104000039000000000204041a000003df02200197000000000252019f000000000024041b000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d02000039000003e40400004100000000060500190f680f5e0000040f0000000100200190000001bc0000613d0000000101000039000000000010043f0000000501000039000000200010043f000003e501000041000000000201041a000003e600200198000001c10000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000502041a000000000445016f000000010330020f000000000334019f000000000032041b000000000201041a000003e80220019700000064022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d02000039000000030300003900000001050000390000006406000039000003e9040000410f680f5e0000040f0000000100200190000001bc0000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d02000039000000030300003900000001050000390000006406000039000003ea040000410f680f5e0000040f0000000100200190000001bc0000613d0000003201000039000000000010043f0000000501000039000000200010043f000003eb01000041000000000201041a000003e600200198000001c10000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000502041a000000000445016f000000320330020f000000000334019f000000000032041b000000000201041a000003e802200197000001f4022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d0200003900000003030000390000003205000039000001f406000039000003e9040000410f680f5e0000040f0000000100200190000001bc0000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d0200003900000003030000390000003205000039000001f406000039000003ea040000410f680f5e0000040f0000000100200190000001bc0000613d0000006401000039000000000010043f0000000501000039000000200010043f000003ec01000041000000000201041a000003e600200198000001c10000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000502041a000000000445016f000000640330020f000000000334019f000000000032041b000000000201041a000003e802200197000001f4022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d0200003900000003030000390000006405000039000001f406000039000003e9040000410f680f5e0000040f0000000100200190000001bc0000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d0200003900000003030000390000006405000039000001f406000039000003ea040000410f680f5e0000040f0000000100200190000001bc0000613d000000c801000039000000000010043f0000000501000039000000200010043f000003ed01000041000000000201041a000003e600200198000001c10000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000502041a000000000445016f000000c80330020f000000000334019f000000000032041b000000000201041a000003e80220019700000bb8022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000000c80500003900000bb806000039000003e9040000410f680f5e0000040f0000000100200190000001bc0000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000000c80500003900000bb806000039000003ea040000410f680f5e0000040f0000000100200190000001bc0000613d000007d001000039000000000010043f0000000501000039000000200010043f000003ee01000041000000000201041a000003e600200198000001c10000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000502041a000000000445016f000007d00330020f000000000334019f000000000032041b000000000201041a000003e80220019700002710022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000007d0050000390000271006000039000003e9040000410f680f5e0000040f0000000100200190000001bc0000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000007d0050000390000271006000039000003ea040000410f680f5e0000040f0000000100200190000001bc0000613d000000800100043d000000a00200043d000001400000044300000060022002700000016000200443000000200200003900000180002004430000006001100270000001a000100443000001000020044300000002010000390000012000100443000003f00100004100000f690001042e000000000100001900000f6a000104300000004402100039000003e203000041000001c40000013d000000400100043d0000004402100039000003ef03000041000000000032043500000024021000390000000f030000390000000000320435000003e3020000410000000000210435000000040210003900000020030000390000000000320435000000400200043d00000000012100490000006401100039000003db0010009c000003db010080410000006001100210000003db0020009c000003db020080410000004002200210000000000121019f00000f6a0001043000080000000000020000000002000416000000000001004b000003910000613d000000c003000039000000400030043f000000000002004b000003980000c13d000000020400036700000000010000310000044c051001980000001f0610018f000000c002500039000001eb0000613d000000000704034f000000007807043c0000000003830436000000000023004b000001e70000c13d000000000006004b000001f80000613d000000000354034f0000000304600210000000000502043300000000054501cf000000000545022f000000000303043b0000010004400089000000000343022f00000000034301cf000000000353019f0000000000320435000000c002100039000000400020043f000003fa0010009c000003980000213d0000005f0010008c000003980000a13d000000c00400043d000003de0040009c000003980000813d000000e00100043d000800000001001d000003dd0010009c000003980000213d000001000100043d000700000001001d000003dd0010009c000003980000213d000000000100041a000003df011001970000000003000411000003dd06300197000000000161019f000000000010041b000003db0020009c000003db0200804100000040012002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000600000004001d000003e10400004100000000050000190f680f5e0000040f00000006030000290000000100200190000003980000613d000003dd00300198000000400100043d0000000804000029000006880000613d000003dd00400198000006880000613d0000000702000029000003dd052001970000006002300210000000800020043f0000006002400210000000a00020043f0000000203000039000000000203041a000003df022001970000000004000411000000000242019f000000000023041b0000000303000039000000000203041a000003df02200197000000000242019f000000000023041b0000000104000039000000000204041a000003df02200197000000000252019f000000000024041b000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d02000039000003e40400004100000000060500190f680f5e0000040f0000000100200190000003980000613d0000000105000039000000000050043f0000000501000039000000200010043f000003e501000041000000000201041a000003e600200198000008910000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000602041a000000000446016f000000010330020f000000000334019f000000000032041b000000000050043f000000000201041a000003e80220019700000064022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d0200003900000003030000390000006406000039000003e9040000410f680f5e0000040f0000000100200190000003980000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d02000039000000030300003900000001050000390000006406000039000003ea040000410f680f5e0000040f0000000100200190000003980000613d0000003205000039000000000050043f0000000501000039000000200010043f000003eb01000041000000000201041a000003e600200198000008910000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000602041a000000000446016f000000320330020f000000000334019f000000000032041b000000000050043f000000000201041a000003e802200197000001f4022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000001f406000039000003e9040000410f680f5e0000040f0000000100200190000003980000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d0200003900000003030000390000003205000039000001f406000039000003ea040000410f680f5e0000040f0000000100200190000003980000613d0000006401000039000000000010043f0000000501000039000000200010043f000003ec01000041000000000201041a000003e600200198000008910000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000502041a000000000445016f000000640330020f000000000334019f000000000032041b0000006405000039000000000050043f000000000201041a000003e802200197000001f4022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000001f406000039000003e9040000410f680f5e0000040f0000000100200190000003980000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d0200003900000003030000390000006405000039000001f406000039000003ea040000410f680f5e0000040f0000000100200190000003980000613d000000c805000039000000000050043f0000000501000039000000200010043f000003ed01000041000000000201041a000003e600200198000008910000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000602041a000000000446016f000000c80330020f000000000334019f000000000032041b000000000050043f000000000201041a000003e80220019700000bb8022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d02000039000000030300003900000bb806000039000003e9040000410f680f5e0000040f0000000100200190000003980000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000000c80500003900000bb806000039000003ea040000410f680f5e0000040f0000000100200190000003980000613d000007d005000039000000000050043f0000000501000039000000200010043f000003ee01000041000000000201041a000003e600200198000008910000c13d0000000a04000039000000000204041a0000000103200039000000000034041b0000000a3220011a00000018033000c9000003e60430021f000003f104400167000003e70220009a000000000602041a000000000446016f000007d00330020f000000000334019f000000000032041b000000000050043f000000000201041a000003e80220019700002710022001bf000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d0200003900000003030000390000271006000039000003e9040000410f680f5e0000040f0000000100200190000003980000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000007d0050000390000271006000039000003ea040000410f680f5e0000040f0000000100200190000003980000613d000000800100043d000000a00200043d000001400000044300000060022002700000016000200443000000200200003900000180002004430000006001100270000001a000100443000001000020044300000002010000390000012000100443000003f00100004100000f690001042e0000008004000039000000400040043f000000000002004b000003980000c13d0000000002000031000000030020008c0000039a0000213d000000000100001900000f6a000104300000000201000367000000000501043b000000e003500270000003f20050009c000004770000813d0000041f0050009c000004850000813d000004340050009c000004fc0000813d000004470030009c0000068b0000613d000004480030009c000006860000613d000004490030009c000003980000c13d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000403100370000000000303043b0000042d0030009c000003980000213d0000002304300039000000000024004b000003980000813d0000000404300039000000000541034f000000000505043b0000042d0050009c000003980000213d00000000035300190000002403300039000000000023004b000003980000213d0000007f0050008c000003980000a13d0000002002400039000000000321034f000000000303043b000003de0030009c000003980000813d00000000070300190000002003200039000000000231034f000000000202043b000003de0020009c000003980000813d0000002005300039000000000351034f000000000803043b000003ff00800198000004000400004100000000040060190000040103800197000000000634019f000700000008001d000000000068004b000003980000c13d0000002005500039000000000151034f000000000101043b000800000001001d000003de0010009c000003980000813d0000000301000039000000000101041a000003dd011001970000000005000411000000000015004b000009320000c13d000003dd01700197000003dd05200197000000000051004b000008410000613d00000000010700190000000001024019000500000001001d0000000007028019000600000007001d000000000007004b0000094e0000613d000003ff0040019800000400010000410000000001006019000000000131019f000400000001001d000000000010043f0000000501000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000101041a000003e600100198000009cd0000613d0000000601000029000000000010043f0000000601000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000502000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000402000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000101041a000003dd00100198000003980000c13d000000400300043d000000400130003900000005020000290000000000210435000000200130003900000006020000290000000000210435000000600130003900000007020000290000000000210435000000400200043d00000000012100490000000001120436000300000003001d0000008003300039000000400030043f000003db0010009c000003db0100804100000040011002100000000002020433000003db0020009c000003db020080410000006002200210000000000112019f0000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000306000029000000a4026000390000043c030000410000000000320435000000400200043d000000440320003900000000040004140000006005000039000000000053043500000000032600490000008005300039000000640620003900000000005604350000043d050000410000000000520435000000040520003900000000001504350000010401300039000003db0010009c000003db010080410000006001100210000003db0020009c000003db020080410000004002200210000000000121019f000003db0040009c000003db04008041000000c002400210000000000121019f000003e0011001c700008006020000390f680f5e0000040f000000010020019000000d1a0000613d000000000101043b000000000001004b00000d280000c13d0000000301000367000000010200003100000d1e0000013d000003f30050009c000004f20000813d0000040f0050009c0000051f0000813d000004180030009c000005a10000213d0000041b0030009c000006af0000613d0000041c0030009c000003980000c13d000000000100041a000803dd0010019b000000400400043d000008700000013d000004200050009c000005580000813d000004270030009c000005c20000213d0000042a0030009c000006f10000613d0000042b0030009c000003980000c13d000003fa0020009c000003980000213d000000a30020008c000003980000a13d0000000403100370000000000403043b000003dd0040009c000003980000213d0000002403100370000000000303043b000003dd0030009c000003980000213d0000004405100370000000000505043b000003dd0050009c000003980000213d0000006406100370000000000606043b000003dd0060009c000003980000213d0000008407100370000000000807043b0000042d0080009c000003980000213d0000002307800039000000000027004b000003980000813d0000000409800039000000000791034f000000000707043b0000042e0070009c000009810000213d0000001f0a7000390000044c0aa00197000000a00aa000390000004000a0043f000000800070043f00000000087800190000002408800039000000000082004b000003980000413d0000002002900039000000000221034f0000044c087001980000001f0970018f000000a001800039000004c20000613d000000a00a000039000000000b02034f00000000bc0b043c000000000aca043600000000001a004b000004be0000c13d000000000009004b000004cf0000613d000000000282034f0000000308900210000000000901043300000000098901cf000000000989022f000000000202043b0000010008800089000000000282022f00000000028201cf000000000292019f0000000000210435000803dd0040019b000000a00170003900000000000104350000000101000039000000000101041a000703dd0010019c000009dd0000c13d000000400200043d0000043201000041000600000002001d0000000000120435000000400100043d000700000001001d00000430010000410000000000100443000000080100002900000004001004430000000001000414000003db0010009c000003db01008041000000c00110021000000431011001c700008002020000390f680f630000040f000000010020019000000ee30000613d000000000101043b000000000001004b000003980000613d00000000010004140000000802000029000000040020008c00000a920000c13d000000010300003100000ac20000013d000003f40050009c000005750000813d0000040a0030009c000005e20000213d0000040d0030009c000006fe0000613d0000040e0030009c000003980000c13d0000000a010000390000086e0000013d000004350030009c000006010000213d000004380030009c000007050000613d000004390030009c000003980000c13d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b000003de0010009c000003980000813d0000000002000411000000000300041a000000000223013f000003dd00200198000008100000c13d000003dd061001970000000401000039000000000201041a000003df03200197000000000363019f000000000031041b0000000001000414000003dd05200197000003db0010009c000003db01008041000000c001100210000003fb011001c70000800d02000039000000030300003900000446040000410000080b0000013d000004100030009c000006440000213d000004130030009c0000072f0000613d000004140030009c000003980000c13d000003fa0020009c000003980000213d000000430020008c000003980000a13d0000000402100370000000000502043b000003ff00500198000004000300004100000000030060190000040102500197000000000423019f000800000005001d000000000045004b000003980000c13d0000002401100370000000000101043b000700000001001d000004020010009c000003980000813d0000000001000411000000000400041a000000000114013f000003dd00100198000008100000c13d000003ff0030019800000400010000410000000001006019000000000121019f000000000010043f0000000501000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000400200043d000000000101043b000000000301041a000003e6003001980000093c0000c13d000000440120003900000415030000410000000000310435000000240120003900000018030000390000095f0000013d000004210030009c0000064a0000213d000004240030009c000007a70000613d000004250030009c000003980000c13d000000000100041a000003dd051001970000000001000411000003dd01100197000000000051004b000008100000c13d0000000001000414000003db0010009c000003db01008041000000c001100210000003fb011001c70000800d020000390000000303000039000003e10400004100000000060000190f680f5e0000040f0000000100200190000003980000613d000000000100041a000003df01100197000000000010041b000000000100001900000f690001042e000003f50030009c000006660000213d000003f80030009c000007bc0000613d000003f90030009c000003980000c13d000003fa0020009c000003980000213d000000430020008c000003980000a13d0000000402100370000000000302043b000003ff0030019800000400020000410000000002006019000704010030019b00000007022001af000800000003001d000000000023004b000003980000c13d0000002401100370000000000101043b000600000001001d000004020010009c000003980000813d0000000001000411000000000200041a000000000112013f000003dd00100198000008100000c13d0000000801000029000040000110008a0000044d0010009c000008ed0000813d000003e301000041000000800010043f0000002001000039000000840010043f0000001401000039000000a40010043f0000040701000041000000c40010043f0000008002000039000009650000013d000004190030009c000007cd0000613d0000041a0030009c000003980000c13d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b000003de0010009c000003980000813d0000000002000411000000000300041a000000000223013f000003dd00200198000008100000c13d000003dd061001970000000201000039000000000201041a000003df03200197000000000363019f000000000031041b0000000001000414000003dd05200197000003db0010009c000003db01008041000000c001100210000003fb011001c70000800d0200003900000003030000390000041d040000410000080b0000013d000004280030009c000007ef0000613d000004290030009c000003980000c13d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b000003de0010009c000003980000813d0000000002000411000000000300041a000000000223013f000003dd00200198000008100000c13d000003dd061001970000000303000039000000000103041a000003df02100197000000000262019f000000000023041b0000000002000414000003dd05100197000003db0020009c000003db02008041000000c001200210000003fb011001c70000800d020000390000042c040000410000080b0000013d0000040b0030009c000008190000613d0000040c0030009c000003980000c13d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b000003de0010009c000003980000813d000000000010043f0000000801000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000400400043d000000000101043b000000000101041a000000ff001001900000000001000039000000010100c0390000086f0000013d000004360030009c0000081b0000613d000004370030009c000003980000c13d000003fa0020009c000003980000213d000000630020008c000003980000a13d0000000402100370000000000202043b000003dd0020009c000003980000213d0000002403100370000000000303043b000800000003001d000003dd0030009c000003980000213d0000004401100370000000000401043b000003ff00400198000004000100004100000000010060190000040103400197000000000131019f000700000004001d000000000014004b000003980000c13d0000000601000039000000200010043f000000000020043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000200010043f0000000801000029000000000010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000200010043f0000000701000029000000000010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000008450000013d000004110030009c000008440000613d000004120030009c000003980000c13d0000000301000039000008450000013d000004220030009c000008550000613d000004230030009c000003980000c13d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b0000000a02000039000000000302041a000000000031004b000003980000813d000000000020043f0000000a2110011a00000018022000c9000003e70110009a000000000101041a000000000121022f0000040102100197000003ff0010019800000400010000410000000001006019000000000121019f000000800010043f000004260100004100000f690001042e000003f60030009c0000086d0000613d000003f70030009c000003980000c13d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b000003de0010009c000003980000813d000000000200041a000003dd052001970000000002000411000003dd02200197000000000052004b000008100000c13d000003dd06100198000008a80000c13d000003e301000041000000800010043f0000002001000039000000840010043f0000002601000039000000a40010043f000003fc01000041000000c40010043f000003fd01000041000000e40010043f000003fe0100004100000f6a000104300000000401000039000008450000013d0000004402100039000003e203000041000008940000013d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b000003de0010009c000003980000813d0000000102000039000000000202041a0000044a03000041000000800030043f000000840010043f00000430010000410000000000100443000003dd01200197000800000001001d00000004001004430000000001000414000003db0010009c000003db01008041000000c00110021000000431011001c700008002020000390f680f630000040f000000010020019000000ee30000613d000000000101043b000000000001004b000003980000613d00000000010004140000000802000029000000040020008c000008ba0000c13d0000000103000031000008df0000013d000003fa0020009c000003980000213d000000630020008c000003980000a13d0000000402100370000000000202043b000003dd0020009c000003980000213d0000002403100370000000000303043b000800000003001d000003dd0030009c000003980000213d0000004401100370000000000101043b000700000001001d0000000701000039000000200010043f000000000020043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000200010043f0000000801000029000000000010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000000070020006b000003980000813d000000000010043f000000200200003900000000010000190f680f490000040f0000000701100029000000000101041a000000a0021002700000040102200197000004170010019800000400030000410000000003006019000000000223019f000000400300043d00000020043000390000000000240435000003dd011001970000000000130435000000400100043d000000000213004900000040022000390000084d0000013d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b0000000902000039000000000302041a000000000031004b000003980000813d000000000020043f000004330110009a000008450000013d000004080100004100000000001004430000000001000412000000040010044300000024000004430000000001000414000007c30000013d000003fa0020009c000003980000213d000000430020008c000003980000a13d0000000402100370000000000202043b000003de0020009c000003980000813d0000002401100370000000000101043b000800000001001d000003de0010009c000003980000813d000003dd01200197000000000010043f0000000701000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000802000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000400400043d000000000101043b0000086e0000013d000003fa0020009c000003980000213d000000430020008c000003980000a13d0000000402100370000000000202043b000003de0020009c000003980000813d0000002401100370000000000101043b000800000001001d000003de0010009c000003980000813d000003dd01200197000000000010043f0000000701000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000802000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000400300043d0000002002300039000600000001001d000000000401041a0000000501400210000400000002001d0000000001120019000000400010043f000300000003001d0000000000430435000500000004001d000000000004004b000007890000613d000800040000002d000700000000001d0000000601000029000000000010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000416011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000400200043d0000004003200039000000400030043f00000007050000290000000001510019000000000101041a000000a0031002700000040103300197000004170010019800000400040000410000000004006019000000000334019f00000020042000390000000000340435000003dd01100197000000000012043500000008010000290000000001210436000800000001001d0000000105500039000700000005001d000000050050006c000007660000413d000000400300043d000000200100003900000000011304360000000302000029000000000202043300000000002104350000004001300039000000000002004b000008720000613d00000000040000190000000407000029000000000501001900000000710704340000000061010434000003dd01100197000000000015043500000000010604330000040106100197000003ff0010019800000400010000410000000001006019000000000161019f0000006003300039000000000013043500000040015000390000000104400039000000000024004b0000000003050019000007940000413d000008720000013d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b000003de0010009c000003980000813d0000000802000039000000200020043f000000000010043f000000400200003900000000010000190f680f490000040f000000000101041a000000ff001001900000000001000039000000010100c039000000800010043f000004260100004100000f690001042e0000040801000041000000000010044300000000010004120000000400100443000000200100003900000024001004430000000001000414000003db0010009c000003db01008041000000c00110021000000409011001c700008005020000390f680f630000040f000000010020019000000ee30000613d000000000101043b000008470000013d0000000a03000039000000000203041a0000000501200210000000a001100039000000400010043f000000800020043f000000000002004b0000087d0000613d000000a002000039000000000030043f0000041e030000410000000004000019000007e80000013d0000040106500197000003ff0050019800000400050000410000000005006019000000000565019f00000000025204360000000505400039000000050550027000000000033500190000000304400039000000010550008900000000044500a9000000000021004b0000087c0000a13d0000001f0040008c0000000005000019000007da0000213d0000000305400210000000000603041a000000000556022f000007da0000013d000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b000003de0010009c000003980000813d0000000002000411000000000300041a000000000223013f000003dd00200198000008100000c13d000003dd051001970000000101000039000000000201041a000003df02200197000000000252019f000000000021041b0000000001000414000003db0010009c000003db01008041000000c001100210000003fb011001c70000800d020000390000000303000039000003e40400004100000000060500190f680f5e0000040f0000000100200190000003980000613d000000000100001900000f690001042e000003e301000041000000800010043f0000002001000039000000840010043f000000a40010043f0000044501000041000000c40010043f000004440100004100000f6a000104300000000101000039000008450000013d000003fa0020009c000003980000213d000000830020008c000003980000a13d0000000402100370000000000202043b000003de0020009c000003980000813d00000000060200190000002402100370000000000202043b000003de0020009c000003980000813d0000004403100370000000000703043b000003ff00700198000004000400004100000000040060190000040103700197000000000534019f000700000007001d000000000057004b000003980000c13d0000006401100370000000000101043b000800000001001d000003de0010009c000003980000813d0000000301000039000000000101041a000003dd011001970000000005000411000000000015004b000009320000c13d000003dd01600197000003dd05200197000000000051004b000009470000c13d0000043b010000410000000f02000039000009340000013d0000000201000039000000000101041a000003dd01100197000003dd01100197000000400200043d0000000000120435000000400100043d00000000021200490000002002200039000003db0020009c000003db020080410000006002200210000003db0010009c000003db010080410000004001100210000000000112019f00000f690001042e000003fa0020009c000003980000213d000000230020008c000003980000a13d0000000401100370000000000101043b000003ff00100198000004000200004100000000020060190000040103100197000000000232019f000000000021004b000003980000c13d0000000502000039000000200020043f000000000010043f000000400200003900000000010000190f680f490000040f000000000101041a000003e601100197000000800010043f000004260100004100000f690001042e0000000901000039000000000101041a000800000001001d00000008010000290000000001140436000000400200043d0000000001210049000003db0010009c000003db010080410000006001100210000003db0020009c000003db020080410000004002200210000000000121019f00000f690001042e000000400100043d00000020020000390000000003210436000000800200043d00000000002304350000004001100039000000000002004b000008720000613d000000a003000039000000000400001900000000350304340000040106500197000003ff0050019800000400050000410000000005006019000000000565019f00000000015104360000000104400039000000000024004b000008860000413d000008720000013d000000400100043d0000004402100039000003ef03000041000000000032043500000024021000390000000f030000390000000000320435000003e3020000410000000000210435000000040210003900000020030000390000000000320435000000400200043d00000000012100490000006401100039000003db0010009c000003db010080410000006001100210000003db0020009c000003db020080410000004002200210000000000121019f00000f6a000104300000000001000414000003db0010009c000003db01008041000000c001100210000003fb011001c70000800d020000390000000303000039000003e104000041000800000006001d0f680f5e0000040f0000000100200190000003980000613d000000000100041a000003df0110019700000008011001af000000000010041b000000000100001900000f690001042e000003db0010009c000003db01008041000000c0011002100000044b011001c70f680f630000040f0000006003100270000003db03300197000000200030008c000000200400003900000000040340190000001f0540018f000000200640019000000080046001bf000008ce0000613d0000008007000039000000000801034f000000008908043c0000000007970436000000000047004b000008ca0000c13d000000000005004b000008db0000613d000000000661034f0000000305500210000000000704043300000000075701cf000000000757022f000000000606043b0000010005500089000000000656022f00000000055601cf000000000575019f0000000000540435000100000003001f000300000001035500000001002001900000091a0000613d0000001f013000390000044c02100197000000400100043d0000000004120019000000400040043f000003fa0030009c000003980000213d0000001f0030008c000003980000a13d0000000001010433000800000001001d000004020010009c000008700000413d000003980000013d0000000701000029000000000010043f0000000501000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000101041a000003e600100198000009590000c13d0000000601000029000003e6051001970000000a01000039000000000201041a0000000103200039000000000031041b000000000010043f0000000a2120011a00000018022000c900000008032001ef000003e60220021f000003f102200167000003e70110009a000000000401041a000000000224016f000000000232019f000000000021041b000600000005001d000004040150009a000004050010009c000009840000813d000000400100043d00000044021000390000040603000041000000000032043500000024021000390000000b03000039000008970000013d0000001f0430018f000003dc02300198000009230000613d000000000501034f0000000006000019000000005705043c0000000006760436000000000026004b0000091f0000c13d000000000004004b000009300000613d000000000121034f0000000304400210000000000502043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000120435000000600130021000000f6a000104300000043a010000410000001002000039000003e303000041000000800030043f0000002003000039000000840030043f000000a40020043f000000c40010043f000004440100004100000f6a000104300000000704000029000003e606400197000004040460009a000004050040009c000009700000813d00000044012000390000040603000041000000000031043500000024012000390000000b030000390000095f0000013d00000000010600190000000001024019000500000001001d0000000006028019000600000006001d000000000006004b000009b80000c13d000003e301000041000000800010043f0000002001000039000000840010043f0000000d01000039000000a40010043f0000044301000041000000c40010043f000000e4020000390000008001000039000009db0000013d000000400200043d0000004401200039000003ef03000041000000000031043500000024012000390000000f030000390000000000310435000003e3010000410000000000120435000000040120003900000020030000390000000000310435000000400100043d00000000021200490000006402200039000003db0020009c000003db020080410000006002200210000003db0010009c000003db010080410000004001100210000000000112019f00000f6a00010430000003e803300197000000000363019f000000000031041b000003db0020009c000003db0200804100000040012002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000003e90400004100000008050000290000080b0000013d000000010100008a000000000001043500000000000004310000000701000029000000000010043f0000000501000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000003e8022001970000000606000029000000000262019f000000000021041b000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000003e90400004100000008050000290f680f5e0000040f0000000100200190000003980000613d000000400100043d000003db0010009c000003db0100804100000040011002100000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c70000800d020000390000000303000039000003ea04000041000000080500002900000006060000290000080b0000013d000003ff0040019800000400010000410000000001006019000000000131019f000400000001001d000000000010043f0000000501000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000101041a000003e60010019800000a1c0000c13d000000400100043d000000440210003900000415030000410000000000320435000000240210003900000018030000390000000000320435000003e30200004100000000002104350000000402100039000000200300003900000000003204350000006402100039000000400100043d0000000002120049000009680000013d000003dd01300197000003dd02500197000003dd03600197000000400400043d0000008405400039000000a00600003900000000006504350000006405400039000000000035043500000044034000390000000000230435000000240240003900000000001204350000042f010000410000000000140435000000040140003900000008020000290000000000210435000000a401400039000000800200043d0000000000210435000600000002001d000000000002004b000500c40040003d00000a040000613d0000000001000019000000060400002900000005050000290000000002150019000000a003100039000000000303043300000000003204350000002001100039000000000041004b000009f90000413d00000a040000a13d000000050200002900000006012000290000000000010435000000400100043d000400000001001d00000430010000410000000000100443000000070100002900000004001004430000000001000414000003db0010009c000003db01008041000000c00110021000000431011001c700008002020000390f680f630000040f000000010020019000000ee30000613d000000000101043b000000000001004b000003980000613d00000000010004140000000702000029000000040020008c00000ae80000c13d000000010300003100000b1b0000013d0000000601000029000000000010043f0000000601000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000502000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000402000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000101041a000003dd00100198000003980000c13d000000400300043d000000400130003900000005020000290000000000210435000000200130003900000006020000290000000000210435000000600130003900000007020000290000000000210435000000400200043d00000000012100490000000001120436000300000003001d0000008003300039000000400030043f000003db0010009c000003db0100804100000040011002100000000002020433000003db0020009c000003db020080410000006002200210000000000112019f0000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000306000029000000a4026000390000043c030000410000000000320435000000400200043d000000440320003900000000040004140000006005000039000000000053043500000000032600490000008005300039000000640620003900000000005604350000043d050000410000000000520435000000040520003900000000001504350000010401300039000003db0010009c000003db010080410000006001100210000003db0020009c000003db020080410000004002200210000000000121019f000003db0040009c000003db04008041000000c002400210000000000121019f000003e0011001c700008006020000390f680f5e0000040f000000010020019000000b410000613d000000000101043b000000000001004b00000b5f0000c13d0000000301000367000000010200003100000b450000013d000000070300002900000006023000690000000402200039000003db0030009c000003db030080410000004003300210000003db0020009c000003db020080410000006002200210000000000232019f000003db0010009c000003db01008041000000c001100210000000000121019f00000008020000290f680f630000040f00000007090000290000006003100270000003db03300197000000200030008c000000200400003900000000040340190000001f0540018f0000002006400190000000000469001900000ab10000613d000000000701034f000000007807043c0000000009890436000000000049004b00000aad0000c13d000000000005004b00000abe0000613d000000000661034f0000000305500210000000000704043300000000075701cf000000000757022f000000000606043b0000010005500089000000000656022f00000000055601cf000000000575019f0000000000540435000100000003001f0003000000010355000000010020019000000b290000613d0000001f013000390000044c02100197000000400100043d0000000002120019000000400020043f000003fa0030009c000003980000213d0000001f0030008c000003980000a13d0000000003010433000003ff00300198000004000200004100000000020060190000040101300197000000000412019f000000000043004b000003980000c13d000003ff0020019800000400020000410000000002006019000000000112019f000000000010043f0000000501000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000400400043d000000000101043b000000000101041a000003e6011001970000086f0000013d00000006020000290000001f022000390000044c02200197000000050220002900000004030000290000000002320049000003db0030009c000003db030080410000004003300210000003db0020009c000003db020080410000006002200210000000000232019f000003db0010009c000003db01008041000000c001100210000000000121019f00000007020000290f680f630000040f00000004090000290000006003100270000003db03300197000000200030008c000000200400003900000000040340190000001f0540018f0000002006400190000000000469001900000b0a0000613d000000000701034f000000007807043c0000000009890436000000000049004b00000b060000c13d000000000005004b00000b170000613d000000000661034f0000000305500210000000000704043300000000075701cf000000000757022f000000000606043b0000010005500089000000000656022f00000000055601cf000000000575019f0000000000540435000100000003001f00030000000103550000000100200190000004d60000613d0000001f013000390000044c02100197000000400100043d0000000004120019000000400040043f000003fa0030009c000003980000213d0000001f0030008c000003980000a13d0000000001010433000800000001001d000004020010009c000008700000413d000003980000013d0000001f0430018f000003dc0230019800000b320000613d000000000501034f0000000006000019000000005705043c0000000006760436000000000026004b00000b2e0000c13d000000000004004b00000b3f0000613d000000000121034f0000000304400210000000000502043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000120435000000600130021000000f6a0001043000030000000103550000006002100270000103db0020019d000003db022001970000044c032001980000001f0420018f00000b4e0000613d000000000501034f0000000006000019000000005705043c0000000006760436000000000036004b00000b4a0000c13d000000000004004b00000b5b0000613d000000000131034f0000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000130435000003db0020009c000003db02008041000000600120021000000f6a000104300000000802000029000003dd02200197000000400400043d000000840340003900000000002304350000006402400039000000070300002900000000003204350000004402400039000000050300002900000000003204350000002402400039000000060300002900000000003204350000043e0200004100000000002404350000000002000410000003dd02200197000300000004001d00000004034000390000000000230435000000400200043d000200000002001d00000430020000410000000000200443000003dd01100197000800000001001d00000004001004430000000001000414000003db0010009c000003db01008041000000c00110021000000431011001c700008002020000390f680f630000040f000000010020019000000ee30000613d000000000101043b000000000001004b000003980000613d00000000010004140000000802000029000000040020008c00000ba00000613d00000002030000290000000302300069000000a402200039000003db0030009c000003db030080410000004003300210000003db0020009c000003db020080410000006002200210000000000232019f000003db0010009c000003db01008041000000c001100210000000000121019f00000008020000290f680f5e0000040f0000006003100270000103db0030019d0003000000010355000000010020019000000ee40000613d0000000901000039000000000201041a0000000103200039000000000031041b000004330120009a000000000201041a000003df022001970000000803000029000000000232019f000000000021041b000000000030043f0000000801000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a0000044e0220019700000001022001bf000000000021041b0000000601000029000000000010043f0000000601000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000502000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000402000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000003df0220019700000008022001af000000000021041b0000000501000029000000000010043f0000000601000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000602000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000402000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000003df022001970000000803000029000000000232019f000000000021041b000000400200043d0000004001200039000000400010043f00000020042000390000000701000029000300000004001d0000000000140435000400000002001d00000000003204350000000601000029000000000010043f0000000701000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000502000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000200000002001d0000000102200039000000000021041b000000000010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000416011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000201100029000000000201041a0000043f0220019700000004030000290000000003030433000003dd03300197000000000232019f00000003030000290000000003030433000000a0033002100000044003300197000000000232019f000000000021041b0000000501000029000000000010043f0000000701000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000602000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000200000002001d0000000102200039000000000021041b000000000010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000416011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000201100029000000000201041a0000043f0220019700000004030000290000000003030433000003dd03300197000000000232019f00000003030000290000000003030433000000a0033002100000044003300197000000000232019f000000000021041b0000040801000041000000000010044300000000010004120000000400100443000000200100003900000024001004430000000001000414000003db0010009c000003db01008041000000c00110021000000409011001c700008005020000390f680f630000040f000000010020019000000ee30000613d000000000301043b000000400100043d000000400210003900000005040000290000000000420435000000200210003900000006040000290000000000420435000000600210003900000007040000290000000000420435000000400400043d000000000242004900000000022404360000008005100039000000400050043f00000441060000410000000000650435000000c405100039000000a0060000390000000000650435000000a40510003900000004060000390000000000650435000000840510003900000008060000290000000000650435000001240510003900000000040404330000000000450435000203dd0030019b000400000004001d000000000004004b000301440010003d00000cc90000613d000000000300001900000003043000290000000005320019000000000505043300000000005404350000002003300039000000040030006c00000cbe0000413d00000cc90000a13d000000030300002900000004023000290000000000020435000001040210003900000005030000290000000000320435000000e40110003900000006020000290000000000210435000000400100043d000100000001001d00000430010000410000000000100443000000020100002900000004001004430000000001000414000003db0010009c000003db01008041000000c00110021000000431011001c700008002020000390f680f630000040f000000010020019000000ee30000613d000000000101043b000000000001004b000003980000613d00000000010004140000000202000029000000040020008c00000cfd0000613d00000004020000290000001f022000390000044c02200197000000030220002900000001030000290000000002320049000003db0030009c000003db030080410000004003300210000003db0020009c000003db020080410000006002200210000000000232019f000003db0010009c000003db01008041000000c001100210000000000121019f00000002020000290f680f5e0000040f0000006003100270000103db0030019d0003000000010355000000010020019000000f160000613d000000400100043d00000008020000290000000000210435000000400200043d00000000012100490000002001100039000003db0010009c000003db010080410000006001100210000003db0020009c000003db020080410000004002200210000000000121019f0000000002000414000003db0020009c000003db02008041000000c002200210000000000121019f000003e0011001c70000800d02000039000000040300003900000442040000410000000605000029000000050600002900000007070000290f680f5e0000040f0000000100200190000004830000c13d000003980000013d00030000000103550000006002100270000103db0020019d000003db022001970000044c032001980000001f0420018f00000b4e0000613d000000000501034f0000000006000019000000005705043c0000000006760436000000000036004b00000d230000c13d00000b4e0000013d0000000802000029000003dd02200197000000400400043d000000840340003900000000002304350000006402400039000000070300002900000000003204350000004402400039000000050300002900000000003204350000002402400039000000060300002900000000003204350000043e0200004100000000002404350000000002000410000003dd02200197000300000004001d00000004034000390000000000230435000000400200043d000200000002001d00000430020000410000000000200443000003dd01100197000800000001001d00000004001004430000000001000414000003db0010009c000003db01008041000000c00110021000000431011001c700008002020000390f680f630000040f000000010020019000000ee30000613d000000000101043b000000000001004b000003980000613d00000000010004140000000802000029000000040020008c00000d690000613d00000002030000290000000302300069000000a402200039000003db0030009c000003db030080410000004003300210000003db0020009c000003db020080410000006002200210000000000232019f000003db0010009c000003db01008041000000c001100210000000000121019f00000008020000290f680f5e0000040f0000006003100270000103db0030019d0003000000010355000000010020019000000efd0000613d0000000901000039000000000201041a0000000103200039000000000031041b000004330120009a000000000201041a000003df022001970000000803000029000000000232019f000000000021041b000000000030043f0000000801000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a0000044e0220019700000001022001bf000000000021041b0000000601000029000000000010043f0000000601000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000502000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000402000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000003df0220019700000008022001af000000000021041b0000000501000029000000000010043f0000000601000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000602000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000402000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000003df022001970000000803000029000000000232019f000000000021041b000000400200043d0000004001200039000000400010043f00000020042000390000000701000029000300000004001d0000000000140435000400000002001d00000000003204350000000601000029000000000010043f0000000701000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000502000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000200000002001d0000000102200039000000000021041b000000000010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000416011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000201100029000000000201041a0000043f0220019700000004030000290000000003030433000003dd03300197000000000232019f00000003030000290000000003030433000000a0033002100000044003300197000000000232019f000000000021041b0000000501000029000000000010043f0000000701000039000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000602000029000000000020043f000000200010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000403011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b000000000201041a000200000002001d0000000102200039000000000021041b000000000010043f0000000001000414000003db0010009c000003db01008041000000c00110021000000416011001c700008010020000390f680f630000040f0000000100200190000003980000613d000000000101043b0000000201100029000000000201041a0000043f0220019700000004030000290000000003030433000003dd03300197000000000232019f00000003030000290000000003030433000000a0033002100000044003300197000000000232019f000000000021041b0000040801000041000000000010044300000000010004120000000400100443000000200100003900000024001004430000000001000414000003db0010009c000003db01008041000000c00110021000000409011001c700008005020000390f680f630000040f000000010020019000000ee30000613d000000000301043b000000400100043d000000400210003900000005040000290000000000420435000000200210003900000006040000290000000000420435000000600210003900000007040000290000000000420435000000400400043d000000000242004900000000022404360000008005100039000000400050043f00000441060000410000000000650435000000c405100039000000a0060000390000000000650435000000a40510003900000004060000390000000000650435000000840510003900000008060000290000000000650435000001240510003900000000040404330000000000450435000203dd0030019b000400000004001d000000000004004b000301440010003d00000e920000613d000000000300001900000003043000290000000005320019000000000505043300000000005404350000002003300039000000040030006c00000e870000413d00000e920000a13d000000030300002900000004023000290000000000020435000001040210003900000005030000290000000000320435000000e40110003900000006020000290000000000210435000000400100043d000100000001001d00000430010000410000000000100443000000020100002900000004001004430000000001000414000003db0010009c000003db01008041000000c00110021000000431011001c700008002020000390f680f630000040f000000010020019000000ee30000613d000000000101043b000000000001004b000003980000613d00000000010004140000000202000029000000040020008c00000ec60000613d00000004020000290000001f022000390000044c02200197000000030220002900000001030000290000000002320049000003db0030009c000003db030080410000004003300210000003db0020009c000003db020080410000006002200210000000000232019f000003db0010009c000003db01008041000000c001100210000000000121019f00000002020000290f680f5e0000040f0000006003100270000103db0030019d0003000000010355000000010020019000000f2f0000613d000000400100043d00000008020000290000000000210435000000400200043d00000000012100490000002001100039000003db0010009c000003db010080410000006001100210000003db0020009c000003db020080410000004002200210000000000121019f0000000002000414000003db0020009c000003db02008041000000c002200210000000000121019f000003e0011001c70000800d02000039000000040300003900000442040000410000000605000029000000050600002900000007070000290f680f5e0000040f0000000100200190000004830000c13d000003980000013d000000000001042f000003db023001970000001f0420018f000003dc0320019800000eee0000613d000000000501034f0000000006000019000000005705043c0000000006760436000000000036004b00000eea0000c13d000000000004004b00000efb0000613d000000000131034f0000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000130435000000600120021000000f6a00010430000003db023001970000001f0420018f000003dc0320019800000f070000613d000000000501034f0000000006000019000000005705043c0000000006760436000000000036004b00000f030000c13d000000000004004b00000f140000613d000000000131034f0000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000130435000000600120021000000f6a00010430000003db023001970000001f0420018f000003dc0320019800000f200000613d000000000501034f0000000006000019000000005705043c0000000006760436000000000036004b00000f1c0000c13d000000000004004b00000f2d0000613d000000000131034f0000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000130435000000600120021000000f6a00010430000003db023001970000001f0420018f000003dc0320019800000f390000613d000000000501034f0000000006000019000000005705043c0000000006760436000000000036004b00000f350000c13d000000000004004b00000f460000613d000000000131034f0000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000130435000000600120021000000f6a00010430000000000001042f000003db0010009c000003db010080410000004001100210000003db0020009c000003db020080410000006002200210000000000112019f0000000002000414000003db0020009c000003db02008041000000c002200210000000000112019f000003e0011001c700008010020000390f680f630000040f000000010020019000000f5c0000613d000000000101043b000000000001042d000000000100001900000f6a0001043000000f61002104210000000102000039000000000001042d0000000002000019000000000001042d00000f66002104230000000102000039000000000001042d0000000002000019000000000001042d00000f680000043200000f690001042e00000f6a00010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000000ffffffe0000000000000000000000000ffffffffffffffffffffffffffffffffffffffff0000000000000000000000010000000000000000000000000000000000000000ffffffffffffffffffffffff000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000008be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0496e76616c69642061646472657373000000000000000000000000000000000008c379a000000000000000000000000000000000000000000000000000000000ffeb5a3c7f7bdb9ff0f87602dd325de1025633b63a8e6be6067f69e5be49e1761471eb6eb2c5e789fc3de43f8ce62938c7d1836ec861730447e2ada8fd81017b0000000000000000000000000000000000000000000000000000000000ffffff39a5844729cae3e308f36a5ce933956d7c6367997d26743ca06a70b77c062d58ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000009a2d8bc7345050aaf7d4b898cab6482acefd371e8398b783132911fab583ef2cebafae466a4a780a1d87f5fab2f52fad33be9151a7f69d099e8934c8de85b747641a7e47c832ef1f4ef72e654761ca2c0b592dc5a9de41ec09261efc0afea2bead66b8e7ab72f450ddfdaf1c5bc10e3a3fabf9f63ad8aa07b8743b93722f0a457a1de661595fed1ebd14726acb09298a08f8300cc62585766e164a3e18fbf85b37eddff2aef6ba0c09113e922b4f0444dc96bd6309797350df0da249aa038461416c726561647920656e61626c6564000000000000000000000000000000000000000002000000000000000000000000000000c0000001000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f47b8e600000000000000000000000000000000000000000000000000000000cefa779900000000000000000000000000000000000000000000000000000000ee97f7f30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000efde4e6300000000000000000000000000000000000000000000000000000000efde4e6400000000000000000000000000000000000000000000000000000000f2fde38b00000000000000000000000000000000000000000000000000000000ee97f7f300000000000000000000000000000000000000000000000000000000eee0fdb47fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff02000000000000000000000000000000000000000000008000000000000000004f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000008000000000000000000000000000000000000000000000000000000000000000000000000000800000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000000000000007fffff0000000000000000000000000000000000000000000000000000000001000000020000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000186a1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7960496e76616c696420666565000000000000000000000000000000000000000000496e76616c6964207469636b2073706163696e67000000000000000000000000310ab089e4439a4c15d089f94afb7896ff553aecb10793d0ab882de59d99a32e020000020000000000000000000000000000004400000000000000000000000000000000000000000000000000000000000000000000000000000000d0fb020200000000000000000000000000000000000000000000000000000000d0fb020300000000000000000000000000000000000000000000000000000000e5e31b1300000000000000000000000000000000000000000000000000000000cefa779900000000000000000000000000000000000000000000000000000000d09a4bc5af88634f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c415b95b00000000000000000000000000000000000000000000000000000000c415b95c00000000000000000000000000000000000000000000000000000000c6c1decd00000000000000000000000000000000000000000000000000000000af88634f00000000000000000000000000000000000000000000000000000000b03d02c65469636b2073706163696e67206e6f7420656e61626c6564000000000000000002000000000000000000000000000000000000200000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009cbbbe85000000000000000000000000000000000000000000000000000000009cbbbe8600000000000000000000000000000000000000000000000000000000a42dce80000000000000000000000000000000000000000000000000000000007f47b8e6000000000000000000000000000000000000000000000000000000008da5cb5b9ea5568f737dfb292c6112b470f5deda06c5b264cdc5b29687cbf6f27a73964dc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a841d1de97000000000000000000000000000000000000000000000000000000005b16ebb7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074e10dfd0000000000000000000000000000000000000000000000000000000074e10dfe000000000000000000000000000000000000000000000000000000007a5527c4000000000000000000000000000000000000000000000000000000005b16ebb700000000000000000000000000000000000000000000000000000000715018a6000000000000000000000000000000000000002000000080000000000000000000000000000000000000000000000000000000000000000000000000472d35b800000000000000000000000000000000000000000000000000000000472d35b90000000000000000000000000000000000000000000000000000000054acc3d10000000000000000000000000000000000000000000000000000000041d1de97000000000000000000000000000000000000000000000000000000004625a94d4f11e6c5b18ddfa5a7993c23fb38cc2f9127209735048572088201cb73318dcd000000000000000000000000000000000000000000000000ffffffffffffffff000000000000000000000000000000000000000000000000ffffffffffffff404625a94d000000000000000000000000000000000000000000000000000000001806aa1896bbf26568e884a7374b41e002500962caba6a15023a8d90e8508b830200000200000000000000000000000000000024000000000000000000000000d0c93a7c0000000000000000000000000000000000000000000000000000000091eabfe8e493f369f48e58fdf2609ff8809506ce57440a6f25fddc25308a3851202e4f9e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000232aa5ab00000000000000000000000000000000000000000000000000000000232aa5ac0000000000000000000000000000000000000000000000000000000028af8d0b00000000000000000000000000000000000000000000000000000000202e4f9e0000000000000000000000000000000000000000000000000000000023130d114e6f7420706f6f6c2063726561746f72000000000000000000000000000000004964656e746963616c20746f6b656e000000000000000000000000000000000001002407a9fa92c7fe412e0c6a453f4ef2d9d3a9660f72c9db7eee1d0bc96f623cda33511d41a8a5431b1770c5bc0ddd62e1cd30555d16659b89c0d60f4f9f57a514fe7700000000000000000000000000000000000000000000000000000000ffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000ffffff0000000000000000000000000000000000000000a5a7f8b700000000000000000000000000000000000000000000000000000000ab0d57f0df537bb25e80245ef7748fa62353808c54d6e528a9dd20887aed9ac2496e76616c696420746f6b656e0000000000000000000000000000000000000000000000000000000000000000000000000000640000008000000000000000004f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572a1bb19b5d754d8c6479f7761797294f0786b22f6fe2fd51b0b81e56f4136cd93000000000000000000000000000000000000000000000000000000000a992e0c000000000000000000000000000000000000000000000000000000000d52333c0000000000000000000000000000000000000000000000000000000013b8683f0a992e0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024000000800000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000000000000000000000fb8dccf1ac994721aaad15cef6cf28b31e3702d863bfd5e99dada589b029a524
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000009012c7ce4d1f677aaf9241cf7d4d05fc596556e8000000000000000000000000000000000000000000000000000000000000000100000000000000000000000061bafc2f483cdb6c6710426d15cf11fb6acf49f7
-----Decoded View---------------
Arg [0] : _master (address): 0x9012C7CE4d1f677aaf9241CF7d4D05fC596556e8
Arg [1] : _poolImplementation (address): 0x0000000000000000000000000000000000000001
Arg [2] : _feeManager (address): 0x61Bafc2f483cdb6C6710426d15Cf11fb6acF49f7
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 0000000000000000000000009012c7ce4d1f677aaf9241cf7d4d05fc596556e8
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [2] : 00000000000000000000000061bafc2f483cdb6c6710426d15cf11fb6acf49f7
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.