Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xcd4570D9D089eCf9b91A00B6a9C130d71bf9D479
Balance 0 ETH
Nonce 1
Code Size 5086 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

5086 bytes
0x608060405234801561001057600080fd5b506004361061011b5760003560e01c8063862da878116100b2578063d6ebb5f311610081578063dd07ab1c11610066578063dd07ab1c1461030c578063f2fde38b1461031f578063f61b1b781461033257600080fd5b8063d6ebb5f3146102e6578063d9caed12146102f957600080fd5b8063862da878146102415780638da5cb5b1461025b578063a69b66bf14610276578063d1c699aa146102d357600080fd5b806358c0528f116100ee57806358c0528f146101b6578063676e4cb5146101c8578063715018a6146101db5780637eda9957146101e357600080fd5b806303f90a461461012057806313966db5146101355780631c33f16e1461017557806337f7cc0b14610188575b600080fd5b61013361012e366004610ec1565b610345565b005b600154610158906c0100000000000000000000000090046001600160601b031681565b6040516001600160601b0390911681526020015b60405180910390f35b610133610183366004610ec1565b6103dc565b6101a8610196366004610ef3565b60036020526000908152604090205481565b60405190815260200161016c565b6101336101c4366004610f0e565b5050565b6101336101d6366004610ec1565b610481565b61013361054c565b61022c6101f1366004610ef3565b6001546001600160a01b03919091166000908152600360205260409020546c010000000000000000000000009091046001600160601b031691565b6040805192835260208301919091520161016c565b60005461015890600160a01b90046001600160601b031681565b6000546040516001600160a01b03909116815260200161016c565b6102b4610284366004610f38565b600260209081526000928352604080842090915290825290205460ff81169061010090046001600160601b031682565b6040805192151583526001600160601b0390911660208301520161016c565b600154610158906001600160601b031681565b6101336102f4366004610fb7565b610560565b610133610307366004611023565b61073e565b61022c61031a36600461105f565b6107ac565b61013361032d366004610ef3565b61088c565b6101336103403660046110c7565b6108e8565b61034d610b74565b6702c68af0bb1400006001600160601b038216111561037f57604051630ae3904560e41b815260040160405180910390fd5b600080546001600160a01b0316600160a01b6001600160601b038416908102919091179091556040519081527f5d870338f69740a001fb5cc82ca75ec81286dee157245ec9b365e3be72144c72906020015b60405180910390a150565b6103e4610b74565b6611c37937e080006001600160601b038216111561042e576040517f65a0597f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180546bffffffffffffffffffffffff19166001600160601b0383169081179091556040519081527fae8264d027536c60e1bc3fbecc8a25c1fa9634478a1bd116b8f4a469ec5ac048906020016103d1565b610489610b74565b6702c68af0bb1400006001600160601b03821611156104d4576040517fc288bf8f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180547fffffffffffffffff000000000000000000000000ffffffffffffffffffffffff166c010000000000000000000000006001600160601b038416908102919091179091556040519081527f276a443d2b2c8332fc729f4de8847f12625c9f099e07b8501c91df8a4fcb1210906020016103d1565b610554610b74565b61055e6000610bba565b565b610568610b74565b8215806105755750828114155b1561059357604051634ec4810560e11b815260040160405180910390fd5b60005b838110156106fa57670de0b6b3a76400008383838181106105b9576105b9611190565b9050602002013511156105f8576040517fa9c14d7800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82828281811061060a5761060a611190565b905060200201356003600087878581811061062757610627611190565b905060200201602081019061063c9190610ef3565b6001600160a01b03166001600160a01b031681526020019081526020016000205403610694576040517f7d44fab900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8282828181106106a6576106a6611190565b90506020020135600360008787858181106106c3576106c3611190565b90506020020160208101906106d89190610ef3565b6001600160a01b03168152602081019190915260400160002055600101610596565b507f14a3751e1b958d3fae2cc626f7f33fccbf74d7d78c46d4f2364600ad46ed81058484848460405161073094939291906111ed565b60405180910390a150505050565b610746610b74565b61075a6001600160a01b0383168483610c22565b816001600160a01b0316836001600160a01b03167f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb8360405161079f91815260200190565b60405180910390a3505050565b600080806002816107c06020870187610ef3565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008560400160208101906107f59190610ef3565b6001600160a01b03168152602080820192909252604090810160002081518083019092525460ff811615158083526101009091046001600160601b031692820192909252915061085757600054600160a01b90046001600160601b031661085d565b80602001515b6001600160a01b039096166000908152600360205260409020546001600160601b039690961696945050505050565b610894610b74565b6001600160a01b0381166108dc576040517f1e4fbdf7000000000000000000000000000000000000000000000000000000008152600060048201526024015b60405180910390fd5b6108e581610bba565b50565b6108f0610b74565b848015806108fe5750808414155b806109095750808214155b1561092757604051634ec4810560e11b815260040160405180910390fd5b60005b81811015610b2957600084848381811061094657610946611190565b90506040020180360381019061095c9190611260565b805190915015610a7e576702c68af0bb1400006001600160601b031681602001516001600160601b031611156109a557604051630ae3904560e41b815260040160405180910390fd5b80600260008b8b868181106109bc576109bc611190565b90506020020160208101906109d19190610ef3565b6001600160a01b03166001600160a01b031681526020019081526020016000206000898986818110610a0557610a05611190565b9050602002016020810190610a1a9190610ef3565b6001600160a01b031681526020808201929092526040016000208251815493909201516001600160601b0316610100026cffffffffffffffffffffffff0019921515929092166cffffffffffffffffffffffffff1990931692909217179055610b20565b600260008a8a85818110610a9457610a94611190565b9050602002016020810190610aa99190610ef3565b6001600160a01b03166001600160a01b031681526020019081526020016000206000888885818110610add57610add611190565b9050602002016020810190610af29190610ef3565b6001600160a01b03168152602081019190915260400160002080546cffffffffffffffffffffffffff191690555b5060010161092a565b507f0c1b633a683dc0d0a3a78f77b7acb3af3a79a73a9ac82fb6dd73deb877a8e183878787878787604051610b63969594939291906112cb565b60405180910390a150505050505050565b6000546001600160a01b0316331461055e576040517f118cdaa70000000000000000000000000000000000000000000000000000000081523360048201526024016108d3565b600080546001600160a01b038381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610ca2908490610ca7565b505050565b6000610cbc6001600160a01b03841683610d23565b90508051600014158015610ce1575080806020019051810190610cdf919061135c565b155b15610ca2576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b03841660048201526024016108d3565b6060610d3183836000610d38565b9392505050565b606081471015610d76576040517fcd7860590000000000000000000000000000000000000000000000000000000081523060048201526024016108d3565b600080856001600160a01b03168486604051610d929190611379565b60006040518083038185875af1925050503d8060008114610dcf576040519150601f19603f3d011682016040523d82523d6000602084013e610dd4565b606091505b5091509150610de4868383610dee565b9695505050505050565b606082610e0357610dfe82610e63565b610d31565b8151158015610e1a57506001600160a01b0384163b155b15610e5c576040517f9996b3150000000000000000000000000000000000000000000000000000000081526001600160a01b03851660048201526024016108d3565b5080610d31565b805115610e735780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80356001600160601b0381168114610ebc57600080fd5b919050565b600060208284031215610ed357600080fd5b610d3182610ea5565b80356001600160a01b0381168114610ebc57600080fd5b600060208284031215610f0557600080fd5b610d3182610edc565b60008060408385031215610f2157600080fd5b610f2a83610edc565b946020939093013593505050565b60008060408385031215610f4b57600080fd5b610f5483610edc565b9150610f6260208401610edc565b90509250929050565b60008083601f840112610f7d57600080fd5b50813567ffffffffffffffff811115610f9557600080fd5b6020830191508360208260051b8501011115610fb057600080fd5b9250929050565b60008060008060408587031215610fcd57600080fd5b843567ffffffffffffffff80821115610fe557600080fd5b610ff188838901610f6b565b9096509450602087013591508082111561100a57600080fd5b5061101787828801610f6b565b95989497509550505050565b60008060006060848603121561103857600080fd5b61104184610edc565b925061104f60208501610edc565b9150604084013590509250925092565b60008060008385036101a081121561107657600080fd5b61107f85610edc565b935060208501356fffffffffffffffffffffffffffffffff811681146110a457600080fd5b9250610160603f19820112156110b957600080fd5b506040840190509250925092565b600080600080600080606087890312156110e057600080fd5b863567ffffffffffffffff808211156110f857600080fd5b6111048a838b01610f6b565b9098509650602089013591508082111561111d57600080fd5b6111298a838b01610f6b565b9096509450604089013591508082111561114257600080fd5b818901915089601f83011261115657600080fd5b81358181111561116557600080fd5b8a60208260061b850101111561117a57600080fd5b6020830194508093505050509295509295509295565b634e487b7160e01b600052603260045260246000fd5b8183526000602080850194508260005b858110156111e2576001600160a01b036111cf83610edc565b16875295820195908201906001016111b6565b509495945050505050565b6040815260006112016040830186886111a6565b82810360208401528381527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff84111561123957600080fd5b8360051b80866020840137016020019695505050505050565b80151581146108e557600080fd5b60006040828403121561127257600080fd5b6040516040810181811067ffffffffffffffff821117156112a357634e487b7160e01b600052604160045260246000fd5b60405282356112b181611252565b81526112bf60208401610ea5565b60208201529392505050565b6060815260006112df60608301888a6111a6565b602083820360208501526112f482888a6111a6565b8481036040868101919091528682528793509060200160005b8781101561134c57843561132081611252565b151582526001600160601b03611337868601610ea5565b1682850152938201939082019060010161130d565b509b9a5050505050505050505050565b60006020828403121561136e57600080fd5b8151610d3181611252565b6000825160005b8181101561139a5760208186018101518583015201611380565b50600092019182525091905056fea26469706673582212202193cfecf8150de325de7b4164a067a34e7a138a5256be5d5e028e454d2e270f64736f6c63430008180033

