Address Contract Verified
Address
0xcbFdA6F9245FE4449dDF8936Bb5D46E9C61Cf0Dd
Balance
0 ETH
Nonce
1
Code Size
7056 bytes
Creator
0x9812Ae6F...0E43 at tx 0x16c16cf5...0c3364
Indexed Transactions
0
Contract Bytecode
7056 bytes
0x608060405234801561001057600080fd5b50600436106102485760003560e01c80638456cb591161013b578063ca4fb87c116100b8578063ebcd9f351161007c578063ebcd9f351461050e578063f2fde38b14610537578063f6094bd11461054a578063fc0c546a14610553578063fd5e6dd11461056657600080fd5b8063ca4fb87c146104b7578063cc4e5cdd146104cc578063d547741f146104df578063e9cf1532146104f2578063e9fad8ee1461050657600080fd5b806391d14854116100ff57806391d14854146104625780639ef3a26114610475578063a217fddf14610488578063a694fc3a14610490578063c9b570ac146104a357600080fd5b80638456cb59146103fe57806386989038146104125780638980f11f1461041b5780638cfde5221461042e5780638da5cb5b1461043757600080fd5b806336568abe116101c95780634fbdea4d1161018d5780634fbdea4d146103bd57806350335d52146103c657806353bd4678146103d95780637b0a47ee146103e25780637c1406d4146103eb57600080fd5b806336568abe14610363578063386a9525146103765780633d18b9121461037f578063484f12f0146103875780634bae89ba146103aa57600080fd5b80632e1a7d4d116102105780632e1a7d4d1461030e5780632f0528a7146103215780632f2ff15d146103345780632fc0d96e14610347578063313ce5671461035a57600080fd5b806301ffc9a71461024d57806318160ddd146102755780631959a0021461028c578063248a9ca3146102d657806324d51424146102f9575b600080fd5b61026061025b366004611953565b610579565b60405190151581526020015b60405180910390f35b61027e60065481565b60405190815260200161026c565b6102bb61029a366004611994565b600e6020526000908152604090208054600182015460029092015490919083565b6040805193845260208401929092529082015260600161026c565b61027e6102e43660046119af565b60009081526020819052604090206001015490565b61030c6103073660046119af565b6105b0565b005b61030c61031c3660046119af565b61065d565b61030c61032f3660046119af565b61084b565b61030c6103423660046119c8565b61089d565b61030c610355366004611a02565b6108c8565b61027e60055481565b61030c6103713660046119c8565b61097b565b61027e60075481565b61030c6109b3565b6102606103953660046119af565b60106020526000908152604090205460ff1681565b61030c6103b8366004611a02565b610b0e565b61027e600c5481565b61030c6103d4366004611a02565b610c3e565b61027e60085481565b61027e60045481565b61030c6103f9366004611a1f565b610ce6565b60025461026090600160a01b900460ff1681565b61027e600b5481565b61030c610429366004611a4f565b610d9b565b61027e600d5481565b60035461044a906001600160a01b031681565b6040516001600160a01b03909116815260200161026c565b6102606104703660046119c8565b610e42565b6102606104833660046119af565b610e6b565b61027e600081565b61030c61049e3660046119af565b610f1d565b60035461026090600160a01b900460ff1681565b61027e600080516020611b3b83398151915281565b61027e6104da366004611994565b61118d565b61030c6104ed3660046119c8565b611347565b60035461026090600160a81b900460ff1681565b61030c61136c565b61027e61051c366004611994565b6001600160a01b03166000908152600e602052604090205490565b61030c610545366004611994565b611407565b61027e60095481565b60025461044a906001600160a01b031681565b61044a6105743660046119af565b61151e565b60006001600160e01b03198216637965db0b60e01b14806105aa57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6105b8611548565b6003546001600160a01b0316331415806105e757506105e5600080516020611b3b83398151915233610e42565b155b15610605576040516342bcdf7f60e11b815260040160405180910390fd5b60025461061c906001600160a01b03163383611572565b60405181815233907f5991a08bb51d1fc3f552255ed446f040dca378ad3ff91763507b63b185eb5d2e9060200160405180910390a261065a60018055565b50565b610665611548565b600254600160a01b900460ff1615610690576040516362d3abeb60e01b815260040160405180910390fd5b6001600081905260106020527f8c6065603763fec3f5742441d3833f3f43b982453612d76adb39a885e3006b5f5460ff16156106df576040516362d3abeb60e01b815260040160405180910390fd5b336106e98161118d565b6001600160a01b0382166000908152600e6020526040902060020155600354600160a81b900460ff1661072f576040516315e34e0560e01b815260040160405180910390fd5b336000818152600e60205260409020805485118061074b575084155b156107695760405163162908e360e11b815260040160405180910390fd5b8481600001600082825461077d9190611a8f565b90915550504260018201556006805486919060009061079d908490611a8f565b909155505080546000036107e4576001600160a01b0382166000908152600f60205260408120805460ff19169055600b8054600192906107de908490611a8f565b90915550505b6002546107fb906001600160a01b03168387611572565b816001600160a01b03167f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d58660405161083691815260200190565b60405180910390a25050505061065a60018055565b6003546001600160a01b03163314158061087a5750610878600080516020611b3b83398151915233610e42565b155b15610898576040516342bcdf7f60e11b815260040160405180910390fd5b600d55565b6000828152602081905260409020600101546108b8816115d1565b6108c283836115db565b50505050565b6108d0611548565b6003546001600160a01b0316331415806108ff57506108fd600080516020611b3b83398151915233610e42565b155b1561091d576040516342bcdf7f60e11b815260040160405180910390fd5b60028054821515600160a01b0260ff60a01b199091161790556040517f752d7e161ff5146f80e3820893176eb40532811e5e20400dfdde57455213706a9061096a90831515815260200190565b60405180910390a161065a60018055565b6001600160a01b03811633146109a45760405163334bd91960e11b815260040160405180910390fd5b6109ae828261166d565b505050565b6109bb611548565b600254600160a01b900460ff16156109e6576040516362d3abeb60e01b815260040160405180910390fd5b6002600081905260106020527f853b2fefe141400fef543280f93d98bd49996069f632d0d20236afeeed8e46a25460ff1615610a35576040516362d3abeb60e01b815260040160405180910390fd5b600354600160a81b900460ff16610a5f576040516315e34e0560e01b815260040160405180910390fd5b336000610a6b8261118d565b6001600160a01b0383166000908152600e60205260408120600281019190915542600190910155600c54909150610aa3908290611aa2565b600c55600254610abd906001600160a01b03168383611572565b816001600160a01b03167fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e048682604051610af891815260200190565b60405180910390a2505050610b0c60018055565b565b610b16611548565b6003546001600160a01b031633141580610b455750610b43600080516020611b3b83398151915233610e42565b155b15610b63576040516342bcdf7f60e11b815260040160405180910390fd5b801515600360149054906101000a900460ff16151503610b9657604051630e52390960e41b815260040160405180910390fd5b600854600003610bbe5780610bbe5760405163279c10b160e21b815260040160405180910390fd5b6003805482158015600160a01b0260ff60a01b1990921691909117909155610c07576000600854600954610bf29190611a8f565b9050610bfe8142611a8f565b60085550610c0c565b426009555b60405181151581527f4c7a95ccbb9e28630be28433ff0b95e601f5ce869bf847250b1c5f0aeb1cb7ad9060200161096a565b6003546001600160a01b031633141580610c6d5750610c6b600080516020611b3b83398151915233610e42565b155b15610c8b576040516342bcdf7f60e11b815260040160405180910390fd5b6003805460ff60a81b1916600160a81b8315158102919091179182905560405160ff9190920416151581527ffd2697329e66633e3073b732cb28f19da605611fa6d19434b4af081ce5eaa1fe9060200160405180910390a150565b610cee611548565b6003546001600160a01b031633141580610d1d5750610d1b600080516020611b3b83398151915233610e42565b155b15610d3b576040516342bcdf7f60e11b815260040160405180910390fd5b600082815260106020908152604091829020805460ff1916841515908117909155915191825283917fbf27c8b33bf83a55f30f15dfff410d7b238a2b77cad12c2c07b8a250b7fabc15910160405180910390a2610d9760018055565b5050565b6003546001600160a01b031633141580610dca5750610dc8600080516020611b3b83398151915233610e42565b155b15610de8576040516342bcdf7f60e11b815260040160405180910390fd5b610dfc6001600160a01b0383163383611572565b604080516001600160a01b0384168152602081018390527f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa28910160405180910390a15050565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6003546000906001600160a01b031633141580610e9d5750610e9b600080516020611b3b83398151915233610e42565b155b15610ebb576040516342bcdf7f60e11b815260040160405180910390fd5b81600003610edc5760405163162908e360e11b815260040160405180910390fd5b60048290556040518281527f41d466ebd06fb97e7786086ac8b69b7eb7da798592036251291d34e9791cde019060200160405180910390a15060015b919050565b610f25611548565b600254600160a01b900460ff1615610f50576040516362d3abeb60e01b815260040160405180910390fd5b600080805260106020527f6e0956cda88cad152e89927e53611735b61a5c762d1428573c6931b0a5efcb015460ff1615610f9d576040516362d3abeb60e01b815260040160405180910390fd5b600354600160a01b900460ff1615610fc857604051631e0b268560e21b815260040160405180910390fd5b33610fd28161118d565b6001600160a01b0382166000908152600e6020526040812060020191909155839003611011576040516307a1cab560e11b815260040160405180910390fd5b600d546006546110219085611aa2565b11156110405760405163a9e3848f60e01b815260040160405180910390fd5b82600660008282546110529190611aa2565b9091555050336000818152600e602052604081208054869290611076908490611aa2565b90915550506001600160a01b0381166000908152600e6020908152604080832042600190910155600f90915290205460ff1661112657600a805460018082019092557fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80180546001600160a01b0319166001600160a01b0384169081179091556000908152600f60205260408120805460ff191683179055600b8054909190611120908490611aa2565b90915550505b60025461113e906001600160a01b03168230876116d8565b806001600160a01b03167f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d8560405161117991815260200190565b60405180910390a250505061065a60018055565b6003546000908190600160a01b900460ff161580156111c857506009546001600160a01b0384166000908152600e6020526040902060010154115b156111fd576001600160a01b0383166000908152600e60205260409020600101546111f69084904290611711565b90506105aa565b600354600160a01b900460ff1615611239576008546001600160a01b0384166000908152600e60205260409020600101546111f6918591611711565b6008546001600160a01b0384166000908152600e602052604090206001015411156112b5576005546004546001600160a01b0385166000908152600e602052604090205460075460095461128d9042611a8f565b6112979190611ab5565b6112a19190611ad7565b6112ab9190611ad7565b6111f69190611ab5565b6005546004546001600160a01b0385166000908152600e60205260409020546007546009546112e49042611a8f565b6112ee9190611ab5565b6112f89190611ad7565b6113029190611ad7565b61130c9190611ab5565b6008546001600160a01b0385166000908152600e6020526040902060010154611336918691611711565b6113409190611aa2565b9392505050565b600082815260208190526040902060010154611362816115d1565b6108c2838361166d565b600254600160a01b900460ff1615611397576040516362d3abeb60e01b815260040160405180910390fd5b6003600081905260106020527fb3edd0d534d647cffdae9f1294f11ad21f3fcf2814bea44c92bbb8d384a57d9e5460ff16156113e6576040516362d3abeb60e01b815260040160405180910390fd5b336000908152600e60205260409020546113ff9061065d565b61065a6109b3565b61140f611548565b6003546001600160a01b03163314158061143e575061143c600080516020611b3b83398151915233610e42565b155b1561145c576040516342bcdf7f60e11b815260040160405180910390fd5b6001600160a01b038116611483576040516342bcdf7f60e11b815260040160405180910390fd5b6003546114a890600080516020611b3b833981519152906001600160a01b031661166d565b506114c1600080516020611b3b833981519152826115db565b506003546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600380546001600160a01b0319166001600160a01b0383161790556001805550565b600a818154811061152e57600080fd5b6000918252602090912001546001600160a01b0316905081565b60026001540361156b57604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b6040516001600160a01b038381166024830152604482018390526109ae91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506117ab565b61065a8133611813565b60006115e78383610e42565b611665576000838152602081815260408083206001600160a01b03861684529091529020805460ff1916600117905561161d3390565b6001600160a01b0316826001600160a01b0316847f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45060016105aa565b5060006105aa565b60006116798383610e42565b15611665576000838152602081815260408083206001600160a01b0386168085529252808320805460ff1916905551339286917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45060016105aa565b6040516001600160a01b0384811660248301528381166044830152606482018390526108c29186918216906323b872dd9060840161159f565b60008060075483856117239190611a8f565b61172d9190611ab5565b6004546001600160a01b0387166000908152600e6020526040812054929350916117579190611ad7565b90506000600554828461176a9190611ad7565b6117749190611ab5565b6001600160a01b0388166000908152600e60205260408120600201549192509061179f908390611aa2565b98975050505050505050565b60006117c06001600160a01b0384168361184c565b905080516000141580156117e55750808060200190518101906117e39190611aee565b155b156109ae57604051635274afe760e01b81526001600160a01b03841660048201526024015b60405180910390fd5b61181d8282610e42565b610d975760405163e2517d3f60e01b81526001600160a01b03821660048201526024810183905260440161180a565b60606113408383600084600080856001600160a01b031684866040516118729190611b0b565b60006040518083038185875af1925050503d80600081146118af576040519150601f19603f3d011682016040523d82523d6000602084013e6118b4565b606091505b50915091506118c48683836118ce565b9695505050505050565b6060826118e3576118de8261192a565b611340565b81511580156118fa57506001600160a01b0384163b155b1561192357604051639996b31560e01b81526001600160a01b038516600482015260240161180a565b5080611340565b80511561193a5780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b60006020828403121561196557600080fd5b81356001600160e01b03198116811461134057600080fd5b80356001600160a01b0381168114610f1857600080fd5b6000602082840312156119a657600080fd5b6113408261197d565b6000602082840312156119c157600080fd5b5035919050565b600080604083850312156119db57600080fd5b823591506119eb6020840161197d565b90509250929050565b801515811461065a57600080fd5b600060208284031215611a1457600080fd5b8135611340816119f4565b60008060408385031215611a3257600080fd5b823591506020830135611a44816119f4565b809150509250929050565b60008060408385031215611a6257600080fd5b611a6b8361197d565b946020939093013593505050565b634e487b7160e01b600052601160045260246000fd5b818103818111156105aa576105aa611a79565b808201808211156105aa576105aa611a79565b600082611ad257634e487b7160e01b600052601260045260246000fd5b500490565b80820281158282048414176105aa576105aa611a79565b600060208284031215611b0057600080fd5b8151611340816119f4565b6000825160005b81811015611b2c5760208186018101518583015201611b12565b50600092019182525091905056fe5407862f04286ebe607684514c14b7fffc750b6bf52ba44ea49569174845a5bda2646970667358221220128422530473c957baae9e9abd2375afa13d0c7876977f6d300c60b369ce2d2b64736f6c63430008140033
Verified Source Code Full Match
Compiler: v0.8.20+commit.a1b79de6
EVM: paris
Optimization: Yes (200 runs)
MaivForeverStaking.sol 366 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
/**
* @title MaivForeverStaking Contract
* @notice Handles staking of given token and distributes rewards
*/
contract MaivForeverStaking is AccessControl, ReentrancyGuard {
using SafeERC20 for IERC20;
bytes32 public constant REWARDS_ROLE = keccak256("REWARDS_ROLE");
IERC20 public token;
bool public pause;
address public owner;
bool public rewardSystemStatus;
bool public isWithdrawEnable;
struct UserInfo {
uint256 amount;
uint256 since;
uint256 rewardDebt;
}
uint256 public rewardRate;
uint256 public decimals;
uint256 public totalSupply;
uint256 public rewardsDuration;
uint256 public lastUpdatedDuration;
uint256 public currentUpdatedDuration;
address[] public stakers;
uint256 public totalStakers;
uint256 public totalClaimedReward;
uint256 public totalStakingCap;
mapping(address user => UserInfo userInfo) public userInfo;
mapping(address user => bool isStaker) private isStaker;
// 0-stake, 1-withdraw, 2-getrewards, 3-exit
mapping(uint256 value => bool perFunctionStatus) public perFunctionStatus;
/* ========== EVENTS ========== */
event Staked(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event RewardPaid(address indexed user, uint256 reward);
event ContractPaused(bool status);
event FunctionPause(uint256 indexed index, bool status);
event RewardSystemPause(bool status);
event RewardRateUpdated(uint256 newRate);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event RewardTokenWithdrawn(address indexed owner, uint256 amount);
event Recovered(address token, uint256 amount);
event IsWithdrawEnableChanged(bool isWithdrawEnable);
/* ========== ERRORS ========== */
error ZeroAddressNotAllowed();
error ZeroAmountNotAllowed();
error InvalidAmount();
error InvalidParameters();
error FunctionPaused();
error RewardSystemPaused();
error FirstTimePauseRequired();
error WithdrawNotAllowed();
error StakingCapLimitReached();
/* ========== MODIFIERS ========== */
modifier updateReward(address account) {
userInfo[account].rewardDebt = updatedEarned(account);
_;
}
modifier onlyOwner() {
if (owner != msg.sender || !hasRole(REWARDS_ROLE, msg.sender)) {
revert ZeroAddressNotAllowed();
}
_;
}
modifier whenNotPaused() {
if (pause) {
revert FunctionPaused();
}
_;
}
modifier pausedStatus(uint256 _index) {
if (perFunctionStatus[_index]) {
revert FunctionPaused();
}
_;
}
modifier rewardStatus() {
if (rewardSystemStatus) {
revert RewardSystemPaused();
}
_;
}
/* ========== CONSTRUCTOR ========== */
/**
* @dev Initializes the contract
* @param _token address of staking token
* @param _owner address of the contract owner
* @param _rewardRate reward rate per token staked
* @param _decimals number of decimals for rewards calculation
* @param _rewardsDuration duration for rewards calculation
*/
constructor(address _token, address _owner, uint256 _rewardRate, uint256 _decimals, uint256 _rewardsDuration) {
if (_token == address(0) || _owner == address(0)) {
revert ZeroAddressNotAllowed();
}
if (_rewardRate == 0 || _decimals == 0 || _rewardsDuration == 0) {
revert InvalidParameters();
}
token = IERC20(_token);
owner = _owner;
rewardRate = _rewardRate;
decimals = _decimals;
rewardsDuration = _rewardsDuration;
isWithdrawEnable = true;
totalStakingCap = 250000000 * 10 ** 18;
_grantRole(REWARDS_ROLE, _owner);
}
/* ========== MUTATIVE FUNCTIONS ========== */
/**
* @dev Stakes a certain amount of tokens
* @param _amount number of tokens to stake
*/
function stake(
uint256 _amount
) external nonReentrant whenNotPaused pausedStatus(0) rewardStatus updateReward(msg.sender) {
if (_amount == 0) {
revert ZeroAmountNotAllowed();
}
if ((_amount + totalSupply) > totalStakingCap) {
revert StakingCapLimitReached();
}
totalSupply += _amount;
address user = msg.sender;
userInfo[user].amount += _amount;
userInfo[user].since = block.timestamp;
if (!isStaker[user]) {
stakers.push(user);
isStaker[user] = true;
totalStakers += 1;
}
token.safeTransferFrom(user, address(this), _amount);
emit Staked(user, _amount);
}
/**
* @dev Withdraws a certain amount of staked tokens
* @param _amount number of tokens to withdraw
*/
function withdraw(uint256 _amount) public nonReentrant whenNotPaused pausedStatus(1) updateReward(msg.sender) {
if (!(isWithdrawEnable)) revert WithdrawNotAllowed();
address user = msg.sender;
UserInfo storage u = userInfo[user];
if (u.amount < _amount || _amount == 0) {
revert InvalidAmount();
}
u.amount -= _amount;
u.since = block.timestamp;
totalSupply -= _amount;
if (u.amount == 0) {
isStaker[user] = false;
totalStakers -= 1;
}
token.safeTransfer(user, _amount);
emit Withdrawn(user, _amount);
}
/**
* @dev Claims the accrued rewards for the user
*/
function getReward() public nonReentrant whenNotPaused pausedStatus(2) {
if (!(isWithdrawEnable)) revert WithdrawNotAllowed();
address user = msg.sender;
uint256 reward = updatedEarned(user);
userInfo[user].rewardDebt = 0;
userInfo[user].since = block.timestamp;
totalClaimedReward = totalClaimedReward + reward;
token.safeTransfer(user, reward);
emit RewardPaid(user, reward);
}
/**
* @dev Withdraws all staked tokens and claims the rewards
*/
function exit() external whenNotPaused pausedStatus(3) {
withdraw(userInfo[msg.sender].amount);
getReward();
}
/* ========== RESTRICTED FUNCTIONS ========== */
/**
* @dev Pauses the contract
* @param _status true to pause, false to unpause
*/
function pausedContract(bool _status) external nonReentrant onlyOwner {
pause = _status;
emit ContractPaused(_status);
}
/**
* @dev Pauses a specific function
* @param _index index of the function to pause
* @param _status true to pause, false to unpause
*/
function pausedFunction(uint256 _index, bool _status) external nonReentrant onlyOwner {
perFunctionStatus[_index] = _status;
emit FunctionPause(_index, _status);
}
/**
* @dev Pauses the reward system
* @param _status true to pause, false to unpause
*/
function rewardSystemPaused(bool _status) external nonReentrant onlyOwner {
if (rewardSystemStatus == _status) {
revert InvalidParameters();
}
if (lastUpdatedDuration == 0) {
if (!_status) {
revert FirstTimePauseRequired();
}
}
rewardSystemStatus = _status;
if (_status) {
uint256 stopSecond = currentUpdatedDuration - lastUpdatedDuration;
lastUpdatedDuration = block.timestamp - stopSecond;
} else {
currentUpdatedDuration = block.timestamp;
}
emit RewardSystemPause(_status);
}
/**
* @dev Updates the reward rate
* @param _newRate new reward rate
* @return true if the operation is successful
*/
function updateRewardRate(uint256 _newRate) external onlyOwner returns (bool) {
if (_newRate == 0) {
revert InvalidAmount();
}
rewardRate = _newRate;
emit RewardRateUpdated(_newRate);
return true;
}
/**
* @dev Transfers the ownership of the contract to a new owner
* @param _owner address of the new owner
*/
function transferOwnership(address _owner) external nonReentrant onlyOwner {
if (_owner == address(0)) {
revert ZeroAddressNotAllowed();
}
_revokeRole(REWARDS_ROLE, owner);
_grantRole(REWARDS_ROLE, _owner);
emit OwnershipTransferred(owner, _owner);
owner = _owner;
}
/**
* @dev Withdraws a certain amount of reward tokens from the contract
* @param _amount number of tokens to withdraw
*/
function withdrawRewardToken(uint256 _amount) external nonReentrant onlyOwner {
token.safeTransfer(msg.sender, _amount);
emit RewardTokenWithdrawn(msg.sender, _amount);
}
/* ========== VIEWS ========== */
/**
* @dev Calculates the total rewards earned by an account
* @param _account address of the user
* @param _updateTime last updated time for rewards calculation
* @param _sinceTime time since the user staked tokens
* @return total rewards earned
*/
function earned(address _account, uint256 _updateTime, uint256 _sinceTime) internal view returns (uint256) {
uint256 finalTime = ((_updateTime - _sinceTime) / rewardsDuration);
uint256 finalAmount = (userInfo[_account].amount * rewardRate);
uint256 currentReward = ((finalTime * finalAmount) / decimals);
uint256 totalRewards = (userInfo[_account].rewardDebt + currentReward);
return totalRewards;
}
/**
* @dev Updates and returns the total rewards earned by an account
* @param _account address of the user
* @return total rewards earned
*/
function updatedEarned(address _account) public view returns (uint256) {
uint256 claimRewards;
if (!rewardSystemStatus && userInfo[_account].since > currentUpdatedDuration) {
claimRewards = earned(_account, block.timestamp, userInfo[_account].since);
} else if (rewardSystemStatus) {
claimRewards = earned(_account, lastUpdatedDuration, userInfo[_account].since);
} else {
if (userInfo[_account].since > lastUpdatedDuration) {
claimRewards = (((((block.timestamp - currentUpdatedDuration) / rewardsDuration) *
userInfo[_account].amount) * rewardRate) / decimals);
} else {
claimRewards =
earned(_account, lastUpdatedDuration, userInfo[_account].since) +
(((((block.timestamp - currentUpdatedDuration) / rewardsDuration) * userInfo[_account].amount) *
rewardRate) / decimals);
}
}
return claimRewards;
}
/**
* @dev Returns the staked balance of a user
* @param _user address of the user
* @return staked balance of the user
*/
function stakeBalanceOfUser(address _user) external view returns (uint256) {
return userInfo[_user].amount;
}
/**
* @dev Updates isWithdrawEnable
* @param _isWithdrawEnable value to update isWithdrawEnable
*/
function setIsWithdrawEnable(bool _isWithdrawEnable) external onlyOwner {
isWithdrawEnable = _isWithdrawEnable;
emit IsWithdrawEnableChanged(isWithdrawEnable);
}
function setTotalStakingCap(uint256 stakingCap) external onlyOwner {
totalStakingCap = stakingCap;
}
/**
* @dev recover any token from this contract to caller account
* @param _token address for recovering token
* @param _amount number of tokens want to recover
* Added to support recovering to stuck tokens, even reward token in case emergency. only owner
*/
function recoverERC20(address _token, uint256 _amount) external onlyOwner {
IERC20(_token).safeTransfer(msg.sender, _amount);
emit Recovered(_token, _amount);
}
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
AccessControl.sol 209 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
IAccessControl.sol 98 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}
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;
}
}
ERC165.sol 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* 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[EIP 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
DEFAULT_ADMIN_ROLE 0xa217fddf → bytes32
REWARDS_ROLE 0xca4fb87c → bytes32
currentUpdatedDuration 0xf6094bd1 → uint256
decimals 0x313ce567 → uint256
getRoleAdmin 0x248a9ca3 → bytes32
hasRole 0x91d14854 → bool
isWithdrawEnable 0xe9cf1532 → bool
lastUpdatedDuration 0x53bd4678 → uint256
owner 0x8da5cb5b → address
pause 0x8456cb59 → bool
perFunctionStatus 0x484f12f0 → bool
rewardRate 0x7b0a47ee → uint256
rewardSystemStatus 0xc9b570ac → bool
rewardsDuration 0x386a9525 → uint256
stakeBalanceOfUser 0xebcd9f35 → uint256
stakers 0xfd5e6dd1 → address
supportsInterface 0x01ffc9a7 → bool
token 0xfc0c546a → address
totalClaimedReward 0x4fbdea4d → uint256
totalStakers 0x86989038 → uint256
totalStakingCap 0x8cfde522 → uint256
totalSupply 0x18160ddd → uint256
updatedEarned 0xcc4e5cdd → uint256
userInfo 0x1959a002 → uint256, uint256, uint256
Write Contract 16 functions
These functions modify contract state and require a wallet transaction to execute.
exit 0xe9fad8ee
No parameters
getReward 0x3d18b912
No parameters
grantRole 0x2f2ff15d
bytes32 role
address account
pausedContract 0x2fc0d96e
bool _status
pausedFunction 0x7c1406d4
uint256 _index
bool _status
recoverERC20 0x8980f11f
address _token
uint256 _amount
renounceRole 0x36568abe
bytes32 role
address callerConfirmation
revokeRole 0xd547741f
bytes32 role
address account
rewardSystemPaused 0x4bae89ba
bool _status
setIsWithdrawEnable 0x50335d52
bool _isWithdrawEnable
setTotalStakingCap 0x2f0528a7
uint256 stakingCap
stake 0xa694fc3a
uint256 _amount
transferOwnership 0xf2fde38b
address _owner
updateRewardRate 0x9ef3a261
uint256 _newRate
returns: bool
withdraw 0x2e1a7d4d
uint256 _amount
withdrawRewardToken 0x24d51424
uint256 _amount
Recent Transactions
No transactions found for this address