Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xCEc15df628FE699E88cC9AC04faE4f399e4D2a5c
Balance 0 ETH
Nonce 1
Code Size 4560 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

4560 bytes
0x608060405234801561000f575f5ffd5b50600436106100e5575f3560e01c8063a5d4096b11610088578063cdf456e111610063578063cdf456e1146101f4578063e5711e8b1461021b578063f851a4401461022e578063fbfa77cf14610240575f5ffd5b8063a5d4096b14610194578063aced1661146101a7578063c646aee2146101d2575f5ffd5b8063748747e6116100c3578063748747e61461014857806375829def1461015b5780637b2243391461016e57806391cab88f14610181575f5ffd5b80630576e753146100e95780633a2b4a891461012b5780635487e94314610140575b5f5ffd5b6101166100f7366004610eb7565b600260209081525f928352604080842090915290825290205460ff1681565b60405190151581526020015b60405180910390f35b61013e610139366004610ef7565b610267565b005b61013e610308565b61013e610156366004610f37565b610518565b61013e610169366004610f37565b61059d565b61013e61017c366004610f57565b610647565b61013e61018f366004610fc4565b6106cf565b61013e6101a2366004611013565b61087a565b6001546101ba906001600160a01b031681565b6040516001600160a01b039091168152602001610122565b6101166101e0366004610f37565b60036020525f908152604090205460ff1681565b6101ba7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b61013e610229366004611096565b610c07565b5f546101ba906001600160a01b031681565b6101ba7f000000000000000000000000608de7d88d60e796376599d1827854a5323bdde681565b5f546001600160a01b0316331461029157604051637bfa4b9f60e01b815260040160405180910390fd5b6001600160a01b0383165f8181526002602090815260408083206001600160e01b0319871680855290835292819020805460ff191686151590811790915590519081529192917f82fb8983d257e8540f827608f2ff0f9a77fcd6c4b0735d9074f7637c62c8978791015b60405180910390a3505050565b5f546001600160a01b0316331480159061032d57506001546001600160a01b03163314155b1561034b57604051635439671560e11b815260040160405180910390fd5b610353610d03565b6040516370a0823160e01b81523060048201525f907f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316906370a0823190602401602060405180830381865afa1580156103b7573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103db91906110d0565b9050805f036103fd57604051630d44987f60e21b815260040160405180910390fd5b6104516001600160a01b037f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48167f000000000000000000000000608de7d88d60e796376599d1827854a5323bdde683610d1e565b6040516345efb3f960e11b8152600481018290527f000000000000000000000000608de7d88d60e796376599d1827854a5323bdde66001600160a01b031690638bdf67f2906024015f604051808303815f87803b1580156104b0575f5ffd5b505af11580156104c2573d5f5f3e3d5ffd5b505050507f72efa1f1dc0a045e5990134ff8b9f2bfa1f8bd6a181ee0cc3c5823263ca8b492816040516104f791815260200190565b60405180910390a15061051660015f51602061117b5f395f51905f5255565b565b5f546001600160a01b0316331461054257604051637bfa4b9f60e01b815260040160405180910390fd5b6001546040516001600160a01b038084169216907f53d3703fe259def57584466f32d1b94c30278008c683c21b04501c4966f13a69905f90a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b5f546001600160a01b031633146105c757604051637bfa4b9f60e01b815260040160405180910390fd5b6001600160a01b0381166105ee5760405163d92e233d60e01b815260040160405180910390fd5b5f80546040516001600160a01b03808516939216917ff8ccb027dfcd135e000e9d45e6cc2d662578a8825d4c45b5e32e0adf67e79ec691a35f80546001600160a01b0319166001600160a01b0392909216919091179055565b5f546001600160a01b0316331461067157604051637bfa4b9f60e01b815260040160405180910390fd5b6001600160a01b0382165f81815260036020908152604091829020805460ff191685151590811790915591519182527f7dfa5a39e8d4ab2d330416cdd5102e73066069ba1c76ec335cc47727a07fe798910160405180910390a25050565b5f546001600160a01b031633148015906106f457506001546001600160a01b03163314155b1561071257604051635439671560e11b815260040160405180910390fd5b61071a610d03565b600481101561073c576040516301d0c40560e21b815260040160405180910390fd5b5f61074a60048284866110e7565b6107539161110e565b6001600160a01b0385165f9081526002602090815260408083206001600160e01b03198516845290915290205490915060ff166107a3576040516301d0c40560e21b815260040160405180910390fd5b5f846001600160a01b031684846040516107be929190611146565b5f604051808303815f865af19150503d805f81146107f7576040519150601f19603f3d011682016040523d82523d5f602084013e6107fc565b606091505b505090508061081e5760405163360e42e160e01b815260040160405180910390fd5b6040516001600160e01b03198316906001600160a01b038716907f674e1610a0b9b6cd46f6a5439b0fc99a5db0d4e8c23805bc6fd5bfd17ed3910e905f90a3505061087560015f51602061117b5f395f51905f5255565b505050565b5f546001600160a01b0316331480159061089f57506001546001600160a01b03163314155b156108bd57604051635439671560e11b815260040160405180910390fd5b6108c5610d03565b6001600160a01b0387165f9081526003602052604090205460ff166108fd57604051635bb5845760e11b815260040160405180910390fd5b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316856001600160a01b03161461094e5760405162db68fd60e51b815260040160405180910390fd5b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316866001600160a01b0316036109a05760405163ab1f06eb60e01b815260040160405180910390fd5b6109b46001600160a01b0387168886610d1e565b6040516370a0823160e01b81523060048201525f907f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316906370a0823190602401602060405180830381865afa158015610a18573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a3c91906110d0565b90505f886001600160a01b03168484604051610a59929190611146565b5f604051808303815f865af19150503d805f8114610a92576040519150601f19603f3d011682016040523d82523d5f602084013e610a97565b606091505b5050905080610ab85760405162e902f160e21b815260040160405180910390fd5b6040516370a0823160e01b81523060048201525f907f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316906370a0823190602401602060405180830381865afa158015610b1c573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610b4091906110d0565b90505f610b4d8483611155565b905086811015610b7057604051638199f5f360e01b815260040160405180910390fd5b610b846001600160a01b038b168c5f610d1e565b886001600160a01b03168a6001600160a01b03168c6001600160a01b03167f6782190c91d4a7e8ad2a867deed6ec0a970cab8ff137ae2bd4abd92b3810f4d38b85604051610bdc929190918252602082015260400190565b60405180910390a450505050610bfe60015f51602061117b5f395f51905f5255565b50505050505050565b5f546001600160a01b03163314610c3157604051637bfa4b9f60e01b815260040160405180910390fd5b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486001600160a01b0316836001600160a01b031603610c8357604051631bd9165160e31b815260040160405180910390fd5b6001600160a01b038216610caa5760405163d92e233d60e01b815260040160405180910390fd5b610cbe6001600160a01b0384168383610d9d565b816001600160a01b0316836001600160a01b03167f4143f7b5cb6ea007914c32b8a3e64cebc051d7f493fa0755454da1e47701e125836040516102fb91815260200190565b610d0b610daa565b60025f51602061117b5f395f51905f5255565b610d2a8383835f610dd9565b61087557610d3b83835f6001610dd9565b610d6857604051635274afe760e01b81526001600160a01b03841660048201526024015b60405180910390fd5b610d758383836001610dd9565b61087557604051635274afe760e01b81526001600160a01b0384166004820152602401610d5f565b610d758383836001610e3b565b5f51602061117b5f395f51905f525460020361051657604051633ee5aeb560e01b815260040160405180910390fd5b60405163095ea7b360e01b5f8181526001600160a01b038616600452602485905291602083604481808b5af1925060015f51148316610e2f578383151615610e23573d5f823e3d81fd5b5f873b113d1516831692505b60405250949350505050565b60405163a9059cbb60e01b5f8181526001600160a01b038616600452602485905291602083604481808b5af1925060015f51148316610e2f578383151615610e23573d5f823e3d81fd5b80356001600160a01b0381168114610e9b575f5ffd5b919050565b80356001600160e01b031981168114610e9b575f5ffd5b5f5f60408385031215610ec8575f5ffd5b610ed183610e85565b9150610edf60208401610ea0565b90509250929050565b80358015158114610e9b575f5ffd5b5f5f5f60608486031215610f09575f5ffd5b610f1284610e85565b9250610f2060208501610ea0565b9150610f2e60408501610ee8565b90509250925092565b5f60208284031215610f47575f5ffd5b610f5082610e85565b9392505050565b5f5f60408385031215610f68575f5ffd5b610f7183610e85565b9150610edf60208401610ee8565b5f5f83601f840112610f8f575f5ffd5b50813567ffffffffffffffff811115610fa6575f5ffd5b602083019150836020828501011115610fbd575f5ffd5b9250929050565b5f5f5f60408486031215610fd6575f5ffd5b610fdf84610e85565b9250602084013567ffffffffffffffff811115610ffa575f5ffd5b61100686828701610f7f565b9497909650939450505050565b5f5f5f5f5f5f5f60c0888a031215611029575f5ffd5b61103288610e85565b965061104060208901610e85565b955061104e60408901610e85565b9450606088013593506080880135925060a088013567ffffffffffffffff811115611077575f5ffd5b6110838a828b01610f7f565b989b979a50959850939692959293505050565b5f5f5f606084860312156110a8575f5ffd5b6110b184610e85565b92506110bf60208501610e85565b929592945050506040919091013590565b5f602082840312156110e0575f5ffd5b5051919050565b5f5f858511156110f5575f5ffd5b83861115611101575f5ffd5b5050820193919092039150565b80356001600160e01b0319811690600484101561113f576001600160e01b0319600485900360031b81901b82161691505b5092915050565b818382375f9101908152919050565b8181038181111561117457634e487b7160e01b5f52601160045260245ffd5b9291505056fe9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220b27f57022ad00f803890df9c947d467367026cd7a61e4f5bbc27e125df91d5ee64736f6c634300081c0033

