Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x4BD57f97E35E7c3302Dc3A8d4d803826856F9f32
Balance 0 ETH
Nonce 1
Code Size 6570 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6570 bytes
0x608060405234801561001057600080fd5b50600436106101f05760003560e01c80637bb7bed11161010f578063a893c9be116100a2578063d547741f11610071578063d547741f14610421578063d73792a914610434578063e941fa781461043e578063f12b59c91461044757600080fd5b8063a893c9be146103da578063afffd5b7146103ed578063bc063e1a14610405578063ca54be3b1461040e57600080fd5b806391d14854116100de57806391d14854146103a357806396d53eb8146103b657806399ec9246146103c9578063a217fddf146103d257600080fd5b80637bb7bed1146103605780637ceaf92f1461037357806382aefa24146103865780638456cb591461039b57600080fd5b806336568abe1161018757806352d0b7681161015657806352d0b768146103155780635c975abb14610328578063686f6b511461033357806375451b4f1461034657600080fd5b806336568abe146102e9578063372500ab146102fc5780633a8051ac146103045780633f4ba83a1461030d57600080fd5b8063201e81a8116101c3578063201e81a81461027c578063248a9ca3146102915780632d62af2f146102c35780632f2ff15d146102d657600080fd5b806301ffc9a7146101f55780630cca87491461021d5780630d43e8ad1461022a57806316f0115b14610255575b600080fd5b61020861020336600461140d565b61045a565b60405190151581526020015b60405180910390f35b6006546102089060ff1681565b60085461023d906001600160a01b031681565b6040516001600160a01b039091168152602001610214565b61023d7f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f222281565b61028f61028a3660046114bc565b610491565b005b6102b561029f36600461156e565b6000908152600160208190526040909120015490565b604051908152602001610214565b6102b56102d13660046115d7565b6104a9565b61028f6102e436600461160f565b610677565b61028f6102f736600461160f565b6106a3565b61028f6106db565b6102b560055481565b61028f610711565b61028f61032336600461156e565b610727565b60005460ff16610208565b61028f61034136600461156e565b610810565b61034e600581565b60405160ff9091168152602001610214565b61023d61036e36600461156e565b6108f1565b61028f610381366004611642565b61091b565b6102b560008051602061195583398151915281565b61028f61096d565b6102086103b136600461160f565b610980565b61028f6103c436600461165f565b6109ab565b6102b560045481565b6102b5600081565b61028f6103e836600461156e565b610a52565b60065461023d9061010090046001600160a01b031681565b6102b561c35081565b61028f61041c36600461167c565b610ab5565b61028f61042f36600461160f565b610b31565b6102b5620f424081565b6102b560075481565b61028f61045536600461165f565b610b57565b60006001600160e01b03198216637965db0b60e01b148061048b57506301ffc9a760e01b6001600160e01b03198316145b92915050565b600061049c81610bd7565b6104a582610be1565b5050565b60006104b3610cb7565b6104bb610cdb565b60065460ff1680156104e257506104e060008051602061195583398151915233610980565b155b15610500576040516355b51ef160e01b815260040160405180910390fd5b6001600160a01b038216610512573391505b60007f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f22226001600160a01b0316639d63848a6040518163ffffffff1660e01b815260040160a060405180830381865afa158015610572573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061059691906116bd565b905060005b600581101561065f5760008282600581106105b8576105b861171b565b602002015190506001600160a01b038116158015906105ed575060008683600581106105e6576105e661171b565b6020020151115b1561065657610656337f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f22228885600581106106295761062961171b565b60200201518686600581106106405761064061171b565b60200201516001600160a01b0316929190610d03565b5060010161059b565b5061066a8484610d6a565b91505061048b6001600255565b6000828152600160208190526040909120015461069381610bd7565b61069d8383610d7d565b50505050565b6001600160a01b03811633146106cc5760405163334bd91960e11b815260040160405180910390fd5b6106d68282610df6565b505050565b6106e3610cb7565b6106eb610cdb565b6006546107059061010090046001600160a01b0316610e63565b61070f6001600255565b565b600061071c81610bd7565b610724610ee7565b50565b600061073281610bd7565b7f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f22226001600160a01b03166322068b446040518163ffffffff1660e01b8152600401602060405180830381865afa158015610790573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107b49190611731565b82106107d357604051634dd76a3360e01b815260040160405180910390fd5b60058290556040518281527f1263b39fe165b48c204de3a3d752e6c7a129670cbe325757bdf76562664ef8d1906020015b60405180910390a15050565b600061081b81610bd7565b7f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f22226001600160a01b03166322068b446040518163ffffffff1660e01b8152600401602060405180830381865afa158015610879573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089d9190611731565b82106108bc57604051634dd76a3360e01b815260040160405180910390fd5b60048290556040518281527fdefccea87e6a6ac5c177a3e0318456cf032572ae03a96d9f44c4664a92999aef90602001610804565b6003818154811061090157600080fd5b6000918252602090912001546001600160a01b0316905081565b600061092681610bd7565b6006805460ff191683151590811790915560405160ff909116151581527fa3a2d1c4db55b0d5a8a9528000a005a3a576034e16abc47815aecff96fa3d90390602001610804565b600061097881610bd7565b610724610f39565b60009182526001602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60006109b681610bd7565b6001600160a01b0382166109dd5760405163d92e233d60e01b815260040160405180910390fd5b600654604080516001600160a01b036101009093048316815291841660208301527f83ebbd31e22910c696bcf3b247e11e635c0204f0c6dc527dae30aa58a076af13910160405180910390a150600680546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b6000610a5d81610bd7565b61c350821115610a805760405163185da2c160e01b815260040160405180910390fd5b60078290556040518281527fef51b055f1ac1490e0c230364c65b0a9eca534656954023b56053b78461678e490602001610804565b610abd610cb7565b610ac5610cdb565b60065460ff168015610aec5750610aea60008051602061195583398151915233610980565b155b15610b0a576040516355b51ef160e01b815260040160405180910390fd5b6001600160a01b038116610b1b5750335b610b2733848484610f76565b6106d66001600255565b60008281526001602081905260409091200154610b4d81610bd7565b61069d8383610df6565b6000610b6281610bd7565b6001600160a01b038216610b895760405163d92e233d60e01b815260040160405180910390fd5b600880546001600160a01b0319166001600160a01b0384169081179091556040519081527fae5a12c29e496b092467a620746b9eaf4e0e231a631a4370c233b1fac38e8e2690602001610804565b610724813361102a565b80516000819003610c105781604051630362609760e51b8152600401610c07919061174a565b60405180910390fd5b60005b81811015610c725760006001600160a01b0316838281518110610c3857610c3861171b565b60200260200101516001600160a01b031603610c6a5760405163af7bbf6960e01b815260048101829052602401610c07565b600101610c13565b508151610c86906003906020850190611393565b507f69be44b81d4f8b6cf7825a37f020b264079658f3d72856eeb0a0efed09c7d392600360405161080491906117e1565b60005460ff161561070f5760405163d93c066560e01b815260040160405180910390fd5b6002805403610cfd57604051633ee5aeb560e01b815260040160405180910390fd5b60028055565b6040516001600160a01b03848116602483015283811660448301526064820183905261069d9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050611063565b6000610d7683836110c6565b9392505050565b6000610d898383610980565b610dee5760008381526001602081815260408084206001600160a01b0387168086529252808420805460ff19169093179092559051339286917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a450600161048b565b50600061048b565b6000610e028383610980565b15610dee5760008381526001602090815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a450600161048b565b604051632026ffa360e01b81526001600160a01b037f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f22221690632026ffa390610eb29084906003906004016117f4565b600060405180830381600087803b158015610ecc57600080fd5b505af1158015610ee0573d6000803e3d6000fd5b5050505050565b610eef61115c565b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b610f41610cb7565b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610f1c3390565b610fab6001600160a01b037f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f222216853086610d03565b6000610fb7338561117f565b9050600081118015610fd357506008546001600160a01b031615155b1561101f57600854611012906001600160a01b037f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f222281169116836111d0565b61101c8185611836565b93505b610ee0848484611201565b6110348282610980565b6104a55760405163e2517d3f60e01b81526001600160a01b038216600482015260248101839052604401610c07565b60006110786001600160a01b0384168361128c565b9050805160001415801561109d57508080602001905181019061109b9190611849565b155b156106d657604051635274afe760e01b81526001600160a01b0384166004820152602401610c07565b60048054604051636766ea0f60e01b81526000926001600160a01b037f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f22221692636766ea0f92611119928891889101611889565b6020604051808303816000875af1158015611138573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d769190611731565b60005460ff1661070f57604051638dfc202b60e01b815260040160405180910390fd5b60075460009080158015906111a957506111a760008051602061195583398151915285610980565b155b156111c957620f42406111bc82856118b6565b6111c691906118cd565b91505b5092915050565b6040516001600160a01b038381166024830152604482018390526106d691859182169063a9059cbb90606401610d38565b600554604051632d526f8f60e21b81526001600160a01b037f000000000000000000000000c2e660c62f72c2ad35ace6db78a616215e2f2222169163b549be3c9161125591908790879087906004016118ef565b600060405180830381600087803b15801561126f57600080fd5b505af1158015611283573d6000803e3d6000fd5b50505050505050565b6060610d768383600084600080856001600160a01b031684866040516112b29190611925565b60006040518083038185875af1925050503d80600081146112ef576040519150601f19603f3d011682016040523d82523d6000602084013e6112f4565b606091505b509150915061130486838361130e565b9695505050505050565b6060826113235761131e8261136a565b610d76565b815115801561133a57506001600160a01b0384163b155b1561136357604051639996b31560e01b81526001600160a01b0385166004820152602401610c07565b5080610d76565b80511561137a5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b8280548282559060005260206000209081019282156113e8579160200282015b828111156113e857825182546001600160a01b0319166001600160a01b039091161782556020909201916001909101906113b3565b506113f49291506113f8565b5090565b5b808211156113f457600081556001016113f9565b60006020828403121561141f57600080fd5b81356001600160e01b031981168114610d7657600080fd5b634e487b7160e01b600052604160045260246000fd5b60405160a0810167ffffffffffffffff8111828210171561147057611470611437565b60405290565b604051601f8201601f1916810167ffffffffffffffff8111828210171561149f5761149f611437565b604052919050565b6001600160a01b038116811461072457600080fd5b600060208083850312156114cf57600080fd5b823567ffffffffffffffff808211156114e757600080fd5b818501915085601f8301126114fb57600080fd5b81358181111561150d5761150d611437565b8060051b915061151e848301611476565b818152918301840191848101908884111561153857600080fd5b938501935b838510156115625784359250611552836114a7565b828252938501939085019061153d565b98975050505050505050565b60006020828403121561158057600080fd5b5035919050565b600082601f83011261159857600080fd5b6115a061144d565b8060a08401858111156115b257600080fd5b845b818110156115cc5780358452602093840193016115b4565b509095945050505050565b60008060c083850312156115ea57600080fd5b6115f48484611587565b915060a0830135611604816114a7565b809150509250929050565b6000806040838503121561162257600080fd5b823591506020830135611604816114a7565b801515811461072457600080fd5b60006020828403121561165457600080fd5b8135610d7681611634565b60006020828403121561167157600080fd5b8135610d76816114a7565b600080600060e0848603121561169157600080fd5b833592506116a28560208601611587565b915060c08401356116b2816114a7565b809150509250925092565b600060a082840312156116cf57600080fd5b82601f8301126116de57600080fd5b6116e661144d565b8060a08401858111156116f857600080fd5b845b818110156115cc57805161170d816114a7565b8452602093840193016116fa565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561174357600080fd5b5051919050565b6020808252825182820181905260009190848201906040850190845b8181101561178b5783516001600160a01b031683529284019291840191600101611766565b50909695505050505050565b600081548084526020808501945083600052602060002060005b838110156117d65781546001600160a01b0316875295820195600191820191016117b1565b509495945050505050565b602081526000610d766020830184611797565b6001600160a01b038316815260406020820181905260009061181890830184611797565b949350505050565b634e487b7160e01b600052601160045260246000fd5b8181038181111561048b5761048b611820565b60006020828403121561185b57600080fd5b8151610d7681611634565b8060005b600581101561069d57815184526020938401939091019060010161186a565b83815260e0810161189d6020830185611866565b6001600160a01b039290921660c0919091015292915050565b808202811582820484141761048b5761048b611820565b6000826118ea57634e487b7160e01b600052601260045260246000fd5b500490565b84815260208101849052610100810161190b6040830185611866565b6001600160a01b039290921660e091909101529392505050565b6000825160005b81811015611946576020818601810151858301520161192c565b50600092019182525091905056fe114e74f6ea3bd819998f78687bfcb11b140da08e9b7d222fa9c1f1ba1f2aa122a264697066735822122089b732d10a074fd101ad15e3f983ae28a36eb20ab21074da3d922d37649ce14464736f6c63430008170033

