Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xfd1B30D0721D10B9Ea41de66c8E462d1EBbCE3AC
Balance 0 ETH
Nonce 1
Code Size 6169 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6169 bytes
0x608060405234801561001057600080fd5b50600436106101215760003560e01c806362680e4b116100ad578063bc063e1a11610071578063bc063e1a146102da578063d73792a9146102e3578063d8780161146102ed578063e58ff0ec14610302578063e941fa781461031557600080fd5b806362680e4b1461024257806375451b4f146102695780637dc0d1d014610283578063805fcc90146102aa578063935c96fa146102b357600080fd5b80633eeeafe6116100f45780633eeeafe6146101cf57806340e34f4e146101d85780634ec7d3cf146101ff5780635036c3c4146102125780635e87140f1461023957600080fd5b80630d43e8ad146101265780631c19cddd1461016a5780632ab370a41461019f57806337d77c4b146101c6575b600080fd5b61014d7f000000000000000000000000d5d1acc9c7ebaf8bbf85c45aee2b8b3f3b1bd06281565b6040516001600160a01b0390911681526020015b60405180910390f35b6101917f000000000000000000000000000000000000000000000000000000000001518081565b604051908152602001610161565b61014d7f000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b61019160005481565b61019160035481565b6101917f000000000000000000000000000000000000000000000000000000000001518081565b61019161020d366004611476565b61033c565b6101917f0000000000000000000000000000000000000000000000015af1d78b58c4000081565b61019160015481565b6101917f00000000000000000000000000000000000000000000000ee86442fcd06c000081565b610271600581565b60405160ff9091168152602001610161565b61014d7f0000000000000000000000004142bb1ceec0dec4f7aaeb3d51d2dc8e6ee1841081565b61019160025481565b61014d7f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f3281565b61019161c35081565b610191620f424081565b6103006102fb3660046114b6565b610652565b005b6101916103103660046114ee565b610c40565b6101917f0000000000000000000000000000000000000000000000000000000000001d4c81565b60006001600160a01b038316610350573392505b6000807f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f326001600160a01b03166316f0115b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103d5919061150a565b90506000816001600160a01b0316639d63848a6040518163ffffffff1660e01b815260040160a060405180830381865afa158015610417573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061043b9190611527565b90506000826001600160a01b031663f46a30206040518163ffffffff1660e01b815260040160a060405180830381865afa15801561047d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104a19190611585565b905060005b60058110156105835760008382600581106104c3576104c36115da565b6020020151905060008a83600581106104de576104de6115da565b602002015190506001600160a01b038216158015906104fd5750600081115b15610579576105176001600160a01b038316333084610e37565b61054b6001600160a01b0383167f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f3283610ea4565b83836005811061055d5761055d6115da565b602002015161056c9082611606565b610576908861161d565b96505b50506001016104a6565b5061058d84610f2e565b604051632d62af2f60e01b81526000906001600160a01b037f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f321690632d62af2f906105de908c908c90600401611653565b6020604051808303816000875af11580156105fd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106219190611679565b90508681101561064457604051630d143f8360e01b815260040160405180910390fd5b9450505050505b9392505050565b61065b83610fd6565b60007f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f326001600160a01b03166316f0115b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106df919061150a565b90506106f66001600160a01b038216333087610e37565b60006107018561107b565b9050801561074a5761073d6001600160a01b0383167f000000000000000000000000d5d1acc9c7ebaf8bbf85c45aee2b8b3f3b1bd062836110c5565b6107478186611692565b94505b61077e6001600160a01b0383167f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f3287610ea4565b6040805160a081018252600080825260208201819052818301819052606082018190526080820152905163ca54be3b60e01b81526001600160a01b037f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f32169163ca54be3b916107f391899130906004016116a5565b600060405180830381600087803b15801561080d57600080fd5b505af1158015610821573d6000803e3d6000fd5b505050506000807f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f326001600160a01b03166316f0115b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610886573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108aa919061150a565b90506000816001600160a01b0316639d63848a6040518163ffffffff1660e01b815260040160a060405180830381865afa1580156108ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109109190611527565b90506000826001600160a01b031663f46a30206040518163ffffffff1660e01b815260040160a060405180830381865afa158015610952573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109769190611585565b905060005b6005811015610b19576000838260058110610998576109986115da565b602002015190506001600160a01b03811615610b10576040516370a0823160e01b81523060048201526000906001600160a01b038316906370a0823190602401602060405180830381865afa1580156109f5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a199190611679565b90508015610b0e57610a356001600160a01b0383168c836110c5565b670de0b6b3a7640000848460058110610a5057610a506115da565b6020020151604051638b2f0f4f60e01b81526001600160a01b03858116600483015284917f0000000000000000000000004142bb1ceec0dec4f7aaeb3d51d2dc8e6ee1841090911690638b2f0f4f90602401602060405180830381865afa158015610abf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ae39190611679565b610aed9190611606565b610af79190611606565b610b0191906116d2565b610b0b908861161d565b96505b505b5060010161097b565b50837f000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b031615610c1357604051638b2f0f4f60e01b81526001600160a01b037f000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee811660048301527f0000000000000000000000004142bb1ceec0dec4f7aaeb3d51d2dc8e6ee184101690638b2f0f4f90602401602060405180830381865afa158015610bd0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bf49190611679565b610c0686670de0b6b3a7640000611606565b610c1091906116d2565b90505b87811015610c3457604051630d143f8360e01b815260040160405180910390fd5b50505050505050505050565b6000807f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f326001600160a01b03166399ec92466040518163ffffffff1660e01b8152600401602060405180830381865afa158015610ca1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cc59190611679565b905060007f0000000000000000000000004bd57f97e35e7c3302dc3a8d4d803826856f9f326001600160a01b03166316f0115b6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610d27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4b919061150a565b60405163bb91c33960e01b8152600481018490529091506000906001600160a01b0383169063bb91c33990602401608060405180830381865afa158015610d96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dba9190611709565b51604051634eabdcd360e11b81529091506001600160a01b03821690639d57b9a690610ded90889060019060040161177c565b602060405180830381865afa158015610e0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e2e9190611679565b95945050505050565b6040516001600160a01b038481166024830152838116604483015260648201839052610e9e9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506110fb565b50505050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa158015610ef4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f189190611679565b9050610e9e8484610f29858561161d565b611163565b7f00000000000000000000000000000000000000000000000000000000000151808015610fd25780600154610f63919061161d565b421115610f7857600082905542600155610f8f565b81600080828254610f89919061161d565b90915550505b7f00000000000000000000000000000000000000000000000ee86442fcd06c00006000541115610fd25760405163790e7b2760e11b815260040160405180910390fd5b5050565b7f00000000000000000000000000000000000000000000000000000000000151808015610fd2578060035461100b919061161d565b42111561102057600282905542600355611038565b8160026000828254611032919061161d565b90915550505b7f0000000000000000000000000000000000000000000000015af1d78b58c400006002541115610fd25760405163051d4f4760e11b815260040160405180910390fd5b60007f0000000000000000000000000000000000000000000000000000000000001d4c80156110bf57620f42406110b28285611606565b6110bc91906116d2565b91505b50919050565b6040516001600160a01b038381166024830152604482018390526110f691859182169063a9059cbb90606401610e6c565b505050565b60006111106001600160a01b038416836111f3565b905080516000141580156111355750808060200190518101906111339190611799565b155b156110f657604051635274afe760e01b81526001600160a01b03841660048201526024015b60405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b1790526111b4848261120a565b610e9e576040516001600160a01b038481166024830152600060448301526111e991869182169063095ea7b390606401610e6c565b610e9e84826110fb565b6060611201838360006112ad565b90505b92915050565b6000806000846001600160a01b03168460405161122791906117b4565b6000604051808303816000865af19150503d8060008114611264576040519150601f19603f3d011682016040523d82523d6000602084013e611269565b606091505b50915091508180156112935750805115806112935750808060200190518101906112939190611799565b8015610e2e5750505050506001600160a01b03163b151590565b6060814710156112d25760405163cd78605960e01b815230600482015260240161115a565b600080856001600160a01b031684866040516112ee91906117b4565b60006040518083038185875af1925050503d806000811461132b576040519150601f19603f3d011682016040523d82523d6000602084013e611330565b606091505b509150915061134086838361134a565b9695505050505050565b60608261135f5761135a826113a6565b61064b565b815115801561137657506001600160a01b0384163b155b1561139f57604051639996b31560e01b81526001600160a01b038516600482015260240161115a565b508061064b565b8051156113b65780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b50565b634e487b7160e01b600052604160045260246000fd5b60405160a0810167ffffffffffffffff8111828210171561140b5761140b6113d2565b60405290565b600082601f83011261142257600080fd5b61142a6113e8565b8060a084018581111561143c57600080fd5b845b8181101561145657803584526020938401930161143e565b509095945050505050565b6001600160a01b03811681146113cf57600080fd5b600080600060e0848603121561148b57600080fd5b6114958585611411565b925060a08401356114a581611461565b9295929450505060c0919091013590565b6000806000606084860312156114cb57600080fd5b8335925060208401356114dd81611461565b929592945050506040919091013590565b600060a0828403121561150057600080fd5b6112018383611411565b60006020828403121561151c57600080fd5b815161064b81611461565b600060a0828403121561153957600080fd5b82601f83011261154857600080fd5b6115506113e8565b8060a084018581111561156257600080fd5b845b8181101561145657805161157781611461565b845260209384019301611564565b600060a0828403121561159757600080fd5b82601f8301126115a657600080fd5b6115ae6113e8565b8060a08401858111156115c057600080fd5b845b818110156114565780518452602093840193016115c2565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b8082028115828204841417611204576112046115f0565b80820180821115611204576112046115f0565b8060005b6005811015610e9e578151845260209384019390910190600101611634565b60c081016116618285611630565b6001600160a01b039290921660a09190910152919050565b60006020828403121561168b57600080fd5b5051919050565b81810381811115611204576112046115f0565b83815260e081016116b96020830185611630565b6001600160a01b039290921660c0919091015292915050565b6000826116ef57634e487b7160e01b600052601260045260246000fd5b500490565b8051801515811461170457600080fd5b919050565b60006080828403121561171b57600080fd5b6040516080810181811067ffffffffffffffff8211171561173e5761173e6113d2565b604052825161174c81611461565b808252506020830151602082015260408301516040820152611770606084016116f4565b60608201529392505050565b60c0810161178a8285611630565b82151560a08301529392505050565b6000602082840312156117ab57600080fd5b611201826116f4565b6000825160005b818110156117d557602081860181015185830152016117bb565b50600092019182525091905056fea2646970667358221220779b83faf1895137470172b2a4fdb118a3b39dae2488aebd7ee7d1bf3512eddb64736f6c63430008170033

