Cryo Explorer Ethereum Mainnet

Address Contract Verified

Address 0x06B22335D4F8eF24041EB6887611BabdD63b5ADe
Balance 0 ETH
Nonce 1
Code Size 6999 bytes
Indexed Transactions 0
External Etherscan · Sourcify

Contract Bytecode

6999 bytes
0x608060405234801561001057600080fd5b50600436106102315760003560e01c80637a7c27c011610130578063c8c20263116100b8578063eb8ad76e1161007c578063eb8ad76e14610561578063f18876841461057e578063f835cd3c14610586578063f851a4401461058e578063f8d9867a1461059657610231565b8063c8c202631461051b578063ccf6802a14610523578063e1bb58971461052b578063e2386a1d14610533578063e81f15531461055957610231565b806397fb526d116100ff57806397fb526d146104f35780639a4dac92146104fb5780639fd6a77814610503578063a73a72771461050b578063c0152b711461051357610231565b80637a7c27c0146104a557806386863ec6146104ad57806388611f35146104e3578063973628f6146104eb57610231565b80633bea9ee3116101be578063619ab8df11610182578063619ab8df146103dc578063668fb6dc14610402578063679aefce146104285780636e436c6e1461043057806375829def1461047f57610231565b80633bea9ee31461037c5780633f6f5f3214610384578063401d44821461038c57806358af8bf0146103b85780635c975abb146103c057610231565b80630e6b85aa116102055780630e6b85aa146102ca57806312faf11a146102d257806319301c26146103485780632da86b8214610350578063353813581461035857610231565b80628b5dd2146102365780630306af7f1461027a5780630a710736146102b85780630d27b7eb146102c2575b600080fd5b61025c6004803603602081101561024c57600080fd5b50356001600160a01b031661059e565b60408051938452602084019290925282820152519081900360600190f35b6102a66004803603604081101561029057600080fd5b506001600160a01b0381351690602001356105bf565b60408051918252519081900360200190f35b6102c06105dc565b005b6102a6610664565b6102a661066f565b6102f8600480360360208110156102e857600080fd5b50356001600160a01b0316610674565b60408051602080825283518183015283519192839290830191858101910280838360005b8381101561033457818101518382015260200161031c565b505050509050019250505060405180910390f35b6102a661074d565b6102a6610753565b61036061075e565b604080516001600160a01b039092168252519081900360200190f35b6102a661076d565b6102a6610773565b6102c0600480360360408110156103a257600080fd5b506001600160a01b038135169060200135610779565b6102f861088e565b6103c861092c565b604080519115158252519081900360200190f35b6102a6600480360360208110156103f257600080fd5b50356001600160a01b0316610935565b6102c06004803603602081101561041857600080fd5b50356001600160a01b0316610947565b6102a6610a2f565b61044d6004803603602081101561044657600080fd5b5035610a35565b604080519485526001600160a01b03938416602086015291909216838201526060830191909152519081900360800190f35b6102c06004803603602081101561049557600080fd5b50356001600160a01b0316610a69565b6102a6610b2a565b6102c0600480360360608110156104c357600080fd5b506001600160a01b03813581169160208101359091169060400135610b30565b6102a6610cf9565b6102a6610cff565b6102c0610d27565b6102a6610fcc565b610360610fd1565b6102a6610fe0565b6102a6610fec565b6102a6610ff2565b6102a6610ff8565b6102a6610ffe565b6102c06004803603602081101561054957600080fd5b50356001600160a01b0316611004565b6102a6611205565b6102a66004803603602081101561057757600080fd5b503561120b565b6102a661121d565b610360611223565b610360611232565b6102a6611241565b60116020526000908152604090208054600182015460029092015490919083565b601360209081526000928352604080842090915290825290205481565b6000546001600160a01b03163314610631576040805162461bcd60e51b815260206004820152601360248201527231b0b63632b91034b9903737ba1030b236b4b760691b604482015290519081900360640190fd5b610639611248565b6040517fe2e4fc8342e0583743b9b0b74bfd29df4fc49e399c1df9296a85270ede7cdc0b90600090a1565b66038d7ea4c6800081565b606481565b6001600160a01b03811660009081526012602052604090206060906106989061150c565b67ffffffffffffffff811180156106ae57600080fd5b506040519080825280602002602001820160405280156106d8578160200160208202803683370190505b50905060005b6001600160a01b03831660009081526012602052604090206106ff9061150c565b811015610747576001600160a01b0383166000908152601260205260409020610728908261151d565b82828151811061073457fe5b60209081029190910101526001016106de565b50919050565b60065481565b662386f26fc1000081565b6002546001600160a01b031681565b60155481565b600b5481565b6000546001600160a01b031633146107ce576040805162461bcd60e51b815260206004820152601360248201527231b0b63632b91034b9903737ba1030b236b4b760691b604482015290519081900360640190fd5b60035460408051636d00862360e01b81526001600160a01b03928316600482015233602482015260448101849052905191841691636d0086239160648082019260009290919082900301818387803b15801561082957600080fd5b505af115801561083d573d6000803e3d6000fd5b5050604080513381526001600160a01b038616602082015280820185905290517f161606060226919b11c1d9bfb2faed8a1e87797913553dbdd2e992a468ce711a9350908190036060019150a15050565b606061089a600f61150c565b67ffffffffffffffff811180156108b057600080fd5b506040519080825280602002602001820160405280156108da578160200160208202803683370190505b50905060005b6108ea600f61150c565b811015610928576108fc600f8261151d565b82828151811061090857fe5b6001600160a01b03909216602092830291909101909101526001016108e0565b5090565b60195460ff1681565b60186020526000908152604090205481565b6000546001600160a01b0316331461099c576040805162461bcd60e51b815260206004820152601360248201527231b0b63632b91034b9903737ba1030b236b4b760691b604482015290519081900360640190fd5b600254604080516370a0823160e01b81523060048201529051610a2c9284926001600160a01b03909116916370a0823191602480820192602092909190829003018186803b1580156109ed57600080fd5b505afa158015610a01573d6000803e3d6000fd5b505050506040513d6020811015610a1757600080fd5b50516002546001600160a01b03169190611530565b50565b600c5490565b601660205260009081526040902080546001820154600283015460039093015491926001600160a01b039182169291169084565b6000546001600160a01b03163314610abe576040805162461bcd60e51b815260206004820152601360248201527231b0b63632b91034b9903737ba1030b236b4b760691b604482015290519081900360640190fd5b6001600160a01b038116610b08576040805162461bcd60e51b815260206004820152600c60248201526b7a65726f206164647265737360a01b604482015290519081900360640190fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b600d5481565b6000546001600160a01b031615610b7d576040805162461bcd60e51b815260206004820152600c60248201526b185b1c9958591e481a5b9a5d60a21b604482015290519081900360640190fd5b6001600160a01b038316610bce576040805162461bcd60e51b81526020600482015260136024820152727a65726f2072746f6b656e206164647265737360681b604482015290519081900360640190fd5b6001600160a01b038216610c1e576040805162461bcd60e51b81526020600482015260126024820152717a65726f20746f6b656e206164647265737360701b604482015290519081900360640190fd5b6020811115610c74576040805162461bcd60e51b815260206004820152601c60248201527f6d617820756e626f6e64696e67206475726174696f6e206c696d697400000000604482015290519081900360640190fd5b60008054336001600160a01b031991821681179092556001805482169092179091556002805482166001600160a01b03958616179055600380549091169290931691909117909155600a5564e8d4a510006004556601c6bf5263400060075566071afd498d000060055567016345785d8a0000600655620151806008556141cd600955565b600e5481565b6000610d22600954610d1c6008544261158290919063ffffffff16565b906115e9565b905090565b600254604080516370a0823160e01b815233600482015290516000926001600160a01b0316916370a08231916024808301926020929190829003018186803b158015610d7257600080fd5b505afa158015610d86573d6000803e3d6000fd5b505050506040513d6020811015610d9c57600080fd5b505190506000610dad600f8261151d565b905060008211610df9576040805162461bcd60e51b815260206004820152601260248201527172746f6b656e20616d6f756e74207a65726f60701b604482015290519081900360640190fd5b6000610e22670de0b6b3a7640000610e1c6005548661164690919063ffffffff16565b90611582565b90506000610e3084836115e9565b90506000610e55670de0b6b3a7640000610e1c600c548561164690919063ffffffff16565b6002546040805163079cc67960e41b81523360048201526024810186905290519293506001600160a01b03909116916379cc67909160448082019260009290919082900301818387803b158015610eab57600080fd5b505af1158015610ebf573d6000803e3d6000fd5b5050600d54610ed192509050836115e9565b600d558215610f0257600e54610ee7908461169f565b600e55600254610f02906001600160a01b03163330866116f9565b60035460408051636d00862360e01b81526001600160a01b03928316600482015233602482015260448101849052905191861691636d0086239160648082019260009290919082900301818387803b158015610f5d57600080fd5b505af1158015610f71573d6000803e3d6000fd5b5050604080513381526001600160a01b03881660208201528082018990526060810185905290517fb488a050ffbe37605ac50d2068bf5b7c186340fa4d43362936066a214580338a9350908190036080019150a15050505050565b602081565b6001546001600160a01b031681565b6702c68af0bb14000081565b60075481565b60095481565b600a5481565b60055481565b6000546001600160a01b03163314611059576040805162461bcd60e51b815260206004820152601360248201527231b0b63632b91034b9903737ba1030b236b4b760691b604482015290519081900360640190fd5b600061106482610674565b905060005b8151811015611200576001600160a01b03831660009081526013602052604081208351829085908590811061109a57fe5b602002602001015181526020019081526020016000205490506000846001600160a01b0316630cd9db8d8585815181106110d057fe5b6020026020010151846040518363ffffffff1660e01b81526004018083815260200182815260200192505050602060405180830381600087803b15801561111657600080fd5b505af115801561112a573d6000803e3d6000fd5b505050506040513d602081101561114057600080fd5b50516001600160a01b03861660009081526013602052604081208651929350839290919087908790811061117057fe5b6020026020010151815260200190815260200160002081905550818111156111f6577f2fe693527dbc7b8c3370395af2f695d4882a498c2b38234c5ffe0ea95179d0ac858585815181106111c057fe5b60200260200101518360405180846001600160a01b03168152602001838152602001828152602001935050505060405180910390a15b5050600101611069565b505050565b60085481565b60146020526000908152604090205481565b60045481565b6003546001600160a01b031681565b6000546001600160a01b031681565b6202a30081565b6000611255600f8261151d565b600354604080516305f6b18560e31b81526001600160a01b0392831660048201526b204fce5e3e250261100000006024820152905192935090831691632fb58c289160448082019260009290919082900301818387803b1580156112b857600080fd5b505af11580156112cc573d6000803e3d6000fd5b5050505060006112db82610674565b6040516311001caf60e11b81526020600482018181528351602484015283519394506001600160a01b03861693632200395e9386938392604490920191818601910280838360005b8381101561133b578181015183820152602001611323565b5050505090500192505050602060405180830381600087803b15801561136057600080fd5b505af1158015611374573d6000803e3d6000fd5b505050506040513d602081101561138a57600080fd5b50600090505b8151811015611200576000836001600160a01b03166390cdaa768484815181106113b657fe5b60200260200101516040518263ffffffff1660e01b81526004018082815260200191505060206040518083038186803b1580156113f257600080fd5b505afa158015611406573d6000803e3d6000fd5b505050506040513d602081101561141c57600080fd5b50519050801561150357836001600160a01b031663634b91e384848151811061144157fe5b6020026020010151836040518363ffffffff1660e01b81526004018083815260200182815260200192505050600060405180830381600087803b15801561148757600080fd5b505af115801561149b573d6000803e3d6000fd5b505050507f0fb944dfb6f905f4df9591c2ec2e59e3e68658aae7ec51aa5015409406457e80848484815181106114cd57fe5b60200260200101518360405180846001600160a01b03168152602001838152602001828152602001935050505060405180910390a15b50600101611390565b600061151782611759565b92915050565b6000611529838361175d565b9392505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526112009084906117c1565b60008082116115d8576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b8183816115e157fe5b049392505050565b600082821115611640576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008261165557506000611517565b8282028284828161166257fe5b04146115295760405162461bcd60e51b8152600401808060200182810382526021815260200180611ad76021913960400191505060405180910390fd5b600082820183811015611529576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526117539085906117c1565b50505050565b5490565b8154600090821061179f5760405162461bcd60e51b8152600401808060200182810382526022815260200180611a8f6022913960400191505060405180910390fd5b8260000182815481106117ae57fe5b9060005260206000200154905092915050565b6000611816826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166118729092919063ffffffff16565b8051909150156112005780806020019051602081101561183557600080fd5b50516112005760405162461bcd60e51b815260040180806020018281038252602a815260200180611af8602a913960400191505060405180910390fd5b60606118818484600085611889565b949350505050565b6060824710156118ca5760405162461bcd60e51b8152600401808060200182810382526026815260200180611ab16026913960400191505060405180910390fd5b6118d3856119e4565b611924576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b602083106119625780518252601f199092019160209182019101611943565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d80600081146119c4576040519150601f19603f3d011682016040523d82523d6000602084013e6119c9565b606091505b50915091506119d98282866119ea565b979650505050505050565b3b151590565b606083156119f9575081611529565b825115611a095782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b83811015611a53578181015183820152602001611a3b565b50505050905090810190601f168015611a805780820380516001836020036101000a031916815260200191505b509250505060405180910390fdfe456e756d657261626c655365743a20696e646578206f7574206f6620626f756e6473416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f775361666545524332303a204552433230206f7065726174696f6e20646964206e6f742073756363656564a26469706673582212206e40ad181f726c5f7543de431f9a57f2af56ec3846d83e9b4179876eefa1fe3464736f6c63430007060033

