Contract 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 1

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x85e9549f3f373e8ae8a9769cbace5cc51c398b3d6c97374841e4d0456e97faffGet Reward1173743612023-08-02 9:42:01265 days 7 hrs ago0x3d49c72784c4558366c3088779e3d26d2c5e1702 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.000035640.1
0x088e70dbd6329b4a5bf8d80004020a4cc50cb0013ed0b6e1a61a74d574937728Withdraw1170628642023-08-01 10:54:15266 days 6 hrs ago0x3d49c72784c4558366c3088779e3d26d2c5e1702 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00006314 0.1
0x4072f162afb7b30523ef65cf9fb8e460592b663185fbf1e68672007e36727f25Withdraw1081841092023-07-05 17:24:55292 days 23 hrs ago0x6e868846b2182235c16fd122fcd44739e55a58e4 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.000112560.1
0x051441dcc39c2b729839988d0dd421e7f35338b5a95b078578c556b9d6983ef7Withdraw730764152023-03-24 5:32:25396 days 11 hrs ago0x50b975b022abcbb16e7d8398e7143c6cfae66c74 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00005456 0.1
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075User_checkpoint716315532023-03-20 2:43:16400 days 14 hrs ago0x947b7742c403f20e5faccdac5e092c943e7d0277 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.000059170.1
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84Withdraw702657252023-03-16 2:47:10404 days 14 hrs ago0x43cd745bd5fbfc8cfd79ebc855f949abc79a1e0c IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00008869 0.1
0x88ff52efa8421af85ab0c042b10f95ac6b7bd2915704ad30774631de3af6c1daWithdraw699616792023-03-15 4:37:18405 days 12 hrs ago0x9b590cae0949b46aade82bdfbf9fe427173a948e IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00009641 0.1
0xc50a5ba79d08b7f1c46b149caca72f44f252d31973703d821ccb317265f6fe4bWithdraw622825272023-02-19 2:11:46429 days 15 hrs ago0xaf965aa261db754c7af98b6d4988f27c8e594327 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00008158 0.1
0xab68b11a401fb2f9b36d4ef91184959eef97ad2689517b36e409e5b4b732707bWithdraw592257722023-02-08 21:54:37439 days 19 hrs ago0xeb4576fe753dab07635c0bb6c8f0a355e1db5d31 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.000107660.1
0x6d728d99ec0bc7bb3bc05d2a464bc34eaacfd39941d562c0153392bfc05bff5bGet Reward564888352023-01-30 0:06:16449 days 17 hrs ago0xb8c5bb7d01294f5148488786ac9578e97ffb95fd IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00006302 0.1
0x750e22049519c949f78ab0f470d9f118a2f0643ee55a6d85ed87a297da845511Withdraw558600002023-01-27 12:37:42452 days 4 hrs ago0x43cd745bd5fbfc8cfd79ebc855f949abc79a1e0c IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00007436 0.1
0x936918647ca0c9adcca41e5edfd38ad72b25b67bf6165f54876055950cf88659Withdraw545217292023-01-21 14:48:08458 days 2 hrs ago0x934d96724147328d9b376d5d532c2455f31f089b IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.000077290.1
0xe1b87399617ba411652ead83fe540492b0f91fc990c881a4c2f6e56b030c3549Get Reward543213532023-01-20 16:30:41459 days 45 mins ago0xeb00af6fe0eed4425bb48cf516d85e5edb08d6be IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00007941 0.1
0x4d419d0d78788759f2ac23425bc727f6f6560541d2f56243c4bf8122fc7786beWithdraw543212252023-01-20 16:30:02459 days 46 mins ago0xeb00af6fe0eed4425bb48cf516d85e5edb08d6be IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00010566 0.1
0xfad3f743ab93fcf0c1296154c8fc2cc4c66d1b2a0801b7b9f1bd460f66910f0bWithdraw539698482023-01-18 21:01:51460 days 20 hrs ago0xb6741a6d8829bee4f8139a31261a8610961a2548 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00010045 0.1
0x13208553e96924306a6e36c1f7623fcb4cbfe28410cb2f127becab14730ea4a9Get Reward531678702023-01-15 5:54:55464 days 11 hrs ago0x3a212d3d7504dc4a39e21c731d0e80b114a2108b IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00005889 0.1
0x6e86eb6557e1ab35b9c12bbf15ce2c6d4e765f66d0d752773e1c26b62a14ea42Withdraw531668952023-01-15 5:46:53464 days 11 hrs ago0x3a212d3d7504dc4a39e21c731d0e80b114a2108b IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00007907 0.1
0xa605fca63b8bac73d5878417d16de722f7cdfc4d9e8919a0bc72cb87e9789829Withdraw530743852023-01-14 17:56:59464 days 23 hrs ago0xbe187c30a0176aac698cae51c9a786c802de8f1a IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00008918 0.1
0x155d5255b6c818e0f16e9bbbe7c63c1305c1bfcfdb125080a09c920ef1ed0345Get Reward530743172023-01-14 17:56:28464 days 23 hrs ago0xbe187c30a0176aac698cae51c9a786c802de8f1a IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.0000706 0.1
0x08b762079b21a614a6c20ead232fc6e7f07f6463bf3f275c59444b66e48c595cWithdraw529681642023-01-14 8:21:44465 days 8 hrs ago0x4796e4afd565e43b7267f1688ec09b6a246cb5fc IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00008103 0.1
0x27714f5d8c4deb05fcd7ad1a4df07d479a1799db2aa76daf8a265efd28722910Withdraw528865772023-01-14 0:24:16465 days 16 hrs ago0xaf965aa261db754c7af98b6d4988f27c8e594327 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00009113 0.1
0x98192c95988a8f87447174b210f94d0723329c2aa8429cede8df71e70807af9dWithdraw526725242023-01-13 1:42:27466 days 15 hrs ago0xd2dc63192e14d65a64c4d473ae006dce23be33d6 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.000082140.1
0xd85f02817e1883e73fd0b08e9b73f96d8c6a099eeb49ea8310934d463b7e7f0bWithdraw525849042023-01-12 15:52:18467 days 1 hr ago0xf4a8e405481a15923c13022016ea33827ae87469 IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.0000871 0.1
0xf82037468be780c6aaaf69e53c369cdcccb95355103853365453bd2472ae7d34Withdraw525033772023-01-12 8:42:03467 days 8 hrs ago0xe0a09b49721fbd8b23c67a3a9fde44be4412b8fd IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00008178 0.1
0x6cc0d66b5507ffd367c17bbe128bdb24902123fee5aca6a73f27eaf440f7b31fWithdraw521766042023-01-10 23:18:46468 days 17 hrs ago0x984ff362c105cd8fa55d816ddefdd5889710bcec IN  0x8ec22ec81e740e0f9310e7318d03c494e62a70cd0 ETH0.00009932 0.1
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075716315532023-03-20 2:43:16400 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xb952a807345991bd529fdded05009f5e80fe8f450 ETH
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075716315532023-03-20 2:43:16400 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xf403c135812408bfbe8713b5a23a04b3d48aae310 ETH
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075716315532023-03-20 2:43:16400 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x11cdb42b0eb46d95f990bedd4695a6e3fa0349780 ETH
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075716315532023-03-20 2:43:16400 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xedccb35798fae4925718a43cc608ae136208aa8d0 ETH
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075716315532023-03-20 2:43:16400 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x6339ef8df0c2d3d3e7ee697e241666a916b815870 ETH
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075716315532023-03-20 2:43:16400 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xf403c135812408bfbe8713b5a23a04b3d48aae310 ETH
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075716315532023-03-20 2:43:16400 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x6339ef8df0c2d3d3e7ee697e241666a916b815870 ETH
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075716315532023-03-20 2:43:16400 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xf403c135812408bfbe8713b5a23a04b3d48aae310 ETH
0x76f9f50f7865827a8c0083643a5c078c412130916e363b8073f26f1c52138075716315532023-03-20 2:43:16400 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x3b2d30734491ad77880d31e8afe2a4d8ac135a9c0 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xf403c135812408bfbe8713b5a23a04b3d48aae310 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xb952a807345991bd529fdded05009f5e80fe8f450 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xf403c135812408bfbe8713b5a23a04b3d48aae310 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x11cdb42b0eb46d95f990bedd4695a6e3fa0349780 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xedccb35798fae4925718a43cc608ae136208aa8d0 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x6339ef8df0c2d3d3e7ee697e241666a916b815870 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xf403c135812408bfbe8713b5a23a04b3d48aae310 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x6339ef8df0c2d3d3e7ee697e241666a916b815870 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xf403c135812408bfbe8713b5a23a04b3d48aae310 ETH
0x3534ea32e4b00ce4716bae5e7769477472c9820ca8a09554632fdeefc3fc4b84702657252023-03-16 2:47:10404 days 14 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x3b2d30734491ad77880d31e8afe2a4d8ac135a9c0 ETH
0x88ff52efa8421af85ab0c042b10f95ac6b7bd2915704ad30774631de3af6c1da699616792023-03-15 4:37:18405 days 12 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xf403c135812408bfbe8713b5a23a04b3d48aae310 ETH
0x88ff52efa8421af85ab0c042b10f95ac6b7bd2915704ad30774631de3af6c1da699616792023-03-15 4:37:18405 days 12 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xb952a807345991bd529fdded05009f5e80fe8f450 ETH
0x88ff52efa8421af85ab0c042b10f95ac6b7bd2915704ad30774631de3af6c1da699616792023-03-15 4:37:18405 days 12 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xf403c135812408bfbe8713b5a23a04b3d48aae310 ETH
0x88ff52efa8421af85ab0c042b10f95ac6b7bd2915704ad30774631de3af6c1da699616792023-03-15 4:37:18405 days 12 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x11cdb42b0eb46d95f990bedd4695a6e3fa0349780 ETH
0x88ff52efa8421af85ab0c042b10f95ac6b7bd2915704ad30774631de3af6c1da699616792023-03-15 4:37:18405 days 12 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0xedccb35798fae4925718a43cc608ae136208aa8d0 ETH
0x88ff52efa8421af85ab0c042b10f95ac6b7bd2915704ad30774631de3af6c1da699616792023-03-15 4:37:18405 days 12 hrs ago 0x8ec22ec81e740e0f9310e7318d03c494e62a70cd 0x6339ef8df0c2d3d3e7ee697e241666a916b815870 ETH
[ Download CSV Export 
Loading

Minimal Proxy Contract for 0x3b2d30734491ad77880d31e8afe2a4d8ac135a9c

Contract Name:
ConvexRewardPool

Compiler Version
v0.8.10+commit.fc410830

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license
Decompile ByteCode

Contract Source Code (Solidity)

Similar Contracts
/**
 *Submitted for verification at Arbiscan.io on 2022-11-16
*/

// File: contracts\interfaces\IGauge.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

interface IGauge {
    function deposit(uint256) external;
    function balanceOf(address) external view returns (uint256);
    function working_balances(address) external view returns (uint256);
    function totalSupply() external view returns (uint256);
    function working_supply() external view returns (uint256);
    function withdraw(uint256) external;
    function claim_rewards() external;
    function claim_rewards(address _account) external;
    function lp_token() external view returns(address);
    function set_rewards_receiver(address _receiver) external;
    function reward_count() external view returns(uint256);
    function reward_tokens(uint256 _rid) external view returns(address _rewardToken);
    function reward_data(address _reward) external view returns(address distributor, uint256 period_finish, uint256 rate, uint256 last_update, uint256 integral);
    function claimed_reward(address _account, address _token) external view returns(uint256);
    function claimable_reward(address _account, address _token) external view returns(uint256);
    function claimable_tokens(address _account) external returns(uint256);
    function inflation_rate(uint256 _week) external view returns(uint256);
    function period() external view returns(uint256);
    function period_timestamp(uint256 _period) external view returns(uint256);
    // function claimable_reward_write(address _account, address _token) external returns(uint256);
    function add_reward(address _reward, address _distributor) external;
    function set_reward_distributor(address _reward, address _distributor) external;
    function deposit_reward_token(address _reward, uint256 _amount) external;
    function manager() external view returns(address _manager);
}

// File: contracts\interfaces\IBooster.sol

pragma solidity 0.8.10;

interface IBooster {
   function isShutdown() external view returns(bool);
   function withdrawTo(uint256,uint256,address) external;
   function claimCrv(uint256 _pid, address _gauge) external;
   function setGaugeRedirect(uint256 _pid) external returns(bool);
   function owner() external view returns(address);
   function rewardManager() external view returns(address);
   function feeDeposit() external view returns(address);
   function factoryCrv(address _factory) external view returns(address _crv);
   function calculatePlatformFees(uint256 _amount) external view returns(uint256);
   function addPool(address _lptoken, address _gauge, address _factory) external returns(bool);
   function shutdownPool(uint256 _pid) external returns(bool);
   function poolInfo(uint256) external view returns(address _lptoken, address _gauge, address _rewards,bool _shutdown, address _factory);
   function poolLength() external view returns (uint256);
   function activeMap(address) external view returns(bool);
   function fees() external view returns(uint256);
   function setPoolManager(address _poolM) external;
}

// File: contracts\interfaces\IRewardHook.sol

pragma solidity 0.8.10;

interface IRewardHook {
    function onRewardClaim() external;
    function rewardManager() external view returns(address);
    function poolRewardLength(address _pool) external view returns(uint256);
    // function poolRewardList(address _pool) external view returns(address[] memory _rewardContractList);
    function poolRewardList(address _pool, uint256 _index) external view returns(address _rewardContract);
    function clearPoolRewardList(address _pool) external;
    function addPoolReward(address _pool, address _rewardContract) external;
}

// File: contracts\interfaces\IRewardManager.sol

pragma solidity 0.8.10;

interface IRewardManager {
    function rewardHook() external view returns(address);
    function cvx() external view returns(address);
}

// File: @openzeppelin\contracts\token\ERC20\IERC20.sol

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

    /**
     * @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);
}

// File: @openzeppelin\contracts\token\ERC20\extensions\IERC20Metadata.sol

pragma solidity ^0.8.0;

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
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);
}

// File: @openzeppelin\contracts\utils\Context.sol


pragma solidity ^0.8.0;

/**
 * @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;
    }
}

// File: @openzeppelin\contracts\token\ERC20\ERC20.sol


pragma solidity ^0.8.0;



/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - amount);
        }

        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);

        _afterTokenTransfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {}
}

// File: @openzeppelin\contracts\utils\Address.sol

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

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

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

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // 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 {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

// File: @openzeppelin\contracts\token\ERC20\utils\SafeERC20.sol


pragma solidity ^0.8.0;


/**
 * @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;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

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

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

// File: @openzeppelin\contracts\security\ReentrancyGuard.sol


pragma solidity ^0.8.0;

/**
 * @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;

    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 make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

        _;

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

// File: contracts\ConvexRewardPool.sol

pragma solidity 0.8.10;

//claim and distribute gauge rewards without need of harvesters
//more gas cost but no delayed rewards
//
//Reward distro based on Curve.fi's gauge wrapper implementations at https://github.com/curvefi/curve-dao-contracts/tree/master/contracts/gauges/wrappers
contract ConvexRewardPool is ERC20, ReentrancyGuard{
    using SafeERC20 for IERC20;

    struct EarnedData {
        address token;
        uint256 amount;
    }

    struct RewardType {
        address reward_token;
        uint128 reward_integral;
        uint128 reward_remaining;
    }

    //pool and system info
    address public curveGauge;
    address public convexStaker;
    address public convexBooster;
    uint256 public convexPoolId;


    //rewards
    RewardType[] public rewards;
    mapping(address => mapping(address => uint256)) public reward_integral_for;// token -> account -> integral
    mapping(address => mapping(address => uint256)) public claimable_reward;//token -> account -> claimable
    mapping(address => bool) public rewardMap;
    address public rewardHook;
    address public crv;

    //management
    string internal _tokenname;
    string internal _tokensymbol;

    //events
    event Staked(address indexed _user, uint256 _amount);
    event Withdrawn(address indexed _user, uint256 _amount);
    event RewardPaid(address indexed _user, address indexed _rewardToken, address indexed _receiver, uint256 _rewardAmount);
    event RewardAdded(address indexed _rewardToken);

    constructor() ERC20(
            "TokenizedConvexPosition",
            "cvxToken"
        ){
    }

    function initialize(
        address _crv,
        address _curveGauge,
        address _convexStaker,
        address _convexBooster,
        address _lptoken,
        uint256 _poolId)
    external {
        require(bytes(_tokenname).length == 0, "already init");

        crv = _crv;
        curveGauge = _curveGauge;
        convexStaker = _convexStaker;
        convexBooster = _convexBooster;
        convexPoolId = _poolId;

        _tokenname = string(abi.encodePacked(ERC20(_lptoken).name()," Convex Deposit"));
        _tokensymbol = string(abi.encodePacked("cvx", ERC20(_lptoken).symbol()));

        //always add CRV in first slot
        _insertRewardToken(_crv);

        //add CVX in second slot
        address rmanager = IBooster(convexBooster).rewardManager();
        _insertRewardToken(IRewardManager(rmanager).cvx());

        //set default hook
        rewardHook = IRewardManager(rmanager).rewardHook();
    }

    function name() public view override returns (string memory) {
        return _tokenname;
    }

    function symbol() public view override returns (string memory) {
        return _tokensymbol;
    }

    function decimals() public pure override returns (uint8) {
        return 18;
    }

    //check curve gauge for any reward tokens
    function updateRewardList() public {

        //max rewards 8, need to check if anything new has been added
        for (uint256 i = 0; i < 8; i++) {
            address rewardToken = IGauge(curveGauge).reward_tokens(i);
            if(rewardToken == address(0)) break;

            //add to reward list if new
            _insertRewardToken(rewardToken);
        }
    }

    //register an extra reward token to be handled
    // (any new incentive that is not directly on curve gauges)
    function addExtraReward(address _token) external{
        //reward manager can set extra rewards
        require(IBooster(convexBooster).rewardManager() == msg.sender, "!owner");
        
        //add to reward list
        _insertRewardToken(_token);
    }

    //insert a new reward, ignore if already registered or invalid
    function _insertRewardToken(address _token) internal{
        if(_token == address(this) || _token == address(0)){
            //dont allow reward tracking of the staking token or invalid address
            return;
        }
        //add to reward list if new
        if(!rewardMap[_token]){
            RewardType storage r = rewards.push();
            r.reward_token = _token;
            rewardMap[_token] = true;

            //workaround: transfer 0 to self so that earned() reports correctly
            //with new tokens
            try IERC20(_token).transfer(address(this), 0){}catch{}

            emit RewardAdded(_token);
        }
    }

    //set a reward hook that calls an outside contract to pull external rewards
    function setRewardHook(address _hook) external{
        //reward manager can set reward hook
        require(IBooster(convexBooster).rewardManager() == msg.sender, "!owner");
        rewardHook = _hook;
    }

    //update and claim rewards from all locations
    function updateRewardsAndClaim() internal{
        (,,,bool _shutdown,) = IBooster(convexBooster).poolInfo(convexPoolId);

        if(!_shutdown){
            //make sure reward list is up to date
            updateRewardList();

            //claim crv
            IBooster(convexBooster).claimCrv(convexPoolId, curveGauge);

            //claim rewards from gauge
            IGauge(curveGauge).claim_rewards(convexStaker);

            //hook for external reward pulls
            if(rewardHook != address(0)){
                try IRewardHook(rewardHook).onRewardClaim(){
                }catch{}
            }
        }
    }

    //get reward count
    function rewardLength() external view returns(uint256) {
        return rewards.length;
    }

    //calculate and record an account's earnings of the given reward.  if _claimTo is given it will also claim.
    function _calcRewardIntegral(uint256 _index, address _account, address _claimTo) internal{
        RewardType storage reward = rewards[_index];

        //get difference in balance and remaining rewards
        //getReward is unguarded so we use reward_remaining to keep track of how much was actually claimed since last checkpoint
        uint256 bal = IERC20(reward.reward_token).balanceOf(address(this));

        //if reward token is crv (always slot 0), need to calculate and send fees
        if(_index == 0){
            uint256 diff = bal - reward.reward_remaining;
            uint256 fees = IBooster(convexBooster).calculatePlatformFees(diff);
            if(fees > 0){
                //send to fee deposit to process later
                IERC20(crv).safeTransfer( IBooster(convexBooster).feeDeposit() , fees);
            }
            //remove what was sent as fees
            bal -= fees;
        }

        //update the global integral
        if (totalSupply() > 0 && (bal - reward.reward_remaining) > 0) {
            reward.reward_integral = reward.reward_integral + uint128( (bal - reward.reward_remaining) * 1e20 / totalSupply());
        }

        //update user integrals
        uint userI = reward_integral_for[reward.reward_token][_account];
        if(_claimTo != address(0) || userI < reward.reward_integral){
            //_claimTo address non-zero means its a claim 
            if(_claimTo != address(0)){
                uint256 receiveable = claimable_reward[reward.reward_token][_account] + (balanceOf(_account) * uint256(reward.reward_integral - userI) / 1e20);
                if(receiveable > 0){
                    claimable_reward[reward.reward_token][_account] = 0;
                    IERC20(reward.reward_token).safeTransfer(_claimTo, receiveable);
                    emit RewardPaid(_account, reward.reward_token, _claimTo, receiveable);
                    //remove what was claimed from balance
                    bal -= receiveable;
                }
            }else{
                claimable_reward[reward.reward_token][_account] = claimable_reward[reward.reward_token][_account] + ( balanceOf(_account) * uint256(reward.reward_integral - userI) / 1e20);
            }
            reward_integral_for[reward.reward_token][_account] = reward.reward_integral;
        }


        //update remaining reward so that next claim can properly calculate the balance change
        if(bal != reward.reward_remaining){
            reward.reward_remaining = uint128(bal);
        }
    }

    //checkpoint without claiming
    function _checkpoint(address _account) internal {
        //checkpoint without claiming by passing address(0)
        _checkpoint(_account, address(0));
    }

    //checkpoint with claim
    function _checkpoint(address _account, address _claimTo) internal {
        //update rewards and claim
        updateRewardsAndClaim();

        //calc reward integrals
        uint256 rewardCount = rewards.length;
        for(uint256 i = 0; i < rewardCount; i++){
           _calcRewardIntegral(i,_account,_claimTo);
        }
    }

    //manually checkpoint a user account
    function user_checkpoint(address _account) external nonReentrant returns(bool) {
        _checkpoint(_account);
        return true;
    }

    //get earned token info
    //Note: The curve gauge function "claimable_tokens" is a write function and thus this is not by default a view
    //change ABI to view to use this off chain
    function earned(address _account) external returns(EarnedData[] memory claimable) {
        
        //because this is a state mutative function
        //we can simplify the earned() logic of all rewards (internal and external)
        //and allow this contract to be agnostic to outside reward contract design
        //by just claiming everything and checking token balances
        updateRewardsAndClaim();

        uint256 rewardCount = rewards.length;
        claimable = new EarnedData[](rewardCount);

        for (uint256 i = 0; i < rewardCount; i++) {
            RewardType storage reward = rewards[i];

            //change in reward is current balance - remaining reward + earned
            uint256 bal = IERC20(reward.reward_token).balanceOf(address(this));
            uint256 d_reward = bal - reward.reward_remaining;

            // crv is always slot 0
            if(i == 0){
                //check fees
                uint256 fees = IBooster(convexBooster).calculatePlatformFees(d_reward);
                if(fees > 0){
                    d_reward -= fees;
                }
            }

            //calc new global integral
            uint256 I = reward.reward_integral;
            if (totalSupply() > 0) {
                I = I + (d_reward * 1e20 / totalSupply());
            }

            //user claimable amount = previous recorded claimable + new user integral
            uint256 newlyClaimable = balanceOf(_account) * (I - reward_integral_for[reward.reward_token][_account]) / 1e20;
            claimable[i].amount = claimable_reward[reward.reward_token][_account] + newlyClaimable;
            claimable[i].token = reward.reward_token;
        }
    }

    //claim reward for given account (unguarded)
    function getReward(address _account) external nonReentrant {
        //claim directly in checkpoint logic to save a bit of gas
        _checkpoint(_account, _account);
    }

    //claim reward for given account and forward (guarded)
    function getReward(address _account, address _forwardTo) external nonReentrant {
        //in order to forward, must be called by the account itself
        require(msg.sender == _account, "!self");
        //use _forwardTo address instead of _account
        _checkpoint(_account,_forwardTo);
    }


    //deposit/stake on behalf of another account
    function stakeFor(address _for, uint256 _amount) external nonReentrant returns(bool){
        require(msg.sender == convexBooster, "!auth");
        require(_amount > 0, 'RewardPool : Cannot stake 0');

        //change state
        //assign to _for
        //Mint will checkpoint so safe to not call
        _mint(_for, _amount);

        emit Staked(_for, _amount);
        
        return true;
    }


    //withdraw balance and unwrap to the underlying lp token
    // function withdrawAndUnwrap(uint256 _amount, bool _claim) public nonReentrant returns(bool){
    function withdraw(uint256 _amount, bool _claim) public nonReentrant returns(bool){

        //checkpoint first if claiming, or burn will call checkpoint anyway
        if(_claim){
            //checkpoint with claim flag
            _checkpoint(msg.sender, msg.sender);
        }

        //change state
        //burn will also call checkpoint
        _burn(msg.sender, _amount);

        //tell booster to withdraw underlying lp tokens directly to user
        IBooster(convexBooster).withdrawTo(convexPoolId,_amount,msg.sender);

        emit Withdrawn(msg.sender, _amount);

        return true;
    }

    //withdraw full balance
    function withdrawAll(bool claim) external{
        withdraw(balanceOf(msg.sender),claim);
    }

    function _beforeTokenTransfer(address _from, address _to, uint256 _amount) internal override {
        if(_from != address(0)){
            _checkpoint(_from);
        }
        if(_to != address(0)){
            _checkpoint(_to);
        }
    }
}

Contract ABI

[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_rewardToken","type":"address"}],"name":"RewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":true,"internalType":"address","name":"_rewardToken","type":"address"},{"indexed":true,"internalType":"address","name":"_receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"_rewardAmount","type":"uint256"}],"name":"RewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"addExtraReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"claimable_reward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"convexBooster","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"convexPoolId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"convexStaker","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"crv","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"curveGauge","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"earned","outputs":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct ConvexRewardPool.EarnedData[]","name":"claimable","type":"tuple[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"address","name":"_forwardTo","type":"address"}],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"getReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_crv","type":"address"},{"internalType":"address","name":"_curveGauge","type":"address"},{"internalType":"address","name":"_convexStaker","type":"address"},{"internalType":"address","name":"_convexBooster","type":"address"},{"internalType":"address","name":"_lptoken","type":"address"},{"internalType":"uint256","name":"_poolId","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardHook","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewardMap","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"reward_integral_for","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewards","outputs":[{"internalType":"address","name":"reward_token","type":"address"},{"internalType":"uint128","name":"reward_integral","type":"uint128"},{"internalType":"uint128","name":"reward_remaining","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_hook","type":"address"}],"name":"setRewardHook","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_for","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"stakeFor","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateRewardList","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"user_checkpoint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"bool","name":"_claim","type":"bool"}],"name":"withdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"claim","type":"bool"}],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"}]

Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.