Verified Source Code Full Match

Compiler: v0.8.23+commit.f704f362 EVM: paris Optimization: Yes (200 runs)
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}
IPool.sol 84 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import { IStrategy } from './IStrategy.sol';

interface IPool is IERC20 {
    error WrongDeposit(uint256 sid, uint256[5] amounts);
    error AbsentStrategy(uint256 sid);
    error NotStartedStrategy(uint256 sid);
    error DisabledStrategy(uint256 sid);
    error WrongAmount();
    error WrongWithdrawParams(uint256 sid);
    error WrongRatio();
    error ZeroAddress();
    error DuplicatedStrategy();
    error IncorrectArguments();
    error WrongWithdrawPercent();
    error WrongReceiver();
    error IncorrectSid();
    error WrongTokens();
    error WrongDecimalMultipliers();

    struct StrategyInfo {
        IStrategy strategy;
        uint256 startTime;
        uint256 minted;
        bool enabled;
    }

    event Deposited(
        address indexed depositor,
        uint256 deposited,
        uint256[5] amounts,
        uint256 indexed sid
    );

    event Withdrawn(address indexed withdrawer, uint256 withdrawn, uint256 indexed sid);

    event FailedWithdrawal(address indexed withdrawer, uint256[5] amounts, uint256 withdrawn);