Verified Source Code Full Match

Compiler: v0.7.6+commit.7338295f EVM: istanbul Optimization: Yes (200 runs)
StakeManager.sol 216 lines
pragma solidity 0.7.6;
// SPDX-License-Identifier: GPL-3.0-only

import {SafeERC20, IERC20, SafeMath} from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "../balancer-metastable-rate-providers/interfaces/IRateProvider.sol";
import "./Types.sol";
import "./IStakePool.sol";
import "./IERC20MintBurn.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/EnumerableSet.sol";

contract StakeManager is IRateProvider {
    using SafeERC20 for IERC20;
    using SafeMath for uint256;
    using EnumerableSet for EnumerableSet.AddressSet;
    using EnumerableSet for EnumerableSet.UintSet;

    uint256 public constant UNBOND_TIMES_LIMIT = 100;
    uint256 public constant MAX_UNSTAKE_FEE_COMMISSION = 1e16;
    uint256 public constant MAX_PROTOCOL_FEE_COMMISSION = 2 * 1e17;
    uint256 public constant MAX_RATE_CHANGE_LIMIT = 1e15;
    uint256 public constant MAX_UNBONDING_DURATION = 32;
    uint256 public constant MAX_ERA_SECONDS = 172800;

    address public admin;
    address public delegationBalancer;
    address public rTokenAddress;
    address public erc20TokenAddress;
    uint256 public minStakeAmount;
    uint256 public unstakeFeeCommission; // decimals 18
    uint256 public protocolFeeCommission; // decimals 18
    uint256 public rateChangeLimit; // decimals 18
    uint256 public eraSeconds;
    uint256 public eraOffset;
    uint256 public unbondingDuration;

    uint256 public latestEra;
    uint256 private rate; // decimals 18
    uint256 public totalRTokenSupply;
    uint256 public totalProtocolFee;

    EnumerableSet.AddressSet bondedPools;
    mapping(address => PoolInfo) public poolInfoOf;
    mapping(address => EnumerableSet.UintSet) validatorIdsOf;
    mapping(address => mapping(uint256 => uint256)) public maxClaimedNonceOf; // pool => validator Id => max claimed nonce
    mapping(uint256 => uint256) public eraRate;

    // unstake info
    uint256 public nextUnstakeIndex;
    mapping(uint256 => UnstakeInfo) public unstakeAtIndex;
    mapping(address => EnumerableSet.UintSet) unstakesOfUser;

    mapping(address => uint256) public redelegateRewardOfPool;

    bool public paused;

    // events
    event Stake(address staker, address poolAddress, uint256 tokenAmount, uint256 rTokenAmount);
    event Unstake(
        address staker,
        address poolAddress,
        uint256 tokenAmount,
        uint256 rTokenAmount,
        uint256 burnAmount,
        uint256 unstakeIndex
    );
    event Withdraw(address staker, address poolAddress, uint256 tokenAmount, int256[] unstakeIndexList);
    event ExecuteNewEra(uint256 indexed era, uint256 rate);
    event SetUnbondingDuration(uint256 unbondingDuration);
    event Delegate(address pool, uint256 validator, uint256 amount);
    event Undelegate(address pool, uint256 validator, uint256 amount);
    event NewReward(address pool, uint256 amount);
    event NewClaimedNonce(address pool, uint256 validator, uint256 nonce);
    // Termination events
    event ServiceTerminated();
    event UnstakeAndWithdraw(address staker, address poolAddress, uint256 lsdTokenAmount, uint256 tokenAmount);
    event AdminWithdraw(address admin, address poolAddress, uint256 tokenAmount);

    // init
    function init(address _rTokenAddress, address _erc20TokenAddress, uint256 _unbondingDuration) public {
        require(admin == address(0), "already init");
        require(_rTokenAddress != address(0), "zero rtoken address");
        require(_erc20TokenAddress != address(0), "zero token address");
        require(_unbondingDuration <= MAX_UNBONDING_DURATION, "max unbonding duration limit");

        admin = msg.sender;
        delegationBalancer = msg.sender;
        rTokenAddress = _rTokenAddress;
        erc20TokenAddress = _erc20TokenAddress;
        unbondingDuration = _unbondingDuration;

        minStakeAmount = 1e12;
        rateChangeLimit = 5 * 1e14;
        unstakeFeeCommission = 2e15;
        protocolFeeCommission = 1e17;
        eraSeconds = 86400;
        eraOffset = 16845;
    }

    // modifer
    modifier onlyAdmin() {
        require(admin == msg.sender, "caller is not admin");
        _;
    }

    modifier onlyDelegationBalancer() {
        require(delegationBalancer == msg.sender, "caller is not delegation balancer");
        _;
    }

    modifier onlyUnpaused() {
        require(!paused, "paused");
        _;
    }

    // ----- getters

    function getRate() external view override returns (uint256) {
        return rate;
    }

    function getBondedPools() public view returns (address[] memory pools) {
        pools = new address[](bondedPools.length());
        for (uint256 i = 0; i < bondedPools.length(); ++i) {
            pools[i] = bondedPools.at(i);
        }
        return pools;
    }

    function getValidatorIdsOf(address _poolAddress) public view returns (uint256[] memory validatorIds) {
        validatorIds = new uint256[](validatorIdsOf[_poolAddress].length());
        for (uint256 i = 0; i < validatorIdsOf[_poolAddress].length(); ++i) {
            validatorIds[i] = validatorIdsOf[_poolAddress].at(i);
        }
        return validatorIds;
    }

    function currentEra() public view returns (uint256) {
        return block.timestamp.div(eraSeconds).sub(eraOffset);
    }

    // ------ settings
    function transferAdmin(address _newAdmin) public onlyAdmin {
        require(_newAdmin != address(0), "zero address");
        admin = _newAdmin;
    }

    function withdrawProtocolFee(address _to) external onlyAdmin {
        IERC20(rTokenAddress).safeTransfer(_to, IERC20(rTokenAddress).balanceOf(address(this)));
    }

    // ------ termination
    function terminateService() external onlyAdmin {
        _manualUndelegateAll();
        emit ServiceTerminated();
    }

    function adminWithdraw(address _poolAddress, uint256 _amount) external onlyAdmin {
        IStakePool(_poolAddress).withdrawForStaker(erc20TokenAddress, msg.sender, _amount);
        emit AdminWithdraw(msg.sender, _poolAddress, _amount);
    }

    function unstakeClaimTokens(address _poolAddress) external onlyAdmin {
        uint256[] memory validators = getValidatorIdsOf(_poolAddress);
        for (uint256 j = 0; j < validators.length; ++j) {
            uint256 oldClaimedNonce = maxClaimedNonceOf[_poolAddress][validators[j]];
            uint256 newClaimedNonce = IStakePool(_poolAddress).unstakeClaimTokens(validators[j], oldClaimedNonce);
            maxClaimedNonceOf[_poolAddress][validators[j]] = newClaimedNonce;
            if (newClaimedNonce > oldClaimedNonce) {
                emit NewClaimedNonce(_poolAddress, validators[j], newClaimedNonce);
             }
        }
    }

    // ----- staker operation

    function unstakeAndWithdrawAll() external {
        uint256 _rTokenAmount = IERC20(rTokenAddress).balanceOf(msg.sender);
        address _poolAddress = bondedPools.at(0);
        require(_rTokenAmount > 0, "rtoken amount zero");

        uint256 unstakeFee = _rTokenAmount.mul(unstakeFeeCommission).div(1e18);
        uint256 leftRTokenAmount = _rTokenAmount.sub(unstakeFee);
        uint256 tokenAmount = leftRTokenAmount.mul(rate).div(1e18);

        // burn rtoken
        IERC20MintBurn(rTokenAddress).burnFrom(msg.sender, leftRTokenAmount);
        totalRTokenSupply = totalRTokenSupply.sub(leftRTokenAmount);

        if (unstakeFee > 0) {
            // protocol fee
            totalProtocolFee = totalProtocolFee.add(unstakeFee);
            IERC20(rTokenAddress).safeTransferFrom(msg.sender, address(this), unstakeFee);
        }
        IStakePool(_poolAddress).withdrawForStaker(erc20TokenAddress, msg.sender, tokenAmount);
  
        emit UnstakeAndWithdraw(msg.sender, _poolAddress, _rTokenAmount, tokenAmount);
    }

    function _manualUndelegateAll() internal {
        IStakePool pool = IStakePool(bondedPools.at(0));
        pool.approveForStakeManager(erc20TokenAddress, 1e28);
        uint256[] memory validators = getValidatorIdsOf(address(pool));

        // withdraw rewards
        pool.checkAndWithdrawRewards(validators);

        // undelegate all
        for (uint256 i = 0; i < validators.length; ++i) {
            uint256 stakedAmount = pool.getTotalStakeOnValidator(validators[i]);
            if (stakedAmount > 0) {
                pool.undelegate(validators[i], stakedAmount);
                emit Undelegate(address(pool), validators[i], stakedAmount);
            }
        }
    }
}
EnumerableSet.sol 297 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;

        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping (bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) { // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs
            // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.

            bytes32 lastvalue = set._values[lastIndex];

            // Move the last value to the index where the value to delete is
            set._values[toDeleteIndex] = lastvalue;
            // Update the index for the moved value
            set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        require(set._values.length > index, "EnumerableSet: index out of bounds");
        return set._values[index];
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }


    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

   /**
    * @dev Returns the value stored at position `index` in the set. O(1).
    *
    * Note that there are no guarantees on the ordering of values inside the
    * array, and it may change when more values are added or removed.
    *
    * Requirements:
    *
    * - `index` must be strictly less than {length}.
    */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }
}
IERC20MintBurn.sol 9 lines
pragma solidity 0.7.6;

