Address Contract Verified
Address
0x22330865fC33dcdd413b58a956D855eAC17b22a6
Balance
0 ETH
Nonce
1
Code Size
5528 bytes
Creator
0x9812Ae6F...0E43 at tx 0x21add51d...e8d9a3
Indexed Transactions
0
Contract Bytecode
5528 bytes
0x608060405234801561001057600080fd5b506004361061023d5760003560e01c806372f702f31161013b578063c77c7387116100b8578063e9fad8ee1161007c578063e9fad8ee1461048a578063ebe2b12b14610492578063ee1725461461049b578063f2fde38b146104a4578063fb092bba146104b757600080fd5b8063c77c738714610436578063c8f33c9114610449578063d1af0c7d14610452578063e4d75c9d14610465578063e9cf15321461047857600080fd5b80638da5cb5b116100ff5780638da5cb5b146103d357806393ee5b61146103e4578063a2c9ec4014610407578063a694fc3a1461041a578063c25fc4ec1461042d57600080fd5b806372f702f3146103665780637b0a47ee146103915780637b2c39861461039a578063817b1cd2146103b75780638980f11f146103c057600080fd5b806344c370d3116101c957806366666aa91161018d57806366666aa91461031a5780636ea056a91461032357806370a0823114610336578063715018a61461035657806371b0cbfa1461035e57600080fd5b806344c370d3146102c557806347786d37146102ce578063485e7ba5146102e157806350335d52146102f4578063622e10f61461030757600080fd5b80631c1f78eb116102105780631c1f78eb146102905780632ca50e6e146102985780632e1a7d4d146102a1578063386a9525146102b45780633d18b912146102bd57600080fd5b80630550b266146102425780630700037d1461024c5780630c51dde41461027f57806318160ddd14610287575b600080fd5b61024a6104ca565b005b61026c61025a3660046113b5565b60066020526000908152604090205481565b6040519081526020015b60405180910390f35b61024a61050d565b61026c600e5481565b61026c6105d9565b61026c60035481565b61024a6102af3660046113d0565b6105f0565b61026c600a5481565b61024a610742565b61026c60125481565b61024a6102dc3660046113d0565b610852565b61024a6102ef3660046113f7565b6108bb565b61024a61030236600461142e565b61091f565b61024a61031536600461142e565b61097f565b61026c600c5481565b61024a61033136600461144b565b6109ce565b61026c6103443660046113b5565b60076020526000908152604090205481565b61024a610acc565b61024a610ade565b600554610379906001600160a01b031681565b6040516001600160a01b039091168152602001610276565b61026c60095481565b6010546103a79060ff1681565b6040519015158152602001610276565b61026c600f5481565b61024a6103ce36600461144b565b610b16565b6000546001600160a01b0316610379565b6103a76103f23660046113b5565b60026020526000908152604090205460ff1681565b61024a610415366004611475565b610bb9565b61024a6104283660046113d0565b610da2565b61026c600d5481565b601354610379906001600160a01b031681565b61026c600b5481565b600454610379906001600160a01b031681565b61024a6104733660046113b5565b610f00565b6010546103a790610100900460ff1681565b61024a610f7d565b61026c60085481565b61026c60115481565b61024a6104b23660046113b5565b610f9e565b61024a6104c53660046113d0565b610fde565b6104d2611014565b4260038190556040519081527f8fd4fc48a3951a715baaaf0dbe5217726f9bf9fcf962c3abe5af5cd90c474f5a9060200160405180910390a1565b610515611014565b6000618e94601254600a5460095461052d91906114b7565b61053791906114b7565b61054191906114ce565b9050600042905081600c54101561057f57600c80549083905561057d333061056984876114f0565b6004546001600160a01b0316929190611041565b505b600b819055600a5461059490620151806114b7565b61059e9082611503565b6008556040518281527fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d906020015b60405180910390a15050565b6000600a546009546105eb91906114b7565b905090565b6105f86110ae565b601054610100900460ff16610620576040516315e34e0560e01b815260040160405180910390fd5b80600003610641576040516307a1cab560e11b815260040160405180910390fd5b60085442111580156106535750600354155b15610671576040516325b5757360e21b815260040160405180910390fd5b3361067b816110d8565b6001600160a01b038216600090815260066020526040812091909155600e80548492906106a99084906114f0565b90915550506001600160a01b038116600090815260076020526040812080548492906106d69084906114f0565b90915550506005546106f2906001600160a01b03168284611175565b806001600160a01b03167f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d58360405161072d91815260200190565b60405180910390a25061073f60018055565b50565b61074a6110ae565b601054610100900460ff16610772576040516315e34e0560e01b815260040160405180910390fd5b60085442111580156107845750600354155b156107a2576040516325b5757360e21b815260040160405180910390fd5b336000818152600660205260409020548015610845576001600160a01b0382166000908152600660205260408120819055601180548392906107e5908490611503565b9091555050600454610801906001600160a01b03168383611175565b816001600160a01b03167fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e04868260405161083c91815260200190565b60405180910390a25b505061085060018055565b565b61085a611014565b600e5481101561087d5760405163a195fc8b60e01b815260040160405180910390fd5b601280549082905560408051828152602081018490527fe33ab2ea612635770f109d34ef704ae0b0ff4185179b98530e28727d96f1946791016105cd565b6108c3611014565b6001600160a01b038216600081815260026020908152604091829020805460ff19168515159081179091558251938452908301527f0483573f0f59138afd0a14e7518c1b013a0906f02bdf44af2696faa9ab3e78da91016105cd565b610927611014565b6010805461ff0019166101008315158102919091179182905560405160ff9190920416151581527ffd2697329e66633e3073b732cb28f19da605611fa6d19434b4af081ce5eaa1fe906020015b60405180910390a150565b610987611014565b6010805460ff191682151590811790915560405160ff909116151581527f44a66e254d052a27bf8f99a0968da1ac6bfbe15163b16b66ed4abf770562a61690602001610974565b3360009081526002602052604090205460ff16806109f657506000546001600160a01b031633145b610a13576040516369081b0160e11b815260040160405180910390fd5b60405163a9059cbb60e01b8152336004820152602481018290526001600160a01b0383169063a9059cbb906044016020604051808303816000875af1158015610a60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a849190611516565b50816001600160a01b03167f1b94d65e3a03a98b13e90142a41884547fdd622b7f14a4daf94f6338e2e85cf082604051610ac091815260200190565b60405180910390a25050565b610ad4611014565b61085060006111ab565b610ae6611014565b600060038190556040517f9745947f8ff0201b5238e0178690729bd983805edecf51b177bc460737d2426e9190a1565b610b1e611014565b6001600160a01b038216610b45576040516342bcdf7f60e11b815260040160405180910390fd5b80600003610b66576040516307a1cab560e11b815260040160405180910390fd5b610b7a6001600160a01b0383163383611175565b604080516001600160a01b0384168152602081018390527f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa2891016105cd565b610bc16110ae565b6013546001600160a01b03163314610bec576040516348f5c3ed60e01b815260040160405180910390fd5b60105460ff16610c0f57604051634eb3494f60e01b815260040160405180910390fd5b81600003610c30576040516307a1cab560e11b815260040160405180910390fd5b6001600160a01b038116610c57576040516342bcdf7f60e11b815260040160405180910390fd5b600d5442101580610c69575060035415155b15610c87576040516372c7583360e11b815260040160405180910390fd5b60125482600e54610c989190611503565b10610cb657604051632fda69dd60e21b815260040160405180910390fd5b80610cc0816110d8565b6001600160a01b038216600090815260066020526040812091909155600e8054859290610cee908490611503565b9250508190555082600f6000828254610d079190611503565b90915550506001600160a01b03811660009081526007602052604081208054859290610d34908490611503565b9091555050600554610d51906001600160a01b0316333086611041565b806001600160a01b03167f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d84604051610d8c91815260200190565b60405180910390a250610d9e60018055565b5050565b610daa6110ae565b80600003610dcb576040516307a1cab560e11b815260040160405180910390fd5b600d5442101580610ddd575060035415155b15610dfb576040516372c7583360e11b815260040160405180910390fd5b60125481600e54610e0c9190611503565b10610e2a57604051632fda69dd60e21b815260040160405180910390fd5b33610e34816110d8565b6001600160a01b038216600090815260066020526040812091909155600e8054849290610e62908490611503565b9250508190555081600f6000828254610e7b9190611503565b90915550506001600160a01b03811660009081526007602052604081208054849290610ea8908490611503565b9091555050600554610ec5906001600160a01b0316823085611041565b806001600160a01b03167f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d8360405161072d91815260200190565b610f08611014565b6001600160a01b038116610f2f576040516342bcdf7f60e11b815260040160405180910390fd5b601380546001600160a01b0319166001600160a01b0383169081179091556040519081527f2a4c3f973906b03b7a406904d1792327b7d13f646d6fe085a47d452f01dd6e1c90602001610974565b33600090815260076020526040902054610f96906105f0565b610850610742565b610fa6611014565b6001600160a01b038116610fd557604051631e4fbdf760e01b8152600060048201526024015b60405180910390fd5b61073f816111ab565b610fe6611014565b80600003611007576040516307a1cab560e11b815260040160405180910390fd5b600981905561073f61050d565b6000546001600160a01b031633146108505760405163118cdaa760e01b8152336004820152602401610fcc565b6040516001600160a01b0384811660248301528381166044830152606482018390526110a89186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b0383818316178352505050506111fb565b50505050565b6002600154036110d157604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b6001600160a01b038116600090815260076020526040812054600a546009548392618e9492909161110991906114b7565b61111391906114b7565b61111d91906114ce565b905060035460000361112f5792915050565b6000600d5460035461114191906114f0565b90506000600d5460085461115591906114f0565b90508161116282856114b7565b61116c91906114ce565b95945050505050565b6040516001600160a01b038381166024830152604482018390526111a691859182169063a9059cbb90606401611076565b505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006112106001600160a01b0384168361125e565b905080516000141580156112355750808060200190518101906112339190611516565b155b156111a657604051635274afe760e01b81526001600160a01b0384166004820152602401610fcc565b606061126c83836000611275565b90505b92915050565b60608147101561129a5760405163cd78605960e01b8152306004820152602401610fcc565b600080856001600160a01b031684866040516112b69190611533565b60006040518083038185875af1925050503d80600081146112f3576040519150601f19603f3d011682016040523d82523d6000602084013e6112f8565b606091505b5091509150611308868383611314565b925050505b9392505050565b6060826113295761132482611370565b61130d565b815115801561134057506001600160a01b0384163b155b1561136957604051639996b31560e01b81526001600160a01b0385166004820152602401610fcc565b508061130d565b8051156113805780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b80356001600160a01b03811681146113b057600080fd5b919050565b6000602082840312156113c757600080fd5b61126c82611399565b6000602082840312156113e257600080fd5b5035919050565b801515811461073f57600080fd5b6000806040838503121561140a57600080fd5b61141383611399565b91506020830135611423816113e9565b809150509250929050565b60006020828403121561144057600080fd5b813561130d816113e9565b6000806040838503121561145e57600080fd5b61146783611399565b946020939093013593505050565b6000806040838503121561148857600080fd5b8235915061149860208401611399565b90509250929050565b634e487b7160e01b600052601160045260246000fd5b808202811582820484141761126f5761126f6114a1565b6000826114eb57634e487b7160e01b600052601260045260246000fd5b500490565b8181038181111561126f5761126f6114a1565b8082018082111561126f5761126f6114a1565b60006020828403121561152857600080fd5b815161130d816113e9565b6000825160005b81811015611554576020818601810151858301520161153a565b50600092019182525091905056fea2646970667358221220adf0bedb966c79084e1f110f8c533a937416f594600e580f005dbc671c55853b64736f6c63430008140033
Verified Source Code Full Match
Compiler: v0.8.20+commit.a1b79de6
EVM: paris
Optimization: Yes (200 runs)
Staking.sol 330 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 { HelperFunctions } from "../utils/HelperFunctions.sol";
/**
* @title Staking Contract
* @author Nonceblox
* @notice Handles staking of given token and distribute Rewards tokens
*/
contract Staking is HelperFunctions {
using SafeERC20 for IERC20;
/* ========== STATE VARIABLES ========== */
IERC20 public rewardsToken;
IERC20 public stakingToken;
mapping(address user => uint256 rewards) public rewards;
mapping(address user => uint256 balanceOf) public balanceOf;
uint256 public periodFinish;
uint256 public rewardRate;
uint256 public rewardsDuration;
uint256 public lastUpdateTime;
uint256 public rewardPool;
uint256 public stakingTill;
uint256 public totalSupply;
uint256 public totalStaked;
bool public isStakeVestedToken;
bool public isWithdrawEnable;
uint256 public totalRewardsDistributed;
uint256 public stakingCap;
address public vestingAddress;
/* ========== EVENTS ========== */
event RewardAdded(uint256 reward);
event Staked(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event RewardPaid(address indexed user, uint256 reward);
event IsStakeVestedTokenChanged(bool isStakeVestedToken);
event IsWithdrawEnableChanged(bool isWithdrawEnable);
event CapChange(uint256 oldCap, uint256 newCap);
event Recovered(address token, uint256 amount);
event VestingAddressChanged(address _vestingAddress);
/* ========== ERRORS ========== */
error ZeroAmountNotAllowed();
error StakingNotAllowed();
error StakingCapExceeded();
error StakingNotYetOver();
error ZeroAddressNotAllowed();
error StakeVestedTokenPaused();
error InvalidCapLimit();
error InvalidCaller();
error WithdrawNotAllowed();
/* ========== CONSTRUCTOR ========== */
/**
* @dev Constructor that initializes the contract with the given parameters
* @param _rewardsToken The address of the rewards token
* @param _stakingToken The address of the staking token
* @param _rewardsDuration The duration of the rewards period in days
* @param _stakingTill The timestamp until when staking is allowed
* @param _stakingCap The maximum number of tokens allowed to stake
* @param _rate The reward rate in percentage
*/
constructor(
address _rewardsToken,
address _stakingToken,
uint256 _rewardsDuration,
uint256 _stakingTill,
uint256 _stakingCap,
uint256 _rate
) {
if (_stakingToken == address(0) || _rewardsToken == address(0)) {
revert ZeroAddressNotAllowed();
}
if (_stakingCap == 0 || _rewardsDuration == 0 || _stakingTill == 0 || _rate == 0) {
revert ZeroAmountNotAllowed();
}
rewardsToken = IERC20(_rewardsToken);
stakingToken = IERC20(_stakingToken);
rewardsDuration = _rewardsDuration; // period in days - ex 30
stakingTill = _stakingTill; // timestamp to close staking window
stakingCap = _stakingCap; // max num of tokens allowed to stake in decimals
rewardRate = _rate; // rate in percentage - ex 200%
isStakeVestedToken = true; // this enable direct staking for vested tokens
isWithdrawEnable = false; // this disable withdraw and getReward
}
/* ========== VIEWS ========== */
/**
* @dev Calculates the reward for a given account
* @param account The address of the account
* @return The calculated reward
*/
function _updateReward(address account) internal view returns (uint256) {
uint256 r = (rewardRate * rewardsDuration * balanceOf[account]) / 36500;
if (stoppedAt == 0) return r;
// ratio = daysCompleted / tenure
// rewardsAccumulated = rewards / ratio
uint256 daysCompleted = stoppedAt - stakingTill;
uint256 tenure = periodFinish - stakingTill;
return (r * tenure) / daysCompleted;
}
/**
* @dev Gets the reward for the entire duration
* @return The reward for the duration
*/
function getRewardForDuration() external view returns (uint256) {
return rewardRate * rewardsDuration;
}
/* ========== MUTATIVE FUNCTIONS ========== */
/**
* @dev Stakes a given amount of tokens
* @param amount The amount of tokens to stake
* @notice The amount must be greater than 0 and staking must be allowed
*/
function stake(uint256 amount) external nonReentrant {
if (amount == 0) {
revert ZeroAmountNotAllowed();
}
if (block.timestamp >= stakingTill || stoppedAt != 0) {
revert StakingNotAllowed();
}
if (totalSupply + amount >= stakingCap) {
revert StakingCapExceeded();
}
address caller = msg.sender;
rewards[caller] = _updateReward(caller);
totalSupply += amount;
totalStaked += amount;
balanceOf[caller] += amount;
stakingToken.safeTransferFrom(caller, address(this), amount);
emit Staked(caller, amount);
}
/**
* @dev stakes amount of vesting claimable tokens for user
* @param amount number of tokens user want to stake
* @param userAddress address of user want to stake claimable amount
*/
function stakeClaimableToken(uint256 amount, address userAddress) external nonReentrant {
if (vestingAddress != msg.sender) {
revert InvalidCaller();
}
if (!(isStakeVestedToken)) {
revert StakeVestedTokenPaused();
}
if (amount == 0) {
revert ZeroAmountNotAllowed();
}
if (userAddress == address(0)) {
revert ZeroAddressNotAllowed();
}
if (block.timestamp >= stakingTill || stoppedAt != 0) {
revert StakingNotAllowed();
}
if (totalSupply + amount >= stakingCap) {
revert StakingCapExceeded();
}
address caller = userAddress;
rewards[caller] = _updateReward(caller);
totalSupply += amount;
totalStaked += amount;
balanceOf[caller] += amount;
stakingToken.safeTransferFrom(msg.sender, address(this), amount);
emit Staked(caller, amount);
}
/**
* @dev Withdraws a given amount of tokens
* @param amount The amount of tokens to withdraw
* @notice The amount must be greater than 0 and staking must be finished or stopped
*/
function withdraw(uint256 amount) public nonReentrant {
if (!(isWithdrawEnable)) revert WithdrawNotAllowed();
if (amount == 0) {
revert ZeroAmountNotAllowed();
}
if (block.timestamp <= periodFinish && stoppedAt == 0) {
revert StakingNotYetOver();
}
address caller = msg.sender;
rewards[caller] = _updateReward(caller);
totalSupply -= amount;
balanceOf[caller] -= amount;
stakingToken.safeTransfer(caller, amount);
emit Withdrawn(caller, amount);
}
/**
* @dev Gets the reward for the caller
* @notice Staking must be finished or stopped
*/
function getReward() public nonReentrant {
if (!(isWithdrawEnable)) revert WithdrawNotAllowed();
if (block.timestamp <= periodFinish && stoppedAt == 0) {
revert StakingNotYetOver();
}
address caller = msg.sender;
uint256 reward = rewards[caller];
if (reward > 0) {
rewards[caller] = 0;
totalRewardsDistributed += reward;
rewardsToken.safeTransfer(caller, reward);
emit RewardPaid(caller, reward);
}
}
/**
* @dev Exits the staking by withdrawing all tokens and getting the reward
*/
function exit() external {
withdraw(balanceOf[msg.sender]);
getReward();
}
/* ========== RESTRICTED FUNCTIONS ========== */
/**
* @dev Notifies the contract of the reward amount
* @notice Can only be called by the owner
*/
function notifyRewardAmount() public onlyOwner {
uint256 reward = (rewardRate * rewardsDuration * stakingCap) / 36500;
uint256 timestamp = block.timestamp;
if (rewardPool < reward) {
uint256 _rewardPool = rewardPool;
rewardPool = reward;
rewardsToken.safeTransferFrom(msg.sender, address(this), reward - _rewardPool);
}
lastUpdateTime = timestamp;
periodFinish = timestamp + rewardsDuration * 1 days;
emit RewardAdded(reward);
}
/**
* @dev Updates the reward rate
* @param rate The new reward rate
* @notice Can only be called by the owner
*/
function updateInterest(uint256 rate) external onlyOwner {
if (rate == 0) revert ZeroAmountNotAllowed();
rewardRate = rate;
notifyRewardAmount();
}
/**
* @dev Updates Staking Cap value
* @param _newCap value of new StakingCap
*/
function setCap(uint256 _newCap) external onlyOwner {
if (_newCap < totalSupply) {
revert InvalidCapLimit();
}
uint256 oldCap = stakingCap;
stakingCap = _newCap;
emit CapChange(oldCap, _newCap);
}
/**
* @dev Updates isStakeVestedToken
* @param _isStakeVestedToken value to update IsStakeVestedToken
*/
function setIsStakeVestedToken(bool _isStakeVestedToken) external onlyOwner {
isStakeVestedToken = _isStakeVestedToken;
emit IsStakeVestedTokenChanged(isStakeVestedToken);
}
/**
* @dev Updates isStakeVestedToken
* @param _isWithdrawEnable value to update isWithdrawEnable
*/
function setIsWithdrawEnable(bool _isWithdrawEnable) external onlyOwner {
isWithdrawEnable = _isWithdrawEnable;
emit IsWithdrawEnableChanged(isWithdrawEnable);
}
/**
* @dev Set vesting address
* @param _vestingAddress value of vestingAddress
*/
function setVestingAddress(address _vestingAddress) external onlyOwner {
if (_vestingAddress == address(0)) revert ZeroAddressNotAllowed();
vestingAddress = _vestingAddress;
emit VestingAddressChanged(_vestingAddress);
}
/**
* @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 {
if (_token == address(0)) revert ZeroAddressNotAllowed();
if (_amount == 0) revert ZeroAmountNotAllowed();
IERC20(_token).safeTransfer(msg.sender, _amount);
emit Recovered(_token, _amount);
}
}
HelperFunctions.sol 69 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/**
* @title HelperFunction Contract
* @author Nonceblox
* @notice Handles staking helper functions
*/
contract HelperFunctions is Ownable(msg.sender), ReentrancyGuard {
mapping(address _user => bool sweepers) public sweepers;
uint256 public stoppedAt;
/* ========== EVENTS ========== */
event Sweeped(address indexed token, uint256 amount);
event SetSweeper(address account, bool enable);
event StakingStopped(uint256 at);
event StakingStart();
/* ========== ERRORS ========== */
error CallerDoesNotHaveAccess();
/* ========== MUTATIVE FUNCTIONS ========== */
/**
* @dev Sets or unsets a sweeper
* @param account The address of the account to set or unset as a sweeper
* @param enable A boolean indicating if the account should be enabled as a sweeper
*/
function setSweeper(address account, bool enable) external onlyOwner {
sweepers[account] = enable;
emit SetSweeper(account, enable);
}
/**
* @dev Sweeps tokens to the caller
* @param token The address of the token to sweep
* @param amount The amount of tokens to sweep
* @notice Caller must be an owner or a sweeper
*/
function sweep(address token, uint256 amount) external {
if (!(sweepers[msg.sender] || msg.sender == owner())) {
revert CallerDoesNotHaveAccess();
}
IERC20(token).transfer(msg.sender, amount);
emit Sweeped(token, amount);
}
/**
* @dev Stops the staking process
* @notice Can only be called by the owner
*/
function stopStaking() external onlyOwner {
stoppedAt = block.timestamp;
emit StakingStopped(block.timestamp);
}
/**
* @dev Start the staking process
* @notice Can only be called by the owner
*/
function startStaking() external onlyOwner {
stoppedAt = 0;
emit StakingStart();
}
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Read Contract
balanceOf 0x70a08231 → uint256
getRewardForDuration 0x1c1f78eb → uint256
isStakeVestedToken 0x7b2c3986 → bool
isWithdrawEnable 0xe9cf1532 → bool
lastUpdateTime 0xc8f33c91 → uint256
owner 0x8da5cb5b → address
periodFinish 0xebe2b12b → uint256
rewardPool 0x66666aa9 → uint256
rewardRate 0x7b0a47ee → uint256
rewards 0x0700037d → uint256
rewardsDuration 0x386a9525 → uint256
rewardsToken 0xd1af0c7d → address
stakingCap 0x44c370d3 → uint256
stakingTill 0xc25fc4ec → uint256
stakingToken 0x72f702f3 → address
stoppedAt 0x2ca50e6e → uint256
sweepers 0x93ee5b61 → bool
totalRewardsDistributed 0xee172546 → uint256
totalStaked 0x817b1cd2 → uint256
totalSupply 0x18160ddd → uint256
vestingAddress 0xc77c7387 → address
Write Contract 18 functions
These functions modify contract state and require a wallet transaction to execute.
exit 0xe9fad8ee
No parameters
getReward 0x3d18b912
No parameters
notifyRewardAmount 0x0c51dde4
No parameters
recoverERC20 0x8980f11f
address _token
uint256 _amount
renounceOwnership 0x715018a6
No parameters
setCap 0x47786d37
uint256 _newCap
setIsStakeVestedToken 0x622e10f6
bool _isStakeVestedToken
setIsWithdrawEnable 0x50335d52
bool _isWithdrawEnable
setSweeper 0x485e7ba5
address account
bool enable
setVestingAddress 0xe4d75c9d
address _vestingAddress
stake 0xa694fc3a
uint256 amount
stakeClaimableToken 0xa2c9ec40
uint256 amount
address userAddress
startStaking 0x71b0cbfa
No parameters
stopStaking 0x0550b266
No parameters
sweep 0x6ea056a9
address token
uint256 amount
transferOwnership 0xf2fde38b
address newOwner
updateInterest 0xfb092bba
uint256 rate
withdraw 0x2e1a7d4d
uint256 amount
Recent Transactions
No transactions found for this address