Cryo Explorer Ethereum Mainnet

Address Contract Partially Verified

Address 0xB226c52EB411326CdB54824a88aBaFDAAfF16D3d
Balance 0 ETH
Nonce 1
Code Size 5405 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

5405 bytes
0x608060405234801561000f575f80fd5b506004361061016d575f3560e01c80637e9c3626116100d9578063aaf5eb6811610093578063d1118dee1161006e578063d1118dee146103d8578063ddaa26ad146103eb578063ddeae03314610412578063f7c618c114610425575f80fd5b8063aaf5eb681461039f578063be960fda146103b2578063c09f3457146103c5575f80fd5b80637e9c3626146102d5578063874d6d81146102fd57806391c17197146103055780639dd1947314610318578063a583024b1461032b578063a7310b581461033e575f80fd5b80634e71d92d1161012a5780634e71d92d146102425780635ebaf1db1461024a5780635fe6b01014610289578063610ae1211461029c57806364607a53146102af5780636db369ca146102c2575f80fd5b80630e057047146101715780631e2720ff146101ab57806337381f42146101c05780633bb959ce146101df5780633f43ae691461021c57806345fc1da11461022f575b5f80fd5b6101987f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020015b60405180910390f35b6101be6101b936600461121c565b61044c565b005b6101986101ce36600461121c565b5f6020819052908152604090205481565b61020c6101ed36600461124e565b600260209081525f928352604080842090915290825290205460ff1681565b60405190151581526020016101a2565b61019861022a36600461121c565b6104f4565b61019861023d36600461127f565b610660565b6101986106c1565b6102717f000000000000000000000000e9a115b77a1057c918f997c32663fdce24fb873f81565b6040516001600160a01b0390911681526020016101a2565b6101986102973660046112af565b6106f8565b6101986102aa36600461127f565b6107a5565b6101be6102bd3660046112e4565b6107da565b6101986102d03660046112af565b61083e565b6102e86102e3366004611319565b6109ba565b604080519283526020830191909152016101a2565b610198610ad8565b61019861031336600461121c565b610b16565b610198610326366004611332565b610b5a565b610198610339366004611319565b610b66565b61037861034c366004611319565b60016020525f90815260409020546001600160a01b03811690600160a01b90046001600160601b031682565b604080516001600160a01b0390931683526001600160601b039091166020830152016101a2565b6101986b033b2e3c9fd0803ce800000081565b6101986103c03660046112af565b610b81565b6101be6103d3366004611319565b610ba1565b61020c6103e636600461121c565b610bf7565b6101987f000000000000000000000000000000000000000000000000000000006660fdc781565b610198610420366004611319565b610c8b565b6102717f000000000000000000000000bf319ddc2edc1eb6fdf9910e39b37be221c8805f81565b80156104f1575f61045b610ad8565b9050815f808381526020019081526020015f205f82825461047c9190611366565b909155506104b790506001600160a01b037f000000000000000000000000bf319ddc2edc1eb6fdf9910e39b37be221c8805f16333085610d04565b604051828152339082907f4e3c672324bfa4c8193ded7cce75b1e608180241cf3d89ca45bc08101f3594b3906020015b60405180910390a3505b50565b60405163259d8a0560e11b8152600481018290525f9081906001600160a01b037f000000000000000000000000e9a115b77a1057c918f997c32663fdce24fb873f1690634b3b140a90602401602060405180830381865afa15801561055b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061057f9190611379565b9050805f0361059057505f92915050565b6001600160a01b037f000000000000000000000000e9a115b77a1057c918f997c32663fdce24fb873f1663e399f29f6105e97f000000000000000000000000000000000000000000000000000000000000000486611366565b6040518263ffffffff1660e01b815260040161060791815260200190565b6040805180830381865afa158015610621573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061064591906113a6565b51610659906001600160701b03168261140b565b9392505050565b5f61066a84610d75565b6106ae5760405162461bcd60e51b815260206004820152601060248201526f10b0b8383937bb32b221b630b4b6b2b960811b60448201526064015b60405180910390fd5b6106b9848484610db3565b949350505050565b5f806106cb610ad8565b905080156106e3576106de60018261140b565b6106e5565b5f5b90506106f2335f83610db3565b91505090565b5f610701610ad8565b82111561073f5760405162461bcd60e51b815260206004820152600c60248201526b496e76616c6964207765656b60a01b60448201526064016106a5565b5f61074a848461083e565b9050805f0361075c575f91505061079f565b5f610766846104f4565b9050805f03610779575f9250505061079f565b806107906b033b2e3c9fd0803ce80000008461141e565b61079a9190611435565b925050505b92915050565b5f806107af610ad8565b90508083106107c6576107c360018261140b565b92505b6107d1858585610f42565b95945050505050565b335f8181526002602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f9f38c81c1e9cacacd0164ea32b7ef77030a477aa51fb25be746c93ee9181887e91016104e7565b60405162ff274760e31b81526001600160a01b038381166004830152602482018390525f9182917f000000000000000000000000e9a115b77a1057c918f997c32663fdce24fb873f16906307f93a3890604401602060405180830381865afa1580156108ac573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108d09190611379565b9050805f036108e2575f91505061079f565b6001600160a01b037f000000000000000000000000e9a115b77a1057c918f997c32663fdce24fb873f166388ba63ba8561093c7f000000000000000000000000000000000000000000000000000000000000000487611366565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016040805180830381865afa158015610982573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109a691906113a6565b516106b9906001600160701b03168261140b565b5f805f6109c5610ad8565b9050805f036109d957505f93849350915050565b6001600160a01b0384165f90815260016020526040812054600160a01b90046001600160601b03167f00000000000000000000000000000000000000000000000000000000000000008110610a2e5780610a50565b7f00000000000000000000000000000000000000000000000000000000000000005b94505b828511610a86575f610a658787610f7a565b1115610a745760019150610a86565b84610a7e81611454565b955050610a53565b81610a9857505f958695509350505050565b610aa360018461140b565b93505b84841115610ad0575f610ab98786610f7a565b11610ad05783610ac88161146c565b945050610aa6565b505050915091565b5f62093a80610b077f000000000000000000000000000000000000000000000000000000006660fdc74261140b565b610b119190611435565b905090565b5f80610b20610ad8565b9050808310610b3157505f92915050565b610b3a836104f4565b15610b4757505f92915050565b50505f9081526020819052604090205490565b5f610659338484610db3565b5f805f610b72846109ba565b915091506106b9848383610f42565b5f610b8a610ad8565b8210610b9757505f61079f565b6106598383610f7a565b335f8181526001602052604080822080546001600160a01b0319166001600160a01b03861690811790915590519092917faa5fe307c4032d125234ac8d9407bec1dd055f9b536fefb4e299a188b2553e7b91a350565b5f80610c01610ad8565b90505f610c0d84610b16565b9050805f03610c1f57505f9392505050565b5f8481526020819052604080822082905583825281208054839290610c45908490611366565b9091555050604051818152829085907f87fed1526492187eb815d549aa57942a31b68987639b4703148b85f5a877a24d9060200160405180910390a35060019392505050565b5f610c9582610d75565b610cd45760405162461bcd60e51b815260206004820152601060248201526f10b0b8383937bb32b221b630b4b6b2b960811b60448201526064016106a5565b5f610cdd610ad8565b90508015610cf557610cf060018261140b565b610cf7565b5f5b9050610659835f83610db3565b6040516001600160a01b0380851660248301528316604482015260648101829052610d6f9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152610fe3565b50505050565b6001600160a01b0381165f90815260026020908152604080832033845290915281205460ff168061079f57506001600160a01b038216331492915050565b5f80610dbd610ad8565b9050808310610dcf575f915050610659565b6001600160a01b0385165f9081526001602052604081208054909190600160a01b90046001600160601b031615610e17578154600160a01b90046001600160601b0316610e39565b7f00000000000000000000000000000000000000000000000000000000000000005b9050610e4581876110bb565b955084861115610e5a575f9350505050610659565b610e65878787610f42565b9350610e72600186611366565b82546001600160a01b0316600160a01b6001600160601b0383160217835594508315610f385781545f906001600160a01b031615610eba5782546001600160a01b0316610ebc565b875b9050610ef26001600160a01b037f000000000000000000000000bf319ddc2edc1eb6fdf9910e39b37be221c8805f1682876110cf565b85886001600160a01b03167fdacbdde355ba930696a362ea6738feb9f8bd52dfb3d81947558fd3217e23e32587604051610f2e91815260200190565b60405180910390a3505b5050509392505050565b5f825b828111610f7257610f568582610f7a565b610f609083611366565b9150610f6b81611454565b9050610f45565b509392505050565b6001600160a01b0382165f90815260016020526040812054600160a01b90046001600160601b0316821015610fb057505f61079f565b5f610fbb84846106f8565b5f848152602081905260409020549091506b033b2e3c9fd0803ce8000000610790828461141e565b5f611037826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166110ff9092919063ffffffff16565b905080515f14806110575750808060200190518101906110579190611481565b6110b65760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016106a5565b505050565b5f8183106110c95782610659565b50919050565b6040516001600160a01b0383166024820152604481018290526110b690849063a9059cbb60e01b90606401610d38565b60606106b984845f85855f80866001600160a01b03168587604051611124919061149c565b5f6040518083038185875af1925050503d805f811461115e576040519150601f19603f3d011682016040523d82523d5f602084013e611163565b606091505b50915091506111748783838761117f565b979650505050505050565b606083156111ed5782515f036111e6576001600160a01b0385163b6111e65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016106a5565b50816106b9565b6106b983838151156112025781518083602001fd5b8060405162461bcd60e51b81526004016106a591906114b2565b5f6020828403121561122c575f80fd5b5035919050565b80356001600160a01b0381168114611249575f80fd5b919050565b5f806040838503121561125f575f80fd5b61126883611233565b915061127660208401611233565b90509250929050565b5f805f60608486031215611291575f80fd5b61129a84611233565b95602085013595506040909401359392505050565b5f80604083850312156112c0575f80fd5b6112c983611233565b946020939093013593505050565b80151581146104f1575f80fd5b5f80604083850312156112f5575f80fd5b6112fe83611233565b9150602083013561130e816112d7565b809150509250929050565b5f60208284031215611329575f80fd5b61065982611233565b5f8060408385031215611343575f80fd5b50508035926020909101359150565b634e487b7160e01b5f52601160045260245ffd5b8082018082111561079f5761079f611352565b5f60208284031215611389575f80fd5b5051919050565b80516001600160701b0381168114611249575f80fd5b5f604082840312156113b6575f80fd5b6040516040810181811067ffffffffffffffff821117156113e557634e487b7160e01b5f52604160045260245ffd5b6040526113f183611390565b81526113ff60208401611390565b60208201529392505050565b8181038181111561079f5761079f611352565b808202811582820484141761079f5761079f611352565b5f8261144f57634e487b7160e01b5f52601260045260245ffd5b500490565b5f6001820161146557611465611352565b5060010190565b5f8161147a5761147a611352565b505f190190565b5f60208284031215611491575f80fd5b8151610659816112d7565b5f82518060208501845e5f920191825250919050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f8301168401019150509291505056fea2646970667358221220bcb8e98f1a28212e899dc28c15606fa365b931d68b349e2ffcb80ecf9fe9f67864736f6c63430008190033

