Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xD56320Ed737A04542f227eFa3538DAC494d1aA3b
Balance 0 ETH
Nonce 1
Code Size 6697 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6697 bytes
0x608080604052600436101561001357600080fd5b60003560e01c9081630103c92b1461151d575080632def66201461123c578063372500ab14610f9e5780633bcfc4b814610f5e5780633ccfd60b14610cfe5780633f4ba83a14610c095780634277766a14610bcd5780635617a6e814610b685780635c975abb14610b2457806370a0823114610a34578063715018a614610998578063817b1cd21461095c5780638456cb59146108485780638da5cb5b146107f6578063a3f2110514610751578063a694fc3a146104a8578063b4b69cba14610443578063c8f33c9114610407578063d18df53c146103a2578063d3e1574714610338578063f2fde38b14610246578063f83d08ba1461020a578063fbfa77cf1461019b5763fc0c546a1461012757600080fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000006243558a24cc6116abe751f27e6d7ede50abfc76168152f35b600080fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602060405173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000ea42f017a9d962019e36ce4d7d376d0421855b66168152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576020600754604051908152f35b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965773ffffffffffffffffffffffffffffffffffffffff61029261157e565b61029a61187b565b1680156103095773ffffffffffffffffffffffffffffffffffffffff600054827fffffffffffffffffffffffff0000000000000000000000000000000000000000821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3005b7f1e4fbdf700000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196577fc96ac8f962bbb0ee952304839108c72982a49173fa73e62ede62c943e10f5742602060043561039561187b565b80600755604051908152a1005b346101965760407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965760243573ffffffffffffffffffffffffffffffffffffffff81168103610196576103ff602091600435611712565b604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576020600954604051908152f35b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965773ffffffffffffffffffffffffffffffffffffffff61048f61157e565b1660005260036020526020604060002054604051908152f35b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576004356104e261178b565b6104ea6117c6565b80156106f3576040517f70a082310000000000000000000000000000000000000000000000000000000081523360048201527f0000000000000000000000006243558a24cc6116abe751f27e6d7ede50abfc7660208260248173ffffffffffffffffffffffffffffffffffffffff85165afa9182156106e7576000926106b1575b5061057b6105d39284111561166a565b6105836117ff565b604051907f23b872dd000000000000000000000000000000000000000000000000000000006020830152336024830152306044830152836064830152606482526105ce6084836115fa565b611968565b670de0b6b3a76400008102818104670de0b6b3a764000003610682576008546105fb916115c1565b3360005260026020526106146040600020918254611705565b9055336000526003602052604060002061062f828254611705565b90553360005260046020524260406000205561064d81600554611705565b6005556040519081527febedb8b3c678666e7f36970bc8f57abf6d8fa2e828c0da91ea5b75bf68ed101a60203392a260018055005b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b91506020823d6020116106df575b816106cc602093836115fa565b810103126101965790519061057b61056b565b3d91506106bf565b6040513d6000823e3d90fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f43616e6e6f74207374616b65203020746f6b656e7300000000000000000000006044820152fd5b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965760043561ffff81168091036101965760207feb96c2afe223f01218957822de6a706141023973470929f7cdff34537ac43694916107bb61187b565b6107c36117ff565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00006006541617600655604051908152a1005b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602073ffffffffffffffffffffffffffffffffffffffff60005416604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965761087f61187b565b60005460ff8160a01c166108fe577fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff74010000000000000000000000000000000000000000916108cd6117c6565b16176000557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a1005b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f5374616b696e6720697320616c726561647920706175736564000000000000006044820152fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576020600554604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576109cf61187b565b600073ffffffffffffffffffffffffffffffffffffffff81547fffffffffffffffffffffffff000000000000000000000000000000000000000081168355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657610a6b61157e565b610a736116cf565b5073ffffffffffffffffffffffffffffffffffffffff8116806000526004602052610aa660406000205460075490611705565b428103906000421281831281169183139015161761068257608092610ac96116cf565b928060005260046020526040600020548452602084019283526000526003602052610b01604060002054916040850192835242611712565b916060840192835260405193518452516020840152516040830152516060820152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602060ff60005460a01c166040519015158152f35b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965773ffffffffffffffffffffffffffffffffffffffff610bb461157e565b1660005260046020526020604060002054604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576020600854604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657610c4061187b565b60005460ff8160a01c1615610ca0577fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff166000557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a1005b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5374616b696e67206973206e6f742070617573656400000000000000000000006044820152fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657610d3561187b565b7f0000000000000000000000006243558a24cc6116abe751f27e6d7ede50abfc7673ffffffffffffffffffffffffffffffffffffffff8116604051907f70a08231000000000000000000000000000000000000000000000000000000008252306004830152602082602481845afa9182156106e757600092610f2a575b50610dc060055480936115a1565b15610ecc576020602491604051928380927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa9081156106e757600091610e86575b5073ffffffffffffffffffffffffffffffffffffffff610e4e7f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364936020936115a1565b93610e7b857f000000000000000000000000ea42f017a9d962019e36ce4d7d376d0421855b66809361181c565b6040519485521692a2005b90506020813d602011610ec4575b81610ea1602093836115fa565b81010312610196575173ffffffffffffffffffffffffffffffffffffffff610e0b565b3d9150610e94565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4e6f207265776172647320746f207769746864726177000000000000000000006044820152fd5b9091506020813d602011610f56575b81610f46602093836115fa565b8101031261019657519083610db2565b3d9150610f39565b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602061ffff60065416604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657610fd561178b565b610fdd6117c6565b33600052600360205260406000205480156111de57610ffa6117ff565b336000526002602052670de0b6b3a764000061101e604060002054600854906115ae565b04818082106111d6575b611031916115a1565b908115611178577f0000000000000000000000006243558a24cc6116abe751f27e6d7ede50abfc766040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260208160248173ffffffffffffffffffffffffffffffffffffffff86165afa80156106e7578491600091611141575b50916110d1826110ca6110d895600554906115a1565b101561166a565b339061181c565b670de0b6b3a76400008102908104670de0b6b3a76400000361068257600854611100916115c1565b3360005260026020526040600020556040519081527f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d460203392a260018055005b9150506020813d602011611170575b8161115d602093836115fa565b81010312610196575183906110d16110b4565b3d9150611150565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f4e6f207265776172647320617661696c61626c650000000000000000000000006044820152fd5b905080611028565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f4e6f20746f6b656e73207374616b6564000000000000000000000000000000006044820152fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965761127361178b565b61127b6117c6565b33600052600360205260406000205480156114bf573360005260046020526112a8604060002054426115a1565b60075411611461576112b86117ff565b336000526002602052670de0b6b3a76400006112dc604060002054600854906115ae565b0490808210611459575b6112f081836115a1565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015290927f0000000000000000000000006243558a24cc6116abe751f27e6d7ede50abfc7660208360248173ffffffffffffffffffffffffffffffffffffffff85165afa80156106e7578593600091611420575b50611383936110ca6110d192600554906115a1565b3360005260026020526000604081205533600052600360205260006040812055336000526004602052600060408120556113bf816005546115a1565b6005556040519081527f85082129d87b2fe11527cb1b3b7a520aeb5aa6913f88a3d8757fe40d1db02fdd60203392a26040519081527f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d460203392a260018055005b9350506020833d602011611451575b8161143c602093836115fa565b8101031261019657915184929061138361136e565b3d915061142f565b9050806112e6565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f546f6b656e7320617265206c6f636b65640000000000000000000000000000006044820152fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f43616e6e6f7420756e7374616b65203020746f6b656e730000000000000000006044820152fd5b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965760209073ffffffffffffffffffffffffffffffffffffffff61156c61157e565b16600052600282526040600020548152f35b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361019657565b9190820391821161068257565b8181029291811591840414171561068257565b81156115cb570490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761163b57604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b1561167157565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4e6f2066756e6420617661696c61626c650000000000000000000000000000006044820152fd5b604051906080820182811067ffffffffffffffff82111761163b5760405260006060838281528260208201528260408201520152565b9190820180921161068257565b9073ffffffffffffffffffffffffffffffffffffffff168060005260036020526040600020549081156117835761176c670de0b6b3a764000091611758611779956118ca565b9060005260026020526040600020546115ae565b0481811061177c576115a1565b90565b50806115a1565b505050600090565b60026001541461179c576002600155565b7f3ee5aeb50000000000000000000000000000000000000000000000000000000060005260046000fd5b60ff60005460a01c166117d557565b7fd93c06650000000000000000000000000000000000000000000000000000000060005260046000fd5b600954421161180a57565b611813426118ca565b60085542600955565b6118799273ffffffffffffffffffffffffffffffffffffffff604051937fa9059cbb0000000000000000000000000000000000000000000000000000000060208601521660248401526044830152604482526105ce6064836115fa565b565b73ffffffffffffffffffffffffffffffffffffffff60005416330361189c57565b7f118cdaa7000000000000000000000000000000000000000000000000000000006000523360045260246000fd5b6009549081811061190a57611779916118e2916115a1565b63bbf81e00611903600854926118fe61ffff60065416856115ae565b6115ae565b0490611705565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f496e76616c69642074696d657374616d700000000000000000000000000000006044820152fd5b906000602091828151910182855af1156106e7576000513d6119ea575073ffffffffffffffffffffffffffffffffffffffff81163b155b6119a65750565b73ffffffffffffffffffffffffffffffffffffffff907f5274afe7000000000000000000000000000000000000000000000000000000006000521660045260246000fd5b6001141561199f56fea264697066735822122070396bd0565088bf8b7d594ba982b3b0c83c7f56e8a7a2473c80d2b6e67f94fb64736f6c634300081b0033

