Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Initialize | 22483263 | 41 hrs ago | IN | 0 ETH | 0.00036594 |
Latest 1 internal transaction
Advanced mode:
Parent Transaction Hash | Method | Block |
From
|
To
|
|||
---|---|---|---|---|---|---|---|
0x60808060 | 22483256 | 41 hrs ago | Contract Creation | 0 ETH |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
LpValidator
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 150 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.28; import "../../interfaces/strategies/ILpValidator.sol"; import "../../interfaces/strategies/ILpStrategy.sol"; import "../../interfaces/core/IConfigManager.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { IUniswapV3Factory } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol"; import { IPancakeV3Pool as IUniswapV3Pool } from "@pancakeswap/v3-core/contracts/interfaces/IPancakeV3Pool.sol"; import { TickMath } from "@uniswap/v3-core/contracts/libraries/TickMath.sol"; import { LiquidityAmounts } from "@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol"; import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; contract LpValidator is OwnableUpgradeable, ILpValidator { IConfigManager public configManager; mapping(address => bool) public whitelistNfpms; function initialize(address _owner, address _configManager, address[] memory _whitelistNfpms) public initializer { __Ownable_init(_owner); require(_configManager != address(0), ZeroAddress()); configManager = IConfigManager(_configManager); for (uint256 i = 0; i < _whitelistNfpms.length; i++) { whitelistNfpms[_whitelistNfpms[i]] = true; } } function validateNfpm(address nfpm) external view { require(whitelistNfpms[address(nfpm)], InvalidNfpm()); } /// @dev Checks the principal amount in the pool /// @param nfpm The non-fungible position manager /// @param fee The fee of the pool /// @param token0 The token0 of the pool /// @param token1 The token1 of the pool /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param config The configuration of the strategy function validateConfig( INFPM nfpm, uint24 fee, address token0, address token1, int24 tickLower, int24 tickUpper, VaultConfig calldata config ) external view { LpStrategyConfig memory lpConfig = abi.decode(configManager.getStrategyConfig(address(this), config.principalToken), (LpStrategyConfig)); LpStrategyRangeConfig memory rangeConfig = lpConfig.rangeConfigs[config.rangeStrategyType]; LpStrategyTvlConfig memory tvlConfig = lpConfig.tvlConfigs[config.tvlStrategyType]; address pool = IUniswapV3Factory(nfpm.factory()).getPool(token0, token1, fee); // Check if the pool is allowed require(_isPoolAllowed(config, pool), InvalidPool()); uint256 poolPrincipalTokenAmount = IERC20(config.principalToken).balanceOf(pool); // Check if the pool amount is greater than the minimum amount principal token require(poolPrincipalTokenAmount >= tvlConfig.principalTokenAmountMin, InvalidPoolAmountMin()); // Check if tick width to mint/increase liquidity is greater than the minimum tick width uint256 token0Type = configManager.getTypedToken(token0); uint256 token1Type = configManager.getTypedToken(token1); int24 minTickWidth = token0Type == token1Type && token0Type > 0 && token1Type > 0 ? rangeConfig.tickWidthTypedMin : rangeConfig.tickWidthMin; require(tickUpper - tickLower >= minTickWidth, InvalidTickWidth()); } /// @dev Checks the tick width of the position /// @param token0 The token0 of the pool /// @param token1 The token1 of the pool /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param config The configuration of the strategy function validateTickWidth( address token0, address token1, int24 tickLower, int24 tickUpper, VaultConfig calldata config ) external view { LpStrategyConfig memory lpConfig = abi.decode(configManager.getStrategyConfig(address(this), config.principalToken), (LpStrategyConfig)); LpStrategyRangeConfig memory rangeConfig = lpConfig.rangeConfigs[config.rangeStrategyType]; // Check if tick width to mint/increase liquidity is greater than the minimum tick width uint256 token0Type = configManager.getTypedToken(token0); uint256 token1Type = configManager.getTypedToken(token1); int24 minTickWidth = token0Type == token1Type && token0Type > 0 && token1Type > 0 ? rangeConfig.tickWidthTypedMin : rangeConfig.tickWidthMin; require(tickUpper - tickLower >= minTickWidth, InvalidTickWidth()); } function validateObservationCardinality(INFPM nfpm, uint24 fee, address token0, address token1) external view { address pool = IUniswapV3Factory(nfpm.factory()).getPool(token0, token1, fee); (,,, uint16 observationCardinality,,,) = IUniswapV3Pool(pool).slot0(); require(observationCardinality >= 2, InvalidObservationCardinality()); } /// @dev Check average price of the last 2 observed ticks compares to current tick /// @param pool The pool to check the price function validatePriceSanity(address pool) external view override { // get the observed price before this block unchecked { (, int24 tick, uint16 observationIndex, uint16 cardinality,,,) = IUniswapV3Pool(pool).slot0(); require(cardinality > 0, InvalidObservationCardinality()); uint32 lastTimestamp; int56 lastTickCummulative; uint32 secondLastTimestamp; int56 secondLastTickCummulative; bool initialized; (lastTimestamp, lastTickCummulative,, initialized) = IUniswapV3Pool(pool).observations(observationIndex); require(initialized, InvalidObservation()); if (observationIndex == 0) observationIndex = cardinality - 1; else observationIndex--; (secondLastTimestamp, secondLastTickCummulative,, initialized) = IUniswapV3Pool(pool).observations(observationIndex); require(initialized, InvalidObservation()); require(lastTimestamp > secondLastTimestamp, InvalidObservation()); int24 lastTick = int24((lastTickCummulative - secondLastTickCummulative) / int32(lastTimestamp - secondLastTimestamp)); require( -configManager.maxHarvestSlippage() < tick - lastTick && tick - lastTick < configManager.maxHarvestSlippage(), PriceSanityCheckFailed() ); // ~5% } } /// @dev Checks if the pool is allowed /// @param config The configuration of the strategy /// @param pool The pool to check /// @return allowed If the pool is allowed function _isPoolAllowed(VaultConfig memory config, address pool) internal pure returns (bool) { if (config.supportedAddresses.length == 0) return true; uint256 length = config.supportedAddresses.length; for (uint256 i; i < length;) { if (config.supportedAddresses[i] == pool) return true; unchecked { i++; } } return false; } function setWhitelistNfpms(address[] calldata _whitelistNfpms, bool isWhitelist) external onlyOwner { for (uint256 i; i < _whitelistNfpms.length; i++) { whitelistNfpms[_whitelistNfpms[i]] = isWhitelist; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol) pragma solidity ^0.8.20; import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol"; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * The initial owner is set to the address provided by the deployer. This can * later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { /// @custom:storage-location erc7201:openzeppelin.storage.Ownable struct OwnableStorage { address _owner; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300; function _getOwnableStorage() private pure returns (OwnableStorage storage $) { assembly { $.slot := OwnableStorageLocation } } /** * @dev The caller account is not authorized to perform an operation. */ error OwnableUnauthorizedAccount(address account); /** * @dev The owner is not a valid owner account. (eg. `address(0)`) */ error OwnableInvalidOwner(address owner); event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the address provided by the deployer as the initial owner. */ function __Ownable_init(address initialOwner) internal onlyInitializing { __Ownable_init_unchained(initialOwner); } function __Ownable_init_unchained(address initialOwner) internal onlyInitializing { if (initialOwner == address(0)) { revert OwnableInvalidOwner(address(0)); } _transferOwnership(initialOwner); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { OwnableStorage storage $ = _getOwnableStorage(); return $._owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { if (owner() != _msgSender()) { revert OwnableUnauthorizedAccount(_msgSender()); } } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby disabling any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _transferOwnership(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { if (newOwner == address(0)) { revert OwnableInvalidOwner(address(0)); } _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { OwnableStorage storage $ = _getOwnableStorage(); address oldOwner = $._owner; $._owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.20; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ```solidity * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Storage of the initializable contract. * * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions * when using with upgradeable contracts. * * @custom:storage-location erc7201:openzeppelin.storage.Initializable */ struct InitializableStorage { /** * @dev Indicates that the contract has been initialized. */ uint64 _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool _initializing; } // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00; /** * @dev The contract is already initialized. */ error InvalidInitialization(); /** * @dev The contract is not initializing. */ error NotInitializing(); /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint64 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in * production. * * Emits an {Initialized} event. */ modifier initializer() { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); // Cache values to avoid duplicated sloads bool isTopLevelCall = !$._initializing; uint64 initialized = $._initialized; // Allowed calls: // - initialSetup: the contract is not in the initializing state and no previous version was // initialized // - construction: the contract is initialized at version 1 (no reininitialization) and the // current contract is just being deployed bool initialSetup = initialized == 0 && isTopLevelCall; bool construction = initialized == 1 && address(this).code.length == 0; if (!initialSetup && !construction) { revert InvalidInitialization(); } $._initialized = 1; if (isTopLevelCall) { $._initializing = true; } _; if (isTopLevelCall) { $._initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint64 version) { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing || $._initialized >= version) { revert InvalidInitialization(); } $._initialized = version; $._initializing = true; _; $._initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { _checkInitializing(); _; } /** * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}. */ function _checkInitializing() internal view virtual { if (!_isInitializing()) { revert NotInitializing(); } } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { // solhint-disable-next-line var-name-mixedcase InitializableStorage storage $ = _getInitializableStorage(); if ($._initializing) { revert InvalidInitialization(); } if ($._initialized != type(uint64).max) { $._initialized = type(uint64).max; emit Initialized(type(uint64).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint64) { return _getInitializableStorage()._initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _getInitializableStorage()._initializing; } /** * @dev Returns a pointer to the storage namespace. */ // solhint-disable-next-line var-name-mixedcase function _getInitializableStorage() private pure returns (InitializableStorage storage $) { assembly { $.slot := INITIALIZABLE_STORAGE } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) pragma solidity ^0.8.20; import {Initializable} from "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } 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.1.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-20 standard as defined in the ERC. */ 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/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/extensions/IERC721Metadata.sol) pragma solidity ^0.8.20; import {IERC721} from "../IERC721.sol"; /** * @title ERC-721 Non-Fungible Token Standard, optional metadata extension * @dev See https://eips.ethereum.org/EIPS/eip-721 */ interface IERC721Metadata is IERC721 { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.1.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.20; import {IERC165} from "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC-721 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 ERC-721 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 ERC-721 * 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.1.0) (utils/introspection/IERC165.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC-165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[ERC]. * * 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[ERC section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import './pool/IPancakeV3PoolImmutables.sol'; import './pool/IPancakeV3PoolState.sol'; import './pool/IPancakeV3PoolDerivedState.sol'; import './pool/IPancakeV3PoolActions.sol'; import './pool/IPancakeV3PoolOwnerActions.sol'; import './pool/IPancakeV3PoolEvents.sol'; /// @title The interface for a PancakeSwap V3 Pool /// @notice A PancakeSwap pool facilitates swapping and automated market making between any two assets that strictly conform /// to the ERC20 specification /// @dev The pool interface is broken up into many smaller pieces interface IPancakeV3Pool is IPancakeV3PoolImmutables, IPancakeV3PoolState, IPancakeV3PoolDerivedState, IPancakeV3PoolActions, IPancakeV3PoolOwnerActions, IPancakeV3PoolEvents { }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissionless pool actions /// @notice Contains pool methods that can be called by anyone interface IPancakeV3PoolActions { /// @notice Sets the initial price for the pool /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96 function initialize(uint160 sqrtPriceX96) external; /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position /// @dev The caller of this method receives a callback in the form of IPancakeV3MintCallback#pancakeV3MintCallback /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends /// on tickLower, tickUpper, the amount of liquidity, and the current price. /// @param recipient The address for which the liquidity will be created /// @param tickLower The lower tick of the position in which to add liquidity /// @param tickUpper The upper tick of the position in which to add liquidity /// @param amount The amount of liquidity to mint /// @param data Any data that should be passed through to the callback /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback function mint( address recipient, int24 tickLower, int24 tickUpper, uint128 amount, bytes calldata data ) external returns (uint256 amount0, uint256 amount1); /// @notice Collects tokens owed to a position /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity. /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity. /// @param recipient The address which should receive the fees collected /// @param tickLower The lower tick of the position for which to collect fees /// @param tickUpper The upper tick of the position for which to collect fees /// @param amount0Requested How much token0 should be withdrawn from the fees owed /// @param amount1Requested How much token1 should be withdrawn from the fees owed /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect( address recipient, int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0 /// @dev Fees must be collected separately via a call to #collect /// @param tickLower The lower tick of the position for which to burn liquidity /// @param tickUpper The upper tick of the position for which to burn liquidity /// @param amount How much liquidity to burn /// @return amount0 The amount of token0 sent to the recipient /// @return amount1 The amount of token1 sent to the recipient function burn( int24 tickLower, int24 tickUpper, uint128 amount ) external returns (uint256 amount0, uint256 amount1); /// @notice Swap token0 for token1, or token1 for token0 /// @dev The caller of this method receives a callback in the form of IPancakeV3SwapCallback#pancakeV3SwapCallback /// @param recipient The address to receive the output of the swap /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0 /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative) /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this /// value after the swap. If one for zero, the price cannot be greater than this value after the swap /// @param data Any data to be passed through to the callback /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive function swap( address recipient, bool zeroForOne, int256 amountSpecified, uint160 sqrtPriceLimitX96, bytes calldata data ) external returns (int256 amount0, int256 amount1); /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback /// @dev The caller of this method receives a callback in the form of IPancakeV3FlashCallback#pancakeV3FlashCallback /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling /// with 0 amount{0,1} and sending the donation amount(s) from the callback /// @param recipient The address which will receive the token0 and token1 amounts /// @param amount0 The amount of token0 to send /// @param amount1 The amount of token1 to send /// @param data Any data to be passed through to the callback function flash( address recipient, uint256 amount0, uint256 amount1, bytes calldata data ) external; /// @notice Increase the maximum number of price and liquidity observations that this pool will store /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to /// the input observationCardinalityNext. /// @param observationCardinalityNext The desired minimum number of observations for the pool to store function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that is not stored /// @notice Contains view functions to provide information about the pool that is computed rather than stored on the /// blockchain. The functions here may have variable gas costs. interface IPancakeV3PoolDerivedState { /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick, /// you must call it with secondsAgos = [3600, 0]. /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio. /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block /// timestamp function observe(uint32[] calldata secondsAgos) external view returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s); /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed. /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first /// snapshot is taken and the second snapshot is taken. /// @param tickLower The lower tick of the range /// @param tickUpper The upper tick of the range /// @return tickCumulativeInside The snapshot of the tick accumulator for the range /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range /// @return secondsInside The snapshot of seconds per liquidity for the range function snapshotCumulativesInside(int24 tickLower, int24 tickUpper) external view returns ( int56 tickCumulativeInside, uint160 secondsPerLiquidityInsideX128, uint32 secondsInside ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Events emitted by a pool /// @notice Contains all events emitted by the pool interface IPancakeV3PoolEvents { /// @notice Emitted exactly once by a pool when #initialize is first called on the pool /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96 /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool event Initialize(uint160 sqrtPriceX96, int24 tick); /// @notice Emitted when liquidity is minted for a given position /// @param sender The address that minted the liquidity /// @param owner The owner of the position and recipient of any minted liquidity /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity minted to the position range /// @param amount0 How much token0 was required for the minted liquidity /// @param amount1 How much token1 was required for the minted liquidity event Mint( address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted when fees are collected by the owner of a position /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees /// @param owner The owner of the position for which fees are collected /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount0 The amount of token0 fees collected /// @param amount1 The amount of token1 fees collected event Collect( address indexed owner, address recipient, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount0, uint128 amount1 ); /// @notice Emitted when a position's liquidity is removed /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect /// @param owner The owner of the position for which liquidity is removed /// @param tickLower The lower tick of the position /// @param tickUpper The upper tick of the position /// @param amount The amount of liquidity to remove /// @param amount0 The amount of token0 withdrawn /// @param amount1 The amount of token1 withdrawn event Burn( address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1 ); /// @notice Emitted by the pool for any swaps between token0 and token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the output of the swap /// @param amount0 The delta of the token0 balance of the pool /// @param amount1 The delta of the token1 balance of the pool /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96 /// @param liquidity The liquidity of the pool after the swap /// @param tick The log base 1.0001 of price of the pool after the swap /// @param protocolFeesToken0 The protocol fee of token0 in the swap /// @param protocolFeesToken1 The protocol fee of token1 in the swap event Swap( address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick, uint128 protocolFeesToken0, uint128 protocolFeesToken1 ); /// @notice Emitted by the pool for any flashes of token0/token1 /// @param sender The address that initiated the swap call, and that received the callback /// @param recipient The address that received the tokens from flash /// @param amount0 The amount of token0 that was flashed /// @param amount1 The amount of token1 that was flashed /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee event Flash( address indexed sender, address indexed recipient, uint256 amount0, uint256 amount1, uint256 paid0, uint256 paid1 ); /// @notice Emitted by the pool for increases to the number of observations that can be stored /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index /// just before a mint/swap/burn. /// @param observationCardinalityNextOld The previous value of the next observation cardinality /// @param observationCardinalityNextNew The updated value of the next observation cardinality event IncreaseObservationCardinalityNext( uint16 observationCardinalityNextOld, uint16 observationCardinalityNextNew ); /// @notice Emitted when the protocol fee is changed by the pool /// @param feeProtocol0Old The previous value of the token0 protocol fee /// @param feeProtocol1Old The previous value of the token1 protocol fee /// @param feeProtocol0New The updated value of the token0 protocol fee /// @param feeProtocol1New The updated value of the token1 protocol fee event SetFeeProtocol( uint32 feeProtocol0Old, uint32 feeProtocol1Old, uint32 feeProtocol0New, uint32 feeProtocol1New ); /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner /// @param sender The address that collects the protocol fees /// @param recipient The address that receives the collected protocol fees /// @param amount0 The amount of token0 protocol fees that is withdrawn /// @param amount0 The amount of token1 protocol fees that is withdrawn event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that never changes /// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values interface IPancakeV3PoolImmutables { /// @notice The contract that deployed the pool, which must adhere to the IPancakeV3Factory interface /// @return The contract address function factory() external view returns (address); /// @notice The first of the two tokens of the pool, sorted by address /// @return The token contract address function token0() external view returns (address); /// @notice The second of the two tokens of the pool, sorted by address /// @return The token contract address function token1() external view returns (address); /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6 /// @return The fee function fee() external view returns (uint24); /// @notice The pool tick spacing /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ... /// This value is an int24 to avoid casting even though it is always positive. /// @return The tick spacing function tickSpacing() external view returns (int24); /// @notice The maximum amount of position liquidity that can use any tick in the range /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool /// @return The max amount of liquidity per tick function maxLiquidityPerTick() external view returns (uint128); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Permissioned pool actions /// @notice Contains pool methods that may only be called by the factory owner interface IPancakeV3PoolOwnerActions { /// @notice Set the denominator of the protocol's % share of the fees /// @param feeProtocol0 new protocol fee for token0 of the pool /// @param feeProtocol1 new protocol fee for token1 of the pool function setFeeProtocol(uint32 feeProtocol0, uint32 feeProtocol1) external; /// @notice Collect the protocol fee accrued to the pool /// @param recipient The address to which collected protocol fees should be sent /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1 /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0 /// @return amount0 The protocol fee collected in token0 /// @return amount1 The protocol fee collected in token1 function collectProtocol( address recipient, uint128 amount0Requested, uint128 amount1Requested ) external returns (uint128 amount0, uint128 amount1); /// @notice Set the LM pool to enable liquidity mining function setLmPool(address lmPool) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Pool state that can change /// @notice These methods compose the pool's state, and can change with any frequency including multiple times /// per transaction interface IPancakeV3PoolState { /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas /// when accessed externally. /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value /// tick The current tick of the pool, i.e. according to the last tick transition that was run. /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick /// boundary. /// observationIndex The index of the last oracle observation that was written, /// observationCardinality The current maximum number of observations stored in the pool, /// observationCardinalityNext The next maximum number of observations, to be updated when the observation. /// feeProtocol The protocol fee for both tokens of the pool. /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0 /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee. /// unlocked Whether the pool is currently locked to reentrancy function slot0() external view returns ( uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint32 feeProtocol, bool unlocked ); /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal0X128() external view returns (uint256); /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool /// @dev This value can overflow the uint256 function feeGrowthGlobal1X128() external view returns (uint256); /// @notice The amounts of token0 and token1 that are owed to the protocol /// @dev Protocol fees will never exceed uint128 max in either token function protocolFees() external view returns (uint128 token0, uint128 token1); /// @notice The currently in range liquidity available to the pool /// @dev This value has no relationship to the total liquidity across all ticks function liquidity() external view returns (uint128); /// @notice Look up information about a specific tick in the pool /// @param tick The tick to look up /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or /// tick upper, /// liquidityNet how much liquidity changes when the pool price crosses the tick, /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0, /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1, /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick, /// secondsOutside the seconds spent on the other side of the tick from the current tick, /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false. /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0. /// In addition, these values are only relative and must be used only in comparison to previous snapshots for /// a specific position. function ticks(int24 tick) external view returns ( uint128 liquidityGross, int128 liquidityNet, uint256 feeGrowthOutside0X128, uint256 feeGrowthOutside1X128, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized ); /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information function tickBitmap(int16 wordPosition) external view returns (uint256); /// @notice Returns the information about a position by the position's key /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper /// @return _liquidity The amount of liquidity in the position, /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke, /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke, /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke, /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke function positions(bytes32 key) external view returns ( uint128 _liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); /// @notice Returns data about a specific observation index /// @param index The element of the observations array to fetch /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time /// ago, rather than at a specific index in the array. /// @return blockTimestamp The timestamp of the observation, /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp, /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp, /// Returns initialized whether the observation has been initialized and the values are safe to use function observations(uint256 index) external view returns ( uint32 blockTimestamp, int56 tickCumulative, uint160 secondsPerLiquidityCumulativeX128, bool initialized ); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title The interface for the Uniswap V3 Factory /// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees interface IUniswapV3Factory { /// @notice Emitted when the owner of the factory is changed /// @param oldOwner The owner before the owner was changed /// @param newOwner The owner after the owner was changed event OwnerChanged(address indexed oldOwner, address indexed newOwner); /// @notice Emitted when a pool is created /// @param token0 The first token of the pool by address sort order /// @param token1 The second token of the pool by address sort order /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip /// @param tickSpacing The minimum number of ticks between initialized ticks /// @param pool The address of the created pool event PoolCreated( address indexed token0, address indexed token1, uint24 indexed fee, int24 tickSpacing, address pool ); /// @notice Emitted when a new fee amount is enabled for pool creation via the factory /// @param fee The enabled fee, denominated in hundredths of a bip /// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing); /// @notice Returns the current owner of the factory /// @dev Can be changed by the current owner via setOwner /// @return The address of the factory owner function owner() external view returns (address); /// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled /// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context /// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee /// @return The tick spacing function feeAmountTickSpacing(uint24 fee) external view returns (int24); /// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order /// @param tokenA The contract address of either token0 or token1 /// @param tokenB The contract address of the other token /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip /// @return pool The pool address function getPool( address tokenA, address tokenB, uint24 fee ) external view returns (address pool); /// @notice Creates a pool for the given two tokens and fee /// @param tokenA One of the two tokens in the desired pool /// @param tokenB The other of the two tokens in the desired pool /// @param fee The desired fee for the pool /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved /// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments /// are invalid. /// @return pool The address of the newly created pool function createPool( address tokenA, address tokenB, uint24 fee ) external returns (address pool); /// @notice Updates the owner of the factory /// @dev Must be called by the current owner /// @param _owner The new owner of the factory function setOwner(address _owner) external; /// @notice Enables a fee amount with the given tickSpacing /// @dev Fee amounts may never be removed once enabled /// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6) /// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount function enableFeeAmount(uint24 fee, int24 tickSpacing) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.4.0; /// @title FixedPoint96 /// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format) /// @dev Used in SqrtPriceMath.sol library FixedPoint96 { uint8 internal constant RESOLUTION = 96; uint256 internal constant Q96 = 0x1000000000000000000000000; }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Contains 512-bit math functions /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits library FullMath { /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv function mulDiv( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = a * b // Compute the product mod 2**256 and mod 2**256 - 1 // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2**256 + prod0 uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(a, b, not(0)) prod0 := mul(a, b) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division if (prod1 == 0) { require(denominator > 0); assembly { result := div(prod0, denominator) } return result; } // Make sure the result is less than 2**256. // Also prevents denominator == 0 require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0] // Compute remainder using mulmod uint256 remainder; assembly { remainder := mulmod(a, b, denominator) } // Subtract 256 bit number from 512 bit number assembly { prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator // Compute largest power of two divisor of denominator. // Always >= 1. uint256 twos = (0 - denominator) & denominator; // Divide denominator by power of two assembly { denominator := div(denominator, twos) } // Divide [prod1 prod0] by the factors of two assembly { prod0 := div(prod0, twos) } // Shift in bits from prod1 into prod0. For this we need // to flip `twos` such that it is 2**256 / twos. // If twos is zero, then it becomes one assembly { twos := add(div(sub(0, twos), twos), 1) } prod0 |= prod1 * twos; // Invert denominator mod 2**256 // Now that denominator is an odd number, it has an inverse // modulo 2**256 such that denominator * inv = 1 mod 2**256. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, denominator * inv = 1 mod 2**4 uint256 inv = (3 * denominator) ^ 2; // Now use Newton-Raphson iteration to improve the precision. // Thanks to Hensel's lifting lemma, this also works in modular // arithmetic, doubling the correct bits in each step. inv *= 2 - denominator * inv; // inverse mod 2**8 inv *= 2 - denominator * inv; // inverse mod 2**16 inv *= 2 - denominator * inv; // inverse mod 2**32 inv *= 2 - denominator * inv; // inverse mod 2**64 inv *= 2 - denominator * inv; // inverse mod 2**128 inv *= 2 - denominator * inv; // inverse mod 2**256 // Because the division is now exact we can divide by multiplying // with the modular inverse of denominator. This will give us the // correct result modulo 2**256. Since the precoditions guarantee // that the outcome is less than 2**256, this is the final result. // We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inv; return result; } } /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 /// @param a The multiplicand /// @param b The multiplier /// @param denominator The divisor /// @return result The 256-bit result function mulDivRoundingUp( uint256 a, uint256 b, uint256 denominator ) internal pure returns (uint256 result) { unchecked { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max); result++; } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.0; /// @title Math library for computing sqrt prices from ticks and vice versa /// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports /// prices between 2**-128 and 2**128 library TickMath { error T(); error R(); /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 int24 internal constant MIN_TICK = -887272; /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 int24 internal constant MAX_TICK = -MIN_TICK; /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) uint160 internal constant MIN_SQRT_RATIO = 4295128739; /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342; /// @notice Calculates sqrt(1.0001^tick) * 2^96 /// @dev Throws if |tick| > max tick /// @param tick The input tick for the above formula /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) /// at the given tick function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) { unchecked { uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick)); if (absTick > uint256(int256(MAX_TICK))) revert T(); uint256 ratio = absTick & 0x1 != 0 ? 0xfffcb933bd6fad37aa2d162d1a594001 : 0x100000000000000000000000000000000; if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128; if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128; if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128; if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128; if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128; if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128; if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128; if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128; if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128; if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128; if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128; if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128; if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128; if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128; if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128; if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128; if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128; if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128; if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128; if (tick > 0) ratio = type(uint256).max / ratio; // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96. // we then downcast because we know the result always fits within 160 bits due to our tick input constraint // we round up in the division so getTickAtSqrtRatio of the output price is always consistent sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1)); } } /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may /// ever return. /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96 /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) { unchecked { // second inequality must be < because the price can never reach the price at the max tick if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) revert R(); uint256 ratio = uint256(sqrtPriceX96) << 32; uint256 r = ratio; uint256 msb = 0; assembly { let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(5, gt(r, 0xFFFFFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(4, gt(r, 0xFFFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(3, gt(r, 0xFF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(2, gt(r, 0xF)) msb := or(msb, f) r := shr(f, r) } assembly { let f := shl(1, gt(r, 0x3)) msb := or(msb, f) r := shr(f, r) } assembly { let f := gt(r, 0x1) msb := or(msb, f) } if (msb >= 128) r = ratio >> (msb - 127); else r = ratio << (127 - msb); int256 log_2 = (int256(msb) - 128) << 64; assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(63, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(62, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(61, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(60, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(59, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(58, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(57, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(56, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(55, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(54, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(53, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(52, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(51, f)) r := shr(f, r) } assembly { r := shr(127, mul(r, r)) let f := shr(128, r) log_2 := or(log_2, shl(50, f)) } int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128); int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128); tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow; } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; import '@openzeppelin/contracts/token/ERC721/IERC721.sol'; /// @title ERC721 with permit /// @notice Extension to ERC721 that includes a permit function for signature based approvals interface IERC721Permit is IERC721 { /// @notice The permit typehash used in the permit signature /// @return The typehash for the permit function PERMIT_TYPEHASH() external pure returns (bytes32); /// @notice The domain separator used in the permit signature /// @return The domain seperator used in encoding of permit signature function DOMAIN_SEPARATOR() external view returns (bytes32); /// @notice Approve of a specific token ID for spending by spender via signature /// @param spender The account that is being approved /// @param tokenId The ID of the token that is being approved for spending /// @param deadline The deadline timestamp by which the call must be mined for the approve to work /// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s` /// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s` /// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v` function permit( address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol'; import './IPoolInitializer.sol'; import './IERC721Permit.sol'; import './IPeripheryPayments.sol'; import './IPeripheryImmutableState.sol'; import '../libraries/PoolAddress.sol'; /// @title Non-fungible token for positions /// @notice Wraps Uniswap V3 positions in a non-fungible token interface which allows for them to be transferred /// and authorized. interface INonfungiblePositionManager is IPoolInitializer, IPeripheryPayments, IPeripheryImmutableState, IERC721Metadata, IERC721Enumerable, IERC721Permit { /// @notice Emitted when liquidity is increased for a position NFT /// @dev Also emitted when a token is minted /// @param tokenId The ID of the token for which liquidity was increased /// @param liquidity The amount by which liquidity for the NFT position was increased /// @param amount0 The amount of token0 that was paid for the increase in liquidity /// @param amount1 The amount of token1 that was paid for the increase in liquidity event IncreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); /// @notice Emitted when liquidity is decreased for a position NFT /// @param tokenId The ID of the token for which liquidity was decreased /// @param liquidity The amount by which liquidity for the NFT position was decreased /// @param amount0 The amount of token0 that was accounted for the decrease in liquidity /// @param amount1 The amount of token1 that was accounted for the decrease in liquidity event DecreaseLiquidity(uint256 indexed tokenId, uint128 liquidity, uint256 amount0, uint256 amount1); /// @notice Emitted when tokens are collected for a position NFT /// @dev The amounts reported may not be exactly equivalent to the amounts transferred, due to rounding behavior /// @param tokenId The ID of the token for which underlying tokens were collected /// @param recipient The address of the account that received the collected tokens /// @param amount0 The amount of token0 owed to the position that was collected /// @param amount1 The amount of token1 owed to the position that was collected event Collect(uint256 indexed tokenId, address recipient, uint256 amount0, uint256 amount1); /// @notice Returns the position information associated with a given token ID. /// @dev Throws if the token ID is not valid. /// @param tokenId The ID of the token that represents the position /// @return nonce The nonce for permits /// @return operator The address that is approved for spending /// @return token0 The address of the token0 for a specific pool /// @return token1 The address of the token1 for a specific pool /// @return fee The fee associated with the pool /// @return tickLower The lower end of the tick range for the position /// @return tickUpper The higher end of the tick range for the position /// @return liquidity The liquidity of the position /// @return feeGrowthInside0LastX128 The fee growth of token0 as of the last action on the individual position /// @return feeGrowthInside1LastX128 The fee growth of token1 as of the last action on the individual position /// @return tokensOwed0 The uncollected amount of token0 owed to the position as of the last computation /// @return tokensOwed1 The uncollected amount of token1 owed to the position as of the last computation function positions(uint256 tokenId) external view returns ( uint96 nonce, address operator, address token0, address token1, uint24 fee, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128, uint128 tokensOwed0, uint128 tokensOwed1 ); struct MintParams { address token0; address token1; uint24 fee; int24 tickLower; int24 tickUpper; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; address recipient; uint256 deadline; } /// @notice Creates a new position wrapped in a NFT /// @dev Call this when the pool does exist and is initialized. Note that if the pool is created but not initialized /// a method does not exist, i.e. the pool is assumed to be initialized. /// @param params The params necessary to mint a position, encoded as `MintParams` in calldata /// @return tokenId The ID of the token that represents the minted position /// @return liquidity The amount of liquidity for this position /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function mint(MintParams calldata params) external payable returns ( uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1 ); struct IncreaseLiquidityParams { uint256 tokenId; uint256 amount0Desired; uint256 amount1Desired; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Increases the amount of liquidity in a position, with tokens paid by the `msg.sender` /// @param params tokenId The ID of the token for which liquidity is being increased, /// amount0Desired The desired amount of token0 to be spent, /// amount1Desired The desired amount of token1 to be spent, /// amount0Min The minimum amount of token0 to spend, which serves as a slippage check, /// amount1Min The minimum amount of token1 to spend, which serves as a slippage check, /// deadline The time by which the transaction must be included to effect the change /// @return liquidity The new liquidity amount as a result of the increase /// @return amount0 The amount of token0 to acheive resulting liquidity /// @return amount1 The amount of token1 to acheive resulting liquidity function increaseLiquidity(IncreaseLiquidityParams calldata params) external payable returns ( uint128 liquidity, uint256 amount0, uint256 amount1 ); struct DecreaseLiquidityParams { uint256 tokenId; uint128 liquidity; uint256 amount0Min; uint256 amount1Min; uint256 deadline; } /// @notice Decreases the amount of liquidity in a position and accounts it to the position /// @param params tokenId The ID of the token for which liquidity is being decreased, /// amount The amount by which liquidity will be decreased, /// amount0Min The minimum amount of token0 that should be accounted for the burned liquidity, /// amount1Min The minimum amount of token1 that should be accounted for the burned liquidity, /// deadline The time by which the transaction must be included to effect the change /// @return amount0 The amount of token0 accounted to the position's tokens owed /// @return amount1 The amount of token1 accounted to the position's tokens owed function decreaseLiquidity(DecreaseLiquidityParams calldata params) external payable returns (uint256 amount0, uint256 amount1); struct CollectParams { uint256 tokenId; address recipient; uint128 amount0Max; uint128 amount1Max; } /// @notice Collects up to a maximum amount of fees owed to a specific position to the recipient /// @param params tokenId The ID of the NFT for which tokens are being collected, /// recipient The account that should receive the tokens, /// amount0Max The maximum amount of token0 to collect, /// amount1Max The maximum amount of token1 to collect /// @return amount0 The amount of fees collected in token0 /// @return amount1 The amount of fees collected in token1 function collect(CollectParams calldata params) external payable returns (uint256 amount0, uint256 amount1); /// @notice Burns a token ID, which deletes it from the NFT contract. The token must have 0 liquidity and all tokens /// must be collected first. /// @param tokenId The ID of the token that is being burned function burn(uint256 tokenId) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Immutable state /// @notice Functions that return immutable state of the router interface IPeripheryImmutableState { /// @return Returns the address of the Uniswap V3 factory function factory() external view returns (address); /// @return Returns the address of WETH9 function WETH9() external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; /// @title Periphery Payments /// @notice Functions to ease deposits and withdrawals of ETH interface IPeripheryPayments { /// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH. /// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users. /// @param amountMinimum The minimum amount of WETH9 to unwrap /// @param recipient The address receiving ETH function unwrapWETH9(uint256 amountMinimum, address recipient) external payable; /// @notice Refunds any ETH balance held by this contract to the `msg.sender` /// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps /// that use ether for the input amount function refundETH() external payable; /// @notice Transfers the full amount of a token held by this contract to recipient /// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users /// @param token The contract address of the token which will be transferred to `recipient` /// @param amountMinimum The minimum amount of token required for a transfer /// @param recipient The destination address of the token function sweepToken( address token, uint256 amountMinimum, address recipient ) external payable; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; /// @title Creates and initializes V3 Pools /// @notice Provides a method for creating and initializing a pool, if necessary, for bundling with other methods that /// require the pool to exist. interface IPoolInitializer { /// @notice Creates a new pool if it does not exist, then initializes if not initialized /// @dev This method can be bundled with others via IMulticall for the first action (e.g. mint) performed against a pool /// @param token0 The contract address of token0 of the pool /// @param token1 The contract address of token1 of the pool /// @param fee The fee amount of the v3 pool for the specified token pair /// @param sqrtPriceX96 The initial square root price of the pool as a Q64.96 value /// @return pool Returns the pool address based on the pair of tokens and fee, will return the newly created pool address if necessary function createAndInitializePoolIfNecessary( address token0, address token1, uint24 fee, uint160 sqrtPriceX96 ) external payable returns (address pool); }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; import '@uniswap/v3-core/contracts/libraries/FullMath.sol'; import '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol'; /// @title Liquidity amount functions /// @notice Provides functions for computing liquidity amounts from token amounts and prices library LiquidityAmounts { /// @notice Downcasts uint256 to uint128 /// @param x The uint258 to be downcasted /// @return y The passed value, downcasted to uint128 function toUint128(uint256 x) private pure returns (uint128 y) { require((y = uint128(x)) == x); } /// @notice Computes the amount of liquidity received for a given amount of token0 and price range /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower)) /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount0 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount0( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96); unchecked { return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96)); } } /// @notice Computes the amount of liquidity received for a given amount of token1 and price range /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)). /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount1 The amount1 being sent in /// @return liquidity The amount of returned liquidity function getLiquidityForAmount1( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); unchecked { return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96)); } } /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param amount0 The amount of token0 being sent in /// @param amount1 The amount of token1 being sent in /// @return liquidity The maximum amount of liquidity received function getLiquidityForAmounts( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount0, uint256 amount1 ) internal pure returns (uint128 liquidity) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0); } else if (sqrtRatioX96 < sqrtRatioBX96) { uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0); uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1); liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1; } else { liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1); } } /// @notice Computes the amount of token0 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 function getAmount0ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0) { unchecked { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); return FullMath.mulDiv( uint256(liquidity) << FixedPoint96.RESOLUTION, sqrtRatioBX96 - sqrtRatioAX96, sqrtRatioBX96 ) / sqrtRatioAX96; } } /// @notice Computes the amount of token1 for a given amount of liquidity and a price range /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount1 The amount of token1 function getAmount1ForLiquidity( uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); unchecked { return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96); } } /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current /// pool prices and the prices at the tick boundaries /// @param sqrtRatioX96 A sqrt price representing the current pool prices /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary /// @param liquidity The liquidity being valued /// @return amount0 The amount of token0 /// @return amount1 The amount of token1 function getAmountsForLiquidity( uint160 sqrtRatioX96, uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint128 liquidity ) internal pure returns (uint256 amount0, uint256 amount1) { if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96); if (sqrtRatioX96 <= sqrtRatioAX96) { amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } else if (sqrtRatioX96 < sqrtRatioBX96) { amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity); amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity); } else { amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity); } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.5.0; /// @title Provides functions for deriving a pool address from the factory, tokens, and the fee library PoolAddress { bytes32 internal constant POOL_INIT_CODE_HASH = 0xa598dd2fba360510c5a8f02f44423a4468e902df5857dbce3ca162a43a3a31ff; /// @notice The identifying key of the pool struct PoolKey { address token0; address token1; uint24 fee; } /// @notice Returns PoolKey: the ordered tokens with the matched fee levels /// @param tokenA The first token of a pool, unsorted /// @param tokenB The second token of a pool, unsorted /// @param fee The fee level of the pool /// @return Poolkey The pool details with ordered token0 and token1 assignments function getPoolKey( address tokenA, address tokenB, uint24 fee ) internal pure returns (PoolKey memory) { if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA); return PoolKey({token0: tokenA, token1: tokenB, fee: fee}); } /// @notice Deterministically computes the pool address given the factory and PoolKey /// @param factory The Uniswap V3 factory contract address /// @param key The PoolKey /// @return pool The contract address of the V3 pool function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) { require(key.token0 < key.token1); pool = address( uint160( uint256( keccak256( abi.encodePacked( hex'ff', factory, keccak256(abi.encode(key.token0, key.token1, key.fee)), POOL_INIT_CODE_HASH ) ) ) ) ); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.28; import "../ICommon.sol"; interface IConfigManager is ICommon { event MaxPositionsSet(uint8 _maxPositions); event MaxHarvestSlippageSet(int24 _maxHarvestSlippage); event VaultPausedSet(bool _isVaultPaused); event WhitelistStrategy(address[] _strategies, bool _isWhitelisted); event WhitelistSwapRouter(address[] _swapRouters, bool _isWhitelisted); event WhitelistAutomator(address[] _automators, bool _isWhitelisted); event WhitelistSigner(address[] _signers, bool _isWhitelisted); event SetStrategyConfig(address indexed _strategy, address indexed _principalToken, bytes _config); event SetTypedTokens(address[] _typedTokens, uint256[] _typedTokenTypes); event SetFeeConfig(bool allowDeposit, FeeConfig _feeConfig); function maxPositions() external view returns (uint8 _maxPositions); function maxHarvestSlippage() external view returns (int24 _maxHarvestSlippage); function isVaultPaused() external view returns (bool _isVaultPaused); function whitelistStrategy(address[] memory _strategies, bool _isWhitelisted) external; function isWhitelistedStrategy(address _strategy) external view returns (bool _isWhitelisted); function whitelistSwapRouter(address[] memory _swapRouters, bool _isWhitelisted) external; function isWhitelistedSwapRouter(address _swapRouter) external view returns (bool _isWhitelisted); function whitelistAutomator(address[] memory _automators, bool _isWhitelisted) external; function isWhitelistedAutomator(address _automator) external view returns (bool _isWhitelisted); function whitelistSigner(address[] memory signers, bool _isWhitelisted) external; function isWhitelistSigner(address signer) external view returns (bool _isWhitelisted); function getTypedTokens() external view returns (address[] memory _typedTokens, uint256[] memory _typedTokenTypes); function getTypedToken(address _token) external view returns (uint256 _type); function setTypedTokens(address[] memory _typedTokens, uint256[] memory _typedTokenTypes) external; function isMatchedWithType(address _token, uint256 _type) external view returns (bool); function getStrategyConfig(address _strategy, address _principalToken) external view returns (bytes memory); function setStrategyConfig(address _strategy, address _principalToken, bytes memory _config) external; function setMaxPositions(uint8 _maxPositions) external; function setMaxHarvestSlippage(int24 _maxHarvestSlippage) external; function setVaultPaused(bool _isVaultPaused) external; function setFeeConfig(bool allowDeposit, FeeConfig memory _feeConfig) external; function getFeeConfig(bool allowDeposit) external view returns (FeeConfig memory); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.28; interface ICommon { struct VaultConfig { bool allowDeposit; uint8 rangeStrategyType; uint8 tvlStrategyType; address principalToken; address[] supportedAddresses; } struct VaultCreateParams { string name; string symbol; uint256 principalTokenAmount; VaultConfig config; } struct FeeConfig { uint16 vaultOwnerFeeBasisPoint; address vaultOwner; uint16 platformFeeBasisPoint; address platformFeeRecipient; uint64 gasFeeX64; address gasFeeRecipient; } struct Instruction { uint8 instructionType; bytes params; } error ZeroAddress(); error TransferFailed(); error InvalidVaultConfig(); error InvalidFeeConfig(); error InvalidStrategy(); error InvalidSwapRouter(); error InvalidInstructionType(); error InvalidSigner(); error SignatureExpired(); error ApproveFailed(); error InvalidParams(); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.28; interface IFeeTaker { enum FeeType { PLATFORM, OWNER, GAS } event FeeCollected( address indexed vaultAddress, FeeType indexed feeType, address indexed recipient, address token, uint256 amount ); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.28; import "./IStrategy.sol"; import { INonfungiblePositionManager as INFPM } from "@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol"; interface ILpStrategy is IStrategy { enum InstructionType { // MintPosition, SwapAndMintPosition, // IncreaseLiquidity, SwapAndIncreaseLiquidity, DecreaseLiquidityAndSwap, SwapAndRebalancePosition, SwapAndCompound } event LpStrategyCompound( address vaultAddress, uint256 amount0Collected, uint256 amount1Collected, AssetLib.Asset[] compoundAssets ); struct MintPositionParams { INFPM nfpm; address token0; address token1; uint24 fee; int24 tickLower; int24 tickUpper; uint256 amount0Min; uint256 amount1Min; } struct SwapAndMintPositionParams { INFPM nfpm; address token0; address token1; uint24 fee; int24 tickLower; int24 tickUpper; uint256 amount0Min; uint256 amount1Min; bytes swapData; } struct IncreaseLiquidityParams { uint256 amount0Min; uint256 amount1Min; } struct SwapAndIncreaseLiquidityParams { uint256 amount0Min; uint256 amount1Min; bytes swapData; } struct DecreaseLiquidityParams { uint128 liquidity; uint256 amount0Min; uint256 amount1Min; } struct DecreaseLiquidityAndSwapParams { uint128 liquidity; uint256 amount0Min; uint256 amount1Min; uint256 principalAmountOutMin; bytes swapData; } struct SwapAndRebalancePositionParams { int24 tickLower; int24 tickUpper; uint256 decreasedAmount0Min; uint256 decreasedAmount1Min; uint256 amount0Min; uint256 amount1Min; bool compoundFee; uint256 compoundFeeAmountOutMin; bytes swapData; } struct SwapAndCompoundParams { uint256 amount0Min; uint256 amount1Min; bytes swapData; } struct SwapFromPrincipalParams { uint256 principalTokenAmount; address pool; address principalToken; address otherToken; int24 tickLower; int24 tickUpper; bytes swapData; } struct SwapToPrincipalParams { address pool; address principalToken; address token; uint256 amount; uint256 amountOutMin; bytes swapData; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.28; import { INonfungiblePositionManager as INFPM } from "@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol"; import "../ICommon.sol"; interface ILpValidator is ICommon { struct LpStrategyConfig { LpStrategyRangeConfig[] rangeConfigs; LpStrategyTvlConfig[] tvlConfigs; } struct LpStrategyRangeConfig { int24 tickWidthMin; int24 tickWidthTypedMin; } struct LpStrategyTvlConfig { uint256 principalTokenAmountMin; } function validateConfig( INFPM nfpm, uint24 fee, address token0, address token1, int24 tickLower, int24 tickUpper, VaultConfig calldata config ) external view; function validateTickWidth( address token0, address token1, int24 tickLower, int24 tickUpper, VaultConfig calldata config ) external view; function validateObservationCardinality(INFPM nfpm, uint24 fee, address token0, address token1) external view; function validatePriceSanity(address pool) external view; function validateNfpm(address nfpm) external view; error InvalidPool(); error InvalidNfpm(); error InvalidPoolAmountMin(); error InvalidTickWidth(); error InvalidObservationCardinality(); error InvalidObservation(); error PriceSanityCheckFailed(); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.28; import "../ICommon.sol"; import { AssetLib } from "../../libraries/AssetLib.sol"; import { IFeeTaker } from "./IFeeTaker.sol"; interface IStrategy is ICommon, IFeeTaker { error InvalidAsset(); error InvalidNumberOfAssets(); error InsufficientAmountOut(); function valueOf(AssetLib.Asset calldata asset, address principalToken) external view returns (uint256); function convert( AssetLib.Asset[] calldata assets, VaultConfig calldata config, FeeConfig calldata feeConfig, bytes calldata data ) external payable returns (AssetLib.Asset[] memory); function harvest( AssetLib.Asset calldata asset, address tokenOut, uint256 amountTokenOutMin, VaultConfig calldata vaultConfig, FeeConfig calldata feeConfig ) external payable returns (AssetLib.Asset[] memory); function convertFromPrincipal( AssetLib.Asset calldata existingAsset, uint256 principalTokenAmount, VaultConfig calldata config ) external payable returns (AssetLib.Asset[] memory); function convertToPrincipal( AssetLib.Asset memory existingAsset, uint256 shares, uint256 totalSupply, VaultConfig calldata config, FeeConfig calldata feeConfig ) external payable returns (AssetLib.Asset[] memory); function revalidate(AssetLib.Asset calldata asset, VaultConfig calldata config) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.8.28; library AssetLib { enum AssetType { ERC20, ERC721, ERC1155 } struct Asset { AssetType assetType; address strategy; address token; uint256 tokenId; uint256 amount; } }
{ "viaIR": true, "optimizer": { "enabled": true, "runs": 150 }, "evmVersion": "cancun", "metadata": { "bytecodeHash": "none" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"ApproveFailed","type":"error"},{"inputs":[],"name":"InvalidFeeConfig","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidInstructionType","type":"error"},{"inputs":[],"name":"InvalidNfpm","type":"error"},{"inputs":[],"name":"InvalidObservation","type":"error"},{"inputs":[],"name":"InvalidObservationCardinality","type":"error"},{"inputs":[],"name":"InvalidParams","type":"error"},{"inputs":[],"name":"InvalidPool","type":"error"},{"inputs":[],"name":"InvalidPoolAmountMin","type":"error"},{"inputs":[],"name":"InvalidSigner","type":"error"},{"inputs":[],"name":"InvalidStrategy","type":"error"},{"inputs":[],"name":"InvalidSwapRouter","type":"error"},{"inputs":[],"name":"InvalidTickWidth","type":"error"},{"inputs":[],"name":"InvalidVaultConfig","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"PriceSanityCheckFailed","type":"error"},{"inputs":[],"name":"SignatureExpired","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"configManager","outputs":[{"internalType":"contract IConfigManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_configManager","type":"address"},{"internalType":"address[]","name":"_whitelistNfpms","type":"address[]"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_whitelistNfpms","type":"address[]"},{"internalType":"bool","name":"isWhitelist","type":"bool"}],"name":"setWhitelistNfpms","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"nfpm","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"components":[{"internalType":"bool","name":"allowDeposit","type":"bool"},{"internalType":"uint8","name":"rangeStrategyType","type":"uint8"},{"internalType":"uint8","name":"tvlStrategyType","type":"uint8"},{"internalType":"address","name":"principalToken","type":"address"},{"internalType":"address[]","name":"supportedAddresses","type":"address[]"}],"internalType":"struct ICommon.VaultConfig","name":"config","type":"tuple"}],"name":"validateConfig","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"nfpm","type":"address"}],"name":"validateNfpm","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract INonfungiblePositionManager","name":"nfpm","type":"address"},{"internalType":"uint24","name":"fee","type":"uint24"},{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"}],"name":"validateObservationCardinality","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"validatePriceSanity","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"components":[{"internalType":"bool","name":"allowDeposit","type":"bool"},{"internalType":"uint8","name":"rangeStrategyType","type":"uint8"},{"internalType":"uint8","name":"tvlStrategyType","type":"uint8"},{"internalType":"address","name":"principalToken","type":"address"},{"internalType":"address[]","name":"supportedAddresses","type":"address[]"}],"internalType":"struct ICommon.VaultConfig","name":"config","type":"tuple"}],"name":"validateTickWidth","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelistNfpms","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
6080806040523460155761154c908161001a8239f35b5f80fdfe6080806040526004361015610012575f80fd5b5f3560e01c9081630b25894b14610d9b57508063446e7fd014610d545780635925844d14610be8578063715018a614610b8157806377a24f36146109aa578063808d125f146105095780638da5cb5b146104d5578063c94a521d146101de578063ca0ab075146101b7578063de7a35ed1461010c578063f2fde38b146100e15763f4a9af63146100a0575f80fd5b346100dd5760203660031901126100dd576001600160a01b036100c1610f22565b165f526001602052602060ff60405f2054166040519015158152f35b5f80fd5b346100dd5760203660031901126100dd5761010a6100fd610f22565b610105611442565b6113d1565b005b346100dd5760403660031901126100dd576004356001600160401b0381116100dd57366023820112156100dd5780600401356001600160401b0381116100dd573660248260051b840101116100dd57602435908115158092036100dd5790610172611442565b60ff165f5b8281101561010a576001906001600160a01b0361019c600583901b8701602401611058565b165f528160205260405f208360ff1982541617905501610177565b346100dd575f3660031901126100dd575f546040516001600160a01b039091168152602090f35b346100dd5760203660031901126100dd576001600160a01b036101ff610f22565b16604051633850c7bd60e01b815260e081600481855afa9081156103b6575f905f905f9361049e575b5061ffff83161561048f5760405163252c09d760e01b815261ffff8216600482018190529093608085602481895afa9283156103b6575f935f965f91610464575b50156104115761ffff8092602492608095155f1461045957505f1901165b604051978893849263252c09d760e01b84521660048301525afa80156103b6575f905f955f91610420575b50156104115763ffffffff811663ffffffff831611156104115763ffffffff91031660030b80156103fd575f5460405163721c19f160e11b81526001600160a01b03909116949093602085600481895afa9485156103b6575f956103c1575b500360060b0560020b900360020b80915f0360020b129182610346575b50501561033757005b631422c96f60e31b5f5260045ffd5b60405163721c19f160e11b8152919250602090829060049082905afa9081156103b6575f9161037c575b5060020b13818061032e565b90506020813d6020116103ae575b8161039760209383610fbb565b810103126100dd576103a8906110dd565b82610370565b3d915061038a565b6040513d5f823e3d90fd5b9094506020813d6020116103f5575b816103dd60209383610fbb565b810103126100dd576103ee906110dd565b9386610311565b3d91506103d0565b634e487b7160e01b5f52601260045260245ffd5b6367530e9160e11b5f5260045ffd5b91505061044691945060803d608011610452575b61043e8183610fbb565b81019061139a565b959290509094866102b2565b503d610434565b90505f190116610287565b9194505061048291955060803d6080116104525761043e8183610fbb565b9692905093909588610269565b63e8da34a160e01b5f5260045ffd5b9150506104c3915060e03d60e0116104ce575b6104bb8183610fbb565b810190611328565b505050925084610228565b503d6104b1565b346100dd575f3660031901126100dd575f5160206115005f395f51905f52546040516001600160a01b039091168152602090f35b346100dd5760e03660031901126100dd57610522610f22565b61052a610f8e565b90610533610f4e565b61053b610f64565b92608435918260020b83036100dd5760a435948560020b86036100dd5760c435926001600160401b0384116100dd5760a060031985360301126100dd575f80546001600160a01b0316969060648601906105c79061059883611058565b60405163037b728960e21b81523060048201526001600160a01b03909116602482015291829081906044820190565b03818c5afa80156103b6576105ed915f91610988575b50602080825183010191016110eb565b95865190602061060d602483019360ff61060686611261565b169061126f565b519801519160046020610629604485019560ff61060688611261565b5160405163c45a015560e01b815290979092839182906001600160a01b03165afa9687156103b6576106a0976020925f9161096b575b50604051630b4c774160e11b81526001600160a01b03808d1660048301528b16602482015262ffffff90921660448301529097889190829081906064820190565b03916001600160a01b03165afa9586156103b6575f9661093a575b506040519260a084018481106001600160401b0382111761092657604052826004013580151581036100dd57610700926106f691865261138c565b602085015261138c565b604083015261070e83610f7a565b60608301526084810135916001600160401b0383116100dd5761073b869260046107459536920101610ff3565b6080820152611475565b15610918576020906001600160a01b039061075f90611058565b6040516370a0823160e01b81526001600160a01b03909516600486015284916024918391165afa9182156103b6575f926108e4575b5051116108d5576040516308f3a79b60e31b81526001600160a01b039092166004830152602082602481885afa9182156103b6575f926108a0575b506040516308f3a79b60e31b81526001600160a01b03909116600482015293602090859060249082905afa80156103b6575f9061086c575b61083094508082149182610862575b5081610858575b501561084e576020015160020b92611297565b9060020b9060020b1261083f57005b63600f040160e01b5f5260045ffd5b5160020b92611297565b905015158561081d565b1515915086610816565b506020843d602011610898575b8161088660209383610fbb565b810103126100dd576108309351610807565b3d9150610879565b9091506020813d6020116108cd575b816108bc60209383610fbb565b810103126100dd57519060206107cf565b3d91506108af565b63a4ce195160e01b5f5260045ffd5b9091506020813d602011610910575b8161090060209383610fbb565b810103126100dd57519088610794565b3d91506108f3565b62820f3560e61b5f5260045ffd5b634e487b7160e01b5f52604160045260245ffd5b61095d91965060203d602011610964575b6109558183610fbb565b8101906112c8565b948c6106bb565b503d61094b565b6109829150833d8511610964576109558183610fbb565b8f61065f565b6109a491503d805f833e61099c8183610fbb565b81019061106c565b8b6105dd565b346100dd5760603660031901126100dd576109c3610f22565b6109cb610f38565b6044356001600160401b0381116100dd576109ea903690600401610ff3565b905f5160206115205f395f51905f525460ff8160401c1615936001600160401b03821680159081610b79575b6001149081610b6f575b159081610b66575b50610b575767ffffffffffffffff1982166001175f5160206115205f395f51905f5255610a669185610b2b575b50610a5e6114d4565b6101056114d4565b6001600160a01b03168015610b1c575f80546001600160a01b0319169190911781555b8151811015610ac3576001906001600160a01b03610aa7828561126f565b51165f528160205260405f208260ff1982541617905501610a89565b82610aca57005b60ff60401b195f5160206115205f395f51905f5254165f5160206115205f395f51905f52557fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602060405160018152a1005b63d92e233d60e01b5f5260045ffd5b68ffffffffffffffffff191668010000000000000001175f5160206115205f395f51905f525585610a55565b63f92ee8a960e01b5f5260045ffd5b90501586610a28565b303b159150610a20565b869150610a16565b346100dd575f3660031901126100dd57610b99611442565b5f5160206115005f395f51905f5280546001600160a01b031981169091555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b346100dd5760803660031901126100dd57610c01610f22565b6004610c0b610f8e565b610c13610f4e565b926020610c1e610f64565b60405163c45a015560e01b815294909285919082906001600160a01b03165afa9081156103b657610c94946020945f93610d35575b50604051630b4c774160e11b81526001600160a01b0391821660048201529116602482015262ffffff90921660448301529092839190829081906064820190565b03916001600160a01b03165afa9081156103b65760049160e0915f91610d16575b50604051633850c7bd831b815292839182906001600160a01b03165afa9081156103b65760029161ffff915f91610cf0575b50161061048f57005b610d09915060e03d60e0116104ce576104bb8183610fbb565b5050509250505083610ce7565b610d2f915060203d602011610964576109558183610fbb565b83610cb5565b610d4d919350853d8711610964576109558183610fbb565b9186610c53565b346100dd5760203660031901126100dd576001600160a01b03610d75610f22565b165f52600160205260ff60405f20541615610d8c57005b630f9405bd60e11b5f5260045ffd5b346100dd5760a03660031901126100dd57610db4610f22565b90610dbd610f38565b604435908160020b82036100dd57606435938460020b85036100dd57608435936001600160401b0385116100dd5760a060031986360301126100dd575f80546001600160a01b031695908280610e3d610e1860648601611058565b63037b728960e21b83523060048401526001600160a01b031660248301526044820190565b0381895afa80156103b6576106066024610e6d60ff93610e75965f91610f085750602080825183010191016110eb565b519301611261565b516040516308f3a79b60e31b81526001600160a01b03909216600483015291602082602481885afa9182156103b6575f926108a057506040516308f3a79b60e31b81526001600160a01b03909116600482015293602090859060249082905afa80156103b6575f9061086c576108309450808214918261086257508161085857501561084e576020015160020b92611297565b610f1c91503d805f833e61099c8183610fbb565b8c6105dd565b600435906001600160a01b03821682036100dd57565b602435906001600160a01b03821682036100dd57565b604435906001600160a01b03821682036100dd57565b606435906001600160a01b03821682036100dd57565b35906001600160a01b03821682036100dd57565b6024359062ffffff821682036100dd57565b604081019081106001600160401b0382111761092657604052565b90601f801991011681019081106001600160401b0382111761092657604052565b6001600160401b0381116109265760051b60200190565b9080601f830112156100dd57813561100a81610fdc565b926110186040519485610fbb565b81845260208085019260051b8201019283116100dd57602001905b8282106110405750505090565b6020809161104d84610f7a565b815201910190611033565b356001600160a01b03811681036100dd5790565b6020818303126100dd578051906001600160401b0382116100dd570181601f820112156100dd578051906001600160401b03821161092657604051926110bc601f8401601f191660200185610fbb565b828452602083830101116100dd57815f9260208093018386015e8301015290565b51908160020b82036100dd57565b6020818303126100dd578051906001600160401b0382116100dd5701906040828203126100dd576040519161111f83610fa0565b80516001600160401b0381116100dd57810182601f820112156100dd57805161114781610fdc565b916111556040519384610fbb565b81835260208084019260061b820101908582116100dd57602001915b8183106112225750505083526020810151906001600160401b0382116100dd570181601f820112156100dd578051906111a982610fdc565b926111b76040519485610fbb565b82845260208085019360051b830101918183116100dd57602001925b8284106111e65750505050602082015290565b6020848303126100dd576040519060208201908282106001600160401b03831117610926576020928392604052865181528152019301926111d3565b6040838703126100dd576020604091825161123c81610fa0565b611245866110dd565b81526112528387016110dd565b83820152815201920191611171565b3560ff811681036100dd5790565b80518210156112835760209160051b010190565b634e487b7160e01b5f52603260045260245ffd5b600291820b910b0390627fffff198212627fffff8313176112b457565b634e487b7160e01b5f52601160045260245ffd5b908160209103126100dd57516001600160a01b03811681036100dd5790565b51906001600160a01b03821682036100dd57565b519061ffff821682036100dd57565b519063ffffffff821682036100dd57565b519081151582036100dd57565b908160e09103126100dd5761133c816112e7565b91611349602083016110dd565b91611356604082016112fb565b91611363606083016112fb565b91611370608082016112fb565b9161138960c061138260a0850161130a565b930161131b565b90565b359060ff821682036100dd57565b91908260809103126100dd576113af8261130a565b9160208101518060060b81036100dd57916113896060611382604085016112e7565b6001600160a01b0316801561142f575f5160206115005f395f51905f5280546001600160a01b0319811683179091556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3565b631e4fbdf760e01b5f525f60045260245ffd5b5f5160206115005f395f51905f52546001600160a01b0316330361146257565b63118cdaa760e01b5f523360045260245ffd5b608001908151519182156114cc575f5b83811061149457505050505f90565b81516001600160a01b03906114aa90839061126f565b51166001600160a01b038416146114c357600101611485565b50505050600190565b505050600190565b60ff5f5160206115205f395f51905f525460401c16156114f057565b631afcd79f60e31b5f5260045ffdfe9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a164736f6c634300081c000a
Deployed Bytecode
0x6080806040526004361015610012575f80fd5b5f3560e01c9081630b25894b14610d9b57508063446e7fd014610d545780635925844d14610be8578063715018a614610b8157806377a24f36146109aa578063808d125f146105095780638da5cb5b146104d5578063c94a521d146101de578063ca0ab075146101b7578063de7a35ed1461010c578063f2fde38b146100e15763f4a9af63146100a0575f80fd5b346100dd5760203660031901126100dd576001600160a01b036100c1610f22565b165f526001602052602060ff60405f2054166040519015158152f35b5f80fd5b346100dd5760203660031901126100dd5761010a6100fd610f22565b610105611442565b6113d1565b005b346100dd5760403660031901126100dd576004356001600160401b0381116100dd57366023820112156100dd5780600401356001600160401b0381116100dd573660248260051b840101116100dd57602435908115158092036100dd5790610172611442565b60ff165f5b8281101561010a576001906001600160a01b0361019c600583901b8701602401611058565b165f528160205260405f208360ff1982541617905501610177565b346100dd575f3660031901126100dd575f546040516001600160a01b039091168152602090f35b346100dd5760203660031901126100dd576001600160a01b036101ff610f22565b16604051633850c7bd60e01b815260e081600481855afa9081156103b6575f905f905f9361049e575b5061ffff83161561048f5760405163252c09d760e01b815261ffff8216600482018190529093608085602481895afa9283156103b6575f935f965f91610464575b50156104115761ffff8092602492608095155f1461045957505f1901165b604051978893849263252c09d760e01b84521660048301525afa80156103b6575f905f955f91610420575b50156104115763ffffffff811663ffffffff831611156104115763ffffffff91031660030b80156103fd575f5460405163721c19f160e11b81526001600160a01b03909116949093602085600481895afa9485156103b6575f956103c1575b500360060b0560020b900360020b80915f0360020b129182610346575b50501561033757005b631422c96f60e31b5f5260045ffd5b60405163721c19f160e11b8152919250602090829060049082905afa9081156103b6575f9161037c575b5060020b13818061032e565b90506020813d6020116103ae575b8161039760209383610fbb565b810103126100dd576103a8906110dd565b82610370565b3d915061038a565b6040513d5f823e3d90fd5b9094506020813d6020116103f5575b816103dd60209383610fbb565b810103126100dd576103ee906110dd565b9386610311565b3d91506103d0565b634e487b7160e01b5f52601260045260245ffd5b6367530e9160e11b5f5260045ffd5b91505061044691945060803d608011610452575b61043e8183610fbb565b81019061139a565b959290509094866102b2565b503d610434565b90505f190116610287565b9194505061048291955060803d6080116104525761043e8183610fbb565b9692905093909588610269565b63e8da34a160e01b5f5260045ffd5b9150506104c3915060e03d60e0116104ce575b6104bb8183610fbb565b810190611328565b505050925084610228565b503d6104b1565b346100dd575f3660031901126100dd575f5160206115005f395f51905f52546040516001600160a01b039091168152602090f35b346100dd5760e03660031901126100dd57610522610f22565b61052a610f8e565b90610533610f4e565b61053b610f64565b92608435918260020b83036100dd5760a435948560020b86036100dd5760c435926001600160401b0384116100dd5760a060031985360301126100dd575f80546001600160a01b0316969060648601906105c79061059883611058565b60405163037b728960e21b81523060048201526001600160a01b03909116602482015291829081906044820190565b03818c5afa80156103b6576105ed915f91610988575b50602080825183010191016110eb565b95865190602061060d602483019360ff61060686611261565b169061126f565b519801519160046020610629604485019560ff61060688611261565b5160405163c45a015560e01b815290979092839182906001600160a01b03165afa9687156103b6576106a0976020925f9161096b575b50604051630b4c774160e11b81526001600160a01b03808d1660048301528b16602482015262ffffff90921660448301529097889190829081906064820190565b03916001600160a01b03165afa9586156103b6575f9661093a575b506040519260a084018481106001600160401b0382111761092657604052826004013580151581036100dd57610700926106f691865261138c565b602085015261138c565b604083015261070e83610f7a565b60608301526084810135916001600160401b0383116100dd5761073b869260046107459536920101610ff3565b6080820152611475565b15610918576020906001600160a01b039061075f90611058565b6040516370a0823160e01b81526001600160a01b03909516600486015284916024918391165afa9182156103b6575f926108e4575b5051116108d5576040516308f3a79b60e31b81526001600160a01b039092166004830152602082602481885afa9182156103b6575f926108a0575b506040516308f3a79b60e31b81526001600160a01b03909116600482015293602090859060249082905afa80156103b6575f9061086c575b61083094508082149182610862575b5081610858575b501561084e576020015160020b92611297565b9060020b9060020b1261083f57005b63600f040160e01b5f5260045ffd5b5160020b92611297565b905015158561081d565b1515915086610816565b506020843d602011610898575b8161088660209383610fbb565b810103126100dd576108309351610807565b3d9150610879565b9091506020813d6020116108cd575b816108bc60209383610fbb565b810103126100dd57519060206107cf565b3d91506108af565b63a4ce195160e01b5f5260045ffd5b9091506020813d602011610910575b8161090060209383610fbb565b810103126100dd57519088610794565b3d91506108f3565b62820f3560e61b5f5260045ffd5b634e487b7160e01b5f52604160045260245ffd5b61095d91965060203d602011610964575b6109558183610fbb565b8101906112c8565b948c6106bb565b503d61094b565b6109829150833d8511610964576109558183610fbb565b8f61065f565b6109a491503d805f833e61099c8183610fbb565b81019061106c565b8b6105dd565b346100dd5760603660031901126100dd576109c3610f22565b6109cb610f38565b6044356001600160401b0381116100dd576109ea903690600401610ff3565b905f5160206115205f395f51905f525460ff8160401c1615936001600160401b03821680159081610b79575b6001149081610b6f575b159081610b66575b50610b575767ffffffffffffffff1982166001175f5160206115205f395f51905f5255610a669185610b2b575b50610a5e6114d4565b6101056114d4565b6001600160a01b03168015610b1c575f80546001600160a01b0319169190911781555b8151811015610ac3576001906001600160a01b03610aa7828561126f565b51165f528160205260405f208260ff1982541617905501610a89565b82610aca57005b60ff60401b195f5160206115205f395f51905f5254165f5160206115205f395f51905f52557fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602060405160018152a1005b63d92e233d60e01b5f5260045ffd5b68ffffffffffffffffff191668010000000000000001175f5160206115205f395f51905f525585610a55565b63f92ee8a960e01b5f5260045ffd5b90501586610a28565b303b159150610a20565b869150610a16565b346100dd575f3660031901126100dd57610b99611442565b5f5160206115005f395f51905f5280546001600160a01b031981169091555f906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b346100dd5760803660031901126100dd57610c01610f22565b6004610c0b610f8e565b610c13610f4e565b926020610c1e610f64565b60405163c45a015560e01b815294909285919082906001600160a01b03165afa9081156103b657610c94946020945f93610d35575b50604051630b4c774160e11b81526001600160a01b0391821660048201529116602482015262ffffff90921660448301529092839190829081906064820190565b03916001600160a01b03165afa9081156103b65760049160e0915f91610d16575b50604051633850c7bd831b815292839182906001600160a01b03165afa9081156103b65760029161ffff915f91610cf0575b50161061048f57005b610d09915060e03d60e0116104ce576104bb8183610fbb565b5050509250505083610ce7565b610d2f915060203d602011610964576109558183610fbb565b83610cb5565b610d4d919350853d8711610964576109558183610fbb565b9186610c53565b346100dd5760203660031901126100dd576001600160a01b03610d75610f22565b165f52600160205260ff60405f20541615610d8c57005b630f9405bd60e11b5f5260045ffd5b346100dd5760a03660031901126100dd57610db4610f22565b90610dbd610f38565b604435908160020b82036100dd57606435938460020b85036100dd57608435936001600160401b0385116100dd5760a060031986360301126100dd575f80546001600160a01b031695908280610e3d610e1860648601611058565b63037b728960e21b83523060048401526001600160a01b031660248301526044820190565b0381895afa80156103b6576106066024610e6d60ff93610e75965f91610f085750602080825183010191016110eb565b519301611261565b516040516308f3a79b60e31b81526001600160a01b03909216600483015291602082602481885afa9182156103b6575f926108a057506040516308f3a79b60e31b81526001600160a01b03909116600482015293602090859060249082905afa80156103b6575f9061086c576108309450808214918261086257508161085857501561084e576020015160020b92611297565b610f1c91503d805f833e61099c8183610fbb565b8c6105dd565b600435906001600160a01b03821682036100dd57565b602435906001600160a01b03821682036100dd57565b604435906001600160a01b03821682036100dd57565b606435906001600160a01b03821682036100dd57565b35906001600160a01b03821682036100dd57565b6024359062ffffff821682036100dd57565b604081019081106001600160401b0382111761092657604052565b90601f801991011681019081106001600160401b0382111761092657604052565b6001600160401b0381116109265760051b60200190565b9080601f830112156100dd57813561100a81610fdc565b926110186040519485610fbb565b81845260208085019260051b8201019283116100dd57602001905b8282106110405750505090565b6020809161104d84610f7a565b815201910190611033565b356001600160a01b03811681036100dd5790565b6020818303126100dd578051906001600160401b0382116100dd570181601f820112156100dd578051906001600160401b03821161092657604051926110bc601f8401601f191660200185610fbb565b828452602083830101116100dd57815f9260208093018386015e8301015290565b51908160020b82036100dd57565b6020818303126100dd578051906001600160401b0382116100dd5701906040828203126100dd576040519161111f83610fa0565b80516001600160401b0381116100dd57810182601f820112156100dd57805161114781610fdc565b916111556040519384610fbb565b81835260208084019260061b820101908582116100dd57602001915b8183106112225750505083526020810151906001600160401b0382116100dd570181601f820112156100dd578051906111a982610fdc565b926111b76040519485610fbb565b82845260208085019360051b830101918183116100dd57602001925b8284106111e65750505050602082015290565b6020848303126100dd576040519060208201908282106001600160401b03831117610926576020928392604052865181528152019301926111d3565b6040838703126100dd576020604091825161123c81610fa0565b611245866110dd565b81526112528387016110dd565b83820152815201920191611171565b3560ff811681036100dd5790565b80518210156112835760209160051b010190565b634e487b7160e01b5f52603260045260245ffd5b600291820b910b0390627fffff198212627fffff8313176112b457565b634e487b7160e01b5f52601160045260245ffd5b908160209103126100dd57516001600160a01b03811681036100dd5790565b51906001600160a01b03821682036100dd57565b519061ffff821682036100dd57565b519063ffffffff821682036100dd57565b519081151582036100dd57565b908160e09103126100dd5761133c816112e7565b91611349602083016110dd565b91611356604082016112fb565b91611363606083016112fb565b91611370608082016112fb565b9161138960c061138260a0850161130a565b930161131b565b90565b359060ff821682036100dd57565b91908260809103126100dd576113af8261130a565b9160208101518060060b81036100dd57916113896060611382604085016112e7565b6001600160a01b0316801561142f575f5160206115005f395f51905f5280546001600160a01b0319811683179091556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e05f80a3565b631e4fbdf760e01b5f525f60045260245ffd5b5f5160206115005f395f51905f52546001600160a01b0316330361146257565b63118cdaa760e01b5f523360045260245ffd5b608001908151519182156114cc575f5b83811061149457505050505f90565b81516001600160a01b03906114aa90839061126f565b51166001600160a01b038416146114c357600101611485565b50505050600190565b505050600190565b60ff5f5160206115205f395f51905f525460401c16156114f057565b631afcd79f60e31b5f5260045ffdfe9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a164736f6c634300081c000a
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
Loading...
Loading
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.