¡El código fuente de este contrato está verificado!
Metadatos del Contrato
Compilador
0.8.19+commit.7dd6d404
Idioma
Solidity
¡El código fuente de este contrato está verificado!
Metadatos del Contrato
Compilador
0.8.11+commit.d7f03943
Idioma
Solidity
Código Fuente del Contrato
Archivo 1 de 3: ReentrancyGuard.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)pragmasolidity ^0.8.0;/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/abstractcontractReentrancyGuard{
// 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.uint256privateconstant _NOT_ENTERED =1;
uint256privateconstant _ENTERED =2;
uint256private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/modifiernonReentrant() {
// On the first call to nonReentrant, _notEntered will be truerequire(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
Código Fuente del Contrato
Archivo 2 de 3: SafeMath.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)pragmasolidity ^0.8.0;// CAUTION// This version of SafeMath should only be used with Solidity 0.8 or later,// because it relies on the compiler's built in overflow checks./**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/librarySafeMath{
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/functiontryAdd(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/functiontrySub(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/functiontryMul(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the// benefit is lost if 'b' is also tested.// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522if (a ==0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/functiontryDiv(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
unchecked {
if (b ==0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/functiontryMod(uint256 a, uint256 b) internalpurereturns (bool, uint256) {
unchecked {
if (b ==0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/functionadd(uint256 a, uint256 b) internalpurereturns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/functionsub(uint256 a, uint256 b) internalpurereturns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/functionmul(uint256 a, uint256 b) internalpurereturns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/functiondiv(uint256 a, uint256 b) internalpurereturns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functionmod(uint256 a, uint256 b) internalpurereturns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/functionsub(uint256 a,
uint256 b,
stringmemory errorMessage
) internalpurereturns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functiondiv(uint256 a,
uint256 b,
stringmemory errorMessage
) internalpurereturns (uint256) {
unchecked {
require(b >0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/functionmod(uint256 a,
uint256 b,
stringmemory errorMessage
) internalpurereturns (uint256) {
unchecked {
require(b >0, errorMessage);
return a % b;
}
}
}
Código Fuente del Contrato
Archivo 3 de 3: staking_contractV7_2.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8;import"@openzeppelin/contracts/security/ReentrancyGuard.sol";
import"@openzeppelin/contracts/utils/math/SafeMath.sol";
contractStakingV7_2isReentrancyGuard{
usingSafeMathforuint256;
addresspublic owner;
addresspublic stakevault;
IERC20 publicimmutable stakingToken;
IERC20 publicimmutable rewardsToken;
uint256public stakingTokenDecimals;
uint256public rewardTokenDecimals;
stringpublic stakingTokenName;
stringpublic rewardTokenName;
stringpublic contractType;
uint256public duration;
uint256public finishAt;
uint256public updatedAt;
//claim rulesuint256public phase1;
uint256public phase2;
uint256public phase3;
uint256public phase4;
uint256public percentage1;
uint256public percentage2;
uint256public percentage3;
// Reward to be paid out per seconduint256public rewardRate;
// Sum of (reward rate * dt * rewardTokenDecimals / total supply)uint256public rewardPerTokenStored;
// User address => rewardPerTokenStoredmapping(address=>uint256) public userRewardPerTokenPaid;
// User address => rewards to be claimed since "updateReward"mapping(address=>uint256) public rewards;
// User Infomapping(address=>uint256) public balanceOf;
mapping(address=>uint256) public claimedRewards;
mapping(address=>uint256) public userStakeUpdateTime;
mapping(address=>uint256) public lastClaimedTime;
mapping(address=>uint256) public userLastTimeStaked;
// Total staked amountuint256public totalSupply;
// Total claimed amountuint256public totalClaimed;
// Total usersuint256public totalUsers;
constructor(address _stakevault, address _stakingToken, address _rewardToken, uint256 _stakingTokenDecimals, uint256 _rewardTokenDecimals, stringmemory _stakingTokenName, stringmemory _rewardTokenName, stringmemory _contractType) {
require(
keccak256(bytes(_contractType)) ==keccak256(bytes("stake")) ||keccak256(bytes(_contractType)) ==keccak256(bytes("farm")),
"Only use stake or farm as contractType"
);
owner =msg.sender;
stakevault = _stakevault;
stakingToken = IERC20(_stakingToken);
rewardsToken = IERC20(_rewardToken);
stakingTokenDecimals = _stakingTokenDecimals;
rewardTokenDecimals = _rewardTokenDecimals;
stakingTokenName = _stakingTokenName;
rewardTokenName = _rewardTokenName;
contractType = _contractType;
}
// Modifier: Only allows the contract owner to execute the functionmodifieronlyOwner() {
require(msg.sender== owner, "not authorized");
_;
}
functionupdateRewardInternal(address _account) internal{
rewardPerTokenStored = rewardPerToken();
updatedAt = lastTimeRewardApplicable();
if (_account !=address(0)) {
rewards[_account] = earned(_account);
userRewardPerTokenPaid[_account] = rewardPerTokenStored;
}
}
// Stakes the specified amount of tokensfunctionstake(uint256 _amount) externalnonReentrant{
updateRewardInternal(msg.sender);
userLastTimeStaked[msg.sender] =block.timestamp;
require(_amount >0, "amount = 0");
if (balanceOf[msg.sender] ==0) {
userStakeUpdateTime[msg.sender] =block.timestamp;
totalUsers +=1;
}
//transfer from RewardVault
stakingToken.transferFrom(msg.sender, address(this), _amount);
//update info
balanceOf[msg.sender] = balanceOf[msg.sender].add(_amount);
totalSupply = totalSupply.add(_amount);
updateRewardInternal(msg.sender);
}
// Withdraws the specified amount of tokensfunctionwithdraw(uint256 _amount) externalnonReentrant{
updateRewardInternal(msg.sender);
require(_amount >0, "amount = 0");
require(balanceOf[msg.sender] >= _amount, "amount > balance");
stakingToken.transfer(msg.sender, _amount);
//update info
balanceOf[msg.sender] = balanceOf[msg.sender].sub(_amount);
totalSupply = totalSupply.sub(_amount);
updateRewardInternal(msg.sender);
if (balanceOf[msg.sender] ==0) {
userStakeUpdateTime[msg.sender] =0;
totalUsers -=1;
}
}
// Claims the rewards for the senderfunctiongetReward() externalnonReentrant{
updateRewardInternal(msg.sender);
require(rewards[msg.sender] >0, "No rewards to claim.");
uint256 reward = rewards[msg.sender];
uint256 userStakeEndTime = userLastTimeStaked[msg.sender] + phase4;
if (block.timestamp< userStakeEndTime) {
if (block.timestamp>= userLastTimeStaked[msg.sender] + phase3) {
reward = (reward * percentage3) /100;
} elseif (block.timestamp>= userLastTimeStaked[msg.sender] + phase2) {
reward = (reward * percentage2) /100;
} elseif (block.timestamp>= userLastTimeStaked[msg.sender] + phase1) {
reward = (reward * percentage1) /100;
} else {
revert("You cannot claim yet");
}
}
rewardsToken.transferFrom(stakevault, msg.sender, reward);
//update info
rewards[msg.sender] =0;
claimedRewards[msg.sender] += reward;
totalClaimed += reward;
lastClaimedTime[msg.sender] =block.timestamp;
}
// Calculates the reward per tokenfunctionrewardPerToken() publicviewreturns (uint256) {
if (totalSupply ==0) {
return rewardPerTokenStored;
}
return rewardPerTokenStored.add(
rewardRate.mul(lastTimeRewardApplicable().sub(updatedAt)).mul(10**rewardTokenDecimals).div(totalSupply)
);
}
// Calculates the total earnings of an accountfunctionearned(address _account) publicviewreturns (uint256) {
return balanceOf[_account].mul(rewardPerToken().sub(userRewardPerTokenPaid[_account])).div(10**rewardTokenDecimals).add(rewards[_account]);
}
// Sets the duration of rewards distributionfunctionsetRewardsDurationDays(uint256 _durationInDays) externalonlyOwner{
require(finishAt <block.timestamp, "reward duration not finished");
duration = _durationInDays *1days;
}
// Notifies the contract about the amount of rewards to be distributedfunctionnotifyRewardAmount(uint256 _amount) externalonlyOwner{
updateRewardInternal(address(0));
// Reward duration not started or expired. Set the duration first.if (block.timestamp> finishAt) {
rewardRate = _amount.div(duration);
} else {
uint256 remainingRewards = finishAt.sub(block.timestamp).mul(rewardRate);
rewardRate = _amount.add(remainingRewards).div(duration);
}
require(rewardRate >0, "reward rate = 0");
require(rewardRate.mul(duration) <= rewardsToken.balanceOf(address(stakevault)), "reward amount > balance");
finishAt =block.timestamp.add(duration);
updatedAt =block.timestamp;
updateRewardInternal(address(0));
}
// Returns the last applicable timestamp for the rewardsfunctionlastTimeRewardApplicable() publicviewreturns (uint256) {
returnblock.timestamp<= finishAt ? block.timestamp : finishAt;
}
functionuserInfo(address _account) publicviewreturns (uint256, uint256, uint256, uint256, uint256) {
uint256 userPercentageX1000 = balanceOf[_account].mul(100000).div(totalSupply);
uint256 userRewardRate = rewardRate.mul(userPercentageX1000).div(100000);
uint256 userTimeUpdate =block.timestamp.sub(lastClaimedTime[_account]);
uint256 userCurrentEarned = earned(_account);
uint256 userEarningsNext24Hours = userRewardRate.mul(1days);
if (lastClaimedTime[_account] ==0) {
userTimeUpdate =block.timestamp.sub(userStakeUpdateTime[_account]);
}
return (
userPercentageX1000, // User percentage multiplied by 1000
userRewardRate, // User reward rate
userTimeUpdate, // Time elapsed since the last claim or stake update
userCurrentEarned, // User's currently earned amount
userEarningsNext24Hours // Estimated earnings in the next 24 hours
);
}
functiongetEthBalance(address _address) publicviewreturns (uint256) {
return _address.balance;
}
functionsetPhaseAndPercentage (uint256 _phase1sec, uint256 _phase2sec, uint256 _phase3sec, uint256 _phase4sec,
uint256 _percentage1, uint256 _percentage2, uint256 _percentage3) externalonlyOwner{
phase1 = _phase1sec;
phase2 = _phase2sec;
phase3 = _phase3sec;
phase4 = _phase4sec;
percentage1 = _percentage1;
percentage2 = _percentage2;
percentage3 = _percentage3;
}
functioncheckPhase(address user) publicviewreturns (uint256, uint256, uint256, uint256) {
uint256 currentPhase =0; // Default phaseuint256 phasetime =0; // Default phasetimeuint256 percent =0; // Default Reward amount to withdrawuint256 remainingtime =0; // Default time leftif (block.timestamp> (userLastTimeStaked[user] + phase4)) {
currentPhase =4;
percent =100;
phasetime =0;
} elseif (block.timestamp> (userLastTimeStaked[user] + phase3)) {
currentPhase =3;
percent = percentage3;
phasetime = phase4;
remainingtime = (userLastTimeStaked[user] + phase4) -block.timestamp;
} elseif (block.timestamp> (userLastTimeStaked[user] + phase2)) {
currentPhase =2;
percent = percentage2;
phasetime = phase3;
remainingtime = (userLastTimeStaked[user] + phase3) -block.timestamp;
} elseif (block.timestamp> (userLastTimeStaked[user] + phase1)) {
currentPhase =1;
percent = percentage1;
phasetime = phase2;
remainingtime = (userLastTimeStaked[user] + phase2) -block.timestamp;
} else {
phasetime = phase1;
remainingtime = (userLastTimeStaked[user] + phase1) -block.timestamp;
}
return (currentPhase, phasetime, percent, remainingtime);
}
}
// Interface for ERC20 token contractinterfaceIERC20{
functiontotalSupply() externalviewreturns (uint256);
functionbalanceOf(address account) externalviewreturns (uint256);
functiontransfer(address recipient, uint256 amount) externalreturns (bool);
functionallowance(address owner, address spender) externalviewreturns (uint256);
functionapprove(address spender, uint256 amount) externalreturns (bool);
functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}