Verified Source Code Partial Match

Compiler: v0.8.25+commit.b61c2a91 EVM: cancun Optimization: Yes (200 runs)
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

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

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}
SafeERC20.sol 143 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./IERC20Permit.sol";
import "./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 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.encodeWithSelector(token.transfer.selector, 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.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @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);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @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.encodeWithSelector(token.approve.selector, spender, value);

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

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

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

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * 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.isContract(address(token));
    }
}
WeekStart.sol 19 lines
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity ^0.8.22;
import {IYearnBoostedStaker} from "./IYearnBoostedStaker.sol";

/**
    @title Week Start
    @dev Provides a unified `START_TIME` and `getWeek` aligned with the staker.
 */
contract WeekStart {
    uint256 public immutable START_TIME;

    constructor(IYearnBoostedStaker staker) {
        START_TIME = staker.START_TIME();
    }

    function getWeek() public view returns (uint256 week) {
        return (block.timestamp - START_TIME) / 1 weeks;
    }
}
IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IYearnBoostedStaker.sol 80 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.22;

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

interface IYearnBoostedStaker {
    struct AccountData {
        uint112 realizedStake;
        uint112 pendingStake;
        uint16 lastUpdateWeek;
        uint8 updateWeeksBitmap;
    }

    struct ToRealize {
        uint112 weightPersistent;
        uint112 weight;
    }