    event AddedStrategy(uint256 indexed sid, address indexed strategyAddr, uint256 startTime);
    event ClaimedRewards(address indexed receiver, IERC20[] rewardTokens);
    event ClaimedExtraGains(address indexed receiver, uint256 amount);
    event EnabledStrategy(address indexed pool);
    event DisableStrategy(address indexed pool);
    event UpdatedToken(
        uint256 indexed tid,
        address indexed token,
        uint256 tokenDecimalMultiplier,
        address tokenOld
    );

    function tokens() external view returns (IERC20[5] memory);

    function token(uint256 tid) external view returns (IERC20);

    function tokenDecimalsMultipliers() external view returns (uint256[5] memory);

    function strategyInfo(uint256 sid) external view returns (StrategyInfo memory);

    function claimRewards(address receiver, IERC20[] memory rewardTokens) external;

    function totalHoldings() external view returns (uint256);

    function strategyCount() external view returns (uint256);

    function deposit(
        uint256 sid,
        uint256[5] memory amounts,
        address receiver
    ) external returns (uint256);

    function depositStrategy(uint256 sid, uint256[5] memory amounts) external returns (uint256);

    function withdraw(
        uint256 sid,
        uint256 stableAmount,
        uint256[5] memory minTokenAmounts,
        address receiver
    ) external;

