Overview
S Balance
0 S
S Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Update Whitelist... | 1861884 | 32 days ago | IN | 0 S | 0.00005062 |
Loading...
Loading
Contract Name:
SushiV3SingleTickLiquidityHandlerV2
Compiler Version
v0.8.15+commit.e14f2714
Optimization Enabled:
Yes with 0 runs
Other Settings:
london EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.0 <0.9.0; // Interfaces import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol"; import {ISwapRouter} from "v3-periphery/SwapRouter.sol"; import {IHandler} from "../interfaces/IHandler.sol"; import {IHook} from "../interfaces/IHook.sol"; // Libraries import {Math} from "openzeppelin-contracts/contracts/utils/math/Math.sol"; import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol"; import {LiquidityAmounts} from "v3-periphery/libraries/LiquidityAmounts.sol"; import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol"; import {FullMath} from "@uniswap/v3-core/contracts/libraries/FullMath.sol"; import {FixedPoint128} from "@uniswap/v3-core/contracts/libraries/FixedPoint128.sol"; // Contracts import {AccessControl} from "openzeppelin-contracts/contracts/access/AccessControl.sol"; import {Pausable} from "openzeppelin-contracts/contracts/security/Pausable.sol"; import {ERC6909} from "../libraries/tokens/ERC6909.sol"; import {LiquidityManager} from "../uniswap-v3/LiquidityManager.sol"; contract SushiV3SingleTickLiquidityHandlerV2 is ERC6909, IHandler, Pausable, AccessControl, LiquidityManager { using Math for uint128; using TickMath for int24; using SafeERC20 for IERC20; struct TokenIdInfo { uint128 totalLiquidity; uint128 totalSupply; uint128 liquidityUsed; uint256 feeGrowthInside0LastX128; uint256 feeGrowthInside1LastX128; uint128 tokensOwed0; uint128 tokensOwed1; uint64 lastDonation; uint128 donatedLiquidity; address token0; address token1; uint24 fee; uint128 reservedLiquidity; } struct MintPositionParams { IUniswapV3Pool pool; address hook; int24 tickLower; int24 tickUpper; uint128 liquidity; } struct BurnPositionParams { IUniswapV3Pool pool; address hook; int24 tickLower; int24 tickUpper; uint128 shares; } struct ReserveLiquidityData { uint128 liquidity; uint64 lastReserve; } struct UsePositionParams { IUniswapV3Pool pool; address hook; int24 tickLower; int24 tickUpper; uint128 liquidityToUse; } struct UnusePositionParams { IUniswapV3Pool pool; address hook; int24 tickLower; int24 tickUpper; uint128 liquidityToUnuse; } struct DonateParams { IUniswapV3Pool pool; address hook; int24 tickLower; int24 tickUpper; uint128 liquidityToDonate; } struct MintPositionCache { int24 tickLower; int24 tickUpper; uint160 sqrtRatioTickLower; uint160 sqrtRatioTickUpper; uint128 liquidity; uint256 amount0; uint256 amount1; } struct BurnPositionCache { uint128 liquidityToBurn; uint256 amount0; uint256 amount1; } // events event LogMintedPosition( uint256 tokenId, uint128 liquidityMinted, address pool, address hook, address user, int24 tickLower, int24 tickUpper ); event LogBurnedPosition( uint256 tokenId, uint128 liquidityBurned, address pool, address hook, address user, int24 tickLower, int24 tickUpper ); event LogFeeCompound( address handler, IUniswapV3Pool pool, uint256 tokenId, int24 tickLower, int24 tickUpper, uint128 liquidity ); event LogUsePosition(uint256 tokenId, uint128 liquidityUsed); event LogUnusePosition(uint256 tokenId, uint128 liquidityUnused); event LogDonation(uint256 tokenId, uint128 liquidityDonated); event LogUpdateWhitelistedApp(address _app, bool _status); event LogUpdatedLockBlockAndReserveCooldownDuration(uint64 _newLockedBlockDuration, uint64 _newReserveCooldown); event LogReservedLiquidity(uint256 tokenId, uint128 liquidityReserved, address user); event LogWithdrawReservedLiquidity(uint256 tokenId, uint128 liquidityWithdrawn, address user); // errors error UniswapV3SingleTickLiquidityHandlerV2__NotWhitelisted(); error UniswapV3SingleTickLiquidityHandlerV2__InRangeLP(); error UniswapV3SingleTickLiquidityHandlerV2__InsufficientLiquidity(); error UniswapV3SingleTickLiquidityHandlerV2__BeforeReserveCooldown(); mapping(uint256 => TokenIdInfo) public tokenIds; mapping(address => bool) public whitelistedApps; mapping(uint256 => mapping(address => ReserveLiquidityData)) public reservedLiquidityPerUser; ISwapRouter swapRouter; uint64 public reserveCooldown = 6 hours; uint64 public lockedBlockDuration = 100; uint64 public newLockedBlockDuration; bytes32 constant PAUSER_ROLE = keccak256("P"); bytes32 constant SOS_ROLE = keccak256("SOS"); constructor(address _factory, bytes32 _pool_init_code_hash, address _swapRouter) LiquidityManager(_factory, _pool_init_code_hash) { swapRouter = ISwapRouter(_swapRouter); _setupRole(DEFAULT_ADMIN_ROLE, msg.sender); } /** * @notice Mints a new position for the user. * @param context The address of the user minting the position. * @param _mintPositionData The data required to mint the position. * @dev Only whitelisted DopexV2PositionManager can call it. It auto-compounds * the fees on mint. You cannot mint in range liquidity. Recommended to add liquidity * on a single ticks only. * @return sharesMinted The number of shares minted. */ function mintPositionHandler(address context, bytes calldata _mintPositionData) external whenNotPaused returns (uint256 sharesMinted) { onlyWhitelisted(); MintPositionParams memory _params = abi.decode(_mintPositionData, (MintPositionParams)); uint256 tokenId = uint256( keccak256(abi.encode(address(this), _params.pool, _params.hook, _params.tickLower, _params.tickUpper)) ); TokenIdInfo storage tki = tokenIds[tokenId]; if (tki.token0 == address(0)) { tki.token0 = _params.pool.token0(); tki.token1 = _params.pool.token1(); tki.fee = _params.pool.fee(); } MintPositionCache memory posCache = MintPositionCache({ tickLower: _params.tickLower, tickUpper: _params.tickUpper, sqrtRatioTickLower: _params.tickLower.getSqrtRatioAtTick(), sqrtRatioTickUpper: _params.tickUpper.getSqrtRatioAtTick(), liquidity: 0, amount0: 0, amount1: 0 }); (posCache.amount0, posCache.amount1) = LiquidityAmounts.getAmountsForLiquidity( _getCurrentSqrtPriceX96(_params.pool), posCache.sqrtRatioTickLower, posCache.sqrtRatioTickUpper, uint128(_params.liquidity) ); if (posCache.amount0 > 0 && posCache.amount1 > 0) { revert UniswapV3SingleTickLiquidityHandlerV2__InRangeLP(); } (posCache.liquidity,,,) = addLiquidity( LiquidityManager.AddLiquidityParams({ token0: tki.token0, token1: tki.token1, fee: tki.fee, recipient: address(this), tickLower: posCache.tickLower, tickUpper: posCache.tickUpper, amount0Desired: posCache.amount0, amount1Desired: posCache.amount1, amount0Min: posCache.amount0, amount1Min: posCache.amount1 }) ); _feeCalculation(tki, _params.pool, posCache.tickLower, posCache.tickUpper); if (tki.totalSupply > 0) { // compound fees if (tki.tokensOwed0 > 1_000 || tki.tokensOwed1 > 1_000) { uint256 expectedAmountForLiquidity0 = LiquidityAmounts.getAmount0ForLiquidity(posCache.sqrtRatioTickLower, posCache.sqrtRatioTickUpper, 2); uint256 expectedAmountForLiquidity1 = LiquidityAmounts.getAmount1ForLiquidity(posCache.sqrtRatioTickLower, posCache.sqrtRatioTickUpper, 2); if (expectedAmountForLiquidity0 > tki.tokensOwed0 || expectedAmountForLiquidity1 > tki.tokensOwed1) { bool isAmount0 = posCache.amount0 > 0; (uint256 a0, uint256 a1) = _params.pool.collect( address(this), _params.tickLower, _params.tickUpper, uint128(tki.tokensOwed0), uint128(tki.tokensOwed1) ); (tki.tokensOwed0, tki.tokensOwed1) = (0, 0); uint256 amountOut; if (isAmount0 ? a1 > 0 : a0 > 0) { IERC20(isAmount0 ? tki.token1 : tki.token0).safeIncreaseAllowance( address(swapRouter), isAmount0 ? a1 : a0 ); amountOut = swapRouter.exactInputSingle( ISwapRouter.ExactInputSingleParams({ tokenIn: isAmount0 ? tki.token1 : tki.token0, tokenOut: isAmount0 ? tki.token0 : tki.token1, fee: tki.fee, recipient: address(this), deadline: block.timestamp, amountIn: isAmount0 ? a1 : a0, amountOutMinimum: 0, sqrtPriceLimitX96: 0 }) ); } (uint128 liquidityFee,,,) = SushiV3SingleTickLiquidityHandlerV2(address(this)).addLiquidity( LiquidityManager.AddLiquidityParams({ token0: tki.token0, token1: tki.token1, fee: tki.fee, recipient: address(this), tickLower: _params.tickLower, tickUpper: _params.tickUpper, amount0Desired: a0 + (isAmount0 ? amountOut : 0), amount1Desired: a1 + (isAmount0 ? 0 : amountOut), amount0Min: a0 + (isAmount0 ? amountOut : 0), amount1Min: a1 + (isAmount0 ? 0 : amountOut) }) ); tki.totalLiquidity += liquidityFee; emit LogFeeCompound( address(this), _params.pool, tokenId, posCache.tickLower, posCache.tickUpper, liquidityFee ); } } uint128 shares = _convertToShares(posCache.liquidity, tokenId); tki.totalLiquidity += posCache.liquidity; tki.totalSupply += shares; sharesMinted = shares; } else { tki.totalLiquidity += posCache.liquidity; tki.totalSupply += posCache.liquidity; sharesMinted = posCache.liquidity; } _mint(context, tokenId, sharesMinted); emit LogMintedPosition( tokenId, posCache.liquidity, address(_params.pool), _params.hook, context, posCache.tickLower, posCache.tickUpper ); } /** * @notice Burn an existing position. * @param context The address of the user burning the position. * @param _burnPositionData The data required to burn the position. * @dev Only whitelisted DopexV2PositionManager can call it. Users will receive the fees * in either token0 or token1 or both based on the fee collection. * @return The number of shares burned. */ function burnPositionHandler(address context, bytes calldata _burnPositionData) external whenNotPaused returns (uint256) { onlyWhitelisted(); BurnPositionParams memory _params = abi.decode(_burnPositionData, (BurnPositionParams)); uint256 tokenId = uint256( keccak256(abi.encode(address(this), _params.pool, _params.hook, _params.tickLower, _params.tickUpper)) ); TokenIdInfo storage tki = tokenIds[tokenId]; BurnPositionCache memory posCache = BurnPositionCache({liquidityToBurn: 0, amount0: 0, amount1: 0}); posCache.liquidityToBurn = _convertToAssets(_params.shares, tokenId); if ((tki.totalLiquidity - tki.liquidityUsed) < posCache.liquidityToBurn) { revert UniswapV3SingleTickLiquidityHandlerV2__InsufficientLiquidity(); } (posCache.amount0, posCache.amount1) = _params.pool.burn(_params.tickLower, _params.tickUpper, posCache.liquidityToBurn); _feeCalculation(tki, _params.pool, _params.tickLower, _params.tickUpper); (uint128 feesOwedToken0, uint128 feesOwedToken1) = _feesTokenOwed( _params.tickLower, _params.tickUpper, posCache.liquidityToBurn, tki.totalLiquidity, tki.tokensOwed0, tki.tokensOwed1 ); tki.tokensOwed0 -= feesOwedToken0; tki.tokensOwed1 -= feesOwedToken1; _params.pool.collect( context, _params.tickLower, _params.tickUpper, uint128(posCache.amount0 + feesOwedToken0), uint128(posCache.amount1 + feesOwedToken1) ); tki.totalLiquidity -= posCache.liquidityToBurn; tki.totalSupply -= _params.shares; _burn(context, tokenId, _params.shares); emit LogBurnedPosition( tokenId, posCache.liquidityToBurn, address(_params.pool), _params.hook, context, _params.tickLower, _params.tickUpper ); return (_params.shares); } /** * @notice Reserve Liquidity from future * @param _reserveLiquidityParam The data required for reserving liquidity. * @dev This can be called by the user directly, it uses msg.sender context. Users share would * be burned and they will receive Uniswap V3 fees upto this point. * @return The number of shares burned. */ function reserveLiquidity(bytes calldata _reserveLiquidityParam) external whenNotPaused returns (uint256) { BurnPositionParams memory _params = abi.decode(_reserveLiquidityParam, (BurnPositionParams)); uint256 tokenId = uint256( keccak256(abi.encode(address(this), _params.pool, _params.hook, _params.tickLower, _params.tickUpper)) ); TokenIdInfo storage tki = tokenIds[tokenId]; uint128 liquidityToBurn = _convertToAssets(_params.shares, tokenId); _params.pool.burn(_params.tickLower, _params.tickUpper, 0); _feeCalculation(tki, _params.pool, _params.tickLower, _params.tickUpper); (uint128 feesOwedToken0, uint128 feesOwedToken1) = _feesTokenOwed( _params.tickLower, _params.tickUpper, liquidityToBurn, tki.totalLiquidity, tki.tokensOwed0, tki.tokensOwed1 ); tki.tokensOwed0 -= feesOwedToken0; tki.tokensOwed1 -= feesOwedToken1; _params.pool.collect( msg.sender, _params.tickLower, _params.tickUpper, uint128(feesOwedToken0), uint128(feesOwedToken1) ); ReserveLiquidityData storage rld = reservedLiquidityPerUser[tokenId][msg.sender]; rld.liquidity += liquidityToBurn; rld.lastReserve = uint64(block.timestamp); tki.totalLiquidity -= liquidityToBurn; tki.totalSupply -= _params.shares; tki.reservedLiquidity += liquidityToBurn; _burn(msg.sender, tokenId, _params.shares); emit LogBurnedPosition( tokenId, liquidityToBurn, address(_params.pool), _params.hook, msg.sender, _params.tickLower, _params.tickUpper ); emit LogReservedLiquidity(tokenId, liquidityToBurn, msg.sender); return (_params.shares); } function _feesTokenOwed( int24 tickLower, int24 tickUpper, uint128 liquidityToBurn, uint128 totalLiquidity, uint128 tokensOwed0, uint128 tokensOwed1 ) private view returns (uint128 feesOwedToken0, uint128 feesOwedToken1) { uint256 userLiquidity0 = LiquidityAmounts.getAmount0ForLiquidity( tickLower.getSqrtRatioAtTick(), tickUpper.getSqrtRatioAtTick(), liquidityToBurn ); uint256 userLiquidity1 = LiquidityAmounts.getAmount1ForLiquidity( tickLower.getSqrtRatioAtTick(), tickUpper.getSqrtRatioAtTick(), liquidityToBurn ); uint256 totalLiquidity0 = LiquidityAmounts.getAmount0ForLiquidity( tickLower.getSqrtRatioAtTick(), tickUpper.getSqrtRatioAtTick(), totalLiquidity ); uint256 totalLiquidity1 = LiquidityAmounts.getAmount1ForLiquidity( tickLower.getSqrtRatioAtTick(), tickUpper.getSqrtRatioAtTick(), totalLiquidity ); if (totalLiquidity0 > 0) { feesOwedToken0 = uint128((tokensOwed0 * userLiquidity0) / totalLiquidity0); } if (totalLiquidity1 > 0) { feesOwedToken1 = uint128((tokensOwed1 * userLiquidity1) / totalLiquidity1); } } /** * @notice Withdraw reserved liquidity * @param _reserveLiquidityParam The data required for withdraw reserved liquidity. * @dev This can be called by the user directly, it uses msg.sender context. Users can withdraw * liquidity if it is available and their cooldown is over. */ function withdrawReserveLiquidity(bytes calldata _reserveLiquidityParam) external whenNotPaused { BurnPositionParams memory _params = abi.decode(_reserveLiquidityParam, (BurnPositionParams)); uint256 tokenId = uint256( keccak256(abi.encode(address(this), _params.pool, _params.hook, _params.tickLower, _params.tickUpper)) ); TokenIdInfo storage tki = tokenIds[tokenId]; ReserveLiquidityData storage rld = reservedLiquidityPerUser[tokenId][msg.sender]; if (rld.lastReserve + reserveCooldown > block.timestamp) { revert UniswapV3SingleTickLiquidityHandlerV2__BeforeReserveCooldown(); } if (((tki.totalLiquidity + tki.reservedLiquidity) - tki.liquidityUsed) < _params.shares) { revert UniswapV3SingleTickLiquidityHandlerV2__InsufficientLiquidity(); } (uint256 amount0, uint256 amount1) = _params.pool.burn(_params.tickLower, _params.tickUpper, _params.shares); _params.pool.collect(msg.sender, _params.tickLower, _params.tickUpper, uint128(amount0), uint128(amount1)); _feeCalculation(tki, _params.pool, _params.tickLower, _params.tickUpper); tki.reservedLiquidity -= _params.shares; rld.liquidity -= _params.shares; emit LogWithdrawReservedLiquidity(tokenId, _params.shares, msg.sender); } /** * @notice Use an existing position. * @param _usePositionHandler The data required to use the position. * @dev Only whitelisted DopexV2PositionManager can call it. * @return tokens The addresses of the tokens that were unwrapped. * @return amounts The amounts of the tokens that were unwrapped. * @return liquidityUsed The amount of liquidity that was used. */ function usePositionHandler(bytes calldata _usePositionHandler) external whenNotPaused returns (address[] memory, uint256[] memory, uint256) { onlyWhitelisted(); (UsePositionParams memory _params, bytes memory hookData) = abi.decode(_usePositionHandler, (UsePositionParams, bytes)); uint256 tokenId = uint256( keccak256(abi.encode(address(this), _params.pool, _params.hook, _params.tickLower, _params.tickUpper)) ); TokenIdInfo storage tki = tokenIds[tokenId]; if (_params.hook != address(0)) { IHook(_params.hook).onPositionUse(hookData); } if ((tki.totalLiquidity - tki.liquidityUsed) < _params.liquidityToUse) { revert UniswapV3SingleTickLiquidityHandlerV2__InsufficientLiquidity(); } (uint256 amount0, uint256 amount1) = _params.pool.burn(_params.tickLower, _params.tickUpper, uint128(_params.liquidityToUse)); _params.pool.collect(msg.sender, _params.tickLower, _params.tickUpper, uint128(amount0), uint128(amount1)); _feeCalculation(tki, _params.pool, _params.tickLower, _params.tickUpper); tki.liquidityUsed += _params.liquidityToUse; address[] memory tokens = new address[](2); tokens[0] = tki.token0; tokens[1] = tki.token1; uint256[] memory amounts = new uint256[](2); amounts[0] = amount0; amounts[1] = amount1; emit LogUsePosition(tokenId, _params.liquidityToUse); return (tokens, amounts, _params.liquidityToUse); } /** * @notice Unuse a portion of an existing position. * @param _unusePositionData The data required to unuse the position. * @dev Only whitelisted DopexV2PositionManager can call it. * @return amounts The amounts of the tokens that were wrapped. * @return liquidityUnused The amount of liquidity that was unused. */ function unusePositionHandler(bytes calldata _unusePositionData) external whenNotPaused returns (uint256[] memory, uint256) { onlyWhitelisted(); (UnusePositionParams memory _params, bytes memory hookData) = abi.decode(_unusePositionData, (UnusePositionParams, bytes)); uint256 tokenId = uint256( keccak256(abi.encode(address(this), _params.pool, _params.hook, _params.tickLower, _params.tickUpper)) ); TokenIdInfo storage tki = tokenIds[tokenId]; if (_params.hook != address(0)) { IHook(_params.hook).onPositionUnUse(hookData); } (uint256 amount0, uint256 amount1) = LiquidityAmounts.getAmountsForLiquidity( _getCurrentSqrtPriceX96(_params.pool), _params.tickLower.getSqrtRatioAtTick(), _params.tickUpper.getSqrtRatioAtTick(), uint128(_params.liquidityToUnuse) ); (uint128 liquidity,,,) = addLiquidity( LiquidityManager.AddLiquidityParams({ token0: tki.token0, token1: tki.token1, fee: tki.fee, recipient: address(this), tickLower: _params.tickLower, tickUpper: _params.tickUpper, amount0Desired: amount0, amount1Desired: amount1, amount0Min: amount0, amount1Min: amount1 }) ); _feeCalculation(tki, _params.pool, _params.tickLower, _params.tickUpper); if (tki.liquidityUsed >= liquidity) { tki.liquidityUsed -= liquidity; } else { tki.totalLiquidity += (liquidity - tki.liquidityUsed); tki.liquidityUsed = 0; } uint256[] memory amounts = new uint256[](2); amounts[0] = amount0; amounts[1] = amount1; emit LogUnusePosition(tokenId, liquidity); return (amounts, uint256(liquidity)); } /** * @notice Donate liquidity to an existing position. * @param _donateData The data required to donate liquidity to the position. * @dev Only whitelisted DopexV2PositionManager can call it. * @return amounts The amounts of the tokens that were donated. * @return liquidityDonated The amount of liquidity that was donated. */ function donateToPosition(bytes calldata _donateData) external whenNotPaused returns (uint256[] memory, uint256) { onlyWhitelisted(); DonateParams memory _params = abi.decode(_donateData, (DonateParams)); uint256 tokenId = uint256( keccak256(abi.encode(address(this), _params.pool, _params.hook, _params.tickLower, _params.tickUpper)) ); TokenIdInfo storage tki = tokenIds[tokenId]; (uint256 amount0, uint256 amount1) = LiquidityAmounts.getAmountsForLiquidity( _getCurrentSqrtPriceX96(_params.pool), _params.tickLower.getSqrtRatioAtTick(), _params.tickUpper.getSqrtRatioAtTick(), uint128(_params.liquidityToDonate) ); (uint128 liquidity,,,) = addLiquidity( LiquidityManager.AddLiquidityParams({ token0: tki.token0, token1: tki.token1, fee: tki.fee, recipient: address(this), tickLower: _params.tickLower, tickUpper: _params.tickUpper, amount0Desired: amount0, amount1Desired: amount1, amount0Min: amount0, amount1Min: amount1 }) ); _feeCalculation(tki, _params.pool, _params.tickLower, _params.tickUpper); tki.totalLiquidity += liquidity; tki.donatedLiquidity = _donationLocked(tokenId) + liquidity; tki.lastDonation = uint64(block.number); if (newLockedBlockDuration != 0) { lockedBlockDuration = newLockedBlockDuration; newLockedBlockDuration = 0; } uint256[] memory amounts = new uint256[](2); amounts[0] = amount0; amounts[1] = amount1; emit LogDonation(tokenId, liquidity); return (amounts, liquidity); } /** * @notice Calculates the fees owed to the position. * @param _tki The TokenIdInfo struct for the position. * @param _pool The UniswapV3Pool contract. * @param _tickLower The lower tick of the position. * @param _tickUpper The upper tick of the position. */ function _feeCalculation(TokenIdInfo storage _tki, IUniswapV3Pool _pool, int24 _tickLower, int24 _tickUpper) internal { bytes32 positionKey = _computePositionKey(address(this), _tickLower, _tickUpper); (, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128,,) = _pool.positions(positionKey); unchecked { _tki.tokensOwed0 += uint128( FullMath.mulDiv( feeGrowthInside0LastX128 - _tki.feeGrowthInside0LastX128, _tki.totalLiquidity + _tki.reservedLiquidity - _tki.liquidityUsed, FixedPoint128.Q128 ) ); _tki.tokensOwed1 += uint128( FullMath.mulDiv( feeGrowthInside1LastX128 - _tki.feeGrowthInside1LastX128, _tki.totalLiquidity + _tki.reservedLiquidity - _tki.liquidityUsed, FixedPoint128.Q128 ) ); _tki.feeGrowthInside0LastX128 = feeGrowthInside0LastX128; _tki.feeGrowthInside1LastX128 = feeGrowthInside1LastX128; } } /** * @notice Calculates the handler identifier for a position. * @param _data The encoded position data. * @return handlerIdentifierId The handler identifier for the position. */ function getHandlerIdentifier(bytes calldata _data) external view returns (uint256 handlerIdentifierId) { (IUniswapV3Pool pool, address hook, int24 tickLower, int24 tickUpper) = abi.decode(_data, (IUniswapV3Pool, address, int24, int24)); return uint256(keccak256(abi.encode(address(this), pool, hook, tickLower, tickUpper))); } /** * @notice Calculates the amount of tokens that need to be pulled for a mint position. * @param _mintPositionData The encoded mint position data. * @return tokens The tokens that need to be pulled. * @return amounts The amount of each token that needs to be pulled. */ function tokensToPullForMint(bytes calldata _mintPositionData) external view returns (address[] memory, uint256[] memory) { return _tokensToPull(_mintPositionData); } /** * @notice Calculates the amount of tokens that need to be pulled for an unuse position. * @param _unusePositionData The encoded unuse position data. * @return tokens The tokens that need to be pulled. * @return amounts The amount of each token that needs to be pulled. */ function tokensToPullForUnUse(bytes calldata _unusePositionData) external view returns (address[] memory, uint256[] memory) { return _tokensToPull(_unusePositionData); } /** * @notice Calculates the amount of tokens that need to be pulled for a donate position. * @param _donatePosition The encoded donate position data. * @return tokens The tokens that need * */ function tokensToPullForDonate(bytes calldata _donatePosition) external view returns (address[] memory, uint256[] memory) { return _tokensToPull(_donatePosition); } function _tokensToPull(bytes calldata _positionData) private view returns (address[] memory, uint256[] memory) { MintPositionParams memory _params = abi.decode(_positionData, (MintPositionParams)); (uint256 amount0, uint256 amount1) = LiquidityAmounts.getAmountsForLiquidity( _getCurrentSqrtPriceX96(_params.pool), _params.tickLower.getSqrtRatioAtTick(), _params.tickUpper.getSqrtRatioAtTick(), uint128(_params.liquidity) ); address[] memory tokens = new address[](2); tokens[0] = _params.pool.token0(); tokens[1] = _params.pool.token1(); uint256[] memory amounts = new uint256[](2); amounts[0] = amount0; amounts[1] = amount1; return (tokens, amounts); } /** * @notice Calculates the amount of donated liquidity that is locked. * @param tokenId The tokenId of the position. * @return donationLocked The amount of donated liquidity that is locked. */ function _donationLocked(uint256 tokenId) internal view returns (uint128) { TokenIdInfo memory tki = tokenIds[tokenId]; if (block.number >= tki.lastDonation + lockedBlockDuration) return 0; uint128 donationLocked = tki.donatedLiquidity - (tki.donatedLiquidity * (uint64(block.number) - tki.lastDonation)) / lockedBlockDuration; return donationLocked; } /** * @notice Converts an amount of assets to shares. * @param assets The amount of assets. * @param tokenId The tokenId of the position. * @return shares The number of shares. */ function convertToShares(uint128 assets, uint256 tokenId) external view returns (uint128) { return _convertToShares(assets, tokenId); } /** * @notice Converts an amount of shares to assets. * @param shares The number of shares. * @param tokenId The tokenId of the position. * @return assets The amount of assets. */ function convertToAssets(uint128 shares, uint256 tokenId) external view returns (uint128) { return _convertToAssets(shares, tokenId); } /** * @notice Converts an amount of assets to shares. * @param assets The amount of assets. * @param tokenId The tokenId of the position. * @return shares The number of shares. */ function _convertToShares(uint128 assets, uint256 tokenId) internal view returns (uint128) { return uint128( assets.mulDiv( tokenIds[tokenId].totalSupply, (tokenIds[tokenId].totalLiquidity + 1) - _donationLocked(tokenId), Math.Rounding.Down ) ); } /** * @notice Converts an amount of shares to assets. * @param shares The number of shares. * @param tokenId The tokenId of the position. * @return assets The amount of assets. */ function _convertToAssets(uint128 shares, uint256 tokenId) internal view returns (uint128) { return uint128( shares.mulDiv( (tokenIds[tokenId].totalLiquidity + 1) - _donationLocked(tokenId), tokenIds[tokenId].totalSupply, Math.Rounding.Up ) ); } /** * @notice Gets the current sqrtPriceX96 of the given UniswapV3Pool. * @param pool The UniswapV3Pool to get the sqrtPriceX96 from. * @return sqrtPriceX96 The current sqrtPriceX96 of the given UniswapV3Pool. */ function _getCurrentSqrtPriceX96(IUniswapV3Pool pool) internal view returns (uint160 sqrtPriceX96) { (sqrtPriceX96,,,,,,) = pool.slot0(); } /** * @notice Computes the position key for the given owner, tickLower, and tickUpper. * @param owner The owner of the position. * @param tickLower The lower tick of the position. * @param tickUpper The upper tick of the position. * @return positionKey The position key for the given owner, tickLower, and tickUpper. */ function _computePositionKey(address owner, int24 tickLower, int24 tickUpper) internal pure returns (bytes32) { return keccak256(abi.encodePacked(owner, tickLower, tickUpper)); } function getTokenIdData(uint256 tokenId) external view returns (TokenIdInfo memory) { return tokenIds[tokenId]; } function onlyWhitelisted() private { if (!whitelistedApps[msg.sender]) { revert UniswapV3SingleTickLiquidityHandlerV2__NotWhitelisted(); } } // admin functions /** * @notice Updates the whitelist status of the given app. * @param _app The app to update the whitelist status of. * @param _status The new whitelist status of the app. */ function updateWhitelistedApps(address _app, bool _status) external onlyRole(DEFAULT_ADMIN_ROLE) { whitelistedApps[_app] = _status; emit LogUpdateWhitelistedApp(_app, _status); } /** * @notice Updates the locked block duration and reserve cooldown. * @param _newLockedBlockDuration The new lock block duration. * @param _newReserveCooldown The new reserve cooldown. */ function updateLockedBlockDurationAndReserveCooldown(uint64 _newLockedBlockDuration, uint64 _newReserveCooldown) external onlyRole(DEFAULT_ADMIN_ROLE) { newLockedBlockDuration = _newLockedBlockDuration; reserveCooldown = _newReserveCooldown; emit LogUpdatedLockBlockAndReserveCooldownDuration(_newLockedBlockDuration, _newReserveCooldown); } // SOS admin functions /** * @notice Forcefully withdraws UniswapV3 liquidity from the given position. * @param pool The UniswapV3Pool to withdraw liquidity from. * @param tickLower The lower tick of the position to withdraw liquidity from. * @param tickUpper The upper tick of the position to withdraw liquidity from. * @param liquidity The amount of liquidity to withdraw. * @param token The token to recover from this pool */ function forceWithdrawUniswapV3LiquidityAndToken( IUniswapV3Pool pool, int24 tickLower, int24 tickUpper, uint128 liquidity, address token ) external onlyRole(SOS_ROLE) { if (token != address(0)) { IERC20(token).transfer(msg.sender, IERC20(token).balanceOf(address(this))); return; } pool.burn(tickLower, tickUpper, liquidity); (,,, uint128 t0, uint128 t1) = pool.positions(_computePositionKey(address(this), tickLower, tickUpper)); pool.collect(msg.sender, tickLower, tickUpper, t0, t1); } /** * @notice Emergency pauses the contract. */ function emergencyPause() external onlyRole(PAUSER_ROLE) { _pause(); } /** * @notice Emergency unpauses the contract. */ function emergencyUnpause() external onlyRole(PAUSER_ROLE) { _unpause(); } /** * @notice Interface Support * @param interfaceId The Id of the interface */ function supportsInterface(bytes4 interfaceId) public view override(ERC6909, AccessControl) returns (bool) { return super.supportsInterface(interfaceId); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import {IUniswapV3PoolImmutables} from './pool/IUniswapV3PoolImmutables.sol'; import {IUniswapV3PoolState} from './pool/IUniswapV3PoolState.sol'; import {IUniswapV3PoolDerivedState} from './pool/IUniswapV3PoolDerivedState.sol'; import {IUniswapV3PoolActions} from './pool/IUniswapV3PoolActions.sol'; import {IUniswapV3PoolOwnerActions} from './pool/IUniswapV3PoolOwnerActions.sol'; import {IUniswapV3PoolErrors} from './pool/IUniswapV3PoolErrors.sol'; import {IUniswapV3PoolEvents} from './pool/IUniswapV3PoolEvents.sol'; /// @title The interface for a Uniswap V3 Pool /// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform /// to the ERC20 specification /// @dev The pool interface is broken up into many smaller pieces interface IUniswapV3Pool is IUniswapV3PoolImmutables, IUniswapV3PoolState, IUniswapV3PoolDerivedState, IUniswapV3PoolActions, IUniswapV3PoolOwnerActions, IUniswapV3PoolErrors, IUniswapV3PoolEvents { }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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); /** * @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 `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, 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 `from` to `to` 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 from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.8.15; pragma abicoder v2; import '@uniswap/v3-core/contracts/libraries/SafeCast.sol'; import '@uniswap/v3-core/contracts/libraries/TickMath.sol'; import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol'; import './interfaces/ISwapRouter.sol'; import './base/PeripheryImmutableState.sol'; import './base/PeripheryValidation.sol'; import './base/PeripheryPaymentsWithFee.sol'; import './base/Multicall.sol'; import './base/SelfPermit.sol'; import './libraries/Path.sol'; import './libraries/PoolAddress.sol'; import './libraries/CallbackValidation.sol'; import './interfaces/external/IWETH9.sol'; /// @title Uniswap V3 Swap Router /// @notice Router for stateless execution of swaps against Uniswap V3 contract SwapRouter is ISwapRouter, PeripheryImmutableState, PeripheryValidation, PeripheryPaymentsWithFee, Multicall, SelfPermit { using Path for bytes; using SafeCast for uint256; /// @dev Used as the placeholder value for amountInCached, because the computed amount in for an exact output swap /// can never actually be this value uint256 private constant DEFAULT_AMOUNT_IN_CACHED = type(uint256).max; /// @dev Transient storage variable used for returning the computed amount in for an exact output swap. uint256 private amountInCached = DEFAULT_AMOUNT_IN_CACHED; constructor(address _factory, address _WETH9) PeripheryImmutableState(_factory, _WETH9) {} /// @dev Returns the pool for the given token pair and fee. The pool contract may or may not exist. function getPool( address tokenA, address tokenB, uint24 fee ) private view returns (IUniswapV3Pool) { return IUniswapV3Pool(PoolAddress.computeAddress(factory, PoolAddress.getPoolKey(tokenA, tokenB, fee))); } struct SwapCallbackData { bytes path; address payer; } /// @inheritdoc IUniswapV3SwapCallback function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata _data ) external override { require(amount0Delta > 0 || amount1Delta > 0); // swaps entirely within 0-liquidity regions are not supported SwapCallbackData memory data = abi.decode(_data, (SwapCallbackData)); (address tokenIn, address tokenOut, uint24 fee) = data.path.decodeFirstPool(); CallbackValidation.verifyCallback(factory, tokenIn, tokenOut, fee); (bool isExactInput, uint256 amountToPay) = amount0Delta > 0 ? (tokenIn < tokenOut, uint256(amount0Delta)) : (tokenOut < tokenIn, uint256(amount1Delta)); if (isExactInput) { pay(tokenIn, data.payer, msg.sender, amountToPay); } else { // either initiate the next swap or pay if (data.path.hasMultiplePools()) { data.path = data.path.skipToken(); exactOutputInternal(amountToPay, msg.sender, 0, data); } else { amountInCached = amountToPay; tokenIn = tokenOut; // swap in/out because exact output swaps are reversed pay(tokenIn, data.payer, msg.sender, amountToPay); } } } /// @dev Performs a single exact input swap function exactInputInternal( uint256 amountIn, address recipient, uint160 sqrtPriceLimitX96, SwapCallbackData memory data ) private returns (uint256 amountOut) { // allow swapping to the router address with address 0 if (recipient == address(0)) recipient = address(this); (address tokenIn, address tokenOut, uint24 fee) = data.path.decodeFirstPool(); bool zeroForOne = tokenIn < tokenOut; (int256 amount0, int256 amount1) = getPool(tokenIn, tokenOut, fee).swap( recipient, zeroForOne, amountIn.toInt256(), sqrtPriceLimitX96 == 0 ? (zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1) : sqrtPriceLimitX96, abi.encode(data) ); return uint256(-(zeroForOne ? amount1 : amount0)); } /// @inheritdoc ISwapRouter function exactInputSingle(ExactInputSingleParams calldata params) external payable override checkDeadline(params.deadline) returns (uint256 amountOut) { amountOut = exactInputInternal( params.amountIn, params.recipient, params.sqrtPriceLimitX96, SwapCallbackData({path: abi.encodePacked(params.tokenIn, params.fee, params.tokenOut), payer: msg.sender}) ); require(amountOut >= params.amountOutMinimum, 'Too little received'); } /// @inheritdoc ISwapRouter function exactInput(ExactInputParams memory params) external payable override checkDeadline(params.deadline) returns (uint256 amountOut) { address payer = msg.sender; // msg.sender pays for the first hop while (true) { bool hasMultiplePools = params.path.hasMultiplePools(); // the outputs of prior swaps become the inputs to subsequent ones params.amountIn = exactInputInternal( params.amountIn, hasMultiplePools ? address(this) : params.recipient, // for intermediate swaps, this contract custodies 0, SwapCallbackData({ path: params.path.getFirstPool(), // only the first pool in the path is necessary payer: payer }) ); // decide whether to continue or terminate if (hasMultiplePools) { payer = address(this); // at this point, the caller has paid params.path = params.path.skipToken(); } else { amountOut = params.amountIn; break; } } require(amountOut >= params.amountOutMinimum, 'Too little received'); } /// @dev Performs a single exact output swap function exactOutputInternal( uint256 amountOut, address recipient, uint160 sqrtPriceLimitX96, SwapCallbackData memory data ) private returns (uint256 amountIn) { // allow swapping to the router address with address 0 if (recipient == address(0)) recipient = address(this); (address tokenOut, address tokenIn, uint24 fee) = data.path.decodeFirstPool(); bool zeroForOne = tokenIn < tokenOut; (int256 amount0Delta, int256 amount1Delta) = getPool(tokenIn, tokenOut, fee).swap( recipient, zeroForOne, -amountOut.toInt256(), sqrtPriceLimitX96 == 0 ? (zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1) : sqrtPriceLimitX96, abi.encode(data) ); uint256 amountOutReceived; (amountIn, amountOutReceived) = zeroForOne ? (uint256(amount0Delta), uint256(-amount1Delta)) : (uint256(amount1Delta), uint256(-amount0Delta)); // it's technically possible to not receive the full output amount, // so if no price limit has been specified, require this possibility away if (sqrtPriceLimitX96 == 0) require(amountOutReceived == amountOut); } /// @inheritdoc ISwapRouter function exactOutputSingle(ExactOutputSingleParams calldata params) external payable override checkDeadline(params.deadline) returns (uint256 amountIn) { // avoid an SLOAD by using the swap return data amountIn = exactOutputInternal( params.amountOut, params.recipient, params.sqrtPriceLimitX96, SwapCallbackData({path: abi.encodePacked(params.tokenOut, params.fee, params.tokenIn), payer: msg.sender}) ); require(amountIn <= params.amountInMaximum, 'Too much requested'); // has to be reset even though we don't use it in the single hop case amountInCached = DEFAULT_AMOUNT_IN_CACHED; } /// @inheritdoc ISwapRouter function exactOutput(ExactOutputParams calldata params) external payable override checkDeadline(params.deadline) returns (uint256 amountIn) { // it's okay that the payer is fixed to msg.sender here, as they're only paying for the "final" exact output // swap, which happens first, and subsequent swaps are paid for within nested callback frames exactOutputInternal( params.amountOut, params.recipient, 0, SwapCallbackData({path: params.path, payer: msg.sender}) ); amountIn = amountInCached; require(amountIn <= params.amountInMaximum, 'Too much requested'); amountInCached = DEFAULT_AMOUNT_IN_CACHED; } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; interface IHandler { function getHandlerIdentifier( bytes calldata _data ) external view returns (uint256 handlerIdentifierId); function tokensToPullForMint( bytes calldata _mintPositionData ) external view returns (address[] memory tokens, uint256[] memory amounts); function mintPositionHandler( address context, bytes calldata _mintPositionData ) external returns (uint256 sharesMinted); function burnPositionHandler( address context, bytes calldata _burnPositionData ) external returns (uint256 sharesBurned); function usePositionHandler( bytes calldata _usePositionData ) external returns ( address[] memory tokens, uint256[] memory amounts, uint256 liquidityUsed ); function tokensToPullForUnUse( bytes calldata _unusePositionData ) external view returns (address[] memory tokens, uint256[] memory amounts); function unusePositionHandler( bytes calldata _unusePositionData ) external returns (uint256[] memory amounts, uint256 liquidity); function donateToPosition( bytes calldata _donatePosition ) external returns (uint256[] memory amounts, uint256 liquidity); function tokensToPullForDonate( bytes calldata _donatePosition ) external view returns (address[] memory tokens, uint256[] memory amounts); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; interface IHook { function onPositionUse(bytes calldata _data) external; function onPositionUnUse(bytes calldata _data) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // 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(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. 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 for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the 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. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // 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 preconditions 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 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.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; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ 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)); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value)); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ 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"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value)); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to * 0 before setting it to a non-zero value. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0)); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @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"); require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } /** * @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). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // 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 cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import '@uniswap/v3-core/contracts/libraries/FullMath.sol'; import '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol'; /// @title Liquidity amount functions /// @notice Provides functions for computing liquidity amounts from token amounts and prices library LiquidityAmounts { /// @notice Downcasts uint256 to uint128 /// @param x The uint258 to be downcasted /// @return y The passed value, downcasted to uint128 function toUint128(uint256 x) private pure returns (uint128 y) { require((y = uint128(x)) == x); } /// @notice Computes the amount of liquidity received for a given amount of token0 and price range /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount0 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount0( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96); unchecked { return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96)); } } /// @notice Computes the amount of liquidity received for a given amount of token1 and price range /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)). /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount1 The amount1 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount1( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); unchecked { return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96)); } } /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount of token0 being sent in /// @param amount1 The amount of token1 being sent in /// @return liquidity The maximum amount of liquidity received function getLiquidityForAmounts( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0); } else if (sqrtRatioX96 < sqrtRatioBX96) { uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0); uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1); liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1; } else { liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1); } } /// @notice Computes the amount of token0 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 function getAmount0ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0) { unchecked { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv( uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96 - sqrtRatioAX96, sqrtRatioBX96 ) / sqrtRatioAX96; } } /// @notice Computes the amount of token1 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount1 The amount of token1 function getAmount1ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); unchecked { return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96); } } /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function getAmountsForLiquidity( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0, uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } else if (sqrtRatioX96 < sqrtRatioBX96) { amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity); amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity); } else { amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.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 { error T(); error R(); /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 int24 internal constant MIN_TICK = -887272; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 4295128739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342; /// @notice Calculates sqrt(1.0001^tick) * 2^96 /// @dev Throws if |tick| > max tick /// @param tick The input tick for the above formula /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) /// at the given tick function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { unchecked { uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); if (absTick > uint256(int256(MAX_TICK))) revert T(); uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000; if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128; if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128; if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128; if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128; if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128; if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128; if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128; if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128; if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128; if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128; if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128; if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128; if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128; if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128; if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128; if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128; if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128; if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128; if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128; if (tick > 0) ratio = type(uint256).max / ratio; // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96. // we then downcast because we know the result always fits within 160 bits due to our tick input constraint // we round up in the division so getTickAtSqrtRatio of the output price is always consistent sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1)); } } /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may /// ever return. /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) { unchecked { // second inequality must be < because the price can never reach the price at the max tick if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) revert R(); uint256 ratio = uint256(sqrtPriceX96) << 32; uint256 r = ratio; uint256 msb = 0; assembly { let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(5, gt(r, 0xFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(4, gt(r, 0xFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(3, gt(r, 0xFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(2, gt(r, 0xF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(1, gt(r, 0x3)) msb := or(msb, f) r := shr(f, r) } assembly { let f := gt(r, 0x1) msb := or(msb, f) } if (msb >= 128) r = ratio >> (msb - 127); else r = ratio << (127 - msb); int256 log_2 = (int256(msb) - 128) << 64; assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(63, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(62, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(61, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(60, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(59, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(58, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(57, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(56, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(55, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(54, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(53, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(52, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(51, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(50, f)) } int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128); int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128); tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } } }
// SPDX-License-Identifier: 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 library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2**256 + prod0 uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(a, b, not(0)) prod0 := mul(a, b) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { require(denominator > 0); assembly { result := div(prod0, denominator) } return result; } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. uint256 twos = (0 - denominator) & denominator; // Divide denominator by power of two assembly { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly { twos := add(div(sub(0, twos), twos), 1) } prod0 |= prod1 * twos; // Invert denominator mod 2**256 // Now that denominator is an odd number, it has an inverse // modulo 2**256 such that denominator * inv = 1 mod 2**256. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // inverse mod 2**256 // Because the division is now exact we can divide by multiplying // with the modular inverse of denominator. This will give us the // correct result modulo 2**256. Since the precoditions guarantee // that the outcome is less than 2**256, this is the final result. // We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inv; return result; } } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max); result++; } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title FixedPoint128 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) library FixedPoint128 { uint256 internal constant Q128 = 0x100000000000000000000000000000000; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; import "../utils/Context.sol"; import "../utils/Strings.sol"; import "../utils/introspection/ERC165.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ```solidity * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ```solidity * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules} * to enforce additional security measures for this role. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(account), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract Pausable is Context { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ constructor() { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0 <0.9.0; /// @notice Minimalist and gas efficient standard ERC6909 implementation. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC6909.sol) /// @dev Copied from the commit at 4b47a19038b798b4a33d9749d25e570443520647 /// @dev This contract has been modified from the implementation at the above link. abstract contract ERC6909 { /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event OperatorSet( address indexed owner, address indexed operator, bool approved ); event Approval( address indexed owner, address indexed spender, uint256 indexed id, uint256 amount ); event Transfer( address caller, address indexed from, address indexed to, uint256 indexed id, uint256 amount ); /*////////////////////////////////////////////////////////////// ERC6909 STORAGE //////////////////////////////////////////////////////////////*/ mapping(address => mapping(address => bool)) public isOperator; mapping(address => mapping(uint256 => uint256)) public balanceOf; mapping(address => mapping(address => mapping(uint256 => uint256))) public allowance; /*////////////////////////////////////////////////////////////// ERC6909 LOGIC //////////////////////////////////////////////////////////////*/ function transfer( address receiver, uint256 id, uint256 amount ) public virtual returns (bool) { balanceOf[msg.sender][id] -= amount; balanceOf[receiver][id] += amount; emit Transfer(msg.sender, msg.sender, receiver, id, amount); return true; } function transferFrom( address sender, address receiver, uint256 id, uint256 amount ) public virtual returns (bool) { if (msg.sender != sender && !isOperator[sender][msg.sender]) { uint256 allowed = allowance[sender][msg.sender][id]; if (allowed != type(uint256).max) allowance[sender][msg.sender][id] = allowed - amount; } balanceOf[sender][id] -= amount; balanceOf[receiver][id] += amount; emit Transfer(msg.sender, sender, receiver, id, amount); return true; } function approve( address spender, uint256 id, uint256 amount ) public virtual returns (bool) { allowance[msg.sender][spender][id] = amount; emit Approval(msg.sender, spender, id, amount); return true; } function setOperator( address operator, bool approved ) public virtual returns (bool) { isOperator[msg.sender][operator] = approved; emit OperatorSet(msg.sender, operator, approved); return true; } /*////////////////////////////////////////////////////////////// ERC165 LOGIC //////////////////////////////////////////////////////////////*/ function supportsInterface( bytes4 interfaceId ) public view virtual returns (bool) { return interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165 interfaceId == 0x0f632fb3; // ERC165 Interface ID for ERC6909 } /*////////////////////////////////////////////////////////////// INTERNAL MINT/BURN LOGIC //////////////////////////////////////////////////////////////*/ function _mint( address receiver, uint256 id, uint256 amount ) internal virtual { balanceOf[receiver][id] += amount; emit Transfer(msg.sender, address(0), receiver, id, amount); } function _burn( address sender, uint256 id, uint256 amount ) internal virtual { balanceOf[sender][id] -= amount; emit Transfer(msg.sender, sender, address(0), id, amount); } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13; // Interfaces import {IUniswapV3Factory} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol"; import {IUniswapV3MintCallback} from "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol"; import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol"; // Libraries import {SafeERC20} from "openzeppelin/token/ERC20/utils/SafeERC20.sol"; import {LiquidityAmounts} from "v3-periphery/libraries/LiquidityAmounts.sol"; import {TickMath} from "@uniswap/v3-core/contracts/libraries/TickMath.sol"; /// @title Liquidity management functions /// @notice Internal functions for safely managing liquidity in Uniswap V3 abstract contract LiquidityManager is IUniswapV3MintCallback { address public immutable factory; bytes32 public immutable POOL_INIT_CODE_HASH; struct PoolKey { address token0; address token1; uint24 fee; } constructor(address _factory, bytes32 _pool_init_code_hash) { factory = _factory; POOL_INIT_CODE_HASH = _pool_init_code_hash; } struct MintCallbackData { PoolKey poolKey; address payer; } /// @inheritdoc IUniswapV3MintCallback function uniswapV3MintCallback(uint256 amount0Owed, uint256 amount1Owed, bytes calldata data) external override { MintCallbackData memory decoded = abi.decode(data, (MintCallbackData)); verifyCallback(factory, decoded.poolKey); if (amount0Owed > 0) { pay(decoded.poolKey.token0, decoded.payer, msg.sender, amount0Owed); } if (amount1Owed > 0) { pay(decoded.poolKey.token1, decoded.payer, msg.sender, amount1Owed); } } struct AddLiquidityParams { address token0; address token1; uint24 fee; address recipient; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; } /// @notice Add liquidity to an initialized pool function addLiquidity(AddLiquidityParams memory params) public returns (uint128 liquidity, uint256 amount0, uint256 amount1, IUniswapV3Pool pool) { PoolKey memory poolKey = PoolKey({token0: params.token0, token1: params.token1, fee: params.fee}); pool = IUniswapV3Pool(computeAddress(factory, poolKey)); // compute the liquidity amount { (uint160 sqrtPriceX96,,,,,,) = pool.slot0(); uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(params.tickLower); uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(params.tickUpper); liquidity = LiquidityAmounts.getLiquidityForAmounts( sqrtPriceX96, sqrtRatioAX96, sqrtRatioBX96, params.amount0Desired, params.amount1Desired ); } (amount0, amount1) = pool.mint( params.recipient, params.tickLower, params.tickUpper, liquidity, abi.encode(MintCallbackData({poolKey: poolKey, payer: msg.sender})) ); } /// @param token The token to pay /// @param payer The entity that must pay /// @param recipient The entity that will receive payment /// @param value The amount to pay function pay(address token, address payer, address recipient, uint256 value) internal { // pull payment if (payer == address(this)) { SafeERC20.safeTransfer(IERC20(token), recipient, value); } else { SafeERC20.safeTransferFrom(IERC20(token), payer, recipient, value); } } function getPoolKey(address tokenA, address tokenB, uint24 fee) internal pure returns (PoolKey memory) { if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); return PoolKey({token0: tokenA, token1: tokenB, fee: fee}); } function computeAddress(address _factory, PoolKey memory key) internal view returns (address pool) { require(key.token0 < key.token1); pool = address( uint160( uint256( keccak256( abi.encodePacked( hex"ff", _factory, keccak256(abi.encode(key.token0, key.token1, key.fee)), POOL_INIT_CODE_HASH ) ) ) ) ); } function verifyCallback(address _factory, address tokenA, address tokenB, uint24 fee) internal view returns (IUniswapV3Pool pool) { return verifyCallback(_factory, getPoolKey(tokenA, tokenB, fee)); } function verifyCallback(address _factory, PoolKey memory poolKey) internal view returns (IUniswapV3Pool pool) { pool = IUniswapV3Pool(computeAddress(_factory, poolKey)); require(msg.sender == address(pool)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that never changes /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values interface IUniswapV3PoolImmutables { /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface /// @return The contract address function factory() external view returns (address); /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (address); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (address); /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 /// @return The fee function fee() external view returns (uint24); /// @notice The pool tick spacing /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... /// This value is an int24 to avoid casting even though it is always positive. /// @return The tick spacing function tickSpacing() external view returns (int24); /// @notice The maximum amount of position liquidity that can use any tick in the range /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool /// @return The max amount of liquidity per tick function maxLiquidityPerTick() external view returns (uint128); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that can change /// @notice These methods compose the pool's state, and can change with any frequency including multiple times /// per transaction interface IUniswapV3PoolState { /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas /// when accessed externally. /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value /// @return tick The current tick of the pool, i.e. according to the last tick transition that was run. /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick /// boundary. /// @return observationIndex The index of the last oracle observation that was written, /// @return observationCardinality The current maximum number of observations stored in the pool, /// @return observationCardinalityNext The next maximum number of observations, to be updated when the observation. /// @return feeProtocol The protocol fee for both tokens of the pool. /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. /// unlocked Whether the pool is currently locked to reentrancy function slot0() external view returns ( uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked ); /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal0X128() external view returns (uint256); /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal1X128() external view returns (uint256); /// @notice The amounts of token0 and token1 that are owed to the protocol /// @dev Protocol fees will never exceed uint128 max in either token function protocolFees() external view returns (uint128 token0, uint128 token1); /// @notice The currently in range liquidity available to the pool /// @dev This value has no relationship to the total liquidity across all ticks /// @return The liquidity at the current price of the pool function liquidity() external view returns (uint128); /// @notice Look up information about a specific tick in the pool /// @param tick The tick to look up /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or /// tick upper /// @return liquidityNet how much liquidity changes when the pool price crosses the tick, /// @return feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0, /// @return feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1, /// @return tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick /// @return secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick, /// @return secondsOutside the seconds spent on the other side of the tick from the current tick, /// @return initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false. /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0. /// In addition, these values are only relative and must be used only in comparison to previous snapshots for /// a specific position. function ticks(int24 tick) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized ); /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information function tickBitmap(int16 wordPosition) external view returns (uint256); /// @notice Returns the information about a position by the position's key /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper /// @return liquidity The amount of liquidity in the position, /// @return feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke, /// @return feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke, /// @return tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke, /// @return tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke function positions(bytes32 key) external view returns ( uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); /// @notice Returns data about a specific observation index /// @param index The element of the observations array to fetch /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time /// ago, rather than at a specific index in the array. /// @return blockTimestamp The timestamp of the observation, /// @return tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp, /// @return secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp, /// @return initialized whether the observation has been initialized and the values are safe to use function observations(uint256 index) external view returns ( uint32 blockTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, bool initialized ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that is not stored /// @notice Contains view functions to provide information about the pool that is computed rather than stored on the /// blockchain. The functions here may have variable gas costs. interface IUniswapV3PoolDerivedState { /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, /// you must call it with secondsAgos = [3600, 0]. /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio. /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block /// timestamp function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed. /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first /// snapshot is taken and the second snapshot is taken. /// @param tickLower The lower tick of the range /// @param tickUpper The upper tick of the range /// @return tickCumulativeInside The snapshot of the tick accumulator for the range /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range /// @return secondsInside The snapshot of seconds per liquidity for the range function snapshotCumulativesInside(int24 tickLower, int24 tickUpper) external view returns ( int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissionless pool actions /// @notice Contains pool methods that can be called by anyone interface IUniswapV3PoolActions { /// @notice Sets the initial price for the pool /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 function initialize(uint160 sqrtPriceX96) external; /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends /// on tickLower, tickUpper, the amount of liquidity, and the current price. /// @param recipient The address for which the liquidity will be created /// @param tickLower The lower tick of the position in which to add liquidity /// @param tickUpper The upper tick of the position in which to add liquidity /// @param amount The amount of liquidity to mint /// @param data Any data that should be passed through to the callback /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data ) external returns (uint256 amount0, uint256 amount1); /// @notice Collects tokens owed to a position /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity. /// @param recipient The address which should receive the fees collected /// @param tickLower The lower tick of the position for which to collect fees /// @param tickUpper The upper tick of the position for which to collect fees /// @param amount0Requested How much token0 should be withdrawn from the fees owed /// @param amount1Requested How much token1 should be withdrawn from the fees owed /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0 /// @dev Fees must be collected separately via a call to #collect /// @param tickLower The lower tick of the position for which to burn liquidity /// @param tickUpper The upper tick of the position for which to burn liquidity /// @param amount How much liquidity to burn /// @return amount0 The amount of token0 sent to the recipient /// @return amount1 The amount of token1 sent to the recipient function burn( int24 tickLower, int24 tickUpper, uint128 amount ) external returns (uint256 amount0, uint256 amount1); /// @notice Swap token0 for token1, or token1 for token0 /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback /// @param recipient The address to receive the output of the swap /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this /// value after the swap. If one for zero, the price cannot be greater than this value after the swap /// @param data Any data to be passed through to the callback /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling /// with 0 amount{0,1} and sending the donation amount(s) from the callback /// @param recipient The address which will receive the token0 and token1 amounts /// @param amount0 The amount of token0 to send /// @param amount1 The amount of token1 to send /// @param data Any data to be passed through to the callback function flash( address recipient, uint256 amount0, uint256 amount1, bytes calldata data ) external; /// @notice Increase the maximum number of price and liquidity observations that this pool will store /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to /// the input observationCardinalityNext. /// @param observationCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissioned pool actions /// @notice Contains pool methods that may only be called by the factory owner interface IUniswapV3PoolOwnerActions { /// @notice Set the denominator of the protocol's % share of the fees /// @param feeProtocol0 new protocol fee for token0 of the pool /// @param feeProtocol1 new protocol fee for token1 of the pool function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external; /// @notice Collect the protocol fee accrued to the pool /// @param recipient The address to which collected protocol fees should be sent /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 /// @return amount0 The protocol fee collected in token0 /// @return amount1 The protocol fee collected in token1 function collectProtocol( address recipient, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Errors emitted by a pool /// @notice Contains all events emitted by the pool interface IUniswapV3PoolErrors { error LOK(); error TLU(); error TLM(); error TUM(); error AI(); error M0(); error M1(); error AS(); error IIA(); error L(); error F0(); error F1(); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Events emitted by a pool /// @notice Contains all events emitted by the pool interface IUniswapV3PoolEvents { /// @notice Emitted exactly once by a pool when #initialize is first called on the pool /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96 /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool event Initialize(uint160 sqrtPriceX96, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @param sender The address that minted the liquidity /// @param owner The owner of the position and recipient of any minted liquidity /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity minted to the position range /// @param amount0 How much token0 was required for the minted liquidity /// @param amount1 How much token1 was required for the minted liquidity event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees are collected by the owner of a position /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees /// @param owner The owner of the position for which fees are collected /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount0 The amount of token0 fees collected /// @param amount1 The amount of token1 fees collected event Collect( address indexed owner, address recipient, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount0, uint128 amount1 ); /// @notice Emitted when a position's liquidity is removed /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect /// @param owner The owner of the position for which liquidity is removed /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity to remove /// @param amount0 The amount of token0 withdrawn /// @param amount1 The amount of token1 withdrawn event Burn( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted by the pool for any swaps between token0 and token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the output of the swap /// @param amount0 The delta of the token0 balance of the pool /// @param amount1 The delta of the token1 balance of the pool /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of price of the pool after the swap event Swap( address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick ); /// @notice Emitted by the pool for any flashes of token0/token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the tokens from flash /// @param amount0 The amount of token0 that was flashed /// @param amount1 The amount of token1 that was flashed /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee event Flash( address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1 ); /// @notice Emitted by the pool for increases to the number of observations that can be stored /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index /// just before a mint/swap/burn. /// @param observationCardinalityNextOld The previous value of the next observation cardinality /// @param observationCardinalityNextNew The updated value of the next observation cardinality event IncreaseObservationCardinalityNext( uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); /// @notice Emitted when the protocol fee is changed by the pool /// @param feeProtocol0Old The previous value of the token0 protocol fee /// @param feeProtocol1Old The previous value of the token1 protocol fee /// @param feeProtocol0New The updated value of the token0 protocol fee /// @param feeProtocol1New The updated value of the token1 protocol fee event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New); /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner /// @param sender The address that collects the protocol fees /// @param recipient The address that receives the collected protocol fees /// @param amount0 The amount of token0 protocol fees that is withdrawn /// @param amount0 The amount of token1 protocol fees that is withdrawn event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Safe casting methods /// @notice Contains methods for safely casting between types library SafeCast { /// @notice Cast a uint256 to a uint160, revert on overflow /// @param y The uint256 to be downcasted /// @return z The downcasted integer, now type uint160 function toUint160(uint256 y) internal pure returns (uint160 z) { require((z = uint160(y)) == y); } /// @notice Cast a int256 to a int128, revert on overflow or underflow /// @param y The int256 to be downcasted /// @return z The downcasted integer, now type int128 function toInt128(int256 y) internal pure returns (int128 z) { require((z = int128(y)) == y); } /// @notice Cast a uint256 to a int256, revert on overflow /// @param y The uint256 to be casted /// @return z The casted integer, now type int256 function toInt256(uint256 y) internal pure returns (int256 z) { require(y < 2**255); z = int256(y); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol'; /// @title Router token swapping functionality /// @notice Functions for swapping tokens via Uniswap V3 interface ISwapRouter is IUniswapV3SwapCallback { struct ExactInputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; uint160 sqrtPriceLimitX96; } /// @notice Swaps `amountIn` of one token for as much as possible of another token /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata /// @return amountOut The amount of the received token function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut); struct ExactInputParams { bytes path; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; } /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata /// @return amountOut The amount of the received token function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut); struct ExactOutputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; uint160 sqrtPriceLimitX96; } /// @notice Swaps as little as possible of one token for `amountOut` of another token /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata /// @return amountIn The amount of the input token function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn); struct ExactOutputParams { bytes path; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; } /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed) /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata /// @return amountIn The amount of the input token function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.8.15; import '../interfaces/IPeripheryImmutableState.sol'; /// @title Immutable state /// @notice Immutable state used by periphery contracts abstract contract PeripheryImmutableState is IPeripheryImmutableState { /// @inheritdoc IPeripheryImmutableState address public immutable override factory; /// @inheritdoc IPeripheryImmutableState address public immutable override WETH9; constructor(address _factory, address _WETH9) { factory = _factory; WETH9 = _WETH9; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.8.15; import './BlockTimestamp.sol'; abstract contract PeripheryValidation is BlockTimestamp { modifier checkDeadline(uint256 deadline) { require(_blockTimestamp() <= deadline, 'Transaction too old'); _; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import './PeripheryPayments.sol'; import '../interfaces/IPeripheryPaymentsWithFee.sol'; import '../interfaces/external/IWETH9.sol'; import '../libraries/TransferHelper.sol'; abstract contract PeripheryPaymentsWithFee is PeripheryPayments, IPeripheryPaymentsWithFee { /// @inheritdoc IPeripheryPaymentsWithFee function unwrapWETH9WithFee( uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient ) public payable override { require(feeBips > 0 && feeBips <= 100); uint256 balanceWETH9 = IWETH9(WETH9).balanceOf(address(this)); require(balanceWETH9 >= amountMinimum, 'Insufficient WETH9'); if (balanceWETH9 > 0) { IWETH9(WETH9).withdraw(balanceWETH9); uint256 feeAmount = (balanceWETH9 * feeBips) / 10_000; if (feeAmount > 0) TransferHelper.safeTransferETH(feeRecipient, feeAmount); TransferHelper.safeTransferETH(recipient, balanceWETH9 - feeAmount); } } /// @inheritdoc IPeripheryPaymentsWithFee function sweepTokenWithFee( address token, uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient ) public payable override { require(feeBips > 0 && feeBips <= 100); uint256 balanceToken = IERC20(token).balanceOf(address(this)); require(balanceToken >= amountMinimum, 'Insufficient token'); if (balanceToken > 0) { uint256 feeAmount = (balanceToken * feeBips) / 10_000; if (feeAmount > 0) TransferHelper.safeTransfer(token, feeRecipient, feeAmount); TransferHelper.safeTransfer(token, recipient, balanceToken - feeAmount); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.8.15; pragma abicoder v2; import '../interfaces/IMulticall.sol'; /// @title Multicall /// @notice Enables calling multiple methods in a single call to the contract abstract contract Multicall is IMulticall { /// @inheritdoc IMulticall function multicall(bytes[] calldata data) public payable override returns (bytes[] memory results) { results = new bytes[](data.length); for (uint256 i = 0; i < data.length; i++) { (bool success, bytes memory result) = address(this).delegatecall(data[i]); if (!success) { // Next 5 lines from https://ethereum.stackexchange.com/a/83577 if (result.length < 68) revert(); assembly { result := add(result, 0x04) } revert(abi.decode(result, (string))); } results[i] = result; } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol'; import '../interfaces/ISelfPermit.sol'; import '../interfaces/external/IERC20PermitAllowed.sol'; /// @title Self Permit /// @notice Functionality to call permit on any EIP-2612-compliant token for use in the route /// @dev These functions are expected to be embedded in multicalls to allow EOAs to approve a contract and call a function /// that requires an approval in a single transaction. abstract contract SelfPermit is ISelfPermit { /// @inheritdoc ISelfPermit function selfPermit( address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public payable override { IERC20Permit(token).permit(msg.sender, address(this), value, deadline, v, r, s); } /// @inheritdoc ISelfPermit function selfPermitIfNecessary( address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external payable override { if (IERC20(token).allowance(msg.sender, address(this)) < value) selfPermit(token, value, deadline, v, r, s); } /// @inheritdoc ISelfPermit function selfPermitAllowed( address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s ) public payable override { IERC20PermitAllowed(token).permit(msg.sender, address(this), nonce, expiry, true, v, r, s); } /// @inheritdoc ISelfPermit function selfPermitAllowedIfNecessary( address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s ) external payable override { if (IERC20(token).allowance(msg.sender, address(this)) < type(uint256).max) selfPermitAllowed(token, nonce, expiry, v, r, s); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.6.0; import './BytesLib.sol'; /// @title Functions for manipulating path data for multihop swaps library Path { using BytesLib for bytes; /// @dev The length of the bytes encoded address uint256 private constant ADDR_SIZE = 20; /// @dev The length of the bytes encoded fee uint256 private constant FEE_SIZE = 3; /// @dev The offset of a single token address and pool fee uint256 private constant NEXT_OFFSET = ADDR_SIZE + FEE_SIZE; /// @dev The offset of an encoded pool key uint256 private constant POP_OFFSET = NEXT_OFFSET + ADDR_SIZE; /// @dev The minimum length of an encoding that contains 2 or more pools uint256 private constant MULTIPLE_POOLS_MIN_LENGTH = POP_OFFSET + NEXT_OFFSET; /// @notice Returns true iff the path contains two or more pools /// @param path The encoded swap path /// @return True if path contains two or more pools, otherwise false function hasMultiplePools(bytes memory path) internal pure returns (bool) { return path.length >= MULTIPLE_POOLS_MIN_LENGTH; } /// @notice Returns the number of pools in the path /// @param path The encoded swap path /// @return The number of pools in the path function numPools(bytes memory path) internal pure returns (uint256) { // Ignore the first token address. From then on every fee and token offset indicates a pool. return ((path.length - ADDR_SIZE) / NEXT_OFFSET); } /// @notice Decodes the first pool in path /// @param path The bytes encoded swap path /// @return tokenA The first token of the given pool /// @return tokenB The second token of the given pool /// @return fee The fee level of the pool function decodeFirstPool(bytes memory path) internal pure returns ( address tokenA, address tokenB, uint24 fee ) { tokenA = path.toAddress(0); fee = path.toUint24(ADDR_SIZE); tokenB = path.toAddress(NEXT_OFFSET); } /// @notice Gets the segment corresponding to the first pool in the path /// @param path The bytes encoded swap path /// @return The segment containing all data necessary to target the first pool in the path function getFirstPool(bytes memory path) internal pure returns (bytes memory) { return path.slice(0, POP_OFFSET); } /// @notice Skips a token + fee element from the buffer and returns the remainder /// @param path The swap path /// @return The remaining token + fee elements in the path function skipToken(bytes memory path) internal pure returns (bytes memory) { return path.slice(NEXT_OFFSET, path.length - NEXT_OFFSET); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Provides functions for deriving a pool address from the factory, tokens, and the fee library PoolAddress { bytes32 internal constant POOL_INIT_CODE_HASH = 0xa598dd2fba360510c5a8f02f44423a4468e902df5857dbce3ca162a43a3a31ff; /// @notice The identifying key of the pool struct PoolKey { address token0; address token1; uint24 fee; } /// @notice Returns PoolKey: the ordered tokens with the matched fee levels /// @param tokenA The first token of a pool, unsorted /// @param tokenB The second token of a pool, unsorted /// @param fee The fee level of the pool /// @return Poolkey The pool details with ordered token0 and token1 assignments function getPoolKey( address tokenA, address tokenB, uint24 fee ) internal pure returns (PoolKey memory) { if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); return PoolKey({token0: tokenA, token1: tokenB, fee: fee}); } /// @notice Deterministically computes the pool address given the factory and PoolKey /// @param factory The Uniswap V3 factory contract address /// @param key The PoolKey /// @return pool The contract address of the V3 pool function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { require(key.token0 < key.token1); pool = address( uint160( uint256( keccak256( abi.encodePacked( hex'ff', factory, keccak256(abi.encode(key.token0, key.token1, key.fee)), POOL_INIT_CODE_HASH ) ) ) ) ); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; import '@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol'; import './PoolAddress.sol'; /// @notice Provides validation for callbacks from Uniswap V3 Pools library CallbackValidation { /// @notice Returns the address of a valid Uniswap V3 Pool /// @param factory The contract address of the Uniswap V3 factory /// @param tokenA The contract address of either token0 or token1 /// @param tokenB The contract address of the other token /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip /// @return pool The V3 pool contract address function verifyCallback( address factory, address tokenA, address tokenB, uint24 fee ) internal view returns (IUniswapV3Pool pool) { return verifyCallback(factory, PoolAddress.getPoolKey(tokenA, tokenB, fee)); } /// @notice Returns the address of a valid Uniswap V3 Pool /// @param factory The contract address of the Uniswap V3 factory /// @param poolKey The identifying key of the V3 pool /// @return pool The V3 pool contract address function verifyCallback(address factory, PoolAddress.PoolKey memory poolKey) internal view returns (IUniswapV3Pool pool) { pool = IUniswapV3Pool(PoolAddress.computeAddress(factory, poolKey)); require(msg.sender == address(pool)); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.8.15; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; /// @title Interface for WETH9 interface IWETH9 is IERC20 { /// @notice Deposit ether to get wrapped ether function deposit() external payable; /// @notice Withdraw wrapped ether to get ether function withdraw(uint256) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @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 * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 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://consensys.net/diligence/blog/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.8.0/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 functionCallWithValue(target, data, 0, "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"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or 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 { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // 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 /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title FixedPoint96 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) /// @dev Used in SqrtPriceMath.sol library FixedPoint96 { uint8 internal constant RESOLUTION = 96; uint256 internal constant Q96 = 0x1000000000000000000000000; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) 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 // OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/Math.sol"; import "./math/SignedMath.sol"; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value)))); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal(string memory a, string memory b) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title The interface for the Uniswap V3 Factory /// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees interface IUniswapV3Factory { /// @notice Emitted when the owner of the factory is changed /// @param oldOwner The owner before the owner was changed /// @param newOwner The owner after the owner was changed event OwnerChanged(address indexed oldOwner, address indexed newOwner); /// @notice Emitted when a pool is created /// @param token0 The first token of the pool by address sort order /// @param token1 The second token of the pool by address sort order /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip /// @param tickSpacing The minimum number of ticks between initialized ticks /// @param pool The address of the created pool event PoolCreated( address indexed token0, address indexed token1, uint24 indexed fee, int24 tickSpacing, address pool ); /// @notice Emitted when a new fee amount is enabled for pool creation via the factory /// @param fee The enabled fee, denominated in hundredths of a bip /// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing); /// @notice Returns the current owner of the factory /// @dev Can be changed by the current owner via setOwner /// @return The address of the factory owner function owner() external view returns (address); /// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled /// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context /// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee /// @return The tick spacing function feeAmountTickSpacing(uint24 fee) external view returns (int24); /// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order /// @param tokenA The contract address of either token0 or token1 /// @param tokenB The contract address of the other token /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip /// @return pool The pool address function getPool( address tokenA, address tokenB, uint24 fee ) external view returns (address pool); /// @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 fee The desired fee for the pool /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved /// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments /// are invalid. /// @return pool The address of the newly created pool function createPool( address tokenA, address tokenB, uint24 fee ) external returns (address pool); /// @notice Updates the owner of the factory /// @dev Must be called by the current owner /// @param _owner The new owner of the factory function setOwner(address _owner) external; /// @notice Enables a fee amount with the given tickSpacing /// @dev Fee amounts may never be removed once enabled /// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6) /// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount function enableFeeAmount(uint24 fee, int24 tickSpacing) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Callback for IUniswapV3PoolActions#mint /// @notice Any contract that calls IUniswapV3PoolActions#mint must implement this interface interface IUniswapV3MintCallback { /// @notice Called to `msg.sender` after minting liquidity to a position from IUniswapV3Pool#mint. /// @dev In the implementation you must pay the pool tokens owed for the minted liquidity. /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory. /// @param amount0Owed The amount of token0 due to the pool for the minted liquidity /// @param amount1Owed The amount of token1 due to the pool for the minted liquidity /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#mint call function uniswapV3MintCallback( uint256 amount0Owed, uint256 amount1Owed, bytes calldata data ) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Callback for IUniswapV3PoolActions#swap /// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface interface IUniswapV3SwapCallback { /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap. /// @dev In the implementation you must pay the pool tokens owed for the swap. /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory. /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped. /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token0 to the pool. /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token1 to the pool. /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata data ) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Immutable state /// @notice Functions that return immutable state of the router interface IPeripheryImmutableState { /// @return Returns the address of the Uniswap V3 factory function factory() external view returns (address); /// @return Returns the address of WETH9 function WETH9() external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity =0.8.15; /// @title Function for getting block timestamp /// @dev Base contract that is overridden for tests abstract contract BlockTimestamp { /// @dev Method that exists purely to be overridden for tests /// @return The current block timestamp function _blockTimestamp() internal view virtual returns (uint256) { return block.timestamp; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '../interfaces/IPeripheryPayments.sol'; import '../interfaces/external/IWETH9.sol'; import '../libraries/TransferHelper.sol'; import './PeripheryImmutableState.sol'; abstract contract PeripheryPayments is IPeripheryPayments, PeripheryImmutableState { receive() external payable { require(msg.sender == WETH9, 'Not WETH9'); } /// @inheritdoc IPeripheryPayments function unwrapWETH9(uint256 amountMinimum, address recipient) public payable override { uint256 balanceWETH9 = IWETH9(WETH9).balanceOf(address(this)); require(balanceWETH9 >= amountMinimum, 'Insufficient WETH9'); if (balanceWETH9 > 0) { IWETH9(WETH9).withdraw(balanceWETH9); TransferHelper.safeTransferETH(recipient, balanceWETH9); } } /// @inheritdoc IPeripheryPayments function sweepToken( address token, uint256 amountMinimum, address recipient ) public payable override { uint256 balanceToken = IERC20(token).balanceOf(address(this)); require(balanceToken >= amountMinimum, 'Insufficient token'); if (balanceToken > 0) { TransferHelper.safeTransfer(token, recipient, balanceToken); } } /// @inheritdoc IPeripheryPayments function refundETH() external payable override { if (address(this).balance > 0) TransferHelper.safeTransferETH(msg.sender, address(this).balance); } /// @param token The token to pay /// @param payer The entity that must pay /// @param recipient The entity that will receive payment /// @param value The amount to pay function pay( address token, address payer, address recipient, uint256 value ) internal { if (token == WETH9 && address(this).balance >= value) { // pay with WETH9 IWETH9(WETH9).deposit{value: value}(); // wrap only what is needed to pay IWETH9(WETH9).transfer(recipient, value); } else if (payer == address(this)) { // pay with tokens already in the contract (for the exact input multihop case) TransferHelper.safeTransfer(token, recipient, value); } else { // pull payment TransferHelper.safeTransferFrom(token, payer, recipient, value); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; import './IPeripheryPayments.sol'; /// @title Periphery Payments /// @notice Functions to ease deposits and withdrawals of ETH interface IPeripheryPaymentsWithFee is IPeripheryPayments { /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH, with a percentage between /// 0 (exclusive), and 1 (inclusive) going to feeRecipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users. function unwrapWETH9WithFee( uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient ) external payable; /// @notice Transfers the full amount of a token held by this contract to recipient, with a percentage between /// 0 (exclusive) and 1 (inclusive) going to feeRecipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users function sweepTokenWithFee( address token, uint256 amountMinimum, address recipient, uint256 feeBips, address feeRecipient ) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.6.0; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; library TransferHelper { /// @notice Transfers tokens from the targeted address to the given destination /// @notice Errors with 'STF' if transfer fails /// @param token The contract address of the token to be transferred /// @param from The originating address from which the tokens will be transferred /// @param to The destination address of the transfer /// @param value The amount to be transferred function safeTransferFrom( address token, address from, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call( abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value) ); require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF'); } /// @notice Transfers tokens from msg.sender to a recipient /// @dev Errors with ST if transfer fails /// @param token The contract address of the token which will be transferred /// @param to The recipient of the transfer /// @param value The value of the transfer function safeTransfer( address token, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST'); } /// @notice Approves the stipulated contract to spend the given allowance in the given token /// @dev Errors with 'SA' if transfer fails /// @param token The contract address of the token to be approved /// @param to The target of the approval /// @param value The amount of the given token the target will be allowed to spend function safeApprove( address token, address to, uint256 value ) internal { (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA'); } /// @notice Transfers ETH to the recipient address /// @dev Fails with `STE` /// @param to The destination of the transfer /// @param value The value to be transferred function safeTransferETH(address to, uint256 value) internal { (bool success, ) = to.call{value: value}(new bytes(0)); require(success, 'STE'); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; /// @title Multicall interface /// @notice Enables calling multiple methods in a single call to the contract interface IMulticall { /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed /// @dev The `msg.value` should not be trusted for any method callable from multicall. /// @param data The encoded function data for each of the calls to make to this contract /// @return results The results from each of the calls passed in via data function multicall(bytes[] calldata data) external payable returns (bytes[] memory results); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; // EIP-2612 is Final as of 2022-11-01. This file is deprecated. import "./IERC20Permit.sol";
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; /// @title Self Permit /// @notice Functionality to call permit on any EIP-2612-compliant token for use in the route interface ISelfPermit { /// @notice Permits this contract to spend a given token from `msg.sender` /// @dev The `owner` is always msg.sender and the `spender` is always address(this). /// @param token The address of the token spent /// @param value The amount that can be spent of token /// @param deadline A timestamp, the current blocktime must be less than or equal to this timestamp /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s` /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s` /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v` function selfPermit( address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external payable; /// @notice Permits this contract to spend a given token from `msg.sender` /// @dev The `owner` is always msg.sender and the `spender` is always address(this). /// Can be used instead of #selfPermit to prevent calls from failing due to a frontrun of a call to #selfPermit /// @param token The address of the token spent /// @param value The amount that can be spent of token /// @param deadline A timestamp, the current blocktime must be less than or equal to this timestamp /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s` /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s` /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v` function selfPermitIfNecessary( address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external payable; /// @notice Permits this contract to spend the sender's tokens for permit signatures that have the `allowed` parameter /// @dev The `owner` is always msg.sender and the `spender` is always address(this) /// @param token The address of the token spent /// @param nonce The current nonce of the owner /// @param expiry The timestamp at which the permit is no longer valid /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s` /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s` /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v` function selfPermitAllowed( address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s ) external payable; /// @notice Permits this contract to spend the sender's tokens for permit signatures that have the `allowed` parameter /// @dev The `owner` is always msg.sender and the `spender` is always address(this) /// Can be used instead of #selfPermitAllowed to prevent calls from failing due to a frontrun of a call to #selfPermitAllowed. /// @param token The address of the token spent /// @param nonce The current nonce of the owner /// @param expiry The timestamp at which the permit is no longer valid /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s` /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s` /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v` function selfPermitAllowedIfNecessary( address token, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s ) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Interface for permit /// @notice Interface used by DAI/CHAI for permit interface IERC20PermitAllowed { /// @notice Approve the spender to spend some tokens via the holder signature /// @dev This is the permit interface used by DAI and CHAI /// @param holder The address of the token holder, the token owner /// @param spender The address of the token spender /// @param nonce The holder's nonce, increases at each call to permit /// @param expiry The timestamp at which the permit is no longer valid /// @param allowed Boolean that sets approval amount, true for type(uint256).max and false for 0 /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s` /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s` /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v` function permit( address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s ) external; }
// SPDX-License-Identifier: GPL-2.0-or-later /* * @title Solidity Bytes Arrays Utils * @author Gonçalo Sá <[email protected]> * * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage. */ pragma solidity >=0.8.0 <0.9.0; library BytesLib { function slice( bytes memory _bytes, uint256 _start, uint256 _length ) internal pure returns (bytes memory) { require(_length + 31 >= _length, 'slice_overflow'); require(_bytes.length >= _start + _length, 'slice_outOfBounds'); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) //zero out the 32 bytes slice we are about to return //we need to do it because Solidity does not garbage collect mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_bytes.length >= _start + 20, 'toAddress_outOfBounds'); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000) } return tempAddress; } function toUint24(bytes memory _bytes, uint256 _start) internal pure returns (uint24) { require(_start + 3 >= _start, 'toUint24_overflow'); require(_bytes.length >= _start + 3, 'toUint24_outOfBounds'); uint24 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x3), _start)) } return tempUint; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; /// @title Periphery Payments /// @notice Functions to ease deposits and withdrawals of ETH interface IPeripheryPayments { /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH. /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users. /// @param amountMinimum The minimum amount of WETH9 to unwrap /// @param recipient The address receiving ETH function unwrapWETH9(uint256 amountMinimum, address recipient) external payable; /// @notice Refunds any ETH balance held by this contract to the `msg.sender` /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps /// that use ether for the input amount function refundETH() external payable; /// @notice Transfers the full amount of a token held by this contract to recipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users /// @param token The contract address of the token which will be transferred to `recipient` /// @param amountMinimum The minimum amount of token required for a transfer /// @param recipient The destination address of the token function sweepToken( address token, uint256 amountMinimum, address recipient ) external payable; }
{ "remappings": [ "ds-test/=lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-std/=lib/forge-std/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "openzeppelin/=lib/openzeppelin-contracts/contracts/", "@openzeppelin/=lib/openzeppelin-contracts/", "v3-core/=lib/v3-core/", "v3-periphery/=lib/v3-periphery/contracts/", "@uniswap/v3-core/=lib/v3-core/", "base64-sol/=lib/openzeppelin-contracts/contracts/utils/", "BokkyPooBahsDateTimeLibrary/=lib/BokkyPooBahsDateTimeLibrary/" ], "optimizer": { "enabled": true, "runs": 0 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "viaIR": false, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"bytes32","name":"_pool_init_code_hash","type":"bytes32"},{"internalType":"address","name":"_swapRouter","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"T","type":"error"},{"inputs":[],"name":"UniswapV3SingleTickLiquidityHandlerV2__BeforeReserveCooldown","type":"error"},{"inputs":[],"name":"UniswapV3SingleTickLiquidityHandlerV2__InRangeLP","type":"error"},{"inputs":[],"name":"UniswapV3SingleTickLiquidityHandlerV2__InsufficientLiquidity","type":"error"},{"inputs":[],"name":"UniswapV3SingleTickLiquidityHandlerV2__NotWhitelisted","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityBurned","type":"uint128"},{"indexed":false,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"hook","type":"address"},{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":false,"internalType":"int24","name":"tickUpper","type":"int24"}],"name":"LogBurnedPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityDonated","type":"uint128"}],"name":"LogDonation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"handler","type":"address"},{"indexed":false,"internalType":"contract IUniswapV3Pool","name":"pool","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":false,"internalType":"int24","name":"tickUpper","type":"int24"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"}],"name":"LogFeeCompound","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityMinted","type":"uint128"},{"indexed":false,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"hook","type":"address"},{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"int24","name":"tickLower","type":"int24"},{"indexed":false,"internalType":"int24","name":"tickUpper","type":"int24"}],"name":"LogMintedPosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityReserved","type":"uint128"},{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"LogReservedLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityUnused","type":"uint128"}],"name":"LogUnusePosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_app","type":"address"},{"indexed":false,"internalType":"bool","name":"_status","type":"bool"}],"name":"LogUpdateWhitelistedApp","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"_newLockedBlockDuration","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"_newReserveCooldown","type":"uint64"}],"name":"LogUpdatedLockBlockAndReserveCooldownDuration","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityUsed","type":"uint128"}],"name":"LogUsePosition","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidityWithdrawn","type":"uint128"},{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"LogWithdrawReservedLiquidity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"OperatorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POOL_INIT_CODE_HASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint256","name":"amount0Desired","type":"uint256"},{"internalType":"uint256","name":"amount1Desired","type":"uint256"},{"internalType":"uint256","name":"amount0Min","type":"uint256"},{"internalType":"uint256","name":"amount1Min","type":"uint256"}],"internalType":"struct LiquidityManager.AddLiquidityParams","name":"params","type":"tuple"}],"name":"addLiquidity","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"contract IUniswapV3Pool","name":"pool","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"context","type":"address"},{"internalType":"bytes","name":"_burnPositionData","type":"bytes"}],"name":"burnPositionHandler","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"shares","type":"uint128"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint128","name":"assets","type":"uint128"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_donateData","type":"bytes"}],"name":"donateToPosition","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emergencyPause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"emergencyUnpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IUniswapV3Pool","name":"pool","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"address","name":"token","type":"address"}],"name":"forceWithdrawUniswapV3LiquidityAndToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"getHandlerIdentifier","outputs":[{"internalType":"uint256","name":"handlerIdentifierId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getTokenIdData","outputs":[{"components":[{"internalType":"uint128","name":"totalLiquidity","type":"uint128"},{"internalType":"uint128","name":"totalSupply","type":"uint128"},{"internalType":"uint128","name":"liquidityUsed","type":"uint128"},{"internalType":"uint256","name":"feeGrowthInside0LastX128","type":"uint256"},{"internalType":"uint256","name":"feeGrowthInside1LastX128","type":"uint256"},{"internalType":"uint128","name":"tokensOwed0","type":"uint128"},{"internalType":"uint128","name":"tokensOwed1","type":"uint128"},{"internalType":"uint64","name":"lastDonation","type":"uint64"},{"internalType":"uint128","name":"donatedLiquidity","type":"uint128"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"uint128","name":"reservedLiquidity","type":"uint128"}],"internalType":"struct SushiV3SingleTickLiquidityHandlerV2.TokenIdInfo","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lockedBlockDuration","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"context","type":"address"},{"internalType":"bytes","name":"_mintPositionData","type":"bytes"}],"name":"mintPositionHandler","outputs":[{"internalType":"uint256","name":"sharesMinted","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"newLockedBlockDuration","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"reserveCooldown","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_reserveLiquidityParam","type":"bytes"}],"name":"reserveLiquidity","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"reservedLiquidityPerUser","outputs":[{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint64","name":"lastReserve","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenIds","outputs":[{"internalType":"uint128","name":"totalLiquidity","type":"uint128"},{"internalType":"uint128","name":"totalSupply","type":"uint128"},{"internalType":"uint128","name":"liquidityUsed","type":"uint128"},{"internalType":"uint256","name":"feeGrowthInside0LastX128","type":"uint256"},{"internalType":"uint256","name":"feeGrowthInside1LastX128","type":"uint256"},{"internalType":"uint128","name":"tokensOwed0","type":"uint128"},{"internalType":"uint128","name":"tokensOwed1","type":"uint128"},{"internalType":"uint64","name":"lastDonation","type":"uint64"},{"internalType":"uint128","name":"donatedLiquidity","type":"uint128"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"uint128","name":"reservedLiquidity","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_donatePosition","type":"bytes"}],"name":"tokensToPullForDonate","outputs":[{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_mintPositionData","type":"bytes"}],"name":"tokensToPullForMint","outputs":[{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_unusePositionData","type":"bytes"}],"name":"tokensToPullForUnUse","outputs":[{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"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":"receiver","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount0Owed","type":"uint256"},{"internalType":"uint256","name":"amount1Owed","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uniswapV3MintCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_unusePositionData","type":"bytes"}],"name":"unusePositionHandler","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"_newLockedBlockDuration","type":"uint64"},{"internalType":"uint64","name":"_newReserveCooldown","type":"uint64"}],"name":"updateLockedBlockDurationAndReserveCooldown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_app","type":"address"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"updateWhitelistedApps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_usePositionHandler","type":"bytes"}],"name":"usePositionHandler","outputs":[{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelistedApps","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_reserveLiquidityParam","type":"bytes"}],"name":"withdrawReserveLiquidity","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60c0604052600880546102a360a51b600160a01b600160e01b0319909116179055600980546001600160401b03191660641790553480156200004057600080fd5b50604051620061f2380380620061f283398101604081905262000063916200017e565b6003805460ff191690556001600160a01b0383811660805260a0839052600880546001600160a01b031916918316919091179055620000a4600033620000ad565b505050620001bf565b620000b98282620000bd565b5050565b60008281526004602090815260408083206001600160a01b038516845290915290205460ff16620000b95760008281526004602090815260408083206001600160a01b03851684529091529020805460ff191660011790556200011d3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200017957600080fd5b919050565b6000806000606084860312156200019457600080fd5b6200019f8462000161565b925060208401519150620001b66040850162000161565b90509250925092565b60805160a051615ff8620001fa6000396000818161083c01526144d5015260008181610706015281816128670152612e710152615ff86000f3fe608060405234801561001057600080fd5b50600436106102035760003560e01c8062fdd58e1461020857806301ffc9a714610246578063095bcdb6146102695780630c774f4a1461027c5780631575e948146102a75780631e0250ed146102ba578063248a9ca3146102d457806328daa117146102e75780632b4d93ea146103125780632f2ff15d1461033357806336568abe14610348578063426a84931461035b57806348f449bd1461036e5780634a4e3bd5146103815780634d0b1de31461038957806351858e271461039c578063558a7297146103a4578063598af9e7146103b75780635bbc4068146103e85780635c975abb1461045557806363f558c8146104605780636b69e342146104735780636f78d29814610486578063742b5fdd146105e95780637b3fd9651461060a5780637da68a651461061d5780638cf699981461063057806391d14854146106535780639981bb9b14610666578063a217fddf146106ac578063b220e470146106b4578063b6363cf2146106d6578063b8ea4a84146105e9578063c45a015514610701578063ca83cb2214610735578063d34879971461074f578063d547741f14610762578063d58778d614610775578063dc6fd8ab14610837578063e0f19adf146105e9578063ec944b6d1461085e578063efb7dbb814610871578063f349625d14610884578063fe99049a14610897575b600080fd5b610233610216366004614df9565b600160209081526000928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b610259610254366004614e25565b6108aa565b604051901515815260200161023d565b610259610277366004614e4f565b6108bb565b60095461028f906001600160401b031681565b6040516001600160401b03909116815260200161023d565b6102336102b5366004614ec5565b61096d565b60085461028f90600160a01b90046001600160401b031681565b6102336102e2366004614f19565b610d88565b6102fa6102f5366004614f47565b610d9d565b6040516001600160801b03909116815260200161023d565b610325610320366004614f72565b610da9565b60405161023d929190614fee565b610346610341366004615010565b6110fd565b005b610346610356366004615010565b61111e565b610259610369366004614e4f565b6111a1565b61034661037c36600461505a565b611206565b610346611497565b610325610397366004614f72565b6114ba565b610346611792565b6102596103b23660046150d9565b6117b2565b6102336103c5366004615107565b600260209081526000938452604080852082529284528284209052825290205481565b61042e6103f6366004615010565b60076020908152600092835260408084209091529082529020546001600160801b03811690600160801b90046001600160401b031682565b604080516001600160801b0390931683526001600160401b0390911660208301520161023d565b60035460ff16610259565b61023361046e366004614f72565b611820565b610233610481366004614f72565b611876565b6105dc610494366004614f19565b604080516101a081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081018290526101208101829052610140810182905261016081018290526101808101919091525060009081526005602081815260409283902083516101a08101855281546001600160801b038082168352600160801b9182900481169483019490945260018301548416958201959095526002820154606082015260038201546080820152600482015480841660a083015294909404821660c0850152918201546001600160401b03811660e0850152600160401b9004811661010084015260068201546001600160a01b039081166101208501526007830154908116610140850152600160a01b900462ffffff166101608401526008909101541661018082015290565b60405161023d9190615155565b6105fc6105f7366004614f72565b611cdd565b60405161023d929190615287565b610233610618366004614ec5565b611cf5565b6102fa61062b366004614f47565b6127e3565b61025961063e3660046152ac565b60066020526000908152604090205460ff1681565b610259610661366004615010565b6127ef565b610679610674366004615324565b61281a565b604080516001600160801b0390951685526020850193909352918301526001600160a01b0316606082015260800161023d565b610233600081565b6106c76106c2366004614f72565b612a3d565b60405161023d939291906153d2565b6102596106e4366004615408565b600060208181529281526040808220909352908152205460ff1681565b6107287f000000000000000000000000000000000000000000000000000000000000000081565b60405161023d9190615436565b60095461028f90600160401b90046001600160401b031681565b61034661075d36600461544a565b612e5c565b610346610770366004615010565b612eda565b61081e610783366004614f19565b60056020819052600091825260409091208054600182015460028301546003840154600485015495850154600686015460078701546008909701546001600160801b0380881699600160801b9889900482169997821698969795968282169691048216946001600160401b03811694600160401b9091048316936001600160a01b039182169391831692600160a01b900462ffffff1691168d565b60405161023d9d9c9b9a9998979695949392919061549c565b6102337f000000000000000000000000000000000000000000000000000000000000000081565b61034661086c3660046150d9565b612ef6565b61034661087f366004614f72565b612f66565b610346610892366004615557565b613298565b6102596108a536600461558a565b613324565b60006108b58261348e565b92915050565b3360009081526001602090815260408083208584529091528120805483919083906108e79084906155e6565b90915550506001600160a01b03841660009081526001602090815260408083208684529091528120805484929061091f9084906155fd565b9250508190555082846001600160a01b0316336001600160a01b0316600080516020615f63833981519152338660405161095a929190615615565b60405180910390a45060015b9392505050565b60006109776134c3565b61097f61350b565b600061098d838501856156c9565b905060003082600001518360200151846040015185606001516040516020016109ba9594939291906156e5565b60408051601f1981840301815282825280516020918201206000818152600583528381206060860185528186529285018190529284019290925260808501519193509190610a08908461353b565b6001600160801b03908116808352600184015484549192610a2d92918116911661571b565b6001600160801b03161015610a5557604051638118326d60e01b815260040160405180910390fd5b835160408086015160608701518451925163a34123a760e01b81526001600160a01b039094169363a34123a793610a90939291600401615743565b60408051808303816000875af1158015610aae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ad29190615769565b826020018360400182815250828152505050610afc828560000151866040015187606001516135a3565b604084015160608501518251845460048601546000948594610b3994919390926001600160801b039182169181811691600160801b9004166136fd565b6004860180549294509092508391600090610b5e9084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550808460040160108282829054906101000a90046001600160801b0316610ba8919061571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555085600001516001600160a01b0316634f1eb3d88b88604001518960600151866001600160801b03168860200151610c0391906155fd565b866001600160801b03168960400151610c1c91906155fd565b6040518663ffffffff1660e01b8152600401610c3c95949392919061578d565b60408051808303816000875af1158015610c5a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c7e91906157ca565b5050825184548590600090610c9d9084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555085608001518460000160108282829054906101000a90046001600160801b0316610ceb919061571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550610d278a8688608001516001600160801b03166137f1565b600080516020615fa3833981519152858460000151886000015189602001518e8b604001518c60600151604051610d6497969594939291906157f9565b60405180910390a15050506080909201516001600160801b03169695505050505050565b60009081526004602052604090206001015490565b6000610966838361353b565b60606000610db56134c3565b610dbd61350b565b600080610dcc858701876158cf565b915091506000308360000151846020015185604001518660600151604051602001610dfb9594939291906156e5565b60408051601f19818403018152918152815160209283012060008181526005845291909120918501519092506001600160a01b031615610e985783602001516001600160a01b0316633f9dd868846040518263ffffffff1660e01b8152600401610e659190615975565b600060405180830381600087803b158015610e7f57600080fd5b505af1158015610e93573d6000803e3d6000fd5b505050505b600080610ed5610eab876000015161386d565b610ebb886040015160020b6138de565b610ecb896060015160020b6138de565b8960800151613bf6565b604080516101408101825260068701546001600160a01b03908116825260078801549081166020830152600160a01b900462ffffff168183015230606080830191909152918a0151600290810b6080830152918a015190910b60a082015260c0810183905260e08101829052610100810183905261012081018290529193509150600090610f629061281a565b5050509050610f7f84886000015189604001518a606001516135a3565b60018401546001600160801b03808316911610610fdf57600184018054829190600090610fb69084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550611048565b6001840154610ff7906001600160801b03168261571b565b845485906000906110129084906001600160801b0316615988565b82546001600160801b039182166101009390930a9283029190920219909116179055506001840180546001600160801b03191690555b604080516002808252606082018352600092602083019080368337019050509050838160008151811061107d5761107d6159b3565b602002602001018181525050828160018151811061109d5761109d6159b3565b6020026020010181815250507f64d8efec9e37db387b761d25cf5596ba293cd64d72fbcd86d7bb43b14c3bfaa886836040516110da9291906159c9565b60405180910390a198506001600160801b031696505050505050505b9250929050565b61110682610d88565b61110f81613c92565b6111198383613c9c565b505050565b6001600160a01b03811633146111935760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b61119d8282613d22565b5050565b3360008181526002602090815260408083206001600160a01b03881680855290835281842087855290925280832085905551919285927fb3fd5071835887567a0671151121894ddccc2842f1d10bedad13e0d17cace9a79061095a9087815260200190565b7f0a82b25974fd602b636b85d2a46fd7e8e40145d9a7739850ececf3c2b6eab34c61123081613c92565b6001600160a01b0382161561131c576040516370a0823160e01b81526001600160a01b0383169063a9059cbb90339083906370a0823190611275903090600401615436565b602060405180830381865afa158015611292573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112b691906159e0565b6040518363ffffffff1660e01b81526004016112d3929190615615565b6020604051808303816000875af11580156112f2573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061131691906159f9565b5061148f565b60405163a34123a760e01b81526001600160a01b0387169063a34123a79061134c90889088908890600401615743565b60408051808303816000875af115801561136a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061138e9190615769565b5050600080876001600160a01b031663514ea4bf6113ad308a8a613d89565b6040518263ffffffff1660e01b81526004016113cb91815260200190565b60a060405180830381865afa1580156113e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061140c9190615a16565b6040516309e3d67b60e31b815291965094506001600160a01b038c169350634f1eb3d89250611448915033908b908b908890889060040161578d565b60408051808303816000875af1158015611466573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148a91906157ca565b505050505b505050505050565b600080516020615f838339815191526114af81613c92565b6114b7613dd7565b50565b606060006114c66134c3565b6114ce61350b565b60006114dc848601866156c9565b905060003082600001518360200151846040015185606001516040516020016115099594939291906156e5565b60408051601f1981840301815291815281516020928301206000818152600590935290822084519193509190819061156e906115449061386d565b611554876040015160020b6138de565b611564886060015160020b6138de565b8860800151613bf6565b604080516101408101825260068701546001600160a01b03908116825260078801549081166020830152600160a01b900462ffffff16818301523060608083019190915291890151600290810b60808301529189015190910b60a082015260c0810183905260e081018290526101008101839052610120810182905291935091506000906115fb9061281a565b5050509050611618848760000151886040015189606001516135a3565b8354819085906000906116359084906001600160801b0316615988565b92506101000a8154816001600160801b0302191690836001600160801b031602179055508061166386613e23565b61166d9190615988565b6005850180546001600160c01b031916600160401b6001600160801b039390931683026001600160401b03191617436001600160401b03908116919091179091556009549190910416156116df5760098054600160401b81046001600160401b03166001600160801b03199091161790555b6040805160028082526060820183526000926020830190803683370190505090508381600081518110611714576117146159b3565b6020026020010181815250508281600181518110611734576117346159b3565b6020026020010181815250507f504089073b229a89dd5c190e4348d0ba4fcfcf103683f51f771deb19bd9fc27a86836040516117719291906159c9565b60405180910390a197506001600160801b0316955050505050509250929050565b600080516020615f838339815191526117aa81613c92565b6114b7613f7e565b336000818152602081815260408083206001600160a01b038716808552908352818420805460ff191687151590811790915591519182529293917fceb576d9f15e4e200fdb5096d64d5dfd667e16def20c1eefd14256d8e3faa267910160405180910390a350600192915050565b60008080808061183286880188615a6a565b935093509350935030848484846040516020016118539594939291906156e5565b60408051601f198184030181529190528051602090910120979650505050505050565b60006118806134c3565b600061188e838501856156c9565b905060003082600001518360200151846040015185606001516040516020016118bb9594939291906156e5565b60408051601f19818403018152918152815160209283012060008181526005909352908220608085015191935091906118f4908461353b565b905083600001516001600160a01b031663a34123a78560400151866060015160006040518463ffffffff1660e01b815260040161193393929190615743565b60408051808303816000875af1158015611951573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119759190615769565b505061198f828560000151866040015187606001516135a3565b604084015160608501518354600485015460009384936119cc939192909187916001600160801b039182169181811691600160801b9004166136fd565b60048601805492945090925083916000906119f19084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550808460040160108282829054906101000a90046001600160801b0316611a3b919061571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555085600001516001600160a01b0316634f1eb3d8338860400151896060015186866040518663ffffffff1660e01b8152600401611a9f95949392919061578d565b60408051808303816000875af1158015611abd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ae191906157ca565b505060008581526007602090815260408083203384529091528120805490918591839190611b199084906001600160801b0316615988565b82546101009290920a6001600160801b038181021990931691831602179091558254600160801b600160c01b031916600160801b426001600160401b03160217835586548692508791600091611b719185911661571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555086608001518560000160108282829054906101000a90046001600160801b0316611bbf919061571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550838560080160008282829054906101000a90046001600160801b0316611c099190615988565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550611c45338789608001516001600160801b03166137f1565b600080516020615fa3833981519152868589600001518a60200151338c604001518d60600151604051611c7e97969594939291906157f9565b60405180910390a17fbe8fbc6de0db32ef9e0a0a10395e4909f1d5c5ba6505d8c32363787038b7681b868533604051611cb993929190615ac6565b60405180910390a15050506080909301516001600160801b03169695505050505050565b606080611cea8484613fbb565b915091509250929050565b6000611cff6134c3565b611d0761350b565b6000611d15838501856156c9565b90506000308260000151836020015184604001518560600151604051602001611d429594939291906156e5565b60408051601f1981840301815291815281516020928301206000818152600590935291206006810154919250906001600160a01b0316611f1f5782600001516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611dbe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611de29190615aee565b8160060160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555082600001516001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e709190615aee565b8160070160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555082600001516001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015611eda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611efe9190615b0b565b8160070160146101000a81548162ffffff021916908362ffffff1602179055505b60006040518060e00160405280856040015160020b8152602001856060015160020b8152602001611f56866040015160020b6138de565b6001600160a01b03168152602001611f74866060015160020b6138de565b6001600160a01b0316815260200160006001600160801b031681526020016000815260200160008152509050611fc4611fb0856000015161386d565b826040015183606001518760800151613bf6565b60c083015260a0820181905215801590611fe2575060008160c00151115b1561200057604051639677149b60e01b815260040160405180910390fd5b604080516101408101825260068401546001600160a01b0390811682526007850154908116602080840191909152600160a01b90910462ffffff16928201929092523060608201528251600290810b60808301529183015190910b60a0808301919091528201805160c0808401919091528301805160e08401529051610100830152516101208201526120929061281a565b5050506001600160801b031660808201528351815160208301516120b992859290916135a3565b8154600160801b90046001600160801b0316156126d35760048201546103e86001600160801b039091161180612105575060048201546103e8600160801b9091046001600160801b0316115b1561261f5760006121208260400151836060015160026141cd565b9050600061213883604001518460600151600261423c565b60048501549091506001600160801b031682118061216957506004840154600160801b90046001600160801b031681115b1561261c5760a0830151865160408089015160608a01516004808a015493516309e3d67b60e31b81529515159560009586956001600160a01b0390911694634f1eb3d8946121d2943094929391926001600160801b0380841693600160801b900416910161578d565b60408051808303816000875af11580156121f0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221491906157ca565b600060048a018190556001600160801b039283169450911691508361223c5760008311612241565b600082115b156124275760085461229a906001600160a01b0316856122615784612263565b835b8661227b5760068b01546001600160a01b031661228a565b60078b01546001600160a01b03165b6001600160a01b0316919061427f565b6008546040805161010081019091526001600160a01b039091169063414bf3899080876122d45760068c01546001600160a01b03166122e3565b60078c01546001600160a01b03165b6001600160a01b03168152602001876123095760078c01546001600160a01b0316612318565b60068c01546001600160a01b03165b6001600160a01b0316815260078c0154600160a01b900462ffffff166020820152306040820152426060820152608001876123535786612355565b855b815260006020808301829052604092830191909152815160e085811b6001600160e01b031916825284516001600160a01b03908116600484015292850151831660248301529284015162ffffff1660448201526060840151821660648201526080840151608482015260a084015160a482015260c084015160c482015292909101511660e4820152610104016020604051808303816000875af1158015612400573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061242491906159e0565b90505b604080516101408101825260068a01546001600160a01b03908116825260078b01549081166020830152600160a01b900462ffffff1681830152306060808301829052928d0151600290810b6080840152928d015190920b60a082015260009190639981bb9b9060c081018861249e5760006124a0565b855b6124aa90896155fd565b8152602001886124ba57856124bd565b60005b6124c790886155fd565b8152602001886124d85760006124da565b855b6124e490896155fd565b8152602001886124f457856124f7565b60005b61250190886155fd565b8152506040518263ffffffff1660e01b81526004016125209190615b28565b6080604051808303816000875af115801561253f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125639190615bd5565b50508a5491925082918b91506000906125869084906001600160801b0316615988565b82546101009290920a6001600160801b038181021990931691831602179091558c518a516020808d0151604080513081526001600160a01b03909516928501929092529083018f9052600291820b6060840152900b608082015290831660a08201527fac625f3c119d91f686e26c248c9faeb771664f8da88187bf7560fe575803724b915060c00160405180910390a150505050505b50505b600061262f82608001518561435a565b608083015184549192509084906000906126539084906001600160801b0316615988565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550808360000160108282829054906101000a90046001600160801b031661269d9190615988565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550806001600160801b0316955050612776565b6080810151825483906000906126f39084906001600160801b0316615988565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555080608001518260000160108282829054906101000a90046001600160801b03166127419190615988565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555080608001516001600160801b031694505b6127818884876143c8565b7fe0fa091eaba5cace48ae5dce26123c6842423b1b0f95fe24fd3a7704582b1f84838260800151866000015187602001518c866000015187602001516040516127d097969594939291906157f9565b60405180910390a1505050509392505050565b6000610966838361435a565b60009182526004602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000806000806000604051806060016040528087600001516001600160a01b0316815260200187602001516001600160a01b03168152602001876040015162ffffff16815250905061288c7f000000000000000000000000000000000000000000000000000000000000000082614437565b91506000826001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156128ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128f29190615c28565b5050505050509050600061290988608001516138de565b9050600061291a8960a001516138de565b90506129318383838c60c001518d60e0015161451b565b9750505050816001600160a01b0316633c8a7d8d876060015188608001518960a00151896040518060400160405280888152602001336001600160a01b03168152506040516020016129be9190815180516001600160a01b03908116835260208083015182168185015260409283015162ffffff1692840192909252920151909116606082015260800190565b6040516020818303038152906040526040518663ffffffff1660e01b81526004016129ed959493929190615cc0565b60408051808303816000875af1158015612a0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a2f9190615769565b959790965091935090915050565b6060806000612a4a6134c3565b612a5261350b565b600080612a61868801886158cf565b915091506000308360000151846020015185604001518660600151604051602001612a909594939291906156e5565b60408051601f19818403018152918152815160209283012060008181526005845291909120918501519092506001600160a01b031615612b2d5783602001516001600160a01b0316637bd14bcd846040518263ffffffff1660e01b8152600401612afa9190615975565b600060405180830381600087803b158015612b1457600080fd5b505af1158015612b28573d6000803e3d6000fd5b505050505b6080840151600182015482546001600160801b0392831692612b52928116911661571b565b6001600160801b03161015612b7a57604051638118326d60e01b815260040160405180910390fd5b60008085600001516001600160a01b031663a34123a78760400151886060015189608001516040518463ffffffff1660e01b8152600401612bbd93929190615743565b60408051808303816000875af1158015612bdb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bff9190615769565b87516040808a015160608b015191516309e3d67b60e31b81529496509294506001600160a01b0390911692634f1eb3d892612c429233928890889060040161578d565b60408051808303816000875af1158015612c60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c8491906157ca565b5050612c9e838760000151886040015189606001516135a3565b6080860151600184018054600090612cc09084906001600160801b0316615988565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550600060026001600160401b03811115612cff57612cff6152c9565b604051908082528060200260200182016040528015612d28578160200160208202803683370190505b50600685015481519192506001600160a01b0316908290600090612d4e57612d4e6159b3565b6001600160a01b0392831660209182029290920101526007850154825191169082906001908110612d8157612d816159b3565b6001600160a01b039290921660209283029190910182015260408051600280825260608201835260009391929091830190803683370190505090508381600081518110612dd057612dd06159b3565b6020026020010181815250508281600181518110612df057612df06159b3565b6020026020010181815250507f7fc7ce728583421fb192c9bac9c143fabf47263826e2fb21203a8f7038c093d4868960800151604051612e319291906159c9565b60405180910390a160809790970151909c969b506001600160801b0316995094975050505050505050565b6000612e6a82840184615d05565b9050612e9a7f000000000000000000000000000000000000000000000000000000000000000082600001516145df565b508415612eb5578051516020820151612eb591903388614602565b8315612ed357612ed381600001516020015182602001513387614602565b5050505050565b612ee382610d88565b612eec81613c92565b6111198383613d22565b6000612f0181613c92565b6001600160a01b038316600081815260066020908152604091829020805460ff19168615159081179091558251938452908301527f6bf75a1f3a54afacac4f907472d898c39eb17762894b2a10c33bca0d1b7f2eba91015b60405180910390a1505050565b612f6e6134c3565b6000612f7c828401846156c9565b90506000308260000151836020015184604001518560600151604051602001612fa99594939291906156e5565b60408051601f198184030181529181528151602092830120600081815260058452828120600785528382203383529094529190912060085481549294509091429161300f916001600160401b03600160a01b909204821691600160801b90910416615dca565b6001600160401b031611156130375760405163a2657bdb60e01b815260040160405180910390fd5b60808401516001830154600884015484546001600160801b0393841693928316926130659281169116615988565b61306f919061571b565b6001600160801b0316101561309757604051638118326d60e01b815260040160405180910390fd5b60008085600001516001600160a01b031663a34123a78760400151886060015189608001516040518463ffffffff1660e01b81526004016130da93929190615743565b60408051808303816000875af11580156130f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061311c9190615769565b87516040808a015160608b015191516309e3d67b60e31b81529496509294506001600160a01b0390911692634f1eb3d89261315f9233928890889060040161578d565b60408051808303816000875af115801561317d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131a191906157ca565b50506131bb848760000151886040015189606001516135a3565b60808601516008850180546000906131dd9084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555085608001518360000160008282829054906101000a90046001600160801b031661322b919061571b565b92506101000a8154816001600160801b0302191690836001600160801b031602179055507f03be56853a49a2ee6e258df43a11d283372ae6f5bca6e176a330c465707c48c48587608001513360405161328693929190615ac6565b60405180910390a15050505050505050565b60006132a381613c92565b60098054600160401b600160801b031916600160401b6001600160401b038681169182029290921790925560088054600160a01b600160e01b031916600160a01b9286169283021790556040805192835260208301919091527fd5368f2daf5acde390dbc8cc0e5e15a5b475dd8aa34486d812c08490319bfdd69101612f59565b6000336001600160a01b0386161480159061336157506001600160a01b03851660009081526020818152604080832033845290915290205460ff16155b156133d4576001600160a01b0385166000908152600260209081526040808320338452825280832086845290915290205460001981146133d2576133a583826155e6565b6001600160a01b038716600090815260026020908152604080832033845282528083208884529091529020555b505b6001600160a01b0385166000908152600160209081526040808320868452909152812080548492906134079084906155e6565b90915550506001600160a01b03841660009081526001602090815260408083208684529091528120805484929061343f9084906155fd565b9250508190555082846001600160a01b0316866001600160a01b0316600080516020615f63833981519152338660405161347a929190615615565b60405180910390a45060015b949350505050565b60006001600160e01b03198216637965db0b60e01b14806108b557506301ffc9a760e01b6001600160e01b03198316146108b5565b60035460ff16156135095760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161118a565b565b3360009081526006602052604090205460ff1661350957604051633a12d49f60e11b815260040160405180910390fd5b600061096661354983613e23565b60008481526005602052604090205461356c906001600160801b03166001615988565b613576919061571b565b6000848152600560205260409020546001600160801b0386811692811691600160801b900416600161462e565b60006135b0308484613d89565b9050600080856001600160a01b031663514ea4bf846040518263ffffffff1660e01b81526004016135e391815260200190565b60a060405180830381865afa158015613600573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136249190615a16565b505060028a015460018b015460088c01548c549497509295506136679450908603926001600160801b03918216928216908216019190910316600160801b61467f565b6004880180546001600160801b0380821690930183166001600160801b03199091161790556003880154600189015460088a01548a546136be9493860393928316908316918316919091010316600160801b61467f565b6004880180546001600160801b03600160801b808304821690940181169093029216919091179055600287019190915560039095019490945550505050565b60008060006137236137118a60020b6138de565b61371d8a60020b6138de565b896141cd565b905060006137486137368b60020b6138de565b6137428b60020b6138de565b8a61423c565b9050600061376d61375b8c60020b6138de565b6137678c60020b6138de565b8a6141cd565b905060006137926137808d60020b6138de565b61378c8d60020b6138de565b8b61423c565b905081156137bb57816137ae856001600160801b038b16615dec565b6137b89190615e21565b95505b80156137e257806137d5846001600160801b038a16615dec565b6137df9190615e21565b94505b50505050965096945050505050565b6001600160a01b0383166000908152600160209081526040808320858452909152812080548392906138249084906155e6565b925050819055508160006001600160a01b0316846001600160a01b0316600080516020615f638339815191523385604051613860929190615615565b60405180910390a4505050565b6000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156138ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138d19190615c28565b5094979650505050505050565b60008060008360020b126138f5578260020b6138fd565b8260020b6000035b9050620d89e8811115613923576040516315e4079d60e11b815260040160405180910390fd5b60008160011660000361393a57600160801b61394c565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b031690506002821615613976576ffff97272373d413259a46990580e213a0260801c5b6004821615613995576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b60088216156139b4576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b60108216156139d3576fffcb9843d60f6159c9db58835c9266440260801c5b60208216156139f2576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615613a11576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615613a30576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615613a50576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615613a70576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615613a90576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615613ab0576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615613ad0576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615613af0576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615613b10576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615613b30576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615613b51576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615613b71576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615613b90576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615613bad576b048a170391f7dc42444e8fa20260801c5b60008460020b1315613bce578060001981613bca57613bca615e0b565b0490505b600160201b810615613be1576001613be4565b60005b60ff16602082901c0192505050919050565b600080836001600160a01b0316856001600160a01b03161115613c17579293925b846001600160a01b0316866001600160a01b031611613c4257613c3b8585856141cd565b9150613c89565b836001600160a01b0316866001600160a01b03161015613c7b57613c678685856141cd565b9150613c7485878561423c565b9050613c89565b613c8685858561423c565b90505b94509492505050565b6114b78133614731565b613ca682826127ef565b61119d5760008281526004602090815260408083206001600160a01b03851684529091529020805460ff19166001179055613cde3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b613d2c82826127ef565b1561119d5760008281526004602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6040516001600160601b0319606085901b16602082015260e883811b603483015282901b6037820152600090603a016040516020818303038152906040528051906020012090509392505050565b613ddf61478a565b6003805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613e199190615436565b60405180910390a1565b600081815260056020818152604080842081516101a08101835281546001600160801b038082168352600160801b9182900481169583019590955260018301548516938201939093526002820154606082015260038201546080820152600482015480851660a083015292909204831660c0830152928301546001600160401b0380821660e08401819052600160401b909204841661010084015260068501546001600160a01b039081166101208501526007860154908116610140850152600160a01b900462ffffff166101608401526008909401549092166101808201526009549092613f1492911690615dca565b6001600160401b03164310613f2c5750600092915050565b60095460e08201516000916001600160401b031690613f4b9043615e35565b6001600160401b0316836101000151613f649190615e55565b613f6e9190615e84565b826101000151613486919061571b565b613f866134c3565b6003805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613e0c3390565b6060806000613fcc848601866156c9565b905060008061400b613fe1846000015161386d565b613ff1856040015160020b6138de565b614001866060015160020b6138de565b8660800151613bf6565b6040805160028082526060820183529395509193506000929060208301908036833701905050905083600001516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015614075573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140999190615aee565b816000815181106140ac576140ac6159b3565b60200260200101906001600160a01b031690816001600160a01b03168152505083600001516001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561410e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141329190615aee565b81600181518110614145576141456159b3565b6001600160a01b039290921660209283029190910182015260408051600280825260608201835260009391929091830190803683370190505090508381600081518110614194576141946159b3565b60200260200101818152505082816001815181106141b4576141b46159b3565b6020908102919091010152909890975095505050505050565b6000826001600160a01b0316846001600160a01b031611156141ed579192915b836001600160a01b0316614226606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b031661467f565b8161423357614233615e0b565b04949350505050565b6000826001600160a01b0316846001600160a01b0316111561425c579192915b613486826001600160801b03168585036001600160a01b0316600160601b61467f565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa1580156142cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142f391906159e0565b90506143548463095ea7b360e01b8561430c86866155fd565b60405160240161431d929190615615565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526147d3565b50505050565b60008181526005602052604081205461096690600160801b90046001600160801b031661438684613e23565b6000858152600560205260409020546143a9906001600160801b03166001615988565b6143b3919061571b565b6001600160801b03868116929116600061462e565b6001600160a01b0383166000908152600160209081526040808320858452909152812080548392906143fb9084906155fd565b9250508190555081836001600160a01b031660006001600160a01b0316600080516020615f638339815191523385604051613860929190615615565b600081602001516001600160a01b031682600001516001600160a01b03161061445f57600080fd5b815160208084015160408086015181516001600160a01b0395861681860152949092168482015262ffffff90911660608085019190915281518085038201815260808501909252815191909201206001600160f81b031960a08401529085901b6001600160601b03191660a183015260b58201527f000000000000000000000000000000000000000000000000000000000000000060d582015260f50160408051601f1981840301815291905280516020909101209392505050565b6000836001600160a01b0316856001600160a01b0316111561453b579293925b846001600160a01b0316866001600160a01b0316116145665761455f8585856148a8565b90506145d6565b836001600160a01b0316866001600160a01b031610156145c857600061458d8786866148a8565b9050600061459c87898661490b565b9050806001600160801b0316826001600160801b0316106145bd57806145bf565b815b925050506145d6565b6145d385858461490b565b90505b95945050505050565b60006145eb8383614437565b9050336001600160a01b038216146108b557600080fd5b306001600160a01b038416036146225761461d848383614948565b614354565b61435484848484614967565b60008061463c86868661499f565b9050600183600281111561465257614652615eaa565b14801561466f57506000848061466a5761466a615e0b565b868809115b156145d6576145d36001826155fd565b60008080600019858709858702925082811083820303915050806000036146b857600084116146ad57600080fd5b508290049050610966565b8084116146c457600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b61473b82826127ef565b61119d5761474881614a89565b614753836020614a9b565b604051602001614764929190615ec0565b60408051601f198184030181529082905262461bcd60e51b825261118a91600401615975565b60035460ff166135095760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161118a565b6000614828826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614c369092919063ffffffff16565b905080516000148061484957508080602001905181019061484991906159f9565b6111195760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161118a565b6000826001600160a01b0316846001600160a01b031611156148c8579192915b60006148eb856001600160a01b0316856001600160a01b0316600160601b61467f565b90506145d661490684838888036001600160a01b031661467f565b614c45565b6000826001600160a01b0316846001600160a01b0316111561492b579192915b61348661490683600160601b8787036001600160a01b031661467f565b6111198363a9059cbb60e01b848460405160240161431d929190615615565b6040516001600160a01b03808516602483015283166044820152606481018290526143549085906323b872dd60e01b9060840161431d565b60008080600019858709858702925082811083820303915050806000036149d9578382816149cf576149cf615e0b565b0492505050610966565b808411614a205760405162461bcd60e51b81526020600482015260156024820152744d6174683a206d756c446976206f766572666c6f7760581b604482015260640161118a565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b60606108b56001600160a01b03831660145b60606000614aaa836002615dec565b614ab59060026155fd565b6001600160401b03811115614acc57614acc6152c9565b6040519080825280601f01601f191660200182016040528015614af6576020820181803683370190505b509050600360fc1b81600081518110614b1157614b116159b3565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110614b4057614b406159b3565b60200101906001600160f81b031916908160001a9053506000614b64846002615dec565b614b6f9060016155fd565b90505b6001811115614be7576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110614ba357614ba36159b3565b1a60f81b828281518110614bb957614bb96159b3565b60200101906001600160f81b031916908160001a90535060049490941c93614be081615f2f565b9050614b72565b5083156109665760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161118a565b60606134868484600085614c60565b806001600160801b0381168114614c5b57600080fd5b919050565b606082471015614cc15760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161118a565b600080866001600160a01b03168587604051614cdd9190615f46565b60006040518083038185875af1925050503d8060008114614d1a576040519150601f19603f3d011682016040523d82523d6000602084013e614d1f565b606091505b5091509150614d3087838387614d3b565b979650505050505050565b60608315614daa578251600003614da3576001600160a01b0385163b614da35760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161118a565b5081613486565b6134868383815115614dbf5781518083602001fd5b8060405162461bcd60e51b815260040161118a9190615975565b6001600160a01b03811681146114b757600080fd5b8035614c5b81614dd9565b60008060408385031215614e0c57600080fd5b8235614e1781614dd9565b946020939093013593505050565b600060208284031215614e3757600080fd5b81356001600160e01b03198116811461096657600080fd5b600080600060608486031215614e6457600080fd5b8335614e6f81614dd9565b95602085013595506040909401359392505050565b60008083601f840112614e9657600080fd5b5081356001600160401b03811115614ead57600080fd5b6020830191508360208285010111156110f657600080fd5b600080600060408486031215614eda57600080fd5b8335614ee581614dd9565b925060208401356001600160401b03811115614f0057600080fd5b614f0c86828701614e84565b9497909650939450505050565b600060208284031215614f2b57600080fd5b5035919050565b6001600160801b03811681146114b757600080fd5b60008060408385031215614f5a57600080fd5b8235614e1781614f32565b6001600160801b03169052565b60008060208385031215614f8557600080fd5b82356001600160401b03811115614f9b57600080fd5b614fa785828601614e84565b90969095509350505050565b600081518084526020808501945080840160005b83811015614fe357815187529582019590820190600101614fc7565b509495945050505050565b6040815260006150016040830185614fb3565b90508260208301529392505050565b6000806040838503121561502357600080fd5b82359150602083013561503581614dd9565b809150509250929050565b8060020b81146114b757600080fd5b8035614c5b81615040565b600080600080600060a0868803121561507257600080fd5b853561507d81614dd9565b9450602086013561508d81615040565b9350604086013561509d81615040565b925060608601356150ad81614f32565b915060808601356150bd81614dd9565b809150509295509295909350565b80151581146114b757600080fd5b600080604083850312156150ec57600080fd5b82356150f781614dd9565b91506020830135615035816150cb565b60008060006060848603121561511c57600080fd5b833561512781614dd9565b9250602084013561513781614dd9565b929592945050506040919091013590565b6001600160a01b03169052565b60006101a082019050615169828451614f65565b602083015161517b6020840182614f65565b50604083015161518e6040840182614f65565b50606083015160608301526080830151608083015260a08301516151b560a0840182614f65565b5060c08301516151c860c0840182614f65565b5060e08301516151e360e08401826001600160401b03169052565b50610100808401516151f782850182614f65565b50506101208084015161520c82850182615148565b50506101408084015161522182850182615148565b50506101608381015162ffffff16908301526101808084015161524682850182614f65565b505092915050565b600081518084526020808501945080840160005b83811015614fe35781516001600160a01b031687529582019590820190600101615262565b60408152600061529a604083018561524e565b82810360208401526145d68185614fb3565b6000602082840312156152be57600080fd5b813561096681614dd9565b634e487b7160e01b600052604160045260246000fd5b60405161014081016001600160401b0381118282101715615302576153026152c9565b60405290565b62ffffff811681146114b757600080fd5b8035614c5b81615308565b6000610140828403121561533757600080fd5b61533f6152df565b61534883614dee565b815261535660208401614dee565b602082015261536760408401615319565b604082015261537860608401614dee565b60608201526153896080840161504f565b608082015261539a60a0840161504f565b60a082015260c0838101359082015260e080840135908201526101008084013590820152610120928301359281019290925250919050565b6060815260006153e5606083018661524e565b82810360208401526153f78186614fb3565b915050826040830152949350505050565b6000806040838503121561541b57600080fd5b823561542681614dd9565b9150602083013561503581614dd9565b6001600160a01b0391909116815260200190565b6000806000806060858703121561546057600080fd5b843593506020850135925060408501356001600160401b0381111561548457600080fd5b61549087828801614e84565b95989497509550505050565b6001600160801b038e811682528d811660208301528c81166040830152606082018c9052608082018b905289811660a0830152881660c08201526001600160401b03871660e08201526101a081016154f8610100830188614f65565b615506610120830187615148565b615514610140830186615148565b62ffffff841661016083015261552e610180830184614f65565b9e9d5050505050505050505050505050565b80356001600160401b0381168114614c5b57600080fd5b6000806040838503121561556a57600080fd5b61557383615540565b915061558160208401615540565b90509250929050565b600080600080608085870312156155a057600080fd5b84356155ab81614dd9565b935060208501356155bb81614dd9565b93969395505050506040820135916060013590565b634e487b7160e01b600052601160045260246000fd5b6000828210156155f8576155f86155d0565b500390565b60008219821115615610576156106155d0565b500190565b6001600160a01b03929092168252602082015260400190565b600060a0828403121561564057600080fd5b60405160a081016001600160401b0381118282101715615662576156626152c9565b604052905080823561567381614dd9565b8152602083013561568381614dd9565b6020820152604083013561569681615040565b604082015260608301356156a981615040565b606082015260808301356156bc81614f32565b6080919091015292915050565b600060a082840312156156db57600080fd5b610966838361562e565b6001600160a01b0395861681529385166020850152919093166040830152600292830b606083015290910b608082015260a00190565b60006001600160801b038381169083168181101561573b5761573b6155d0565b039392505050565b600293840b81529190920b60208201526001600160801b03909116604082015260600190565b6000806040838503121561577c57600080fd5b505080516020909101519092909150565b6001600160a01b03959095168552600293840b60208601529190920b60408401526001600160801b03918216606084015216608082015260a00190565b600080604083850312156157dd57600080fd5b82516157e881614f32565b602084015190925061503581614f32565b9687526001600160801b039590951660208701526001600160a01b03938416604087015291831660608601529091166080840152600290810b60a08401520b60c082015260e00190565b600082601f83011261585457600080fd5b81356001600160401b038082111561586e5761586e6152c9565b604051601f8301601f19908116603f01168101908282118183101715615896576158966152c9565b816040528381528660208588010111156158af57600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060c083850312156158e257600080fd5b6158ec848461562e565b915060a08301356001600160401b0381111561590757600080fd5b61591385828601615843565b9150509250929050565b60005b83811015615938578181015183820152602001615920565b838111156143545750506000910152565b6000815180845261596181602086016020860161591d565b601f01601f19169290920160200192915050565b6020815260006109666020830184615949565b60006001600160801b038281168482168083038211156159aa576159aa6155d0565b01949350505050565b634e487b7160e01b600052603260045260246000fd5b9182526001600160801b0316602082015260400190565b6000602082840312156159f257600080fd5b5051919050565b600060208284031215615a0b57600080fd5b8151610966816150cb565b600080600080600060a08688031215615a2e57600080fd5b8551615a3981614f32565b8095505060208601519350604086015192506060860151615a5981614f32565b60808701519092506150bd81614f32565b60008060008060808587031215615a8057600080fd5b8435615a8b81614dd9565b93506020850135615a9b81614dd9565b92506040850135615aab81615040565b91506060850135615abb81615040565b939692955090935050565b9283526001600160801b039190911660208301526001600160a01b0316604082015260600190565b600060208284031215615b0057600080fd5b815161096681614dd9565b600060208284031215615b1d57600080fd5b815161096681615308565b600061014082019050615b3c828451615148565b6020830151615b4e6020840182615148565b506040830151615b65604084018262ffffff169052565b506060830151615b786060840182615148565b506080830151615b8d608084018260020b9052565b5060a0830151615ba260a084018260020b9052565b5060c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525092915050565b60008060008060808587031215615beb57600080fd5b8451615bf681614f32565b8094505060208501519250604085015191506060850151615abb81614dd9565b805161ffff81168114614c5b57600080fd5b600080600080600080600060e0888a031215615c4357600080fd5b8751615c4e81614dd9565b6020890151909750615c5f81615040565b9550615c6d60408901615c16565b9450615c7b60608901615c16565b9350615c8960808901615c16565b925060a088015160ff81168114615c9f57600080fd5b60c0890151909250615cb0816150cb565b8091505092959891949750929550565b6001600160a01b0386168152600285810b602083015284900b60408201526001600160801b038316606082015260a060808201819052600090614d3090830184615949565b60008183036080811215615d1857600080fd5b604080519081016001600160401b038082118383101715615d3b57615d3b6152c9565b816040526060841215615d4d57600080fd5b60a0830193508184108185111715615d6757615d676152c9565b508260405284359250615d7983614dd9565b918252602084013591615d8b83614dd9565b82606083015260408501359250615da183615308565b8260808301528082525060608401359150615dbb82614dd9565b60208101919091529392505050565b60006001600160401b038281168482168083038211156159aa576159aa6155d0565b6000816000190483118215151615615e0657615e066155d0565b500290565b634e487b7160e01b600052601260045260246000fd5b600082615e3057615e30615e0b565b500490565b60006001600160401b038381169083168181101561573b5761573b6155d0565b60006001600160801b0382811684821681151582840482111615615e7b57615e7b6155d0565b02949350505050565b60006001600160801b0383811680615e9e57615e9e615e0b565b92169190910492915050565b634e487b7160e01b600052602160045260246000fd5b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351615ef281601785016020880161591d565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615f2381602884016020880161591d565b01602801949350505050565b600081615f3e57615f3e6155d0565b506000190190565b60008251615f5881846020870161591d565b919091019291505056fe1b3d7edb2e9c0b0e7c525b20aaaef0f5940d2ed71663c7d39266ecafac7288597b2ab94bb7d45041581aa3757ae020084674ccad6f75dc3750eb2ea8a92c4e9af5a3adca44ef2aebaa0119b112fdab77a870084d4df7c374f841e9c5b150863ea2646970667358221220b8b771d35aae2e25d18a7681d6df5285160e02fc7717158bb2ad2c8020bdb99f64736f6c634300080f003300000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202ee34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b540000000000000000000000001400fefd6f9b897970f00df6237ff2b8b27dc82c
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106102035760003560e01c8062fdd58e1461020857806301ffc9a714610246578063095bcdb6146102695780630c774f4a1461027c5780631575e948146102a75780631e0250ed146102ba578063248a9ca3146102d457806328daa117146102e75780632b4d93ea146103125780632f2ff15d1461033357806336568abe14610348578063426a84931461035b57806348f449bd1461036e5780634a4e3bd5146103815780634d0b1de31461038957806351858e271461039c578063558a7297146103a4578063598af9e7146103b75780635bbc4068146103e85780635c975abb1461045557806363f558c8146104605780636b69e342146104735780636f78d29814610486578063742b5fdd146105e95780637b3fd9651461060a5780637da68a651461061d5780638cf699981461063057806391d14854146106535780639981bb9b14610666578063a217fddf146106ac578063b220e470146106b4578063b6363cf2146106d6578063b8ea4a84146105e9578063c45a015514610701578063ca83cb2214610735578063d34879971461074f578063d547741f14610762578063d58778d614610775578063dc6fd8ab14610837578063e0f19adf146105e9578063ec944b6d1461085e578063efb7dbb814610871578063f349625d14610884578063fe99049a14610897575b600080fd5b610233610216366004614df9565b600160209081526000928352604080842090915290825290205481565b6040519081526020015b60405180910390f35b610259610254366004614e25565b6108aa565b604051901515815260200161023d565b610259610277366004614e4f565b6108bb565b60095461028f906001600160401b031681565b6040516001600160401b03909116815260200161023d565b6102336102b5366004614ec5565b61096d565b60085461028f90600160a01b90046001600160401b031681565b6102336102e2366004614f19565b610d88565b6102fa6102f5366004614f47565b610d9d565b6040516001600160801b03909116815260200161023d565b610325610320366004614f72565b610da9565b60405161023d929190614fee565b610346610341366004615010565b6110fd565b005b610346610356366004615010565b61111e565b610259610369366004614e4f565b6111a1565b61034661037c36600461505a565b611206565b610346611497565b610325610397366004614f72565b6114ba565b610346611792565b6102596103b23660046150d9565b6117b2565b6102336103c5366004615107565b600260209081526000938452604080852082529284528284209052825290205481565b61042e6103f6366004615010565b60076020908152600092835260408084209091529082529020546001600160801b03811690600160801b90046001600160401b031682565b604080516001600160801b0390931683526001600160401b0390911660208301520161023d565b60035460ff16610259565b61023361046e366004614f72565b611820565b610233610481366004614f72565b611876565b6105dc610494366004614f19565b604080516101a081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e0810182905261010081018290526101208101829052610140810182905261016081018290526101808101919091525060009081526005602081815260409283902083516101a08101855281546001600160801b038082168352600160801b9182900481169483019490945260018301548416958201959095526002820154606082015260038201546080820152600482015480841660a083015294909404821660c0850152918201546001600160401b03811660e0850152600160401b9004811661010084015260068201546001600160a01b039081166101208501526007830154908116610140850152600160a01b900462ffffff166101608401526008909101541661018082015290565b60405161023d9190615155565b6105fc6105f7366004614f72565b611cdd565b60405161023d929190615287565b610233610618366004614ec5565b611cf5565b6102fa61062b366004614f47565b6127e3565b61025961063e3660046152ac565b60066020526000908152604090205460ff1681565b610259610661366004615010565b6127ef565b610679610674366004615324565b61281a565b604080516001600160801b0390951685526020850193909352918301526001600160a01b0316606082015260800161023d565b610233600081565b6106c76106c2366004614f72565b612a3d565b60405161023d939291906153d2565b6102596106e4366004615408565b600060208181529281526040808220909352908152205460ff1681565b6107287f00000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202e81565b60405161023d9190615436565b60095461028f90600160401b90046001600160401b031681565b61034661075d36600461544a565b612e5c565b610346610770366004615010565b612eda565b61081e610783366004614f19565b60056020819052600091825260409091208054600182015460028301546003840154600485015495850154600686015460078701546008909701546001600160801b0380881699600160801b9889900482169997821698969795968282169691048216946001600160401b03811694600160401b9091048316936001600160a01b039182169391831692600160a01b900462ffffff1691168d565b60405161023d9d9c9b9a9998979695949392919061549c565b6102337fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5481565b61034661086c3660046150d9565b612ef6565b61034661087f366004614f72565b612f66565b610346610892366004615557565b613298565b6102596108a536600461558a565b613324565b60006108b58261348e565b92915050565b3360009081526001602090815260408083208584529091528120805483919083906108e79084906155e6565b90915550506001600160a01b03841660009081526001602090815260408083208684529091528120805484929061091f9084906155fd565b9250508190555082846001600160a01b0316336001600160a01b0316600080516020615f63833981519152338660405161095a929190615615565b60405180910390a45060015b9392505050565b60006109776134c3565b61097f61350b565b600061098d838501856156c9565b905060003082600001518360200151846040015185606001516040516020016109ba9594939291906156e5565b60408051601f1981840301815282825280516020918201206000818152600583528381206060860185528186529285018190529284019290925260808501519193509190610a08908461353b565b6001600160801b03908116808352600184015484549192610a2d92918116911661571b565b6001600160801b03161015610a5557604051638118326d60e01b815260040160405180910390fd5b835160408086015160608701518451925163a34123a760e01b81526001600160a01b039094169363a34123a793610a90939291600401615743565b60408051808303816000875af1158015610aae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ad29190615769565b826020018360400182815250828152505050610afc828560000151866040015187606001516135a3565b604084015160608501518251845460048601546000948594610b3994919390926001600160801b039182169181811691600160801b9004166136fd565b6004860180549294509092508391600090610b5e9084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550808460040160108282829054906101000a90046001600160801b0316610ba8919061571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555085600001516001600160a01b0316634f1eb3d88b88604001518960600151866001600160801b03168860200151610c0391906155fd565b866001600160801b03168960400151610c1c91906155fd565b6040518663ffffffff1660e01b8152600401610c3c95949392919061578d565b60408051808303816000875af1158015610c5a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c7e91906157ca565b5050825184548590600090610c9d9084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555085608001518460000160108282829054906101000a90046001600160801b0316610ceb919061571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550610d278a8688608001516001600160801b03166137f1565b600080516020615fa3833981519152858460000151886000015189602001518e8b604001518c60600151604051610d6497969594939291906157f9565b60405180910390a15050506080909201516001600160801b03169695505050505050565b60009081526004602052604090206001015490565b6000610966838361353b565b60606000610db56134c3565b610dbd61350b565b600080610dcc858701876158cf565b915091506000308360000151846020015185604001518660600151604051602001610dfb9594939291906156e5565b60408051601f19818403018152918152815160209283012060008181526005845291909120918501519092506001600160a01b031615610e985783602001516001600160a01b0316633f9dd868846040518263ffffffff1660e01b8152600401610e659190615975565b600060405180830381600087803b158015610e7f57600080fd5b505af1158015610e93573d6000803e3d6000fd5b505050505b600080610ed5610eab876000015161386d565b610ebb886040015160020b6138de565b610ecb896060015160020b6138de565b8960800151613bf6565b604080516101408101825260068701546001600160a01b03908116825260078801549081166020830152600160a01b900462ffffff168183015230606080830191909152918a0151600290810b6080830152918a015190910b60a082015260c0810183905260e08101829052610100810183905261012081018290529193509150600090610f629061281a565b5050509050610f7f84886000015189604001518a606001516135a3565b60018401546001600160801b03808316911610610fdf57600184018054829190600090610fb69084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550611048565b6001840154610ff7906001600160801b03168261571b565b845485906000906110129084906001600160801b0316615988565b82546001600160801b039182166101009390930a9283029190920219909116179055506001840180546001600160801b03191690555b604080516002808252606082018352600092602083019080368337019050509050838160008151811061107d5761107d6159b3565b602002602001018181525050828160018151811061109d5761109d6159b3565b6020026020010181815250507f64d8efec9e37db387b761d25cf5596ba293cd64d72fbcd86d7bb43b14c3bfaa886836040516110da9291906159c9565b60405180910390a198506001600160801b031696505050505050505b9250929050565b61110682610d88565b61110f81613c92565b6111198383613c9c565b505050565b6001600160a01b03811633146111935760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084015b60405180910390fd5b61119d8282613d22565b5050565b3360008181526002602090815260408083206001600160a01b03881680855290835281842087855290925280832085905551919285927fb3fd5071835887567a0671151121894ddccc2842f1d10bedad13e0d17cace9a79061095a9087815260200190565b7f0a82b25974fd602b636b85d2a46fd7e8e40145d9a7739850ececf3c2b6eab34c61123081613c92565b6001600160a01b0382161561131c576040516370a0823160e01b81526001600160a01b0383169063a9059cbb90339083906370a0823190611275903090600401615436565b602060405180830381865afa158015611292573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112b691906159e0565b6040518363ffffffff1660e01b81526004016112d3929190615615565b6020604051808303816000875af11580156112f2573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061131691906159f9565b5061148f565b60405163a34123a760e01b81526001600160a01b0387169063a34123a79061134c90889088908890600401615743565b60408051808303816000875af115801561136a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061138e9190615769565b5050600080876001600160a01b031663514ea4bf6113ad308a8a613d89565b6040518263ffffffff1660e01b81526004016113cb91815260200190565b60a060405180830381865afa1580156113e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061140c9190615a16565b6040516309e3d67b60e31b815291965094506001600160a01b038c169350634f1eb3d89250611448915033908b908b908890889060040161578d565b60408051808303816000875af1158015611466573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148a91906157ca565b505050505b505050505050565b600080516020615f838339815191526114af81613c92565b6114b7613dd7565b50565b606060006114c66134c3565b6114ce61350b565b60006114dc848601866156c9565b905060003082600001518360200151846040015185606001516040516020016115099594939291906156e5565b60408051601f1981840301815291815281516020928301206000818152600590935290822084519193509190819061156e906115449061386d565b611554876040015160020b6138de565b611564886060015160020b6138de565b8860800151613bf6565b604080516101408101825260068701546001600160a01b03908116825260078801549081166020830152600160a01b900462ffffff16818301523060608083019190915291890151600290810b60808301529189015190910b60a082015260c0810183905260e081018290526101008101839052610120810182905291935091506000906115fb9061281a565b5050509050611618848760000151886040015189606001516135a3565b8354819085906000906116359084906001600160801b0316615988565b92506101000a8154816001600160801b0302191690836001600160801b031602179055508061166386613e23565b61166d9190615988565b6005850180546001600160c01b031916600160401b6001600160801b039390931683026001600160401b03191617436001600160401b03908116919091179091556009549190910416156116df5760098054600160401b81046001600160401b03166001600160801b03199091161790555b6040805160028082526060820183526000926020830190803683370190505090508381600081518110611714576117146159b3565b6020026020010181815250508281600181518110611734576117346159b3565b6020026020010181815250507f504089073b229a89dd5c190e4348d0ba4fcfcf103683f51f771deb19bd9fc27a86836040516117719291906159c9565b60405180910390a197506001600160801b0316955050505050509250929050565b600080516020615f838339815191526117aa81613c92565b6114b7613f7e565b336000818152602081815260408083206001600160a01b038716808552908352818420805460ff191687151590811790915591519182529293917fceb576d9f15e4e200fdb5096d64d5dfd667e16def20c1eefd14256d8e3faa267910160405180910390a350600192915050565b60008080808061183286880188615a6a565b935093509350935030848484846040516020016118539594939291906156e5565b60408051601f198184030181529190528051602090910120979650505050505050565b60006118806134c3565b600061188e838501856156c9565b905060003082600001518360200151846040015185606001516040516020016118bb9594939291906156e5565b60408051601f19818403018152918152815160209283012060008181526005909352908220608085015191935091906118f4908461353b565b905083600001516001600160a01b031663a34123a78560400151866060015160006040518463ffffffff1660e01b815260040161193393929190615743565b60408051808303816000875af1158015611951573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119759190615769565b505061198f828560000151866040015187606001516135a3565b604084015160608501518354600485015460009384936119cc939192909187916001600160801b039182169181811691600160801b9004166136fd565b60048601805492945090925083916000906119f19084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550808460040160108282829054906101000a90046001600160801b0316611a3b919061571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555085600001516001600160a01b0316634f1eb3d8338860400151896060015186866040518663ffffffff1660e01b8152600401611a9f95949392919061578d565b60408051808303816000875af1158015611abd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ae191906157ca565b505060008581526007602090815260408083203384529091528120805490918591839190611b199084906001600160801b0316615988565b82546101009290920a6001600160801b038181021990931691831602179091558254600160801b600160c01b031916600160801b426001600160401b03160217835586548692508791600091611b719185911661571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555086608001518560000160108282829054906101000a90046001600160801b0316611bbf919061571b565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550838560080160008282829054906101000a90046001600160801b0316611c099190615988565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550611c45338789608001516001600160801b03166137f1565b600080516020615fa3833981519152868589600001518a60200151338c604001518d60600151604051611c7e97969594939291906157f9565b60405180910390a17fbe8fbc6de0db32ef9e0a0a10395e4909f1d5c5ba6505d8c32363787038b7681b868533604051611cb993929190615ac6565b60405180910390a15050506080909301516001600160801b03169695505050505050565b606080611cea8484613fbb565b915091509250929050565b6000611cff6134c3565b611d0761350b565b6000611d15838501856156c9565b90506000308260000151836020015184604001518560600151604051602001611d429594939291906156e5565b60408051601f1981840301815291815281516020928301206000818152600590935291206006810154919250906001600160a01b0316611f1f5782600001516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611dbe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611de29190615aee565b8160060160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555082600001516001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611e4c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e709190615aee565b8160070160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555082600001516001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015611eda573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611efe9190615b0b565b8160070160146101000a81548162ffffff021916908362ffffff1602179055505b60006040518060e00160405280856040015160020b8152602001856060015160020b8152602001611f56866040015160020b6138de565b6001600160a01b03168152602001611f74866060015160020b6138de565b6001600160a01b0316815260200160006001600160801b031681526020016000815260200160008152509050611fc4611fb0856000015161386d565b826040015183606001518760800151613bf6565b60c083015260a0820181905215801590611fe2575060008160c00151115b1561200057604051639677149b60e01b815260040160405180910390fd5b604080516101408101825260068401546001600160a01b0390811682526007850154908116602080840191909152600160a01b90910462ffffff16928201929092523060608201528251600290810b60808301529183015190910b60a0808301919091528201805160c0808401919091528301805160e08401529051610100830152516101208201526120929061281a565b5050506001600160801b031660808201528351815160208301516120b992859290916135a3565b8154600160801b90046001600160801b0316156126d35760048201546103e86001600160801b039091161180612105575060048201546103e8600160801b9091046001600160801b0316115b1561261f5760006121208260400151836060015160026141cd565b9050600061213883604001518460600151600261423c565b60048501549091506001600160801b031682118061216957506004840154600160801b90046001600160801b031681115b1561261c5760a0830151865160408089015160608a01516004808a015493516309e3d67b60e31b81529515159560009586956001600160a01b0390911694634f1eb3d8946121d2943094929391926001600160801b0380841693600160801b900416910161578d565b60408051808303816000875af11580156121f0573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221491906157ca565b600060048a018190556001600160801b039283169450911691508361223c5760008311612241565b600082115b156124275760085461229a906001600160a01b0316856122615784612263565b835b8661227b5760068b01546001600160a01b031661228a565b60078b01546001600160a01b03165b6001600160a01b0316919061427f565b6008546040805161010081019091526001600160a01b039091169063414bf3899080876122d45760068c01546001600160a01b03166122e3565b60078c01546001600160a01b03165b6001600160a01b03168152602001876123095760078c01546001600160a01b0316612318565b60068c01546001600160a01b03165b6001600160a01b0316815260078c0154600160a01b900462ffffff166020820152306040820152426060820152608001876123535786612355565b855b815260006020808301829052604092830191909152815160e085811b6001600160e01b031916825284516001600160a01b03908116600484015292850151831660248301529284015162ffffff1660448201526060840151821660648201526080840151608482015260a084015160a482015260c084015160c482015292909101511660e4820152610104016020604051808303816000875af1158015612400573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061242491906159e0565b90505b604080516101408101825260068a01546001600160a01b03908116825260078b01549081166020830152600160a01b900462ffffff1681830152306060808301829052928d0151600290810b6080840152928d015190920b60a082015260009190639981bb9b9060c081018861249e5760006124a0565b855b6124aa90896155fd565b8152602001886124ba57856124bd565b60005b6124c790886155fd565b8152602001886124d85760006124da565b855b6124e490896155fd565b8152602001886124f457856124f7565b60005b61250190886155fd565b8152506040518263ffffffff1660e01b81526004016125209190615b28565b6080604051808303816000875af115801561253f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125639190615bd5565b50508a5491925082918b91506000906125869084906001600160801b0316615988565b82546101009290920a6001600160801b038181021990931691831602179091558c518a516020808d0151604080513081526001600160a01b03909516928501929092529083018f9052600291820b6060840152900b608082015290831660a08201527fac625f3c119d91f686e26c248c9faeb771664f8da88187bf7560fe575803724b915060c00160405180910390a150505050505b50505b600061262f82608001518561435a565b608083015184549192509084906000906126539084906001600160801b0316615988565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550808360000160108282829054906101000a90046001600160801b031661269d9190615988565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550806001600160801b0316955050612776565b6080810151825483906000906126f39084906001600160801b0316615988565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555080608001518260000160108282829054906101000a90046001600160801b03166127419190615988565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555080608001516001600160801b031694505b6127818884876143c8565b7fe0fa091eaba5cace48ae5dce26123c6842423b1b0f95fe24fd3a7704582b1f84838260800151866000015187602001518c866000015187602001516040516127d097969594939291906157f9565b60405180910390a1505050509392505050565b6000610966838361435a565b60009182526004602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000806000806000604051806060016040528087600001516001600160a01b0316815260200187602001516001600160a01b03168152602001876040015162ffffff16815250905061288c7f00000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202e82614437565b91506000826001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156128ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128f29190615c28565b5050505050509050600061290988608001516138de565b9050600061291a8960a001516138de565b90506129318383838c60c001518d60e0015161451b565b9750505050816001600160a01b0316633c8a7d8d876060015188608001518960a00151896040518060400160405280888152602001336001600160a01b03168152506040516020016129be9190815180516001600160a01b03908116835260208083015182168185015260409283015162ffffff1692840192909252920151909116606082015260800190565b6040516020818303038152906040526040518663ffffffff1660e01b81526004016129ed959493929190615cc0565b60408051808303816000875af1158015612a0b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a2f9190615769565b959790965091935090915050565b6060806000612a4a6134c3565b612a5261350b565b600080612a61868801886158cf565b915091506000308360000151846020015185604001518660600151604051602001612a909594939291906156e5565b60408051601f19818403018152918152815160209283012060008181526005845291909120918501519092506001600160a01b031615612b2d5783602001516001600160a01b0316637bd14bcd846040518263ffffffff1660e01b8152600401612afa9190615975565b600060405180830381600087803b158015612b1457600080fd5b505af1158015612b28573d6000803e3d6000fd5b505050505b6080840151600182015482546001600160801b0392831692612b52928116911661571b565b6001600160801b03161015612b7a57604051638118326d60e01b815260040160405180910390fd5b60008085600001516001600160a01b031663a34123a78760400151886060015189608001516040518463ffffffff1660e01b8152600401612bbd93929190615743565b60408051808303816000875af1158015612bdb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bff9190615769565b87516040808a015160608b015191516309e3d67b60e31b81529496509294506001600160a01b0390911692634f1eb3d892612c429233928890889060040161578d565b60408051808303816000875af1158015612c60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c8491906157ca565b5050612c9e838760000151886040015189606001516135a3565b6080860151600184018054600090612cc09084906001600160801b0316615988565b92506101000a8154816001600160801b0302191690836001600160801b03160217905550600060026001600160401b03811115612cff57612cff6152c9565b604051908082528060200260200182016040528015612d28578160200160208202803683370190505b50600685015481519192506001600160a01b0316908290600090612d4e57612d4e6159b3565b6001600160a01b0392831660209182029290920101526007850154825191169082906001908110612d8157612d816159b3565b6001600160a01b039290921660209283029190910182015260408051600280825260608201835260009391929091830190803683370190505090508381600081518110612dd057612dd06159b3565b6020026020010181815250508281600181518110612df057612df06159b3565b6020026020010181815250507f7fc7ce728583421fb192c9bac9c143fabf47263826e2fb21203a8f7038c093d4868960800151604051612e319291906159c9565b60405180910390a160809790970151909c969b506001600160801b0316995094975050505050505050565b6000612e6a82840184615d05565b9050612e9a7f00000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202e82600001516145df565b508415612eb5578051516020820151612eb591903388614602565b8315612ed357612ed381600001516020015182602001513387614602565b5050505050565b612ee382610d88565b612eec81613c92565b6111198383613d22565b6000612f0181613c92565b6001600160a01b038316600081815260066020908152604091829020805460ff19168615159081179091558251938452908301527f6bf75a1f3a54afacac4f907472d898c39eb17762894b2a10c33bca0d1b7f2eba91015b60405180910390a1505050565b612f6e6134c3565b6000612f7c828401846156c9565b90506000308260000151836020015184604001518560600151604051602001612fa99594939291906156e5565b60408051601f198184030181529181528151602092830120600081815260058452828120600785528382203383529094529190912060085481549294509091429161300f916001600160401b03600160a01b909204821691600160801b90910416615dca565b6001600160401b031611156130375760405163a2657bdb60e01b815260040160405180910390fd5b60808401516001830154600884015484546001600160801b0393841693928316926130659281169116615988565b61306f919061571b565b6001600160801b0316101561309757604051638118326d60e01b815260040160405180910390fd5b60008085600001516001600160a01b031663a34123a78760400151886060015189608001516040518463ffffffff1660e01b81526004016130da93929190615743565b60408051808303816000875af11580156130f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061311c9190615769565b87516040808a015160608b015191516309e3d67b60e31b81529496509294506001600160a01b0390911692634f1eb3d89261315f9233928890889060040161578d565b60408051808303816000875af115801561317d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131a191906157ca565b50506131bb848760000151886040015189606001516135a3565b60808601516008850180546000906131dd9084906001600160801b031661571b565b92506101000a8154816001600160801b0302191690836001600160801b0316021790555085608001518360000160008282829054906101000a90046001600160801b031661322b919061571b565b92506101000a8154816001600160801b0302191690836001600160801b031602179055507f03be56853a49a2ee6e258df43a11d283372ae6f5bca6e176a330c465707c48c48587608001513360405161328693929190615ac6565b60405180910390a15050505050505050565b60006132a381613c92565b60098054600160401b600160801b031916600160401b6001600160401b038681169182029290921790925560088054600160a01b600160e01b031916600160a01b9286169283021790556040805192835260208301919091527fd5368f2daf5acde390dbc8cc0e5e15a5b475dd8aa34486d812c08490319bfdd69101612f59565b6000336001600160a01b0386161480159061336157506001600160a01b03851660009081526020818152604080832033845290915290205460ff16155b156133d4576001600160a01b0385166000908152600260209081526040808320338452825280832086845290915290205460001981146133d2576133a583826155e6565b6001600160a01b038716600090815260026020908152604080832033845282528083208884529091529020555b505b6001600160a01b0385166000908152600160209081526040808320868452909152812080548492906134079084906155e6565b90915550506001600160a01b03841660009081526001602090815260408083208684529091528120805484929061343f9084906155fd565b9250508190555082846001600160a01b0316866001600160a01b0316600080516020615f63833981519152338660405161347a929190615615565b60405180910390a45060015b949350505050565b60006001600160e01b03198216637965db0b60e01b14806108b557506301ffc9a760e01b6001600160e01b03198316146108b5565b60035460ff16156135095760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015260640161118a565b565b3360009081526006602052604090205460ff1661350957604051633a12d49f60e11b815260040160405180910390fd5b600061096661354983613e23565b60008481526005602052604090205461356c906001600160801b03166001615988565b613576919061571b565b6000848152600560205260409020546001600160801b0386811692811691600160801b900416600161462e565b60006135b0308484613d89565b9050600080856001600160a01b031663514ea4bf846040518263ffffffff1660e01b81526004016135e391815260200190565b60a060405180830381865afa158015613600573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136249190615a16565b505060028a015460018b015460088c01548c549497509295506136679450908603926001600160801b03918216928216908216019190910316600160801b61467f565b6004880180546001600160801b0380821690930183166001600160801b03199091161790556003880154600189015460088a01548a546136be9493860393928316908316918316919091010316600160801b61467f565b6004880180546001600160801b03600160801b808304821690940181169093029216919091179055600287019190915560039095019490945550505050565b60008060006137236137118a60020b6138de565b61371d8a60020b6138de565b896141cd565b905060006137486137368b60020b6138de565b6137428b60020b6138de565b8a61423c565b9050600061376d61375b8c60020b6138de565b6137678c60020b6138de565b8a6141cd565b905060006137926137808d60020b6138de565b61378c8d60020b6138de565b8b61423c565b905081156137bb57816137ae856001600160801b038b16615dec565b6137b89190615e21565b95505b80156137e257806137d5846001600160801b038a16615dec565b6137df9190615e21565b94505b50505050965096945050505050565b6001600160a01b0383166000908152600160209081526040808320858452909152812080548392906138249084906155e6565b925050819055508160006001600160a01b0316846001600160a01b0316600080516020615f638339815191523385604051613860929190615615565b60405180910390a4505050565b6000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156138ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138d19190615c28565b5094979650505050505050565b60008060008360020b126138f5578260020b6138fd565b8260020b6000035b9050620d89e8811115613923576040516315e4079d60e11b815260040160405180910390fd5b60008160011660000361393a57600160801b61394c565b6ffffcb933bd6fad37aa2d162d1a5940015b6001600160881b031690506002821615613976576ffff97272373d413259a46990580e213a0260801c5b6004821615613995576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b60088216156139b4576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b60108216156139d3576fffcb9843d60f6159c9db58835c9266440260801c5b60208216156139f2576fff973b41fa98c081472e6896dfb254c00260801c5b6040821615613a11576fff2ea16466c96a3843ec78b326b528610260801c5b6080821615613a30576ffe5dee046a99a2a811c461f1969c30530260801c5b610100821615613a50576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b610200821615613a70576ff987a7253ac413176f2b074cf7815e540260801c5b610400821615613a90576ff3392b0822b70005940c7a398e4b70f30260801c5b610800821615613ab0576fe7159475a2c29b7443b29c7fa6e889d90260801c5b611000821615613ad0576fd097f3bdfd2022b8845ad8f792aa58250260801c5b612000821615613af0576fa9f746462d870fdf8a65dc1f90e061e50260801c5b614000821615613b10576f70d869a156d2a1b890bb3df62baf32f70260801c5b618000821615613b30576f31be135f97d08fd981231505542fcfa60260801c5b62010000821615613b51576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b62020000821615613b71576e5d6af8dedb81196699c329225ee6040260801c5b62040000821615613b90576d2216e584f5fa1ea926041bedfe980260801c5b62080000821615613bad576b048a170391f7dc42444e8fa20260801c5b60008460020b1315613bce578060001981613bca57613bca615e0b565b0490505b600160201b810615613be1576001613be4565b60005b60ff16602082901c0192505050919050565b600080836001600160a01b0316856001600160a01b03161115613c17579293925b846001600160a01b0316866001600160a01b031611613c4257613c3b8585856141cd565b9150613c89565b836001600160a01b0316866001600160a01b03161015613c7b57613c678685856141cd565b9150613c7485878561423c565b9050613c89565b613c8685858561423c565b90505b94509492505050565b6114b78133614731565b613ca682826127ef565b61119d5760008281526004602090815260408083206001600160a01b03851684529091529020805460ff19166001179055613cde3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b613d2c82826127ef565b1561119d5760008281526004602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6040516001600160601b0319606085901b16602082015260e883811b603483015282901b6037820152600090603a016040516020818303038152906040528051906020012090509392505050565b613ddf61478a565b6003805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613e199190615436565b60405180910390a1565b600081815260056020818152604080842081516101a08101835281546001600160801b038082168352600160801b9182900481169583019590955260018301548516938201939093526002820154606082015260038201546080820152600482015480851660a083015292909204831660c0830152928301546001600160401b0380821660e08401819052600160401b909204841661010084015260068501546001600160a01b039081166101208501526007860154908116610140850152600160a01b900462ffffff166101608401526008909401549092166101808201526009549092613f1492911690615dca565b6001600160401b03164310613f2c5750600092915050565b60095460e08201516000916001600160401b031690613f4b9043615e35565b6001600160401b0316836101000151613f649190615e55565b613f6e9190615e84565b826101000151613486919061571b565b613f866134c3565b6003805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613e0c3390565b6060806000613fcc848601866156c9565b905060008061400b613fe1846000015161386d565b613ff1856040015160020b6138de565b614001866060015160020b6138de565b8660800151613bf6565b6040805160028082526060820183529395509193506000929060208301908036833701905050905083600001516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015614075573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140999190615aee565b816000815181106140ac576140ac6159b3565b60200260200101906001600160a01b031690816001600160a01b03168152505083600001516001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561410e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141329190615aee565b81600181518110614145576141456159b3565b6001600160a01b039290921660209283029190910182015260408051600280825260608201835260009391929091830190803683370190505090508381600081518110614194576141946159b3565b60200260200101818152505082816001815181106141b4576141b46159b3565b6020908102919091010152909890975095505050505050565b6000826001600160a01b0316846001600160a01b031611156141ed579192915b836001600160a01b0316614226606060ff16846001600160801b0316901b8686036001600160a01b0316866001600160a01b031661467f565b8161423357614233615e0b565b04949350505050565b6000826001600160a01b0316846001600160a01b0316111561425c579192915b613486826001600160801b03168585036001600160a01b0316600160601b61467f565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa1580156142cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142f391906159e0565b90506143548463095ea7b360e01b8561430c86866155fd565b60405160240161431d929190615615565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526147d3565b50505050565b60008181526005602052604081205461096690600160801b90046001600160801b031661438684613e23565b6000858152600560205260409020546143a9906001600160801b03166001615988565b6143b3919061571b565b6001600160801b03868116929116600061462e565b6001600160a01b0383166000908152600160209081526040808320858452909152812080548392906143fb9084906155fd565b9250508190555081836001600160a01b031660006001600160a01b0316600080516020615f638339815191523385604051613860929190615615565b600081602001516001600160a01b031682600001516001600160a01b03161061445f57600080fd5b815160208084015160408086015181516001600160a01b0395861681860152949092168482015262ffffff90911660608085019190915281518085038201815260808501909252815191909201206001600160f81b031960a08401529085901b6001600160601b03191660a183015260b58201527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460d582015260f50160408051601f1981840301815291905280516020909101209392505050565b6000836001600160a01b0316856001600160a01b0316111561453b579293925b846001600160a01b0316866001600160a01b0316116145665761455f8585856148a8565b90506145d6565b836001600160a01b0316866001600160a01b031610156145c857600061458d8786866148a8565b9050600061459c87898661490b565b9050806001600160801b0316826001600160801b0316106145bd57806145bf565b815b925050506145d6565b6145d385858461490b565b90505b95945050505050565b60006145eb8383614437565b9050336001600160a01b038216146108b557600080fd5b306001600160a01b038416036146225761461d848383614948565b614354565b61435484848484614967565b60008061463c86868661499f565b9050600183600281111561465257614652615eaa565b14801561466f57506000848061466a5761466a615e0b565b868809115b156145d6576145d36001826155fd565b60008080600019858709858702925082811083820303915050806000036146b857600084116146ad57600080fd5b508290049050610966565b8084116146c457600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b61473b82826127ef565b61119d5761474881614a89565b614753836020614a9b565b604051602001614764929190615ec0565b60408051601f198184030181529082905262461bcd60e51b825261118a91600401615975565b60035460ff166135095760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015260640161118a565b6000614828826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316614c369092919063ffffffff16565b905080516000148061484957508080602001905181019061484991906159f9565b6111195760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161118a565b6000826001600160a01b0316846001600160a01b031611156148c8579192915b60006148eb856001600160a01b0316856001600160a01b0316600160601b61467f565b90506145d661490684838888036001600160a01b031661467f565b614c45565b6000826001600160a01b0316846001600160a01b0316111561492b579192915b61348661490683600160601b8787036001600160a01b031661467f565b6111198363a9059cbb60e01b848460405160240161431d929190615615565b6040516001600160a01b03808516602483015283166044820152606481018290526143549085906323b872dd60e01b9060840161431d565b60008080600019858709858702925082811083820303915050806000036149d9578382816149cf576149cf615e0b565b0492505050610966565b808411614a205760405162461bcd60e51b81526020600482015260156024820152744d6174683a206d756c446976206f766572666c6f7760581b604482015260640161118a565b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b60606108b56001600160a01b03831660145b60606000614aaa836002615dec565b614ab59060026155fd565b6001600160401b03811115614acc57614acc6152c9565b6040519080825280601f01601f191660200182016040528015614af6576020820181803683370190505b509050600360fc1b81600081518110614b1157614b116159b3565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110614b4057614b406159b3565b60200101906001600160f81b031916908160001a9053506000614b64846002615dec565b614b6f9060016155fd565b90505b6001811115614be7576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110614ba357614ba36159b3565b1a60f81b828281518110614bb957614bb96159b3565b60200101906001600160f81b031916908160001a90535060049490941c93614be081615f2f565b9050614b72565b5083156109665760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161118a565b60606134868484600085614c60565b806001600160801b0381168114614c5b57600080fd5b919050565b606082471015614cc15760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161118a565b600080866001600160a01b03168587604051614cdd9190615f46565b60006040518083038185875af1925050503d8060008114614d1a576040519150601f19603f3d011682016040523d82523d6000602084013e614d1f565b606091505b5091509150614d3087838387614d3b565b979650505050505050565b60608315614daa578251600003614da3576001600160a01b0385163b614da35760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161118a565b5081613486565b6134868383815115614dbf5781518083602001fd5b8060405162461bcd60e51b815260040161118a9190615975565b6001600160a01b03811681146114b757600080fd5b8035614c5b81614dd9565b60008060408385031215614e0c57600080fd5b8235614e1781614dd9565b946020939093013593505050565b600060208284031215614e3757600080fd5b81356001600160e01b03198116811461096657600080fd5b600080600060608486031215614e6457600080fd5b8335614e6f81614dd9565b95602085013595506040909401359392505050565b60008083601f840112614e9657600080fd5b5081356001600160401b03811115614ead57600080fd5b6020830191508360208285010111156110f657600080fd5b600080600060408486031215614eda57600080fd5b8335614ee581614dd9565b925060208401356001600160401b03811115614f0057600080fd5b614f0c86828701614e84565b9497909650939450505050565b600060208284031215614f2b57600080fd5b5035919050565b6001600160801b03811681146114b757600080fd5b60008060408385031215614f5a57600080fd5b8235614e1781614f32565b6001600160801b03169052565b60008060208385031215614f8557600080fd5b82356001600160401b03811115614f9b57600080fd5b614fa785828601614e84565b90969095509350505050565b600081518084526020808501945080840160005b83811015614fe357815187529582019590820190600101614fc7565b509495945050505050565b6040815260006150016040830185614fb3565b90508260208301529392505050565b6000806040838503121561502357600080fd5b82359150602083013561503581614dd9565b809150509250929050565b8060020b81146114b757600080fd5b8035614c5b81615040565b600080600080600060a0868803121561507257600080fd5b853561507d81614dd9565b9450602086013561508d81615040565b9350604086013561509d81615040565b925060608601356150ad81614f32565b915060808601356150bd81614dd9565b809150509295509295909350565b80151581146114b757600080fd5b600080604083850312156150ec57600080fd5b82356150f781614dd9565b91506020830135615035816150cb565b60008060006060848603121561511c57600080fd5b833561512781614dd9565b9250602084013561513781614dd9565b929592945050506040919091013590565b6001600160a01b03169052565b60006101a082019050615169828451614f65565b602083015161517b6020840182614f65565b50604083015161518e6040840182614f65565b50606083015160608301526080830151608083015260a08301516151b560a0840182614f65565b5060c08301516151c860c0840182614f65565b5060e08301516151e360e08401826001600160401b03169052565b50610100808401516151f782850182614f65565b50506101208084015161520c82850182615148565b50506101408084015161522182850182615148565b50506101608381015162ffffff16908301526101808084015161524682850182614f65565b505092915050565b600081518084526020808501945080840160005b83811015614fe35781516001600160a01b031687529582019590820190600101615262565b60408152600061529a604083018561524e565b82810360208401526145d68185614fb3565b6000602082840312156152be57600080fd5b813561096681614dd9565b634e487b7160e01b600052604160045260246000fd5b60405161014081016001600160401b0381118282101715615302576153026152c9565b60405290565b62ffffff811681146114b757600080fd5b8035614c5b81615308565b6000610140828403121561533757600080fd5b61533f6152df565b61534883614dee565b815261535660208401614dee565b602082015261536760408401615319565b604082015261537860608401614dee565b60608201526153896080840161504f565b608082015261539a60a0840161504f565b60a082015260c0838101359082015260e080840135908201526101008084013590820152610120928301359281019290925250919050565b6060815260006153e5606083018661524e565b82810360208401526153f78186614fb3565b915050826040830152949350505050565b6000806040838503121561541b57600080fd5b823561542681614dd9565b9150602083013561503581614dd9565b6001600160a01b0391909116815260200190565b6000806000806060858703121561546057600080fd5b843593506020850135925060408501356001600160401b0381111561548457600080fd5b61549087828801614e84565b95989497509550505050565b6001600160801b038e811682528d811660208301528c81166040830152606082018c9052608082018b905289811660a0830152881660c08201526001600160401b03871660e08201526101a081016154f8610100830188614f65565b615506610120830187615148565b615514610140830186615148565b62ffffff841661016083015261552e610180830184614f65565b9e9d5050505050505050505050505050565b80356001600160401b0381168114614c5b57600080fd5b6000806040838503121561556a57600080fd5b61557383615540565b915061558160208401615540565b90509250929050565b600080600080608085870312156155a057600080fd5b84356155ab81614dd9565b935060208501356155bb81614dd9565b93969395505050506040820135916060013590565b634e487b7160e01b600052601160045260246000fd5b6000828210156155f8576155f86155d0565b500390565b60008219821115615610576156106155d0565b500190565b6001600160a01b03929092168252602082015260400190565b600060a0828403121561564057600080fd5b60405160a081016001600160401b0381118282101715615662576156626152c9565b604052905080823561567381614dd9565b8152602083013561568381614dd9565b6020820152604083013561569681615040565b604082015260608301356156a981615040565b606082015260808301356156bc81614f32565b6080919091015292915050565b600060a082840312156156db57600080fd5b610966838361562e565b6001600160a01b0395861681529385166020850152919093166040830152600292830b606083015290910b608082015260a00190565b60006001600160801b038381169083168181101561573b5761573b6155d0565b039392505050565b600293840b81529190920b60208201526001600160801b03909116604082015260600190565b6000806040838503121561577c57600080fd5b505080516020909101519092909150565b6001600160a01b03959095168552600293840b60208601529190920b60408401526001600160801b03918216606084015216608082015260a00190565b600080604083850312156157dd57600080fd5b82516157e881614f32565b602084015190925061503581614f32565b9687526001600160801b039590951660208701526001600160a01b03938416604087015291831660608601529091166080840152600290810b60a08401520b60c082015260e00190565b600082601f83011261585457600080fd5b81356001600160401b038082111561586e5761586e6152c9565b604051601f8301601f19908116603f01168101908282118183101715615896576158966152c9565b816040528381528660208588010111156158af57600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060c083850312156158e257600080fd5b6158ec848461562e565b915060a08301356001600160401b0381111561590757600080fd5b61591385828601615843565b9150509250929050565b60005b83811015615938578181015183820152602001615920565b838111156143545750506000910152565b6000815180845261596181602086016020860161591d565b601f01601f19169290920160200192915050565b6020815260006109666020830184615949565b60006001600160801b038281168482168083038211156159aa576159aa6155d0565b01949350505050565b634e487b7160e01b600052603260045260246000fd5b9182526001600160801b0316602082015260400190565b6000602082840312156159f257600080fd5b5051919050565b600060208284031215615a0b57600080fd5b8151610966816150cb565b600080600080600060a08688031215615a2e57600080fd5b8551615a3981614f32565b8095505060208601519350604086015192506060860151615a5981614f32565b60808701519092506150bd81614f32565b60008060008060808587031215615a8057600080fd5b8435615a8b81614dd9565b93506020850135615a9b81614dd9565b92506040850135615aab81615040565b91506060850135615abb81615040565b939692955090935050565b9283526001600160801b039190911660208301526001600160a01b0316604082015260600190565b600060208284031215615b0057600080fd5b815161096681614dd9565b600060208284031215615b1d57600080fd5b815161096681615308565b600061014082019050615b3c828451615148565b6020830151615b4e6020840182615148565b506040830151615b65604084018262ffffff169052565b506060830151615b786060840182615148565b506080830151615b8d608084018260020b9052565b5060a0830151615ba260a084018260020b9052565b5060c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525092915050565b60008060008060808587031215615beb57600080fd5b8451615bf681614f32565b8094505060208501519250604085015191506060850151615abb81614dd9565b805161ffff81168114614c5b57600080fd5b600080600080600080600060e0888a031215615c4357600080fd5b8751615c4e81614dd9565b6020890151909750615c5f81615040565b9550615c6d60408901615c16565b9450615c7b60608901615c16565b9350615c8960808901615c16565b925060a088015160ff81168114615c9f57600080fd5b60c0890151909250615cb0816150cb565b8091505092959891949750929550565b6001600160a01b0386168152600285810b602083015284900b60408201526001600160801b038316606082015260a060808201819052600090614d3090830184615949565b60008183036080811215615d1857600080fd5b604080519081016001600160401b038082118383101715615d3b57615d3b6152c9565b816040526060841215615d4d57600080fd5b60a0830193508184108185111715615d6757615d676152c9565b508260405284359250615d7983614dd9565b918252602084013591615d8b83614dd9565b82606083015260408501359250615da183615308565b8260808301528082525060608401359150615dbb82614dd9565b60208101919091529392505050565b60006001600160401b038281168482168083038211156159aa576159aa6155d0565b6000816000190483118215151615615e0657615e066155d0565b500290565b634e487b7160e01b600052601260045260246000fd5b600082615e3057615e30615e0b565b500490565b60006001600160401b038381169083168181101561573b5761573b6155d0565b60006001600160801b0382811684821681151582840482111615615e7b57615e7b6155d0565b02949350505050565b60006001600160801b0383811680615e9e57615e9e615e0b565b92169190910492915050565b634e487b7160e01b600052602160045260246000fd5b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260008351615ef281601785016020880161591d565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615f2381602884016020880161591d565b01602801949350505050565b600081615f3e57615f3e6155d0565b506000190190565b60008251615f5881846020870161591d565b919091019291505056fe1b3d7edb2e9c0b0e7c525b20aaaef0f5940d2ed71663c7d39266ecafac7288597b2ab94bb7d45041581aa3757ae020084674ccad6f75dc3750eb2ea8a92c4e9af5a3adca44ef2aebaa0119b112fdab77a870084d4df7c374f841e9c5b150863ea2646970667358221220b8b771d35aae2e25d18a7681d6df5285160e02fc7717158bb2ad2c8020bdb99f64736f6c634300080f0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202ee34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b540000000000000000000000001400fefd6f9b897970f00df6237ff2b8b27dc82c
-----Decoded View---------------
Arg [0] : _factory (address): 0x46B3fDF7b5CDe91Ac049936bF0bDb12c5d22202e
Arg [1] : _pool_init_code_hash (bytes32): 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54
Arg [2] : _swapRouter (address): 0x1400feFD6F9b897970f00Df6237Ff2B8b27Dc82C
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 00000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202e
Arg [1] : e34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54
Arg [2] : 0000000000000000000000001400fefd6f9b897970f00df6237ff2b8b27dc82c
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.