Verified Source Code Full Match

Compiler: v0.8.23+commit.f704f362 EVM: paris Optimization: Yes (200 runs)
AccessControl.sol 209 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)

pragma solidity ^0.8.20;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```solidity
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```solidity
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
 * to enforce additional security measures for this role.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address account => bool) hasRole;
        bytes32 adminRole;
    }

    mapping(bytes32 role => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with an {AccessControlUnauthorizedAccount} error including the required role.
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual returns (bool) {
        return _roles[role].hasRole[account];
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
     * is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
     * is missing `role`.
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert AccessControlUnauthorizedAccount(account, role);
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address callerConfirmation) public virtual {
        if (callerConfirmation != _msgSender()) {
            revert AccessControlBadConfirmation();
        }

        _revokeRole(role, callerConfirmation);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
        if (!hasRole(role, account)) {
            _roles[role].hasRole[account] = true;
            emit RoleGranted(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
        if (hasRole(role, account)) {
            _roles[role].hasRole[account] = false;
            emit RoleRevoked(role, account, _msgSender());
            return true;
        } else {
            return false;
        }
    }
}
IAccessControl.sol 98 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)

pragma solidity ^0.8.20;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev The `account` is missing a role.
     */
    error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);

    /**
     * @dev The caller of a function is not the expected one.
     *
     * NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
     */
    error AccessControlBadConfirmation();

    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `callerConfirmation`.
     */
    function renounceRole(bytes32 role, address callerConfirmation) external;
}
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;
    }
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

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