    function mintAndClaimExtraGains(address receiver) external;
}
IPoolController.sol 21 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import './IPool.sol';

interface IPoolController is IERC20 {
    function pool() external view returns (IPool);

    function deposit(uint256[5] memory amounts, address receiver) external returns (uint256);

    function withdraw(
        uint256 stableAmount,
        uint256[5] memory minTokenAmounts,
        address receiver
    ) external;

    function defaultDepositSid() external view returns (uint256);

    function defaultWithdrawSid() external view returns (uint256);
}
IStrategy.sol 25 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

interface IStrategy {
    function deposit(uint256[5] memory amounts) external returns (uint256);

    function withdraw(
        address receiver,
        uint256 userDepositRatio, // multiplied by 1e18
        uint256[5] memory minTokenAmounts
    ) external returns (bool);

    function withdrawAll(uint256[5] memory minTokenAmounts) external;

    function totalHoldings() external view returns (uint256);

    function claimRewards(address receiver, IERC20[] memory rewardTokens) external;

    function calcTokenAmount(
        uint256[5] memory tokenAmounts,
        bool isDeposit
    ) external view returns (uint256 sharesAmount);
}
IOracle.sol 15 lines
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.23;

interface IOracle {

    error ZeroAddress();
    error UnsupportedToken();


    /// @notice returns the price in USD of symbol.
    function getUSDPrice(address token) external view returns (uint256);

    /// @notice returns if the given token is supported for pricing.
    function isTokenSupported(address token) external view returns (bool);
}
ZunamiStableZap.sol 203 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '../interfaces/IPoolController.sol';
import "../lib/Oracle/interfaces/IOracle.sol";

//import "hardhat/console.sol";

