Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x4f8d96ed344Dc7F394dB1d0a019264bEbff28f71
Balance 0 ETH
Nonce 1
Code Size 6840 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6840 bytes
0x608080604052600436101561001357600080fd5b60003560e01c9081630103c92b1461164b575080632def66201461137a578063372500ab146110ed5780633bcfc4b8146110ad5780633ccfd60b14610e4d5780633f4ba83a14610d585780634277766a14610d1c5780635617a6e814610cb45780635c975abb14610c7057806370a0823114610b7f578063715018a614610ae3578063817b1cd214610aa75780638456cb59146109935780638da5cb5b14610941578063a3f211051461089c578063a694fc3a146105ff578063b4b69cba14610597578063c8f33c911461055b578063d3e15747146104f1578063f2fde38b146103fc578063f83d08ba146103c0578063fa09e6301461020a578063fbfa77cf1461019b5763fc0c546a1461012757600080fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004123a133ae3c521fd134d7b13a2dec35b56c2463168152f35b600080fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602060405173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004fbc79d384235e59574a2ebb6c721e4b939ce188168152f35b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965760043573ffffffffffffffffffffffffffffffffffffffff81169081810361019657610263611910565b8115610362576040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201527f0000000000000000000000004123a133ae3c521fd134d7b13a2dec35b56c246360208260248173ffffffffffffffffffffffffffffffffffffffff85165afa9182156103565760009261031d575b5090610314817f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364946020946118b1565b604051908152a2005b90916020823d60201161034e575b8161033860209383611709565b8101031261034b575051906103146102e4565b80fd5b3d915061032b565b6040513d6000823e3d90fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f496e76616c6964207573657220616464726573730000000000000000000000006044820152fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576020600754604051908152f35b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965760043573ffffffffffffffffffffffffffffffffffffffff811680910361019657610454611910565b80156104c25773ffffffffffffffffffffffffffffffffffffffff600054827fffffffffffffffffffffffff0000000000000000000000000000000000000000821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3005b7f1e4fbdf700000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196577fc96ac8f962bbb0ee952304839108c72982a49173fa73e62ede62c943e10f5742602060043561054e611910565b80600755604051908152a1005b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576020600954604051908152f35b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965760043573ffffffffffffffffffffffffffffffffffffffff81168091036101965760005260036020526020604060002054604051908152f35b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657600435610639611821565b61064161185c565b801561083e576040517f70a082310000000000000000000000000000000000000000000000000000000081523360048201527f0000000000000000000000004123a133ae3c521fd134d7b13a2dec35b56c246360208260248173ffffffffffffffffffffffffffffffffffffffff85165afa91821561035657600092610808575b506106d261072a92841115611779565b6106da611895565b604051907f23b872dd00000000000000000000000000000000000000000000000000000000602083015233602483015230604483015283606483015260648252610725608483611709565b6119f7565b670de0b6b3a76400008102818104670de0b6b3a7640000036107d957600854610752916116d0565b33600052600260205261076b6040600020918254611814565b90553360005260036020526040600020610786828254611814565b9055336000526004602052426040600020556107a481600554611814565b6005556040519081527febedb8b3c678666e7f36970bc8f57abf6d8fa2e828c0da91ea5b75bf68ed101a60203392a260018055005b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b91506020823d602011610836575b8161082360209383611709565b81010312610196579051906106d26106c2565b3d9150610816565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f43616e6e6f74207374616b65203020746f6b656e7300000000000000000000006044820152fd5b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965760043561ffff81168091036101965760207feb96c2afe223f01218957822de6a706141023973470929f7cdff34537ac4369491610906611910565b61090e611895565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00006006541617600655604051908152a1005b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602073ffffffffffffffffffffffffffffffffffffffff60005416604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576109ca611910565b60005460ff8160a01c16610a49577fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff7401000000000000000000000000000000000000000091610a1861185c565b16176000557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a1005b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f5374616b696e6720697320616c726561647920706175736564000000000000006044820152fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576020600554604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657610b1a611910565b600073ffffffffffffffffffffffffffffffffffffffff81547fffffffffffffffffffffffff000000000000000000000000000000000000000081168355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965760043573ffffffffffffffffffffffffffffffffffffffff811680820361019657610bd76117de565b50806000526004602052610bf360406000205460075490611814565b42810390600042128183128116918313901516176107d957608092610c166117de565b926000526004602052604060002054835260208301918252336000526003602052610c4d604060002054916040850192835261195f565b916060840192835260405193518452516020840152516040830152516060820152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602060ff60005460a01c166040519015158152f35b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101965760043573ffffffffffffffffffffffffffffffffffffffff81168091036101965760005260046020526020604060002054604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576020600854604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657610d8f611910565b60005460ff8160a01c1615610def577fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff166000557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a1005b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f5374616b696e67206973206e6f742070617573656400000000000000000000006044820152fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657610e84611910565b7f0000000000000000000000004123a133ae3c521fd134d7b13a2dec35b56c246373ffffffffffffffffffffffffffffffffffffffff8116604051907f70a08231000000000000000000000000000000000000000000000000000000008252306004830152602082602481845afa91821561035657600092611079575b50610f0f60055480936116b0565b1561101b576020602491604051928380927f70a082310000000000000000000000000000000000000000000000000000000082523060048301525afa90811561035657600091610fd5575b5073ffffffffffffffffffffffffffffffffffffffff610f9d7f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a9424364936020936116b0565b93610fca857f0000000000000000000000004fbc79d384235e59574a2ebb6c721e4b939ce18880936118b1565b6040519485521692a2005b90506020813d602011611013575b81610ff060209383611709565b81010312610196575173ffffffffffffffffffffffffffffffffffffffff610f5a565b3d9150610fe3565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f4e6f207265776172647320746f207769746864726177000000000000000000006044820152fd5b9091506020813d6020116110a5575b8161109560209383611709565b8101031261019657519083610f01565b3d9150611088565b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657602061ffff60065416604051908152f35b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261019657611124611821565b61112c61185c565b336000526003602052604060002054801561131c57611149611895565b33600052600260205261117781670de0b6b3a7640000611171604060002054600854906116bd565b046116b0565b9081156112be577f0000000000000000000000004123a133ae3c521fd134d7b13a2dec35b56c24636040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260208160248173ffffffffffffffffffffffffffffffffffffffff86165afa8015610356578491600091611287575b50916112178261121061121e95600554906116b0565b1015611779565b33906118b1565b670de0b6b3a76400008102908104670de0b6b3a7640000036107d957600854611246916116d0565b3360005260026020526040600020556040519081527f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d460203392a260018055005b9150506020813d6020116112b6575b816112a360209383611709565b81010312610196575183906112176111fa565b3d9150611296565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f4e6f207265776172647320617661696c61626c650000000000000000000000006044820152fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f4e6f20746f6b656e73207374616b6564000000000000000000000000000000006044820152fd5b346101965760007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576113b1611821565b6113b961185c565b33600052600360205260406000205480156115ed573360005260046020526113e6604060002054426116b0565b6007541161158f576113f6611895565b336000526002602052670de0b6b3a764000061141a604060002054600854906116bd565b049061142681836116b0565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015290927f0000000000000000000000004123a133ae3c521fd134d7b13a2dec35b56c246360208360248173ffffffffffffffffffffffffffffffffffffffff85165afa8015610356578593600091611556575b506114b99361121061121792600554906116b0565b3360005260026020526000604081205533600052600360205260006040812055336000526004602052600060408120556114f5816005546116b0565b6005556040519081527f85082129d87b2fe11527cb1b3b7a520aeb5aa6913f88a3d8757fe40d1db02fdd60203392a26040519081527f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d460203392a260018055005b9350506020833d602011611587575b8161157260209383611709565b810103126101965791518492906114b96114a4565b3d9150611565565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f546f6b656e7320617265206c6f636b65640000000000000000000000000000006044820152fd5b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f43616e6e6f7420756e7374616b65203020746f6b656e730000000000000000006044820152fd5b346101965760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610196576004359073ffffffffffffffffffffffffffffffffffffffff821680920361019657602091600052600282526040600020548152f35b919082039182116107d957565b818102929181159184041417156107d957565b81156116da570490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761174a57604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b1561178057565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f4e6f2066756e6420617661696c61626c650000000000000000000000000000006044820152fd5b604051906080820182811067ffffffffffffffff82111761174a5760405260006060838281528260208201528260408201520152565b919082018092116107d957565b600260015414611832576002600155565b7f3ee5aeb50000000000000000000000000000000000000000000000000000000060005260046000fd5b60ff60005460a01c1661186b57565b7fd93c06650000000000000000000000000000000000000000000000000000000060005260046000fd5b60095442116118a057565b6118a86119c0565b60085542600955565b61190e9273ffffffffffffffffffffffffffffffffffffffff604051937fa9059cbb000000000000000000000000000000000000000000000000000000006020860152166024840152604483015260448252610725606483611709565b565b73ffffffffffffffffffffffffffffffffffffffff60005416330361193157565b7f118cdaa7000000000000000000000000000000000000000000000000000000006000523360045260246000fd5b73ffffffffffffffffffffffffffffffffffffffff1680600052600360205260406000205480156119b957670de0b6b3a76400006111716119b6936119a26119c0565b9060005260026020526040600020546116bd565b90565b5050600090565b6119b66119cf600954426116b0565b63bbf81e006119f0600854926119eb61ffff60065416856116bd565b6116bd565b0490611814565b906000602091828151910182855af115610356576000513d611a79575073ffffffffffffffffffffffffffffffffffffffff81163b155b611a355750565b73ffffffffffffffffffffffffffffffffffffffff907f5274afe7000000000000000000000000000000000000000000000000000000006000521660045260246000fd5b60011415611a2e56fea26469706673582212206aff0a1fe00c1fef2dee280e6fca6b69630fbed6796abe17616fc5ae2ea50a3f64736f6c634300081b0033

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 274 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;
		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;
		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[msg.sender];
		data.rewards = pendingRewards(_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();
			lastUpdateTime = block.timestamp;
		}
	}
	
	/*
	* Internal function to calculate the pending rewards of a user
	* @param _user user to calculate rewards for
    */
	function pendingRewards(address _user) internal view returns (uint256) {
		uint256 userStakedAmount = userBalanceInitial[_user];
		if (userStakedAmount == 0) return 0;

		uint256 currentCompoundIndex = calculateUpdatedIndex();		
		uint256 userCompoundBalance = (userBalance[_user] * currentCompoundIndex) / ONE;
		uint256 rewards = userCompoundBalance - userStakedAmount;
		
		return rewards;
	}

	function calculateUpdatedIndex() internal view returns (uint256 indexUpdated) {
		uint256 timeElapsed = block.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 withdrawAll(address _user) external onlyOwner {
		require(_user != address(0), "Invalid user address");

		uint256 amount = token.balanceOf(address(this));
		token.safeTransfer(_user, amount);

		emit Withdraw(_user, amount);
	}
	
	/*
	* 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
token 0xfc0c546a → address
totalStaked 0x817b1cd2 → uint256
userBalance 0x0103c92b → uint256
userBalanceInitial 0xb4b69cba → uint256
userLock 0x5617a6e8 → uint256
vault 0xfbfa77cf → address

Write Contract 11 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
withdrawAll 0xfa09e630
address _user

Recent Transactions

No transactions found for this address