Transactions
Token Transfers
Tokens
Internal Transactions
Coin Balance History
Logs
Code
Read Contract
Write Contract
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- MintStaking
- Optimization enabled
- true
- Compiler version
- v0.8.17+commit.8df45f5f
- Optimization runs
- 20000
- EVM Version
- default
- Verified at
- 2023-10-19T23:57:39.146782Z
Constructor Arguments
0x000000000000000000000000207e6b4529840a4fd518f73c68bc9c19b2a1594400000000000000000000000000000000000000000000000000000000000021c0
Arg [0] (address) : 0x207e6b4529840a4fd518f73c68bc9c19b2a15944
Arg [1] (uint256) : 8640
Contract source code
// File: contracts/mintStaking/interfaces/IMintStaking.sol
pragma solidity 0.8.17;
/**
* @title IMintStaking interface
* @dev This interface defines the methods and variables used in the Mint Staking smart contract
*/
interface IMintStaking {
/**
* @dev Struct that defines user information, including the number of staking tokens the user has provided,
* unclaimed rewards, yield rate, and the sum of total earned rewards (for stats only).
*/
struct UserInfo {
uint256 userStakedMint;
uint256 unclaimedReward;
uint256 yieldRate; // PLSPerMint: PLS yield per staked mint
uint256 sumPLSRewardsTransferredToUser;
}
/**
* @dev Struct that defines pool information, including the total amount of stakeToken that has been staked,
* the accumulated reward per staked mint, the last block number that rewards distribution occurred, the Mint
* ERC20 token address, and rewards that are not yet calculated into the yieldRateSum.
*/
struct PoolInfo {
uint256 totalStakedMint;
uint256 yieldRateSum;
uint256 lastDurationEndBlock;
address stakeToken;
uint256 stagedRewards;
}
enum OperationType {
NEW_REWARD_ADDED,
STAKE,
UNSTAKE,
HARVEST
}
event StakingEvent(
address indexed user,
uint256 amount,
uint256 timestamp,
OperationType operationType
);
event PoolEvent(
uint256 timestamp,
uint256 totalStakedMint,
uint256 yieldRateSum,
uint256 lastDurationEndBlock,
uint256 stagedRewards
);
/**
* @dev Deposits tokens to accumulate rewards
* @param _amount: the amount of stakeToken to be deposited
*/
function stake(uint256 _amount) external;
/**
* @dev Withdraws tokens from the pool and also harvests rewards
* @param _amount: the amount of stakeToken to be withdrawn
*/
function unstake(uint256 _amount) external;
/**
* @dev Harvests rewards from a pool for the sender
*/
function harvest() external;
/**
* @dev Gets pending rewards of a user from a pool, mostly for front-end
* @param _user : the user to check for pending rewards
* @return rewards : the pending rewards for the user
*/
function calculateUserProgressiveEstimatedYield(
address _user
) external view returns (uint256 rewards);
/**
* @dev Returns user information including deposited amount and reward data
* @param _user : the user whose information is to be returned
* @return _userInfo : the user's information, including staked mint, unclaimed rewards, yield rate, and sum of total earned rewards.
*/
function getUserInfo(
address _user
) external view returns (UserInfo memory _userInfo);
}
// File: @openzeppelin/contracts/utils/structs/EnumerableSet.sol
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}
// File: @openzeppelin/contracts/utils/math/SafeCast.sol
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.2._
*/
function toUint224(uint256 value) internal pure returns (uint224) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v2.5._
*/
function toUint128(uint256 value) internal pure returns (uint128) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.2._
*/
function toUint96(uint256 value) internal pure returns (uint96) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v2.5._
*/
function toUint64(uint256 value) internal pure returns (uint64) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v2.5._
*/
function toUint32(uint256 value) internal pure returns (uint32) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v2.5._
*/
function toUint16(uint256 value) internal pure returns (uint16) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v2.5._
*/
function toUint8(uint256 value) internal pure returns (uint8) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}
// File: @openzeppelin/contracts/utils/Address.sol
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
}
}
}
// File: @openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @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.
*/
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].
*/
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);
}
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @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 amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
// File: @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
/**
* @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;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// File: @openzeppelin/contracts/security/ReentrancyGuard.sol
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
// File: contracts/mintStaking/MintStaking.sol
pragma solidity 0.8.17;
// pragma abicoder v2;
/// Allow stakers to stake MINT token and receive rewards from trading fees
/// When staking, unstaking & harvesting, pending rewards will be transferred to a user account
contract MintStaking is IMintStaking, ReentrancyGuard {
using SafeCast for uint256;
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
uint256 private constant PRECISION = 1e18;
uint256 public minRewardsDurationInBlocks;
// info of pool
PoolInfo public poolInfo;
// Info of each user that stakes Staking tokens.
mapping(address => UserInfo) public userInfo;
/**
* @dev Contract constructor function
* @param _stakeToken : the address of the Mint ERC20 token to be staked
* @param _minRewardsDurationInBlocks : the minimum duration in blocks for a rewards distribution period
* @notice This constructor function initializes the contract by setting the pool information,
* including the last block number that rewards distribution occurred and the accumulated reward per staked mint,
* to their initial values of zero. It also sets the address of the Mint ERC20 token to be
* staked and the minimum duration in blocks for a rewards distribution period.
*/
constructor(address _stakeToken, uint256 _minRewardsDurationInBlocks) {
require(_stakeToken != address(0), "Invalid stake token address");
require(_minRewardsDurationInBlocks > 0, "Invalid min rewards duration");
poolInfo.lastDurationEndBlock = block.number;
poolInfo.yieldRateSum = 0;
poolInfo.stakeToken = _stakeToken;
minRewardsDurationInBlocks = _minRewardsDurationInBlocks;
}
/**
* @dev If someone sends native token to this contract, it will be treated as rewards
* @notice This function receives native tokens sent to the contract and treats them as rewards.
* It calls the updateRewards function to distribute the rewards to all stakers.
*/
receive() external payable {
updateRewards();
}
/**
* @dev Add new rewards that will be distributed to all stakers in next `_rewardsDurationInBlocks` blocks,
* @notice This function adds new rewards to the pool,
* which will be distributed to all stakers in the next rewards duration blocks.
* The function emits a StakingEvent event to notify listeners of the new reward added operation.
*/
function updateRewards() public payable {
require(msg.value > 0, "Invalid rewards amount");
updatePoolRewards();
emit StakingEvent(
msg.sender,
msg.value,
block.timestamp,
OperationType.NEW_REWARD_ADDED
);
}
/**
* @dev Stake tokens to accumulate rewards
* @param _userStakedMint: amount of stakeToken to be staked
* @notice This function allows the user to stake their tokens to accumulate rewards.
* The amount of tokens to be staked is passed as a parameter.
* The function updates the pool rewards and the user's rewards,
* collects the stakeToken from the user, and updates the user's
* staked tokens and the total staked tokens for the pool.
* If this is the user's first stake, their yieldRate is set
* to the pool's accumulated reward per staked mint.
* If the user has previously staked, their rewards are updated
* based on the change in yieldRate since their last stake.
* The function emits a StakingEvent event to notify listeners of the stake operation.
*/
function stake(uint256 _userStakedMint) external nonReentrant {
require(_userStakedMint > 1e16, "Minimum stake 0.01 MINT");
UserInfo storage user = userInfo[msg.sender];
// update pool rewards, user's rewards
updatePoolRewards();
// If this is a users first stake, set their yieldRate
if (user.userStakedMint == 0) {
user.yieldRate = poolInfo.yieldRateSum;
} else {
updateUserReward(user, false);
}
// collect stakeToken
IERC20(poolInfo.stakeToken).safeTransferFrom(
msg.sender,
address(this),
_userStakedMint
);
// update user staked userStakedMint, and total staked userStakedMint for the pool
user.userStakedMint += _userStakedMint;
poolInfo.totalStakedMint += _userStakedMint;
emit StakingEvent(
msg.sender,
_userStakedMint,
block.timestamp,
OperationType.STAKE
);
}
/**
* @dev Unstake token (of the sender) from pool, also harvest rewards
* @param _amountToUnstake: userStakedMint of stakeToken to unstake
* @notice This function allows the user to unstake their tokens from the pool
* and harvest any rewards earned. The amount of tokens to be unstaked is
* passed as a parameter. transfers the stakeToken to the user,
* and updates the user's staked tokens and the total staked tokens
* for the pool. If the user is not unstaking all of their tokens,
* they must leave at least 0.01 MINT staked. The function emits a
* StakingEvent event to notify listeners of the unstake operation.
*/
function unstake(uint256 _amountToUnstake) public nonReentrant {
address msi = msg.sender;
UserInfo storage user = userInfo[msi];
require(_amountToUnstake > 0, "Amount must be > 0");
require(user.userStakedMint >= _amountToUnstake, "Insufficient balance");
// If you are not unstaking all of your MINT you need to leave at least 0.01 MINT staked
if (user.userStakedMint - _amountToUnstake != 0) {
require(
(user.userStakedMint - _amountToUnstake) >= 1e16,
"Min remaining stake 0.01 MINT"
);
}
// update pool reward and harvest
updatePoolRewards();
updateUserReward(user, true);
user.userStakedMint -= _amountToUnstake;
poolInfo.totalStakedMint -= _amountToUnstake;
IERC20(poolInfo.stakeToken).safeTransfer(msg.sender, _amountToUnstake);
emit StakingEvent(
msg.sender,
_amountToUnstake,
block.timestamp,
OperationType.UNSTAKE
);
}
/**
* @dev Harvest rewards from a pool for the sender
* @notice This function allows the user to harvest their earned rewards from the pool.
* The function updates the pool rewards and the user's rewards, but does not
* transfer the earned rewards to the user's account. The function emits a
* StakingEvent event to notify listeners of the harvest operation.
*/
function harvest() external nonReentrant {
UserInfo storage user = userInfo[msg.sender];
require(user.userStakedMint > 0, "No staked userStakedMint");
updatePoolRewards();
updateUserReward(user, true);
}
/**
* @dev Update rewards for the pool
* @notice This function updates the rewards for the pool based on the number
* of blocks since the last rewards distribution, the minimum duration for
* rewards distribution, the total amount of staked tokens, and the staged rewards.
* If the duration for rewards distribution has been reached and the total staked tokens
* and staged rewards are greater than zero, the yield rate sum for the pool is
* updated and the staged rewards are reset to zero.
*/
function updatePoolRewards() private {
if (msg.value > 0) {
poolInfo.stagedRewards += msg.value;
}
uint256 _numberOfBlocksSinceLastDurationEndBlock = numberOfBlocksSinceLastDurationEndBlock();
bool isDurationReached = _numberOfBlocksSinceLastDurationEndBlock >=
minRewardsDurationInBlocks;
if (
isDurationReached &&
poolInfo.totalStakedMint > 0 &&
poolInfo.stagedRewards > 0
) {
// This is the only place where poolInfo.yieldRateSum is updated
poolInfo.yieldRateSum += calculateYieldRate();
poolInfo.stagedRewards = 0;
poolInfo.lastDurationEndBlock = block.number;
}
emit PoolEvent(
block.timestamp,
poolInfo.totalStakedMint,
poolInfo.yieldRateSum,
poolInfo.lastDurationEndBlock,
poolInfo.stagedRewards
);
}
/**
* @dev Update reward of user, harvest if needed
* @param user: user to update reward for
* @param shouldHarvest: if true, harvest reward for user
* @notice This function updates the reward for a given user based
* on the current yield rate sum and the user's staked tokens.
* If `shouldHarvest` is true and the user has unclaimed rewards, the function
* transfers the earned rewards to the user's account and updates the
* user's unclaimed rewards to zero. The function emits a StakingEvent
* event to notify listeners of the harvest operation.
*/
function updateUserReward(UserInfo storage user, bool shouldHarvest) private {
// calculate the user's unclaimed rewards
uint256 currentUserYieldRateSum = poolInfo.yieldRateSum - user.yieldRate;
uint256 currentUserUnclaimedReward = (user.userStakedMint *
currentUserYieldRateSum) / PRECISION;
user.unclaimedReward += currentUserUnclaimedReward;
// user gets a new yield rate as the unclaimedReward has been distrubuted with the previous yieldrate
user.yieldRate = poolInfo.yieldRateSum;
if (shouldHarvest && user.unclaimedReward > 0) {
// (stats only) update user's total rewards
user.sumPLSRewardsTransferredToUser =
user.sumPLSRewardsTransferredToUser +
user.unclaimedReward;
//send value to user
(bool success, ) = msg.sender.call{ value: user.unclaimedReward }("");
require(success, "ETH_TRANSFER_FAILED");
emit StakingEvent(
msg.sender,
user.unclaimedReward,
block.timestamp,
OperationType.HARVEST
);
// PLS Rewards have been claimed by the user
user.unclaimedReward = 0;
}
// update the user in the mapping
userInfo[msg.sender] = user;
}
/**
* @dev Calculates the progressive estimated yield for a given user.
* @notice This function provides an estimation of the yield that the user can expect to
* receive based on their staked amount and their current yield rate sum. It takes
* into account various factors such as the duration, staged rewards, and individual
* yield rates to provide a more accurate estimate of the user's potential earnings.
* @param _user The address of the user.
* @return The progressive estimated yield for the user.
*/
function calculateUserProgressiveEstimatedYield(
address _user
) external view returns (uint256) {
// Get the user information.
UserInfo storage user = userInfo[_user];
// Initialize the user's progressive estimated yield to zero.
uint256 userProgressiveEstimatedYield = 0;
// Calculate the number of blocks since the last duration end block.
uint256 _numberOfBlocksSinceLastDurationEndBlock = numberOfBlocksSinceLastDurationEndBlock();
// If the yield rate sum is zero and the number of blocks since the
// last duration end block is greater than zero and the staged rewards
// are greater than zero,
// calculate the yield rate and the user's progressive estimated yield.
if (
poolInfo.yieldRateSum == 0 &&
_numberOfBlocksSinceLastDurationEndBlock > 0 &&
poolInfo.stagedRewards > 0
) {
uint256 yieldRate = calculateYieldRate();
userProgressiveEstimatedYield =
(user.userStakedMint * yieldRate) /
PRECISION;
} else {
// Determine whether the duration has been reached.
bool isDurationReached = _numberOfBlocksSinceLastDurationEndBlock >=
minRewardsDurationInBlocks;
// Get the yield rate sum.
uint256 yieldRateSum = poolInfo.yieldRateSum;
// If the duration has been reached and the staged rewards are greater than zero, update the yield rate sum.
// This will provide a better estimate of what the user would get if they unstake or harvest.
if (isDurationReached && poolInfo.stagedRewards > 0) {
yieldRateSum += calculateYieldRate();
}
// Calculate the user's estimated yield rate sum.
uint256 currentUserEstimatedYieldRateSum = yieldRateSum - user.yieldRate;
// If the estimated yield rate sum is greater than zero, calculate the user's progressive estimated yield.
if (currentUserEstimatedYieldRateSum > 0) {
userProgressiveEstimatedYield =
(user.userStakedMint * currentUserEstimatedYieldRateSum) /
PRECISION;
}
// Add the user's unclaimed reward to their progressive estimated yield.
userProgressiveEstimatedYield += user.unclaimedReward;
}
// Return the user's progressive estimated yield.
return userProgressiveEstimatedYield;
}
/**
* @dev Retrieves user data for a specified address.
* @param _user The user's address.
* @return The user's UserInfo object.
*/
function getUserInfo(address _user) external view returns (UserInfo memory) {
// Return the user's UserInfo object.
return userInfo[_user];
}
/**
* @dev Calculates the number of blocks since the last duration end block.
* @return The number of blocks since the last duration end block.
*/
function numberOfBlocksSinceLastDurationEndBlock()
private
view
returns (uint256)
{
// Return the difference between the current block number and the last duration end block.
return block.number - poolInfo.lastDurationEndBlock;
}
/**
* @dev Calculates the yield rate.
* @return The yield rate.
*/
function calculateYieldRate() private view returns (uint256) {
// Calculate the yield rate for the duration. This is the amount of PLS the user will receive per mint staked.
return (poolInfo.stagedRewards * PRECISION) / poolInfo.totalStakedMint;
}
}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_stakeToken","internalType":"address"},{"type":"uint256","name":"_minRewardsDurationInBlocks","internalType":"uint256"}]},{"type":"event","name":"PoolEvent","inputs":[{"type":"uint256","name":"timestamp","internalType":"uint256","indexed":false},{"type":"uint256","name":"totalStakedMint","internalType":"uint256","indexed":false},{"type":"uint256","name":"yieldRateSum","internalType":"uint256","indexed":false},{"type":"uint256","name":"lastDurationEndBlock","internalType":"uint256","indexed":false},{"type":"uint256","name":"stagedRewards","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"StakingEvent","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false},{"type":"uint256","name":"timestamp","internalType":"uint256","indexed":false},{"type":"uint8","name":"operationType","internalType":"enum IMintStaking.OperationType","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"calculateUserProgressiveEstimatedYield","inputs":[{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple","name":"","internalType":"struct IMintStaking.UserInfo","components":[{"type":"uint256","name":"userStakedMint","internalType":"uint256"},{"type":"uint256","name":"unclaimedReward","internalType":"uint256"},{"type":"uint256","name":"yieldRate","internalType":"uint256"},{"type":"uint256","name":"sumPLSRewardsTransferredToUser","internalType":"uint256"}]}],"name":"getUserInfo","inputs":[{"type":"address","name":"_user","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"harvest","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"minRewardsDurationInBlocks","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"totalStakedMint","internalType":"uint256"},{"type":"uint256","name":"yieldRateSum","internalType":"uint256"},{"type":"uint256","name":"lastDurationEndBlock","internalType":"uint256"},{"type":"address","name":"stakeToken","internalType":"address"},{"type":"uint256","name":"stagedRewards","internalType":"uint256"}],"name":"poolInfo","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"stake","inputs":[{"type":"uint256","name":"_userStakedMint","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unstake","inputs":[{"type":"uint256","name":"_amountToUnstake","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"updateRewards","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"userStakedMint","internalType":"uint256"},{"type":"uint256","name":"unclaimedReward","internalType":"uint256"},{"type":"uint256","name":"yieldRate","internalType":"uint256"},{"type":"uint256","name":"sumPLSRewardsTransferredToUser","internalType":"uint256"}],"name":"userInfo","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"receive","stateMutability":"payable"}]
Contract Creation Code
0x608060405234801561001057600080fd5b5060405161147a38038061147a83398101604081905261002f91610111565b60016000556001600160a01b03821661008f5760405162461bcd60e51b815260206004820152601b60248201527f496e76616c6964207374616b6520746f6b656e2061646472657373000000000060448201526064015b60405180910390fd5b600081116100df5760405162461bcd60e51b815260206004820152601c60248201527f496e76616c6964206d696e2072657761726473206475726174696f6e000000006044820152606401610086565b436004556000600355600580546001600160a01b0319166001600160a01b03939093169290921790915560015561014b565b6000806040838503121561012457600080fd5b82516001600160a01b038116811461013b57600080fd5b6020939093015192949293505050565b6113208061015a6000396000f3fe60806040526004361061009a5760003560e01c80634641257d116100695780636386c1c71161004e5780636386c1c7146101fb578063a694fc3a1461024e578063b1d87d961461026e57600080fd5b80634641257d1461016b5780635a2f3d091461018057600080fd5b80631959a002146100ae5780632e17de78146101155780632e521a3b146101355780633e158b0c1461016357600080fd5b366100a9576100a7610284565b005b600080fd5b3480156100ba57600080fd5b506100f06100c93660046110e1565b60076020526000908152604090208054600182015460028301546003909301549192909184565b6040805194855260208501939093529183015260608201526080015b60405180910390f35b34801561012157600080fd5b506100a761013036600461111e565b610350565b34801561014157600080fd5b506101556101503660046110e1565b610595565b60405190815260200161010c565b6100a7610284565b34801561017757600080fd5b506100a76106af565b34801561018c57600080fd5b506002546003546004546005546006546101bd9493929173ffffffffffffffffffffffffffffffffffffffff169085565b6040805195865260208601949094529284019190915273ffffffffffffffffffffffffffffffffffffffff166060830152608082015260a00161010c565b34801561020757600080fd5b5061021b6102163660046110e1565b61074e565b60405161010c91908151815260208083015190820152604080830151908201526060918201519181019190915260800190565b34801561025a57600080fd5b506100a761026936600461111e565b6107d4565b34801561027a57600080fd5b5061015560015481565b600034116102f3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f496e76616c6964207265776172647320616d6f756e740000000000000000000060448201526064015b60405180910390fd5b6102fb610926565b3373ffffffffffffffffffffffffffffffffffffffff167f3585198d07e828811559e83f38a04e95c328af4edd28122306b10475843fdd353442600060405161034693929190611137565b60405180910390a2565b610358610a00565b336000818152600760205260409020826103ce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f416d6f756e74206d757374206265203e2030000000000000000000000000000060448201526064016102ea565b8054831115610439576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f496e73756666696369656e742062616c616e636500000000000000000000000060448201526064016102ea565b80546104469084906111b9565b156104c9578054662386f26fc10000906104619085906111b9565b10156104c9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4d696e2072656d61696e696e67207374616b6520302e3031204d494e5400000060448201526064016102ea565b6104d1610926565b6104dc816001610a73565b828160000160008282546104f091906111b9565b90915550506002805484919060009061050a9084906111b9565b90915550506005546105339073ffffffffffffffffffffffffffffffffffffffff163385610c4d565b3373ffffffffffffffffffffffffffffffffffffffff167f3585198d07e828811559e83f38a04e95c328af4edd28122306b10475843fdd358442600260405161057e93929190611137565b60405180910390a250506105926001600055565b50565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260076020526040812081806105c4610d26565b6003549091501580156105d75750600081115b80156105e4575060065415155b156106205760006105f3610d3b565b9050670de0b6b3a764000081856000015461060e91906111d2565b61061891906111e9565b9250506106a7565b60015460035490821080159190829061063a575060065415155b1561065457610647610d3b565b6106519082611224565b90505b600085600201548261066691906111b9565b90508015610692578554670de0b6b3a7640000906106859083906111d2565b61068f91906111e9565b94505b60018601546106a19086611224565b94505050505b509392505050565b6106b7610a00565b336000908152600760205260409020805461072e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4e6f207374616b656420757365725374616b65644d696e74000000000000000060448201526064016102ea565b610736610926565b610741816001610a73565b5061074c6001600055565b565b6107796040518060800160405280600081526020016000815260200160008152602001600081525090565b5073ffffffffffffffffffffffffffffffffffffffff16600090815260076020908152604091829020825160808101845281548152600182015492810192909252600281015492820192909252600390910154606082015290565b6107dc610a00565b662386f26fc10000811161084c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d696e696d756d207374616b6520302e3031204d494e5400000000000000000060448201526064016102ea565b336000908152600760205260409020610863610926565b8054600003610879576003546002820155610884565b610884816000610a73565b6005546108a99073ffffffffffffffffffffffffffffffffffffffff16333085610d62565b818160000160008282546108bd9190611224565b9091555050600280548391906000906108d7908490611224565b909155505060405133907f3585198d07e828811559e83f38a04e95c328af4edd28122306b10475843fdd35906109139085904290600190611137565b60405180910390a2506105926001600055565b34156109475734600260040160008282546109419190611224565b90915550505b6000610951610d26565b60015490915081108015908190610969575060025415155b8015610976575060065415155b156109a457610983610d3b565b60038054600090610995908490611224565b90915550506000600655436004555b600254600354600454600654604080514281526020810195909552840192909252606083015260808201527f70fb16df52b3673ab8b20eac89cded3b68181f7b69752d4b92b96d2c29865dd79060a00160405180910390a15050565b600260005403610a6c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016102ea565b6002600055565b6002820154600354600091610a87916111b9565b90506000670de0b6b3a7640000828560000154610aa491906111d2565b610aae91906111e9565b905080846001016000828254610ac49190611224565b90915550506003546002850155828015610ae2575060008460010154115b15610c155783600101548460030154610afb9190611224565b6003850155600184015460405160009133918381818185875af1925050503d8060008114610b45576040519150601f19603f3d011682016040523d82523d6000602084013e610b4a565b606091505b5050905080610bb5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4554485f5452414e534645525f4641494c45440000000000000000000000000060448201526064016102ea565b3373ffffffffffffffffffffffffffffffffffffffff167f3585198d07e828811559e83f38a04e95c328af4edd28122306b10475843fdd358660010154426003604051610c0493929190611137565b60405180910390a250600060018501555b505033600090815260076020526040902082548155600180840154908201556002808401549082015560039283015492019190915550565b60405173ffffffffffffffffffffffffffffffffffffffff8316602482015260448101829052610d219084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152610dc6565b505050565b600454600090610d3690436111b9565b905090565b60025460065460009190610d5890670de0b6b3a7640000906111d2565b610d3691906111e9565b60405173ffffffffffffffffffffffffffffffffffffffff80851660248301528316604482015260648101829052610dc09085907f23b872dd0000000000000000000000000000000000000000000000000000000090608401610c9f565b50505050565b6000610e28826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610ed29092919063ffffffff16565b805190915015610d215780806020019051810190610e469190611237565b610d21576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f7420737563636565640000000000000000000000000000000000000000000060648201526084016102ea565b6060610ee18484600085610ee9565b949350505050565b606082471015610f7b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c000000000000000000000000000000000000000000000000000060648201526084016102ea565b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051610fa4919061127d565b60006040518083038185875af1925050503d8060008114610fe1576040519150601f19603f3d011682016040523d82523d6000602084013e610fe6565b606091505b5091509150610ff787838387611002565b979650505050505050565b606083156110985782516000036110915773ffffffffffffffffffffffffffffffffffffffff85163b611091576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016102ea565b5081610ee1565b610ee183838151156110ad5781518083602001fd5b806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102ea9190611299565b6000602082840312156110f357600080fd5b813573ffffffffffffffffffffffffffffffffffffffff8116811461111757600080fd5b9392505050565b60006020828403121561113057600080fd5b5035919050565b83815260208101839052606081016004831061117c577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b826040830152949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b818103818111156111cc576111cc61118a565b92915050565b80820281158282048414176111cc576111cc61118a565b60008261121f577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b808201808211156111cc576111cc61118a565b60006020828403121561124957600080fd5b8151801515811461111757600080fd5b60005b8381101561127457818101518382015260200161125c565b50506000910152565b6000825161128f818460208701611259565b9190910192915050565b60208152600082518060208401526112b8816040850160208701611259565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016919091016040019291505056fea264697066735822122002428b47171434d69cf448e26a6729ee3d9e5eca5278f3791d1b70ede6a1775164736f6c63430008110033000000000000000000000000207e6b4529840a4fd518f73c68bc9c19b2a1594400000000000000000000000000000000000000000000000000000000000021c0
Deployed ByteCode
0x60806040526004361061009a5760003560e01c80634641257d116100695780636386c1c71161004e5780636386c1c7146101fb578063a694fc3a1461024e578063b1d87d961461026e57600080fd5b80634641257d1461016b5780635a2f3d091461018057600080fd5b80631959a002146100ae5780632e17de78146101155780632e521a3b146101355780633e158b0c1461016357600080fd5b366100a9576100a7610284565b005b600080fd5b3480156100ba57600080fd5b506100f06100c93660046110e1565b60076020526000908152604090208054600182015460028301546003909301549192909184565b6040805194855260208501939093529183015260608201526080015b60405180910390f35b34801561012157600080fd5b506100a761013036600461111e565b610350565b34801561014157600080fd5b506101556101503660046110e1565b610595565b60405190815260200161010c565b6100a7610284565b34801561017757600080fd5b506100a76106af565b34801561018c57600080fd5b506002546003546004546005546006546101bd9493929173ffffffffffffffffffffffffffffffffffffffff169085565b6040805195865260208601949094529284019190915273ffffffffffffffffffffffffffffffffffffffff166060830152608082015260a00161010c565b34801561020757600080fd5b5061021b6102163660046110e1565b61074e565b60405161010c91908151815260208083015190820152604080830151908201526060918201519181019190915260800190565b34801561025a57600080fd5b506100a761026936600461111e565b6107d4565b34801561027a57600080fd5b5061015560015481565b600034116102f3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601660248201527f496e76616c6964207265776172647320616d6f756e740000000000000000000060448201526064015b60405180910390fd5b6102fb610926565b3373ffffffffffffffffffffffffffffffffffffffff167f3585198d07e828811559e83f38a04e95c328af4edd28122306b10475843fdd353442600060405161034693929190611137565b60405180910390a2565b610358610a00565b336000818152600760205260409020826103ce576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f416d6f756e74206d757374206265203e2030000000000000000000000000000060448201526064016102ea565b8054831115610439576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f496e73756666696369656e742062616c616e636500000000000000000000000060448201526064016102ea565b80546104469084906111b9565b156104c9578054662386f26fc10000906104619085906111b9565b10156104c9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4d696e2072656d61696e696e67207374616b6520302e3031204d494e5400000060448201526064016102ea565b6104d1610926565b6104dc816001610a73565b828160000160008282546104f091906111b9565b90915550506002805484919060009061050a9084906111b9565b90915550506005546105339073ffffffffffffffffffffffffffffffffffffffff163385610c4d565b3373ffffffffffffffffffffffffffffffffffffffff167f3585198d07e828811559e83f38a04e95c328af4edd28122306b10475843fdd358442600260405161057e93929190611137565b60405180910390a250506105926001600055565b50565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260076020526040812081806105c4610d26565b6003549091501580156105d75750600081115b80156105e4575060065415155b156106205760006105f3610d3b565b9050670de0b6b3a764000081856000015461060e91906111d2565b61061891906111e9565b9250506106a7565b60015460035490821080159190829061063a575060065415155b1561065457610647610d3b565b6106519082611224565b90505b600085600201548261066691906111b9565b90508015610692578554670de0b6b3a7640000906106859083906111d2565b61068f91906111e9565b94505b60018601546106a19086611224565b94505050505b509392505050565b6106b7610a00565b336000908152600760205260409020805461072e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f4e6f207374616b656420757365725374616b65644d696e74000000000000000060448201526064016102ea565b610736610926565b610741816001610a73565b5061074c6001600055565b565b6107796040518060800160405280600081526020016000815260200160008152602001600081525090565b5073ffffffffffffffffffffffffffffffffffffffff16600090815260076020908152604091829020825160808101845281548152600182015492810192909252600281015492820192909252600390910154606082015290565b6107dc610a00565b662386f26fc10000811161084c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4d696e696d756d207374616b6520302e3031204d494e5400000000000000000060448201526064016102ea565b336000908152600760205260409020610863610926565b8054600003610879576003546002820155610884565b610884816000610a73565b6005546108a99073ffffffffffffffffffffffffffffffffffffffff16333085610d62565b818160000160008282546108bd9190611224565b9091555050600280548391906000906108d7908490611224565b909155505060405133907f3585198d07e828811559e83f38a04e95c328af4edd28122306b10475843fdd35906109139085904290600190611137565b60405180910390a2506105926001600055565b34156109475734600260040160008282546109419190611224565b90915550505b6000610951610d26565b60015490915081108015908190610969575060025415155b8015610976575060065415155b156109a457610983610d3b565b60038054600090610995908490611224565b90915550506000600655436004555b600254600354600454600654604080514281526020810195909552840192909252606083015260808201527f70fb16df52b3673ab8b20eac89cded3b68181f7b69752d4b92b96d2c29865dd79060a00160405180910390a15050565b600260005403610a6c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0060448201526064016102ea565b6002600055565b6002820154600354600091610a87916111b9565b90506000670de0b6b3a7640000828560000154610aa491906111d2565b610aae91906111e9565b905080846001016000828254610ac49190611224565b90915550506003546002850155828015610ae2575060008460010154115b15610c155783600101548460030154610afb9190611224565b6003850155600184015460405160009133918381818185875af1925050503d8060008114610b45576040519150601f19603f3d011682016040523d82523d6000602084013e610b4a565b606091505b5050905080610bb5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f4554485f5452414e534645525f4641494c45440000000000000000000000000060448201526064016102ea565b3373ffffffffffffffffffffffffffffffffffffffff167f3585198d07e828811559e83f38a04e95c328af4edd28122306b10475843fdd358660010154426003604051610c0493929190611137565b60405180910390a250600060018501555b505033600090815260076020526040902082548155600180840154908201556002808401549082015560039283015492019190915550565b60405173ffffffffffffffffffffffffffffffffffffffff8316602482015260448101829052610d219084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152610dc6565b505050565b600454600090610d3690436111b9565b905090565b60025460065460009190610d5890670de0b6b3a7640000906111d2565b610d3691906111e9565b60405173ffffffffffffffffffffffffffffffffffffffff80851660248301528316604482015260648101829052610dc09085907f23b872dd0000000000000000000000000000000000000000000000000000000090608401610c9f565b50505050565b6000610e28826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610ed29092919063ffffffff16565b805190915015610d215780806020019051810190610e469190611237565b610d21576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f7420737563636565640000000000000000000000000000000000000000000060648201526084016102ea565b6060610ee18484600085610ee9565b949350505050565b606082471015610f7b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c000000000000000000000000000000000000000000000000000060648201526084016102ea565b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051610fa4919061127d565b60006040518083038185875af1925050503d8060008114610fe1576040519150601f19603f3d011682016040523d82523d6000602084013e610fe6565b606091505b5091509150610ff787838387611002565b979650505050505050565b606083156110985782516000036110915773ffffffffffffffffffffffffffffffffffffffff85163b611091576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016102ea565b5081610ee1565b610ee183838151156110ad5781518083602001fd5b806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102ea9190611299565b6000602082840312156110f357600080fd5b813573ffffffffffffffffffffffffffffffffffffffff8116811461111757600080fd5b9392505050565b60006020828403121561113057600080fd5b5035919050565b83815260208101839052606081016004831061117c577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b826040830152949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b818103818111156111cc576111cc61118a565b92915050565b80820281158282048414176111cc576111cc61118a565b60008261121f577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b808201808211156111cc576111cc61118a565b60006020828403121561124957600080fd5b8151801515811461111757600080fd5b60005b8381101561127457818101518382015260200161125c565b50506000910152565b6000825161128f818460208701611259565b9190910192915050565b60208152600082518060208401526112b8816040850160208701611259565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016919091016040019291505056fea264697066735822122002428b47171434d69cf448e26a6729ee3d9e5eca5278f3791d1b70ede6a1775164736f6c63430008110033