contract ZunamiStableZap {
    using SafeERC20 for IERC20;

    error ZeroAddress();
    error SameAddress();
    error DailyMintLimitOverflow();
    error DailyRedeemLimitOverflow();
    error BrokenMinimumAmount();
    error FeeWronglyHigh();

    uint8 public constant POOL_ASSETS = 5;

    uint256 public constant FEE_DENOMINATOR = 1000000; // 100.0000%
    uint256 public constant MAX_FEE = 50000; // 5%

    IPoolController immutable public zunStableController;
    IOracle immutable public oracle;
    address immutable public basedToken;

    uint256 immutable public dailyMintDuration; // in secs
    uint256 immutable public dailyMintLimit; // in minimal value

    uint256 immutable public dailyRedeemDuration; // in secs
    uint256 immutable public dailyRedeemLimit; // in minimal value

    uint256 public dailyMintTotal;
    uint256 public dailyMintCountingTimestamp; // start block timestamp of limit counting

    uint256 public dailyRedeemTotal;
    uint256 public dailyRedeemCountingTimestamp; // start block timestamp of limit counting

    uint256 immutable public withdrawFee;
    address immutable public feeDistributor;

    constructor(
        address _zunStableController,
        address _oracle,
        uint256 _dailyMintDuration,
        uint256 _dailyMintLimit,
        uint256 _dailyRedeemDuration,
        uint256 _dailyRedeemLimit,
        address _basedToken, // address(0) for USD, 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for ETH, 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BTC
        uint256 _withdrawFee,
        address _feeDistributor
    ) {
        if (_zunStableController == address(0))
            revert ZeroAddress();

        zunStableController = IPoolController(_zunStableController);

        if (_oracle == address(0))
            revert ZeroAddress();

        oracle = IOracle(_oracle);

        dailyMintDuration = _dailyMintDuration;
        dailyMintLimit = _dailyMintLimit;
        dailyMintCountingTimestamp = _dailyMintDuration > 0 ? block.timestamp : 0;

        dailyRedeemDuration = _dailyRedeemDuration;
        dailyRedeemLimit = _dailyRedeemLimit;
        dailyRedeemCountingTimestamp = _dailyRedeemDuration > 0 ? block.timestamp : 0;

        basedToken = _basedToken;

        if (_withdrawFee > MAX_FEE) revert FeeWronglyHigh();
        withdrawFee = _withdrawFee;

        if (_feeDistributor == address(0)) revert ZeroAddress();
        feeDistributor = _feeDistributor;
    }

    function mint(
        uint256[POOL_ASSETS] memory amounts,
        address receiver,
        uint256 minAmountStable
    ) external returns (uint256) {
        if (receiver == address(0)) {
            receiver = msg.sender;
        }

        uint256 depositingAmount;

        IPool pool = zunStableController.pool();
        IERC20[POOL_ASSETS] memory tokens = pool.tokens();
        uint256[POOL_ASSETS] memory tokenDecimalsMultipliers = pool.tokenDecimalsMultipliers();
        for (uint256 i = 0; i < POOL_ASSETS; ++i) {
            IERC20 token = tokens[i];
            uint256 amount = amounts[i];
            if (address(token) != address(0) && amount > 0) {
                token.safeTransferFrom(msg.sender, address(this), amount);
                token.safeIncreaseAllowance(address(zunStableController), amount);
                depositingAmount += amount * tokenDecimalsMultipliers[i];
            }
        }

        _verifyMintLimits(depositingAmount);

        uint256 zunStableAmount = zunStableController.deposit(amounts, receiver);
        if (zunStableAmount < minAmountStable) revert BrokenMinimumAmount();
        return zunStableAmount;
    }

    function estimateMint(
        uint256[POOL_ASSETS] memory amounts
    ) external view returns (uint256) {

        uint256 depositSid = zunStableController.defaultDepositSid();
        IPool pool = zunStableController.pool();
        IStrategy strategy = pool.strategyInfo(depositSid).strategy;

        return strategy.calcTokenAmount(amounts, true);
    }

    function _verifyMintLimits(
        uint256 value
    ) internal {
        uint256 dailyDuration = dailyMintDuration;
        if (dailyDuration > 0) {
            if (block.timestamp > dailyMintCountingTimestamp + dailyDuration) {
                dailyMintTotal = value;
                dailyMintCountingTimestamp = block.timestamp;
            } else {
                dailyMintTotal += value;
            }
            if(dailyMintTotal > dailyMintLimit) revert DailyMintLimitOverflow();
        }
    }

    function redeem(
        uint256 zunStableAmount,
        address receiver,
        uint256 minAmountBased
    ) external {
        _verifyRedeemLimits(zunStableAmount);

        IERC20 zunStable = IERC20(zunStableController.pool());
        zunStable.safeTransferFrom(msg.sender, address(this), zunStableAmount);

        uint256 nominalFee = _calcFee(zunStableAmount);
        if (nominalFee > 0) {
            zunStable.safeTransfer(feeDistributor, nominalFee);
            zunStableAmount -= nominalFee;
        }

        zunStable.safeIncreaseAllowance(address(zunStableController), zunStableAmount);
        zunStableController.withdraw(zunStableAmount, [uint256(0),0,0,0,0], address(this));

        uint256 usdAmount;
        IPool pool = zunStableController.pool();
        IERC20[POOL_ASSETS] memory tokens = pool.tokens();
        uint256[POOL_ASSETS] memory tokenDecimalsMultipliers = pool.tokenDecimalsMultipliers();
        for (uint256 i = 0; i < POOL_ASSETS; ++i) {
            IERC20 token = tokens[i];
            if (address(token) != address(0)) {
                uint256 tokenBalance = token.balanceOf(address(this));
                if (tokenBalance > 0) {
                    token.safeTransfer(receiver, tokenBalance);
                    usdAmount += oracle.getUSDPrice(address(token)) * tokenBalance * tokenDecimalsMultipliers[i] / 1e18;
                }
            }
        }

        uint256 basedAmount = usdAmount;
        if (basedToken != address(0)) {
            basedAmount = usdAmount * 1e18 / oracle.getUSDPrice(basedToken);
        }

        if ( basedAmount < minAmountBased) revert BrokenMinimumAmount();
    }

    function _verifyRedeemLimits(
        uint256 value
    ) internal {
        uint256 dailyDuration = dailyRedeemDuration;
        if (dailyDuration > 0) {
            if (block.timestamp > dailyRedeemCountingTimestamp + dailyDuration) {
                dailyRedeemTotal = value;
                dailyRedeemCountingTimestamp = block.timestamp;
            } else {
                dailyRedeemTotal += value;
            }
            if(dailyRedeemTotal > dailyRedeemLimit) revert DailyRedeemLimitOverflow();
        }
    }

    function _calcFee(uint256 value) internal view returns (uint256 nominalFee) {
        uint256 withdrawFee_ = withdrawFee;
        if (withdrawFee_ > 0 ) {
            nominalFee = (value * withdrawFee_) / FEE_DENOMINATOR;
        }
    }
}