pragma solidity ^0.8.20;

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

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    bool private _paused;

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @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 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].
 */
abstract contract ReentrancyGuard {
    // 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;

    uint256 private _status;

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

    constructor() {
        _status = 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();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = 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 _status == ENTERED;
    }
}
ZunamiPoolControllerZunETH.sol 8 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import '../../ZunamiPoolThroughRedemptionFeeController.sol';

contract ZunamiPoolControllerZunETH is ZunamiPoolThroughRedemptionFeeController {
    constructor(address pool) ZunamiPoolThroughRedemptionFeeController(pool) {}
}
IPool.sol 84 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

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

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

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

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

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

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

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

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

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

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

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

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

    function totalHoldings() external view returns (uint256);

    function strategyCount() external view returns (uint256);

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

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

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

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

interface IRewardManager {
    function handle(address reward, uint256 amount, address feeToken) external;

    function valuate(
        address reward,
        uint256 amount,
        address feeToken
    ) external view returns (uint256);
}
IStrategy.sol 25 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

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

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

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

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

    function totalHoldings() external view returns (uint256);

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

    function calcTokenAmount(
        uint256[5] memory tokenAmounts,
        bool isDeposit
    ) external view returns (uint256 sharesAmount);
}
RewardTokenManager.sol 105 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import './interfaces/IRewardManager.sol';

