Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0xAc9a52Dfe26Cf3b8Bca4CcFb328000E19A586B69
Balance 0 ETH
Nonce 1
Code Size 7785 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

7785 bytes
0x608060405234801561001057600080fd5b506004361061020b5760003560e01c806372f702f31161012a578063bcd11014116100bd578063e70b9e271161008c578063e941fa7811610071578063e941fa78146104f3578063f1229777146104fc578063f2fde38b1461050f57600080fd5b8063e70b9e27146104b5578063e74b981b146104e057600080fd5b8063bcd1101414610474578063c4ae316814610487578063c7b9d5301461048f578063d0ed26ae146104a257600080fd5b8063a694fc3a116100f9578063a694fc3a14610432578063b66503cf14610445578063b6ac642a14610458578063bc063e1a1461046b57600080fd5b806372f702f3146103e35780637bb7bed1146103f65780638980f11f146104095780638da5cb5b1461041c57600080fd5b806348e5d9f8116101a257806367a527931161017157806367a527931461037e5780637035ab981461038757806370a08231146103b2578063715018a6146103db57600080fd5b806348e5d9f8146102bb578063490ae210146103425780635c975abb14610355578063638634ee1461036b57600080fd5b80632e1a7d4d116101de5780632e1a7d4d1461027a5780633d18b9121461028d5780633f695b451461029557806346904840146102a857600080fd5b806318160ddd146102105780631fe4a68614610227578063211dc32d146102525780632378bea614610265575b600080fd5b6007545b6040519081526020015b60405180910390f35b60095461023a906001600160a01b031681565b6040516001600160a01b03909116815260200161021e565b610214610260366004611c71565b610522565b610278610273366004611ca4565b6105bc565b005b610278610288366004611cce565b6106fd565b610278610939565b6102786102a3366004611c71565b610b2a565b600a5461023a906001600160a01b031681565b61030b6102c9366004611ce7565b60036020819052600091825260409091208054600182015460028301549383015460048401546005909401546001600160a01b03909316949193919290919086565b604080516001600160a01b0390971687526020870195909552938501929092526060840152608083015260a082015260c00161021e565b610278610350366004611cce565b610beb565b60015460ff16604051901515815260200161021e565b610214610379366004611ce7565b610c75565b610214600b5481565b610214610395366004611c71565b600560209081526000928352604080842090915290825290205481565b6102146103c0366004611ce7565b6001600160a01b031660009081526008602052604090205490565b610278610cbf565b60025461023a906001600160a01b031681565b61023a610404366004611cce565b610cd1565b610278610417366004611ca4565b610cfb565b60015461010090046001600160a01b031661023a565b610278610440366004611cce565b610e2f565b610278610453366004611ca4565b611069565b610278610466366004611cce565b611332565b6102146101f481565b610214610482366004611ce7565b6113bc565b6102786113e8565b61027861049d366004611ce7565b611489565b6102786104b0366004611d02565b61155d565b6102146104c3366004611c71565b600660209081526000928352604080842090915290825290205481565b6102786104ee366004611ce7565b611606565b610214600c5481565b61021461050a366004611ce7565b6116da565b61027861051d366004611ce7565b61178c565b6001600160a01b038083166000818152600660209081526040808320948616808452948252808320549383526005825280832094835293905291822054670de0b6b3a764000090610572856116da565b61057c9190611d54565b6001600160a01b03861660009081526008602052604090205461059f9190611d67565b6105a99190611d7e565b6105b39190611da0565b90505b92915050565b6001600160a01b038216600090815260036020526040902060020154421161062b5760405162461bcd60e51b815260206004820152601a60248201527f52657761726420706572696f64207374696c6c2061637469766500000000000060448201526064015b60405180910390fd5b6001600160a01b0382811660009081526003602052604090205416331461065157600080fd5b600081116106a15760405162461bcd60e51b815260206004820181905260248201527f526577617264206475726174696f6e206d757374206265206e6f6e2d7a65726f6044820152606401610622565b6001600160a01b038216600081815260036020908152604091829020600101849055815192835282018390527fad2f86b01ed93b4b3a150d448c61a4f5d8d38075d3c0c64cc0a26fd6e1f4954591015b60405180910390a15050565b6107056117e0565b3360005b6004548110156107fe5760006004828154811061072857610728611db3565b6000918252602090912001546001600160a01b03169050610748816116da565b6001600160a01b03821660009081526003602052604090206005015561076d81610c75565b6001600160a01b038083166000908152600360205260409020600401919091558316156107eb5761079e8382610522565b6001600160a01b0380851660008181526006602090815260408083209487168084529482528083209590955560038152848220600590810154938352815284822093825292909252919020555b50806107f681611dc9565b915050610709565b506000821161084f5760405162461bcd60e51b815260206004820152601160248201527f43616e6e6f7420776974686472617720300000000000000000000000000000006044820152606401610622565b8160075461085d9190611d54565b6007553360009081526008602052604090205461087b908390611d54565b33600090815260086020526040902055600c54156108de576000612710600c54846108a69190611d67565b6108b09190611d7e565b600a546002549192506108d0916001600160a01b03908116911683611823565b6108da8184611d54565b9250505b6002546108f5906001600160a01b03163384611823565b60405182815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5906020015b60405180910390a2506109366001600055565b50565b6109416117e0565b3360005b600454811015610a3a5760006004828154811061096457610964611db3565b6000918252602090912001546001600160a01b03169050610984816116da565b6001600160a01b0382166000908152600360205260409020600501556109a981610c75565b6001600160a01b03808316600090815260036020526040902060040191909155831615610a27576109da8382610522565b6001600160a01b0380851660008181526006602090815260408083209487168084529482528083209590955560038152848220600590810154938352815284822093825292909252919020555b5080610a3281611dc9565b915050610945565b5060005b600454811015610b1c57600060048281548110610a5d57610a5d611db3565b60009182526020808320909101543383526006825260408084206001600160a01b03909216808552919092529120549091508015610b07573360008181526006602090815260408083206001600160a01b0387168085529252822091909155610ac69183611823565b6040518181526001600160a01b0383169033907f540798df468d7b23d11f156fdb954cb19ad414d150722a7b6d55ba369dea792e9060200160405180910390a35b50508080610b1490611dc9565b915050610a3e565b5050610b286001600055565b565b60015461010090046001600160a01b03166001600160a01b0316336001600160a01b03161480610b6457506009546001600160a01b031633145b610bb05760405162461bcd60e51b815260206004820152601160248201527f7065726d697373696f6e2064656e6965640000000000000000000000000000006044820152606401610622565b6001600160a01b039182166000908152600360205260409020805473ffffffffffffffffffffffffffffffffffffffff191691909216179055565b610bf361189c565b6101f4811115610c345760405162461bcd60e51b815260206004820152600c60248201526b0cccaca40e8dede40d0d2ced60a31b6044820152606401610622565b600b5460408051918252602082018390527f828cf983933545af35b9ba46eec951db1cb4c5433c3ec403aeced2963c264790910160405180910390a1600b55565b6001600160a01b0381166000908152600360205260408120600201544210610cb8576001600160a01b0382166000908152600360205260409020600201546105b6565b4292915050565b610cc761189c565b610b2860006118e8565b60048181548110610ce157600080fd5b6000918252602090912001546001600160a01b0316905081565b610d0361189c565b6002546001600160a01b0390811690831603610d615760405162461bcd60e51b815260206004820152601d60248201527f43616e6e6f74207769746864726177207374616b696e6720746f6b656e0000006044820152606401610622565b6001600160a01b03821660009081526003602052604090206004015415610dca5760405162461bcd60e51b815260206004820152601c60248201527f43616e6e6f742077697468647261772072657761726420746f6b656e000000006044820152606401610622565b600154610df09061010090046001600160a01b03166001600160a01b0384169083611823565b604080516001600160a01b0384168152602081018390527f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa2891016106f1565b610e376117e0565b610e3f611959565b3360005b600454811015610f3857600060048281548110610e6257610e62611db3565b6000918252602090912001546001600160a01b03169050610e82816116da565b6001600160a01b038216600090815260036020526040902060050155610ea781610c75565b6001600160a01b03808316600090815260036020526040902060040191909155831615610f2557610ed88382610522565b6001600160a01b0380851660008181526006602090815260408083209487168084529482528083209590955560038152848220600590810154938352815284822093825292909252919020555b5080610f3081611dc9565b915050610e43565b5060008211610f895760405162461bcd60e51b815260206004820152600e60248201527f43616e6e6f74207374616b6520300000000000000000000000000000000000006044820152606401610622565b600b5415610fde576000612710600b5484610fa49190611d67565b610fae9190611d7e565b600a54600254919250610fd0916001600160a01b039081169133911684611996565b610fda8184611d54565b9250505b81600754610fec9190611da0565b6007553360009081526008602052604090205461100a908390611da0565b33600081815260086020526040902091909155600254611037916001600160a01b03909116903085611996565b60405182815233907f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d90602001610923565b6000805b6004548110156111625760006004828154811061108c5761108c611db3565b6000918252602090912001546001600160a01b031690506110ac816116da565b6001600160a01b0382166000908152600360205260409020600501556110d181610c75565b6001600160a01b0380831660009081526003602052604090206004019190915583161561114f576111028382610522565b6001600160a01b0380851660008181526006602090815260408083209487168084529482528083209590955560038152848220600590810154938352815284822093825292909252919020555b508061115a81611dc9565b91505061106d565b506001600160a01b0383811660009081526003602052604090205416331461118957600080fd5b61119e6001600160a01b038416333085611996565b6001600160a01b0383166000908152600360205260409020600201544210611208576001600160a01b0383166000908152600360205260409020600101546111e69083611d7e565b6001600160a01b038416600090815260036020819052604090912001556112ac565b6001600160a01b03831660009081526003602052604081206002015461122f904290611d54565b6001600160a01b038516600090815260036020819052604082200154919250906112599083611d67565b6001600160a01b0386166000908152600360205260409020600101549091506112828286611da0565b61128c9190611d7e565b6001600160a01b0386166000908152600360208190526040909120015550505b6001600160a01b038316600090815260036020526040902042600482018190556001909101546112db91611da0565b6001600160a01b03841660009081526003602090815260409182902060020192909255518381527fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d910160405180910390a1505050565b61133a61189c565b6101f481111561137b5760405162461bcd60e51b815260206004820152600c60248201526b0cccaca40e8dede40d0d2ced60a31b6044820152606401610622565b600c5460408051918252602082018390527f733071ab8253b372ed26a6d1b04aec71c4bfcd209c93397df32bb77478cdd2c8910160405180910390a1600c55565b6001600160a01b0381166000908152600360208190526040822060018101549101546105b69190611d67565b60015461010090046001600160a01b03166001600160a01b0316336001600160a01b0316148061142257506009546001600160a01b031633145b61146e5760405162461bcd60e51b815260206004820152601160248201527f7065726d697373696f6e2064656e6965640000000000000000000000000000006044820152606401610622565b60015460ff161561148157610b286119d5565b610b28611a27565b61149161189c565b6001600160a01b0381166114e75760405162461bcd60e51b815260206004820152600f60248201527f73747261746567697374206973203000000000000000000000000000000000006044820152606401610622565b600954604080516001600160a01b03928316815291831660208301527ff6a8d961ba4f41874e38ad8bed56ca4bcf2356a3dd5bfa626b8a73a0da9f5c69910160405180910390a16009805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b61156561189c565b6001600160a01b0383166000908152600360205260409020600101541561158b57600080fd5b6004805460018181019092557f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b0180546001600160a01b0395861673ffffffffffffffffffffffffffffffffffffffff1991821681179092556000918252600360205260409091208054949095169316929092178355910155565b61160e61189c565b6001600160a01b0381166116645760405162461bcd60e51b815260206004820152601160248201527f666565526563697069656e7420697320300000000000000000000000000000006044820152606401610622565b600a54604080516001600160a01b03928316815291831660208301527faaebcf1bfa00580e41d966056b48521fa9f202645c86d4ddf28113e617c1b1d3910160405180910390a1600a805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b600060075460000361170557506001600160a01b031660009081526003602052604090206005015490565b6007546001600160a01b03831660009081526003602081905260409091209081015460049091015461173685610c75565b6117409190611d54565b61174a9190611d67565b61175c90670de0b6b3a7640000611d67565b6117669190611d7e565b6001600160a01b0383166000908152600360205260409020600501546105b69190611da0565b61179461189c565b6001600160a01b0381166117d7576040517f1e4fbdf700000000000000000000000000000000000000000000000000000000815260006004820152602401610622565b610936816118e8565b60026000540361181c576040517f3ee5aeb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6002600055565b6040516001600160a01b0383811660248301526044820183905261189791859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611a62565b505050565b6001546001600160a01b03610100909104163314610b28576040517f118cdaa7000000000000000000000000000000000000000000000000000000008152336004820152602401610622565b600180546001600160a01b038381166101008181027fffffffffffffffffffffff0000000000000000000000000000000000000000ff85161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60015460ff1615610b28576040517fd93c066500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040516001600160a01b0384811660248301528381166044830152606482018390526119cf9186918216906323b872dd90608401611850565b50505050565b6119dd611ade565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b611a2f611959565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833611a0a565b6000611a776001600160a01b03841683611b1a565b90508051600014158015611a9c575080806020019051810190611a9a9190611de2565b155b15611897576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b0384166004820152602401610622565b60015460ff16610b28576040517f8dfc202b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60606105b38383600084600080856001600160a01b03168486604051611b409190611e04565b60006040518083038185875af1925050503d8060008114611b7d576040519150601f19603f3d011682016040523d82523d6000602084013e611b82565b606091505b5091509150611b92868383611b9e565b925050505b9392505050565b606082611bb357611bae82611c13565b611b97565b8151158015611bca57506001600160a01b0384163b155b15611c0c576040517f9996b3150000000000000000000000000000000000000000000000000000000081526001600160a01b0385166004820152602401610622565b5080611b97565b805115611c235780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80356001600160a01b0381168114611c6c57600080fd5b919050565b60008060408385031215611c8457600080fd5b611c8d83611c55565b9150611c9b60208401611c55565b90509250929050565b60008060408385031215611cb757600080fd5b611cc083611c55565b946020939093013593505050565b600060208284031215611ce057600080fd5b5035919050565b600060208284031215611cf957600080fd5b6105b382611c55565b600080600060608486031215611d1757600080fd5b611d2084611c55565b9250611d2e60208501611c55565b9150604084013590509250925092565b634e487b7160e01b600052601160045260246000fd5b818103818111156105b6576105b6611d3e565b80820281158282048414176105b6576105b6611d3e565b600082611d9b57634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156105b6576105b6611d3e565b634e487b7160e01b600052603260045260246000fd5b600060018201611ddb57611ddb611d3e565b5060010190565b600060208284031215611df457600080fd5b81518015158114611b9757600080fd5b6000825160005b81811015611e255760208186018101518583015201611e0b565b50600092019182525091905056fea26469706673582212207c993bcf8253a3f4a5c9926b3615e22abb42a0298f75abccea93b696e5daa5a364736f6c63430008150033