Verified Source Code Full Match

Compiler: v0.8.24+commit.e11b9ed9 EVM: paris Optimization: Yes (1000 runs)
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
IERC20Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}
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();
        }
    }
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
DataTypes.sol 116 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

library DataTypes {
    struct OptionInfo {
        address underlyingToken;
        uint48 expiry;
        address settlementToken;
        uint48 earliestExercise;
        uint128 notional;
        uint128 strike;
        AdvancedSettings advancedSettings;
    }

    struct AdvancedSettings {
        uint64 borrowCap;
        address oracle;
        bool premiumTokenIsUnderlying;
        bool votingDelegationAllowed;
        address allowedDelegateRegistry;
    }

    struct AuctionInitialization {
        address underlyingToken;
        address settlementToken;
        uint128 notional;
        AuctionParams auctionParams;
        AdvancedSettings advancedSettings;
    }

    struct AuctionParams {
        uint128 relStrike;
        uint48 tenor;
        uint48 earliestExerciseTenor;
        uint32 decayStartTime;
        uint32 decayDuration;
        uint64 relPremiumStart;
        uint64 relPremiumFloor;
        uint128 minSpot;
        uint128 maxSpot;
    }

    struct RFQInitialization {
        OptionInfo optionInfo;
        RFQQuote rfqQuote;
    }

    struct RFQQuote {
        uint128 premium;
        uint256 validUntil;
        bytes signature;
        address eip1271Maker;
    }

    enum BidStatus {
        Success,
        SpotPriceTooLow,
        OutOfRangeSpotPrice,
        OptionAlreadyMinted,
        PremiumTooLow
    }

    struct BidPreview {
        BidStatus status;
        address settlementToken;
        address underlyingToken;
        uint128 strike;
        uint48 expiry;
        uint48 earliestExercise;
        uint128 premium;
        address premiumToken;
        uint256 oracleSpotPrice;
        uint64 currAsk;
        uint128 matchFeeProtocol;
        uint128 matchFeeDistPartner;
    }

    enum RFQStatus {
        Expired,
        InvalidQuote,
        AlreadyExecuted,
        QuotesPaused,
        Success,
        InvalidEIP1271Signature
    }

    struct TakeQuotePreview {
        RFQStatus status;
        bytes32 msgHash;
        address quoter;
        uint128 premium;
        address premiumToken;
        uint128 matchFeeProtocol;
        uint128 matchFeeDistPartner;
    }

    struct SwapQuote {
        address takerGiveToken;
        uint256 takerGiveAmount;
        address makerGiveToken;
        uint256 makerGiveAmount;
        uint256 validUntil;
        bytes signature;
        address eip1271Maker;
    }

    struct OptionNaming {
        string name;
        string symbol;
    }

    struct MatchFeePerPair {
        bool isSet;
        uint96 matchFee;
    }
}
Errors.sol 54 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