Verified Source Code Full Match

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

pragma solidity ^0.8.20;

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _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.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     *
     * IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
     * smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
     * this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
     * that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        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 Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
     * code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
     * targeting contracts.
     *
     * Reverts if the returned value is other than `true`.
     */
    function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
        if (to.code.length == 0) {
            safeTransfer(token, to, value);
        } else if (!token.transferAndCall(to, value, data)) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

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

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

    /**
     * @dev Imitates a Solidity 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 {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            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 silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}
Address.sol 150 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @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 Errors.InsufficientBalance(address(this).balance, amount);
        }

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

    /**
     * @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
     * {Errors.FailedCall} 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 Errors.InsufficientBalance(address(this).balance, value);
        }
        (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 {Errors.FailedCall}) 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 {Errors.FailedCall} 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 {Errors.FailedCall}.
     */
    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
            assembly ("memory-safe") {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert Errors.FailedCall();
        }
    }
}
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;
    }
}
Errors.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of common custom errors used in multiple contracts
 *
 * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
 * It is recommended to avoid relying on the error API for critical functionality.
 *
 * _Available since v5.1._
 */
library Errors {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error InsufficientBalance(uint256 balance, uint256 needed);

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

    /**
     * @dev The deployment failed.
     */
    error FailedDeployment();

    /**
     * @dev A necessary precompile is missing.
     */
    error MissingPrecompile(address);
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
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 87 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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 EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
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;
    }
}
Staking.sol 278 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

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