Verified Source Code Full Match

Compiler: v0.8.28+commit.7893614a EVM: cancun Optimization: Yes (200 runs)
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)

pragma solidity >=0.6.2;

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

/**
 * @title IERC1363
 * @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
 *
 * Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
 * after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
 */
interface IERC1363 is IERC20, IERC165 {
    /*
     * Note: the ERC-165 identifier for this interface is 0xb0202a11.
     * 0xb0202a11 ===
     *   bytes4(keccak256('transferAndCall(address,uint256)')) ^
     *   bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
     *   bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256)')) ^
     *   bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
     */

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
     * and then calls {IERC1363Receiver-onTransferReceived} on `to`.
     * @param from The address which you want to send tokens from.
     * @param to The address which you want to transfer to.
     * @param value The amount of tokens to be transferred.
     * @param data Additional data with no specified format, sent in call to `to`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value) external returns (bool);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
     * @param spender The address which will spend the funds.
     * @param value The amount of tokens to be spent.
     * @param data Additional data with no specified format, sent in call to `spender`.
     * @return A boolean value indicating whether the operation succeeded unless throwing.
     */
    function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

/**
 * @title SafeERC20
 * @dev Wrappers around ERC-20 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 {
    /**
     * @dev An operation with an ERC-20 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 {
        if (!_safeTransfer(token, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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 {
        if (!_safeTransferFrom(token, from, to, value, true)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _safeTransfer(token, to, value, false);
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _safeTransferFrom(token, from, to, value, false);
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    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.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    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.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        if (!_safeApprove(token, spender, value, false)) {
            if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
            if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
     * has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferFromAndCallRelaxed(
        IERC1363 token,
        address from,
        address to,
        uint256 value,
        bytes memory data
    ) internal {
        if (to.code.length == 0) {
            safeTransferFrom(token, from, to, value);
        } else if (!token.transferFromAndCall(from, to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
     * Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
     * once without retrying, and relies on the returned value to be true.
     *
     * Reverts if the returned value is other than `true`.
     */
    function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            forceApprove(token, to, value);
        } else if (!token.approveAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity `token.transfer(to, value)` call, 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 to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.transfer.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(to, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }

    /**
     * @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, 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 from The sender of the tokens
     * @param to The recipient of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value,
        bool bubble
    ) private returns (bool success) {
        bytes4 selector = IERC20.transferFrom.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(from, shr(96, not(0))))
            mstore(0x24, and(to, shr(96, not(0))))
            mstore(0x44, value)
            success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
            mstore(0x60, 0)
        }
    }

    /**
     * @dev Imitates a Solidity `token.approve(spender, value)` call, 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 spender The spender of the tokens
     * @param value The amount of token to transfer
     * @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
     */
    function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
        bytes4 selector = IERC20.approve.selector;

        assembly ("memory-safe") {
            let fmp := mload(0x40)
            mstore(0x00, selector)
            mstore(0x04, and(spender, shr(96, not(0))))
            mstore(0x24, value)
            success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
            // if call success and return is true, all is good.
            // otherwise (not success or return is not true), we need to perform further checks
            if iszero(and(success, eq(mload(0x00), 1))) {
                // if the call was a failure and bubble is enabled, bubble the error
                if and(iszero(success), bubble) {
                    returndatacopy(fmp, 0x00, returndatasize())
                    revert(fmp, returndatasize())
                }
                // if the return value is not true, then the call is only successful if:
                // - the token address has code
                // - the returndata is empty
                success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
            }
            mstore(0x40, fmp)
        }
    }
}
ReentrancyGuard.sol 119 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 *
 * IMPORTANT: Deprecated. This storage-based reentrancy guard will be removed and replaced
 * by the {ReentrancyGuardTransient} variant in v6.0.
 *
 * @custom:stateless
 */