library Errors {
    error AlreadyInitialized();
    error DistPartnerFeeUnchanged();
    error FeeHandlerAlreadySet();
    error InvalidAddress();
    error InvalidArrayLength();
    error InvalidBid();
    error InvalidBorrowAmount();
    error InvalidBorrowCap();
    error InvalidBorrowTime();
    error InvalidDistPartnerFeeShare();
    error InvalidEarliestExercise();
    error InvalidEarliestExerciseTenor();
    error InvalidEIP1271Signature();
    error InvalidExpiry();
    error InvalidExercise();
    error InvalidExerciseAmount();
    error InvalidExerciseFee();
    error InvalidExerciseTime();
    error InvalidGetEscrowsQuery();
    error InvalidMatchFee();
    error InvalidMaxTimeSinceLastUpdate();
    error InvalidMintFee();
    error InvalidMinMaxSpot();
    error InvalidNotional();
    error InvalidOracle();
    error InvalidOracleAnswer();
    error InvalidOracleDecimals();
    error InvalidRelPremiums();
    error InvalidRepayAmount();
    error InvalidRepayTime();
    error InvalidSender();
    error InvalidStrike();
    error InvalidTakeQuote();
    error InvalidTenor();
    error InvalidTokenPair();
    error InvalidWithdraw();
    error NoAllowedDelegateRegistry();
    error NoOptionMinted();
    error NoOracle();
    error NotAnEscrow();
    error NothingToRedeem();
    error NothingToRepay();
    error OnlyAvailableForAuctions();
    error OracleAlreadySet(address oracleAddr);
    error OwnerAlreadySet();
    error SwapQuoteAlreadyUsed();
    error SwapQuoteExpired();
    error SwapQuotePaused();
    error VotingDelegationNotAllowed();
}
FeeHandler.sol 169 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {DataTypes} from "../DataTypes.sol";
import {Errors} from "../errors/Errors.sol";
import {IFeeHandler} from "../interfaces/IFeeHandler.sol";