    enum ApprovalStatus {
        None,
        StakeOnly,
        UnstakeOnly,
        StakeAndUnstake
    }

    // State variables
    function MAX_STAKE_GROWTH_WEEKS() external view returns (uint);
    function MAX_WEEK_BIT() external view returns (uint8);
    function START_TIME() external view returns (uint);
    function stakeToken() external view returns (IERC20);
    function globalGrowthRate() external view returns (uint112);
    function globalLastUpdateWeek() external view returns (uint16);
    function totalSupply() external view returns (uint);
    function decimals() external view returns (uint8);
    function owner() external view returns (address);
    function pendingOwner() external view returns (address);
    function approvedCaller(address account, address caller) external view returns (ApprovalStatus);
    function approvedWeightedStaker(address staker) external view returns (bool);
    function accountWeeklyToRealize(address account, uint week) external view returns (ToRealize memory);
    function globalWeeklyToRealize(uint week) external view returns (ToRealize memory);
    function accountWeeklyMaxStake(address account, uint week) external view returns (uint);
    function globalWeeklyMaxStake(uint week) external view returns (uint);

    // Events
    event Stake(address indexed account, uint indexed week, uint amount, uint newUserWeight, uint weightAdded);
    event Unstake(address indexed account, uint indexed week, uint amount, uint newUserWeight, uint weightRemoved);
    event ApprovedCallerSet(address indexed account, address indexed caller, ApprovalStatus status);
    event WeightedStakerSet(address indexed staker, bool approved);
    event OwnershipTransferred(address indexed newOwner);