abstract contract ReentrancyGuard {
    using StorageSlot for bytes32;

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant REENTRANCY_GUARD_STORAGE =
        0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    /**
     * @dev A `view` only version of {nonReentrant}. Use to block view functions
     * from being called, preventing reading from inconsistent contract state.
     *
     * CAUTION: This is a "view" modifier and does not change the reentrancy
     * status. Use it only on view functions. For payable or non-payable functions,
     * use the standard {nonReentrant} modifier instead.
     */
    modifier nonReentrantView() {
        _nonReentrantBeforeView();
        _;
    }

    function _nonReentrantBeforeView() private view {
        if (_reentrancyGuardEntered()) {
            revert ReentrancyGuardReentrantCall();
        }
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        _nonReentrantBeforeView();

        // Any calls to nonReentrant after this point will fail
        _reentrancyGuardStorageSlot().getUint256Slot().value = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _reentrancyGuardStorageSlot().getUint256Slot().value = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _reentrancyGuardStorageSlot().getUint256Slot().value == ENTERED;
    }

    function _reentrancyGuardStorageSlot() internal pure virtual returns (bytes32) {
        return REENTRANCY_GUARD_STORAGE;
    }
}
StorageSlot.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC-1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * TIP: Consider using this library along with {SlotDerivation}.
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct Int256Slot {
        int256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Int256Slot` with member `value` located at `slot`.
     */
    function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns a `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
RewardsModule.sol 195 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {IAutopilotVault} from "./interfaces/IAutopilotVault.sol";

/// @title RewardsModule
/// @notice Manages reward token claims, swaps, and auto-compounding into the vault.
///         Receives reward tokens from strategies during harvest. Claims merkle-based
///         rewards via whitelisted executeClaim. Swaps to base asset via whitelisted
///         DEX routers. Sweeps base asset back to vault via depositRewards().
/// @dev Security boundary: can ONLY send base asset to the vault. Even if fully
///      compromised, user deposits are safe -- only reward tokens at risk.
contract RewardsModule is ReentrancyGuard {
    using SafeERC20 for IERC20;

    // --- Immutables ---

    address public immutable vault;
    address public immutable baseAsset;

    // --- State ---

    address public admin;
    address public keeper;

    // Claims Executor: target address => function selector => allowed
    mapping(address => mapping(bytes4 => bool)) public claimWhitelist;

    // Swap Engine: router address => allowed
    mapping(address => bool) public allowedRouters;

    // --- Events ---

    event ClaimExecuted(address indexed target, bytes4 indexed selector);
    event Swapped(
        address indexed router, address indexed tokenIn, address indexed tokenOut, uint256 amountIn, uint256 amountOut
    );
    event SweptToVault(uint256 amount);
    event ClaimWhitelistUpdated(address indexed target, bytes4 indexed selector, bool allowed);
    event RouterWhitelistUpdated(address indexed router, bool allowed);
    event AdminTransferred(address indexed previousAdmin, address indexed newAdmin);
    event KeeperUpdated(address indexed previousKeeper, address indexed newKeeper);
    event TokenRescued(address indexed token, address indexed to, uint256 amount);

    // --- Errors ---

    error NotAdmin();
    error NotAdminOrKeeper();
    error ZeroAddress();
    error TargetNotWhitelisted();
    error RouterNotWhitelisted();
    error InvalidTokenOut();
    error SlippageExceeded();
    error ClaimFailed();
    error NothingToSweep();
    error CannotRescueBaseAsset();
    error CannotSwapBaseAsset();
    error SwapCallFailed();

    // --- Modifiers ---

    modifier onlyAdmin() {
        if (msg.sender != admin) revert NotAdmin();
        _;
    }

    modifier onlyAdminOrKeeper() {
        if (msg.sender != admin && msg.sender != keeper) revert NotAdminOrKeeper();
        _;
    }

    // --- Constructor ---

    constructor(address vault_, address admin_) {
        if (vault_ == address(0) || admin_ == address(0)) revert ZeroAddress();
        vault = vault_;
        baseAsset = IAutopilotVault(vault_).asset();
        admin = admin_;
    }

    // =========================================================================
    // Claims Executor
    // =========================================================================

    /// @notice Execute a claim call on a whitelisted target.
    ///         Used for merkle claims (Morpho URD, Merkl), airdrops, etc.
    /// @param target The contract to call
    /// @param data The calldata (must match a whitelisted selector)
    function executeClaim(address target, bytes calldata data) external onlyAdminOrKeeper nonReentrant {
        if (data.length < 4) revert TargetNotWhitelisted();
        bytes4 selector = bytes4(data[:4]);
        if (!claimWhitelist[target][selector]) revert TargetNotWhitelisted();

        (bool success,) = target.call(data);
        if (!success) revert ClaimFailed();

        emit ClaimExecuted(target, selector);
    }

    /// @notice Add or remove a target+selector pair from the claims whitelist
    function setClaimWhitelist(address target, bytes4 selector, bool allowed) external onlyAdmin {
        claimWhitelist[target][selector] = allowed;
        emit ClaimWhitelistUpdated(target, selector, allowed);
    }

    // =========================================================================
    // Swap Engine
    // =========================================================================

    /// @notice Swap reward tokens to the vault's base asset via a whitelisted router.
    /// @param router The DEX aggregator router (must be whitelisted)
    /// @param tokenIn The reward token to sell
    /// @param tokenOut Must be baseAsset (enforced)
    /// @param amountIn Amount of tokenIn to swap
    /// @param minAmountOut Minimum output (slippage protection)
    /// @param routerData Encoded swap calldata for the router
    function swap(
        address router,
        address tokenIn,
        address tokenOut,
        uint256 amountIn,
        uint256 minAmountOut,
        bytes calldata routerData
    ) external onlyAdminOrKeeper nonReentrant {
        if (!allowedRouters[router]) revert RouterNotWhitelisted();
        if (tokenOut != baseAsset) revert InvalidTokenOut();
        if (tokenIn == baseAsset) revert CannotSwapBaseAsset();

        IERC20(tokenIn).forceApprove(router, amountIn);

        uint256 balanceBefore = IERC20(baseAsset).balanceOf(address(this));

        (bool success,) = router.call(routerData);
        if (!success) revert SwapCallFailed();

        uint256 balanceAfter = IERC20(baseAsset).balanceOf(address(this));
        uint256 amountOut = balanceAfter - balanceBefore;

        if (amountOut < minAmountOut) revert SlippageExceeded();

        // Reset approval for safety
        IERC20(tokenIn).forceApprove(router, 0);

        emit Swapped(router, tokenIn, tokenOut, amountIn, amountOut);
    }

    /// @notice Add or remove a router from the swap whitelist
    function setRouterWhitelist(address router, bool allowed) external onlyAdmin {
        allowedRouters[router] = allowed;
        emit RouterWhitelistUpdated(router, allowed);
    }

    // =========================================================================
    // Sweep to Vault
    // =========================================================================

    /// @notice Send all base asset balance to the vault via depositRewards().
    ///         This is the ONLY way assets leave this contract to the vault.
    function sweepToVault() external onlyAdminOrKeeper nonReentrant {
        uint256 balance = IERC20(baseAsset).balanceOf(address(this));
        if (balance == 0) revert NothingToSweep();

        IERC20(baseAsset).forceApprove(vault, balance);
        IAutopilotVault(vault).depositRewards(balance);

        emit SweptToVault(balance);
    }

    // =========================================================================
    // Admin
    // =========================================================================

    function transferAdmin(address newAdmin) external onlyAdmin {
        if (newAdmin == address(0)) revert ZeroAddress();
        emit AdminTransferred(admin, newAdmin);
        admin = newAdmin;
    }

    function setKeeper(address newKeeper) external onlyAdmin {
        emit KeeperUpdated(keeper, newKeeper);
        keeper = newKeeper;
    }

    /// @notice Rescue stuck tokens (e.g., tokens sent accidentally).
    ///         Cannot rescue the base asset -- that goes through sweepToVault().
    function rescueToken(address token, address to, uint256 amount) external onlyAdmin {
        if (token == baseAsset) revert CannotRescueBaseAsset();
        if (to == address(0)) revert ZeroAddress();
        IERC20(token).safeTransfer(to, amount);
        emit TokenRescued(token, to, amount);
    }
}
IAutopilotVault.sol 9 lines
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

/// @title IAutopilotVault
/// @notice Minimal interface for RewardsModule to interact with the vault.
interface IAutopilotVault {
    function asset() external view returns (address);
    function depositRewards(uint256 amount) external;
}

Read Contract

admin 0xf851a440 → address
allowedRouters 0xc646aee2 → bool
baseAsset 0xcdf456e1 → address
claimWhitelist 0x0576e753 → bool
keeper 0xaced1661 → address
vault 0xfbfa77cf → address

Write Contract 8 functions

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

executeClaim 0x91cab88f
address target
bytes data
rescueToken 0xe5711e8b
address token
address to
uint256 amount
setClaimWhitelist 0x3a2b4a89
address target
bytes4 selector
bool allowed
setKeeper 0x748747e6
address newKeeper
setRouterWhitelist 0x7b224339
address router
bool allowed
swap 0xa5d4096b
address router
address tokenIn
address tokenOut
uint256 amountIn
uint256 minAmountOut
bytes routerData
sweepToVault 0x5487e943
No parameters
transferAdmin 0x75829def
address newAdmin

Recent Transactions

No transactions found for this address