contract FeeHandler is Ownable, IFeeHandler {
    using SafeERC20 for IERC20Metadata;

    uint256 internal constant BASE = 1 ether;
    uint96 internal constant MAX_MATCH_FEE = 0.2 ether;
    uint96 internal constant MAX_EXERCISE_FEE = 0.005 ether;

    uint96 public matchFee;
    uint96 public exerciseFee;
    uint96 public mintFee;

    mapping(address => mapping(address => DataTypes.MatchFeePerPair))
        public matchFeePerPair;
    mapping(address => uint256) public distPartnerFeeShare;

    constructor(
        address initOwner,
        uint96 _matchFee,
        uint96 _exerciseFee,
        uint96 _mintFee
    ) Ownable(initOwner) {
        setMatchFee(_matchFee);
        setExerciseFee(_exerciseFee);
        setMintFee(_mintFee);
    }

    function provisionFees(
        address /*token*/,
        uint256 /*amount*/
    ) external virtual {
        // @dev: placeholder to add fee distribution
        // logic in derived contracts
    }

    function withdraw(
        address to,
        address token,
        uint256 amount
    ) external virtual onlyOwner {
        IERC20Metadata(token).safeTransfer(to, amount);
        emit Withdraw(to, token, amount);
    }

    function getMatchFeeInfo(
        address distPartner,
        uint128 /*optionPremium*/,
        DataTypes.OptionInfo calldata optionInfo
    )
        external
        view
        virtual
        returns (uint256 _matchFee, uint256 _matchFeeDistPartnerShare)
    {
        DataTypes.MatchFeePerPair memory _matchFeePerPair = matchFeePerPair[
            optionInfo.underlyingToken
        ][optionInfo.settlementToken];
        // @dev: use pair specific match fee if set; else use general match fee;
        // additional match fee rules can be added in derived contracts
        _matchFee = _matchFeePerPair.isSet
            ? _matchFeePerPair.matchFee
            : matchFee;
        _matchFeeDistPartnerShare = distPartnerFeeShare[distPartner];
    }

    function getMintFeeInfo(
        address distPartner
    )
        external
        view
        virtual
        returns (uint256 _mintFee, uint256 _mintFeeDistPartnerShare)
    {
        _mintFee = mintFee;
        _mintFeeDistPartnerShare = distPartnerFeeShare[distPartner];
    }

    function setDistPartnerFeeShares(
        address[] calldata accounts,
        uint256[] calldata feeShares
    ) external virtual onlyOwner {
        if (accounts.length == 0 || accounts.length != feeShares.length) {
            revert Errors.InvalidArrayLength();
        }
        for (uint256 i = 0; i < accounts.length; ++i) {
            if (feeShares[i] > BASE) {
                revert Errors.InvalidDistPartnerFeeShare();
            }
            if (distPartnerFeeShare[accounts[i]] == feeShares[i]) {
                revert Errors.DistPartnerFeeUnchanged();
            }
            distPartnerFeeShare[accounts[i]] = feeShares[i];
        }

        emit SetDistPartnerFeeShares(accounts, feeShares);
    }

    function setMatchFee(uint96 _matchFee) public virtual onlyOwner {
        if (_matchFee > MAX_MATCH_FEE) {
            revert Errors.InvalidMatchFee();
        }
        matchFee = _matchFee;
        emit SetMatchFee(_matchFee);
    }

    function setMatchFeesPerPair(
        address[] calldata underlyingTokens,
        address[] calldata settlementTokens,
        DataTypes.MatchFeePerPair[] calldata _matchFeesPerPair
    ) public virtual onlyOwner {
        uint256 length = underlyingTokens.length;
        if (
            length == 0 ||
            length != settlementTokens.length ||
            length != _matchFeesPerPair.length
        ) {
            revert Errors.InvalidArrayLength();
        }

        for (uint256 i = 0; i < length; ++i) {
            DataTypes.MatchFeePerPair memory feePerPair = _matchFeesPerPair[i];

            if (feePerPair.isSet) {
                if (feePerPair.matchFee > MAX_MATCH_FEE) {
                    revert Errors.InvalidMatchFee();
                }
                matchFeePerPair[underlyingTokens[i]][
                    settlementTokens[i]
                ] = feePerPair;
            } else {
                delete matchFeePerPair[underlyingTokens[i]][
                    settlementTokens[i]
                ];
            }
        }

        emit SetMatchFeesPerPair(
            underlyingTokens,
            settlementTokens,
            _matchFeesPerPair
        );
    }

    function setExerciseFee(uint96 _exerciseFee) public virtual onlyOwner {
        if (_exerciseFee > MAX_EXERCISE_FEE) {
            revert Errors.InvalidExerciseFee();
        }
        exerciseFee = _exerciseFee;
        emit SetExerciseFee(_exerciseFee);
    }

    function setMintFee(uint96 _mintFee) public virtual onlyOwner {
        // @dev: use same fee cap as match fee
        if (_mintFee > MAX_MATCH_FEE) {
            revert Errors.InvalidMintFee();
        }
        mintFee = _mintFee;
        emit SetMintFee(_mintFee);
    }
}
IFeeHandler.sol 126 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {DataTypes} from "../DataTypes.sol";

