Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x2F47Fad6F16aD87bc5Bd9f837C98e1d6D169A8d4
Balance 0 ETH
Nonce 1
Code Size 6237 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6237 bytes
0x60806040526004361015610011575f80fd5b5f3560e01c806310482e3d146112c457806313e7c9d8146112875780631e2720ff14610ff05780633ef0c35114610f595780634e71d92d14610bd65780635291162314610bad578063558a729714610b3057806369c2389b14610af8578063715018a614610aa15780638259e6a0146109d05780638d0aba17146108725780638da5cb5b1461084b57806396c82e571461082e5780639b1b919c146107ac5780639cfa41f91461078f578063a87430ba14610736578063aaf89fca146105ad578063ac4afa381461055e578063b124df0214610521578063ece8a770146103ec578063ef79d33e14610245578063f2fde38b146101c0578063f40f0f5214610191578063f525cb68146101745763f7c618c11461012c575f80fd5b34610170575f366003190112610170576040517f000000000000000000000000044ca854fa227e27e07652b7f6a6b578703f39456001600160a01b03168152602090f35b5f80fd5b34610170575f366003190112610170576020600254604051908152f35b346101705760203660031901126101705760406101b46101af611357565b61165b565b82519182526020820152f35b34610170576020366003190112610170576101d9611357565b6101e1611748565b6001600160a01b03168015610232575f80546001600160a01b03198116831782556001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09080a3005b631e4fbdf760e01b5f525f60045260245ffd5b346101705760203660031901126101705761025e611357565b335f52600760205261027660ff60405f2054166113f7565b6001600160a01b031661028a811515611432565b805f52600660205260405f209081549182156103b957825f52600560205260405f206001810154670de0b6b3a76400006102ca60018501928354906113dd565b04908161039b575b60028301908154918215610362575f19830192831161034e577f83c393609f95a39c1e07ae5abfbbaeeb5121cfe60cb4528b981e6737be2238eb95602095845f958694551580610344575b61032e575b505555604051908152a3005b61033b90546003546113dd565b60035589610322565b508054151561031d565b634e487b7160e01b5f52601160045260245ffd5b60405162461bcd60e51b81526020600482015260116024820152701a5b9d985b1a59081d5cd95c90dbdd5b9d607a1b6044820152606490fd5b845f52600860205260405f206103b28382546113ea565b90556102d2565b60405162461bcd60e51b815260206004820152600b60248201526a1b9bdd081a5b881c1bdbdb60aa1b6044820152606490fd5b3461017057604036600319011261017057610405611357565b60243590335f52600760205261042160ff60405f2054166113f7565b6001600160a01b0316610435811515611432565b805f52600660205260405f2080546104ea57821515806104de575b6104599061146d565b825f52600560205260405f2060028101805415806104d4575b6104bf575b8054916001830180931161034e5760019283925542600285015585845501549101557f8730defadf31128cae6c179f2e35badcdae73d06e461d14d13f3894b56d7d79f5f80a3005b6104cc82546003546113ea565b600355610477565b5081541515610472565b50600254831115610450565b60405162461bcd60e51b815260206004820152600f60248201526e185b1c9958591e481a5b881c1bdbdb608a1b6044820152606490fd5b34610170576020366003190112610170576001600160a01b03610542611357565b165f526009602052602060ff60405f2054166040519015158152f35b34610170576020366003190112610170576004355f52600560205260405f2080546105a960026001840154930154604051938493846040919493926060820195825260208201520152565b0390f35b346101705760203660031901126101705760043567ffffffffffffffff8111610170576105de90369060040161136d565b90335f5260076020526105f760ff60405f2054166113f7565b6106028215156115c4565b5f5b82811061060d57005b61062061061b8285856115fb565b61161f565b335f52600760205261063860ff60405f2054166113f7565b6001600160a01b03169061064d821515611432565b815f52600660205260405f209182549081156103b957815f52600560205260405f2093600185015494670de0b6b3a764000061068f60018401978854906113dd565b0480610718575b60028201968754908115610362575f19820191821161034e575f7f83c393609f95a39c1e07ae5abfbbaeeb5121cfe60cb4528b981e6737be2238eb9560209584839560019d55158061070e575b6106f8575b505555604051908152a301610604565b61070590546003546113dd565b6003558d6106e8565b50805415156106e3565b835f52600860205260405f2061072f8282546113ea565b9055610696565b34610170576020366003190112610170576001600160a01b03610757611357565b165f52600660205260405f2080546105a960026001840154930154604051938493846040919493926060820195825260208201520152565b34610170575f366003190112610170576020600454604051908152f35b34610170576020366003190112610170576107c5611357565b335f5260076020526107dd60ff60405f2054166113f7565b6001600160a01b03166107f1811515611432565b805f52600960205260405f20600160ff198254161790557f57295f6c5605364a09fa598e0faf60fec630424880bbb954a0ae937b973f6d7b5f80a2005b34610170575f366003190112610170576020600354604051908152f35b34610170575f366003190112610170575f546040516001600160a01b039091168152602090f35b346101705760403660031901126101705760043567ffffffffffffffff8111610170576108a390369060040161136d565b602435335f5260076020526108be60ff60405f2054166113f7565b6108c98215156115c4565b801515925f5b8381106108d857005b6108e661061b8286856115fb565b335f5260076020526108fe60ff60405f2054166113f7565b6001600160a01b031690610913821515611432565b815f52600660205260405f209182546104ea5786806109c4575b6109369061146d565b845f52600560205260405f20906002820193845415806109ba575b6109a5575b84546001810180911161034e576001889481979282935542600285015585845501549101557f8730defadf31128cae6c179f2e35badcdae73d06e461d14d13f3894b56d7d79f5f80a3016108cf565b6109b283546003546113ea565b600355610956565b5082541515610951565b5060025485111561092d565b34610170576020366003190112610170576004356109ec611748565b8015610a6e576002546001810180911161034e5780600255600260405191610a1383611572565b838352602083015f815260408401915f83525f52600560205260405f2093518455516001840155519101557f37d4a71449cd4163b2d08aeed513412fe798bf25bb804c48f90470f32a17308f602060025492604051908152a2005b60405162461bcd60e51b815260206004820152600b60248201526a776569676874207a65726f60a81b6044820152606490fd5b34610170575f36600319011261017057610ab9611748565b5f80546001600160a01b0319811682556001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b34610170576020366003190112610170576001600160a01b03610b19611357565b165f526008602052602060405f2054604051908152f35b3461017057604036600319011261017057610b49611357565b602435908115158092036101705760207f966c160e1c4dbc7df8d69af4ace01e9297c3cf016397b7914971f2fbfa32672d91610b83611748565b60018060a01b031692835f526007825260405f2060ff1981541660ff8316179055604051908152a2005b3461017057604036600319011261017057610bc6611748565b610bd46024356004356114a8565b005b34610170575f36600319011261017057610bee61176e565b335f908152600660205260408120805491908215158281610f24575b335f52600860205260405f205490335f52600960205260ff60405f20541693845f14610f1b57610c3b5f5b836113ea565b928315610eea57600282019384548015610ead576127109162015180610c6f610c67610c7d94426113dd565b6004546113ac565b0490838211610ea5576113ac565b04948515610e6c5785915f965f981580610e63575b610e13575b50508115159081610e09575b81610e01575b50610d86575b505050610cbf93504290556113ea565b8015610d4b57610d1960405163a9059cbb60e01b602082015233602482015282604482015260448152610cf36064826115a2565b7f000000000000000000000000044ca854fa227e27e07652b7f6a6b578703f39456117c4565b6040519081527ff01da32686223933d8a18a391060918c7f11a3648639edd87ae013e2e273174360203392a360018055005b60405162461bcd60e51b81526020600482015260136024820152723737ba3434b733903a37903a3930b739b332b960691b6044820152606490fd5b91945090610da890858110610dfa5785610da2819788936113dd565b506113dd565b670de0b6b3a7640000810290808204670de0b6b3a7640000149015171561034e57610def610ddb610cbf976001936113ea565b885f5260056020528260405f2001546113dd565b910155858080610caf565b80956113dd565b905089610ca9565b8415159150610ca3565b9296509091818110610e42575080610e2b91966113dd565b90335f5260086020525f60408120555b8980610c97565b610e4f91965080966113dd565b335f52600860205260405f20555f90610e3b565b50811515610c92565b60405162461bcd60e51b81526020600482015260116024820152701b1a5b5a5d081b9bdd081c995858da1959607a1b6044820152606490fd5b8391506113ac565b60405162461bcd60e51b815260206004820152601560248201527418db185a5b481b9bdd081a5b9a5d1a585b1a5e9959605a1b6044820152606490fd5b60405162461bcd60e51b81526020600482015260096024820152681b9bc81c995dd85c9960ba1b6044820152606490fd5b610c3b83610c35565b509150825f526005602052610f45600160405f2001546001830154906113dd565b670de0b6b3a7640000808206939104610c0a565b3461017057602036600319011261017057610f72611357565b335f526007602052610f8a60ff60405f2054166113f7565b6001600160a01b0316610f9e811515611432565b805f52600960205260405f2060ff198154169055805f52600660205260405f206002429101557f926fa864ade7f79ff7ba821167dfce9ed6ad94ccc6181e82518368ca1a7c7ae16020604051428152a2005b346101705760203660031901126101705760043561100c61176e565b8015611254576003541561121e5761104e6040516323b872dd60e01b602082015233602482015230604482015282606482015260648152610cf36084826115a2565b6040518181527f7dbc080e4530c8bcf265eb5c9a35ae096ca1eb607b7e802b96581ef4c5e1a70360203392a25f60016002545b808211156111d957505080156111a1578160015b600254811161119b57805f52600560205260405f209081548015801561118f575b6111845781850361115d5750825b831561115157836110d4916113dd565b92670de0b6b3a7640000810292818404670de0b6b3a76400000361034e576040839282611139600161112f61114c9960027f61736aa0052a515c51b1ddb2510cba52a07f40b52c9493b814aab4fc0ddb5bfc980154906113bf565b92019182546113ea565b80915582519182526020820152a261139e565b611095565b925061114c915061139e565b61116a61117391876113ac565b600354906113bf565b92808411156110c4579250826110c4565b5061114c915061139e565b506002830154156110b6565b60018055005b60405162461bcd60e51b815260206004820152601060248201526f1b9bc8195b1a59da589b19481c1bdbdb60821b6044820152606490fd5b9091825f52600560205260405f20805415908115611211575b5061120757506112018261139e565b90611081565b916112019061139e565b60029150015415856111f2565b60405162461bcd60e51b815260206004820152600e60248201526d1b9bc81858dd1a5d99481c1bdbdb60921b6044820152606490fd5b60405162461bcd60e51b815260206004820152600b60248201526a616d6f756e74207a65726f60a81b6044820152606490fd5b34610170576020366003190112610170576001600160a01b036112a8611357565b165f526007602052602060ff60405f2054166040519015158152f35b34610170576020366003190112610170576004356112e0611748565b61271081116113225760407fbdb49d5208e20f1318e77223a864a14dfdcf0180d19676b518396f8a51c1d58791600454908060045582519182526020820152a1005b60405162461bcd60e51b815260206004820152600d60248201526c726174696f20746f6f2062696760981b6044820152606490fd5b600435906001600160a01b038216820361017057565b9181601f840112156101705782359167ffffffffffffffff8311610170576020808501948460051b01011161017057565b5f19811461034e5760010190565b8181029291811591840414171561034e57565b81156113c9570490565b634e487b7160e01b5f52601260045260245ffd5b9190820391821161034e57565b9190820180921161034e57565b156113fe57565b60405162461bcd60e51b815260206004820152600c60248201526b3737ba1037b832b930ba37b960a11b6044820152606490fd5b1561143957565b60405162461bcd60e51b815260206004820152600c60248201526b34b73b30b634b2103ab9b2b960a11b6044820152606490fd5b1561147457565b60405162461bcd60e51b815260206004820152600c60248201526b1a5b9d985b1a59081c1bdbdb60a21b6044820152606490fd5b9081151580611566575b6114bb9061146d565b815f52600560205260405f2080548281146115605782827fac39f4daefcd1c76d5f04ecf5ccba4bd1758ba2e10ed24921209f47df5dabfb294600260409501918254151580611557575b611543575b555415158061153a575b611526575b82519182526020820152a2565b611532816003546113ea565b600355611519565b50801515611514565b61154f856003546113dd565b60035561150a565b50841515611505565b50505050565b506002548211156114b2565b6060810190811067ffffffffffffffff82111761158e57604052565b634e487b7160e01b5f52604160045260245ffd5b90601f8019910116810190811067ffffffffffffffff82111761158e57604052565b156115cb57565b60405162461bcd60e51b81526020600482015260086024820152676e6f20757365727360c01b6044820152606490fd5b919081101561160b5760051b0190565b634e487b7160e01b5f52603260045260245ffd5b356001600160a01b03811681036101705790565b9060405161164081611572565b60406002829480548452600181015460208501520154910152565b60018060a01b031690815f52600660205261167860405f20611633565b915f835180611711575b50815f52600860205260405f2054915f52600960205260ff60405f2054169160406116ad82846113ea565b9501928351158015611709575b611701576116d1929190156116fb57505f906113ea565b9081156116f5576127109162015180610c6f610c676116f19451426113dd565b0490565b50505f90565b906113ea565b505050505f90565b5085156116ba565b90505f526005602052670de0b6b3a7640000611741602061173460405f20611633565b01516020860151906113dd565b045f611682565b5f546001600160a01b0316330361175b57565b63118cdaa760e01b5f523360045260245ffd5b60026001541461177f576002600155565b60405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606490fd5b905f602091828151910182855af11561181c575f513d61181357506001600160a01b0381163b155b6117f35750565b635274afe760e01b5f9081526001600160a01b0391909116600452602490fd5b600114156117ec565b6040513d5f823e3d90fdfea2646970667358221220fda8083f07268ab4a406a98633ea3499e564fe517f646318ab3a53f12685e90d64736f6c634300081e0033