abstract contract RewardTokenManager {
    using SafeERC20 for IERC20;

    error WrongRewardTokens(IERC20[] rewardTokens);
    error WrongRewardTokensLength(uint256 length);
    error ZeroRewardManager();
    error ZeroTokenAddress(uint256 index);

    IERC20[] public rewardTokens;

    event SetRewardTokens(IERC20[] rewardTokens);

    function _setRewardTokens(IERC20[] memory rewardTokens_) internal virtual {
        uint256 rewardsLength_ = rewardTokens_.length;
        if (rewardsLength_ == 0) revert WrongRewardTokens(rewardTokens_);

        for (uint256 i = 0; i < rewardsLength_; ++i) {
            if (address(rewardTokens_[i]) == address(0)) revert ZeroTokenAddress(i);
        }

        rewardTokens = rewardTokens_;
        emit SetRewardTokens(rewardTokens);
    }

    function _sellRewardsAll(
        IRewardManager rewardManager,
        IERC20 feeToken,
        uint256 rewardTokenFrozen
    ) internal returns (uint256) {
        if (address(rewardManager) == address(0)) revert ZeroRewardManager();

        uint256 rewardsLength_ = rewardTokens.length;
        uint256[] memory rewardBalances = new uint256[](rewardsLength_);
        bool allRewardsEmpty = true;

        for (uint256 i = 0; i < rewardsLength_; ++i) {
            IERC20 rewardToken = rewardTokens[i];
            rewardBalances[i] = rewardToken.balanceOf(address(this));
            if (feeToken == rewardToken) {
                rewardBalances[i] -= rewardTokenFrozen;
            }
            if (rewardBalances[i] > 0) {
                allRewardsEmpty = false;
            }
        }
        if (allRewardsEmpty) {
            return 0;
        }

        return _sellRewards(rewardManager, rewardsLength_, feeToken, rewardBalances);
    }

    function _sellRewardsByAmounts(
        IRewardManager rewardManager,
        IERC20 feeToken,
        uint256[] memory rewardAmounts
    ) internal returns (uint256) {
        if (address(rewardManager) == address(0)) revert ZeroRewardManager();
        uint256 rewardsLength_ = rewardTokens.length;
        if (rewardsLength_ != rewardAmounts.length) revert WrongRewardTokensLength(rewardsLength_);

        return _sellRewards(rewardManager, rewardsLength_, feeToken, rewardAmounts);
    }

    function _sellRewards(
        IRewardManager rewardManager,
        uint256 rewardsLength,
        IERC20 feeToken,
        uint256[] memory rewardAmounts
    ) private returns (uint256) {
        uint256 feeTokenBalanceBefore = feeToken.balanceOf(address(this));

        IERC20 rewardToken_;
        for (uint256 i = 0; i < rewardsLength; ++i) {
            if (rewardAmounts[i] == 0) continue;
            rewardToken_ = rewardTokens[i];
            //don't sell fee token itself as reward
            if (rewardToken_ == feeToken) {
                //reduce current fee token balance by it's reward balance
                feeTokenBalanceBefore -= rewardAmounts[i];
                continue;
            }
            _sellToken(rewardManager, rewardToken_, rewardAmounts[i], address(feeToken));
        }

        return feeToken.balanceOf(address(this)) - feeTokenBalanceBefore;
    }

    function _sellToken(
        IRewardManager rewardManager,
        IERC20 sellingToken,
        uint256 sellingTokenAmount,
        address receivedToken
    ) internal {
        sellingToken.safeTransfer(address(rewardManager), sellingTokenAmount);
        rewardManager.handle(address(sellingToken), sellingTokenAmount, receivedToken);
    }
}
ZunamiPoolControllerBase.sol 143 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@openzeppelin/contracts/utils/Pausable.sol';
import '@openzeppelin/contracts/access/AccessControl.sol';
import '@openzeppelin/contracts/utils/ReentrancyGuard.sol';