/// @title IFeeHandler
/// @dev Interface for the FeeHandler contract.
/// Provides functionality for managing and distributing fees, and setting fee configurations.

interface IFeeHandler {
    /// @notice Emitted when fees are provisioned.
    /// @param token The address of the token in which fees are provisioned.
    /// @param amount The amount of the token provisioned as fees.
    event ProvisionFees(address indexed token, uint256 amount);

    /// @notice Emitted when tokens are withdrawn from the FeeHandler.
    /// @param to The address receiving the withdrawn tokens.
    /// @param token The address of the token being withdrawn.
    /// @param amount The amount of tokens withdrawn.
    event Withdraw(address indexed to, address indexed token, uint256 amount);

    /// @notice Emitted when match fee is set.
    /// @param matchFee The match fee set as a percentage.
    event SetMatchFee(uint256 matchFee);

    /// @notice Emitted when token pair-specific match fees are set or removed.
    /// @param underlyingTokens The underlying tokens per pair.
    /// @param settlementTokens The settlement tokens per pair.
    /// @param matchFeesPerPair The match fee structs per pair.
    event SetMatchFeesPerPair(
        address[] underlyingTokens,
        address[] settlementTokens,
        DataTypes.MatchFeePerPair[] matchFeesPerPair
    );

    /// @notice Emitted when mint fee is set.
    /// @param mintFee The mint fee set as a percentage.
    event SetMintFee(uint256 mintFee);

    /// @notice Emitted when the exercise fee is set.
    /// @param exerciseFee The exercise fee set as a percentage.
    event SetExerciseFee(uint96 exerciseFee);

    /// @notice Emitted when distribution partners are set.
    /// @param accounts The addresses of the distribution partners.
    /// @param feeShares The fee shares for given distribution partners.
    event SetDistPartnerFeeShares(address[] accounts, uint256[] feeShares);