    // Functions
    function stake(uint _amount) external returns (uint);
    function stakeFor(address _account, uint _amount) external returns (uint);
    function stakeAsMaxWeighted(address _account, uint _amount) external returns (uint);
    function unstake(uint _amount, address _receiver) external returns (uint);
    function unstakeFor(address _account, uint _amount, address _receiver) external returns (uint);

    function checkpointAccount(address _account) external returns (AccountData memory acctData, uint weight);
    function checkpointAccountWithLimit(address _account, uint _week) external returns (AccountData memory acctData, uint weight);

    function getAccountWeight(address account) external view returns (uint);
    function getAccountWeightAt(address _account, uint _week) external view returns (uint);

    function checkpointGlobal() external returns (uint);
    function getGlobalWeight() external view returns (uint);
    function getGlobalWeightAt(uint week) external view returns (uint);

    function getAccountWeightRatio(address _account) external view returns (uint);
    function getAccountWeightRatioAt(address _account, uint _week) external view returns (uint);

    function balanceOf(address _account) external view returns (uint);
    function setApprovedCaller(address _caller, ApprovalStatus _status) external;
    function setWeightedStaker(address _staker, bool _approved) external;

    function transferOwnership(address _pendingOwner) external;
    function acceptOwnership() external;

    function sweep(address _token) external;
    function getWeek() external view returns (uint);
}
SingleTokenRewardDistributor.sol 322 lines
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity ^0.8.22;

import {WeekStart, IYearnBoostedStaker} from "./WeekStart.sol";
import {IERC20, SafeERC20} from "./SafeERC20.sol";