Verified Source Code Full Match

Compiler: v0.8.30+commit.73712a01 EVM: prague Optimization: Yes (200 runs)
RewardPoolManager.sol 392 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

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

contract RewardPoolManager is Ownable, ReentrancyGuard {
    using SafeERC20 for IERC20;

    IERC20 public immutable rewardToken;

    uint256 public poolCount;
    uint256 public totalWeight;

    // dailyWithdrawRatio 精度 1e4,例如 10000 = 100%,5000 = 50%
    uint256 public dailyWithdrawRatio = 2000; // 默认每天最多 20%,可调整

    // 累计奖励精度:对应「每个用户一份」的 1e18 精度
    uint256 private constant ACC_REWARD_PRECISION = 1e18;

    struct Pool {
        uint256 weight;            // 池子的权重
        uint256 accRewardPerShare; // 每份权重累计奖励(ACC_REWARD_PRECISION 精度)
        uint256 userCount;         // 当前池子内用户数量
    }

    struct UserInfo {
        uint256 poolId;        // 所在池子 ID,0 表示未在任何池
        uint256 rewardDebt;    // 对应 pool.accRewardPerShare 的结算基准(ACC_REWARD_PRECISION 精度)
        uint256 lastClaimTime; // 上次领取时间,用于秒级线性释放
    }

    mapping(uint256 => Pool) public pools;
    mapping(address => UserInfo) public users;
    mapping(address => bool) public operators;

    // 用户被移出池子后锁定的剩余奖励(离开池子时的 pending,单位:token)
    mapping(address => uint256) public exitedPending;

    // 冻结标记:true 表示用户的 exitedPending 暂时冻结,不能领取
    mapping(address => bool) public exitedFrozen;

    // -------------------- 事件 --------------------
    event PoolCreated(uint256 indexed poolId, uint256 weight);
    event PoolWeightUpdated(uint256 indexed poolId, uint256 oldWeight, uint256 newWeight);

    event OperatorUpdated(address indexed operator, bool enabled);

    event UserJoinedPool(address indexed user, uint256 indexed poolId);
    event UserRemovedFromPool(address indexed user, uint256 indexed poolId, uint256 lockedReward);

    event RewardDeposited(address indexed operator, uint256 amount);
    event RewardAllocated(uint256 indexed poolId, uint256 amount, uint256 accRewardPerShare);

    event RewardClaimed(address indexed user, uint256 indexed poolId, uint256 amount);

    event DailyWithdrawRatioUpdated(uint256 oldRatio, uint256 newRatio);

    // 冻结 / 解冻退出奖励
    event ExitedRewardFrozen(address indexed user);
    event ExitedRewardUnfrozen(address indexed user, uint256 newLastClaimTime);

    // -------------------- 修饰器 --------------------
    modifier onlyOperator() {
        require(operators[msg.sender], "not operator");
        _;
    }

    constructor(IERC20 _rewardToken) Ownable(msg.sender) {
        rewardToken = _rewardToken;
    }

    // -------------------- 管理员功能 --------------------

    function setOperator(address operator, bool enabled) external onlyOwner {
        operators[operator] = enabled;
        emit OperatorUpdated(operator, enabled);
    }

    function createPool(uint256 weight) external onlyOwner {
        require(weight > 0, "weight zero");

        poolCount += 1;
        pools[poolCount] = Pool({
            weight: weight,
            accRewardPerShare: 0,
            userCount: 0
        });

        emit PoolCreated(poolCount, weight);
    }

    function setPoolWeight(uint256 poolId, uint256 newWeight) external onlyOwner {
        require(poolId != 0 && poolId <= poolCount, "invalid pool");

        Pool storage pool = pools[poolId];
        uint256 oldWeight = pool.weight;

        if (oldWeight == newWeight) {
            return;
        }

        // 先从 totalWeight 中移除旧权重
        if (pool.userCount > 0 && oldWeight > 0) {
            totalWeight -= oldWeight;
        }

        pool.weight = newWeight;

        // 再把新权重加回 totalWeight
        if (pool.userCount > 0 && newWeight > 0) {
            totalWeight += newWeight;
        }

        emit PoolWeightUpdated(poolId, oldWeight, newWeight);
    }

    function setDailyWithdrawRatio(uint256 newRatio) external onlyOwner {
        require(newRatio <= 10000, "ratio too big"); // 不能超过 100%
        uint256 old = dailyWithdrawRatio;
        dailyWithdrawRatio = newRatio;
        emit DailyWithdrawRatioUpdated(old, newRatio);
    }

    // -------------------- 操作员功能 --------------------
    function addUserToPool(address user, uint256 poolId) public onlyOperator {
        require(user != address(0), "invalid user");

        UserInfo storage userInfo = users[user];
        require(userInfo.poolId == 0, "already in pool"); // 只能在不在任何池子的情况下加入新池
        require(poolId != 0 && poolId <= poolCount, "invalid pool");

        Pool storage pool = pools[poolId];

        // 如果池子之前是空池子,则激活它的权重
        if (pool.userCount == 0 && pool.weight > 0) {
            totalWeight += pool.weight;
        }

        pool.userCount += 1;

        // 进入池子就自动把上次领取时间设置为现在
        userInfo.lastClaimTime = block.timestamp;

        // 设置新的池信息和 rewardDebt
        userInfo.poolId = poolId;
        userInfo.rewardDebt = pool.accRewardPerShare;

        emit UserJoinedPool(user, poolId);
    }

    function addUsersToPool(address[] calldata usersToAdd, uint256 poolId) external onlyOperator {
        require(usersToAdd.length > 0, "no users");
        for (uint256 i = 0; i < usersToAdd.length; i++) {
            addUserToPool(usersToAdd[i], poolId);
        }
    }

    function removeUsersFromPool(address[] calldata usersToRemove) external onlyOperator {
        require(usersToRemove.length > 0, "no users");
        for (uint256 i = 0; i < usersToRemove.length; i++) {
            removeUserFromPool(usersToRemove[i]);
        }
    }

    // remove user from pool, stop rewards and move pending to exitedPending
    function removeUserFromPool(address userAddr) public onlyOperator {
        require(userAddr != address(0), "invalid user");

        UserInfo storage user = users[userAddr];
        uint256 poolId = user.poolId;
        require(poolId != 0, "not in pool");

        Pool storage pool = pools[poolId];

        // 1. 计算当前用户在池子里的总 pending,并锁到 exitedPending
        uint256 totalPendingScaled = pool.accRewardPerShare - user.rewardDebt; // ACC_REWARD_PRECISION 精度
        uint256 totalPending = totalPendingScaled / ACC_REWARD_PRECISION;       // 向下取整(丢掉 <1 token 的小数)
        if (totalPending > 0) {
            exitedPending[userAddr] += totalPending;
        }

        // 2. 从池子里移除用户
        require(pool.userCount > 0, "invalid userCount");
        pool.userCount -= 1;

        if (pool.userCount == 0 && pool.weight > 0) {
            totalWeight -= pool.weight;
        }

        // 3. 清空池子信息,但保留 lastClaimTime 用于线性释放
        user.poolId = 0;
        user.rewardDebt = 0;

        emit UserRemovedFromPool(userAddr, poolId, totalPending);
    }

    // 冻结用户的 exitedPending,冻结后无法提取 exitedPending 部分
    function freezeExitedReward(address userAddr) external onlyOperator {
        require(userAddr != address(0), "invalid user");
        exitedFrozen[userAddr] = true;
        emit ExitedRewardFrozen(userAddr);
    }

    // 解冻用户的 exitedPending,并重置 lastClaimTime(重置线性释放计时)
    function unfreezeExitedReward(address userAddr) external onlyOperator {
        require(userAddr != address(0), "invalid user");
        exitedFrozen[userAddr] = false;

        UserInfo storage user = users[userAddr];
        user.lastClaimTime = block.timestamp;

        emit ExitedRewardUnfrozen(userAddr, block.timestamp);
    }

    // 操作员把奖励充值进合约并按权重分配
    function depositReward(uint256 amount) external nonReentrant {
        require(amount > 0, "amount zero");
        require(totalWeight > 0, "no active pool");

        // 先把奖励转进合约
        rewardToken.safeTransferFrom(msg.sender, address(this), amount);
        emit RewardDeposited(msg.sender, amount);

        // 先找出最后一个有效池,用于吃掉权重分配产生的 dust
        uint256 lastEligiblePid = 0;
        for (uint256 pid = 1; pid <= poolCount; pid++) {
            Pool storage pool = pools[pid];
            if (pool.weight == 0 || pool.userCount == 0) {
                continue;
            }
            lastEligiblePid = pid;
        }
        require(lastEligiblePid != 0, "no eligible pool");

        uint256 remaining = amount;

        // 按照池子权重分配本次 amount
        for (uint256 pid = 1; pid <= poolCount; pid++) {
            Pool storage pool = pools[pid];
            if (pool.weight == 0 || pool.userCount == 0) {
                continue;
            }

            uint256 poolAmount;
            if (pid == lastEligiblePid) {
                // 最后一个池子吃掉所有剩余,避免 amount 中的 dust 卡在合约
                poolAmount = remaining;
            } else {
                poolAmount = (amount * pool.weight) / totalWeight;
                if (poolAmount > remaining) {
                    poolAmount = remaining;
                }
            }

            if (poolAmount == 0) {
                continue;
            }

            remaining -= poolAmount;

            // 每个池子内部按照 userCount 均分,使用 ACC_REWARD_PRECISION 精度
            uint256 rewardPerShare = (poolAmount * ACC_REWARD_PRECISION) / pool.userCount;
            pool.accRewardPerShare += rewardPerShare;

            emit RewardAllocated(pid, poolAmount, pool.accRewardPerShare);
        }
    }

    // -------------------- 用户功能 --------------------
    function claim() external nonReentrant {
        UserInfo storage user = users[msg.sender];

        uint256 poolId = user.poolId;
        uint256 poolPendingTokens = 0;
        uint256 poolPendingRemainder = 0;
        uint256 poolPendingScaled = 0;

        // 1. 计算池内 pending(含小数部分)
        if (poolId != 0) {
            Pool storage pool = pools[poolId];
            poolPendingScaled = pool.accRewardPerShare - user.rewardDebt; // ACC_REWARD_PRECISION 精度
            poolPendingTokens = poolPendingScaled / ACC_REWARD_PRECISION; // 向下取整:整数 token
            poolPendingRemainder = poolPendingScaled % ACC_REWARD_PRECISION; // < ACC_REWARD_PRECISION
        }

        // 2. 读取移出后锁定的奖励
        uint256 exitPendingStored = exitedPending[msg.sender];
        bool frozen = exitedFrozen[msg.sender];

        // 如果被冻结,则本次不允许领取 exitedPending,只能领池内奖励
        uint256 exitPendingUsable = frozen ? 0 : exitPendingStored;

        // 可用于计算本次额度的“可提部分”(单位:token)
        uint256 totalBase = poolPendingTokens + exitPendingUsable;
        require(totalBase > 0, "no reward");

        // 3. 按秒级线性释放,对“可提部分”做限额
        uint256 lastTime = user.lastClaimTime;
        require(lastTime != 0, "claim not initialized");

        uint256 timeDelta = block.timestamp - lastTime;
        uint256 maxRatio = (dailyWithdrawRatio * timeDelta) / 86400;
        if (maxRatio > 10000) maxRatio = 10000;

        uint256 maxWithdrawable = (totalBase * maxRatio) / 10000;
        require(maxWithdrawable > 0, "limit not reached");

        // 4. 优先提掉 exitedPending 再提池内 pending(但只在未冻结时)
        uint256 remaining = maxWithdrawable;
        uint256 fromExit = 0;
        uint256 fromPool = 0;

        if (!frozen && exitPendingStored > 0) {
            if (remaining >= exitPendingStored) {
                fromExit = exitPendingStored;
                remaining -= exitPendingStored;
                exitedPending[msg.sender] = 0;
            } else {
                fromExit = remaining;
                exitedPending[msg.sender] = exitPendingStored - remaining;
                remaining = 0;
            }
        }

        if (remaining > 0 && poolPendingTokens > 0 && poolId != 0) {
            if (remaining >= poolPendingTokens) {
                fromPool = poolPendingTokens;
                remaining -= poolPendingTokens;
            } else {
                fromPool = remaining;
                remaining = 0;
            }

            // 池内剩余 = 原 pending - 本次提走(单位:token)
            uint256 poolRemainTokens = poolPendingTokens - fromPool;

            // 新的未领取 scaled = 剩余整数 token + 之前的小数残余
            uint256 newPendingScaled = poolRemainTokens * ACC_REWARD_PRECISION + poolPendingRemainder;

            Pool storage pool2 = pools[poolId];
            // 把剩余部分折回 rewardDebt(不丢小数)
            user.rewardDebt = pool2.accRewardPerShare - newPendingScaled;
        }

        user.lastClaimTime = block.timestamp;

        uint256 toTransfer = fromExit + fromPool;
        require(toTransfer > 0, "nothing to transfer");

        rewardToken.safeTransfer(msg.sender, toTransfer);
        emit RewardClaimed(msg.sender, poolId, toTransfer);
    }

    // -------------------- 视图函数 --------------------
    // pending: 理论总待领取(池内 + 退出锁定,不考虑冻结)
    // maxWithdrawable: 当前在日限额下允许领取的数量(如果被冻结,则不包含 exitedPending 部分)
    function pendingReward(address userAddr) external view returns (uint256 pending, uint256 maxWithdrawable) {
        UserInfo memory user = users[userAddr];

        uint256 poolPendingTokens = 0;
        if (user.poolId != 0) {
            Pool memory pool = pools[user.poolId];
            uint256 poolPendingScaled = pool.accRewardPerShare - user.rewardDebt;
            poolPendingTokens = poolPendingScaled / ACC_REWARD_PRECISION;
        }

        uint256 exitPendingStored = exitedPending[userAddr];
        bool frozen = exitedFrozen[userAddr];

        pending = poolPendingTokens + exitPendingStored; // 理论总待领取

        if (user.lastClaimTime == 0 || pending == 0) {
            // 还没初始化过 lastClaimTime 或没有任何待领,则认为暂时不可提,只返回总待领取
            return (pending, 0);
        }

        // 可提基数:如果被冻结,则不把 exitedPending 计入本次可提额度
        uint256 usableBase = poolPendingTokens + (frozen ? 0 : exitPendingStored);
        if (usableBase == 0) {
            // 只有 exitedPending 且被冻结的情况:可提为 0
            return (pending, 0);
        }

        uint256 timeDelta = block.timestamp - user.lastClaimTime;
        uint256 maxRatio = (dailyWithdrawRatio * timeDelta) / 86400;
        if (maxRatio > 10000) maxRatio = 10000;

        maxWithdrawable = (usableBase * maxRatio) / 10000;
    }
}
SafeERC20.sol 212 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

    /**
     * @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
     */
    function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
        return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

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

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

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     *
     * NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
     * only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
     * set here.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

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

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

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

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

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            // bubble errors
            if iszero(success) {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }
            returnSize := returndatasize()
            returnValue := mload(0)
        }

        if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        bool success;
        uint256 returnSize;
        uint256 returnValue;
        assembly ("memory-safe") {
            success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
            returnSize := returndatasize()
            returnValue := mload(0)
        }
        return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
    }
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (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 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
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // 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;
    }
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity >=0.6.2;

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

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

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

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

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

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

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

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