using SafeERC20 for IERC20;

// Struct to hold user data
struct UserData {
  uint256 lockStart; // The time when the user last staked
  int256 lockRemaining; // The time remaining before unlock
  uint256 balance; // The balance of staked tokens
  uint256 rewards; // The balance of rewards
}

contract Staking is Ownable, Pausable, ReentrancyGuard {
  // Keep the normalized balance of stake tokens for a user
  mapping(address => uint256) public userBalance;

  // Keep the initial balance of stake tokens for a user
  mapping(address => uint256) public userBalanceInitial;

  // Keep the time of staking for a user
  mapping(address => uint256) public userLock;

  // Address of the vault to hold reward tokens
  address public immutable vault;

  // Address of the token to be staked
  IERC20 public immutable token;

  // Total amount of tokens staked
  uint256 public totalStaked;

  // APY of the rewards (in percentage ex. 20)
  uint16 public apy;

  // Lock time (in seconds)
  uint256 public lock;

  // Global compound index for calculating compound interest
  uint256 public compoundIndex;

  // Last update time for the compound index
  uint256 public lastUpdateTime;

  // compoundIndex precision
  uint256 constant ONE = 1e18;

  // number representing 100% in apy calculations
  uint256 constant APY_ONE = 100;

  // seconds in a year: 365 * 24 * 60 * 60
  uint256 constant YEAR = 31536000;

  // Events
  event Stake(address indexed user, uint256 amount);
  event Unstake(address indexed user, uint256 amount);
  event Claim(address indexed user, uint256 amount);
  event Withdraw(address indexed vault, uint256 amount);
  event ApySet(uint256 apy);
  event LockSet(uint256 lock);

  constructor(IERC20 _token, address _owner, address _vault, uint16 _apy, uint256 _lock) Ownable(_owner) {
    token = _token;
    apy = _apy;
    lock = _lock;
    vault = _vault;
    compoundIndex = ONE; // Initialize to 1.0 (scaled by 1e18 for precision)
    lastUpdateTime = block.timestamp;

    emit ApySet(_apy);
    emit LockSet(_lock);
  }

  /*
   * Internal function to update the compound index based on the elapsed time
   * @params _amount The amount to stake (in wei)
   */
  function stake(uint256 _amount) external nonReentrant whenNotPaused {
    require(_amount > 0, 'Cannot stake 0 tokens');
    require(_amount <= token.balanceOf(msg.sender), 'No fund available');

    // Update the compound index
    updateIndex();

    // Transfer the tokens from the user to the contract
    token.safeTransferFrom(msg.sender, address(this), _amount);

    // Calculate the adjusted amount based on the current compound index
    uint256 adjustedAmount = (_amount * ONE) / compoundIndex;

    // Update the user
    userBalance[msg.sender] += adjustedAmount;
    userBalanceInitial[msg.sender] += _amount;
    userLock[msg.sender] = block.timestamp;

    totalStaked += _amount;

    emit Stake(msg.sender, _amount);
  }

  /*
   * Function to unstake
   */
  function unstake() external nonReentrant whenNotPaused {
    uint256 _amount = userBalanceInitial[msg.sender];

    require(_amount > 0, 'Cannot unstake 0 tokens');
    require(block.timestamp - userLock[msg.sender] >= lock, 'Tokens are locked');

    // Update the compound index
    updateIndex();

    // Calculate rewards
    uint256 userCompoundBalance = (userBalance[msg.sender] * compoundIndex) / ONE;
    if (userCompoundBalance < _amount) {
      // In case of rounding error userCompoundBalance could be less than initial amount
      userCompoundBalance = _amount;
    }
    uint256 rewards = userCompoundBalance - _amount;

    // Transfer the total amount back to the user
    require(token.balanceOf(address(this)) - totalStaked >= rewards, 'No fund available');
    token.safeTransfer(msg.sender, userCompoundBalance);

    // Update the user
    delete userBalance[msg.sender];
    delete userBalanceInitial[msg.sender];
    delete userLock[msg.sender];

    totalStaked -= _amount;

    emit Unstake(msg.sender, _amount);
    emit Claim(msg.sender, rewards);
  }

  /*
   * Function to claim rewards
   */
  function claimRewards() external nonReentrant whenNotPaused {
    uint256 userStakedAmount = userBalanceInitial[msg.sender];
    require(userStakedAmount > 0, 'No tokens staked');

    // Update the compound index
    updateIndex();

    // Calculate the rewards
    uint256 userCompoundBalance = (userBalance[msg.sender] * compoundIndex) / ONE;
    if (userCompoundBalance < userStakedAmount) {
      // In case of rounding error userCompoundBalance could be less than initial amount
      userCompoundBalance = userStakedAmount;
    }
    uint256 rewards = userCompoundBalance - userStakedAmount;

    require(rewards > 0, 'No rewards available');
    require(token.balanceOf(address(this)) - totalStaked >= rewards, 'No fund available');

    // Transfer the rewards to the user
    token.safeTransfer(msg.sender, rewards);

    // Update the balance
    userBalance[msg.sender] = (userStakedAmount * ONE) / compoundIndex;

    emit Claim(msg.sender, rewards);
  }

  /*
   * Function to check the balance of a user
   * @params _user Address of the user to check
   */
  function balanceOf(address _user) public view returns (UserData memory) {
    int256 remaining = int256(userLock[_user] + lock) - int256(block.timestamp);

    UserData memory data;

    data.lockStart = userLock[_user];
    data.lockRemaining = remaining;
    data.balance = userBalanceInitial[_user];
    data.rewards = pendingRewards(block.timestamp, _user);

    return data;
  }

  // HELPERS

  /*
   * Internal function to update the compound index based on the elapsed time
   */
  function updateIndex() internal {
    if (block.timestamp > lastUpdateTime) {
      compoundIndex = calculateUpdatedIndex(block.timestamp);
      lastUpdateTime = block.timestamp;
    }
  }

  /*
   * Helper function to calculate the pending rewards of a user
   * @param _user user to calculate rewards for
   */
  function pendingRewards(uint256 _timestamp, address _user) public view returns (uint256) {
    uint256 userStakedAmount = userBalanceInitial[_user];
    if (userStakedAmount == 0) return 0;

    uint256 currentCompoundIndex = calculateUpdatedIndex(_timestamp);
    uint256 userCompoundBalance = (userBalance[_user] * currentCompoundIndex) / ONE;
    if (userCompoundBalance < userStakedAmount) {
      // In case of rounding error userCompoundBalance could be less than initial amount
      userCompoundBalance = userStakedAmount;
    }
    uint256 rewards = userCompoundBalance - userStakedAmount;

    return rewards;
  }

  function calculateUpdatedIndex(uint256 timestamp) internal view returns (uint256 indexUpdated) {
    require(timestamp >= lastUpdateTime, 'Invalid timestamp');

    uint256 timeElapsed = timestamp - lastUpdateTime;
    uint256 _compoundIndex = compoundIndex;
    indexUpdated = _compoundIndex + (_compoundIndex * uint256(apy) * timeElapsed) / (APY_ONE * YEAR);
  }

  // ADMIN

  /*
   * Function to withdraw rewards
   * Only the fund added for the rewards can be withdrawn.
   */
  function withdraw() external onlyOwner {
    require(token.balanceOf(address(this)) - totalStaked > 0, 'No rewards to withdraw');

    uint256 balance = token.balanceOf(address(this)) - totalStaked;
    token.safeTransfer(vault, balance);

    emit Withdraw(vault, balance);
  }

  /*
   * Function to set the APY
   * @params _apy The new apy. Effective immediately. in percent, like 20 (meaning 20%)
   */
  function setApy(uint16 _apy) external onlyOwner {
    updateIndex();
    apy = _apy;

    emit ApySet(_apy);
  }

  /*
   * Function to set lock period
   * @params _lock The new lock period (in seconds). Effective immediately. 1 day = 86 400 seconds
   */
  function setLock(uint256 _lock) external onlyOwner {
    lock = _lock;

    emit LockSet(_lock);
  }

  /*
   * Function to pause the staking
   */
  function pause() external onlyOwner {
    require(!paused(), 'Staking is already paused');
    _pause();
  }

  /*
   * Function to unpause the staking
   */
  function unpause() external onlyOwner {
    require(paused(), 'Staking is not paused');
    _unpause();
  }
}

Read Contract

apy 0x3bcfc4b8 → uint16
balanceOf 0x70a08231 → tuple
compoundIndex 0x4277766a → uint256
lastUpdateTime 0xc8f33c91 → uint256
lock 0xf83d08ba → uint256
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
pendingRewards 0xd18df53c → uint256
token 0xfc0c546a → address
totalStaked 0x817b1cd2 → uint256
userBalance 0x0103c92b → uint256
userBalanceInitial 0xb4b69cba → uint256
userLock 0x5617a6e8 → uint256
vault 0xfbfa77cf → address

Write Contract 10 functions

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

claimRewards 0x372500ab
No parameters
pause 0x8456cb59
No parameters
renounceOwnership 0x715018a6
No parameters
setApy 0xa3f21105
uint16 _apy
setLock 0xd3e15747
uint256 _lock
stake 0xa694fc3a
uint256 _amount
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters
unstake 0x2def6620
No parameters
withdraw 0x3ccfd60b
No parameters

Recent Transactions

No transactions found for this address