Feature Tip: Add private address tag to any address under My Name Tag !
More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 56 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Withdraw Balance... | 20843863 | 35 days ago | IN | 0 ETH | 0.00311901 | ||||
Withdraw Balance... | 20628556 | 65 days ago | IN | 0 ETH | 0.00129597 | ||||
Transfer Ownersh... | 20343533 | 105 days ago | IN | 0 ETH | 0.00015484 | ||||
Withdraw Balance... | 20342348 | 105 days ago | IN | 0 ETH | 0.00183371 | ||||
Set Withdrawer | 20342181 | 105 days ago | IN | 0 ETH | 0.0001832 | ||||
Set Withdrawer | 20235544 | 120 days ago | IN | 0 ETH | 0.0002246 | ||||
Config Token | 20220451 | 122 days ago | IN | 0 ETH | 0.00017256 | ||||
Config Token | 20112393 | 137 days ago | IN | 0 ETH | 0.00112079 | ||||
Execute | 20089864 | 141 days ago | IN | 0 ETH | 0.00235239 | ||||
Execute | 20080497 | 142 days ago | IN | 0 ETH | 0.00358034 | ||||
Config Token | 20076892 | 142 days ago | IN | 0 ETH | 0.00163336 | ||||
Config Token | 20065402 | 144 days ago | IN | 0 ETH | 0.000472 | ||||
Config Token | 20052272 | 146 days ago | IN | 0 ETH | 0.00040319 | ||||
Config Token | 20031276 | 149 days ago | IN | 0 ETH | 0.00110074 | ||||
Config Token | 20024824 | 150 days ago | IN | 0 ETH | 0.00090387 | ||||
Config Token | 20021792 | 150 days ago | IN | 0 ETH | 0.00025779 | ||||
Config Token | 20021789 | 150 days ago | IN | 0 ETH | 0.00056087 | ||||
Config Token | 19997471 | 153 days ago | IN | 0 ETH | 0.00044376 | ||||
Config Token | 19994825 | 154 days ago | IN | 0 ETH | 0.00044301 | ||||
Config Token | 19974202 | 157 days ago | IN | 0 ETH | 0.00117252 | ||||
Config Token | 19953795 | 160 days ago | IN | 0 ETH | 0.00041929 | ||||
Execute | 19907311 | 166 days ago | IN | 0 ETH | 0.00177919 | ||||
Config Token | 19906955 | 166 days ago | IN | 0 ETH | 0.00023544 | ||||
Config Token | 19886639 | 169 days ago | IN | 0 ETH | 0.00031077 | ||||
Config Token | 19872101 | 171 days ago | IN | 0 ETH | 0.00037188 |
Advanced mode: Intended for advanced users or developers and will display all Internal Transactions including zero value transfers. Name tag integration is not available in advanced view.
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block | From | To | ||||
---|---|---|---|---|---|---|---|
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH | |||||
20843863 | 35 days ago | 0 ETH |
Loading...
Loading
Contract Name:
AutoExit
Compiler Version
v0.8.15+commit.e14f2714
Optimization Enabled:
Yes with 200 runs
Other Settings:
london EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./Automator.sol"; /// @title AutoExit /// @notice Lets a v3 position to be automatically removed (limit order) or swapped to the opposite token (stop loss order) when it reaches a certain tick. /// A revert controlled bot (operator) is responsible for the execution of optimized swaps (using external swap router) /// Positions need to be approved (approve or setApprovalForAll) for the contract and configured with configToken method contract AutoExit is Automator { error NoLiquidity(); error MissingSwapData(); event Executed( uint256 indexed tokenId, address account, bool isSwap, uint256 amountReturned0, uint256 amountReturned1, address token0, address token1 ); event PositionConfigured( uint256 indexed tokenId, bool isActive, bool token0Swap, bool token1Swap, int24 token0TriggerTick, int24 token1TriggerTick, uint64 token0SlippageX64, uint64 token1SlippageX64, bool onlyFees, uint64 maxRewardX64 ); constructor(INonfungiblePositionManager _npm, address _operator, address _withdrawer, uint32 _TWAPSeconds, uint16 _maxTWAPTickDifference, address[] memory _swapRouterOptions) Automator(_npm, _operator, _withdrawer, _TWAPSeconds, _maxTWAPTickDifference, _swapRouterOptions) { } // define how stoploss / limit should be handled struct PositionConfig { bool isActive; // if position is active // should swap token to other token when triggered bool token0Swap; bool token1Swap; // when should action be triggered (when this tick is reached - allow execute) int24 token0TriggerTick; // when tick is below this one int24 token1TriggerTick; // when tick is equal or above this one // max price difference from current pool price for swap / Q64 uint64 token0SlippageX64; // when token 0 is swapped to token 1 uint64 token1SlippageX64; // when token 1 is swapped to token 0 bool onlyFees; // if only fees maybe used for protocol reward uint64 maxRewardX64; // max allowed reward percentage of fees or full position } // configured tokens mapping (uint256 => PositionConfig) public positionConfigs; /// @notice params for execute() struct ExecuteParams { uint256 tokenId; // tokenid to process bytes swapData; // if its a swap order - must include swap data uint128 liquidity; // liquidity the calculations are based on uint256 amountRemoveMin0; // min amount to be removed from liquidity uint256 amountRemoveMin1; // min amount to be removed from liquidity uint256 deadline; // for uniswap operations - operator promises fair value uint64 rewardX64; // which reward will be used for protocol, can be max configured amount (considering onlyFees) } struct ExecuteState { address token0; address token1; uint24 fee; int24 tickLower; int24 tickUpper; uint128 liquidity; uint256 amount0; uint256 amount1; uint256 feeAmount0; uint256 feeAmount1; uint256 amountOutMin; uint256 amountInDelta; uint256 amountOutDelta; IUniswapV3Pool pool; uint256 swapAmount; int24 tick; bool isSwap; bool isAbove; address owner; } /** * @notice Handle token (must be in correct state) * Can only be called only from configured operator account * Swap needs to be done with max price difference from current pool price - otherwise reverts */ function execute(ExecuteParams calldata params) external { if (!operators[msg.sender]) { revert Unauthorized(); } ExecuteState memory state; PositionConfig memory config = positionConfigs[params.tokenId]; if (!config.isActive) { revert NotConfigured(); } if (config.onlyFees && params.rewardX64 > config.maxRewardX64 || !config.onlyFees && params.rewardX64 > config.maxRewardX64) { revert ExceedsMaxReward(); } // get position info (,,state.token0, state.token1, state.fee, state.tickLower, state.tickUpper, state.liquidity, , , , ) = nonfungiblePositionManager.positions(params.tokenId); // so can be executed only once if (state.liquidity == 0) { revert NoLiquidity(); } if (state.liquidity != params.liquidity) { revert LiquidityChanged(); } state.pool = _getPool(state.token0, state.token1, state.fee); (,state.tick,,,,,) = state.pool.slot0(); // not triggered if (config.token0TriggerTick <= state.tick && state.tick < config.token1TriggerTick) { revert NotReady(); } state.isAbove = state.tick >= config.token1TriggerTick; state.isSwap = !state.isAbove && config.token0Swap || state.isAbove && config.token1Swap; // decrease full liquidity for given position - and return fees as well (state.amount0, state.amount1, state.feeAmount0, state.feeAmount1) = _decreaseFullLiquidityAndCollect(params.tokenId, state.liquidity, params.amountRemoveMin0, params.amountRemoveMin1, params.deadline); // swap to other token if (state.isSwap) { if (params.swapData.length == 0) { revert MissingSwapData(); } // reward is taken before swap - if from fees only if (config.onlyFees) { state.amount0 -= state.feeAmount0 * params.rewardX64 / Q64; state.amount1 -= state.feeAmount1 * params.rewardX64 / Q64; } state.swapAmount = state.isAbove ? state.amount1 : state.amount0; // checks if price in valid oracle range and calculates amountOutMin (state.amountOutMin,,,) = _validateSwap(!state.isAbove, state.swapAmount, state.pool, TWAPSeconds, maxTWAPTickDifference, state.isAbove ? config.token1SlippageX64 : config.token0SlippageX64); (state.amountInDelta, state.amountOutDelta) = _swap(state.isAbove ? IERC20(state.token1) : IERC20(state.token0), state.isAbove ? IERC20(state.token0) : IERC20(state.token1), state.swapAmount, state.amountOutMin, params.swapData); state.amount0 = state.isAbove ? state.amount0 + state.amountOutDelta : state.amount0 - state.amountInDelta; state.amount1 = state.isAbove ? state.amount1 - state.amountInDelta : state.amount1 + state.amountOutDelta; // when swap and !onlyFees - protocol reward is removed only from target token (to incentivize optimal swap done by operator) if (!config.onlyFees) { if (state.isAbove) { state.amount0 -= state.amount0 * params.rewardX64 / Q64; } else { state.amount1 -= state.amount1 * params.rewardX64 / Q64; } } } else { // reward is taken as configured state.amount0 -= (config.onlyFees ? state.feeAmount0 : state.amount0) * params.rewardX64 / Q64; state.amount1 -= (config.onlyFees ? state.feeAmount1 : state.amount1) * params.rewardX64 / Q64; } state.owner = nonfungiblePositionManager.ownerOf(params.tokenId); if (state.amount0 > 0) { _transferToken(state.owner, IERC20(state.token0), state.amount0, true); } if (state.amount1 > 0) { _transferToken(state.owner, IERC20(state.token1), state.amount1, true); } // delete config for position delete positionConfigs[params.tokenId]; emit PositionConfigured(params.tokenId, false, false, false, 0, 0, 0, 0, false, 0); // log event emit Executed(params.tokenId, msg.sender, state.isSwap, state.amount0, state.amount1, state.token0, state.token1); } // function to configure a token to be used with this runner // it needs to have approvals set for this contract beforehand function configToken(uint256 tokenId, PositionConfig calldata config) external { address owner = nonfungiblePositionManager.ownerOf(tokenId); if (owner != msg.sender) { revert Unauthorized(); } if (config.isActive) { if (config.token0TriggerTick >= config.token1TriggerTick) { revert InvalidConfig(); } } positionConfigs[tokenId] = config; emit PositionConfigured( tokenId, config.isActive, config.token0Swap, config.token1Swap, config.token0TriggerTick, config.token1TriggerTick, config.token0SlippageX64, config.token1SlippageX64, config.onlyFees, config.maxRewardX64 ); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/utils/math/SafeCast.sol"; import "v3-core/interfaces/IUniswapV3Factory.sol"; import "v3-core/interfaces/IUniswapV3Pool.sol"; import "v3-core/libraries/TickMath.sol"; import "v3-core/libraries/FullMath.sol"; import "v3-periphery/interfaces/INonfungiblePositionManager.sol"; import "v3-periphery/interfaces/external/IWETH9.sol"; abstract contract Automator is Ownable { uint256 internal constant Q64 = 2 ** 64; uint256 internal constant Q96 = 2 ** 96; uint32 public constant MIN_TWAP_SECONDS = 60; // 1 minute uint32 public constant MAX_TWAP_TICK_DIFFERENCE = 200; // 2% error NotConfigured(); error NotReady(); error Unauthorized(); error InvalidConfig(); error TWAPCheckFailed(); error EtherSendFailed(); error NotWETH(); error SwapFailed(); error SlippageError(); error LiquidityChanged(); error ExceedsMaxReward(); INonfungiblePositionManager public immutable nonfungiblePositionManager; IUniswapV3Factory public immutable factory; IWETH9 public immutable weth; // preconfigured options for swap routers address public immutable swapRouterOption0; address public immutable swapRouterOption1; address public immutable swapRouterOption2; // admin events event OperatorChanged(address newOperator, bool active); event WithdrawerChanged(address newWithdrawer); event TWAPConfigChanged(uint32 TWAPSeconds, uint16 maxTWAPTickDifference); event SwapRouterChanged(uint8 swapRouterIndex); // configurable by owner mapping(address => bool) public operators; address public withdrawer; uint32 public TWAPSeconds; uint16 public maxTWAPTickDifference; uint8 public swapRouterIndex; // default is 0 constructor(INonfungiblePositionManager npm, address _operator, address _withdrawer, uint32 _TWAPSeconds, uint16 _maxTWAPTickDifference, address[] memory _swapRouterOptions) { nonfungiblePositionManager = npm; weth = IWETH9(npm.WETH9()); factory = IUniswapV3Factory(npm.factory()); // hardcoded 3 options for swap routers swapRouterOption0 = _swapRouterOptions[0]; swapRouterOption1 = _swapRouterOptions[1]; swapRouterOption2 = _swapRouterOptions[2]; emit SwapRouterChanged(0); setOperator(_operator, true); setWithdrawer(_withdrawer); setTWAPConfig(_maxTWAPTickDifference, _TWAPSeconds); } /** * @notice Owner controlled function to change swap router (onlyOwner) * @param _swapRouterIndex new swap router index */ function setSwapRouter(uint8 _swapRouterIndex) external onlyOwner { // only allow preconfigured routers if (_swapRouterIndex > 2) { revert InvalidConfig(); } emit SwapRouterChanged(_swapRouterIndex); swapRouterIndex = _swapRouterIndex; } /** * @notice Owner controlled function to set withdrawer address * @param _withdrawer withdrawer */ function setWithdrawer(address _withdrawer) public onlyOwner { emit WithdrawerChanged(_withdrawer); withdrawer = _withdrawer; } /** * @notice Owner controlled function to activate/deactivate operator address * @param _operator operator * @param _active active or not */ function setOperator(address _operator, bool _active) public onlyOwner { emit OperatorChanged(_operator, _active); operators[_operator] = _active; } /** * @notice Owner controlled function to increase TWAPSeconds / decrease maxTWAPTickDifference */ function setTWAPConfig(uint16 _maxTWAPTickDifference, uint32 _TWAPSeconds) public onlyOwner { if (_TWAPSeconds < MIN_TWAP_SECONDS) { revert InvalidConfig(); } if (_maxTWAPTickDifference > MAX_TWAP_TICK_DIFFERENCE) { revert InvalidConfig(); } emit TWAPConfigChanged(_TWAPSeconds, _maxTWAPTickDifference); TWAPSeconds = _TWAPSeconds; maxTWAPTickDifference = _maxTWAPTickDifference; } /** * @notice Withdraws token balance * @param tokens Addresses of tokens to withdraw * @param to Address to send to */ function withdrawBalances(address[] calldata tokens, address to) external { if (msg.sender != withdrawer) { revert Unauthorized(); } uint i; uint count = tokens.length; for(;i < count;++i) { uint256 balance = IERC20(tokens[i]).balanceOf(address(this)); if (balance > 0) { _transferToken(to, IERC20(tokens[i]), balance, true); } } } /** * @notice Withdraws ETH balance * @param to Address to send to */ function withdrawETH(address to) external { if (msg.sender != withdrawer) { revert Unauthorized(); } uint256 balance = address(this).balance; if (balance > 0) { (bool sent,) = to.call{value: balance}(""); if (!sent) { revert EtherSendFailed(); } } } // validate if swap can be done with specified oracle parameters - if not possible reverts // if possible returns minAmountOut function _validateSwap(bool swap0For1, uint256 amountIn, IUniswapV3Pool pool, uint32 twapPeriod, uint16 maxTickDifference, uint64 maxPriceDifferenceX64) internal view returns (uint256 amountOutMin, int24 currentTick, uint160 sqrtPriceX96, uint256 priceX96) { // get current price and tick (sqrtPriceX96,currentTick,,,,,) = pool.slot0(); // check if current tick not too far from TWAP if (!_hasMaxTWAPTickDifference(pool, twapPeriod, currentTick, maxTickDifference)) { revert TWAPCheckFailed(); } // calculate min output price price and percentage priceX96 = FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, Q96); if (swap0For1) { amountOutMin = FullMath.mulDiv(amountIn * (Q64 - maxPriceDifferenceX64), priceX96, Q96 * Q64); } else { amountOutMin = FullMath.mulDiv(amountIn * (Q64 - maxPriceDifferenceX64), Q96, priceX96 * Q64); } } // general swap function which uses external router with off-chain calculated swap instructions // does price difference check with amountOutMin param (calculated based on oracle verified price) // NOTE: can be only called from (partially) trusted context (nft owner / contract owner / operator) because otherwise swapData can be manipulated to return always amountOutMin // returns new token amounts after swap function _swap(IERC20 tokenIn, IERC20 tokenOut, uint256 amountIn, uint256 amountOutMin, bytes memory swapData) internal returns (uint256 amountInDelta, uint256 amountOutDelta) { if (amountIn > 0 && swapData.length > 0) { uint256 balanceInBefore = tokenIn.balanceOf(address(this)); uint256 balanceOutBefore = tokenOut.balanceOf(address(this)); // get router specific swap data (address allowanceTarget, bytes memory data) = abi.decode(swapData, (address, bytes)); // approve needed amount SafeERC20.safeApprove(tokenIn, allowanceTarget, amountIn); // execute swap with configured router address swapRouter = swapRouterIndex == 0 ? swapRouterOption0 : (swapRouterIndex == 1 ? swapRouterOption1 : swapRouterOption2); (bool success,) = swapRouter.call(data); if (!success) { revert SwapFailed(); } // remove any remaining allowance SafeERC20.safeApprove(tokenIn, allowanceTarget, 0); uint256 balanceInAfter = tokenIn.balanceOf(address(this)); uint256 balanceOutAfter = tokenOut.balanceOf(address(this)); amountInDelta = balanceInBefore - balanceInAfter; amountOutDelta = balanceOutAfter - balanceOutBefore; // amountMin slippage check if (amountOutDelta < amountOutMin) { revert SlippageError(); } } } // Checks if there was not more tick difference // returns false if not enough data available or tick difference >= maxDifference function _hasMaxTWAPTickDifference(IUniswapV3Pool pool, uint32 twapPeriod, int24 currentTick, uint16 maxDifference) internal view returns (bool) { (int24 twapTick, bool twapOk) = _getTWAPTick(pool, twapPeriod); if (twapOk) { return twapTick - currentTick >= -int16(maxDifference) && twapTick - currentTick <= int16(maxDifference); } else { return false; } } // gets twap tick from pool history if enough history available function _getTWAPTick(IUniswapV3Pool pool, uint32 twapPeriod) internal view returns (int24, bool) { uint32[] memory secondsAgos = new uint32[](2); secondsAgos[0] = 0; // from (before) secondsAgos[1] = twapPeriod; // from (before) // pool observe may fail when there is not enough history available try pool.observe(secondsAgos) returns (int56[] memory tickCumulatives, uint160[] memory) { return (int24((tickCumulatives[0] - tickCumulatives[1]) / int56(uint56(twapPeriod))), true); } catch { return (0, false); } } // get pool for token function _getPool( address tokenA, address tokenB, uint24 fee ) internal view returns (IUniswapV3Pool) { return IUniswapV3Pool( PoolAddress.computeAddress( address(factory), PoolAddress.getPoolKey(tokenA, tokenB, fee) ) ); } function _decreaseFullLiquidityAndCollect(uint256 tokenId, uint128 liquidity, uint256 amountRemoveMin0, uint256 amountRemoveMin1, uint256 deadline) internal returns (uint256 amount0, uint256 amount1, uint256 feeAmount0, uint256 feeAmount1) { if (liquidity > 0) { // store in temporarely "misnamed" variables - see comment below (feeAmount0, feeAmount1) = nonfungiblePositionManager.decreaseLiquidity( INonfungiblePositionManager.DecreaseLiquidityParams( tokenId, liquidity, amountRemoveMin0, amountRemoveMin1, deadline ) ); } (amount0, amount1) = nonfungiblePositionManager.collect( INonfungiblePositionManager.CollectParams( tokenId, address(this), type(uint128).max, type(uint128).max ) ); // fee amount is what was collected additionally to liquidity amount feeAmount0 = amount0 - feeAmount0; feeAmount1 = amount1 - feeAmount1; } // transfers token (or unwraps WETH and sends ETH) function _transferToken(address to, IERC20 token, uint256 amount, bool unwrap) internal { if (address(weth) == address(token) && unwrap) { weth.withdraw(amount); (bool sent, ) = to.call{value: amount}(""); if (!sent) { revert EtherSendFailed(); } } else { SafeERC20.safeTransfer(token, to, amount); } } // needed for WETH unwrapping receive() external payable { if (msg.sender != address(weth)) { revert NotWETH(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _transferOwnership(_msgSender()); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { require(owner() == _msgSender(), "Ownable: caller is not the owner"); } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-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; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } 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"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toUint248(uint256 value) internal pure returns (uint248) { require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits"); return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toUint240(uint256 value) internal pure returns (uint240) { require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits"); return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toUint232(uint256 value) internal pure returns (uint232) { require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits"); return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.2._ */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toUint216(uint256 value) internal pure returns (uint216) { require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits"); return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toUint208(uint256 value) internal pure returns (uint208) { require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits"); return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toUint200(uint256 value) internal pure returns (uint200) { require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits"); return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toUint184(uint256 value) internal pure returns (uint184) { require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits"); return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toUint176(uint256 value) internal pure returns (uint176) { require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits"); return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toUint168(uint256 value) internal pure returns (uint168) { require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits"); return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toUint160(uint256 value) internal pure returns (uint160) { require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits"); return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toUint152(uint256 value) internal pure returns (uint152) { require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits"); return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toUint144(uint256 value) internal pure returns (uint144) { require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits"); return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toUint136(uint256 value) internal pure returns (uint136) { require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits"); return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v2.5._ */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toUint120(uint256 value) internal pure returns (uint120) { require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits"); return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toUint112(uint256 value) internal pure returns (uint112) { require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits"); return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toUint104(uint256 value) internal pure returns (uint104) { require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits"); return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.2._ */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toUint88(uint256 value) internal pure returns (uint88) { require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits"); return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toUint80(uint256 value) internal pure returns (uint80) { require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits"); return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toUint72(uint256 value) internal pure returns (uint72) { require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits"); return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v2.5._ */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toUint56(uint256 value) internal pure returns (uint56) { require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits"); return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toUint48(uint256 value) internal pure returns (uint48) { require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits"); return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toUint40(uint256 value) internal pure returns (uint40) { require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits"); return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v2.5._ */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toUint24(uint256 value) internal pure returns (uint24) { require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits"); return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v2.5._ */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v2.5._ */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. * * _Available since v3.0._ */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); require(downcasted == value, "SafeCast: value doesn't fit in 248 bits"); } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); require(downcasted == value, "SafeCast: value doesn't fit in 240 bits"); } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); require(downcasted == value, "SafeCast: value doesn't fit in 232 bits"); } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.7._ */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); require(downcasted == value, "SafeCast: value doesn't fit in 224 bits"); } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); require(downcasted == value, "SafeCast: value doesn't fit in 216 bits"); } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); require(downcasted == value, "SafeCast: value doesn't fit in 208 bits"); } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); require(downcasted == value, "SafeCast: value doesn't fit in 200 bits"); } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); require(downcasted == value, "SafeCast: value doesn't fit in 192 bits"); } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); require(downcasted == value, "SafeCast: value doesn't fit in 184 bits"); } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); require(downcasted == value, "SafeCast: value doesn't fit in 176 bits"); } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); require(downcasted == value, "SafeCast: value doesn't fit in 168 bits"); } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); require(downcasted == value, "SafeCast: value doesn't fit in 160 bits"); } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); require(downcasted == value, "SafeCast: value doesn't fit in 152 bits"); } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); require(downcasted == value, "SafeCast: value doesn't fit in 144 bits"); } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); require(downcasted == value, "SafeCast: value doesn't fit in 136 bits"); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); require(downcasted == value, "SafeCast: value doesn't fit in 128 bits"); } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); require(downcasted == value, "SafeCast: value doesn't fit in 120 bits"); } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); require(downcasted == value, "SafeCast: value doesn't fit in 112 bits"); } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); require(downcasted == value, "SafeCast: value doesn't fit in 104 bits"); } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.7._ */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); require(downcasted == value, "SafeCast: value doesn't fit in 96 bits"); } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); require(downcasted == value, "SafeCast: value doesn't fit in 88 bits"); } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); require(downcasted == value, "SafeCast: value doesn't fit in 80 bits"); } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); require(downcasted == value, "SafeCast: value doesn't fit in 72 bits"); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); require(downcasted == value, "SafeCast: value doesn't fit in 64 bits"); } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); require(downcasted == value, "SafeCast: value doesn't fit in 56 bits"); } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); require(downcasted == value, "SafeCast: value doesn't fit in 48 bits"); } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); require(downcasted == value, "SafeCast: value doesn't fit in 40 bits"); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); require(downcasted == value, "SafeCast: value doesn't fit in 32 bits"); } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); require(downcasted == value, "SafeCast: value doesn't fit in 24 bits"); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); require(downcasted == value, "SafeCast: value doesn't fit in 16 bits"); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); require(downcasted == value, "SafeCast: value doesn't fit in 8 bits"); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. * * _Available since v3.0._ */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// 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; 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: 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.7.5; pragma abicoder v2; import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol'; import './IPoolInitializer.sol'; import './IERC721Permit.sol'; import './IPeripheryPayments.sol'; import './IPeripheryImmutableState.sol'; import '../libraries/PoolAddress.sol'; /// @title Non-fungible token for positions /// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred /// and authorized. interface INonfungiblePositionManager is IPoolInitializer, IPeripheryPayments, IPeripheryImmutableState, IERC721Metadata, IERC721Enumerable, IERC721Permit { /// @notice Emitted when liquidity is increased for a position NFT /// @dev Also emitted when a token is minted /// @param tokenId The ID of the token for which liquidity was increased /// @param liquidity The amount by which liquidity for the NFT position was increased /// @param amount0 The amount of token0 that was paid for the increase in liquidity /// @param amount1 The amount of token1 that was paid for the increase in liquidity event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); /// @notice Emitted when liquidity is decreased for a position NFT /// @param tokenId The ID of the token for which liquidity was decreased /// @param liquidity The amount by which liquidity for the NFT position was decreased /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); /// @notice Emitted when tokens are collected for a position NFT /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior /// @param tokenId The ID of the token for which underlying tokens were collected /// @param recipient The address of the account that received the collected tokens /// @param amount0 The amount of token0 owed to the position that was collected /// @param amount1 The amount of token1 owed to the position that was collected event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1); /// @notice Returns the position information associated with a given token ID. /// @dev Throws if the token ID is not valid. /// @param tokenId The ID of the token that represents the position /// @return nonce The nonce for permits /// @return operator The address that is approved for spending /// @return token0 The address of the token0 for a specific pool /// @return token1 The address of the token1 for a specific pool /// @return fee The fee associated with the pool /// @return tickLower The lower end of the tick range for the position /// @return tickUpper The higher end of the tick range for the position /// @return liquidity The liquidity of the position /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation function positions(uint256 tokenId) external view returns ( uint96 nonce, address operator, address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); struct MintParams { address token0; address token1; uint24 fee; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; address recipient; uint256 deadline; } /// @notice Creates a new position wrapped in a NFT /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized /// a method does not exist, i.e. the pool is assumed to be initialized. /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata /// @return tokenId The ID of the token that represents the minted position /// @return liquidity The amount of liquidity for this position /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function mint(MintParams calldata params) external payable returns ( uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1 ); struct IncreaseLiquidityParams { uint256 tokenId; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender` /// @param params tokenId The ID of the token for which liquidity is being increased, /// amount0Desired The desired amount of token0 to be spent, /// amount1Desired The desired amount of token1 to be spent, /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check, /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check, /// deadline The time by which the transaction must be included to effect the change /// @return liquidity The new liquidity amount as a result of the increase /// @return amount0 The amount of token0 to acheive resulting liquidity /// @return amount1 The amount of token1 to acheive resulting liquidity function increaseLiquidity(IncreaseLiquidityParams calldata params) external payable returns ( uint128 liquidity, uint256 amount0, uint256 amount1 ); struct DecreaseLiquidityParams { uint256 tokenId; uint128 liquidity; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Decreases the amount of liquidity in a position and accounts it to the position /// @param params tokenId The ID of the token for which liquidity is being decreased, /// amount The amount by which liquidity will be decreased, /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity, /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity, /// deadline The time by which the transaction must be included to effect the change /// @return amount0 The amount of token0 accounted to the position's tokens owed /// @return amount1 The amount of token1 accounted to the position's tokens owed function decreaseLiquidity(DecreaseLiquidityParams calldata params) external payable returns (uint256 amount0, uint256 amount1); struct CollectParams { uint256 tokenId; address recipient; uint128 amount0Max; uint128 amount1Max; } /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient /// @param params tokenId The ID of the NFT for which tokens are being collected, /// recipient The account that should receive the tokens, /// amount0Max The maximum amount of token0 to collect, /// amount1Max The maximum amount of token1 to collect /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1); /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens /// must be collected first. /// @param tokenId The ID of the token that is being burned function burn(uint256 tokenId) external payable; }
// 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 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.6.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: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-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.8.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 * ==== * * [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://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return 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.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: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.0; import "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Enumerable is IERC721 { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; /// @title Creates and initializes V3 Pools /// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that /// require the pool to exist. interface IPoolInitializer { /// @notice Creates a new pool if it does not exist, then initializes if not initialized /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool /// @param token0 The contract address of token0 of the pool /// @param token1 The contract address of token1 of the pool /// @param fee The fee amount of the v3 pool for the specified token pair /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary function createAndInitializePoolIfNecessary( address token0, address token1, uint24 fee, uint160 sqrtPriceX96 ) external payable returns (address pool); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; import '@openzeppelin/contracts/token/ERC721/IERC721.sol'; /// @title ERC721 with permit /// @notice Extension to ERC721 that includes a permit function for signature based approvals interface IERC721Permit is IERC721 { /// @notice The permit typehash used in the permit signature /// @return The typehash for the permit function PERMIT_TYPEHASH() external pure returns (bytes32); /// @notice The domain separator used in the permit signature /// @return The domain seperator used in encoding of permit signature function DOMAIN_SEPARATOR() external view returns (bytes32); /// @notice Approve of a specific token ID for spending by spender via signature /// @param spender The account that is being approved /// @param tokenId The ID of the token that is being approved for spending /// @param deadline The deadline timestamp by which the call must be mined for the approve to work /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s` /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s` /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v` function permit( address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; /// @title Periphery Payments /// @notice Functions to ease deposits and withdrawals of ETH interface IPeripheryPayments { /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH. /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users. /// @param amountMinimum The minimum amount of WETH9 to unwrap /// @param recipient The address receiving ETH function unwrapWETH9(uint256 amountMinimum, address recipient) external payable; /// @notice Refunds any ETH balance held by this contract to the `msg.sender` /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps /// that use ether for the input amount function refundETH() external payable; /// @notice Transfers the full amount of a token held by this contract to recipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users /// @param token The contract address of the token which will be transferred to `recipient` /// @param amountMinimum The minimum amount of token required for a transfer /// @param recipient The destination address of the token function sweepToken( address token, uint256 amountMinimum, address recipient ) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @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.5.0; /// @title Provides functions for deriving a pool address from the factory, tokens, and the fee library PoolAddress { bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54; /// @notice The identifying key of the pool struct PoolKey { address token0; address token1; uint24 fee; } /// @notice Returns PoolKey: the ordered tokens with the matched fee levels /// @param tokenA The first token of a pool, unsorted /// @param tokenB The second token of a pool, unsorted /// @param fee The fee level of the pool /// @return Poolkey The pool details with ordered token0 and token1 assignments function getPoolKey( address tokenA, address tokenB, uint24 fee ) internal pure returns (PoolKey memory) { if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); return PoolKey({token0: tokenA, token1: tokenB, fee: fee}); } /// @notice Deterministically computes the pool address given the factory and PoolKey /// @param factory The Uniswap V3 factory contract address /// @param key The PoolKey /// @return pool The contract address of the V3 pool function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { require(key.token0 < key.token1); pool = address( uint160( uint256( keccak256( abi.encodePacked( hex'ff', factory, keccak256(abi.encode(key.token0, key.token1, key.fee)), POOL_INIT_CODE_HASH ) ) ) ) ); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
// 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); }
{ "remappings": [ "@openzeppelin/=lib/openzeppelin-contracts/", "@uniswap/v3-core/=lib/v3-core/", "@uniswap/v3-periphery/=lib/v3-periphery/", "v3-core/=lib/v3-core/contracts/", "v3-periphery/=lib/v3-periphery/contracts/", "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"_npm","type":"address"},{"internalType":"address","name":"_operator","type":"address"},{"internalType":"address","name":"_withdrawer","type":"address"},{"internalType":"uint32","name":"_TWAPSeconds","type":"uint32"},{"internalType":"uint16","name":"_maxTWAPTickDifference","type":"uint16"},{"internalType":"address[]","name":"_swapRouterOptions","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"EtherSendFailed","type":"error"},{"inputs":[],"name":"ExceedsMaxReward","type":"error"},{"inputs":[],"name":"InvalidConfig","type":"error"},{"inputs":[],"name":"LiquidityChanged","type":"error"},{"inputs":[],"name":"MissingSwapData","type":"error"},{"inputs":[],"name":"NoLiquidity","type":"error"},{"inputs":[],"name":"NotConfigured","type":"error"},{"inputs":[],"name":"NotReady","type":"error"},{"inputs":[],"name":"NotWETH","type":"error"},{"inputs":[],"name":"SlippageError","type":"error"},{"inputs":[],"name":"SwapFailed","type":"error"},{"inputs":[],"name":"TWAPCheckFailed","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isSwap","type":"bool"},{"indexed":false,"internalType":"uint256","name":"amountReturned0","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountReturned1","type":"uint256"},{"indexed":false,"internalType":"address","name":"token0","type":"address"},{"indexed":false,"internalType":"address","name":"token1","type":"address"}],"name":"Executed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOperator","type":"address"},{"indexed":false,"internalType":"bool","name":"active","type":"bool"}],"name":"OperatorChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"bool","name":"isActive","type":"bool"},{"indexed":false,"internalType":"bool","name":"token0Swap","type":"bool"},{"indexed":false,"internalType":"bool","name":"token1Swap","type":"bool"},{"indexed":false,"internalType":"int24","name":"token0TriggerTick","type":"int24"},{"indexed":false,"internalType":"int24","name":"token1TriggerTick","type":"int24"},{"indexed":false,"internalType":"uint64","name":"token0SlippageX64","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"token1SlippageX64","type":"uint64"},{"indexed":false,"internalType":"bool","name":"onlyFees","type":"bool"},{"indexed":false,"internalType":"uint64","name":"maxRewardX64","type":"uint64"}],"name":"PositionConfigured","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"swapRouterIndex","type":"uint8"}],"name":"SwapRouterChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"TWAPSeconds","type":"uint32"},{"indexed":false,"internalType":"uint16","name":"maxTWAPTickDifference","type":"uint16"}],"name":"TWAPConfigChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newWithdrawer","type":"address"}],"name":"WithdrawerChanged","type":"event"},{"inputs":[],"name":"MAX_TWAP_TICK_DIFFERENCE","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MIN_TWAP_SECONDS","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TWAPSeconds","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"components":[{"internalType":"bool","name":"isActive","type":"bool"},{"internalType":"bool","name":"token0Swap","type":"bool"},{"internalType":"bool","name":"token1Swap","type":"bool"},{"internalType":"int24","name":"token0TriggerTick","type":"int24"},{"internalType":"int24","name":"token1TriggerTick","type":"int24"},{"internalType":"uint64","name":"token0SlippageX64","type":"uint64"},{"internalType":"uint64","name":"token1SlippageX64","type":"uint64"},{"internalType":"bool","name":"onlyFees","type":"bool"},{"internalType":"uint64","name":"maxRewardX64","type":"uint64"}],"internalType":"struct AutoExit.PositionConfig","name":"config","type":"tuple"}],"name":"configToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"swapData","type":"bytes"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"uint256","name":"amountRemoveMin0","type":"uint256"},{"internalType":"uint256","name":"amountRemoveMin1","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint64","name":"rewardX64","type":"uint64"}],"internalType":"struct AutoExit.ExecuteParams","name":"params","type":"tuple"}],"name":"execute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract IUniswapV3Factory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxTWAPTickDifference","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nonfungiblePositionManager","outputs":[{"internalType":"contract INonfungiblePositionManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"operators","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"positionConfigs","outputs":[{"internalType":"bool","name":"isActive","type":"bool"},{"internalType":"bool","name":"token0Swap","type":"bool"},{"internalType":"bool","name":"token1Swap","type":"bool"},{"internalType":"int24","name":"token0TriggerTick","type":"int24"},{"internalType":"int24","name":"token1TriggerTick","type":"int24"},{"internalType":"uint64","name":"token0SlippageX64","type":"uint64"},{"internalType":"uint64","name":"token1SlippageX64","type":"uint64"},{"internalType":"bool","name":"onlyFees","type":"bool"},{"internalType":"uint64","name":"maxRewardX64","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"},{"internalType":"bool","name":"_active","type":"bool"}],"name":"setOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"_swapRouterIndex","type":"uint8"}],"name":"setSwapRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_maxTWAPTickDifference","type":"uint16"},{"internalType":"uint32","name":"_TWAPSeconds","type":"uint32"}],"name":"setTWAPConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_withdrawer","type":"address"}],"name":"setWithdrawer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"swapRouterIndex","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapRouterOption0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapRouterOption1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapRouterOption2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"contract IWETH9","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"address","name":"to","type":"address"}],"name":"withdrawBalances","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"withdrawETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
6101406040523480156200001257600080fd5b5060405162003aa638038062003aa68339810160408190526200003591620005a2565b858585858585620000463362000247565b6001600160a01b0386166080819052604080516312a9293f60e21b81529051634aa4a4fc916004808201926020929091908290030181865afa15801562000091573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000b791906200065b565b6001600160a01b031660c0816001600160a01b031681525050856001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200010f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200013591906200065b565b6001600160a01b031660a0528051819060009062000157576200015762000682565b60200260200101516001600160a01b031660e0816001600160a01b031681525050806001815181106200018e576200018e62000682565b60200260200101516001600160a01b0316610100816001600160a01b03168152505080600281518110620001c657620001c662000682565b6020908102919091018101516001600160a01b031661012052604051600081527fc64d400644b97c7d8b5d28e4e58c64870402f168cf6e409cb18a30fe491473d5910160405180910390a16200021e85600162000297565b62000229846200030f565b62000235828462000377565b50505050505050505050505062000698565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b620002a162000453565b604080516001600160a01b038416815282151560208201527f193de8d500b5cb7b720089b258a39e9c1d0b840019a73ae7c51c3f9101732b02910160405180910390a16001600160a01b03919091166000908152600160205260409020805460ff1916911515919091179055565b6200031962000453565b6040516001600160a01b03821681527fe01f246deab125c166ce0af811ab6c9df550a5df2c09786e50c294b547555acb9060200160405180910390a1600280546001600160a01b0319166001600160a01b0392909216919091179055565b6200038162000453565b603c63ffffffff82161015620003aa576040516306b7c75960e31b815260040160405180910390fd5b60c861ffff83161115620003d1576040516306b7c75960e31b815260040160405180910390fd5b6040805163ffffffff8316815261ffff841660208201527f357caff64c051e6cfe5bc6ac50962fffbed9b9d32b95bc99bd724139c6576645910160405180910390a16002805461ffff909316600160c01b0261ffff60c01b1963ffffffff909316600160a01b029290921665ffffffffffff60a01b1990931692909217179055565b6000546001600160a01b03163314620004b25760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640160405180910390fd5b565b6001600160a01b0381168114620004ca57600080fd5b50565b8051620004da81620004b4565b919050565b634e487b7160e01b600052604160045260246000fd5b600082601f8301126200050757600080fd5b815160206001600160401b0380831115620005265762000526620004df565b8260051b604051601f19603f830116810181811084821117156200054e576200054e620004df565b6040529384528581018301938381019250878511156200056d57600080fd5b83870191505b8482101562000597576200058782620004cd565b8352918301919083019062000573565b979650505050505050565b60008060008060008060c08789031215620005bc57600080fd5b8651620005c981620004b4565b6020880151909650620005dc81620004b4565b6040880151909550620005ef81620004b4565b606088015190945063ffffffff811681146200060a57600080fd5b608088015190935061ffff811681146200062357600080fd5b60a08801519092506001600160401b038111156200064057600080fd5b6200064e89828a01620004f5565b9150509295509295509295565b6000602082840312156200066e57600080fd5b81516200067b81620004b4565b9392505050565b634e487b7160e01b600052603260045260246000fd5b60805160a05160c05160e051610100516101205161336a6200073c600039600081816104f40152611c3b0152600081816105f10152611c6101526000818161022b0152611c8701526000818161017a0152818161030101528181611e660152611eb301526000818161054801526117840152600081816104c0015281816108d701528181610f470152818161132f0152818161183f0152611915015261336a6000f3fe60806040526004361061016a5760003560e01c80638da5cb5b116100d1578063c45a01551161008a578063de14f05d11610064578063de14f05d1461059f578063eb4f36cf146105bf578063ec1eae61146105df578063f2fde38b1461061357600080fd5b8063c45a015514610536578063cdc184241461056a578063ceee8d811461058a57600080fd5b80638da5cb5b1461043d578063976b3d9e1461045b5780639ccb2eb01461047b578063b44a2722146104ae578063b619ff06146104e2578063b90d820f1461051657600080fd5b80633fc8cef3116101235780633fc8cef3146102ef578063558a72971461032357806355b86dad14610343578063690d832014610367578063715018a6146103875780637865da621461039c57600080fd5b80630d174c24146101bf5780630d334380146101df578063139cec001461021957806313e7c9d8146102655780631559e14a146102a557806331268b69146102c557600080fd5b366101ba57336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146101b857604051635724f38560e01b815260040160405180910390fd5b005b600080fd5b3480156101cb57600080fd5b506101b86101da36600461273e565b610633565b3480156101eb57600080fd5b5060025461020190600160c01b900461ffff1681565b60405161ffff90911681526020015b60405180910390f35b34801561022557600080fd5b5061024d7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610210565b34801561027157600080fd5b5061029561028036600461273e565b60016020526000908152604090205460ff1681565b6040519015158152602001610210565b3480156102b157600080fd5b506101b86102c036600461275b565b610699565b3480156102d157600080fd5b506102da603c81565b60405163ffffffff9091168152602001610210565b3480156102fb57600080fd5b5061024d7f000000000000000000000000000000000000000000000000000000000000000081565b34801561032f57600080fd5b506101b861033e3660046127a3565b611109565b34801561034f57600080fd5b506002546102da90600160a01b900463ffffffff1681565b34801561037357600080fd5b506101b861038236600461273e565b61117f565b34801561039357600080fd5b506101b861122a565b3480156103a857600080fd5b506104286103b73660046127dc565b6003602052600090815260409020805460019091015460ff80831692610100810482169262010000820483169263010000008304600290810b936601000000000000810490910b926001600160401b03600160481b8304811693600160881b8404821693600160c81b900416911689565b604051610210999897969594939291906127f5565b34801561044957600080fd5b506000546001600160a01b031661024d565b34801561046757600080fd5b506101b861047636600461285a565b61123e565b34801561048757600080fd5b5060025461049c90600160d01b900460ff1681565b60405160ff9091168152602001610210565b3480156104ba57600080fd5b5061024d7f000000000000000000000000000000000000000000000000000000000000000081565b3480156104ee57600080fd5b5061024d7f000000000000000000000000000000000000000000000000000000000000000081565b34801561052257600080fd5b506101b8610531366004612891565b611316565b34801561054257600080fd5b5061024d7f000000000000000000000000000000000000000000000000000000000000000081565b34801561057657600080fd5b5060025461024d906001600160a01b031681565b34801561059657600080fd5b506102da60c881565b3480156105ab57600080fd5b506101b86105ba3660046128da565b611506565b3480156105cb57600080fd5b506101b86105da3660046128f7565b611589565b3480156105eb57600080fd5b5061024d7f000000000000000000000000000000000000000000000000000000000000000081565b34801561061f57600080fd5b506101b861062e36600461273e565b6116a5565b61063b611723565b6040516001600160a01b03821681527fe01f246deab125c166ce0af811ab6c9df550a5df2c09786e50c294b547555acb9060200160405180910390a1600280546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526001602052604090205460ff166106c8576040516282b42960e81b815260040160405180910390fd5b6040805161026081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081018290526101c081018290526101e08101829052610200810182905261022081018290526102408101919091528135600090815260036020908152604091829020825161012081018452815460ff80821615158084526101008084048316151596850196909652620100008304821615159684019690965263010000008204600290810b606085015266010000000000008304900b60808401526001600160401b03600160481b8304811660a0850152600160881b8304811660c0850152600160c81b90920416151560e083015260019092015490911691810191909152906108305760405163d311bc3960e01b815260040160405180910390fd5b8060e00151801561086657506101008101516001600160401b031661085b60e0850160c08601612991565b6001600160401b0316115b806108a357508060e001511580156108a357506101008101516001600160401b031661089860e0850160c08601612991565b6001600160401b0316115b156108c1576040516304f7ea9360e51b815260040160405180910390fd5b60405163133f757160e31b8152833560048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906399fbab889060240161018060405180830381865afa158015610927573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061094b9190612a0b565b505050506001600160801b031660a08a01819052600291820b60808b015291900b606089015262ffffff9190911660408801526001600160a01b0391821660208801529116855260000391506109b6905057604051636180f03f60e11b815260040160405180910390fd5b6109c66060840160408501612aec565b6001600160801b03168260a001516001600160801b0316146109fb57604051638f2f3f9f60e01b815260040160405180910390fd5b610a1282600001518360200151846040015161177d565b6001600160a01b03166101a0830181905260408051633850c7bd60e01b81529051633850c7bd9160048082019260e0929091908290030181865afa158015610a5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a829190612b09565b50505050600291820b6101e08601819052606085015190920b91909113801592509050610abd5750806080015160020b826101e0015160020b125b15610adb57604051634a44555360e11b815260040160405180910390fd5b60808101516101e0830151600291820b910b1280156102208401819052610b03575080602001515b80610b1c57508161022001518015610b1c575080604001515b151561020083015260a080830151610b4691853591906060870135906080880135908801356117bd565b61012086015261010085015260e084015260c083015261020082015115610e7057610b746020840184612ba5565b9050600003610b965760405163ce97055760e01b815260040160405180910390fd5b8060e0015115610c3957600160401b610bb560e0850160c08601612991565b6001600160401b0316836101000151610bce9190612c01565b610bd89190612c36565b8260c001818151610be99190612c4a565b905250600160401b610c0160e0850160c08601612991565b6001600160401b0316836101200151610c1a9190612c01565b610c249190612c36565b8260e001818151610c359190612c4a565b9052505b816102200151610c4d578160c00151610c53565b8160e001515b6101c083018190526102208301516101a0840151600254610ca793831593909291600160a01b810463ffffffff1691600160c01b90910461ffff1690610c9d578660a001516119ac565b8660c001516119ac565b505050610140830152610220820151610d3590610cc5578251610ccb565b82602001515b836102200151610cdf578360200151610ce2565b83515b6101c0850151610140860151610cfb6020890189612ba5565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611af692505050565b610180840152610160830152610220820151610d65578161016001518260c00151610d609190612c4a565b610d7a565b8161018001518260c00151610d7a9190612c61565b60c0830152610220820151610da3578161018001518260e00151610d9e9190612c61565b610db8565b8161016001518260e00151610db89190612c4a565b60e080840191909152810151610e6b5781610220015115610e2357600160401b610de860e0850160c08601612991565b6001600160401b03168360c00151610e009190612c01565b610e0a9190612c36565b8260c001818151610e1b9190612c4a565b905250610f31565b600160401b610e3860e0850160c08601612991565b6001600160401b03168360e00151610e509190612c01565b610e5a9190612c36565b8260e001818151610e1b9190612c4a565b610f31565b600160401b610e8560e0850160c08601612991565b6001600160401b03168260e00151610ea1578360c00151610ea8565b8361010001515b610eb29190612c01565b610ebc9190612c36565b8260c001818151610ecd9190612c4a565b905250600160401b610ee560e0850160c08601612991565b6001600160401b03168260e00151610f01578360e00151610f08565b8361012001515b610f129190612c01565b610f1c9190612c36565b8260e001818151610f2d9190612c4a565b9052505b6040516331a9108f60e11b8152833560048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636352211e90602401602060405180830381865afa158015610f96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fba9190612c79565b6001600160a01b031661024083015260c082015115610fed57610fed82610240015183600001518460c001516001611e5a565b60e0820151156110115761101182610240015183602001518460e001516001611e5a565b823560008181526003602052604080822080546001600160d01b0319168155600101805467ffffffffffffffff19169055517fd6f8196cd3db6e8d20eed80c12148f2443ca7dec14495bb8676037e16551fce09161107e91819081908190819081908190819081906127f5565b60405180910390a261020082015160c08084015160e0850151855160208088015160408051338152971515928801929092529086019390935260608501919091526001600160a01b0390811660808501521660a08301528435917f52a89f8bd773b39ebe3d16a6b1be99d115c5b2b3793bc0524046c8064e1f1dc391015b60405180910390a2505050565b611111611723565b604080516001600160a01b038416815282151560208201527f193de8d500b5cb7b720089b258a39e9c1d0b840019a73ae7c51c3f9101732b02910160405180910390a16001600160a01b03919091166000908152600160205260409020805460ff1916911515919091179055565b6002546001600160a01b031633146111a9576040516282b42960e81b815260040160405180910390fd5b478015611226576000826001600160a01b03168260405160006040518083038185875af1925050503d80600081146111fd576040519150601f19603f3d011682016040523d82523d6000602084013e611202565b606091505b505090508061122457604051637cd69c3960e11b815260040160405180910390fd5b505b5050565b611232611723565b61123c6000611fa2565b565b611246611723565b603c63ffffffff8216101561126e576040516306b7c75960e31b815260040160405180910390fd5b60c861ffff83161115611294576040516306b7c75960e31b815260040160405180910390fd5b6040805163ffffffff8316815261ffff841660208201527f357caff64c051e6cfe5bc6ac50962fffbed9b9d32b95bc99bd724139c6576645910160405180910390a16002805461ffff909316600160c01b0261ffff60c01b1963ffffffff909316600160a01b029290921665ffffffffffff60a01b1990931692909217179055565b6040516331a9108f60e11b8152600481018390526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690636352211e90602401602060405180830381865afa15801561137e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113a29190612c79565b90506001600160a01b03811633146113cc576040516282b42960e81b815260040160405180910390fd5b6113d96020830183612c96565b15611422576113ee60a0830160808401612cb3565b60020b6114016080840160608501612cb3565b60020b12611422576040516306b7c75960e31b815260040160405180910390fd5b6000838152600360205260409020829061143c8282612cfd565b508390507fd6f8196cd3db6e8d20eed80c12148f2443ca7dec14495bb8676037e16551fce061146e6020850185612c96565b61147e6040860160208701612c96565b61148e6060870160408801612c96565b61149e6080880160608901612cb3565b6114ae60a0890160808a01612cb3565b6114be60c08a0160a08b01612991565b6114ce60e08b0160c08c01612991565b6114df6101008c0160e08d01612c96565b6114f16101208d016101008e01612991565b6040516110fc999897969594939291906127f5565b61150e611723565b60028160ff161115611533576040516306b7c75960e31b815260040160405180910390fd5b60405160ff821681527fc64d400644b97c7d8b5d28e4e58c64870402f168cf6e409cb18a30fe491473d59060200160405180910390a16002805460ff909216600160d01b0260ff60d01b19909216919091179055565b6002546001600160a01b031633146115b3576040516282b42960e81b815260040160405180910390fd5b6000825b8082101561169e5760008585848181106115d3576115d3612ea8565b90506020020160208101906115e8919061273e565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa15801561162e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116529190612ebe565b9050801561168d5761168d8487878681811061167057611670612ea8565b9050602002016020810190611685919061273e565b836001611e5a565b5061169782612ed7565b91506115b7565b5050505050565b6116ad611723565b6001600160a01b0381166117175760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084015b60405180910390fd5b61172081611fa2565b50565b6000546001600160a01b0316331461123c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161170e565b60006117b37f00000000000000000000000000000000000000000000000000000000000000006117ae868686611ff2565b61205d565b90505b9392505050565b60008080806001600160801b038816156118b1576040805160a0810182528a81526001600160801b03808b16602083019081528284018b8152606084018b8152608085018b81529551630624e65f60e11b8152945160048601529151909216602484015290516044830152516064820152905160848201526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690630c49ccbe9060a40160408051808303816000875af1158015611887573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ab9190612ef0565b90925090505b604080516080810182528a815230602082019081526001600160801b0382840181815260608401828152945163fc6f786560e01b81529351600485015291516001600160a01b039081166024850152915181166044840152925190921660648201527f00000000000000000000000000000000000000000000000000000000000000009091169063fc6f78659060840160408051808303816000875af115801561195f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119839190612ef0565b90945092506119928285612c4a565b915061199e8184612c4a565b905095509550955095915050565b600080600080876001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156119f0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a149190612b09565b50939750939550611a2f93508b92508a915086905089612146565b611a4c57604051634fa493cb60e01b815260040160405180910390fd5b611a646001600160a01b03831680600160601b6121ae565b90508915611aaf57611aa8611a866001600160401b038716600160401b612c4a565b611a90908b612c01565b82611aa3600160401b600160601b612c01565b6121ae565b9350611ae9565b611ae6611ac96001600160401b038716600160401b612c4a565b611ad3908b612c01565b600160601b611aa3600160401b85612c01565b93505b9650965096509692505050565b600080600085118015611b0a575060008351115b15611e50576040516370a0823160e01b81523060048201526000906001600160a01b038916906370a0823190602401602060405180830381865afa158015611b56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b7a9190612ebe565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038916906370a0823190602401602060405180830381865afa158015611bc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611be89190612ebe565b905060008086806020019051810190611c019190612f86565b91509150611c108b838b612260565b600254600090600160d01b900460ff1615611c8557600254600160d01b900460ff16600114611c5f577f0000000000000000000000000000000000000000000000000000000000000000611ca7565b7f0000000000000000000000000000000000000000000000000000000000000000611ca7565b7f00000000000000000000000000000000000000000000000000000000000000005b90506000816001600160a01b031683604051611cc3919061302f565b6000604051808303816000865af19150503d8060008114611d00576040519150601f19603f3d011682016040523d82523d6000602084013e611d05565b606091505b5050905080611d275760405163081ceff360e41b815260040160405180910390fd5b611d338d856000612260565b6040516370a0823160e01b81523060048201526000906001600160a01b038f16906370a0823190602401602060405180830381865afa158015611d7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d9e9190612ebe565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038f16906370a0823190602401602060405180830381865afa158015611de8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0c9190612ebe565b9050611e188289612c4a565b9950611e248782612c4a565b98508b891015611e4757604051630d4205a160e11b815260040160405180910390fd5b50505050505050505b9550959350505050565b826001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316148015611e985750805b15611f9157604051632e1a7d4d60e01b8152600481018390527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015611eff57600080fd5b505af1158015611f13573d6000803e3d6000fd5b505050506000846001600160a01b03168360405160006040518083038185875af1925050503d8060008114611f64576040519150601f19603f3d011682016040523d82523d6000602084013e611f69565b606091505b5050905080611f8b57604051637cd69c3960e11b815260040160405180910390fd5b50611f9c565b611f9c8385846123a8565b50505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040805160608101825260008082526020820181905291810191909152826001600160a01b0316846001600160a01b0316111561202d579192915b50604080516060810182526001600160a01b03948516815292909316602083015262ffffff169181019190915290565b600081602001516001600160a01b031682600001516001600160a01b03161061208557600080fd5b815160208084015160408086015181516001600160a01b0395861681860152949092168482015262ffffff90911660608085019190915281518085038201815260808501909252815191909201206001600160f81b031960a08401529085901b6bffffffffffffffffffffffff191660a183015260b58201527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460d582015260f50160408051601f1981840301815291905280516020909101209392505050565b600080600061215587876123d8565b91509150801561219f576121688461304b565b60010b612175868461306c565b60020b121580156121965750600184900b612190868461306c565b60020b13155b925050506121a6565b6000925050505b949350505050565b60008080600019858709858702925082811083820303915050806000036121e757600084116121dc57600080fd5b5082900490506117b6565b8084116121f357600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b8015806122da5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa1580156122b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122d89190612ebe565b155b6123455760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606482015260840161170e565b6040516001600160a01b03831660248201526044810182905261122490849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612534565b6040516001600160a01b03831660248201526044810182905261122490849063a9059cbb60e01b90606401612371565b60408051600280825260608201835260009283928392909160208301908036833701905050905060008160008151811061241457612414612ea8565b602002602001019063ffffffff16908163ffffffff1681525050838160018151811061244257612442612ea8565b63ffffffff9092166020928302919091019091015260405163883bdbfd60e01b81526001600160a01b0386169063883bdbfd906124839084906004016130b4565b600060405180830381865afa9250505080156124c157506040513d6000823e601f3d908101601f191682016040526124be9190810190613195565b60015b6124d257600080925092505061252d565b8563ffffffff16826001815181106124ec576124ec612ea8565b60200260200101518360008151811061250757612507612ea8565b60200260200101516125199190613260565b61252391906132a6565b6001945094505050505b9250929050565b6000612589826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166126069092919063ffffffff16565b80519091501561122457808060200190518101906125a791906132e4565b6112245760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161170e565b60606117b3848460008585600080866001600160a01b0316858760405161262d919061302f565b60006040518083038185875af1925050503d806000811461266a576040519150601f19603f3d011682016040523d82523d6000602084013e61266f565b606091505b50915091506126808783838761268b565b979650505050505050565b606083156126fa5782516000036126f3576001600160a01b0385163b6126f35760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161170e565b50816121a6565b6121a6838381511561270f5781518083602001fd5b8060405162461bcd60e51b815260040161170e9190613301565b6001600160a01b038116811461172057600080fd5b60006020828403121561275057600080fd5b81356117b681612729565b60006020828403121561276d57600080fd5b81356001600160401b0381111561278357600080fd5b820160e081850312156117b657600080fd5b801515811461172057600080fd5b600080604083850312156127b657600080fd5b82356127c181612729565b915060208301356127d181612795565b809150509250929050565b6000602082840312156127ee57600080fd5b5035919050565b981515895296151560208901529415156040880152600293840b60608801529190920b60808601526001600160401b0391821660a0860152811660c085015290151560e0840152166101008201526101200190565b61ffff8116811461172057600080fd5b6000806040838503121561286d57600080fd5b82356128788161284a565b9150602083013563ffffffff811681146127d157600080fd5b6000808284036101408112156128a657600080fd5b83359250610120601f19820112156128bd57600080fd5b506020830190509250929050565b60ff8116811461172057600080fd5b6000602082840312156128ec57600080fd5b81356117b6816128cb565b60008060006040848603121561290c57600080fd5b83356001600160401b038082111561292357600080fd5b818601915086601f83011261293757600080fd5b81358181111561294657600080fd5b8760208260051b850101111561295b57600080fd5b6020928301955093505084013561297181612729565b809150509250925092565b6001600160401b038116811461172057600080fd5b6000602082840312156129a357600080fd5b81356117b68161297c565b80516129b981612729565b919050565b805162ffffff811681146129b957600080fd5b8060020b811461172057600080fd5b80516129b9816129d1565b6001600160801b038116811461172057600080fd5b80516129b9816129eb565b6000806000806000806000806000806000806101808d8f031215612a2e57600080fd5b8c516bffffffffffffffffffffffff81168114612a4a57600080fd5b9b50612a5860208e016129ae565b9a50612a6660408e016129ae565b9950612a7460608e016129ae565b9850612a8260808e016129be565b9750612a9060a08e016129e0565b9650612a9e60c08e016129e0565b9550612aac60e08e01612a00565b94506101008d015193506101208d01519250612acb6101408e01612a00565b9150612ada6101608e01612a00565b90509295989b509295989b509295989b565b600060208284031215612afe57600080fd5b81356117b6816129eb565b600080600080600080600060e0888a031215612b2457600080fd5b8751612b2f81612729565b6020890151909750612b40816129d1565b6040890151909650612b518161284a565b6060890151909550612b628161284a565b6080890151909450612b738161284a565b60a0890151909350612b84816128cb565b60c0890151909250612b9581612795565b8091505092959891949750929550565b6000808335601e19843603018112612bbc57600080fd5b8301803591506001600160401b03821115612bd657600080fd5b60200191503681900382131561252d57600080fd5b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615612c1b57612c1b612beb565b500290565b634e487b7160e01b600052601260045260246000fd5b600082612c4557612c45612c20565b500490565b600082821015612c5c57612c5c612beb565b500390565b60008219821115612c7457612c74612beb565b500190565b600060208284031215612c8b57600080fd5b81516117b681612729565b600060208284031215612ca857600080fd5b81356117b681612795565b600060208284031215612cc557600080fd5b81356117b6816129d1565b60008135612cdd81612795565b92915050565b60008135612cdd816129d1565b60008135612cdd8161297c565b8135612d0881612795565b815490151560ff1660ff19919091161781556020820135612d2881612795565b815461ff00191681151560081b61ff001617825550612d68612d4c60408401612cd0565b82805462ff0000191691151560101b62ff000016919091179055565b612d97612d7760608401612ce3565b825460189190911b65ffffff0000001665ffffff00000019909116178255565b612dcc612da660808401612ce3565b825460309190911b68ffffff0000000000001668ffffff00000000000019909116178255565b612e0f612ddb60a08401612cf0565b825470ffffffffffffffff000000000000000000191660489190911b70ffffffffffffffff00000000000000000016178255565b612e4a612e1e60c08401612cf0565b82805467ffffffffffffffff60881b191660889290921b67ffffffffffffffff60881b16919091179055565b612e77612e5960e08401612cd0565b82805460ff60c81b191691151560c81b60ff60c81b16919091179055565b611226612e876101008401612cf0565b600183016001600160401b0382166001600160401b03198254161781555050565b634e487b7160e01b600052603260045260246000fd5b600060208284031215612ed057600080fd5b5051919050565b600060018201612ee957612ee9612beb565b5060010190565b60008060408385031215612f0357600080fd5b505080516020909101519092909150565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715612f5257612f52612f14565b604052919050565b60005b83811015612f75578181015183820152602001612f5d565b83811115611f9c5750506000910152565b60008060408385031215612f9957600080fd5b8251612fa481612729565b60208401519092506001600160401b0380821115612fc157600080fd5b818501915085601f830112612fd557600080fd5b815181811115612fe757612fe7612f14565b612ffa601f8201601f1916602001612f2a565b915080825286602082850101111561301157600080fd5b613022816020840160208601612f5a565b5080925050509250929050565b60008251613041818460208701612f5a565b9190910192915050565b60008160010b617fff19810361306357613063612beb565b60000392915050565b60008160020b8360020b6000811281627fffff190183128115161561309357613093612beb565b81627fffff0183138116156130aa576130aa612beb565b5090039392505050565b6020808252825182820181905260009190848201906040850190845b818110156130f257835163ffffffff16835292840192918401916001016130d0565b50909695505050505050565b60006001600160401b0382111561311757613117612f14565b5060051b60200190565b600082601f83011261313257600080fd5b81516020613147613142836130fe565b612f2a565b82815260059290921b8401810191818101908684111561316657600080fd5b8286015b8481101561318a57805161317d81612729565b835291830191830161316a565b509695505050505050565b600080604083850312156131a857600080fd5b82516001600160401b03808211156131bf57600080fd5b818501915085601f8301126131d357600080fd5b815160206131e3613142836130fe565b82815260059290921b8401810191818101908984111561320257600080fd5b948201945b838610156132305785518060060b81146132215760008081fd5b82529482019490820190613207565b9188015191965090935050508082111561324957600080fd5b5061325685828601613121565b9150509250929050565b60008160060b8360060b6000811281667fffffffffffff190183128115161561328b5761328b612beb565b81667fffffffffffff0183138116156130aa576130aa612beb565b60008160060b8360060b806132bd576132bd612c20565b667fffffffffffff198214600019821416156132db576132db612beb565b90059392505050565b6000602082840312156132f657600080fd5b81516117b681612795565b6020815260008251806020840152613320816040850160208701612f5a565b601f01601f1916919091016040019291505056fea2646970667358221220dafc8dce87e9f3af650b8d3a3e806d6087b006618a9991fcf33af924d99e7fa964736f6c634300080f0033000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88000000000000000000000000bb1a1a2773a799d83078ae4d59d9f4b2b6ac50ff000000000000000000000000bb1a1a2773a799d83078ae4d59d9f4b2b6ac50ff000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000003000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45
Deployed Bytecode
0x60806040526004361061016a5760003560e01c80638da5cb5b116100d1578063c45a01551161008a578063de14f05d11610064578063de14f05d1461059f578063eb4f36cf146105bf578063ec1eae61146105df578063f2fde38b1461061357600080fd5b8063c45a015514610536578063cdc184241461056a578063ceee8d811461058a57600080fd5b80638da5cb5b1461043d578063976b3d9e1461045b5780639ccb2eb01461047b578063b44a2722146104ae578063b619ff06146104e2578063b90d820f1461051657600080fd5b80633fc8cef3116101235780633fc8cef3146102ef578063558a72971461032357806355b86dad14610343578063690d832014610367578063715018a6146103875780637865da621461039c57600080fd5b80630d174c24146101bf5780630d334380146101df578063139cec001461021957806313e7c9d8146102655780631559e14a146102a557806331268b69146102c557600080fd5b366101ba57336001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216146101b857604051635724f38560e01b815260040160405180910390fd5b005b600080fd5b3480156101cb57600080fd5b506101b86101da36600461273e565b610633565b3480156101eb57600080fd5b5060025461020190600160c01b900461ffff1681565b60405161ffff90911681526020015b60405180910390f35b34801561022557600080fd5b5061024d7f000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff81565b6040516001600160a01b039091168152602001610210565b34801561027157600080fd5b5061029561028036600461273e565b60016020526000908152604090205460ff1681565b6040519015158152602001610210565b3480156102b157600080fd5b506101b86102c036600461275b565b610699565b3480156102d157600080fd5b506102da603c81565b60405163ffffffff9091168152602001610210565b3480156102fb57600080fd5b5061024d7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b34801561032f57600080fd5b506101b861033e3660046127a3565b611109565b34801561034f57600080fd5b506002546102da90600160a01b900463ffffffff1681565b34801561037357600080fd5b506101b861038236600461273e565b61117f565b34801561039357600080fd5b506101b861122a565b3480156103a857600080fd5b506104286103b73660046127dc565b6003602052600090815260409020805460019091015460ff80831692610100810482169262010000820483169263010000008304600290810b936601000000000000810490910b926001600160401b03600160481b8304811693600160881b8404821693600160c81b900416911689565b604051610210999897969594939291906127f5565b34801561044957600080fd5b506000546001600160a01b031661024d565b34801561046757600080fd5b506101b861047636600461285a565b61123e565b34801561048757600080fd5b5060025461049c90600160d01b900460ff1681565b60405160ff9091168152602001610210565b3480156104ba57600080fd5b5061024d7f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe8881565b3480156104ee57600080fd5b5061024d7f00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc4581565b34801561052257600080fd5b506101b8610531366004612891565b611316565b34801561054257600080fd5b5061024d7f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f98481565b34801561057657600080fd5b5060025461024d906001600160a01b031681565b34801561059657600080fd5b506102da60c881565b3480156105ab57600080fd5b506101b86105ba3660046128da565b611506565b3480156105cb57600080fd5b506101b86105da3660046128f7565b611589565b3480156105eb57600080fd5b5061024d7f0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad81565b34801561061f57600080fd5b506101b861062e36600461273e565b6116a5565b61063b611723565b6040516001600160a01b03821681527fe01f246deab125c166ce0af811ab6c9df550a5df2c09786e50c294b547555acb9060200160405180910390a1600280546001600160a01b0319166001600160a01b0392909216919091179055565b3360009081526001602052604090205460ff166106c8576040516282b42960e81b815260040160405180910390fd5b6040805161026081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081018290526101c081018290526101e08101829052610200810182905261022081018290526102408101919091528135600090815260036020908152604091829020825161012081018452815460ff80821615158084526101008084048316151596850196909652620100008304821615159684019690965263010000008204600290810b606085015266010000000000008304900b60808401526001600160401b03600160481b8304811660a0850152600160881b8304811660c0850152600160c81b90920416151560e083015260019092015490911691810191909152906108305760405163d311bc3960e01b815260040160405180910390fd5b8060e00151801561086657506101008101516001600160401b031661085b60e0850160c08601612991565b6001600160401b0316115b806108a357508060e001511580156108a357506101008101516001600160401b031661089860e0850160c08601612991565b6001600160401b0316115b156108c1576040516304f7ea9360e51b815260040160405180910390fd5b60405163133f757160e31b8152833560048201527f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b0316906399fbab889060240161018060405180830381865afa158015610927573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061094b9190612a0b565b505050506001600160801b031660a08a01819052600291820b60808b015291900b606089015262ffffff9190911660408801526001600160a01b0391821660208801529116855260000391506109b6905057604051636180f03f60e11b815260040160405180910390fd5b6109c66060840160408501612aec565b6001600160801b03168260a001516001600160801b0316146109fb57604051638f2f3f9f60e01b815260040160405180910390fd5b610a1282600001518360200151846040015161177d565b6001600160a01b03166101a0830181905260408051633850c7bd60e01b81529051633850c7bd9160048082019260e0929091908290030181865afa158015610a5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a829190612b09565b50505050600291820b6101e08601819052606085015190920b91909113801592509050610abd5750806080015160020b826101e0015160020b125b15610adb57604051634a44555360e11b815260040160405180910390fd5b60808101516101e0830151600291820b910b1280156102208401819052610b03575080602001515b80610b1c57508161022001518015610b1c575080604001515b151561020083015260a080830151610b4691853591906060870135906080880135908801356117bd565b61012086015261010085015260e084015260c083015261020082015115610e7057610b746020840184612ba5565b9050600003610b965760405163ce97055760e01b815260040160405180910390fd5b8060e0015115610c3957600160401b610bb560e0850160c08601612991565b6001600160401b0316836101000151610bce9190612c01565b610bd89190612c36565b8260c001818151610be99190612c4a565b905250600160401b610c0160e0850160c08601612991565b6001600160401b0316836101200151610c1a9190612c01565b610c249190612c36565b8260e001818151610c359190612c4a565b9052505b816102200151610c4d578160c00151610c53565b8160e001515b6101c083018190526102208301516101a0840151600254610ca793831593909291600160a01b810463ffffffff1691600160c01b90910461ffff1690610c9d578660a001516119ac565b8660c001516119ac565b505050610140830152610220820151610d3590610cc5578251610ccb565b82602001515b836102200151610cdf578360200151610ce2565b83515b6101c0850151610140860151610cfb6020890189612ba5565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611af692505050565b610180840152610160830152610220820151610d65578161016001518260c00151610d609190612c4a565b610d7a565b8161018001518260c00151610d7a9190612c61565b60c0830152610220820151610da3578161018001518260e00151610d9e9190612c61565b610db8565b8161016001518260e00151610db89190612c4a565b60e080840191909152810151610e6b5781610220015115610e2357600160401b610de860e0850160c08601612991565b6001600160401b03168360c00151610e009190612c01565b610e0a9190612c36565b8260c001818151610e1b9190612c4a565b905250610f31565b600160401b610e3860e0850160c08601612991565b6001600160401b03168360e00151610e509190612c01565b610e5a9190612c36565b8260e001818151610e1b9190612c4a565b610f31565b600160401b610e8560e0850160c08601612991565b6001600160401b03168260e00151610ea1578360c00151610ea8565b8361010001515b610eb29190612c01565b610ebc9190612c36565b8260c001818151610ecd9190612c4a565b905250600160401b610ee560e0850160c08601612991565b6001600160401b03168260e00151610f01578360e00151610f08565b8361012001515b610f129190612c01565b610f1c9190612c36565b8260e001818151610f2d9190612c4a565b9052505b6040516331a9108f60e11b8152833560048201527f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b031690636352211e90602401602060405180830381865afa158015610f96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fba9190612c79565b6001600160a01b031661024083015260c082015115610fed57610fed82610240015183600001518460c001516001611e5a565b60e0820151156110115761101182610240015183602001518460e001516001611e5a565b823560008181526003602052604080822080546001600160d01b0319168155600101805467ffffffffffffffff19169055517fd6f8196cd3db6e8d20eed80c12148f2443ca7dec14495bb8676037e16551fce09161107e91819081908190819081908190819081906127f5565b60405180910390a261020082015160c08084015160e0850151855160208088015160408051338152971515928801929092529086019390935260608501919091526001600160a01b0390811660808501521660a08301528435917f52a89f8bd773b39ebe3d16a6b1be99d115c5b2b3793bc0524046c8064e1f1dc391015b60405180910390a2505050565b611111611723565b604080516001600160a01b038416815282151560208201527f193de8d500b5cb7b720089b258a39e9c1d0b840019a73ae7c51c3f9101732b02910160405180910390a16001600160a01b03919091166000908152600160205260409020805460ff1916911515919091179055565b6002546001600160a01b031633146111a9576040516282b42960e81b815260040160405180910390fd5b478015611226576000826001600160a01b03168260405160006040518083038185875af1925050503d80600081146111fd576040519150601f19603f3d011682016040523d82523d6000602084013e611202565b606091505b505090508061122457604051637cd69c3960e11b815260040160405180910390fd5b505b5050565b611232611723565b61123c6000611fa2565b565b611246611723565b603c63ffffffff8216101561126e576040516306b7c75960e31b815260040160405180910390fd5b60c861ffff83161115611294576040516306b7c75960e31b815260040160405180910390fd5b6040805163ffffffff8316815261ffff841660208201527f357caff64c051e6cfe5bc6ac50962fffbed9b9d32b95bc99bd724139c6576645910160405180910390a16002805461ffff909316600160c01b0261ffff60c01b1963ffffffff909316600160a01b029290921665ffffffffffff60a01b1990931692909217179055565b6040516331a9108f60e11b8152600481018390526000907f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe886001600160a01b031690636352211e90602401602060405180830381865afa15801561137e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113a29190612c79565b90506001600160a01b03811633146113cc576040516282b42960e81b815260040160405180910390fd5b6113d96020830183612c96565b15611422576113ee60a0830160808401612cb3565b60020b6114016080840160608501612cb3565b60020b12611422576040516306b7c75960e31b815260040160405180910390fd5b6000838152600360205260409020829061143c8282612cfd565b508390507fd6f8196cd3db6e8d20eed80c12148f2443ca7dec14495bb8676037e16551fce061146e6020850185612c96565b61147e6040860160208701612c96565b61148e6060870160408801612c96565b61149e6080880160608901612cb3565b6114ae60a0890160808a01612cb3565b6114be60c08a0160a08b01612991565b6114ce60e08b0160c08c01612991565b6114df6101008c0160e08d01612c96565b6114f16101208d016101008e01612991565b6040516110fc999897969594939291906127f5565b61150e611723565b60028160ff161115611533576040516306b7c75960e31b815260040160405180910390fd5b60405160ff821681527fc64d400644b97c7d8b5d28e4e58c64870402f168cf6e409cb18a30fe491473d59060200160405180910390a16002805460ff909216600160d01b0260ff60d01b19909216919091179055565b6002546001600160a01b031633146115b3576040516282b42960e81b815260040160405180910390fd5b6000825b8082101561169e5760008585848181106115d3576115d3612ea8565b90506020020160208101906115e8919061273e565b6040516370a0823160e01b81523060048201526001600160a01b0391909116906370a0823190602401602060405180830381865afa15801561162e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116529190612ebe565b9050801561168d5761168d8487878681811061167057611670612ea8565b9050602002016020810190611685919061273e565b836001611e5a565b5061169782612ed7565b91506115b7565b5050505050565b6116ad611723565b6001600160a01b0381166117175760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084015b60405180910390fd5b61172081611fa2565b50565b6000546001600160a01b0316331461123c5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161170e565b60006117b37f0000000000000000000000001f98431c8ad98523631ae4a59f267346ea31f9846117ae868686611ff2565b61205d565b90505b9392505050565b60008080806001600160801b038816156118b1576040805160a0810182528a81526001600160801b03808b16602083019081528284018b8152606084018b8152608085018b81529551630624e65f60e11b8152945160048601529151909216602484015290516044830152516064820152905160848201526001600160a01b037f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe881690630c49ccbe9060a40160408051808303816000875af1158015611887573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118ab9190612ef0565b90925090505b604080516080810182528a815230602082019081526001600160801b0382840181815260608401828152945163fc6f786560e01b81529351600485015291516001600160a01b039081166024850152915181166044840152925190921660648201527f000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe889091169063fc6f78659060840160408051808303816000875af115801561195f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119839190612ef0565b90945092506119928285612c4a565b915061199e8184612c4a565b905095509550955095915050565b600080600080876001600160a01b0316633850c7bd6040518163ffffffff1660e01b815260040160e060405180830381865afa1580156119f0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a149190612b09565b50939750939550611a2f93508b92508a915086905089612146565b611a4c57604051634fa493cb60e01b815260040160405180910390fd5b611a646001600160a01b03831680600160601b6121ae565b90508915611aaf57611aa8611a866001600160401b038716600160401b612c4a565b611a90908b612c01565b82611aa3600160401b600160601b612c01565b6121ae565b9350611ae9565b611ae6611ac96001600160401b038716600160401b612c4a565b611ad3908b612c01565b600160601b611aa3600160401b85612c01565b93505b9650965096509692505050565b600080600085118015611b0a575060008351115b15611e50576040516370a0823160e01b81523060048201526000906001600160a01b038916906370a0823190602401602060405180830381865afa158015611b56573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b7a9190612ebe565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038916906370a0823190602401602060405180830381865afa158015611bc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611be89190612ebe565b905060008086806020019051810190611c019190612f86565b91509150611c108b838b612260565b600254600090600160d01b900460ff1615611c8557600254600160d01b900460ff16600114611c5f577f00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45611ca7565b7f0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad611ca7565b7f000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff5b90506000816001600160a01b031683604051611cc3919061302f565b6000604051808303816000865af19150503d8060008114611d00576040519150601f19603f3d011682016040523d82523d6000602084013e611d05565b606091505b5050905080611d275760405163081ceff360e41b815260040160405180910390fd5b611d338d856000612260565b6040516370a0823160e01b81523060048201526000906001600160a01b038f16906370a0823190602401602060405180830381865afa158015611d7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d9e9190612ebe565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038f16906370a0823190602401602060405180830381865afa158015611de8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e0c9190612ebe565b9050611e188289612c4a565b9950611e248782612c4a565b98508b891015611e4757604051630d4205a160e11b815260040160405180910390fd5b50505050505050505b9550959350505050565b826001600160a01b03167f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316148015611e985750805b15611f9157604051632e1a7d4d60e01b8152600481018390527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015611eff57600080fd5b505af1158015611f13573d6000803e3d6000fd5b505050506000846001600160a01b03168360405160006040518083038185875af1925050503d8060008114611f64576040519150601f19603f3d011682016040523d82523d6000602084013e611f69565b606091505b5050905080611f8b57604051637cd69c3960e11b815260040160405180910390fd5b50611f9c565b611f9c8385846123a8565b50505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040805160608101825260008082526020820181905291810191909152826001600160a01b0316846001600160a01b0316111561202d579192915b50604080516060810182526001600160a01b03948516815292909316602083015262ffffff169181019190915290565b600081602001516001600160a01b031682600001516001600160a01b03161061208557600080fd5b815160208084015160408086015181516001600160a01b0395861681860152949092168482015262ffffff90911660608085019190915281518085038201815260808501909252815191909201206001600160f81b031960a08401529085901b6bffffffffffffffffffffffff191660a183015260b58201527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460d582015260f50160408051601f1981840301815291905280516020909101209392505050565b600080600061215587876123d8565b91509150801561219f576121688461304b565b60010b612175868461306c565b60020b121580156121965750600184900b612190868461306c565b60020b13155b925050506121a6565b6000925050505b949350505050565b60008080600019858709858702925082811083820303915050806000036121e757600084116121dc57600080fd5b5082900490506117b6565b8084116121f357600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b8015806122da5750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa1580156122b4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122d89190612ebe565b155b6123455760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606482015260840161170e565b6040516001600160a01b03831660248201526044810182905261122490849063095ea7b360e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612534565b6040516001600160a01b03831660248201526044810182905261122490849063a9059cbb60e01b90606401612371565b60408051600280825260608201835260009283928392909160208301908036833701905050905060008160008151811061241457612414612ea8565b602002602001019063ffffffff16908163ffffffff1681525050838160018151811061244257612442612ea8565b63ffffffff9092166020928302919091019091015260405163883bdbfd60e01b81526001600160a01b0386169063883bdbfd906124839084906004016130b4565b600060405180830381865afa9250505080156124c157506040513d6000823e601f3d908101601f191682016040526124be9190810190613195565b60015b6124d257600080925092505061252d565b8563ffffffff16826001815181106124ec576124ec612ea8565b60200260200101518360008151811061250757612507612ea8565b60200260200101516125199190613260565b61252391906132a6565b6001945094505050505b9250929050565b6000612589826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166126069092919063ffffffff16565b80519091501561122457808060200190518101906125a791906132e4565b6112245760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161170e565b60606117b3848460008585600080866001600160a01b0316858760405161262d919061302f565b60006040518083038185875af1925050503d806000811461266a576040519150601f19603f3d011682016040523d82523d6000602084013e61266f565b606091505b50915091506126808783838761268b565b979650505050505050565b606083156126fa5782516000036126f3576001600160a01b0385163b6126f35760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161170e565b50816121a6565b6121a6838381511561270f5781518083602001fd5b8060405162461bcd60e51b815260040161170e9190613301565b6001600160a01b038116811461172057600080fd5b60006020828403121561275057600080fd5b81356117b681612729565b60006020828403121561276d57600080fd5b81356001600160401b0381111561278357600080fd5b820160e081850312156117b657600080fd5b801515811461172057600080fd5b600080604083850312156127b657600080fd5b82356127c181612729565b915060208301356127d181612795565b809150509250929050565b6000602082840312156127ee57600080fd5b5035919050565b981515895296151560208901529415156040880152600293840b60608801529190920b60808601526001600160401b0391821660a0860152811660c085015290151560e0840152166101008201526101200190565b61ffff8116811461172057600080fd5b6000806040838503121561286d57600080fd5b82356128788161284a565b9150602083013563ffffffff811681146127d157600080fd5b6000808284036101408112156128a657600080fd5b83359250610120601f19820112156128bd57600080fd5b506020830190509250929050565b60ff8116811461172057600080fd5b6000602082840312156128ec57600080fd5b81356117b6816128cb565b60008060006040848603121561290c57600080fd5b83356001600160401b038082111561292357600080fd5b818601915086601f83011261293757600080fd5b81358181111561294657600080fd5b8760208260051b850101111561295b57600080fd5b6020928301955093505084013561297181612729565b809150509250925092565b6001600160401b038116811461172057600080fd5b6000602082840312156129a357600080fd5b81356117b68161297c565b80516129b981612729565b919050565b805162ffffff811681146129b957600080fd5b8060020b811461172057600080fd5b80516129b9816129d1565b6001600160801b038116811461172057600080fd5b80516129b9816129eb565b6000806000806000806000806000806000806101808d8f031215612a2e57600080fd5b8c516bffffffffffffffffffffffff81168114612a4a57600080fd5b9b50612a5860208e016129ae565b9a50612a6660408e016129ae565b9950612a7460608e016129ae565b9850612a8260808e016129be565b9750612a9060a08e016129e0565b9650612a9e60c08e016129e0565b9550612aac60e08e01612a00565b94506101008d015193506101208d01519250612acb6101408e01612a00565b9150612ada6101608e01612a00565b90509295989b509295989b509295989b565b600060208284031215612afe57600080fd5b81356117b6816129eb565b600080600080600080600060e0888a031215612b2457600080fd5b8751612b2f81612729565b6020890151909750612b40816129d1565b6040890151909650612b518161284a565b6060890151909550612b628161284a565b6080890151909450612b738161284a565b60a0890151909350612b84816128cb565b60c0890151909250612b9581612795565b8091505092959891949750929550565b6000808335601e19843603018112612bbc57600080fd5b8301803591506001600160401b03821115612bd657600080fd5b60200191503681900382131561252d57600080fd5b634e487b7160e01b600052601160045260246000fd5b6000816000190483118215151615612c1b57612c1b612beb565b500290565b634e487b7160e01b600052601260045260246000fd5b600082612c4557612c45612c20565b500490565b600082821015612c5c57612c5c612beb565b500390565b60008219821115612c7457612c74612beb565b500190565b600060208284031215612c8b57600080fd5b81516117b681612729565b600060208284031215612ca857600080fd5b81356117b681612795565b600060208284031215612cc557600080fd5b81356117b6816129d1565b60008135612cdd81612795565b92915050565b60008135612cdd816129d1565b60008135612cdd8161297c565b8135612d0881612795565b815490151560ff1660ff19919091161781556020820135612d2881612795565b815461ff00191681151560081b61ff001617825550612d68612d4c60408401612cd0565b82805462ff0000191691151560101b62ff000016919091179055565b612d97612d7760608401612ce3565b825460189190911b65ffffff0000001665ffffff00000019909116178255565b612dcc612da660808401612ce3565b825460309190911b68ffffff0000000000001668ffffff00000000000019909116178255565b612e0f612ddb60a08401612cf0565b825470ffffffffffffffff000000000000000000191660489190911b70ffffffffffffffff00000000000000000016178255565b612e4a612e1e60c08401612cf0565b82805467ffffffffffffffff60881b191660889290921b67ffffffffffffffff60881b16919091179055565b612e77612e5960e08401612cd0565b82805460ff60c81b191691151560c81b60ff60c81b16919091179055565b611226612e876101008401612cf0565b600183016001600160401b0382166001600160401b03198254161781555050565b634e487b7160e01b600052603260045260246000fd5b600060208284031215612ed057600080fd5b5051919050565b600060018201612ee957612ee9612beb565b5060010190565b60008060408385031215612f0357600080fd5b505080516020909101519092909150565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715612f5257612f52612f14565b604052919050565b60005b83811015612f75578181015183820152602001612f5d565b83811115611f9c5750506000910152565b60008060408385031215612f9957600080fd5b8251612fa481612729565b60208401519092506001600160401b0380821115612fc157600080fd5b818501915085601f830112612fd557600080fd5b815181811115612fe757612fe7612f14565b612ffa601f8201601f1916602001612f2a565b915080825286602082850101111561301157600080fd5b613022816020840160208601612f5a565b5080925050509250929050565b60008251613041818460208701612f5a565b9190910192915050565b60008160010b617fff19810361306357613063612beb565b60000392915050565b60008160020b8360020b6000811281627fffff190183128115161561309357613093612beb565b81627fffff0183138116156130aa576130aa612beb565b5090039392505050565b6020808252825182820181905260009190848201906040850190845b818110156130f257835163ffffffff16835292840192918401916001016130d0565b50909695505050505050565b60006001600160401b0382111561311757613117612f14565b5060051b60200190565b600082601f83011261313257600080fd5b81516020613147613142836130fe565b612f2a565b82815260059290921b8401810191818101908684111561316657600080fd5b8286015b8481101561318a57805161317d81612729565b835291830191830161316a565b509695505050505050565b600080604083850312156131a857600080fd5b82516001600160401b03808211156131bf57600080fd5b818501915085601f8301126131d357600080fd5b815160206131e3613142836130fe565b82815260059290921b8401810191818101908984111561320257600080fd5b948201945b838610156132305785518060060b81146132215760008081fd5b82529482019490820190613207565b9188015191965090935050508082111561324957600080fd5b5061325685828601613121565b9150509250929050565b60008160060b8360060b6000811281667fffffffffffff190183128115161561328b5761328b612beb565b81667fffffffffffff0183138116156130aa576130aa612beb565b60008160060b8360060b806132bd576132bd612c20565b667fffffffffffff198214600019821416156132db576132db612beb565b90059392505050565b6000602082840312156132f657600080fd5b81516117b681612795565b6020815260008251806020840152613320816040850160208701612f5a565b601f01601f1916919091016040019291505056fea2646970667358221220dafc8dce87e9f3af650b8d3a3e806d6087b006618a9991fcf33af924d99e7fa964736f6c634300080f0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88000000000000000000000000bb1a1a2773a799d83078ae4d59d9f4b2b6ac50ff000000000000000000000000bb1a1a2773a799d83078ae4d59d9f4b2b6ac50ff000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000006400000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000003000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45
-----Decoded View---------------
Arg [0] : _npm (address): 0xC36442b4a4522E871399CD717aBDD847Ab11FE88
Arg [1] : _operator (address): 0xBb1A1a2773a799D83078ae4d59d9F4B2B6aC50fF
Arg [2] : _withdrawer (address): 0xBb1A1a2773a799D83078ae4d59d9F4B2B6aC50fF
Arg [3] : _TWAPSeconds (uint32): 60
Arg [4] : _maxTWAPTickDifference (uint16): 100
Arg [5] : _swapRouterOptions (address[]): 0xDef1C0ded9bec7F1a1670819833240f027b25EfF,0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD,0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45
-----Encoded View---------------
10 Constructor Arguments found :
Arg [0] : 000000000000000000000000c36442b4a4522e871399cd717abdd847ab11fe88
Arg [1] : 000000000000000000000000bb1a1a2773a799d83078ae4d59d9f4b2b6ac50ff
Arg [2] : 000000000000000000000000bb1a1a2773a799d83078ae4d59d9f4b2b6ac50ff
Arg [3] : 000000000000000000000000000000000000000000000000000000000000003c
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000064
Arg [5] : 00000000000000000000000000000000000000000000000000000000000000c0
Arg [6] : 0000000000000000000000000000000000000000000000000000000000000003
Arg [7] : 000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff
Arg [8] : 0000000000000000000000003fc91a3afd70395cd496c647d5a6cc9d4b2b7fad
Arg [9] : 00000000000000000000000068b3465833fb72a70ecdf485e0e4c7bd8665fc45
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ 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.