import './interfaces/IPool.sol';
import './RewardTokenManager.sol';

abstract contract ZunamiPoolControllerBase is
    Pausable,
    AccessControl,
    ReentrancyGuard,
    RewardTokenManager
{
    using SafeERC20 for IERC20;

    error OnlyIssuer();
    error ZeroAddress();
    error WrongSid();

    bytes32 public constant ISSUER_ROLE = keccak256('ISSUER_ROLE');
    uint8 public constant POOL_ASSETS = 5;

    uint256 public defaultDepositSid;
    uint256 public defaultWithdrawSid;

    bool public onlyIssuerMode = false;

    IPool public immutable pool;

    event SetDefaultDepositSid(uint256 sid);
    event SetDefaultWithdrawSid(uint256 sid);
    event RewardCollectorChanged(address oldRewardCollector, address newRewardCollector);
    event SetOnlyIssuerMode(bool onlyIssuerMode);

    modifier onlyIssuance() {
        if (onlyIssuerMode && !hasRole(ISSUER_ROLE, msg.sender)) revert OnlyIssuer();
        _;
    }

    constructor(address pool_) {
        if (pool_ == address(0)) revert ZeroAddress();
        pool = IPool(pool_);

        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
    }

    function setOnlyIssuerMode(bool _onlyIssuerMode) external onlyRole(DEFAULT_ADMIN_ROLE) {
        onlyIssuerMode = _onlyIssuerMode;
        emit SetOnlyIssuerMode(onlyIssuerMode);
    }

    function setRewardTokens(IERC20[] memory rewardTokens_) external onlyRole(DEFAULT_ADMIN_ROLE) {
        _setRewardTokens(rewardTokens_);
    }

    function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {
        _pause();
    }

    function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
        _unpause();
    }

    function setDefaultDepositSid(uint256 _newPoolId) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (_newPoolId >= pool.strategyCount()) revert WrongSid();

        defaultDepositSid = _newPoolId;
        emit SetDefaultDepositSid(_newPoolId);
    }

    function setDefaultWithdrawSid(uint256 _newPoolId) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (_newPoolId >= pool.strategyCount()) revert WrongSid();

        defaultWithdrawSid = _newPoolId;
        emit SetDefaultWithdrawSid(_newPoolId);
    }

    function claimPoolRewards(address collector) internal {
        pool.claimRewards(collector, rewardTokens);
    }

    function deposit(
        uint256[POOL_ASSETS] memory amounts,
        address receiver
    ) external whenNotPaused nonReentrant onlyIssuance returns (uint256 shares) {
        if (receiver == address(0)) {
            receiver = msg.sender;
        }

        IERC20[POOL_ASSETS] memory tokens = pool.tokens();
        for (uint256 i = 0; i < POOL_ASSETS; ++i) {
            IERC20 token = tokens[i];
            if (address(token) != address(0) && amounts[i] > 0) {
                tokens[i].safeTransferFrom(msg.sender, address(pool), amounts[i]);
            }
        }

        return depositPool(amounts, receiver);
    }

    function depositPool(
        uint256[POOL_ASSETS] memory amounts,
        address receiver
    ) internal virtual returns (uint256);

    function depositDefaultPool(
        uint256[POOL_ASSETS] memory amounts,
        address receiver
    ) internal returns (uint256) {
        return pool.deposit(defaultDepositSid, amounts, receiver);
    }

    function withdraw(
        uint256 shares,
        uint256[POOL_ASSETS] memory minTokenAmounts,
        address receiver
    ) external whenNotPaused nonReentrant onlyIssuance {
        if (receiver == address(0)) {
            receiver = msg.sender;
        }
        withdrawPool(msg.sender, shares, minTokenAmounts, receiver);
    }

    function withdrawDefaultPool(
        uint256 shares,
        uint256[POOL_ASSETS] memory minTokenAmounts,
        address receiver
    ) internal virtual {
        pool.withdraw(defaultWithdrawSid, shares, minTokenAmounts, receiver);
    }

    function withdrawPool(
        address user,
        uint256 shares,
        uint256[POOL_ASSETS] memory minTokenAmounts,
        address receiver
    ) internal virtual;
}
ZunamiPoolThroughController.sol 44 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

