Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Multi Chain
Multichain Addresses
1 address found via
Latest 4 from a total of 4 transactions
Latest 3 internal transactions
Advanced mode:
Parent Txn Hash | Block | From | To | Value | ||
---|---|---|---|---|---|---|
16412191 | 326 days 14 hrs ago | Contract Creation | 0 ETH | |||
16412164 | 326 days 14 hrs ago | Contract Creation | 0 ETH | |||
16219997 | 353 days 9 hrs ago | Contract Creation | 0 ETH |
Loading...
Loading
Contract Name:
GearboxVaultGovernance
Compiler Version
v0.8.9+commit.e5eed63a
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BSL-1.1 pragma solidity 0.8.9; import "../interfaces/vaults/IGearboxVaultGovernance.sol"; import "../libraries/ExceptionsLibrary.sol"; import "../utils/ContractMeta.sol"; import "./VaultGovernance.sol"; contract GearboxVaultGovernance is ContractMeta, IGearboxVaultGovernance, VaultGovernance { uint256 public constant D9 = 10**9; /// @notice Creates a new contract constructor(InternalParams memory internalParams_, DelayedProtocolParams memory delayedProtocolParams_) VaultGovernance(internalParams_) { require(delayedProtocolParams_.crv3Pool != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(delayedProtocolParams_.crv != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(delayedProtocolParams_.cvx != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(delayedProtocolParams_.uniswapRouter != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(delayedProtocolParams_.maxSlippageD9 <= D9, ExceptionsLibrary.INVARIANT); require(delayedProtocolParams_.maxSmallPoolsSlippageD9 <= D9, ExceptionsLibrary.INVARIANT); require(delayedProtocolParams_.maxCurveSlippageD9 <= D9, ExceptionsLibrary.INVARIANT); _delayedProtocolParams = abi.encode(delayedProtocolParams_); } // ------------------- EXTERNAL, VIEW ------------------- /// @inheritdoc IGearboxVaultGovernance function delayedProtocolParams() public view returns (DelayedProtocolParams memory) { // params are initialized in constructor, so cannot be 0 return abi.decode(_delayedProtocolParams, (DelayedProtocolParams)); } /// @inheritdoc IERC165 function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return super.supportsInterface(interfaceId) || interfaceId == type(IGearboxVaultGovernance).interfaceId; } /// @inheritdoc IGearboxVaultGovernance function stagedDelayedProtocolParams() external view returns (DelayedProtocolParams memory) { if (_stagedDelayedProtocolParams.length == 0) { return DelayedProtocolParams({ crv3Pool: address(0), crv: address(0), cvx: address(0), maxSlippageD9: 0, maxSmallPoolsSlippageD9: 0, maxCurveSlippageD9: 0, uniswapRouter: address(0) }); } return abi.decode(_stagedDelayedProtocolParams, (DelayedProtocolParams)); } /// @inheritdoc IGearboxVaultGovernance function stagedDelayedProtocolPerVaultParams(uint256 nft) external view returns (DelayedProtocolPerVaultParams memory) { if (_stagedDelayedProtocolPerVaultParams[nft].length == 0) { return DelayedProtocolPerVaultParams({ primaryToken: address(0), univ3Adapter: address(0), facade: address(0), withdrawDelay: 0, initialMarginalValueD9: 0, referralCode: 0 }); } return abi.decode(_stagedDelayedProtocolPerVaultParams[nft], (DelayedProtocolPerVaultParams)); } /// @inheritdoc IGearboxVaultGovernance function strategyParams(uint256 nft) external view returns (StrategyParams memory) { if (_strategyParams[nft].length == 0) { return StrategyParams({largePoolFeeUsed: 500}); } return abi.decode(_strategyParams[nft], (StrategyParams)); } /// @inheritdoc IGearboxVaultGovernance function delayedProtocolPerVaultParams(uint256 nft) external view returns (DelayedProtocolPerVaultParams memory) { if (_delayedProtocolPerVaultParams[nft].length == 0) { return DelayedProtocolPerVaultParams({ primaryToken: address(0), univ3Adapter: address(0), facade: address(0), withdrawDelay: 0, initialMarginalValueD9: 0, referralCode: 0 }); } return abi.decode(_delayedProtocolPerVaultParams[nft], (DelayedProtocolPerVaultParams)); } // ------------------- EXTERNAL, MUTATING ------------------- /// @inheritdoc IGearboxVaultGovernance function stageDelayedProtocolParams(DelayedProtocolParams memory params) external { require(params.crv3Pool != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(params.crv != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(params.cvx != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(params.uniswapRouter != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(params.maxSlippageD9 <= D9, ExceptionsLibrary.INVARIANT); require(params.maxSmallPoolsSlippageD9 <= D9, ExceptionsLibrary.INVARIANT); require(params.maxCurveSlippageD9 <= D9, ExceptionsLibrary.INVARIANT); _stageDelayedProtocolParams(abi.encode(params)); emit StageDelayedProtocolParams(tx.origin, msg.sender, params, _delayedProtocolParamsTimestamp); } /// @inheritdoc IGearboxVaultGovernance function commitDelayedProtocolParams() external { _commitDelayedProtocolParams(); emit CommitDelayedProtocolParams( tx.origin, msg.sender, abi.decode(_delayedProtocolParams, (DelayedProtocolParams)) ); } function stageDelayedProtocolPerVaultParams(uint256 nft, DelayedProtocolPerVaultParams calldata params) external { require(params.primaryToken != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(params.univ3Adapter != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(params.facade != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(params.withdrawDelay <= 86400 * 30, ExceptionsLibrary.INVALID_VALUE); require(params.initialMarginalValueD9 >= D9, ExceptionsLibrary.INVALID_VALUE); _stageDelayedProtocolPerVaultParams(nft, abi.encode(params)); emit StageDelayedProtocolPerVaultParams( tx.origin, msg.sender, nft, params, _delayedStrategyParamsTimestamp[nft] ); } /// @inheritdoc IGearboxVaultGovernance function commitDelayedProtocolPerVaultParams(uint256 nft) external { _commitDelayedProtocolPerVaultParams(nft); emit CommitDelayedProtocolPerVaultParams( tx.origin, msg.sender, nft, abi.decode(_delayedProtocolPerVaultParams[nft], (DelayedProtocolPerVaultParams)) ); } /// @inheritdoc IGearboxVaultGovernance function setStrategyParams(uint256 nft, StrategyParams calldata params) external { require( params.largePoolFeeUsed == 100 || params.largePoolFeeUsed == 500 || params.largePoolFeeUsed == 3000 || params.largePoolFeeUsed == 10000, ExceptionsLibrary.FORBIDDEN ); _setStrategyParams(nft, abi.encode(params)); emit SetStrategyParams(tx.origin, msg.sender, params); } /// @inheritdoc IGearboxVaultGovernance function createVault( address[] memory vaultTokens_, address owner_, address helper_ ) external returns (IGearboxVault vault, uint256 nft) { address vaddr; (vaddr, nft) = _createVault(owner_); IGearboxVault gearboxVault = IGearboxVault(vaddr); gearboxVault.initialize(nft, vaultTokens_, helper_); vault = IGearboxVault(vaddr); } // ------------------- INTERNAL, VIEW ------------------- function _contractName() internal pure override returns (bytes32) { return bytes32("GearboxVaultGovernance"); } function _contractVersion() internal pure override returns (bytes32) { return bytes32("1.0.0"); } // -------------------------- EVENTS -------------------------- /// @notice Emitted when new DelayedProtocolPerVaultParams are staged for commit /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param nft VaultRegistry NFT of the vault /// @param params New params that were staged for commit /// @param when When the params could be committed event StageDelayedProtocolPerVaultParams( address indexed origin, address indexed sender, uint256 indexed nft, DelayedProtocolPerVaultParams params, uint256 when ); /// @notice Emitted when new DelayedProtocolPerVaultParams are committed /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param nft VaultRegistry NFT of the vault /// @param params New params that are committed event CommitDelayedProtocolPerVaultParams( address indexed origin, address indexed sender, uint256 indexed nft, DelayedProtocolPerVaultParams params ); /// @notice Emitted when new DelayedProtocolParams are staged for commit /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param params New params that were staged for commit /// @param when When the params could be committed event StageDelayedProtocolParams( address indexed origin, address indexed sender, DelayedProtocolParams params, uint256 when ); /// @notice Emitted when new StrategyParams are set. /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param params New params that are set event SetStrategyParams(address indexed origin, address indexed sender, StrategyParams params); /// @notice Emitted when new DelayedProtocolParams are committed /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param params New params that are committed event CommitDelayedProtocolParams(address indexed origin, address indexed sender, DelayedProtocolParams params); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControl.sol"; /** * @dev External interface of AccessControlEnumerable declared to support ERC165 detection. */ interface IAccessControlEnumerable is IAccessControl { /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) external view returns (address); /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) external view returns (uint256); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/Clones.sol) pragma solidity ^0.8.0; /** * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for * deploying minimal proxy contracts, also known as "clones". * * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies * > a minimal bytecode implementation that delegates all calls to a known, fixed address. * * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2` * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the * deterministic method. * * _Available since v3.4._ */ library Clones { /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create opcode, which should never revert. */ function clone(address implementation) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes // of the `implementation` address with the bytecode before the address. mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000)) // Packs the remaining 17 bytes of `implementation` with the bytecode after the address. mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3)) instance := create(0, 0x09, 0x37) } require(instance != address(0), "ERC1167: create failed"); } /** * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`. * * This function uses the create2 opcode and a `salt` to deterministically deploy * the clone. Using the same `implementation` and `salt` multiple time will revert, since * the clones cannot be deployed twice at the same address. */ function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) { /// @solidity memory-safe-assembly assembly { // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes // of the `implementation` address with the bytecode before the address. mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000)) // Packs the remaining 17 bytes of `implementation` with the bytecode after the address. mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3)) instance := create2(0, 0x09, 0x37, salt) } require(instance != address(0), "ERC1167: create2 failed"); } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress( address implementation, bytes32 salt, address deployer ) internal pure returns (address predicted) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(add(ptr, 0x38), deployer) mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff) mstore(add(ptr, 0x14), implementation) mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73) mstore(add(ptr, 0x58), salt) mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37)) predicted := keccak256(add(ptr, 0x43), 0x55) } } /** * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}. */ function predictDeterministicAddress(address implementation, bytes32 salt) internal view returns (address predicted) { return predictDeterministicAddress(implementation, salt, address(this)); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/draft-IERC20Permit.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721 * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must * understand this adds an external call which potentially creates a reentrancy vulnerability. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "./utils/IDefaultAccessControl.sol"; import "./IUnitPricesGovernance.sol"; interface IProtocolGovernance is IDefaultAccessControl, IUnitPricesGovernance { /// @notice CommonLibrary protocol params. /// @param maxTokensPerVault Max different token addresses that could be managed by the vault /// @param governanceDelay The delay (in secs) that must pass before setting new pending params to commiting them /// @param protocolTreasury The address that collects protocolFees, if protocolFee is not zero /// @param forceAllowMask If a permission bit is set in this mask it forces all addresses to have this permission as true /// @param withdrawLimit Withdraw limit (in unit prices, i.e. usd) struct Params { uint256 maxTokensPerVault; uint256 governanceDelay; address protocolTreasury; uint256 forceAllowMask; uint256 withdrawLimit; } // ------------------- EXTERNAL, VIEW ------------------- /// @notice Timestamp after which staged granted permissions for the given address can be committed. /// @param target The given address /// @return Zero if there are no staged permission grants, timestamp otherwise function stagedPermissionGrantsTimestamps(address target) external view returns (uint256); /// @notice Staged granted permission bitmask for the given address. /// @param target The given address /// @return Bitmask function stagedPermissionGrantsMasks(address target) external view returns (uint256); /// @notice Permission bitmask for the given address. /// @param target The given address /// @return Bitmask function permissionMasks(address target) external view returns (uint256); /// @notice Timestamp after which staged pending protocol parameters can be committed /// @return Zero if there are no staged parameters, timestamp otherwise. function stagedParamsTimestamp() external view returns (uint256); /// @notice Staged pending protocol parameters. function stagedParams() external view returns (Params memory); /// @notice Current protocol parameters. function params() external view returns (Params memory); /// @notice Addresses for which non-zero permissions are set. function permissionAddresses() external view returns (address[] memory); /// @notice Permission addresses staged for commit. function stagedPermissionGrantsAddresses() external view returns (address[] memory); /// @notice Return all addresses where rawPermissionMask bit for permissionId is set to 1. /// @param permissionId Id of the permission to check. /// @return A list of dirty addresses. function addressesByPermission(uint8 permissionId) external view returns (address[] memory); /// @notice Checks if address has permission or given permission is force allowed for any address. /// @param addr Address to check /// @param permissionId Permission to check function hasPermission(address addr, uint8 permissionId) external view returns (bool); /// @notice Checks if address has all permissions. /// @param target Address to check /// @param permissionIds A list of permissions to check function hasAllPermissions(address target, uint8[] calldata permissionIds) external view returns (bool); /// @notice Max different ERC20 token addresses that could be managed by the protocol. function maxTokensPerVault() external view returns (uint256); /// @notice The delay for committing any governance params. function governanceDelay() external view returns (uint256); /// @notice The address of the protocol treasury. function protocolTreasury() external view returns (address); /// @notice Permissions mask which defines if ordinary permission should be reverted. /// This bitmask is xored with ordinary mask. function forceAllowMask() external view returns (uint256); /// @notice Withdraw limit per token per block. /// @param token Address of the token /// @return Withdraw limit per token per block function withdrawLimit(address token) external view returns (uint256); /// @notice Addresses that has staged validators. function stagedValidatorsAddresses() external view returns (address[] memory); /// @notice Timestamp after which staged granted permissions for the given address can be committed. /// @param target The given address /// @return Zero if there are no staged permission grants, timestamp otherwise function stagedValidatorsTimestamps(address target) external view returns (uint256); /// @notice Staged validator for the given address. /// @param target The given address /// @return Validator function stagedValidators(address target) external view returns (address); /// @notice Addresses that has validators. function validatorsAddresses() external view returns (address[] memory); /// @notice Address that has validators. /// @param i The number of address /// @return Validator address function validatorsAddress(uint256 i) external view returns (address); /// @notice Validator for the given address. /// @param target The given address /// @return Validator function validators(address target) external view returns (address); // ------------------- EXTERNAL, MUTATING, GOVERNANCE, IMMEDIATE ------------------- /// @notice Rollback all staged validators. function rollbackStagedValidators() external; /// @notice Revoke validator instantly from the given address. /// @param target The given address function revokeValidator(address target) external; /// @notice Stages a new validator for the given address /// @param target The given address /// @param validator The validator for the given address function stageValidator(address target, address validator) external; /// @notice Commits validator for the given address. /// @dev Reverts if governance delay has not passed yet. /// @param target The given address. function commitValidator(address target) external; /// @notice Commites all staged validators for which governance delay passed /// @return Addresses for which validators were committed function commitAllValidatorsSurpassedDelay() external returns (address[] memory); /// @notice Rollback all staged granted permission grant. function rollbackStagedPermissionGrants() external; /// @notice Commits permission grants for the given address. /// @dev Reverts if governance delay has not passed yet. /// @param target The given address. function commitPermissionGrants(address target) external; /// @notice Commites all staged permission grants for which governance delay passed. /// @return An array of addresses for which permission grants were committed. function commitAllPermissionGrantsSurpassedDelay() external returns (address[] memory); /// @notice Revoke permission instantly from the given address. /// @param target The given address. /// @param permissionIds A list of permission ids to revoke. function revokePermissions(address target, uint8[] memory permissionIds) external; /// @notice Commits staged protocol params. /// Reverts if governance delay has not passed yet. function commitParams() external; // ------------------- EXTERNAL, MUTATING, GOVERNANCE, DELAY ------------------- /// @notice Sets new pending params that could have been committed after governance delay expires. /// @param newParams New protocol parameters to set. function stageParams(Params memory newParams) external; /// @notice Stage granted permissions that could have been committed after governance delay expires. /// Resets commit delay and permissions if there are already staged permissions for this address. /// @param target Target address /// @param permissionIds A list of permission ids to grant function stagePermissionGrants(address target, uint8[] memory permissionIds) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import "./utils/IDefaultAccessControl.sol"; interface IUnitPricesGovernance is IDefaultAccessControl, IERC165 { // ------------------- EXTERNAL, VIEW ------------------- /// @notice Estimated amount of token worth 1 USD staged for commit. /// @param token Address of the token /// @return The amount of token function stagedUnitPrices(address token) external view returns (uint256); /// @notice Timestamp after which staged unit prices for the given token can be committed. /// @param token Address of the token /// @return Timestamp function stagedUnitPricesTimestamps(address token) external view returns (uint256); /// @notice Estimated amount of token worth 1 USD. /// @param token Address of the token /// @return The amount of token function unitPrices(address token) external view returns (uint256); // ------------------- EXTERNAL, MUTATING ------------------- /// @notice Stage estimated amount of token worth 1 USD staged for commit. /// @param token Address of the token /// @param value The amount of token function stageUnitPrice(address token, uint256 value) external; /// @notice Reset staged value /// @param token Address of the token function rollbackUnitPrice(address token) external; /// @notice Commit staged unit price /// @param token Address of the token function commitUnitPrice(address token) external; }
// SPDX-License-Identifier: MIT pragma solidity =0.8.9; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "./IProtocolGovernance.sol"; interface IVaultRegistry is IERC721 { /// @notice Get Vault for the giver NFT ID. /// @param nftId NFT ID /// @return vault Address of the Vault contract function vaultForNft(uint256 nftId) external view returns (address vault); /// @notice Get NFT ID for given Vault contract address. /// @param vault Address of the Vault contract /// @return nftId NFT ID function nftForVault(address vault) external view returns (uint256 nftId); /// @notice Checks if the nft is locked for all transfers /// @param nft NFT to check for lock /// @return `true` if locked, false otherwise function isLocked(uint256 nft) external view returns (bool); /// @notice Register new Vault and mint NFT. /// @param vault address of the vault /// @param owner owner of the NFT /// @return nft Nft minted for the given Vault function registerVault(address vault, address owner) external returns (uint256 nft); /// @notice Number of Vaults registered. function vaultsCount() external view returns (uint256); /// @notice All Vaults registered. function vaults() external view returns (address[] memory); /// @notice Address of the ProtocolGovernance. function protocolGovernance() external view returns (IProtocolGovernance); /// @notice Address of the staged ProtocolGovernance. function stagedProtocolGovernance() external view returns (IProtocolGovernance); /// @notice Minimal timestamp when staged ProtocolGovernance can be applied. function stagedProtocolGovernanceTimestamp() external view returns (uint256); /// @notice Stage new ProtocolGovernance. /// @param newProtocolGovernance new ProtocolGovernance function stageProtocolGovernance(IProtocolGovernance newProtocolGovernance) external; /// @notice Commit new ProtocolGovernance. function commitStagedProtocolGovernance() external; /// @notice Lock NFT for transfers /// @dev Use this method when vault structure is set up and should become immutable. Can be called by owner. /// @param nft - NFT to lock function lockNft(uint256 nft) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; interface IConvexToken { function totalSupply() external view returns (uint256); function reductionPerCliff() external view returns (uint256); function maxSupply() external view returns (uint256); function totalCliffs() external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; interface ICurveGauge { function deposit(uint256) external; function balanceOf(address) external view returns (uint256); function withdraw(uint256) external; function claim_rewards() external; function reward_tokens(uint256) external view returns (address); //v2 function rewarded_token() external view returns (address); //v1 function lp_token() external view returns (address); } interface ICurveVoteEscrow { function create_lock(uint256, uint256) external; function increase_amount(uint256) external; function increase_unlock_time(uint256) external; function withdraw() external; function smart_wallet_checker() external view returns (address); } interface IWalletChecker { function check(address) external view returns (bool); } interface IVoting { function vote( uint256, bool, bool ) external; //voteId, support, executeIfDecided function getVote(uint256) external view returns ( bool, bool, uint64, uint64, uint64, uint64, uint256, uint256, uint256, bytes memory ); function vote_for_gauge_weights(address, uint256) external; } interface IMinter { function mint(address) external; } interface IRegistry { function get_registry() external view returns (address); function get_address(uint256 _id) external view returns (address); function gauge_controller() external view returns (address); function get_lp_token(address) external view returns (address); function get_gauges(address) external view returns (address[10] memory, uint128[10] memory); } interface IStaker { function deposit(address, address) external; function withdraw(address) external; function withdraw( address, address, uint256 ) external; function withdrawAll(address, address) external; function createLock(uint256, uint256) external; function increaseAmount(uint256) external; function increaseTime(uint256) external; function release() external; function claimCrv(address) external returns (uint256); function claimRewards(address) external; function claimFees(address, address) external; function setStashAccess(address, bool) external; function vote( uint256, address, bool ) external; function voteGaugeWeight(address, uint256) external; function balanceOfPool(address) external view returns (uint256); function operator() external view returns (address); function execute( address _to, uint256 _value, bytes calldata _data ) external returns (bool, bytes memory); } interface IRewards { function stake(address, uint256) external; function stakeFor(address, uint256) external; function withdraw(address, uint256) external; function exit(address) external; function getReward(address) external; function queueNewRewards(uint256) external; function notifyRewardAmount(uint256) external; function addExtraReward(address) external; function stakingToken() external view returns (address); function rewardToken() external view returns (address); function earned(address account) external view returns (uint256); } interface IStash { function stashRewards() external returns (bool); function processStash() external returns (bool); function claimRewards() external returns (bool); function initialize( uint256 _pid, address _operator, address _staker, address _gauge, address _rewardFactory ) external; } interface IFeeDistro { function claim() external; function token() external view returns (address); } interface ITokenMinter { function mint(address, uint256) external; function burn(address, uint256) external; } interface IDeposit { function isShutdown() external view returns (bool); function balanceOf(address _account) external view returns (uint256); function totalSupply() external view returns (uint256); function poolInfo(uint256) external view returns ( address, address, address, address, address, bool ); function rewardClaimed( uint256, address, uint256 ) external; function withdrawTo( uint256, uint256, address ) external; function claimRewards(uint256, address) external returns (bool); function rewardArbitrator() external returns (address); function setGaugeRedirect(uint256 _pid) external returns (bool); function owner() external returns (address); } interface ICrvDeposit { function deposit(uint256, bool) external; function lockIncentive() external view returns (uint256); } interface IRewardFactory { function setAccess(address, bool) external; function CreateCrvRewards(uint256, address) external returns (address); function CreateTokenRewards( address, address, address ) external returns (address); function activeRewardCount(address) external view returns (uint256); function addActiveReward(address, uint256) external returns (bool); function removeActiveReward(address, uint256) external returns (bool); } interface IStashFactory { function CreateStash( uint256, address, address, uint256 ) external returns (address); } interface ITokenFactory { function CreateDepositToken(address) external returns (address); } interface IPools { function addPool( address _lptoken, address _gauge, uint256 _stashVersion ) external returns (bool); function forceAddPool( address _lptoken, address _gauge, uint256 _stashVersion ) external returns (bool); function shutdownPool(uint256 _pid) external returns (bool); function poolInfo(uint256) external view returns ( address, address, address, address, address, bool ); function poolLength() external view returns (uint256); function gaugeMap(address) external view returns (bool); function setPoolManager(address _poolM) external; } interface IVestedEscrow { function fund(address[] calldata _recipient, uint256[] calldata _amount) external returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; interface IERC1271 { /// @notice Verifies offchain signature. /// @dev Should return whether the signature provided is valid for the provided hash /// /// MUST return the bytes4 magic value 0x1626ba7e when function passes. /// /// MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5) /// /// MUST allow external calls /// @param _hash Hash of the data to be signed /// @param _signature Signature byte array associated with _hash /// @return magicValue 0x1626ba7e if valid, 0xffffffff otherwise function isValidSignature(bytes32 _hash, bytes memory _signature) external view returns (bytes4 magicValue); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.9; import { IAdapter } from "./helpers/IAdapter.sol"; import { IBaseRewardPool } from "./helpers/convex/IBaseRewardPool.sol"; interface IConvexV1BaseRewardPoolAdapterErrors { /// @dev Thrown when the adapter attempts to use a token not /// allowed in its corresponding Credit Manager error TokenIsNotAddedToCreditManagerException(address token); } interface IConvexV1BaseRewardPoolAdapter is IAdapter, IBaseRewardPool, IConvexV1BaseRewardPoolAdapterErrors { /// @dev Returns the address of a Curve pool LP token /// staked in the adapter's targer Convex pool function curveLPtoken() external view returns (address); /// @dev Returns the address of a phantom token tracking /// a Credit Account's staked balance in a Convex /// pool function stakedPhantomToken() external view returns (address); /// @dev Returns the address of the first extra reward token /// @notice address(0) if the Convex pool has no extra reward tokens function extraReward1() external view returns (address); /// @dev Returns the address of the second extra reward token /// @notice address(0) if the Convex pool has less than 2 extra reward tokens function extraReward2() external view returns (address); /// @dev Returns the address of CVX function cvx() external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.9; import { IVersion } from "./helpers/IVersion.sol"; import { ICreditManagerV2, ICreditManagerV2Exceptions } from "./helpers/ICreditManagerV2.sol"; import { Balance } from "./helpers/libraries/Balances.sol"; import { MultiCall } from "./helpers/libraries/MultiCall.sol"; interface ICreditFacadeExtended { /// @dev Stores expected balances (computed as current balance + passed delta) /// and compare with actual balances at the end of a multicall, reverts /// if at least one is less than expected /// @param expected Array of expected balance changes /// @notice This is an extenstion function that does not exist in the Credit Facade /// itself and can only be used within a multicall function revertIfReceivedLessThan(Balance[] memory expected) external; /// @dev Disables a token on the caller's Credit Account /// @param token Token to disable /// @notice This is an extenstion function that does not exist in the Credit Facade /// itself and can only be used within a multicall function disableToken(address token) external; } interface ICreditFacadeEvents { /// @dev Emits when a new Credit Account is opened through the /// Credit Facade event OpenCreditAccount( address indexed onBehalfOf, address indexed creditAccount, uint256 borrowAmount, uint16 referralCode ); /// @dev Emits when the account owner closes their CA normally event CloseCreditAccount(address indexed owner, address indexed to); /// @dev Emits when a Credit Account is liquidated due to low health factor event LiquidateCreditAccount( address indexed owner, address indexed liquidator, address indexed to, uint256 remainingFunds ); /// @dev Emits when a Credit Account is liquidated due to expiry event LiquidateExpiredCreditAccount( address indexed owner, address indexed liquidator, address indexed to, uint256 remainingFunds ); /// @dev Emits when the account owner increases CA's debt event IncreaseBorrowedAmount(address indexed borrower, uint256 amount); /// @dev Emits when the account owner reduces CA's debt event DecreaseBorrowedAmount(address indexed borrower, uint256 amount); /// @dev Emits when the account owner add new collateral to a CA event AddCollateral( address indexed onBehalfOf, address indexed token, uint256 value ); /// @dev Emits when a multicall is started event MultiCallStarted(address indexed borrower); /// @dev Emits when a multicall is finished event MultiCallFinished(); /// @dev Emits when Credit Account ownership is transferred event TransferAccount(address indexed oldOwner, address indexed newOwner); /// @dev Emits when the user changes approval for account transfers to itself from another address event TransferAccountAllowed( address indexed from, address indexed to, bool state ); /// @dev Emits when the account owner enables a token on their CA event TokenEnabled(address creditAccount, address token); /// @dev Emits when the account owner disables a token on their CA event TokenDisabled(address creditAccount, address token); } interface ICreditFacadeExceptions is ICreditManagerV2Exceptions { /// @dev Thrown if the CreditFacade is not expirable, and an aciton is attempted that /// requires expirability error NotAllowedWhenNotExpirableException(); /// @dev Thrown if whitelisted mode is enabled, and an action is attempted that is /// not allowed in whitelisted mode error NotAllowedInWhitelistedMode(); /// @dev Thrown if a user attempts to transfer a CA to an address that didn't allow it error AccountTransferNotAllowedException(); /// @dev Thrown if a liquidator tries to liquidate an account with a health factor above 1 error CantLiquidateWithSuchHealthFactorException(); /// @dev Thrown if a liquidator tries to liquidate an account by expiry while a Credit Facade is not expired error CantLiquidateNonExpiredException(); /// @dev Thrown if call data passed to a multicall is too short error IncorrectCallDataException(); /// @dev Thrown inside account closure multicall if the borrower attempts an action that is forbidden on closing /// an account error ForbiddenDuringClosureException(); /// @dev Thrown if debt increase and decrease are subsequently attempted in one multicall error IncreaseAndDecreaseForbiddenInOneCallException(); /// @dev Thrown if a selector that doesn't match any allowed function is passed to the Credit Facade /// during a multicall error UnknownMethodException(); /// @dev Thrown if a user tries to open an account or increase debt with increaseDebtForbidden mode on error IncreaseDebtForbiddenException(); /// @dev Thrown if the account owner tries to transfer an unhealthy account error CantTransferLiquidatableAccountException(); /// @dev Thrown if too much new debt was taken within a single block error BorrowedBlockLimitException(); /// @dev Thrown if the new debt principal for a CA falls outside of borrowing limits error BorrowAmountOutOfLimitsException(); /// @dev Thrown if one of the balances on a Credit Account is less than expected /// at the end of a multicall, if revertIfReceivedLessThan was called error BalanceLessThanMinimumDesiredException(address); /// @dev Thrown if a user attempts to open an account on a Credit Facade that has expired error OpenAccountNotAllowedAfterExpirationException(); /// @dev Thrown if expected balances are attempted to be set through revertIfReceivedLessThan twice error ExpectedBalancesAlreadySetException(); /// @dev Thrown if a Credit Account has enabled forbidden tokens and the owner attempts to perform an action /// that is not allowed with any forbidden tokens enabled error ActionProhibitedWithForbiddenTokensException(); } interface ICreditFacade is ICreditFacadeEvents, ICreditFacadeExceptions, IVersion { // // CREDIT ACCOUNT MANAGEMENT // /// @dev Opens credit account, borrows funds from the pool and pulls collateral /// without any additional action. /// @param amount The amount of collateral provided by the borrower /// @param onBehalfOf The address to open an account for. Transfers to it have to be allowed if /// msg.sender != obBehalfOf /// @param leverageFactor Percentage of the user's own funds to borrow. 100 is equal to 100% - borrows the same amount /// as the user's own collateral, equivalent to 2x leverage. /// @param referralCode Referral code that is used for potential rewards. 0 if no referral code provided. function openCreditAccount( uint256 amount, address onBehalfOf, uint16 leverageFactor, uint16 referralCode ) external payable; /// @dev Opens a Credit Account and runs a batch of operations in a multicall /// @param borrowedAmount Debt size /// @param onBehalfOf The address to open an account for. Transfers to it have to be allowed if /// msg.sender != obBehalfOf /// @param calls The array of MultiCall structs encoding the required operations. Generally must have /// at least a call to addCollateral, as otherwise the health check at the end will fail. /// @param referralCode Referral code which is used for potential rewards. 0 if no referral code provided function openCreditAccountMulticall( uint256 borrowedAmount, address onBehalfOf, MultiCall[] calldata calls, uint16 referralCode ) external payable; /// @dev Runs a batch of transactions within a multicall and closes the account /// - Wraps ETH to WETH and sends it msg.sender if value > 0 /// - Executes the multicall - the main purpose of a multicall when closing is to convert all assets to underlying /// in order to pay the debt. /// - Closes credit account: /// + Checks the underlying balance: if it is greater than the amount paid to the pool, transfers the underlying /// from the Credit Account and proceeds. If not, tries to transfer the shortfall from msg.sender. /// + Transfers all enabled assets with non-zero balances to the "to" address, unless they are marked /// to be skipped in skipTokenMask /// + If convertWETH is true, converts WETH into ETH before sending to the recipient /// - Emits a CloseCreditAccount event /// /// @param to Address to send funds to during account closing /// @param skipTokenMask Uint-encoded bit mask where 1's mark tokens that shouldn't be transferred /// @param convertWETH If true, converts WETH into ETH before sending to "to" /// @param calls The array of MultiCall structs encoding the operations to execute before closing the account. function closeCreditAccount( address to, uint256 skipTokenMask, bool convertWETH, MultiCall[] calldata calls ) external payable; /// @dev Runs a batch of transactions within a multicall and liquidates the account /// - Computes the total value and checks that hf < 1. An account can't be liquidated when hf >= 1. /// Total value has to be computed before the multicall, otherwise the liquidator would be able /// to manipulate it. /// - Wraps ETH to WETH and sends it to msg.sender (liquidator) if value > 0 /// - Executes the multicall - the main purpose of a multicall when liquidating is to convert all assets to underlying /// in order to pay the debt. /// - Liquidate credit account: /// + Computes the amount that needs to be paid to the pool. If totalValue * liquidationDiscount < borrow + interest + fees, /// only totalValue * liquidationDiscount has to be paid. Since liquidationDiscount < 1, the liquidator can take /// totalValue * (1 - liquidationDiscount) as premium. Also computes the remaining funds to be sent to borrower /// as totalValue * liquidationDiscount - amountToPool. /// + Checks the underlying balance: if it is greater than amountToPool + remainingFunds, transfers the underlying /// from the Credit Account and proceeds. If not, tries to transfer the shortfall from the liquidator. /// + Transfers all enabled assets with non-zero balances to the "to" address, unless they are marked /// to be skipped in skipTokenMask. If the liquidator is confident that all assets were converted /// during the multicall, they can set the mask to uint256.max - 1, to only transfer the underlying /// + If convertWETH is true, converts WETH into ETH before sending /// - Emits LiquidateCreditAccount event /// /// @param to Address to send funds to after liquidation /// @param skipTokenMask Uint-encoded bit mask where 1's mark tokens that shouldn't be transferred /// @param convertWETH If true, converts WETH into ETH before sending to "to" /// @param calls The array of MultiCall structs encoding the operations to execute before liquidating the account. function liquidateCreditAccount( address borrower, address to, uint256 skipTokenMask, bool convertWETH, MultiCall[] calldata calls ) external payable; /// @dev Runs a batch of transactions within a multicall and liquidates the account when /// this Credit Facade is expired /// The general flow of liquidation is nearly the same as normal liquidations, with two main differences: /// - An account can be liquidated on an expired Credit Facade even with hf > 1. However, /// no accounts can be liquidated through this function if the Credit Facade is not expired. /// - Liquidation premiums and fees for liquidating expired accounts are reduced. /// It is still possible to normally liquidate an underwater Credit Account, even when the Credit Facade /// is expired. /// @param to Address to send funds to after liquidation /// @param skipTokenMask Uint-encoded bit mask where 1's mark tokens that shouldn't be transferred /// @param convertWETH If true, converts WETH into ETH before sending to "to" /// @param calls The array of MultiCall structs encoding the operations to execute before liquidating the account. /// @notice See more at https://dev.gearbox.fi/docs/documentation/credit/liquidation#liquidating-accounts-by-expiration function liquidateExpiredCreditAccount( address borrower, address to, uint256 skipTokenMask, bool convertWETH, MultiCall[] calldata calls ) external payable; /// @dev Increases debt for msg.sender's Credit Account /// - Borrows the requested amount from the pool /// - Updates the CA's borrowAmount / cumulativeIndexOpen /// to correctly compute interest going forward /// - Performs a full collateral check /// /// @param amount Amount to borrow function increaseDebt(uint256 amount) external; /// @dev Decrease debt /// - Decreases the debt by paying the requested amount + accrued interest + fees back to the pool /// - It's also include to this payment interest accrued at the moment and fees /// - Updates cunulativeIndex to cumulativeIndex now /// /// @param amount Amount to increase borrowed amount function decreaseDebt(uint256 amount) external; /// @dev Adds collateral to borrower's credit account /// @param onBehalfOf Address of the borrower whose account is funded /// @param token Address of a collateral token /// @param amount Amount to add function addCollateral( address onBehalfOf, address token, uint256 amount ) external payable; /// @dev Executes a batch of transactions within a Multicall, to manage an existing account /// - Wraps ETH and sends it back to msg.sender, if value > 0 /// - Executes the Multicall /// - Performs a fullCollateralCheck to verify that hf > 1 after all actions /// @param calls The array of MultiCall structs encoding the operations to execute. function multicall(MultiCall[] calldata calls) external payable; /// @dev Returns true if the borrower has an open Credit Account /// @param borrower Borrower address function hasOpenedCreditAccount(address borrower) external view returns (bool); /// @dev Sets token allowance from msg.sender's Credit Account to a connected target contract /// @param targetContract Contract to set allowance to. Cannot be in the list of upgradeable contracts /// @param token Token address /// @param amount Allowance amount function approve( address targetContract, address token, uint256 amount ) external; /// @dev Approves account transfer from another user to msg.sender /// @param from Address for which account transfers are allowed/forbidden /// @param state True is transfer is allowed, false if forbidden function approveAccountTransfer(address from, bool state) external; /// @dev Enables token in enabledTokenMask for the Credit Account of msg.sender /// @param token Address of token to enable function enableToken(address token) external; /// @dev Transfers credit account to another user /// By default, this action is forbidden, and the user has to approve transfers from sender to itself /// by calling approveAccountTransfer. /// This is done to prevent malicious actors from transferring compromised accounts to other users. /// @param to Address to transfer the account to function transferAccountOwnership(address to) external; // // GETTERS // /// @dev Calculates total value for provided Credit Account in underlying /// /// @param creditAccount Credit Account address /// @return total Total value in underlying /// @return twv Total weighted (discounted by liquidation thresholds) value in underlying function calcTotalValue(address creditAccount) external view returns (uint256 total, uint256 twv); /** * @dev Calculates health factor for the credit account * * sum(asset[i] * liquidation threshold[i]) * Hf = -------------------------------------------- * borrowed amount + interest accrued + fees * * * More info: https://dev.gearbox.fi/developers/credit/economy#health-factor * * @param creditAccount Credit account address * @return hf = Health factor in bp (see PERCENTAGE FACTOR in PercentageMath.sol) */ function calcCreditAccountHealthFactor(address creditAccount) external view returns (uint256 hf); /// @dev Returns true if token is a collateral token and is not forbidden, /// otherwise returns false /// @param token Token to check function isTokenAllowed(address token) external view returns (bool); /// @dev Returns the CreditManager connected to this Credit Facade function creditManager() external view returns (ICreditManagerV2); /// @dev Returns true if 'from' is allowed to transfer Credit Accounts to 'to' /// @param from Sender address to check allowance for /// @param to Receiver address to check allowance for function transfersAllowed(address from, address to) external view returns (bool); /// @return maxBorrowedAmountPerBlock Maximal amount of new debt that can be taken per block /// @return isIncreaseDebtForbidden True if increasing debt is forbidden /// @return expirationDate Timestamp of the next expiration (for expirable Credit Facades only) function params() external view returns ( uint128 maxBorrowedAmountPerBlock, bool isIncreaseDebtForbidden, uint40 expirationDate ); /// @return minBorrowedAmount Minimal borrowed amount per credit account /// @return maxBorrowedAmount Maximal borrowed amount per credit account function limits() external view returns (uint128 minBorrowedAmount, uint128 maxBorrowedAmount); /// @dev Address of the DegenNFT that gatekeeps account openings in whitelisted mode function degenNFT() external view returns (address); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.9; import { IAdapter } from "./helpers/IAdapter.sol"; import { ICurvePool } from "./helpers/curve/ICurvePool.sol"; interface ICurveV1AdapterExceptions { error IncorrectIndexException(); } interface ICurveV1Adapter is IAdapter, ICurvePool, ICurveV1AdapterExceptions { /// @dev Sends an order to exchange the entire balance of one asset to another /// @param i Index for the coin sent /// @param j Index for the coin received /// @param rateMinRAY Minimum exchange rate between coins i and j function exchange_all( int128 i, int128 j, uint256 rateMinRAY ) external; /// @dev Sends an order to exchange the entire balance of one underlying asset to another /// @param i Index for the underlying coin sent /// @param j Index for the underlying coin received /// @param rateMinRAY Minimum exchange rate between underlyings i and j function exchange_all_underlying( int128 i, int128 j, uint256 rateMinRAY ) external; /// @dev Sends an order to add liquidity with only 1 input asset /// @param amount Amount of asset to deposit /// @param i Index of the asset to deposit /// @param minAmount Minimal number of LP tokens to receive function add_liquidity_one_coin( uint256 amount, int128 i, uint256 minAmount ) external; /// @dev Sends an order to add liquidity with only 1 input asset, using the entire balance /// @param i Index of the asset to deposit /// @param rateMinRAY Minimal exchange rate between the deposited asset and the LP token function add_all_liquidity_one_coin(int128 i, uint256 rateMinRAY) external; /// @dev Sends an order to remove all liquidity from the pool in a single asset /// @param i Index of the asset to withdraw /// @param minRateRAY Minimal exchange rate between the LP token and the received token function remove_all_liquidity_one_coin(int128 i, uint256 minRateRAY) external; // // GETTERS // /// @dev The pool LP token function lp_token() external view returns (address); /// @dev Address of the base pool (for metapools only) function metapoolBase() external view returns (address); /// @dev Number of coins in the pool function nCoins() external view returns (uint256); /// @dev Token in the pool under index 0 function token0() external view returns (address); /// @dev Token in the pool under index 1 function token1() external view returns (address); /// @dev Token in the pool under index 2 function token2() external view returns (address); /// @dev Token in the pool under index 3 function token3() external view returns (address); /// @dev Underlying in the pool under index 0 function underlying0() external view returns (address); /// @dev Underlying in the pool under index 1 function underlying1() external view returns (address); /// @dev Underlying in the pool under index 2 function underlying2() external view returns (address); /// @dev Underlying in the pool under index 3 function underlying3() external view returns (address); /// @dev Returns the amount of lp token received when adding a single coin to the pool /// @param amount Amount of coin to be deposited /// @param i Index of a coin to be deposited function calc_add_one_coin(uint256 amount, int128 i) external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.9; import { IAdapter } from "./helpers/IAdapter.sol"; import { ISwapRouter } from "./helpers/uniswap/IUniswapV3.sol"; interface IUniswapV3AdapterExceptions { error IncorrectPathLengthException(); } interface IUniswapV3Adapter is IAdapter, ISwapRouter, IUniswapV3AdapterExceptions { /// @dev A struct encoding parameters for exactAllInputSingle, /// which is unique to the Gearbox adapter /// @param tokenIn Token that is spent by the swap /// @param tokenOut Token that is received from the swap /// @param fee The fee category to use /// @param deadline The timestamp, after which the swap will revert /// @param rateMinRAY The minimal exhange rate between tokenIn and tokenOut /// used to calculate amountOutMin on the spot, since the input amount /// may not always be known in advance /// @param sqrtPriceLimitX96 The max execution price. Will be ignored if set to 0. struct ExactAllInputSingleParams { address tokenIn; address tokenOut; uint24 fee; uint256 deadline; uint256 rateMinRAY; uint160 sqrtPriceLimitX96; } /// @notice Sends an order to swap the entire balance of one token for as much as possible of another token /// - Fills the `ExactInputSingleParams` struct /// - Makes a max allowance fast check call, passing the new struct as params /// @param params The parameters necessary for the swap, encoded as `ExactAllInputSingleParams` in calldata function exactAllInputSingle(ExactAllInputSingleParams calldata params) external returns (uint256 amountOut); /// @dev A struct encoding parameters for exactAllInput, /// which is unique to the Gearbox adapter /// @param path Bytes array encoding the sequence of swaps to perform, /// in the format TOKEN_FEE_TOKEN_FEE_TOKEN... /// @param deadline The timestamp, after which the swap will revert /// @param rateMinRAY The minimal exhange rate between tokenIn and tokenOut /// used to calculate amountOutMin on the spot, since the input amount /// may not always be known in advance struct ExactAllInputParams { bytes path; uint256 deadline; uint256 rateMinRAY; } /// @notice Swaps the entire balance of one token for as much as possible of another along the specified path /// - Fills the `ExactAllInputParams` struct /// - Makes a max allowance fast check call, passing the new struct as `params` /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactAllInputParams` in calldata function exactAllInput(ExactAllInputParams calldata params) external returns (uint256 amountOut); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.9; import { ICreditManagerV2 } from "./ICreditManagerV2.sol"; enum AdapterType { ABSTRACT, UNISWAP_V2_ROUTER, UNISWAP_V3_ROUTER, CURVE_V1_EXCHANGE_ONLY, YEARN_V2, CURVE_V1_2ASSETS, CURVE_V1_3ASSETS, CURVE_V1_4ASSETS, CURVE_V1_STECRV_POOL, CURVE_V1_WRAPPER, CONVEX_V1_BASE_REWARD_POOL, CONVEX_V1_BOOSTER, CONVEX_V1_CLAIM_ZAP, LIDO_V1, UNIVERSAL } interface IAdapterExceptions { /// @dev Thrown when the adapter attempts to use a token /// that is not recognized as collateral in the connected /// Credit Manager error TokenIsNotInAllowedList(address); } interface IAdapter is IAdapterExceptions { /// @dev Returns the Credit Manager connected to the adapter function creditManager() external view returns (ICreditManagerV2); /// @dev Returns the Credit Facade connected to the adapter's Credit Manager function creditFacade() external view returns (address); /// @dev Returns the address of the contract the adapter is interacting with function targetContract() external view returns (address); /// @dev Returns the adapter type function _gearboxAdapterType() external pure returns (AdapterType); /// @dev Returns the adapter version function _gearboxAdapterVersion() external pure returns (uint16); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.9; import { IPriceOracleV2 } from "./IPriceOracle.sol"; import { IVersion } from "./IVersion.sol"; enum ClosureAction { CLOSE_ACCOUNT, LIQUIDATE_ACCOUNT, LIQUIDATE_EXPIRED_ACCOUNT, LIQUIDATE_PAUSED } interface ICreditManagerV2Events { /// @dev Emits when a call to an external contract is made through the Credit Manager event ExecuteOrder(address indexed borrower, address indexed target); /// @dev Emits when a configurator is upgraded event NewConfigurator(address indexed newConfigurator); } interface ICreditManagerV2Exceptions { /// @dev Thrown if an access-restricted function is called by an address that is not /// the connected Credit Facade, or an allowed adapter error AdaptersOrCreditFacadeOnlyException(); /// @dev Thrown if an access-restricted function is called by an address that is not /// the connected Credit Facade error CreditFacadeOnlyException(); /// @dev Thrown if an access-restricted function is called by an address that is not /// the connected Credit Configurator error CreditConfiguratorOnlyException(); /// @dev Thrown on attempting to open a Credit Account for or transfer a Credit Account /// to the zero address or an address that already owns a Credit Account error ZeroAddressOrUserAlreadyHasAccountException(); /// @dev Thrown on attempting to execute an order to an address that is not an allowed /// target contract error TargetContractNotAllowedException(); /// @dev Thrown on failing a full collateral check after an operation error NotEnoughCollateralException(); /// @dev Thrown on attempting to receive a token that is not a collateral token /// or was forbidden error TokenNotAllowedException(); /// @dev Thrown if an attempt to approve a collateral token to a target contract failed error AllowanceFailedException(); /// @dev Thrown on attempting to perform an action for an address that owns no Credit Account error HasNoOpenedAccountException(); /// @dev Thrown on attempting to add a token that is already in a collateral list error TokenAlreadyAddedException(); /// @dev Thrown on configurator attempting to add more than 256 collateral tokens error TooManyTokensException(); /// @dev Thrown if more than the maximal number of tokens were enabled on a Credit Account, /// and there are not enough unused token to disable error TooManyEnabledTokensException(); /// @dev Thrown when a reentrancy into the contract is attempted error ReentrancyLockException(); } /// @notice All Credit Manager functions are access-restricted and can only be called /// by the Credit Facade or allowed adapters. Users are not allowed to /// interact with the Credit Manager directly interface ICreditManagerV2 is ICreditManagerV2Events, ICreditManagerV2Exceptions, IVersion { // // CREDIT ACCOUNT MANAGEMENT // /// @dev Opens credit account and borrows funds from the pool. /// - Takes Credit Account from the factory; /// - Requests the pool to lend underlying to the Credit Account /// /// @param borrowedAmount Amount to be borrowed by the Credit Account /// @param onBehalfOf The owner of the newly opened Credit Account function openCreditAccount(uint256 borrowedAmount, address onBehalfOf) external returns (address); /// @dev Closes a Credit Account - covers both normal closure and liquidation /// - Checks whether the contract is paused, and, if so, if the payer is an emergency liquidator. /// Only emergency liquidators are able to liquidate account while the CM is paused. /// Emergency liquidations do not pay a liquidator premium or liquidation fees. /// - Calculates payments to various recipients on closure: /// + Computes amountToPool, which is the amount to be sent back to the pool. /// This includes the principal, interest and fees, but can't be more than /// total position value /// + Computes remainingFunds during liquidations - these are leftover funds /// after paying the pool and the liquidator, and are sent to the borrower /// + Computes protocol profit, which includes interest and liquidation fees /// + Computes loss if the totalValue is less than borrow amount + interest /// - Checks the underlying token balance: /// + if it is larger than amountToPool, then the pool is paid fully from funds on the Credit Account /// + else tries to transfer the shortfall from the payer - either the borrower during closure, or liquidator during liquidation /// - Send assets to the "to" address, as long as they are not included into skipTokenMask /// - If convertWETH is true, the function converts WETH into ETH before sending /// - Returns the Credit Account back to factory /// /// @param borrower Borrower address /// @param closureActionType Whether the account is closed, liquidated or liquidated due to expiry /// @param totalValue Portfolio value for liqution, 0 for ordinary closure /// @param payer Address which would be charged if credit account has not enough funds to cover amountToPool /// @param to Address to which the leftover funds will be sent /// @param skipTokenMask Tokenmask contains 1 for tokens which needed to be skipped for sending /// @param convertWETH If true converts WETH to ETH function closeCreditAccount( address borrower, ClosureAction closureActionType, uint256 totalValue, address payer, address to, uint256 skipTokenMask, bool convertWETH ) external returns (uint256 remainingFunds); /// @dev Manages debt size for borrower: /// /// - Increase debt: /// + Increases debt by transferring funds from the pool to the credit account /// + Updates the cumulative index to keep interest the same. Since interest /// is always computed dynamically as borrowedAmount * (cumulativeIndexNew / cumulativeIndexOpen - 1), /// cumulativeIndexOpen needs to be updated, as the borrow amount has changed /// /// - Decrease debt: /// + Repays debt partially + all interest and fees accrued thus far /// + Updates cunulativeIndex to cumulativeIndex now /// /// @param creditAccount Address of the Credit Account to change debt for /// @param amount Amount to increase / decrease the principal by /// @param increase True to increase principal, false to decrease /// @return newBorrowedAmount The new debt principal function manageDebt( address creditAccount, uint256 amount, bool increase ) external returns (uint256 newBorrowedAmount); /// @dev Adds collateral to borrower's credit account /// @param payer Address of the account which will be charged to provide additional collateral /// @param creditAccount Address of the Credit Account /// @param token Collateral token to add /// @param amount Amount to add function addCollateral( address payer, address creditAccount, address token, uint256 amount ) external; /// @dev Transfers Credit Account ownership to another address /// @param from Address of previous owner /// @param to Address of new owner function transferAccountOwnership(address from, address to) external; /// @dev Requests the Credit Account to approve a collateral token to another contract. /// @param borrower Borrower's address /// @param targetContract Spender to change allowance for /// @param token Collateral token to approve /// @param amount New allowance amount function approveCreditAccount( address borrower, address targetContract, address token, uint256 amount ) external; /// @dev Requests a Credit Account to make a low-level call with provided data /// This is the intended pathway for state-changing interactions with 3rd-party protocols /// @param borrower Borrower's address /// @param targetContract Contract to be called /// @param data Data to pass with the call function executeOrder( address borrower, address targetContract, bytes memory data ) external returns (bytes memory); // // COLLATERAL VALIDITY AND ACCOUNT HEALTH CHECKS // /// @dev Enables a token on a Credit Account, including it /// into account health and total value calculations /// @param creditAccount Address of a Credit Account to enable the token for /// @param token Address of the token to be enabled function checkAndEnableToken(address creditAccount, address token) external; /// @dev Optimized health check for individual swap-like operations. /// @notice Fast health check assumes that only two tokens (input and output) /// participate in the operation and computes a % change in weighted value between /// inbound and outbound collateral. The cumulative negative change across several /// swaps in sequence cannot be larger than feeLiquidation (a fee that the /// protocol is ready to waive if needed). Since this records a % change /// between just two tokens, the corresponding % change in TWV will always be smaller, /// which makes this check safe. /// More details at https://dev.gearbox.fi/docs/documentation/risk/fast-collateral-check#fast-check-protection /// @param creditAccount Address of the Credit Account /// @param tokenIn Address of the token spent by the swap /// @param tokenOut Address of the token received from the swap /// @param balanceInBefore Balance of tokenIn before the operation /// @param balanceOutBefore Balance of tokenOut before the operation function fastCollateralCheck( address creditAccount, address tokenIn, address tokenOut, uint256 balanceInBefore, uint256 balanceOutBefore ) external; /// @dev Performs a full health check on an account, summing up /// value of all enabled collateral tokens /// @param creditAccount Address of the Credit Account to check function fullCollateralCheck(address creditAccount) external; /// @dev Checks that the number of enabled tokens on a Credit Account /// does not violate the maximal enabled token limit and tries /// to disable unused tokens if it does /// @param creditAccount Account to check enabled tokens for function checkAndOptimizeEnabledTokens(address creditAccount) external; /// @dev Disables a token on a credit account /// @notice Usually called by adapters to disable spent tokens during a multicall, /// but can also be called separately from the Credit Facade to remove /// unwanted tokens function disableToken(address creditAccount, address token) external; // // GETTERS // /// @dev Returns the address of a borrower's Credit Account, or reverts if there is none. /// @param borrower Borrower's address function getCreditAccountOrRevert(address borrower) external view returns (address); /// @dev Computes amounts that must be sent to various addresses before closing an account /// @param totalValue Credit Accounts total value in underlying /// @param closureActionType Type of account closure /// * CLOSE_ACCOUNT: The account is healthy and is closed normally /// * LIQUIDATE_ACCOUNT: The account is unhealthy and is being liquidated to avoid bad debt /// * LIQUIDATE_EXPIRED_ACCOUNT: The account has expired and is being liquidated (lowered liquidation premium) /// * LIQUIDATE_PAUSED: The account is liquidated while the system is paused due to emergency (no liquidation premium) /// @param borrowedAmount Credit Account's debt principal /// @param borrowedAmountWithInterest Credit Account's debt principal + interest /// @return amountToPool Amount of underlying to be sent to the pool /// @return remainingFunds Amount of underlying to be sent to the borrower (only applicable to liquidations) /// @return profit Protocol's profit from fees (if any) /// @return loss Protocol's loss from bad debt (if any) function calcClosePayments( uint256 totalValue, ClosureAction closureActionType, uint256 borrowedAmount, uint256 borrowedAmountWithInterest ) external view returns ( uint256 amountToPool, uint256 remainingFunds, uint256 profit, uint256 loss ); /// @dev Calculates the debt accrued by a Credit Account /// @param creditAccount Address of the Credit Account /// @return borrowedAmount The debt principal /// @return borrowedAmountWithInterest The debt principal + accrued interest /// @return borrowedAmountWithInterestAndFees The debt principal + accrued interest and protocol fees function calcCreditAccountAccruedInterest(address creditAccount) external view returns ( uint256 borrowedAmount, uint256 borrowedAmountWithInterest, uint256 borrowedAmountWithInterestAndFees ); /// @dev Maps Credit Accounts to bit masks encoding their enabled token sets /// Only enabled tokens are counted as collateral for the Credit Account /// @notice An enabled token mask encodes an enabled token by setting /// the bit at the position equal to token's index to 1 function enabledTokensMap(address creditAccount) external view returns (uint256); /// @dev Maps the Credit Account to its current percentage drop across all swaps since /// the last full check, in RAY format function cumulativeDropAtFastCheckRAY(address creditAccount) external view returns (uint256); /// @dev Returns the collateral token at requested index and its liquidation threshold /// @param id The index of token to return function collateralTokens(uint256 id) external view returns (address token, uint16 liquidationThreshold); /// @dev Returns the collateral token with requested mask and its liquidationThreshold /// @param tokenMask Token mask corresponding to the token function collateralTokensByMask(uint256 tokenMask) external view returns (address token, uint16 liquidationThreshold); /// @dev Total number of known collateral tokens. function collateralTokensCount() external view returns (uint256); /// @dev Returns the mask for the provided token /// @param token Token to returns the mask for function tokenMasksMap(address token) external view returns (uint256); /// @dev Bit mask encoding a set of forbidden tokens function forbiddenTokenMask() external view returns (uint256); /// @dev Maps allowed adapters to their respective target contracts. function adapterToContract(address adapter) external view returns (address); /// @dev Maps 3rd party contracts to their respective adapters function contractToAdapter(address targetContract) external view returns (address); /// @dev Address of the underlying asset function underlying() external view returns (address); /// @dev Address of the connected pool function pool() external view returns (address); /// @dev Address of the connected pool /// @notice [DEPRECATED]: use pool() instead. function poolService() external view returns (address); /// @dev A map from borrower addresses to Credit Account addresses function creditAccounts(address borrower) external view returns (address); /// @dev Address of the connected Credit Configurator function creditConfigurator() external view returns (address); /// @dev Address of WETH function wethAddress() external view returns (address); /// @dev Returns the liquidation threshold for the provided token /// @param token Token to retrieve the LT for function liquidationThresholds(address token) external view returns (uint16); /// @dev The maximal number of enabled tokens on a single Credit Account function maxAllowedEnabledTokenLength() external view returns (uint8); /// @dev Maps addresses to their status as emergency liquidator. /// @notice Emergency liquidators are trusted addresses /// that are able to liquidate positions while the contracts are paused, /// e.g. when there is a risk of bad debt while an exploit is being patched. /// In the interest of fairness, emergency liquidators do not receive a premium /// And are compensated by the Gearbox DAO separately. function canLiquidateWhilePaused(address) external view returns (bool); /// @dev Returns the fee parameters of the Credit Manager /// @return feeInterest Percentage of interest taken by the protocol as profit /// @return feeLiquidation Percentage of account value taken by the protocol as profit /// during unhealthy account liquidations /// @return liquidationDiscount Multiplier that reduces the effective totalValue during unhealthy account liquidations, /// allowing the liquidator to take the unaccounted for remainder as premium. Equal to (1 - liquidationPremium) /// @return feeLiquidationExpired Percentage of account value taken by the protocol as profit /// during expired account liquidations /// @return liquidationDiscountExpired Multiplier that reduces the effective totalValue during expired account liquidations, /// allowing the liquidator to take the unaccounted for remainder as premium. Equal to (1 - liquidationPremiumExpired) function fees() external view returns ( uint16 feeInterest, uint16 feeLiquidation, uint16 liquidationDiscount, uint16 feeLiquidationExpired, uint16 liquidationDiscountExpired ); /// @dev Address of the connected Credit Facade function creditFacade() external view returns (address); /// @dev Address of the connected Price Oracle function priceOracle() external view returns (IPriceOracleV2); /// @dev Address of the universal adapter function universalAdapter() external view returns (address); /// @dev Contract's version function version() external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.9; import { IVersion } from "./IVersion.sol"; interface IPriceOracleV2Events { /// @dev Emits when a new price feed is added event NewPriceFeed(address indexed token, address indexed priceFeed); } interface IPriceOracleV2Exceptions { /// @dev Thrown if a price feed returns 0 error ZeroPriceException(); /// @dev Thrown if the last recorded result was not updated in the last round error ChainPriceStaleException(); /// @dev Thrown on attempting to get a result for a token that does not have a price feed error PriceOracleNotExistsException(); } /// @title Price oracle interface interface IPriceOracleV2 is IPriceOracleV2Events, IPriceOracleV2Exceptions, IVersion { /// @dev Converts a quantity of an asset to USD (decimals = 8). /// @param amount Amount to convert /// @param token Address of the token to be converted function convertToUSD(uint256 amount, address token) external view returns (uint256); /// @dev Converts a quantity of USD (decimals = 8) to an equivalent amount of an asset /// @param amount Amount to convert /// @param token Address of the token converted to function convertFromUSD(uint256 amount, address token) external view returns (uint256); /// @dev Converts one asset into another /// /// @param amount Amount to convert /// @param tokenFrom Address of the token to convert from /// @param tokenTo Address of the token to convert to function convert( uint256 amount, address tokenFrom, address tokenTo ) external view returns (uint256); /// @dev Returns collateral values for two tokens, required for a fast check /// @param amountFrom Amount of the outbound token /// @param tokenFrom Address of the outbound token /// @param amountTo Amount of the inbound token /// @param tokenTo Address of the inbound token /// @return collateralFrom Value of the outbound token amount in USD /// @return collateralTo Value of the inbound token amount in USD function fastCheck( uint256 amountFrom, address tokenFrom, uint256 amountTo, address tokenTo ) external view returns (uint256 collateralFrom, uint256 collateralTo); /// @dev Returns token's price in USD (8 decimals) /// @param token The token to compute the price for function getPrice(address token) external view returns (uint256); /// @dev Returns the price feed address for the passed token /// @param token Token to get the price feed for function priceFeeds(address token) external view returns (address priceFeed); /// @dev Returns the price feed for the passed token, /// with additional parameters /// @param token Token to get the price feed for function priceFeedsWithFlags(address token) external view returns ( address priceFeed, bool skipCheck, uint256 decimals ); } interface IPriceOracleV2Ext is IPriceOracleV2 { /// @dev Sets a price feed if it doesn't exist, or updates an existing one /// @param token Address of the token to set the price feed for /// @param priceFeed Address of a USD price feed adhering to Chainlink's interface function addPriceFeed(address token, address priceFeed) external; }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.9; /// @title IVersion /// @dev Declares a version function which returns the contract's version interface IVersion { /// @dev Returns contract version function version() external view returns (uint256); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IBaseRewardPool { // // STATE CHANGING FUNCTIONS // function stake(uint256 _amount) external returns (bool); function stakeAll() external returns (bool); function stakeFor(address _for, uint256 _amount) external returns (bool); function withdraw(uint256 amount, bool claim) external returns (bool); function withdrawAll(bool claim) external; function withdrawAndUnwrap(uint256 amount, bool claim) external returns (bool); function withdrawAllAndUnwrap(bool claim) external; function getReward(address _account, bool _claimExtras) external returns (bool); function getReward() external returns (bool); function donate(uint256 _amount) external returns (bool); // // GETTERS // function earned(address account) external view returns (uint256); function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function extraRewardsLength() external view returns (uint256); function lastTimeRewardApplicable() external view returns (uint256); function rewardPerToken() external view returns (uint256); function rewardToken() external view returns (IERC20); function stakingToken() external view returns (IERC20); function duration() external view returns (uint256); function operator() external view returns (address); function rewardManager() external view returns (address); function pid() external view returns (uint256); function periodFinish() external view returns (uint256); function rewardRate() external view returns (uint256); function lastUpdateTime() external view returns (uint256); function rewardPerTokenStored() external view returns (uint256); function queuedRewards() external view returns (uint256); function currentRewards() external view returns (uint256); function historicalRewards() external view returns (uint256); function newRewardRatio() external view returns (uint256); function userRewardPerTokenPaid(address account) external view returns (uint256); function rewards(address account) external view returns (uint256); function extraRewards(uint256 i) external view returns (address); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; interface IBooster { struct PoolInfo { address lptoken; address token; address gauge; address crvRewards; address stash; bool shutdown; } function deposit( uint256 _pid, uint256 _amount, bool _stake ) external returns (bool); function depositAll(uint256 _pid, bool _stake) external returns (bool); function withdraw(uint256 _pid, uint256 _amount) external returns (bool); function withdrawAll(uint256 _pid) external returns (bool); // function earmarkRewards(uint256 _pid) external returns (bool); // function earmarkFees() external returns (bool); // // GETTERS // function poolInfo(uint256 i) external view returns (PoolInfo memory); function poolLength() external view returns (uint256); function staker() external view returns (address); function minter() external view returns (address); function crv() external view returns (address); function registry() external view returns (address); function stakerRewards() external view returns (address); function lockRewards() external view returns (address); function lockFees() external view returns (address); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.9; interface ICurvePool { function coins(uint256 i) external view returns (address); function underlying_coins(uint256 i) external view returns (address); function balances(uint256 i) external view returns (uint256); function coins(int128) external view returns (address); function underlying_coins(int128) external view returns (address); function balances(int128) external view returns (uint256); function exchange( int128 i, int128 j, uint256 dx, uint256 min_dy ) external; function exchange_underlying( int128 i, int128 j, uint256 dx, uint256 min_dy ) external; function get_dy_underlying( int128 i, int128 j, uint256 dx ) external view returns (uint256); function get_dy( int128 i, int128 j, uint256 dx ) external view returns (uint256); function get_virtual_price() external view returns (uint256); function token() external view returns (address); function remove_liquidity_one_coin( uint256 _token_amount, int128 i, uint256 min_amount ) external; function A() external view returns (uint256); function A_precise() external view returns (uint256); function calc_withdraw_one_coin(uint256 _burn_amount, int128 i) external view returns (uint256); function admin_balances(uint256 i) external view returns (uint256); function admin() external view returns (address); function fee() external view returns (uint256); function admin_fee() external view returns (uint256); function block_timestamp_last() external view returns (uint256); function initial_A() external view returns (uint256); function future_A() external view returns (uint256); function initial_A_time() external view returns (uint256); function future_A_time() external view returns (uint256); // Some pools implement ERC20 function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint256); function balanceOf(address) external view returns (uint256); function allowance(address, address) external view returns (uint256); function totalSupply() external view returns (uint256); }
// SPDX-License-Identifier: GPL-2.0-or-later // Gearbox Protocol. Generalized leverage for DeFi protocols // (c) Gearbox Holdings, 2021 pragma solidity ^0.8.9; struct Balance { address token; uint256 balance; } library BalanceOps { error UnknownToken(address); function copyBalance(Balance memory b) internal pure returns (Balance memory) { return Balance({ token: b.token, balance: b.balance }); } function addBalance( Balance[] memory b, address token, uint256 amount ) internal pure { b[getIndex(b, token)].balance += amount; } function subBalance( Balance[] memory b, address token, uint256 amount ) internal pure { b[getIndex(b, token)].balance -= amount; } function getBalance(Balance[] memory b, address token) internal pure returns (uint256 amount) { return b[getIndex(b, token)].balance; } function setBalance( Balance[] memory b, address token, uint256 amount ) internal pure { b[getIndex(b, token)].balance = amount; } function getIndex(Balance[] memory b, address token) internal pure returns (uint256 index) { for (uint256 i; i < b.length; ) { if (b[i].token == token) { return i; } unchecked { ++i; } } revert UnknownToken(token); } function copy(Balance[] memory b, uint256 len) internal pure returns (Balance[] memory res) { res = new Balance[](len); for (uint256 i; i < len; ) { res[i] = copyBalance(b[i]); unchecked { ++i; } } } function clone(Balance[] memory b) internal pure returns (Balance[] memory) { return copy(b, b.length); } function getModifiedAfterSwap( Balance[] memory b, address tokenFrom, uint256 amountFrom, address tokenTo, uint256 amountTo ) internal pure returns (Balance[] memory res) { res = copy(b, b.length); setBalance(res, tokenFrom, getBalance(b, tokenFrom) - amountFrom); setBalance(res, tokenTo, getBalance(b, tokenTo) + amountTo); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.9; struct MultiCall { address target; bytes callData; } library MultiCallOps { function copyMulticall(MultiCall memory call) internal pure returns (MultiCall memory) { return MultiCall({ target: call.target, callData: call.callData }); } function trim(MultiCall[] memory calls) internal pure returns (MultiCall[] memory trimmed) { uint256 len = calls.length; if (len == 0) return calls; uint256 foundLen; while (calls[foundLen].target != address(0)) { unchecked { ++foundLen; if (foundLen == len) return calls; } } if (foundLen > 0) return copy(calls, foundLen); } function copy(MultiCall[] memory calls, uint256 len) internal pure returns (MultiCall[] memory res) { res = new MultiCall[](len); for (uint256 i; i < len; ) { res[i] = copyMulticall(calls[i]); unchecked { ++i; } } } function clone(MultiCall[] memory calls) internal pure returns (MultiCall[] memory res) { return copy(calls, calls.length); } function append(MultiCall[] memory calls, MultiCall memory newCall) internal pure returns (MultiCall[] memory res) { uint256 len = calls.length; res = new MultiCall[](len + 1); for (uint256 i; i < len; ) { res[i] = copyMulticall(calls[i]); unchecked { ++i; } } res[len] = copyMulticall(newCall); } function prepend(MultiCall[] memory calls, MultiCall memory newCall) internal pure returns (MultiCall[] memory res) { uint256 len = calls.length; res = new MultiCall[](len + 1); res[0] = copyMulticall(newCall); for (uint256 i = 1; i < len + 1; ) { res[i] = copyMulticall(calls[i]); unchecked { ++i; } } } function concat(MultiCall[] memory calls1, MultiCall[] memory calls2) internal pure returns (MultiCall[] memory res) { uint256 len1 = calls1.length; uint256 lenTotal = len1 + calls2.length; if (lenTotal == calls1.length) return clone(calls1); if (lenTotal == calls2.length) return clone(calls2); res = new MultiCall[](lenTotal); for (uint256 i; i < lenTotal; ) { res[i] = (i < len1) ? copyMulticall(calls1[i]) : copyMulticall(calls2[i - len1]); unchecked { ++i; } } } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.7.5; pragma abicoder v2; /// @title Router token swapping functionality /// @notice Functions for swapping tokens via Uniswap V3 interface ISwapRouter { struct ExactInputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; uint160 sqrtPriceLimitX96; } /// @notice Swaps `amountIn` of one token for as much as possible of another token /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata /// @return amountOut The amount of the received token function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut); struct ExactInputParams { bytes path; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; } /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata /// @return amountOut The amount of the received token function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut); struct ExactOutputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; uint160 sqrtPriceLimitX96; } /// @notice Swaps as little as possible of one token for `amountOut` of another token /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata /// @return amountIn The amount of the input token function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn); struct ExactOutputParams { bytes path; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; } /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed) /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata /// @return amountIn The amount of the input token function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn); }
// SPDX-License-Identifier: BSL-1.1 pragma solidity 0.8.9; interface IContractMeta { function contractName() external view returns (string memory); function contractNameBytes() external view returns (bytes32); function contractVersion() external view returns (string memory); function contractVersionBytes() external view returns (bytes32); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "@openzeppelin/contracts/access/IAccessControlEnumerable.sol"; interface IDefaultAccessControl is IAccessControlEnumerable { /// @notice Checks that the address is contract admin. /// @param who Address to check /// @return `true` if who is admin, `false` otherwise function isAdmin(address who) external view returns (bool); /// @notice Checks that the address is contract admin. /// @param who Address to check /// @return `true` if who is operator, `false` otherwise function isOperator(address who) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "./IIntegrationVault.sol"; import "../external/gearbox/ICreditFacade.sol"; import "../external/gearbox/IUniswapV3Adapter.sol"; import "../../utils/GearboxHelper.sol"; interface IGearboxVault is IIntegrationVault { /// @notice Reference to the Gearbox creditFacade contract for the primary token of this vault. function creditFacade() external view returns (ICreditFacade); /// @notice Reference to the Gearbox creditManager contract for the primary token of this vault. function creditManager() external view returns (ICreditManagerV2); /// @notice Primary token of the vault, for this token a credit account is opened in Gearbox. function primaryToken() external view returns (address); /// @notice Deposit token of the vault, deposits/withdawals are made in this token (might be the same or different with primaryToken) function depositToken() external view returns (address); /// @notice Gearbox vault helper function helper() external view returns (GearboxHelper); /// @notice The leverage factor of the vault, multiplied by 10^9 /// For a vault with X usd of collateral and marginal factor T >= 1, total assets (collateral + debt) should be equal to X * T function marginalFactorD9() external view returns (uint256); /// @notice Index used for claiming in Gearbox V2 Degen contract function merkleIndex() external view returns (uint256); /// @notice NFTs amount used for claiming in Gearbox V2 Degen contract function merkleTotalAmount() external view returns (uint256); /// @notice Proof used for claiming in Gearbox V2 Degen contract function getMerkleProof() external view returns (bytes32[] memory); /// @notice The index of the curve pool the vault invests into function poolId() external view returns (uint256); /// @notice The index of the primary token in the used curve pool function primaryIndex() external view returns (int128); /// @notice The address of the convex token we receive after staking Convex LPs function convexOutputToken() external view returns (address); /// @notice Adds an array of pools into the set of approved pools (opening a credit account is allowed by our protocol only for operations in such pools) /// @param pools List of pools function addPoolsToAllowList(uint256[] calldata pools) external; /// @notice Remove an array of pools from the set of approved pools (opening a credit account is allowed by our protocol only for operations in such pools) /// @param pools List of pools function removePoolsFromAllowlist(uint256[] calldata pools) external; /// @notice Initialized a new contract. /// @dev Can only be initialized by vault governance /// @param nft_ NFT of the vault in the VaultRegistry /// @param vaultTokens_ ERC20 tokens that will be managed by this Vault /// @param helper_ Address of helper function initialize(uint256 nft_, address[] memory vaultTokens_, address helper_) external; /// @notice Updates marginalFactorD9 (can be successfully called only by an admin or a strategist) /// @param marginalFactorD_ New marginalFactorD9 function updateTargetMarginalFactor(uint256 marginalFactorD_) external; /// @notice Sets merkle tree parameters for claiming Gearbox V2 Degen NFT (can be successfully called only by an admin or a strategist) /// @param merkleIndex_ Required index /// @param merkleTotalAmount_ Total amount of NFTs we have in Gearbox Degen Contract /// @param merkleProof_ Proof in Merkle tree function setMerkleParameters(uint256 merkleIndex_, uint256 merkleTotalAmount_, bytes32[] memory merkleProof_) external; /// @notice Adjust a position (takes more debt or repays some, depending on the past performance) to achieve the required marginalFactorD9 function adjustPosition() external; /// @notice Opens a new credit account on the address of the vault function openCreditAccount(address curveAdapter, address convexAdapter) external; /// @notice Closes existing credit account (only possible to be successfully called by the root vault) function closeCreditAccount() external; /// @notice A helper function to be able to call Gearbox multicalls from the helper, but on behalf of the vault /// Can be successfully called only by the helper function openCreditAccountInManager(uint256 currentPrimaryTokenAmount, uint16 referralCode) external; /// @notice Returns an address of the credit account connected to the address of the vault function getCreditAccount() external view returns (address); /// @notice Returns value of all assets located on the vault, including taken with leverage (nominated in primary tokens) function getAllAssetsOnCreditAccountValue() external view returns (uint256 currentAllAssetsValue); /// @notice Returns value of rewards (CRV, CVX) we can obtain from Convex (nominated in primary tokens) function getClaimableRewardsValue() external view returns (uint256); /// @notice A helper function to be able to call Gearbox multicalls from the helper, but on behalf of the vault /// Can be successfully called only by the helper function multicall(MultiCall[] memory calls) external; /// @notice A helper function to be able to call Gearbox multicalls from the helper, but on behalf of the vault /// Can be successfully called only by the helper function swapExactOutput(ISwapRouter router, ISwapRouter.ExactOutputParams memory uniParams, address token, uint256 amount) external; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "./IGearboxVault.sol"; import "./IVaultGovernance.sol"; interface IGearboxVaultGovernance is IVaultGovernance { /// @notice Params that could be changed by Strategy or Protocol Governance with Protocol Governance delay. /// @param crv3Pool 3CRV token address /// @param crv CRV token address /// @param cvx CVX token address /// @param maxSlippageD9 Maximal admissible slippage for swaps between primary/deposit tokes /// @param maxSmallPoolsSlippageD9 Maximal admissible slippage for swaps crv-weth and cvx-weth /// @param maxCurveSlippageD9 Maximal admissible slippage for add/remove liquidity in Curve pool /// @param uniswapRouter Address of the Uniswap V3 router struct DelayedProtocolParams { address crv3Pool; address crv; address cvx; uint256 maxSlippageD9; uint256 maxSmallPoolsSlippageD9; uint256 maxCurveSlippageD9; address uniswapRouter; } /// @notice Params that could be changed by Protocol Governance with Protocol Governance delay. /// @param primaryToken Primary token of the vault (i.e. the token of the Gearbox Credit Account) /// @param univ3Adapter Address of the Uniswap V3 Adapter by Gearbox used by the system /// @param facade Address of the Gearbox CreditFacade contract used by the vault /// @param withdrawDelay The minimal time to pass between two consecutive withdrawal orders execution /// @param initialMarginalValueD9 Initial value of marginal factor of the vault /// @param referralCode The referral code to be used when depositing to Gearbox struct DelayedProtocolPerVaultParams { address primaryToken; address univ3Adapter; address facade; uint256 withdrawDelay; uint256 initialMarginalValueD9; uint16 referralCode; } /// @notice Params that could be changed by Strategy or Protocol Governance. /// @param largePoolFeeUsed Fee for the primary/deposit pool we want to use struct StrategyParams { uint24 largePoolFeeUsed; } // ------------------- EXTERNAL, VIEW ------------------- /// @notice Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay. function delayedProtocolParams() external view returns (DelayedProtocolParams memory); /// @notice Delayed Protocol Params staged for commit after delay. function stagedDelayedProtocolParams() external view returns (DelayedProtocolParams memory); /// @notice Delayed Protocol Per Vault Params staged for commit after delay. /// @param nft VaultRegistry NFT of the vault function stagedDelayedProtocolPerVaultParams(uint256 nft) external view returns (DelayedProtocolPerVaultParams memory); /// @notice Delayed Protocol Per Vault Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay. /// @param nft VaultRegistry NFT of the vault function delayedProtocolPerVaultParams(uint256 nft) external view returns (DelayedProtocolPerVaultParams memory); /// @notice Strategy Params. function strategyParams(uint256 nft) external view returns (StrategyParams memory); // ------------------- EXTERNAL, MUTATING ------------------- /// @notice Stage Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay. /// @dev Can only be called after delayedProtocolParamsTimestamp. /// @param params New params function stageDelayedProtocolParams(DelayedProtocolParams memory params) external; /// @notice Commit Delayed Protocol Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay. function commitDelayedProtocolParams() external; /// @notice Stage Delayed Protocol Per Vault Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay. /// @param nft VaultRegistry NFT of the vault /// @param params New params function stageDelayedProtocolPerVaultParams(uint256 nft, DelayedProtocolPerVaultParams calldata params) external; /// @notice Commit Delayed Protocol Per Vault Params, i.e. Params that could be changed by Protocol Governance with Protocol Governance delay. /// @dev Can only be called after delayedProtocolPerVaultParamsTimestamp /// @param nft VaultRegistry NFT of the vault function commitDelayedProtocolPerVaultParams(uint256 nft) external; /// @notice Set Strategy params, i.e. Params that could be changed by Strategy or Protocol Governance immediately. /// @param params New params function setStrategyParams(uint256 nft, StrategyParams calldata params) external; /// @notice Deploys a new vault. /// @param vaultTokens_ ERC20 tokens that will be managed by this Vault /// @param owner_ Owner of the vault NFT /// @param helper_ Gearbox helper contract address function createVault(address[] memory vaultTokens_, address owner_, address helper_) external returns (IGearboxVault vault, uint256 nft); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "../external/erc/IERC1271.sol"; import "./IVault.sol"; interface IIntegrationVault is IVault, IERC1271 { /// @notice Pushes tokens on the vault balance to the underlying protocol. For example, for Yearn this operation will take USDC from /// the contract balance and convert it to yUSDC. /// @dev Tokens **must** be a subset of Vault Tokens. However, the convention is that if tokenAmount == 0 it is the same as token is missing. /// /// Also notice that this operation doesn't guarantee that tokenAmounts will be invested in full. /// @param tokens Tokens to push /// @param tokenAmounts Amounts of tokens to push /// @param options Additional options that could be needed for some vaults. E.g. for Uniswap this could be `deadline` param. For the exact bytes structure see concrete vault descriptions /// @return actualTokenAmounts The amounts actually invested. It could be less than tokenAmounts (but not higher) function push( address[] memory tokens, uint256[] memory tokenAmounts, bytes memory options ) external returns (uint256[] memory actualTokenAmounts); /// @notice The same as `push` method above but transfers tokens to vault balance prior to calling push. /// After the `push` it returns all the leftover tokens back (`push` method doesn't guarantee that tokenAmounts will be invested in full). /// @param tokens Tokens to push /// @param tokenAmounts Amounts of tokens to push /// @param options Additional options that could be needed for some vaults. E.g. for Uniswap this could be `deadline` param. For the exact bytes structure see concrete vault descriptions /// @return actualTokenAmounts The amounts actually invested. It could be less than tokenAmounts (but not higher) function transferAndPush( address from, address[] memory tokens, uint256[] memory tokenAmounts, bytes memory options ) external returns (uint256[] memory actualTokenAmounts); /// @notice Pulls tokens from the underlying protocol to the `to` address. /// @dev Can only be called but Vault Owner or Strategy. Vault owner is the owner of NFT for this vault in VaultManager. /// Strategy is approved address for the vault NFT. /// When called by vault owner this method just pulls the tokens from the protocol to the `to` address /// When called by strategy on vault other than zero vault it pulls the tokens to zero vault (required `to` == zero vault) /// When called by strategy on zero vault it pulls the tokens to zero vault, pushes tokens on the `to` vault, and reclaims everything that's left. /// Thus any vault other than zero vault cannot have any tokens on it /// /// Tokens **must** be a subset of Vault Tokens. However, the convention is that if tokenAmount == 0 it is the same as token is missing. /// /// Pull is fulfilled on the best effort basis, i.e. if the tokenAmounts overflows available funds it withdraws all the funds. /// @param to Address to receive the tokens /// @param tokens Tokens to pull /// @param tokenAmounts Amounts of tokens to pull /// @param options Additional options that could be needed for some vaults. E.g. for Uniswap this could be `deadline` param. For the exact bytes structure see concrete vault descriptions /// @return actualTokenAmounts The amounts actually withdrawn. It could be less than tokenAmounts (but not higher) function pull( address to, address[] memory tokens, uint256[] memory tokenAmounts, bytes memory options ) external returns (uint256[] memory actualTokenAmounts); /// @notice Claim ERC20 tokens from vault balance to zero vault. /// @dev Cannot be called from zero vault. /// @param tokens Tokens to claim /// @return actualTokenAmounts Amounts reclaimed function reclaimTokens(address[] memory tokens) external returns (uint256[] memory actualTokenAmounts); /// @notice Execute one of whitelisted calls. /// @dev Can only be called by Vault Owner or Strategy. Vault owner is the owner of NFT for this vault in VaultManager. /// Strategy is approved address for the vault NFT. /// /// Since this method allows sending arbitrary transactions, the destinations of the calls /// are whitelisted by Protocol Governance. /// @param to Address of the reward pool /// @param selector Selector of the call /// @param data Abi encoded parameters to `to::selector` /// @return result Result of execution of the call function externalCall( address to, bytes4 selector, bytes memory data ) external payable returns (bytes memory result); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "./IVaultGovernance.sol"; interface IVault is IERC165 { /// @notice Checks if the vault is initialized function initialized() external view returns (bool); /// @notice VaultRegistry NFT for this vault function nft() external view returns (uint256); /// @notice Address of the Vault Governance for this contract. function vaultGovernance() external view returns (IVaultGovernance); /// @notice ERC20 tokens under Vault management. function vaultTokens() external view returns (address[] memory); /// @notice Checks if a token is vault token /// @param token Address of the token to check /// @return `true` if this token is managed by Vault function isVaultToken(address token) external view returns (bool); /// @notice Total value locked for this contract. /// @dev Generally it is the underlying token value of this contract in some /// other DeFi protocol. For example, for USDC Yearn Vault this would be total USDC balance that could be withdrawn for Yearn to this contract. /// The tvl itself is estimated in some range. Sometimes the range is exact, sometimes it's not /// @return minTokenAmounts Lower bound for total available balances estimation (nth tokenAmount corresponds to nth token in vaultTokens) /// @return maxTokenAmounts Upper bound for total available balances estimation (nth tokenAmount corresponds to nth token in vaultTokens) function tvl() external view returns (uint256[] memory minTokenAmounts, uint256[] memory maxTokenAmounts); /// @notice Existential amounts for each token function pullExistentials() external view returns (uint256[] memory); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; import "../IProtocolGovernance.sol"; import "../IVaultRegistry.sol"; import "./IVault.sol"; interface IVaultGovernance { /// @notice Internal references of the contract. /// @param protocolGovernance Reference to Protocol Governance /// @param registry Reference to Vault Registry struct InternalParams { IProtocolGovernance protocolGovernance; IVaultRegistry registry; IVault singleton; } // ------------------- EXTERNAL, VIEW ------------------- /// @notice Timestamp in unix time seconds after which staged Delayed Strategy Params could be committed. /// @param nft Nft of the vault function delayedStrategyParamsTimestamp(uint256 nft) external view returns (uint256); /// @notice Timestamp in unix time seconds after which staged Delayed Protocol Params could be committed. function delayedProtocolParamsTimestamp() external view returns (uint256); /// @notice Timestamp in unix time seconds after which staged Delayed Protocol Params Per Vault could be committed. /// @param nft Nft of the vault function delayedProtocolPerVaultParamsTimestamp(uint256 nft) external view returns (uint256); /// @notice Timestamp in unix time seconds after which staged Internal Params could be committed. function internalParamsTimestamp() external view returns (uint256); /// @notice Internal Params of the contract. function internalParams() external view returns (InternalParams memory); /// @notice Staged new Internal Params. /// @dev The Internal Params could be committed after internalParamsTimestamp function stagedInternalParams() external view returns (InternalParams memory); // ------------------- EXTERNAL, MUTATING ------------------- /// @notice Stage new Internal Params. /// @param newParams New Internal Params function stageInternalParams(InternalParams memory newParams) external; /// @notice Commit staged Internal Params. function commitInternalParams() external; }
// SPDX-License-Identifier: MIT pragma solidity 0.8.9; /// @notice Exceptions stores project`s smart-contracts exceptions library ExceptionsLibrary { string constant ADDRESS_ZERO = "AZ"; string constant VALUE_ZERO = "VZ"; string constant EMPTY_LIST = "EMPL"; string constant NOT_FOUND = "NF"; string constant INIT = "INIT"; string constant DUPLICATE = "DUP"; string constant NULL = "NULL"; string constant TIMESTAMP = "TS"; string constant FORBIDDEN = "FRB"; string constant ALLOWLIST = "ALL"; string constant LIMIT_OVERFLOW = "LIMO"; string constant LIMIT_UNDERFLOW = "LIMU"; string constant INVALID_VALUE = "INV"; string constant INVARIANT = "INVA"; string constant INVALID_TARGET = "INVTR"; string constant INVALID_TOKEN = "INVTO"; string constant INVALID_INTERFACE = "INVI"; string constant INVALID_SELECTOR = "INVS"; string constant INVALID_STATE = "INVST"; string constant INVALID_LENGTH = "INVL"; string constant LOCK = "LCKD"; string constant DISABLED = "DIS"; }
//SPDX-License-Identifier: MIT pragma solidity 0.8.9; /// @notice Stores permission ids for addresses library PermissionIdsLibrary { // The msg.sender is allowed to register vault uint8 constant REGISTER_VAULT = 0; // The msg.sender is allowed to create vaults uint8 constant CREATE_VAULT = 1; // The token is allowed to be transfered by vault uint8 constant ERC20_TRANSFER = 2; // The token is allowed to be added to vault uint8 constant ERC20_VAULT_TOKEN = 3; // Trusted protocols that are allowed to be approved of vault ERC20 tokens by any strategy uint8 constant ERC20_APPROVE = 4; // Trusted protocols that are allowed to be approved of vault ERC20 tokens by trusted strategy uint8 constant ERC20_APPROVE_RESTRICTED = 5; // Strategy allowed using restricted API uint8 constant TRUSTED_STRATEGY = 6; }
// SPDX-License-Identifier: MIT pragma solidity =0.8.9; /// @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) { // diff: original lib works under 0.7.6 with overflows enabled 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. // diff: original uint256 twos = -denominator & denominator; uint256 twos = uint256(-int256(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) { // diff: original lib works under 0.7.6 with overflows enabled unchecked { result = mulDiv(a, b, denominator); if (mulmod(a, b, denominator) > 0) { require(result < type(uint256).max); result++; } } } }
// SPDX-License-Identifier: BSL-1.1 pragma solidity 0.8.9; import "../interfaces/utils/IContractMeta.sol"; abstract contract ContractMeta is IContractMeta { // ------------------- EXTERNAL, VIEW ------------------- function contractName() external pure returns (string memory) { return _bytes32ToString(_contractName()); } function contractNameBytes() external pure returns (bytes32) { return _contractName(); } function contractVersion() external pure returns (string memory) { return _bytes32ToString(_contractVersion()); } function contractVersionBytes() external pure returns (bytes32) { return _contractVersion(); } // ------------------- INTERNAL, VIEW ------------------- function _contractName() internal pure virtual returns (bytes32); function _contractVersion() internal pure virtual returns (bytes32); function _bytes32ToString(bytes32 b) internal pure returns (string memory s) { s = new string(32); uint256 len = 32; for (uint256 i = 0; i < 32; ++i) { if (uint8(b[i]) == 0) { len = i; break; } } assembly { mstore(s, len) mstore(add(s, 0x20), b) } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.9; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "../interfaces/external/convex/ICvx.sol"; import "../interfaces/external/convex/Interfaces.sol"; import "../interfaces/external/gearbox/helpers/IPriceOracle.sol"; import "../libraries/external/FullMath.sol"; import "../interfaces/external/gearbox/ICreditFacade.sol"; import "../interfaces/external/gearbox/ICurveV1Adapter.sol"; import "../interfaces/external/gearbox/IConvexV1BaseRewardPoolAdapter.sol"; import "../interfaces/external/gearbox/IUniswapV3Adapter.sol"; import "../libraries/ExceptionsLibrary.sol"; import "../interfaces/vaults/IGearboxVaultGovernance.sol"; import "../interfaces/external/gearbox/helpers/convex/IBooster.sol"; contract GearboxHelper { using SafeERC20 for IERC20; uint256 public constant D9 = 10**9; uint256 public constant D27 = 10**27; bytes4 public constant GET_REWARD_SELECTOR = 0x7050ccd9; ICreditFacade public creditFacade; ICreditManagerV2 public creditManager; address public curveAdapter; address public convexAdapter; address public primaryToken; address public depositToken; bool public parametersSet; bool public is3crv; int128 crv3Index; IGearboxVault public gearboxVault; uint256 public vaultNft; function setParameters( ICreditFacade creditFacade_, ICreditManagerV2 creditManager_, address primaryToken_, address depositToken_, uint256 nft_ ) external { require(!parametersSet, ExceptionsLibrary.FORBIDDEN); creditFacade = creditFacade_; creditManager = creditManager_; primaryToken = primaryToken_; depositToken = depositToken_; vaultNft = nft_; parametersSet = true; gearboxVault = IGearboxVault(msg.sender); } function setAdapters(address curveAdapter_, address convexAdapter_) external { require(msg.sender == address(gearboxVault), ExceptionsLibrary.FORBIDDEN); curveAdapter = curveAdapter_; convexAdapter = convexAdapter_; } function calcWithdrawOneCoin(address adapter, uint256 amount, int128 index) public view returns (uint256) { if (amount == 0) { return 0; } return ICurveV1Adapter(adapter).calc_withdraw_one_coin(amount, index); } function calcTotalValue(address creditAccount, address vaultGovernance) public view returns (uint256 currentAllAssetsValue) { IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams = IGearboxVaultGovernance(vaultGovernance) .delayedProtocolParams(); IPriceOracleV2 oracle = IPriceOracleV2(creditManager.priceOracle()); (currentAllAssetsValue, ) = creditFacade.calcTotalValue(creditAccount); currentAllAssetsValue += calculateClaimableRewards(creditAccount, vaultGovernance); address convexOutputToken = IConvexV1BaseRewardPoolAdapter(convexAdapter).stakedPhantomToken(); uint256 balance = IERC20(convexOutputToken).balanceOf(creditAccount); int128 primaryIndex = gearboxVault.primaryIndex(); if (!is3crv) { currentAllAssetsValue += calcWithdrawOneCoin(curveAdapter, balance, primaryIndex); } else { uint256 crv3LpBalance = calcWithdrawOneCoin(curveAdapter, balance, crv3Index); address crv3Adapter = creditManager.contractToAdapter(protocolParams.crv3Pool); currentAllAssetsValue += calcWithdrawOneCoin(crv3Adapter, crv3LpBalance, primaryIndex); } currentAllAssetsValue -= oracle.convert(balance, convexOutputToken, primaryToken); } function calcTvl(address creditAccount, address vaultGovernance) external view returns (uint256) { address depositToken_ = depositToken; address primaryToken_ = primaryToken; ICreditManagerV2 creditManager_ = creditManager; uint256 primaryTokenAmount = 0; if (primaryToken_ != depositToken_) { primaryTokenAmount += IERC20(primaryToken_).balanceOf(address(gearboxVault)); } if (creditAccount != address(0)) { uint256 currentAllAssetsValue = calcTotalValue(creditAccount, vaultGovernance); (, , uint256 borrowAmountWithInterestAndFees) = creditManager_.calcCreditAccountAccruedInterest( creditAccount ); if (currentAllAssetsValue >= borrowAmountWithInterestAndFees) { primaryTokenAmount += currentAllAssetsValue - borrowAmountWithInterestAndFees; } } if (primaryToken_ == depositToken_) { return primaryTokenAmount + IERC20(depositToken_).balanceOf(address(gearboxVault)); } else { IPriceOracleV2 oracle = IPriceOracleV2(creditManager_.priceOracle()); return oracle.convert(primaryTokenAmount, primaryToken_, depositToken_) + IERC20(depositToken_).balanceOf(address(gearboxVault)); } } function verifyInstances(address vaultGovernance) external returns ( int128 primaryIndex, address convexOutputToken, uint256 poolId ) { require(msg.sender == address(gearboxVault), ExceptionsLibrary.FORBIDDEN); IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams = IGearboxVaultGovernance(vaultGovernance) .delayedProtocolParams(); ICurveV1Adapter curveAdapter_ = ICurveV1Adapter(curveAdapter); IConvexV1BaseRewardPoolAdapter convexAdapter_ = IConvexV1BaseRewardPoolAdapter(convexAdapter); poolId = convexAdapter_.pid(); address primaryToken_ = primaryToken; require(creditFacade.isTokenAllowed(primaryToken_), ExceptionsLibrary.INVALID_TOKEN); bool havePrimaryTokenInCurve = false; is3crv = false; for (uint256 i = 0; i < curveAdapter_.nCoins(); ++i) { address tokenI = curveAdapter_.coins(i); if (tokenI == primaryToken_) { primaryIndex = int128(int256(i)); havePrimaryTokenInCurve = true; } } if (!havePrimaryTokenInCurve) { ICurveV1Adapter crv3Adapter = ICurveV1Adapter(creditManager.contractToAdapter(protocolParams.crv3Pool)); address crv3Token = crv3Adapter.lp_token(); for (uint256 i = 0; i < curveAdapter_.nCoins(); ++i) { address tokenI = curveAdapter_.coins(i); if (tokenI == crv3Token) { crv3Index = int128(uint128(i)); is3crv = true; for (uint256 j = 0; j < 3; ++j) { address tokenJ = crv3Adapter.coins(j); if (tokenJ == primaryToken_) { primaryIndex = int128(int256(j)); havePrimaryTokenInCurve = true; } } } } } require(havePrimaryTokenInCurve, ExceptionsLibrary.INVALID_TOKEN); convexOutputToken = address(convexAdapter_.stakedPhantomToken()); require(curveAdapter_.lp_token() == convexAdapter_.curveLPtoken(), ExceptionsLibrary.INVALID_TARGET); } function calculateEarnedCvxAmountByEarnedCrvAmount(uint256 crvAmount, address cvxTokenAddress) public view returns (uint256) { IConvexToken cvxToken = IConvexToken(cvxTokenAddress); unchecked { uint256 supply = cvxToken.totalSupply(); uint256 cliff = supply / cvxToken.reductionPerCliff(); uint256 totalCliffs = cvxToken.totalCliffs(); if (cliff < totalCliffs) { uint256 reduction = totalCliffs - cliff; uint256 cvxAmount = FullMath.mulDiv(crvAmount, reduction, totalCliffs); uint256 amtTillMax = cvxToken.maxSupply() - supply; if (cvxAmount > amtTillMax) { cvxAmount = amtTillMax; } return cvxAmount; } return 0; } } function calculateClaimableRewards(address creditAccount, address vaultGovernance) public view returns (uint256 totalValue) { uint256 earnedCrvAmount = IConvexV1BaseRewardPoolAdapter(convexAdapter).earned(creditAccount); IPriceOracleV2 oracle = IPriceOracleV2(creditManager.priceOracle()); IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams = IGearboxVaultGovernance(vaultGovernance) .delayedProtocolParams(); totalValue = oracle.convert(earnedCrvAmount, protocolParams.crv, primaryToken); totalValue += oracle.convert( calculateEarnedCvxAmountByEarnedCrvAmount(earnedCrvAmount, protocolParams.cvx), protocolParams.cvx, primaryToken ); uint256 valueExtraToUsd = 0; IBaseRewardPool underlyingContract = IBaseRewardPool(creditManager.adapterToContract(convexAdapter)); for (uint256 i = 0; i < underlyingContract.extraRewardsLength(); ++i) { IRewards rewardsContract = IRewards(underlyingContract.extraRewards(i)); uint256 valueEarned = rewardsContract.earned(creditAccount); totalValue += oracle.convert(valueEarned, rewardsContract.rewardToken(), primaryToken); } } function calculateDesiredTotalValue( address creditAccount, address vaultGovernance, uint256 marginalFactorD9 ) external view returns (uint256 expectedAllAssetsValue, uint256 currentAllAssetsValue) { currentAllAssetsValue = calcTotalValue(creditAccount, vaultGovernance); (, , uint256 borrowAmountWithInterestAndFees) = creditManager.calcCreditAccountAccruedInterest(creditAccount); uint256 currentTvl = currentAllAssetsValue - borrowAmountWithInterestAndFees; expectedAllAssetsValue = FullMath.mulDiv(currentTvl, marginalFactorD9, D9); } function calcConvexTokensToWithdraw( uint256 desiredValueNominatedUnderlying, address creditAccount, address convexOutputToken ) public view returns (uint256) { uint256 currentConvexTokensAmount = IERC20(convexOutputToken).balanceOf(creditAccount); IPriceOracleV2 oracle = IPriceOracleV2(creditManager.priceOracle()); uint256 valueInConvexNominatedUnderlying = oracle.convert( currentConvexTokensAmount, convexOutputToken, primaryToken ); if (desiredValueNominatedUnderlying >= valueInConvexNominatedUnderlying) { return currentConvexTokensAmount; } return FullMath.mulDiv( currentConvexTokensAmount, desiredValueNominatedUnderlying, valueInConvexNominatedUnderlying ); } function calcRateRAY(address tokenFrom, address tokenTo) public view returns (uint256) { IPriceOracleV2 oracle = IPriceOracleV2(creditManager.priceOracle()); return oracle.convert(D27, tokenFrom, tokenTo); } function calculateAmountInMaximum( address fromToken, address toToken, uint256 amount, uint256 maxSlippageD9 ) public view returns (uint256) { uint256 rateRAY = calcRateRAY(toToken, fromToken); uint256 amountInExpected = FullMath.mulDiv(amount, rateRAY, D27) + 1; return FullMath.mulDiv(amountInExpected, D9 + maxSlippageD9, D9) + 1; } function createUniswapMulticall( address tokenFrom, address tokenTo, uint256 fee, address adapter, uint256 slippage ) public view returns (MultiCall memory) { uint256 rateRAY = calcRateRAY(tokenFrom, tokenTo); IUniswapV3Adapter.ExactAllInputParams memory params = IUniswapV3Adapter.ExactAllInputParams({ path: abi.encodePacked(tokenFrom, uint24(fee), tokenTo), deadline: block.timestamp + 1, rateMinRAY: FullMath.mulDiv(rateRAY, D9 - slippage, D9) }); return MultiCall({ target: adapter, callData: abi.encodeWithSelector(IUniswapV3Adapter.exactAllInput.selector, params) }); } function checkNecessaryDepositExchange( uint256 expectedMaximalDepositTokenValueNominatedUnderlying, address vaultGovernance, address creditAccount ) public { require(msg.sender == address(gearboxVault), ExceptionsLibrary.FORBIDDEN); address depositToken_ = depositToken; address primaryToken_ = primaryToken; if (depositToken_ == primaryToken_) { return; } uint256 currentDepositTokenAmount = IERC20(depositToken_).balanceOf(creditAccount); IPriceOracleV2 oracle = IPriceOracleV2(creditManager.priceOracle()); uint256 currentValueDepositTokenNominatedUnderlying = oracle.convert( currentDepositTokenAmount, depositToken_, primaryToken_ ); if (currentValueDepositTokenNominatedUnderlying > expectedMaximalDepositTokenValueNominatedUnderlying) { uint256 toSwap = FullMath.mulDiv( currentDepositTokenAmount, currentValueDepositTokenNominatedUnderlying - expectedMaximalDepositTokenValueNominatedUnderlying, currentValueDepositTokenNominatedUnderlying ); swapExactInput(depositToken_, primaryToken_, toSwap, vaultGovernance, creditAccount); } } function claimRewards( address vaultGovernance, address creditAccount, address convexOutputToken ) public { IGearboxVault gearboxVault_ = gearboxVault; address primaryToken_ = primaryToken; require(msg.sender == address(gearboxVault_), ExceptionsLibrary.FORBIDDEN); uint256 balance = IERC20(convexOutputToken).balanceOf(creditAccount); if (balance == 0) { return; } IBaseRewardPool underlyingContract = IBaseRewardPool(creditManager.adapterToContract(convexAdapter)); IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams = IGearboxVaultGovernance(vaultGovernance) .delayedProtocolParams(); IGearboxVaultGovernance.StrategyParams memory strategyParams = IGearboxVaultGovernance(vaultGovernance) .strategyParams(vaultNft); IGearboxVaultGovernance.DelayedProtocolPerVaultParams memory vaultParams = IGearboxVaultGovernance( vaultGovernance ).delayedProtocolPerVaultParams(vaultNft); address weth = creditManager.wethAddress(); uint256 callsCount = 4; if (weth == primaryToken_ || weth == depositToken) { callsCount -= 1; } for (uint256 i = 0; i < underlyingContract.extraRewardsLength(); ++i) { address rewardToken = address(IRewards(underlyingContract.extraRewards(i)).rewardToken()); if (rewardToken != depositToken && rewardToken != primaryToken_ && rewardToken != weth) { callsCount += 1; } } MultiCall[] memory calls = new MultiCall[](callsCount); calls[0] = MultiCall({ // taking crv and cvx target: convexAdapter, callData: abi.encodeWithSelector(GET_REWARD_SELECTOR, creditAccount, true) }); calls[1] = createUniswapMulticall( protocolParams.crv, weth, 10000, vaultParams.univ3Adapter, protocolParams.maxSmallPoolsSlippageD9 ); calls[2] = createUniswapMulticall( protocolParams.cvx, weth, 10000, vaultParams.univ3Adapter, protocolParams.maxSmallPoolsSlippageD9 ); uint256 pointer = 3; for (uint256 i = 2; i < 2 + underlyingContract.extraRewardsLength(); ++i) { address rewardToken = address(IRewards(underlyingContract.extraRewards(i - 2)).rewardToken()); if (rewardToken != depositToken && rewardToken != primaryToken_ && rewardToken != weth) { calls[pointer] = createUniswapMulticall( rewardToken, weth, 10000, vaultParams.univ3Adapter, protocolParams.maxSmallPoolsSlippageD9 ); pointer += 1; } } if (weth != primaryToken_ && weth != depositToken) { calls[callsCount - 1] = createUniswapMulticall( weth, primaryToken_, strategyParams.largePoolFeeUsed, vaultParams.univ3Adapter, protocolParams.maxSlippageD9 ); } gearboxVault_.multicall(calls); } function withdrawFromConvex( uint256 amount, address vaultGovernance, int128 primaryIndex ) public { if (amount == 0) { return; } IGearboxVault gearboxVault_ = gearboxVault; require(msg.sender == address(gearboxVault_), ExceptionsLibrary.FORBIDDEN); address curveLpToken = ICurveV1Adapter(curveAdapter).lp_token(); IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams = IGearboxVaultGovernance(vaultGovernance) .delayedProtocolParams(); if (!is3crv) { uint256 rateRAY = calcRateRAY(curveLpToken, primaryToken); MultiCall[] memory calls = new MultiCall[](2); calls[0] = MultiCall({ target: convexAdapter, callData: abi.encodeWithSelector(IBaseRewardPool.withdrawAndUnwrap.selector, amount, false) }); calls[1] = MultiCall({ target: curveAdapter, callData: abi.encodeWithSelector( ICurveV1Adapter.remove_all_liquidity_one_coin.selector, primaryIndex, FullMath.mulDiv(rateRAY, D9 - protocolParams.maxCurveSlippageD9, D9) ) }); gearboxVault_.multicall(calls); } else { ICurveV1Adapter crv3Adapter = ICurveV1Adapter(creditManager.contractToAdapter(protocolParams.crv3Pool)); address crv3Token = crv3Adapter.lp_token(); uint256 rateRAY1 = calcRateRAY(curveLpToken, crv3Token); uint256 rateRAY2 = calcRateRAY(crv3Token, primaryToken); MultiCall[] memory calls = new MultiCall[](3); calls[0] = MultiCall({ target: convexAdapter, callData: abi.encodeWithSelector(IBaseRewardPool.withdrawAndUnwrap.selector, amount, false) }); calls[1] = MultiCall({ target: curveAdapter, callData: abi.encodeWithSelector( ICurveV1Adapter.remove_all_liquidity_one_coin.selector, crv3Index, FullMath.mulDiv(rateRAY1, D9 - protocolParams.maxCurveSlippageD9, D9) ) }); calls[2] = MultiCall({ target: address(crv3Adapter), callData: abi.encodeWithSelector( ICurveV1Adapter.remove_all_liquidity_one_coin.selector, primaryIndex, FullMath.mulDiv(rateRAY2, D9 - protocolParams.maxCurveSlippageD9, D9) ) }); gearboxVault_.multicall(calls); } } function depositToConvex( MultiCall memory debtManagementCall, IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams, uint256 poolId, int128 primaryIndex ) public { IGearboxVault gearboxVault_ = gearboxVault; require(msg.sender == address(gearboxVault_), ExceptionsLibrary.FORBIDDEN); address curveLpToken = ICurveV1Adapter(curveAdapter).lp_token(); if (!is3crv) { uint256 rateRAY = calcRateRAY(primaryToken, curveLpToken); MultiCall[] memory calls = new MultiCall[](3); calls[0] = debtManagementCall; calls[1] = MultiCall({ target: curveAdapter, callData: abi.encodeWithSelector( ICurveV1Adapter.add_all_liquidity_one_coin.selector, primaryIndex, FullMath.mulDiv(rateRAY, D9 - protocolParams.maxCurveSlippageD9, D9) ) }); calls[2] = MultiCall({ target: creditManager.contractToAdapter(IConvexV1BaseRewardPoolAdapter(convexAdapter).operator()), callData: abi.encodeWithSelector(IBooster.depositAll.selector, poolId, true) }); gearboxVault_.multicall(calls); } else { ICurveV1Adapter crv3Adapter = ICurveV1Adapter(creditManager.contractToAdapter(protocolParams.crv3Pool)); address crv3Token = crv3Adapter.lp_token(); uint256 rateRAY1 = calcRateRAY(primaryToken, crv3Token); uint256 rateRAY2 = calcRateRAY(crv3Token, curveLpToken); MultiCall[] memory calls = new MultiCall[](4); calls[0] = debtManagementCall; calls[1] = MultiCall({ target: address(crv3Adapter), callData: abi.encodeWithSelector( ICurveV1Adapter.add_all_liquidity_one_coin.selector, primaryIndex, FullMath.mulDiv(rateRAY1, D9 - protocolParams.maxCurveSlippageD9, D9) ) }); calls[2] = MultiCall({ target: curveAdapter, callData: abi.encodeWithSelector( ICurveV1Adapter.add_all_liquidity_one_coin.selector, crv3Index, FullMath.mulDiv(rateRAY2, D9 - protocolParams.maxCurveSlippageD9, D9) ) }); calls[3] = MultiCall({ target: creditManager.contractToAdapter(IConvexV1BaseRewardPoolAdapter(convexAdapter).operator()), callData: abi.encodeWithSelector(IBooster.depositAll.selector, poolId, true) }); gearboxVault_.multicall(calls); } } function adjustPosition( uint256 expectedAllAssetsValue, uint256 currentAllAssetsValue, address vaultGovernance, uint256 marginalFactorD9, int128 primaryIndex, uint256 poolId, address convexOutputToken, address creditAccount_ ) external { require(msg.sender == address(gearboxVault), ExceptionsLibrary.FORBIDDEN); claimRewards(vaultGovernance, creditAccount_, convexOutputToken); IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams = IGearboxVaultGovernance(vaultGovernance) .delayedProtocolParams(); ICreditFacade creditFacade_ = creditFacade; checkNecessaryDepositExchange( FullMath.mulDiv(expectedAllAssetsValue, D9, marginalFactorD9), vaultGovernance, creditAccount_ ); if (expectedAllAssetsValue >= currentAllAssetsValue) { uint256 delta = expectedAllAssetsValue - currentAllAssetsValue; MultiCall memory increaseDebtCall = MultiCall({ target: address(creditFacade_), callData: abi.encodeWithSelector(ICreditFacade.increaseDebt.selector, delta) }); depositToConvex(increaseDebtCall, protocolParams, poolId, primaryIndex); } else { uint256 delta = currentAllAssetsValue - expectedAllAssetsValue; uint256 currentPrimaryTokenAmount = IERC20(primaryToken).balanceOf(creditAccount_); if (currentPrimaryTokenAmount >= delta) { MultiCall memory decreaseDebtCall = MultiCall({ target: address(creditFacade_), callData: abi.encodeWithSelector(ICreditFacade.decreaseDebt.selector, delta) }); depositToConvex(decreaseDebtCall, protocolParams, poolId, primaryIndex); } else { uint256 convexAmountToWithdraw = calcConvexTokensToWithdraw( delta - currentPrimaryTokenAmount, creditAccount_, convexOutputToken ); withdrawFromConvex(convexAmountToWithdraw, vaultGovernance, primaryIndex); currentPrimaryTokenAmount = IERC20(primaryToken).balanceOf(creditAccount_); if (currentPrimaryTokenAmount < delta) { delta = currentPrimaryTokenAmount; } MultiCall[] memory decreaseCall = new MultiCall[](1); decreaseCall[0] = MultiCall({ target: address(creditFacade_), callData: abi.encodeWithSelector(ICreditFacade.decreaseDebt.selector, delta) }); gearboxVault.multicall(decreaseCall); } } emit PositionAdjusted(tx.origin, msg.sender, expectedAllAssetsValue); } function swapExactOutput( address fromToken, address toToken, uint256 amount, address vaultGovernance, address creditAccount ) external { require(msg.sender == address(gearboxVault), ExceptionsLibrary.FORBIDDEN); IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams = IGearboxVaultGovernance(vaultGovernance) .delayedProtocolParams(); IGearboxVaultGovernance.StrategyParams memory strategyParams = IGearboxVaultGovernance(vaultGovernance) .strategyParams(vaultNft); IGearboxVaultGovernance.DelayedProtocolPerVaultParams memory vaultParams = IGearboxVaultGovernance( vaultGovernance ).delayedProtocolPerVaultParams(vaultNft); uint256 amountInMaximum = calculateAmountInMaximum(fromToken, toToken, amount, protocolParams.maxSlippageD9); ISwapRouter.ExactOutputParams memory uniParams = ISwapRouter.ExactOutputParams({ path: abi.encodePacked(toToken, strategyParams.largePoolFeeUsed, fromToken), // exactOutput arguments are in reversed order recipient: creditAccount, deadline: block.timestamp + 1, amountOut: amount, amountInMaximum: amountInMaximum }); MultiCall[] memory calls = new MultiCall[](1); calls[0] = MultiCall({ target: vaultParams.univ3Adapter, callData: abi.encodeWithSelector(ISwapRouter.exactOutput.selector, uniParams) }); gearboxVault.multicall(calls); } function swapExactInput( address fromToken, address toToken, uint256 amount, address vaultGovernance, address creditAccount ) public { require(msg.sender == address(gearboxVault), ExceptionsLibrary.FORBIDDEN); IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams = IGearboxVaultGovernance(vaultGovernance) .delayedProtocolParams(); IGearboxVaultGovernance.StrategyParams memory strategyParams = IGearboxVaultGovernance(vaultGovernance) .strategyParams(vaultNft); IGearboxVaultGovernance.DelayedProtocolPerVaultParams memory vaultParams = IGearboxVaultGovernance( vaultGovernance ).delayedProtocolPerVaultParams(vaultNft); MultiCall[] memory calls = new MultiCall[](1); IPriceOracleV2 oracle = IPriceOracleV2(creditManager.priceOracle()); uint256 expectedOutput = oracle.convert(amount, fromToken, toToken); ISwapRouter.ExactInputParams memory inputParams = ISwapRouter.ExactInputParams({ path: abi.encodePacked(fromToken, strategyParams.largePoolFeeUsed, toToken), recipient: creditAccount, deadline: block.timestamp + 1, amountIn: amount, amountOutMinimum: FullMath.mulDiv(expectedOutput, D9 - protocolParams.maxSlippageD9, D9) }); calls[0] = MultiCall({ // swap deposit to primary token target: vaultParams.univ3Adapter, callData: abi.encodeWithSelector(ISwapRouter.exactInput.selector, inputParams) }); gearboxVault.multicall(calls); } function openCreditAccount(address vaultGovernance, uint256 marginalFactorD9) external { IGearboxVault gearboxVault_ = gearboxVault; require(msg.sender == address(gearboxVault_), ExceptionsLibrary.FORBIDDEN); ICreditFacade creditFacade_ = creditFacade; address primaryToken_ = primaryToken; address depositToken_ = depositToken; uint256 minimalNecessaryAmount; { (uint256 minBorrowingLimit, ) = creditFacade_.limits(); minimalNecessaryAmount = FullMath.mulDiv(minBorrowingLimit, D9, (marginalFactorD9 - D9)) + 1; } uint256 currentPrimaryTokenAmount = IERC20(primaryToken_).balanceOf(address(gearboxVault_)); IGearboxVaultGovernance vaultGovernance_ = IGearboxVaultGovernance(vaultGovernance); uint256 vaultNft_ = vaultNft; IGearboxVaultGovernance.DelayedProtocolParams memory protocolParams = vaultGovernance_.delayedProtocolParams(); IGearboxVaultGovernance.StrategyParams memory strategyParams = vaultGovernance_.strategyParams(vaultNft_); IGearboxVaultGovernance.DelayedProtocolPerVaultParams memory vaultParams = vaultGovernance_ .delayedProtocolPerVaultParams(vaultNft_); if (depositToken_ != primaryToken_ && currentPrimaryTokenAmount < minimalNecessaryAmount) { ISwapRouter router = ISwapRouter(protocolParams.uniswapRouter); uint256 amountInMaximum = calculateAmountInMaximum( depositToken_, primaryToken_, minimalNecessaryAmount - currentPrimaryTokenAmount, protocolParams.maxSlippageD9 ); require(IERC20(depositToken_).balanceOf(address(gearboxVault_)) >= amountInMaximum, ExceptionsLibrary.INVARIANT); ISwapRouter.ExactOutputParams memory uniParams = ISwapRouter.ExactOutputParams({ path: abi.encodePacked(primaryToken_, strategyParams.largePoolFeeUsed, depositToken_), // exactOutput arguments are in reversed order recipient: address(gearboxVault_), deadline: block.timestamp + 1, amountOut: minimalNecessaryAmount - currentPrimaryTokenAmount, amountInMaximum: amountInMaximum }); gearboxVault_.swapExactOutput(router, uniParams, depositToken_, amountInMaximum); currentPrimaryTokenAmount = IERC20(primaryToken_).balanceOf(address(gearboxVault_)); } require(currentPrimaryTokenAmount >= minimalNecessaryAmount, ExceptionsLibrary.LIMIT_UNDERFLOW); gearboxVault_.openCreditAccountInManager(currentPrimaryTokenAmount, vaultParams.referralCode); emit CreditAccountOpened(tx.origin, msg.sender, creditManager.creditAccounts(address(gearboxVault_))); } /// @notice Emitted when a credit account linked to this vault is opened in Gearbox /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param creditAccount Address of the opened credit account event CreditAccountOpened(address indexed origin, address indexed sender, address creditAccount); /// @notice Emitted when an adjusment of the position made in Gearbox /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param newTotalAssetsValue New value of all assets (debt + real assets) of the vault event PositionAdjusted(address indexed origin, address indexed sender, uint256 newTotalAssetsValue); }
// SPDX-License-Identifier: BSL-1.1 pragma solidity 0.8.9; import "@openzeppelin/contracts/proxy/Clones.sol"; import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; import "../interfaces/IProtocolGovernance.sol"; import "../interfaces/vaults/IVaultGovernance.sol"; import "../libraries/ExceptionsLibrary.sol"; import "../libraries/PermissionIdsLibrary.sol"; /// @notice Internal contract for managing different params. /// @dev The contract should be overriden by the concrete VaultGovernance, /// define different params structs and use abi.decode / abi.encode to serialize /// to bytes in this contract. It also should emit events on params change. abstract contract VaultGovernance is IVaultGovernance, ERC165 { InternalParams internal _internalParams; InternalParams private _stagedInternalParams; uint256 internal _internalParamsTimestamp; mapping(uint256 => bytes) internal _delayedStrategyParams; mapping(uint256 => bytes) internal _stagedDelayedStrategyParams; mapping(uint256 => uint256) internal _delayedStrategyParamsTimestamp; mapping(uint256 => bytes) internal _delayedProtocolPerVaultParams; mapping(uint256 => bytes) internal _stagedDelayedProtocolPerVaultParams; mapping(uint256 => uint256) internal _delayedProtocolPerVaultParamsTimestamp; bytes internal _delayedProtocolParams; bytes internal _stagedDelayedProtocolParams; uint256 internal _delayedProtocolParamsTimestamp; mapping(uint256 => bytes) internal _strategyParams; bytes internal _protocolParams; bytes internal _operatorParams; /// @notice Creates a new contract. /// @param internalParams_ Initial Internal Params constructor(InternalParams memory internalParams_) { require(address(internalParams_.protocolGovernance) != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(address(internalParams_.registry) != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(address(internalParams_.singleton) != address(0), ExceptionsLibrary.ADDRESS_ZERO); _internalParams = internalParams_; } // ------------------- EXTERNAL, VIEW ------------------- /// @inheritdoc IVaultGovernance function delayedStrategyParamsTimestamp(uint256 nft) external view returns (uint256) { return _delayedStrategyParamsTimestamp[nft]; } /// @inheritdoc IVaultGovernance function delayedProtocolPerVaultParamsTimestamp(uint256 nft) external view returns (uint256) { return _delayedProtocolPerVaultParamsTimestamp[nft]; } /// @inheritdoc IVaultGovernance function delayedProtocolParamsTimestamp() external view returns (uint256) { return _delayedProtocolParamsTimestamp; } /// @inheritdoc IVaultGovernance function internalParamsTimestamp() external view returns (uint256) { return _internalParamsTimestamp; } /// @inheritdoc IVaultGovernance function internalParams() external view returns (InternalParams memory) { return _internalParams; } /// @inheritdoc IVaultGovernance function stagedInternalParams() external view returns (InternalParams memory) { return _stagedInternalParams; } function supportsInterface(bytes4 interfaceID) public view virtual override(ERC165) returns (bool) { return super.supportsInterface(interfaceID) || interfaceID == type(IVaultGovernance).interfaceId; } // ------------------- EXTERNAL, MUTATING ------------------- /// @inheritdoc IVaultGovernance function stageInternalParams(InternalParams memory newParams) external { _requireProtocolAdmin(); require(address(newParams.protocolGovernance) != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(address(newParams.registry) != address(0), ExceptionsLibrary.ADDRESS_ZERO); require(address(newParams.singleton) != address(0), ExceptionsLibrary.ADDRESS_ZERO); _stagedInternalParams = newParams; _internalParamsTimestamp = block.timestamp + _internalParams.protocolGovernance.governanceDelay(); emit StagedInternalParams(tx.origin, msg.sender, newParams, _internalParamsTimestamp); } /// @inheritdoc IVaultGovernance function commitInternalParams() external { _requireProtocolAdmin(); require(_internalParamsTimestamp != 0, ExceptionsLibrary.NULL); require(block.timestamp >= _internalParamsTimestamp, ExceptionsLibrary.TIMESTAMP); _internalParams = _stagedInternalParams; delete _internalParamsTimestamp; delete _stagedInternalParams; emit CommitedInternalParams(tx.origin, msg.sender, _internalParams); } // ------------------- INTERNAL, VIEW ------------------- function _requireAtLeastStrategy(uint256 nft) internal view { require( (_internalParams.protocolGovernance.isAdmin(msg.sender) || _internalParams.registry.getApproved(nft) == msg.sender || (_internalParams.registry.ownerOf(nft) == msg.sender)), ExceptionsLibrary.FORBIDDEN ); } function _requireProtocolAdmin() internal view { require(_internalParams.protocolGovernance.isAdmin(msg.sender), ExceptionsLibrary.FORBIDDEN); } function _requireAtLeastOperator() internal view { IProtocolGovernance governance = _internalParams.protocolGovernance; require(governance.isAdmin(msg.sender) || governance.isOperator(msg.sender), ExceptionsLibrary.FORBIDDEN); } // ------------------- INTERNAL, MUTATING ------------------- function _createVault(address owner) internal returns (address vault, uint256 nft) { IProtocolGovernance protocolGovernance = IProtocolGovernance(_internalParams.protocolGovernance); require( protocolGovernance.hasPermission(msg.sender, PermissionIdsLibrary.CREATE_VAULT), ExceptionsLibrary.FORBIDDEN ); IVaultRegistry vaultRegistry = _internalParams.registry; nft = vaultRegistry.vaultsCount() + 1; vault = Clones.cloneDeterministic(address(_internalParams.singleton), bytes32(nft)); vaultRegistry.registerVault(address(vault), owner); } /// @notice Set Delayed Strategy Params /// @param nft Nft of the vault /// @param params New params function _stageDelayedStrategyParams(uint256 nft, bytes memory params) internal { _requireAtLeastStrategy(nft); _stagedDelayedStrategyParams[nft] = params; uint256 delayFactor = _delayedStrategyParams[nft].length == 0 ? 0 : 1; _delayedStrategyParamsTimestamp[nft] = block.timestamp + _internalParams.protocolGovernance.governanceDelay() * delayFactor; } /// @notice Commit Delayed Strategy Params function _commitDelayedStrategyParams(uint256 nft) internal { _requireAtLeastStrategy(nft); uint256 thisDelayedStrategyParamsTimestamp = _delayedStrategyParamsTimestamp[nft]; require(thisDelayedStrategyParamsTimestamp != 0, ExceptionsLibrary.NULL); require(block.timestamp >= thisDelayedStrategyParamsTimestamp, ExceptionsLibrary.TIMESTAMP); _delayedStrategyParams[nft] = _stagedDelayedStrategyParams[nft]; delete _stagedDelayedStrategyParams[nft]; delete _delayedStrategyParamsTimestamp[nft]; } /// @notice Set Delayed Protocol Per Vault Params /// @param nft Nft of the vault /// @param params New params function _stageDelayedProtocolPerVaultParams(uint256 nft, bytes memory params) internal { _requireProtocolAdmin(); _stagedDelayedProtocolPerVaultParams[nft] = params; uint256 delayFactor = _delayedProtocolPerVaultParams[nft].length == 0 ? 0 : 1; _delayedProtocolPerVaultParamsTimestamp[nft] = block.timestamp + _internalParams.protocolGovernance.governanceDelay() * delayFactor; } /// @notice Commit Delayed Protocol Per Vault Params function _commitDelayedProtocolPerVaultParams(uint256 nft) internal { _requireProtocolAdmin(); uint256 thisDelayedProtocolPerVaultParamsTimestamp = _delayedProtocolPerVaultParamsTimestamp[nft]; require(thisDelayedProtocolPerVaultParamsTimestamp != 0, ExceptionsLibrary.NULL); require(block.timestamp >= thisDelayedProtocolPerVaultParamsTimestamp, ExceptionsLibrary.TIMESTAMP); _delayedProtocolPerVaultParams[nft] = _stagedDelayedProtocolPerVaultParams[nft]; delete _stagedDelayedProtocolPerVaultParams[nft]; delete _delayedProtocolPerVaultParamsTimestamp[nft]; } /// @notice Set Delayed Protocol Params /// @param params New params function _stageDelayedProtocolParams(bytes memory params) internal { _requireProtocolAdmin(); uint256 delayFactor = _delayedProtocolParams.length == 0 ? 0 : 1; _stagedDelayedProtocolParams = params; _delayedProtocolParamsTimestamp = block.timestamp + _internalParams.protocolGovernance.governanceDelay() * delayFactor; } /// @notice Commit Delayed Protocol Params function _commitDelayedProtocolParams() internal { _requireProtocolAdmin(); require(_delayedProtocolParamsTimestamp != 0, ExceptionsLibrary.NULL); require(block.timestamp >= _delayedProtocolParamsTimestamp, ExceptionsLibrary.TIMESTAMP); _delayedProtocolParams = _stagedDelayedProtocolParams; delete _stagedDelayedProtocolParams; delete _delayedProtocolParamsTimestamp; } /// @notice Set immediate strategy params /// @dev Should require nft > 0 /// @param nft Nft of the vault /// @param params New params function _setStrategyParams(uint256 nft, bytes memory params) internal { _requireAtLeastStrategy(nft); _strategyParams[nft] = params; } /// @notice Set immediate operator params /// @param params New params function _setOperatorParams(bytes memory params) internal { _requireAtLeastOperator(); _operatorParams = params; } /// @notice Set immediate protocol params /// @param params New params function _setProtocolParams(bytes memory params) internal { _requireProtocolAdmin(); _protocolParams = params; } // -------------------------- EVENTS -------------------------- /// @notice Emitted when InternalParams are staged for commit /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param params New params that were staged for commit /// @param when When the params could be committed event StagedInternalParams(address indexed origin, address indexed sender, InternalParams params, uint256 when); /// @notice Emitted when InternalParams are staged for commit /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param params New params that were staged for commit event CommitedInternalParams(address indexed origin, address indexed sender, InternalParams params); /// @notice Emitted when New Vault is deployed /// @param origin Origin of the transaction (tx.origin) /// @param sender Sender of the call (msg.sender) /// @param vaultTokens Vault tokens for this vault /// @param options Options for deploy. The details of the options structure are specified in subcontracts /// @param owner Owner of the VaultRegistry NFT for this vault /// @param vaultAddress Address of the new Vault /// @param vaultNft VaultRegistry NFT for the new Vault event DeployedVault( address indexed origin, address indexed sender, address[] vaultTokens, bytes options, address owner, address vaultAddress, uint256 vaultNft ); }
{ "remappings": [ "@openzeppelin/=lib/openzeppelin-contracts/", "@solmate/=lib/solmate/", "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/" ], "optimizer": { "enabled": true, "runs": 200, "details": { "yul": true, "yulDetails": { "stackAllocation": true } } }, "metadata": { "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"components":[{"internalType":"contract IProtocolGovernance","name":"protocolGovernance","type":"address"},{"internalType":"contract IVaultRegistry","name":"registry","type":"address"},{"internalType":"contract IVault","name":"singleton","type":"address"}],"internalType":"struct IVaultGovernance.InternalParams","name":"internalParams_","type":"tuple"},{"components":[{"internalType":"address","name":"crv3Pool","type":"address"},{"internalType":"address","name":"crv","type":"address"},{"internalType":"address","name":"cvx","type":"address"},{"internalType":"uint256","name":"maxSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxSmallPoolsSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxCurveSlippageD9","type":"uint256"},{"internalType":"address","name":"uniswapRouter","type":"address"}],"internalType":"struct IGearboxVaultGovernance.DelayedProtocolParams","name":"delayedProtocolParams_","type":"tuple"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"address","name":"crv3Pool","type":"address"},{"internalType":"address","name":"crv","type":"address"},{"internalType":"address","name":"cvx","type":"address"},{"internalType":"uint256","name":"maxSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxSmallPoolsSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxCurveSlippageD9","type":"uint256"},{"internalType":"address","name":"uniswapRouter","type":"address"}],"indexed":false,"internalType":"struct IGearboxVaultGovernance.DelayedProtocolParams","name":"params","type":"tuple"}],"name":"CommitDelayedProtocolParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"nft","type":"uint256"},{"components":[{"internalType":"address","name":"primaryToken","type":"address"},{"internalType":"address","name":"univ3Adapter","type":"address"},{"internalType":"address","name":"facade","type":"address"},{"internalType":"uint256","name":"withdrawDelay","type":"uint256"},{"internalType":"uint256","name":"initialMarginalValueD9","type":"uint256"},{"internalType":"uint16","name":"referralCode","type":"uint16"}],"indexed":false,"internalType":"struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams","name":"params","type":"tuple"}],"name":"CommitDelayedProtocolPerVaultParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"contract IProtocolGovernance","name":"protocolGovernance","type":"address"},{"internalType":"contract IVaultRegistry","name":"registry","type":"address"},{"internalType":"contract IVault","name":"singleton","type":"address"}],"indexed":false,"internalType":"struct IVaultGovernance.InternalParams","name":"params","type":"tuple"}],"name":"CommitedInternalParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address[]","name":"vaultTokens","type":"address[]"},{"indexed":false,"internalType":"bytes","name":"options","type":"bytes"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"address","name":"vaultAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"vaultNft","type":"uint256"}],"name":"DeployedVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"uint24","name":"largePoolFeeUsed","type":"uint24"}],"indexed":false,"internalType":"struct IGearboxVaultGovernance.StrategyParams","name":"params","type":"tuple"}],"name":"SetStrategyParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"address","name":"crv3Pool","type":"address"},{"internalType":"address","name":"crv","type":"address"},{"internalType":"address","name":"cvx","type":"address"},{"internalType":"uint256","name":"maxSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxSmallPoolsSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxCurveSlippageD9","type":"uint256"},{"internalType":"address","name":"uniswapRouter","type":"address"}],"indexed":false,"internalType":"struct IGearboxVaultGovernance.DelayedProtocolParams","name":"params","type":"tuple"},{"indexed":false,"internalType":"uint256","name":"when","type":"uint256"}],"name":"StageDelayedProtocolParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"nft","type":"uint256"},{"components":[{"internalType":"address","name":"primaryToken","type":"address"},{"internalType":"address","name":"univ3Adapter","type":"address"},{"internalType":"address","name":"facade","type":"address"},{"internalType":"uint256","name":"withdrawDelay","type":"uint256"},{"internalType":"uint256","name":"initialMarginalValueD9","type":"uint256"},{"internalType":"uint16","name":"referralCode","type":"uint16"}],"indexed":false,"internalType":"struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams","name":"params","type":"tuple"},{"indexed":false,"internalType":"uint256","name":"when","type":"uint256"}],"name":"StageDelayedProtocolPerVaultParams","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"components":[{"internalType":"contract IProtocolGovernance","name":"protocolGovernance","type":"address"},{"internalType":"contract IVaultRegistry","name":"registry","type":"address"},{"internalType":"contract IVault","name":"singleton","type":"address"}],"indexed":false,"internalType":"struct IVaultGovernance.InternalParams","name":"params","type":"tuple"},{"indexed":false,"internalType":"uint256","name":"when","type":"uint256"}],"name":"StagedInternalParams","type":"event"},{"inputs":[],"name":"D9","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"commitDelayedProtocolParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"}],"name":"commitDelayedProtocolPerVaultParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"commitInternalParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"contractName","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"contractNameBytes","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"contractVersion","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"contractVersionBytes","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address[]","name":"vaultTokens_","type":"address[]"},{"internalType":"address","name":"owner_","type":"address"},{"internalType":"address","name":"helper_","type":"address"}],"name":"createVault","outputs":[{"internalType":"contract IGearboxVault","name":"vault","type":"address"},{"internalType":"uint256","name":"nft","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"delayedProtocolParams","outputs":[{"components":[{"internalType":"address","name":"crv3Pool","type":"address"},{"internalType":"address","name":"crv","type":"address"},{"internalType":"address","name":"cvx","type":"address"},{"internalType":"uint256","name":"maxSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxSmallPoolsSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxCurveSlippageD9","type":"uint256"},{"internalType":"address","name":"uniswapRouter","type":"address"}],"internalType":"struct IGearboxVaultGovernance.DelayedProtocolParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"delayedProtocolParamsTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"}],"name":"delayedProtocolPerVaultParams","outputs":[{"components":[{"internalType":"address","name":"primaryToken","type":"address"},{"internalType":"address","name":"univ3Adapter","type":"address"},{"internalType":"address","name":"facade","type":"address"},{"internalType":"uint256","name":"withdrawDelay","type":"uint256"},{"internalType":"uint256","name":"initialMarginalValueD9","type":"uint256"},{"internalType":"uint16","name":"referralCode","type":"uint16"}],"internalType":"struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"}],"name":"delayedProtocolPerVaultParamsTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"}],"name":"delayedStrategyParamsTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"internalParams","outputs":[{"components":[{"internalType":"contract IProtocolGovernance","name":"protocolGovernance","type":"address"},{"internalType":"contract IVaultRegistry","name":"registry","type":"address"},{"internalType":"contract IVault","name":"singleton","type":"address"}],"internalType":"struct IVaultGovernance.InternalParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"internalParamsTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"},{"components":[{"internalType":"uint24","name":"largePoolFeeUsed","type":"uint24"}],"internalType":"struct IGearboxVaultGovernance.StrategyParams","name":"params","type":"tuple"}],"name":"setStrategyParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"crv3Pool","type":"address"},{"internalType":"address","name":"crv","type":"address"},{"internalType":"address","name":"cvx","type":"address"},{"internalType":"uint256","name":"maxSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxSmallPoolsSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxCurveSlippageD9","type":"uint256"},{"internalType":"address","name":"uniswapRouter","type":"address"}],"internalType":"struct IGearboxVaultGovernance.DelayedProtocolParams","name":"params","type":"tuple"}],"name":"stageDelayedProtocolParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"},{"components":[{"internalType":"address","name":"primaryToken","type":"address"},{"internalType":"address","name":"univ3Adapter","type":"address"},{"internalType":"address","name":"facade","type":"address"},{"internalType":"uint256","name":"withdrawDelay","type":"uint256"},{"internalType":"uint256","name":"initialMarginalValueD9","type":"uint256"},{"internalType":"uint16","name":"referralCode","type":"uint16"}],"internalType":"struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams","name":"params","type":"tuple"}],"name":"stageDelayedProtocolPerVaultParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"contract IProtocolGovernance","name":"protocolGovernance","type":"address"},{"internalType":"contract IVaultRegistry","name":"registry","type":"address"},{"internalType":"contract IVault","name":"singleton","type":"address"}],"internalType":"struct IVaultGovernance.InternalParams","name":"newParams","type":"tuple"}],"name":"stageInternalParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stagedDelayedProtocolParams","outputs":[{"components":[{"internalType":"address","name":"crv3Pool","type":"address"},{"internalType":"address","name":"crv","type":"address"},{"internalType":"address","name":"cvx","type":"address"},{"internalType":"uint256","name":"maxSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxSmallPoolsSlippageD9","type":"uint256"},{"internalType":"uint256","name":"maxCurveSlippageD9","type":"uint256"},{"internalType":"address","name":"uniswapRouter","type":"address"}],"internalType":"struct IGearboxVaultGovernance.DelayedProtocolParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"}],"name":"stagedDelayedProtocolPerVaultParams","outputs":[{"components":[{"internalType":"address","name":"primaryToken","type":"address"},{"internalType":"address","name":"univ3Adapter","type":"address"},{"internalType":"address","name":"facade","type":"address"},{"internalType":"uint256","name":"withdrawDelay","type":"uint256"},{"internalType":"uint256","name":"initialMarginalValueD9","type":"uint256"},{"internalType":"uint16","name":"referralCode","type":"uint16"}],"internalType":"struct IGearboxVaultGovernance.DelayedProtocolPerVaultParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stagedInternalParams","outputs":[{"components":[{"internalType":"contract IProtocolGovernance","name":"protocolGovernance","type":"address"},{"internalType":"contract IVaultRegistry","name":"registry","type":"address"},{"internalType":"contract IVault","name":"singleton","type":"address"}],"internalType":"struct IVaultGovernance.InternalParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"nft","type":"uint256"}],"name":"strategyParams","outputs":[{"components":[{"internalType":"uint24","name":"largePoolFeeUsed","type":"uint24"}],"internalType":"struct IGearboxVaultGovernance.StrategyParams","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
60806040523480156200001157600080fd5b5060405162002dff38038062002dff83398101604081905262000034916200052a565b815160408051808201909152600281526120ad60f11b602082015283916001600160a01b0316620000835760405162461bcd60e51b81526004016200007a91906200062e565b60405180910390fd5b5060006001600160a01b031681602001516001600160a01b031614156040518060400160405280600281526020016120ad60f11b81525090620000db5760405162461bcd60e51b81526004016200007a91906200062e565b506040808201518151808301909252600282526120ad60f11b60208301526001600160a01b0316620001225760405162461bcd60e51b81526004016200007a91906200062e565b508051600080546001600160a01b03199081166001600160a01b039384161790915560208084015160018054841691851691909117905560409384015160028054909316908416178255845184518086019095529184526120ad60f11b9084015216620001a45760405162461bcd60e51b81526004016200007a91906200062e565b5060006001600160a01b031681602001516001600160a01b031614156040518060400160405280600281526020016120ad60f11b81525090620001fc5760405162461bcd60e51b81526004016200007a91906200062e565b506040808201518151808301909252600282526120ad60f11b60208301526001600160a01b0316620002435760405162461bcd60e51b81526004016200007a91906200062e565b5060c081015160408051808201909152600281526120ad60f11b6020820152906001600160a01b03166200028c5760405162461bcd60e51b81526004016200007a91906200062e565b50633b9aca008160600151111560405180604001604052806004815260200163494e564160e01b81525090620002d75760405162461bcd60e51b81526004016200007a91906200062e565b50633b9aca008160800151111560405180604001604052806004815260200163494e564160e01b81525090620003225760405162461bcd60e51b81526004016200007a91906200062e565b50633b9aca008160a00151111560405180604001604052806004815260200163494e564160e01b815250906200036d5760405162461bcd60e51b81526004016200007a91906200062e565b5080604051602001620003d4919081516001600160a01b039081168252602080840151821690830152604080840151821690830152606080840151908301526080808401519083015260a0838101519083015260c092830151169181019190915260e00190565b604051602081830303815290604052600d9080519060200190620003fa92919062000403565b505050620006c3565b828054620004119062000686565b90600052602060002090601f01602090048101928262000435576000855562000480565b82601f106200045057805160ff191683800117855562000480565b8280016001018555821562000480579182015b828111156200048057825182559160200191906001019062000463565b506200048e92915062000492565b5090565b5b808211156200048e576000815560010162000493565b604051606081016001600160401b0381118282101715620004da57634e487b7160e01b600052604160045260246000fd5b60405290565b60405160e081016001600160401b0381118282101715620004da57634e487b7160e01b600052604160045260246000fd5b6001600160a01b03811681146200052757600080fd5b50565b6000808284036101408112156200054057600080fd5b60608112156200054f57600080fd5b62000559620004a9565b8451620005668162000511565b81526020850151620005788162000511565b602082015260408501516200058d8162000511565b6040820152925060e0605f1982011215620005a757600080fd5b50620005b2620004e0565b6060840151620005c28162000511565b81526080840151620005d48162000511565b602082015260a0840151620005e98162000511565b604082015260c0840151606082015260e0840151608082015261010084015160a08201526101208401516200061e8162000511565b60c0820152919491935090915050565b600060208083528351808285015260005b818110156200065d578581018301518582016040015282016200063f565b8181111562000670576000604083870101525b50601f01601f1916929092016040019392505050565b600181811c908216806200069b57607f821691505b60208210811415620006bd57634e487b7160e01b600052602260045260246000fd5b50919050565b61272c80620006d36000396000f3fe608060405234801561001057600080fd5b50600436106101735760003560e01c80637ac46fbb116100de578063c2cbdc6711610097578063dbb1c35f11610071578063dbb1c35f146103bc578063de2f76a4146103cf578063e4af6e7914610401578063ee2d59f41461040957600080fd5b8063c2cbdc6714610397578063d34cc380146103ac578063d4a07d34146103b457600080fd5b80637ac46fbb146102a157806386c6be3e146103015780638e207dda1461035457806398347a5d14610374578063a0a8e4601461037c578063b016d9a61461038457600080fd5b80631c7f4c73116101305780631c7f4c7314610226578063476f84ae1461022e578063511ce79814610241578063551530ae146102615780636707acee1461026c57806375d0c0dc1461028c57600080fd5b806301ffc9a71461017857806306a46239146101a057806309946538146101b85780630e3e80ac146101cd57806312466b68146101ec578063136857bb14610213575b600080fd5b61018b610186366004611e64565b61041c565b60405190151581526020015b60405180910390f35b640312e302e360dc1b5b604051908152602001610197565b6101cb6101c6366004611f1a565b61044d565b005b7547656172626f785661756c74476f7665726e616e636560501b6101aa565b6101ff6101fa366004611f8c565b61063f565b604051905162ffffff168152602001610197565b6101cb610221366004611fb5565b61072e565b6006546101aa565b6101cb61023c36600461203c565b610988565b6101aa61024f366004611f8c565b6000908152600c602052604090205490565b6101aa633b9aca0081565b6101aa61027a366004611f8c565b60009081526009602052604090205490565b610294610b8c565b6040516101979190612074565b6102f4604080516060810182526000808252602082018190529181019190915250604080516060810182526000546001600160a01b03908116825260015481166020830152600254169181019190915290565b60405161019791906120c9565b6102f4604080516060810182526000808252602082018190529181019190915250604080516060810182526003546001600160a01b03908116825260045481166020830152600554169181019190915290565b610367610362366004611f8c565b610bb0565b60405161019791906120f9565b6101cb610ce4565b610294610dd6565b6101cb61039236600461214c565b610de9565b61039f610ef9565b60405161019791906121c7565b61039f611022565b6101cb611068565b6103676103ca366004611f8c565b61118d565b6103e26103dd3660046121d5565b611230565b604080516001600160a01b039093168352602083019190915201610197565b600f546101aa565b6101cb610417366004611f8c565b6112b5565b6000610427826113a8565b8061044257506001600160e01b0319821663069de56d60e21b145b92915050565b905090565b6104556113de565b805160408051808201909152600281526120ad60f11b6020820152906001600160a01b03166104a05760405162461bcd60e51b81526004016104979190612074565b60405180910390fd5b5060006001600160a01b031681602001516001600160a01b031614156040518060400160405280600281526020016120ad60f11b815250906104f55760405162461bcd60e51b81526004016104979190612074565b506040808201518151808301909252600282526120ad60f11b60208301526001600160a01b03166105395760405162461bcd60e51b81526004016104979190612074565b508051600380546001600160a01b03199081166001600160a01b03938416179091556020808401516004805484169185169190911781556040808601516005805490951690861617909355600054835163bba3293960e01b8152935194169363bba3293993808301939290829003018186803b1580156105b857600080fd5b505afa1580156105cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f091906122a9565b6105fa90426122d8565b6006819055604051339132917f0887cab3184f7c02b16978ab31f8acee05979f59fc3da6abe5bf71105ec3179d91610634918691906122f0565b60405180910390a350565b604080516020810190915260008152600082815260106020526040902080546106679061232d565b1515905061068457505060408051602081019091526101f4815290565b6000828152601060205260409020805461069d9061232d565b80601f01602080910402602001604051908101604052809291908181526020018280546106c99061232d565b80156107165780601f106106eb57610100808354040283529160200191610716565b820191906000526020600020905b8154815290600101906020018083116106f957829003601f168201915b50505050508060200190518101906104429190612379565b805160408051808201909152600281526120ad60f11b6020820152906001600160a01b03166107705760405162461bcd60e51b81526004016104979190612074565b5060006001600160a01b031681602001516001600160a01b031614156040518060400160405280600281526020016120ad60f11b815250906107c55760405162461bcd60e51b81526004016104979190612074565b506040808201518151808301909252600282526120ad60f11b60208301526001600160a01b03166108095760405162461bcd60e51b81526004016104979190612074565b5060c081015160408051808201909152600281526120ad60f11b6020820152906001600160a01b031661084f5760405162461bcd60e51b81526004016104979190612074565b50633b9aca008160600151111560405180604001604052806004815260200163494e564160e01b815250906108975760405162461bcd60e51b81526004016104979190612074565b50633b9aca008160800151111560405180604001604052806004815260200163494e564160e01b815250906108df5760405162461bcd60e51b81526004016104979190612074565b50633b9aca008160a00151111560405180604001604052806004815260200163494e564160e01b815250906109275760405162461bcd60e51b81526004016104979190612074565b506109508160405160200161093c91906121c7565b604051602081830303815290604052611496565b600f54604051339132917f2f351d8b0a600245a91d01ff87eba64b2dbe1fd9a285a4be53ddd0daa032f7b991610634918691906123c5565b600061099760208301836123e1565b6001600160a01b031614156040518060400160405280600281526020016120ad60f11b815250906109db5760405162461bcd60e51b81526004016104979190612074565b5060006109ee60408301602084016123e1565b6001600160a01b031614156040518060400160405280600281526020016120ad60f11b81525090610a325760405162461bcd60e51b81526004016104979190612074565b506000610a4560608301604084016123e1565b6001600160a01b031614156040518060400160405280600281526020016120ad60f11b81525090610a895760405162461bcd60e51b81526004016104979190612074565b5060408051808201909152600381526224a72b60e91b602082015262278d0060608301351115610acc5760405162461bcd60e51b81526004016104979190612074565b5060408051808201909152600381526224a72b60e91b6020820152633b9aca0060808301351015610b105760405162461bcd60e51b81526004016104979190612074565b50610b3a8282604051602001610b269190612483565b604051602081830303815290604052611571565b600082815260096020526040908190205490518391339132917f6ae17db029139848a3df6bf6e1c2dcc02b41a990d7dd5ad68555845f22a365e491610b80918791612491565b60405180910390a45050565b60606104487547656172626f785661756c74476f7665726e616e636560501b61167c565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a08101919091526000828152600b602052604090208054610bfb9061232d565b15159050610c3a5750506040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a081019190915290565b6000828152600b602052604090208054610c539061232d565b80601f0160208091040260200160405190810160405280929190818152602001828054610c7f9061232d565b8015610ccc5780601f10610ca157610100808354040283529160200191610ccc565b820191906000526020600020905b815481529060010190602001808311610caf57829003601f168201915b505050505080602001905181019061044291906124ac565b610cec6116e8565b336001600160a01b0316326001600160a01b03167f605579cce93bd960b09f4adf9dc8f2aeb81b0bb5bd72db747ddf7918f5ee76de600d8054610d2e9061232d565b80601f0160208091040260200160405190810160405280929190818152602001828054610d5a9061232d565b8015610da75780601f10610d7c57610100808354040283529160200191610da7565b820191906000526020600020905b815481529060010190602001808311610d8a57829003601f168201915b5050505050806020019051810190610dbf9190612547565b604051610dcc91906121c7565b60405180910390a3565b6060610448640312e302e360dc1b61167c565b610df660208201826125c2565b62ffffff1660641480610e1b5750610e1160208201826125c2565b62ffffff166101f4145b80610e385750610e2e60208201826125c2565b62ffffff16610bb8145b80610e555750610e4b60208201826125c2565b62ffffff16612710145b6040518060400160405280600381526020016223292160e91b81525090610e8f5760405162461bcd60e51b81526004016104979190612074565b50610eb98282604051602001610ea591906125df565b60405160208183030381529060405261179c565b604051339032907fc23b76068091bcccde9bf3acb65e35e9f9c027c514d1004651c4310fb11364d190610eed9085906125df565b60405180910390a35050565b6040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810191909152600e8054610f3f9061232d565b15159050610f8457506040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c081019190915290565b600e8054610f919061232d565b80601f0160208091040260200160405190810160405280929190818152602001828054610fbd9061232d565b801561100a5780601f10610fdf5761010080835404028352916020019161100a565b820191906000526020600020905b815481529060010190602001808311610fed57829003601f168201915b50505050508060200190518101906104489190612547565b6040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810191909152600d8054610f919061232d565b6110706113de565b6006546040805180820190915260048152631395531360e21b6020820152906110ac5760405162461bcd60e51b81526004016104979190612074565b5060065442101560405180604001604052806002815260200161545360f01b815250906110ec5760405162461bcd60e51b81526004016104979190612074565b5060038054600080546001600160a01b038084166001600160a01b03199283168117845560048054600180548286169087168117909155600580546002805497821697891688179055600698909855978616909855841690559290911690925560408051918252602082019390935291820152339032907fef3e4bc9725fa684957d7de03c6dcd01078ee86cf78ceef25c5f8346df69cc9990606001610dcc565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a08101919091526000828152600a6020526040902080546111d89061232d565b151590506112175750506040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a081019190915290565b6000828152600a602052604090208054610c539061232d565b600080600061123e856117c9565b6040516352af719f60e01b815290935090915081906001600160a01b038216906352af719f906112769086908b908a906004016125fb565b600060405180830381600087803b15801561129057600080fd5b505af11580156112a4573d6000803e3d6000fd5b505050508193505050935093915050565b6112be816119ba565b6000818152600a6020526040902080548291339132917fd229126034649ef380712eb09e2688f8375a6278ad3537f7d86e6d97b8099d0f916112ff9061232d565b80601f016020809104026020016040519081016040528092919081815260200182805461132b9061232d565b80156113785780601f1061134d57610100808354040283529160200191611378565b820191906000526020600020905b81548152906001019060200180831161135b57829003601f168201915b505050505080602001905181019061139091906124ac565b60405161139d91906120f9565b60405180910390a450565b60006301ffc9a760e01b6001600160e01b03198316148061044257506001600160e01b0319821663effda0f560e01b1492915050565b600054604051630935e01b60e21b81523360048201526001600160a01b03909116906324d7806c9060240160206040518083038186803b15801561142157600080fd5b505afa158015611435573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114599190612667565b6040518060400160405280600381526020016223292160e91b815250906114935760405162461bcd60e51b81526004016104979190612074565b50565b61149e6113de565b6000600d80546114ad9061232d565b1590506114bb5760016114be565b60005b60ff16905081600e90805190602001906114d9929190611d1a565b506000546040805163bba3293960e01b8152905183926001600160a01b03169163bba32939916004808301926020929190829003018186803b15801561151e57600080fd5b505afa158015611532573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061155691906122a9565b6115609190612689565b61156a90426122d8565b600f555050565b6115796113de565b6000828152600b60209081526040909120825161159892840190611d1a565b506000828152600a6020526040812080546115b29061232d565b1590506115c05760016115c3565b60005b60ff169050806000800160009054906101000a90046001600160a01b03166001600160a01b031663bba329396040518163ffffffff1660e01b815260040160206040518083038186803b15801561161957600080fd5b505afa15801561162d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165191906122a9565b61165b9190612689565b61166590426122d8565b6000938452600c6020526040909320929092555050565b604080516020808252818301909252606091602082018180368337019050509050602060005b60208110156116da578381602081106116bd576116bd6126a8565b1a6116ca578091506116da565b6116d3816126be565b90506116a2565b508152602081019190915290565b6116f06113de565b600f546040805180820190915260048152631395531360e21b60208201529061172c5760405162461bcd60e51b81526004016104979190612074565b50600f5442101560405180604001604052806002815260200161545360f01b8152509061176c5760405162461bcd60e51b81526004016104979190612074565b50600e600d90805461177d9061232d565b611788929190611d9e565b50611795600e6000611e19565b6000600f55565b6117a582611aaa565b600082815260106020908152604090912082516117c492840190611d1a565b505050565b600080546040516363e85d2d60e01b81523360048201526001602482015282916001600160a01b03169081906363e85d2d9060440160206040518083038186803b15801561181657600080fd5b505afa15801561182a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184e9190612667565b6040518060400160405280600381526020016223292160e91b815250906118885760405162461bcd60e51b81526004016104979190612074565b5060015460408051631112eee760e31b815290516001600160a01b039092169182916388977738916004808301926020929190829003018186803b1580156118cf57600080fd5b505afa1580156118e3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061190791906122a9565b6119129060016122d8565b60025490935061192b906001600160a01b031684611c7d565b6040516305c4fdf960e01b81526001600160a01b0380831660048301528781166024830152919550908216906305c4fdf990604401602060405180830381600087803b15801561197a57600080fd5b505af115801561198e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119b291906122a9565b505050915091565b6119c26113de565b6000818152600c602090815260409182902054825180840190935260048352631395531360e21b918301919091529081611a0f5760405162461bcd60e51b81526004016104979190612074565b508042101560405180604001604052806002815260200161545360f01b81525090611a4d5760405162461bcd60e51b81526004016104979190612074565b506000828152600b60209081526040808320600a9092529091208154909190611a759061232d565b611a80929190611d9e565b506000828152600b60205260408120611a9891611e19565b506000908152600c6020526040812055565b600054604051630935e01b60e21b81523360048201526001600160a01b03909116906324d7806c9060240160206040518083038186803b158015611aed57600080fd5b505afa158015611b01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b259190612667565b80611bb2575060015460405163020604bf60e21b81526004810183905233916001600160a01b03169063081812fc9060240160206040518083038186803b158015611b6f57600080fd5b505afa158015611b83573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ba791906126d9565b6001600160a01b0316145b80611c3f57506001546040516331a9108f60e11b81526004810183905233916001600160a01b031690636352211e9060240160206040518083038186803b158015611bfc57600080fd5b505afa158015611c10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c3491906126d9565b6001600160a01b0316145b6040518060400160405280600381526020016223292160e91b81525090611c795760405162461bcd60e51b81526004016104979190612074565b5050565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008360601b60e81c176000526e5af43d82803e903d91602b57fd5bf38360781b1760205281603760096000f590506001600160a01b0381166104425760405162461bcd60e51b815260206004820152601760248201527f455243313136373a2063726561746532206661696c65640000000000000000006044820152606401610497565b828054611d269061232d565b90600052602060002090601f016020900481019282611d485760008555611d8e565b82601f10611d6157805160ff1916838001178555611d8e565b82800160010185558215611d8e579182015b82811115611d8e578251825591602001919060010190611d73565b50611d9a929150611e4f565b5090565b828054611daa9061232d565b90600052602060002090601f016020900481019282611dcc5760008555611d8e565b82601f10611ddd5780548555611d8e565b82800160010185558215611d8e57600052602060002091601f016020900482015b82811115611d8e578254825591600101919060010190611dfe565b508054611e259061232d565b6000825580601f10611e35575050565b601f01602090049060005260206000209081019061149391905b5b80821115611d9a5760008155600101611e50565b600060208284031215611e7657600080fd5b81356001600160e01b031981168114611e8e57600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b60405160e0810167ffffffffffffffff81118282101715611ece57611ece611e95565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715611efd57611efd611e95565b604052919050565b6001600160a01b038116811461149357600080fd5b600060608284031215611f2c57600080fd5b6040516060810181811067ffffffffffffffff82111715611f4f57611f4f611e95565b6040528235611f5d81611f05565b81526020830135611f6d81611f05565b60208201526040830135611f8081611f05565b60408201529392505050565b600060208284031215611f9e57600080fd5b5035919050565b8035611fb081611f05565b919050565b600060e08284031215611fc757600080fd5b611fcf611eab565b8235611fda81611f05565b81526020830135611fea81611f05565b60208201526040830135611ffd81611f05565b80604083015250606083013560608201526080830135608082015260a083013560a082015260c083013561203081611f05565b60c08201529392505050565b60008082840360e081121561205057600080fd5b8335925060c0601f198201121561206657600080fd5b506020830190509250929050565b600060208083528351808285015260005b818110156120a157858101830151858201604001528201612085565b818111156120b3576000604083870101525b50601f01601f1916929092016040019392505050565b60608101610442828480516001600160a01b03908116835260208083015182169084015260409182015116910152565b81516001600160a01b03908116825260208084015182169083015260408084015190911690820152606080830151908201526080808301519082015260a09182015161ffff169181019190915260c00190565b600080828403604081121561216057600080fd5b833592506020601f198201121561206657600080fd5b80516001600160a01b039081168352602080830151821690840152604080830151821690840152606080830151908401526080808301519084015260a0828101519084015260c09182015116910152565b60e081016104428284612176565b6000806000606084860312156121ea57600080fd5b833567ffffffffffffffff8082111561220257600080fd5b818601915086601f83011261221657600080fd5b813560208282111561222a5761222a611e95565b8160051b925061223b818401611ed4565b828152928401810192818101908a85111561225557600080fd5b948201945b8486101561227f578535935061226f84611f05565b838252948201949082019061225a565b975061228e9050888201611fa5565b9550505050506122a060408501611fa5565b90509250925092565b6000602082840312156122bb57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156122eb576122eb6122c2565b500190565b60808101612320828580516001600160a01b03908116835260208083015182169084015260409182015116910152565b8260608301529392505050565b600181811c9082168061234157607f821691505b6020821081141561236257634e487b7160e01b600052602260045260246000fd5b50919050565b62ffffff8116811461149357600080fd5b60006020828403121561238b57600080fd5b6040516020810181811067ffffffffffffffff821117156123ae576123ae611e95565b60405282516123bc81612368565b81529392505050565b61010081016123d48285612176565b8260e08301529392505050565b6000602082840312156123f357600080fd5b8135611e8e81611f05565b61ffff8116811461149357600080fd5b803561241981611f05565b6001600160a01b03908116835260208201359061243582611f05565b908116602084015260408201359061244c82611f05565b166040830152606081810135908301526080808201359083015260a0810135612474816123fe565b61ffff811660a0840152505050565b60c08101610442828461240e565b60e0810161249f828561240e565b8260c08301529392505050565b600060c082840312156124be57600080fd5b60405160c0810181811067ffffffffffffffff821117156124e1576124e1611e95565b60405282516124ef81611f05565b815260208301516124ff81611f05565b6020820152604083015161251281611f05565b80604083015250606083015160608201526080830151608082015260a083015161253b816123fe565b60a08201529392505050565b600060e0828403121561255957600080fd5b612561611eab565b825161256c81611f05565b8152602083015161257c81611f05565b6020820152604083015161258f81611f05565b80604083015250606083015160608201526080830151608082015260a083015160a082015260c083015161203081611f05565b6000602082840312156125d457600080fd5b8135611e8e81612368565b6020810182356125ee81612368565b62ffffff16909152919050565b6000606082018583526020606081850152818651808452608086019150828801935060005b818110156126455784516001600160a01b031683529383019391830191600101612620565b50506001600160a01b0395909516604094909401939093525091949350505050565b60006020828403121561267957600080fd5b81518015158114611e8e57600080fd5b60008160001904831182151516156126a3576126a36122c2565b500290565b634e487b7160e01b600052603260045260246000fd5b60006000198214156126d2576126d26122c2565b5060010190565b6000602082840312156126eb57600080fd5b8151611e8e81611f0556fea2646970667358221220bbbf1b702b4ea20638ab46633022bc3154e6f53520f42bed4243990077262b7864736f6c63430008090033000000000000000000000000dc9c17662133fb865e7ba3198b67c53a617b2153000000000000000000000000fd23f971696576331fcf96f80a20b4d3b31ca5b2000000000000000000000000f95a53a7d97ab122ed4349eec4abd4d57edce6c4000000000000000000000000bebc44782c7db0a1a60cb6fe97d0b483032ff1c7000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd520000000000000000000000004e3fbd56cd56c3e72c1403e103b45db9da5b9d2b00000000000000000000000000000000000000000000000000000000009896800000000000000000000000000000000000000000000000000000000002625a000000000000000000000000000000000000000000000000000000000001c9c380000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106101735760003560e01c80637ac46fbb116100de578063c2cbdc6711610097578063dbb1c35f11610071578063dbb1c35f146103bc578063de2f76a4146103cf578063e4af6e7914610401578063ee2d59f41461040957600080fd5b8063c2cbdc6714610397578063d34cc380146103ac578063d4a07d34146103b457600080fd5b80637ac46fbb146102a157806386c6be3e146103015780638e207dda1461035457806398347a5d14610374578063a0a8e4601461037c578063b016d9a61461038457600080fd5b80631c7f4c73116101305780631c7f4c7314610226578063476f84ae1461022e578063511ce79814610241578063551530ae146102615780636707acee1461026c57806375d0c0dc1461028c57600080fd5b806301ffc9a71461017857806306a46239146101a057806309946538146101b85780630e3e80ac146101cd57806312466b68146101ec578063136857bb14610213575b600080fd5b61018b610186366004611e64565b61041c565b60405190151581526020015b60405180910390f35b640312e302e360dc1b5b604051908152602001610197565b6101cb6101c6366004611f1a565b61044d565b005b7547656172626f785661756c74476f7665726e616e636560501b6101aa565b6101ff6101fa366004611f8c565b61063f565b604051905162ffffff168152602001610197565b6101cb610221366004611fb5565b61072e565b6006546101aa565b6101cb61023c36600461203c565b610988565b6101aa61024f366004611f8c565b6000908152600c602052604090205490565b6101aa633b9aca0081565b6101aa61027a366004611f8c565b60009081526009602052604090205490565b610294610b8c565b6040516101979190612074565b6102f4604080516060810182526000808252602082018190529181019190915250604080516060810182526000546001600160a01b03908116825260015481166020830152600254169181019190915290565b60405161019791906120c9565b6102f4604080516060810182526000808252602082018190529181019190915250604080516060810182526003546001600160a01b03908116825260045481166020830152600554169181019190915290565b610367610362366004611f8c565b610bb0565b60405161019791906120f9565b6101cb610ce4565b610294610dd6565b6101cb61039236600461214c565b610de9565b61039f610ef9565b60405161019791906121c7565b61039f611022565b6101cb611068565b6103676103ca366004611f8c565b61118d565b6103e26103dd3660046121d5565b611230565b604080516001600160a01b039093168352602083019190915201610197565b600f546101aa565b6101cb610417366004611f8c565b6112b5565b6000610427826113a8565b8061044257506001600160e01b0319821663069de56d60e21b145b92915050565b905090565b6104556113de565b805160408051808201909152600281526120ad60f11b6020820152906001600160a01b03166104a05760405162461bcd60e51b81526004016104979190612074565b60405180910390fd5b5060006001600160a01b031681602001516001600160a01b031614156040518060400160405280600281526020016120ad60f11b815250906104f55760405162461bcd60e51b81526004016104979190612074565b506040808201518151808301909252600282526120ad60f11b60208301526001600160a01b03166105395760405162461bcd60e51b81526004016104979190612074565b508051600380546001600160a01b03199081166001600160a01b03938416179091556020808401516004805484169185169190911781556040808601516005805490951690861617909355600054835163bba3293960e01b8152935194169363bba3293993808301939290829003018186803b1580156105b857600080fd5b505afa1580156105cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f091906122a9565b6105fa90426122d8565b6006819055604051339132917f0887cab3184f7c02b16978ab31f8acee05979f59fc3da6abe5bf71105ec3179d91610634918691906122f0565b60405180910390a350565b604080516020810190915260008152600082815260106020526040902080546106679061232d565b1515905061068457505060408051602081019091526101f4815290565b6000828152601060205260409020805461069d9061232d565b80601f01602080910402602001604051908101604052809291908181526020018280546106c99061232d565b80156107165780601f106106eb57610100808354040283529160200191610716565b820191906000526020600020905b8154815290600101906020018083116106f957829003601f168201915b50505050508060200190518101906104429190612379565b805160408051808201909152600281526120ad60f11b6020820152906001600160a01b03166107705760405162461bcd60e51b81526004016104979190612074565b5060006001600160a01b031681602001516001600160a01b031614156040518060400160405280600281526020016120ad60f11b815250906107c55760405162461bcd60e51b81526004016104979190612074565b506040808201518151808301909252600282526120ad60f11b60208301526001600160a01b03166108095760405162461bcd60e51b81526004016104979190612074565b5060c081015160408051808201909152600281526120ad60f11b6020820152906001600160a01b031661084f5760405162461bcd60e51b81526004016104979190612074565b50633b9aca008160600151111560405180604001604052806004815260200163494e564160e01b815250906108975760405162461bcd60e51b81526004016104979190612074565b50633b9aca008160800151111560405180604001604052806004815260200163494e564160e01b815250906108df5760405162461bcd60e51b81526004016104979190612074565b50633b9aca008160a00151111560405180604001604052806004815260200163494e564160e01b815250906109275760405162461bcd60e51b81526004016104979190612074565b506109508160405160200161093c91906121c7565b604051602081830303815290604052611496565b600f54604051339132917f2f351d8b0a600245a91d01ff87eba64b2dbe1fd9a285a4be53ddd0daa032f7b991610634918691906123c5565b600061099760208301836123e1565b6001600160a01b031614156040518060400160405280600281526020016120ad60f11b815250906109db5760405162461bcd60e51b81526004016104979190612074565b5060006109ee60408301602084016123e1565b6001600160a01b031614156040518060400160405280600281526020016120ad60f11b81525090610a325760405162461bcd60e51b81526004016104979190612074565b506000610a4560608301604084016123e1565b6001600160a01b031614156040518060400160405280600281526020016120ad60f11b81525090610a895760405162461bcd60e51b81526004016104979190612074565b5060408051808201909152600381526224a72b60e91b602082015262278d0060608301351115610acc5760405162461bcd60e51b81526004016104979190612074565b5060408051808201909152600381526224a72b60e91b6020820152633b9aca0060808301351015610b105760405162461bcd60e51b81526004016104979190612074565b50610b3a8282604051602001610b269190612483565b604051602081830303815290604052611571565b600082815260096020526040908190205490518391339132917f6ae17db029139848a3df6bf6e1c2dcc02b41a990d7dd5ad68555845f22a365e491610b80918791612491565b60405180910390a45050565b60606104487547656172626f785661756c74476f7665726e616e636560501b61167c565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a08101919091526000828152600b602052604090208054610bfb9061232d565b15159050610c3a5750506040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a081019190915290565b6000828152600b602052604090208054610c539061232d565b80601f0160208091040260200160405190810160405280929190818152602001828054610c7f9061232d565b8015610ccc5780601f10610ca157610100808354040283529160200191610ccc565b820191906000526020600020905b815481529060010190602001808311610caf57829003601f168201915b505050505080602001905181019061044291906124ac565b610cec6116e8565b336001600160a01b0316326001600160a01b03167f605579cce93bd960b09f4adf9dc8f2aeb81b0bb5bd72db747ddf7918f5ee76de600d8054610d2e9061232d565b80601f0160208091040260200160405190810160405280929190818152602001828054610d5a9061232d565b8015610da75780601f10610d7c57610100808354040283529160200191610da7565b820191906000526020600020905b815481529060010190602001808311610d8a57829003601f168201915b5050505050806020019051810190610dbf9190612547565b604051610dcc91906121c7565b60405180910390a3565b6060610448640312e302e360dc1b61167c565b610df660208201826125c2565b62ffffff1660641480610e1b5750610e1160208201826125c2565b62ffffff166101f4145b80610e385750610e2e60208201826125c2565b62ffffff16610bb8145b80610e555750610e4b60208201826125c2565b62ffffff16612710145b6040518060400160405280600381526020016223292160e91b81525090610e8f5760405162461bcd60e51b81526004016104979190612074565b50610eb98282604051602001610ea591906125df565b60405160208183030381529060405261179c565b604051339032907fc23b76068091bcccde9bf3acb65e35e9f9c027c514d1004651c4310fb11364d190610eed9085906125df565b60405180910390a35050565b6040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810191909152600e8054610f3f9061232d565b15159050610f8457506040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c081019190915290565b600e8054610f919061232d565b80601f0160208091040260200160405190810160405280929190818152602001828054610fbd9061232d565b801561100a5780601f10610fdf5761010080835404028352916020019161100a565b820191906000526020600020905b815481529060010190602001808311610fed57829003601f168201915b50505050508060200190518101906104489190612547565b6040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810191909152600d8054610f919061232d565b6110706113de565b6006546040805180820190915260048152631395531360e21b6020820152906110ac5760405162461bcd60e51b81526004016104979190612074565b5060065442101560405180604001604052806002815260200161545360f01b815250906110ec5760405162461bcd60e51b81526004016104979190612074565b5060038054600080546001600160a01b038084166001600160a01b03199283168117845560048054600180548286169087168117909155600580546002805497821697891688179055600698909855978616909855841690559290911690925560408051918252602082019390935291820152339032907fef3e4bc9725fa684957d7de03c6dcd01078ee86cf78ceef25c5f8346df69cc9990606001610dcc565b6040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a08101919091526000828152600a6020526040902080546111d89061232d565b151590506112175750506040805160c081018252600080825260208201819052918101829052606081018290526080810182905260a081019190915290565b6000828152600a602052604090208054610c539061232d565b600080600061123e856117c9565b6040516352af719f60e01b815290935090915081906001600160a01b038216906352af719f906112769086908b908a906004016125fb565b600060405180830381600087803b15801561129057600080fd5b505af11580156112a4573d6000803e3d6000fd5b505050508193505050935093915050565b6112be816119ba565b6000818152600a6020526040902080548291339132917fd229126034649ef380712eb09e2688f8375a6278ad3537f7d86e6d97b8099d0f916112ff9061232d565b80601f016020809104026020016040519081016040528092919081815260200182805461132b9061232d565b80156113785780601f1061134d57610100808354040283529160200191611378565b820191906000526020600020905b81548152906001019060200180831161135b57829003601f168201915b505050505080602001905181019061139091906124ac565b60405161139d91906120f9565b60405180910390a450565b60006301ffc9a760e01b6001600160e01b03198316148061044257506001600160e01b0319821663effda0f560e01b1492915050565b600054604051630935e01b60e21b81523360048201526001600160a01b03909116906324d7806c9060240160206040518083038186803b15801561142157600080fd5b505afa158015611435573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114599190612667565b6040518060400160405280600381526020016223292160e91b815250906114935760405162461bcd60e51b81526004016104979190612074565b50565b61149e6113de565b6000600d80546114ad9061232d565b1590506114bb5760016114be565b60005b60ff16905081600e90805190602001906114d9929190611d1a565b506000546040805163bba3293960e01b8152905183926001600160a01b03169163bba32939916004808301926020929190829003018186803b15801561151e57600080fd5b505afa158015611532573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061155691906122a9565b6115609190612689565b61156a90426122d8565b600f555050565b6115796113de565b6000828152600b60209081526040909120825161159892840190611d1a565b506000828152600a6020526040812080546115b29061232d565b1590506115c05760016115c3565b60005b60ff169050806000800160009054906101000a90046001600160a01b03166001600160a01b031663bba329396040518163ffffffff1660e01b815260040160206040518083038186803b15801561161957600080fd5b505afa15801561162d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061165191906122a9565b61165b9190612689565b61166590426122d8565b6000938452600c6020526040909320929092555050565b604080516020808252818301909252606091602082018180368337019050509050602060005b60208110156116da578381602081106116bd576116bd6126a8565b1a6116ca578091506116da565b6116d3816126be565b90506116a2565b508152602081019190915290565b6116f06113de565b600f546040805180820190915260048152631395531360e21b60208201529061172c5760405162461bcd60e51b81526004016104979190612074565b50600f5442101560405180604001604052806002815260200161545360f01b8152509061176c5760405162461bcd60e51b81526004016104979190612074565b50600e600d90805461177d9061232d565b611788929190611d9e565b50611795600e6000611e19565b6000600f55565b6117a582611aaa565b600082815260106020908152604090912082516117c492840190611d1a565b505050565b600080546040516363e85d2d60e01b81523360048201526001602482015282916001600160a01b03169081906363e85d2d9060440160206040518083038186803b15801561181657600080fd5b505afa15801561182a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184e9190612667565b6040518060400160405280600381526020016223292160e91b815250906118885760405162461bcd60e51b81526004016104979190612074565b5060015460408051631112eee760e31b815290516001600160a01b039092169182916388977738916004808301926020929190829003018186803b1580156118cf57600080fd5b505afa1580156118e3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061190791906122a9565b6119129060016122d8565b60025490935061192b906001600160a01b031684611c7d565b6040516305c4fdf960e01b81526001600160a01b0380831660048301528781166024830152919550908216906305c4fdf990604401602060405180830381600087803b15801561197a57600080fd5b505af115801561198e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119b291906122a9565b505050915091565b6119c26113de565b6000818152600c602090815260409182902054825180840190935260048352631395531360e21b918301919091529081611a0f5760405162461bcd60e51b81526004016104979190612074565b508042101560405180604001604052806002815260200161545360f01b81525090611a4d5760405162461bcd60e51b81526004016104979190612074565b506000828152600b60209081526040808320600a9092529091208154909190611a759061232d565b611a80929190611d9e565b506000828152600b60205260408120611a9891611e19565b506000908152600c6020526040812055565b600054604051630935e01b60e21b81523360048201526001600160a01b03909116906324d7806c9060240160206040518083038186803b158015611aed57600080fd5b505afa158015611b01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b259190612667565b80611bb2575060015460405163020604bf60e21b81526004810183905233916001600160a01b03169063081812fc9060240160206040518083038186803b158015611b6f57600080fd5b505afa158015611b83573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ba791906126d9565b6001600160a01b0316145b80611c3f57506001546040516331a9108f60e11b81526004810183905233916001600160a01b031690636352211e9060240160206040518083038186803b158015611bfc57600080fd5b505afa158015611c10573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c3491906126d9565b6001600160a01b0316145b6040518060400160405280600381526020016223292160e91b81525090611c795760405162461bcd60e51b81526004016104979190612074565b5050565b6000763d602d80600a3d3981f3363d3d373d3d3d363d730000008360601b60e81c176000526e5af43d82803e903d91602b57fd5bf38360781b1760205281603760096000f590506001600160a01b0381166104425760405162461bcd60e51b815260206004820152601760248201527f455243313136373a2063726561746532206661696c65640000000000000000006044820152606401610497565b828054611d269061232d565b90600052602060002090601f016020900481019282611d485760008555611d8e565b82601f10611d6157805160ff1916838001178555611d8e565b82800160010185558215611d8e579182015b82811115611d8e578251825591602001919060010190611d73565b50611d9a929150611e4f565b5090565b828054611daa9061232d565b90600052602060002090601f016020900481019282611dcc5760008555611d8e565b82601f10611ddd5780548555611d8e565b82800160010185558215611d8e57600052602060002091601f016020900482015b82811115611d8e578254825591600101919060010190611dfe565b508054611e259061232d565b6000825580601f10611e35575050565b601f01602090049060005260206000209081019061149391905b5b80821115611d9a5760008155600101611e50565b600060208284031215611e7657600080fd5b81356001600160e01b031981168114611e8e57600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b60405160e0810167ffffffffffffffff81118282101715611ece57611ece611e95565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715611efd57611efd611e95565b604052919050565b6001600160a01b038116811461149357600080fd5b600060608284031215611f2c57600080fd5b6040516060810181811067ffffffffffffffff82111715611f4f57611f4f611e95565b6040528235611f5d81611f05565b81526020830135611f6d81611f05565b60208201526040830135611f8081611f05565b60408201529392505050565b600060208284031215611f9e57600080fd5b5035919050565b8035611fb081611f05565b919050565b600060e08284031215611fc757600080fd5b611fcf611eab565b8235611fda81611f05565b81526020830135611fea81611f05565b60208201526040830135611ffd81611f05565b80604083015250606083013560608201526080830135608082015260a083013560a082015260c083013561203081611f05565b60c08201529392505050565b60008082840360e081121561205057600080fd5b8335925060c0601f198201121561206657600080fd5b506020830190509250929050565b600060208083528351808285015260005b818110156120a157858101830151858201604001528201612085565b818111156120b3576000604083870101525b50601f01601f1916929092016040019392505050565b60608101610442828480516001600160a01b03908116835260208083015182169084015260409182015116910152565b81516001600160a01b03908116825260208084015182169083015260408084015190911690820152606080830151908201526080808301519082015260a09182015161ffff169181019190915260c00190565b600080828403604081121561216057600080fd5b833592506020601f198201121561206657600080fd5b80516001600160a01b039081168352602080830151821690840152604080830151821690840152606080830151908401526080808301519084015260a0828101519084015260c09182015116910152565b60e081016104428284612176565b6000806000606084860312156121ea57600080fd5b833567ffffffffffffffff8082111561220257600080fd5b818601915086601f83011261221657600080fd5b813560208282111561222a5761222a611e95565b8160051b925061223b818401611ed4565b828152928401810192818101908a85111561225557600080fd5b948201945b8486101561227f578535935061226f84611f05565b838252948201949082019061225a565b975061228e9050888201611fa5565b9550505050506122a060408501611fa5565b90509250925092565b6000602082840312156122bb57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156122eb576122eb6122c2565b500190565b60808101612320828580516001600160a01b03908116835260208083015182169084015260409182015116910152565b8260608301529392505050565b600181811c9082168061234157607f821691505b6020821081141561236257634e487b7160e01b600052602260045260246000fd5b50919050565b62ffffff8116811461149357600080fd5b60006020828403121561238b57600080fd5b6040516020810181811067ffffffffffffffff821117156123ae576123ae611e95565b60405282516123bc81612368565b81529392505050565b61010081016123d48285612176565b8260e08301529392505050565b6000602082840312156123f357600080fd5b8135611e8e81611f05565b61ffff8116811461149357600080fd5b803561241981611f05565b6001600160a01b03908116835260208201359061243582611f05565b908116602084015260408201359061244c82611f05565b166040830152606081810135908301526080808201359083015260a0810135612474816123fe565b61ffff811660a0840152505050565b60c08101610442828461240e565b60e0810161249f828561240e565b8260c08301529392505050565b600060c082840312156124be57600080fd5b60405160c0810181811067ffffffffffffffff821117156124e1576124e1611e95565b60405282516124ef81611f05565b815260208301516124ff81611f05565b6020820152604083015161251281611f05565b80604083015250606083015160608201526080830151608082015260a083015161253b816123fe565b60a08201529392505050565b600060e0828403121561255957600080fd5b612561611eab565b825161256c81611f05565b8152602083015161257c81611f05565b6020820152604083015161258f81611f05565b80604083015250606083015160608201526080830151608082015260a083015160a082015260c083015161203081611f05565b6000602082840312156125d457600080fd5b8135611e8e81612368565b6020810182356125ee81612368565b62ffffff16909152919050565b6000606082018583526020606081850152818651808452608086019150828801935060005b818110156126455784516001600160a01b031683529383019391830191600101612620565b50506001600160a01b0395909516604094909401939093525091949350505050565b60006020828403121561267957600080fd5b81518015158114611e8e57600080fd5b60008160001904831182151516156126a3576126a36122c2565b500290565b634e487b7160e01b600052603260045260246000fd5b60006000198214156126d2576126d26122c2565b5060010190565b6000602082840312156126eb57600080fd5b8151611e8e81611f0556fea2646970667358221220bbbf1b702b4ea20638ab46633022bc3154e6f53520f42bed4243990077262b7864736f6c63430008090033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000dc9c17662133fb865e7ba3198b67c53a617b2153000000000000000000000000fd23f971696576331fcf96f80a20b4d3b31ca5b2000000000000000000000000f95a53a7d97ab122ed4349eec4abd4d57edce6c4000000000000000000000000bebc44782c7db0a1a60cb6fe97d0b483032ff1c7000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd520000000000000000000000004e3fbd56cd56c3e72c1403e103b45db9da5b9d2b00000000000000000000000000000000000000000000000000000000009896800000000000000000000000000000000000000000000000000000000002625a000000000000000000000000000000000000000000000000000000000001c9c380000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564
-----Decoded View---------------
Arg [0] : internalParams_ (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [1] : delayedProtocolParams_ (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
-----Encoded View---------------
10 Constructor Arguments found :
Arg [0] : 000000000000000000000000dc9c17662133fb865e7ba3198b67c53a617b2153
Arg [1] : 000000000000000000000000fd23f971696576331fcf96f80a20b4d3b31ca5b2
Arg [2] : 000000000000000000000000f95a53a7d97ab122ed4349eec4abd4d57edce6c4
Arg [3] : 000000000000000000000000bebc44782c7db0a1a60cb6fe97d0b483032ff1c7
Arg [4] : 000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd52
Arg [5] : 0000000000000000000000004e3fbd56cd56c3e72c1403e103b45db9da5b9d2b
Arg [6] : 0000000000000000000000000000000000000000000000000000000000989680
Arg [7] : 0000000000000000000000000000000000000000000000000000000002625a00
Arg [8] : 0000000000000000000000000000000000000000000000000000000001c9c380
Arg [9] : 000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564
Loading...
Loading
Loading...
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.
[ 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.