    /// @notice Provisions fees in a specified token.
    /// @param token The address of the token in which fees are provisioned.
    /// @param amount The amount of the token provisioned as fees.
    function provisionFees(address token, uint256 amount) external;

    /// @notice Withdraws a specified amount of tokens to a given address.
    /// @param to The address receiving the withdrawn tokens.
    /// @param token The address of the token to withdraw.
    /// @param amount The amount of tokens to withdraw.
    function withdraw(address to, address token, uint256 amount) external;

    /// @notice Returns the match fee and distribution partner fee share for a given option match.
    /// @param distPartner The address of the distribution partner.
    /// @param optionPremium The given option premium.
    /// @param optionInfo The given option info.
    /// @return _matchFee The applicable match fee for the given option.
    /// @return _matchFeeDistPartnerShare The distribution partner's share of the match fee.
    function getMatchFeeInfo(
        address distPartner,
        uint128 optionPremium,
        DataTypes.OptionInfo calldata optionInfo
    )
        external
        view
        returns (uint256 _matchFee, uint256 _matchFeeDistPartnerShare);

    /// @notice Returns the mint fee and fee share for given distribution partner.
    /// @param distPartner The address of the distribution partner.
    /// @return _mintFee The mint fee as a percentage.
    /// @return _mintFeeDistPartnerShare The share of the mint fee for the distribution partner.
    function getMintFeeInfo(
        address distPartner
    )
        external
        view
        returns (uint256 _mintFee, uint256 _mintFeeDistPartnerShare);

    /// @notice Sets distribution partners and their status.
    /// @param accounts The addresses of the distribution partners.
    /// @param feeShares The fee shares for given distribution partners.
    function setDistPartnerFeeShares(
        address[] calldata accounts,
        uint256[] calldata feeShares
    ) external;

    /// @notice Sets the match fee and distribution partner share.
    /// @param _matchFee The match fee as a percentage.
    function setMatchFee(uint96 _matchFee) external;

    /// @notice Sets or removes a token pair-specific match fee.
    /// @param underlyingTokens The underlying tokens per pair.
    /// @param settlementTokens The settlement tokens per pair.
    /// @param _matchFeePerPair The match fee structs per pair.
    function setMatchFeesPerPair(
        address[] calldata underlyingTokens,
        address[] calldata settlementTokens,
        DataTypes.MatchFeePerPair[] calldata _matchFeePerPair
    ) external;

    /// @notice Sets the exercise fee.
    /// @param _exerciseFee The exercise fee as a percentage.
    function setExerciseFee(uint96 _exerciseFee) external;

    /// @notice Returns the match fee set in the FeeHandler.
    /// @return The match fee as a percentage.
    function matchFee() external view returns (uint96);

    /// @notice Returns the distribution fee share for a given account.
    /// @param account The account to query the distribution fee share for.
    /// @return The fee share for the given distribution partner.
    function distPartnerFeeShare(
        address account
    ) external view returns (uint256);

    /// @notice Returns the exercise fee set in the FeeHandler.
    /// @return The exercise fee as a percentage.
    function exerciseFee() external view returns (uint96);
}

Read Contract

distPartnerFeeShare 0x37f7cc0b → uint256
exerciseFee 0xd1c699aa → uint96
getMatchFeeInfo 0xd2cb2225 → uint256, uint256
getMintFeeInfo 0x7eda9957 → uint256, uint256
matchFee 0x862da878 → uint96
matchFeePerPair 0xa69b66bf → bool, uint96
mintFee 0x13966db5 → uint96
owner 0x8da5cb5b → address

Write Contract 9 functions

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

provisionFees 0x58c0528f
address
uint256
renounceOwnership 0x715018a6
No parameters
setDistPartnerFeeShares 0xd6ebb5f3
address[] accounts
uint256[] feeShares
setExerciseFee 0x1c33f16e
uint96 _exerciseFee
setMatchFee 0x03f90a46
uint96 _matchFee
setMatchFeesPerPair 0xcb387aab
address[] underlyingTokens
address[] settlementTokens
tuple[] _matchFeesPerPair
setMintFee 0x676e4cb5
uint96 _mintFee
transferOwnership 0xf2fde38b
address newOwner
withdraw 0xd9caed12
address to
address token
uint256 amount

Recent Transactions

No transactions found for this address