import './ZunamiPoolControllerBase.sol';

contract ZunamiPoolThroughController is ZunamiPoolControllerBase {
    using SafeERC20 for IERC20;

    address public rewardCollector;

    constructor(address pool_) ZunamiPoolControllerBase(pool_) {
        rewardCollector = msg.sender;
    }

    function changeRewardCollector(address _rewardCollector) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (_rewardCollector == address(0)) revert ZeroAddress();
        emit RewardCollectorChanged(rewardCollector, _rewardCollector);
        rewardCollector = _rewardCollector;
    }

    function claimRewards() external whenNotPaused nonReentrant {
        claimPoolRewards(rewardCollector);
    }

    function depositPool(
        uint256[POOL_ASSETS] memory amounts,
        address receiver
    ) internal virtual override returns (uint256) {
        return depositDefaultPool(amounts, receiver);
    }

    function withdrawPool(
        address user,
        uint256 shares,
        uint256[POOL_ASSETS] memory minTokenAmounts,
        address receiver
    ) internal virtual override {
        IERC20(address(pool)).safeTransferFrom(user, address(this), shares);
        withdrawDefaultPool(shares, minTokenAmounts, receiver);
    }
}
ZunamiPoolThroughRedemptionFeeController.sol 62 lines
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

import './ZunamiPoolThroughController.sol';