Verified Source Code Full Match

Compiler: v0.8.21+commit.d9974bed EVM: paris Optimization: Yes (1000 runs)
TBANKStaking.sol 321 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

/***
 TTTTT  BBBBB   A   N   N  K   K
   T    B   B  A A  NN  N  K  K
   T    BBBBB  A A  N N N  KK
   T    B   B AAAAA N  NN  K  K
   T    BBBBB A   A N   N  K   K
***/


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

contract TBANKStaking is ReentrancyGuard, Pausable, Ownable {
    using SafeERC20 for IERC20;

    /* ========== STATE VARIABLES ========== */

    struct Reward {
        address rewardsDistributor;
        uint256 rewardsDuration;
        uint256 periodFinish;
        uint256 rewardRate;
        uint256 lastUpdateTime;
        uint256 rewardPerTokenStored;
    }
    IERC20 public stakingToken;
    mapping(address => Reward) public rewardData;
    address[] public rewardTokens;

    // user -> reward token -> amount
    mapping(address => mapping(address => uint256))
        public userRewardPerTokenPaid;
    mapping(address => mapping(address => uint256)) public rewards;

    uint256 private _totalSupply;
    mapping(address => uint256) private _balances;

    address public strategist;
    address public feeRecipient;

    uint256 public constant MAX_FEE = 500; // 5%
    uint256 public depositFee = 0; // 0%
    uint256 public withdrawFee = 0; // 0%


    /* ========== CONSTRUCTOR ========== */

    modifier onlyOwnerOrStrategist() {
        require(
            msg.sender == owner() || msg.sender == strategist,
            "permission denied"
        );
        _;
    }

    constructor(address _stakingToken) Ownable(msg.sender) {
        stakingToken = IERC20(_stakingToken);
        strategist = msg.sender;
        feeRecipient = msg.sender;
    }

    function togglePause() external onlyOwnerOrStrategist {
        if (paused()) _unpause();
        else _pause();
    }

    function setStrategist(address _strategist) external onlyOwner {
        require(_strategist != address(0), "strategist is 0");
        emit StrategistUpdated(strategist, _strategist);
        strategist = _strategist;
    }

    function setFeeRecipient(address _feeRecipient) external onlyOwner {
        require(_feeRecipient != address(0), "feeRecipient is 0");
        emit FeeRecipientUpdated(feeRecipient, _feeRecipient);
        feeRecipient = _feeRecipient;
    }

    function setDepositFee(uint256 _depositFee) external onlyOwner {
        require(_depositFee <= MAX_FEE, "fee too high");
        emit DepositFeeUpdated(depositFee, _depositFee);
        depositFee = _depositFee;
    }

    function setWithdrawFee(uint256 _withdrawFee) external onlyOwner {
        require(_withdrawFee <= MAX_FEE, "fee too high");
        emit WithdrawFeeUpdated(withdrawFee, _withdrawFee);
        withdrawFee = _withdrawFee;
    }

    function addReward(
        address _rewardsToken,
        address _rewardsDistributor,
        uint256 _rewardsDuration
    ) public onlyOwner {
        require(rewardData[_rewardsToken].rewardsDuration == 0);
        rewardTokens.push(_rewardsToken);
        rewardData[_rewardsToken].rewardsDistributor = _rewardsDistributor;
        rewardData[_rewardsToken].rewardsDuration = _rewardsDuration;
    }

    /* ========== VIEWS ========== */

    function totalSupply() external view returns (uint256) {
        return _totalSupply;
    }

    function balanceOf(address account) external view returns (uint256) {
        return _balances[account];
    }

    function lastTimeRewardApplicable(
        address _rewardsToken
    ) public view returns (uint256) {
        return (block.timestamp < rewardData[_rewardsToken].periodFinish
            ? block.timestamp
            : rewardData[_rewardsToken].periodFinish);
    }

    function rewardPerToken(
        address _rewardsToken
    ) public view returns (uint256) {
        if (_totalSupply == 0) {
            return rewardData[_rewardsToken].rewardPerTokenStored;
        }
        return
            rewardData[_rewardsToken].rewardPerTokenStored +
            (((lastTimeRewardApplicable(_rewardsToken) -
                rewardData[_rewardsToken].lastUpdateTime) *
                rewardData[_rewardsToken].rewardRate) * 1e18) /
            _totalSupply;
    }

    function earned(
        address account,
        address _rewardsToken
    ) public view returns (uint256) {
        return
            ((_balances[account] *
                (rewardPerToken(_rewardsToken) -
                    userRewardPerTokenPaid[account][_rewardsToken])) / 1e18) +
            rewards[account][_rewardsToken];
    }

    function getRewardForDuration(
        address _rewardsToken
    ) external view returns (uint256) {
        return
            rewardData[_rewardsToken].rewardRate *
            rewardData[_rewardsToken].rewardsDuration;
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    function setRewardsDistributor(
        address _rewardsToken,
        address _rewardsDistributor
    ) external onlyOwnerOrStrategist {
        rewardData[_rewardsToken].rewardsDistributor = _rewardsDistributor;
    }

    function stake(
        uint256 amount
    ) external nonReentrant whenNotPaused updateReward(msg.sender) {
        require(amount > 0, "Cannot stake 0");

        if (depositFee > 0) {
            uint256 _fee = (amount * depositFee) / 10000;
            stakingToken.safeTransferFrom(msg.sender, feeRecipient, _fee);
            amount = amount - _fee;
        }

        _totalSupply = _totalSupply + amount;
        _balances[msg.sender] = _balances[msg.sender] + amount;

        stakingToken.safeTransferFrom(msg.sender, address(this), amount);

        emit Staked(msg.sender, amount);
    }

    function withdraw(
        uint256 amount
    ) public nonReentrant updateReward(msg.sender) {
        require(amount > 0, "Cannot withdraw 0");

        _totalSupply = _totalSupply - amount;
        _balances[msg.sender] = _balances[msg.sender] - amount;

        if (withdrawFee > 0) {
            uint256 fee = (amount * withdrawFee) / 10000;
            stakingToken.safeTransfer(feeRecipient, fee);
            amount = amount - fee;
        }
        stakingToken.safeTransfer(msg.sender, amount);

        emit Withdrawn(msg.sender, amount);
    }

    function getReward() public nonReentrant updateReward(msg.sender) {
        for (uint i; i < rewardTokens.length; i++) {
            address _rewardsToken = rewardTokens[i];
            uint256 reward = rewards[msg.sender][_rewardsToken];
            if (reward > 0) {
                rewards[msg.sender][_rewardsToken] = 0;
                IERC20(_rewardsToken).safeTransfer(msg.sender, reward);
                emit RewardPaid(msg.sender, _rewardsToken, reward);
            }
        }
    }


    /* ========== RESTRICTED FUNCTIONS ========== */

    function notifyRewardAmount(
        address _rewardsToken,
        uint256 reward
    ) external updateReward(address(0)) {
        require(rewardData[_rewardsToken].rewardsDistributor == msg.sender);
        // handle the transfer of reward tokens via `transferFrom` to reduce the number
        // of transactions required and ensure correctness of the reward amount
        IERC20(_rewardsToken).safeTransferFrom(
            msg.sender,
            address(this),
            reward
        );

        if (block.timestamp >= rewardData[_rewardsToken].periodFinish) {
            rewardData[_rewardsToken].rewardRate =
                reward /
                (rewardData[_rewardsToken].rewardsDuration);
        } else {
            uint256 remaining = rewardData[_rewardsToken].periodFinish -
                (block.timestamp);
            uint256 leftover = remaining *
                (rewardData[_rewardsToken].rewardRate);
            rewardData[_rewardsToken].rewardRate =
                (reward + leftover) /
                (rewardData[_rewardsToken].rewardsDuration);
        }

        rewardData[_rewardsToken].lastUpdateTime = block.timestamp;
        rewardData[_rewardsToken].periodFinish =
            block.timestamp +
            (rewardData[_rewardsToken].rewardsDuration);
        emit RewardAdded(reward);
    }

    // Added to support recovering LP Rewards from other systems such as BAL to be distributed to holders
    function recoverERC20(
        address tokenAddress,
        uint256 tokenAmount
    ) external onlyOwner {
        require(
            tokenAddress != address(stakingToken),
            "Cannot withdraw staking token"
        );
        require(
            rewardData[tokenAddress].lastUpdateTime == 0,
            "Cannot withdraw reward token"
        );
        IERC20(tokenAddress).safeTransfer(owner(), tokenAmount);
        emit Recovered(tokenAddress, tokenAmount);
    }

    function setRewardsDuration(
        address _rewardsToken,
        uint256 _rewardsDuration
    ) external  {
        require(
            block.timestamp > rewardData[_rewardsToken].periodFinish,
            "Reward period still active"
        );
        require(rewardData[_rewardsToken].rewardsDistributor == msg.sender);
        require(_rewardsDuration > 0, "Reward duration must be non-zero");
        rewardData[_rewardsToken].rewardsDuration = _rewardsDuration;
        emit RewardsDurationUpdated(
            _rewardsToken,
            rewardData[_rewardsToken].rewardsDuration
        );
    }

    /* ========== MODIFIERS ========== */

    modifier updateReward(address account) {
        for (uint i; i < rewardTokens.length; i++) {
            address token = rewardTokens[i];
            rewardData[token].rewardPerTokenStored = rewardPerToken(token);
            rewardData[token].lastUpdateTime = lastTimeRewardApplicable(token);
            if (account != address(0)) {
                rewards[account][token] = earned(account, token);
                userRewardPerTokenPaid[account][token] = rewardData[token]
                    .rewardPerTokenStored;
            }
        }
        _;
    }

    /* ========== EVENTS ========== */

    event RewardAdded(uint256 reward);
    event Staked(address indexed user, uint256 amount);
    event Withdrawn(address indexed user, uint256 amount);
    event RewardPaid(
        address indexed user,
        address indexed rewardsToken,
        uint256 reward
    );
    event RewardsDurationUpdated(address token, uint256 newDuration);
    event Recovered(address token, uint256 amount);
    event Invested(address indexed strategist, uint256 amount);
    event StrategistUpdated(address oldStrategist, address newStrategist);
    event FeeRecipientUpdated(address oldFeeRecipient, address newFeeRecipient);
    event DepositFeeUpdated(uint256 oldDepositFee, uint256 newDepositFee);
    event WithdrawFeeUpdated(uint256 oldWithdrawFee, uint256 newWithdrawFee);
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

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

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

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

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

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

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
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);
    }
}
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());
    }
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

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

    uint256 private _status;

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

    constructor() {
        _status = NOT_ENTERED;
    }

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

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

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

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

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

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

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

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

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

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

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

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

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

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

