ERC-20
Overview
Max Total Supply
0.000000000000294446 KS2-RT
Holders
2
Market
Onchain Market Cap
$0.00
Circulating Supply Market Cap
-
Other Info
Token Contract (WITH 18 Decimals)
Balance
0.000000000000294345 KS2-RTValue
$0.00Loading...
Loading
Loading...
Loading
Loading...
Loading
# | Exchange | Pair | Price | 24H Volume | % Volume |
---|
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x84970A2D...369418674 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
Pool
Compiler Version
v0.8.9+commit.e5eed63a
Optimization Enabled:
Yes with 500 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol'; import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol'; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import {LiqDeltaMath} from './libraries/LiqDeltaMath.sol'; import {QtyDeltaMath} from './libraries/QtyDeltaMath.sol'; import {MathConstants as C} from './libraries/MathConstants.sol'; import {ReinvestmentMath} from './libraries/ReinvestmentMath.sol'; import {SwapMath} from './libraries/SwapMath.sol'; import {FullMath} from './libraries/FullMath.sol'; import {SafeCast} from './libraries/SafeCast.sol'; import {TickMath} from './libraries/TickMath.sol'; import {IPool} from './interfaces/IPool.sol'; import {IPoolActions} from './interfaces/pool/IPoolActions.sol'; import {IFactory} from './interfaces/IFactory.sol'; import {IMintCallback} from './interfaces/callback/IMintCallback.sol'; import {ISwapCallback} from './interfaces/callback/ISwapCallback.sol'; import {IFlashCallback} from './interfaces/callback/IFlashCallback.sol'; import {PoolTicksState} from './PoolTicksState.sol'; contract Pool is IPool, PoolTicksState, ERC20('KyberSwap v2 Reinvestment Token', 'KS2-RT') { using SafeCast for uint256; using SafeCast for int256; using SafeERC20 for IERC20; constructor() {} /// @dev Get pool's balance of token0 /// Gas saving to avoid a redundant extcodesize check /// in addition to the returndatasize check function _poolBalToken0() private view returns (uint256) { (bool success, bytes memory data) = address(token0).staticcall( abi.encodeWithSelector(IERC20.balanceOf.selector, address(this)) ); require(success && data.length >= 32); return abi.decode(data, (uint256)); } /// @dev Get pool's balance of token1 /// Gas saving to avoid a redundant extcodesize check /// in addition to the returndatasize check function _poolBalToken1() private view returns (uint256) { (bool success, bytes memory data) = address(token1).staticcall( abi.encodeWithSelector(IERC20.balanceOf.selector, address(this)) ); require(success && data.length >= 32); return abi.decode(data, (uint256)); } /// @inheritdoc IPoolActions function unlockPool(uint160 initialSqrtP) external override returns (uint256 qty0, uint256 qty1) { require(poolData.sqrtP == 0, 'already inited'); // initial tick bounds (min & max price limits) are checked in this function int24 initialTick = TickMath.getTickAtSqrtRatio(initialSqrtP); (qty0, qty1) = QtyDeltaMath.calcUnlockQtys(initialSqrtP); // because of price bounds, qty0 and qty1 >= 1 require(qty0 <= _poolBalToken0(), 'lacking qty0'); require(qty1 <= _poolBalToken1(), 'lacking qty1'); _mint(address(this), C.MIN_LIQUIDITY); _initPoolStorage(initialSqrtP, initialTick); emit Initialize(initialSqrtP, initialTick); } /// @dev Make changes to a position /// @param posData the position details and the change to the position's liquidity to effect /// @return qty0 token0 qty owed to the pool, negative if the pool should pay the recipient /// @return qty1 token1 qty owed to the pool, negative if the pool should pay the recipient function _tweakPosition(UpdatePositionData memory posData) private returns ( int256 qty0, int256 qty1, uint256 feeGrowthInsideLast ) { require(posData.tickLower < posData.tickUpper, 'invalid tick range'); require(TickMath.MIN_TICK <= posData.tickLower, 'invalid lower tick'); require(posData.tickUpper <= TickMath.MAX_TICK, 'invalid upper tick'); require( posData.tickLower % tickDistance == 0 && posData.tickUpper % tickDistance == 0, 'tick not in distance' ); // SLOAD variables into memory uint160 sqrtP = poolData.sqrtP; int24 currentTick = poolData.currentTick; uint128 baseL = poolData.baseL; uint128 reinvestL = poolData.reinvestL; CumulativesData memory cumulatives; cumulatives.feeGrowth = _syncFeeGrowth(baseL, reinvestL, poolData.feeGrowthGlobal, true); cumulatives.secondsPerLiquidity = _syncSecondsPerLiquidity( poolData.secondsPerLiquidityGlobal, baseL ); uint256 feesClaimable; (feesClaimable, feeGrowthInsideLast) = _updatePosition(posData, currentTick, cumulatives); if (feesClaimable != 0) _transfer(address(this), posData.owner, feesClaimable); if (currentTick < posData.tickLower) { // current tick < position range // liquidity only comes in range when tick increases // which occurs when pool increases in token1, decreases in token0 // means token0 is appreciating more against token1 // hence user should provide token0 return ( QtyDeltaMath.calcRequiredQty0( TickMath.getSqrtRatioAtTick(posData.tickLower), TickMath.getSqrtRatioAtTick(posData.tickUpper), posData.liquidityDelta, posData.isAddLiquidity ), 0, feeGrowthInsideLast ); } if (currentTick >= posData.tickUpper) { // current tick > position range // liquidity only comes in range when tick decreases // which occurs when pool decreases in token1, increases in token0 // means token1 is appreciating more against token0 // hence user should provide token1 return ( 0, QtyDeltaMath.calcRequiredQty1( TickMath.getSqrtRatioAtTick(posData.tickLower), TickMath.getSqrtRatioAtTick(posData.tickUpper), posData.liquidityDelta, posData.isAddLiquidity ), feeGrowthInsideLast ); } // write an oracle entry poolOracle.write(_blockTimestamp(), currentTick, baseL); // current tick is inside the passed range qty0 = QtyDeltaMath.calcRequiredQty0( sqrtP, TickMath.getSqrtRatioAtTick(posData.tickUpper), posData.liquidityDelta, posData.isAddLiquidity ); qty1 = QtyDeltaMath.calcRequiredQty1( TickMath.getSqrtRatioAtTick(posData.tickLower), sqrtP, posData.liquidityDelta, posData.isAddLiquidity ); // in addition, add liquidityDelta to current poolData.baseL // since liquidity is in range poolData.baseL = LiqDeltaMath.applyLiquidityDelta( baseL, posData.liquidityDelta, posData.isAddLiquidity ); } /// @inheritdoc IPoolActions function mint( address recipient, int24 tickLower, int24 tickUpper, int24[2] calldata ticksPrevious, uint128 qty, bytes calldata data ) external override lock returns ( uint256 qty0, uint256 qty1, uint256 feeGrowthInsideLast ) { require(qty != 0, '0 qty'); require(factory.isWhitelistedNFTManager(msg.sender), 'forbidden'); int256 qty0Int; int256 qty1Int; (qty0Int, qty1Int, feeGrowthInsideLast) = _tweakPosition( UpdatePositionData({ owner: recipient, tickLower: tickLower, tickUpper: tickUpper, tickLowerPrevious: ticksPrevious[0], tickUpperPrevious: ticksPrevious[1], liquidityDelta: qty, isAddLiquidity: true }) ); qty0 = uint256(qty0Int); qty1 = uint256(qty1Int); uint256 balance0Before; uint256 balance1Before; if (qty0 > 0) balance0Before = _poolBalToken0(); if (qty1 > 0) balance1Before = _poolBalToken1(); IMintCallback(msg.sender).mintCallback(qty0, qty1, data); if (qty0 > 0) require(balance0Before + qty0 <= _poolBalToken0(), 'lacking qty0'); if (qty1 > 0) require(balance1Before + qty1 <= _poolBalToken1(), 'lacking qty1'); emit Mint(msg.sender, recipient, tickLower, tickUpper, qty, qty0, qty1); } /// @inheritdoc IPoolActions function burn( int24 tickLower, int24 tickUpper, uint128 qty ) external override lock returns ( uint256 qty0, uint256 qty1, uint256 feeGrowthInsideLast ) { require(qty != 0, '0 qty'); int256 qty0Int; int256 qty1Int; (qty0Int, qty1Int, feeGrowthInsideLast) = _tweakPosition( UpdatePositionData({ owner: msg.sender, tickLower: tickLower, tickUpper: tickUpper, tickLowerPrevious: 0, // no use as there is no insertion tickUpperPrevious: 0, // no use as there is no insertion liquidityDelta: qty, isAddLiquidity: false }) ); if (qty0Int < 0) { qty0 = qty0Int.revToUint256(); token0.safeTransfer(msg.sender, qty0); } if (qty1Int < 0) { qty1 = qty1Int.revToUint256(); token1.safeTransfer(msg.sender, qty1); } emit Burn(msg.sender, tickLower, tickUpper, qty, qty0, qty1); } /// @inheritdoc IPoolActions function burnRTokens(uint256 _qty, bool isLogicalBurn) external override lock returns (uint256 qty0, uint256 qty1) { if (isLogicalBurn) { _burn(msg.sender, _qty); emit BurnRTokens(msg.sender, _qty, 0, 0); return (0, 0); } // SLOADs for gas optimizations uint128 baseL = poolData.baseL; uint128 reinvestL = poolData.reinvestL; uint160 sqrtP = poolData.sqrtP; _syncFeeGrowth(baseL, reinvestL, poolData.feeGrowthGlobal, false); // totalSupply() is the reinvestment token supply after syncing, but before burning uint256 deltaL = FullMath.mulDivFloor(_qty, reinvestL, totalSupply()); reinvestL = reinvestL - deltaL.toUint128(); poolData.reinvestL = reinvestL; poolData.reinvestLLast = reinvestL; // finally, calculate and send token quantities to user qty0 = QtyDeltaMath.getQty0FromBurnRTokens(sqrtP, deltaL); qty1 = QtyDeltaMath.getQty1FromBurnRTokens(sqrtP, deltaL); _burn(msg.sender, _qty); if (qty0 > 0) token0.safeTransfer(msg.sender, qty0); if (qty1 > 0) token1.safeTransfer(msg.sender, qty1); emit BurnRTokens(msg.sender, _qty, qty0, qty1); } // temporary swap variables, some of which will be used to update the pool state struct SwapData { int256 specifiedAmount; // the specified amount (could be tokenIn or tokenOut) int256 returnedAmount; // the opposite amout of sourceQty uint160 sqrtP; // current sqrt(price), multiplied by 2^96 int24 currentTick; // the tick associated with the current price int24 nextTick; // the next initialized tick uint160 nextSqrtP; // the price of nextTick bool isToken0; // true if specifiedAmount is in token0, false if in token1 bool isExactInput; // true = input qty, false = output qty uint128 baseL; // the cached base pool liquidity without reinvestment liquidity uint128 reinvestL; // the cached reinvestment liquidity uint160 startSqrtP; // the start sqrt price before each iteration } // variables below are loaded only when crossing a tick struct SwapCache { uint256 rTotalSupply; // cache of total reinvestment token supply uint128 reinvestLLast; // collected liquidity uint256 feeGrowthGlobal; // cache of fee growth of the reinvestment token, multiplied by 2^96 uint128 secondsPerLiquidityGlobal; // all-time seconds per liquidity, multiplied by 2^96 address feeTo; // recipient of govt fees uint24 governmentFeeUnits; // governmentFeeUnits to be charged uint256 governmentFee; // qty of reinvestment token for government fee uint256 lpFee; // qty of reinvestment token for liquidity provider } struct OracleCache { int24 currentTick; uint128 baseL; } // @inheritdoc IPoolActions function swap( address recipient, int256 swapQty, bool isToken0, uint160 limitSqrtP, bytes calldata data ) external override lock returns (int256 deltaQty0, int256 deltaQty1) { require(swapQty != 0, '0 swapQty'); SwapData memory swapData; swapData.specifiedAmount = swapQty; swapData.isToken0 = isToken0; swapData.isExactInput = swapData.specifiedAmount > 0; // tick (token1Qty/token0Qty) will increase for swapping from token1 to token0 bool willUpTick = (swapData.isExactInput != isToken0); ( swapData.baseL, swapData.reinvestL, swapData.sqrtP, swapData.currentTick, swapData.nextTick ) = _getInitialSwapData(willUpTick); // cache data before swap to write into oracle if needed OracleCache memory oracleCache = OracleCache({ currentTick: swapData.currentTick, baseL: swapData.baseL }); // verify limitSqrtP if (willUpTick) { require( limitSqrtP > swapData.sqrtP && limitSqrtP < TickMath.MAX_SQRT_RATIO, 'bad limitSqrtP' ); } else { require( limitSqrtP < swapData.sqrtP && limitSqrtP > TickMath.MIN_SQRT_RATIO, 'bad limitSqrtP' ); } SwapCache memory cache; // continue swapping while specified input/output isn't satisfied or price limit not reached while (swapData.specifiedAmount != 0 && swapData.sqrtP != limitSqrtP) { // math calculations work with the assumption that the price diff is capped to 5% // since tick distance is uncapped between currentTick and nextTick // we use tempNextTick to satisfy our assumption with MAX_TICK_DISTANCE is set to be matched this condition int24 tempNextTick = swapData.nextTick; if (willUpTick && tempNextTick > C.MAX_TICK_DISTANCE + swapData.currentTick) { tempNextTick = swapData.currentTick + C.MAX_TICK_DISTANCE; } else if (!willUpTick && tempNextTick < swapData.currentTick - C.MAX_TICK_DISTANCE) { tempNextTick = swapData.currentTick - C.MAX_TICK_DISTANCE; } swapData.startSqrtP = swapData.sqrtP; swapData.nextSqrtP = TickMath.getSqrtRatioAtTick(tempNextTick); // local scope for targetSqrtP, usedAmount, returnedAmount and deltaL { uint160 targetSqrtP = swapData.nextSqrtP; // ensure next sqrtP (and its corresponding tick) does not exceed price limit if (willUpTick == (swapData.nextSqrtP > limitSqrtP)) { targetSqrtP = limitSqrtP; } int256 usedAmount; int256 returnedAmount; uint256 deltaL; (usedAmount, returnedAmount, deltaL, swapData.sqrtP) = SwapMath.computeSwapStep( swapData.baseL + swapData.reinvestL, swapData.sqrtP, targetSqrtP, swapFeeUnits, swapData.specifiedAmount, swapData.isExactInput, swapData.isToken0 ); swapData.specifiedAmount -= usedAmount; swapData.returnedAmount += returnedAmount; swapData.reinvestL += deltaL.toUint128(); } // if price has not reached the next sqrt price if (swapData.sqrtP != swapData.nextSqrtP) { if (swapData.sqrtP != swapData.startSqrtP) { // update the current tick data in case the sqrtP has changed swapData.currentTick = TickMath.getTickAtSqrtRatio(swapData.sqrtP); } break; } swapData.currentTick = willUpTick ? tempNextTick : tempNextTick - 1; // if tempNextTick is not next initialized tick if (tempNextTick != swapData.nextTick) continue; if (cache.rTotalSupply == 0) { // load variables that are only initialized when crossing a tick cache.rTotalSupply = totalSupply(); cache.reinvestLLast = poolData.reinvestLLast; cache.feeGrowthGlobal = poolData.feeGrowthGlobal; cache.secondsPerLiquidityGlobal = _syncSecondsPerLiquidity( poolData.secondsPerLiquidityGlobal, swapData.baseL ); (cache.feeTo, cache.governmentFeeUnits) = factory.feeConfiguration(); } // update rTotalSupply, feeGrowthGlobal and reinvestL uint256 rMintQty = ReinvestmentMath.calcrMintQty( swapData.reinvestL, cache.reinvestLLast, swapData.baseL, cache.rTotalSupply ); if (rMintQty != 0) { cache.rTotalSupply += rMintQty; // overflow/underflow not possible bc governmentFeeUnits < 20000 unchecked { uint256 governmentFee = (rMintQty * cache.governmentFeeUnits) / C.FEE_UNITS; cache.governmentFee += governmentFee; uint256 lpFee = rMintQty - governmentFee; cache.lpFee += lpFee; cache.feeGrowthGlobal += FullMath.mulDivFloor(lpFee, C.TWO_POW_96, swapData.baseL); } } cache.reinvestLLast = swapData.reinvestL; (swapData.baseL, swapData.nextTick) = _updateLiquidityAndCrossTick( swapData.nextTick, swapData.baseL, cache.feeGrowthGlobal, cache.secondsPerLiquidityGlobal, willUpTick ); } // if the swap crosses at least 1 initalized tick if (cache.rTotalSupply != 0) { if (cache.governmentFee > 0) _mint(cache.feeTo, cache.governmentFee); if (cache.lpFee > 0) _mint(address(this), cache.lpFee); poolData.reinvestLLast = cache.reinvestLLast; poolData.feeGrowthGlobal = cache.feeGrowthGlobal; } // write an oracle entry if tick changed if (swapData.currentTick != oracleCache.currentTick) { poolOracle.write(_blockTimestamp(), oracleCache.currentTick, oracleCache.baseL); } _updatePoolData( swapData.baseL, swapData.reinvestL, swapData.sqrtP, swapData.currentTick, swapData.nextTick ); (deltaQty0, deltaQty1) = isToken0 ? (swapQty - swapData.specifiedAmount, swapData.returnedAmount) : (swapData.returnedAmount, swapQty - swapData.specifiedAmount); // handle token transfers and perform callback if (willUpTick) { // outbound deltaQty0 (negative), inbound deltaQty1 (positive) // transfer deltaQty0 to recipient if (deltaQty0 < 0) token0.safeTransfer(recipient, deltaQty0.revToUint256()); // collect deltaQty1 uint256 balance1Before = _poolBalToken1(); ISwapCallback(msg.sender).swapCallback(deltaQty0, deltaQty1, data); require(_poolBalToken1() >= balance1Before + uint256(deltaQty1), 'lacking deltaQty1'); } else { // inbound deltaQty0 (positive), outbound deltaQty1 (negative) // transfer deltaQty1 to recipient if (deltaQty1 < 0) token1.safeTransfer(recipient, deltaQty1.revToUint256()); // collect deltaQty0 uint256 balance0Before = _poolBalToken0(); ISwapCallback(msg.sender).swapCallback(deltaQty0, deltaQty1, data); require(_poolBalToken0() >= balance0Before + uint256(deltaQty0), 'lacking deltaQty0'); } emit Swap( msg.sender, recipient, deltaQty0, deltaQty1, swapData.sqrtP, swapData.baseL, swapData.currentTick ); } /// @inheritdoc IPoolActions function flash( address recipient, uint256 qty0, uint256 qty1, bytes calldata data ) external override lock { // send all collected fees to feeTo (address feeTo, ) = factory.feeConfiguration(); uint256 feeQty0; uint256 feeQty1; if (feeTo != address(0)) { feeQty0 = (qty0 * swapFeeUnits) / C.FEE_UNITS; feeQty1 = (qty1 * swapFeeUnits) / C.FEE_UNITS; } uint256 balance0Before = _poolBalToken0(); uint256 balance1Before = _poolBalToken1(); if (qty0 > 0) token0.safeTransfer(recipient, qty0); if (qty1 > 0) token1.safeTransfer(recipient, qty1); IFlashCallback(msg.sender).flashCallback(feeQty0, feeQty1, data); uint256 balance0After = _poolBalToken0(); uint256 balance1After = _poolBalToken1(); require(balance0Before + feeQty0 <= balance0After, 'lacking feeQty0'); require(balance1Before + feeQty1 <= balance1After, 'lacking feeQty1'); uint256 paid0; uint256 paid1; unchecked { paid0 = balance0After - balance0Before; paid1 = balance1After - balance1Before; } if (paid0 > 0) token0.safeTransfer(feeTo, paid0); if (paid1 > 0) token1.safeTransfer(feeTo, paid1); emit Flash(msg.sender, recipient, qty0, qty1, paid0, paid1); } /// @dev sync the value of secondsPerLiquidity data to current block.timestamp /// @return new value of _secondsPerLiquidityGlobal function _syncSecondsPerLiquidity(uint128 _secondsPerLiquidityGlobal, uint128 baseL) internal returns (uint128) { uint256 secondsElapsed = _blockTimestamp() - poolData.secondsPerLiquidityUpdateTime; // update secondsPerLiquidityGlobal and secondsPerLiquidityUpdateTime if needed if (secondsElapsed > 0) { poolData.secondsPerLiquidityUpdateTime = _blockTimestamp(); if (baseL > 0) { _secondsPerLiquidityGlobal += uint128((secondsElapsed << C.RES_96) / baseL); // write to storage poolData.secondsPerLiquidityGlobal = _secondsPerLiquidityGlobal; } } return _secondsPerLiquidityGlobal; } function tweakPosZeroLiq(int24 tickLower, int24 tickUpper) external override lock returns (uint256 feeGrowthInsideLast) { require(factory.isWhitelistedNFTManager(msg.sender), 'forbidden'); require(tickLower < tickUpper, 'invalid tick range'); require(TickMath.MIN_TICK <= tickLower, 'invalid lower tick'); require(tickUpper <= TickMath.MAX_TICK, 'invalid upper tick'); require( tickLower % tickDistance == 0 && tickUpper % tickDistance == 0, 'tick not in distance' ); bytes32 key = _positionKey(msg.sender, tickLower, tickUpper); require(positions[key].liquidity > 0, 'invalid position'); // SLOAD variables into memory uint128 baseL = poolData.baseL; CumulativesData memory cumulatives; cumulatives.feeGrowth = _syncFeeGrowth(baseL, poolData.reinvestL, poolData.feeGrowthGlobal, true); cumulatives.secondsPerLiquidity = _syncSecondsPerLiquidity( poolData.secondsPerLiquidityGlobal, baseL ); uint256 feesClaimable; (feesClaimable, feeGrowthInsideLast) = _updatePosition( UpdatePositionData({ owner: msg.sender, tickLower: tickLower, tickUpper: tickUpper, tickLowerPrevious: 0, tickUpperPrevious: 0, liquidityDelta: 0, isAddLiquidity: false }) , poolData.currentTick, cumulatives); if (feesClaimable != 0) _transfer(address(this), msg.sender, feesClaimable); } /// @dev sync the value of feeGrowthGlobal and the value of each reinvestment token. /// @dev update reinvestLLast to latest value if necessary /// @return the lastest value of _feeGrowthGlobal function _syncFeeGrowth( uint128 baseL, uint128 reinvestL, uint256 _feeGrowthGlobal, bool updateReinvestLLast ) internal returns (uint256) { uint256 rMintQty = ReinvestmentMath.calcrMintQty( uint256(reinvestL), uint256(poolData.reinvestLLast), baseL, totalSupply() ); if (rMintQty != 0) { rMintQty = _deductGovermentFee(rMintQty); _mint(address(this), rMintQty); // baseL != 0 because baseL = 0 => rMintQty = 0 unchecked { _feeGrowthGlobal += FullMath.mulDivFloor(rMintQty, C.TWO_POW_96, baseL); } poolData.feeGrowthGlobal = _feeGrowthGlobal; } // update poolData.reinvestLLast if required if (updateReinvestLLast) poolData.reinvestLLast = reinvestL; return _feeGrowthGlobal; } /// @return the lp fee without governance fee function _deductGovermentFee(uint256 rMintQty) internal returns (uint256) { // fetch governmentFeeUnits (address feeTo, uint24 governmentFeeUnits) = factory.feeConfiguration(); if (governmentFeeUnits == 0) { return rMintQty; } // unchecked due to governmentFeeUnits <= 20000 unchecked { uint256 rGovtQty = (rMintQty * governmentFeeUnits) / C.FEE_UNITS; if (rGovtQty != 0) { _mint(feeTo, rGovtQty); } return rMintQty - rGovtQty; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * Requirements: * * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom( address sender, address recipient, uint256 amount ) public virtual override returns (bool) { _transfer(sender, recipient, amount); uint256 currentAllowance = _allowances[sender][_msgSender()]; require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); unchecked { _approve(sender, _msgSender(), currentAllowance - amount); } return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { uint256 currentAllowance = _allowances[_msgSender()][spender]; require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(_msgSender(), spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `sender` to `recipient`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer( address sender, address recipient, uint256 amount ) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); uint256 senderBalance = _balances[sender]; require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[sender] = senderBalance - amount; } _balances[recipient] += amount; emit Transfer(sender, recipient, amount); _afterTokenTransfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address sender, address recipient, uint256 amount ) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; /// @title Contains helper function to add or remove uint128 liquidityDelta to uint128 liquidity library LiqDeltaMath { function applyLiquidityDelta( uint128 liquidity, uint128 liquidityDelta, bool isAddLiquidity ) internal pure returns (uint128) { return isAddLiquidity ? liquidity + liquidityDelta : liquidity - liquidityDelta; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; import {MathConstants as C} from './MathConstants.sol'; import {TickMath} from './TickMath.sol'; import {FullMath} from './FullMath.sol'; import {SafeCast} from './SafeCast.sol'; /// @title Contains helper functions for calculating /// token0 and token1 quantites from differences in prices /// or from burning reinvestment tokens library QtyDeltaMath { using SafeCast for uint256; using SafeCast for int128; function calcUnlockQtys(uint160 initialSqrtP) internal pure returns (uint256 qty0, uint256 qty1) { qty0 = FullMath.mulDivCeiling(C.MIN_LIQUIDITY, C.TWO_POW_96, initialSqrtP); qty1 = FullMath.mulDivCeiling(C.MIN_LIQUIDITY, initialSqrtP, C.TWO_POW_96); } /// @notice Gets the qty0 delta between two prices /// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper), /// i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower)) /// rounds up if adding liquidity, rounds down if removing liquidity /// @param lowerSqrtP The lower sqrt price. /// @param upperSqrtP The upper sqrt price. Should be >= lowerSqrtP /// @param liquidity Liquidity quantity /// @param isAddLiquidity true = add liquidity, false = remove liquidity /// @return token0 qty required for position with liquidity between the 2 sqrt prices function calcRequiredQty0( uint160 lowerSqrtP, uint160 upperSqrtP, uint128 liquidity, bool isAddLiquidity ) internal pure returns (int256) { uint256 numerator1 = uint256(liquidity) << C.RES_96; uint256 numerator2; unchecked { numerator2 = upperSqrtP - lowerSqrtP; } return isAddLiquidity ? (divCeiling(FullMath.mulDivCeiling(numerator1, numerator2, upperSqrtP), lowerSqrtP)) .toInt256() : (FullMath.mulDivFloor(numerator1, numerator2, upperSqrtP) / lowerSqrtP).revToInt256(); } /// @notice Gets the token1 delta quantity between two prices /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower)) /// rounds up if adding liquidity, rounds down if removing liquidity /// @param lowerSqrtP The lower sqrt price. /// @param upperSqrtP The upper sqrt price. Should be >= lowerSqrtP /// @param liquidity Liquidity quantity /// @param isAddLiquidity true = add liquidity, false = remove liquidity /// @return token1 qty required for position with liquidity between the 2 sqrt prices function calcRequiredQty1( uint160 lowerSqrtP, uint160 upperSqrtP, uint128 liquidity, bool isAddLiquidity ) internal pure returns (int256) { unchecked { return isAddLiquidity ? (FullMath.mulDivCeiling(liquidity, upperSqrtP - lowerSqrtP, C.TWO_POW_96)).toInt256() : (FullMath.mulDivFloor(liquidity, upperSqrtP - lowerSqrtP, C.TWO_POW_96)).revToInt256(); } } /// @notice Calculates the token0 quantity proportion to be sent to the user /// for burning reinvestment tokens /// @param sqrtP Current pool sqrt price /// @param liquidity Difference in reinvestment liquidity due to reinvestment token burn /// @return token0 quantity to be sent to the user function getQty0FromBurnRTokens(uint160 sqrtP, uint256 liquidity) internal pure returns (uint256) { return FullMath.mulDivFloor(liquidity, C.TWO_POW_96, sqrtP); } /// @notice Calculates the token1 quantity proportion to be sent to the user /// for burning reinvestment tokens /// @param sqrtP Current pool sqrt price /// @param liquidity Difference in reinvestment liquidity due to reinvestment token burn /// @return token1 quantity to be sent to the user function getQty1FromBurnRTokens(uint160 sqrtP, uint256 liquidity) internal pure returns (uint256) { return FullMath.mulDivFloor(liquidity, sqrtP, C.TWO_POW_96); } /// @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 divCeiling(uint256 x, uint256 y) internal pure returns (uint256 z) { // return x / y + ((x % y == 0) ? 0 : 1); require(y > 0); assembly { z := add(div(x, y), gt(mod(x, y), 0)) } } }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; /// @title Contains constants needed for math libraries library MathConstants { uint256 internal constant TWO_FEE_UNITS = 200_000; uint256 internal constant TWO_POW_96 = 2 ** 96; uint128 internal constant MIN_LIQUIDITY = 100; uint8 internal constant RES_96 = 96; uint24 internal constant FEE_UNITS = 100000; // it is strictly less than 5% price movement if jumping MAX_TICK_DISTANCE ticks int24 internal constant MAX_TICK_DISTANCE = 480; // max number of tick travel when inserting if data changes uint256 internal constant MAX_TICK_TRAVEL = 10; }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; import {MathConstants as C} from './MathConstants.sol'; import {FullMath} from './FullMath.sol'; /// @title Contains helper function to calculate the number of reinvestment tokens to be minted library ReinvestmentMath { /// @dev calculate the mint amount with given reinvestL, reinvestLLast, baseL and rTotalSupply /// contribution of lp to the increment is calculated by the proportion of baseL with reinvestL + baseL /// then rMintQty is calculated by mutiplying this with the liquidity per reinvestment token /// rMintQty = rTotalSupply * (reinvestL - reinvestLLast) / reinvestLLast * baseL / (baseL + reinvestL) function calcrMintQty( uint256 reinvestL, uint256 reinvestLLast, uint128 baseL, uint256 rTotalSupply ) internal pure returns (uint256 rMintQty) { uint256 lpContribution = FullMath.mulDivFloor( baseL, reinvestL - reinvestLLast, baseL + reinvestL ); rMintQty = FullMath.mulDivFloor(rTotalSupply, lpContribution, reinvestLLast); } }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; import {MathConstants as C} from './MathConstants.sol'; import {FullMath} from './FullMath.sol'; import {QuadMath} from './QuadMath.sol'; import {SafeCast} from './SafeCast.sol'; /// @title Contains helper functions for swaps library SwapMath { using SafeCast for uint256; using SafeCast for int256; /// @dev Computes the actual swap input / output amounts to be deducted or added, /// the swap fee to be collected and the resulting sqrtP. /// @notice nextSqrtP should not exceed targetSqrtP. /// @param liquidity active base liquidity + reinvest liquidity /// @param currentSqrtP current sqrt price /// @param targetSqrtP sqrt price limit the new sqrt price can take /// @param feeInFeeUnits swap fee in basis points /// @param specifiedAmount the amount remaining to be used for the swap /// @param isExactInput true if specifiedAmount refers to input amount, false if specifiedAmount refers to output amount /// @param isToken0 true if specifiedAmount is in token0, false if specifiedAmount is in token1 /// @return usedAmount actual amount to be used for the swap /// @return returnedAmount output qty to be accumulated if isExactInput = true, input qty if isExactInput = false /// @return deltaL collected swap fee, to be incremented to reinvest liquidity /// @return nextSqrtP the new sqrt price after the computed swap step function computeSwapStep( uint256 liquidity, uint160 currentSqrtP, uint160 targetSqrtP, uint256 feeInFeeUnits, int256 specifiedAmount, bool isExactInput, bool isToken0 ) internal pure returns ( int256 usedAmount, int256 returnedAmount, uint256 deltaL, uint160 nextSqrtP ) { // in the event currentSqrtP == targetSqrtP because of tick movements, return // eg. swapped up tick where specified price limit is on an initialised tick // then swapping down tick will cause next tick to be the same as the current tick if (currentSqrtP == targetSqrtP) return (0, 0, 0, currentSqrtP); usedAmount = calcReachAmount( liquidity, currentSqrtP, targetSqrtP, feeInFeeUnits, isExactInput, isToken0 ); if ( (isExactInput && usedAmount > specifiedAmount) || (!isExactInput && usedAmount <= specifiedAmount) ) { usedAmount = specifiedAmount; } else { nextSqrtP = targetSqrtP; } uint256 absDelta = usedAmount >= 0 ? uint256(usedAmount) : usedAmount.revToUint256(); if (nextSqrtP == 0) { deltaL = estimateIncrementalLiquidity( absDelta, liquidity, currentSqrtP, feeInFeeUnits, isExactInput, isToken0 ); nextSqrtP = calcFinalPrice(absDelta, liquidity, deltaL, currentSqrtP, isExactInput, isToken0) .toUint160(); } else { deltaL = calcIncrementalLiquidity( absDelta, liquidity, currentSqrtP, nextSqrtP, isExactInput, isToken0 ); } returnedAmount = calcReturnedAmount( liquidity, currentSqrtP, nextSqrtP, deltaL, isExactInput, isToken0 ); } /// @dev calculates the amount needed to reach targetSqrtP from currentSqrtP /// @dev we cast currentSqrtP and targetSqrtP to uint256 as they are multiplied by TWO_FEE_UNITS or feeInFeeUnits function calcReachAmount( uint256 liquidity, uint256 currentSqrtP, uint256 targetSqrtP, uint256 feeInFeeUnits, bool isExactInput, bool isToken0 ) internal pure returns (int256 reachAmount) { uint256 absPriceDiff; unchecked { absPriceDiff = (currentSqrtP >= targetSqrtP) ? (currentSqrtP - targetSqrtP) : (targetSqrtP - currentSqrtP); } if (isExactInput) { // we round down so that we avoid taking giving away too much for the specified input // ie. require less input qty to move ticks if (isToken0) { // numerator = 2 * liquidity * absPriceDiff // denominator = currentSqrtP * (2 * targetSqrtP - currentSqrtP * feeInFeeUnits / FEE_UNITS) // overflow should not happen because the absPriceDiff is capped to ~5% uint256 denominator = C.TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * currentSqrtP; uint256 numerator = FullMath.mulDivFloor( liquidity, C.TWO_FEE_UNITS * absPriceDiff, denominator ); reachAmount = FullMath.mulDivFloor(numerator, C.TWO_POW_96, currentSqrtP).toInt256(); } else { // numerator = 2 * liquidity * absPriceDiff * currentSqrtP // denominator = 2 * currentSqrtP - targetSqrtP * feeInFeeUnits / FEE_UNITS // overflow should not happen because the absPriceDiff is capped to ~5% uint256 denominator = C.TWO_FEE_UNITS * currentSqrtP - feeInFeeUnits * targetSqrtP; uint256 numerator = FullMath.mulDivFloor( liquidity, C.TWO_FEE_UNITS * absPriceDiff, denominator ); reachAmount = FullMath.mulDivFloor(numerator, currentSqrtP, C.TWO_POW_96).toInt256(); } } else { // we will perform negation as the last step // we round down so that we require less output qty to move ticks if (isToken0) { // numerator: (liquidity)(absPriceDiff)(2 * currentSqrtP - deltaL * (currentSqrtP + targetSqrtP)) // denominator: (currentSqrtP * targetSqrtP) * (2 * currentSqrtP - deltaL * targetSqrtP) // overflow should not happen because the absPriceDiff is capped to ~5% uint256 denominator = C.TWO_FEE_UNITS * currentSqrtP - feeInFeeUnits * targetSqrtP; uint256 numerator = denominator - feeInFeeUnits * currentSqrtP; numerator = FullMath.mulDivFloor(liquidity << C.RES_96, numerator, denominator); reachAmount = (FullMath.mulDivFloor(numerator, absPriceDiff, currentSqrtP) / targetSqrtP) .revToInt256(); } else { // numerator: liquidity * absPriceDiff * (TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * (targetSqrtP + currentSqrtP)) // denominator: (TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * currentSqrtP) // overflow should not happen because the absPriceDiff is capped to ~5% uint256 denominator = C.TWO_FEE_UNITS * targetSqrtP - feeInFeeUnits * currentSqrtP; uint256 numerator = denominator - feeInFeeUnits * targetSqrtP; numerator = FullMath.mulDivFloor(liquidity, numerator, denominator); reachAmount = FullMath.mulDivFloor(numerator, absPriceDiff, C.TWO_POW_96).revToInt256(); } } } /// @dev estimates deltaL, the swap fee to be collected based on amount specified /// for the final swap step to be performed, /// where the next (temporary) tick will not be crossed function estimateIncrementalLiquidity( uint256 absDelta, uint256 liquidity, uint160 currentSqrtP, uint256 feeInFeeUnits, bool isExactInput, bool isToken0 ) internal pure returns (uint256 deltaL) { if (isExactInput) { if (isToken0) { // deltaL = feeInFeeUnits * absDelta * currentSqrtP / 2 deltaL = FullMath.mulDivFloor( currentSqrtP, absDelta * feeInFeeUnits, C.TWO_FEE_UNITS << C.RES_96 ); } else { // deltaL = feeInFeeUnits * absDelta * / (currentSqrtP * 2) // Because nextSqrtP = (liquidity + absDelta / currentSqrtP) * currentSqrtP / (liquidity + deltaL) // so we round up deltaL, to round down nextSqrtP deltaL = FullMath.mulDivFloor( C.TWO_POW_96, absDelta * feeInFeeUnits, C.TWO_FEE_UNITS * currentSqrtP ); } } else { // obtain the smaller root of the quadratic equation // ax^2 - 2bx + c = 0 such that b > 0, and x denotes deltaL uint256 a = feeInFeeUnits; uint256 b = (C.FEE_UNITS - feeInFeeUnits) * liquidity; uint256 c = feeInFeeUnits * liquidity * absDelta; if (isToken0) { // a = feeInFeeUnits // b = (FEE_UNITS - feeInFeeUnits) * liquidity - FEE_UNITS * absDelta * currentSqrtP // c = feeInFeeUnits * liquidity * absDelta * currentSqrtP b -= FullMath.mulDivFloor(C.FEE_UNITS * absDelta, currentSqrtP, C.TWO_POW_96); c = FullMath.mulDivFloor(c, currentSqrtP, C.TWO_POW_96); } else { // a = feeInFeeUnits // b = (FEE_UNITS - feeInFeeUnits) * liquidity - FEE_UNITS * absDelta / currentSqrtP // c = liquidity * feeInFeeUnits * absDelta / currentSqrtP b -= FullMath.mulDivFloor(C.FEE_UNITS * absDelta, C.TWO_POW_96, currentSqrtP); c = FullMath.mulDivFloor(c, C.TWO_POW_96, currentSqrtP); } deltaL = QuadMath.getSmallerRootOfQuadEqn(a, b, c); } } /// @dev calculates deltaL, the swap fee to be collected for an intermediate swap step, /// where the next (temporary) tick will be crossed function calcIncrementalLiquidity( uint256 absDelta, uint256 liquidity, uint160 currentSqrtP, uint160 nextSqrtP, bool isExactInput, bool isToken0 ) internal pure returns (uint256 deltaL) { if (isToken0) { // deltaL = nextSqrtP * (liquidity / currentSqrtP +/- absDelta)) - liquidity // needs to be minimum uint256 tmp1 = FullMath.mulDivFloor(liquidity, C.TWO_POW_96, currentSqrtP); uint256 tmp2 = isExactInput ? tmp1 + absDelta : tmp1 - absDelta; uint256 tmp3 = FullMath.mulDivFloor(nextSqrtP, tmp2, C.TWO_POW_96); // in edge cases where liquidity or absDelta is small // liquidity might be greater than nextSqrtP * ((liquidity / currentSqrtP) +/- absDelta)) // due to rounding deltaL = (tmp3 > liquidity) ? tmp3 - liquidity : 0; } else { // deltaL = (liquidity * currentSqrtP +/- absDelta) / nextSqrtP - liquidity // needs to be minimum uint256 tmp1 = FullMath.mulDivFloor(liquidity, currentSqrtP, C.TWO_POW_96); uint256 tmp2 = isExactInput ? tmp1 + absDelta : tmp1 - absDelta; uint256 tmp3 = FullMath.mulDivFloor(tmp2, C.TWO_POW_96, nextSqrtP); // in edge cases where liquidity or absDelta is small // liquidity might be greater than nextSqrtP * ((liquidity / currentSqrtP) +/- absDelta)) // due to rounding deltaL = (tmp3 > liquidity) ? tmp3 - liquidity : 0; } } /// @dev calculates the sqrt price of the final swap step /// where the next (temporary) tick will not be crossed function calcFinalPrice( uint256 absDelta, uint256 liquidity, uint256 deltaL, uint160 currentSqrtP, bool isExactInput, bool isToken0 ) internal pure returns (uint256) { if (isToken0) { // if isExactInput: swap 0 -> 1, sqrtP decreases, we round up // else swap: 1 -> 0, sqrtP increases, we round down uint256 tmp = FullMath.mulDivFloor(absDelta, currentSqrtP, C.TWO_POW_96); if (isExactInput) { return FullMath.mulDivCeiling(liquidity + deltaL, currentSqrtP, liquidity + tmp); } else { return FullMath.mulDivFloor(liquidity + deltaL, currentSqrtP, liquidity - tmp); } } else { // if isExactInput: swap 1 -> 0, sqrtP increases, we round down // else swap: 0 -> 1, sqrtP decreases, we round up uint256 tmp = FullMath.mulDivFloor(absDelta, C.TWO_POW_96, currentSqrtP); if (isExactInput) { return FullMath.mulDivFloor(liquidity + tmp, currentSqrtP, liquidity + deltaL); } else { return FullMath.mulDivCeiling(liquidity - tmp, currentSqrtP, liquidity + deltaL); } } } /// @dev calculates returned output | input tokens in exchange for specified amount /// @dev round down when calculating returned output (isExactInput) so we avoid sending too much /// @dev round up when calculating returned input (!isExactInput) so we get desired output amount function calcReturnedAmount( uint256 liquidity, uint160 currentSqrtP, uint160 nextSqrtP, uint256 deltaL, bool isExactInput, bool isToken0 ) internal pure returns (int256 returnedAmount) { if (isToken0) { if (isExactInput) { // minimise actual output (<0, make less negative) so we avoid sending too much // returnedAmount = deltaL * nextSqrtP - liquidity * (currentSqrtP - nextSqrtP) returnedAmount = FullMath.mulDivCeiling(deltaL, nextSqrtP, C.TWO_POW_96).toInt256() + FullMath.mulDivFloor(liquidity, currentSqrtP - nextSqrtP, C.TWO_POW_96).revToInt256(); } else { // maximise actual input (>0) so we get desired output amount // returnedAmount = deltaL * nextSqrtP + liquidity * (nextSqrtP - currentSqrtP) returnedAmount = FullMath.mulDivCeiling(deltaL, nextSqrtP, C.TWO_POW_96).toInt256() + FullMath.mulDivCeiling(liquidity, nextSqrtP - currentSqrtP, C.TWO_POW_96).toInt256(); } } else { // returnedAmount = (liquidity + deltaL)/nextSqrtP - (liquidity)/currentSqrtP // if exactInput, minimise actual output (<0, make less negative) so we avoid sending too much // if exactOutput, maximise actual input (>0) so we get desired output amount returnedAmount = FullMath.mulDivCeiling(liquidity + deltaL, C.TWO_POW_96, nextSqrtP).toInt256() + FullMath.mulDivFloor(liquidity, C.TWO_POW_96, currentSqrtP).revToInt256(); } if (isExactInput && returnedAmount == 1) { // rounding make returnedAmount == 1 returnedAmount = 0; } } }
// SPDX-License-Identifier: MIT pragma solidity >=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 /// @dev Code has been modified to be compatible with sol 0.8 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 mulDivFloor( 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, '0 denom'); assembly { result := div(prod0, denominator) } return result; } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1, 'denom <= 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 + 1); // 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) } unchecked { 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 mulDivCeiling( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { result = mulDivFloor(a, b, denominator); if (mulmod(a, b, denominator) > 0) { result++; } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; /// @title Safe casting methods /// @notice Contains methods for safely casting between types library SafeCast { /// @notice Cast a uint256 to uint32, revert on overflow /// @param y The uint256 to be downcasted /// @return z The downcasted integer, now type uint32 function toUint32(uint256 y) internal pure returns (uint32 z) { require((z = uint32(y)) == y); } /// @notice Cast a uint128 to a int128, revert on overflow /// @param y The uint256 to be casted /// @return z The casted integer, now type int256 function toInt128(uint128 y) internal pure returns (int128 z) { require(y < 2**127); z = int128(y); } /// @notice Cast a uint256 to a uint128, revert on overflow /// @param y the uint256 to be downcasted /// @return z The downcasted integer, now type uint128 function toUint128(uint256 y) internal pure returns (uint128 z) { require((z = uint128(y)) == y); } /// @notice Cast a int128 to a uint128 and reverses the sign. /// @param y The int128 to be casted /// @return z = -y, now type uint128 function revToUint128(int128 y) internal pure returns (uint128 z) { unchecked { return type(uint128).max - uint128(y) + 1; } } /// @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 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 uint256 to a int256 and reverses the sign, revert on overflow /// @param y The uint256 to be casted /// @return z = -y, now type int256 function revToInt256(uint256 y) internal pure returns (int256 z) { require(y < 2**255); z = -int256(y); } /// @notice Cast a int256 to a uint256 and reverses the sign. /// @param y The int256 to be casted /// @return z = -y, now type uint256 function revToUint256(int256 y) internal pure returns (uint256 z) { unchecked { return type(uint256).max - uint256(y) + 1; } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=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 sqrtP 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 sqrtP) { unchecked { uint256 absTick = uint256(tick < 0 ? -int256(tick) : int256(tick)); require(absTick <= uint256(int256(MAX_TICK)), 'T'); // do bitwise comparison, if i-th bit is turned on, // multiply ratio by hardcoded values of sqrt(1.0001^-(2^i)) * 2^128 // where 0 <= i <= 19 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; // take reciprocal for positive tick values 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 sqrtP = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1)); } } /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio /// @dev Throws in case sqrtP < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may /// ever return. /// @param sqrtP 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 sqrtP) internal pure returns (int24 tick) { // second inequality must be < because the price can never reach the price at the max tick require(sqrtP >= MIN_SQRT_RATIO && sqrtP < MAX_SQRT_RATIO, 'R'); uint256 ratio = uint256(sqrtP) << 32; uint256 r = ratio; uint256 msb = 0; unchecked { 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) <= sqrtP ? tickHi : tickLow; } } function getMaxNumberTicks(int24 _tickDistance) internal pure returns (uint24 numTicks) { return uint24(TickMath.MAX_TICK / _tickDistance) * 2; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; import {IPoolActions} from './pool/IPoolActions.sol'; import {IPoolEvents} from './pool/IPoolEvents.sol'; import {IPoolStorage} from './pool/IPoolStorage.sol'; interface IPool is IPoolActions, IPoolEvents, IPoolStorage {}
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; interface IPoolActions { /// @notice Sets the initial price for the pool and seeds reinvestment liquidity /// @dev Assumes the caller has sent the necessary token amounts /// required for initializing reinvestment liquidity prior to calling this function /// @param initialSqrtP the initial sqrt price of the pool /// @param qty0 token0 quantity sent to and locked permanently in the pool /// @param qty1 token1 quantity sent to and locked permanently in the pool function unlockPool(uint160 initialSqrtP) external returns (uint256 qty0, uint256 qty1); /// @notice Adds liquidity for the specified recipient/tickLower/tickUpper position /// @dev Any token0 or token1 owed for the liquidity provision have to be paid for when /// the IMintCallback#mintCallback is called to this method's caller /// The quantity of token0/token1 to be sent depends on /// tickLower, tickUpper, the amount of liquidity, and the current price of the pool. /// Also sends reinvestment tokens (fees) to the recipient for any fees collected /// while the position is in range /// Reinvestment tokens have to be burnt via #burnRTokens in exchange for token0 and token1 /// @param recipient Address for which the added liquidity is credited to /// @param tickLower Recipient position's lower tick /// @param tickUpper Recipient position's upper tick /// @param ticksPrevious The nearest tick that is initialized and <= the lower & upper ticks /// @param qty Liquidity quantity to mint /// @param data Data (if any) to be passed through to the callback /// @return qty0 token0 quantity sent to the pool in exchange for the minted liquidity /// @return qty1 token1 quantity sent to the pool in exchange for the minted liquidity /// @return feeGrowthInside position's updated feeGrowthInside value function mint( address recipient, int24 tickLower, int24 tickUpper, int24[2] calldata ticksPrevious, uint128 qty, bytes calldata data ) external returns ( uint256 qty0, uint256 qty1, uint256 feeGrowthInside ); /// @notice Remove liquidity from the caller /// Also sends reinvestment tokens (fees) to the caller for any fees collected /// while the position is in range /// Reinvestment tokens have to be burnt via #burnRTokens in exchange for token0 and token1 /// @param tickLower Position's lower tick for which to burn liquidity /// @param tickUpper Position's upper tick for which to burn liquidity /// @param qty Liquidity quantity to burn /// @return qty0 token0 quantity sent to the caller /// @return qty1 token1 quantity sent to the caller /// @return feeGrowthInside position's updated feeGrowthInside value function burn( int24 tickLower, int24 tickUpper, uint128 qty ) external returns ( uint256 qty0, uint256 qty1, uint256 feeGrowthInside ); /// @notice Burns reinvestment tokens in exchange to receive the fees collected in token0 and token1 /// @param qty Reinvestment token quantity to burn /// @param isLogicalBurn true if burning rTokens without returning any token0/token1 /// otherwise should transfer token0/token1 to sender /// @return qty0 token0 quantity sent to the caller for burnt reinvestment tokens /// @return qty1 token1 quantity sent to the caller for burnt reinvestment tokens function burnRTokens(uint256 qty, bool isLogicalBurn) external returns (uint256 qty0, uint256 qty1); /// @notice Swap token0 -> token1, or vice versa /// @dev This method's caller receives a callback in the form of ISwapCallback#swapCallback /// @dev swaps will execute up to limitSqrtP or swapQty is fully used /// @param recipient The address to receive the swap output /// @param swapQty The swap quantity, which implicitly configures the swap as exact input (>0), or exact output (<0) /// @param isToken0 Whether the swapQty is specified in token0 (true) or token1 (false) /// @param limitSqrtP the limit of sqrt price after swapping /// could be MAX_SQRT_RATIO-1 when swapping 1 -> 0 and MIN_SQRT_RATIO+1 when swapping 0 -> 1 for no limit swap /// @param data Any data to be passed through to the callback /// @return qty0 Exact token0 qty sent to recipient if < 0. Minimally received quantity if > 0. /// @return qty1 Exact token1 qty sent to recipient if < 0. Minimally received quantity if > 0. function swap( address recipient, int256 swapQty, bool isToken0, uint160 limitSqrtP, bytes calldata data ) external returns (int256 qty0, int256 qty1); /// @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 IFlashCallback#flashCallback /// @dev Fees collected are sent to the feeTo address if it is set in Factory /// @param recipient The address which will receive the token0 and token1 quantities /// @param qty0 token0 quantity to be loaned to the recipient /// @param qty1 token1 quantity to be loaned to the recipient /// @param data Any data to be passed through to the callback function flash( address recipient, uint256 qty0, uint256 qty1, bytes calldata data ) external; /// @notice sync fee of position /// @param tickLower Position's lower tick /// @param tickUpper Position's upper tick function tweakPosZeroLiq(int24 tickLower, int24 tickUpper) external returns(uint256 feeGrowthInsideLast); }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; /// @title KyberSwap v2 factory /// @notice Deploys KyberSwap v2 pools and manages control over government fees interface IFactory { /// @notice Emitted when a pool is created /// @param token0 First pool token by address sort order /// @param token1 Second pool token by address sort order /// @param swapFeeUnits Fee to be collected upon every swap in the pool, in fee units /// @param tickDistance Minimum number of ticks between initialized ticks /// @param pool The address of the created pool event PoolCreated( address indexed token0, address indexed token1, uint24 indexed swapFeeUnits, int24 tickDistance, address pool ); /// @notice Emitted when a new fee is enabled for pool creation via the factory /// @param swapFeeUnits Fee to be collected upon every swap in the pool, in fee units /// @param tickDistance Minimum number of ticks between initialized ticks for pools created with the given fee event SwapFeeEnabled(uint24 indexed swapFeeUnits, int24 indexed tickDistance); /// @notice Emitted when vesting period changes /// @param vestingPeriod The maximum time duration for which LP fees /// are proportionally burnt upon LP removals event VestingPeriodUpdated(uint32 vestingPeriod); /// @notice Emitted when configMaster changes /// @param oldConfigMaster configMaster before the update /// @param newConfigMaster configMaster after the update event ConfigMasterUpdated(address oldConfigMaster, address newConfigMaster); /// @notice Emitted when fee configuration changes /// @param feeTo Recipient of government fees /// @param governmentFeeUnits Fee amount, in fee units, /// to be collected out of the fee charged for a pool swap event FeeConfigurationUpdated(address feeTo, uint24 governmentFeeUnits); /// @notice Emitted when whitelist feature is enabled event WhitelistEnabled(); /// @notice Emitted when whitelist feature is disabled event WhitelistDisabled(); /// @notice Returns the maximum time duration for which LP fees /// are proportionally burnt upon LP removals function vestingPeriod() external view returns (uint32); /// @notice Returns the tick distance for a specified fee. /// @dev Once added, cannot be updated or removed. /// @param swapFeeUnits Swap fee, in fee units. /// @return The tick distance. Returns 0 if fee has not been added. function feeAmountTickDistance(uint24 swapFeeUnits) external view returns (int24); /// @notice Returns the address which can update the fee configuration function configMaster() external view returns (address); /// @notice Returns the keccak256 hash of the Pool creation code /// This is used for pre-computation of pool addresses function poolInitHash() external view returns (bytes32); /// @notice Returns the pool oracle contract for twap function poolOracle() external view returns (address); /// @notice Fetches the recipient of government fees /// and current government fee charged in fee units function feeConfiguration() external view returns (address _feeTo, uint24 _governmentFeeUnits); /// @notice Returns the status of whitelisting feature of NFT managers /// If true, anyone can mint liquidity tokens /// Otherwise, only whitelisted NFT manager(s) are allowed to mint liquidity tokens function whitelistDisabled() external view returns (bool); //// @notice Returns all whitelisted NFT managers /// If the whitelisting feature is turned on, /// only whitelisted NFT manager(s) are allowed to mint liquidity tokens function getWhitelistedNFTManagers() external view returns (address[] memory); /// @notice Checks if sender is a whitelisted NFT manager /// If the whitelisting feature is turned on, /// only whitelisted NFT manager(s) are allowed to mint liquidity tokens /// @param sender address to be checked /// @return true if sender is a whistelisted NFT manager, false otherwise function isWhitelistedNFTManager(address sender) external view returns (bool); /// @notice Returns the pool address for a given pair of tokens and a swap fee /// @dev Token order does not matter /// @param tokenA Contract address of either token0 or token1 /// @param tokenB Contract address of the other token /// @param swapFeeUnits Fee to be collected upon every swap in the pool, in fee units /// @return pool The pool address. Returns null address if it does not exist function getPool( address tokenA, address tokenB, uint24 swapFeeUnits ) external view returns (address pool); /// @notice Fetch parameters to be used for pool creation /// @dev Called by the pool constructor to fetch the parameters of the pool /// @return factory The factory address /// @return poolOracle The pool oracle for twap /// @return token0 First pool token by address sort order /// @return token1 Second pool token by address sort order /// @return swapFeeUnits Fee to be collected upon every swap in the pool, in fee units /// @return tickDistance Minimum number of ticks between initialized ticks function parameters() external view returns ( address factory, address poolOracle, address token0, address token1, uint24 swapFeeUnits, int24 tickDistance ); /// @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 swapFeeUnits Desired swap fee for the pool, in fee units /// @dev Token order does not matter. tickDistance is determined from the fee. /// Call will revert under any of these conditions: /// 1) pool already exists /// 2) invalid swap fee /// 3) invalid token arguments /// @return pool The address of the newly created pool function createPool( address tokenA, address tokenB, uint24 swapFeeUnits ) external returns (address pool); /// @notice Enables a fee amount with the given tickDistance /// @dev Fee amounts may never be removed once enabled /// @param swapFeeUnits The fee amount to enable, in fee units /// @param tickDistance The distance between ticks to be enforced for all pools created with the given fee amount function enableSwapFee(uint24 swapFeeUnits, int24 tickDistance) external; /// @notice Updates the address which can update the fee configuration /// @dev Must be called by the current configMaster function updateConfigMaster(address) external; /// @notice Updates the vesting period /// @dev Must be called by the current configMaster function updateVestingPeriod(uint32) external; /// @notice Updates the address receiving government fees and fee quantity /// @dev Only configMaster is able to perform the update /// @param feeTo Address to receive government fees collected from pools /// @param governmentFeeUnits Fee amount, in fee units, /// to be collected out of the fee charged for a pool swap function updateFeeConfiguration(address feeTo, uint24 governmentFeeUnits) external; /// @notice Enables the whitelisting feature /// @dev Only configMaster is able to perform the update function enableWhitelist() external; /// @notice Disables the whitelisting feature /// @dev Only configMaster is able to perform the update function disableWhitelist() external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; /// @title Callback for IPool#mint /// @notice Any contract that calls IPool#mint must implement this interface interface IMintCallback { /// @notice Called to `msg.sender` after minting liquidity via IPool#mint. /// @dev This function's implementation must send pool tokens to the pool for the minted LP tokens. /// The caller of this method must be checked to be a Pool deployed by the canonical Factory. /// @param deltaQty0 The token0 quantity to be sent to the pool. /// @param deltaQty1 The token1 quantity to be sent to the pool. /// @param data Data passed through by the caller via the IPool#mint call function mintCallback( uint256 deltaQty0, uint256 deltaQty1, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; /// @title Callback for IPool#swap /// @notice Any contract that calls IPool#swap must implement this interface interface ISwapCallback { /// @notice Called to `msg.sender` after swap execution of IPool#swap. /// @dev This function's implementation must pay tokens owed to the pool for the swap. /// The caller of this method must be checked to be a Pool deployed by the canonical Factory. /// deltaQty0 and deltaQty1 can both be 0 if no tokens were swapped. /// @param deltaQty0 The token0 quantity that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send deltaQty0 of token0 to the pool. /// @param deltaQty1 The token1 quantity that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send deltaQty1 of token1 to the pool. /// @param data Data passed through by the caller via the IPool#swap call function swapCallback( int256 deltaQty0, int256 deltaQty1, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; /// @title Callback for IPool#flash /// @notice Any contract that calls IPool#flash must implement this interface interface IFlashCallback { /// @notice Called to `msg.sender` after flash loaning to the recipient from IPool#flash. /// @dev This function's implementation must send the loaned amounts with computed fee amounts /// The caller of this method must be checked to be a Pool deployed by the canonical Factory. /// @param feeQty0 The token0 fee to be sent to the pool. /// @param feeQty1 The token1 fee to be sent to the pool. /// @param data Data passed through by the caller via the IPool#flash call function flashCallback( uint256 feeQty0, uint256 feeQty1, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import {LiqDeltaMath} from './libraries/LiqDeltaMath.sol'; import {SafeCast} from './libraries/SafeCast.sol'; import {MathConstants} from './libraries/MathConstants.sol'; import {FullMath} from './libraries/FullMath.sol'; import {TickMath} from './libraries/TickMath.sol'; import {Linkedlist} from './libraries/Linkedlist.sol'; import {PoolStorage} from './PoolStorage.sol'; contract PoolTicksState is PoolStorage { using SafeCast for int128; using SafeCast for uint128; using Linkedlist for mapping(int24 => Linkedlist.Data); struct UpdatePositionData { // address of owner of the position address owner; // position's lower and upper ticks int24 tickLower; int24 tickUpper; // if minting, need to pass the previous initialized ticks for tickLower and tickUpper int24 tickLowerPrevious; int24 tickUpperPrevious; // any change in liquidity uint128 liquidityDelta; // true = adding liquidity, false = removing liquidity bool isAddLiquidity; } function _updatePosition( UpdatePositionData memory updateData, int24 currentTick, CumulativesData memory cumulatives ) internal returns (uint256 feesClaimable, uint256 feeGrowthInside) { // update ticks if necessary uint256 feeGrowthOutsideLowerTick = _updateTick( updateData.tickLower, currentTick, updateData.tickLowerPrevious, updateData.liquidityDelta, updateData.isAddLiquidity, cumulatives, true ); uint256 feeGrowthOutsideUpperTick = _updateTick( updateData.tickUpper, currentTick, updateData.tickUpperPrevious, updateData.liquidityDelta, updateData.isAddLiquidity, cumulatives, false ); // calculate feeGrowthInside unchecked { if (currentTick < updateData.tickLower) { feeGrowthInside = feeGrowthOutsideLowerTick - feeGrowthOutsideUpperTick; } else if (currentTick >= updateData.tickUpper) { feeGrowthInside = feeGrowthOutsideUpperTick - feeGrowthOutsideLowerTick; } else { feeGrowthInside = cumulatives.feeGrowth - feeGrowthOutsideLowerTick - feeGrowthOutsideUpperTick; } } // calc rTokens to be minted for the position's accumulated fees feesClaimable = _updatePositionData(updateData, feeGrowthInside); } /// @dev Update liquidity net data and do cross tick function _updateLiquidityAndCrossTick( int24 nextTick, uint128 currentLiquidity, uint256 feeGrowthGlobal, uint128 secondsPerLiquidityGlobal, bool willUpTick ) internal returns (uint128 newLiquidity, int24 newNextTick) { unchecked { ticks[nextTick].feeGrowthOutside = feeGrowthGlobal - ticks[nextTick].feeGrowthOutside; ticks[nextTick].secondsPerLiquidityOutside = secondsPerLiquidityGlobal - ticks[nextTick].secondsPerLiquidityOutside; } int128 liquidityNet = ticks[nextTick].liquidityNet; if (willUpTick) { newNextTick = initializedTicks[nextTick].next; } else { newNextTick = initializedTicks[nextTick].previous; liquidityNet = -liquidityNet; } newLiquidity = LiqDeltaMath.applyLiquidityDelta( currentLiquidity, liquidityNet >= 0 ? uint128(liquidityNet) : liquidityNet.revToUint128(), liquidityNet >= 0 ); } function _updatePoolData( uint128 baseL, uint128 reinvestL, uint160 sqrtP, int24 currentTick, int24 nextTick ) internal { poolData.baseL = baseL; poolData.reinvestL = reinvestL; poolData.sqrtP = sqrtP; poolData.currentTick = currentTick; poolData.nearestCurrentTick = nextTick > currentTick ? initializedTicks[nextTick].previous : nextTick; } /// @dev Return initial data before swapping /// @param willUpTick whether is up/down tick /// @return baseL current pool base liquidity without reinvestment liquidity /// @return reinvestL current pool reinvestment liquidity /// @return sqrtP current pool sqrt price /// @return currentTick current pool tick /// @return nextTick next tick to calculate data function _getInitialSwapData(bool willUpTick) internal view returns ( uint128 baseL, uint128 reinvestL, uint160 sqrtP, int24 currentTick, int24 nextTick ) { baseL = poolData.baseL; reinvestL = poolData.reinvestL; sqrtP = poolData.sqrtP; currentTick = poolData.currentTick; nextTick = poolData.nearestCurrentTick; if (willUpTick) { nextTick = initializedTicks[nextTick].next; } } function _updatePositionData(UpdatePositionData memory _data, uint256 feeGrowthInside) private returns (uint256 feesClaimable) { bytes32 key = _positionKey(_data.owner, _data.tickLower, _data.tickUpper); // calculate accumulated fees for current liquidity // feeGrowthInside is relative value, hence underflow is acceptable uint256 feeGrowth; unchecked { feeGrowth = feeGrowthInside - positions[key].feeGrowthInsideLast; } uint128 prevLiquidity = positions[key].liquidity; feesClaimable = FullMath.mulDivFloor(feeGrowth, prevLiquidity, MathConstants.TWO_POW_96); // update the position if (_data.liquidityDelta != 0) { positions[key].liquidity = LiqDeltaMath.applyLiquidityDelta( prevLiquidity, _data.liquidityDelta, _data.isAddLiquidity ); } positions[key].feeGrowthInsideLast = feeGrowthInside; } /// @notice Updates a tick and returns the fee growth outside of that tick /// @param tick Tick to be updated /// @param tickCurrent Current tick /// @param tickPrevious the nearest initialized tick which is lower than or equal to `tick` /// @param liquidityDelta Liquidity quantity to be added | removed when tick is crossed up | down /// @param cumulatives All-time global fee growth and seconds, per unit of liquidity /// @param isLower true | false if updating a position's lower | upper tick /// @return feeGrowthOutside last value of feeGrowthOutside function _updateTick( int24 tick, int24 tickCurrent, int24 tickPrevious, uint128 liquidityDelta, bool isAdd, CumulativesData memory cumulatives, bool isLower ) private returns (uint256 feeGrowthOutside) { uint128 liquidityGrossBefore = ticks[tick].liquidityGross; require(liquidityGrossBefore != 0 || liquidityDelta != 0, 'invalid liq'); if (liquidityDelta == 0) return ticks[tick].feeGrowthOutside; uint128 liquidityGrossAfter = LiqDeltaMath.applyLiquidityDelta( liquidityGrossBefore, liquidityDelta, isAdd ); require(liquidityGrossAfter <= maxTickLiquidity, '> max liquidity'); int128 signedLiquidityDelta = isAdd ? liquidityDelta.toInt128() : -(liquidityDelta.toInt128()); // if lower tick, liquidityDelta should be added | removed when crossed up | down // else, for upper tick, liquidityDelta should be removed | added when crossed up | down int128 liquidityNetAfter = isLower ? ticks[tick].liquidityNet + signedLiquidityDelta : ticks[tick].liquidityNet - signedLiquidityDelta; if (liquidityGrossBefore == 0) { // by convention, all growth before a tick was initialized is assumed to happen below it if (tick <= tickCurrent) { ticks[tick].feeGrowthOutside = cumulatives.feeGrowth; ticks[tick].secondsPerLiquidityOutside = cumulatives.secondsPerLiquidity; } } ticks[tick].liquidityGross = liquidityGrossAfter; ticks[tick].liquidityNet = liquidityNetAfter; feeGrowthOutside = ticks[tick].feeGrowthOutside; if (liquidityGrossBefore > 0 && liquidityGrossAfter == 0) { delete ticks[tick]; } if ((liquidityGrossBefore > 0) != (liquidityGrossAfter > 0)) { _updateTickList(tick, tickPrevious, tickCurrent, isAdd); } } /// @dev Update the tick linkedlist, assume that tick is not in the list /// @param tick tick index to update /// @param currentTick the pool currentt tick /// @param previousTick the nearest initialized tick that is lower than the tick, in case adding /// @param isAdd whether is add or remove the tick function _updateTickList( int24 tick, int24 previousTick, int24 currentTick, bool isAdd ) internal { if (isAdd) { if (tick == TickMath.MIN_TICK || tick == TickMath.MAX_TICK) return; // find the correct previousTick to the `tick`, avoid revert when new liquidity has been added between tick & previousTick int24 nextTick = initializedTicks[previousTick].next; require( nextTick != initializedTicks[previousTick].previous, 'previous tick has been removed' ); uint256 iteration = 0; while (nextTick <= tick && iteration < MathConstants.MAX_TICK_TRAVEL) { previousTick = nextTick; nextTick = initializedTicks[previousTick].next; iteration++; } initializedTicks.insert(tick, previousTick, nextTick); if (poolData.nearestCurrentTick < tick && tick <= currentTick) { poolData.nearestCurrentTick = tick; } } else { if (tick == poolData.nearestCurrentTick) { poolData.nearestCurrentTick = initializedTicks.remove(tick); } else { initializedTicks.remove(tick); } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; assembly { size := extcodesize(account) } return size > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT pragma solidity ^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 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) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; library QuadMath { // our equation is ax^2 - 2bx + c = 0, where a, b and c > 0 // the qudratic formula to obtain the smaller root is (2b - sqrt((2*b)^2 - 4ac)) / 2a // which can be simplified to (b - sqrt(b^2 - ac)) / a function getSmallerRootOfQuadEqn( uint256 a, uint256 b, uint256 c ) internal pure returns (uint256 smallerRoot) { smallerRoot = (b - sqrt(b * b - a * c)) / a; } // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method) function sqrt(uint256 y) internal pure returns (uint256 z) { unchecked { if (y > 3) { z = y; uint256 x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } } } }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; interface IPoolEvents { /// @notice Emitted only once per pool when #initialize is first called /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize /// @param sqrtP The initial price of the pool /// @param tick The initial tick of the pool event Initialize(uint160 sqrtP, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @dev transfers reinvestment tokens for any collected fees earned by the position /// @param sender address that minted the liquidity /// @param owner address of owner of the position /// @param tickLower position's lower tick /// @param tickUpper position's upper tick /// @param qty liquidity minted to the position range /// @param qty0 token0 quantity needed to mint the liquidity /// @param qty1 token1 quantity needed to mint the liquidity event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 qty, uint256 qty0, uint256 qty1 ); /// @notice Emitted when a position's liquidity is removed /// @dev transfers reinvestment tokens for any collected fees earned by the position /// @param owner address of owner of the position /// @param tickLower position's lower tick /// @param tickUpper position's upper tick /// @param qty liquidity removed /// @param qty0 token0 quantity withdrawn from removal of liquidity /// @param qty1 token1 quantity withdrawn from removal of liquidity event Burn( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 qty, uint256 qty0, uint256 qty1 ); /// @notice Emitted when reinvestment tokens are burnt /// @param owner address which burnt the reinvestment tokens /// @param qty reinvestment token quantity burnt /// @param qty0 token0 quantity sent to owner for burning reinvestment tokens /// @param qty1 token1 quantity sent to owner for burning reinvestment tokens event BurnRTokens(address indexed owner, uint256 qty, uint256 qty0, uint256 qty1); /// @notice Emitted for swaps by the pool between token0 and token1 /// @param sender Address that initiated the swap call, and that received the callback /// @param recipient Address that received the swap output /// @param deltaQty0 Change in pool's token0 balance /// @param deltaQty1 Change in pool's token1 balance /// @param sqrtP Pool's sqrt price after the swap /// @param liquidity Pool's liquidity after the swap /// @param currentTick Log base 1.0001 of pool's price after the swap event Swap( address indexed sender, address indexed recipient, int256 deltaQty0, int256 deltaQty1, uint160 sqrtP, uint128 liquidity, int24 currentTick ); /// @notice Emitted by the pool for any flash loans of token0/token1 /// @param sender The address that initiated the flash loan, and that received the callback /// @param recipient The address that received the flash loan quantities /// @param qty0 token0 quantity loaned to the recipient /// @param qty1 token1 quantity loaned to the recipient /// @param paid0 token0 quantity paid for the flash, which can exceed qty0 + fee /// @param paid1 token1 quantity paid for the flash, which can exceed qty0 + fee event Flash( address indexed sender, address indexed recipient, uint256 qty0, uint256 qty1, uint256 paid0, uint256 paid1 ); }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import {IFactory} from '../IFactory.sol'; import {IPoolOracle} from '../oracle/IPoolOracle.sol'; interface IPoolStorage { /// @notice The contract that deployed the pool, which must adhere to the IFactory interface /// @return The contract address function factory() external view returns (IFactory); /// @notice The oracle contract that stores necessary data for price oracle /// @return The contract address function poolOracle() external view returns (IPoolOracle); /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (IERC20); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (IERC20); /// @notice The fee to be charged for a swap in basis points /// @return The swap fee in basis points function swapFeeUnits() external view returns (uint24); /// @notice The pool tick distance /// @dev Ticks can only be initialized and used at multiples of this value /// It remains an int24 to avoid casting even though it is >= 1. /// e.g: a tickDistance of 5 means ticks can be initialized every 5th tick, i.e., ..., -10, -5, 0, 5, 10, ... /// @return The tick distance function tickDistance() external view returns (int24); /// @notice Maximum gross liquidity that an initialized tick can have /// @dev This is to prevent overflow the pool's active base liquidity (uint128) /// 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 maxTickLiquidity() external view returns (uint128); /// @notice Look up information about a specific tick in the pool /// @param tick The tick to look up /// @return liquidityGross total liquidity amount from positions that uses this tick as a lower or upper tick /// liquidityNet how much liquidity changes when the pool tick crosses above the tick /// feeGrowthOutside the fee growth on the other side of the tick relative to the current tick /// secondsPerLiquidityOutside the seconds per unit of liquidity spent on the other side of the tick relative to the current tick function ticks(int24 tick) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside, uint128 secondsPerLiquidityOutside ); /// @notice Returns the previous and next initialized ticks of a specific tick /// @dev If specified tick is uninitialized, the returned values are zero. /// @param tick The tick to look up function initializedTicks(int24 tick) external view returns (int24 previous, int24 next); /// @notice Returns the information about a position by the position's key /// @return liquidity the liquidity quantity of the position /// @return feeGrowthInsideLast fee growth inside the tick range as of the last mint / burn action performed function getPositions( address owner, int24 tickLower, int24 tickUpper ) external view returns (uint128 liquidity, uint256 feeGrowthInsideLast); /// @notice Fetches the pool's prices, ticks and lock status /// @return sqrtP sqrt of current price: sqrt(token1/token0) /// @return currentTick pool's current tick /// @return nearestCurrentTick pool's nearest initialized tick that is <= currentTick /// @return locked true if pool is locked, false otherwise function getPoolState() external view returns ( uint160 sqrtP, int24 currentTick, int24 nearestCurrentTick, bool locked ); /// @notice Fetches the pool's liquidity values /// @return baseL pool's base liquidity without reinvest liqudity /// @return reinvestL the liquidity is reinvested into the pool /// @return reinvestLLast last cached value of reinvestL, used for calculating reinvestment token qty function getLiquidityState() external view returns ( uint128 baseL, uint128 reinvestL, uint128 reinvestLLast ); /// @return feeGrowthGlobal All-time fee growth per unit of liquidity of the pool function getFeeGrowthGlobal() external view returns (uint256); /// @return secondsPerLiquidityGlobal All-time seconds per unit of liquidity of the pool /// @return lastUpdateTime The timestamp in which secondsPerLiquidityGlobal was last updated function getSecondsPerLiquidityData() external view returns (uint128 secondsPerLiquidityGlobal, uint32 lastUpdateTime); /// @notice Calculates and returns the active time per unit of liquidity until current block.timestamp /// @param tickLower The lower tick (of a position) /// @param tickUpper The upper tick (of a position) /// @return secondsPerLiquidityInside active time (multiplied by 2^96) /// between the 2 ticks, per unit of liquidity. function getSecondsPerLiquidityInside(int24 tickLower, int24 tickUpper) external view returns (uint128 secondsPerLiquidityInside); }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; interface IPoolOracle { /// @notice Owner withdrew funds in the pool oracle in case some funds are stuck there event OwnerWithdrew( address indexed owner, address indexed token, uint256 indexed amount ); /// @notice Emitted by the Pool Oracle 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 pool The pool address to update /// @param observationCardinalityNextOld The previous value of the next observation cardinality /// @param observationCardinalityNextNew The updated value of the next observation cardinality event IncreaseObservationCardinalityNext( address pool, uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); /// @notice Initalize observation data for the caller. function initializeOracle(uint32 time) external returns (uint16 cardinality, uint16 cardinalityNext); /// @notice Write a new oracle entry into the array /// and update the observation index and cardinality /// Read the Oralce.write function for more details function writeNewEntry( uint16 index, uint32 blockTimestamp, int24 tick, uint128 liquidity, uint16 cardinality, uint16 cardinalityNext ) external returns (uint16 indexUpdated, uint16 cardinalityUpdated); /// @notice Write a new oracle entry into the array, take the latest observaion data as inputs /// and update the observation index and cardinality /// Read the Oralce.write function for more details function write( uint32 blockTimestamp, int24 tick, uint128 liquidity ) external returns (uint16 indexUpdated, uint16 cardinalityUpdated); /// @notice Increase the maximum number of price 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 pool The pool address to be updated /// @param observationCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext( address pool, uint16 observationCardinalityNext ) external; /// @notice Returns the accumulator values as of each time seconds ago from the latest block time in the array of `secondsAgos` /// @dev Reverts if `secondsAgos` > oldest observation /// @dev It fetches the latest current tick data from the pool /// Read the Oracle.observe function for more details function observeFromPool( address pool, uint32[] memory secondsAgos ) external view returns (int56[] memory tickCumulatives); /// @notice Returns the accumulator values as the time seconds ago from the latest block time of secondsAgo /// @dev Reverts if `secondsAgo` > oldest observation /// @dev It fetches the latest current tick data from the pool /// Read the Oracle.observeSingle function for more details function observeSingleFromPool( address pool, uint32 secondsAgo ) external view returns (int56 tickCumulative); /// @notice Return the latest pool observation data given the pool address function getPoolObservation(address pool) external view returns (bool initialized, uint16 index, uint16 cardinality, uint16 cardinalityNext); /// @notice Returns data about a specific observation index /// @param pool The pool address of the observations array to fetch /// @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 initialized whether the observation has been initialized and the values are safe to use function getObservationAt(address pool, uint256 index) external view returns ( uint32 blockTimestamp, int56 tickCumulative, bool initialized ); }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; /// @title The implementation for a LinkedList library Linkedlist { struct Data { int24 previous; int24 next; } /// @dev init data with the lowest and highest value of the LinkedList /// @param lowestValue the lowest and also the HEAD of LinkedList /// @param highestValue the highest and also the TAIL of the LinkedList function init( mapping(int24 => Linkedlist.Data) storage self, int24 lowestValue, int24 highestValue ) internal { (self[lowestValue].previous, self[lowestValue].next) = (lowestValue, highestValue); (self[highestValue].previous, self[highestValue].next) = (lowestValue, highestValue); } /// @dev Remove a value from the linked list, return the lower value /// Return the lower value after removing, in case removedValue is the lowest/highest, no removing is done function remove(mapping(int24 => Linkedlist.Data) storage self, int24 removedValue) internal returns (int24 lowerValue) { Data memory removedValueData = self[removedValue]; require(removedValueData.next != removedValueData.previous, 'remove non-existent value'); if (removedValueData.previous == removedValue) return removedValue; // remove the lowest value, nothing is done lowerValue = removedValueData.previous; if (removedValueData.next == removedValue) return lowerValue; // remove the highest value, nothing is done self[removedValueData.previous].next = removedValueData.next; self[removedValueData.next].previous = removedValueData.previous; delete self[removedValue]; } /// @dev Insert a new value to the linked list given its lower value that is inside the linked list /// @param newValue the new value to insert, it must not exist in the LinkedList /// @param lowerValue the nearest value which is <= newValue and is in the LinkedList function insert( mapping(int24 => Linkedlist.Data) storage self, int24 newValue, int24 lowerValue, int24 nextValue ) internal { require(nextValue != self[lowerValue].previous, 'lower value is not initialized'); require(lowerValue < newValue && nextValue > newValue, 'invalid lower value'); self[newValue].next = nextValue; self[newValue].previous = lowerValue; self[nextValue].previous = newValue; self[lowerValue].next = newValue; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import {Clones} from '@openzeppelin/contracts/proxy/Clones.sol'; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import {Linkedlist} from './libraries/Linkedlist.sol'; import {TickMath} from './libraries/TickMath.sol'; import {MathConstants as C} from './libraries/MathConstants.sol'; import {IPoolOracle} from './interfaces/oracle/IPoolOracle.sol'; import {IFactory} from './interfaces/IFactory.sol'; import {IPoolStorage} from './interfaces/pool/IPoolStorage.sol'; abstract contract PoolStorage is IPoolStorage { using Clones for address; using Linkedlist for mapping(int24 => Linkedlist.Data); address internal constant LIQUIDITY_LOCKUP_ADDRESS = 0xD444422222222222222222222222222222222222; struct PoolData { uint160 sqrtP; int24 nearestCurrentTick; int24 currentTick; bool locked; uint128 baseL; uint128 reinvestL; uint128 reinvestLLast; uint256 feeGrowthGlobal; uint128 secondsPerLiquidityGlobal; uint32 secondsPerLiquidityUpdateTime; } // data stored for each initialized individual tick struct TickData { // gross liquidity of all positions in tick uint128 liquidityGross; // liquidity quantity to be added | removed when tick is crossed up | down int128 liquidityNet; // fee growth per unit of liquidity on the other side of this tick (relative to current tick) // only has relative meaning, not absolute — the value depends on when the tick is initialized uint256 feeGrowthOutside; // 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 uint128 secondsPerLiquidityOutside; } // data stored for each user's position struct Position { // the amount of liquidity owned by this position uint128 liquidity; // fee growth per unit of liquidity as of the last update to liquidity uint256 feeGrowthInsideLast; } struct CumulativesData { uint256 feeGrowth; uint128 secondsPerLiquidity; } /// see IPoolStorage for explanations of the immutables below IFactory public immutable override factory; IERC20 public immutable override token0; IERC20 public immutable override token1; IPoolOracle public immutable override poolOracle; uint128 public immutable override maxTickLiquidity; uint24 public immutable override swapFeeUnits; int24 public immutable override tickDistance; mapping(int24 => TickData) public override ticks; mapping(int24 => Linkedlist.Data) public override initializedTicks; mapping(bytes32 => Position) internal positions; PoolData internal poolData; /// @dev Mutually exclusive reentrancy protection into the pool from/to a method. /// Also prevents entrance to pool actions prior to initalization modifier lock() { require(poolData.locked == false, 'locked'); poolData.locked = true; _; poolData.locked = false; } constructor() { // fetch data from factory constructor ( address _factory, address _poolOracle, address _token0, address _token1, uint24 _swapFeeUnits, int24 _tickDistance ) = IFactory(msg.sender).parameters(); factory = IFactory(_factory); poolOracle = IPoolOracle(_poolOracle); token0 = IERC20(_token0); token1 = IERC20(_token1); swapFeeUnits = _swapFeeUnits; tickDistance = _tickDistance; maxTickLiquidity = type(uint128).max / TickMath.getMaxNumberTicks(_tickDistance); poolData.locked = true; // set pool to locked state } function _initPoolStorage(uint160 initialSqrtP, int24 initialTick) internal { poolData.baseL = 0; poolData.reinvestL = C.MIN_LIQUIDITY; poolData.reinvestLLast = C.MIN_LIQUIDITY; poolData.sqrtP = initialSqrtP; poolData.currentTick = initialTick; poolData.nearestCurrentTick = TickMath.MIN_TICK; initializedTicks.init(TickMath.MIN_TICK, TickMath.MAX_TICK); poolOracle.initializeOracle(_blockTimestamp()); poolData.locked = false; // unlock the pool } function getPositions( address owner, int24 tickLower, int24 tickUpper ) external view override returns (uint128 liquidity, uint256 feeGrowthInsideLast) { bytes32 key = _positionKey(owner, tickLower, tickUpper); return (positions[key].liquidity, positions[key].feeGrowthInsideLast); } /// @inheritdoc IPoolStorage function getPoolState() external view override returns ( uint160 sqrtP, int24 currentTick, int24 nearestCurrentTick, bool locked ) { sqrtP = poolData.sqrtP; currentTick = poolData.currentTick; nearestCurrentTick = poolData.nearestCurrentTick; locked = poolData.locked; } /// @inheritdoc IPoolStorage function getLiquidityState() external view override returns ( uint128 baseL, uint128 reinvestL, uint128 reinvestLLast ) { baseL = poolData.baseL; reinvestL = poolData.reinvestL; reinvestLLast = poolData.reinvestLLast; } function getFeeGrowthGlobal() external view override returns (uint256) { return poolData.feeGrowthGlobal; } function getSecondsPerLiquidityData() external view override returns (uint128 secondsPerLiquidityGlobal, uint32 lastUpdateTime) { secondsPerLiquidityGlobal = poolData.secondsPerLiquidityGlobal; lastUpdateTime = poolData.secondsPerLiquidityUpdateTime; } function getSecondsPerLiquidityInside(int24 tickLower, int24 tickUpper) external view override returns (uint128 secondsPerLiquidityInside) { require(tickLower <= tickUpper, 'bad tick range'); int24 currentTick = poolData.currentTick; uint128 secondsPerLiquidityGlobal = poolData.secondsPerLiquidityGlobal; uint32 lastUpdateTime = poolData.secondsPerLiquidityUpdateTime; uint128 lowerValue = ticks[tickLower].secondsPerLiquidityOutside; uint128 upperValue = ticks[tickUpper].secondsPerLiquidityOutside; unchecked { if (currentTick < tickLower) { secondsPerLiquidityInside = lowerValue - upperValue; } else if (currentTick >= tickUpper) { secondsPerLiquidityInside = upperValue - lowerValue; } else { secondsPerLiquidityInside = secondsPerLiquidityGlobal - (lowerValue + upperValue); } } // in the case where position is in range (tickLower <= _poolTick < tickUpper), // need to add timeElapsed per liquidity if (tickLower <= currentTick && currentTick < tickUpper) { uint256 secondsElapsed = _blockTimestamp() - lastUpdateTime; uint128 baseL = poolData.baseL; if (secondsElapsed > 0 && baseL > 0) { unchecked { secondsPerLiquidityInside += uint128((secondsElapsed << 96) / baseL); } } } } function _positionKey( address owner, int24 tickLower, int24 tickUpper ) internal pure returns (bytes32) { return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); } /// @dev For overriding in tests function _blockTimestamp() internal view virtual returns (uint32) { return uint32(block.timestamp); } }
// SPDX-License-Identifier: MIT pragma solidity ^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 `implementation`. * * This function uses the create opcode, which should never revert. */ function clone(address implementation) internal returns (address instance) { assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, implementation)) 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 `implementation`. * * This function uses the create2 opcode and a `salt` to deterministically deploy * the clone. Using the same `implementation` and `salt` multiple time will revert, since * the clones cannot be deployed twice at the same address. */ function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) { assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, implementation)) 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 implementation, bytes32 salt, address deployer ) internal pure returns (address predicted) { assembly { let ptr := mload(0x40) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) mstore(add(ptr, 0x14), shl(0x60, implementation)) 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 implementation, bytes32 salt) internal view returns (address predicted) { return predictDeterministicAddress(implementation, salt, address(this)); } }
{ "optimizer": { "enabled": true, "runs": 500 }, "metadata": { "bytecodeHash": "none" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":true,"internalType":"int24","name":"tickUpper","type":"int24"},{"indexed":false,"internalType":"uint128","name":"qty","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"qty0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"qty1","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"qty","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"qty0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"qty1","type":"uint256"}],"name":"BurnRTokens","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"qty0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"qty1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"paid0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"paid1","type":"uint256"}],"name":"Flash","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint160","name":"sqrtP","type":"uint160"},{"indexed":false,"internalType":"int24","name":"tick","type":"int24"}],"name":"Initialize","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":true,"internalType":"int24","name":"tickUpper","type":"int24"},{"indexed":false,"internalType":"uint128","name":"qty","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"qty0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"qty1","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"int256","name":"deltaQty0","type":"int256"},{"indexed":false,"internalType":"int256","name":"deltaQty1","type":"int256"},{"indexed":false,"internalType":"uint160","name":"sqrtP","type":"uint160"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"int24","name":"currentTick","type":"int24"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"qty","type":"uint128"}],"name":"burn","outputs":[{"internalType":"uint256","name":"qty0","type":"uint256"},{"internalType":"uint256","name":"qty1","type":"uint256"},{"internalType":"uint256","name":"feeGrowthInsideLast","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_qty","type":"uint256"},{"internalType":"bool","name":"isLogicalBurn","type":"bool"}],"name":"burnRTokens","outputs":[{"internalType":"uint256","name":"qty0","type":"uint256"},{"internalType":"uint256","name":"qty1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract IFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"qty0","type":"uint256"},{"internalType":"uint256","name":"qty1","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"flash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getFeeGrowthGlobal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLiquidityState","outputs":[{"internalType":"uint128","name":"baseL","type":"uint128"},{"internalType":"uint128","name":"reinvestL","type":"uint128"},{"internalType":"uint128","name":"reinvestLLast","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoolState","outputs":[{"internalType":"uint160","name":"sqrtP","type":"uint160"},{"internalType":"int24","name":"currentTick","type":"int24"},{"internalType":"int24","name":"nearestCurrentTick","type":"int24"},{"internalType":"bool","name":"locked","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"}],"name":"getPositions","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"feeGrowthInsideLast","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSecondsPerLiquidityData","outputs":[{"internalType":"uint128","name":"secondsPerLiquidityGlobal","type":"uint128"},{"internalType":"uint32","name":"lastUpdateTime","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"}],"name":"getSecondsPerLiquidityInside","outputs":[{"internalType":"uint128","name":"secondsPerLiquidityInside","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"","type":"int24"}],"name":"initializedTicks","outputs":[{"internalType":"int24","name":"previous","type":"int24"},{"internalType":"int24","name":"next","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxTickLiquidity","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"int24[2]","name":"ticksPrevious","type":"int24[2]"},{"internalType":"uint128","name":"qty","type":"uint128"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"mint","outputs":[{"internalType":"uint256","name":"qty0","type":"uint256"},{"internalType":"uint256","name":"qty1","type":"uint256"},{"internalType":"uint256","name":"feeGrowthInsideLast","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolOracle","outputs":[{"internalType":"contract IPoolOracle","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"int256","name":"swapQty","type":"int256"},{"internalType":"bool","name":"isToken0","type":"bool"},{"internalType":"uint160","name":"limitSqrtP","type":"uint160"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swap","outputs":[{"internalType":"int256","name":"deltaQty0","type":"int256"},{"internalType":"int256","name":"deltaQty1","type":"int256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"swapFeeUnits","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tickDistance","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int24","name":"","type":"int24"}],"name":"ticks","outputs":[{"internalType":"uint128","name":"liquidityGross","type":"uint128"},{"internalType":"int128","name":"liquidityNet","type":"int128"},{"internalType":"uint256","name":"feeGrowthOutside","type":"uint256"},{"internalType":"uint128","name":"secondsPerLiquidityOutside","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"}],"name":"tweakPosZeroLiq","outputs":[{"internalType":"uint256","name":"feeGrowthInsideLast","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint160","name":"initialSqrtP","type":"uint160"}],"name":"unlockPool","outputs":[{"internalType":"uint256","name":"qty0","type":"uint256"},{"internalType":"uint256","name":"qty1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
6101606040523480156200001257600080fd5b506040518060400160405280601f81526020017f4b7962657253776170207632205265696e766573746d656e7420546f6b656e008152506040518060400160405280600681526020016512d4cc8b549560d21b815250600080600080600080336001600160a01b031663890357306040518163ffffffff1660e01b815260040160c06040518083038186803b158015620000ab57600080fd5b505afa158015620000c0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000e69190620002a4565b6001600160a01b0386811660805285811660e05284811660a052831660c05262ffffff821661012052600281900b61014052949a509298509096509450925090506200013e81620001b0602090811b6200284317901c565b620001569062ffffff166001600160801b0362000365565b6001600160801b03166101005250506003805460ff60d01b1916600160d01b17905550508351620001919250600b91506020850190620001e1565b508051620001a790600c906020840190620001e1565b5050506200045f565b600081620001c2620d89e7196200038e565b620001ce9190620003b4565b620001db906002620003f4565b92915050565b828054620001ef9062000422565b90600052602060002090601f0160209004810192826200021357600085556200025e565b82601f106200022e57805160ff19168380011785556200025e565b828001600101855582156200025e579182015b828111156200025e57825182559160200191906001019062000241565b506200026c92915062000270565b5090565b5b808211156200026c576000815560010162000271565b80516001600160a01b03811681146200029f57600080fd5b919050565b60008060008060008060c08789031215620002be57600080fd5b620002c98762000287565b9550620002d96020880162000287565b9450620002e96040880162000287565b9350620002f96060880162000287565b9250608087015162ffffff811681146200031257600080fd5b8092505060a08701518060020b81146200032b57600080fd5b809150509295509295509295565b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b60006001600160801b038381168062000382576200038262000339565b92169190910492915050565b60008160020b627fffff19811415620003ab57620003ab6200034f565b60000392915050565b60008160020b8360020b80620003ce57620003ce62000339565b627fffff19821460001982141615620003eb57620003eb6200034f565b90059392505050565b600062ffffff808316818516818304811182151516156200041957620004196200034f565b02949350505050565b600181811c908216806200043757607f821691505b602082108114156200045957634e487b7160e01b600052602260045260246000fd5b50919050565b60805160a05160c05160e051610100516101205161014051615ea56200057e60003960008181610370015281816126020152818161263701528181612a900152612acb0152600081816105b50152818161103b01528181611906015261194501526000818161057b0152614ba00152600081816103bf015281816113f101528181612cd10152613ee40152600081816105f001528181611629015281816119e101528181611b8101528181611ef2015281816123620152612ee501526000818161027401528181611518015281816119a701528181611b4701528181611eae015281816123280152612de7015260008181610554015281816108bf015281816111d50152818161186e0152818161245d0152614a270152615ea56000f3fe608060405234801561001057600080fd5b50600436106101fb5760003560e01c806395d89b411161011a578063c20830d7116100ad578063c79a590e1161007c578063c79a590e146105b0578063d21220a7146105eb578063dd62ed3e14610612578063f2843d1e1461064b578063f30dba93146106e957600080fd5b8063c20830d71461053c578063c45a01551461054f578063c5611c6014610576578063c7333e941461059d57600080fd5b8063ab612f2b116100e9578063ab612f2b14610466578063aff67f551461049c578063b231a3b8146104c8578063c0ac75cf146104f357600080fd5b806395d89b4114610425578063a34123a71461042d578063a457c2d714610440578063a9059cbb1461045357600080fd5b8063313ce567116101925780636efff33b116101615780636efff33b146103ba57806370a08231146103e157806372cc51481461040a5780637caae8701461041257600080fd5b8063313ce56714610349578063395093511461035857806348626a8c1461036b578063490e6cbc146103a557600080fd5b806318160ddd116101ce57806318160ddd146102ae578063217ac237146102c057806323b872dd1461030e57806324b31a0c1461032157600080fd5b806306fdde0314610200578063095ea7b31461021e5780630c1225b7146102415780630dfe16811461026f575b600080fd5b610208610761565b6040516102159190615578565b60405180910390f35b61023161022c3660046155c3565b6107f3565b6040519015158152602001610215565b61025461024f366004615661565b61080a565b60408051938452602084019290925290820152606001610215565b6102967f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610215565b600a545b604051908152602001610215565b600354604080516001600160a01b0383168152600160b81b8304600290810b6020830152600160a01b8404900b91810191909152600160d01b90910460ff1615156060820152608001610215565b61023161031c366004615701565b610be0565b61033461032f366004615750565b610c8c565b60408051928352602083019190915201610215565b60405160128152602001610215565b6102316103663660046155c3565b6117bf565b6103927f000000000000000000000000000000000000000000000000000000000000000081565b60405160029190910b8152602001610215565b6103b86103b33660046157d5565b6117fb565b005b6102967f000000000000000000000000000000000000000000000000000000000000000081565b6102b26103ef36600461583f565b6001600160a01b031660009081526008602052604090205490565b6006546102b2565b61033461042036600461583f565b611c1a565b610208611d7f565b61025461043b36600461585c565b611d8e565b61023161044e3660046155c3565b611f8b565b6102316104613660046155c3565b612024565b600454600554604080516001600160801b038085168252600160801b909404841660208201529290911690820152606001610215565b600754604080516001600160801b0383168152600160801b90920463ffffffff16602083015201610215565b6104db6104d636600461589f565b612031565b6040516001600160801b039091168152602001610215565b6105226105013660046158d2565b600160205260009081526040902054600281810b9163010000009004900b82565b60408051600293840b81529190920b602082015201610215565b61033461054a3660046158ed565b61219c565b6102967f000000000000000000000000000000000000000000000000000000000000000081565b6104db7f000000000000000000000000000000000000000000000000000000000000000081565b6102b26105ab36600461589f565b6123e7565b6105d77f000000000000000000000000000000000000000000000000000000000000000081565b60405162ffffff9091168152602001610215565b6102967f000000000000000000000000000000000000000000000000000000000000000081565b6102b261062036600461591d565b6001600160a01b03918216600090815260096020908152604080832093909416825291909152205490565b6106ca61065936600461594b565b6040805160609490941b6bffffffffffffffffffffffff191660208086019190915260e893841b60348601529190921b60378401528151601a818503018152603a909301825282519281019290922060009081526002909252902080546001909101546001600160801b0390911691565b604080516001600160801b039093168352602083019190915201610215565b61072f6106f73660046158d2565b6000602081905290815260409020805460018201546002909201546001600160801b0380831693600160801b909304600f0b92911684565b604080516001600160801b039586168152600f9490940b60208501528301919091529091166060820152608001610215565b6060600b805461077090615987565b80601f016020809104026020016040519081016040528092919081815260200182805461079c90615987565b80156107e95780601f106107be576101008083540402835291602001916107e9565b820191906000526020600020905b8154815290600101906020018083116107cc57829003601f168201915b5050505050905090565b6000610800338484612868565b5060015b92915050565b60035460009081908190600160d01b900460ff16156108595760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b60448201526064015b60405180910390fd5b6003805460ff60d01b1916600160d01b1790556001600160801b0386166108aa5760405162461bcd60e51b8152602060048201526005602482015264302071747960d81b6044820152606401610850565b6040516310083c0760e21b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690634020f01c9060240160206040518083038186803b15801561090957600080fd5b505afa15801561091d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061094191906159bc565b6109795760405162461bcd60e51b81526020600482015260096024820152683337b93134b23232b760b91b6044820152606401610850565b600080610a0d6040518060e001604052808e6001600160a01b031681526020018d60020b81526020018c60020b81526020018b6000600281106109be576109be6159d9565b6020020160208101906109d191906158d2565b60020b81526020908101906109ec9060408e01908e016158d2565b60020b81526001600160801b038b166020820152600160409091015261298c565b919650945092508491508390506000808315610a2e57610a2b612dcd565b91505b8515610a3f57610a3c612ecb565b90505b604051639f382e9b60e01b81523390639f382e9b90610a68908a908a908e908e90600401615a18565b600060405180830381600087803b158015610a8257600080fd5b505af1158015610a96573d6000803e3d6000fd5b505050506000871115610af257610aab612dcd565b610ab58884615a4e565b1115610af25760405162461bcd60e51b815260206004820152600c60248201526b06c61636b696e6720717479360a41b6044820152606401610850565b8515610b4757610b00612ecb565b610b0a8783615a4e565b1115610b475760405162461bcd60e51b815260206004820152600c60248201526b6c61636b696e67207174793160a01b6044820152606401610850565b8b60020b8d60020b8f6001600160a01b03167f7a53080ba414158be7ec69b987b5fb7d07dee101fe85488f0853ae16239d0bde338e8c8c604051610bb894939291906001600160a01b039490941684526001600160801b039290921660208401526040830152606082015260800190565b60405180910390a450506003805460ff60d01b1916905550929a919950975095505050505050565b6000610bed848484612f17565b6001600160a01b038416600090815260096020908152604080832033845290915290205482811015610c725760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610850565b610c7f8533858403612868565b60019150505b9392505050565b6003546000908190600160d01b900460ff1615610cd45760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b17905586610d205760405162461bcd60e51b815260206004820152600960248201526830207377617051747960b81b6044820152606401610850565b6040805161016081018252600060208201819052918101829052606081018290526080810182905260a0810182905261010081018290526101208101829052610140810182905288815287151560c0820181905291891360e0820181905290911415610d8b816130e7565b600290810b608088015290810b606087019081526001600160a01b039092166040808801919091526001600160801b03938416610120880152938316610100870190815284518086019095529151900b8352511660208201528115610e6d5782604001516001600160a01b0316886001600160a01b0316118015610e2b575073fffd8963efd1fc6a506488495d951d5263988d266001600160a01b038916105b610e685760405162461bcd60e51b815260206004820152600e60248201526d0626164206c696d697453717274560941b6044820152606401610850565b610edc565b82604001516001600160a01b0316886001600160a01b0316108015610e9f57506401000276a36001600160a01b038916115b610edc5760405162461bcd60e51b815260206004820152600e60248201526d0626164206c696d697453717274560941b6044820152606401610850565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101919091525b835115801590610f445750886001600160a01b031684604001516001600160a01b031614155b1561136a576080840151838015610f7057506060850151610f67906101e0615a66565b60020b8160020b135b15610f8e576101e08560600151610f879190615a66565b9050610fcc565b83158015610fb257506101e08560600151610fa99190615aad565b60020b8160020b125b15610fcc576101e08560600151610fc99190615aad565b90505b60408501516001600160a01b0316610140860152610fe981613150565b6001600160a01b0390811660a08701819052908b168111851515141561100c5750895b60008060006110738961012001518a610100015161102a9190615af5565b6001600160801b03168a60400151867f000000000000000000000000000000000000000000000000000000000000000062ffffff168d600001518e60e001518f60c00151613483565b6001600160a01b031660408d01528b51929550909350915083908a9061109a908390615b20565b9052506020890180518391906110b1908390615b5f565b9052506110bd8161358a565b89610120018181516110cf9190615af5565b6001600160801b031690525050505060a086015160408701516001600160a01b03918216911614905061113a578461014001516001600160a01b031685604001516001600160a01b0316146111345761112b85604001516135a5565b60020b60608601525b5061136a565b8361114f5761114a600182615aad565b611151565b805b600290810b6060870152608086015182820b910b146111705750610f1e565b815161126857600a5482526005546001600160801b03908116602084015260065460408401526007546101008701516111ad9291909116906138cb565b6001600160801b03166060830152604080516326311fa360e21b815281516001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926398c47e8c9260048082019391829003018186803b15801561121757600080fd5b505afa15801561122b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061124f9190615b9f565b62ffffff1660a08401526001600160a01b031660808301525b600061129a8661012001516001600160801b031684602001516001600160801b0316886101000151866000015161397a565b905080156113155780836000018181516112b49190615a4e565b90525060a083015160c084018051620186a062ffffff909316840292909204918201905260e084018051828403908101909152610100880151611307908290600160601b906001600160801b03166139be565b604086018051909101905250505b6101208601516001600160801b0316602084015260808601516101008701516040850151606086015161134b9392919089613aec565b60020b60808801526001600160801b031661010087015250610f1e9050565b8051156113d25760c08101511561138d5761138d81608001518260c00151613bc9565b60e0810151156113a5576113a5308260e00151613bc9565b6020810151600580546001600160801b0319166001600160801b0390921691909117905560408101516006555b816000015160020b846060015160020b146114af576001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663ff11275e428451602086015160405160e085901b6001600160e01b031916815263ffffffff909316600484015260029190910b60248301526001600160801b031660448201526064016040805180830381600087803b15801561147457600080fd5b505af1158015611488573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ac9190615bfe565b50505b6114d2846101000151856101200151866040015187606001518860800151613ca8565b896114ed57602084015184516114e8908d615b20565b6114ff565b83516114f9908c615b20565b84602001515b9096509450821561161b57600086121561154b5761154b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168d6001891901613d52565b6000611555612ecb565b604051637d241f3960e11b8152909150339063fa483e7290611581908a908a908e908e90600401615a18565b600060405180830381600087803b15801561159b57600080fd5b505af11580156115af573d6000803e3d6000fd5b5050505085816115bf9190615a4e565b6115c7612ecb565b10156116155760405162461bcd60e51b815260206004820152601160248201527f6c61636b696e672064656c7461517479310000000000000000000000000000006044820152606401610850565b50611728565b600085121561165c5761165c7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168d6001881901613d52565b6000611666612dcd565b604051637d241f3960e11b8152909150339063fa483e7290611692908a908a908e908e90600401615a18565b600060405180830381600087803b1580156116ac57600080fd5b505af11580156116c0573d6000803e3d6000fd5b5050505086816116d09190615a4e565b6116d8612dcd565b10156117265760405162461bcd60e51b815260206004820152601160248201527f6c61636b696e672064656c7461517479300000000000000000000000000000006044820152606401610850565b505b60408085015161010086015160608088015184518b8152602081018b90526001600160a01b03948516958101959095526001600160801b039092169084015260020b60808301528d169033907fc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca679060a00160405180910390a350506003805460ff60d01b1916905550919890975095505050505050565b3360008181526009602090815260408083206001600160a01b038716845290915281205490916108009185906117f6908690615a4e565b612868565b600354600160d01b900460ff161561183e5760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b179055604080516326311fa360e21b815281516000926001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926398c47e8c9260048083019392829003018186803b1580156118b057600080fd5b505afa1580156118c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118e89190615b9f565b5090506000806001600160a01b0383161561197c57620186a06119307f000000000000000000000000000000000000000000000000000000000000000062ffffff1689615c28565b61193a9190615c47565b9150620186a061196f7f000000000000000000000000000000000000000000000000000000000000000062ffffff1688615c28565b6119799190615c47565b90505b6000611986612dcd565b90506000611992612ecb565b905088156119ce576119ce6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168b8b613d52565b8715611a0857611a086001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168b8a613d52565b6040516361c9276b60e11b8152339063c3924ed690611a3190879087908c908c90600401615a18565b600060405180830381600087803b158015611a4b57600080fd5b505af1158015611a5f573d6000803e3d6000fd5b505050506000611a6d612dcd565b90506000611a79612ecb565b905081611a868786615a4e565b1115611ad45760405162461bcd60e51b815260206004820152600f60248201527f6c61636b696e67206665655174793000000000000000000000000000000000006044820152606401610850565b80611adf8685615a4e565b1115611b2d5760405162461bcd60e51b815260206004820152600f60248201527f6c61636b696e67206665655174793100000000000000000000000000000000006044820152606401610850565b838203838203838614611b6e57611b6e6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168a84613d52565b8015611ba857611ba86001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168a83613d52565b604080518e8152602081018e9052908101839052606081018290526001600160a01b038f169033907fbdbdb71d7860376ba52b25a5028beea23581364a40522f6bcfb86bb1f2dca6339060800160405180910390a350506003805460ff60d01b19169055505050505050505050505050565b60035460009081906001600160a01b031615611c785760405162461bcd60e51b815260206004820152600e60248201527f616c726561647920696e697465640000000000000000000000000000000000006044820152606401610850565b6000611c83846135a5565b9050611c8e84613da9565b9093509150611c9b612dcd565b831115611cd95760405162461bcd60e51b815260206004820152600c60248201526b06c61636b696e6720717479360a41b6044820152606401610850565b611ce1612ecb565b821115611d1f5760405162461bcd60e51b815260206004820152600c60248201526b6c61636b696e67207174793160a01b6044820152606401610850565b611d2a306064613bc9565b611d348482613de7565b604080516001600160a01b0386168152600283900b60208201527f98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95910160405180910390a150915091565b6060600c805461077090615987565b60035460009081908190600160d01b900460ff1615611dd85760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b1790556001600160801b038416611e295760405162461bcd60e51b8152602060048201526005602482015264302071747960d81b6044820152606401610850565b600080611e8a6040518060e00160405280336001600160a01b031681526020018a60020b81526020018960020b8152602001600060020b8152602001600060020b8152602001886001600160801b031681526020016000151581525061298c565b945090925090506000821215611ed55781196001019450611ed56001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163387613d52565b6000811215611f195780196001019350611f196001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163386613d52565b604080516001600160801b038816815260208101879052908101859052600288810b91908a900b9033907f0c396cd989a39f4459b5fa1aed6a9a8dcdbc45908acfd67e028cd568da98982c9060600160405180910390a450506003805460ff60d01b1916905591959094509092509050565b3360009081526009602090815260408083206001600160a01b03861684529091528120548281101561200d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610850565b61201a3385858403612868565b5060019392505050565b6000610800338484612f17565b60008160020b8360020b13156120895760405162461bcd60e51b815260206004820152600e60248201527f626164207469636b2072616e67650000000000000000000000000000000000006044820152606401610850565b600354600754600285810b60008181526020819052604080822084015488850b83529120830154600160b81b90950490920b936001600160801b0380851694600160801b900463ffffffff16938116929116908512156120ed57808203955061210c565b8660020b8560020b1261210457818103955061210c565b808201840395505b8460020b8860020b1315801561212757508660020b8560020b125b156121915760006121388442615c5b565b60045463ffffffff9190911691506001600160801b0316811580159061216757506000816001600160801b0316115b1561218e57806001600160801b0316606083901b8161218857612188615bd6565b04880197505b50505b505050505092915050565b6003546000908190600160d01b900460ff16156121e45760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b1790558215612255576122073385613f7b565b6040805185815260006020820181905281830152905133917f324487c99a1f7f0e3127499a548452d3a198e78ccd07add913cb93d59f0f039b919081900360600190a25060009050806123d1565b6004546003546006546001600160801b0380841693600160801b900416916001600160a01b03169061228c908490849060006140c9565b5060006122ab88846001600160801b03166122a6600a5490565b6139be565b90506122b68161358a565b6122c09084615c80565b600480546001600160801b03808416600160801b81029190921617909155600580546001600160801b031916909117905592506122fd828261415c565b95506123098282614176565b94506123153389613f7b565b851561234f5761234f6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163388613d52565b8415612389576123896001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163387613d52565b604080518981526020810188905290810186905233907f324487c99a1f7f0e3127499a548452d3a198e78ccd07add913cb93d59f0f039b9060600160405180910390a2505050505b6003805460ff60d01b1916905590939092509050565b600354600090600160d01b900460ff161561242d5760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b1790556040516310083c0760e21b81523360048201526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690634020f01c9060240160206040518083038186803b15801561249f57600080fd5b505afa1580156124b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124d791906159bc565b61250f5760405162461bcd60e51b81526020600482015260096024820152683337b93134b23232b760b91b6044820152606401610850565b8160020b8360020b126125595760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207469636b2072616e676560701b6044820152606401610850565b600283900b620d89e71913156125a65760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964206c6f776572207469636b60701b6044820152606401610850565b6125b3620d89e719615ca0565b60020b8260020b13156125fd5760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207570706572207469636b60701b6044820152606401610850565b6126277f000000000000000000000000000000000000000000000000000000000000000084615cc3565b60020b158015612661575061265c7f000000000000000000000000000000000000000000000000000000000000000083615cc3565b60020b155b6126a45760405162461bcd60e51b81526020600482015260146024820152737469636b206e6f7420696e2064697374616e636560601b6044820152606401610850565b604080516bffffffffffffffffffffffff193360601b1660208083019190915260e886811b603484015285901b60378301528251808303601a018152603a909201835281519181019190912060008181526002909252919020546001600160801b03166127535760405162461bcd60e51b815260206004820152601060248201527f696e76616c696420706f736974696f6e000000000000000000000000000000006044820152606401610850565b60045460408051808201909152600080825260208201526006546001600160801b0380841693612792928592600160801b9092049091169060016140c9565b81526007546127aa906001600160801b0316836138cb565b6001600160801b03166020808301919091526040805160e081018252338152600289810b9382019390935287830b918101919091526000606082018190526080820181905260a0820181905260c0820181905260035490926128169291600160b81b9004900b84614190565b95509050801561282b5761282b303383612f17565b50506003805460ff60d01b1916905550909392505050565b600081612853620d89e719615ca0565b61285d9190615ce5565b610804906002615d1f565b6001600160a01b0383166128ca5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610850565b6001600160a01b03821661292b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610850565b6001600160a01b0383811660008181526009602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6000806000836040015160020b846020015160020b126129e35760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207469636b2072616e676560701b6044820152606401610850565b602084015160020b620d89e7191315612a335760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964206c6f776572207469636b60701b6044820152606401610850565b612a40620d89e719615ca0565b60020b846040015160020b1315612a8e5760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207570706572207469636b60701b6044820152606401610850565b7f00000000000000000000000000000000000000000000000000000000000000008460200151612abe9190615cc3565b60020b158015612afe57507f00000000000000000000000000000000000000000000000000000000000000008460400151612af99190615cc3565b60020b155b612b415760405162461bcd60e51b81526020600482015260146024820152737469636b206e6f7420696e2064697374616e636560601b6044820152606401610850565b60035460045460408051808201909152600080825260208201526001600160a01b03831692600160b81b900460020b916001600160801b0380821692600160801b9092041690612b988383600380015460016140c9565b8152600754612bb0906001600160801b0316846138cb565b6001600160801b031660208201526000612bcb8a8684614190565b975090508015612be457612be4308b6000015183612f17565b896020015160020b8560020b1215612c3357612c22612c068b60200151613150565b612c138c60400151613150565b8c60a001518d60c00151614234565b600098509850505050505050612dc6565b896040015160020b8560020b12612c81576000612c72612c568c60200151613150565b612c638d60400151613150565b8d60a001518e60c001516142d8565b98509850505050505050612dc6565b604080517fff11275e00000000000000000000000000000000000000000000000000000000815263ffffffff42166004820152600287900b60248201526001600160801b038616604482015281517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169263ff11275e92606480820193918290030181600087803b158015612d1d57600080fd5b505af1158015612d31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d559190615bfe565b5050612d6886612c138c60400151613150565b9850612d8a612d7a8b60200151613150565b878c60a001518d60c001516142d8565b9750612d9f848b60a001518c60c00151614339565b600480546001600160801b0319166001600160801b03929092169190911790555050505050505b9193909250565b604051306024820152600090819081906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823160e01b906044015b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051612e539190615d4a565b600060405180830381855afa9150503d8060008114612e8e576040519150601f19603f3d011682016040523d82523d6000602084013e612e93565b606091505b5091509150818015612ea757506020815110155b612eb057600080fd5b80806020019051810190612ec49190615d66565b9250505090565b604051306024820152600090819081906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823160e01b90604401612e15565b6001600160a01b038316612f7b5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610850565b6001600160a01b038216612fdd5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610850565b6001600160a01b038316600090815260086020526040902054818110156130555760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610850565b6001600160a01b0380851660009081526008602052604080822085850390559185168152908120805484929061308c908490615a4e565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516130d891815260200190565b60405180910390a35b50505050565b6004546003546001600160801b0380831692600160801b900416906001600160a01b03811690600160b81b8104600290810b91600160a01b9004900b851561314757600290810b60009081526001602052604090205463010000009004900b5b91939590929450565b60008060008360020b12613167578260020b61316f565b8260020b6000035b9050620d89e88111156131a85760405162461bcd60e51b81526020600482015260016024820152601560fa1b6044820152606401610850565b6000600182166131bc57600160801b6131ce565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615613202576ffff97272373d413259a46990580e213a0260801c5b6004821615613221576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615613240576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b601082161561325f576fffcb9843d60f6159c9db58835c9266440260801c5b602082161561327e576fff973b41fa98c081472e6896dfb254c00260801c5b604082161561329d576fff2ea16466c96a3843ec78b326b528610260801c5b60808216156132bc576ffe5dee046a99a2a811c461f1969c30530260801c5b6101008216156132dc576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b6102008216156132fc576ff987a7253ac413176f2b074cf7815e540260801c5b61040082161561331c576ff3392b0822b70005940c7a398e4b70f30260801c5b61080082161561333c576fe7159475a2c29b7443b29c7fa6e889d90260801c5b61100082161561335c576fd097f3bdfd2022b8845ad8f792aa58250260801c5b61200082161561337c576fa9f746462d870fdf8a65dc1f90e061e50260801c5b61400082161561339c576f70d869a156d2a1b890bb3df62baf32f70260801c5b6180008216156133bc576f31be135f97d08fd981231505542fcfa60260801c5b620100008216156133dd576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b620200008216156133fd576e5d6af8dedb81196699c329225ee6040260801c5b6204000082161561341c576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615613439576b048a170391f7dc42444e8fa20260801c5b60008460020b131561345a57806000198161345657613456615bd6565b0490505b64010000000081061561346e576001613471565b60005b60ff16602082901c0192505050919050565b600080600080886001600160a01b03168a6001600160a01b031614156134b45750600092508291508190508861357c565b6134d48b8b6001600160a01b03168b6001600160a01b03168b8a8a614361565b93508580156134e257508684135b806134f65750851580156134f65750868413155b1561350357869350613506565b50875b60008085121561351a57841960010161351c565b845b90506001600160a01b0382166135595761353a818d8d8c8b8b6144fc565b925061355261354d828e868f8c8c614646565b614723565b915061356a565b613567818d8d858b8b614739565b92505b6135788c8c84868b8b61482f565b9350505b975097509750979350505050565b806001600160801b03811681146135a057600080fd5b919050565b60006401000276a36001600160a01b038316108015906135e1575073fffd8963efd1fc6a506488495d951d5263988d266001600160a01b038316105b6136115760405162461bcd60e51b81526020600482015260016024820152602960f91b6044820152606401610850565b77ffffffffffffffffffffffffffffffffffffffff00000000602083901b166001600160801b03811160071b81811c67ffffffffffffffff811160061b90811c63ffffffff811160051b90811c61ffff811160041b90811c60ff8111600390811b91821c600f811160021b90811c918211600190811b92831c979088119617909417909217179091171717608081106136b257607f810383901c91506136bc565b80607f0383901b91505b908002607f81811c60ff83811c9190911c800280831c81831c1c800280841c81841c1c800280851c81851c1c800280861c81861c1c800280871c81871c1c800280881c81881c1c800280891c81891c1c8002808a1c818a1c1c8002808b1c818b1c1c8002808c1c818c1c1c8002808d1c818d1c1c8002808e1c9c81901c9c909c1c80029c8d901c9e9d607f198f0160401b60c09190911c678000000000000000161760c19b909b1c674000000000000000169a909a1760c29990991c672000000000000000169890981760c39790971c671000000000000000169690961760c49590951c670800000000000000169490941760c59390931c670400000000000000169290921760c69190911c670200000000000000161760c79190911c670100000000000000161760c89190911c6680000000000000161760c99190911c6640000000000000161760ca9190911c6620000000000000161760cb9190911c6610000000000000161760cc9190911c6608000000000000161760cd9190911c66040000000000001617693627a301d71055774c8581026f028f6481ab7f045a5af012a19d003aa9198101608090811d906fdb2df09e81959a81455e260799a0632f8301901d600281810b9083900b146138bc57886001600160a01b03166138a182613150565b6001600160a01b031611156138b657816138be565b806138be565b815b9998505050505050505050565b6007546000908190600160801b900463ffffffff16426138eb9190615c5b565b63ffffffff1690508015613972576007805473ffffffff000000000000000000000000000000001916600160801b63ffffffff4216021790556001600160801b038316156139725761394a6001600160801b038416606083901b615c47565b6139549085615af5565b600780546001600160801b0319166001600160801b03831617905593505b509192915050565b6000806139a76001600160801b0385166139948789615d7f565b6122a6896001600160801b038916615a4e565b90506139b48382876139be565b9695505050505050565b600080806000198587098587029250828110838203039150508060001415613a255760008411613a1a5760405162461bcd60e51b8152602060048201526007602482015266302064656e6f6d60c81b6044820152606401610850565b508290049050610c85565b808411613a745760405162461bcd60e51b815260206004820152600e60248201527f64656e6f6d203c3d2070726f64310000000000000000000000000000000000006044820152606401610850565b6000848688098084039381119092039190506000613a9486196001615a4e565b8616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030260008290038290046001019490940294049390931791909102925050509392505050565b600285810b60009081526020819052604081206001810180548703905591820180546001600160801b038082168703166001600160801b031990911617905590548190600160801b9004600f0b8315613b6357600288810b60009081526001602052604090205463010000009004900b9150613b87565b600288810b600090815260016020526040902054900b9150613b8481615d96565b90505b613bbc87600083600f0b1215613bad57600f83900b6001600160801b0303600101613baf565b825b600084600f0b1215614339565b9250509550959350505050565b6001600160a01b038216613c1f5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610850565b80600a6000828254613c319190615a4e565b90915550506001600160a01b03821660009081526008602052604081208054839290613c5e908490615a4e565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6001600160801b03848116600160801b02908616176004556003805462ffffff8416600160b81b0279ffffff000000ffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03861617179055600282810b9082900b13613d115780613d28565b600281810b600090815260016020526040902054900b5b6003805462ffffff92909216600160a01b0262ffffff60a01b199092169190911790555050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052613da490849061491c565b505050565b600080613dc56064600160601b6001600160a01b0386166149ee565b9150613de060646001600160a01b038516600160601b6149ee565b9050915091565b7064000000000000000000000000000000006004556005805460646001600160801b0319909116179055600380546001600160a01b03841679ffffff000000ffffffffffffffffffffffffffffffffffffffff1990911617600160b81b62ffffff8416021762ffffff60a01b1916621e4ec360a31b179055613ec6620d89e719613e7081615ca0565b600282810b600090815260016020526040808220805462ffffff96871662ffffff199787166301000000029790971665ffffffffffff19918216811788179092559490930b825290208054909216179091179055565b60408051633440fba760e01b815263ffffffff4216600482015281517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031692633440fba792602480820193918290030181600087803b158015613f3057600080fd5b505af1158015613f44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f689190615bfe565b50506003805460ff60d01b191690555050565b6001600160a01b038216613fdb5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610850565b6001600160a01b0382166000908152600860205260409020548181101561404f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610850565b6001600160a01b03831660009081526008602052604081208383039055600a805484929061407e908490615d7f565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b60055460009081906140f1906001600160801b038088169116886140ec600a5490565b61397a565b905080156141305761410281614a20565b905061410e3082613bc9565b61412681600160601b886001600160801b03166139be565b9093016006819055925b821561415257600580546001600160801b0319166001600160801b0387161790555b5091949350505050565b6000610c8582600160601b856001600160a01b03166139be565b6000610c8582846001600160a01b0316600160601b6139be565b60008060006141b586602001518688606001518960a001518a60c00151896001614af6565b905060006141d987604001518789608001518a60a001518b60c001518a6000614af6565b9050866020015160020b8660020b12156141f757808203925061421e565b866040015160020b8660020b1261421257818103925061421e565b80828660000151030392505b6142288784614dc5565b93505050935093915050565b60007bffffffffffffffffffffffffffffffff000000000000000000000000606084901b166001600160a01b03868603168361429f5761429a876001600160a01b031661428b84848a6001600160a01b03166139be565b6142959190615c47565b614ec1565b6142cd565b6142cd6142c86142b984848a6001600160a01b03166149ee565b896001600160a01b0316614edc565b614ef6565b979650505050505050565b60008161430a57614305614295846001600160801b03168787036001600160a01b0316600160601b6139be565b614330565b6143306142c8846001600160801b03168787036001600160a01b0316600160601b6149ee565b95945050505050565b60008161434f5761434a8385615c80565b614359565b6143598385615af5565b949350505050565b6000808587101561437457868603614378565b8587035b9050831561442d5782156143e15760006143928887615c28565b61439f8862030d40615c28565b6143a99190615d7f565b905060006143c48a6143be8562030d40615c28565b846139be565b90506143d86142c882600160601b8c6139be565b935050506144f1565b60006143ed8787615c28565b6143fa8962030d40615c28565b6144049190615d7f565b905060006144198a6143be8562030d40615c28565b90506143d86142c8828b600160601b6139be565b821561449057600061443f8787615c28565b61444c8962030d40615c28565b6144569190615d7f565b905060006144648988615c28565b61446e9083615d7f565b905061447f60608b901b82846139be565b90506143d88861428b83868d6139be565b600061449c8887615c28565b6144a98862030d40615c28565b6144b39190615d7f565b905060006144c18888615c28565b6144cb9083615d7f565b90506144d88a82846139be565b90506144ec6142958285600160601b6139be565b935050505b509695505050505050565b6000821561456557811561453d576145366001600160a01b038616614521868a615c28565b6e030d400000000000000000000000006139be565b90506139b4565b614536600160601b61454f868a615c28565b6122a66001600160a01b03891662030d40615c28565b8360008761457683620186a0615d7f565b6145809190615c28565b905060008961458f8a89615c28565b6145999190615c28565b905084156145f0576145c56145b18b620186a0615c28565b896001600160a01b0316600160601b6139be565b6145cf9083615d7f565b91506145e981896001600160a01b0316600160601b6139be565b905061463b565b6146146146008b620186a0615c28565b600160601b8a6001600160a01b03166139be565b61461e9083615d7f565b915061463881600160601b8a6001600160a01b03166139be565b90505b6144ec838383614f0c565b600081156146bf57600061466888866001600160a01b0316600160601b6139be565b9050831561469e5761469661467d8789615a4e565b6001600160a01b038716614691848b615a4e565b6149ee565b9150506139b4565b6146966146ab8789615a4e565b6001600160a01b0387166122a6848b615d7f565b60006146d988600160601b876001600160a01b03166139be565b90508315614702576146966146ee8289615a4e565b6001600160a01b0387166122a6898b615a4e565b61469661470f8289615d7f565b6001600160a01b038716614691898b615a4e565b806001600160a01b03811681146135a057600080fd5b600081156147bd57600061475b87600160601b886001600160a01b03166139be565b90506000846147735761476e8983615d7f565b61477d565b61477d8983615a4e565b90506000614799876001600160a01b031683600160601b6139be565b90508881116147a95760006147b3565b6147b38982615d7f565b93505050506139b4565b60006147d787876001600160a01b0316600160601b6139be565b90506000846147ef576147ea8983615d7f565b6147f9565b6147f98983615a4e565b9050600061481582600160601b896001600160a01b03166139be565b90508881116148255760006144ec565b6144ec8982615d7f565b600081156148b157821561488d576148616142958861484e888a615db4565b6001600160a01b0316600160601b6139be565b61487c6142c886886001600160a01b0316600160601b6149ee565b6148869190615b5f565b90506148fd565b6148616142c88861489e8989615db4565b6001600160a01b0316600160601b6149ee565b6148cc61429588600160601b896001600160a01b03166139be565b6148f06142c86148dc878b615a4e565b600160601b896001600160a01b03166149ee565b6148fa9190615b5f565b90505b82801561490a5750806001145b156139b4575060009695505050505050565b6000614971826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614f499092919063ffffffff16565b805190915015613da4578080602001905181019061498f91906159bc565b613da45760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610850565b60006149fb8484846139be565b905060008280614a0d57614a0d615bd6565b8486091115610c85578061433081615dd4565b60008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166398c47e8c6040518163ffffffff1660e01b8152600401604080518083038186803b158015614a7d57600080fd5b505afa158015614a91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ab59190615b9f565b915091508062ffffff1660001415614acf57509192915050565b620186a062ffffff82168502048015614aec57614aec8382613bc9565b9093039392505050565b600287900b6000908152602081905260408120546001600160801b031680151580614b2957506001600160801b03861615155b614b635760405162461bcd60e51b815260206004820152600b60248201526a696e76616c6964206c697160a81b6044820152606401610850565b6001600160801b038616614b8f575050600287900b6000908152602081905260409020600101546142cd565b6000614b9c828888614339565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160801b0316816001600160801b03161115614c205760405162461bcd60e51b815260206004820152600f60248201527f3e206d6178206c697175696469747900000000000000000000000000000000006044820152606401610850565b600086614c4757614c39886001600160801b0316614f58565b614c4290615d96565b614c59565b614c59886001600160801b0316614f58565b9050600085614c905760028c900b600090815260208190526040902054614c8b908390600160801b9004600f0b615def565b614cb9565b60028c900b600090815260208190526040902054614cb9908390600160801b9004600f0b615e35565b90506001600160801b038416614d17578a60020b8c60020b13614d1757865160028d810b6000908152602081815260409091206001810193909355890151910180546001600160801b0319166001600160801b039092169190911790555b60028c900b60009081526020819052604090206001600160801b03828116600160801b028186161782556001909101549550841615801590614d6057506001600160801b038316155b15614d935760028c810b600090815260208190526040812081815560018101919091550180546001600160801b03191690555b6001600160801b038481161515908416151514614db657614db68c8b8d8b614f7f565b50505050979650505050505050565b8151602080840151604080860151815160609590951b6bffffffffffffffffffffffff19168585015260e892831b603486015290911b60378401528051601a818503018152603a9093019052815191012060009081906000818152600260205260409020600181015490549192508403906001600160801b0316614e4e8282600160601b6139be565b93508560a001516001600160801b0316600014614ea557614e78818760a001518860c00151614339565b600084815260026020526040902080546001600160801b0319166001600160801b03929092169190911790555b5050600090815260026020526040902060010191909155919050565b6000600160ff1b8210614ed357600080fd5b61080482615e7b565b6000808211614eea57600080fd5b50808204910615150190565b6000600160ff1b8210614f0857600080fd5b5090565b600083614f35614f1c8483615c28565b614f268680615c28565b614f309190615d7f565b61512f565b614f3f9085615d7f565b6143599190615c47565b6060614359848460008561518c565b60006f80000000000000000000000000000000826001600160801b031610614f0857600080fd5b80156150d257600284900b620d89e7191480614fac5750614fa3620d89e719615ca0565b60020b8460020b145b15614fb6576130e1565b600283810b60009081526001602052604090205463010000008104820b910b8114156150245760405162461bcd60e51b815260206004820152601e60248201527f70726576696f7573207469636b20686173206265656e2072656d6f76656400006044820152606401610850565b60005b8560020b8260020b1315801561503d5750600a81105b1561507757600282810b600090815260016020526040902054929550630100000090920490910b908061506f81615dd4565b915050615027565b61508460018787856152a9565b600354600287810b600160a01b909204900b1280156150a957508360020b8660020b13155b156150cb576003805462ffffff60a01b1916600160a01b62ffffff8916021790555b50506130e1565b600354600285810b600160a01b909204900b141561511d576150f56001856153e9565b6003805462ffffff92909216600160a01b0262ffffff60a01b199092169190911790556130e1565b6151286001856153e9565b5050505050565b6000600382111561517e575080600160028204015b818110156151785780915060028182858161516157615161615bd6565b04018161517057615170615bd6565b049050615144565b50919050565b81156135a057506001919050565b6060824710156151ed5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610850565b843b61523b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610850565b600080866001600160a01b031685876040516152579190615d4a565b60006040518083038185875af1925050503d8060008114615294576040519150601f19603f3d011682016040523d82523d6000602084013e615299565b606091505b50915091506142cd828286615513565b600282810b60009081526020869052604090205482820b910b14156153105760405162461bcd60e51b815260206004820152601e60248201527f6c6f7765722076616c7565206973206e6f7420696e697469616c697a656400006044820152606401610850565b8260020b8260020b12801561532a57508260020b8160020b135b6153765760405162461bcd60e51b815260206004820152601360248201527f696e76616c6964206c6f7765722076616c7565000000000000000000000000006044820152606401610850565b600283810b60009081526020959095526040808620805465ffffffffffff1916630100000062ffffff868116820262ffffff19908116939093178882161790935594840b885282882080549091169190961690811790955592900b84529220805465ffffff000000191691909202179055565b600281810b60009081526020848152604080832081518083019092525480850b808352630100000090910490940b9181018290529192141561546d5760405162461bcd60e51b815260206004820152601960248201527f72656d6f7665206e6f6e2d6578697374656e742076616c7565000000000000006044820152606401610850565b8260020b816000015160020b14156154885782915050610804565b806000015191508260020b816020015160020b14156154a75750610804565b602081810180518351600290810b6000908152979093526040808820805465ffffff0000001916630100000062ffffff9485160217905593519151830b8752838720805462ffffff1916929091169190911790559290920b83529120805465ffffffffffff1916905590565b60608315615522575081610c85565b8251156155325782518084602001fd5b8160405162461bcd60e51b81526004016108509190615578565b60005b8381101561556757818101518382015260200161554f565b838111156130e15750506000910152565b602081526000825180602084015261559781604085016020870161554c565b601f01601f19169190910160400192915050565b6001600160a01b03811681146155c057600080fd5b50565b600080604083850312156155d657600080fd5b82356155e1816155ab565b946020939093013593505050565b8035600281900b81146135a057600080fd5b80356001600160801b03811681146135a057600080fd5b60008083601f84011261562a57600080fd5b50813567ffffffffffffffff81111561564257600080fd5b60208301915083602082850101111561565a57600080fd5b9250929050565b600080600080600080600060e0888a03121561567c57600080fd5b8735615687816155ab565b9650615695602089016155ef565b95506156a3604089016155ef565b945060a08801898111156156b657600080fd5b6060890194506156c581615601565b93505060c088013567ffffffffffffffff8111156156e257600080fd5b6156ee8a828b01615618565b989b979a50959850939692959293505050565b60008060006060848603121561571657600080fd5b8335615721816155ab565b92506020840135615731816155ab565b929592945050506040919091013590565b80151581146155c057600080fd5b60008060008060008060a0878903121561576957600080fd5b8635615774816155ab565b955060208701359450604087013561578b81615742565b9350606087013561579b816155ab565b9250608087013567ffffffffffffffff8111156157b757600080fd5b6157c389828a01615618565b979a9699509497509295939492505050565b6000806000806000608086880312156157ed57600080fd5b85356157f8816155ab565b94506020860135935060408601359250606086013567ffffffffffffffff81111561582257600080fd5b61582e88828901615618565b969995985093965092949392505050565b60006020828403121561585157600080fd5b8135610c85816155ab565b60008060006060848603121561587157600080fd5b61587a846155ef565b9250615888602085016155ef565b915061589660408501615601565b90509250925092565b600080604083850312156158b257600080fd5b6158bb836155ef565b91506158c9602084016155ef565b90509250929050565b6000602082840312156158e457600080fd5b610c85826155ef565b6000806040838503121561590057600080fd5b82359150602083013561591281615742565b809150509250929050565b6000806040838503121561593057600080fd5b823561593b816155ab565b91506020830135615912816155ab565b60008060006060848603121561596057600080fd5b833561596b816155ab565b9250615979602085016155ef565b9150615896604085016155ef565b600181811c9082168061599b57607f821691505b6020821081141561517857634e487b7160e01b600052602260045260246000fd5b6000602082840312156159ce57600080fd5b8151610c8581615742565b634e487b7160e01b600052603260045260246000fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b8481528360208201526060604082015260006139b46060830184866159ef565b634e487b7160e01b600052601160045260246000fd5b60008219821115615a6157615a61615a38565b500190565b60008160020b8360020b6000821282627fffff03821381151615615a8c57615a8c615a38565b82627fffff19038212811615615aa457615aa4615a38565b50019392505050565b60008160020b8360020b6000811281627fffff1901831281151615615ad457615ad4615a38565b81627fffff018313811615615aeb57615aeb615a38565b5090039392505050565b60006001600160801b03808316818516808303821115615b1757615b17615a38565b01949350505050565b60008083128015600160ff1b850184121615615b3e57615b3e615a38565b836001600160ff1b03018313811615615b5957615b59615a38565b50500390565b6000808212826001600160ff1b0303841381151615615b8057615b80615a38565b600160ff1b8390038412811615615b9957615b99615a38565b50500190565b60008060408385031215615bb257600080fd5b8251615bbd816155ab565b602084015190925062ffffff8116811461591257600080fd5b634e487b7160e01b600052601260045260246000fd5b805161ffff811681146135a057600080fd5b60008060408385031215615c1157600080fd5b615c1a83615bec565b91506158c960208401615bec565b6000816000190483118215151615615c4257615c42615a38565b500290565b600082615c5657615c56615bd6565b500490565b600063ffffffff83811690831681811015615c7857615c78615a38565b039392505050565b60006001600160801b0383811690831681811015615c7857615c78615a38565b60008160020b627fffff19811415615cba57615cba615a38565b60000392915050565b60008260020b80615cd657615cd6615bd6565b808360020b0791505092915050565b60008160020b8360020b80615cfc57615cfc615bd6565b627fffff19821460001982141615615d1657615d16615a38565b90059392505050565b600062ffffff80831681851681830481118215151615615d4157615d41615a38565b02949350505050565b60008251615d5c81846020870161554c565b9190910192915050565b600060208284031215615d7857600080fd5b5051919050565b600082821015615d9157615d91615a38565b500390565b600081600f0b60016001607f1b0319811415615cba57615cba615a38565b60006001600160a01b0383811690831681811015615c7857615c78615a38565b6000600019821415615de857615de8615a38565b5060010190565b600081600f0b83600f0b600081128160016001607f1b031901831281151615615e1a57615e1a615a38565b8160016001607f1b03018313811615615aeb57615aeb615a38565b600081600f0b83600f0b600082128260016001607f1b0303821381151615615e5f57615e5f615a38565b8260016001607f1b0319038212811615615aa457615aa4615a38565b6000600160ff1b821415615e9157615e91615a38565b506000039056fea164736f6c6343000809000a
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101fb5760003560e01c806395d89b411161011a578063c20830d7116100ad578063c79a590e1161007c578063c79a590e146105b0578063d21220a7146105eb578063dd62ed3e14610612578063f2843d1e1461064b578063f30dba93146106e957600080fd5b8063c20830d71461053c578063c45a01551461054f578063c5611c6014610576578063c7333e941461059d57600080fd5b8063ab612f2b116100e9578063ab612f2b14610466578063aff67f551461049c578063b231a3b8146104c8578063c0ac75cf146104f357600080fd5b806395d89b4114610425578063a34123a71461042d578063a457c2d714610440578063a9059cbb1461045357600080fd5b8063313ce567116101925780636efff33b116101615780636efff33b146103ba57806370a08231146103e157806372cc51481461040a5780637caae8701461041257600080fd5b8063313ce56714610349578063395093511461035857806348626a8c1461036b578063490e6cbc146103a557600080fd5b806318160ddd116101ce57806318160ddd146102ae578063217ac237146102c057806323b872dd1461030e57806324b31a0c1461032157600080fd5b806306fdde0314610200578063095ea7b31461021e5780630c1225b7146102415780630dfe16811461026f575b600080fd5b610208610761565b6040516102159190615578565b60405180910390f35b61023161022c3660046155c3565b6107f3565b6040519015158152602001610215565b61025461024f366004615661565b61080a565b60408051938452602084019290925290820152606001610215565b6102967f0000000000000000000000009ae380f0272e2162340a5bb646c354271c0f5cfc81565b6040516001600160a01b039091168152602001610215565b600a545b604051908152602001610215565b600354604080516001600160a01b0383168152600160b81b8304600290810b6020830152600160a01b8404900b91810191909152600160d01b90910460ff1615156060820152608001610215565b61023161031c366004615701565b610be0565b61033461032f366004615750565b610c8c565b60408051928352602083019190915201610215565b60405160128152602001610215565b6102316103663660046155c3565b6117bf565b6103927f000000000000000000000000000000000000000000000000000000000000006481565b60405160029190910b8152602001610215565b6103b86103b33660046157d5565b6117fb565b005b6102967f000000000000000000000000d8ac7f696ae99cd7b689726cf03c5711dd8dcdb481565b6102b26103ef36600461583f565b6001600160a01b031660009081526008602052604090205490565b6006546102b2565b61033461042036600461583f565b611c1a565b610208611d7f565b61025461043b36600461585c565b611d8e565b61023161044e3660046155c3565b611f8b565b6102316104613660046155c3565b612024565b600454600554604080516001600160801b038085168252600160801b909404841660208201529290911690820152606001610215565b600754604080516001600160801b0383168152600160801b90920463ffffffff16602083015201610215565b6104db6104d636600461589f565b612031565b6040516001600160801b039091168152602001610215565b6105226105013660046158d2565b600160205260009081526040902054600281810b9163010000009004900b82565b60408051600293840b81529190920b602082015201610215565b61033461054a3660046158ed565b61219c565b6102967f000000000000000000000000c7a590291e07b9fe9e64b86c58fd8fc764308c4a81565b6104db7f000000000000000000000000000000000003b183cf0fed886cf4b05c55df388e81565b6102b26105ab36600461589f565b6123e7565b6105d77f00000000000000000000000000000000000000000000000000000000000007d081565b60405162ffffff9091168152602001610215565b6102967f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b6102b261062036600461591d565b6001600160a01b03918216600090815260096020908152604080832093909416825291909152205490565b6106ca61065936600461594b565b6040805160609490941b6bffffffffffffffffffffffff191660208086019190915260e893841b60348601529190921b60378401528151601a818503018152603a909301825282519281019290922060009081526002909252902080546001909101546001600160801b0390911691565b604080516001600160801b039093168352602083019190915201610215565b61072f6106f73660046158d2565b6000602081905290815260409020805460018201546002909201546001600160801b0380831693600160801b909304600f0b92911684565b604080516001600160801b039586168152600f9490940b60208501528301919091529091166060820152608001610215565b6060600b805461077090615987565b80601f016020809104026020016040519081016040528092919081815260200182805461079c90615987565b80156107e95780601f106107be576101008083540402835291602001916107e9565b820191906000526020600020905b8154815290600101906020018083116107cc57829003601f168201915b5050505050905090565b6000610800338484612868565b5060015b92915050565b60035460009081908190600160d01b900460ff16156108595760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b60448201526064015b60405180910390fd5b6003805460ff60d01b1916600160d01b1790556001600160801b0386166108aa5760405162461bcd60e51b8152602060048201526005602482015264302071747960d81b6044820152606401610850565b6040516310083c0760e21b81523360048201527f000000000000000000000000c7a590291e07b9fe9e64b86c58fd8fc764308c4a6001600160a01b031690634020f01c9060240160206040518083038186803b15801561090957600080fd5b505afa15801561091d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061094191906159bc565b6109795760405162461bcd60e51b81526020600482015260096024820152683337b93134b23232b760b91b6044820152606401610850565b600080610a0d6040518060e001604052808e6001600160a01b031681526020018d60020b81526020018c60020b81526020018b6000600281106109be576109be6159d9565b6020020160208101906109d191906158d2565b60020b81526020908101906109ec9060408e01908e016158d2565b60020b81526001600160801b038b166020820152600160409091015261298c565b919650945092508491508390506000808315610a2e57610a2b612dcd565b91505b8515610a3f57610a3c612ecb565b90505b604051639f382e9b60e01b81523390639f382e9b90610a68908a908a908e908e90600401615a18565b600060405180830381600087803b158015610a8257600080fd5b505af1158015610a96573d6000803e3d6000fd5b505050506000871115610af257610aab612dcd565b610ab58884615a4e565b1115610af25760405162461bcd60e51b815260206004820152600c60248201526b06c61636b696e6720717479360a41b6044820152606401610850565b8515610b4757610b00612ecb565b610b0a8783615a4e565b1115610b475760405162461bcd60e51b815260206004820152600c60248201526b6c61636b696e67207174793160a01b6044820152606401610850565b8b60020b8d60020b8f6001600160a01b03167f7a53080ba414158be7ec69b987b5fb7d07dee101fe85488f0853ae16239d0bde338e8c8c604051610bb894939291906001600160a01b039490941684526001600160801b039290921660208401526040830152606082015260800190565b60405180910390a450506003805460ff60d01b1916905550929a919950975095505050505050565b6000610bed848484612f17565b6001600160a01b038416600090815260096020908152604080832033845290915290205482811015610c725760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610850565b610c7f8533858403612868565b60019150505b9392505050565b6003546000908190600160d01b900460ff1615610cd45760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b17905586610d205760405162461bcd60e51b815260206004820152600960248201526830207377617051747960b81b6044820152606401610850565b6040805161016081018252600060208201819052918101829052606081018290526080810182905260a0810182905261010081018290526101208101829052610140810182905288815287151560c0820181905291891360e0820181905290911415610d8b816130e7565b600290810b608088015290810b606087019081526001600160a01b039092166040808801919091526001600160801b03938416610120880152938316610100870190815284518086019095529151900b8352511660208201528115610e6d5782604001516001600160a01b0316886001600160a01b0316118015610e2b575073fffd8963efd1fc6a506488495d951d5263988d266001600160a01b038916105b610e685760405162461bcd60e51b815260206004820152600e60248201526d0626164206c696d697453717274560941b6044820152606401610850565b610edc565b82604001516001600160a01b0316886001600160a01b0316108015610e9f57506401000276a36001600160a01b038916115b610edc5760405162461bcd60e51b815260206004820152600e60248201526d0626164206c696d697453717274560941b6044820152606401610850565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101919091525b835115801590610f445750886001600160a01b031684604001516001600160a01b031614155b1561136a576080840151838015610f7057506060850151610f67906101e0615a66565b60020b8160020b135b15610f8e576101e08560600151610f879190615a66565b9050610fcc565b83158015610fb257506101e08560600151610fa99190615aad565b60020b8160020b125b15610fcc576101e08560600151610fc99190615aad565b90505b60408501516001600160a01b0316610140860152610fe981613150565b6001600160a01b0390811660a08701819052908b168111851515141561100c5750895b60008060006110738961012001518a610100015161102a9190615af5565b6001600160801b03168a60400151867f00000000000000000000000000000000000000000000000000000000000007d062ffffff168d600001518e60e001518f60c00151613483565b6001600160a01b031660408d01528b51929550909350915083908a9061109a908390615b20565b9052506020890180518391906110b1908390615b5f565b9052506110bd8161358a565b89610120018181516110cf9190615af5565b6001600160801b031690525050505060a086015160408701516001600160a01b03918216911614905061113a578461014001516001600160a01b031685604001516001600160a01b0316146111345761112b85604001516135a5565b60020b60608601525b5061136a565b8361114f5761114a600182615aad565b611151565b805b600290810b6060870152608086015182820b910b146111705750610f1e565b815161126857600a5482526005546001600160801b03908116602084015260065460408401526007546101008701516111ad9291909116906138cb565b6001600160801b03166060830152604080516326311fa360e21b815281516001600160a01b037f000000000000000000000000c7a590291e07b9fe9e64b86c58fd8fc764308c4a16926398c47e8c9260048082019391829003018186803b15801561121757600080fd5b505afa15801561122b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061124f9190615b9f565b62ffffff1660a08401526001600160a01b031660808301525b600061129a8661012001516001600160801b031684602001516001600160801b0316886101000151866000015161397a565b905080156113155780836000018181516112b49190615a4e565b90525060a083015160c084018051620186a062ffffff909316840292909204918201905260e084018051828403908101909152610100880151611307908290600160601b906001600160801b03166139be565b604086018051909101905250505b6101208601516001600160801b0316602084015260808601516101008701516040850151606086015161134b9392919089613aec565b60020b60808801526001600160801b031661010087015250610f1e9050565b8051156113d25760c08101511561138d5761138d81608001518260c00151613bc9565b60e0810151156113a5576113a5308260e00151613bc9565b6020810151600580546001600160801b0319166001600160801b0390921691909117905560408101516006555b816000015160020b846060015160020b146114af576001600160a01b037f000000000000000000000000d8ac7f696ae99cd7b689726cf03c5711dd8dcdb41663ff11275e428451602086015160405160e085901b6001600160e01b031916815263ffffffff909316600484015260029190910b60248301526001600160801b031660448201526064016040805180830381600087803b15801561147457600080fd5b505af1158015611488573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114ac9190615bfe565b50505b6114d2846101000151856101200151866040015187606001518860800151613ca8565b896114ed57602084015184516114e8908d615b20565b6114ff565b83516114f9908c615b20565b84602001515b9096509450821561161b57600086121561154b5761154b7f0000000000000000000000009ae380f0272e2162340a5bb646c354271c0f5cfc6001600160a01b03168d6001891901613d52565b6000611555612ecb565b604051637d241f3960e11b8152909150339063fa483e7290611581908a908a908e908e90600401615a18565b600060405180830381600087803b15801561159b57600080fd5b505af11580156115af573d6000803e3d6000fd5b5050505085816115bf9190615a4e565b6115c7612ecb565b10156116155760405162461bcd60e51b815260206004820152601160248201527f6c61636b696e672064656c7461517479310000000000000000000000000000006044820152606401610850565b50611728565b600085121561165c5761165c7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b03168d6001881901613d52565b6000611666612dcd565b604051637d241f3960e11b8152909150339063fa483e7290611692908a908a908e908e90600401615a18565b600060405180830381600087803b1580156116ac57600080fd5b505af11580156116c0573d6000803e3d6000fd5b5050505086816116d09190615a4e565b6116d8612dcd565b10156117265760405162461bcd60e51b815260206004820152601160248201527f6c61636b696e672064656c7461517479300000000000000000000000000000006044820152606401610850565b505b60408085015161010086015160608088015184518b8152602081018b90526001600160a01b03948516958101959095526001600160801b039092169084015260020b60808301528d169033907fc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca679060a00160405180910390a350506003805460ff60d01b1916905550919890975095505050505050565b3360008181526009602090815260408083206001600160a01b038716845290915281205490916108009185906117f6908690615a4e565b612868565b600354600160d01b900460ff161561183e5760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b179055604080516326311fa360e21b815281516000926001600160a01b037f000000000000000000000000c7a590291e07b9fe9e64b86c58fd8fc764308c4a16926398c47e8c9260048083019392829003018186803b1580156118b057600080fd5b505afa1580156118c4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118e89190615b9f565b5090506000806001600160a01b0383161561197c57620186a06119307f00000000000000000000000000000000000000000000000000000000000007d062ffffff1689615c28565b61193a9190615c47565b9150620186a061196f7f00000000000000000000000000000000000000000000000000000000000007d062ffffff1688615c28565b6119799190615c47565b90505b6000611986612dcd565b90506000611992612ecb565b905088156119ce576119ce6001600160a01b037f0000000000000000000000009ae380f0272e2162340a5bb646c354271c0f5cfc168b8b613d52565b8715611a0857611a086001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48168b8a613d52565b6040516361c9276b60e11b8152339063c3924ed690611a3190879087908c908c90600401615a18565b600060405180830381600087803b158015611a4b57600080fd5b505af1158015611a5f573d6000803e3d6000fd5b505050506000611a6d612dcd565b90506000611a79612ecb565b905081611a868786615a4e565b1115611ad45760405162461bcd60e51b815260206004820152600f60248201527f6c61636b696e67206665655174793000000000000000000000000000000000006044820152606401610850565b80611adf8685615a4e565b1115611b2d5760405162461bcd60e51b815260206004820152600f60248201527f6c61636b696e67206665655174793100000000000000000000000000000000006044820152606401610850565b838203838203838614611b6e57611b6e6001600160a01b037f0000000000000000000000009ae380f0272e2162340a5bb646c354271c0f5cfc168a84613d52565b8015611ba857611ba86001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48168a83613d52565b604080518e8152602081018e9052908101839052606081018290526001600160a01b038f169033907fbdbdb71d7860376ba52b25a5028beea23581364a40522f6bcfb86bb1f2dca6339060800160405180910390a350506003805460ff60d01b19169055505050505050505050505050565b60035460009081906001600160a01b031615611c785760405162461bcd60e51b815260206004820152600e60248201527f616c726561647920696e697465640000000000000000000000000000000000006044820152606401610850565b6000611c83846135a5565b9050611c8e84613da9565b9093509150611c9b612dcd565b831115611cd95760405162461bcd60e51b815260206004820152600c60248201526b06c61636b696e6720717479360a41b6044820152606401610850565b611ce1612ecb565b821115611d1f5760405162461bcd60e51b815260206004820152600c60248201526b6c61636b696e67207174793160a01b6044820152606401610850565b611d2a306064613bc9565b611d348482613de7565b604080516001600160a01b0386168152600283900b60208201527f98636036cb66a9c19a37435efc1e90142190214e8abeb821bdba3f2990dd4c95910160405180910390a150915091565b6060600c805461077090615987565b60035460009081908190600160d01b900460ff1615611dd85760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b1790556001600160801b038416611e295760405162461bcd60e51b8152602060048201526005602482015264302071747960d81b6044820152606401610850565b600080611e8a6040518060e00160405280336001600160a01b031681526020018a60020b81526020018960020b8152602001600060020b8152602001600060020b8152602001886001600160801b031681526020016000151581525061298c565b945090925090506000821215611ed55781196001019450611ed56001600160a01b037f0000000000000000000000009ae380f0272e2162340a5bb646c354271c0f5cfc163387613d52565b6000811215611f195780196001019350611f196001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48163386613d52565b604080516001600160801b038816815260208101879052908101859052600288810b91908a900b9033907f0c396cd989a39f4459b5fa1aed6a9a8dcdbc45908acfd67e028cd568da98982c9060600160405180910390a450506003805460ff60d01b1916905591959094509092509050565b3360009081526009602090815260408083206001600160a01b03861684529091528120548281101561200d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610850565b61201a3385858403612868565b5060019392505050565b6000610800338484612f17565b60008160020b8360020b13156120895760405162461bcd60e51b815260206004820152600e60248201527f626164207469636b2072616e67650000000000000000000000000000000000006044820152606401610850565b600354600754600285810b60008181526020819052604080822084015488850b83529120830154600160b81b90950490920b936001600160801b0380851694600160801b900463ffffffff16938116929116908512156120ed57808203955061210c565b8660020b8560020b1261210457818103955061210c565b808201840395505b8460020b8860020b1315801561212757508660020b8560020b125b156121915760006121388442615c5b565b60045463ffffffff9190911691506001600160801b0316811580159061216757506000816001600160801b0316115b1561218e57806001600160801b0316606083901b8161218857612188615bd6565b04880197505b50505b505050505092915050565b6003546000908190600160d01b900460ff16156121e45760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b1790558215612255576122073385613f7b565b6040805185815260006020820181905281830152905133917f324487c99a1f7f0e3127499a548452d3a198e78ccd07add913cb93d59f0f039b919081900360600190a25060009050806123d1565b6004546003546006546001600160801b0380841693600160801b900416916001600160a01b03169061228c908490849060006140c9565b5060006122ab88846001600160801b03166122a6600a5490565b6139be565b90506122b68161358a565b6122c09084615c80565b600480546001600160801b03808416600160801b81029190921617909155600580546001600160801b031916909117905592506122fd828261415c565b95506123098282614176565b94506123153389613f7b565b851561234f5761234f6001600160a01b037f0000000000000000000000009ae380f0272e2162340a5bb646c354271c0f5cfc163388613d52565b8415612389576123896001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48163387613d52565b604080518981526020810188905290810186905233907f324487c99a1f7f0e3127499a548452d3a198e78ccd07add913cb93d59f0f039b9060600160405180910390a2505050505b6003805460ff60d01b1916905590939092509050565b600354600090600160d01b900460ff161561242d5760405162461bcd60e51b81526020600482015260066024820152651b1bd8dad95960d21b6044820152606401610850565b6003805460ff60d01b1916600160d01b1790556040516310083c0760e21b81523360048201526001600160a01b037f000000000000000000000000c7a590291e07b9fe9e64b86c58fd8fc764308c4a1690634020f01c9060240160206040518083038186803b15801561249f57600080fd5b505afa1580156124b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124d791906159bc565b61250f5760405162461bcd60e51b81526020600482015260096024820152683337b93134b23232b760b91b6044820152606401610850565b8160020b8360020b126125595760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207469636b2072616e676560701b6044820152606401610850565b600283900b620d89e71913156125a65760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964206c6f776572207469636b60701b6044820152606401610850565b6125b3620d89e719615ca0565b60020b8260020b13156125fd5760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207570706572207469636b60701b6044820152606401610850565b6126277f000000000000000000000000000000000000000000000000000000000000006484615cc3565b60020b158015612661575061265c7f000000000000000000000000000000000000000000000000000000000000006483615cc3565b60020b155b6126a45760405162461bcd60e51b81526020600482015260146024820152737469636b206e6f7420696e2064697374616e636560601b6044820152606401610850565b604080516bffffffffffffffffffffffff193360601b1660208083019190915260e886811b603484015285901b60378301528251808303601a018152603a909201835281519181019190912060008181526002909252919020546001600160801b03166127535760405162461bcd60e51b815260206004820152601060248201527f696e76616c696420706f736974696f6e000000000000000000000000000000006044820152606401610850565b60045460408051808201909152600080825260208201526006546001600160801b0380841693612792928592600160801b9092049091169060016140c9565b81526007546127aa906001600160801b0316836138cb565b6001600160801b03166020808301919091526040805160e081018252338152600289810b9382019390935287830b918101919091526000606082018190526080820181905260a0820181905260c0820181905260035490926128169291600160b81b9004900b84614190565b95509050801561282b5761282b303383612f17565b50506003805460ff60d01b1916905550909392505050565b600081612853620d89e719615ca0565b61285d9190615ce5565b610804906002615d1f565b6001600160a01b0383166128ca5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610850565b6001600160a01b03821661292b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610850565b6001600160a01b0383811660008181526009602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6000806000836040015160020b846020015160020b126129e35760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207469636b2072616e676560701b6044820152606401610850565b602084015160020b620d89e7191315612a335760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964206c6f776572207469636b60701b6044820152606401610850565b612a40620d89e719615ca0565b60020b846040015160020b1315612a8e5760405162461bcd60e51b8152602060048201526012602482015271696e76616c6964207570706572207469636b60701b6044820152606401610850565b7f00000000000000000000000000000000000000000000000000000000000000648460200151612abe9190615cc3565b60020b158015612afe57507f00000000000000000000000000000000000000000000000000000000000000648460400151612af99190615cc3565b60020b155b612b415760405162461bcd60e51b81526020600482015260146024820152737469636b206e6f7420696e2064697374616e636560601b6044820152606401610850565b60035460045460408051808201909152600080825260208201526001600160a01b03831692600160b81b900460020b916001600160801b0380821692600160801b9092041690612b988383600380015460016140c9565b8152600754612bb0906001600160801b0316846138cb565b6001600160801b031660208201526000612bcb8a8684614190565b975090508015612be457612be4308b6000015183612f17565b896020015160020b8560020b1215612c3357612c22612c068b60200151613150565b612c138c60400151613150565b8c60a001518d60c00151614234565b600098509850505050505050612dc6565b896040015160020b8560020b12612c81576000612c72612c568c60200151613150565b612c638d60400151613150565b8d60a001518e60c001516142d8565b98509850505050505050612dc6565b604080517fff11275e00000000000000000000000000000000000000000000000000000000815263ffffffff42166004820152600287900b60248201526001600160801b038616604482015281517f000000000000000000000000d8ac7f696ae99cd7b689726cf03c5711dd8dcdb46001600160a01b03169263ff11275e92606480820193918290030181600087803b158015612d1d57600080fd5b505af1158015612d31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d559190615bfe565b5050612d6886612c138c60400151613150565b9850612d8a612d7a8b60200151613150565b878c60a001518d60c001516142d8565b9750612d9f848b60a001518c60c00151614339565b600480546001600160801b0319166001600160801b03929092169190911790555050505050505b9193909250565b604051306024820152600090819081906001600160a01b037f0000000000000000000000009ae380f0272e2162340a5bb646c354271c0f5cfc16906370a0823160e01b906044015b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051612e539190615d4a565b600060405180830381855afa9150503d8060008114612e8e576040519150601f19603f3d011682016040523d82523d6000602084013e612e93565b606091505b5091509150818015612ea757506020815110155b612eb057600080fd5b80806020019051810190612ec49190615d66565b9250505090565b604051306024820152600090819081906001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816906370a0823160e01b90604401612e15565b6001600160a01b038316612f7b5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610850565b6001600160a01b038216612fdd5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610850565b6001600160a01b038316600090815260086020526040902054818110156130555760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610850565b6001600160a01b0380851660009081526008602052604080822085850390559185168152908120805484929061308c908490615a4e565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516130d891815260200190565b60405180910390a35b50505050565b6004546003546001600160801b0380831692600160801b900416906001600160a01b03811690600160b81b8104600290810b91600160a01b9004900b851561314757600290810b60009081526001602052604090205463010000009004900b5b91939590929450565b60008060008360020b12613167578260020b61316f565b8260020b6000035b9050620d89e88111156131a85760405162461bcd60e51b81526020600482015260016024820152601560fa1b6044820152606401610850565b6000600182166131bc57600160801b6131ce565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615613202576ffff97272373d413259a46990580e213a0260801c5b6004821615613221576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615613240576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b601082161561325f576fffcb9843d60f6159c9db58835c9266440260801c5b602082161561327e576fff973b41fa98c081472e6896dfb254c00260801c5b604082161561329d576fff2ea16466c96a3843ec78b326b528610260801c5b60808216156132bc576ffe5dee046a99a2a811c461f1969c30530260801c5b6101008216156132dc576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b6102008216156132fc576ff987a7253ac413176f2b074cf7815e540260801c5b61040082161561331c576ff3392b0822b70005940c7a398e4b70f30260801c5b61080082161561333c576fe7159475a2c29b7443b29c7fa6e889d90260801c5b61100082161561335c576fd097f3bdfd2022b8845ad8f792aa58250260801c5b61200082161561337c576fa9f746462d870fdf8a65dc1f90e061e50260801c5b61400082161561339c576f70d869a156d2a1b890bb3df62baf32f70260801c5b6180008216156133bc576f31be135f97d08fd981231505542fcfa60260801c5b620100008216156133dd576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b620200008216156133fd576e5d6af8dedb81196699c329225ee6040260801c5b6204000082161561341c576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615613439576b048a170391f7dc42444e8fa20260801c5b60008460020b131561345a57806000198161345657613456615bd6565b0490505b64010000000081061561346e576001613471565b60005b60ff16602082901c0192505050919050565b600080600080886001600160a01b03168a6001600160a01b031614156134b45750600092508291508190508861357c565b6134d48b8b6001600160a01b03168b6001600160a01b03168b8a8a614361565b93508580156134e257508684135b806134f65750851580156134f65750868413155b1561350357869350613506565b50875b60008085121561351a57841960010161351c565b845b90506001600160a01b0382166135595761353a818d8d8c8b8b6144fc565b925061355261354d828e868f8c8c614646565b614723565b915061356a565b613567818d8d858b8b614739565b92505b6135788c8c84868b8b61482f565b9350505b975097509750979350505050565b806001600160801b03811681146135a057600080fd5b919050565b60006401000276a36001600160a01b038316108015906135e1575073fffd8963efd1fc6a506488495d951d5263988d266001600160a01b038316105b6136115760405162461bcd60e51b81526020600482015260016024820152602960f91b6044820152606401610850565b77ffffffffffffffffffffffffffffffffffffffff00000000602083901b166001600160801b03811160071b81811c67ffffffffffffffff811160061b90811c63ffffffff811160051b90811c61ffff811160041b90811c60ff8111600390811b91821c600f811160021b90811c918211600190811b92831c979088119617909417909217179091171717608081106136b257607f810383901c91506136bc565b80607f0383901b91505b908002607f81811c60ff83811c9190911c800280831c81831c1c800280841c81841c1c800280851c81851c1c800280861c81861c1c800280871c81871c1c800280881c81881c1c800280891c81891c1c8002808a1c818a1c1c8002808b1c818b1c1c8002808c1c818c1c1c8002808d1c818d1c1c8002808e1c9c81901c9c909c1c80029c8d901c9e9d607f198f0160401b60c09190911c678000000000000000161760c19b909b1c674000000000000000169a909a1760c29990991c672000000000000000169890981760c39790971c671000000000000000169690961760c49590951c670800000000000000169490941760c59390931c670400000000000000169290921760c69190911c670200000000000000161760c79190911c670100000000000000161760c89190911c6680000000000000161760c99190911c6640000000000000161760ca9190911c6620000000000000161760cb9190911c6610000000000000161760cc9190911c6608000000000000161760cd9190911c66040000000000001617693627a301d71055774c8581026f028f6481ab7f045a5af012a19d003aa9198101608090811d906fdb2df09e81959a81455e260799a0632f8301901d600281810b9083900b146138bc57886001600160a01b03166138a182613150565b6001600160a01b031611156138b657816138be565b806138be565b815b9998505050505050505050565b6007546000908190600160801b900463ffffffff16426138eb9190615c5b565b63ffffffff1690508015613972576007805473ffffffff000000000000000000000000000000001916600160801b63ffffffff4216021790556001600160801b038316156139725761394a6001600160801b038416606083901b615c47565b6139549085615af5565b600780546001600160801b0319166001600160801b03831617905593505b509192915050565b6000806139a76001600160801b0385166139948789615d7f565b6122a6896001600160801b038916615a4e565b90506139b48382876139be565b9695505050505050565b600080806000198587098587029250828110838203039150508060001415613a255760008411613a1a5760405162461bcd60e51b8152602060048201526007602482015266302064656e6f6d60c81b6044820152606401610850565b508290049050610c85565b808411613a745760405162461bcd60e51b815260206004820152600e60248201527f64656e6f6d203c3d2070726f64310000000000000000000000000000000000006044820152606401610850565b6000848688098084039381119092039190506000613a9486196001615a4e565b8616958690049560026003880281188089028203028089028203028089028203028089028203028089028203028089029091030260008290038290046001019490940294049390931791909102925050509392505050565b600285810b60009081526020819052604081206001810180548703905591820180546001600160801b038082168703166001600160801b031990911617905590548190600160801b9004600f0b8315613b6357600288810b60009081526001602052604090205463010000009004900b9150613b87565b600288810b600090815260016020526040902054900b9150613b8481615d96565b90505b613bbc87600083600f0b1215613bad57600f83900b6001600160801b0303600101613baf565b825b600084600f0b1215614339565b9250509550959350505050565b6001600160a01b038216613c1f5760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610850565b80600a6000828254613c319190615a4e565b90915550506001600160a01b03821660009081526008602052604081208054839290613c5e908490615a4e565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b6001600160801b03848116600160801b02908616176004556003805462ffffff8416600160b81b0279ffffff000000ffffffffffffffffffffffffffffffffffffffff199091166001600160a01b03861617179055600282810b9082900b13613d115780613d28565b600281810b600090815260016020526040902054900b5b6003805462ffffff92909216600160a01b0262ffffff60a01b199092169190911790555050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052613da490849061491c565b505050565b600080613dc56064600160601b6001600160a01b0386166149ee565b9150613de060646001600160a01b038516600160601b6149ee565b9050915091565b7064000000000000000000000000000000006004556005805460646001600160801b0319909116179055600380546001600160a01b03841679ffffff000000ffffffffffffffffffffffffffffffffffffffff1990911617600160b81b62ffffff8416021762ffffff60a01b1916621e4ec360a31b179055613ec6620d89e719613e7081615ca0565b600282810b600090815260016020526040808220805462ffffff96871662ffffff199787166301000000029790971665ffffffffffff19918216811788179092559490930b825290208054909216179091179055565b60408051633440fba760e01b815263ffffffff4216600482015281517f000000000000000000000000d8ac7f696ae99cd7b689726cf03c5711dd8dcdb46001600160a01b031692633440fba792602480820193918290030181600087803b158015613f3057600080fd5b505af1158015613f44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f689190615bfe565b50506003805460ff60d01b191690555050565b6001600160a01b038216613fdb5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610850565b6001600160a01b0382166000908152600860205260409020548181101561404f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610850565b6001600160a01b03831660009081526008602052604081208383039055600a805484929061407e908490615d7f565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b60055460009081906140f1906001600160801b038088169116886140ec600a5490565b61397a565b905080156141305761410281614a20565b905061410e3082613bc9565b61412681600160601b886001600160801b03166139be565b9093016006819055925b821561415257600580546001600160801b0319166001600160801b0387161790555b5091949350505050565b6000610c8582600160601b856001600160a01b03166139be565b6000610c8582846001600160a01b0316600160601b6139be565b60008060006141b586602001518688606001518960a001518a60c00151896001614af6565b905060006141d987604001518789608001518a60a001518b60c001518a6000614af6565b9050866020015160020b8660020b12156141f757808203925061421e565b866040015160020b8660020b1261421257818103925061421e565b80828660000151030392505b6142288784614dc5565b93505050935093915050565b60007bffffffffffffffffffffffffffffffff000000000000000000000000606084901b166001600160a01b03868603168361429f5761429a876001600160a01b031661428b84848a6001600160a01b03166139be565b6142959190615c47565b614ec1565b6142cd565b6142cd6142c86142b984848a6001600160a01b03166149ee565b896001600160a01b0316614edc565b614ef6565b979650505050505050565b60008161430a57614305614295846001600160801b03168787036001600160a01b0316600160601b6139be565b614330565b6143306142c8846001600160801b03168787036001600160a01b0316600160601b6149ee565b95945050505050565b60008161434f5761434a8385615c80565b614359565b6143598385615af5565b949350505050565b6000808587101561437457868603614378565b8587035b9050831561442d5782156143e15760006143928887615c28565b61439f8862030d40615c28565b6143a99190615d7f565b905060006143c48a6143be8562030d40615c28565b846139be565b90506143d86142c882600160601b8c6139be565b935050506144f1565b60006143ed8787615c28565b6143fa8962030d40615c28565b6144049190615d7f565b905060006144198a6143be8562030d40615c28565b90506143d86142c8828b600160601b6139be565b821561449057600061443f8787615c28565b61444c8962030d40615c28565b6144569190615d7f565b905060006144648988615c28565b61446e9083615d7f565b905061447f60608b901b82846139be565b90506143d88861428b83868d6139be565b600061449c8887615c28565b6144a98862030d40615c28565b6144b39190615d7f565b905060006144c18888615c28565b6144cb9083615d7f565b90506144d88a82846139be565b90506144ec6142958285600160601b6139be565b935050505b509695505050505050565b6000821561456557811561453d576145366001600160a01b038616614521868a615c28565b6e030d400000000000000000000000006139be565b90506139b4565b614536600160601b61454f868a615c28565b6122a66001600160a01b03891662030d40615c28565b8360008761457683620186a0615d7f565b6145809190615c28565b905060008961458f8a89615c28565b6145999190615c28565b905084156145f0576145c56145b18b620186a0615c28565b896001600160a01b0316600160601b6139be565b6145cf9083615d7f565b91506145e981896001600160a01b0316600160601b6139be565b905061463b565b6146146146008b620186a0615c28565b600160601b8a6001600160a01b03166139be565b61461e9083615d7f565b915061463881600160601b8a6001600160a01b03166139be565b90505b6144ec838383614f0c565b600081156146bf57600061466888866001600160a01b0316600160601b6139be565b9050831561469e5761469661467d8789615a4e565b6001600160a01b038716614691848b615a4e565b6149ee565b9150506139b4565b6146966146ab8789615a4e565b6001600160a01b0387166122a6848b615d7f565b60006146d988600160601b876001600160a01b03166139be565b90508315614702576146966146ee8289615a4e565b6001600160a01b0387166122a6898b615a4e565b61469661470f8289615d7f565b6001600160a01b038716614691898b615a4e565b806001600160a01b03811681146135a057600080fd5b600081156147bd57600061475b87600160601b886001600160a01b03166139be565b90506000846147735761476e8983615d7f565b61477d565b61477d8983615a4e565b90506000614799876001600160a01b031683600160601b6139be565b90508881116147a95760006147b3565b6147b38982615d7f565b93505050506139b4565b60006147d787876001600160a01b0316600160601b6139be565b90506000846147ef576147ea8983615d7f565b6147f9565b6147f98983615a4e565b9050600061481582600160601b896001600160a01b03166139be565b90508881116148255760006144ec565b6144ec8982615d7f565b600081156148b157821561488d576148616142958861484e888a615db4565b6001600160a01b0316600160601b6139be565b61487c6142c886886001600160a01b0316600160601b6149ee565b6148869190615b5f565b90506148fd565b6148616142c88861489e8989615db4565b6001600160a01b0316600160601b6149ee565b6148cc61429588600160601b896001600160a01b03166139be565b6148f06142c86148dc878b615a4e565b600160601b896001600160a01b03166149ee565b6148fa9190615b5f565b90505b82801561490a5750806001145b156139b4575060009695505050505050565b6000614971826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614f499092919063ffffffff16565b805190915015613da4578080602001905181019061498f91906159bc565b613da45760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610850565b60006149fb8484846139be565b905060008280614a0d57614a0d615bd6565b8486091115610c85578061433081615dd4565b60008060007f000000000000000000000000c7a590291e07b9fe9e64b86c58fd8fc764308c4a6001600160a01b03166398c47e8c6040518163ffffffff1660e01b8152600401604080518083038186803b158015614a7d57600080fd5b505afa158015614a91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ab59190615b9f565b915091508062ffffff1660001415614acf57509192915050565b620186a062ffffff82168502048015614aec57614aec8382613bc9565b9093039392505050565b600287900b6000908152602081905260408120546001600160801b031680151580614b2957506001600160801b03861615155b614b635760405162461bcd60e51b815260206004820152600b60248201526a696e76616c6964206c697160a81b6044820152606401610850565b6001600160801b038616614b8f575050600287900b6000908152602081905260409020600101546142cd565b6000614b9c828888614339565b90507f000000000000000000000000000000000003b183cf0fed886cf4b05c55df388e6001600160801b0316816001600160801b03161115614c205760405162461bcd60e51b815260206004820152600f60248201527f3e206d6178206c697175696469747900000000000000000000000000000000006044820152606401610850565b600086614c4757614c39886001600160801b0316614f58565b614c4290615d96565b614c59565b614c59886001600160801b0316614f58565b9050600085614c905760028c900b600090815260208190526040902054614c8b908390600160801b9004600f0b615def565b614cb9565b60028c900b600090815260208190526040902054614cb9908390600160801b9004600f0b615e35565b90506001600160801b038416614d17578a60020b8c60020b13614d1757865160028d810b6000908152602081815260409091206001810193909355890151910180546001600160801b0319166001600160801b039092169190911790555b60028c900b60009081526020819052604090206001600160801b03828116600160801b028186161782556001909101549550841615801590614d6057506001600160801b038316155b15614d935760028c810b600090815260208190526040812081815560018101919091550180546001600160801b03191690555b6001600160801b038481161515908416151514614db657614db68c8b8d8b614f7f565b50505050979650505050505050565b8151602080840151604080860151815160609590951b6bffffffffffffffffffffffff19168585015260e892831b603486015290911b60378401528051601a818503018152603a9093019052815191012060009081906000818152600260205260409020600181015490549192508403906001600160801b0316614e4e8282600160601b6139be565b93508560a001516001600160801b0316600014614ea557614e78818760a001518860c00151614339565b600084815260026020526040902080546001600160801b0319166001600160801b03929092169190911790555b5050600090815260026020526040902060010191909155919050565b6000600160ff1b8210614ed357600080fd5b61080482615e7b565b6000808211614eea57600080fd5b50808204910615150190565b6000600160ff1b8210614f0857600080fd5b5090565b600083614f35614f1c8483615c28565b614f268680615c28565b614f309190615d7f565b61512f565b614f3f9085615d7f565b6143599190615c47565b6060614359848460008561518c565b60006f80000000000000000000000000000000826001600160801b031610614f0857600080fd5b80156150d257600284900b620d89e7191480614fac5750614fa3620d89e719615ca0565b60020b8460020b145b15614fb6576130e1565b600283810b60009081526001602052604090205463010000008104820b910b8114156150245760405162461bcd60e51b815260206004820152601e60248201527f70726576696f7573207469636b20686173206265656e2072656d6f76656400006044820152606401610850565b60005b8560020b8260020b1315801561503d5750600a81105b1561507757600282810b600090815260016020526040902054929550630100000090920490910b908061506f81615dd4565b915050615027565b61508460018787856152a9565b600354600287810b600160a01b909204900b1280156150a957508360020b8660020b13155b156150cb576003805462ffffff60a01b1916600160a01b62ffffff8916021790555b50506130e1565b600354600285810b600160a01b909204900b141561511d576150f56001856153e9565b6003805462ffffff92909216600160a01b0262ffffff60a01b199092169190911790556130e1565b6151286001856153e9565b5050505050565b6000600382111561517e575080600160028204015b818110156151785780915060028182858161516157615161615bd6565b04018161517057615170615bd6565b049050615144565b50919050565b81156135a057506001919050565b6060824710156151ed5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610850565b843b61523b5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610850565b600080866001600160a01b031685876040516152579190615d4a565b60006040518083038185875af1925050503d8060008114615294576040519150601f19603f3d011682016040523d82523d6000602084013e615299565b606091505b50915091506142cd828286615513565b600282810b60009081526020869052604090205482820b910b14156153105760405162461bcd60e51b815260206004820152601e60248201527f6c6f7765722076616c7565206973206e6f7420696e697469616c697a656400006044820152606401610850565b8260020b8260020b12801561532a57508260020b8160020b135b6153765760405162461bcd60e51b815260206004820152601360248201527f696e76616c6964206c6f7765722076616c7565000000000000000000000000006044820152606401610850565b600283810b60009081526020959095526040808620805465ffffffffffff1916630100000062ffffff868116820262ffffff19908116939093178882161790935594840b885282882080549091169190961690811790955592900b84529220805465ffffff000000191691909202179055565b600281810b60009081526020848152604080832081518083019092525480850b808352630100000090910490940b9181018290529192141561546d5760405162461bcd60e51b815260206004820152601960248201527f72656d6f7665206e6f6e2d6578697374656e742076616c7565000000000000006044820152606401610850565b8260020b816000015160020b14156154885782915050610804565b806000015191508260020b816020015160020b14156154a75750610804565b602081810180518351600290810b6000908152979093526040808820805465ffffff0000001916630100000062ffffff9485160217905593519151830b8752838720805462ffffff1916929091169190911790559290920b83529120805465ffffffffffff1916905590565b60608315615522575081610c85565b8251156155325782518084602001fd5b8160405162461bcd60e51b81526004016108509190615578565b60005b8381101561556757818101518382015260200161554f565b838111156130e15750506000910152565b602081526000825180602084015261559781604085016020870161554c565b601f01601f19169190910160400192915050565b6001600160a01b03811681146155c057600080fd5b50565b600080604083850312156155d657600080fd5b82356155e1816155ab565b946020939093013593505050565b8035600281900b81146135a057600080fd5b80356001600160801b03811681146135a057600080fd5b60008083601f84011261562a57600080fd5b50813567ffffffffffffffff81111561564257600080fd5b60208301915083602082850101111561565a57600080fd5b9250929050565b600080600080600080600060e0888a03121561567c57600080fd5b8735615687816155ab565b9650615695602089016155ef565b95506156a3604089016155ef565b945060a08801898111156156b657600080fd5b6060890194506156c581615601565b93505060c088013567ffffffffffffffff8111156156e257600080fd5b6156ee8a828b01615618565b989b979a50959850939692959293505050565b60008060006060848603121561571657600080fd5b8335615721816155ab565b92506020840135615731816155ab565b929592945050506040919091013590565b80151581146155c057600080fd5b60008060008060008060a0878903121561576957600080fd5b8635615774816155ab565b955060208701359450604087013561578b81615742565b9350606087013561579b816155ab565b9250608087013567ffffffffffffffff8111156157b757600080fd5b6157c389828a01615618565b979a9699509497509295939492505050565b6000806000806000608086880312156157ed57600080fd5b85356157f8816155ab565b94506020860135935060408601359250606086013567ffffffffffffffff81111561582257600080fd5b61582e88828901615618565b969995985093965092949392505050565b60006020828403121561585157600080fd5b8135610c85816155ab565b60008060006060848603121561587157600080fd5b61587a846155ef565b9250615888602085016155ef565b915061589660408501615601565b90509250925092565b600080604083850312156158b257600080fd5b6158bb836155ef565b91506158c9602084016155ef565b90509250929050565b6000602082840312156158e457600080fd5b610c85826155ef565b6000806040838503121561590057600080fd5b82359150602083013561591281615742565b809150509250929050565b6000806040838503121561593057600080fd5b823561593b816155ab565b91506020830135615912816155ab565b60008060006060848603121561596057600080fd5b833561596b816155ab565b9250615979602085016155ef565b9150615896604085016155ef565b600181811c9082168061599b57607f821691505b6020821081141561517857634e487b7160e01b600052602260045260246000fd5b6000602082840312156159ce57600080fd5b8151610c8581615742565b634e487b7160e01b600052603260045260246000fd5b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b8481528360208201526060604082015260006139b46060830184866159ef565b634e487b7160e01b600052601160045260246000fd5b60008219821115615a6157615a61615a38565b500190565b60008160020b8360020b6000821282627fffff03821381151615615a8c57615a8c615a38565b82627fffff19038212811615615aa457615aa4615a38565b50019392505050565b60008160020b8360020b6000811281627fffff1901831281151615615ad457615ad4615a38565b81627fffff018313811615615aeb57615aeb615a38565b5090039392505050565b60006001600160801b03808316818516808303821115615b1757615b17615a38565b01949350505050565b60008083128015600160ff1b850184121615615b3e57615b3e615a38565b836001600160ff1b03018313811615615b5957615b59615a38565b50500390565b6000808212826001600160ff1b0303841381151615615b8057615b80615a38565b600160ff1b8390038412811615615b9957615b99615a38565b50500190565b60008060408385031215615bb257600080fd5b8251615bbd816155ab565b602084015190925062ffffff8116811461591257600080fd5b634e487b7160e01b600052601260045260246000fd5b805161ffff811681146135a057600080fd5b60008060408385031215615c1157600080fd5b615c1a83615bec565b91506158c960208401615bec565b6000816000190483118215151615615c4257615c42615a38565b500290565b600082615c5657615c56615bd6565b500490565b600063ffffffff83811690831681811015615c7857615c78615a38565b039392505050565b60006001600160801b0383811690831681811015615c7857615c78615a38565b60008160020b627fffff19811415615cba57615cba615a38565b60000392915050565b60008260020b80615cd657615cd6615bd6565b808360020b0791505092915050565b60008160020b8360020b80615cfc57615cfc615bd6565b627fffff19821460001982141615615d1657615d16615a38565b90059392505050565b600062ffffff80831681851681830481118215151615615d4157615d41615a38565b02949350505050565b60008251615d5c81846020870161554c565b9190910192915050565b600060208284031215615d7857600080fd5b5051919050565b600082821015615d9157615d91615a38565b500390565b600081600f0b60016001607f1b0319811415615cba57615cba615a38565b60006001600160a01b0383811690831681811015615c7857615c78615a38565b6000600019821415615de857615de8615a38565b5060010190565b600081600f0b83600f0b600081128160016001607f1b031901831281151615615e1a57615e1a615a38565b8160016001607f1b03018313811615615aeb57615aeb615a38565b600081600f0b83600f0b600082128260016001607f1b0303821381151615615e5f57615e5f615a38565b8260016001607f1b0319038212811615615aa457615aa4615a38565b6000600160ff1b821415615e9157615e91615a38565b506000039056fea164736f6c6343000809000a
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.