Read Contract

FEE_DENOMINATOR 0xd73792a9 → uint256
MAX_FEE 0xbc063e1a → uint256
POOL_ASSETS 0x75451b4f → uint8
basedToken 0x2ab370a4 → address
dailyMintCountingTimestamp 0x5e87140f → uint256
dailyMintDuration 0x40e34f4e → uint256
dailyMintLimit 0x62680e4b → uint256
dailyMintTotal 0x37d77c4b → uint256
dailyRedeemCountingTimestamp 0x3eeeafe6 → uint256
dailyRedeemDuration 0x1c19cddd → uint256
dailyRedeemLimit 0x5036c3c4 → uint256
dailyRedeemTotal 0x805fcc90 → uint256
estimateMint 0xe58ff0ec → uint256
feeDistributor 0x0d43e8ad → address
oracle 0x7dc0d1d0 → address
withdrawFee 0xe941fa78 → uint256
zunStableController 0x935c96fa → address

Write Contract 2 functions

These functions modify contract state and require a wallet transaction to execute.

mint 0x4ec7d3cf
uint256[5] amounts
address receiver
uint256 minAmountStable
returns: uint256
redeem 0xd8780161
uint256 zunStableAmount
address receiver
uint256 minAmountBased

Recent Transactions

No transactions found for this address