Read Contract

MAX_FEE 0xbc063e1a → uint256
balanceOf 0x70a08231 → uint256
depositFee 0x67a52793 → uint256
earned 0x211dc32d → uint256
feeRecipient 0x46904840 → address
getRewardForDuration 0xbcd11014 → uint256
lastTimeRewardApplicable 0x638634ee → uint256
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
rewardData 0x48e5d9f8 → address, uint256, uint256, uint256, uint256, uint256
rewardPerToken 0xf1229777 → uint256
rewardTokens 0x7bb7bed1 → address
rewards 0xe70b9e27 → uint256
stakingToken 0x72f702f3 → address
strategist 0x1fe4a686 → address
totalSupply 0x18160ddd → uint256
userRewardPerTokenPaid 0x7035ab98 → uint256
withdrawFee 0xe941fa78 → uint256

Write Contract 15 functions

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

addReward 0xd0ed26ae
address _rewardsToken
address _rewardsDistributor
uint256 _rewardsDuration
getReward 0x3d18b912
No parameters
notifyRewardAmount 0xb66503cf
address _rewardsToken
uint256 reward
recoverERC20 0x8980f11f
address tokenAddress
uint256 tokenAmount
renounceOwnership 0x715018a6
No parameters
setDepositFee 0x490ae210
uint256 _depositFee
setFeeRecipient 0xe74b981b
address _feeRecipient
setRewardsDistributor 0x3f695b45
address _rewardsToken
address _rewardsDistributor
setRewardsDuration 0x2378bea6
address _rewardsToken
uint256 _rewardsDuration
setStrategist 0xc7b9d530
address _strategist
setWithdrawFee 0xb6ac642a
uint256 _withdrawFee
stake 0xa694fc3a
uint256 amount
togglePause 0xc4ae3168
No parameters
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x2e1a7d4d
uint256 amount

Recent Transactions

No transactions found for this address