contract SingleTokenRewardDistributor is WeekStart {
    using SafeERC20 for IERC20;

    uint constant public PRECISION = 1e27;
    IYearnBoostedStaker public immutable staker;
    IERC20 public immutable rewardToken;
    uint public immutable START_WEEK;
    uint immutable MAX_STAKE_GROWTH_WEEKS;

    struct AccountInfo {
        address recipient; // Who rewards will be sent to. Cheaper to store here than in dedicated mapping.
        uint96 lastClaimWeek;
    }

    mapping(uint week => uint amount) public weeklyRewardAmount;
    mapping(address account => AccountInfo info) public accountInfo;
    mapping(address account => mapping(address claimer => bool approved)) public approvedClaimer;
    
    event RewardDeposited(uint indexed week, address indexed depositor, uint rewardAmount);
    event RewardsClaimed(address indexed account, uint indexed week, uint rewardAmount);
    event RecipientConfigured(address indexed account, address indexed recipient);
    event ClaimerApproved(address indexed account, address indexed, bool approved);
    event RewardPushed(uint indexed fromWeek, uint indexed toWeek, uint amount);

    /**
        @param _staker the staking contract to use for weight calculations.
        @param _rewardToken address of reward token to be used.
    */
    constructor(
        IYearnBoostedStaker _staker,
        IERC20 _rewardToken
    )
        WeekStart(_staker) {
        staker = _staker;
        rewardToken = _rewardToken;
        START_WEEK = staker.getWeek();
        MAX_STAKE_GROWTH_WEEKS = staker.MAX_STAKE_GROWTH_WEEKS();
    }

    /**
        @notice Allow permissionless deposits to the current week.
        @param _amount the amount of reward token to deposit.
    */
    function depositReward(uint _amount) external {
        if (_amount > 0) {
            uint week = getWeek();
            weeklyRewardAmount[week] += _amount;
            rewardToken.safeTransferFrom(msg.sender, address(this), _amount);
            emit RewardDeposited(week, msg.sender, _amount);
        }
    }

    /**
        @notice Push inaccessible rewards to current week.
        @dev    In rare circumstances, rewards may have been deposited to a week where no adjusted weight exists.
                This function allows us to recover rewards to the current week.
        @param _week the week to push rewards from.
        @return true if operation was successful.
    */
    function pushRewards(uint _week) external returns (bool) {
        uint week = getWeek();
        uint amount = pushableRewards(_week);
        if(amount == 0) return false;
        weeklyRewardAmount[_week] = 0;
        weeklyRewardAmount[week] += amount;
        emit RewardPushed(_week, week, amount);
        return true;
    }

    /**
        @notice Helper view function to check if any rewards are pushable.
        @param _week the week to push rewards from.
        @return uint representing rewards amount that is pushable.
    */
    function pushableRewards(uint _week) public view returns (uint) {
        uint week = getWeek();
        if(_week >= week) return 0;
        if(adjustedGlobalWeightAt(_week) != 0) return 0;
        return weeklyRewardAmount[_week];
    }

    /**
        @notice Claim all owed rewards since the last week touched by the user.
        @dev    It is not suggested to use this function directly. Rather `claimWithRange` 
                will tend to be more gas efficient when used with values from `getSuggestedClaimRange`.
    */
    function claim() external returns (uint amountClaimed) {
        uint currentWeek = getWeek();
        currentWeek = currentWeek == 0 ? 0 : currentWeek - 1;
        return _claimWithRange(msg.sender, 0, currentWeek);
    }

    /**
        @notice Claim on behalf of another account. Retrieves all owed rewards since the last week touched by the user.
        @dev    It is not suggested to use this function directly. Rather `claimWithRange` 
                will tend to be more gas efficient when used with values from `getSuggestedClaimRange`.
    */
    function claimFor(address _account) external returns (uint amountClaimed) {
        require(_onlyClaimers(_account), "!approvedClaimer");
        uint currentWeek = getWeek();
        currentWeek = currentWeek == 0 ? 0 : currentWeek - 1;
        return _claimWithRange(_account, 0, currentWeek);
    }

    /**
        @notice Claim rewards within a range of specified past weeks.
        @param _claimStartWeek the min week to search and rewards.
        @param _claimEndWeek the max week in which to search for and claim rewards.
        @dev    IMPORTANT: Choosing a `_claimStartWeek` that is greater than the earliest week in which a user
                may claim. Will result in the user being locked out (total loss) of rewards for any weeks prior.
    */
    function claimWithRange(
        uint _claimStartWeek,
        uint _claimEndWeek
    ) external returns (uint amountClaimed) {
        return _claimWithRange(msg.sender, _claimStartWeek, _claimEndWeek);
    }

    /**
        @notice Claim on behalf of another account for a range of specified past weeks.
        @param _account Account of which to make the claim on behalf of.
        @param _claimStartWeek The min week to search and rewards.
        @param _claimEndWeek The max week in which to search for and claim rewards.
        @dev    WARNING: Choosing a `_claimStartWeek` that is greater than the earliest week in which a user
                may claim will result in the user being locked out (total loss) of rewards for any weeks prior.
        @dev    Useful to target specific weeks with known reward amounts. Claiming via this function will tend 
                to be more gas efficient when used with values from `getSuggestedClaimRange`.
    */
    function claimWithRangeFor(
        address _account,
        uint _claimStartWeek,
        uint _claimEndWeek
    ) external returns (uint amountClaimed) {
        require(_onlyClaimers(_account), "!approvedClaimer");
        return _claimWithRange(_account, _claimStartWeek, _claimEndWeek);
    }

    function _claimWithRange(
        address _account,
        uint _claimStartWeek,
        uint _claimEndWeek
    ) internal returns (uint amountClaimed) {
        uint currentWeek = getWeek();
        if(_claimEndWeek >= currentWeek) return 0;

        AccountInfo storage info = accountInfo[_account];
        
        // Sanitize inputs
        uint _minStartWeek = info.lastClaimWeek == 0 ? START_WEEK : info.lastClaimWeek;
        _claimStartWeek = max(_minStartWeek, _claimStartWeek);
        if(_claimStartWeek > _claimEndWeek) return 0;
        
        amountClaimed = _getTotalClaimableByRange(_account, _claimStartWeek, _claimEndWeek);
        
        _claimEndWeek += 1;
        info.lastClaimWeek = uint96(_claimEndWeek);
        
        if (amountClaimed > 0) {
            address recipient = info.recipient == address(0) ? _account : info.recipient;
            rewardToken.safeTransfer(recipient, amountClaimed);
            emit RewardsClaimed(_account, _claimEndWeek, amountClaimed);
        }
    }

    /**
        @notice Helper function used to determine overall share of rewards at a particular week.
        @dev    IMPORTANT: This calculation cannot be relied upon to return strictly the users weight
                against global weight as it implements custom logic to ignore the first week of each deposit.
        @dev    Computing shares in past weeks is accurate. However, current week computations will not 
                be accurate until week is finalized.
        @dev    Results scaled to PRECSION.
    */
    function computeSharesAt(address _account, uint _week) public view returns (uint) {
        require(_week <= getWeek(), "Invalid week");
        // As a security measure, we don't distribute rewards to YBS deposits on their first full week of staking.
        // To acheive this, we lookup the weight that was added in the target week and ignore it.
        uint adjAcctWeight = adjustedAccountWeightAt(_account, _week);
        if (adjAcctWeight == 0) return 0;
        
        uint adjGlobalWeight = adjustedGlobalWeightAt(_week);
        if (adjGlobalWeight == 0) return 0;

        return adjAcctWeight * PRECISION / adjGlobalWeight;
    }

    function adjustedAccountWeightAt(address _account, uint _week) public view returns (uint) {
        uint acctWeight = staker.getAccountWeightAt(_account, _week);
        if (acctWeight == 0) return 0;
        return acctWeight - staker.accountWeeklyToRealize(_account, _week + MAX_STAKE_GROWTH_WEEKS).weightPersistent;
    }

    function adjustedGlobalWeightAt(uint _week) public view returns (uint) {
        uint globalWeight = staker.getGlobalWeightAt(_week);
        if (globalWeight == 0) return 0;
        return globalWeight - staker.globalWeeklyToRealize(_week + MAX_STAKE_GROWTH_WEEKS).weightPersistent;
    }

    /**
        @notice Get the sum total number of claimable tokens for a user across all his claimable weeks.
    */
    function getClaimable(address _account) external view returns (uint claimable) {
        (uint claimStartWeek, uint claimEndWeek) = getSuggestedClaimRange(_account);
        return _getTotalClaimableByRange(_account, claimStartWeek, claimEndWeek);
    }

    /**
        @notice Returns sum of tokens earned with a specified range of weeks.
        @param _account Account to query.
        @param _claimStartWeek Week to begin querying from.
        @param _claimEndWeek Week to end querying at.
    */
    function getTotalClaimableByRange(
        address _account,
        uint _claimStartWeek,
        uint _claimEndWeek
    ) external view returns (uint claimable) {
        uint currentWeek = getWeek();
        if (_claimEndWeek >= currentWeek) _claimEndWeek = currentWeek - 1;
        return _getTotalClaimableByRange(_account, _claimStartWeek, _claimEndWeek);
    }

    function _getTotalClaimableByRange(
        address _account,
        uint _claimStartWeek,
        uint _claimEndWeek
    ) internal view returns (uint claimableAmount) {
        for (uint i = _claimStartWeek; i <= _claimEndWeek; ++i) {
            claimableAmount += _getClaimableAt(_account, i);
        }
    }

    /**
        @notice Helper function returns suggested start and end range for claim weeks.
        @dev    This function is designed to be called prior to ranged claims to shorten the number of iterations
                required to loop if possible.
    */
    function getSuggestedClaimRange(address _account) public view returns (uint claimStartWeek, uint claimEndWeek) {
        uint currentWeek = getWeek();
        if (currentWeek == 0) return (0, 0);
        bool canClaim;
        uint lastClaimWeek = accountInfo[_account].lastClaimWeek;
        
        claimStartWeek = START_WEEK > lastClaimWeek ? START_WEEK : lastClaimWeek;

        // Loop from old towards recent.
        for (claimStartWeek; claimStartWeek <= currentWeek; claimStartWeek++) {
            if (_getClaimableAt(_account, claimStartWeek) > 0) {
                canClaim = true;
                break;
            }
        }

        if (!canClaim) return (0,0);

        // Loop backwards from recent week towards old. Skip current week.
        for (claimEndWeek = currentWeek - 1; claimEndWeek > claimStartWeek; claimEndWeek--) {
            if (_getClaimableAt(_account, claimEndWeek) > 0) {
                break;
            }
        }

        return (claimStartWeek, claimEndWeek);
    }

    /**
        @notice Get the reward amount available at a given week index.
        @param _account The account to check.
        @param _week The past week to check.
    */
    function getClaimableAt(
        address _account, 
        uint _week
    ) external view returns (uint rewardAmount) {
        if(_week >= getWeek()) return 0;
        return _getClaimableAt(_account, _week);
    }

    function _getClaimableAt(
        address _account, 
        uint _week
    ) internal view returns (uint rewardAmount) {
        if(_week < accountInfo[_account].lastClaimWeek) return 0;
        uint rewardShare = computeSharesAt(_account, _week);
        uint totalWeeklyAmount = weeklyRewardAmount[_week];
        rewardAmount = rewardShare * totalWeeklyAmount / PRECISION;
    }

    function _onlyClaimers(address _account) internal view returns (bool approved) {
        return approvedClaimer[_account][msg.sender] || _account == msg.sender;
    }

    /**
        @notice User may configure their account to set a custom reward recipient.
        @param _recipient   Wallet to receive rewards on behalf of the account. Zero address will result in all 
                            rewards being transferred directly to the account holder.
    */
    function configureRecipient(address _recipient) external {
        accountInfo[msg.sender].recipient = _recipient;
        emit RecipientConfigured(msg.sender, _recipient);
    }

    /**
        @notice Allow account to specify addresses to claim on their behalf.
        @param _claimer Claimer to approve or revoke
        @param _approved True to approve, False to revoke.
    */
    function approveClaimer(address _claimer, bool _approved) external {
        approvedClaimer[msg.sender][_claimer] = _approved;
        emit ClaimerApproved(msg.sender, _claimer, _approved);
    }

    function max(uint a, uint b) internal pure returns (uint) {
        return a < b ? b : a;
    }
}