pragma solidity >=0.4.16;

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

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

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

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

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

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

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

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
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;
    }
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)

pragma solidity >=0.4.16;

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

pragma solidity >=0.4.16;

import {IERC20} from "../token/ERC20/IERC20.sol";
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Read Contract

dailyWithdrawRatio 0x9cfa41f9 → uint256
exitedFrozen 0xb124df02 → bool
exitedPending 0x69c2389b → uint256
operators 0x13e7c9d8 → bool
owner 0x8da5cb5b → address
pendingReward 0xf40f0f52 → uint256, uint256
poolCount 0xf525cb68 → uint256
pools 0xac4afa38 → uint256, uint256, uint256
rewardToken 0xf7c618c1 → address
totalWeight 0x96c82e57 → uint256
users 0xa87430ba → uint256, uint256, uint256

Write Contract 14 functions

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

addUserToPool 0xece8a770
address user
uint256 poolId
addUsersToPool 0x8d0aba17
address[] usersToAdd
uint256 poolId
claim 0x4e71d92d
No parameters
createPool 0x8259e6a0
uint256 weight
depositReward 0x1e2720ff
uint256 amount
freezeExitedReward 0x9b1b919c
address userAddr
removeUserFromPool 0xef79d33e
address userAddr
removeUsersFromPool 0xaaf89fca
address[] usersToRemove
renounceOwnership 0x715018a6
No parameters
setDailyWithdrawRatio 0x10482e3d
uint256 newRatio
setOperator 0x558a7297
address operator
bool enabled
setPoolWeight 0x52911623
uint256 poolId
uint256 newWeight
transferOwnership 0xf2fde38b
address newOwner
unfreezeExitedReward 0x3ef0c351
address userAddr

Recent Transactions

No transactions found for this address