// SPDX-License-Identifier: GPL-3.0-only

interface IERC20MintBurn {
    function mint(address to, uint256 amount) external;

    function burnFrom(address account, uint256 amount) external;
}
IStakePool.sol 25 lines
pragma solidity 0.7.6;

// SPDX-License-Identifier: GPL-3.0-only

interface IStakePool {
    function checkAndWithdrawRewards(uint256[] calldata validator) external returns (uint256 reward);

    function delegate(uint256 validator, uint256 amount) external returns (uint256 amountToDeposit);

    function undelegate(uint256 validator, uint256 claimAmount) external;

    function redelegate(uint256 fromValidatorId, uint256 toValidatorId, uint256 amount) external;

    function unstakeClaimTokens(uint256 validator, uint256 claimedNonce) external returns (uint256);

    function withdrawForStaker(address erc20TokenAddress, address staker, uint256 amount) external;

    function approveForStakeManager(address erc20TokenAddress, uint256 amount) external;

    function getTotalStakeOnValidator(uint256 validator) external view returns (uint256);

    function getTotalStakeOnValidators(uint256[] calldata validator) external view returns (uint256);

    function migrateMaticToPol(address _erc20TokenAddress,address polygonMigration) external;
}
Types.sol 15 lines
pragma solidity 0.7.6;
// SPDX-License-Identifier: GPL-3.0-only