contract ZunamiPoolThroughRedemptionFeeController is ZunamiPoolThroughController {
    using SafeERC20 for IERC20;

    error FeeWronglyHigh();

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

    uint256 public withdrawFee;
    address public feeDistributor;

    event WithdrawFeeChanged(uint256 withdrawFee);
    event FeeDistributorChanged(address feeDistributor);

    constructor(address pool_) ZunamiPoolThroughController(pool_) {}

    function changeWithdrawFee(uint256 withdrawFee_) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (withdrawFee_ > MAX_FEE) revert FeeWronglyHigh();
        withdrawFee = withdrawFee_;

        emit WithdrawFeeChanged(withdrawFee_);
    }

    function changeFeeDistributor(address feeDistributor_) external onlyRole(DEFAULT_ADMIN_ROLE) {
        if (feeDistributor_ == address(0)) revert ZeroAddress();
        feeDistributor = feeDistributor_;

        emit FeeDistributorChanged(feeDistributor_);
    }

    function withdrawPool(
        address user,
        uint256 shares,
        uint256[POOL_ASSETS] memory minTokenAmounts,
        address receiver
    ) internal virtual override {
        IERC20(address(pool)).safeTransferFrom(user, address(this), shares);

        uint256 nominalFee = _calcFee(msg.sender, shares);
        if (nominalFee > 0 && feeDistributor != address(0)) {
            IERC20(address(pool)).safeTransfer(feeDistributor, nominalFee);
            shares -= nominalFee;
        }

        withdrawDefaultPool(shares, minTokenAmounts, receiver);
    }

    function _calcFee(address caller, uint256 value) internal view returns (uint256 nominalFee) {
        uint256 withdrawFee_ = withdrawFee;
        if (withdrawFee_ > 0 && !hasRole(ISSUER_ROLE, caller)) {
            nominalFee = (value * withdrawFee_) / FEE_DENOMINATOR;
        }
    }
}

Read Contract

DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
FEE_DENOMINATOR 0xd73792a9 → uint256
ISSUER_ROLE 0x82aefa24 → bytes32
MAX_FEE 0xbc063e1a → uint256
POOL_ASSETS 0x75451b4f → uint8
defaultDepositSid 0x99ec9246 → uint256
defaultWithdrawSid 0x3a8051ac → uint256
feeDistributor 0x0d43e8ad → address
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
onlyIssuerMode 0x0cca8749 → bool
paused 0x5c975abb → bool
pool 0x16f0115b → address
rewardCollector 0xafffd5b7 → address
rewardTokens 0x7bb7bed1 → address
supportsInterface 0x01ffc9a7 → bool
withdrawFee 0xe941fa78 → uint256

Write Contract 15 functions

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

changeFeeDistributor 0xf12b59c9
address feeDistributor_
changeRewardCollector 0x96d53eb8
address _rewardCollector
changeWithdrawFee 0xa893c9be
uint256 withdrawFee_
claimRewards 0x372500ab
No parameters
deposit 0x2d62af2f
uint256[5] amounts
address receiver
returns: uint256
grantRole 0x2f2ff15d
bytes32 role
address account
pause 0x8456cb59
No parameters
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeRole 0xd547741f
bytes32 role
address account
setDefaultDepositSid 0x686f6b51
uint256 _newPoolId
setDefaultWithdrawSid 0x52d0b768
uint256 _newPoolId
setOnlyIssuerMode 0x7ceaf92f
bool _onlyIssuerMode
setRewardTokens 0x201e81a8
address[] rewardTokens_
unpause 0x3f4ba83a
No parameters
withdraw 0xca54be3b
uint256 shares
uint256[5] minTokenAmounts
address receiver

Recent Transactions

No transactions found for this address