Read Contract

PRECISION 0xaaf5eb68 → uint256
START_TIME 0xddaa26ad → uint256
START_WEEK 0x0e057047 → uint256
accountInfo 0xa7310b58 → address, uint96
adjustedAccountWeightAt 0x6db369ca → uint256
adjustedGlobalWeightAt 0x3f43ae69 → uint256
approvedClaimer 0x3bb959ce → bool
computeSharesAt 0x5fe6b010 → uint256
getClaimable 0xa583024b → uint256
getClaimableAt 0xbe960fda → uint256
getSuggestedClaimRange 0x7e9c3626 → uint256, uint256
getTotalClaimableByRange 0x610ae121 → uint256
getWeek 0x874d6d81 → uint256
pushableRewards 0x91c17197 → uint256
rewardToken 0xf7c618c1 → address
staker 0x5ebaf1db → address
weeklyRewardAmount 0x37381f42 → uint256

Write Contract 8 functions

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

approveClaimer 0x64607a53
address _claimer
bool _approved
claim 0x4e71d92d
No parameters
returns: uint256
claimFor 0xddeae033
address _account
returns: uint256
claimWithRange 0x9dd19473
uint256 _claimStartWeek
uint256 _claimEndWeek
returns: uint256
claimWithRangeFor 0x45fc1da1
address _account
uint256 _claimStartWeek
uint256 _claimEndWeek
returns: uint256
configureRecipient 0xc09f3457
address _recipient
depositReward 0x1e2720ff
uint256 _amount
pushRewards 0xd1118dee
uint256 _week
returns: bool

Recent Transactions

No transactions found for this address