Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 427 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Multicall | 21663209 | 6 days ago | IN | 0 ETH | 0.01068287 | ||||
Multicall | 21663110 | 6 days ago | IN | 0 ETH | 0.01142085 | ||||
Multicall | 21644920 | 8 days ago | IN | 0 ETH | 0.00545881 | ||||
Multicall | 21644916 | 8 days ago | IN | 0 ETH | 0.00714401 | ||||
Multicall | 21639759 | 9 days ago | IN | 0 ETH | 0.00355128 | ||||
Multicall | 21638641 | 9 days ago | IN | 0 ETH | 0.00654738 | ||||
Multicall | 21638562 | 9 days ago | IN | 0 ETH | 0.00579968 | ||||
Multicall | 21638085 | 9 days ago | IN | 0 ETH | 0.00482648 | ||||
Multicall | 21637954 | 9 days ago | IN | 0 ETH | 0.00965308 | ||||
Multicall | 21624096 | 11 days ago | IN | 0 ETH | 0.01058176 | ||||
Multicall | 21618570 | 12 days ago | IN | 0 ETH | 0.00461264 | ||||
Multicall | 21612907 | 13 days ago | IN | 0 ETH | 0.00124563 | ||||
Multicall | 21576472 | 18 days ago | IN | 0 ETH | 0.00274075 | ||||
Multicall | 21569194 | 19 days ago | IN | 0 ETH | 0.00467157 | ||||
Multicall | 21567186 | 19 days ago | IN | 0 ETH | 0.02725454 | ||||
Multicall | 21566103 | 19 days ago | IN | 0 ETH | 0.02125175 | ||||
Multicall | 21563660 | 19 days ago | IN | 0 ETH | 0.01409252 | ||||
Multicall | 21546904 | 22 days ago | IN | 0 ETH | 0.00726699 | ||||
Multicall | 21540503 | 23 days ago | IN | 0 ETH | 0.00685765 | ||||
Multicall | 21514159 | 26 days ago | IN | 0 ETH | 0.00202441 | ||||
Multicall | 21505424 | 28 days ago | IN | 0 ETH | 0.00189978 | ||||
Multicall | 21505310 | 28 days ago | IN | 0 ETH | 0.00211283 | ||||
Multicall | 21485240 | 30 days ago | IN | 0 ETH | 0.00320349 | ||||
Multicall | 21485034 | 30 days ago | IN | 0 ETH | 0.0037105 | ||||
Multicall | 21474091 | 32 days ago | IN | 1.00001248 ETH | 0.07096275 |
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block |
From
|
To
|
|||
---|---|---|---|---|---|---|
21474091 | 32 days ago | 0.00001 ETH | ||||
21474091 | 32 days ago | 1.00000248 ETH | ||||
21474091 | 32 days ago | 0 ETH | ||||
21397140 | 43 days ago | 0.00000004 ETH | ||||
21397140 | 43 days ago | 0.00468561 ETH | ||||
21314998 | 54 days ago | 0.00001673 ETH | ||||
21314998 | 54 days ago | 1.67309633 ETH | ||||
21279391 | 59 days ago | 0.00000114 ETH | ||||
21279391 | 59 days ago | 0.11434135 ETH | ||||
21276130 | 60 days ago | 0.00000301 ETH | ||||
21276130 | 60 days ago | 0.30145497 ETH | ||||
21267326 | 61 days ago | 0.00000098 ETH | ||||
21267326 | 61 days ago | 0.09844316 ETH | ||||
21252714 | 63 days ago | 0.00000011 ETH | ||||
21252714 | 63 days ago | 0.01147822 ETH | ||||
21243352 | 64 days ago | 0.00000063 ETH | ||||
21243352 | 64 days ago | 0.06313388 ETH | ||||
21243352 | 64 days ago | 0 ETH | ||||
21196240 | 71 days ago | 0.00003167 ETH | ||||
21196054 | 71 days ago | 0 ETH | ||||
21196054 | 71 days ago | 0.00031674 ETH | ||||
21187641 | 72 days ago | 0.00052947 ETH | ||||
21187641 | 72 days ago | 52.947 ETH | ||||
21149591 | 77 days ago | 0.00000035 ETH | ||||
21149591 | 77 days ago | 0.03500089 ETH |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
MaverickV2RewardRouter
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 5500 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IMaverickV2Factory} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Factory.sol"; import {MaverickV2LiquidityManager} from "@maverick/v2-supplemental/contracts/MaverickV2LiquidityManager.sol"; import {IMaverickV2PoolLens} from "@maverick/v2-supplemental/contracts/interfaces/IMaverickV2PoolLens.sol"; import {IMaverickV2BoostedPosition} from "@maverick/v2-supplemental/contracts/interfaces/IMaverickV2BoostedPosition.sol"; import {IWETH9} from "@maverick/v2-supplemental/contracts/paymentbase/IWETH9.sol"; import {IMaverickV2Position} from "@maverick/v2-supplemental/contracts/interfaces/IMaverickV2Position.sol"; import {IMaverickV2BoostedPositionFactory} from "@maverick/v2-supplemental/contracts/interfaces/IMaverickV2BoostedPositionFactory.sol"; import {IMaverickV2Reward} from "./interfaces/IMaverickV2Reward.sol"; import {IMaverickV2RewardRouter} from "./interfaces/IMaverickV2RewardRouter.sol"; import {IMaverickV2RewardFactory} from "./interfaces/IMaverickV2RewardFactory.sol"; import {IMaverickV2VotingEscrow} from "./interfaces/IMaverickV2VotingEscrow.sol"; import {IMaverickV2VotingEscrowWSync} from "./interfaces/IMaverickV2VotingEscrowWSync.sol"; /** * @notice Liquidity and Reward contract to facilitate multi-step interactions * with adding and staking liquidity in Maverick V2. This contracts inherits * all of the functionality of `MaverickV2LiquidityManager` that allows the * creation of pools and BPs and adds mechanisms to interact with the various * reward and ve functionality that are present in v2-rewards. All of the * functions are specified as `payable` to enable multicall transactions that * involve functions that require ETH and those that do not. */ contract MaverickV2RewardRouter is IMaverickV2RewardRouter, MaverickV2LiquidityManager { using SafeERC20 for IERC20; /// @inheritdoc IMaverickV2RewardRouter IMaverickV2RewardFactory public immutable rewardFactory; constructor( IMaverickV2Factory _factory, IWETH9 _weth, IMaverickV2Position _position, IMaverickV2BoostedPositionFactory _boostedPositionFactory, IMaverickV2RewardFactory _rewardFactory ) MaverickV2LiquidityManager(_factory, _weth, _position, _boostedPositionFactory) { rewardFactory = _rewardFactory; } /// @inheritdoc IMaverickV2RewardRouter function stake( IMaverickV2Reward reward, uint256 tokenId ) public payable returns (uint256 amount, uint256 stakedTokenId) { stakedTokenId = tokenId; if (stakedTokenId == 0) { if (reward.tokenOfOwnerByIndexExists(msg.sender, 0)) { stakedTokenId = reward.tokenOfOwnerByIndex(msg.sender, 0); } else { stakedTokenId = reward.mint(msg.sender); } } return reward.stake(stakedTokenId); } /// @inheritdoc IMaverickV2RewardRouter function transferAndStake( IMaverickV2Reward reward, uint256 tokenId, uint256 _amount ) public payable returns (uint256 amount, uint256 stakedTokenId) { reward.stakingToken().safeTransferFrom(msg.sender, address(reward.vault()), _amount); return stake(reward, tokenId); } /// @inheritdoc IMaverickV2RewardRouter function notifyRewardAmount( IMaverickV2Reward reward, IERC20 rewardToken, uint256 duration ) public payable returns (uint256 _duration) { return reward.notifyRewardAmount(rewardToken, duration); } /// @inheritdoc IMaverickV2RewardRouter function transferAndNotifyRewardAmount( IMaverickV2Reward reward, IERC20 rewardToken, uint256 duration, uint256 amount ) public payable returns (uint256 _duration) { rewardToken.safeTransferFrom(msg.sender, address(reward), amount); return reward.notifyRewardAmount(rewardToken, duration); } /// @inheritdoc IMaverickV2RewardRouter function createBoostedPositionAndAddLiquidityAndStake( address recipient, IMaverickV2PoolLens.CreateBoostedPositionInputs memory params, IERC20[] memory rewardTokens, IMaverickV2VotingEscrow[] memory veTokens ) public payable returns ( IMaverickV2BoostedPosition boostedPosition, uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount, uint256 stakeAmount, IMaverickV2Reward reward, uint256 tokenId ) { (boostedPosition, mintedLpAmount, tokenAAmount, tokenBAmount) = createBoostedPositionAndAddLiquidity( address(this), params ); reward = rewardFactory.createRewardsContract(boostedPosition, rewardTokens, veTokens); tokenId = reward.mint(recipient); boostedPosition.transfer(address(reward.vault()), boostedPosition.balanceOf(address(this))); (stakeAmount, ) = reward.stake(tokenId); } /// @inheritdoc IMaverickV2RewardRouter function createBoostedPositionAndAddLiquidityAndStakeToSender( IMaverickV2PoolLens.CreateBoostedPositionInputs memory params, IERC20[] memory rewardTokens, IMaverickV2VotingEscrow[] memory veTokens ) public payable returns ( IMaverickV2BoostedPosition boostedPosition, uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount, uint256 stakeAmount, IMaverickV2Reward reward, uint256 tokenId ) { return createBoostedPositionAndAddLiquidityAndStake(msg.sender, params, rewardTokens, veTokens); } /// @inheritdoc IMaverickV2RewardRouter function addLiquidityAndMintBoostedPositionAndStake( uint256 tokenId, IMaverickV2BoostedPosition boostedPosition, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs, IMaverickV2Reward reward ) public payable returns (uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount, uint256 stakeAmount) { (mintedLpAmount, tokenAAmount, tokenBAmount) = addLiquidityAndMintBoostedPosition( address(reward.vault()), boostedPosition, packedSqrtPriceBreaks, packedArgs ); (stakeAmount, ) = reward.stake(tokenId); } /// @inheritdoc IMaverickV2RewardRouter function addLiquidityAndMintBoostedPositionAndStakeToSender( uint256 sendersTokenIndex, IMaverickV2BoostedPosition boostedPosition, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs, IMaverickV2Reward reward ) public payable returns ( uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount, uint256 stakeAmount, uint256 tokenId ) { if (reward.tokenOfOwnerByIndexExists(msg.sender, sendersTokenIndex)) { tokenId = reward.tokenOfOwnerByIndex(msg.sender, sendersTokenIndex); } else { tokenId = reward.mint(msg.sender); } (mintedLpAmount, tokenAAmount, tokenBAmount, stakeAmount) = addLiquidityAndMintBoostedPositionAndStake( tokenId, boostedPosition, packedSqrtPriceBreaks, packedArgs, reward ); } function mintTokenInRewardToSender(IMaverickV2Reward reward) public payable returns (uint256 tokenId) { tokenId = reward.mint(msg.sender); } function mintTokenInReward(IMaverickV2Reward reward, address recipient) public payable returns (uint256 tokenId) { tokenId = reward.mint(recipient); } /// @inheritdoc IMaverickV2RewardRouter function sync( IMaverickV2VotingEscrowWSync ve, address staker, uint256[] memory legacyLockupIndexes ) public returns (uint256[] memory newBalance) { uint256 length = legacyLockupIndexes.length; newBalance = new uint256[](length); for (uint256 k; k < length; k++) { newBalance[k] = ve.sync(staker, k); } } }
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; interface IMulticall { function multicall(bytes[] calldata data) external returns (bytes[] memory results); }
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; interface IPayableMulticall { function multicall(bytes[] calldata data) external payable returns (bytes[] memory results); }
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; import {IPayableMulticall} from "./IPayableMulticall.sol"; import {Address} from "@openzeppelin/contracts/utils/Address.sol"; // Modified from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/6ba452dea4258afe77726293435f10baf2bed265/contracts/utils/Multicall.sol /* * @notice Payable multicall; requires all functions in the multicall to also be * payable. */ abstract contract PayableMulticall is IPayableMulticall { /** * @dev This function allows multiple calls to different contract functions * in a single transaction. * @param data An array of encoded function call data. * @return results An array of the results of the function calls. */ function multicall(bytes[] calldata data) external payable returns (bytes[] memory results) { results = new bytes[](data.length); for (uint256 i = 0; i < data.length; i++) { results[i] = Address.functionDelegateCall(address(this), data[i]); } } }
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IMaverickV2Pool} from "./IMaverickV2Pool.sol"; interface IMaverickV2Factory { error FactoryInvalidProtocolFeeRatio(uint8 protocolFeeRatioD3); error FactoryInvalidLendingFeeRate(uint256 protocolLendingFeeRateD18); error FactoryProtocolFeeOnRenounce(uint8 protocolFeeRatioD3); error FactorAlreadyInitialized(); error FactorNotInitialized(); error FactoryInvalidTokenOrder(IERC20 _tokenA, IERC20 _tokenB); error FactoryInvalidFee(); error FactoryInvalidKinds(uint8 kinds); error FactoryInvalidTickSpacing(uint256 tickSpacing); error FactoryInvalidLookback(uint256 lookback); error FactoryInvalidTokenDecimals(uint8 decimalsA, uint8 decimalsB); error FactoryPoolAlreadyExists( uint256 feeAIn, uint256 feeBIn, uint256 tickSpacing, uint256 lookback, IERC20 tokenA, IERC20 tokenB, uint8 kinds, address accessor ); error FactoryAccessorMustBeNonZero(); event PoolCreated( IMaverickV2Pool poolAddress, uint8 protocolFeeRatio, uint256 feeAIn, uint256 feeBIn, uint256 tickSpacing, uint256 lookback, int32 activeTick, IERC20 tokenA, IERC20 tokenB, uint8 kinds, address accessor ); event SetFactoryProtocolFeeRatio(uint8 protocolFeeRatioD3); event SetFactoryProtocolLendingFeeRate(uint256 lendingFeeRateD18); event SetFactoryProtocolFeeReceiver(address receiver); struct DeployParameters { uint64 feeAIn; uint64 feeBIn; uint32 lookback; int32 activeTick; uint64 tokenAScale; uint64 tokenBScale; // slot IERC20 tokenA; // slot IERC20 tokenB; // slot uint16 tickSpacing; uint8 options; address accessor; } /** * @notice Called by deployer library to initialize a pool. */ function deployParameters() external view returns ( uint64 feeAIn, uint64 feeBIn, uint32 lookback, int32 activeTick, uint64 tokenAScale, uint64 tokenBScale, // slot IERC20 tokenA, // slot IERC20 tokenB, // slot uint16 tickSpacing, uint8 options, address accessor ); /** * @notice Create a new MaverickV2Pool with symmetric swap fees. * @param fee Fraction of the pool swap amount that is retained as an LP in * D18 scale. * @param tickSpacing Tick spacing of pool where 1.0001^tickSpacing is the * bin width. * @param lookback Pool lookback in seconds. * @param tokenA Address of tokenA. * @param tokenB Address of tokenB. * @param activeTick Tick position that contains the active bins. * @param kinds 1-15 number to represent the active kinds * 0b0001 = static; * 0b0010 = right; * 0b0100 = left; * 0b1000 = both. * E.g. a pool with all 4 modes will have kinds = b1111 = 15 */ function create( uint64 fee, uint16 tickSpacing, uint32 lookback, IERC20 tokenA, IERC20 tokenB, int32 activeTick, uint8 kinds ) external returns (IMaverickV2Pool); /** * @notice Create a new MaverickV2Pool. * @param feeAIn Fraction of the pool swap amount for tokenA-input swaps * that is retained as an LP in D18 scale. * @param feeBIn Fraction of the pool swap amount for tokenB-input swaps * that is retained as an LP in D18 scale. * @param tickSpacing Tick spacing of pool where 1.0001^tickSpacing is the * bin width. * @param lookback Pool lookback in seconds. * @param tokenA Address of tokenA. * @param tokenB Address of tokenB. * @param activeTick Tick position that contains the active bins. * @param kinds 1-15 number to represent the active kinds * 0b0001 = static; * 0b0010 = right; * 0b0100 = left; * 0b1000 = both. * e.g. a pool with all 4 modes will have kinds = b1111 = 15 */ function create( uint64 feeAIn, uint64 feeBIn, uint16 tickSpacing, uint32 lookback, IERC20 tokenA, IERC20 tokenB, int32 activeTick, uint8 kinds ) external returns (IMaverickV2Pool); /** * @notice Create a new MaverickV2PoolPermissioned with symmetric swap fees * with all functions permissioned. Set fee to zero to make the pool fee settable by the accessor. * @param fee Fraction of the pool swap amount that is retained as an LP in * D18 scale. * @param tickSpacing Tick spacing of pool where 1.0001^tickSpacing is the * bin width. * @param lookback Pool lookback in seconds. * @param tokenA Address of tokenA. * @param tokenB Address of tokenB. * @param activeTick Tick position that contains the active bins. * @param kinds 1-15 number to represent the active kinds * 0b0001 = static; * 0b0010 = right; * 0b0100 = left; * 0b1000 = both. * E.g. a pool with all 4 modes will have kinds = b1111 = 15 * @param accessor Only address that can access the pool's public write functions. */ function createPermissioned( uint64 fee, uint16 tickSpacing, uint32 lookback, IERC20 tokenA, IERC20 tokenB, int32 activeTick, uint8 kinds, address accessor ) external returns (IMaverickV2Pool); /** * @notice Create a new MaverickV2PoolPermissioned with all functions * permissioned. Set fees to zero to make the pool fee settable by the * accessor. * @param feeAIn Fraction of the pool swap amount for tokenA-input swaps * that is retained as an LP in D18 scale. * @param feeBIn Fraction of the pool swap amount for tokenB-input swaps * that is retained as an LP in D18 scale. * @param tickSpacing Tick spacing of pool where 1.0001^tickSpacing is the * bin width. * @param lookback Pool lookback in seconds. * @param tokenA Address of tokenA. * @param tokenB Address of tokenB. * @param activeTick Tick position that contains the active bins. * @param kinds 1-15 number to represent the active kinds * 0b0001 = static; * 0b0010 = right; * 0b0100 = left; * 0b1000 = both. * E.g. a pool with all 4 modes will have kinds = b1111 = 15 * @param accessor only address that can access the pool's public write functions. */ function createPermissioned( uint64 feeAIn, uint64 feeBIn, uint16 tickSpacing, uint32 lookback, IERC20 tokenA, IERC20 tokenB, int32 activeTick, uint8 kinds, address accessor ) external returns (IMaverickV2Pool); /** * @notice Create a new MaverickV2PoolPermissioned with the option to make * a subset of function permissionless. Set fee to zero to make the pool * fee settable by the accessor. * @param feeAIn Fraction of the pool swap amount for tokenA-input swaps * that is retained as an LP in D18 scale. * @param feeBIn Fraction of the pool swap amount for tokenB-input swaps * that is retained as an LP in D18 scale. * @param tickSpacing Tick spacing of pool where 1.0001^tickSpacing is the * bin width. * @param lookback Pool lookback in seconds. * @param tokenA Address of tokenA. * @param tokenB Address of tokenB. * @param activeTick Tick position that contains the active bins. * @param kinds 1-15 number to represent the active kinds * 0b0001 = static; * 0b0010 = right; * 0b0100 = left; * 0b1000 = both. * E.g. a pool with all 4 modes will have kinds = b1111 = 15 * @param accessor only address that can access the pool's public permissioned write functions. * @param permissionedLiquidity If true, then only accessor can call * pool's liquidity management functions: `flashLoan`, * `migrateBinsUpstack`, `addLiquidity`, `removeLiquidity`. * @param permissionedSwap If true, then only accessor can call * pool's swap function. */ function createPermissioned( uint64 feeAIn, uint64 feeBIn, uint16 tickSpacing, uint32 lookback, IERC20 tokenA, IERC20 tokenB, int32 activeTick, uint8 kinds, address accessor, bool permissionedLiquidity, bool permissionedSwap ) external returns (IMaverickV2Pool pool); /** * @notice Update the protocol fee ratio for a pool. Can be called * permissionlessly allowing any user to sync the pool protocol fee value * with the factory protocol fee value. * @param pool The pool for which to update. */ function updateProtocolFeeRatioForPool(IMaverickV2Pool pool) external; /** * @notice Update the protocol lending fee rate for a pool. Can be called * permissionlessly allowing any user to sync the pool protocol lending fee * rate value with the factory value. * @param pool The pool for which to update. */ function updateProtocolLendingFeeRateForPool(IMaverickV2Pool pool) external; /** * @notice Claim protocol fee for a pool and transfer it to the protocolFeeReceiver. * @param pool The pool from which to claim the protocol fee. * @param isTokenA A boolean indicating whether tokenA (true) or tokenB * (false) is being collected. */ function claimProtocolFeeForPool(IMaverickV2Pool pool, bool isTokenA) external; /** * @notice Claim protocol fee for a pool and transfer it to the protocolFeeReceiver. * @param pool The pool from which to claim the protocol fee. */ function claimProtocolFeeForPool(IMaverickV2Pool pool) external; /** * @notice Bool indicating whether the pool was deployed from this factory. */ function isFactoryPool(IMaverickV2Pool pool) external view returns (bool); /** * @notice Address that receives the protocol fee when users call * `claimProtocolFeeForPool`. */ function protocolFeeReceiver() external view returns (address); /** * @notice Lookup a pool for given parameters. * * @dev options bit map of kinds and function permissions * 0b000001 = static; * 0b000010 = right; * 0b000100 = left; * 0b001000 = both; * 0b010000 = liquidity functions are permissioned * 0b100000 = swap function is permissioned */ function lookupPermissioned( uint256 feeAIn, uint256 feeBIn, uint256 tickSpacing, uint256 lookback, IERC20 tokenA, IERC20 tokenB, uint8 options, address accessor ) external view returns (IMaverickV2Pool); /** * @notice Lookup a pool for given parameters. */ function lookupPermissioned( IERC20 _tokenA, IERC20 _tokenB, address accessor, uint256 startIndex, uint256 endIndex ) external view returns (IMaverickV2Pool[] memory pools); /** * @notice Lookup a pool for given parameters. */ function lookupPermissioned( uint256 startIndex, uint256 endIndex ) external view returns (IMaverickV2Pool[] memory pools); /** * @notice Lookup a pool for given parameters. */ function lookup( uint256 feeAIn, uint256 feeBIn, uint256 tickSpacing, uint256 lookback, IERC20 tokenA, IERC20 tokenB, uint8 kinds ) external view returns (IMaverickV2Pool); /** * @notice Lookup a pool for given parameters. */ function lookup( IERC20 _tokenA, IERC20 _tokenB, uint256 startIndex, uint256 endIndex ) external view returns (IMaverickV2Pool[] memory pools); /** * @notice Lookup a pool for given parameters. */ function lookup(uint256 startIndex, uint256 endIndex) external view returns (IMaverickV2Pool[] memory pools); /** * @notice Count of permissionless pools. */ function poolCount() external view returns (uint256 _poolCount); /** * @notice Count of permissioned pools. */ function poolPermissionedCount() external view returns (uint256 _poolCount); /** * @notice Count of pools for a given accessor and token pair. For * permissionless pools, pass `accessor = address(0)`. */ function poolByTokenCount( IERC20 _tokenA, IERC20 _tokenB, address accessor ) external view returns (uint256 _poolCount); /** * @notice Get the current factory owner. */ function owner() external view returns (address); /** * @notice Proportion of protocol fee to collect on each swap. Value is in * 3-decimal format with a maximum value of 0.25e3. */ function protocolFeeRatioD3() external view returns (uint8); /** * @notice Fee rate charged by the protocol for flashloans. Value is in * 18-decimal format with a maximum value of 0.02e18. */ function protocolLendingFeeRateD18() external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IMaverickV2Factory} from "./IMaverickV2Factory.sol"; interface IMaverickV2Pool { error PoolZeroLiquidityAdded(); error PoolMinimumLiquidityNotMet(); error PoolLocked(); error PoolInvalidFee(); error PoolTicksNotSorted(uint256 index, int256 previousTick, int256 tick); error PoolTicksAmountsLengthMismatch(uint256 ticksLength, uint256 amountsLength); error PoolBinIdsAmountsLengthMismatch(uint256 binIdsLength, uint256 amountsLength); error PoolKindNotSupported(uint256 kinds, uint256 kind); error PoolInsufficientBalance(uint256 deltaLpAmount, uint256 accountBalance); error PoolReservesExceedMaximum(uint256 amount); error PoolValueExceedsBits(uint256 amount, uint256 bits); error PoolTickMaxExceeded(uint256 tick); error PoolMigrateBinFirst(); error PoolCurrentTickBeyondSwapLimit(int32 startingTick); error PoolSenderNotAccessor(address sender_, address accessor); error PoolSenderNotFactory(address sender_, address accessor); error PoolFunctionNotImplemented(); error PoolTokenNotSolvent(uint256 internalReserve, uint256 tokenBalance, IERC20 token); event PoolSwap(address sender, address recipient, SwapParams params, uint256 amountIn, uint256 amountOut); event PoolAddLiquidity( address sender, address recipient, uint256 subaccount, AddLiquidityParams params, uint256 tokenAAmount, uint256 tokenBAmount, uint32[] binIds ); event PoolMigrateBinsUpStack(address sender, uint32 binId, uint32 maxRecursion); event PoolRemoveLiquidity( address sender, address recipient, uint256 subaccount, RemoveLiquidityParams params, uint256 tokenAOut, uint256 tokenBOut ); event PoolSetVariableFee(uint256 newFeeAIn, uint256 newFeeBIn); /** * @notice Tick state parameters. */ struct TickState { uint128 reserveA; uint128 reserveB; uint128 totalSupply; uint32[4] binIdsByTick; } /** * @notice Tick data parameters. * @param currentReserveA Current reserve of token A. * @param currentReserveB Current reserve of token B. * @param currentLiquidity Current liquidity amount. */ struct TickData { uint256 currentReserveA; uint256 currentReserveB; uint256 currentLiquidity; } /** * @notice Bin state parameters. * @param mergeBinBalance LP token balance that this bin possesses of the merge bin. * @param mergeId Bin ID of the bin that this bin has merged into. * @param totalSupply Total amount of LP tokens in this bin. * @param kind One of the 4 kinds (0=static, 1=right, 2=left, 3=both). * @param tick The lower price tick of the bin in its current state. * @param tickBalance Balance of the tick. */ struct BinState { uint128 mergeBinBalance; uint128 tickBalance; uint128 totalSupply; uint8 kind; int32 tick; uint32 mergeId; } /** * @notice Parameters for swap. * @param amount Amount of the token that is either the input if exactOutput is false * or the output if exactOutput is true. * @param tokenAIn Boolean indicating whether tokenA is the input. * @param exactOutput Boolean indicating whether the amount specified is * the exact output amount (true). * @param tickLimit The furthest tick a swap will execute in. If no limit * is desired, value should be set to type(int32).max for a tokenAIn swap * and type(int32).min for a swap where tokenB is the input. */ struct SwapParams { uint256 amount; bool tokenAIn; bool exactOutput; int32 tickLimit; } /** * @notice Parameters associated with adding liquidity. * @param kind One of the 4 kinds (0=static, 1=right, 2=left, 3=both). * @param ticks Array of ticks to add liquidity to. * @param amounts Array of bin LP amounts to add. */ struct AddLiquidityParams { uint8 kind; int32[] ticks; uint128[] amounts; } /** * @notice Parameters for each bin that will have liquidity removed. * @param binIds Index array of the bins losing liquidity. * @param amounts Array of bin LP amounts to remove. */ struct RemoveLiquidityParams { uint32[] binIds; uint128[] amounts; } /** * @notice State of the pool. * @param reserveA Pool tokenA balanceOf at end of last operation * @param reserveB Pool tokenB balanceOf at end of last operation * @param lastTwaD8 Value of log time weighted average price at last block. * Value is 8-decimal scale and is in the fractional tick domain. E.g. a * value of 12.3e8 indicates the TWAP was 3/10ths of the way into the 12th * tick. * @param lastLogPriceD8 Value of log price at last block. Value is * 8-decimal scale and is in the fractional tick domain. E.g. a value of * 12.3e8 indicates the price was 3/10ths of the way into the 12th tick. * @param lastTimestamp Last block.timestamp value in seconds for latest * swap transaction. * @param activeTick Current tick position that contains the active bins. * @param isLocked Pool isLocked, E.g., locked or unlocked; isLocked values * defined in Pool.sol. * @param binCounter Index of the last bin created. * @param protocolFeeRatioD3 Ratio of the swap fee that is kept for the * protocol. */ struct State { uint128 reserveA; uint128 reserveB; int64 lastTwaD8; int64 lastLogPriceD8; uint40 lastTimestamp; int32 activeTick; bool isLocked; uint32 binCounter; uint8 protocolFeeRatioD3; } /** * @notice Internal data used for data passing between Pool and Bin code. */ struct BinDelta { uint128 deltaA; uint128 deltaB; } /** * @notice 1-15 number to represent the active kinds. * @notice 0b0001 = static; * @notice 0b0010 = right; * @notice 0b0100 = left; * @notice 0b1000 = both; * * E.g. a pool with all 4 modes will have kinds = b1111 = 15 */ function kinds() external view returns (uint8 _kinds); /** * @notice Returns whether a pool has permissioned functions. If true, the * `accessor()` of the pool can set the pool fees. Other functions in the * pool may also be permissioned; whether or not they are can be determined * through calls to `permissionedLiquidity()` and `permissionedSwap()`. */ function permissionedPool() external view returns (bool _permissionedPool); /** * @notice Returns whether a pool has permissioned liquidity management * functions. If true, the pool is incompatible with permissioned pool * liquidity management infrastructure. */ function permissionedLiquidity() external view returns (bool _permissionedLiquidity); /** * @notice Returns whether a pool has a permissioned swap functions. If * true, the pool is incompatible with permissioned pool swap router * infrastructure. */ function permissionedSwap() external view returns (bool _permissionedSwap); /** * @notice Pool swap fee for the given direction (A-in or B-in swap) in * 18-decimal format. E.g. 0.01e18 is a 1% swap fee. */ function fee(bool tokenAIn) external view returns (uint256); /** * @notice TickSpacing of pool where 1.0001^tickSpacing is the bin width. */ function tickSpacing() external view returns (uint256); /** * @notice Lookback period of pool in seconds. */ function lookback() external view returns (uint256); /** * @notice Address of Pool accessor. This is Zero address for * permissionless pools. */ function accessor() external view returns (address); /** * @notice Pool tokenA. Address of tokenA is such that tokenA < tokenB. */ function tokenA() external view returns (IERC20); /** * @notice Pool tokenB. */ function tokenB() external view returns (IERC20); /** * @notice Deploying factory of the pool and also contract that has ability * to set and collect protocol fees for the pool. */ function factory() external view returns (IMaverickV2Factory); /** * @notice Most significant bit of scale value is a flag to indicate whether * tokenA has more or less than 18 decimals. Scale is used in conjuction * with Math.toScale/Math.fromScale functions to convert from token amounts * to D18 scale internal pool accounting. */ function tokenAScale() external view returns (uint256); /** * @notice Most significant bit of scale value is a flag to indicate whether * tokenA has more or less than 18 decimals. Scale is used in conjuction * with Math.toScale/Math.fromScale functions to convert from token amounts * to D18 scale internal pool accounting. */ function tokenBScale() external view returns (uint256); /** * @notice ID of bin at input tick position and kind. */ function binIdByTickKind(int32 tick, uint256 kind) external view returns (uint32); /** * @notice Accumulated tokenA protocol fee. */ function protocolFeeA() external view returns (uint128); /** * @notice Accumulated tokenB protocol fee. */ function protocolFeeB() external view returns (uint128); /** * @notice Lending fee rate on flash loans. */ function lendingFeeRateD18() external view returns (uint256); /** * @notice External function to get the current time-weighted average price. */ function getCurrentTwa() external view returns (int256); /** * @notice External function to get the state of the pool. */ function getState() external view returns (State memory); /** * @notice Return state of Bin at input binId. */ function getBin(uint32 binId) external view returns (BinState memory bin); /** * @notice Return state of Tick at input tick position. */ function getTick(int32 tick) external view returns (TickState memory tickState); /** * @notice Retrieves the balance of a user within a bin. * @param user The user's address. * @param subaccount The subaccount for the user. * @param binId The ID of the bin. */ function balanceOf(address user, uint256 subaccount, uint32 binId) external view returns (uint128 lpToken); /** * @notice Add liquidity to a pool. This function allows users to deposit * tokens into a liquidity pool. * @dev This function will call `maverickV2AddLiquidityCallback` on the * calling contract to collect the tokenA/tokenB payment. * @param recipient The account that will receive credit for the added liquidity. * @param subaccount The account that will receive credit for the added liquidity. * @param params Parameters containing the details for adding liquidity, * such as token types and amounts. * @param data Bytes information that gets passed to the callback. * @return tokenAAmount The amount of token A added to the pool. * @return tokenBAmount The amount of token B added to the pool. * @return binIds An array of bin IDs where the liquidity is stored. */ function addLiquidity( address recipient, uint256 subaccount, AddLiquidityParams calldata params, bytes calldata data ) external returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds); /** * @notice Removes liquidity from the pool. * @dev Liquidy can only be removed from a bin that is either unmerged or * has a mergeId of an unmerged bin. If a bin is merged more than one * level deep, it must be migrated up the merge stack to the root bin * before liquidity removal. * @param recipient The address to receive the tokens. * @param subaccount The subaccount for the recipient. * @param params The parameters for removing liquidity. * @return tokenAOut The amount of token A received. * @return tokenBOut The amount of token B received. */ function removeLiquidity( address recipient, uint256 subaccount, RemoveLiquidityParams calldata params ) external returns (uint256 tokenAOut, uint256 tokenBOut); /** * @notice Migrate bins up the linked list of merged bins so that its * mergeId is the currrent active bin. * @dev Liquidy can only be removed from a bin that is either unmerged or * has a mergeId of an unmerged bin. If a bin is merged more than one * level deep, it must be migrated up the merge stack to the root bin * before liquidity removal. * @param binId The ID of the bin to migrate. * @param maxRecursion The maximum recursion depth for the migration. */ function migrateBinUpStack(uint32 binId, uint32 maxRecursion) external; /** * @notice Swap tokenA/tokenB assets in the pool. The swap user has two * options for funding their swap. * - The user can push the input token amount to the pool before calling * the swap function. In order to avoid having the pool call the callback, * the user should pass a zero-length `data` bytes object with the swap * call. * - The user can send the input token amount to the pool when the pool * calls the `maverickV2SwapCallback` function on the calling contract. * That callback has input parameters that specify the token address of the * input token, the input and output amounts, and the bytes data sent to * the swap function. * @dev If the users elects to do a callback-based swap, the output * assets will be sent before the callback is called, allowing the user to * execute flash swaps. However, the pool does have reentrancy protection, * so a swapper will not be able to interact with the same pool again * while they are in the callback function. * @param recipient The address to receive the output tokens. * @param params Parameters containing the details of the swap * @param data Bytes information that gets passed to the callback. */ function swap( address recipient, SwapParams memory params, bytes calldata data ) external returns (uint256 amountIn, uint256 amountOut); /** * @notice Loan tokenA/tokenB assets from the pool to recipient. The fee * rate of a loan is determined by `lendingFeeRateD18`, which is set at the * protocol level by the factory. This function calls * `maverickV2FlashLoanCallback` on the calling contract. At the end of * the callback, the caller must pay back the loan with fee (if there is a * fee). * @param recipient The address to receive the loaned tokens. * @param amountB Loan amount of tokenA sent to recipient. * @param amountB Loan amount of tokenB sent to recipient. * @param data Bytes information that gets passed to the callback. */ function flashLoan( address recipient, uint256 amountA, uint256 amountB, bytes calldata data ) external returns (uint128 lendingFeeA, uint128 lendingFeeB); /** * @notice Sets fee for permissioned pools. May only be called by the * accessor. */ function setFee(uint256 newFeeAIn, uint256 newFeeBIn) external; }
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; // factory contraints on pools uint8 constant MAX_PROTOCOL_FEE_RATIO_D3 = 0.25e3; // 25% uint256 constant MAX_PROTOCOL_LENDING_FEE_RATE_D18 = 0.02e18; // 2% uint64 constant MAX_POOL_FEE_D18 = 0.9e18; // 90% uint64 constant MIN_LOOKBACK = 1 seconds; uint64 constant MAX_TICK_SPACING = 10_000; // pool constraints uint8 constant NUMBER_OF_KINDS = 4; int32 constant NUMBER_OF_KINDS_32 = int32(int8(NUMBER_OF_KINDS)); uint256 constant MAX_TICK = 322_378; // max price 1e14 in D18 scale int32 constant MAX_TICK_32 = int32(int256(MAX_TICK)); int32 constant MIN_TICK_32 = int32(-int256(MAX_TICK)); uint256 constant MAX_BINS_TO_MERGE = 3; uint128 constant MINIMUM_LIQUIDITY = 1e8; // accessor named constants uint8 constant ALL_KINDS_MASK = 0xF; // 0b1111 uint8 constant PERMISSIONED_LIQUIDITY_MASK = 0x10; // 0b010000 uint8 constant PERMISSIONED_SWAP_MASK = 0x20; // 0b100000 uint8 constant OPTIONS_MASK = ALL_KINDS_MASK | PERMISSIONED_LIQUIDITY_MASK | PERMISSIONED_SWAP_MASK; // 0b111111 // named values address constant MERGED_LP_BALANCE_ADDRESS = address(0); uint256 constant MERGED_LP_BALANCE_SUBACCOUNT = 0; uint128 constant ONE = 1e18; uint128 constant ONE_SQUARED = 1e36; int256 constant INT256_ONE = 1e18; uint256 constant ONE_D8 = 1e8; uint256 constant ONE_D3 = 1e3; int40 constant INT_ONE_D8 = 1e8; int40 constant HALF_TICK_D8 = 0.5e8; uint8 constant DEFAULT_DECIMALS = 18; uint256 constant DEFAULT_SCALE = 1; bytes constant EMPTY_PRICE_BREAKS = hex"010000000000000000000000";
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; import {Math as OzMath} from "@openzeppelin/contracts/utils/math/Math.sol"; import {ONE, DEFAULT_SCALE, DEFAULT_DECIMALS, INT_ONE_D8, ONE_SQUARED} from "./Constants.sol"; /** * @notice Math functions. */ library Math { /** * @notice Returns the lesser of two values. * @param x First uint256 value. * @param y Second uint256 value. */ function min(uint256 x, uint256 y) internal pure returns (uint256 z) { assembly ("memory-safe") { z := xor(x, mul(xor(x, y), lt(y, x))) } } /** * @notice Returns the lesser of two uint128 values. * @param x First uint128 value. * @param y Second uint128 value. */ function min128(uint128 x, uint128 y) internal pure returns (uint128 z) { assembly ("memory-safe") { z := xor(x, mul(xor(x, y), lt(y, x))) } } /** * @notice Returns the lesser of two int256 values. * @param x First int256 value. * @param y Second int256 value. */ function min(int256 x, int256 y) internal pure returns (int256 z) { assembly ("memory-safe") { z := xor(x, mul(xor(x, y), slt(y, x))) } } /** * @notice Returns the greater of two uint256 values. * @param x First uint256 value. * @param y Second uint256 value. */ function max(uint256 x, uint256 y) internal pure returns (uint256 z) { assembly ("memory-safe") { z := xor(x, mul(xor(x, y), gt(y, x))) } } /** * @notice Returns the greater of two int256 values. * @param x First int256 value. * @param y Second int256 value. */ function max(int256 x, int256 y) internal pure returns (int256 z) { assembly ("memory-safe") { z := xor(x, mul(xor(x, y), sgt(y, x))) } } /** * @notice Returns the greater of two uint128 values. * @param x First uint128 value. * @param y Second uint128 value. */ function max128(uint128 x, uint128 y) internal pure returns (uint128 z) { assembly ("memory-safe") { z := xor(x, mul(xor(x, y), gt(y, x))) } } /** * @notice Thresholds a value to be within the specified bounds. * @param value The value to bound. * @param lowerLimit The minimum allowable value. * @param upperLimit The maximum allowable value. */ function boundValue( uint256 value, uint256 lowerLimit, uint256 upperLimit ) internal pure returns (uint256 outputValue) { outputValue = min(max(value, lowerLimit), upperLimit); } /** * @notice Returns the difference between two uint128 values or zero if the result would be negative. * @param x The minuend. * @param y The subtrahend. */ function clip128(uint128 x, uint128 y) internal pure returns (uint128) { unchecked { return x < y ? 0 : x - y; } } /** * @notice Returns the difference between two uint256 values or zero if the result would be negative. * @param x The minuend. * @param y The subtrahend. */ function clip(uint256 x, uint256 y) internal pure returns (uint256) { unchecked { return x < y ? 0 : x - y; } } /** * @notice Divides one uint256 by another, rounding down to the nearest * integer. * @param x The dividend. * @param y The divisor. */ function divFloor(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivFloor(x, ONE, y); } /** * @notice Divides one uint256 by another, rounding up to the nearest integer. * @param x The dividend. * @param y The divisor. */ function divCeil(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivCeil(x, ONE, y); } /** * @notice Multiplies two uint256 values and then divides by ONE, rounding down. * @param x The multiplicand. * @param y The multiplier. */ function mulFloor(uint256 x, uint256 y) internal pure returns (uint256) { return OzMath.mulDiv(x, y, ONE); } /** * @notice Multiplies two uint256 values and then divides by ONE, rounding up. * @param x The multiplicand. * @param y The multiplier. */ function mulCeil(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivCeil(x, y, ONE); } /** * @notice Calculates the multiplicative inverse of a uint256, rounding down. * @param x The value to invert. */ function invFloor(uint256 x) internal pure returns (uint256) { unchecked { return ONE_SQUARED / x; } } /** * @notice Calculates the multiplicative inverse of a uint256, rounding up. * @param denominator The value to invert. */ function invCeil(uint256 denominator) internal pure returns (uint256 z) { assembly ("memory-safe") { // divide z - 1 by the denominator and add 1. z := add(div(sub(ONE_SQUARED, 1), denominator), 1) } } /** * @notice Multiplies two uint256 values and divides by a third, rounding down. * @param x The multiplicand. * @param y The multiplier. * @param k The divisor. */ function mulDivFloor(uint256 x, uint256 y, uint256 k) internal pure returns (uint256 result) { result = OzMath.mulDiv(x, y, max(1, k)); } /** * @notice Multiplies two uint256 values and divides by a third, rounding up if there's a remainder. * @param x The multiplicand. * @param y The multiplier. * @param k The divisor. */ function mulDivCeil(uint256 x, uint256 y, uint256 k) internal pure returns (uint256 result) { result = mulDivFloor(x, y, k); if (mulmod(x, y, max(1, k)) != 0) result = result + 1; } /** * @notice Multiplies two uint256 values and divides by a third, rounding * down. Will revert if `x * y` is larger than `type(uint256).max`. * @param x The first operand for multiplication. * @param y The second operand for multiplication. * @param denominator The divisor after multiplication. */ function mulDivDown(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 z) { assembly ("memory-safe") { // Store x * y in z for now. z := mul(x, y) if iszero(denominator) { denominator := 1 } if iszero(or(iszero(x), eq(div(z, x), y))) { revert(0, 0) } // Divide z by the denominator. z := div(z, denominator) } } /** * @notice Multiplies two uint256 values and divides by a third, rounding * up. Will revert if `x * y` is larger than `type(uint256).max`. * @param x The first operand for multiplication. * @param y The second operand for multiplication. * @param denominator The divisor after multiplication. */ function mulDivUp(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 z) { assembly ("memory-safe") { // Store x * y in z for now. z := mul(x, y) if iszero(denominator) { denominator := 1 } if iszero(or(iszero(x), eq(div(z, x), y))) { revert(0, 0) } // First, divide z - 1 by the denominator and add 1. // We allow z - 1 to underflow if z is 0, because we multiply the // end result by 0 if z is zero, ensuring we return 0 if z is zero. z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1)) } } /** * @notice Multiplies a uint256 by another and divides by a constant, * rounding down. Will revert if `x * y` is larger than * `type(uint256).max`. * @param x The multiplicand. * @param y The multiplier. */ function mulDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, y, ONE); } /** * @notice Divides a uint256 by another, rounding down the result. Will * revert if `x * 1e18` is larger than `type(uint256).max`. * @param x The dividend. * @param y The divisor. */ function divDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, ONE, y); } /** * @notice Divides a uint256 by another, rounding up the result. Will * revert if `x * 1e18` is larger than `type(uint256).max`. * @param x The dividend. * @param y The divisor. */ function divUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, ONE, y); } /** * @notice Scales a number based on a difference in decimals from a default. * @param decimals The new decimal precision. */ function scale(uint8 decimals) internal pure returns (uint256) { unchecked { if (decimals == DEFAULT_DECIMALS) { return DEFAULT_SCALE; } else { return 10 ** (DEFAULT_DECIMALS - decimals); } } } /** * @notice Adjusts a scaled amount to the token decimal scale. * @param amount The scaled amount. * @param scaleFactor The scaling factor to adjust by. * @param ceil Whether to round up (true) or down (false). */ function ammScaleToTokenScale(uint256 amount, uint256 scaleFactor, bool ceil) internal pure returns (uint256 z) { unchecked { if (scaleFactor == DEFAULT_SCALE || amount == 0) { return amount; } else { if (!ceil) return amount / scaleFactor; assembly ("memory-safe") { z := add(div(sub(amount, 1), scaleFactor), 1) } } } } /** * @notice Adjusts a token amount to the D18 AMM scale. * @param amount The amount in token scale. * @param scaleFactor The scale factor for adjustment. */ function tokenScaleToAmmScale(uint256 amount, uint256 scaleFactor) internal pure returns (uint256) { if (scaleFactor == DEFAULT_SCALE) { return amount; } else { return amount * scaleFactor; } } /** * @notice Returns the absolute value of a signed 32-bit integer. * @param x The integer to take the absolute value of. */ function abs32(int32 x) internal pure returns (uint32) { unchecked { return uint32(x < 0 ? -x : x); } } /** * @notice Returns the absolute value of a signed 256-bit integer. * @param x The integer to take the absolute value of. */ function abs(int256 x) internal pure returns (uint256) { unchecked { return uint256(x < 0 ? -x : x); } } /** * @notice Calculates the integer square root of a uint256 rounded down. * @param x The number to take the square root of. */ function sqrt(uint256 x) internal pure returns (uint256 z) { // from https://github.com/transmissions11/solmate/blob/e8f96f25d48fe702117ce76c79228ca4f20206cb/src/utils/FixedPointMathLib.sol assembly ("memory-safe") { let y := x z := 181 if iszero(lt(y, 0x10000000000000000000000000000000000)) { y := shr(128, y) z := shl(64, z) } if iszero(lt(y, 0x1000000000000000000)) { y := shr(64, y) z := shl(32, z) } if iszero(lt(y, 0x10000000000)) { y := shr(32, y) z := shl(16, z) } if iszero(lt(y, 0x1000000)) { y := shr(16, y) z := shl(8, z) } z := shr(18, mul(z, add(y, 65536))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := sub(z, lt(div(x, z), z)) } } /** * @notice Computes the floor of a D8-scaled number as an int32, ignoring * potential overflow in the cast. * @param val The D8-scaled number. */ function floorD8Unchecked(int256 val) internal pure returns (int32) { int32 val32; bool check; unchecked { val32 = int32(val / INT_ONE_D8); check = (val < 0 && val % INT_ONE_D8 != 0); } return check ? val32 - 1 : val32; } }
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; import {SafeCast as Cast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {IMaverickV2Pool} from "../interfaces/IMaverickV2Pool.sol"; import {TickMath} from "./TickMath.sol"; import {Math} from "./Math.sol"; /** * @notice Library of pool functions. */ library PoolLib { using Cast for uint256; struct AddLiquidityInfo { uint256 deltaA; uint256 deltaB; bool tickLtActive; uint256 tickSpacing; int32 tick; } /** * @notice Check to ensure that the ticks are in ascending order and amount * array is same length as tick array. * @param ticks An array of int32 values representing ticks to be checked. * @param amountsLength Amount array length. */ function uniqueOrderedTicksCheck(int32[] memory ticks, uint256 amountsLength) internal pure { unchecked { if (ticks.length != amountsLength) revert IMaverickV2Pool.PoolTicksAmountsLengthMismatch(ticks.length, amountsLength); int32 lastTick = type(int32).min; for (uint256 i; i < ticks.length; ) { if (ticks[i] <= lastTick) revert IMaverickV2Pool.PoolTicksNotSorted(i, lastTick, ticks[i]); lastTick = ticks[i]; i = i + 1; } } } /** * @notice Compute bin reserves assuming the bin is not merged; not accurate * reflection of reserves for merged bins. * @param bin The storage reference to the state for this bin. * @param tick The memory reference to the state for this tick. * @return reserveA The reserve amount for token A. * @return reserveB The reserve amount for token B. */ function binReserves( IMaverickV2Pool.BinState storage bin, IMaverickV2Pool.TickState memory tick ) internal view returns (uint128 reserveA, uint128 reserveB) { return binReserves(bin.tickBalance, tick.reserveA, tick.reserveB, tick.totalSupply); } /** * @notice Compute bin reserves assuming the bin is not merged; not accurate * reflection of reserves for merged bins. * @param tickBalance Bin's balance in the tick. * @param tickReserveA Tick's tokenA reserves. * @param tickReserveB Tick's tokenB reserves. * @param tickTotalSupply Tick total supply of bin balances. */ function binReserves( uint128 tickBalance, uint128 tickReserveA, uint128 tickReserveB, uint128 tickTotalSupply ) internal pure returns (uint128 reserveA, uint128 reserveB) { if (tickTotalSupply != 0) { reserveA = reserveValue(tickReserveA, tickBalance, tickTotalSupply); reserveB = reserveValue(tickReserveB, tickBalance, tickTotalSupply); } } /** * @notice Reserves of a bin in a tick. * @param tickReserve Tick reserve amount in a given token. * @param tickBalance Bin's balance in the tick. * @param tickTotalSupply Tick total supply of bin balances. */ function reserveValue( uint128 tickReserve, uint128 tickBalance, uint128 tickTotalSupply ) internal pure returns (uint128 reserve) { reserve = Math.mulDivFloor(tickReserve, tickBalance, tickTotalSupply).toUint128(); reserve = Math.min128(tickReserve, reserve); } /** * @notice Calculate delta A, delta B, and delta Tick Balance based on delta * LP balance and the Tick/Bin state. */ function deltaTickBalanceFromDeltaLpBalance( uint256 binTickBalance, uint256 binTotalSupply, IMaverickV2Pool.TickState memory tickState, uint128 deltaLpBalance, AddLiquidityInfo memory addLiquidityInfo ) internal pure returns (uint256 deltaTickBalance) { unchecked { if (tickState.reserveA != 0 || tickState.reserveB != 0) { // if there are already reserves, then we just contribute pro rata // deltaLiquidity = deltaBinLP / binTS * binTickBalance / tickTS * tickL uint256 numerator = Math.max(1, binTickBalance) * uint256(deltaLpBalance); uint256 denominator = Math.max(1, tickState.totalSupply) * Math.max(1, binTotalSupply); addLiquidityInfo.deltaA = Math.mulDivCeil(tickState.reserveA, numerator, denominator); addLiquidityInfo.deltaB = Math.mulDivCeil(tickState.reserveB, numerator, denominator); } else { _setRequiredDeltaReservesForEmptyTick(deltaLpBalance, addLiquidityInfo); } // round down the amount credited to the tick; this could lead to a // small add amount getting zero reserves credit. deltaTickBalance = tickState.totalSupply == 0 ? deltaLpBalance : Math.mulDivDown(deltaLpBalance, Math.max(1, binTickBalance), binTotalSupply); } } /** * @notice Calculates deltaA = liquidity * (sqrt(upper) - sqrt(lower)) * @notice Calculates deltaB = liquidity / sqrt(lower) - liquidity / sqrt(upper), * @notice i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower)) * @notice we set liquidity = deltaLpBalance / (1.0001^(tick * tickspacing) - 1) * @notice which simplifies the A/B amounts to: * @notice deltaA = deltaLpBalance * sqrt(lower) * @notice deltaB = deltaLpBalance / sqrt(upper) */ function _setRequiredDeltaReservesForEmptyTick( uint128 deltaLpBalance, AddLiquidityInfo memory addLiquidityInfo ) internal pure { // No reserves, so we will use deltaLpBalance as liquidity to be added. // In this logic branch, the tick is empty, so we know the tick will be // a one-asset add. (uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice) = TickMath.tickSqrtPrices( addLiquidityInfo.tickSpacing, addLiquidityInfo.tick ); addLiquidityInfo.deltaA = addLiquidityInfo.tickLtActive ? Math.mulCeil(deltaLpBalance, sqrtLowerTickPrice) : 0; addLiquidityInfo.deltaB = addLiquidityInfo.tickLtActive ? 0 : Math.divCeil(deltaLpBalance, sqrtUpperTickPrice); } }
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; import {Math as OzMath} from "@openzeppelin/contracts/utils/math/Math.sol"; import {Math} from "./Math.sol"; import {MAX_TICK, ONE} from "./Constants.sol"; /** * @notice Math functions related to tick operations. */ library TickMath { using Math for uint256; error TickMaxExceeded(int256 tick); /** * @notice Compute the lower and upper sqrtPrice of a tick. * @param tickSpacing The tick spacing used for calculations. * @param _tick The input tick value. */ function tickSqrtPrices( uint256 tickSpacing, int32 _tick ) internal pure returns (uint256 sqrtLowerPrice, uint256 sqrtUpperPrice) { unchecked { sqrtLowerPrice = tickSqrtPrice(tickSpacing, _tick); sqrtUpperPrice = tickSqrtPrice(tickSpacing, _tick + 1); } } /** * @notice Compute the base tick value from the pool tick and the * tickSpacing. Revert if base tick is beyond the max tick boundary. * @param tickSpacing The tick spacing used for calculations. * @param _tick The input tick value. */ function subTickIndex(uint256 tickSpacing, int32 _tick) internal pure returns (uint32 subTick) { subTick = Math.abs32(_tick); subTick *= uint32(tickSpacing); if (subTick > MAX_TICK) { revert TickMaxExceeded(_tick); } } /** * @notice Calculate the square root price for a given tick and tick spacing. * @param tickSpacing The tick spacing used for calculations. * @param _tick The input tick value. * @return _result The square root price. */ function tickSqrtPrice(uint256 tickSpacing, int32 _tick) internal pure returns (uint256 _result) { unchecked { uint256 tick = subTickIndex(tickSpacing, _tick); uint256 ratio = tick & 0x1 != 0 ? 0xfffcb933bd6fad9d3af5f0b9f25db4d6 : 0x100000000000000000000000000000000; if (tick & 0x2 != 0) ratio = (ratio * 0xfff97272373d41fd789c8cb37ffcaa1c) >> 128; if (tick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656ac9229c67059486f389) >> 128; if (tick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e81259b3cddc7a064941) >> 128; if (tick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f67b19e8887e0bd251eb7) >> 128; if (tick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98cd2e57b660be99eb2c4a) >> 128; if (tick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c9838804e327cb417cafcb) >> 128; if (tick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99d51e2cc356c2f617dbe0) >> 128; if (tick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900aecf64236ab31f1f9dcb5) >> 128; if (tick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac4d9194200696907cf2e37) >> 128; if (tick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b88206f8abe8a3b44dd9be) >> 128; if (tick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c578ef4f1d17b2b235d480) >> 128; if (tick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd254ee83bdd3f248e7e785e) >> 128; if (tick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d8f7dd10e744d913d033333) >> 128; if (tick & 0x4000 != 0) ratio = (ratio * 0x70d869a156ddd32a39e257bc3f50aa9b) >> 128; if (tick & 0x8000 != 0) ratio = (ratio * 0x31be135f97da6e09a19dc367e3b6da40) >> 128; if (tick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7e5a9780b0cc4e25d61a56) >> 128; if (tick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedbcb3a6ccb7ce618d14225) >> 128; if (tick & 0x40000 != 0) ratio = (ratio * 0x2216e584f630389b2052b8db590e) >> 128; if (_tick > 0) ratio = type(uint256).max / ratio; _result = (ratio * ONE) >> 128; } } /** * @notice Calculate liquidity of a tick. * @param reserveA Tick reserve of token A. * @param reserveB Tick reserve of token B. * @param sqrtLowerTickPrice The square root price of the lower tick edge. * @param sqrtUpperTickPrice The square root price of the upper tick edge. */ function getTickL( uint256 reserveA, uint256 reserveB, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice ) internal pure returns (uint256 liquidity) { // known: // - sqrt price values are different // - reserveA and reserveB fit in 128 bit // - sqrt price is in (1e-7, 1e7) // - D18 max for uint256 is 1.15e59 // - D18 min is 1e-18 unchecked { // diff is in (5e-12, 4e6); max tick spacing is 10_000 uint256 diff = sqrtUpperTickPrice - sqrtLowerTickPrice; // Need to maximize precision by shifting small values A and B up so // that they use more of the available bit range. Two constraints to // consider: we need A * B * diff / sqrtPrice to be bigger than 1e-18 // when the bump is not in play. This constrains the threshold for // bumping to be at least 77 bit; ie, either a or b needs 2^77 which // means that term A * B * diff / sqrtPrice > 1e-18. // // At the other end, the second constraint is that b^2 needs to fit in // a 256-bit number, so, post bump, the max reserve value needs to be // less than 6e22. With a 78-bit threshold and a 57-bit bump, we have A // and B are in (1.4e-1, 4.4e22 (2^(78+57))) with bump, and one of A or // B is at least 2^78 without the bump, but the other reserve value may // be as small as 1 wei. uint256 precisionBump = 0; if ((reserveA >> 78) == 0 && (reserveB >> 78) == 0) { precisionBump = 57; reserveA <<= precisionBump; reserveB <<= precisionBump; } if (reserveB == 0) return Math.divDown(reserveA, diff) >> precisionBump; if (reserveA == 0) return Math.mulDivDown(reserveB.mulDown(sqrtLowerTickPrice), sqrtUpperTickPrice, diff) >> precisionBump; // b is in (7.2e-9 (2^57 / 1e7 / 2), 2.8e29 (2^(78+57) * 1e7 / 2)) with bump // b is in a subset of the same range without bump uint256 b = (reserveA.divDown(sqrtUpperTickPrice) + reserveB.mulDown(sqrtLowerTickPrice)) >> 1; // b^2 is in (5.1e-17, 4.8e58); and will not overflow on either end; // A*B is in (3e-13 (2^78 / 1e18 * 1e-18), 1.9e45) without bump and is in a subset range with bump // A*B*diff/sqrtUpper is in (1.5e-17 (3e-13 * 5e-12 * 1e7), 7.6e58); // Since b^2 is at the upper edge of the precision range, we are not // able to multiply the argument of the sqrt by 1e18, instead, we move // this factor outside of the sqrt. The resulting loss of precision // means that this liquidity value is a lower bound on the tick // liquidity return OzMath.mulDiv( b + Math.sqrt( (OzMath.mulDiv(b, b, ONE) + OzMath.mulDiv(reserveB.mulFloor(reserveA), diff, sqrtUpperTickPrice)) ) * 1e9, sqrtUpperTickPrice, diff ) >> precisionBump; } } /** * @notice Calculate square root price of a tick. Returns left edge of the * tick if the tick has no reserves. * @param reserveA Tick reserve of token A. * @param reserveB Tick reserve of token B. * @param sqrtLowerTickPrice The square root price of the lower tick edge. * @param sqrtUpperTickPrice The square root price of the upper tick edge. * @return sqrtPrice The calculated square root price. */ function getSqrtPrice( uint256 reserveA, uint256 reserveB, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice, uint256 liquidity ) internal pure returns (uint256 sqrtPrice) { unchecked { if (reserveA == 0) { return sqrtLowerTickPrice; } if (reserveB == 0) { return sqrtUpperTickPrice; } sqrtPrice = Math.sqrt( ONE * (reserveA + liquidity.mulDown(sqrtLowerTickPrice)).divDown( reserveB + liquidity.divDown(sqrtUpperTickPrice) ) ); sqrtPrice = Math.boundValue(sqrtPrice, sqrtLowerTickPrice, sqrtUpperTickPrice); } } /** * @notice Calculate square root price of a tick. Returns left edge of the * tick if the tick has no reserves. * @param reserveA Tick reserve of token A. * @param reserveB Tick reserve of token B. * @param sqrtLowerTickPrice The square root price of the lower tick edge. * @param sqrtUpperTickPrice The square root price of the upper tick edge. * @return sqrtPrice The calculated square root price. * @return liquidity The calculated liquidity. */ function getTickSqrtPriceAndL( uint256 reserveA, uint256 reserveB, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice ) internal pure returns (uint256 sqrtPrice, uint256 liquidity) { liquidity = getTickL(reserveA, reserveB, sqrtLowerTickPrice, sqrtUpperTickPrice); sqrtPrice = getSqrtPrice(reserveA, reserveB, sqrtLowerTickPrice, sqrtUpperTickPrice, liquidity); } }
// SPDX-License-Identifier: GPL-2.0-or-later // As the copyright holder of this work, Ubiquity Labs retains // the right to distribute, use, and modify this code under any license of // their choosing, in addition to the terms of the GPL-v2 or later. pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** * @notice Low-gas transfer functions. */ library TransferLib { error TransferFailed(IERC20 token, address to, uint256 amount); error TransferFromFailed(IERC20 token, address from, address to, uint256 amount); // implementation adapted from // https://github.com/transmissions11/solmate/blob/e8f96f25d48fe702117ce76c79228ca4f20206cb/src/utils/SafeTransferLib.sol /** * @notice Transfer token amount. Amount is sent from caller address to `to` address. */ function transfer(IERC20 token, address to, uint256 amount) internal { bool success; assembly ("memory-safe") { // We'll write our calldata to this slot below, but restore it later. let memPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(memPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000) // Append arguments. Addresses are assumed clean. Transfer will fail otherwise. mstore(add(memPointer, 0x4), to) mstore(add(memPointer, 0x24), amount) // Append the "amount" argument. // 68 bytes total // fail if reverted; only allocate 32 bytes for return to ensure we // only use mem slot 0 which is scatch space and memory safe to use. success := call(gas(), token, 0, memPointer, 68, 0, 32) // handle transfers that return 1/true and ensure the value is from // the return and not dirty bits left in the scratch space. let returnedOne := and(eq(mload(0), 1), gt(returndatasize(), 31)) // handle transfers that return nothing let noReturn := iszero(returndatasize()) // good if didn't revert and the return is either empty or true success := and(success, or(returnedOne, noReturn)) } if (!success) revert TransferFailed(token, to, amount); } /** * @notice Transfer token amount. Amount is sent from `from` address to `to` address. */ function transferFrom(IERC20 token, address from, address to, uint256 amount) internal { bool success; assembly ("memory-safe") { // We'll write our calldata to this slot below, but restore it later. let memPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(memPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000) // Append arguments. Addresses are assumed clean. Transfer will fail otherwise. mstore(add(memPointer, 0x4), from) // Append the "from" argument. mstore(add(memPointer, 0x24), to) // Append the "to" argument. mstore(add(memPointer, 0x44), amount) // Append the "amount" argument. // 100 bytes total // fail if reverted; only allocate 32 bytes for return to ensure we // only use mem slot 0 which is scatch space and memory safe to use. success := call(gas(), token, 0, memPointer, 100, 0, 32) // handle transfers that return 1/true and ensure the value is from // the return and not dirty bits left in the scratch space. let returnedOne := and(eq(mload(0), 1), gt(returndatasize(), 31)) // handle transfers that return nothing let noReturn := iszero(returndatasize()) // good if didn't revert and the return is either empty or true success := and(success, or(returnedOne, noReturn)) } if (!success) revert TransferFromFailed(token, from, to, amount); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {INft} from "@maverick/v2-supplemental/contracts/positionbase/INft.sol"; import {IMulticall} from "@maverick/v2-common/contracts/base/IMulticall.sol"; import {IMaverickV2VotingEscrow} from "./IMaverickV2VotingEscrow.sol"; import {IMaverickV2RewardVault} from "./IMaverickV2RewardVault.sol"; import {IRewardAccounting} from "../rewardbase/IRewardAccounting.sol"; interface IMaverickV2Reward is INft, IMulticall, IRewardAccounting { event NotifyRewardAmount( address sender, IERC20 rewardTokenAddress, uint256 amount, uint256 duration, uint256 rewardRate ); event GetReward( address sender, uint256 tokenId, address recipient, uint8 rewardTokenIndex, uint256 stakeDuration, IERC20 rewardTokenAddress, RewardOutput rewardOutput, uint256 lockupId ); event UnStake(address indexed sender, uint256 indexed tokenId, address indexed recipient, uint256 amount); event Stake(address indexed sender, uint256 indexed tokenId, uint256 amount); error RewardDurationOutOfBounds(uint256 duration, uint256 minDuration, uint256 maxDuration); error RewardZeroAmount(); error RewardNotValidRewardToken(IERC20 rewardTokenAddress); error RewardNotValidIndex(uint8 index); error RewardTokenCannotBeStakingToken(IERC20 stakingToken); error RewardTransferNotSupported(); error RewardNotApprovedGetter(uint256 tokenId, address approved, address getter); error RewardUnboostedTimePeriodNotMet(uint256 timestamp, uint256 minTimestamp); struct RewardInfo { // Timestamp of when the rewards finish uint256 finishAt; // Minimum of last updated time and reward finish time uint256 updatedAt; // Reward to be paid out per second uint256 rewardRate; // Escrowed rewards uint256 escrowedReward; // Sum of (reward rate * dt * 1e18 / total supply) uint256 rewardPerTokenStored; // Reward Token to be emitted IERC20 rewardToken; // ve locking contract IMaverickV2VotingEscrow veRewardToken; // amount available to push to ve as incentive uint128 unboostedAmount; // timestamp of unboosted push uint256 lastUnboostedPushTimestamp; } struct ContractInfo { // Reward Name string name; // Reward Symbol string symbol; // total supply staked uint256 totalSupply; // staking token IERC20 stakingToken; } struct EarnedInfo { // earned uint256 earned; // reward token IERC20 rewardToken; } struct RewardOutput { uint256 amount; bool asVe; IMaverickV2VotingEscrow veContract; } // solhint-disable-next-line func-name-mixedcase function MAX_DURATION() external view returns (uint256); // solhint-disable-next-line func-name-mixedcase function MIN_DURATION() external view returns (uint256); /** * @notice This function retrieves the minimum time gap in seconds that * must have elasped between calls to `pushUnboostedToVe()`. */ // solhint-disable-next-line func-name-mixedcase function UNBOOSTED_MIN_TIME_GAP() external view returns (uint256); /** * @notice This function retrieves the address of the token used for * staking in this reward contract. * @return The address of the staking token (IERC20). */ function stakingToken() external view returns (IERC20); /** * @notice This function retrieves the address of the MaverickV2RewardVault * contract associated with this reward contract. * @return The address of the IMaverickV2RewardVault contract. */ function vault() external view returns (IMaverickV2RewardVault); /** * @notice This function retrieves information about all available reward tokens for this reward contract. * @return info An array of RewardInfo structs containing details about each reward token. */ function rewardInfo() external view returns (RewardInfo[] memory info); /** * @notice This function retrieves information about all available reward * tokens and overall contract details for this reward contract. * @return info An array of RewardInfo structs containing details about each reward token. * @return _contractInfo A ContractInfo struct containing overall contract details. */ function contractInfo() external view returns (RewardInfo[] memory info, ContractInfo memory _contractInfo); /** * @notice This function calculates the total amount of all earned rewards * for a specific tokenId across all reward tokens. * @param tokenId The address of the tokenId for which to calculate earned rewards. * @return earnedInfo An array of EarnedInfo structs containing details about earned rewards for each supported token. */ function earned(uint256 tokenId) external view returns (EarnedInfo[] memory earnedInfo); /** * @notice This function calculates the total amount of earned rewards for * a specific tokenId for a particular reward token. * @param tokenId The address of the tokenId for which to calculate earned rewards. * @param rewardTokenAddress The address of the specific reward token. * @return amount The total amount of earned rewards for the specified token. */ function earned(uint256 tokenId, IERC20 rewardTokenAddress) external view returns (uint256); /** * @notice This function retrieves the internal index associated with a specific reward token address. * @param rewardToken The address of the reward token to get the index for. * @return rewardTokenIndex The internal index of the token within the reward contract (uint8). */ function tokenIndex(IERC20 rewardToken) external view returns (uint8 rewardTokenIndex); /** * @notice This function retrieves the total number of supported reward tokens in this reward contract. * @return count The total number of reward tokens (uint256). */ function rewardTokenCount() external view returns (uint256); /** * @notice This function transfers a specified amount of reward tokens from * the caller to distribute them over a defined duration. The caller will * need to approve this rewards contract to make the transfer on the * caller's behalf. See `notifyRewardAmount` for details of how the * duration is set by the rewards contract. * @param rewardToken The address of the reward token to transfer. * @param duration The duration (in seconds) over which to distribute the rewards. * @param amount The amount of reward tokens to transfer. * @return _duration The duration in seconds that the incentives will be distributed over. */ function transferAndNotifyRewardAmount( IERC20 rewardToken, uint256 duration, uint256 amount ) external returns (uint256 _duration); /** * @notice This function notifies the vault to distribute a previously * transferred amount of reward tokens over a defined duration. (Assumes * tokens are already in the contract). * @dev The duration of the distribution may not be the same as the input * duration. If this notify amount is less than the amount already pending * disbursement, then this new amount will be distributed as the same rate * as the existing rate and that will dictate the duration. Alternatively, * if the amount is more than the pending disbursement, then the input * duration will be honored and all pending disbursement tokens will also be * distributed at this newly set rate. * @param rewardToken The address of the reward token to distribute. * @param duration The duration (in seconds) over which to distribute the rewards. * @return _duration The duration in seconds that the incentives will be distributed over. */ function notifyRewardAmount(IERC20 rewardToken, uint256 duration) external returns (uint256 _duration); /** * @notice This function transfers a specified amount of staking tokens * from the caller to the staking `vault()` and stakes them on the * recipient's behalf. The user has to approve this reward contract to * transfer the staking token on their behalf for this function not to * revert. * @param tokenId Nft tokenId to stake for the staked tokens. * @param _amount The amount of staking tokens to transfer and stake. * @return amount The amount of staking tokens staked. May differ from * input if there were unstaked tokens in the vault prior to this call. * @return stakedTokenId TokenId where liquidity was staked to. This may * differ from the input tokenIf if the input `tokenId=0`. */ function transferAndStake( uint256 tokenId, uint256 _amount ) external returns (uint256 amount, uint256 stakedTokenId); /** * @notice This function stakes the staking tokens to the specified * tokenId. If `tokenId=0` is passed in, then this function will look up * the caller's tokenIds and stake to the zero-index tokenId. If the user * does not yet have a staking NFT tokenId, this function will mint one for * the sender and stake to that newly-minted tokenId. * * @dev The amount staked is derived by looking at the new balance on * the `vault()`. So, for staking to yield a non-zero balance, the user * will need to have transfered the `stakingToken()` to the `vault()` prior * to calling `stake`. Note, tokens sent to the reward contract instead * of the vault will not be stakable and instead will be eligible to be * disbursed as rewards to stakers. This is an advanced usage function. * If in doubt about the mechanics of staking, use `transferAndStake()` * instead. * @param tokenId The address of the tokenId whose tokens to stake. * @return amount The amount of staking tokens staked (uint256). * @return stakedTokenId TokenId where liquidity was staked to. This may * differ from the input tokenIf if the input `tokenId=0`. */ function stake(uint256 tokenId) external returns (uint256 amount, uint256 stakedTokenId); /** * @notice This function initiates unstaking of a specified amount of * staking tokens for the caller and sends them to a recipient. * @param tokenId The address of the tokenId whose tokens to unstake. * @param amount The amount of staking tokens to unstake (uint256). */ function unstakeToOwner(uint256 tokenId, uint256 amount) external; /** * @notice This function initiates unstaking of a specified amount of * staking tokens on behalf of a specific tokenId and sends them to a recipient. * @dev To unstakeFrom, the caller must have an approval allowance of at * least `amount`. Approvals follow the ERC-721 approval interface. * @param tokenId The address of the tokenId whose tokens to unstake. * @param recipient The address to which the unstaked tokens will be sent. * @param amount The amount of staking tokens to unstake (uint256). */ function unstake(uint256 tokenId, address recipient, uint256 amount) external; /** * @notice This function retrieves the claimable reward for a specific * reward token and stake duration for the caller. * @param tokenId The address of the tokenId whose reward to claim. * @param rewardTokenIndex The internal index of the reward token. * @param stakeDuration The duration (in seconds) for which the rewards were staked. * @return rewardOutput A RewardOutput struct containing details about the claimable reward. */ function getRewardToOwner( uint256 tokenId, uint8 rewardTokenIndex, uint256 stakeDuration ) external returns (RewardOutput memory rewardOutput); /** * @notice This function retrieves the claimable reward for a specific * reward token, stake duration, and lockup ID for the caller. * @param tokenId The address of the tokenId whose reward to claim. * @param rewardTokenIndex The internal index of the reward token. * @param stakeDuration The duration (in seconds) for which the rewards were staked. * @param lockupId The unique identifier for the specific lockup (optional). * @return rewardOutput A RewardOutput struct containing details about the claimable reward. */ function getRewardToOwnerForExistingVeLockup( uint256 tokenId, uint8 rewardTokenIndex, uint256 stakeDuration, uint256 lockupId ) external returns (RewardOutput memory); /** * @notice This function retrieves the claimable reward for a specific * reward token and stake duration for a specified tokenId and sends it to * a recipient. If the reward is staked in the corresponding veToken, a * new lockup in the ve token will be created. * @param tokenId The address of the tokenId whose reward to claim. * @param recipient The address to which the claimed reward will be sent. * @param rewardTokenIndex The internal index of the reward token. * @param stakeDuration The duration (in seconds) for which the rewards * will be staked in the ve contract. * @return rewardOutput A RewardOutput struct containing details about the claimable reward. */ function getReward( uint256 tokenId, address recipient, uint8 rewardTokenIndex, uint256 stakeDuration ) external returns (RewardOutput memory); /** * @notice This function retrieves a list of all supported tokens in the reward contract. * @param includeStakingToken A flag indicating whether to include the staking token in the list. * @return tokens An array of IERC20 token addresses. */ function tokenList(bool includeStakingToken) external view returns (IERC20[] memory tokens); /** * @notice This function retrieves the veToken contract associated with a * specific index within the reward contract. * @param index The index of the veToken to retrieve. * @return output The IMaverickV2VotingEscrow contract associated with the index. */ function veTokenByIndex(uint8 index) external view returns (IMaverickV2VotingEscrow output); /** * @notice This function retrieves the reward token contract associated * with a specific index within the reward contract. * @param index The index of the reward token to retrieve. * @return output The IERC20 contract associated with the index. */ function rewardTokenByIndex(uint8 index) external view returns (IERC20 output); /** * @notice This function calculates the boosted amount an tokenId would * receive based on their veToken balance and stake duration. * @param tokenId The address of the tokenId for which to calculate the boosted amount. * @param veToken The IMaverickV2VotingEscrow contract representing the veToken used for boosting. * @param rawAmount The raw (unboosted) amount. * @param stakeDuration The duration (in seconds) for which the rewards would be staked. * @return earnedAmount The boosted amount the tokenId would receive (uint256). * @return asVe A boolean indicating whether the boosted amount is * staked in the veToken (true) or is disbursed without ve staking required (false). */ function boostedAmount( uint256 tokenId, IMaverickV2VotingEscrow veToken, uint256 rawAmount, uint256 stakeDuration ) external view returns (uint256 earnedAmount, bool asVe); /** * @notice This function is used to push unboosted rewards to the veToken * contract. This unboosted reward amount is then distributed to the * veToken holders. This function will revert if less than * `UNBOOSTED_MIN_TIME_GAP()` seconds have passed since the last call. * @param rewardTokenIndex The internal index of the reward token. * @return amount The amount of unboosted rewards pushed (uint128). * @return timepoint The timestamp associated with the pushed rewards (uint48). * @return batchIndex The batch index for the pushed rewards (uint256). */ function pushUnboostedToVe( uint8 rewardTokenIndex ) external returns (uint128 amount, uint48 timepoint, uint256 batchIndex); /** * @notice Mints an NFT stake to a user. This NFT will not possesses any * assets until a user `stake`s asset to the NFT tokenId as part of a * separate call. * @param recipient The address that owns the output NFT */ function mint(address recipient) external returns (uint256 tokenId); /** * @notice Mints an NFT stake to caller. This NFT will not possesses any * assets until a user `stake`s asset to the NFT tokenId as part of a * separate call. */ function mintToSender() external returns (uint256 tokenId); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IMaverickV2BoostedPositionFactory} from "@maverick/v2-supplemental/contracts/interfaces/IMaverickV2BoostedPositionFactory.sol"; import {IMaverickV2VotingEscrowFactory} from "./IMaverickV2VotingEscrowFactory.sol"; import {IMaverickV2VotingEscrow} from "./IMaverickV2VotingEscrow.sol"; import {IMaverickV2Reward} from "./IMaverickV2Reward.sol"; interface IMaverickV2RewardFactory { error RewardFactoryNotFactoryBoostedPosition(); error RewardFactoryTooManyRewardTokens(); error RewardFactoryRewardAndVeLengthsAreNotEqual(); error RewardFactoryInvalidVeBaseTokenPair(); error RewardFactoryTokensNotSorted(uint256 index, IERC20 lastRewardToken, IERC20 rewardToken); event CreateRewardsContract( IERC20 stakeToken, IERC20[] rewardTokens, IMaverickV2VotingEscrow[] veTokens, IMaverickV2Reward rewardsContract, bool isFactoryBoostedPosition ); /** * @notice This function creates a new MaverickV2Reward contract associated * with a specific stake token contract and set of reward and voting * escrow tokens. * @param stakeToken Token to be staked in reward contract; e.g. a boosted position contract. * @param rewardTokens An array of IERC20 token addresses representing the available reward tokens. * @param veTokens An array of IMaverickV2VotingEscrow contract addresses * representing the associated veTokens for boosting. * @return rewardsContract The newly created IMaverickV2Reward contract. */ function createRewardsContract( IERC20 stakeToken, IERC20[] memory rewardTokens, IMaverickV2VotingEscrow[] memory veTokens ) external returns (IMaverickV2Reward rewardsContract); /** * @notice This function retrieves the address of the MaverickV2BoostedPositionFactory contract. * @return factory The address of the IMaverickV2BoostedPositionFactory contract. */ function boostedPositionFactory() external returns (IMaverickV2BoostedPositionFactory); /** * @notice This function retrieves the address of the MaverickV2VotingEscrowFactory contract. * @return factory The address of the IMaverickV2VotingEscrowFactory contract. */ function votingEscrowFactory() external returns (IMaverickV2VotingEscrowFactory); /** * @notice This function checks if a provided IMaverickV2Reward contract is * a valid contract created by this factory. * @param reward The IMaverickV2Reward contract to check. * @return isFactoryContract True if the contract is a valid factory-created reward contract, False otherwise. */ function isFactoryContract(IMaverickV2Reward reward) external returns (bool); /** * @notice This function retrieves a list of all MaverickV2Reward contracts * associated with a specific staking token contract within a specified * range. * @param stakeToken Lookup token. * @param startIndex The starting index of the list to retrieve. * @param endIndex The ending index of the list to retrieve. * @return rewardsContract An array of IMaverickV2Reward contracts * associated with the BoostedPosition within the specified range. */ function rewardsForStakeToken( IERC20 stakeToken, uint256 startIndex, uint256 endIndex ) external view returns (IMaverickV2Reward[] memory rewardsContract); /** * @notice Returns the number of reward contracts this factory has deployed * for a given staking token. */ function rewardsForStakeTokenCount(IERC20 stakeToken) external view returns (uint256 count); /** * @notice This function retrieves a list of all MaverickV2Reward contracts within a specified range. * @param startIndex The starting index of the list to retrieve. * @param endIndex The ending index of the list to retrieve. * @return rewardsContract An array of IMaverickV2Reward contracts within the specified range. */ function rewards( uint256 startIndex, uint256 endIndex ) external view returns (IMaverickV2Reward[] memory rewardsContract); /** * @notice Returns the number of reward contracts this factory has deployed. */ function rewardsCount() external view returns (uint256 count); /** * @notice This function retrieves a list of all MaverickV2Reward contracts * within a specified range that have a staking token that is a boosted * position from the maverick boosted position contract. * @param startIndex The starting index of the list to retrieve. * @param endIndex The ending index of the list to retrieve. * @return rewardsContract An array of IMaverickV2Reward contracts within the specified range. */ function boostedPositionRewards( uint256 startIndex, uint256 endIndex ) external view returns (IMaverickV2Reward[] memory); /** * @notice Returns the number of reward contracts where the staking token * is a booste position that this factory has deployed. */ function boostedPositionRewardsCount() external view returns (uint256 count); /** * @notice This function retrieves a list of all MaverickV2Reward contracts * within a specified range that have a staking token that is not a boosted * position from the maverick boosted position contract. * @param startIndex The starting index of the list to retrieve. * @param endIndex The ending index of the list to retrieve. * @return rewardsContract An array of IMaverickV2Reward contracts within the specified range. */ function nonBoostedPositionRewards( uint256 startIndex, uint256 endIndex ) external view returns (IMaverickV2Reward[] memory); /** * @notice Returns the number of reward contracts where the staking token * is not a booste position that this factory has deployed. */ function nonBoostedPositionRewardsCount() external view returns (uint256 count); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IMaverickV2PoolLens} from "@maverick/v2-supplemental/contracts/interfaces/IMaverickV2PoolLens.sol"; import {IMaverickV2BoostedPosition} from "@maverick/v2-supplemental/contracts/interfaces/IMaverickV2BoostedPosition.sol"; import {IMaverickV2LiquidityManager} from "@maverick/v2-supplemental/contracts/interfaces/IMaverickV2LiquidityManager.sol"; import {IMaverickV2RewardFactory} from "./IMaverickV2RewardFactory.sol"; import {IMaverickV2VotingEscrowWSync} from "./IMaverickV2VotingEscrowWSync.sol"; import {IMaverickV2Reward} from "./IMaverickV2Reward.sol"; import {IMaverickV2VotingEscrow} from "./IMaverickV2VotingEscrow.sol"; interface IMaverickV2RewardRouter is IMaverickV2LiquidityManager { /** * @notice This function stakes any new staking token balance that are in * the `reward.vault()` for a specified recipient tokenId. Passing input * `tokenId=0` will cause the stake to mint to either the first tokenId for * the caller, or a new NFT tokenId if the sender does not yet have one. * @param reward The IMaverickV2Reward contract for which to stake. * @param tokenId Nft tokenId to stake for the staked tokens. * @return amount The amount of staking tokens staked. May differ from * input if there were unstaked tokens in the vault prior to this call. * @return stakedTokenId TokenId where liquidity was staked to. This may * differ from the input tokenId if the input `tokenId=0`. */ function stake( IMaverickV2Reward reward, uint256 tokenId ) external payable returns (uint256 amount, uint256 stakedTokenId); /** * @notice This function retrieves the address of the MaverickV2RewardFactory * contract associated with this contract. */ function rewardFactory() external view returns (IMaverickV2RewardFactory); /** * @notice This function transfers a specified amount of reward tokens from * the caller to a reward contract and notifies it to distribute them over * a defined duration. * @param reward The IMaverickV2Reward contract to notify. * @param rewardToken The address of the reward token to transfer. * @param duration The duration (in seconds) over which to distribute the rewards. * @return _duration The duration in seconds that the incentives will be distributed over. */ function notifyRewardAmount( IMaverickV2Reward reward, IERC20 rewardToken, uint256 duration ) external payable returns (uint256 _duration); /** * @notice This function transfers a specified amount of staking tokens from * the caller, stakes them on the recipient's behalf, and * associates them with a specified reward contract. * @param reward The IMaverickV2Reward contract for which to stake. * @param tokenId Nft tokenId to stake for the staked tokens. * @param _amount The amount of staking tokens to transfer and stake. * @return amount The amount of staking tokens staked. May differ from * input if there were unstaked tokens in the vault prior to this call. * @return stakedTokenId TokenId where liquidity was staked to. This may * differ from the input tokenIf if the input `tokenId=0`. * */ function transferAndStake( IMaverickV2Reward reward, uint256 tokenId, uint256 _amount ) external payable returns (uint256 amount, uint256 stakedTokenId); /** * @notice This function transfers a specified amount of reward tokens * from the caller and adds them to the reward contract as incentives. * @param reward The IMaverickV2Reward contract to notify. * @param rewardToken The address of the reward token to transfer. * @param duration The duration (in seconds) over which to distribute the rewards. * @param amount The amount of staking tokens to stake (uint256). * @return _duration The duration in seconds that the incentives will be distributed over. */ function transferAndNotifyRewardAmount( IMaverickV2Reward reward, IERC20 rewardToken, uint256 duration, uint256 amount ) external payable returns (uint256 _duration); /** * @notice This function creates a new BoostedPosition contract, adds * liquidity to a pool using the provided parameters, stakes the received * LP tokens, and associates them with a specified reward contract. * @param recipient The address to which the minted LP tokens will be * credited. * @param params A struct containing parameters for creating the * BoostedPosition (see IMaverickV2PoolLens.CreateBoostedPositionInputs). * @param rewardTokens An array of IERC20 token addresses representing the * available reward tokens for the staked LP position. * @param veTokens An array of IMaverickV2VotingEscrow contract addresses * representing the veTokens used for boosting. * @return boostedPosition The created IMaverickV2BoostedPosition contract. * @return mintedLpAmount The amount of LP tokens minted from the added liquidity. * @return tokenAAmount The amount of token A deposited for liquidity. * @return tokenBAmount The amount of token B deposited for liquidity. * @return stakeAmount The amount of LP tokens staked in the reward contract. * @return reward The IMaverickV2Reward contract. * @return tokenId Token on reward contract where user liquidity was staked. */ function createBoostedPositionAndAddLiquidityAndStake( address recipient, IMaverickV2PoolLens.CreateBoostedPositionInputs memory params, IERC20[] memory rewardTokens, IMaverickV2VotingEscrow[] memory veTokens ) external payable returns ( IMaverickV2BoostedPosition boostedPosition, uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount, uint256 stakeAmount, IMaverickV2Reward reward, uint256 tokenId ); /** * @notice This function is similar to * `createBoostedPositionAndAddLiquidityAndStake` but stakes the minted LP * tokens for the caller (msg.sender) instead of a specified recipient. * @param params A struct containing parameters for creating the * BoostedPosition (see IMaverickV2PoolLens.CreateBoostedPositionInputs). * @param rewardTokens An array of IERC20 token addresses representing the * available reward tokens for the staked LP position. * @param veTokens An array of IMaverickV2VotingEscrow contract addresses * representing the veTokens used for boosting. * @return boostedPosition The created IMaverickV2BoostedPosition contract. * @return mintedLpAmount The amount of LP tokens minted from the added liquidity. * @return tokenAAmount The amount of token A deposited for liquidity. * @return tokenBAmount The amount of token B deposited for liquidity. * @return stakeAmount The amount of LP tokens staked in the reward contract. * @return reward The IMaverickV2Reward contract associated with the staked LP position. * @return tokenId Token on reward contract where user liquidity was staked. */ function createBoostedPositionAndAddLiquidityAndStakeToSender( IMaverickV2PoolLens.CreateBoostedPositionInputs memory params, IERC20[] memory rewardTokens, IMaverickV2VotingEscrow[] memory veTokens ) external payable returns ( IMaverickV2BoostedPosition boostedPosition, uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount, uint256 stakeAmount, IMaverickV2Reward reward, uint256 tokenId ); /** * @notice This function adds liquidity to a pool using a pre-created * BoostedPosition contract, stakes the received LP tokens, and associates * them with a specified reward contract. * @param tokenId Token on reward contract where liquidity is to be staked. * @param boostedPosition The IMaverickV2BoostedPosition contract representing the existing boosted position. * @param packedSqrtPriceBreaks A packed representation of sqrt price * breaks for the liquidity range (see * IMaverickV2Pool.IAddLiquidityParams). * @param packedArgs Additional packed arguments for adding liquidity (see * IMaverickV2Pool.IAddLiquidityParams). * @param reward The IMaverickV2Reward contract for which to stake the LP tokens. * @return mintedLpAmount The amount of LP tokens minted from the added liquidity. * @return tokenAAmount The amount of token A deposited for liquidity. * @return tokenBAmount The amount of token B deposited for liquidity. * @return stakeAmount The amount of LP tokens staked in the reward contract. * */ function addLiquidityAndMintBoostedPositionAndStake( uint256 tokenId, IMaverickV2BoostedPosition boostedPosition, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs, IMaverickV2Reward reward ) external payable returns (uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount, uint256 stakeAmount); /** * @notice This function is similar to * `addLiquidityAndMintBoostedPositionAndStake` but uses the caller * (msg.sender) as the recipient for the minted reward stake. * @param sendersTokenIndex Token index of sender on the reward contract to * mint to. If sender does not have a token already, then this call will * mint one for the user. * @param boostedPosition The IMaverickV2BoostedPosition contract representing the existing boosted position. * @param packedSqrtPriceBreaks A packed representation of sqrt price breaks for the liquidity range (see IMaverickV2Pool.IAddLiquidityParams). * @param packedArgs Additional packed arguments for adding liquidity (see IMaverickV2Pool.IAddLiquidityParams). * @param reward The IMaverickV2Reward contract for which to stake the LP tokens. * @return mintedLpAmount The amount of LP tokens minted from the added liquidity. * @return tokenAAmount The amount of token A deposited for liquidity. * @return tokenBAmount The amount of token B deposited for liquidity. * @return stakeAmount The amount of LP tokens staked in the reward contract. * @return tokenId Token on reward contract where user liquidity was staked. */ function addLiquidityAndMintBoostedPositionAndStakeToSender( uint256 sendersTokenIndex, IMaverickV2BoostedPosition boostedPosition, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs, IMaverickV2Reward reward ) external payable returns ( uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount, uint256 stakeAmount, uint256 tokenId ); /** * @notice This function syncs the balance of a staker's votes on the * legacy ve mav contract with the new V2 ve mav contract. * @param ve The IMaverickV2VotingEscrowWSync contract to interact with. * @param staker The address of the user whose veToken lock may need syncing. * @param legacyLockupIndexes A list of indexes to synchronize from the * legacy veMav to the V2 ve contract. * */ function sync( IMaverickV2VotingEscrowWSync ve, address staker, uint256[] memory legacyLockupIndexes ) external returns (uint256[] memory newBalance); function mintTokenInRewardToSender(IMaverickV2Reward reward) external payable returns (uint256 tokenId); function mintTokenInReward(IMaverickV2Reward reward, address recipient) external payable returns (uint256 tokenId); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IMaverickV2RewardVault { error RewardVaultUnauthorizedAccount(address caller, address owner); /** * @notice This function allows the owner of the reward vault to withdraw a * specified amount of staking tokens to a recipient address. If non-owner * calls this function, it will revert. * @param recipient The address to which the withdrawn staking tokens will be sent. * @param amount The amount of staking tokens to withdraw. */ function withdraw(address recipient, uint256 amount) external; /** * @notice This function retrieves the address of the owner of the reward * vault contract. */ function owner() external view returns (address); /** * @notice This function retrieves the address of the ERC20 token used for * staking within the reward vault. */ function stakingToken() external view returns (IERC20); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IVotes} from "@openzeppelin/contracts/governance/utils/IVotes.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {IERC6372} from "@openzeppelin/contracts/interfaces/IERC6372.sol"; import {IHistoricalBalance} from "../votingescrowbase/IHistoricalBalance.sol"; interface IMaverickV2VotingEscrowBase is IVotes, IHistoricalBalance { error VotingEscrowTransferNotSupported(); error VotingEscrowInvalidAddress(address); error VotingEscrowInvalidAmount(uint256); error VotingEscrowInvalidDuration(uint256 duration, uint256 minDuration, uint256 maxDuration); error VotingEscrowInvalidEndTime(uint256 newEnd, uint256 oldEnd); error VotingEscrowStakeStillLocked(uint256 currentTime, uint256 endTime); error VotingEscrowStakeAlreadyRedeemed(); error VotingEscrowNotApprovedExtender(address account, address extender, uint256 lockupId); error VotingEscrowIncentiveAlreadyClaimed(address account, uint256 batchIndex); error VotingEscrowNoIncentivesToClaim(address account, uint256 batchIndex); error VotingEscrowInvalidExtendIncentiveToken(IERC20 incentiveToken); error VotingEscrowNoSupplyAtTimepoint(); error VotingEscrowIncentiveTimepointInFuture(uint256 timestamp, uint256 claimTimepoint); event Stake(address indexed user, uint256 lockupId, Lockup); event Unstake(address indexed user, uint256 lockupId, Lockup); event ExtenderApproval(address staker, address extender, uint256 lockupId, bool newState); event ClaimIncentiveBatch(uint256 batchIndex, address account, uint256 claimAmount); event CreateNewIncentiveBatch( address user, uint256 amount, uint256 timepoint, uint256 stakeDuration, IERC20 incentiveToken ); struct Lockup { uint128 amount; uint128 end; uint256 votes; } struct ClaimInformation { bool timepointInPast; bool hasClaimed; uint128 claimAmount; } struct BatchInformation { uint128 totalIncentives; uint128 stakeDuration; uint48 claimTimepoint; IERC20 incentiveToken; } struct TokenIncentiveTotals { uint128 totalIncentives; uint128 claimedIncentives; } // solhint-disable-next-line func-name-mixedcase function MIN_STAKE_DURATION() external returns (uint256 duration); // solhint-disable-next-line func-name-mixedcase function MAX_STAKE_DURATION() external returns (uint256 duration); // solhint-disable-next-line func-name-mixedcase function YEAR_BASE() external returns (uint256); /** * @notice This function retrieves the address of the ERC20 token used as the base token for staking and rewards. * @return baseToken The address of the IERC20 base token contract. */ function baseToken() external returns (IERC20); /** * @notice This function retrieves the starting timestamp. This may be used * for reward calculations or other time-based logic. */ function startTimestamp() external returns (uint256 timestamp); /** * @notice This function retrieves the details of a specific lockup for a given staker and lockup index. * @param staker The address of the staker for which to retrieve the lockup details. * @param index The index of the lockup within the staker's lockup history. * @return lockup A Lockup struct containing details about the lockup (see struct definition for details). */ function getLockup(address staker, uint256 index) external view returns (Lockup memory lockup); /** * @notice This function retrieves the total number of lockups associated with a specific staker. * @param staker The address of the staker for which to retrieve the lockup count. * @return count The total number of lockups for the staker. */ function lockupCount(address staker) external view returns (uint256 count); /** * @notice This function simulates a lockup scenario, providing details about the resulting lockup structure for a specified amount and duration. * @param amount The amount of tokens to be locked. * @param duration The duration of the lockup period. * @return lockup A Lockup struct containing details about the simulated lockup (see struct definition for details). */ function previewVotes(uint128 amount, uint256 duration) external view returns (Lockup memory lockup); /** * @notice This function grants approval for a designated extender contract to manage a specific lockup on behalf of the staker. * @param extender The address of the extender contract to be approved. * @param lockupId The ID of the lockup for which to grant approval. */ function approveExtender(address extender, uint256 lockupId) external; /** * @notice This function revokes approval previously granted to an extender contract for managing a specific lockup. * @param extender The address of the extender contract whose approval is being revoked. * @param lockupId The ID of the lockup for which to revoke approval. */ function revokeExtender(address extender, uint256 lockupId) external; /** * @notice This function checks whether a specific account has been approved by a staker to manage a particular lockup through an extender contract. * @param account The address of the account to check for approval (may be the extender or another account). * @param extender The address of the extender contract for which to check approval. * @param lockupId The ID of the lockup to verify approval for. * @return isApproved True if the account is approved for the lockup, False otherwise (bool). */ function isApprovedExtender(address account, address extender, uint256 lockupId) external view returns (bool); /** * @notice This function extends the lockup period for the caller (msg.sender) for a specified lockup ID, adding a new duration and amount. * @param lockupId The ID of the lockup to be extended. * @param duration The additional duration to extend the lockup by. * @param amount The additional amount of tokens to be locked. * @return newLockup A Lockup struct containing details about the newly extended lockup (see struct definition for details). */ function extendForSender( uint256 lockupId, uint256 duration, uint128 amount ) external returns (Lockup memory newLockup); /** * @notice This function extends the lockup period for a specified account, adding a new duration and amount. The caller (msg.sender) must be authorized to manage the lockup through an extender contract. * @param account The address of the account whose lockup is being extended. * @param lockupId The ID of the lockup to be extended. * @param duration The additional duration to extend the lockup by. * @param amount The additional amount of tokens to be locked. * @return newLockup A Lockup struct containing details about the newly extended lockup (see struct definition for details). */ function extendForAccount( address account, uint256 lockupId, uint256 duration, uint128 amount ) external returns (Lockup memory newLockup); /** * @notice This function merges multiple lockups associated with the caller * (msg.sender) into a single new lockup. * @param lockupIds An array containing the IDs of the lockups to be merged. * @return newLockup A Lockup struct containing details about the newly merged lockup (see struct definition for details). */ function merge(uint256[] memory lockupIds) external returns (Lockup memory newLockup); /** * @notice This function unstakes the specified lockup ID for the caller (msg.sender), returning the details of the unstaked lockup. * @param lockupId The ID of the lockup to be unstaked. * @param to The address to which the unstaked tokens should be sent (optional, defaults to msg.sender). * @return lockup A Lockup struct containing details about the unstaked lockup (see struct definition for details). */ function unstake(uint256 lockupId, address to) external returns (Lockup memory lockup); /** * @notice This function is a simplified version of `unstake` that automatically sends the unstaked tokens to the caller (msg.sender). * @param lockupId The ID of the lockup to be unstaked. * @return lockup A Lockup struct containing details about the unstaked lockup (see struct definition for details). */ function unstakeToSender(uint256 lockupId) external returns (Lockup memory lockup); /** * @notice This function stakes a specified amount of tokens for the caller * (msg.sender) for a defined duration. * @param amount The amount of tokens to be staked. * @param duration The duration of the lockup period. * @return lockup A Lockup struct containing details about the newly * created lockup (see struct definition for details). */ function stakeToSender(uint128 amount, uint256 duration) external returns (Lockup memory lockup); /** * @notice This function stakes a specified amount of tokens for a defined * duration, allowing the caller (msg.sender) to specify an optional * recipient for the staked tokens. * @param amount The amount of tokens to be staked. * @param duration The duration of the lockup period. * @param to The address to which the staked tokens will be credited (optional, defaults to msg.sender). * @return lockup A Lockup struct containing details about the newly * created lockup (see struct definition for details). */ function stake(uint128 amount, uint256 duration, address to) external returns (Lockup memory); /** * @notice This function retrieves the total incentive information for a specific ERC-20 token. * @param token The address of the ERC20 token for which to retrieve incentive totals. * @return totals A TokenIncentiveTotals struct containing details about * the token's incentives (see struct definition for details). */ function incentiveTotals(IERC20 token) external view returns (TokenIncentiveTotals memory); /** * @notice This function retrieves the total number of created incentive batches. * @return count The total number of incentive batches. */ function incentiveBatchCount() external view returns (uint256); /** * @notice This function retrieves claim information for a specific account and incentive batch index. * @param account The address of the account for which to retrieve claim information. * @param batchIndex The index of the incentive batch for which to retrieve * claim information. * @return claimInformation A ClaimInformation struct containing details about the * account's claims for the specified batch (see struct definition for * details). * @return batchInformation A BatchInformation struct containing details about the * specified batch (see struct definition for details). */ function claimAndBatchInformation( address account, uint256 batchIndex ) external view returns (ClaimInformation memory claimInformation, BatchInformation memory batchInformation); /** * @notice This function retrieves batch information for a incentive batch index. * @param batchIndex The index of the incentive batch for which to retrieve * claim information. * @return info A BatchInformation struct containing details about the * specified batch (see struct definition for details). */ function incentiveBatchInformation(uint256 batchIndex) external view returns (BatchInformation memory info); /** * @notice This function allows claiming rewards from a specific incentive * batch while simultaneously extending a lockup with the claimed tokens. * @param batchIndex The index of the incentive batch from which to claim rewards. * @param lockupId The ID of the lockup to be extended with the claimed tokens. * @return lockup A Lockup struct containing details about the updated * lockup after extension (see struct definition for details). * @return claimAmount The amount of tokens claimed from the incentive batch. */ function claimFromIncentiveBatchAndExtend( uint256 batchIndex, uint256 lockupId ) external returns (Lockup memory lockup, uint128 claimAmount); /** * @notice This function allows claiming rewards from a specific incentive * batch, without extending any lockups. * @param batchIndex The index of the incentive batch from which to claim rewards. * @return lockup A Lockup struct containing details about the user's * lockup that might have been affected by the claim (see struct definition * for details). * @return claimAmount The amount of tokens claimed from the incentive batch. */ function claimFromIncentiveBatch(uint256 batchIndex) external returns (Lockup memory lockup, uint128 claimAmount); /** * @notice This function creates a new incentive batch for a specified amount * of incentive tokens, timepoint, stake duration, and associated ERC-20 * token. An incentive batch is a reward of incentives put up by the * caller at a certain timepoint. The incentive batch is claimable by ve * holders after the timepoint has passed. The ve holders will receive * their incentive pro rata of their vote balance (`pastbalanceOf`) at that * timepoint. The incentivizer can specify that users have to stake the * resulting incentive for a given `stakeDuration` number of seconds. * `stakeDuration` can either be zero, meaning that no staking is required * on redemption, or can be a number between `MIN_STAKE_DURATION()` and * `MAX_STAKE_DURATION()`. * @param amount The total amount of incentive tokens to be distributed in the batch. * @param timepoint The timepoint at which the incentive batch starts accruing rewards. * @param stakeDuration The duration of the lockup period required to be * eligible for the incentive batch rewards. * @param incentiveToken The address of the ERC20 token used for the incentive rewards. * @return index The index of the newly created incentive batch. */ function createIncentiveBatch( uint128 amount, uint48 timepoint, uint128 stakeDuration, IERC20 incentiveToken ) external returns (uint256 index); } interface IMaverickV2VotingEscrow is IMaverickV2VotingEscrowBase, IERC20Metadata, IERC6372 {}
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import {IMaverickV2VotingEscrow} from "./IMaverickV2VotingEscrow.sol"; interface IMaverickV2VotingEscrowFactory { error VotingEscrowTokenAlreadyExists(IERC20 baseToken, IMaverickV2VotingEscrow veToken); event CreateVotingEscrow(IERC20 baseToken, IMaverickV2VotingEscrow veToken); /** * @notice This function retrieves the address of the legacy Maverick V1 * Voting Escrow (veMAV) token. The address will be zero for blockchains * where this contract is deployed that do not have a legacy MAV contract * deployed. * @return legacyVeMav The address of the IERC20 legacy veMav token. */ function legacyVeMav() external view returns (IERC20); /** * @notice This function checks whether a provided IMaverickV2VotingEscrow * contract address was created by this factory. * @param veToken The address of the IMaverickV2VotingEscrow contract to be checked. * @return isFactoryToken True if the veToken was created by this factory, False otherwise (bool). */ function isFactoryToken(IMaverickV2VotingEscrow veToken) external view returns (bool); /** * @notice This function creates a new Maverick V2 Voting Escrow (veToken) * contract for a specified ERC20 base token. * @dev Once the ve contract is created, it will call `name()` and * `symbol()` on the `baseToken`. If those functions do not exist, the ve * creation will revert. * @param baseToken The address of the ERC-20 token to be used as the base token for the new veToken. * @return veToken The address of the newly created IMaverickV2VotingEscrow contract. */ function createVotingEscrow(IERC20 baseToken) external returns (IMaverickV2VotingEscrow veToken); /** * @notice This function retrieves a paginated list of existing Maverick V2 * Voting Escrow (veToken) contracts within a specified index range. * @param startIndex The starting index for the desired range of veTokens. * @param endIndex The ending index for the desired range of veTokens. * @return votingEscrows An array of IMaverickV2VotingEscrow addresses * representing the veTokens within the specified range. */ function votingEscrows( uint256 startIndex, uint256 endIndex ) external view returns (IMaverickV2VotingEscrow[] memory votingEscrows); /** * @notice This function retrieves the total number of deployed Maverick V2 * Voting Escrow (veToken) contracts. * @return count The total number of veTokens. */ function votingEscrowsCount() external view returns (uint256 count); /** * @notice This function retrieves the address of the existing Maverick V2 * Voting Escrow (veToken) contract associated with a specific ERC20 base * token. * @param baseToken The address of the ERC-20 base token for which to retrieve the veToken address. * @return veToken The address of the IMaverickV2VotingEscrow contract * associated with the base token, or the zero address if none exists. */ function veForBaseToken(IERC20 baseToken) external view returns (IMaverickV2VotingEscrow veToken); /** * @notice This function retrieves the default base token used for creating * new voting escrow contracts. This state variable is only used * temporarily when a new veToken is deployed. * @return baseToken The address of the default ERC-20 base token. */ function baseTokenParameter() external returns (IERC20); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IMaverickV2VotingEscrowWSync { error VotingEscrowLockupEndTooShortToSync(uint256 legacyLockupEnd, uint256 minimumLockupEnd); event Sync(address staker, uint256 legacyLockupIndex, uint256 newBalance); /** * @notice This function retrieves the minimum lockup duration required for * a legacy lockup to be eligible for synchronization. * @return minSyncDuration The minimum allowed lockup end time. */ // solhint-disable-next-line func-name-mixedcase function MIN_SYNC_DURATION() external pure returns (uint256 minSyncDuration); /** * @notice This function retrieves the address of the legacy Maverick V1 * Voting Escrow (veMav) token. * @return legacyVeMav The address of the IERC20 legacy veMav token. */ function legacyVeMav() external view returns (IERC20); /** * @notice This function retrieves the synced balance for a specific legacy lockup index of a user. * @param staker The address of the user for whom to retrieve the synced balance. * @param legacyLockupIndex The index of the legacy lockup for which to * retrieve the synced balance. * @return balance The synced balance associated with the legacy lockup. */ function syncBalances(address staker, uint256 legacyLockupIndex) external view returns (uint256 balance); /** * @notice This function synchronizes a specific legacy lockup index for a * user within the contract. If the legacy lockup.end is not at least * `block.timestamp + MIN_SYNC_DURATION()`, this function will revert. * @param staker The address of the user for whom to perform synchronization. * @param legacyLockupIndex The index of the legacy lockup to be * synchronized. * @return newBalance The new balance resulting from the synchronization * process. */ function sync(address staker, uint256 legacyLockupIndex) external returns (uint256 newBalance); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; interface IRewardAccounting { error InsufficientBalance(uint256 tokenId, uint256 currentBalance, uint256 value); /** * @notice Balance of stake for a given `tokenId` account. */ function stakeBalanceOf(uint256 tokenId) external view returns (uint256 balance); /** * @notice Sum of all balances across all tokenIds. */ function stakeTotalSupply() external view returns (uint256 supply); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; interface IHistoricalBalance { /** * @notice This function retrieves the historical balance of an account at * a specific point in time. * @param account The address of the account for which to retrieve the * historical balance. * @param timepoint The timepoint (block number or timestamp depending on * implementation) at which to query the balance (uint256). * @return balance The balance of the account at the specified timepoint. */ function getPastBalanceOf(address account, uint256 timepoint) external view returns (uint256 balance); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {IChecks} from "./IChecks.sol"; import {PoolInspection} from "../libraries/PoolInspection.sol"; abstract contract Checks is IChecks { /// @inheritdoc IChecks function checkSqrtPrice(IMaverickV2Pool pool, uint256 minSqrtPrice, uint256 maxSqrtPrice) public payable { uint256 sqrtPrice = PoolInspection.poolSqrtPrice(pool); if (sqrtPrice < minSqrtPrice || sqrtPrice > maxSqrtPrice) revert PositionExceededPriceBounds(sqrtPrice, minSqrtPrice, maxSqrtPrice); } /// @inheritdoc IChecks function checkDeadline(uint256 deadline) public payable { if (block.timestamp > deadline) revert PositionDeadlinePassed(deadline, block.timestamp); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; interface IChecks { error PositionExceededPriceBounds(uint256 sqrtPrice, uint256 minSqrtPrice, uint256 maxSqrtPrice); error PositionDeadlinePassed(uint256 deadline, uint256 blockTimestamp); /** * @notice Function to check if the price of a pool is within specified bounds. * @param pool The MaverickV2Pool contract to check. * @param minSqrtPrice The minimum acceptable square root price. * @param maxSqrtPrice The maximum acceptable square root price. */ function checkSqrtPrice(IMaverickV2Pool pool, uint256 minSqrtPrice, uint256 maxSqrtPrice) external payable; /** * @notice Function to check if a given deadline has passed. * @param deadline The timestamp representing the deadline. */ function checkDeadline(uint256 deadline) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; interface IMigrateBins { function migrateBinsUpStack(IMaverickV2Pool pool, uint32[] calldata binIds, uint32 maxRecursion) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {IMigrateBins} from "./IMigrateBins.sol"; abstract contract MigrateBins is IMigrateBins { /** * @dev Migrates bins up the stack in the pool. * @param pool The MaverickV2Pool contract. * @param binIds An array of bin IDs to migrate. * @param maxRecursion The maximum recursion depth. */ function migrateBinsUpStack(IMaverickV2Pool pool, uint32[] memory binIds, uint32 maxRecursion) public payable { for (uint256 i = 0; i < binIds.length; i++) { pool.migrateBinUpStack(binIds[i], maxRecursion); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {IMulticall} from "@maverick/v2-common/contracts/base/IMulticall.sol"; import {IChecks} from "../base/IChecks.sol"; interface IBoostedPositionBase is IERC20Metadata, IChecks, IMulticall { /** * @notice BP Pool. */ function pool() external view returns (IMaverickV2Pool pool_); /** * @notice BP Bin kind (static, right, left, both). */ function kind() external view returns (uint8 kind_); /** * @notice Number of bins in the BP. */ function binCount() external view returns (uint8 binCount_); /** * @notice Liquidity balance in BP bins since last mint/burn operation. */ function getBinBalances() external view returns (uint128[] memory binBalances_); /** * @notice Liquidity balance in given BP bin since last mint/burn * operation. */ function binBalances(uint256 index) external view returns (uint128 binBalance); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IBoostedPositionBase} from "../boostedpositionbase/IBoostedPositionBase.sol"; interface IMaverickV2BoostedPosition is IBoostedPositionBase { event BoostedPositionMigrateBinLiquidity(uint32 currentBinId, uint32 newBinId, uint128 newBinBalance); error BoostedPositionTooLittleLiquidityAdded(uint256 binIdIndex, uint32 binId, uint128 required, uint128 available); error BoostedPositionMovementBinNotMigrated(); /** * @notice Mints BP LP position to recipient. User has to add liquidity to * BP contract before making this call as this mint function simply assigns * any new liquidity that this BP possesses in the pool to the recipient. * Accordingly, this function should only be called in the same transaction * where liquidity has been added to a pool as part of a multicall or * through a router/manager contract. */ function mint(address recipient) external returns (uint256 deltaSupply); /** * @notice Burns BP LP positions and redeems the underlying A/B token to the recipient. */ function burn(address recipient, uint256 amount) external returns (uint256 tokenAOut, uint256 tokenBOut); /** * @notice Migrates all underlying movement-mode liquidity from a merged * bin to the active parent of the merged bin. For Static BPs, this * function is a no-op and never needs to be called. */ function migrateBinLiquidityToRoot() external; /** * @notice Array of ticks where the underlying BP liquidity exists. */ function getTicks() external view returns (int32[] memory ticks); /** * @notice Array of relative pool bin LP balance of the bins in the BP. */ function getRatios() external view returns (uint128[] memory ratios_); /** * @notice Array of BP binIds. Will revert if the BP is a movement mode * and the underlying bin is merged. */ function getBinIds() external view returns (uint32[] memory binIds_); /** * @notice Array of BP binIds. Will not revert if the BP is a movement mode * and the underlying bin is merged. For statis BPs, this returns the same * value as `getBinIds`. */ function getRawBinIds() external view returns (uint32[] memory); /** * @notice Removes excess liquidity from the binId[0] bin and sends to * recipient. Skimming is desirable if there is more than one bin in the BP * and the skimmable amount is non-zero. * Skimming amount is only applicable if the number of bins is more than * one. For single-bin BPs, a user can effectively "skim" by minting BP * tokens to themselves. */ function skim(address recipient) external returns (uint256 tokenAOut, uint256 tokenBOut); /** * @notice Returns the amount of binIds[0] LP balance that is skimmable in * the BP. If this number is non-zero, it is desirable to skim before * minting to ensure that the ratio solvency checks pass. Checking the * skimmable amount is only applicable if the number of bins is more than * one. For single-bin BPs, a user can effectively "skim" by minting BP * tokens to themselves. */ function skimmableAmount() external view returns (uint128 amount); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Factory} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Factory.sol"; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {IMaverickV2BoostedPosition} from "./IMaverickV2BoostedPosition.sol"; interface IMaverickV2BoostedPositionFactory { error BoostedPositionFactoryNotFactoryPool(); error BoostedPositionPermissionedLiquidityPool(); error BoostedPositionFactoryKindNotSupportedByPool(uint8 poolKinds, uint8 kind); error BoostedPositionFactoryInvalidRatioZero(uint128 ratioZero); error BoostedPositionFactoryInvalidLengths(uint256 ratioLength, uint256 binIdsLength); error BoostedPositionFactoryInvalidLengthForKind(uint8 kind, uint256 ratiosLength); error BoostedPositionFactoryBinIdsNotSorted(uint256 index, uint32 lastBinId, uint32 thisBinId); error BoostedPositionFactoryInvalidBinKind(uint8 inputKind, uint8 binKind, uint32 binId); event CreateBoostedPosition( IMaverickV2Pool pool, uint32[] binIds, uint128[] ratios, uint8 kind, IMaverickV2BoostedPosition boostedPosition ); /** * @notice Creates BP from the specified input parameters. Requirements: * * - Pool must be from pool factory * - BP kind must be supported by the pool * - BinIds have to be sorted in ascending order * - ratios[0] must be 1e18; ratios are specified in D18 scale * - ratio and binId arrays have to be the same length * - movement-mode BPs can only have one binId * - static-mode BPs can have at most 24 binIds */ function createBoostedPosition( IMaverickV2Pool pool, uint32[] memory binIds, uint128[] memory ratios, uint8 kind ) external returns (IMaverickV2BoostedPosition boostedPosition); /** * @notice Look up BPs by range of indexes. */ function lookup(uint256 startIndex, uint256 endIndex) external view returns (IMaverickV2BoostedPosition[] memory); /** * @notice Returns count of all BPs deployed by the factory. */ function boostedPositionsCount() external view returns (uint256 count); /** * @notice Look up BPs by range of indexes for a given pool. */ function lookup( IMaverickV2Pool pool, uint256 startIndex, uint256 endIndex ) external view returns (IMaverickV2BoostedPosition[] memory); /** * @notice Returns count of all BPs deployed by the factory for a given * pool. */ function boostedPositionsByPoolCount(IMaverickV2Pool pool) external view returns (uint256 count); /** * @notice Returns whether or not input BP was created by this factory. */ function isFactoryBoostedPosition(IMaverickV2BoostedPosition) external returns (bool); /** * @notice Pool factory that all BPs pool must be deployed from. */ function poolFactory() external returns (IMaverickV2Factory); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {IMaverickV2Position} from "./IMaverickV2Position.sol"; import {IMaverickV2BoostedPosition} from "./IMaverickV2BoostedPosition.sol"; import {IMaverickV2PoolLens} from "./IMaverickV2PoolLens.sol"; import {IMaverickV2BoostedPositionFactory} from "./IMaverickV2BoostedPositionFactory.sol"; import {IArgPacker} from "../liquiditybase/IArgPacker.sol"; import {IExactOutputSlim} from "../routerbase/IExactOutputSlim.sol"; import {IPayment} from "../paymentbase/IPayment.sol"; import {IChecks} from "../base/IChecks.sol"; import {IMigrateBins} from "../base/IMigrateBins.sol"; interface IMaverickV2LiquidityManager is IPayment, IChecks, IExactOutputSlim, IArgPacker, IMigrateBins { error LiquidityManagerNotFactoryPool(); error LiquidityManagerNotTokenIdOwner(); /** * @notice Maverick V2 NFT position contract that tracks NFT-based * liquditiy positions. */ function position() external view returns (IMaverickV2Position); /** * @notice Maverick V2 BP factory contract. */ function boostedPositionFactory() external view returns (IMaverickV2BoostedPositionFactory); /** * @notice Create Maverick V2 pool. Function is a pass through to the pool * factory and is provided here so that is can be assembled as part of a * multicall transaction. */ function createPool( uint64 fee, uint16 tickSpacing, uint32 lookback, IERC20 tokenA, IERC20 tokenB, int32 activeTick, uint8 kinds ) external payable returns (IMaverickV2Pool pool); /** * @notice Create Maverick V2 pool with two-way fees. Function is a pass * through to the pool factory and is provided here so that is can be * assembled as part of a multicall transaction. */ function createPool( uint64 feeAIn, uint64 feeBIn, uint16 tickSpacing, uint32 lookback, IERC20 tokenA, IERC20 tokenB, int32 activeTick, uint8 kinds ) external payable returns (IMaverickV2Pool pool); /** * @notice Add Liquidity to a Maverick V2 pool. Function is a pass through * to the pool and is provided here so that is can be assembled as part of a * multicall transaction. Users can add liquidity to the Position NFT * contract or a BP as part of a multicall in order to mint NFT/BP * positions. * @dev Liquidity is specified as bytes that represent a lookup table of * add parameters. This allows an adder to specify what liquidity amounts * they wish to add conditional on the price of the pool when their * transaction is executed. With this, users have fine-grain control of how * price slippage affects the amount of liquidity they add. The * MaverickV2PoolLens contract has helper view functions that can be used * to easily create a combination of price breaks and packed arguments. */ function addLiquidity( IMaverickV2Pool pool, address recipient, uint256 subaccount, bytes calldata packedSqrtPriceBreaks, bytes[] calldata packedArgs ) external payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds); /** * @notice Add Liquidity position NFT for msg.sender by specifying * msg.sender's token index. * @dev Token index is different from tokenId. * On the Position NFT contract a user can own multiple NFT tokenIds and * these are indexes by an enumeration index which is the `index` input * here. * * See addLiquidity for a description of the add params. */ function addPositionLiquidityToSenderByTokenIndex( IMaverickV2Pool pool, uint256 index, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) external payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds); /** * @notice Add Liquidity position NFT for msg.sender by specifying * recipient's token index. * @dev Token index is different from tokenId. * On the Position NFT contract a user can own multiple NFT tokenIds and * these are indexes by an enumeration index which is the `index` input * here. * * See addLiquidity for a description of the add params. */ function addPositionLiquidityToRecipientByTokenIndex( IMaverickV2Pool pool, address recipient, uint256 index, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) external payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds); /** * @notice Pass through function to the BP bin migration. */ function migrateBoostedPosition(IMaverickV2BoostedPosition boostedPosition) external payable; /** * @notice Mint new tokenId in the Position NFT contract. Both mints an NFT * and adds liquidity to the pool that is held by the NFT. * @dev Caller must approve this LiquidityManager contract to spend the * caller's token A/B in order to fund the liquidity position. * * See addLiquidity for a description of the add params. */ function mintPositionNft( IMaverickV2Pool pool, address recipient, bytes calldata packedSqrtPriceBreaks, bytes[] calldata packedArgs ) external payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId); /** * @notice Mint new tokenId in the Position NFt contract to msg.sender. * Both mints an NFT and adds liquidity to the pool that is held by the * NFT. */ function mintPositionNftToSender( IMaverickV2Pool pool, bytes calldata packedSqrtPriceBreaks, bytes[] calldata packedArgs ) external payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId); /** * @notice Mint BP LP tokens to recipient. This function does not add * liquidity to the BP and is only useful in conjuction with addLiquidity * as part of a multcall. */ function mintBoostedPosition( IMaverickV2BoostedPosition boostedPosition, address recipient ) external payable returns (uint256 mintedLpAmount); /** * @notice Donates liqudity to a pool that is held by the position contract * and will never be retrievable. Can be used to start a pool and ensure * there will always be a base level of liquditiy in the pool. */ function donateLiquidity(IMaverickV2Pool pool, IMaverickV2Pool.AddLiquidityParams memory args) external payable; /** * @notice Creates a pool at a specified price and mints a Position NFT * with liquidity to the recipient. * @dev A Maverick V2 pool has no native was to specify a starting price, * only a starting `activeTick`. The initial pool price will be the left * edge of the initial activeTick. In order to create a pool at a fixed * price, this function dontes a small amount of liquidity to the pool, does * a swap to the specified price, and then adds liquidity for the user. */ function createPoolAtPriceAndAddLiquidity( address recipient, IMaverickV2PoolLens.CreateAndAddParamsInputs memory params ) external payable returns ( IMaverickV2Pool pool, uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId ); /** * @notice Creates a pool at a specified price and mints a Position NFT * with liquidity to msg.sender. */ function createPoolAtPriceAndAddLiquidityToSender( IMaverickV2PoolLens.CreateAndAddParamsInputs memory params ) external payable returns ( IMaverickV2Pool pool, uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId ); /** * @notice Executes the multi-step process of minting BP LP positions by * adding liqudiity to a pool in the BP liquidity distribution and then * minting the BP to recipient. * @dev Caller will need to approve this LiquidityManager contract to spend * their token A/B in order to execute this function. */ function addLiquidityAndMintBoostedPosition( address recipient, IMaverickV2BoostedPosition boostedPosition, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) external payable returns (uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount); /** * @notice Executes the multi-step process of minting BP LP positions by * adding liquidity to a pool in the BP liquidity distribution and then * minting the BP to msg.sender. * @dev Caller will need to approve this LiquidityManager contract to spend * their token A/B in order to execute this function. */ function addLiquidityAndMintBoostedPositionToSender( IMaverickV2BoostedPosition boostedPosition, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) external payable returns (uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount); /** * @notice Deploy new BP contract from the BP factory and mint BP LP tokens * to the recipient. * @dev Caller will need to approve this LiquidityManager contract to spend * their token A/B in order to execute this function. */ function createBoostedPositionAndAddLiquidity( address recipient, IMaverickV2PoolLens.CreateBoostedPositionInputs memory params ) external payable returns ( IMaverickV2BoostedPosition boostedPosition, uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount ); /** * @notice Deploy new BP contract from the BP factory and mint BP LP tokens * to msg.sender. * @dev Caller will need to approve this LiquidityManager contract to spend * their token A/B in order to execute this function. */ function createBoostedPositionAndAddLiquidityToSender( IMaverickV2PoolLens.CreateBoostedPositionInputs memory params ) external payable returns ( IMaverickV2BoostedPosition boostedPosition, uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount ); /** * @notice Skims excess liquidity in a BP to the recipient. */ function skimBoostedPosition( IMaverickV2BoostedPosition boostedPosition, address recipient ) external payable returns (uint256 tokenAAmount, uint256 tokenBAmount); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IMaverickV2Factory} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Factory.sol"; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {IMaverickV2BoostedPosition} from "./IMaverickV2BoostedPosition.sol"; interface IMaverickV2PoolLens { error LensTargetPriceOutOfBounds(uint256 targetSqrtPrice, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice); error LensTooLittleLiquidity(uint256 relativeLiquidityAmount, uint256 deltaA, uint256 deltaB); error LensTargetingTokenWithNoDelta(bool targetIsA, uint256 deltaA, uint256 deltaB); /** * @notice Add liquidity slippage parameters for a distribution of liquidity. * @param pool Pool where liquidity is being added. * @param kind Bin kind; all bins must have the same kind in a given call * to addLiquidity. * @param ticks Array of tick values to add liquidity to. * @param relativeLiquidityAmounts Relative liquidity amounts for the * specified ticks. Liquidity in this case is not bin LP balance, it is * the bin liquidity as defined by liquidity = deltaA / (sqrt(upper) - * sqrt(lower)) or deltaB = liquidity / sqrt(lower) - liquidity / * sqrt(upper). * @param addSpec Slippage specification. */ struct AddParamsViewInputs { IMaverickV2Pool pool; uint8 kind; int32[] ticks; uint128[] relativeLiquidityAmounts; AddParamsSpecification addSpec; } /** * @notice Multi-price add param specification. * @param slippageFactorD18 Max slippage allowed as a percent in D18 scale. e.g. 1% slippage is 0.01e18 * @param numberOfPriceBreaksPerSide Number of price break values on either * side of current price. * @param targetAmount Target token contribution amount in tokenA if * targetIsA is true, otherwise this is the target amount for tokenB. * @param targetIsA Indicates if the target amount is for tokenA or tokenB */ struct AddParamsSpecification { uint256 slippageFactorD18; uint256 numberOfPriceBreaksPerSide; uint256 targetAmount; bool targetIsA; } /** * @notice Boosted position creation specification and add parameters. * @param bpSpec Boosted position kind/binId/ratio information. * @param packedSqrtPriceBreaks Array of sqrt price breaks packed into * bytes. These breaks act as a lookup table for the packedArgs array to * indicate to the Liquidity manager what add liquidity parameters from * packedArgs to use depending on the price of the pool at add time. * @param packedArgs Array of bytes arguments. Each array element is a * packed version of addLiquidity paramters. */ struct CreateBoostedPositionInputs { BoostedPositionSpecification bpSpec; bytes packedSqrtPriceBreaks; bytes[] packedArgs; } /** * @notice Specification for deriving create pool parameters. Creating a pool in the liquidity manager has several steps: * * - Deploy pool * - Donate a small amount of initial liquidity in the activeTick * - Execute a small swap to set the pool price to the desired value * - Add liquidity * * In order to execute these steps, the caller must specify the parameters * of each step. The PoolLens has helper function to derive the values * used by the LiquidityManager, but this struct is the input to that * helper function and represents the core intent of the pool creator. * * @param fee Fraction of the pool swap amount that is retained as an LP in * D18 scale. * @param tickSpacing Tick spacing of pool where 1.0001^tickSpacing is the * bin width. * @param lookback Pool lookback in seconds. * @param tokenA Address of tokenA. * @param tokenB Address of tokenB. * @param activeTick Tick position that contains the active bins. * @param kinds 1-15 number to represent the active kinds * 0b0001 = static; * 0b0010 = right; * 0b0100 = left; * 0b1000 = both. * e.g. a pool with all 4 modes will have kinds = b1111 = 15 * @param initialTargetB Amount of B to be donated to the pool after pool * create. This amount needs to be big enough to meet the minimum bin * liquidity. * @param sqrtPrice Target sqrt price of the pool. * @param kind Bin kind; all bins must have the same kind in a given call * to addLiquidity. * @param ticks Array of tick values to add liquidity to. * @param relativeLiquidityAmounts Relative liquidity amounts for the * specified ticks. Liquidity in this case is not bin LP balance, it is * the bin liquidity as defined by liquidity = deltaA / (sqrt(upper) - * sqrt(lower)) or deltaB = liquidity / sqrt(lower) - liquidity / * sqrt(upper). * @param targetAmount Target token contribution amount in tokenA if * targetIsA is true, otherwise this is the target amount for tokenB. * @param targetIsA Indicates if the target amount is for tokenA or tokenB */ struct CreateAndAddParamsViewInputs { uint64 feeAIn; uint64 feeBIn; uint16 tickSpacing; uint32 lookback; IERC20 tokenA; IERC20 tokenB; int32 activeTick; uint8 kinds; // donate params uint256 initialTargetB; uint256 sqrtPrice; // add target uint8 kind; int32[] ticks; uint128[] relativeLiquidityAmounts; uint256 targetAmount; bool targetIsA; } struct Output { uint256 deltaAOut; uint256 deltaBOut; uint256[] deltaAs; uint256[] deltaBs; uint128[] deltaLpBalances; } struct Reserves { uint256 amountA; uint256 amountB; } struct BinPositionKinds { uint128[4] values; } struct PoolState { IMaverickV2Pool.TickState[] tickStateMapping; IMaverickV2Pool.BinState[] binStateMapping; BinPositionKinds[] binIdByTickKindMapping; IMaverickV2Pool.State state; Reserves protocolFees; } struct BoostedPositionSpecification { IMaverickV2Pool pool; uint32[] binIds; uint128[] ratios; uint8 kind; } struct CreateAndAddParamsInputs { uint64 feeAIn; uint64 feeBIn; uint16 tickSpacing; uint32 lookback; IERC20 tokenA; IERC20 tokenB; int32 activeTick; uint8 kinds; // donate params IMaverickV2Pool.AddLiquidityParams donateParams; // swap params uint256 swapAmount; // add params IMaverickV2Pool.AddLiquidityParams addParams; bytes[] packedAddParams; uint256 deltaAOut; uint256 deltaBOut; uint256 preAddReserveA; uint256 preAddReserveB; } struct TickDeltas { uint256 deltaAOut; uint256 deltaBOut; uint256[] deltaAs; uint256[] deltaBs; } /** * @notice Converts add parameter slippage specification into add * parameters. The return values are given in both raw format and as packed * values that can be used in the LiquidityManager contract. */ function getAddLiquidityParams( AddParamsViewInputs memory params ) external view returns ( bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs, uint88[] memory sqrtPriceBreaks, IMaverickV2Pool.AddLiquidityParams[] memory addParams, IMaverickV2PoolLens.TickDeltas[] memory tickDeltas ); /** * @notice Converts add parameter slippage specification for a boosted * position into add parameters. The return values are given in both raw * format and as packed values that can be used in the LiquidityManager * contract. */ function getAddLiquidityParamsForBoostedPosition( IMaverickV2BoostedPosition boostedPosition, AddParamsSpecification memory addSpec ) external view returns ( bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs, uint88[] memory sqrtPriceBreaks, IMaverickV2Pool.AddLiquidityParams[] memory addParams, IMaverickV2PoolLens.TickDeltas[] memory tickDeltas ); /** * @notice Converts add parameter slippage specification and boosted * position specification into add parameters. The return values are given * in both raw format and as packed values that can be used in the * LiquidityManager contract. */ function getCreateBoostedPositionParams( BoostedPositionSpecification memory bpSpec, AddParamsSpecification memory addSpec ) external view returns ( bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs, uint88[] memory sqrtPriceBreaks, IMaverickV2Pool.AddLiquidityParams[] memory addParams, IMaverickV2PoolLens.TickDeltas[] memory tickDeltas ); /** * @notice Converts add parameter slippage specification and new pool * specification into CreateAndAddParamsInputs parameters that can be used in the * LiquidityManager contract. */ function getCreatePoolAtPriceAndAddLiquidityParams( CreateAndAddParamsViewInputs memory params, IMaverickV2Factory factory ) external view returns (CreateAndAddParamsInputs memory output); /** * @notice View function that provides information about pool ticks within * a tick radius from the activeTick. Ticks with no reserves are not * included in part o f the return array. */ function getTicksAroundActive( IMaverickV2Pool pool, int32 tickRadius ) external view returns (int32[] memory ticks, IMaverickV2Pool.TickState[] memory tickStates); /** * @notice View function that provides information about pool ticks within * a range. Ticks with no reserves are not included in part o f the return * array. */ function getTicks( IMaverickV2Pool pool, int32 tickStart, int32 tickEnd ) external view returns (int32[] memory ticks, IMaverickV2Pool.TickState[] memory tickStates); /** * @notice View function that provides information about pool ticks within * a range. Information returned includes all pool state needed to emulate * a swap off chain. Ticks with no reserves are not included in part o f * the return array. */ function getTicksAroundActiveWLiquidity( IMaverickV2Pool pool, int32 tickRadius ) external view returns ( int32[] memory ticks, IMaverickV2Pool.TickState[] memory tickStates, uint256[] memory liquidities, uint256[] memory sqrtLowerTickPrices, uint256[] memory sqrtUpperTickPrices, IMaverickV2Pool.State memory poolState, uint256 sqrtPrice, uint256 feeAIn, uint256 feeBIn ); /** * @notice View function that provides pool state information. */ function getFullPoolState( IMaverickV2Pool pool, uint32 binStart, uint32 binEnd ) external view returns (PoolState memory poolState); /** * @notice View function that provides price and liquidity of a given tick. */ function getTickSqrtPriceAndL( IMaverickV2Pool pool, int32 tick ) external view returns (uint256 sqrtPrice, uint256 liquidity); /** * @notice Pool sqrt price. */ function getPoolSqrtPrice(IMaverickV2Pool pool) external view returns (uint256 sqrtPrice); /** * @notice Pool price. */ function getPoolPrice(IMaverickV2Pool pool) external view returns (uint256 price); /** * @notice Token scale of two tokens in a pool. */ function tokenScales(IMaverickV2Pool pool) external view returns (uint256 tokenAScale, uint256 tokenBScale); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Factory} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Factory.sol"; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {IMulticall} from "@maverick/v2-common/contracts/base/IMulticall.sol"; import {IPositionImage} from "./IPositionImage.sol"; import {INft} from "../positionbase/INft.sol"; import {IMigrateBins} from "../base/IMigrateBins.sol"; import {IChecks} from "../base/IChecks.sol"; interface IMaverickV2Position is INft, IMigrateBins, IMulticall, IChecks { event PositionClearData(uint256 indexed tokenId); event PositionSetData(uint256 indexed tokenId, uint256 index, PositionPoolBinIds newData); error PositionDuplicatePool(uint256 index, IMaverickV2Pool pool); error PositionNotFactoryPool(); error PositionPermissionedLiquidityPool(); struct PositionPoolBinIds { IMaverickV2Pool pool; uint32[] binIds; } struct PositionFullInformation { PositionPoolBinIds poolBinIds; uint256 amountA; uint256 amountB; uint256[] binAAmounts; uint256[] binBAmounts; int32[] ticks; uint256[] liquidities; } /** * @notice Contract that renders the position nft svg image. */ function positionImage() external view returns (IPositionImage); /** * @notice Pool factory. */ function factory() external view returns (IMaverickV2Factory); /** * @notice Mint NFT that holds liquidity in a Maverick V2 Pool. To mint * liquidity to an NFT, add liquidity to bins in a pool where the * add liquidity recipient is this contract and the subaccount is the * tokenId. LiquidityManager can be used to simplify minting Position NFTs. */ function mint(address recipient, IMaverickV2Pool pool, uint32[] memory binIds) external returns (uint256 tokenId); /** * @notice Overwrites tokenId pool/binId information for a given data index. */ function setTokenIdData(uint256 tokenId, uint256 index, IMaverickV2Pool pool, uint32[] memory binIds) external; /** * @notice Overwrites entire pool/binId data set for a given tokenId. */ function setTokenIdData(uint256 tokenId, PositionPoolBinIds[] memory data) external; /** * @notice Append new pool/binIds data array to tokenId. */ function appendTokenIdData(uint256 tokenId, IMaverickV2Pool pool, uint32[] memory binIds) external; /** * @notice Get array pool/binIds data for a given tokenId. */ function getTokenIdData(uint256 tokenId) external view returns (PositionPoolBinIds[] memory); /** * @notice Get value from array of pool/binIds data for a given tokenId. */ function getTokenIdData(uint256 tokenId, uint256 index) external view returns (PositionPoolBinIds memory); /** * @notice Length of array of pool/binIds data for a given tokenId. */ function tokenIdDataLength(uint256 tokenId) external view returns (uint256 length); /** * @notice Remove liquidity from tokenId for a given pool. User can * specify arbitrary bins to remove from for their subaccount in the pool * even if those bins are not in the tokenIdData set. */ function removeLiquidity( uint256 tokenId, address recipient, IMaverickV2Pool pool, IMaverickV2Pool.RemoveLiquidityParams memory params ) external returns (uint256 tokenAAmount, uint256 tokenBAmount); /** * @notice Remove liquidity from tokenId for a given pool to sender. User * can specify arbitrary bins to remove from for their subaccount in the * pool even if those bins are not in the tokenIdData set. */ function removeLiquidityToSender( uint256 tokenId, IMaverickV2Pool pool, IMaverickV2Pool.RemoveLiquidityParams memory params ) external returns (uint256 tokenAAmount, uint256 tokenBAmount); /** * @notice NFT asset information for a given range of pool/binIds indexes. * This function only returns the liquidity in the pools/binIds stored as * part of the tokenIdData, but it is possible that the NFT has additional * liquidity in pools/binIds that have not been recorded. */ function tokenIdPositionInformation( uint256 tokenId, uint256 startIndex, uint256 stopIndex ) external view returns (PositionFullInformation[] memory output); /** * @notice NFT asset information for a given pool/binIds index. This * function only returns the liquidity in the pools/binIds stored as part * of the tokenIdData, but it is possible that the NFT has additional * liquidity in pools/binIds that have not been recorded. */ function tokenIdPositionInformation( uint256 tokenId, uint256 index ) external view returns (PositionFullInformation memory output); /** * @notice Get remove paramters for removing a fractional part of the * liquidity owned by a given tokenId. The fractional factor to remove is * given by proporationD18 in 18-decimal scale. */ function getRemoveParams( uint256 tokenId, uint256 index, uint256 proportionD18 ) external view returns (IMaverickV2Pool.RemoveLiquidityParams memory params); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Position} from "./IMaverickV2Position.sol"; interface IPositionImage { error PositionImageSetPositionError(address sender, address deployer, IMaverickV2Position currentPosition); function position() external view returns (IMaverickV2Position _position); function setPosition(IMaverickV2Position _position) external; function image(uint256 tokenId, address tokenOwner) external view returns (string memory); }
// SPDX-License-Identifier: Unlicense pragma solidity ^0.8.25; // Adapted from https://github.com/GNSPS/solidity-bytes-utils/blob/1dff13ef21304eb3634cb9e7f86c119cf280bd35/contracts/BytesLib.sol library BytesLib { error BytesLibToBoolOutOfBounds(); error BytesLibToAddressOutOfBounds(); error BytesLibSliceOverflow(); error BytesLibSliceOutOfBounds(); error BytesLibInvalidLength(uint256 inputLength, uint256 expectedLength); function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) { // 31 is added to _length in assembly; need to check here that that // operation will not overflow if (_length > type(uint256).max - 31) revert BytesLibSliceOverflow(); if (_bytes.length < _start + _length) revert BytesLibSliceOutOfBounds(); bytes memory tempBytes; assembly ("memory-safe") { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) //zero out the 32 bytes slice we are about to return //we need to do it because Solidity does not garbage collect mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address addr) { unchecked { if (_bytes.length < _start + 20) revert BytesLibToAddressOutOfBounds(); assembly ("memory-safe") { addr := and(0xffffffffffffffffffffffffffffffffffffffff, mload(add(add(_bytes, 20), _start))) } } } function toBool(bytes memory _bytes, uint256 _start) internal pure returns (bool) { unchecked { if (_bytes.length < _start + 1) revert BytesLibToBoolOutOfBounds(); uint8 tempUint; assembly ("memory-safe") { tempUint := mload(add(add(_bytes, 1), _start)) } return tempUint == 1; } } function toAddressAddressBoolUint128Uint128( bytes memory _bytes ) internal pure returns (address addr1, address addr2, bool bool_, uint128 amount1, uint128 amount2) { if (_bytes.length != 73) revert BytesLibInvalidLength(_bytes.length, 73); uint8 temp; assembly ("memory-safe") { addr1 := and(0xffffffffffffffffffffffffffffffffffffffff, mload(add(_bytes, 20))) addr2 := and(0xffffffffffffffffffffffffffffffffffffffff, mload(add(_bytes, 40))) temp := mload(add(_bytes, 41)) amount1 := and(0xffffffffffffffffffffffffffffffff, mload(add(_bytes, 57))) amount2 := and(0xffffffffffffffffffffffffffffffff, mload(add(_bytes, 73))) } bool_ = temp == 1; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import {SafeCast as Cast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {Math} from "@maverick/v2-common/contracts/libraries/Math.sol"; import {PoolLib} from "@maverick/v2-common/contracts/libraries/PoolLib.sol"; import {ONE, MINIMUM_LIQUIDITY} from "@maverick/v2-common/contracts/libraries/Constants.sol"; import {TickMath} from "@maverick/v2-common/contracts/libraries/TickMath.sol"; import {IMaverickV2PoolLens} from "../interfaces/IMaverickV2PoolLens.sol"; import {IMaverickV2BoostedPosition} from "../interfaces/IMaverickV2BoostedPosition.sol"; import {PoolInspection} from "../libraries/PoolInspection.sol"; import {PackLib} from "../libraries/PackLib.sol"; library LiquidityUtilities { using Cast for uint256; error LiquidityUtilitiesTargetPriceOutOfBounds( uint256 targetSqrtPrice, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice ); error LiquidityUtilitiesTooLittleLiquidity(uint256 relativeLiquidityAmount, uint256 deltaA, uint256 deltaB); error LiquidityUtilitiesTargetingTokenWithNoDelta(bool targetIsA, uint256 deltaA, uint256 deltaB); error LiquidityUtilitiesNoSwapLiquidity(); error LiquidityUtilitiesFailedToFindDeltaAmounts(); error LiquidityUtilitiesInitialTargetBTooSmall( uint256 initialTargetB, uint256 deltaLpBalance, uint256 minimumRequiredLpBalance ); uint256 internal constant MIN_DELTA_RESERVES = 100; /** * * @notice Return index into the price breaks array that corresponds to the * current pool price. * * @dev Price break array is N elements [e_0, e_1, ..., e_{n-1}]. * @dev If price is less than e_0, then `0` is returned, if price is * betweeen e_0 and e_1, then `1` is returned, etc. If the price is * between e_{n-2} and e_{n-1}, then n-2 is returned. If price is larger * than e_{n-1}, then n-1 is returned. * */ function priceIndexFromPriceBreaks( uint256 sqrtPrice, bytes memory packedSqrtPriceBreaks ) internal pure returns (uint256 index) { // index is zero if the pricebreaks array only has one price if (packedSqrtPriceBreaks.length == 12) return index; uint88[] memory breaks = PackLib.unpackUint88Array(packedSqrtPriceBreaks); // loop terminates with `breaks.length - 1` as the max value. for (; index < breaks.length - 1; index++) { if (sqrtPrice <= breaks[index]) break; } } function tokenScales(IMaverickV2Pool pool) internal view returns (uint256 tokenAScale, uint256 tokenBScale) { tokenAScale = pool.tokenAScale(); tokenBScale = pool.tokenBScale(); } function deltaReservesFromDeltaLpBalanceAtNewPrice( IMaverickV2Pool pool, int32 tick, uint128 deltaLpBalance, uint8 kind, uint256 newSqrtPrice ) internal view returns (uint256 deltaA, uint256 deltaB) { PoolLib.AddLiquidityInfo memory addLiquidityInfo; uint32 binId = pool.binIdByTickKind(tick, kind); IMaverickV2Pool.BinState memory bin = pool.getBin(binId); addLiquidityInfo.tickSpacing = pool.tickSpacing(); addLiquidityInfo.tick = tick; IMaverickV2Pool.TickState memory tickState; (tickState, addLiquidityInfo.tickLtActive, ) = reservesInTickForGivenPrice(pool, tick, newSqrtPrice); PoolLib.deltaTickBalanceFromDeltaLpBalance( bin.tickBalance, bin.totalSupply, tickState, deltaLpBalance, addLiquidityInfo ); (uint256 tokenAScale, uint256 tokenBScale) = tokenScales(pool); deltaA = Math.ammScaleToTokenScale(addLiquidityInfo.deltaA, tokenAScale, true); deltaB = Math.ammScaleToTokenScale(addLiquidityInfo.deltaB, tokenBScale, true); } function deltaReservesFromDeltaLpBalancesAtNewPrice( IMaverickV2Pool pool, IMaverickV2Pool.AddLiquidityParams memory addParams, uint256 newSqrtPrice ) internal view returns (IMaverickV2PoolLens.TickDeltas memory tickDeltas) { uint256 length = addParams.ticks.length; tickDeltas.deltaAs = new uint256[](length); tickDeltas.deltaBs = new uint256[](length); for (uint256 k; k < length; k++) { (tickDeltas.deltaAs[k], tickDeltas.deltaBs[k]) = deltaReservesFromDeltaLpBalanceAtNewPrice( pool, addParams.ticks[k], addParams.amounts[k], addParams.kind, newSqrtPrice ); tickDeltas.deltaAOut += tickDeltas.deltaAs[k]; tickDeltas.deltaBOut += tickDeltas.deltaBs[k]; } } function scaleAddParams( IMaverickV2Pool.AddLiquidityParams memory addParams, uint128[] memory ratios, uint256 addAmount, uint256 targetAmount ) internal pure returns (IMaverickV2Pool.AddLiquidityParams memory addParamsScaled) { uint256 length = addParams.ticks.length; addParamsScaled.ticks = addParams.ticks; addParamsScaled.kind = addParams.kind; addParamsScaled.amounts = new uint128[](length); addParamsScaled.amounts[0] = Math.mulDivFloor(addParams.amounts[0], targetAmount, addAmount).toUint128(); for (uint256 k = 1; k < length; k++) { addParamsScaled.amounts[k] = Math.mulCeil(addParamsScaled.amounts[0], ratios[k]).toUint128(); } } function getScaledAddParams( IMaverickV2Pool pool, IMaverickV2Pool.AddLiquidityParams memory addParams, uint128[] memory ratios, uint256 newSqrtPrice, uint256 targetAmount, bool targetIsA ) internal view returns ( IMaverickV2Pool.AddLiquidityParams memory addParamsScaled, IMaverickV2PoolLens.TickDeltas memory tickDeltas ) { // find A and B amount for input addParams tickDeltas = deltaReservesFromDeltaLpBalancesAtNewPrice(pool, addParams, newSqrtPrice); uint256 unScaledAmount = targetIsA ? tickDeltas.deltaAOut : tickDeltas.deltaBOut; if (unScaledAmount == 0) revert LiquidityUtilitiesFailedToFindDeltaAmounts(); // scale addParams to meet the delta target addParamsScaled = scaleAddParams( addParams, ratios, targetIsA ? tickDeltas.deltaAOut : tickDeltas.deltaBOut, targetAmount ); tickDeltas = deltaReservesFromDeltaLpBalancesAtNewPrice(pool, addParamsScaled, newSqrtPrice); } function getAddLiquidityParamsFromRelativeBinLpBalance( IMaverickV2PoolLens.BoostedPositionSpecification memory spec, int32[] memory ticks, IMaverickV2PoolLens.AddParamsSpecification memory params ) internal view returns ( bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs, uint88[] memory sqrtPriceBreaks, IMaverickV2Pool.AddLiquidityParams[] memory addParams, IMaverickV2PoolLens.TickDeltas[] memory tickDeltas ) { uint256 length = params.numberOfPriceBreaksPerSide * 2 + 1; addParams = new IMaverickV2Pool.AddLiquidityParams[](length); tickDeltas = new IMaverickV2PoolLens.TickDeltas[](length); uint256 sqrtPrice = PoolInspection.poolSqrtPrice(spec.pool); addParams[params.numberOfPriceBreaksPerSide].ticks = ticks; addParams[params.numberOfPriceBreaksPerSide].amounts = spec.ratios; addParams[params.numberOfPriceBreaksPerSide].kind = spec.kind; ( addParams[params.numberOfPriceBreaksPerSide], tickDeltas[params.numberOfPriceBreaksPerSide] ) = getScaledAddParams( spec.pool, addParams[params.numberOfPriceBreaksPerSide], spec.ratios, sqrtPrice, params.targetAmount, params.targetIsA ); sqrtPriceBreaks = new uint88[](length); sqrtPriceBreaks[params.numberOfPriceBreaksPerSide] = sqrtPrice.toUint88(); // left of price, for (uint256 k; k < params.numberOfPriceBreaksPerSide; k++) { params.targetIsA = false; params.targetAmount = Math.mulDown(tickDeltas[params.numberOfPriceBreaksPerSide].deltaBOut, 0.99999e18); if (params.targetAmount == 0) continue; // price / (factor + 1), price / (factor * (n-1) / n + 1), price / (factor * (n-2)/n + 1)... uint256 factor = Math.mulDivFloor( params.slippageFactorD18, params.numberOfPriceBreaksPerSide - k, params.numberOfPriceBreaksPerSide ); sqrtPriceBreaks[k] = Math.divCeil(sqrtPrice, factor + ONE).toUint88(); (addParams[k], tickDeltas[k]) = getScaledAddParams( spec.pool, addParams[params.numberOfPriceBreaksPerSide], spec.ratios, sqrtPriceBreaks[k], params.targetAmount, params.targetIsA ); } // right of price for (uint256 k; k < params.numberOfPriceBreaksPerSide; k++) { uint256 index = params.numberOfPriceBreaksPerSide + k + 1; params.targetIsA = true; params.targetAmount = Math.mulDown(tickDeltas[params.numberOfPriceBreaksPerSide].deltaAOut, 0.99999e18); if (params.targetAmount == 0) { sqrtPriceBreaks[index - 1] = type(uint88).max; break; } { // price * (factor * (1 / n) + 1), price * (factor * (2 / n) + 1), price / (factor * (3 / n) + 1)... uint256 factor = Math.mulDivFloor(params.slippageFactorD18, k + 1, params.numberOfPriceBreaksPerSide); sqrtPriceBreaks[index] = Math.mulCeil(sqrtPrice, factor + ONE).toUint88(); } (addParams[index], tickDeltas[index]) = getScaledAddParams( spec.pool, addParams[params.numberOfPriceBreaksPerSide], spec.ratios, sqrtPriceBreaks[index], params.targetAmount, params.targetIsA ); } sortAddParamsArray(addParams, tickDeltas); packedArgs = PackLib.packAddLiquidityArgsArray(addParams); packedSqrtPriceBreaks = PackLib.packArray(sqrtPriceBreaks); } /** @notice Compute add params for N price breaks around price with max right * slippage of p * (1 + f) and max left slippage of p / (1 + f). * * The user specifies the max A and B they are willing to spend. If the * price of the pool does not move, the user will spend exactly this * amount. If the price moves left, then the user would like to spend the * specified B amount, but will end up spending less A. Conversely, if the * price moves right, the user will spend their max A amount, but less B. * * By having more break points, we make it so that the user gets as much * liquidity as possible at the new price. With too few break points, the * user will not have bought as much liquidity as they could have. */ function getAddLiquidityParams( IMaverickV2PoolLens.AddParamsViewInputs memory params ) internal view returns ( bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs, uint88[] memory sqrtPriceBreaks, IMaverickV2Pool.AddLiquidityParams[] memory addParams, IMaverickV2PoolLens.TickDeltas[] memory tickDeltas ) { RelativeLiquidityInput memory input; input.poolTickSpacing = params.pool.tickSpacing(); (input.tokenAScale, input.tokenBScale) = tokenScales(params.pool); input.ticks = params.ticks; input.relativeLiquidityAmounts = params.relativeLiquidityAmounts; uint256 length = params.addSpec.numberOfPriceBreaksPerSide * 2 + 1; addParams = new IMaverickV2Pool.AddLiquidityParams[](length); tickDeltas = new IMaverickV2PoolLens.TickDeltas[](length); // initially target the bigger amount at pool price input.targetIsA = params.addSpec.targetIsA; input.targetAmount = params.addSpec.targetAmount; uint256 startingPrice = PoolInspection.poolSqrtPrice(params.pool); input.newSqrtPrice = startingPrice; bool success; ( addParams[params.addSpec.numberOfPriceBreaksPerSide], tickDeltas[params.addSpec.numberOfPriceBreaksPerSide], success ) = lpBalanceForArrayOfTargetAmounts(input, params.pool, params.kind); if (!success) revert LiquidityUtilitiesFailedToFindDeltaAmounts(); sqrtPriceBreaks = new uint88[](length); sqrtPriceBreaks[params.addSpec.numberOfPriceBreaksPerSide] = input.newSqrtPrice.toUint88(); // compute slippage price // look through N breaks // compute deltas // convert to addParams // // left of price, for (uint256 k; k < params.addSpec.numberOfPriceBreaksPerSide; k++) { input.targetIsA = false; input.targetAmount = tickDeltas[params.addSpec.numberOfPriceBreaksPerSide].deltaBOut; // price / (factor + 1), price / (factor * (n-1) / n + 1), price / (factor * (n-2)/n + 1)... uint256 factor = Math.mulDivFloor( params.addSpec.slippageFactorD18, params.addSpec.numberOfPriceBreaksPerSide - k, params.addSpec.numberOfPriceBreaksPerSide ); sqrtPriceBreaks[k] = Math.divCeil(startingPrice, factor + ONE).toUint88(); input.newSqrtPrice = sqrtPriceBreaks[k]; (addParams[k], tickDeltas[k], success) = lpBalanceForArrayOfTargetAmounts(input, params.pool, params.kind); if (!success) sqrtPriceBreaks[k] = 0; } // right of price for (uint256 k; k < params.addSpec.numberOfPriceBreaksPerSide; k++) { uint256 index = params.addSpec.numberOfPriceBreaksPerSide + k + 1; input.targetIsA = true; input.targetAmount = tickDeltas[params.addSpec.numberOfPriceBreaksPerSide].deltaAOut; // price * (factor * (1 / n) + 1), price * (factor * (2 / n) + 1), price / (factor * (3 / n) + 1)... uint256 factor = Math.mulDivFloor( params.addSpec.slippageFactorD18, k + 1, params.addSpec.numberOfPriceBreaksPerSide ); sqrtPriceBreaks[index] = Math.mulCeil(startingPrice, factor + ONE).toUint88(); input.newSqrtPrice = sqrtPriceBreaks[index]; (addParams[index], tickDeltas[index], success) = lpBalanceForArrayOfTargetAmounts( input, params.pool, params.kind ); if (!success) { sqrtPriceBreaks[index - 1] = type(uint88).max; break; } } packedArgs = PackLib.packAddLiquidityArgsArray(addParams); packedSqrtPriceBreaks = PackLib.packArray(sqrtPriceBreaks); } function deltaReservesFromDeltaLiquidity( uint256 poolTickSpacing, uint256 tokenAScale, uint256 tokenBScale, int32 tick, uint128 deltaLiquidity, uint256 tickSqrtPrice ) internal pure returns (uint256 deltaA, uint256 deltaB) { (uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice) = TickMath.tickSqrtPrices(poolTickSpacing, tick); { uint256 lowerEdge = Math.max(sqrtLowerTickPrice, tickSqrtPrice); deltaB = Math.mulDivCeil( deltaLiquidity, ONE * Math.clip(sqrtUpperTickPrice, lowerEdge), sqrtUpperTickPrice * lowerEdge ); } if (tickSqrtPrice < sqrtLowerTickPrice) { deltaA = 0; } else if (tickSqrtPrice >= sqrtUpperTickPrice) { deltaA = Math.mulCeil(deltaLiquidity, sqrtUpperTickPrice - sqrtLowerTickPrice); deltaB = 0; } else { deltaA = Math.mulCeil( deltaLiquidity, Math.clip(Math.min(sqrtUpperTickPrice, tickSqrtPrice), sqrtLowerTickPrice) ); } deltaA = Math.ammScaleToTokenScale(deltaA, tokenAScale, true); deltaB = Math.ammScaleToTokenScale(deltaB, tokenBScale, true); } function deltasFromBinLiquidityAmounts( uint256 poolTickSpacing, uint256 tokenAScale, uint256 tokenBScale, int32[] memory ticks, uint128[] memory liquidityAmounts, uint256 newSqrtPrice ) internal pure returns (uint256 deltaA, uint256 deltaB, uint256[] memory deltaAs, uint256[] memory deltaBs) { uint256 length = ticks.length; deltaAs = new uint256[](length); deltaBs = new uint256[](length); for (uint256 k = 0; k < length; k++) { (deltaAs[k], deltaBs[k]) = deltaReservesFromDeltaLiquidity( poolTickSpacing, tokenAScale, tokenBScale, ticks[k], liquidityAmounts[k], newSqrtPrice ); deltaA += deltaAs[k]; deltaB += deltaBs[k]; } } struct StateInfo { uint256 reserveA; uint256 reserveB; uint256 binTotalSupply; int32 activeTick; } struct RelativeLiquidityInput { uint256 poolTickSpacing; uint256 tokenAScale; uint256 tokenBScale; int32[] ticks; uint128[] relativeLiquidityAmounts; uint256 targetAmount; bool targetIsA; uint256 newSqrtPrice; } function _deltasFromRelativeBinLiquidityAmountsAndTargetAmount( RelativeLiquidityInput memory input ) internal pure returns (IMaverickV2PoolLens.TickDeltas memory output, bool success) { uint256 deltaA; uint256 deltaB; success = true; (deltaA, deltaB, output.deltaAs, output.deltaBs) = deltasFromBinLiquidityAmounts( input.poolTickSpacing, input.tokenAScale, input.tokenBScale, input.ticks, input.relativeLiquidityAmounts, input.newSqrtPrice ); uint256 deltaDenominator = input.targetIsA ? deltaA : deltaB; if ((input.targetIsA && deltaA == 0) || (!input.targetIsA && deltaB == 0)) return (output, false); for (uint256 k; k < input.ticks.length; k++) { output.deltaAs[k] = Math .mulDivFloor(Math.clip(output.deltaAs[k], 1), input.targetAmount, deltaDenominator) .toUint128(); output.deltaBs[k] = Math .mulDivFloor(Math.clip(output.deltaBs[k], 1), input.targetAmount, deltaDenominator) .toUint128(); if (output.deltaAs[k] < MIN_DELTA_RESERVES && output.deltaBs[k] < MIN_DELTA_RESERVES) return (output, false); output.deltaAOut += output.deltaAs[k]; output.deltaBOut += output.deltaBs[k]; } } function lpBalanceForArrayOfTargetAmountsEmptyPool( IMaverickV2PoolLens.TickDeltas memory tickDeltas, RelativeLiquidityInput memory input, StateInfo memory existingState, uint8 kind ) internal pure returns (IMaverickV2Pool.AddLiquidityParams memory addParams) { addParams.ticks = input.ticks; addParams.kind = kind; addParams.amounts = new uint128[](input.ticks.length); for (uint256 k; k < input.ticks.length; k++) { bool tickIsActive = existingState.activeTick == input.ticks[k]; addParams.amounts[k] = lpBalanceRequiredForTargetReserveAmountsOneBinTick( input, input.ticks[k], Math.tokenScaleToAmmScale(tickDeltas.deltaAs[k], input.tokenAScale), Math.tokenScaleToAmmScale(tickDeltas.deltaBs[k], input.tokenBScale), tickIsActive ? existingState.reserveA : 0, tickIsActive ? existingState.reserveB : 0, tickIsActive ? existingState.binTotalSupply : 0, input.ticks[k] < existingState.activeTick ).toUint128(); } } function lpBalanceForArrayOfTargetAmounts( RelativeLiquidityInput memory input, IMaverickV2Pool pool, uint8 kind ) internal view returns ( IMaverickV2Pool.AddLiquidityParams memory addParams, IMaverickV2PoolLens.TickDeltas memory tickDeltas, bool success ) { (tickDeltas, success) = _deltasFromRelativeBinLiquidityAmountsAndTargetAmount(input); addParams.ticks = input.ticks; addParams.kind = kind; addParams.amounts = new uint128[](input.ticks.length); for (uint256 k; k < input.ticks.length; k++) { addParams.amounts[k] = lpBalanceRequiredForTargetReserveAmountsMultiBinTick( input, pool, input.ticks[k], kind, Math.tokenScaleToAmmScale(tickDeltas.deltaAs[k], input.tokenAScale), Math.tokenScaleToAmmScale(tickDeltas.deltaBs[k], input.tokenBScale) ).toUint128(); } } function donateAndSwapData( uint256 poolTickSpacing, int32 poolTick, uint256 poolFee, IERC20 tokenB, uint256 targetAmountB, uint256 targetSqrtPrice ) internal view returns (uint128 deltaLpBalanceB, uint256 swapAmount) { uint256 tokenBScale = Math.scale(IERC20Metadata(address(tokenB)).decimals()); targetAmountB = Math.tokenScaleToAmmScale(targetAmountB, tokenBScale); (uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice) = TickMath.tickSqrtPrices(poolTickSpacing, poolTick); deltaLpBalanceB = Math.mulFloor(targetAmountB, sqrtUpperTickPrice).toUint128(); uint256 liquidity = TickMath.getTickL(0, targetAmountB, sqrtLowerTickPrice, sqrtUpperTickPrice); if (targetSqrtPrice <= sqrtLowerTickPrice || targetSqrtPrice >= sqrtUpperTickPrice) revert LiquidityUtilitiesTargetPriceOutOfBounds(targetSqrtPrice, sqrtLowerTickPrice, sqrtUpperTickPrice); swapAmount = Math.mulDivCeil( liquidity, ONE * (targetSqrtPrice - sqrtLowerTickPrice), targetSqrtPrice * sqrtLowerTickPrice ); swapAmount = Math.ammScaleToTokenScale(swapAmount, tokenBScale, true); swapAmount = Math.mulCeil(swapAmount, ONE - poolFee); } function getCreatePoolParams( IMaverickV2PoolLens.CreateAndAddParamsViewInputs memory params, uint256 protocolFeeRatio ) internal view returns (IMaverickV2PoolLens.CreateAndAddParamsInputs memory output) { (uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice) = TickMath.tickSqrtPrices( params.tickSpacing, params.activeTick ); RelativeLiquidityInput memory input; StateInfo memory existingState; input.poolTickSpacing = params.tickSpacing; input.tokenAScale = Math.scale(IERC20Metadata(address(params.tokenA)).decimals()); input.tokenBScale = Math.scale(IERC20Metadata(address(params.tokenB)).decimals()); input.ticks = params.ticks; input.relativeLiquidityAmounts = params.relativeLiquidityAmounts; input.targetAmount = params.targetAmount; input.targetIsA = params.targetIsA; existingState.activeTick = params.activeTick; output.donateParams.ticks = new int32[](1); output.donateParams.ticks[0] = params.activeTick; output.donateParams.amounts = new uint128[](1); if (sqrtLowerTickPrice != params.sqrtPrice) { // target price is not tick edge, need to dontate/swap (output.donateParams.amounts[0], output.swapAmount) = donateAndSwapData( params.tickSpacing, params.activeTick, params.feeAIn, params.tokenB, params.initialTargetB, params.sqrtPrice ); if (output.donateParams.amounts[0] < MINIMUM_LIQUIDITY) revert LiquidityUtilitiesInitialTargetBTooSmall( params.initialTargetB, output.donateParams.amounts[0], MINIMUM_LIQUIDITY ); existingState.binTotalSupply = output.donateParams.amounts[0]; existingState.reserveB = Math.tokenScaleToAmmScale( params.initialTargetB - output.swapAmount, input.tokenBScale ); existingState.reserveA = emulateExactOut( Math.tokenScaleToAmmScale(output.swapAmount, input.tokenBScale), Math.tokenScaleToAmmScale(params.initialTargetB, input.tokenBScale), sqrtLowerTickPrice, sqrtUpperTickPrice, params.feeAIn, protocolFeeRatio ); (input.newSqrtPrice, ) = TickMath.getTickSqrtPriceAndL( existingState.reserveA, existingState.reserveB, sqrtLowerTickPrice, sqrtUpperTickPrice ); } else { input.newSqrtPrice = sqrtLowerTickPrice; } { ( IMaverickV2PoolLens.TickDeltas memory tickDeltas, bool success ) = _deltasFromRelativeBinLiquidityAmountsAndTargetAmount(input); if (!success) revert LiquidityUtilitiesFailedToFindDeltaAmounts(); output.addParams = lpBalanceForArrayOfTargetAmountsEmptyPool(tickDeltas, input, existingState, params.kind); output.packedAddParams = PackLib.packAddLiquidityArgsToArray(output.addParams); output.deltaAOut = tickDeltas.deltaAOut; output.deltaBOut = tickDeltas.deltaBOut; output.preAddReserveA = existingState.reserveA; output.preAddReserveB = existingState.reserveB; } } function emulateExactOut( uint256 amountOut, uint256 currentReserveB, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice, uint256 fee, uint256 protocolFee ) internal pure returns (uint256 amountAIn) { uint256 existingLiquidity = TickMath.getTickL(0, currentReserveB, sqrtLowerTickPrice, sqrtUpperTickPrice); if (existingLiquidity == 0) revert LiquidityUtilitiesNoSwapLiquidity(); uint256 binAmountIn = Math.mulDivCeil( amountOut, sqrtLowerTickPrice, Math.invFloor(sqrtLowerTickPrice) - Math.divCeil(amountOut, existingLiquidity) ); // some of the input is fee uint256 feeBasis = Math.mulDivCeil(binAmountIn, fee, ONE - fee); // fee is added to input amount and just increases bin liquidity // out = in / (1-fee) -> out - fee * out = in -> out = in + fee * out uint256 inWithoutProtocolFee = binAmountIn + feeBasis; // add on protocol fee amountAIn = protocolFee != 0 ? Math.clip(inWithoutProtocolFee, Math.mulCeil(feeBasis, protocolFee)) : inWithoutProtocolFee; } /** * @notice Calculates deltaA = liquidity * (sqrt(upper) - sqrt(lower)) * Calculates deltaB = liquidity / sqrt(lower) - liquidity / sqrt(upper), * i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower)) */ function reservesInTickForGivenPrice( IMaverickV2Pool pool, int32 tick, uint256 newSqrtPrice ) internal view returns (IMaverickV2Pool.TickState memory tickState, bool tickLtActive, bool tickGtActive) { tickState = pool.getTick(tick); (uint256 lowerSqrtPrice, uint256 upperSqrtPrice) = TickMath.tickSqrtPrices(pool.tickSpacing(), tick); tickGtActive = newSqrtPrice < lowerSqrtPrice; tickLtActive = newSqrtPrice >= upperSqrtPrice; uint256 liquidity = TickMath.getTickL(tickState.reserveA, tickState.reserveB, lowerSqrtPrice, upperSqrtPrice); if (liquidity == 0) { (tickState.reserveA, tickState.reserveB) = (0, 0); } else { uint256 lowerEdge = Math.max(lowerSqrtPrice, newSqrtPrice); tickState.reserveA = Math .mulCeil(liquidity, Math.clip(Math.min(upperSqrtPrice, newSqrtPrice), lowerSqrtPrice)) .toUint128(); tickState.reserveB = Math .mulDivCeil(liquidity, ONE * Math.clip(upperSqrtPrice, lowerEdge), upperSqrtPrice * lowerEdge) .toUint128(); } } function lpBalanceRequiredForTargetReserveAmountsMultiBinTick( RelativeLiquidityInput memory input, IMaverickV2Pool pool, int32 tick, uint8 kind, uint256 amountAMax, uint256 amountBMax ) internal view returns (uint256 deltaLpBalance) { (IMaverickV2Pool.TickState memory tickState, bool tickLtActive, ) = reservesInTickForGivenPrice( pool, tick, input.newSqrtPrice ); if (tickState.reserveB != 0 || tickState.reserveA != 0) { uint256 liquidity; { (uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice) = TickMath.tickSqrtPrices( input.poolTickSpacing, tick ); liquidity = TickMath.getTickL( tickState.reserveA, tickState.reserveB, sqrtLowerTickPrice, sqrtUpperTickPrice ); } uint32 binId = pool.binIdByTickKind(tick, kind); IMaverickV2Pool.BinState memory bin = pool.getBin(binId); uint256 numerator = Math.max(1, uint256(tickState.totalSupply)) * Math.max(1, uint256(bin.totalSupply)); if (tickState.reserveA != 0) { uint256 denominator = Math.max(1, uint256(bin.tickBalance)) * uint256(tickState.reserveA); amountAMax = Math.max(amountAMax, 1); deltaLpBalance = Math.mulDivFloor(amountAMax, numerator, denominator); } else { deltaLpBalance = type(uint256).max; } if (tickState.reserveB != 0) { uint256 denominator = Math.max(1, uint256(bin.tickBalance)) * uint256(tickState.reserveB); amountBMax = Math.max(amountBMax, 1); deltaLpBalance = Math.min(deltaLpBalance, Math.mulDivFloor(amountBMax, numerator, denominator)); } } else { deltaLpBalance = emptyTickLpBalanceRequirement(input, tick, amountAMax, amountBMax, tickLtActive); } } function lpBalanceRequiredForTargetReserveAmountsOneBinTick( RelativeLiquidityInput memory input, int32 tick, uint256 amountAMax, uint256 amountBMax, uint256 reserveA, uint256 reserveB, uint256 binTotalSupply, bool tickLtActive ) internal pure returns (uint256 deltaLpBalance) { if (reserveB != 0 || reserveA != 0) { deltaLpBalance = Math.min( reserveA == 0 ? type(uint256).max : Math.mulDivFloor(amountAMax, binTotalSupply, reserveA), reserveB == 0 ? type(uint256).max : Math.mulDivFloor(amountBMax, binTotalSupply, reserveB) ); } else { deltaLpBalance = emptyTickLpBalanceRequirement(input, tick, amountAMax, amountBMax, tickLtActive); } } function emptyTickLpBalanceRequirement( RelativeLiquidityInput memory input, int32 tick, uint256 amountAMax, uint256 amountBMax, bool tickLtActive ) internal pure returns (uint256 deltaLpBalance) { (uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice) = TickMath.tickSqrtPrices(input.poolTickSpacing, tick); if (tickLtActive) { deltaLpBalance = Math.divFloor(amountAMax, sqrtLowerTickPrice); } else { deltaLpBalance = Math.mulFloor(amountBMax, sqrtUpperTickPrice); } } function getBoostedPositionSpec( IMaverickV2BoostedPosition boostedPosition ) internal view returns (IMaverickV2PoolLens.BoostedPositionSpecification memory spec, int32[] memory ticks) { spec.pool = boostedPosition.pool(); spec.binIds = boostedPosition.getBinIds(); spec.ratios = boostedPosition.getRatios(); spec.kind = boostedPosition.kind(); ticks = boostedPosition.getTicks(); } /** * @notice Sort ticks and amounts in addParams struct array in tick order. * Mutates input params array in place. * * @notice Sort operation in this function assumes that all element of the * input arrays have the same tick ordering. */ function sortAddParamsArray( IMaverickV2Pool.AddLiquidityParams[] memory addParams, IMaverickV2PoolLens.TickDeltas[] memory tickDeltas ) internal pure { uint256 breakPoints = addParams.length; uint256 length = addParams[0].ticks.length; for (uint256 i = 0; i < length - 1; i++) { for (uint256 j = 0; j < length - i - 1; j++) { // compare if (addParams[0].ticks[j] > addParams[0].ticks[j + 1]) { // if there is a mis-ordering, flip values in all addParam structs for (uint256 k = 0; k < breakPoints; k++) { (addParams[k].ticks[j], addParams[k].ticks[j + 1]) = ( addParams[k].ticks[j + 1], addParams[k].ticks[j] ); (addParams[k].amounts[j], addParams[k].amounts[j + 1]) = ( addParams[k].amounts[j + 1], addParams[k].amounts[j] ); (tickDeltas[k].deltaAs[j], tickDeltas[k].deltaAs[j + 1]) = ( tickDeltas[k].deltaAs[j + 1], tickDeltas[k].deltaAs[j] ); (tickDeltas[k].deltaBs[j], tickDeltas[k].deltaBs[j + 1]) = ( tickDeltas[k].deltaBs[j + 1], tickDeltas[k].deltaBs[j] ); } } } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; // adapted from https://github.com/latticexyz/mud/blob/main/packages/store/src/Slice.sol import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {SafeCast as Cast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {BytesLib} from "./BytesLib.sol"; library PackLib { using Cast for uint256; using BytesLib for bytes; function unpackExactInputSingleArgsAmounts( bytes memory argsPacked ) internal pure returns (address recipient, IMaverickV2Pool pool, bool tokenAIn, uint256 amountIn, uint256 amountOutMinimum) { address pool_; (recipient, pool_, tokenAIn, amountIn, amountOutMinimum) = argsPacked.toAddressAddressBoolUint128Uint128(); pool = IMaverickV2Pool(pool_); } function unpackAddLiquidityArgs( bytes memory argsPacked ) internal pure returns (IMaverickV2Pool.AddLiquidityParams memory args) { args.kind = uint8(argsPacked[0]); args.ticks = unpackInt32Array(argsPacked.slice(1, argsPacked.length - 1)); uint256 startByte = args.ticks.length * 4 + 2; args.amounts = unpackUint128Array(argsPacked.slice(startByte, argsPacked.length - startByte)); } function packAddLiquidityArgs( IMaverickV2Pool.AddLiquidityParams memory args ) internal pure returns (bytes memory argsPacked) { argsPacked = abi.encodePacked(args.kind); argsPacked = bytes.concat(argsPacked, packArray(args.ticks)); argsPacked = bytes.concat(argsPacked, packArray(args.amounts)); } function packAddLiquidityArgsToArray( IMaverickV2Pool.AddLiquidityParams memory args ) internal pure returns (bytes[] memory argsPacked) { argsPacked = new bytes[](1); argsPacked[0] = packAddLiquidityArgs(args); } function packAddLiquidityArgsArray( IMaverickV2Pool.AddLiquidityParams[] memory args ) internal pure returns (bytes[] memory argsPacked) { argsPacked = new bytes[](args.length); for (uint256 k; k < args.length; k++) { argsPacked[k] = packAddLiquidityArgs(args[k]); } } function unpackInt32Array(bytes memory input) internal pure returns (int32[] memory array) { uint256[] memory output = _unpackArray(input, 4); assembly ("memory-safe") { array := output } } function unpackUint128Array(bytes memory input) internal pure returns (uint128[] memory array) { uint256[] memory output = _unpackArray(input, 16); assembly ("memory-safe") { array := output } } function unpackUint88Array(bytes memory input) internal pure returns (uint88[] memory array) { uint256[] memory output = _unpackArray(input, 11); assembly ("memory-safe") { array := output } } function packArray(int32[] memory array) internal pure returns (bytes memory output) { uint256[] memory input; assembly ("memory-safe") { input := array } output = _packArray(input, 4); } function packArray(uint128[] memory array) internal pure returns (bytes memory output) { uint256[] memory input; assembly ("memory-safe") { input := array } output = _packArray(input, 16); } function packArray(uint88[] memory array) internal pure returns (bytes memory output) { uint256[] memory input; assembly ("memory-safe") { input := array } output = _packArray(input, 11); } /* * @notice [length, array[0], array[1],..., array[length-1]]. length is 1 bytes. * @dev Unpacked signed array elements will contain "dirty bits". That is, * this function does not 0xf pad signed return elements. */ function _unpackArray(bytes memory input, uint256 elementBytes) internal pure returns (uint256[] memory array) { uint256 packedPointer; uint256 arrayLength; assembly ("memory-safe") { // read from input pointer + 32 bytes // pad 1-byte length value to fill 32 bytes (248 pad bits) arrayLength := shr(248, mload(add(input, 0x20))) packedPointer := add(input, 0x21) } uint256 padRight = 256 - 8 * elementBytes; assembly ("memory-safe") { // Allocate a word for each element, and a word for the array's length let allocateBytes := add(mul(arrayLength, 32), 0x20) // Allocate memory and update the free memory pointer array := mload(0x40) mstore(0x40, add(array, allocateBytes)) // Store array length mstore(array, arrayLength) for { let i := 0 let arrayCursor := add(array, 0x20) // skip array length let packedCursor := packedPointer } lt(i, arrayLength) { // Loop until we reach the end of the array i := add(i, 1) arrayCursor := add(arrayCursor, 0x20) // increment array pointer by one word packedCursor := add(packedCursor, elementBytes) // increment packed pointer by one element size } { mstore(arrayCursor, shr(padRight, mload(packedCursor))) // unpack one array element } } } /* * @dev [length, array[0], array[1],..., array[length-1]]. length is 1 bytes. */ function _packArray(uint256[] memory array, uint256 elementBytes) internal pure returns (bytes memory output) { // cast to check size fits in 8 bits uint8 arrayLength = array.length.toUint8(); uint256 packedLength = arrayLength * elementBytes + 1; output = new bytes(packedLength); uint256 padLeft = 256 - 8 * elementBytes; assembly ("memory-safe") { // Store array length mstore(add(output, 0x20), shl(248, arrayLength)) for { let i := 0 let arrayCursor := add(array, 0x20) // skip array length let packedCursor := add(output, 0x21) // skip length } lt(i, arrayLength) { // Loop until we reach the end of the array i := add(i, 1) arrayCursor := add(arrayCursor, 0x20) // increment array pointer by one word packedCursor := add(packedCursor, elementBytes) // increment packed pointer by one element size } { mstore(packedCursor, shl(padLeft, mload(arrayCursor))) // pack one array element } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {SafeCast as Cast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {Math} from "@maverick/v2-common/contracts/libraries/Math.sol"; import {PoolLib} from "@maverick/v2-common/contracts/libraries/PoolLib.sol"; import {TickMath} from "@maverick/v2-common/contracts/libraries/TickMath.sol"; library PoolInspection { using Cast for uint256; /** * @dev Calculates the square root price of a given Maverick V2 pool. * @param pool The Maverick V2 pool to inspect. * @return sqrtPrice The square root price of the pool. */ function poolSqrtPrice(IMaverickV2Pool pool) internal view returns (uint256 sqrtPrice) { int32 activeTick = pool.getState().activeTick; IMaverickV2Pool.TickState memory tickState = pool.getTick(activeTick); (uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice) = TickMath.tickSqrtPrices( pool.tickSpacing(), activeTick ); (sqrtPrice, ) = TickMath.getTickSqrtPriceAndL( tickState.reserveA, tickState.reserveB, sqrtLowerTickPrice, sqrtUpperTickPrice ); } /** * @dev Retrieves the reserves of a user's subaccount for a specific bin. */ function userSubaccountBinReserves( IMaverickV2Pool pool, address user, uint256 subaccount, uint32 binId ) internal view returns (uint256 amountA, uint256 amountB, int32 tick, uint256 liquidity) { IMaverickV2Pool.BinState memory bin = pool.getBin(binId); uint256 userBinLpBalance = pool.balanceOf(user, subaccount, binId); while (bin.mergeId != 0) { userBinLpBalance = bin.totalSupply == 0 ? 0 : Math.mulDivFloor(userBinLpBalance, bin.mergeBinBalance, bin.totalSupply); bin = pool.getBin(bin.mergeId); } tick = bin.tick; IMaverickV2Pool.TickState memory tickState = pool.getTick(tick); uint256 activeBinDeltaLpBalance = Math.min(userBinLpBalance, bin.totalSupply); uint128 deltaTickBalance = Math .mulDivDown(activeBinDeltaLpBalance, bin.tickBalance, bin.totalSupply) .toUint128(); deltaTickBalance = Math.min128(deltaTickBalance, tickState.totalSupply); (amountA, amountB) = PoolLib.binReserves( deltaTickBalance, tickState.reserveA, tickState.reserveB, tickState.totalSupply ); { (uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice) = TickMath.tickSqrtPrices( pool.tickSpacing(), tick ); liquidity = TickMath.getTickL(amountA, amountB, sqrtLowerTickPrice, sqrtUpperTickPrice); } } /** * @dev Retrieves the reserves of a token for all bins associated with it. * Bin reserve amounts are in pool D18 scale units. */ function subaccountPositionInformation( IMaverickV2Pool pool, address user, uint256 subaccount, uint32[] memory binIds ) internal view returns ( uint256 amountA, uint256 amountB, uint256[] memory binAAmounts, uint256[] memory binBAmounts, int32[] memory ticks, uint256[] memory liquidities ) { binAAmounts = new uint256[](binIds.length); binBAmounts = new uint256[](binIds.length); ticks = new int32[](binIds.length); liquidities = new uint256[](binIds.length); for (uint256 i; i < binIds.length; i++) { (binAAmounts[i], binBAmounts[i], ticks[i], liquidities[i]) = userSubaccountBinReserves( pool, user, subaccount, binIds[i] ); amountA += binAAmounts[i]; amountB += binBAmounts[i]; } { uint256 tokenAScale = pool.tokenAScale(); uint256 tokenBScale = pool.tokenBScale(); amountA = Math.ammScaleToTokenScale(amountA, tokenAScale, false); amountB = Math.ammScaleToTokenScale(amountB, tokenBScale, false); } } function binLpBalances( IMaverickV2Pool pool, uint32[] memory binIds, uint256 subaccount ) internal view returns (uint128[] memory amounts) { amounts = new uint128[](binIds.length); for (uint256 i = 0; i < binIds.length; i++) { amounts[i] = pool.balanceOf(address(this), subaccount, binIds[i]); } } function lpBalanceForTargetReserveAmounts( IMaverickV2Pool pool, uint32 binId, uint256 amountA, uint256 amountB, uint256 scaleA, uint256 scaleB ) internal view returns (IMaverickV2Pool.AddLiquidityParams memory addParams) { amountA = Math.tokenScaleToAmmScale(amountA, scaleA); amountB = Math.tokenScaleToAmmScale(amountB, scaleB); IMaverickV2Pool.BinState memory bin = pool.getBin(binId); uint128[] memory amounts = new uint128[](1); IMaverickV2Pool.TickState memory tickState = pool.getTick(bin.tick); uint256 numerator = Math.max(1, uint256(tickState.totalSupply)) * Math.max(1, uint256(bin.totalSupply)); if (amountA != 0) { uint256 denominator = Math.max(1, uint256(bin.tickBalance)) * uint256(tickState.reserveA); amounts[0] = Math.mulDivFloor(amountA, numerator, denominator).toUint128(); } if (amountB != 0) { uint256 denominator = Math.max(1, uint256(bin.tickBalance)) * uint256(tickState.reserveB); if (amountA != 0) { amounts[0] = Math.min128(amounts[0], Math.mulDivFloor(amountB, numerator, denominator).toUint128()); } else { amounts[0] = Math.mulDivFloor(amountB, numerator, denominator).toUint128(); } } { int32[] memory ticks = new int32[](1); ticks[0] = bin.tick; addParams = IMaverickV2Pool.AddLiquidityParams({kind: bin.kind, ticks: ticks, amounts: amounts}); } } function maxRemoveParams( IMaverickV2Pool pool, uint32 binId, address user, uint256 subaccount ) internal view returns (IMaverickV2Pool.RemoveLiquidityParams memory params) { uint32[] memory binIds = new uint32[](1); uint128[] memory amounts = new uint128[](1); binIds[0] = binId; amounts[0] = pool.balanceOf(user, subaccount, binId); params = IMaverickV2Pool.RemoveLiquidityParams({binIds: binIds, amounts: amounts}); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {PackLib} from "../libraries/PackLib.sol"; import {IArgPacker} from "./IArgPacker.sol"; /** * @notice View functions that pack and unpack addLiquidity parameters. */ abstract contract ArgPacker is IArgPacker { /// @inheritdoc IArgPacker function unpackAddLiquidityArgs( bytes memory argsPacked ) public pure returns (IMaverickV2Pool.AddLiquidityParams memory args) { return PackLib.unpackAddLiquidityArgs(argsPacked); } /// @inheritdoc IArgPacker function packAddLiquidityArgs( IMaverickV2Pool.AddLiquidityParams memory args ) public pure returns (bytes memory argsPacked) { return PackLib.packAddLiquidityArgs(args); } /// @inheritdoc IArgPacker function packAddLiquidityArgsArray( IMaverickV2Pool.AddLiquidityParams[] memory args ) public pure returns (bytes[] memory argsPacked) { return PackLib.packAddLiquidityArgsArray(args); } /// @inheritdoc IArgPacker function unpackUint88Array(bytes memory packedArray) public pure returns (uint88[] memory fullArray) { fullArray = PackLib.unpackUint88Array(packedArray); } /// @inheritdoc IArgPacker function packUint88Array(uint88[] memory fullArray) public pure returns (bytes memory packedArray) { packedArray = PackLib.packArray(fullArray); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; interface IArgPacker { /** * @notice Packs addLiquidity paramters into a bytes object. The packing * is [kind, ticksArray, amountsArray] where the arrays are packed like * this: [length, array[0], array[1],..., array[length-1]]. length is 1 * byte (256 total possible elements). */ function packAddLiquidityArgs( IMaverickV2Pool.AddLiquidityParams memory args ) external pure returns (bytes memory argsPacked); /** * @notice Unpacks packed addLiquidity parameters. */ function unpackAddLiquidityArgs( bytes memory argsPacked ) external pure returns (IMaverickV2Pool.AddLiquidityParams memory args); /** * @notice Packs addLiquidity paramters array element-wise. */ function packAddLiquidityArgsArray( IMaverickV2Pool.AddLiquidityParams[] memory args ) external pure returns (bytes[] memory argsPacked); /** * @notice Packs sqrtPrice breaks array with this format: [length, * array[0], array[1],..., array[length-1]] where length is 1 byte. */ function packUint88Array(uint88[] memory fullArray) external pure returns (bytes memory packedArray); /** * @notice Unpacks sqrtPrice breaks bytes object into array. */ function unpackUint88Array(bytes memory packedArray) external pure returns (uint88[] memory fullArray); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {IMaverickV2Factory} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Factory.sol"; import {EMPTY_PRICE_BREAKS} from "@maverick/v2-common/contracts/libraries/Constants.sol"; import {PoolInspection} from "./libraries/PoolInspection.sol"; import {IMaverickV2Position} from "./interfaces/IMaverickV2Position.sol"; import {IMaverickV2PoolLens} from "./interfaces/IMaverickV2PoolLens.sol"; import {IMaverickV2BoostedPosition} from "./interfaces/IMaverickV2BoostedPosition.sol"; import {IMaverickV2LiquidityManager} from "./interfaces/IMaverickV2LiquidityManager.sol"; import {IMaverickV2BoostedPositionFactory} from "./interfaces/IMaverickV2BoostedPositionFactory.sol"; import {IWETH9} from "./paymentbase/IWETH9.sol"; import {ArgPacker} from "./liquiditybase/ArgPacker.sol"; import {State} from "./paymentbase/State.sol"; import {ExactOutputSlim} from "./routerbase/ExactOutputSlim.sol"; import {LiquidityUtilities} from "./libraries/LiquidityUtilities.sol"; import {Checks} from "./base/Checks.sol"; import {MigrateBins} from "./base/MigrateBins.sol"; /** * @notice Maverick liquidity management contract that provides helper * functions for minting either NFT liquidity positions or boosted positions * which are fungible positions in a Maverick V2 pool. While this contract * does have public payment callback functions, these are access controlled * so that they can only be called by a factory pool; so it is safe to approve * this contract to spend a caller's tokens. * * This contract inherits "Check" functions that can be multicalled with * liquidity management functions to create slippage and deadline constraints on * transactions. * * * @dev This contract has a multicall interface and all public functions are * payable which facilitates multicall combinations of both payable * interactions and non-payable interactions. * * @dev addLiquidity parameters are specified as a lookup table of prices where * the caller specifies packedSqrtPriceBreaks and packedArgs. During the add * operation, this contract queries the pool for its current sqrtPrice and then * looks up this price relative to the price breaks array (the array is packed * as bytes using the conventions in the inherited ArgPacker contract to save * calldata space). If the current pool sqrt price is in between the N and N+1 * elements of the packedSqrtPriceBreaks array, then the add parameters from the * Nth element of the packedArgs array are used in the add liquidity call. * * @dev This lookup table approach provides a flexible way for callers to * manage price slippage between the time they submit their transaction and the * time it is executed. The MaverickV2PoolLens contract provides a number of * helper function to create this slippage lookup table. */ contract MaverickV2LiquidityManager is Checks, ExactOutputSlim, ArgPacker, MigrateBins, IMaverickV2LiquidityManager { /// @inheritdoc IMaverickV2LiquidityManager IMaverickV2Position public immutable position; /// @inheritdoc IMaverickV2LiquidityManager IMaverickV2BoostedPositionFactory public immutable boostedPositionFactory; constructor( IMaverickV2Factory _factory, IWETH9 _weth, IMaverickV2Position _position, IMaverickV2BoostedPositionFactory _boostedPositionFactory ) State(_factory, _weth) { position = _position; boostedPositionFactory = _boostedPositionFactory; } /////////////////////////// //// Pool functions /////////////////////////// /// @inheritdoc IMaverickV2LiquidityManager function createPool( uint64 fee, uint16 tickSpacing, uint32 lookback, IERC20 tokenA, IERC20 tokenB, int32 activeTick, uint8 kinds ) public payable returns (IMaverickV2Pool pool) { pool = factory().create(fee, fee, tickSpacing, lookback, tokenA, tokenB, activeTick, kinds); } /// @inheritdoc IMaverickV2LiquidityManager function createPool( uint64 feeAIn, uint64 feeBIn, uint16 tickSpacing, uint32 lookback, IERC20 tokenA, IERC20 tokenB, int32 activeTick, uint8 kinds ) public payable returns (IMaverickV2Pool pool) { pool = factory().create(feeAIn, feeBIn, tickSpacing, lookback, tokenA, tokenB, activeTick, kinds); } /// @inheritdoc IMaverickV2LiquidityManager function addLiquidity( IMaverickV2Pool pool, address recipient, uint256 subaccount, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds) { uint256 sqrtPrice = PoolInspection.poolSqrtPrice(pool); uint256 priceIndex = LiquidityUtilities.priceIndexFromPriceBreaks(sqrtPrice, packedSqrtPriceBreaks); IMaverickV2Pool.AddLiquidityParams memory args = unpackAddLiquidityArgs(packedArgs[priceIndex]); (tokenAAmount, tokenBAmount, binIds) = pool.addLiquidity(recipient, subaccount, args, abi.encode(msg.sender)); } /// @inheritdoc IMaverickV2LiquidityManager function donateLiquidity(IMaverickV2Pool pool, IMaverickV2Pool.AddLiquidityParams memory args) public payable { pool.addLiquidity(address(position), 0, args, abi.encode(msg.sender)); } /// @inheritdoc IMaverickV2LiquidityManager function createPoolAtPriceAndAddLiquidityToSender( IMaverickV2PoolLens.CreateAndAddParamsInputs memory params ) public payable returns ( IMaverickV2Pool pool, uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId ) { return createPoolAtPriceAndAddLiquidity(msg.sender, params); } /// @inheritdoc IMaverickV2LiquidityManager function createPoolAtPriceAndAddLiquidity( address recipient, IMaverickV2PoolLens.CreateAndAddParamsInputs memory params ) public payable returns ( IMaverickV2Pool pool, uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId ) { pool = createPool( params.feeAIn, params.feeBIn, params.tickSpacing, params.lookback, params.tokenA, params.tokenB, params.activeTick, params.kinds ); if (params.swapAmount != 0) { donateLiquidity(pool, params.donateParams); exactOutputSingleMinimal(recipient, pool, true, params.swapAmount, type(int32).max); } (tokenAAmount, tokenBAmount, binIds, tokenId) = mintPositionNft( pool, recipient, EMPTY_PRICE_BREAKS, params.packedAddParams ); } function maverickV2AddLiquidityCallback( IERC20 tokenA, IERC20 tokenB, uint256 amountA, uint256 amountB, bytes calldata data ) public { if (!factory().isFactoryPool(IMaverickV2Pool(msg.sender))) revert LiquidityManagerNotFactoryPool(); address payer = abi.decode(data, (address)); if (amountA != 0) { pay(tokenA, payer, msg.sender, amountA); } if (amountB != 0) { pay(tokenB, payer, msg.sender, amountB); } } /////////////////////////// //// Position NFT functions /////////////////////////// /// @inheritdoc IMaverickV2LiquidityManager function addPositionLiquidityToSenderByTokenIndex( IMaverickV2Pool pool, uint256 index, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds) { (tokenAAmount, tokenBAmount, binIds) = addLiquidity( pool, address(position), position.tokenOfOwnerByIndex(msg.sender, index), packedSqrtPriceBreaks, packedArgs ); } /// @inheritdoc IMaverickV2LiquidityManager function addPositionLiquidityToRecipientByTokenIndex( IMaverickV2Pool pool, address recipient, uint256 index, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds) { (tokenAAmount, tokenBAmount, binIds) = addLiquidity( pool, address(position), position.tokenOfOwnerByIndex(recipient, index), packedSqrtPriceBreaks, packedArgs ); } /// @inheritdoc IMaverickV2LiquidityManager function mintPositionNft( IMaverickV2Pool pool, address recipient, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId) { (tokenAAmount, tokenBAmount, binIds) = addLiquidity( pool, address(position), position.nextTokenId(), packedSqrtPriceBreaks, packedArgs ); tokenId = position.mint(recipient, pool, binIds); } /// @inheritdoc IMaverickV2LiquidityManager function mintPositionNftToSender( IMaverickV2Pool pool, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId) { return mintPositionNft(pool, msg.sender, packedSqrtPriceBreaks, packedArgs); } /////////////////////////// //// Booste Position functions /////////////////////////// /// @inheritdoc IMaverickV2LiquidityManager function migrateBoostedPosition(IMaverickV2BoostedPosition boostedPosition) public payable { boostedPosition.migrateBinLiquidityToRoot(); } /// @inheritdoc IMaverickV2LiquidityManager function skimBoostedPosition( IMaverickV2BoostedPosition boostedPosition, address recipient ) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount) { (tokenAAmount, tokenBAmount) = boostedPosition.skim(recipient); } /// @inheritdoc IMaverickV2LiquidityManager function mintBoostedPosition( IMaverickV2BoostedPosition boostedPosition, address recipient ) public payable returns (uint256 mintedLpAmount) { mintedLpAmount = boostedPosition.mint(recipient); } /// @inheritdoc IMaverickV2LiquidityManager function addLiquidityAndMintBoostedPosition( address recipient, IMaverickV2BoostedPosition boostedPosition, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) public payable virtual returns (uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount) { boostedPosition.migrateBinLiquidityToRoot(); if (boostedPosition.skimmableAmount() != 0) skimBoostedPosition(boostedPosition, recipient); (tokenAAmount, tokenBAmount, ) = addLiquidity( boostedPosition.pool(), address(boostedPosition), 0, packedSqrtPriceBreaks, packedArgs ); mintedLpAmount = boostedPosition.mint(recipient); } /// @inheritdoc IMaverickV2LiquidityManager function addLiquidityAndMintBoostedPositionToSender( IMaverickV2BoostedPosition boostedPosition, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs ) public payable returns (uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount) { return addLiquidityAndMintBoostedPosition(msg.sender, boostedPosition, packedSqrtPriceBreaks, packedArgs); } /// @inheritdoc IMaverickV2LiquidityManager function createBoostedPositionAndAddLiquidityToSender( IMaverickV2PoolLens.CreateBoostedPositionInputs memory params ) public payable returns ( IMaverickV2BoostedPosition boostedPosition, uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount ) { return createBoostedPositionAndAddLiquidity(msg.sender, params); } /// @inheritdoc IMaverickV2LiquidityManager function createBoostedPositionAndAddLiquidity( address recipient, IMaverickV2PoolLens.CreateBoostedPositionInputs memory params ) public payable virtual returns ( IMaverickV2BoostedPosition boostedPosition, uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount ) { boostedPosition = boostedPositionFactory.createBoostedPosition( params.bpSpec.pool, params.bpSpec.binIds, params.bpSpec.ratios, params.bpSpec.kind ); (tokenAAmount, tokenBAmount, ) = addLiquidity( params.bpSpec.pool, address(boostedPosition), 0, params.packedSqrtPriceBreaks, params.packedArgs ); mintedLpAmount = boostedPosition.mint(recipient); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IPayableMulticall} from "@maverick/v2-common/contracts/base/IPayableMulticall.sol"; import {IState} from "./IState.sol"; interface IPayment is IPayableMulticall, IState { error PaymentSenderNotWETH9(); error PaymentInsufficientBalance(address token, uint256 amountMinimum, uint256 contractBalance); receive() external payable; /** * @notice Unwrap WETH9 tokens into ETH and send that balance to recipient. * If less than amountMinimum WETH is avialble, then revert. */ function unwrapWETH9(uint256 amountMinimum, address recipient) external payable; /** * @notice Transfers specified token amount to recipient */ function sweepTokenAmount(IERC20 token, uint256 amount, address recipient) external payable; /** * @notice Sweep entire ERC20 token balance on this contract to recipient. * If less than amountMinimum balance is avialble, then revert. */ function sweepToken(IERC20 token, uint256 amountMinimum, address recipient) external payable; /** * @notice Send any ETH on this contract to msg.sender. */ function refundETH() external payable; /** * @notice For tokenA and tokenB, sweep all of the * non-WETH tokens to msg.sender. Any WETH balance is unwrapped to ETH and * then all the ETH on this contract is sent to msg.sender. */ function unwrapAndSweep( IERC20 tokenA, IERC20 tokenB, uint256 tokenAAmountMin, uint256 tokenBAmountMin ) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IWETH9} from "./IWETH9.sol"; import {IMaverickV2Factory} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Factory.sol"; interface IState { function weth() external view returns (IWETH9 _weth); function factory() external view returns (IMaverickV2Factory _factory); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IWETH9 is IERC20 { event Deposit(address indexed dst, uint256 wad); event Withdrawal(address indexed src, uint256 wad); function deposit() external payable; function withdraw(uint256) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {Address} from "@openzeppelin/contracts/utils/Address.sol"; import {TransferLib} from "@maverick/v2-common/contracts/libraries/TransferLib.sol"; import {PayableMulticall} from "@maverick/v2-common/contracts/base/PayableMulticall.sol"; import {IWETH9} from "./IWETH9.sol"; import {State} from "./State.sol"; import {IPayment} from "./IPayment.sol"; /** * @notice Payment helper function that lets user sweep ERC20 tokens off the * router and liquidity manager. Also provides mechanism to wrap and unwrap * ETH/WETH so that it can be used in the Maverick pools. */ abstract contract Payment is State, PayableMulticall, IPayment { receive() external payable { if (IWETH9(msg.sender) != weth()) revert PaymentSenderNotWETH9(); } /// @inheritdoc IPayment function unwrapWETH9(uint256 amountMinimum, address recipient) public payable { uint256 balanceWETH9 = weth().balanceOf(address(this)); if (balanceWETH9 < amountMinimum) revert PaymentInsufficientBalance(address(weth()), amountMinimum, balanceWETH9); if (balanceWETH9 > 0) { weth().withdraw(balanceWETH9); Address.sendValue(payable(recipient), balanceWETH9); } } /// @inheritdoc IPayment function sweepToken(IERC20 token, uint256 amountMinimum, address recipient) public payable { uint256 balanceToken = token.balanceOf(address(this)); if (balanceToken < amountMinimum) revert PaymentInsufficientBalance(address(token), amountMinimum, balanceToken); if (balanceToken > 0) { TransferLib.transfer(token, recipient, balanceToken); } } /// @inheritdoc IPayment function sweepTokenAmount(IERC20 token, uint256 amount, address recipient) public payable { TransferLib.transfer(token, recipient, amount); } /// @inheritdoc IPayment function unwrapAndSweep( IERC20 tokenA, IERC20 tokenB, uint256 tokenAAmountMin, uint256 tokenBAmountMin ) public payable { if (address(tokenA) == address(weth())) { unwrapWETH9(tokenAAmountMin, msg.sender); refundETH(); sweepToken(tokenB, tokenBAmountMin, msg.sender); } else if (address(tokenB) == address(weth())) { sweepToken(tokenA, tokenAAmountMin, msg.sender); unwrapWETH9(tokenBAmountMin, msg.sender); refundETH(); } else { sweepToken(tokenA, tokenAAmountMin, msg.sender); sweepToken(tokenB, tokenBAmountMin, msg.sender); } } /// @inheritdoc IPayment function refundETH() public payable { if (address(this).balance > 0) Address.sendValue(payable(msg.sender), address(this).balance); } /** * @notice Internal function to pay tokens or eth. * @param token ERC20 token to pay. * @param payer Address of the payer. * @param recipient Address of the recipient. * @param value Amount of tokens to pay. */ function pay(IERC20 token, address payer, address recipient, uint256 value) internal { if (IWETH9(address(token)) == weth() && address(this).balance >= value) { weth().deposit{value: value}(); weth().transfer(recipient, value); } else if (payer == address(this)) { TransferLib.transfer(token, recipient, value); } else { TransferLib.transferFrom(token, payer, recipient, value); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Factory} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Factory.sol"; import {IWETH9} from "./IWETH9.sol"; import {IState} from "./IState.sol"; abstract contract State is IState { IWETH9 private immutable _weth; IMaverickV2Factory private immutable _factory; constructor(IMaverickV2Factory __factory, IWETH9 __weth) { _factory = __factory; _weth = __weth; } function weth() public view returns (IWETH9 weth_) { weth_ = _weth; } function factory() public view returns (IMaverickV2Factory factory_) { factory_ = _factory; } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol"; interface INft is IERC721Enumerable { /** * @notice Check if an NFT exists for a given owner and index. */ function tokenOfOwnerByIndexExists(address owner, uint256 index) external view returns (bool); /** * @notice Return Id of the next token minted. */ function nextTokenId() external view returns (uint256 nextTokenId_); /** * @notice Check if the caller has access to a specific NFT by tokenId. */ function checkAuthorized(address spender, uint256 tokenId) external view returns (address owner); /** * @notice List of tokenIds by owner. */ function tokenIdsOfOwner(address owner) external view returns (uint256[] memory tokenIds); /** * @notice Get the token URI for a given tokenId. */ function tokenURI(uint256 tokenId) external view returns (string memory); function name() external view returns (string memory); function symbol() external view returns (string memory); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {Payment} from "../paymentbase/Payment.sol"; import {IExactOutputSlim} from "./IExactOutputSlim.sol"; import {Swap} from "./Swap.sol"; abstract contract ExactOutputSlim is Payment, Swap, IExactOutputSlim { /** * @dev Callback function called by Maverick V2 pools when swapping tokens. * @param tokenIn The input token. * @param amountToPay The amount to pay. * @param data Additional data. */ function maverickV2SwapCallback( IERC20 tokenIn, uint256 amountToPay, uint256, bytes calldata data ) external virtual { if (!factory().isFactoryPool(IMaverickV2Pool(msg.sender))) revert RouterNotFactoryPool(); address payer = abi.decode(data, (address)); if (amountToPay != 0) pay(tokenIn, payer, msg.sender, amountToPay); } /** * @dev Perform a swap with an exact output amount. * @param recipient The recipient of the swapped tokens. * @param pool The MaverickV2 pool to use for the swap. * @param tokenAIn Whether token A is the input token. * @param amountOut The exact output amount. * @param tickLimit The tick limit for the swap. * @return amountIn The input amount required to achieve the exact output. * @return amountOut_ The actual output amount received from the swap. */ function exactOutputSingleMinimal( address recipient, IMaverickV2Pool pool, bool tokenAIn, uint256 amountOut, int32 tickLimit ) public payable returns (uint256 amountIn, uint256 amountOut_) { (amountIn, amountOut_) = _exactOutputSingleWithTickCheck(pool, recipient, amountOut, tokenAIn, tickLimit); } /** * @dev Perform an exact output single swap with tick limit validation. * @param pool The MaverickV2 pool to use for the swap. * @param recipient The recipient of the swapped tokens. * @param amountOut The exact output amount. * @param tokenAIn Whether token A is the input token. * @param tickLimit The tick limit for the swap. * @return amountIn The input amount required to achieve the exact output. * @return _amountOut The actual output amount received from the swap. */ function _exactOutputSingleWithTickCheck( IMaverickV2Pool pool, address recipient, uint256 amountOut, bool tokenAIn, int32 tickLimit ) internal returns (uint256 amountIn, uint256 _amountOut) { IMaverickV2Pool.SwapParams memory swapParams = IMaverickV2Pool.SwapParams({ amount: amountOut, tokenAIn: tokenAIn, exactOutput: true, tickLimit: tickLimit }); (amountIn, _amountOut) = _swap( pool, (recipient == address(0)) ? address(this) : recipient, swapParams, abi.encode(msg.sender) ); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; import {IRouterErrors} from "./IRouterErrors.sol"; interface IExactOutputSlim is IRouterErrors { function exactOutputSingleMinimal( address recipient, IMaverickV2Pool pool, bool tokenAIn, uint256 amountOut, int32 tickLimit ) external payable returns (uint256 amountIn, uint256 amountOut_); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; interface IRouterErrors { error RouterZeroSwap(); error RouterNotFactoryPool(); error RouterTooLittleReceived(uint256 amountOutMinimum, uint256 amountOut); error RouterTooMuchRequested(uint256 amountInMaximum, uint256 amountIn); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.25; import {IMaverickV2Pool} from "@maverick/v2-common/contracts/interfaces/IMaverickV2Pool.sol"; /** * @notice Base contract support for swaps */ abstract contract Swap { /** * @notice Internal swap function. Override this function to add logic * before or after a swap. */ function _swap( IMaverickV2Pool pool, address recipient, IMaverickV2Pool.SwapParams memory params, bytes memory data ) internal virtual returns (uint256 amountIn, uint256 amountOut) { (amountIn, amountOut) = pool.swap(recipient, params, data); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (governance/utils/IVotes.sol) pragma solidity ^0.8.20; /** * @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts. */ interface IVotes { /** * @dev The signature used has expired. */ error VotesExpiredSignature(uint256 expiry); /** * @dev Emitted when an account changes their delegate. */ event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); /** * @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of voting units. */ event DelegateVotesChanged(address indexed delegate, uint256 previousVotes, uint256 newVotes); /** * @dev Returns the current amount of votes that `account` has. */ function getVotes(address account) external view returns (uint256); /** * @dev Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is * configured to use block numbers, this will return the value at the end of the corresponding block. */ function getPastVotes(address account, uint256 timepoint) external view returns (uint256); /** * @dev Returns the total supply of votes available at a specific moment in the past. If the `clock()` is * configured to use block numbers, this will return the value at the end of the corresponding block. * * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes. * Votes that have not been delegated are still part of total supply, even though they would not participate in a * vote. */ function getPastTotalSupply(uint256 timepoint) external view returns (uint256); /** * @dev Returns the delegate that `account` has chosen. */ function delegates(address account) external view returns (address); /** * @dev Delegates votes from the sender to `delegatee`. */ function delegate(address delegatee) external; /** * @dev Delegates votes from signer to `delegatee`. */ function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol) pragma solidity ^0.8.20; /** * @dev Standard ERC20 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens. */ interface IERC20Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC20InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC20InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers. * @param spender Address that may be allowed to operate on tokens without being their owner. * @param allowance Amount of tokens a `spender` is allowed to operate with. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC20InvalidApprover(address approver); /** * @dev Indicates a failure with the `spender` to be approved. Used in approvals. * @param spender Address that may be allowed to operate on tokens without being their owner. */ error ERC20InvalidSpender(address spender); } /** * @dev Standard ERC721 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens. */ interface IERC721Errors { /** * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20. * Used in balance queries. * @param owner Address of the current owner of a token. */ error ERC721InvalidOwner(address owner); /** * @dev Indicates a `tokenId` whose `owner` is the zero address. * @param tokenId Identifier number of a token. */ error ERC721NonexistentToken(uint256 tokenId); /** * @dev Indicates an error related to the ownership over a particular token. Used in transfers. * @param sender Address whose tokens are being transferred. * @param tokenId Identifier number of a token. * @param owner Address of the current owner of a token. */ error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC721InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC721InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param tokenId Identifier number of a token. */ error ERC721InsufficientApproval(address operator, uint256 tokenId); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC721InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC721InvalidOperator(address operator); } /** * @dev Standard ERC1155 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens. */ interface IERC1155Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. * @param tokenId Identifier number of a token. */ error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC1155InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC1155InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param owner Address of the current owner of a token. */ error ERC1155MissingApprovalForAll(address operator, address owner); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC1155InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC1155InvalidOperator(address operator); /** * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation. * Used in batch transfers. * @param idsLength Length of the array of token identifiers * @param valuesLength Length of the array of token amounts */ error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC6372.sol) pragma solidity ^0.8.20; interface IERC6372 { /** * @dev Clock used for flagging checkpoints. Can be overridden to implement timestamp based checkpoints (and voting). */ function clock() external view returns (uint48); /** * @dev Description of the clock */ // solhint-disable-next-line func-name-mixedcase function CLOCK_MODE() external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "./IERC20.sol"; import {IERC20Metadata} from "./extensions/IERC20Metadata.sol"; import {Context} from "../../utils/Context.sol"; import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * * TIP: For a detailed writeup see our guide * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * The default value of {decimals} is 18. To change this, you should override * this function so it returns a different value. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. */ abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors { mapping(address account => uint256) private _balances; mapping(address account => mapping(address spender => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the default value returned by this function, unless * it's overridden. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `value`. */ function transfer(address to, uint256 value) public virtual returns (bool) { address owner = _msgSender(); _transfer(owner, to, value); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 value) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, value); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `value`. * - the caller must have allowance for ``from``'s tokens of at least * `value`. */ function transferFrom(address from, address to, uint256 value) public virtual returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, value); _transfer(from, to, value); return true; } /** * @dev Moves a `value` amount of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * NOTE: This function is not virtual, {_update} should be overridden instead. */ function _transfer(address from, address to, uint256 value) internal { if (from == address(0)) { revert ERC20InvalidSender(address(0)); } if (to == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(from, to, value); } /** * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from` * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding * this function. * * Emits a {Transfer} event. */ function _update(address from, address to, uint256 value) internal virtual { if (from == address(0)) { // Overflow check required: The rest of the code assumes that totalSupply never overflows _totalSupply += value; } else { uint256 fromBalance = _balances[from]; if (fromBalance < value) { revert ERC20InsufficientBalance(from, fromBalance, value); } unchecked { // Overflow not possible: value <= fromBalance <= totalSupply. _balances[from] = fromBalance - value; } } if (to == address(0)) { unchecked { // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply. _totalSupply -= value; } } else { unchecked { // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256. _balances[to] += value; } } emit Transfer(from, to, value); } /** * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0). * Relies on the `_update` mechanism * * Emits a {Transfer} event with `from` set to the zero address. * * NOTE: This function is not virtual, {_update} should be overridden instead. */ function _mint(address account, uint256 value) internal { if (account == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(address(0), account, value); } /** * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply. * Relies on the `_update` mechanism. * * Emits a {Transfer} event with `to` set to the zero address. * * NOTE: This function is not virtual, {_update} should be overridden instead */ function _burn(address account, uint256 value) internal { if (account == address(0)) { revert ERC20InvalidSender(address(0)); } _update(account, address(0), value); } /** * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. * * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument. */ function _approve(address owner, address spender, uint256 value) internal { _approve(owner, spender, value, true); } /** * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event. * * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any * `Approval` event during `transferFrom` operations. * * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to * true using the following override: * ``` * function _approve(address owner, address spender, uint256 value, bool) internal virtual override { * super._approve(owner, spender, value, true); * } * ``` * * Requirements are the same as {_approve}. */ function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual { if (owner == address(0)) { revert ERC20InvalidApprover(address(0)); } if (spender == address(0)) { revert ERC20InvalidSpender(address(0)); } _allowances[owner][spender] = value; if (emitEvent) { emit Approval(owner, spender, value); } } /** * @dev Updates `owner` s allowance for `spender` based on spent `value`. * * Does not update the allowance value in case of infinite allowance. * Revert if not enough allowance is available. * * Does not emit an {Approval} event. */ function _spendAllowance(address owner, address spender, uint256 value) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { if (currentAllowance < value) { revert ERC20InsufficientAllowance(spender, currentAllowance, value); } unchecked { _approve(owner, spender, currentAllowance - value, false); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.20; /** * @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. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ 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]. * * CAUTION: See Security Considerations above. */ 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 v5.0.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @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 value of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the value of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the * allowance mechanism. `value` 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 value) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; import {IERC20Permit} from "../extensions/IERC20Permit.sol"; import {Address} from "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev An operation with an ERC20 token failed. */ error SafeERC20FailedOperation(address token); /** * @dev Indicates a failed `decreaseAllowance` request. */ error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease); /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value))); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value))); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 oldAllowance = token.allowance(address(this), spender); forceApprove(token, spender, oldAllowance + value); } /** * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no * value, non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal { unchecked { uint256 currentAllowance = token.allowance(address(this), spender); if (currentAllowance < requestedDecrease) { revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease); } forceApprove(token, spender, currentAllowance - requestedDecrease); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. */ function forceApprove(IERC20 token, address spender, uint256 value) internal { bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value)); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0))); _callOptionalReturn(token, approvalCall); } } /** * @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); if (returndata.length != 0 && !abi.decode(returndata, (bool))) { revert SafeERC20FailedOperation(address(token)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/extensions/IERC721Enumerable.sol) pragma solidity ^0.8.20; import {IERC721} from "../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: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.20; import {IERC165} from "../../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 address zero. * * 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 (last updated v5.0.0) (utils/Address.sol) pragma solidity ^0.8.20; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev The ETH balance of the account is not enough to perform the operation. */ error AddressInsufficientBalance(address account); /** * @dev There's no code at `target` (it is not a contract). */ error AddressEmptyCode(address target); /** * @dev A call to an address target failed. The target may have reverted. */ error FailedInnerCall(); /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { if (address(this).balance < amount) { revert AddressInsufficientBalance(address(this)); } (bool success, ) = recipient.call{value: amount}(""); if (!success) { revert FailedInnerCall(); } } /** * @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 or custom error, it is bubbled * up by this function (like regular Solidity function calls). However, if * the call reverted with no returned reason, this function reverts with a * {FailedInnerCall} error. * * 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. */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0); } /** * @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`. */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { if (address(this).balance < value) { revert AddressInsufficientBalance(address(this)); } (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an * unsuccessful call. */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata ) internal view returns (bytes memory) { if (!success) { _revert(returndata); } else { // only check if target is a contract if the call was successful and the return data is empty // otherwise we already know that it was a contract if (returndata.length == 0 && target.code.length == 0) { revert AddressEmptyCode(target); } return returndata; } } /** * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the * revert reason or with a default {FailedInnerCall} error. */ function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) { if (!success) { _revert(returndata); } else { return returndata; } } /** * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}. */ function _revert(bytes memory returndata) 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 FailedInnerCall(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; /** * @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; } function _contextSuffixLength() internal view virtual returns (uint256) { return 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol) pragma solidity ^0.8.20; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { /** * @dev Muldiv operation overflow. */ error MathOverflowedMulDiv(); enum Rounding { Floor, // Toward negative infinity Ceil, // Toward positive infinity Trunc, // Toward zero Expand // Away from zero } /** * @dev Returns the addition of two unsigned integers, with an overflow flag. */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds towards infinity instead * of rounding towards zero. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { if (b == 0) { // Guarantee the same behavior as in a regular Solidity division. return a / b; } // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or * denominator == 0. * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by * Uniswap Labs also under MIT license. */ function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0 = x * y; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. if (denominator <= prod1) { revert MathOverflowedMulDiv(); } /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. // Always >= 1. See https://cs.stackexchange.com/q/138556/92363. uint256 twos = denominator & (0 - denominator); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also // works in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded * towards zero. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10 of a positive value rounded towards zero. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256 of a positive value rounded towards zero. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0); } } /** * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers. */ function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) { return uint8(rounding) % 2 == 1; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. pragma solidity ^0.8.20; /** * @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. */ library SafeCast { /** * @dev Value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value); /** * @dev An int value doesn't fit in an uint of `bits` size. */ error SafeCastOverflowedIntToUint(int256 value); /** * @dev Value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedIntDowncast(uint8 bits, int256 value); /** * @dev An uint value doesn't fit in an int of `bits` size. */ error SafeCastOverflowedUintToInt(uint256 value); /** * @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 */ function toUint248(uint256 value) internal pure returns (uint248) { if (value > type(uint248).max) { revert SafeCastOverflowedUintDowncast(248, value); } 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 */ function toUint240(uint256 value) internal pure returns (uint240) { if (value > type(uint240).max) { revert SafeCastOverflowedUintDowncast(240, value); } 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 */ function toUint232(uint256 value) internal pure returns (uint232) { if (value > type(uint232).max) { revert SafeCastOverflowedUintDowncast(232, value); } 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 */ function toUint224(uint256 value) internal pure returns (uint224) { if (value > type(uint224).max) { revert SafeCastOverflowedUintDowncast(224, value); } 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 */ function toUint216(uint256 value) internal pure returns (uint216) { if (value > type(uint216).max) { revert SafeCastOverflowedUintDowncast(216, value); } 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 */ function toUint208(uint256 value) internal pure returns (uint208) { if (value > type(uint208).max) { revert SafeCastOverflowedUintDowncast(208, value); } 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 */ function toUint200(uint256 value) internal pure returns (uint200) { if (value > type(uint200).max) { revert SafeCastOverflowedUintDowncast(200, value); } 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 */ function toUint192(uint256 value) internal pure returns (uint192) { if (value > type(uint192).max) { revert SafeCastOverflowedUintDowncast(192, value); } 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 */ function toUint184(uint256 value) internal pure returns (uint184) { if (value > type(uint184).max) { revert SafeCastOverflowedUintDowncast(184, value); } 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 */ function toUint176(uint256 value) internal pure returns (uint176) { if (value > type(uint176).max) { revert SafeCastOverflowedUintDowncast(176, value); } 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 */ function toUint168(uint256 value) internal pure returns (uint168) { if (value > type(uint168).max) { revert SafeCastOverflowedUintDowncast(168, value); } 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 */ function toUint160(uint256 value) internal pure returns (uint160) { if (value > type(uint160).max) { revert SafeCastOverflowedUintDowncast(160, value); } 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 */ function toUint152(uint256 value) internal pure returns (uint152) { if (value > type(uint152).max) { revert SafeCastOverflowedUintDowncast(152, value); } 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 */ function toUint144(uint256 value) internal pure returns (uint144) { if (value > type(uint144).max) { revert SafeCastOverflowedUintDowncast(144, value); } 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 */ function toUint136(uint256 value) internal pure returns (uint136) { if (value > type(uint136).max) { revert SafeCastOverflowedUintDowncast(136, value); } 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 */ function toUint128(uint256 value) internal pure returns (uint128) { if (value > type(uint128).max) { revert SafeCastOverflowedUintDowncast(128, value); } 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 */ function toUint120(uint256 value) internal pure returns (uint120) { if (value > type(uint120).max) { revert SafeCastOverflowedUintDowncast(120, value); } 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 */ function toUint112(uint256 value) internal pure returns (uint112) { if (value > type(uint112).max) { revert SafeCastOverflowedUintDowncast(112, value); } 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 */ function toUint104(uint256 value) internal pure returns (uint104) { if (value > type(uint104).max) { revert SafeCastOverflowedUintDowncast(104, value); } 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 */ function toUint96(uint256 value) internal pure returns (uint96) { if (value > type(uint96).max) { revert SafeCastOverflowedUintDowncast(96, value); } 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 */ function toUint88(uint256 value) internal pure returns (uint88) { if (value > type(uint88).max) { revert SafeCastOverflowedUintDowncast(88, value); } 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 */ function toUint80(uint256 value) internal pure returns (uint80) { if (value > type(uint80).max) { revert SafeCastOverflowedUintDowncast(80, value); } 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 */ function toUint72(uint256 value) internal pure returns (uint72) { if (value > type(uint72).max) { revert SafeCastOverflowedUintDowncast(72, value); } 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 */ function toUint64(uint256 value) internal pure returns (uint64) { if (value > type(uint64).max) { revert SafeCastOverflowedUintDowncast(64, value); } 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 */ function toUint56(uint256 value) internal pure returns (uint56) { if (value > type(uint56).max) { revert SafeCastOverflowedUintDowncast(56, value); } 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 */ function toUint48(uint256 value) internal pure returns (uint48) { if (value > type(uint48).max) { revert SafeCastOverflowedUintDowncast(48, value); } 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 */ function toUint40(uint256 value) internal pure returns (uint40) { if (value > type(uint40).max) { revert SafeCastOverflowedUintDowncast(40, value); } 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 */ function toUint32(uint256 value) internal pure returns (uint32) { if (value > type(uint32).max) { revert SafeCastOverflowedUintDowncast(32, value); } 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 */ function toUint24(uint256 value) internal pure returns (uint24) { if (value > type(uint24).max) { revert SafeCastOverflowedUintDowncast(24, value); } 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 */ function toUint16(uint256 value) internal pure returns (uint16) { if (value > type(uint16).max) { revert SafeCastOverflowedUintDowncast(16, value); } 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 */ function toUint8(uint256 value) internal pure returns (uint8) { if (value > type(uint8).max) { revert SafeCastOverflowedUintDowncast(8, value); } return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { if (value < 0) { revert SafeCastOverflowedIntToUint(value); } 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 */ function toInt248(int256 value) internal pure returns (int248 downcasted) { downcasted = int248(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(248, value); } } /** * @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 */ function toInt240(int256 value) internal pure returns (int240 downcasted) { downcasted = int240(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(240, value); } } /** * @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 */ function toInt232(int256 value) internal pure returns (int232 downcasted) { downcasted = int232(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(232, value); } } /** * @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 */ function toInt224(int256 value) internal pure returns (int224 downcasted) { downcasted = int224(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(224, value); } } /** * @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 */ function toInt216(int256 value) internal pure returns (int216 downcasted) { downcasted = int216(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(216, value); } } /** * @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 */ function toInt208(int256 value) internal pure returns (int208 downcasted) { downcasted = int208(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(208, value); } } /** * @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 */ function toInt200(int256 value) internal pure returns (int200 downcasted) { downcasted = int200(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(200, value); } } /** * @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 */ function toInt192(int256 value) internal pure returns (int192 downcasted) { downcasted = int192(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(192, value); } } /** * @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 */ function toInt184(int256 value) internal pure returns (int184 downcasted) { downcasted = int184(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(184, value); } } /** * @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 */ function toInt176(int256 value) internal pure returns (int176 downcasted) { downcasted = int176(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(176, value); } } /** * @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 */ function toInt168(int256 value) internal pure returns (int168 downcasted) { downcasted = int168(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(168, value); } } /** * @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 */ function toInt160(int256 value) internal pure returns (int160 downcasted) { downcasted = int160(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(160, value); } } /** * @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 */ function toInt152(int256 value) internal pure returns (int152 downcasted) { downcasted = int152(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(152, value); } } /** * @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 */ function toInt144(int256 value) internal pure returns (int144 downcasted) { downcasted = int144(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(144, value); } } /** * @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 */ function toInt136(int256 value) internal pure returns (int136 downcasted) { downcasted = int136(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(136, value); } } /** * @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 */ function toInt128(int256 value) internal pure returns (int128 downcasted) { downcasted = int128(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(128, value); } } /** * @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 */ function toInt120(int256 value) internal pure returns (int120 downcasted) { downcasted = int120(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(120, value); } } /** * @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 */ function toInt112(int256 value) internal pure returns (int112 downcasted) { downcasted = int112(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(112, value); } } /** * @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 */ function toInt104(int256 value) internal pure returns (int104 downcasted) { downcasted = int104(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(104, value); } } /** * @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 */ function toInt96(int256 value) internal pure returns (int96 downcasted) { downcasted = int96(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(96, value); } } /** * @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 */ function toInt88(int256 value) internal pure returns (int88 downcasted) { downcasted = int88(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(88, value); } } /** * @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 */ function toInt80(int256 value) internal pure returns (int80 downcasted) { downcasted = int80(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(80, value); } } /** * @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 */ function toInt72(int256 value) internal pure returns (int72 downcasted) { downcasted = int72(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(72, value); } } /** * @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 */ function toInt64(int256 value) internal pure returns (int64 downcasted) { downcasted = int64(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(64, value); } } /** * @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 */ function toInt56(int256 value) internal pure returns (int56 downcasted) { downcasted = int56(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(56, value); } } /** * @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 */ function toInt48(int256 value) internal pure returns (int48 downcasted) { downcasted = int48(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(48, value); } } /** * @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 */ function toInt40(int256 value) internal pure returns (int40 downcasted) { downcasted = int40(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(40, value); } } /** * @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 */ function toInt32(int256 value) internal pure returns (int32 downcasted) { downcasted = int32(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(32, value); } } /** * @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 */ function toInt24(int256 value) internal pure returns (int24 downcasted) { downcasted = int24(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(24, value); } } /** * @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 */ function toInt16(int256 value) internal pure returns (int16 downcasted) { downcasted = int16(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(16, value); } } /** * @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 */ function toInt8(int256 value) internal pure returns (int8 downcasted) { downcasted = int8(value); if (downcasted != value) { revert SafeCastOverflowedIntDowncast(8, value); } } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive if (value > uint256(type(int256).max)) { revert SafeCastOverflowedUintToInt(value); } return int256(value); } }
{ "optimizer": { "enabled": true, "runs": 5500 }, "viaIR": true, "evmVersion": "paris", "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract IMaverickV2Factory","name":"_factory","type":"address"},{"internalType":"contract IWETH9","name":"_weth","type":"address"},{"internalType":"contract IMaverickV2Position","name":"_position","type":"address"},{"internalType":"contract IMaverickV2BoostedPositionFactory","name":"_boostedPositionFactory","type":"address"},{"internalType":"contract IMaverickV2RewardFactory","name":"_rewardFactory","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"BytesLibSliceOutOfBounds","type":"error"},{"inputs":[],"name":"BytesLibSliceOverflow","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"LiquidityManagerNotFactoryPool","type":"error"},{"inputs":[],"name":"LiquidityManagerNotTokenIdOwner","type":"error"},{"inputs":[],"name":"MathOverflowedMulDiv","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"uint256","name":"contractBalance","type":"uint256"}],"name":"PaymentInsufficientBalance","type":"error"},{"inputs":[],"name":"PaymentSenderNotWETH9","type":"error"},{"inputs":[{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint256","name":"blockTimestamp","type":"uint256"}],"name":"PositionDeadlinePassed","type":"error"},{"inputs":[{"internalType":"uint256","name":"sqrtPrice","type":"uint256"},{"internalType":"uint256","name":"minSqrtPrice","type":"uint256"},{"internalType":"uint256","name":"maxSqrtPrice","type":"uint256"}],"name":"PositionExceededPriceBounds","type":"error"},{"inputs":[],"name":"RouterNotFactoryPool","type":"error"},{"inputs":[{"internalType":"uint256","name":"amountOutMinimum","type":"uint256"},{"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"RouterTooLittleReceived","type":"error"},{"inputs":[{"internalType":"uint256","name":"amountInMaximum","type":"uint256"},{"internalType":"uint256","name":"amountIn","type":"uint256"}],"name":"RouterTooMuchRequested","type":"error"},{"inputs":[],"name":"RouterZeroSwap","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"int256","name":"tick","type":"int256"}],"name":"TickMaxExceeded","type":"error"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TransferFailed","type":"error"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TransferFromFailed","type":"error"},{"inputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"subaccount","type":"uint256"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"name":"addLiquidityAndMintBoostedPosition","outputs":[{"internalType":"uint256","name":"mintedLpAmount","type":"uint256"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"},{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"}],"name":"addLiquidityAndMintBoostedPositionAndStake","outputs":[{"internalType":"uint256","name":"mintedLpAmount","type":"uint256"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint256","name":"stakeAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"sendersTokenIndex","type":"uint256"},{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"},{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"}],"name":"addLiquidityAndMintBoostedPositionAndStakeToSender","outputs":[{"internalType":"uint256","name":"mintedLpAmount","type":"uint256"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"name":"addLiquidityAndMintBoostedPositionToSender","outputs":[{"internalType":"uint256","name":"mintedLpAmount","type":"uint256"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"name":"addPositionLiquidityToRecipientByTokenIndex","outputs":[{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"name":"addPositionLiquidityToSenderByTokenIndex","outputs":[{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"boostedPositionFactory","outputs":[{"internalType":"contract IMaverickV2BoostedPositionFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"checkDeadline","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"uint256","name":"minSqrtPrice","type":"uint256"},{"internalType":"uint256","name":"maxSqrtPrice","type":"uint256"}],"name":"checkSqrtPrice","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"components":[{"components":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"},{"internalType":"uint128[]","name":"ratios","type":"uint128[]"},{"internalType":"uint8","name":"kind","type":"uint8"}],"internalType":"struct IMaverickV2PoolLens.BoostedPositionSpecification","name":"bpSpec","type":"tuple"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"internalType":"struct IMaverickV2PoolLens.CreateBoostedPositionInputs","name":"params","type":"tuple"}],"name":"createBoostedPositionAndAddLiquidity","outputs":[{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"uint256","name":"mintedLpAmount","type":"uint256"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"components":[{"components":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"},{"internalType":"uint128[]","name":"ratios","type":"uint128[]"},{"internalType":"uint8","name":"kind","type":"uint8"}],"internalType":"struct IMaverickV2PoolLens.BoostedPositionSpecification","name":"bpSpec","type":"tuple"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"internalType":"struct IMaverickV2PoolLens.CreateBoostedPositionInputs","name":"params","type":"tuple"},{"internalType":"contract IERC20[]","name":"rewardTokens","type":"address[]"},{"internalType":"contract IMaverickV2VotingEscrow[]","name":"veTokens","type":"address[]"}],"name":"createBoostedPositionAndAddLiquidityAndStake","outputs":[{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"uint256","name":"mintedLpAmount","type":"uint256"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"},{"internalType":"uint128[]","name":"ratios","type":"uint128[]"},{"internalType":"uint8","name":"kind","type":"uint8"}],"internalType":"struct IMaverickV2PoolLens.BoostedPositionSpecification","name":"bpSpec","type":"tuple"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"internalType":"struct IMaverickV2PoolLens.CreateBoostedPositionInputs","name":"params","type":"tuple"},{"internalType":"contract IERC20[]","name":"rewardTokens","type":"address[]"},{"internalType":"contract IMaverickV2VotingEscrow[]","name":"veTokens","type":"address[]"}],"name":"createBoostedPositionAndAddLiquidityAndStakeToSender","outputs":[{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"uint256","name":"mintedLpAmount","type":"uint256"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"},{"internalType":"uint128[]","name":"ratios","type":"uint128[]"},{"internalType":"uint8","name":"kind","type":"uint8"}],"internalType":"struct IMaverickV2PoolLens.BoostedPositionSpecification","name":"bpSpec","type":"tuple"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"internalType":"struct IMaverickV2PoolLens.CreateBoostedPositionInputs","name":"params","type":"tuple"}],"name":"createBoostedPositionAndAddLiquidityToSender","outputs":[{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"uint256","name":"mintedLpAmount","type":"uint256"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint64","name":"fee","type":"uint64"},{"internalType":"uint16","name":"tickSpacing","type":"uint16"},{"internalType":"uint32","name":"lookback","type":"uint32"},{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"},{"internalType":"int32","name":"activeTick","type":"int32"},{"internalType":"uint8","name":"kinds","type":"uint8"}],"name":"createPool","outputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint64","name":"feeAIn","type":"uint64"},{"internalType":"uint64","name":"feeBIn","type":"uint64"},{"internalType":"uint16","name":"tickSpacing","type":"uint16"},{"internalType":"uint32","name":"lookback","type":"uint32"},{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"},{"internalType":"int32","name":"activeTick","type":"int32"},{"internalType":"uint8","name":"kinds","type":"uint8"}],"name":"createPool","outputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"components":[{"internalType":"uint64","name":"feeAIn","type":"uint64"},{"internalType":"uint64","name":"feeBIn","type":"uint64"},{"internalType":"uint16","name":"tickSpacing","type":"uint16"},{"internalType":"uint32","name":"lookback","type":"uint32"},{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"},{"internalType":"int32","name":"activeTick","type":"int32"},{"internalType":"uint8","name":"kinds","type":"uint8"},{"components":[{"internalType":"uint8","name":"kind","type":"uint8"},{"internalType":"int32[]","name":"ticks","type":"int32[]"},{"internalType":"uint128[]","name":"amounts","type":"uint128[]"}],"internalType":"struct IMaverickV2Pool.AddLiquidityParams","name":"donateParams","type":"tuple"},{"internalType":"uint256","name":"swapAmount","type":"uint256"},{"components":[{"internalType":"uint8","name":"kind","type":"uint8"},{"internalType":"int32[]","name":"ticks","type":"int32[]"},{"internalType":"uint128[]","name":"amounts","type":"uint128[]"}],"internalType":"struct IMaverickV2Pool.AddLiquidityParams","name":"addParams","type":"tuple"},{"internalType":"bytes[]","name":"packedAddParams","type":"bytes[]"},{"internalType":"uint256","name":"deltaAOut","type":"uint256"},{"internalType":"uint256","name":"deltaBOut","type":"uint256"},{"internalType":"uint256","name":"preAddReserveA","type":"uint256"},{"internalType":"uint256","name":"preAddReserveB","type":"uint256"}],"internalType":"struct IMaverickV2PoolLens.CreateAndAddParamsInputs","name":"params","type":"tuple"}],"name":"createPoolAtPriceAndAddLiquidity","outputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint64","name":"feeAIn","type":"uint64"},{"internalType":"uint64","name":"feeBIn","type":"uint64"},{"internalType":"uint16","name":"tickSpacing","type":"uint16"},{"internalType":"uint32","name":"lookback","type":"uint32"},{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"},{"internalType":"int32","name":"activeTick","type":"int32"},{"internalType":"uint8","name":"kinds","type":"uint8"},{"components":[{"internalType":"uint8","name":"kind","type":"uint8"},{"internalType":"int32[]","name":"ticks","type":"int32[]"},{"internalType":"uint128[]","name":"amounts","type":"uint128[]"}],"internalType":"struct IMaverickV2Pool.AddLiquidityParams","name":"donateParams","type":"tuple"},{"internalType":"uint256","name":"swapAmount","type":"uint256"},{"components":[{"internalType":"uint8","name":"kind","type":"uint8"},{"internalType":"int32[]","name":"ticks","type":"int32[]"},{"internalType":"uint128[]","name":"amounts","type":"uint128[]"}],"internalType":"struct IMaverickV2Pool.AddLiquidityParams","name":"addParams","type":"tuple"},{"internalType":"bytes[]","name":"packedAddParams","type":"bytes[]"},{"internalType":"uint256","name":"deltaAOut","type":"uint256"},{"internalType":"uint256","name":"deltaBOut","type":"uint256"},{"internalType":"uint256","name":"preAddReserveA","type":"uint256"},{"internalType":"uint256","name":"preAddReserveB","type":"uint256"}],"internalType":"struct IMaverickV2PoolLens.CreateAndAddParamsInputs","name":"params","type":"tuple"}],"name":"createPoolAtPriceAndAddLiquidityToSender","outputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"components":[{"internalType":"uint8","name":"kind","type":"uint8"},{"internalType":"int32[]","name":"ticks","type":"int32[]"},{"internalType":"uint128[]","name":"amounts","type":"uint128[]"}],"internalType":"struct IMaverickV2Pool.AddLiquidityParams","name":"args","type":"tuple"}],"name":"donateLiquidity","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"bool","name":"tokenAIn","type":"bool"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"int32","name":"tickLimit","type":"int32"}],"name":"exactOutputSingleMinimal","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOut_","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract IMaverickV2Factory","name":"factory_","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"},{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"maverickV2AddLiquidityCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountToPay","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"maverickV2SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"},{"internalType":"uint32","name":"maxRecursion","type":"uint32"}],"name":"migrateBinsUpStack","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"}],"name":"migrateBoostedPosition","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"address","name":"recipient","type":"address"}],"name":"mintBoostedPosition","outputs":[{"internalType":"uint256","name":"mintedLpAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"name":"mintPositionNft","outputs":[{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Pool","name":"pool","type":"address"},{"internalType":"bytes","name":"packedSqrtPriceBreaks","type":"bytes"},{"internalType":"bytes[]","name":"packedArgs","type":"bytes[]"}],"name":"mintPositionNftToSender","outputs":[{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"},{"internalType":"uint32[]","name":"binIds","type":"uint32[]"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"},{"internalType":"address","name":"recipient","type":"address"}],"name":"mintTokenInReward","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"}],"name":"mintTokenInRewardToSender","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"},{"internalType":"contract IERC20","name":"rewardToken","type":"address"},{"internalType":"uint256","name":"duration","type":"uint256"}],"name":"notifyRewardAmount","outputs":[{"internalType":"uint256","name":"_duration","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint8","name":"kind","type":"uint8"},{"internalType":"int32[]","name":"ticks","type":"int32[]"},{"internalType":"uint128[]","name":"amounts","type":"uint128[]"}],"internalType":"struct IMaverickV2Pool.AddLiquidityParams","name":"args","type":"tuple"}],"name":"packAddLiquidityArgs","outputs":[{"internalType":"bytes","name":"argsPacked","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint8","name":"kind","type":"uint8"},{"internalType":"int32[]","name":"ticks","type":"int32[]"},{"internalType":"uint128[]","name":"amounts","type":"uint128[]"}],"internalType":"struct IMaverickV2Pool.AddLiquidityParams[]","name":"args","type":"tuple[]"}],"name":"packAddLiquidityArgsArray","outputs":[{"internalType":"bytes[]","name":"argsPacked","type":"bytes[]"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint88[]","name":"fullArray","type":"uint88[]"}],"name":"packUint88Array","outputs":[{"internalType":"bytes","name":"packedArray","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"position","outputs":[{"internalType":"contract IMaverickV2Position","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"refundETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"rewardFactory","outputs":[{"internalType":"contract IMaverickV2RewardFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2BoostedPosition","name":"boostedPosition","type":"address"},{"internalType":"address","name":"recipient","type":"address"}],"name":"skimBoostedPosition","outputs":[{"internalType":"uint256","name":"tokenAAmount","type":"uint256"},{"internalType":"uint256","name":"tokenBAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"stake","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"stakedTokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"sweepToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"sweepTokenAmount","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2VotingEscrowWSync","name":"ve","type":"address"},{"internalType":"address","name":"staker","type":"address"},{"internalType":"uint256[]","name":"legacyLockupIndexes","type":"uint256[]"}],"name":"sync","outputs":[{"internalType":"uint256[]","name":"newBalance","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"},{"internalType":"contract IERC20","name":"rewardToken","type":"address"},{"internalType":"uint256","name":"duration","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferAndNotifyRewardAmount","outputs":[{"internalType":"uint256","name":"_duration","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IMaverickV2Reward","name":"reward","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"transferAndStake","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"stakedTokenId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"argsPacked","type":"bytes"}],"name":"unpackAddLiquidityArgs","outputs":[{"components":[{"internalType":"uint8","name":"kind","type":"uint8"},{"internalType":"int32[]","name":"ticks","type":"int32[]"},{"internalType":"uint128[]","name":"amounts","type":"uint128[]"}],"internalType":"struct IMaverickV2Pool.AddLiquidityParams","name":"args","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"packedArray","type":"bytes"}],"name":"unpackUint88Array","outputs":[{"internalType":"uint88[]","name":"fullArray","type":"uint88[]"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"tokenA","type":"address"},{"internalType":"contract IERC20","name":"tokenB","type":"address"},{"internalType":"uint256","name":"tokenAAmountMin","type":"uint256"},{"internalType":"uint256","name":"tokenBAmountMin","type":"uint256"}],"name":"unwrapAndSweep","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"unwrapWETH9","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"contract IWETH9","name":"weth_","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
6101203461013a57601f6157b238819003918201601f19168301916001600160401b0383118484101761013f5780849260a09460405283398101031261013a5780516001600160a01b039190828116810361013a576020820151838116810361013a57604083015191848316830361013a57606084015193858516850361013a5760800151948516850361013a5760a05260805260c05260e05261010090815260405161565c918261015683396080518281816026015281816115b7015281816117d701528181612beb0152614591015260a051828181610a9a01528181610d9b015281816114bb01528181611b260152613b15015260c0518281816102c10152818161140601528181611c7301528181613a150152613c5f015260e051828181611c1b01526141f4015251818181611a790152613e4b0152f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe60406080815260049081361015610074575b361561001c57600080fd5b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016330361004e57005b517fc0f54629000000000000000000000000000000000000000000000000000000008152fd5b6000803560e01c80627b077214611eb657806302e705b114611dc557806303bffc5a14611c9757806309218e9114611c5357806312210e8a14611c3f578063176305b514611bfb5780631f2c610114611a9d578063245e4bf014611a595780632dbed792146118805780633052faef146118215780633ec5cded146117fb5780633fc8cef3146117b757806349404b7c146117975780634f2ca8301461170557806350389fb41461167b578063510dc46314610ffb5780635959ccfa14611642578063670ca1811461158757806367ca7c911461143e5780636f7cb4d51461137a5780637817eafb1461132a5780638c014fcb1461112957806395b2a33f146110e557806397e348c514611095578063a36519711461107c578063a69909461461102b578063ac559dee14610ffb578063ac9650d814610ee9578063adc9772e14610ebc578063b06c332114610e16578063b7bd452e14610c99578063b800a20614610b3d578063b9e4530014610abe578063c45a015514610a7a578063c470b79014610a13578063caca688d14610999578063d18214581461092c578063d47607c514610853578063dbba58e514610816578063def0e39f14610766578063df2ab5bb14610753578063e05a807b1461066a578063e34143c8146105f5578063e4d43a4114610530578063ef8d81f6146104b0578063f16d790414610499578063f1bd8bc814610423578063fb2b2063146103d9578063fd388b97146103a95763fd3dfa83146102a55750610011565b6020906102b136612947565b9793926001600160a01b039691967f0000000000000000000000000000000000000000000000000000000000000000169461032c895194859384937f2f745c590000000000000000000000000000000000000000000000000000000085528401602090939291936001600160a01b0360408201951681520152565b0381865afa93841561039e578094610362575b61035e876103508a89898989613478565b90939192519384938461267d565b0390f35b909193506020823d602011610396575b8161037f602093836120e7565b81010312610393575051918161035e61033f565b80fd5b3d9150610372565b8651903d90823e3d90fd5b6080836103c16103b836612733565b939290926142ed565b92939091815194855260208501528301526060820152f35b5060206003193601126103935782359067ffffffffffffffff8211610393575061040c61035e93610412923691016127cc565b336130fc565b929593949190915195869586612915565b5091816003193601126104955761043861234b565b926024359067ffffffffffffffff82116103935750926104616104679261035e953691016125ad565b90614155565b919492935194859485909493926060926001600160a01b036080840197168352602083015260408201520152565b8280fd5b506104ad6104a636612a89565b9091614da8565b80f35b50809183602060031936011261052c576001600160a01b036104d061234b565b16803b156105275783918351809581937f84302a6b0000000000000000000000000000000000000000000000000000000083525af190811561051e5750610515575080f35b6104ad9061209b565b513d84823e3d90fd5b505050fd5b5050fd5b5060806003193601126103935761054561234b565b9267ffffffffffffffff906024358281116105f15761056790369083016125ad565b916044358181116105ed5761057f90369084016129b1565b936064359182116103935750916105a16105a7949261035e9794369101612a19565b92613d9c565b96516001600160a01b039687168152602081019590955260408501939093526060840191909152608083015290911660a082015260c081019190915290819060e0820190565b8480fd5b8380fd5b5060806003193601126103935761060a61234b565b92610613612375565b9067ffffffffffffffff6044358181116105ed576106349036908401612422565b9360643591821161039357509161065661065c949261035e9794369101612440565b92613c4f565b9194929351948594856124fa565b509160606003193601126104955761068061234b565b918360249260243567ffffffffffffffff8111610495576106a79095919536908701612545565b946106b0612521565b63ffffffff908116926001600160a01b03169190845b885181101561074f57816106da828b612b1b565b5116843b1561074b578751907f8e5430a7000000000000000000000000000000000000000000000000000000008252848201528589820152868160448183895af18015610741579060019291610732575b50016106c6565b61073b9061209b565b3861072b565b88513d89823e3d90fd5b8680fd5b8580f35b506104ad61076036612a89565b91613b62565b50906101006003193601126108125761077d6127a0565b6024359067ffffffffffffffff821682036105f15760443561ffff811681036105ed5760643563ffffffff8116810361080e576107b861238b565b9060a435926001600160a01b0395868516850361080a5760c435958660030b87036108065760e4359960ff8b168b036103935750916020999593916107fe979593613a7c565b915191168152f35b8980fd5b8880fd5b8580fd5b5080fd5b5091906003193601126108125761082b61234b565b60243567ffffffffffffffff81116105f1576104ad9261084d91369101612204565b906139bb565b50919060606003193601126104955760206108cd9261087061234b565b610878612375565b866001600160a01b0386518098819682957fb66503cf000000000000000000000000000000000000000000000000000000008452604435918401602090939291936001600160a01b0360408201951681520152565b0393165af19182156109225783926108ea575b6020838351908152f35b9091506020813d60201161091a575b81610906602093836120e7565b8101031261049557602092505190386108e0565b3d91506108f9565b81513d85823e3d90fd5b5060606003193601126103935767ffffffffffffffff9280358481116104955761095990369083016125ad565b936024358181116105f15761097190369084016129b1565b9260443591821161039357509161099261035e95926105a794369101612a19565b9133613d9c565b506060600319360112610393576109ae61234b565b9267ffffffffffffffff6024358181116105f1576109cf9036908401612422565b926044359182116103935750916109f061035e95926109f794369101612440565b91336137b5565b9251918252602082015260408101919091529081906060820190565b50608060031936011261039357610a2861234b565b92610a31612375565b9067ffffffffffffffff6044358181116105ed57610a529036908401612422565b93606435918211610393575091610a746109f7949261035e9794369101612440565b926137b5565b509034610812578160031936011261081257602090516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b5091606060031936011261049557610ad461234b565b602435610ae360443592614a14565b938185108015610b34575b610af6578580f35b517ffcb505c7000000000000000000000000000000000000000000000000000000008152928301938452602084015260408301529081906060010390fd5b50828511610aee565b508260a060031936011261081257610b5361234b565b90610b5c612375565b604435928315158094036105ed57608435908160030b80920361080e57908587949392855196610b8b88612069565b606435885260208801908152610c3a878901916001835260608a019586526001600160a01b0395869485811615600014610c93575030935b8a519233602085015260208452610bd9846120cb565b8b519c8d9b8c9a8b987f3eece7db000000000000000000000000000000000000000000000000000000008a521690880152516024870152511515604486015251151560648501525160030b608484015260c060a484015260c4830190612145565b0393165af1908115610c89578291610c5a575b5082519182526020820152f35b9050610c7c9150823d8411610c82575b610c7481836120e7565b810190612b45565b83610c4d565b503d610c6a565b83513d84823e3d90fd5b93610bc3565b509160e060031936011261049557610caf6127a0565b916024359161ffff831683036105ed57610cc7612521565b606435916001600160a01b03948584168403610e1257610ce561238b565b60a4358060030b81036108065760c4359160ff83168303610e0e576020968a96610d95958a519c8d998a997ff4b52483000000000000000000000000000000000000000000000000000000008b528a01969260ff959299989461ffff63ffffffff9260e099946101008c019d67ffffffffffffffff8092168d521660208c01521660408a01521660608801526001600160a01b0380921660808801521660a086015260030b60c085015216910152565b038187867f0000000000000000000000000000000000000000000000000000000000000000165af1928315610e045760209493610dd5575b505191168152f35b610df6919350843d8611610dfd575b610dee81836120e7565b810190612abd565b9138610dcd565b503d610de4565b81513d86823e3d90fd5b8a80fd5b8780fd5b5091906080600319360112610495576020610ea192610e3361234b565b6001600160a01b03610e43612375565b911690610e546064358333846143d8565b8685518097819582947fb66503cf000000000000000000000000000000000000000000000000000000008452604435918401602090939291936001600160a01b0360408201951681520152565b03925af19182156109225783926108ea576020838351908152f35b50816003193601126103935750610edd610ed461234b565b60243590613562565b82519182526020820152f35b50919060209160206003193601126105f15780359267ffffffffffffffff9182851161080e573660238601121561080e578401359180831161080e5760246005933660248260051b89010111610e125793610f4385613519565b9688917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbd82360301925b878110610f815788518061035e8c826122c9565b8481831b8401013584811215610ff7578301908582013591878311610ff357604401918c81360384136103935780610fc0600195610fd79436916123eb565b8b81519101305af4610fd06144cb565b9030614ea1565b610fe1828d612b1b565b52610fec818c612b1b565b5001610f6d565b8c80fd5b8b80fd5b5090806003193601126108125760209061102461101661234b565b61101e612375565b90612d51565b9051908152f35b509190602060031936011261049557813590814211611048578380f35b6044935051917f3442e977000000000000000000000000000000000000000000000000000000008352820152426024820152fd5b61035e8361035061108c36612947565b93929092613478565b50346103935760206003193601126103935782359067ffffffffffffffff821161039357506110cd61035e936110d292369101612204565b6147d6565b9051918291602083526020830190612145565b509181600319360112610495576110fa61234b565b926024359067ffffffffffffffff82116103935750926111236104129261035e953691016127cc565b906130fc565b50829061113536612733565b969385919395506001600160a01b0388168551977f48fd65fe0000000000000000000000000000000000000000000000000000000089526020988981806111958733878401602090939291936001600160a01b0360408201951681520152565b0381865afa90811561132057918a939186959386916112e1575b50156112735788517f2f745c5900000000000000000000000000000000000000000000000000000000815233918101918252602082019390935291935083918290819060400103915afa918215611268578092611236575b50509160a0969161121a93955b866142ed565b9391909295825196875286015284015260608301526080820152f35b9091508682813d8311611261575b61124e81836120e7565b810103126103935750518161121a611207565b503d611244565b8551903d90823e3d90fd5b6024919250885194859384926335313c2160e11b845233908401525af19182156112685780926112af575b50509160a0969161121a9395611214565b9091508682813d83116112da575b6112c781836120e7565b810103126103935750518161121a61129e565b503d6112bd565b929480929496508391503d8311611319575b6112fd81836120e7565b810103126105ed57918493916113138b94612aef565b8d6111af565b503d6112f3565b88513d87823e3d90fd5b50346103935760206003193601126103935782359067ffffffffffffffff8211610393575061136261035e9361136792369101612422565b612ddf565b9051918291602083526020830190612699565b509160806003193601126104955761139061234b565b9267ffffffffffffffff91604435838111610495576113b29036908301612422565b92606435908111610495576113ca9036908301612440565b84517f2f745c590000000000000000000000000000000000000000000000000000000081523392810192835260243560208481019190915291967f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316939092908290819060400161032c565b5091346104955760806003193601126104955761145961234b565b916024359160643567ffffffffffffffff811161080e5761147d90369083016123a1565b90916001600160a01b039380517f578eaca40000000000000000000000000000000000000000000000000000000081523383820152602081602481897f0000000000000000000000000000000000000000000000000000000000000000165afa90811561157d578991611543575b501561151d5750509061150091810190612afc565b16918161150b578380f35b61151692339161457e565b3880808380f35b517f36294ff5000000000000000000000000000000000000000000000000000000008152fd5b90506020813d602011611575575b8161155e602093836120e7565b8101031261080a5761156f90612aef565b386114eb565b3d9150611551565b82513d8b823e3d90fd5b5060806003193601126103935761159c61234b565b6115a4612375565b90604435606435916001600160a01b03807f00000000000000000000000000000000000000000000000000000000000000001690818184161460001461160657505050906115f76104ad93923390612be0565b6115ff612adc565b3391613b62565b8592951614600014611631575061162992611622913391613b62565b3390612be0565b6104ad612adc565b91906104ad936115ff913391613b62565b5060206003193601126103935782359067ffffffffffffffff8211610393575061167561035e93610467923691016125ad565b33614155565b5091903461049557602091826003193601126105f157803567ffffffffffffffff81116105ed576116b96116b485938793369101612422565b614e48565b9083519383808695860192818752855180945286019401925b8281106116e157505050500390f35b83516affffffffffffffffffffff16855286955093810193928101926001016116d2565b5090602092836003193601126104955783839160246001600160a01b0361172a61234b565b1691855194859384926335313c2160e11b845233908401525af192831561178c57809361175a575b505051908152f35b909192508382813d8311611785575b61177381836120e7565b81010312610393575051903880611752565b503d611769565b8251903d90823e3d90fd5b509190600319360112610812576104ad906117b0612375565b9035612be0565b509034610812578160031936011261081257602090516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b50816003193601126103935750610edd61181361234b565b61181b612375565b90612b5b565b5060606003193601126103935761183661234b565b9267ffffffffffffffff6024358181116105f1576118579036908401612422565b9260443591821161039357509161187861035e959261065c94369101612440565b913390613c4f565b508290346103935760606003193601126103935781356001600160a01b038116809103610812576118af612375565b916044359167ffffffffffffffff831161081257366023840112156108125782850135926118dc8461210a565b906118e9885192836120e7565b84825260209460248684019160051b8301019136831161080e57959897969495602401905b828210611a4a5750505051906119238261210a565b92611930875194856120e7565b82845261193c8361210a565b95601f198986019701368837855b84811061199157505050505083519485948186019282875251809352850193925b82811061197a57505050500390f35b83518552869550938101939281019260010161196b565b88999695979851907fef4fcafa0000000000000000000000000000000000000000000000000000000082528782806119e28488888401602090939291936001600160a01b0360408201951681520152565b03818a895af18015611a40578790611a10575b60019250611a03828b612b1b565b520198979694959861194a565b50908781813d8311611a39575b611a2781836120e7565b8101031261074b5790600191516119f5565b503d611a1d565b8b513d89823e3d90fd5b8135815290890190890161190e565b509034610812578160031936011261081257602090516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b5091346104955760a060031936011261049557611ab861234b565b611ac0612375565b90604435936064359360843567ffffffffffffffff8111610e1257611ae890369083016123a1565b90916001600160a01b039380517f578eaca40000000000000000000000000000000000000000000000000000000081523383820152602081602481897f0000000000000000000000000000000000000000000000000000000000000000165afa908115611bf1578b91611bb7575b5015611b9157505090611b6b91810190612afc565b169380611b7e575b50508161150b578380f35b611b8a9185339161457e565b3880611b73565b517f8a9dab50000000000000000000000000000000000000000000000000000000008152fd5b90506020813d602011611be9575b81611bd2602093836120e7565b81010312610e0e57611be390612aef565b38611b56565b3d9150611bc5565b82513d8d823e3d90fd5b509034610812578160031936011261081257602090516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b5080600319360112610393576104ad612adc565b509034610812578160031936011261081257602090516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168152f35b5091606060031936011261049557611cad61234b565b6001600160a01b03918282168451937f72f702f300000000000000000000000000000000000000000000000000000000855260209485818581865afa928315611dbb5786918994611d81575b508751948580927ffbfa77cf0000000000000000000000000000000000000000000000000000000082525afa928315611d775791611d4c949391610ed4938993611d58575b5060443592169033906143d8565b90918351928352820152f35b611d70919350873d8911610dfd57610dee81836120e7565b9188611d3e565b86513d89823e3d90fd5b8281939295503d8311611db4575b611d9981836120e7565b81010312610e1257518181168103610e125785909238611cf9565b503d611d8f565b87513d8a823e3d90fd5b508234610812576020806003193601126104955781359167ffffffffffffffff908184116105ed57366023850112156105ed57830135602493611e078261210a565b94611e14885196876120e7565b8286526024602087019360051b83010193368511610e125760248301935b858510611e9057898989611e468151613519565b915b8151811015611e835780611e67611e6160019385612b1b565b516147d6565b611e718286612b1b565b52611e7c8185612b1b565b5001611e48565b83518061035e85826122c9565b8435828111610806578791611eab8392863691890101612204565b815201940193611e32565b50903461081257602091826003193601126103935783359367ffffffffffffffff85116108125736602386011215610812578481013594611ef68661210a565b90611f03855192836120e7565b8682528582016024819860051b8301019136831161080e57602401905b82821061204657505050519460ff86116120105760ff861691600b93600b840297848904600b1485151715611ffd5760019260018a01809a11611fea57507fff00000000000000000000000000000000000000000000000000000000000000611fa0611f8b8b6123cf565b9a611f988a519c8d6120e7565b808c526123cf565b91601f198a8c01930136843760f81b169052918660218901935b858110611fd35787518281528061035e8185018d612145565b825160a81b85529386019391019087908301611fba565b826011602492634e487b7160e01b835252fd5b506011602492634e487b7160e01b835252fd5b6044828760088751927f6dfcc6500000000000000000000000000000000000000000000000000000000084528301526024820152fd5b81356affffffffffffffffffffff8116810361074b578152908701908701611f20565b6080810190811067ffffffffffffffff82111761208557604052565b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff811161208557604052565b6060810190811067ffffffffffffffff82111761208557604052565b6040810190811067ffffffffffffffff82111761208557604052565b90601f601f19910116810190811067ffffffffffffffff82111761208557604052565b67ffffffffffffffff81116120855760051b60200190565b60005b8381106121355750506000910152565b8181015183820152602001612125565b90601f19601f60209361216381518092818752878088019101612122565b0116010190565b359060ff8216820361217857565b600080fd5b35908160030b820361217857565b9080601f830112156121785760209082356121a58161210a565b936121b360405195866120e7565b81855260208086019260051b82010192831161217857602001905b8282106121dc575050505090565b81356fffffffffffffffffffffffffffffffff811681036121785781529083019083016121ce565b9190606083820312612178576040519061221d826120af565b81936122288161216a565b835267ffffffffffffffff916020828101358481116121785783019082601f830112156121785781359161225b8361210a565b9261226960405194856120e7565b808452828085019160051b830101918583116121785783809101915b8383106122b157505050508501526040820135928311612178576040926122ac920161218b565b910152565b81906122bc8461217d565b8152019101908390612285565b6020808201906020835283518092526040830192602060408460051b8301019501936000915b8483106122ff5750505050505090565b909192939495848061233b837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc086600196030187528a51612145565b98019301930191949392906122ef565b600435906001600160a01b038216820361217857565b35906001600160a01b038216820361217857565b602435906001600160a01b038216820361217857565b608435906001600160a01b038216820361217857565b9181601f840112156121785782359167ffffffffffffffff8311612178576020838186019501011161217857565b67ffffffffffffffff811161208557601f01601f191660200190565b9291926123f7826123cf565b9161240560405193846120e7565b829481845281830111612178578281602093846000960137010152565b9080601f830112156121785781602061243d933591016123eb565b90565b81601f820112156121785780359160209161245a8461210a565b9361246860405195866120e7565b808552838086019160051b8301019280841161217857848301915b8483106124935750505050505090565b823567ffffffffffffffff81116121785786916124b584848094890101612422565b815201920191612483565b90815180825260208080930193019160005b8281106124e0575050505090565b835163ffffffff16855293810193928101926001016124d2565b94939260609261251c92875260208701526080604087015260808601906124c0565b930152565b6044359063ffffffff8216820361217857565b359063ffffffff8216820361217857565b9080601f8301121561217857602090823561255f8161210a565b9361256d60405195866120e7565b81855260208086019260051b82010192831161217857602001905b828210612596575050505090565b8380916125a284612534565b815201910190612588565b9190916060818403126121785760408051916125c8836120af565b8294813567ffffffffffffffff90818111612178578301608081840312612178578451906125f582612069565b6125fe81612361565b825260208101358381116121785784612618918301612545565b602083015285810135838111612178578161263a86606093612644950161218b565b888501520161216a565b6060820152855260208301358181116121785782612663918501612422565b602086015283830135908111612178576122ac9201612440565b61243d93926060928252602082015281604082015201906124c0565b6060820160ff825116835260209182810151916060848601528251809152836080860193019060005b81811061271c575050506040015192604081830391015281808451928381520193019160005b8281106126f6575050505090565b83516fffffffffffffffffffffffffffffffff16855293810193928101926001016126e8565b825160030b855293850193918501916001016126c2565b9060a060031983011261217857600435916001600160a01b036024358181168103612178579267ffffffffffffffff604435818111612178578461277991600401612422565b936064359182116121785761279091600401612440565b9160843590811681036121785790565b6004359067ffffffffffffffff8216820361217857565b359067ffffffffffffffff8216820361217857565b919091610200908181850312612178576040519182019367ffffffffffffffff9483811086821117612085576040528294612806836127b7565b8452612814602084016127b7565b6020850152604083013561ffff8116810361217857604085015261283a60608401612534565b606085015261284b60808401612361565b608085015261285c60a08401612361565b60a085015261286d60c0840161217d565b60c085015261287e60e0840161216a565b60e085015261010080840135828111612178578361289d918601612204565b9085015261012080840135908501526101408084013582811161217857836128c6918601612204565b908501526101609182840135918211612178576128e4918401612440565b9083015261018080820135908301526101a080820135908301526101c080820135908301526101e080910135910152565b959493909261251c926001600160a01b036080951688526020880152604087015260a0606087015260a08601906124c0565b60a0600319820112612178576001600160a01b039160043583811681036121785792602435908116810361217857916044359167ffffffffffffffff606435818111612178578361299a91600401612422565b926084359182116121785761243d91600401612440565b9080601f830112156121785760209082356129cb8161210a565b936129d960405195866120e7565b81855260208086019260051b82010192831161217857602001905b828210612a02575050505090565b838091612a0e84612361565b8152019101906129f4565b9080601f83011215612178576020908235612a338161210a565b93612a4160405195866120e7565b81855260208086019260051b82010192831161217857602001905b828210612a6a575050505090565b81356001600160a01b0381168103612178578152908301908301612a5c565b6003196060910112612178576001600160a01b03600435818116810361217857916024359160443590811681036121785790565b9081602091031261217857516001600160a01b03811681036121785790565b47612ae357565b612aed47336144fb565b565b5190811515820361217857565b9081602091031261217857356001600160a01b03811681036121785790565b8051821015612b2f5760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b9190826040910312612178576020825192015190565b9060409060246001600160a01b0391600083855196879586947fbc25cf77000000000000000000000000000000000000000000000000000000008652166004850152165af18015612bd457600091600091612bb557509091565b9050612bd0915060403d604011610c8257610c7481836120e7565b9091565b6040513d6000823e3d90fd5b6001600160a01b03807f00000000000000000000000000000000000000000000000000000000000000001692604051927f70a08231000000000000000000000000000000000000000000000000000000008452306004850152602084602481885afa938415612bd457600094612d1d575b50808410612cd4575082612c66575b50505050565b833b1561217857600080946024604051809781937f2e1a7d4d0000000000000000000000000000000000000000000000000000000083528860048401525af1938415612bd457612cbc94612cc5575b50166144fb565b38808080612c60565b612cce9061209b565b38612cb5565b6040517fd1cd07af0000000000000000000000000000000000000000000000000000000081526001600160a01b0386166004820152602481019190915260448101849052606490fd5b90936020823d602011612d49575b81612d38602093836120e7565b810103126103935750519238612c51565b3d9150612d2b565b9060209060246001600160a01b039160008360405196879586946335313c2160e11b8652166004850152165af1908115612bd457600091612d90575090565b90506020813d602011612db7575b81612dab602093836120e7565b81010312612178575190565b3d9150612d9e565b60405190612dcc826120af565b6060604083600081528260208201520152565b612de7612dbf565b50612df0612dbf565b90805115612b2f576020908181015160f81c8352805160001992838201938285116130bc57601f19928386116130d257845195600196826001116130bc578211613092578061303f5750505060405192600084528184016040525b81840151928360f81c93611fe094604096858789519460f31c16840101885281835260009060218785019101915b878b858310613029575092505050829150890152518060021b600491808204831490151715613014576002810193848211612fd757805191808303937ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe9687860194851161301457868511612fec578351868401809211612fd75710612fb0575082612f625750505050505082516000815281810184525b8181015194828660f81c9486519760f31c16870101855283865260009160218488019101925b858110612f4a5750505050505082015290565b8483601092865160801c855201920193019290612f37565b60029089949392945196601f8416801560051b9182828b0101968701019601010101925b86818410612f9f575050601f9250845201168452612f11565b845184529384019390920191612f86565b89517f326b3d3a000000000000000000000000000000000000000000000000000000008152fd5b601183634e487b7160e01b6000525260246000fd5b5089517f648fb3b1000000000000000000000000000000000000000000000000000000008152fd5b601182634e487b7160e01b6000525260246000fd5b600492855160e01c855201920192019190612e79565b9491908490604051966001601f821694851560051b9081878c0101948501019587010101935b8681841061307e5750508752601f011660405250612e4b565b855184529485019488945090920191613065565b60046040517f326b3d3a000000000000000000000000000000000000000000000000000000008152fd5b634e487b7160e01b600052601160045260246000fd5b60046040517f648fb3b1000000000000000000000000000000000000000000000000000000008152fd5b909167ffffffffffffffff9182845116926020850151169361316060409561ffff87840151169563ffffffff606085015116966001600160a01b039788608087015116908960a0880151169260c08801519560ff60e08a0151169660030b95613a7c565b93610120820180516131bc575b50506101606131b69394955191613183836120cb565b600c83527f0100000000000000000000000000000000000000000000000000000000000000602084015201519185613c4f565b90919293565b86906131cd610100850151886139bb565b518151906131da82612069565b8152602081019260018452806000848401600181526132836060860191637fffffff8352848b161584146132cf5730925b88519133602084015260208352613221836120cb565b89519a8b998a9889977f3eece7db000000000000000000000000000000000000000000000000000000008952166004880152516024870152511515604486015251151560648501525160030b608484015260c060a484015260c4830190612145565b03928a165af180156132c45795610160916131b69596976132a8575b5095949361316d565b6132be90823d8411610c8257610c7481836120e7565b5061329f565b86513d6000823e3d90fd5b8a9261320b565b519063ffffffff8216820361217857565b9091606082840312612178578151926020808401519360408101519067ffffffffffffffff821161217857019180601f8401121561217857825161332a8161210a565b9361333860405195866120e7565b818552838086019260051b820101928311612178578301905b82821061335f575050505090565b83809161336b846132d6565b815201910190613351565b9261339a6133a091613394613416949561338f88614a14565b614d2c565b90612b1b565b51612ddf565b916001600160a01b0393849160405194336020870152602086526133c3866120cb565b60405196879485937f42e3d72c0000000000000000000000000000000000000000000000000000000085521660048401528261342860009889988995866024860152608060448601526084850190612699565b90600319848303016064850152612145565b0393165af1801561346b578192828092613444575b5050909192565b9150915061346492503d8091833e61345c81836120e7565b8101906132e7565b388061343d565b50604051903d90823e3d90fd5b90919361339a613492916133946134289661338f86614a14565b906001600160a01b039283926134ff60405191336020840152602083526134b8836120cb565b60405198899687957f42e3d72c0000000000000000000000000000000000000000000000000000000087521660048601526024850152608060448501526084840190612699565b946003198387030160648401528260009788978894612145565b906135238261210a565b61353060405191826120e7565b828152601f19613540829461210a565b019060005b82811061355157505050565b806060602080938501015201613545565b919080156135df575b6001600160a01b039260246040926000845196879485937fa694fc3a0000000000000000000000000000000000000000000000000000000085526004850152165af1918215612bd4576000906000936135c357509190565b9050612bd091925060403d604011610c8257610c7481836120e7565b506001600160a01b03821660409081517f48fd65fe0000000000000000000000000000000000000000000000000000000081523360048201526000908160248201526020908181604481875afa90811561378e578391613759575b50156136e457806044938551948580927f2f745c590000000000000000000000000000000000000000000000000000000082523360048301528660248301525afa9384156136d9575081936136a6575b5050506001600160a01b039260246040925b925050925061356b565b9091809350813d83116136d2575b6136be81836120e7565b81010312610393575051826024604061368a565b503d6136b4565b51913d9150823e3d90fd5b80829360248651809681936335313c2160e11b83523360048401525af19384156136d957508193613726575b5050506001600160a01b0392602460409261369c565b9091809350813d8311613752575b61373e81836120e7565b810103126103935750518260246040613710565b503d613734565b90508181813d8311613787575b61377081836120e7565b810103126104955761378190612aef565b3861363a565b503d613766565b85513d85823e3d90fd5b51906fffffffffffffffffffffffffffffffff8216820361217857565b919392906001600160a01b039081811691823b15612178576040938451977f84302a6b0000000000000000000000000000000000000000000000000000000089526000988981600481838a5af1801561393b576139a8575b508551937fbc0d199200000000000000000000000000000000000000000000000000000000855260209485816004818a5afa90811561399e579089918c91613955575b506fffffffffffffffffffffffffffffffff16613945575b505085517f16f0115b0000000000000000000000000000000000000000000000000000000081528481600481895afa90811561393b57928a9492876138ba93889660249c9d9e9161391e575b50613376565b5097909884885197889485936335313c2160e11b85521660048401525af19384156139145750926138ea57505092565b90809250813d831161390d575b61390181836120e7565b81010312612178575192565b503d6138f7565b51903d90823e3d90fd5b6139359150873d8911610dfd57610dee81836120e7565b386138b4565b87513d8c823e3d90fd5b61394e91612b5b565b5087613868565b809250878092503d8311613997575b61396e81836120e7565b81010312610e0e576fffffffffffffffffffffffffffffffff6139918a92613798565b90613850565b503d613964565b88513d8d823e3d90fd5b6139b49099919961209b565b973861380d565b613a5191600091613416836001600160a01b0360405194336020870152602086526139e5866120cb565b604051978896879586937f42e3d72c000000000000000000000000000000000000000000000000000000008552857f0000000000000000000000000000000000000000000000000000000000000000166004860152866024860152608060448601526084850190612699565b0393165af18015612bd457613a635750565b613a77903d806000833e61345c81836120e7565b505050565b6040517ff4b5248300000000000000000000000000000000000000000000000000000000815267ffffffffffffffff91821660048201529116602482015261ffff909116604482015263ffffffff90911660648201526001600160a01b039182166084820152911660a482015260039190910b60c482015260ff90911660e4820152602081806101048101038160006001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165af1908115612bd457600091613b49575090565b61243d915060203d602011610dfd57610dee81836120e7565b916001600160a01b03831691604051927f70a08231000000000000000000000000000000000000000000000000000000008452306004850152602084602481845afa938415612bd457600094613c1b575b50818410613bd057505081613bc757505050565b612aed92614da8565b6040517fd1cd07af0000000000000000000000000000000000000000000000000000000081526001600160a01b03919091166004820152602481019190915260448101839052606490fd5b90936020823d602011613c47575b81613c36602093836120e7565b810103126103935750519238613bb3565b3d9150613c29565b929390916001600160a01b0394857f000000000000000000000000000000000000000000000000000000000000000016604051917f75794a3c0000000000000000000000000000000000000000000000000000000083526020938484600481865afa8015612bd4578994600091613d5f575b5088928492613cd492889660009c613478565b9a91999098613d2a8c9a9b9c604051988997889687957f45d77f7e0000000000000000000000000000000000000000000000000000000087521660048601521660248401526060604484015260648301906124c0565b03925af1918215612bd457600092613d4157505090565b90809250813d8311613d58575b612dab81836120e7565b503d613d4e565b98929450909290508488813d8111613d95575b613d7c81836120e7565b8101031261217857965190968893909290916000613cc1565b503d613d72565b9190613da89030614155565b96929694919493909495876001600160a01b03936040928351957f9a4f3329000000000000000000000000000000000000000000000000000000008752600491816064890195169687848a0152606060248a01528051809652886084810192602097888094019060005b81811061413a5750505060031982850301604483015282808251958681520191019360005b81811061411f5750508192935003816000857f0000000000000000000000000000000000000000000000000000000000000000165af1968715614114576000976140da575b5080871693818651946335313c2160e11b8652168385015280846024816000895af19384156132c4576000946140ab575b5083968651907ffbfa77cf000000000000000000000000000000000000000000000000000000008252828286818a5afa9182156140a057600092614081575b508751917f70a0823100000000000000000000000000000000000000000000000000000000835230868401528383602481855afa92831561407657600093614043575b5090613f859460008594938b51978895869485937fa9059cbb000000000000000000000000000000000000000000000000000000008552168b8401602090939291936001600160a01b0360408201951681520152565b03925af180156132c457908694939291614007575b50506024906000845195869485937fa694fc3a0000000000000000000000000000000000000000000000000000000085528401525af1918215613ffd57600092613fe357505092565b613ff99250803d10610c8257610c7481836120e7565b5092565b513d6000823e3d90fd5b9080929450813d831161403c575b61401f81836120e7565b81010312612178578492614034602492612aef565b509038613f9a565b503d614015565b9250908383813d831161406f575b61405b81836120e7565b810103126121785791519190613f85613f2f565b503d614051565b89513d6000823e3d90fd5b614099919250833d8511610dfd57610dee81836120e7565b9038613eec565b88513d6000823e3d90fd5b9080945081813d83116140d3575b6140c381836120e7565b8101031261217857519238613ead565b503d6140b9565b8481819993993d831161410d575b6140f281836120e7565b81010312610812575190878216820361039357509538613e7c565b503d6140e8565b85513d6000823e3d90fd5b8551871683529484019489948d945090920191600101613e37565b825188168752958501958a958e955090920191600101613e12565b9190916001600160a01b0392805190848251169460209081808501519760409560ff606088830151920151166141c288519b8c947f3d33af7900000000000000000000000000000000000000000000000000000000865260048601526080602486015260848501906124c0565b60031984820301604485015284808451928381520193019060005b8181106142c25750505060648301528190038160007f000000000000000000000000000000000000000000000000000000000000000086165af19687156142b75760009761427d575b509080602494939261424a8982808751511691169586888683015192015192613376565b509690976000875196879485936335313c2160e11b85521660048401525af1928315613ffd57506000926138ea57505092565b8281819993993d83116142b0575b61429581836120e7565b81010312610812575190878216820361039357509581614226565b503d61428b565b84513d6000823e3d90fd5b82516fffffffffffffffffffffffffffffffff16855288968e965094850194909201916001016141dd565b93909294916001600160a01b038092169360409283517ffbfa77cf0000000000000000000000000000000000000000000000000000000081526020816004818a5afa90811561411457938593614354936024999a9b9360009788916143b9575b50166137b5565b97919796909798835194859384927fa694fc3a00000000000000000000000000000000000000000000000000000000845260048401525af1918215613ffd5760009261439f57505090565b6143b59250803d10610c8257610c7481836120e7565b5090565b6143d2915060203d602011610dfd57610dee81836120e7565b3861434d565b906040519360208501917f23b872dd0000000000000000000000000000000000000000000000000000000083526001600160a01b039485809216602488015216604486015260648501526064845260a084019084821067ffffffffffffffff831117612085576144619360009384936040521694519082865af161445a6144cb565b9083614ea1565b80519081151591826144a8575b50506144775750565b602490604051907f5274afe70000000000000000000000000000000000000000000000000000000082526004820152fd5b81925090602091810103126121785760206144c39101612aef565b15388061446e565b3d156144f6573d906144dc826123cf565b916144ea60405193846120e7565b82523d6000602084013e565b606090565b81471061454e5760008080936001600160a01b038294165af161451c6144cb565b501561452457565b60046040517f1425ea42000000000000000000000000000000000000000000000000000000008152fd5b60246040517fcd786059000000000000000000000000000000000000000000000000000000008152306004820152fd5b9392936001600160a01b039081811691807f000000000000000000000000000000000000000000000000000000000000000016938484148061478b575b156146c55750505050803b1561217857604051937fd0e30db0000000000000000000000000000000000000000000000000000000008552600091828660048185855af19586156146ba5761466095966146a8575b5082936020936040518097819582947fa9059cbb00000000000000000000000000000000000000000000000000000000845260048401602090939291936001600160a01b0360408201951681520152565b03925af1801561346b57614672575050565b6020823d6020116146a0575b8161468b602093836120e7565b81010312610393575061469d90612aef565b50565b3d915061467e565b926146b460209461209b565b9261460f565b6040513d85823e3d90fd5b9080929396979594508116903082146000146146e857505050612aed9350614da8565b606460009182602094959796604051927f23b872dd00000000000000000000000000000000000000000000000000000000845260048401528760248401528960448401525af1601f3d11600160005114163d15171615614749575050505050565b60849550604051947fa8dced90000000000000000000000000000000000000000000000000000000008652600486015260248501521660448301526064820152fd5b50874710156145bb565b6020612aed9193929360405194816147b68793518092868087019101612122565b82016147ca82518093868085019101612122565b010380855201836120e7565b9081519160409081519360207fff00000000000000000000000000000000000000000000000000000000000000809260f81b16818701526001956001815261481d816120cb565b818401519687519160ff83116149cf5760ff8316906103fc8460021b169160049a8184048c14821517156149ba57600184018094116149ba57929091899261487c614867846123cf565b93614874865195866120e7565b8085526123cf565b968989850191601f19809a0136843760f81b1690528c886000960160218501915b8a89858a106149a1575050505050506148b7929350614795565b9501519182519460ff861161496b5760ff861695610ff0818c1b1660109b8882046010148915171561495657600182018092116149565750806149086148ff614910936123cf565b9b519b8c6120e7565b808b526123cf565b898701930136843760f81b1690526021860191830160005b8581106149405750505050505061243d929350614795565b815160801b845292890192908401908201614928565b601190634e487b7160e01b6000525260246000fd5b60448a8760088b51927f6dfcc6500000000000000000000000000000000000000000000000000000000084528301526024820152fd5b835160e01b855298909801978e9750920191018e61489d565b60118c634e487b7160e01b6000525260246000fd5b6044838851907f6dfcc650000000000000000000000000000000000000000000000000000000008252600860048301526024820152fd5b51908160070b820361217857565b6001600160a01b031660409081517f1865c57d000000000000000000000000000000000000000000000000000000008152610120908181600481865afa9081156142b757600091614c31575b5060a09150015160030b8251917f3256cfa900000000000000000000000000000000000000000000000000000000835281600484015260e083602481845afa9283156142b757600093614b72575b5060206004918551928380927fd0c93a7c0000000000000000000000000000000000000000000000000000000082525afa938415613ffd5750600093614b3c575b50614b0e836001614b038461243d97614f0a565b930160030b90614f0a565b906fffffffffffffffffffffffffffffffff60208185511694015116614b36838383876152a7565b93615381565b92506020833d602011614b6a575b81614b57602093836120e7565b8101031261217857915191614b0e614aef565b3d9150614b4a565b60e09391933d60e011614c2a575b614b8a81836120e7565b81019160e08284031261039357855192614ba384612069565b614bac83613798565b8452602091614bbd60208501613798565b6020860152614bcd888501613798565b8886015281607f8501121561039357875193614be885612069565b849160e082019384116103935750606001905b828210614c1357505050506060820152916020614aae565b838091614c1f846132d6565b815201910190614bfb565b503d614b80565b8281813d8311614d25575b614c4681836120e7565b8101031261081257845192830183811067ffffffffffffffff821117614d11578552614c7181613798565b8352614c7f60208201613798565b6020840152614c8f858201614a06565b85840152614c9f60608201614a06565b6060840152608081015164ffffffffff8116810361049557608084015260a08101518060030b81036104955760a0840152614cdc60c08201612aef565b60c0840152614ced60e082016132d6565b60e0840152610100809101519160ff83168303610393575082015260a09038614a60565b602483634e487b7160e01b81526041600452fd5b503d614c3c565b8151600093928491600c14614d9f57614d4790949194614e48565b905b81516000198101908111614d8b57811015614d85576affffffffffffffffffffff614d748284612b1b565b5116831115614d8557600101614d49565b93505050565b602486634e487b7160e01b81526011600452fd5b50600093505050565b9190916020600060446040517fa9059cbb00000000000000000000000000000000000000000000000000000000815286600482015285602482015282855af1601f3d11600160005114163d15171615614e0057505050565b60649350604051927fbf182be80000000000000000000000000000000000000000000000000000000084526001600160a01b0380921660048501521660248301526044820152fd5b906020916020810151928360f81c916020611fe06040519660f31c168601016040528285526000906021602087019101915b848110614e88575050505050565b836001600b92855160a81c855201920192019190614e7a565b90614eb6575080511561452457805190602001fd5b81511580614f01575b614ec7575090565b6024906001600160a01b03604051917f9996b315000000000000000000000000000000000000000000000000000000008352166004820152fd5b50803b15614ebf565b908060030b90600082126000146152a25760000360030b5b63ffffffff808094169116029182168281036130bc576204eb4a106152715760018216156152485770ffffffffffffffffffffffffffffffffff6ffffcb933bd6fad9d3af5f0b9f25db4d65b16906002831661522c575b60048316615210575b600883166151f4575b601083166151d8575b602083166151bc575b604083166151a0575b608092838116615185575b610100811661516a575b610200811661514f575b6104008116615134575b6108008116615119575b61100081166150fe575b61200081166150e3575b61400081166150c8575b61800081166150ad575b620100008116615092575b620200008116615077575b620400001661505d575b600012615038575b670de0b6b3a764000002901c90565b80156150475760001904615029565b634e487b7160e01b600052601260045260246000fd5b6d2216e584f630389b2052b8db590e909102821c90615021565b6e5d6af8dedbcb3a6ccb7ce618d14225909202831c91615017565b916f09aa508b5b7e5a9780b0cc4e25d61a5602831c9161500c565b916f31be135f97da6e09a19dc367e3b6da4002831c91615001565b916f70d869a156ddd32a39e257bc3f50aa9b02831c91614ff7565b916fa9f746462d8f7dd10e744d913d03333302831c91614fed565b916fd097f3bdfd254ee83bdd3f248e7e785e02831c91614fe3565b916fe7159475a2c578ef4f1d17b2b235d48002831c91614fd9565b916ff3392b0822b88206f8abe8a3b44dd9be02831c91614fcf565b916ff987a7253ac4d9194200696907cf2e3702831c91614fc5565b916ffcbe86c7900aecf64236ab31f1f9dcb502831c91614fbb565b916ffe5dee046a99d51e2cc356c2f617dbe002831c91614fb1565b906fff2ea16466c9838804e327cb417cafcb0260801c90614fa6565b906fff973b41fa98cd2e57b660be99eb2c4a0260801c90614f9d565b906fffcb9843d60f67b19e8887e0bd251eb70260801c90614f94565b906fffe5caca7e10e81259b3cddc7a0649410260801c90614f8b565b906ffff2e50f5f656ac9229c67059486f3890260801c90614f82565b906ffff97272373d41fd789c8cb37ffcaa1c0260801c90614f79565b70ffffffffffffffffffffffffffffffffff700100000000000000000000000000000000614f6e565b602490604051907f20ab18100000000000000000000000000000000000000000000000000000000082526004820152fd5b614f22565b9091928381039160009481604e1c1580615376575b615365575b84156153585781156153225761531661531d95615310858761530b633b9aca00966152f66152ef858b6153eb565b9187615419565b0160011c976153058980615437565b95615437565b6154d6565b0161555a565b02016154d6565b901c90565b615330915080939294615419565b909280820292811461534f575b81830414901517156121785704901c90565b6001935061533d565b50905061531d92506153eb565b6039955093851b9390851b906152c1565b5084604e1c156152bc565b9192939082156153e35790818592156153db576153b06153b7936153c6956153a98886615419565b01936153eb565b01906153eb565b670de0b6b3a76400000261555a565b90818111908218021890818110908218021890565b505050505090565b505050905090565b670de0b6b3a764000090818102918315615410575b8183041490151715612178570490565b60019350615400565b81810291818304149015171561217857670de0b6b3a7640000900490565b9080820290600019818409908280831092039180830392146154c557670de0b6b3a7640000908282111561549b577faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac10669940990828211900360ee1b910360121c170290565b60046040517f227bc153000000000000000000000000000000000000000000000000000000008152fd5b5050670de0b6b3a764000091500490565b9091828202916000198482099383808610950394808603951461554c578483111561549b5782910981600003821680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505080925015615047570490565b60b5817101000000000000000000000000000000000081101561560f575b80690100000000000000000062010000921015615602575b650100000000008110156155f5575b63010000008110156155e8575b010260121c60019080830401811c80830401811c80830401811c80830401811c80830401811c80830401811c80830401901c8080920410900390565b60101c9160081b916155ac565b60201c9160101b9161559f565b60401c9160201b91615590565b5068b500000000000000009050608082901c61557856fea26469706673582212201c64c92baae27435f45e6b003e22802584f9d582913f3e80df9e9c8b533042ef64736f6c634300081900330000000000000000000000000a7e848aca42d879ef06507fca0e7b33a0a63c1e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000116193c58b40d50687c0433b2aa0cc4ae00bc32c000000000000000000000000d94c8f6d13cf480ffac686712c63471d1596cc2900000000000000000000000063ef1a657cc53747689b201aa07a76e9ef22f8fe
Deployed Bytecode
0x60406080815260049081361015610074575b361561001c57600080fd5b6001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216330361004e57005b517fc0f54629000000000000000000000000000000000000000000000000000000008152fd5b6000803560e01c80627b077214611eb657806302e705b114611dc557806303bffc5a14611c9757806309218e9114611c5357806312210e8a14611c3f578063176305b514611bfb5780631f2c610114611a9d578063245e4bf014611a595780632dbed792146118805780633052faef146118215780633ec5cded146117fb5780633fc8cef3146117b757806349404b7c146117975780634f2ca8301461170557806350389fb41461167b578063510dc46314610ffb5780635959ccfa14611642578063670ca1811461158757806367ca7c911461143e5780636f7cb4d51461137a5780637817eafb1461132a5780638c014fcb1461112957806395b2a33f146110e557806397e348c514611095578063a36519711461107c578063a69909461461102b578063ac559dee14610ffb578063ac9650d814610ee9578063adc9772e14610ebc578063b06c332114610e16578063b7bd452e14610c99578063b800a20614610b3d578063b9e4530014610abe578063c45a015514610a7a578063c470b79014610a13578063caca688d14610999578063d18214581461092c578063d47607c514610853578063dbba58e514610816578063def0e39f14610766578063df2ab5bb14610753578063e05a807b1461066a578063e34143c8146105f5578063e4d43a4114610530578063ef8d81f6146104b0578063f16d790414610499578063f1bd8bc814610423578063fb2b2063146103d9578063fd388b97146103a95763fd3dfa83146102a55750610011565b6020906102b136612947565b9793926001600160a01b039691967f000000000000000000000000116193c58b40d50687c0433b2aa0cc4ae00bc32c169461032c895194859384937f2f745c590000000000000000000000000000000000000000000000000000000085528401602090939291936001600160a01b0360408201951681520152565b0381865afa93841561039e578094610362575b61035e876103508a89898989613478565b90939192519384938461267d565b0390f35b909193506020823d602011610396575b8161037f602093836120e7565b81010312610393575051918161035e61033f565b80fd5b3d9150610372565b8651903d90823e3d90fd5b6080836103c16103b836612733565b939290926142ed565b92939091815194855260208501528301526060820152f35b5060206003193601126103935782359067ffffffffffffffff8211610393575061040c61035e93610412923691016127cc565b336130fc565b929593949190915195869586612915565b5091816003193601126104955761043861234b565b926024359067ffffffffffffffff82116103935750926104616104679261035e953691016125ad565b90614155565b919492935194859485909493926060926001600160a01b036080840197168352602083015260408201520152565b8280fd5b506104ad6104a636612a89565b9091614da8565b80f35b50809183602060031936011261052c576001600160a01b036104d061234b565b16803b156105275783918351809581937f84302a6b0000000000000000000000000000000000000000000000000000000083525af190811561051e5750610515575080f35b6104ad9061209b565b513d84823e3d90fd5b505050fd5b5050fd5b5060806003193601126103935761054561234b565b9267ffffffffffffffff906024358281116105f15761056790369083016125ad565b916044358181116105ed5761057f90369084016129b1565b936064359182116103935750916105a16105a7949261035e9794369101612a19565b92613d9c565b96516001600160a01b039687168152602081019590955260408501939093526060840191909152608083015290911660a082015260c081019190915290819060e0820190565b8480fd5b8380fd5b5060806003193601126103935761060a61234b565b92610613612375565b9067ffffffffffffffff6044358181116105ed576106349036908401612422565b9360643591821161039357509161065661065c949261035e9794369101612440565b92613c4f565b9194929351948594856124fa565b509160606003193601126104955761068061234b565b918360249260243567ffffffffffffffff8111610495576106a79095919536908701612545565b946106b0612521565b63ffffffff908116926001600160a01b03169190845b885181101561074f57816106da828b612b1b565b5116843b1561074b578751907f8e5430a7000000000000000000000000000000000000000000000000000000008252848201528589820152868160448183895af18015610741579060019291610732575b50016106c6565b61073b9061209b565b3861072b565b88513d89823e3d90fd5b8680fd5b8580f35b506104ad61076036612a89565b91613b62565b50906101006003193601126108125761077d6127a0565b6024359067ffffffffffffffff821682036105f15760443561ffff811681036105ed5760643563ffffffff8116810361080e576107b861238b565b9060a435926001600160a01b0395868516850361080a5760c435958660030b87036108065760e4359960ff8b168b036103935750916020999593916107fe979593613a7c565b915191168152f35b8980fd5b8880fd5b8580fd5b5080fd5b5091906003193601126108125761082b61234b565b60243567ffffffffffffffff81116105f1576104ad9261084d91369101612204565b906139bb565b50919060606003193601126104955760206108cd9261087061234b565b610878612375565b866001600160a01b0386518098819682957fb66503cf000000000000000000000000000000000000000000000000000000008452604435918401602090939291936001600160a01b0360408201951681520152565b0393165af19182156109225783926108ea575b6020838351908152f35b9091506020813d60201161091a575b81610906602093836120e7565b8101031261049557602092505190386108e0565b3d91506108f9565b81513d85823e3d90fd5b5060606003193601126103935767ffffffffffffffff9280358481116104955761095990369083016125ad565b936024358181116105f15761097190369084016129b1565b9260443591821161039357509161099261035e95926105a794369101612a19565b9133613d9c565b506060600319360112610393576109ae61234b565b9267ffffffffffffffff6024358181116105f1576109cf9036908401612422565b926044359182116103935750916109f061035e95926109f794369101612440565b91336137b5565b9251918252602082015260408101919091529081906060820190565b50608060031936011261039357610a2861234b565b92610a31612375565b9067ffffffffffffffff6044358181116105ed57610a529036908401612422565b93606435918211610393575091610a746109f7949261035e9794369101612440565b926137b5565b509034610812578160031936011261081257602090516001600160a01b037f0000000000000000000000000a7e848aca42d879ef06507fca0e7b33a0a63c1e168152f35b5091606060031936011261049557610ad461234b565b602435610ae360443592614a14565b938185108015610b34575b610af6578580f35b517ffcb505c7000000000000000000000000000000000000000000000000000000008152928301938452602084015260408301529081906060010390fd5b50828511610aee565b508260a060031936011261081257610b5361234b565b90610b5c612375565b604435928315158094036105ed57608435908160030b80920361080e57908587949392855196610b8b88612069565b606435885260208801908152610c3a878901916001835260608a019586526001600160a01b0395869485811615600014610c93575030935b8a519233602085015260208452610bd9846120cb565b8b519c8d9b8c9a8b987f3eece7db000000000000000000000000000000000000000000000000000000008a521690880152516024870152511515604486015251151560648501525160030b608484015260c060a484015260c4830190612145565b0393165af1908115610c89578291610c5a575b5082519182526020820152f35b9050610c7c9150823d8411610c82575b610c7481836120e7565b810190612b45565b83610c4d565b503d610c6a565b83513d84823e3d90fd5b93610bc3565b509160e060031936011261049557610caf6127a0565b916024359161ffff831683036105ed57610cc7612521565b606435916001600160a01b03948584168403610e1257610ce561238b565b60a4358060030b81036108065760c4359160ff83168303610e0e576020968a96610d95958a519c8d998a997ff4b52483000000000000000000000000000000000000000000000000000000008b528a01969260ff959299989461ffff63ffffffff9260e099946101008c019d67ffffffffffffffff8092168d521660208c01521660408a01521660608801526001600160a01b0380921660808801521660a086015260030b60c085015216910152565b038187867f0000000000000000000000000a7e848aca42d879ef06507fca0e7b33a0a63c1e165af1928315610e045760209493610dd5575b505191168152f35b610df6919350843d8611610dfd575b610dee81836120e7565b810190612abd565b9138610dcd565b503d610de4565b81513d86823e3d90fd5b8a80fd5b8780fd5b5091906080600319360112610495576020610ea192610e3361234b565b6001600160a01b03610e43612375565b911690610e546064358333846143d8565b8685518097819582947fb66503cf000000000000000000000000000000000000000000000000000000008452604435918401602090939291936001600160a01b0360408201951681520152565b03925af19182156109225783926108ea576020838351908152f35b50816003193601126103935750610edd610ed461234b565b60243590613562565b82519182526020820152f35b50919060209160206003193601126105f15780359267ffffffffffffffff9182851161080e573660238601121561080e578401359180831161080e5760246005933660248260051b89010111610e125793610f4385613519565b9688917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbd82360301925b878110610f815788518061035e8c826122c9565b8481831b8401013584811215610ff7578301908582013591878311610ff357604401918c81360384136103935780610fc0600195610fd79436916123eb565b8b81519101305af4610fd06144cb565b9030614ea1565b610fe1828d612b1b565b52610fec818c612b1b565b5001610f6d565b8c80fd5b8b80fd5b5090806003193601126108125760209061102461101661234b565b61101e612375565b90612d51565b9051908152f35b509190602060031936011261049557813590814211611048578380f35b6044935051917f3442e977000000000000000000000000000000000000000000000000000000008352820152426024820152fd5b61035e8361035061108c36612947565b93929092613478565b50346103935760206003193601126103935782359067ffffffffffffffff821161039357506110cd61035e936110d292369101612204565b6147d6565b9051918291602083526020830190612145565b509181600319360112610495576110fa61234b565b926024359067ffffffffffffffff82116103935750926111236104129261035e953691016127cc565b906130fc565b50829061113536612733565b969385919395506001600160a01b0388168551977f48fd65fe0000000000000000000000000000000000000000000000000000000089526020988981806111958733878401602090939291936001600160a01b0360408201951681520152565b0381865afa90811561132057918a939186959386916112e1575b50156112735788517f2f745c5900000000000000000000000000000000000000000000000000000000815233918101918252602082019390935291935083918290819060400103915afa918215611268578092611236575b50509160a0969161121a93955b866142ed565b9391909295825196875286015284015260608301526080820152f35b9091508682813d8311611261575b61124e81836120e7565b810103126103935750518161121a611207565b503d611244565b8551903d90823e3d90fd5b6024919250885194859384926335313c2160e11b845233908401525af19182156112685780926112af575b50509160a0969161121a9395611214565b9091508682813d83116112da575b6112c781836120e7565b810103126103935750518161121a61129e565b503d6112bd565b929480929496508391503d8311611319575b6112fd81836120e7565b810103126105ed57918493916113138b94612aef565b8d6111af565b503d6112f3565b88513d87823e3d90fd5b50346103935760206003193601126103935782359067ffffffffffffffff8211610393575061136261035e9361136792369101612422565b612ddf565b9051918291602083526020830190612699565b509160806003193601126104955761139061234b565b9267ffffffffffffffff91604435838111610495576113b29036908301612422565b92606435908111610495576113ca9036908301612440565b84517f2f745c590000000000000000000000000000000000000000000000000000000081523392810192835260243560208481019190915291967f000000000000000000000000116193c58b40d50687c0433b2aa0cc4ae00bc32c6001600160a01b0316939092908290819060400161032c565b5091346104955760806003193601126104955761145961234b565b916024359160643567ffffffffffffffff811161080e5761147d90369083016123a1565b90916001600160a01b039380517f578eaca40000000000000000000000000000000000000000000000000000000081523383820152602081602481897f0000000000000000000000000a7e848aca42d879ef06507fca0e7b33a0a63c1e165afa90811561157d578991611543575b501561151d5750509061150091810190612afc565b16918161150b578380f35b61151692339161457e565b3880808380f35b517f36294ff5000000000000000000000000000000000000000000000000000000008152fd5b90506020813d602011611575575b8161155e602093836120e7565b8101031261080a5761156f90612aef565b386114eb565b3d9150611551565b82513d8b823e3d90fd5b5060806003193601126103935761159c61234b565b6115a4612375565b90604435606435916001600160a01b03807f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21690818184161460001461160657505050906115f76104ad93923390612be0565b6115ff612adc565b3391613b62565b8592951614600014611631575061162992611622913391613b62565b3390612be0565b6104ad612adc565b91906104ad936115ff913391613b62565b5060206003193601126103935782359067ffffffffffffffff8211610393575061167561035e93610467923691016125ad565b33614155565b5091903461049557602091826003193601126105f157803567ffffffffffffffff81116105ed576116b96116b485938793369101612422565b614e48565b9083519383808695860192818752855180945286019401925b8281106116e157505050500390f35b83516affffffffffffffffffffff16855286955093810193928101926001016116d2565b5090602092836003193601126104955783839160246001600160a01b0361172a61234b565b1691855194859384926335313c2160e11b845233908401525af192831561178c57809361175a575b505051908152f35b909192508382813d8311611785575b61177381836120e7565b81010312610393575051903880611752565b503d611769565b8251903d90823e3d90fd5b509190600319360112610812576104ad906117b0612375565b9035612be0565b509034610812578160031936011261081257602090516001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2168152f35b50816003193601126103935750610edd61181361234b565b61181b612375565b90612b5b565b5060606003193601126103935761183661234b565b9267ffffffffffffffff6024358181116105f1576118579036908401612422565b9260443591821161039357509161187861035e959261065c94369101612440565b913390613c4f565b508290346103935760606003193601126103935781356001600160a01b038116809103610812576118af612375565b916044359167ffffffffffffffff831161081257366023840112156108125782850135926118dc8461210a565b906118e9885192836120e7565b84825260209460248684019160051b8301019136831161080e57959897969495602401905b828210611a4a5750505051906119238261210a565b92611930875194856120e7565b82845261193c8361210a565b95601f198986019701368837855b84811061199157505050505083519485948186019282875251809352850193925b82811061197a57505050500390f35b83518552869550938101939281019260010161196b565b88999695979851907fef4fcafa0000000000000000000000000000000000000000000000000000000082528782806119e28488888401602090939291936001600160a01b0360408201951681520152565b03818a895af18015611a40578790611a10575b60019250611a03828b612b1b565b520198979694959861194a565b50908781813d8311611a39575b611a2781836120e7565b8101031261074b5790600191516119f5565b503d611a1d565b8b513d89823e3d90fd5b8135815290890190890161190e565b509034610812578160031936011261081257602090516001600160a01b037f00000000000000000000000063ef1a657cc53747689b201aa07a76e9ef22f8fe168152f35b5091346104955760a060031936011261049557611ab861234b565b611ac0612375565b90604435936064359360843567ffffffffffffffff8111610e1257611ae890369083016123a1565b90916001600160a01b039380517f578eaca40000000000000000000000000000000000000000000000000000000081523383820152602081602481897f0000000000000000000000000a7e848aca42d879ef06507fca0e7b33a0a63c1e165afa908115611bf1578b91611bb7575b5015611b9157505090611b6b91810190612afc565b169380611b7e575b50508161150b578380f35b611b8a9185339161457e565b3880611b73565b517f8a9dab50000000000000000000000000000000000000000000000000000000008152fd5b90506020813d602011611be9575b81611bd2602093836120e7565b81010312610e0e57611be390612aef565b38611b56565b3d9150611bc5565b82513d8d823e3d90fd5b509034610812578160031936011261081257602090516001600160a01b037f000000000000000000000000d94c8f6d13cf480ffac686712c63471d1596cc29168152f35b5080600319360112610393576104ad612adc565b509034610812578160031936011261081257602090516001600160a01b037f000000000000000000000000116193c58b40d50687c0433b2aa0cc4ae00bc32c168152f35b5091606060031936011261049557611cad61234b565b6001600160a01b03918282168451937f72f702f300000000000000000000000000000000000000000000000000000000855260209485818581865afa928315611dbb5786918994611d81575b508751948580927ffbfa77cf0000000000000000000000000000000000000000000000000000000082525afa928315611d775791611d4c949391610ed4938993611d58575b5060443592169033906143d8565b90918351928352820152f35b611d70919350873d8911610dfd57610dee81836120e7565b9188611d3e565b86513d89823e3d90fd5b8281939295503d8311611db4575b611d9981836120e7565b81010312610e1257518181168103610e125785909238611cf9565b503d611d8f565b87513d8a823e3d90fd5b508234610812576020806003193601126104955781359167ffffffffffffffff908184116105ed57366023850112156105ed57830135602493611e078261210a565b94611e14885196876120e7565b8286526024602087019360051b83010193368511610e125760248301935b858510611e9057898989611e468151613519565b915b8151811015611e835780611e67611e6160019385612b1b565b516147d6565b611e718286612b1b565b52611e7c8185612b1b565b5001611e48565b83518061035e85826122c9565b8435828111610806578791611eab8392863691890101612204565b815201940193611e32565b50903461081257602091826003193601126103935783359367ffffffffffffffff85116108125736602386011215610812578481013594611ef68661210a565b90611f03855192836120e7565b8682528582016024819860051b8301019136831161080e57602401905b82821061204657505050519460ff86116120105760ff861691600b93600b840297848904600b1485151715611ffd5760019260018a01809a11611fea57507fff00000000000000000000000000000000000000000000000000000000000000611fa0611f8b8b6123cf565b9a611f988a519c8d6120e7565b808c526123cf565b91601f198a8c01930136843760f81b169052918660218901935b858110611fd35787518281528061035e8185018d612145565b825160a81b85529386019391019087908301611fba565b826011602492634e487b7160e01b835252fd5b506011602492634e487b7160e01b835252fd5b6044828760088751927f6dfcc6500000000000000000000000000000000000000000000000000000000084528301526024820152fd5b81356affffffffffffffffffffff8116810361074b578152908701908701611f20565b6080810190811067ffffffffffffffff82111761208557604052565b634e487b7160e01b600052604160045260246000fd5b67ffffffffffffffff811161208557604052565b6060810190811067ffffffffffffffff82111761208557604052565b6040810190811067ffffffffffffffff82111761208557604052565b90601f601f19910116810190811067ffffffffffffffff82111761208557604052565b67ffffffffffffffff81116120855760051b60200190565b60005b8381106121355750506000910152565b8181015183820152602001612125565b90601f19601f60209361216381518092818752878088019101612122565b0116010190565b359060ff8216820361217857565b600080fd5b35908160030b820361217857565b9080601f830112156121785760209082356121a58161210a565b936121b360405195866120e7565b81855260208086019260051b82010192831161217857602001905b8282106121dc575050505090565b81356fffffffffffffffffffffffffffffffff811681036121785781529083019083016121ce565b9190606083820312612178576040519061221d826120af565b81936122288161216a565b835267ffffffffffffffff916020828101358481116121785783019082601f830112156121785781359161225b8361210a565b9261226960405194856120e7565b808452828085019160051b830101918583116121785783809101915b8383106122b157505050508501526040820135928311612178576040926122ac920161218b565b910152565b81906122bc8461217d565b8152019101908390612285565b6020808201906020835283518092526040830192602060408460051b8301019501936000915b8483106122ff5750505050505090565b909192939495848061233b837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc086600196030187528a51612145565b98019301930191949392906122ef565b600435906001600160a01b038216820361217857565b35906001600160a01b038216820361217857565b602435906001600160a01b038216820361217857565b608435906001600160a01b038216820361217857565b9181601f840112156121785782359167ffffffffffffffff8311612178576020838186019501011161217857565b67ffffffffffffffff811161208557601f01601f191660200190565b9291926123f7826123cf565b9161240560405193846120e7565b829481845281830111612178578281602093846000960137010152565b9080601f830112156121785781602061243d933591016123eb565b90565b81601f820112156121785780359160209161245a8461210a565b9361246860405195866120e7565b808552838086019160051b8301019280841161217857848301915b8483106124935750505050505090565b823567ffffffffffffffff81116121785786916124b584848094890101612422565b815201920191612483565b90815180825260208080930193019160005b8281106124e0575050505090565b835163ffffffff16855293810193928101926001016124d2565b94939260609261251c92875260208701526080604087015260808601906124c0565b930152565b6044359063ffffffff8216820361217857565b359063ffffffff8216820361217857565b9080601f8301121561217857602090823561255f8161210a565b9361256d60405195866120e7565b81855260208086019260051b82010192831161217857602001905b828210612596575050505090565b8380916125a284612534565b815201910190612588565b9190916060818403126121785760408051916125c8836120af565b8294813567ffffffffffffffff90818111612178578301608081840312612178578451906125f582612069565b6125fe81612361565b825260208101358381116121785784612618918301612545565b602083015285810135838111612178578161263a86606093612644950161218b565b888501520161216a565b6060820152855260208301358181116121785782612663918501612422565b602086015283830135908111612178576122ac9201612440565b61243d93926060928252602082015281604082015201906124c0565b6060820160ff825116835260209182810151916060848601528251809152836080860193019060005b81811061271c575050506040015192604081830391015281808451928381520193019160005b8281106126f6575050505090565b83516fffffffffffffffffffffffffffffffff16855293810193928101926001016126e8565b825160030b855293850193918501916001016126c2565b9060a060031983011261217857600435916001600160a01b036024358181168103612178579267ffffffffffffffff604435818111612178578461277991600401612422565b936064359182116121785761279091600401612440565b9160843590811681036121785790565b6004359067ffffffffffffffff8216820361217857565b359067ffffffffffffffff8216820361217857565b919091610200908181850312612178576040519182019367ffffffffffffffff9483811086821117612085576040528294612806836127b7565b8452612814602084016127b7565b6020850152604083013561ffff8116810361217857604085015261283a60608401612534565b606085015261284b60808401612361565b608085015261285c60a08401612361565b60a085015261286d60c0840161217d565b60c085015261287e60e0840161216a565b60e085015261010080840135828111612178578361289d918601612204565b9085015261012080840135908501526101408084013582811161217857836128c6918601612204565b908501526101609182840135918211612178576128e4918401612440565b9083015261018080820135908301526101a080820135908301526101c080820135908301526101e080910135910152565b959493909261251c926001600160a01b036080951688526020880152604087015260a0606087015260a08601906124c0565b60a0600319820112612178576001600160a01b039160043583811681036121785792602435908116810361217857916044359167ffffffffffffffff606435818111612178578361299a91600401612422565b926084359182116121785761243d91600401612440565b9080601f830112156121785760209082356129cb8161210a565b936129d960405195866120e7565b81855260208086019260051b82010192831161217857602001905b828210612a02575050505090565b838091612a0e84612361565b8152019101906129f4565b9080601f83011215612178576020908235612a338161210a565b93612a4160405195866120e7565b81855260208086019260051b82010192831161217857602001905b828210612a6a575050505090565b81356001600160a01b0381168103612178578152908301908301612a5c565b6003196060910112612178576001600160a01b03600435818116810361217857916024359160443590811681036121785790565b9081602091031261217857516001600160a01b03811681036121785790565b47612ae357565b612aed47336144fb565b565b5190811515820361217857565b9081602091031261217857356001600160a01b03811681036121785790565b8051821015612b2f5760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b9190826040910312612178576020825192015190565b9060409060246001600160a01b0391600083855196879586947fbc25cf77000000000000000000000000000000000000000000000000000000008652166004850152165af18015612bd457600091600091612bb557509091565b9050612bd0915060403d604011610c8257610c7481836120e7565b9091565b6040513d6000823e3d90fd5b6001600160a01b03807f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21692604051927f70a08231000000000000000000000000000000000000000000000000000000008452306004850152602084602481885afa938415612bd457600094612d1d575b50808410612cd4575082612c66575b50505050565b833b1561217857600080946024604051809781937f2e1a7d4d0000000000000000000000000000000000000000000000000000000083528860048401525af1938415612bd457612cbc94612cc5575b50166144fb565b38808080612c60565b612cce9061209b565b38612cb5565b6040517fd1cd07af0000000000000000000000000000000000000000000000000000000081526001600160a01b0386166004820152602481019190915260448101849052606490fd5b90936020823d602011612d49575b81612d38602093836120e7565b810103126103935750519238612c51565b3d9150612d2b565b9060209060246001600160a01b039160008360405196879586946335313c2160e11b8652166004850152165af1908115612bd457600091612d90575090565b90506020813d602011612db7575b81612dab602093836120e7565b81010312612178575190565b3d9150612d9e565b60405190612dcc826120af565b6060604083600081528260208201520152565b612de7612dbf565b50612df0612dbf565b90805115612b2f576020908181015160f81c8352805160001992838201938285116130bc57601f19928386116130d257845195600196826001116130bc578211613092578061303f5750505060405192600084528184016040525b81840151928360f81c93611fe094604096858789519460f31c16840101885281835260009060218785019101915b878b858310613029575092505050829150890152518060021b600491808204831490151715613014576002810193848211612fd757805191808303937ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe9687860194851161301457868511612fec578351868401809211612fd75710612fb0575082612f625750505050505082516000815281810184525b8181015194828660f81c9486519760f31c16870101855283865260009160218488019101925b858110612f4a5750505050505082015290565b8483601092865160801c855201920193019290612f37565b60029089949392945196601f8416801560051b9182828b0101968701019601010101925b86818410612f9f575050601f9250845201168452612f11565b845184529384019390920191612f86565b89517f326b3d3a000000000000000000000000000000000000000000000000000000008152fd5b601183634e487b7160e01b6000525260246000fd5b5089517f648fb3b1000000000000000000000000000000000000000000000000000000008152fd5b601182634e487b7160e01b6000525260246000fd5b600492855160e01c855201920192019190612e79565b9491908490604051966001601f821694851560051b9081878c0101948501019587010101935b8681841061307e5750508752601f011660405250612e4b565b855184529485019488945090920191613065565b60046040517f326b3d3a000000000000000000000000000000000000000000000000000000008152fd5b634e487b7160e01b600052601160045260246000fd5b60046040517f648fb3b1000000000000000000000000000000000000000000000000000000008152fd5b909167ffffffffffffffff9182845116926020850151169361316060409561ffff87840151169563ffffffff606085015116966001600160a01b039788608087015116908960a0880151169260c08801519560ff60e08a0151169660030b95613a7c565b93610120820180516131bc575b50506101606131b69394955191613183836120cb565b600c83527f0100000000000000000000000000000000000000000000000000000000000000602084015201519185613c4f565b90919293565b86906131cd610100850151886139bb565b518151906131da82612069565b8152602081019260018452806000848401600181526132836060860191637fffffff8352848b161584146132cf5730925b88519133602084015260208352613221836120cb565b89519a8b998a9889977f3eece7db000000000000000000000000000000000000000000000000000000008952166004880152516024870152511515604486015251151560648501525160030b608484015260c060a484015260c4830190612145565b03928a165af180156132c45795610160916131b69596976132a8575b5095949361316d565b6132be90823d8411610c8257610c7481836120e7565b5061329f565b86513d6000823e3d90fd5b8a9261320b565b519063ffffffff8216820361217857565b9091606082840312612178578151926020808401519360408101519067ffffffffffffffff821161217857019180601f8401121561217857825161332a8161210a565b9361333860405195866120e7565b818552838086019260051b820101928311612178578301905b82821061335f575050505090565b83809161336b846132d6565b815201910190613351565b9261339a6133a091613394613416949561338f88614a14565b614d2c565b90612b1b565b51612ddf565b916001600160a01b0393849160405194336020870152602086526133c3866120cb565b60405196879485937f42e3d72c0000000000000000000000000000000000000000000000000000000085521660048401528261342860009889988995866024860152608060448601526084850190612699565b90600319848303016064850152612145565b0393165af1801561346b578192828092613444575b5050909192565b9150915061346492503d8091833e61345c81836120e7565b8101906132e7565b388061343d565b50604051903d90823e3d90fd5b90919361339a613492916133946134289661338f86614a14565b906001600160a01b039283926134ff60405191336020840152602083526134b8836120cb565b60405198899687957f42e3d72c0000000000000000000000000000000000000000000000000000000087521660048601526024850152608060448501526084840190612699565b946003198387030160648401528260009788978894612145565b906135238261210a565b61353060405191826120e7565b828152601f19613540829461210a565b019060005b82811061355157505050565b806060602080938501015201613545565b919080156135df575b6001600160a01b039260246040926000845196879485937fa694fc3a0000000000000000000000000000000000000000000000000000000085526004850152165af1918215612bd4576000906000936135c357509190565b9050612bd091925060403d604011610c8257610c7481836120e7565b506001600160a01b03821660409081517f48fd65fe0000000000000000000000000000000000000000000000000000000081523360048201526000908160248201526020908181604481875afa90811561378e578391613759575b50156136e457806044938551948580927f2f745c590000000000000000000000000000000000000000000000000000000082523360048301528660248301525afa9384156136d9575081936136a6575b5050506001600160a01b039260246040925b925050925061356b565b9091809350813d83116136d2575b6136be81836120e7565b81010312610393575051826024604061368a565b503d6136b4565b51913d9150823e3d90fd5b80829360248651809681936335313c2160e11b83523360048401525af19384156136d957508193613726575b5050506001600160a01b0392602460409261369c565b9091809350813d8311613752575b61373e81836120e7565b810103126103935750518260246040613710565b503d613734565b90508181813d8311613787575b61377081836120e7565b810103126104955761378190612aef565b3861363a565b503d613766565b85513d85823e3d90fd5b51906fffffffffffffffffffffffffffffffff8216820361217857565b919392906001600160a01b039081811691823b15612178576040938451977f84302a6b0000000000000000000000000000000000000000000000000000000089526000988981600481838a5af1801561393b576139a8575b508551937fbc0d199200000000000000000000000000000000000000000000000000000000855260209485816004818a5afa90811561399e579089918c91613955575b506fffffffffffffffffffffffffffffffff16613945575b505085517f16f0115b0000000000000000000000000000000000000000000000000000000081528481600481895afa90811561393b57928a9492876138ba93889660249c9d9e9161391e575b50613376565b5097909884885197889485936335313c2160e11b85521660048401525af19384156139145750926138ea57505092565b90809250813d831161390d575b61390181836120e7565b81010312612178575192565b503d6138f7565b51903d90823e3d90fd5b6139359150873d8911610dfd57610dee81836120e7565b386138b4565b87513d8c823e3d90fd5b61394e91612b5b565b5087613868565b809250878092503d8311613997575b61396e81836120e7565b81010312610e0e576fffffffffffffffffffffffffffffffff6139918a92613798565b90613850565b503d613964565b88513d8d823e3d90fd5b6139b49099919961209b565b973861380d565b613a5191600091613416836001600160a01b0360405194336020870152602086526139e5866120cb565b604051978896879586937f42e3d72c000000000000000000000000000000000000000000000000000000008552857f000000000000000000000000116193c58b40d50687c0433b2aa0cc4ae00bc32c166004860152866024860152608060448601526084850190612699565b0393165af18015612bd457613a635750565b613a77903d806000833e61345c81836120e7565b505050565b6040517ff4b5248300000000000000000000000000000000000000000000000000000000815267ffffffffffffffff91821660048201529116602482015261ffff909116604482015263ffffffff90911660648201526001600160a01b039182166084820152911660a482015260039190910b60c482015260ff90911660e4820152602081806101048101038160006001600160a01b037f0000000000000000000000000a7e848aca42d879ef06507fca0e7b33a0a63c1e165af1908115612bd457600091613b49575090565b61243d915060203d602011610dfd57610dee81836120e7565b916001600160a01b03831691604051927f70a08231000000000000000000000000000000000000000000000000000000008452306004850152602084602481845afa938415612bd457600094613c1b575b50818410613bd057505081613bc757505050565b612aed92614da8565b6040517fd1cd07af0000000000000000000000000000000000000000000000000000000081526001600160a01b03919091166004820152602481019190915260448101839052606490fd5b90936020823d602011613c47575b81613c36602093836120e7565b810103126103935750519238613bb3565b3d9150613c29565b929390916001600160a01b0394857f000000000000000000000000116193c58b40d50687c0433b2aa0cc4ae00bc32c16604051917f75794a3c0000000000000000000000000000000000000000000000000000000083526020938484600481865afa8015612bd4578994600091613d5f575b5088928492613cd492889660009c613478565b9a91999098613d2a8c9a9b9c604051988997889687957f45d77f7e0000000000000000000000000000000000000000000000000000000087521660048601521660248401526060604484015260648301906124c0565b03925af1918215612bd457600092613d4157505090565b90809250813d8311613d58575b612dab81836120e7565b503d613d4e565b98929450909290508488813d8111613d95575b613d7c81836120e7565b8101031261217857965190968893909290916000613cc1565b503d613d72565b9190613da89030614155565b96929694919493909495876001600160a01b03936040928351957f9a4f3329000000000000000000000000000000000000000000000000000000008752600491816064890195169687848a0152606060248a01528051809652886084810192602097888094019060005b81811061413a5750505060031982850301604483015282808251958681520191019360005b81811061411f5750508192935003816000857f00000000000000000000000063ef1a657cc53747689b201aa07a76e9ef22f8fe165af1968715614114576000976140da575b5080871693818651946335313c2160e11b8652168385015280846024816000895af19384156132c4576000946140ab575b5083968651907ffbfa77cf000000000000000000000000000000000000000000000000000000008252828286818a5afa9182156140a057600092614081575b508751917f70a0823100000000000000000000000000000000000000000000000000000000835230868401528383602481855afa92831561407657600093614043575b5090613f859460008594938b51978895869485937fa9059cbb000000000000000000000000000000000000000000000000000000008552168b8401602090939291936001600160a01b0360408201951681520152565b03925af180156132c457908694939291614007575b50506024906000845195869485937fa694fc3a0000000000000000000000000000000000000000000000000000000085528401525af1918215613ffd57600092613fe357505092565b613ff99250803d10610c8257610c7481836120e7565b5092565b513d6000823e3d90fd5b9080929450813d831161403c575b61401f81836120e7565b81010312612178578492614034602492612aef565b509038613f9a565b503d614015565b9250908383813d831161406f575b61405b81836120e7565b810103126121785791519190613f85613f2f565b503d614051565b89513d6000823e3d90fd5b614099919250833d8511610dfd57610dee81836120e7565b9038613eec565b88513d6000823e3d90fd5b9080945081813d83116140d3575b6140c381836120e7565b8101031261217857519238613ead565b503d6140b9565b8481819993993d831161410d575b6140f281836120e7565b81010312610812575190878216820361039357509538613e7c565b503d6140e8565b85513d6000823e3d90fd5b8551871683529484019489948d945090920191600101613e37565b825188168752958501958a958e955090920191600101613e12565b9190916001600160a01b0392805190848251169460209081808501519760409560ff606088830151920151166141c288519b8c947f3d33af7900000000000000000000000000000000000000000000000000000000865260048601526080602486015260848501906124c0565b60031984820301604485015284808451928381520193019060005b8181106142c25750505060648301528190038160007f000000000000000000000000d94c8f6d13cf480ffac686712c63471d1596cc2986165af19687156142b75760009761427d575b509080602494939261424a8982808751511691169586888683015192015192613376565b509690976000875196879485936335313c2160e11b85521660048401525af1928315613ffd57506000926138ea57505092565b8281819993993d83116142b0575b61429581836120e7565b81010312610812575190878216820361039357509581614226565b503d61428b565b84513d6000823e3d90fd5b82516fffffffffffffffffffffffffffffffff16855288968e965094850194909201916001016141dd565b93909294916001600160a01b038092169360409283517ffbfa77cf0000000000000000000000000000000000000000000000000000000081526020816004818a5afa90811561411457938593614354936024999a9b9360009788916143b9575b50166137b5565b97919796909798835194859384927fa694fc3a00000000000000000000000000000000000000000000000000000000845260048401525af1918215613ffd5760009261439f57505090565b6143b59250803d10610c8257610c7481836120e7565b5090565b6143d2915060203d602011610dfd57610dee81836120e7565b3861434d565b906040519360208501917f23b872dd0000000000000000000000000000000000000000000000000000000083526001600160a01b039485809216602488015216604486015260648501526064845260a084019084821067ffffffffffffffff831117612085576144619360009384936040521694519082865af161445a6144cb565b9083614ea1565b80519081151591826144a8575b50506144775750565b602490604051907f5274afe70000000000000000000000000000000000000000000000000000000082526004820152fd5b81925090602091810103126121785760206144c39101612aef565b15388061446e565b3d156144f6573d906144dc826123cf565b916144ea60405193846120e7565b82523d6000602084013e565b606090565b81471061454e5760008080936001600160a01b038294165af161451c6144cb565b501561452457565b60046040517f1425ea42000000000000000000000000000000000000000000000000000000008152fd5b60246040517fcd786059000000000000000000000000000000000000000000000000000000008152306004820152fd5b9392936001600160a01b039081811691807f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216938484148061478b575b156146c55750505050803b1561217857604051937fd0e30db0000000000000000000000000000000000000000000000000000000008552600091828660048185855af19586156146ba5761466095966146a8575b5082936020936040518097819582947fa9059cbb00000000000000000000000000000000000000000000000000000000845260048401602090939291936001600160a01b0360408201951681520152565b03925af1801561346b57614672575050565b6020823d6020116146a0575b8161468b602093836120e7565b81010312610393575061469d90612aef565b50565b3d915061467e565b926146b460209461209b565b9261460f565b6040513d85823e3d90fd5b9080929396979594508116903082146000146146e857505050612aed9350614da8565b606460009182602094959796604051927f23b872dd00000000000000000000000000000000000000000000000000000000845260048401528760248401528960448401525af1601f3d11600160005114163d15171615614749575050505050565b60849550604051947fa8dced90000000000000000000000000000000000000000000000000000000008652600486015260248501521660448301526064820152fd5b50874710156145bb565b6020612aed9193929360405194816147b68793518092868087019101612122565b82016147ca82518093868085019101612122565b010380855201836120e7565b9081519160409081519360207fff00000000000000000000000000000000000000000000000000000000000000809260f81b16818701526001956001815261481d816120cb565b818401519687519160ff83116149cf5760ff8316906103fc8460021b169160049a8184048c14821517156149ba57600184018094116149ba57929091899261487c614867846123cf565b93614874865195866120e7565b8085526123cf565b968989850191601f19809a0136843760f81b1690528c886000960160218501915b8a89858a106149a1575050505050506148b7929350614795565b9501519182519460ff861161496b5760ff861695610ff0818c1b1660109b8882046010148915171561495657600182018092116149565750806149086148ff614910936123cf565b9b519b8c6120e7565b808b526123cf565b898701930136843760f81b1690526021860191830160005b8581106149405750505050505061243d929350614795565b815160801b845292890192908401908201614928565b601190634e487b7160e01b6000525260246000fd5b60448a8760088b51927f6dfcc6500000000000000000000000000000000000000000000000000000000084528301526024820152fd5b835160e01b855298909801978e9750920191018e61489d565b60118c634e487b7160e01b6000525260246000fd5b6044838851907f6dfcc650000000000000000000000000000000000000000000000000000000008252600860048301526024820152fd5b51908160070b820361217857565b6001600160a01b031660409081517f1865c57d000000000000000000000000000000000000000000000000000000008152610120908181600481865afa9081156142b757600091614c31575b5060a09150015160030b8251917f3256cfa900000000000000000000000000000000000000000000000000000000835281600484015260e083602481845afa9283156142b757600093614b72575b5060206004918551928380927fd0c93a7c0000000000000000000000000000000000000000000000000000000082525afa938415613ffd5750600093614b3c575b50614b0e836001614b038461243d97614f0a565b930160030b90614f0a565b906fffffffffffffffffffffffffffffffff60208185511694015116614b36838383876152a7565b93615381565b92506020833d602011614b6a575b81614b57602093836120e7565b8101031261217857915191614b0e614aef565b3d9150614b4a565b60e09391933d60e011614c2a575b614b8a81836120e7565b81019160e08284031261039357855192614ba384612069565b614bac83613798565b8452602091614bbd60208501613798565b6020860152614bcd888501613798565b8886015281607f8501121561039357875193614be885612069565b849160e082019384116103935750606001905b828210614c1357505050506060820152916020614aae565b838091614c1f846132d6565b815201910190614bfb565b503d614b80565b8281813d8311614d25575b614c4681836120e7565b8101031261081257845192830183811067ffffffffffffffff821117614d11578552614c7181613798565b8352614c7f60208201613798565b6020840152614c8f858201614a06565b85840152614c9f60608201614a06565b6060840152608081015164ffffffffff8116810361049557608084015260a08101518060030b81036104955760a0840152614cdc60c08201612aef565b60c0840152614ced60e082016132d6565b60e0840152610100809101519160ff83168303610393575082015260a09038614a60565b602483634e487b7160e01b81526041600452fd5b503d614c3c565b8151600093928491600c14614d9f57614d4790949194614e48565b905b81516000198101908111614d8b57811015614d85576affffffffffffffffffffff614d748284612b1b565b5116831115614d8557600101614d49565b93505050565b602486634e487b7160e01b81526011600452fd5b50600093505050565b9190916020600060446040517fa9059cbb00000000000000000000000000000000000000000000000000000000815286600482015285602482015282855af1601f3d11600160005114163d15171615614e0057505050565b60649350604051927fbf182be80000000000000000000000000000000000000000000000000000000084526001600160a01b0380921660048501521660248301526044820152fd5b906020916020810151928360f81c916020611fe06040519660f31c168601016040528285526000906021602087019101915b848110614e88575050505050565b836001600b92855160a81c855201920192019190614e7a565b90614eb6575080511561452457805190602001fd5b81511580614f01575b614ec7575090565b6024906001600160a01b03604051917f9996b315000000000000000000000000000000000000000000000000000000008352166004820152fd5b50803b15614ebf565b908060030b90600082126000146152a25760000360030b5b63ffffffff808094169116029182168281036130bc576204eb4a106152715760018216156152485770ffffffffffffffffffffffffffffffffff6ffffcb933bd6fad9d3af5f0b9f25db4d65b16906002831661522c575b60048316615210575b600883166151f4575b601083166151d8575b602083166151bc575b604083166151a0575b608092838116615185575b610100811661516a575b610200811661514f575b6104008116615134575b6108008116615119575b61100081166150fe575b61200081166150e3575b61400081166150c8575b61800081166150ad575b620100008116615092575b620200008116615077575b620400001661505d575b600012615038575b670de0b6b3a764000002901c90565b80156150475760001904615029565b634e487b7160e01b600052601260045260246000fd5b6d2216e584f630389b2052b8db590e909102821c90615021565b6e5d6af8dedbcb3a6ccb7ce618d14225909202831c91615017565b916f09aa508b5b7e5a9780b0cc4e25d61a5602831c9161500c565b916f31be135f97da6e09a19dc367e3b6da4002831c91615001565b916f70d869a156ddd32a39e257bc3f50aa9b02831c91614ff7565b916fa9f746462d8f7dd10e744d913d03333302831c91614fed565b916fd097f3bdfd254ee83bdd3f248e7e785e02831c91614fe3565b916fe7159475a2c578ef4f1d17b2b235d48002831c91614fd9565b916ff3392b0822b88206f8abe8a3b44dd9be02831c91614fcf565b916ff987a7253ac4d9194200696907cf2e3702831c91614fc5565b916ffcbe86c7900aecf64236ab31f1f9dcb502831c91614fbb565b916ffe5dee046a99d51e2cc356c2f617dbe002831c91614fb1565b906fff2ea16466c9838804e327cb417cafcb0260801c90614fa6565b906fff973b41fa98cd2e57b660be99eb2c4a0260801c90614f9d565b906fffcb9843d60f67b19e8887e0bd251eb70260801c90614f94565b906fffe5caca7e10e81259b3cddc7a0649410260801c90614f8b565b906ffff2e50f5f656ac9229c67059486f3890260801c90614f82565b906ffff97272373d41fd789c8cb37ffcaa1c0260801c90614f79565b70ffffffffffffffffffffffffffffffffff700100000000000000000000000000000000614f6e565b602490604051907f20ab18100000000000000000000000000000000000000000000000000000000082526004820152fd5b614f22565b9091928381039160009481604e1c1580615376575b615365575b84156153585781156153225761531661531d95615310858761530b633b9aca00966152f66152ef858b6153eb565b9187615419565b0160011c976153058980615437565b95615437565b6154d6565b0161555a565b02016154d6565b901c90565b615330915080939294615419565b909280820292811461534f575b81830414901517156121785704901c90565b6001935061533d565b50905061531d92506153eb565b6039955093851b9390851b906152c1565b5084604e1c156152bc565b9192939082156153e35790818592156153db576153b06153b7936153c6956153a98886615419565b01936153eb565b01906153eb565b670de0b6b3a76400000261555a565b90818111908218021890818110908218021890565b505050505090565b505050905090565b670de0b6b3a764000090818102918315615410575b8183041490151715612178570490565b60019350615400565b81810291818304149015171561217857670de0b6b3a7640000900490565b9080820290600019818409908280831092039180830392146154c557670de0b6b3a7640000908282111561549b577faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac10669940990828211900360ee1b910360121c170290565b60046040517f227bc153000000000000000000000000000000000000000000000000000000008152fd5b5050670de0b6b3a764000091500490565b9091828202916000198482099383808610950394808603951461554c578483111561549b5782910981600003821680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b505080925015615047570490565b60b5817101000000000000000000000000000000000081101561560f575b80690100000000000000000062010000921015615602575b650100000000008110156155f5575b63010000008110156155e8575b010260121c60019080830401811c80830401811c80830401811c80830401811c80830401811c80830401811c80830401901c8080920410900390565b60101c9160081b916155ac565b60201c9160101b9161559f565b60401c9160201b91615590565b5068b500000000000000009050608082901c61557856fea26469706673582212201c64c92baae27435f45e6b003e22802584f9d582913f3e80df9e9c8b533042ef64736f6c63430008190033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000000a7e848aca42d879ef06507fca0e7b33a0a63c1e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000116193c58b40d50687c0433b2aa0cc4ae00bc32c000000000000000000000000d94c8f6d13cf480ffac686712c63471d1596cc2900000000000000000000000063ef1a657cc53747689b201aa07a76e9ef22f8fe
-----Decoded View---------------
Arg [0] : _factory (address): 0x0A7e848Aca42d879EF06507Fca0E7b33A0a63c1e
Arg [1] : _weth (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [2] : _position (address): 0x116193c58B40D50687c0433B2aa0cC4AE00bC32c
Arg [3] : _boostedPositionFactory (address): 0xd94C8f6D13Cf480FfAC686712C63471D1596cc29
Arg [4] : _rewardFactory (address): 0x63EF1a657cc53747689B201aa07A76E9ef22f8Fe
-----Encoded View---------------
5 Constructor Arguments found :
Arg [0] : 0000000000000000000000000a7e848aca42d879ef06507fca0e7b33a0a63c1e
Arg [1] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [2] : 000000000000000000000000116193c58b40d50687c0433b2aa0cc4ae00bc32c
Arg [3] : 000000000000000000000000d94c8f6d13cf480ffac686712c63471d1596cc29
Arg [4] : 00000000000000000000000063ef1a657cc53747689b201aa07a76e9ef22f8fe
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.