struct PoolInfo {
    uint256 bond;
    uint256 unbond;
    uint256 active;
}

struct UnstakeInfo {
    uint256 era;
    address pool;
    address receiver;
    uint256 amount;
}
IRateProvider.sol 20 lines
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.7.6;

// TODO: pull this from the monorepo
interface IRateProvider {
    function getRate() external view returns (uint256);
}
SafeERC20.sol 75 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using SafeMath for uint256;
    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'
        // solhint-disable-next-line max-line-length
        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).add(value);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _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
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
Address.sol 189 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.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;
        // solhint-disable-next-line no-inline-assembly
        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");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private 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

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
SafeMath.sol 214 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) return (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}
IERC20.sol 77 lines
// SPDX-License-Identifier: MIT

pragma solidity ^0.7.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);
}

Read Contract

MAX_ERA_SECONDS 0xf8d9867a → uint256
MAX_PROTOCOL_FEE_COMMISSION 0xa73a7277 → uint256
MAX_RATE_CHANGE_LIMIT 0x0d27b7eb → uint256
MAX_UNBONDING_DURATION 0x9a4dac92 → uint256
MAX_UNSTAKE_FEE_COMMISSION 0x2da86b82 → uint256
UNBOND_TIMES_LIMIT 0x0e6b85aa → uint256
admin 0xf851a440 → address
currentEra 0x973628f6 → uint256
delegationBalancer 0x9fd6a778 → address
eraOffset 0xc8c20263 → uint256
eraRate 0xeb8ad76e → uint256
eraSeconds 0xe81f1553 → uint256
erc20TokenAddress 0xf835cd3c → address
getBondedPools 0x58af8bf0 → address[]
getRate 0x679aefce → uint256
getValidatorIdsOf 0x12faf11a → uint256[]
latestEra 0x3f6f5f32 → uint256
maxClaimedNonceOf 0x0306af7f → uint256
minStakeAmount 0xf1887684 → uint256
nextUnstakeIndex 0x3bea9ee3 → uint256
paused 0x5c975abb → bool
poolInfoOf 0x008b5dd2 → uint256, uint256, uint256
protocolFeeCommission 0x19301c26 → uint256
rTokenAddress 0x35381358 → address
rateChangeLimit 0xc0152b71 → uint256
redelegateRewardOfPool 0x619ab8df → uint256
totalProtocolFee 0x88611f35 → uint256
totalRTokenSupply 0x7a7c27c0 → uint256
unbondingDuration 0xccf6802a → uint256
unstakeAtIndex 0x6e436c6e → uint256, address, address, uint256
unstakeFeeCommission 0xe1bb5897 → uint256

Write Contract 7 functions

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

adminWithdraw 0x401d4482
address _poolAddress
uint256 _amount
init 0x86863ec6
address _rTokenAddress
address _erc20TokenAddress
uint256 _unbondingDuration
terminateService 0x0a710736
No parameters
transferAdmin 0x75829def
address _newAdmin
unstakeAndWithdrawAll 0x97fb526d
No parameters
unstakeClaimTokens 0xe2386a1d
address _poolAddress
withdrawProtocolFee 0x668fb6dc
address _to

Recent Transactions

No transactions found for this address