Source Code
Latest 25 from a total of 32,691 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Burn Batch | 14210771 | 14 hrs ago | IN | 5 GLMR | 0.00589725 | ||||
| Burn Batch | 14210766 | 14 hrs ago | IN | 1 GLMR | 0.00604225 | ||||
| Stake | 14210682 | 14 hrs ago | IN | 0 GLMR | 0.00430162 | ||||
| Claim Rewards | 14210656 | 14 hrs ago | IN | 0 GLMR | 0.00404625 | ||||
| Burn Batch | 14210655 | 14 hrs ago | IN | 10 GLMR | 0.00862543 | ||||
| Stake | 14201321 | 32 hrs ago | IN | 0 GLMR | 0.0041065 | ||||
| Stake | 14199705 | 35 hrs ago | IN | 0 GLMR | 0.0041065 | ||||
| Stake | 14199683 | 35 hrs ago | IN | 0 GLMR | 0.0041065 | ||||
| Stake | 14196236 | 41 hrs ago | IN | 0 GLMR | 0.00430162 | ||||
| Burn Batch | 14196233 | 41 hrs ago | IN | 100 GLMR | 0.00590525 | ||||
| Burn Batch | 14196229 | 42 hrs ago | IN | 10 GLMR | 0.00714903 | ||||
| Claim Rewards | 14196210 | 42 hrs ago | IN | 0 GLMR | 0.00482687 | ||||
| Burn Batch | 14183800 | 2 days ago | IN | 5 GLMR | 0.00589725 | ||||
| Burn Batch | 14183797 | 2 days ago | IN | 1 GLMR | 0.00604225 | ||||
| Stake | 14183402 | 2 days ago | IN | 0 GLMR | 0.00430162 | ||||
| Burn Batch | 14183400 | 2 days ago | IN | 100 GLMR | 0.00590525 | ||||
| Burn Batch | 14183383 | 2 days ago | IN | 10 GLMR | 0.00714903 | ||||
| Claim Rewards | 14183376 | 2 days ago | IN | 0 GLMR | 0.00491437 | ||||
| Burn Batch | 14171390 | 3 days ago | IN | 100 GLMR | 0.00590525 | ||||
| Stake | 14171384 | 3 days ago | IN | 0 GLMR | 0.00430162 | ||||
| Claim Rewards | 14171379 | 3 days ago | IN | 0 GLMR | 0.00404625 | ||||
| Burn Batch | 14171378 | 3 days ago | IN | 10 GLMR | 0.00862543 | ||||
| Stake | 14157772 | 4 days ago | IN | 0 GLMR | 0.00430162 | ||||
| Burn Batch | 14157768 | 4 days ago | IN | 100 GLMR | 0.00590525 | ||||
| Burn Batch | 14157764 | 4 days ago | IN | 10 GLMR | 0.00590525 |
Latest 25 internal transactions (View All)
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 14210771 | 14 hrs ago | 4.71036843 GLMR | ||||
| 14210766 | 14 hrs ago | 0.99613444 GLMR | ||||
| 14210655 | 14 hrs ago | 9.22858271 GLMR | ||||
| 14196233 | 41 hrs ago | 97.19803437 GLMR | ||||
| 14196229 | 42 hrs ago | 9.4522867 GLMR | ||||
| 14183800 | 2 days ago | 4.71036843 GLMR | ||||
| 14183797 | 2 days ago | 0.99613444 GLMR | ||||
| 14183400 | 2 days ago | 97.19803437 GLMR | ||||
| 14183383 | 2 days ago | 9.4522867 GLMR | ||||
| 14171390 | 3 days ago | 97.19803437 GLMR | ||||
| 14171378 | 3 days ago | 9.22858271 GLMR | ||||
| 14157768 | 4 days ago | 97.19803437 GLMR | ||||
| 14157764 | 4 days ago | 9.70653096 GLMR | ||||
| 14157758 | 4 days ago | 9.4522867 GLMR | ||||
| 14148185 | 5 days ago | 4.71036843 GLMR | ||||
| 14148181 | 5 days ago | 0.99613444 GLMR | ||||
| 14145129 | 5 days ago | 97.19803437 GLMR | ||||
| 14145122 | 5 days ago | 9.4522867 GLMR | ||||
| 14132341 | 6 days ago | 97.19803437 GLMR | ||||
| 14132334 | 6 days ago | 97.19803437 GLMR | ||||
| 14132297 | 6 days ago | 9.4522867 GLMR | ||||
| 14129527 | 6 days ago | 4.71036843 GLMR | ||||
| 14129519 | 6 days ago | 0.99554669 GLMR | ||||
| 14121149 | 7 days ago | 97.19803437 GLMR | ||||
| 14121145 | 7 days ago | 9.4522867 GLMR |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
DBXen
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/metatx/ERC2771Context.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./interfaces/IBurnRedeemable.sol";
import "./DBXenERC20.sol";
import "./XENCrypto.sol";
/**
* Main DBXen protocol contract used to burn xen tokens,
* allocate DBXen token rewards, distribute native token fees, stake and unstake.
*/
contract DBXen is ERC2771Context, ReentrancyGuard, IBurnRedeemable {
using SafeERC20 for DBXenERC20;
/**
* DBXen Reward Token contract.
* Initialized in constructor.
*/
DBXenERC20 public dxn;
/**
* XEN Token contract.
* Initialized in constructor.
*/
XENCrypto public xen;
/**
* Basis points representation of 100 percent.
*/
uint256 public constant MAX_BPS = 100_000;
/**
* Amount of XEN tokens per batch
*/
uint256 public constant XEN_BATCH_AMOUNT = 2_500_000 ether;
/**
* Used to minimise division remainder when earned fees are calculated.
*/
uint256 public constant SCALING_FACTOR = 1e40;
/**
* Contract creation timestamp.
* Initialized in constructor.
*/
uint256 public immutable i_initialTimestamp;
/**
* Length of a reward distribution cycle.
* Initialized in contstructor to 1 day.
*/
uint256 public immutable i_periodDuration;
/**
* Reward token amount allocated for the current cycle.
*/
uint256 public currentCycleReward;
/**
* Reward token amount allocated for the previous cycle.
*/
uint256 public lastCycleReward;
/**
* Helper variable to store pending stake amount.
*/
uint256 public pendingStake;
/**
* Index (0-based) of the current cycle.
*
* Updated upon cycle setup that is triggered by contract interraction
* (account burn tokens, claims fees, claims rewards, stakes or unstakes).
*/
uint256 public currentCycle;
/**
* Helper variable to store the index of the last active cycle.
*/
uint256 public lastStartedCycle;
/**
* Stores the index of the penultimate active cycle plus one.
*/
uint256 public previousStartedCycle;
/**
* Helper variable to store the index of the last active cycle.
*/
uint256 public currentStartedCycle;
/**
* Stores the amount of stake that will be subracted from the total
* stake once a new cycle starts.
*/
uint256 public pendingStakeWithdrawal;
/**
* Accumulates fees while there are no tokens staked after the
* entire token supply has been distributed. Once tokens are
* staked again, these fees will be distributed in the next
* active cycle.
*/
uint256 public pendingFees;
/**
* Total amount of batches burned
*/
uint256 public totalNumberOfBatchesBurned;
/**
* The amount of batches an account has burned.
* Resets during a new cycle when an account performs an action
* that updates its stats.
*/
mapping(address => uint256) public accCycleBatchesBurned;
/**
* The total amount of batches all accounts have burned per cycle.
*/
mapping(uint256 => uint256) public cycleTotalBatchesBurned;
/**
* The last cycle in which an account has burned.
*/
mapping(address => uint256) public lastActiveCycle;
/**
* Current unclaimed rewards and staked amounts per account.
*/
mapping(address => uint256) public accRewards;
/**
* The fee amount the account can withdraw.
*/
mapping(address => uint256) public accAccruedFees;
/**
* Total token rewards allocated per cycle.
*/
mapping(uint256 => uint256) public rewardPerCycle;
/**
* Total unclaimed token reward and stake.
*
* Updated when a new cycle starts and when an account claims rewards, stakes or unstakes externally owned tokens.
*/
mapping(uint256 => uint256) public summedCycleStakes;
/**
* The last cycle in which the account had its fees updated.
*/
mapping(address => uint256) public lastFeeUpdateCycle;
/**
* The total amount of accrued fees per cycle.
*/
mapping(uint256 => uint256) public cycleAccruedFees;
/**
* Sum of previous total cycle accrued fees divided by cycle stake.
*/
mapping(uint256 => uint256) public cycleFeesPerStakeSummed;
/**
* Amount an account has staked and is locked during given cycle.
*/
mapping(address => mapping(uint256 => uint256)) public accStakeCycle;
/**
* Stake amount an account can currently withdraw.
*/
mapping(address => uint256) public accWithdrawableStake;
/**
* Cycle in which an account's stake is locked and begins generating fees.
*/
mapping(address => uint256) public accFirstStake;
/**
* Same as accFirstStake, but stores the second stake seperately
* in case the account stakes in two consecutive active cycles.
*/
mapping(address => uint256) public accSecondStake;
/**
* @dev Emitted when `account` claims an amount of `fees` in native token
* through {claimFees} in `cycle`.
*/
event FeesClaimed(
uint256 indexed cycle,
address indexed account,
uint256 fees
);
/**
* @dev Emitted when `account` stakes `amount` DBX tokens through
* {stake} in `cycle`.
*/
event Staked(
uint256 indexed cycle,
address indexed account,
uint256 amount
);
/**
* @dev Emitted when `account` unstakes `amount` DBX tokens through
* {unstake} in `cycle`.
*/
event Unstaked(
uint256 indexed cycle,
address indexed account,
uint256 amount
);
/**
* @dev Emitted when `account` claims `amount` DBX
* token rewards through {claimRewards} in `cycle`.
*/
event RewardsClaimed(
uint256 indexed cycle,
address indexed account,
uint256 reward
);
/**
* @dev Emitted when calling {burnBatch} marking the new current `cycle`,
* `calculatedCycleReward` and `summedCycleStakes`.
*/
event NewCycleStarted(
uint256 indexed cycle,
uint256 calculatedCycleReward,
uint256 summedCycleStakes
);
/**
* @dev Emitted when calling {burnBatch} function for
* `userAddress` which burns `batchNumber` * 2500000 tokens
*/
event Burn(
address indexed userAddress,
uint256 batchNumber
);
/**
* @dev Checks that the caller has sent an amount that is equal or greater
* than the sum of the protocol fee
* The change is sent back to the caller.
*
*/
modifier gasWrapper(uint256 batchNumber) {
uint256 startGas = gasleft();
_;
uint256 discount = (batchNumber * (MAX_BPS - 5 * batchNumber));
uint256 protocolFee = ((startGas - gasleft() + 39400) * tx.gasprice * discount) / MAX_BPS;
require(msg.value >= protocolFee , "DBXen: value less than protocol fee");
totalNumberOfBatchesBurned += batchNumber;
cycleTotalBatchesBurned[currentCycle] += batchNumber;
accCycleBatchesBurned[_msgSender()] += batchNumber;
cycleAccruedFees[currentCycle] += protocolFee;
sendViaCall(payable(msg.sender), msg.value - protocolFee);
}
/**
* @param forwarder forwarder contract address.
* @param xenAddress XEN contract address.
*/
constructor(address forwarder, address xenAddress) ERC2771Context(forwarder) {
dxn = new DBXenERC20();
i_initialTimestamp = block.timestamp;
i_periodDuration = 1 days;
currentCycleReward = 10000 * 1e18;
summedCycleStakes[0] = 10000 * 1e18;
rewardPerCycle[0] = 10000 * 1e18;
xen = XENCrypto(xenAddress);
}
// IBurnRedeemable IMPLEMENTATION
/**
@dev implements IBurnRedeemable interface for burning XEN and completing update for state
*/
function onTokenBurned(address user, uint256 amount) external{
require(msg.sender == address(xen), "DBXen: illegal callback caller");
calculateCycle();
updateCycleFeesPerStakeSummed();
setUpNewCycle();
updateStats(user);
lastActiveCycle[user] = currentCycle;
emit Burn(user, amount);
}
/**
* @dev Burn batchNumber * 2.500.000 tokens
*
* @param batchNumber number of batches
*/
function burnBatch(
uint256 batchNumber
)
external
payable
nonReentrant()
gasWrapper(batchNumber)
{
require(batchNumber <= 10000, "DBXen: maxim batch number is 10000");
require(batchNumber > 0, "DBXen: min batch number is 1");
require(xen.balanceOf(msg.sender) >= batchNumber * XEN_BATCH_AMOUNT, "DBXen: not enough tokens for burn");
IBurnableToken(xen).burn(msg.sender , batchNumber * XEN_BATCH_AMOUNT);
}
/**
* @dev Mints newly accrued account rewards and transfers the entire
* allocated amount to the transaction sender address.
*/
function claimRewards()
external
nonReentrant()
{
calculateCycle();
updateCycleFeesPerStakeSummed();
updateStats(_msgSender());
uint256 reward = accRewards[_msgSender()] - accWithdrawableStake[_msgSender()];
require(reward > 0, "DBXen: account has no rewards");
accRewards[_msgSender()] -= reward;
if (lastStartedCycle == currentStartedCycle) {
pendingStakeWithdrawal += reward;
} else {
summedCycleStakes[currentCycle] = summedCycleStakes[currentCycle] - reward;
}
dxn.mintReward(_msgSender(), reward);
emit RewardsClaimed(currentCycle, _msgSender(), reward);
}
/**
* @dev Transfers newly accrued fees to sender's address.
*/
function claimFees()
external
nonReentrant()
{
calculateCycle();
updateCycleFeesPerStakeSummed();
updateStats(_msgSender());
uint256 fees = accAccruedFees[_msgSender()];
require(fees > 0, "DBXen: amount is zero");
accAccruedFees[_msgSender()] = 0;
sendViaCall(payable(_msgSender()), fees);
emit FeesClaimed(getCurrentCycle(), _msgSender(), fees);
}
/**
* @dev Stakes the given amount and increases the share of the daily allocated fees.
* The tokens are transfered from sender account to this contract.
* To receive the tokens back, the unstake function must be called by the same account address.
*
* @param amount token amount to be staked (in wei).
*/
function stake(uint256 amount)
external
nonReentrant()
{
calculateCycle();
updateCycleFeesPerStakeSummed();
updateStats(_msgSender());
require(amount > 0, "DBXen: amount is zero");
pendingStake += amount;
uint256 cycleToSet = currentCycle + 1;
if (lastStartedCycle == currentStartedCycle) {
cycleToSet = lastStartedCycle + 1;
}
if (
(cycleToSet != accFirstStake[_msgSender()] &&
cycleToSet != accSecondStake[_msgSender()])
) {
if (accFirstStake[_msgSender()] == 0) {
accFirstStake[_msgSender()] = cycleToSet;
} else if (accSecondStake[_msgSender()] == 0) {
accSecondStake[_msgSender()] = cycleToSet;
}
}
accStakeCycle[_msgSender()][cycleToSet] += amount;
dxn.safeTransferFrom(_msgSender(), address(this), amount);
emit Staked(cycleToSet, _msgSender(), amount);
}
/**
* @dev Unstakes the given amount and decreases the share of the daily allocated fees.
* If the balance is availabe, the tokens are transfered from this contract to the sender account.
*
* @param amount token amount to be unstaked (in wei).
*/
function unstake(uint256 amount)
external
nonReentrant()
{
calculateCycle();
updateCycleFeesPerStakeSummed();
updateStats(_msgSender());
require(amount > 0, "DBXen: amount is zero");
require(
amount <= accWithdrawableStake[_msgSender()],
"DBXen: amount greater than withdrawable stake"
);
if (lastStartedCycle == currentStartedCycle) {
pendingStakeWithdrawal += amount;
} else {
summedCycleStakes[currentCycle] -= amount;
}
accWithdrawableStake[_msgSender()] -= amount;
accRewards[_msgSender()] -= amount;
dxn.safeTransfer(_msgSender(), amount);
emit Unstaked(currentCycle, _msgSender(), amount);
}
/**
* @dev Returns the index of the cycle at the current block time.
*/
function getCurrentCycle() public view returns (uint256) {
return (block.timestamp - i_initialTimestamp) / i_periodDuration;
}
/**
* @dev Updates the index of the cycle.
*/
function calculateCycle() internal {
uint256 calculatedCycle = getCurrentCycle();
if (calculatedCycle > currentCycle) {
currentCycle = calculatedCycle;
}
}
/**
* @dev Updates the global helper variables related to fee distribution.
*/
function updateCycleFeesPerStakeSummed() internal {
if (currentCycle != currentStartedCycle) {
previousStartedCycle = lastStartedCycle + 1;
lastStartedCycle = currentStartedCycle;
}
if (
currentCycle > lastStartedCycle &&
cycleFeesPerStakeSummed[lastStartedCycle + 1] == 0
) {
uint256 feePerStake;
if(summedCycleStakes[lastStartedCycle] != 0) {
feePerStake = ((cycleAccruedFees[lastStartedCycle] + pendingFees) * SCALING_FACTOR) /
summedCycleStakes[lastStartedCycle];
pendingFees = 0;
} else {
pendingFees += cycleAccruedFees[lastStartedCycle];
feePerStake = 0;
}
cycleFeesPerStakeSummed[lastStartedCycle + 1] = cycleFeesPerStakeSummed[previousStartedCycle] + feePerStake;
}
}
/**
* @dev Updates the global state related to starting a new cycle along
* with helper state variables used in computation of staking rewards.
*/
function setUpNewCycle() internal {
if (rewardPerCycle[currentCycle] == 0) {
lastCycleReward = currentCycleReward;
uint256 calculatedCycleReward = (lastCycleReward * 10000) / 10020;
currentCycleReward = calculatedCycleReward;
rewardPerCycle[currentCycle] = calculatedCycleReward;
currentStartedCycle = currentCycle;
summedCycleStakes[currentStartedCycle] += summedCycleStakes[lastStartedCycle] + currentCycleReward;
if (pendingStake != 0) {
summedCycleStakes[currentStartedCycle] += pendingStake;
pendingStake = 0;
}
if (pendingStakeWithdrawal != 0) {
summedCycleStakes[currentStartedCycle] -= pendingStakeWithdrawal;
pendingStakeWithdrawal = 0;
}
emit NewCycleStarted(
currentCycle,
calculatedCycleReward,
summedCycleStakes[currentStartedCycle]
);
}
}
/**
* @dev Updates various helper state variables used to compute token rewards
* and fees distribution for a given account.
*
* @param account the address of the account to make the updates for.
*/
function updateStats(address account) internal {
if (
currentCycle > lastActiveCycle[account] &&
accCycleBatchesBurned[account] != 0
) {
uint256 lastCycleAccReward = (accCycleBatchesBurned[account] * rewardPerCycle[lastActiveCycle[account]]) /
cycleTotalBatchesBurned[lastActiveCycle[account]];
accRewards[account] += lastCycleAccReward;
accCycleBatchesBurned[account] = 0;
}
if (
currentCycle > lastStartedCycle &&
lastFeeUpdateCycle[account] != lastStartedCycle + 1
) {
accAccruedFees[account] =
accAccruedFees[account] +
(
(accRewards[account] *
(cycleFeesPerStakeSummed[lastStartedCycle + 1] -
cycleFeesPerStakeSummed[lastFeeUpdateCycle[account]]
)
)
) /
SCALING_FACTOR;
lastFeeUpdateCycle[account] = lastStartedCycle + 1;
}
if (
accFirstStake[account] != 0 &&
currentCycle > accFirstStake[account]
) {
uint256 unlockedFirstStake = accStakeCycle[account][accFirstStake[account]];
accRewards[account] += unlockedFirstStake;
accWithdrawableStake[account] += unlockedFirstStake;
if (lastStartedCycle + 1 > accFirstStake[account]) {
accAccruedFees[account] = accAccruedFees[account] +
(
(accStakeCycle[account][accFirstStake[account]] *
(cycleFeesPerStakeSummed[lastStartedCycle + 1] -
cycleFeesPerStakeSummed[accFirstStake[account]]
)
)
) /
SCALING_FACTOR;
}
accStakeCycle[account][accFirstStake[account]] = 0;
accFirstStake[account] = 0;
if (accSecondStake[account] != 0) {
if (currentCycle > accSecondStake[account]) {
uint256 unlockedSecondStake = accStakeCycle[account][accSecondStake[account]];
accRewards[account] += unlockedSecondStake;
accWithdrawableStake[account] += unlockedSecondStake;
if (lastStartedCycle + 1 > accSecondStake[account]) {
accAccruedFees[account] = accAccruedFees[account] +
(
(accStakeCycle[account][accSecondStake[account]] *
(cycleFeesPerStakeSummed[lastStartedCycle + 1] -
cycleFeesPerStakeSummed[accSecondStake[account]]
)
)
) /
SCALING_FACTOR;
}
accStakeCycle[account][accSecondStake[account]] = 0;
accSecondStake[account] = 0;
} else {
accFirstStake[account] = accSecondStake[account];
accSecondStake[account] = 0;
}
}
}
}
/**
* Recommended method to use to send native coins.
*
* @param to receiving address.
* @param amount in wei.
*/
function sendViaCall(address payable to, uint256 amount) internal {
(bool sent, ) = to.call{value: amount}("");
require(sent, "DBXen: failed to send amount");
}
/**
@dev confirms support for IBurnRedeemable interfaces
*/
function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
return
interfaceId == type(IBurnRedeemable).interfaceId;
}
}// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol) pragma solidity ^0.8.0; import "../utils/introspection/IERC165.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (metatx/ERC2771Context.sol)
pragma solidity ^0.8.9;
import "../utils/Context.sol";
/**
* @dev Context variant with ERC2771 support.
*/
abstract contract ERC2771Context is Context {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable _trustedForwarder;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address trustedForwarder) {
_trustedForwarder = trustedForwarder;
}
function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
return forwarder == _trustedForwarder;
}
function _msgSender() internal view virtual override returns (address sender) {
if (isTrustedForwarder(msg.sender)) {
// The assembly code is more direct than the Solidity version using `abi.decode`.
/// @solidity memory-safe-assembly
assembly {
sender := shr(96, calldataload(sub(calldatasize(), 20)))
}
} else {
return super._msgSender();
}
}
function _msgData() internal view virtual override returns (bytes calldata) {
if (isTrustedForwarder(msg.sender)) {
return msg.data[:msg.data.length - 20];
} else {
return super._msgData();
}
}
}// SPDX-License-Identifier: MIT
// 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;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/extensions/draft-ERC20Permit.sol)
pragma solidity ^0.8.0;
import "./draft-IERC20Permit.sol";
import "../ERC20.sol";
import "../../../utils/cryptography/ECDSA.sol";
import "../../../utils/cryptography/EIP712.sol";
import "../../../utils/Counters.sol";
/**
* @dev Implementation 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.
*
* _Available since v3.4._
*/
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
using Counters for Counters.Counter;
mapping(address => Counters.Counter) private _nonces;
// solhint-disable-next-line var-name-mixedcase
bytes32 private constant _PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/**
* @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`.
* However, to ensure consistency with the upgradeable transpiler, we will continue
* to reserve a slot.
* @custom:oz-renamed-from _PERMIT_TYPEHASH
*/
// solhint-disable-next-line var-name-mixedcase
bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
*
* It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/
constructor(string memory name) EIP712(name, "1") {}
/**
* @dev See {IERC20Permit-permit}.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual override {
require(block.timestamp <= deadline, "ERC20Permit: expired deadline");
bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
require(signer == owner, "ERC20Permit: invalid signature");
_approve(owner, spender, value);
}
/**
* @dev See {IERC20Permit-nonces}.
*/
function nonces(address owner) public view virtual override returns (uint256) {
return _nonces[owner].current();
}
/**
* @dev See {IERC20Permit-DOMAIN_SEPARATOR}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
/**
* @dev "Consume a nonce": return the current value and increment.
*
* _Available since v4.1._
*/
function _useNonce(address owner) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _nonces[owner];
current = nonce.current();
nonce.increment();
}
}// SPDX-License-Identifier: MIT
// 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: MIT
// 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using 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");
}
}
}// SPDX-License-Identifier: MIT
// 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);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.0;
import "./ECDSA.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712 {
/* solhint-disable var-name-mixedcase */
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
address private immutable _CACHED_THIS;
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
);
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_CACHED_THIS = address(this);
_TYPE_HASH = typeHash;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
}
}
function _buildDomainSeparator(
bytes32 typeHash,
bytes32 nameHash,
bytes32 versionHash
) private view returns (bytes32) {
return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1);
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(
uint256 x,
uint256 y,
uint256 denominator,
Rounding rounding
) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10**64) {
value /= 10**64;
result += 64;
}
if (value >= 10**32) {
value /= 10**32;
result += 32;
}
if (value >= 10**16) {
value /= 10**16;
result += 16;
}
if (value >= 10**8) {
value /= 10**8;
result += 8;
}
if (value >= 10**4) {
value /= 10**4;
result += 4;
}
if (value >= 10**2) {
value /= 10**2;
result += 2;
}
if (value >= 10**1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
}// SPDX-License-Identifier: BSD-4-Clause /* * ABDK Math 64.64 Smart Contract Library. Copyright © 2019 by ABDK Consulting. * Author: Mikhail Vladimirov <[email protected]> */ pragma solidity ^0.8.0; /** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */ library ABDKMath64x64 { /* * Minimum value signed 64.64-bit fixed point number may have. */ int128 private constant MIN_64x64 = -0x80000000000000000000000000000000; /* * Maximum value signed 64.64-bit fixed point number may have. */ int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; /** * Convert signed 256-bit integer number into signed 64.64-bit fixed point * number. Revert on overflow. * * @param x signed 256-bit integer number * @return signed 64.64-bit fixed point number */ function fromInt (int256 x) internal pure returns (int128) { unchecked { require (x >= -0x8000000000000000 && x <= 0x7FFFFFFFFFFFFFFF); return int128 (x << 64); } } /** * Convert signed 64.64 fixed point number into signed 64-bit integer number * rounding down. * * @param x signed 64.64-bit fixed point number * @return signed 64-bit integer number */ function toInt (int128 x) internal pure returns (int64) { unchecked { return int64 (x >> 64); } } /** * Convert unsigned 256-bit integer number into signed 64.64-bit fixed point * number. Revert on overflow. * * @param x unsigned 256-bit integer number * @return signed 64.64-bit fixed point number */ function fromUInt (uint256 x) internal pure returns (int128) { unchecked { require (x <= 0x7FFFFFFFFFFFFFFF); return int128 (int256 (x << 64)); } } /** * Convert signed 64.64 fixed point number into unsigned 64-bit integer * number rounding down. Revert on underflow. * * @param x signed 64.64-bit fixed point number * @return unsigned 64-bit integer number */ function toUInt (int128 x) internal pure returns (uint64) { unchecked { require (x >= 0); return uint64 (uint128 (x >> 64)); } } /** * Convert signed 128.128 fixed point number into signed 64.64-bit fixed point * number rounding down. Revert on overflow. * * @param x signed 128.128-bin fixed point number * @return signed 64.64-bit fixed point number */ function from128x128 (int256 x) internal pure returns (int128) { unchecked { int256 result = x >> 64; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Convert signed 64.64 fixed point number into signed 128.128 fixed point * number. * * @param x signed 64.64-bit fixed point number * @return signed 128.128 fixed point number */ function to128x128 (int128 x) internal pure returns (int256) { unchecked { return int256 (x) << 64; } } /** * Calculate x + y. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function add (int128 x, int128 y) internal pure returns (int128) { unchecked { int256 result = int256(x) + y; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate x - y. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function sub (int128 x, int128 y) internal pure returns (int128) { unchecked { int256 result = int256(x) - y; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate x * y rounding down. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function mul (int128 x, int128 y) internal pure returns (int128) { unchecked { int256 result = int256(x) * y >> 64; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate x * y rounding towards zero, where x is signed 64.64 fixed point * number and y is signed 256-bit integer number. Revert on overflow. * * @param x signed 64.64 fixed point number * @param y signed 256-bit integer number * @return signed 256-bit integer number */ function muli (int128 x, int256 y) internal pure returns (int256) { unchecked { if (x == MIN_64x64) { require (y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF && y <= 0x1000000000000000000000000000000000000000000000000); return -y << 63; } else { bool negativeResult = false; if (x < 0) { x = -x; negativeResult = true; } if (y < 0) { y = -y; // We rely on overflow behavior here negativeResult = !negativeResult; } uint256 absoluteResult = mulu (x, uint256 (y)); if (negativeResult) { require (absoluteResult <= 0x8000000000000000000000000000000000000000000000000000000000000000); return -int256 (absoluteResult); // We rely on overflow behavior here } else { require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); return int256 (absoluteResult); } } } } /** * Calculate x * y rounding down, where x is signed 64.64 fixed point number * and y is unsigned 256-bit integer number. Revert on overflow. * * @param x signed 64.64 fixed point number * @param y unsigned 256-bit integer number * @return unsigned 256-bit integer number */ function mulu (int128 x, uint256 y) internal pure returns (uint256) { unchecked { if (y == 0) return 0; require (x >= 0); uint256 lo = (uint256 (int256 (x)) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256 (int256 (x)) * (y >> 128); require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); hi <<= 64; require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo); return hi + lo; } } /** * Calculate x / y rounding towards zero. Revert on overflow or when y is * zero. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function div (int128 x, int128 y) internal pure returns (int128) { unchecked { require (y != 0); int256 result = (int256 (x) << 64) / y; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate x / y rounding towards zero, where x and y are signed 256-bit * integer numbers. Revert on overflow or when y is zero. * * @param x signed 256-bit integer number * @param y signed 256-bit integer number * @return signed 64.64-bit fixed point number */ function divi (int256 x, int256 y) internal pure returns (int128) { unchecked { require (y != 0); bool negativeResult = false; if (x < 0) { x = -x; // We rely on overflow behavior here negativeResult = true; } if (y < 0) { y = -y; // We rely on overflow behavior here negativeResult = !negativeResult; } uint128 absoluteResult = divuu (uint256 (x), uint256 (y)); if (negativeResult) { require (absoluteResult <= 0x80000000000000000000000000000000); return -int128 (absoluteResult); // We rely on overflow behavior here } else { require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); return int128 (absoluteResult); // We rely on overflow behavior here } } } /** * Calculate x / y rounding towards zero, where x and y are unsigned 256-bit * integer numbers. Revert on overflow or when y is zero. * * @param x unsigned 256-bit integer number * @param y unsigned 256-bit integer number * @return signed 64.64-bit fixed point number */ function divu (uint256 x, uint256 y) internal pure returns (int128) { unchecked { require (y != 0); uint128 result = divuu (x, y); require (result <= uint128 (MAX_64x64)); return int128 (result); } } /** * Calculate -x. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function neg (int128 x) internal pure returns (int128) { unchecked { require (x != MIN_64x64); return -x; } } /** * Calculate |x|. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function abs (int128 x) internal pure returns (int128) { unchecked { require (x != MIN_64x64); return x < 0 ? -x : x; } } /** * Calculate 1 / x rounding towards zero. Revert on overflow or when x is * zero. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function inv (int128 x) internal pure returns (int128) { unchecked { require (x != 0); int256 result = int256 (0x100000000000000000000000000000000) / x; require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate arithmetics average of x and y, i.e. (x + y) / 2 rounding down. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function avg (int128 x, int128 y) internal pure returns (int128) { unchecked { return int128 ((int256 (x) + int256 (y)) >> 1); } } /** * Calculate geometric average of x and y, i.e. sqrt (x * y) rounding down. * Revert on overflow or in case x * y is negative. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function gavg (int128 x, int128 y) internal pure returns (int128) { unchecked { int256 m = int256 (x) * int256 (y); require (m >= 0); require (m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128 (sqrtu (uint256 (m))); } } /** * Calculate x^y assuming 0^0 is 1, where x is signed 64.64 fixed point number * and y is unsigned 256-bit integer number. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y uint256 value * @return signed 64.64-bit fixed point number */ function pow (int128 x, uint256 y) internal pure returns (int128) { unchecked { bool negative = x < 0 && y & 1 == 1; uint256 absX = uint128 (x < 0 ? -x : x); uint256 absResult; absResult = 0x100000000000000000000000000000000; if (absX <= 0x10000000000000000) { absX <<= 63; while (y != 0) { if (y & 0x1 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; if (y & 0x2 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; if (y & 0x4 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; if (y & 0x8 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; y >>= 4; } absResult >>= 64; } else { uint256 absXShift = 63; if (absX < 0x1000000000000000000000000) { absX <<= 32; absXShift -= 32; } if (absX < 0x10000000000000000000000000000) { absX <<= 16; absXShift -= 16; } if (absX < 0x1000000000000000000000000000000) { absX <<= 8; absXShift -= 8; } if (absX < 0x10000000000000000000000000000000) { absX <<= 4; absXShift -= 4; } if (absX < 0x40000000000000000000000000000000) { absX <<= 2; absXShift -= 2; } if (absX < 0x80000000000000000000000000000000) { absX <<= 1; absXShift -= 1; } uint256 resultShift = 0; while (y != 0) { require (absXShift < 64); if (y & 0x1 != 0) { absResult = absResult * absX >> 127; resultShift += absXShift; if (absResult > 0x100000000000000000000000000000000) { absResult >>= 1; resultShift += 1; } } absX = absX * absX >> 127; absXShift <<= 1; if (absX >= 0x100000000000000000000000000000000) { absX >>= 1; absXShift += 1; } y >>= 1; } require (resultShift < 64); absResult >>= 64 - resultShift; } int256 result = negative ? -int256 (absResult) : int256 (absResult); require (result >= MIN_64x64 && result <= MAX_64x64); return int128 (result); } } /** * Calculate sqrt (x) rounding down. Revert if x < 0. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function sqrt (int128 x) internal pure returns (int128) { unchecked { require (x >= 0); return int128 (sqrtu (uint256 (int256 (x)) << 64)); } } /** * Calculate binary logarithm of x. Revert if x <= 0. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function log_2 (int128 x) internal pure returns (int128) { unchecked { require (x > 0); int256 msb = 0; int256 xc = x; if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; } if (xc >= 0x100000000) { xc >>= 32; msb += 32; } if (xc >= 0x10000) { xc >>= 16; msb += 16; } if (xc >= 0x100) { xc >>= 8; msb += 8; } if (xc >= 0x10) { xc >>= 4; msb += 4; } if (xc >= 0x4) { xc >>= 2; msb += 2; } if (xc >= 0x2) msb += 1; // No need to shift xc anymore int256 result = msb - 64 << 64; uint256 ux = uint256 (int256 (x)) << uint256 (127 - msb); for (int256 bit = 0x8000000000000000; bit > 0; bit >>= 1) { ux *= ux; uint256 b = ux >> 255; ux >>= 127 + b; result += bit * int256 (b); } return int128 (result); } } /** * Calculate natural logarithm of x. Revert if x <= 0. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function ln (int128 x) internal pure returns (int128) { unchecked { require (x > 0); return int128 (int256 ( uint256 (int256 (log_2 (x))) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128)); } } /** * Calculate binary exponent of x. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function exp_2 (int128 x) internal pure returns (int128) { unchecked { require (x < 0x400000000000000000); // Overflow if (x < -0x400000000000000000) return 0; // Underflow uint256 result = 0x80000000000000000000000000000000; if (x & 0x8000000000000000 > 0) result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128; if (x & 0x4000000000000000 > 0) result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128; if (x & 0x2000000000000000 > 0) result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128; if (x & 0x1000000000000000 > 0) result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128; if (x & 0x800000000000000 > 0) result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128; if (x & 0x400000000000000 > 0) result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128; if (x & 0x200000000000000 > 0) result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128; if (x & 0x100000000000000 > 0) result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128; if (x & 0x80000000000000 > 0) result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128; if (x & 0x40000000000000 > 0) result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128; if (x & 0x20000000000000 > 0) result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128; if (x & 0x10000000000000 > 0) result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128; if (x & 0x8000000000000 > 0) result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128; if (x & 0x4000000000000 > 0) result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128; if (x & 0x2000000000000 > 0) result = result * 0x1000162E525EE054754457D5995292026 >> 128; if (x & 0x1000000000000 > 0) result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128; if (x & 0x800000000000 > 0) result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128; if (x & 0x400000000000 > 0) result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128; if (x & 0x200000000000 > 0) result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128; if (x & 0x100000000000 > 0) result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128; if (x & 0x80000000000 > 0) result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128; if (x & 0x40000000000 > 0) result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128; if (x & 0x20000000000 > 0) result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128; if (x & 0x10000000000 > 0) result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128; if (x & 0x8000000000 > 0) result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128; if (x & 0x4000000000 > 0) result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128; if (x & 0x2000000000 > 0) result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128; if (x & 0x1000000000 > 0) result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128; if (x & 0x800000000 > 0) result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128; if (x & 0x400000000 > 0) result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128; if (x & 0x200000000 > 0) result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128; if (x & 0x100000000 > 0) result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128; if (x & 0x80000000 > 0) result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128; if (x & 0x40000000 > 0) result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128; if (x & 0x20000000 > 0) result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128; if (x & 0x10000000 > 0) result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128; if (x & 0x8000000 > 0) result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128; if (x & 0x4000000 > 0) result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128; if (x & 0x2000000 > 0) result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128; if (x & 0x1000000 > 0) result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128; if (x & 0x800000 > 0) result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128; if (x & 0x400000 > 0) result = result * 0x100000000002C5C85FDF477B662B26945 >> 128; if (x & 0x200000 > 0) result = result * 0x10000000000162E42FEFA3AE53369388C >> 128; if (x & 0x100000 > 0) result = result * 0x100000000000B17217F7D1D351A389D40 >> 128; if (x & 0x80000 > 0) result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128; if (x & 0x40000 > 0) result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128; if (x & 0x20000 > 0) result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128; if (x & 0x10000 > 0) result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128; if (x & 0x8000 > 0) result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128; if (x & 0x4000 > 0) result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128; if (x & 0x2000 > 0) result = result * 0x1000000000000162E42FEFA39F02B772C >> 128; if (x & 0x1000 > 0) result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128; if (x & 0x800 > 0) result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128; if (x & 0x400 > 0) result = result * 0x100000000000002C5C85FDF473DEA871F >> 128; if (x & 0x200 > 0) result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128; if (x & 0x100 > 0) result = result * 0x100000000000000B17217F7D1CF79E949 >> 128; if (x & 0x80 > 0) result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128; if (x & 0x40 > 0) result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128; if (x & 0x20 > 0) result = result * 0x100000000000000162E42FEFA39EF366F >> 128; if (x & 0x10 > 0) result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128; if (x & 0x8 > 0) result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128; if (x & 0x4 > 0) result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128; if (x & 0x2 > 0) result = result * 0x1000000000000000162E42FEFA39EF358 >> 128; if (x & 0x1 > 0) result = result * 0x10000000000000000B17217F7D1CF79AB >> 128; result >>= uint256 (int256 (63 - (x >> 64))); require (result <= uint256 (int256 (MAX_64x64))); return int128 (int256 (result)); } } /** * Calculate natural exponent of x. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function exp (int128 x) internal pure returns (int128) { unchecked { require (x < 0x400000000000000000); // Overflow if (x < -0x400000000000000000) return 0; // Underflow return exp_2 ( int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128)); } } /** * Calculate x / y rounding towards zero, where x and y are unsigned 256-bit * integer numbers. Revert on overflow or when y is zero. * * @param x unsigned 256-bit integer number * @param y unsigned 256-bit integer number * @return unsigned 64.64-bit fixed point number */ function divuu (uint256 x, uint256 y) private pure returns (uint128) { unchecked { require (y != 0); uint256 result; if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) result = (x << 64) / y; else { uint256 msb = 192; uint256 xc = x >> 192; if (xc >= 0x100000000) { xc >>= 32; msb += 32; } if (xc >= 0x10000) { xc >>= 16; msb += 16; } if (xc >= 0x100) { xc >>= 8; msb += 8; } if (xc >= 0x10) { xc >>= 4; msb += 4; } if (xc >= 0x4) { xc >>= 2; msb += 2; } if (xc >= 0x2) msb += 1; // No need to shift xc anymore result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1); require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); uint256 hi = result * (y >> 128); uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); uint256 xh = x >> 192; uint256 xl = x << 64; if (xl < lo) xh -= 1; xl -= lo; // We rely on overflow behavior here lo = hi << 128; if (xl < lo) xh -= 1; xl -= lo; // We rely on overflow behavior here assert (xh == hi >> 128); result += xl / y; } require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); return uint128 (result); } } /** * Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer * number. * * @param x unsigned 256-bit integer number * @return unsigned 128-bit integer number */ function sqrtu (uint256 x) private pure returns (uint128) { unchecked { if (x == 0) return 0; else { uint256 xx = x; uint256 r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x4) { r <<= 1; } r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint256 r1 = x / r; return uint128 (r < r1 ? r : r1); } } } }
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
/**
* Reward token contract to be used by the dbxen protocol.
* The entire amount is minted by the main dbxen contract
* (DBXen.sol - which is the owner of this contract)
* directly to an account when it claims rewards.
*/
contract DBXenERC20 is ERC20Permit {
/**
* The address of the DBXen.sol contract instance.
*/
address public immutable owner;
/**
* Sets the owner address.
* Called from within the DBXen.sol constructor.
*/
constructor() ERC20("DBXen Token on Moonbeam", "mbDXN")
ERC20Permit("DBXen Token on Moonbeam") {
owner = msg.sender;
}
/**
* The total supply is naturally capped by the distribution algorithm
* implemented by the main dbxen contract, however an additional check
* that will never be triggered is added to reassure the reader.
*
* @param account the address of the reward token reciever
* @param amount wei to be minted
*/
function mintReward(address account, uint256 amount) external {
require(msg.sender == owner, "DBXen: caller is not DBXen contract.");
require(super.totalSupply() < 5010000000000000000000000, "DBXen: max supply already minted");
_mint(account, amount);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface IBurnableToken {
function burn(address user, uint256 amount) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface IBurnRedeemable {
event Redeemed(
address indexed user,
address indexed xenContract,
address indexed tokenContract,
uint256 xenAmount,
uint256 tokenAmount
);
function onTokenBurned(address user, uint256 amount) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface IRankedMintingToken {
event RankClaimed(address indexed user, uint256 term, uint256 rank);
event MintClaimed(address indexed user, uint256 rewardAmount);
function claimRank(uint256 term) external;
function claimMintReward() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface IStakingToken {
event Staked(address indexed user, uint256 amount, uint256 term);
event Withdrawn(address indexed user, uint256 amount, uint256 reward);
function stake(uint256 amount, uint256 term) external;
function withdraw() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "abdk-libraries-solidity/ABDKMath64x64.sol";
library MathX {
function min(uint256 a, uint256 b) external pure returns (uint256) {
if (a > b) return b;
return a;
}
function max(uint256 a, uint256 b) external pure returns (uint256) {
if (a > b) return a;
return b;
}
function logX64(uint256 x) external pure returns (int128) {
return ABDKMath64x64.log_2(ABDKMath64x64.fromUInt(x));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "./MathX.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/interfaces/IERC165.sol";
import "abdk-libraries-solidity/ABDKMath64x64.sol";
import "./interfaces/IStakingToken.sol";
import "./interfaces/IRankedMintingToken.sol";
import "./interfaces/IBurnableToken.sol";
import "./interfaces/IBurnRedeemable.sol";
contract XENCrypto is Context, IRankedMintingToken, IStakingToken, IBurnableToken, ERC20("XEN Crypto", "XEN") {
using MathX for uint256;
using ABDKMath64x64 for int128;
using ABDKMath64x64 for uint256;
// INTERNAL TYPE TO DESCRIBE A XEN MINT INFO
struct MintInfo {
address user;
uint256 term;
uint256 maturityTs;
uint256 rank;
uint256 amplifier;
uint256 eaaRate;
}
// INTERNAL TYPE TO DESCRIBE A XEN STAKE
struct StakeInfo {
uint256 term;
uint256 maturityTs;
uint256 amount;
uint256 apy;
}
// PUBLIC CONSTANTS
uint256 public constant SECONDS_IN_DAY = 3_600 * 24;
uint256 public constant DAYS_IN_YEAR = 365;
uint256 public constant GENESIS_RANK = 1;
uint256 public constant MIN_TERM = 1 * SECONDS_IN_DAY - 1;
uint256 public constant MAX_TERM_START = 100 * SECONDS_IN_DAY;
uint256 public constant MAX_TERM_END = 1_000 * SECONDS_IN_DAY;
uint256 public constant TERM_AMPLIFIER = 15;
uint256 public constant TERM_AMPLIFIER_THRESHOLD = 5_000;
uint256 public constant REWARD_AMPLIFIER_START = 3_000;
uint256 public constant REWARD_AMPLIFIER_END = 1;
uint256 public constant EAA_PM_START = 100;
uint256 public constant EAA_PM_STEP = 1;
uint256 public constant EAA_RANK_STEP = 100_000;
uint256 public constant WITHDRAWAL_WINDOW_DAYS = 7;
uint256 public constant MAX_PENALTY_PCT = 99;
uint256 public constant XEN_MIN_STAKE = 0;
uint256 public constant XEN_MIN_BURN = 0;
uint256 public constant XEN_APY_START = 20;
uint256 public constant XEN_APY_DAYS_STEP = 90;
uint256 public constant XEN_APY_END = 2;
string public constant AUTHORS = "@MrJackLevin @lbelyaev faircrypto.org";
// PUBLIC STATE, READABLE VIA NAMESAKE GETTERS
uint256 public immutable genesisTs;
uint256 public globalRank = GENESIS_RANK;
uint256 public activeMinters;
uint256 public activeStakes;
uint256 public totalXenStaked;
// user address => XEN mint info
mapping(address => MintInfo) public userMints;
// user address => XEN stake info
mapping(address => StakeInfo) public userStakes;
// user address => XEN burn amount
mapping(address => uint256) public userBurns;
// CONSTRUCTOR
constructor() {
genesisTs = block.timestamp;
}
// PRIVATE METHODS
/**
* @dev calculates current MaxTerm based on Global Rank
* (if Global Rank crosses over TERM_AMPLIFIER_THRESHOLD)
*/
function _calculateMaxTerm() private view returns (uint256) {
if (globalRank > TERM_AMPLIFIER_THRESHOLD) {
uint256 delta = globalRank.fromUInt().log_2().mul(TERM_AMPLIFIER.fromUInt()).toUInt();
uint256 newMax = MAX_TERM_START + delta * SECONDS_IN_DAY;
return MathX.min(newMax, MAX_TERM_END);
}
return MAX_TERM_START;
}
/**
* @dev calculates Withdrawal Penalty depending on lateness
*/
function _penalty(uint256 secsLate) private pure returns (uint256) {
// =MIN(2^(daysLate+3)/window-1,99)
uint256 daysLate = secsLate / SECONDS_IN_DAY;
if (daysLate > WITHDRAWAL_WINDOW_DAYS - 1) return MAX_PENALTY_PCT;
uint256 penalty = (uint256(1) << (daysLate + 3)) / WITHDRAWAL_WINDOW_DAYS - 1;
return MathX.min(penalty, MAX_PENALTY_PCT);
}
/**
* @dev calculates net Mint Reward (adjusted for Penalty)
*/
function _calculateMintReward(
uint256 cRank,
uint256 term,
uint256 maturityTs,
uint256 amplifier,
uint256 eeaRate
) private view returns (uint256) {
uint256 secsLate = block.timestamp - maturityTs;
uint256 penalty = _penalty(secsLate);
uint256 rankDelta = MathX.max(globalRank - cRank, 2);
uint256 EAA = (1_000 + eeaRate);
uint256 reward = getGrossReward(rankDelta, amplifier, term, EAA);
return (reward * (100 - penalty)) / 100;
}
/**
* @dev cleans up User Mint storage (gets some Gas credit;))
*/
function _cleanUpUserMint() private {
delete userMints[_msgSender()];
activeMinters--;
}
/**
* @dev calculates XEN Stake Reward
*/
function _calculateStakeReward(
uint256 amount,
uint256 term,
uint256 maturityTs,
uint256 apy
) private view returns (uint256) {
if (block.timestamp > maturityTs) {
uint256 rate = (apy * term * 1_000_000) / DAYS_IN_YEAR;
return (amount * rate) / 100_000_000;
}
return 0;
}
/**
* @dev calculates Reward Amplifier
*/
function _calculateRewardAmplifier() private view returns (uint256) {
uint256 amplifierDecrease = (block.timestamp - genesisTs) / SECONDS_IN_DAY;
if (amplifierDecrease < REWARD_AMPLIFIER_START) {
return MathX.max(REWARD_AMPLIFIER_START - amplifierDecrease, REWARD_AMPLIFIER_END);
} else {
return REWARD_AMPLIFIER_END;
}
}
/**
* @dev calculates Early Adopter Amplifier Rate (in 1/000ths)
* actual EAA is (1_000 + EAAR) / 1_000
*/
function _calculateEAARate() private view returns (uint256) {
uint256 decrease = (EAA_PM_STEP * globalRank) / EAA_RANK_STEP;
if (decrease > EAA_PM_START) return 0;
return EAA_PM_START - decrease;
}
/**
* @dev calculates APY (in %)
*/
function _calculateAPY() private view returns (uint256) {
uint256 decrease = (block.timestamp - genesisTs) / (SECONDS_IN_DAY * XEN_APY_DAYS_STEP);
if (XEN_APY_START - XEN_APY_END < decrease) return XEN_APY_END;
return XEN_APY_START - decrease;
}
/**
* @dev creates User Stake
*/
function _createStake(uint256 amount, uint256 term) private {
userStakes[_msgSender()] = StakeInfo({
term: term,
maturityTs: block.timestamp + term * SECONDS_IN_DAY,
amount: amount,
apy: _calculateAPY()
});
activeStakes++;
totalXenStaked += amount;
}
// PUBLIC CONVENIENCE GETTERS
/**
* @dev calculates gross Mint Reward
*/
function getGrossReward(
uint256 rankDelta,
uint256 amplifier,
uint256 term,
uint256 eaa
) public pure returns (uint256) {
int128 log128 = rankDelta.fromUInt().log_2();
int128 reward128 = log128.mul(amplifier.fromUInt()).mul(term.fromUInt()).mul(eaa.fromUInt());
return reward128.div(uint256(1_000).fromUInt()).toUInt();
}
/**
* @dev returns User Mint object associated with User account address
*/
function getUserMint() external view returns (MintInfo memory) {
return userMints[_msgSender()];
}
/**
* @dev returns XEN Stake object associated with User account address
*/
function getUserStake() external view returns (StakeInfo memory) {
return userStakes[_msgSender()];
}
/**
* @dev returns current AMP
*/
function getCurrentAMP() external view returns (uint256) {
return _calculateRewardAmplifier();
}
/**
* @dev returns current EAA Rate
*/
function getCurrentEAAR() external view returns (uint256) {
return _calculateEAARate();
}
/**
* @dev returns current APY
*/
function getCurrentAPY() external view returns (uint256) {
return _calculateAPY();
}
/**
* @dev returns current MaxTerm
*/
function getCurrentMaxTerm() external view returns (uint256) {
return _calculateMaxTerm();
}
// PUBLIC STATE-CHANGING METHODS
/**
* @dev accepts User cRank claim provided all checks pass (incl. no current claim exists)
*/
function claimRank(uint256 term) external {
uint256 termSec = term * SECONDS_IN_DAY;
require(termSec > MIN_TERM, "CRank: Term less than min");
require(termSec < _calculateMaxTerm() + 1, "CRank: Term more than current max term");
require(userMints[_msgSender()].rank == 0, "CRank: Mint already in progress");
// create and store new MintInfo
MintInfo memory mintInfo = MintInfo({
user: _msgSender(),
term: term,
maturityTs: block.timestamp + termSec,
rank: globalRank,
amplifier: _calculateRewardAmplifier(),
eaaRate: _calculateEAARate()
});
userMints[_msgSender()] = mintInfo;
activeMinters++;
emit RankClaimed(_msgSender(), term, globalRank++);
}
/**
* @dev ends minting upon maturity (and within permitted Withdrawal Time Window), gets minted XEN
*/
function claimMintReward() external {
MintInfo memory mintInfo = userMints[_msgSender()];
require(mintInfo.rank > 0, "CRank: No mint exists");
require(block.timestamp > mintInfo.maturityTs, "CRank: Mint maturity not reached");
// calculate reward and mint tokens
uint256 rewardAmount = _calculateMintReward(
mintInfo.rank,
mintInfo.term,
mintInfo.maturityTs,
mintInfo.amplifier,
mintInfo.eaaRate
) * 1 ether;
_mint(_msgSender(), rewardAmount);
_cleanUpUserMint();
emit MintClaimed(_msgSender(), rewardAmount);
}
/**
* @dev ends minting upon maturity (and within permitted Withdrawal time Window)
* mints XEN coins and splits them between User and designated other address
*/
function claimMintRewardAndShare(address other, uint256 pct) external {
MintInfo memory mintInfo = userMints[_msgSender()];
require(other != address(0), "CRank: Cannot share with zero address");
require(pct > 0, "CRank: Cannot share zero percent");
require(pct < 101, "CRank: Cannot share 100+ percent");
require(mintInfo.rank > 0, "CRank: No mint exists");
require(block.timestamp > mintInfo.maturityTs, "CRank: Mint maturity not reached");
// calculate reward
uint256 rewardAmount = _calculateMintReward(
mintInfo.rank,
mintInfo.term,
mintInfo.maturityTs,
mintInfo.amplifier,
mintInfo.eaaRate
) * 1 ether;
uint256 sharedReward = (rewardAmount * pct) / 100;
uint256 ownReward = rewardAmount - sharedReward;
// mint reward tokens
_mint(_msgSender(), ownReward);
_mint(other, sharedReward);
_cleanUpUserMint();
emit MintClaimed(_msgSender(), rewardAmount);
}
/**
* @dev ends minting upon maturity (and within permitted Withdrawal time Window)
* mints XEN coins and stakes 'pct' of it for 'term'
*/
function claimMintRewardAndStake(uint256 pct, uint256 term) external {
MintInfo memory mintInfo = userMints[_msgSender()];
// require(pct > 0, "CRank: Cannot share zero percent");
require(pct < 101, "CRank: Cannot share >100 percent");
require(mintInfo.rank > 0, "CRank: No mint exists");
require(block.timestamp > mintInfo.maturityTs, "CRank: Mint maturity not reached");
// calculate reward
uint256 rewardAmount = _calculateMintReward(
mintInfo.rank,
mintInfo.term,
mintInfo.maturityTs,
mintInfo.amplifier,
mintInfo.eaaRate
) * 1 ether;
uint256 stakedReward = (rewardAmount * pct) / 100;
uint256 ownReward = rewardAmount - stakedReward;
// mint reward tokens part
_mint(_msgSender(), ownReward);
_cleanUpUserMint();
emit MintClaimed(_msgSender(), rewardAmount);
// nothing to burn since we haven't minted this part yet
// stake extra tokens part
require(stakedReward > XEN_MIN_STAKE, "XEN: Below min stake");
require(term * SECONDS_IN_DAY > MIN_TERM, "XEN: Below min stake term");
require(term * SECONDS_IN_DAY < MAX_TERM_END + 1, "XEN: Above max stake term");
require(userStakes[_msgSender()].amount == 0, "XEN: stake exists");
_createStake(stakedReward, term);
emit Staked(_msgSender(), stakedReward, term);
}
/**
* @dev initiates XEN Stake in amount for a term (days)
*/
function stake(uint256 amount, uint256 term) external {
require(balanceOf(_msgSender()) >= amount, "XEN: not enough balance");
require(amount > XEN_MIN_STAKE, "XEN: Below min stake");
require(term * SECONDS_IN_DAY > MIN_TERM, "XEN: Below min stake term");
require(term * SECONDS_IN_DAY < MAX_TERM_END + 1, "XEN: Above max stake term");
require(userStakes[_msgSender()].amount == 0, "XEN: stake exists");
// burn staked XEN
_burn(_msgSender(), amount);
// create XEN Stake
_createStake(amount, term);
emit Staked(_msgSender(), amount, term);
}
/**
* @dev ends XEN Stake and gets reward if the Stake is mature
*/
function withdraw() external {
StakeInfo memory userStake = userStakes[_msgSender()];
require(userStake.amount > 0, "XEN: no stake exists");
uint256 xenReward = _calculateStakeReward(
userStake.amount,
userStake.term,
userStake.maturityTs,
userStake.apy
);
activeStakes--;
totalXenStaked -= userStake.amount;
// mint staked XEN (+ reward)
_mint(_msgSender(), userStake.amount + xenReward);
emit Withdrawn(_msgSender(), userStake.amount, xenReward);
delete userStakes[_msgSender()];
}
/**
* @dev burns XEN tokens and creates Proof-Of-Burn record to be used by connected DeFi services
*/
function burn(address user, uint256 amount) public {
require(amount > XEN_MIN_BURN, "Burn: Below min limit");
require(
IERC165(_msgSender()).supportsInterface(type(IBurnRedeemable).interfaceId),
"Burn: not a supported contract"
);
_spendAllowance(user, _msgSender(), amount);
_burn(user, amount);
userBurns[user] += amount;
IBurnRedeemable(_msgSender()).onTokenBurned(user, amount);
}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"forwarder","type":"address"},{"internalType":"address","name":"xenAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"userAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"batchNumber","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"cycle","type":"uint256"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"fees","type":"uint256"}],"name":"FeesClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"cycle","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"calculatedCycleReward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"summedCycleStakes","type":"uint256"}],"name":"NewCycleStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"xenContract","type":"address"},{"indexed":true,"internalType":"address","name":"tokenContract","type":"address"},{"indexed":false,"internalType":"uint256","name":"xenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"Redeemed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"cycle","type":"uint256"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardsClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"cycle","type":"uint256"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"cycle","type":"uint256"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unstaked","type":"event"},{"inputs":[],"name":"MAX_BPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SCALING_FACTOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"XEN_BATCH_AMOUNT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"accAccruedFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"accCycleBatchesBurned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"accFirstStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"accRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"accSecondStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"accStakeCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"accWithdrawableStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"batchNumber","type":"uint256"}],"name":"burnBatch","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"claimFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentCycleReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentStartedCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"cycleAccruedFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"cycleFeesPerStakeSummed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"cycleTotalBatchesBurned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dxn","outputs":[{"internalType":"contract DBXenERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"i_initialTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"i_periodDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastActiveCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastCycleReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastFeeUpdateCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastStartedCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"onTokenBurned","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pendingFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingStakeWithdrawal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"previousStartedCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardPerCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"summedCycleStakes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"totalNumberOfBatchesBurned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"xen","outputs":[{"internalType":"contract XENCrypto","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60e06040523480156200001157600080fd5b50604051620039fa380380620039fa83398101604081905262000034916200013d565b6001600160a01b0382166080526001600055604051620000549062000112565b604051809103906000f08015801562000071573d6000803e3d6000fd5b50600180546001600160a01b039283166001600160a01b0319918216179091554260a0526201518060c05269021e19e0c9bab24000006003819055600080527f8fa6efc3be94b5b348b21fea823fe8d100408cee9b7f90524494500445d8ff6c81905560126020527f7e7fa33969761a458e04f477e039a608702b4f924981d6653935a8319a08ad7b55600280549390921692169190911790555062000175565b61141180620025e983390190565b80516001600160a01b03811681146200013857600080fd5b919050565b600080604083850312156200015157600080fd5b6200015c8362000120565b91506200016c6020840162000120565b90509250929050565b60805160a05160c05161242f620001ba60003960008181610392015261137a0152600081816104e1015261139e01526000818161043b0152611682015261242f6000f3fe60806040526004361061023b5760003560e01c8063a694fc3a1161012e578063c4235ae9116100ab578063ed725e831161006f578063ed725e8314610761578063ef4cadc51461078e578063f1b371e2146107b1578063fa845ca9146107c7578063fd967f47146107f457600080fd5b8063c4235ae9146106af578063d294f093146106dc578063d4432e4e146106f1578063db80a28c14610707578063e60c90c41461073457600080fd5b8063bab2f552116100f2578063bab2f55214610614578063bc7132901461062a578063be26ed7f14610657578063bebc9dfc1461066c578063c40af1ee1461069957600080fd5b8063a694fc3a1461054c578063a707140b1461056c578063a95f1dac14610599578063aabbb1bd146105af578063adc0f686146105e757600080fd5b8063543746b1116101bc57806368f057691161018057806368f05769146104b95780638bd95563146104cf5780639055c5151461050357806391b3002014610523578063937c54141461053957600080fd5b8063543746b1146103df57806356b96bf5146103ff578063572b6c051461041e5780635afe54d21461046b5780635f5080b4146104a357600080fd5b8063224438d111610203578063224438d1146103485780632e17de781461035e5780632f7cdab014610380578063372500ab146103b4578063436091c1146103c957600080fd5b806301ffc9a7146102405780630ece21541461028657806312cb22ac146102c157806317d9c47a146102ee5780631ed6380f1461031b575b600080fd5b34801561024c57600080fd5b5061027161025b3660046121f6565b6001600160e01b03191663543746b160e01b1490565b60405190151581526020015b60405180910390f35b34801561029257600080fd5b506102b36102a1366004612227565b60156020526000908152604090205481565b60405190815260200161027d565b3480156102cd57600080fd5b506102b36102dc36600461225c565b600d6020526000908152604090205481565b3480156102fa57600080fd5b506102b3610309366004612227565b600e6020526000908152604090205481565b34801561032757600080fd5b506102b361033636600461225c565b60186020526000908152604090205481565b34801561035457600080fd5b506102b3600b5481565b34801561036a57600080fd5b5061037e610379366004612227565b61080b565b005b34801561038c57600080fd5b506102b37f000000000000000000000000000000000000000000000000000000000000000081565b3480156103c057600080fd5b5061037e610a39565b3480156103d557600080fd5b506102b360075481565b3480156103eb57600080fd5b5061037e6103fa366004612277565b610c80565b34801561040b57600080fd5b506102b36a021165458500521280000081565b34801561042a57600080fd5b5061027161043936600461225c565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811691161490565b34801561047757600080fd5b5060015461048b906001600160a01b031681565b6040516001600160a01b03909116815260200161027d565b3480156104af57600080fd5b506102b360085481565b3480156104c557600080fd5b506102b3600a5481565b3480156104db57600080fd5b506102b37f000000000000000000000000000000000000000000000000000000000000000081565b34801561050f57600080fd5b5060025461048b906001600160a01b031681565b34801561052f57600080fd5b506102b360035481565b61037e610547366004612227565b610d59565b34801561055857600080fd5b5061037e610567366004612227565b6110fc565b34801561057857600080fd5b506102b361058736600461225c565b60146020526000908152604090205481565b3480156105a557600080fd5b506102b360045481565b3480156105bb57600080fd5b506102b36105ca366004612277565b601760209081526000928352604080842090915290825290205481565b3480156105f357600080fd5b506102b3610602366004612227565b60126020526000908152604090205481565b34801561062057600080fd5b506102b360065481565b34801561063657600080fd5b506102b361064536600461225c565b60116020526000908152604090205481565b34801561066357600080fd5b506102b3611376565b34801561067857600080fd5b506102b3610687366004612227565b60166020526000908152604090205481565b3480156106a557600080fd5b506102b3600c5481565b3480156106bb57600080fd5b506102b36106ca366004612227565b60136020526000908152604090205481565b3480156106e857600080fd5b5061037e6113d2565b3480156106fd57600080fd5b506102b360055481565b34801561071357600080fd5b506102b361072236600461225c565b601a6020526000908152604090205481565b34801561074057600080fd5b506102b361074f36600461225c565b60196020526000908152604090205481565b34801561076d57600080fd5b506102b361077c36600461225c565b60106020526000908152604090205481565b34801561079a57600080fd5b506102b36b1d6329f1c35ca4bfabb9f56160281b81565b3480156107bd57600080fd5b506102b360095481565b3480156107d357600080fd5b506102b36107e236600461225c565b600f6020526000908152604090205481565b34801561080057600080fd5b506102b3620186a081565b6108136114c8565b61081b611521565b61082361153c565b61083361082e61167e565b6116c2565b6000811161085c5760405162461bcd60e51b8152600401610853906122a1565b60405180910390fd5b6018600061086861167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020548111156108ee5760405162461bcd60e51b815260206004820152602d60248201527f444258656e3a20616d6f756e742067726561746572207468616e20776974686460448201526c72617761626c65207374616b6560981b6064820152608401610853565b600954600754036109165780600a600082825461090b91906122e6565b9091555061093d9050565b600654600090815260136020526040812080548392906109379084906122ff565b90915550505b806018600061094a61167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020600082825461097991906122ff565b909155508190506010600061098c61167e565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546109bb91906122ff565b909155506109df90506109cc61167e565b6001546001600160a01b03169083611cef565b6109e761167e565b6001600160a01b03166006547f37375b03d8924bd8f076f11f8411b9962aa5c02fb489021507bc6bb6f850e36583604051610a2491815260200190565b60405180910390a3610a366001600055565b50565b610a416114c8565b610a49611521565b610a5161153c565b610a5c61082e61167e565b600060186000610a6a61167e565b6001600160a01b03166001600160a01b031681526020019081526020016000205460106000610a9761167e565b6001600160a01b03166001600160a01b0316815260200190815260200160002054610ac291906122ff565b905060008111610b145760405162461bcd60e51b815260206004820152601d60248201527f444258656e3a206163636f756e7420686173206e6f20726577617264730000006044820152606401610853565b8060106000610b2161167e565b6001600160a01b03166001600160a01b031681526020019081526020016000206000828254610b5091906122ff565b909155505060095460075403610b7d5780600a6000828254610b7291906122e6565b90915550610bad9050565b600654600090815260136020526040902054610b9a9082906122ff565b6006546000908152601360205260409020555b6001546001600160a01b0316639a49090e610bc661167e565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b158015610c0e57600080fd5b505af1158015610c22573d6000803e3d6000fd5b50505050610c2e61167e565b6001600160a01b03166006547f3300bdb359cfb956935bca32e9db727413eab1ca84341f2e36caea85bb79696883604051610c6b91815260200190565b60405180910390a350610c7e6001600055565b565b6002546001600160a01b03163314610cda5760405162461bcd60e51b815260206004820152601e60248201527f444258656e3a20696c6c6567616c2063616c6c6261636b2063616c6c657200006044820152606401610853565b610ce2611521565b610cea61153c565b610cf2611d57565b610cfb826116c2565b6006546001600160a01b0383166000818152600f6020526040908190209290925590517fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca590610d4d9084815260200190565b60405180910390a25050565b610d616114c8565b8060005a9050612710831115610dc45760405162461bcd60e51b815260206004820152602260248201527f444258656e3a206d6178696d206261746368206e756d62657220697320313030604482015261030360f41b6064820152608401610853565b60008311610e145760405162461bcd60e51b815260206004820152601c60248201527f444258656e3a206d696e206261746368206e756d6265722069732031000000006044820152606401610853565b610e296a021165458500521280000084612312565b6002546040516370a0823160e01b81523360048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610e71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e959190612329565b1015610eed5760405162461bcd60e51b815260206004820152602160248201527f444258656e3a206e6f7420656e6f75676820746f6b656e7320666f72206275726044820152603760f91b6064820152608401610853565b6002546001600160a01b0316639dc29fac33610f146a021165458500521280000087612312565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015610f5a57600080fd5b505af1158015610f6e573d6000803e3d6000fd5b505050506000826005610f819190612312565b610f8e90620186a06122ff565b610f989084612312565b90506000620186a0823a5a610fad90876122ff565b610fb9906199e86122e6565b610fc39190612312565b610fcd9190612312565b610fd79190612342565b9050803410156110355760405162461bcd60e51b815260206004820152602360248201527f444258656e3a2076616c7565206c657373207468616e2070726f746f636f6c2060448201526266656560e81b6064820152608401610853565b83600c600082825461104791906122e6565b90915550506006546000908152600e60205260408120805486929061106d9084906122e6565b90915550849050600d600061108061167e565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546110af91906122e6565b9091555050600654600090815260156020526040812080548392906110d59084906122e6565b909155506110ee9050336110e983346122ff565b611eb3565b50505050610a366001600055565b6111046114c8565b61110c611521565b61111461153c565b61111f61082e61167e565b6000811161113f5760405162461bcd60e51b8152600401610853906122a1565b806005600082825461115191906122e6565b90915550506006546000906111679060016122e6565b905060095460075403611185576007546111829060016122e6565b90505b6019600061119161167e565b6001600160a01b03166001600160a01b031681526020019081526020016000205481141580156111ed5750601a60006111c861167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020548114155b156112ae57601960006111fe61167e565b6001600160a01b03166001600160a01b031681526020019081526020016000205460000361125257806019600061123361167e565b6001600160a01b031681526020810191909152604001600020556112ae565b601a600061125e61167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020546000036112ae5780601a600061129361167e565b6001600160a01b031681526020810191909152604001600020555b81601760006112bb61167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020600083815260200190815260200160002060008282546112fb91906122e6565b90915550611320905061130c61167e565b6001546001600160a01b0316903085611f56565b61132861167e565b6001600160a01b0316817f18dcd430020e4d4899772fd94a8b40451dc5044dfb70bc46b532eeae431c864f8460405161136391815260200190565b60405180910390a350610a366001600055565b60007f00000000000000000000000000000000000000000000000000000000000000006113c37f0000000000000000000000000000000000000000000000000000000000000000426122ff565b6113cd9190612342565b905090565b6113da6114c8565b6113e2611521565b6113ea61153c565b6113f561082e61167e565b60006011600061140361167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020549050600081116114465760405162461bcd60e51b8152600401610853906122a1565b60006011600061145461167e565b6001600160a01b0316815260208101919091526040016000205561147f61147961167e565b82611eb3565b61148761167e565b6001600160a01b0316611498611376565b6040518381527f2227733fc4c8a9034cb58087dcf6995128b9c0233b038b03366aaf30c92b92d690602001610c6b565b60026000540361151a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610853565b6002600055565b600061152b611376565b9050600654811115610a3657600655565b6009546006541461155f576007546115559060016122e6565b6008556009546007555b600754600654118015611593575060166000600754600161158091906122e6565b8152602001908152602001600020546000145b15610c7e576007546000908152601360205260408120541561160957600754600090815260136020908152604080832054600b5460159093529220546b1d6329f1c35ca4bfabb9f56160281b916115e9916122e6565b6115f39190612312565b6115fd9190612342565b6000600b55905061163a565b60156000600754815260200190815260200160002054600b600082825461163091906122e6565b9091555060009150505b6008546000908152601660205260409020546116579082906122e6565b60166000600754600161166a91906122e6565b815260208101919091526040016000205550565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633036116bd575060131936013560601c90565b503390565b6001600160a01b0381166000908152600f602052604090205460065411801561170257506001600160a01b0381166000908152600d602052604090205415155b156117a5576001600160a01b0381166000818152600f60209081526040808320548352600e8252808320546012835281842054948452600d9092528220549192909161174e9190612312565b6117589190612342565b6001600160a01b0383166000908152601060205260408120805492935083929091906117859084906122e6565b9091555050506001600160a01b0381166000908152600d60205260408120555b6007546006541180156117dd57506007546117c19060016122e6565b6001600160a01b03821660009081526014602052604090205414155b156118d6576001600160a01b03811660009081526014602090815260408083205483526016918290528220546007546b1d6329f1c35ca4bfabb9f56160281b939192919061182c9060016122e6565b81526020019081526020016000205461184591906122ff565b6001600160a01b0383166000908152601060205260409020546118689190612312565b6118729190612342565b6001600160a01b03821660009081526011602052604090205461189591906122e6565b6001600160a01b0382166000908152601160205260409020556007546118bc9060016122e6565b6001600160a01b0382166000908152601460205260409020555b6001600160a01b0381166000908152601960205260409020541580159061191657506001600160a01b038116600090815260196020526040902054600654115b15610a36576001600160a01b0381166000818152601760209081526040808320601983528184205484528252808320549383526010909152812080548392906119609084906122e6565b90915550506001600160a01b0382166000908152601860205260408120805483929061198d9084906122e6565b90915550506001600160a01b0382166000908152601960205260409020546007546119b99060016122e6565b1115611a9e576001600160a01b03821660009081526019602090815260408083205483526016918290528220546007546b1d6329f1c35ca4bfabb9f56160281b9391929190611a099060016122e6565b815260200190815260200160002054611a2291906122ff565b6001600160a01b038416600090815260176020908152604080832060198352818420548452909152902054611a579190612312565b611a619190612342565b6001600160a01b038316600090815260116020526040902054611a8491906122e6565b6001600160a01b0383166000908152601160205260409020555b6001600160a01b0382166000818152601760209081526040808320601983528184208054855290835281842084905593835292829055601a9052205415611ceb576001600160a01b0382166000908152601a60205260409020546006541115611cbe576001600160a01b0382166000818152601760209081526040808320601a8352818420548452825280832054938352601090915281208054839290611b469084906122e6565b90915550506001600160a01b03831660009081526018602052604081208054839290611b739084906122e6565b90915550506001600160a01b0383166000908152601a6020526040902054600754611b9f9060016122e6565b1115611c84576001600160a01b0383166000908152601a602090815260408083205483526016918290528220546007546b1d6329f1c35ca4bfabb9f56160281b9391929190611bef9060016122e6565b815260200190815260200160002054611c0891906122ff565b6001600160a01b0385166000908152601760209081526040808320601a8352818420548452909152902054611c3d9190612312565b611c479190612342565b6001600160a01b038416600090815260116020526040902054611c6a91906122e6565b6001600160a01b0384166000908152601160205260409020555b50506001600160a01b03166000818152601760209081526040808320601a8084528285208054865291845291842084905593835290529055565b6001600160a01b0382166000908152601a6020818152604080842080546019845291852091909155919052555b5050565b6040516001600160a01b038316602482015260448101829052611d5290849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611f94565b505050565b6006546000908152601260205260408120549003610c7e57600354600481905560009061272490611d8a90612710612312565b611d949190612342565b600381905560068054600090815260126020908152604080832085905592546009556007548252601390522054909150611dcf9082906122e6565b60095460009081526013602052604081208054909190611df09084906122e6565b909155505060055415611e2c5760055460095460009081526013602052604081208054909190611e219084906122e6565b909155505060006005555b600a5415611e6357600a5460095460009081526013602052604081208054909190611e589084906122ff565b90915550506000600a555b600654600954600090815260136020908152604091829020548251858152918201527f0666a61c1092f5b86c2cfe6ea1ad0d9a36032c4fb92d285b4e43f662d48f19b4910160405180910390a250565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611f00576040519150601f19603f3d011682016040523d82523d6000602084013e611f05565b606091505b5050905080611d525760405162461bcd60e51b815260206004820152601c60248201527f444258656e3a206661696c656420746f2073656e6420616d6f756e74000000006044820152606401610853565b6040516001600160a01b0380851660248301528316604482015260648101829052611f8e9085906323b872dd60e01b90608401611d1b565b50505050565b6000611fe9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166120669092919063ffffffff16565b805190915015611d5257808060200190518101906120079190612364565b611d525760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610853565b6060612075848460008561207d565b949350505050565b6060824710156120de5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610853565b600080866001600160a01b031685876040516120fa91906123aa565b60006040518083038185875af1925050503d8060008114612137576040519150601f19603f3d011682016040523d82523d6000602084013e61213c565b606091505b509150915061214d87838387612158565b979650505050505050565b606083156121c75782516000036121c0576001600160a01b0385163b6121c05760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610853565b5081612075565b61207583838151156121dc5781518083602001fd5b8060405162461bcd60e51b815260040161085391906123c6565b60006020828403121561220857600080fd5b81356001600160e01b03198116811461222057600080fd5b9392505050565b60006020828403121561223957600080fd5b5035919050565b80356001600160a01b038116811461225757600080fd5b919050565b60006020828403121561226e57600080fd5b61222082612240565b6000806040838503121561228a57600080fd5b61229383612240565b946020939093013593505050565b602080825260159082015274444258656e3a20616d6f756e74206973207a65726f60581b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b808201808211156122f9576122f96122d0565b92915050565b818103818111156122f9576122f96122d0565b80820281158282048414176122f9576122f96122d0565b60006020828403121561233b57600080fd5b5051919050565b60008261235f57634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561237657600080fd5b8151801515811461222057600080fd5b60005b838110156123a1578181015183820152602001612389565b50506000910152565b600082516123bc818460208701612386565b9190910192915050565b60208152600082518060208401526123e5816040850160208701612386565b601f01601f1916919091016040019291505056fea2646970667358221220749f6dae33f18f5e39f8469ea6950045d3a6932694b37218cca01c93ccba1d5464736f6c634300081100336101606040523480156200001257600080fd5b506040518060400160405280601781526020017f444258656e20546f6b656e206f6e204d6f6f6e6265616d00000000000000000081525080604051806040016040528060018152602001603160f81b8152506040518060400160405280601781526020017f444258656e20546f6b656e206f6e204d6f6f6e6265616d0000000000000000008152506040518060400160405280600581526020016436b1222c2760d91b8152508160039081620000c991906200021b565b506004620000d882826200021b565b5050825160209384012082519284019290922060e08390526101008190524660a0818152604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f818901819052818301979097526060810194909452608080850193909352308483018190528151808603909301835260c0948501909152815191909601209052929092526101205250503361014052620002e7565b634e487b7160e01b600052604160045260246000fd5b600181811c90821680620001a157607f821691505b602082108103620001c257634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200021657600081815260208120601f850160051c81016020861015620001f15750805b601f850160051c820191505b818110156200021257828155600101620001fd565b5050505b505050565b81516001600160401b0381111562000237576200023762000176565b6200024f816200024884546200018c565b84620001c8565b602080601f8311600181146200028757600084156200026e5750858301515b600019600386901b1c1916600185901b17855562000212565b600085815260208120601f198616915b82811015620002b85788860151825594840194600190910190840162000297565b5085821015620002d75787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60805160a05160c05160e0516101005161012051610140516110c862000349600039600081816101d601526103b201526000610a8401526000610ad301526000610aae01526000610a0701526000610a3101526000610a5b01526110c86000f3fe608060405234801561001057600080fd5b50600436106101005760003560e01c80637ecebe0011610097578063a457c2d711610066578063a457c2d71461022d578063a9059cbb14610240578063d505accf14610253578063dd62ed3e1461026657600080fd5b80637ecebe00146101be5780638da5cb5b146101d157806395d89b41146102105780639a49090e1461021857600080fd5b8063313ce567116100d3578063313ce5671461016b5780633644e5151461017a578063395093511461018257806370a082311461019557600080fd5b806306fdde0314610105578063095ea7b31461012357806318160ddd1461014657806323b872dd14610158575b600080fd5b61010d610279565b60405161011a9190610e8f565b60405180910390f35b610136610131366004610ef9565b61030b565b604051901515815260200161011a565b6002545b60405190815260200161011a565b610136610166366004610f23565b610325565b6040516012815260200161011a565b61014a610349565b610136610190366004610ef9565b610358565b61014a6101a3366004610f5f565b6001600160a01b031660009081526020819052604090205490565b61014a6101cc366004610f5f565b61037a565b6101f87f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161011a565b61010d610398565b61022b610226366004610ef9565b6103a7565b005b61013661023b366004610ef9565b6104a0565b61013661024e366004610ef9565b61051b565b61022b610261366004610f81565b610529565b61014a610274366004610ff4565b61068d565b60606003805461028890611027565b80601f01602080910402602001604051908101604052809291908181526020018280546102b490611027565b80156103015780601f106102d657610100808354040283529160200191610301565b820191906000526020600020905b8154815290600101906020018083116102e457829003601f168201915b5050505050905090565b6000336103198185856106b8565b60019150505b92915050565b6000336103338582856107dc565b61033e858585610856565b506001949350505050565b60006103536109fa565b905090565b60003361031981858561036b838361068d565b610375919061105b565b6106b8565b6001600160a01b03811660009081526005602052604081205461031f565b60606004805461028890611027565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146104305760405162461bcd60e51b8152602060048201526024808201527f444258656e3a2063616c6c6572206973206e6f7420444258656e20636f6e747260448201526330b1ba1760e11b60648201526084015b60405180910390fd5b6a0424e8a4eaca5ed740000061044560025490565b106104925760405162461bcd60e51b815260206004820181905260248201527f444258656e3a206d617820737570706c7920616c7265616479206d696e7465646044820152606401610427565b61049c8282610b21565b5050565b600033816104ae828661068d565b90508381101561050e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610427565b61033e82868684036106b8565b600033610319818585610856565b834211156105795760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e650000006044820152606401610427565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886105a88c610be0565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e001604051602081830303815290604052805190602001209050600061060382610c08565b9050600061061382878787610c56565b9050896001600160a01b0316816001600160a01b0316146106765760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e617475726500006044820152606401610427565b6106818a8a8a6106b8565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b03831661071a5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610427565b6001600160a01b03821661077b5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610427565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006107e8848461068d565b9050600019811461085057818110156108435760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610427565b61085084848484036106b8565b50505050565b6001600160a01b0383166108ba5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610427565b6001600160a01b03821661091c5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610427565b6001600160a01b038316600090815260208190526040902054818110156109945760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610427565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610850565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148015610a5357507f000000000000000000000000000000000000000000000000000000000000000046145b15610a7d57507f000000000000000000000000000000000000000000000000000000000000000090565b50604080517f00000000000000000000000000000000000000000000000000000000000000006020808301919091527f0000000000000000000000000000000000000000000000000000000000000000828401527f000000000000000000000000000000000000000000000000000000000000000060608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b6001600160a01b038216610b775760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610427565b8060026000828254610b89919061105b565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6001600160a01b03811660009081526005602052604090208054600181018255905b50919050565b600061031f610c156109fa565b8360405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b6000806000610c6787878787610c7e565b91509150610c7481610d42565b5095945050505050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115610cb55750600090506003610d39565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015610d09573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116610d3257600060019250925050610d39565b9150600090505b94509492505050565b6000816004811115610d5657610d5661107c565b03610d5e5750565b6001816004811115610d7257610d7261107c565b03610dbf5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610427565b6002816004811115610dd357610dd361107c565b03610e205760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610427565b6003816004811115610e3457610e3461107c565b03610e8c5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610427565b50565b600060208083528351808285015260005b81811015610ebc57858101830151858201604001528201610ea0565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b0381168114610ef457600080fd5b919050565b60008060408385031215610f0c57600080fd5b610f1583610edd565b946020939093013593505050565b600080600060608486031215610f3857600080fd5b610f4184610edd565b9250610f4f60208501610edd565b9150604084013590509250925092565b600060208284031215610f7157600080fd5b610f7a82610edd565b9392505050565b600080600080600080600060e0888a031215610f9c57600080fd5b610fa588610edd565b9650610fb360208901610edd565b95506040880135945060608801359350608088013560ff81168114610fd757600080fd5b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561100757600080fd5b61101083610edd565b915061101e60208401610edd565b90509250929050565b600181811c9082168061103b57607f821691505b602082108103610c0257634e487b7160e01b600052602260045260246000fd5b8082018082111561031f57634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052602160045260246000fdfea2646970667358221220addff8a1abfee78ca9b357b466bb76bc079180bf7eef7062bcc165e651be9c4a64736f6c634300081100330000000000000000000000003e23172d228bde46435f03a48e7484e351abd410000000000000000000000000b564a5767a00ee9075cac561c427643286f8f4e1
Deployed Bytecode
0x60806040526004361061023b5760003560e01c8063a694fc3a1161012e578063c4235ae9116100ab578063ed725e831161006f578063ed725e8314610761578063ef4cadc51461078e578063f1b371e2146107b1578063fa845ca9146107c7578063fd967f47146107f457600080fd5b8063c4235ae9146106af578063d294f093146106dc578063d4432e4e146106f1578063db80a28c14610707578063e60c90c41461073457600080fd5b8063bab2f552116100f2578063bab2f55214610614578063bc7132901461062a578063be26ed7f14610657578063bebc9dfc1461066c578063c40af1ee1461069957600080fd5b8063a694fc3a1461054c578063a707140b1461056c578063a95f1dac14610599578063aabbb1bd146105af578063adc0f686146105e757600080fd5b8063543746b1116101bc57806368f057691161018057806368f05769146104b95780638bd95563146104cf5780639055c5151461050357806391b3002014610523578063937c54141461053957600080fd5b8063543746b1146103df57806356b96bf5146103ff578063572b6c051461041e5780635afe54d21461046b5780635f5080b4146104a357600080fd5b8063224438d111610203578063224438d1146103485780632e17de781461035e5780632f7cdab014610380578063372500ab146103b4578063436091c1146103c957600080fd5b806301ffc9a7146102405780630ece21541461028657806312cb22ac146102c157806317d9c47a146102ee5780631ed6380f1461031b575b600080fd5b34801561024c57600080fd5b5061027161025b3660046121f6565b6001600160e01b03191663543746b160e01b1490565b60405190151581526020015b60405180910390f35b34801561029257600080fd5b506102b36102a1366004612227565b60156020526000908152604090205481565b60405190815260200161027d565b3480156102cd57600080fd5b506102b36102dc36600461225c565b600d6020526000908152604090205481565b3480156102fa57600080fd5b506102b3610309366004612227565b600e6020526000908152604090205481565b34801561032757600080fd5b506102b361033636600461225c565b60186020526000908152604090205481565b34801561035457600080fd5b506102b3600b5481565b34801561036a57600080fd5b5061037e610379366004612227565b61080b565b005b34801561038c57600080fd5b506102b37f000000000000000000000000000000000000000000000000000000000001518081565b3480156103c057600080fd5b5061037e610a39565b3480156103d557600080fd5b506102b360075481565b3480156103eb57600080fd5b5061037e6103fa366004612277565b610c80565b34801561040b57600080fd5b506102b36a021165458500521280000081565b34801561042a57600080fd5b5061027161043936600461225c565b7f0000000000000000000000003e23172d228bde46435f03a48e7484e351abd4106001600160a01b0390811691161490565b34801561047757600080fd5b5060015461048b906001600160a01b031681565b6040516001600160a01b03909116815260200161027d565b3480156104af57600080fd5b506102b360085481565b3480156104c557600080fd5b506102b3600a5481565b3480156104db57600080fd5b506102b37f000000000000000000000000000000000000000000000000000000006413059281565b34801561050f57600080fd5b5060025461048b906001600160a01b031681565b34801561052f57600080fd5b506102b360035481565b61037e610547366004612227565b610d59565b34801561055857600080fd5b5061037e610567366004612227565b6110fc565b34801561057857600080fd5b506102b361058736600461225c565b60146020526000908152604090205481565b3480156105a557600080fd5b506102b360045481565b3480156105bb57600080fd5b506102b36105ca366004612277565b601760209081526000928352604080842090915290825290205481565b3480156105f357600080fd5b506102b3610602366004612227565b60126020526000908152604090205481565b34801561062057600080fd5b506102b360065481565b34801561063657600080fd5b506102b361064536600461225c565b60116020526000908152604090205481565b34801561066357600080fd5b506102b3611376565b34801561067857600080fd5b506102b3610687366004612227565b60166020526000908152604090205481565b3480156106a557600080fd5b506102b3600c5481565b3480156106bb57600080fd5b506102b36106ca366004612227565b60136020526000908152604090205481565b3480156106e857600080fd5b5061037e6113d2565b3480156106fd57600080fd5b506102b360055481565b34801561071357600080fd5b506102b361072236600461225c565b601a6020526000908152604090205481565b34801561074057600080fd5b506102b361074f36600461225c565b60196020526000908152604090205481565b34801561076d57600080fd5b506102b361077c36600461225c565b60106020526000908152604090205481565b34801561079a57600080fd5b506102b36b1d6329f1c35ca4bfabb9f56160281b81565b3480156107bd57600080fd5b506102b360095481565b3480156107d357600080fd5b506102b36107e236600461225c565b600f6020526000908152604090205481565b34801561080057600080fd5b506102b3620186a081565b6108136114c8565b61081b611521565b61082361153c565b61083361082e61167e565b6116c2565b6000811161085c5760405162461bcd60e51b8152600401610853906122a1565b60405180910390fd5b6018600061086861167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020548111156108ee5760405162461bcd60e51b815260206004820152602d60248201527f444258656e3a20616d6f756e742067726561746572207468616e20776974686460448201526c72617761626c65207374616b6560981b6064820152608401610853565b600954600754036109165780600a600082825461090b91906122e6565b9091555061093d9050565b600654600090815260136020526040812080548392906109379084906122ff565b90915550505b806018600061094a61167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020600082825461097991906122ff565b909155508190506010600061098c61167e565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546109bb91906122ff565b909155506109df90506109cc61167e565b6001546001600160a01b03169083611cef565b6109e761167e565b6001600160a01b03166006547f37375b03d8924bd8f076f11f8411b9962aa5c02fb489021507bc6bb6f850e36583604051610a2491815260200190565b60405180910390a3610a366001600055565b50565b610a416114c8565b610a49611521565b610a5161153c565b610a5c61082e61167e565b600060186000610a6a61167e565b6001600160a01b03166001600160a01b031681526020019081526020016000205460106000610a9761167e565b6001600160a01b03166001600160a01b0316815260200190815260200160002054610ac291906122ff565b905060008111610b145760405162461bcd60e51b815260206004820152601d60248201527f444258656e3a206163636f756e7420686173206e6f20726577617264730000006044820152606401610853565b8060106000610b2161167e565b6001600160a01b03166001600160a01b031681526020019081526020016000206000828254610b5091906122ff565b909155505060095460075403610b7d5780600a6000828254610b7291906122e6565b90915550610bad9050565b600654600090815260136020526040902054610b9a9082906122ff565b6006546000908152601360205260409020555b6001546001600160a01b0316639a49090e610bc661167e565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b158015610c0e57600080fd5b505af1158015610c22573d6000803e3d6000fd5b50505050610c2e61167e565b6001600160a01b03166006547f3300bdb359cfb956935bca32e9db727413eab1ca84341f2e36caea85bb79696883604051610c6b91815260200190565b60405180910390a350610c7e6001600055565b565b6002546001600160a01b03163314610cda5760405162461bcd60e51b815260206004820152601e60248201527f444258656e3a20696c6c6567616c2063616c6c6261636b2063616c6c657200006044820152606401610853565b610ce2611521565b610cea61153c565b610cf2611d57565b610cfb826116c2565b6006546001600160a01b0383166000818152600f6020526040908190209290925590517fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca590610d4d9084815260200190565b60405180910390a25050565b610d616114c8565b8060005a9050612710831115610dc45760405162461bcd60e51b815260206004820152602260248201527f444258656e3a206d6178696d206261746368206e756d62657220697320313030604482015261030360f41b6064820152608401610853565b60008311610e145760405162461bcd60e51b815260206004820152601c60248201527f444258656e3a206d696e206261746368206e756d6265722069732031000000006044820152606401610853565b610e296a021165458500521280000084612312565b6002546040516370a0823160e01b81523360048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610e71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e959190612329565b1015610eed5760405162461bcd60e51b815260206004820152602160248201527f444258656e3a206e6f7420656e6f75676820746f6b656e7320666f72206275726044820152603760f91b6064820152608401610853565b6002546001600160a01b0316639dc29fac33610f146a021165458500521280000087612312565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015610f5a57600080fd5b505af1158015610f6e573d6000803e3d6000fd5b505050506000826005610f819190612312565b610f8e90620186a06122ff565b610f989084612312565b90506000620186a0823a5a610fad90876122ff565b610fb9906199e86122e6565b610fc39190612312565b610fcd9190612312565b610fd79190612342565b9050803410156110355760405162461bcd60e51b815260206004820152602360248201527f444258656e3a2076616c7565206c657373207468616e2070726f746f636f6c2060448201526266656560e81b6064820152608401610853565b83600c600082825461104791906122e6565b90915550506006546000908152600e60205260408120805486929061106d9084906122e6565b90915550849050600d600061108061167e565b6001600160a01b03166001600160a01b0316815260200190815260200160002060008282546110af91906122e6565b9091555050600654600090815260156020526040812080548392906110d59084906122e6565b909155506110ee9050336110e983346122ff565b611eb3565b50505050610a366001600055565b6111046114c8565b61110c611521565b61111461153c565b61111f61082e61167e565b6000811161113f5760405162461bcd60e51b8152600401610853906122a1565b806005600082825461115191906122e6565b90915550506006546000906111679060016122e6565b905060095460075403611185576007546111829060016122e6565b90505b6019600061119161167e565b6001600160a01b03166001600160a01b031681526020019081526020016000205481141580156111ed5750601a60006111c861167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020548114155b156112ae57601960006111fe61167e565b6001600160a01b03166001600160a01b031681526020019081526020016000205460000361125257806019600061123361167e565b6001600160a01b031681526020810191909152604001600020556112ae565b601a600061125e61167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020546000036112ae5780601a600061129361167e565b6001600160a01b031681526020810191909152604001600020555b81601760006112bb61167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020600083815260200190815260200160002060008282546112fb91906122e6565b90915550611320905061130c61167e565b6001546001600160a01b0316903085611f56565b61132861167e565b6001600160a01b0316817f18dcd430020e4d4899772fd94a8b40451dc5044dfb70bc46b532eeae431c864f8460405161136391815260200190565b60405180910390a350610a366001600055565b60007f00000000000000000000000000000000000000000000000000000000000151806113c37f0000000000000000000000000000000000000000000000000000000064130592426122ff565b6113cd9190612342565b905090565b6113da6114c8565b6113e2611521565b6113ea61153c565b6113f561082e61167e565b60006011600061140361167e565b6001600160a01b03166001600160a01b03168152602001908152602001600020549050600081116114465760405162461bcd60e51b8152600401610853906122a1565b60006011600061145461167e565b6001600160a01b0316815260208101919091526040016000205561147f61147961167e565b82611eb3565b61148761167e565b6001600160a01b0316611498611376565b6040518381527f2227733fc4c8a9034cb58087dcf6995128b9c0233b038b03366aaf30c92b92d690602001610c6b565b60026000540361151a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610853565b6002600055565b600061152b611376565b9050600654811115610a3657600655565b6009546006541461155f576007546115559060016122e6565b6008556009546007555b600754600654118015611593575060166000600754600161158091906122e6565b8152602001908152602001600020546000145b15610c7e576007546000908152601360205260408120541561160957600754600090815260136020908152604080832054600b5460159093529220546b1d6329f1c35ca4bfabb9f56160281b916115e9916122e6565b6115f39190612312565b6115fd9190612342565b6000600b55905061163a565b60156000600754815260200190815260200160002054600b600082825461163091906122e6565b9091555060009150505b6008546000908152601660205260409020546116579082906122e6565b60166000600754600161166a91906122e6565b815260208101919091526040016000205550565b60007f0000000000000000000000003e23172d228bde46435f03a48e7484e351abd4106001600160a01b031633036116bd575060131936013560601c90565b503390565b6001600160a01b0381166000908152600f602052604090205460065411801561170257506001600160a01b0381166000908152600d602052604090205415155b156117a5576001600160a01b0381166000818152600f60209081526040808320548352600e8252808320546012835281842054948452600d9092528220549192909161174e9190612312565b6117589190612342565b6001600160a01b0383166000908152601060205260408120805492935083929091906117859084906122e6565b9091555050506001600160a01b0381166000908152600d60205260408120555b6007546006541180156117dd57506007546117c19060016122e6565b6001600160a01b03821660009081526014602052604090205414155b156118d6576001600160a01b03811660009081526014602090815260408083205483526016918290528220546007546b1d6329f1c35ca4bfabb9f56160281b939192919061182c9060016122e6565b81526020019081526020016000205461184591906122ff565b6001600160a01b0383166000908152601060205260409020546118689190612312565b6118729190612342565b6001600160a01b03821660009081526011602052604090205461189591906122e6565b6001600160a01b0382166000908152601160205260409020556007546118bc9060016122e6565b6001600160a01b0382166000908152601460205260409020555b6001600160a01b0381166000908152601960205260409020541580159061191657506001600160a01b038116600090815260196020526040902054600654115b15610a36576001600160a01b0381166000818152601760209081526040808320601983528184205484528252808320549383526010909152812080548392906119609084906122e6565b90915550506001600160a01b0382166000908152601860205260408120805483929061198d9084906122e6565b90915550506001600160a01b0382166000908152601960205260409020546007546119b99060016122e6565b1115611a9e576001600160a01b03821660009081526019602090815260408083205483526016918290528220546007546b1d6329f1c35ca4bfabb9f56160281b9391929190611a099060016122e6565b815260200190815260200160002054611a2291906122ff565b6001600160a01b038416600090815260176020908152604080832060198352818420548452909152902054611a579190612312565b611a619190612342565b6001600160a01b038316600090815260116020526040902054611a8491906122e6565b6001600160a01b0383166000908152601160205260409020555b6001600160a01b0382166000818152601760209081526040808320601983528184208054855290835281842084905593835292829055601a9052205415611ceb576001600160a01b0382166000908152601a60205260409020546006541115611cbe576001600160a01b0382166000818152601760209081526040808320601a8352818420548452825280832054938352601090915281208054839290611b469084906122e6565b90915550506001600160a01b03831660009081526018602052604081208054839290611b739084906122e6565b90915550506001600160a01b0383166000908152601a6020526040902054600754611b9f9060016122e6565b1115611c84576001600160a01b0383166000908152601a602090815260408083205483526016918290528220546007546b1d6329f1c35ca4bfabb9f56160281b9391929190611bef9060016122e6565b815260200190815260200160002054611c0891906122ff565b6001600160a01b0385166000908152601760209081526040808320601a8352818420548452909152902054611c3d9190612312565b611c479190612342565b6001600160a01b038416600090815260116020526040902054611c6a91906122e6565b6001600160a01b0384166000908152601160205260409020555b50506001600160a01b03166000818152601760209081526040808320601a8084528285208054865291845291842084905593835290529055565b6001600160a01b0382166000908152601a6020818152604080842080546019845291852091909155919052555b5050565b6040516001600160a01b038316602482015260448101829052611d5290849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611f94565b505050565b6006546000908152601260205260408120549003610c7e57600354600481905560009061272490611d8a90612710612312565b611d949190612342565b600381905560068054600090815260126020908152604080832085905592546009556007548252601390522054909150611dcf9082906122e6565b60095460009081526013602052604081208054909190611df09084906122e6565b909155505060055415611e2c5760055460095460009081526013602052604081208054909190611e219084906122e6565b909155505060006005555b600a5415611e6357600a5460095460009081526013602052604081208054909190611e589084906122ff565b90915550506000600a555b600654600954600090815260136020908152604091829020548251858152918201527f0666a61c1092f5b86c2cfe6ea1ad0d9a36032c4fb92d285b4e43f662d48f19b4910160405180910390a250565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611f00576040519150601f19603f3d011682016040523d82523d6000602084013e611f05565b606091505b5050905080611d525760405162461bcd60e51b815260206004820152601c60248201527f444258656e3a206661696c656420746f2073656e6420616d6f756e74000000006044820152606401610853565b6040516001600160a01b0380851660248301528316604482015260648101829052611f8e9085906323b872dd60e01b90608401611d1b565b50505050565b6000611fe9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166120669092919063ffffffff16565b805190915015611d5257808060200190518101906120079190612364565b611d525760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610853565b6060612075848460008561207d565b949350505050565b6060824710156120de5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610853565b600080866001600160a01b031685876040516120fa91906123aa565b60006040518083038185875af1925050503d8060008114612137576040519150601f19603f3d011682016040523d82523d6000602084013e61213c565b606091505b509150915061214d87838387612158565b979650505050505050565b606083156121c75782516000036121c0576001600160a01b0385163b6121c05760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610853565b5081612075565b61207583838151156121dc5781518083602001fd5b8060405162461bcd60e51b815260040161085391906123c6565b60006020828403121561220857600080fd5b81356001600160e01b03198116811461222057600080fd5b9392505050565b60006020828403121561223957600080fd5b5035919050565b80356001600160a01b038116811461225757600080fd5b919050565b60006020828403121561226e57600080fd5b61222082612240565b6000806040838503121561228a57600080fd5b61229383612240565b946020939093013593505050565b602080825260159082015274444258656e3a20616d6f756e74206973207a65726f60581b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b808201808211156122f9576122f96122d0565b92915050565b818103818111156122f9576122f96122d0565b80820281158282048414176122f9576122f96122d0565b60006020828403121561233b57600080fd5b5051919050565b60008261235f57634e487b7160e01b600052601260045260246000fd5b500490565b60006020828403121561237657600080fd5b8151801515811461222057600080fd5b60005b838110156123a1578181015183820152602001612389565b50506000910152565b600082516123bc818460208701612386565b9190910192915050565b60208152600082518060208401526123e5816040850160208701612386565b601f01601f1916919091016040019291505056fea2646970667358221220749f6dae33f18f5e39f8469ea6950045d3a6932694b37218cca01c93ccba1d5464736f6c63430008110033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000003e23172d228bde46435f03a48e7484e351abd410000000000000000000000000b564a5767a00ee9075cac561c427643286f8f4e1
-----Decoded View---------------
Arg [0] : forwarder (address): 0x3E23172D228BdE46435F03a48E7484E351Abd410
Arg [1] : xenAddress (address): 0xb564A5767A00Ee9075cAC561c427643286F8F4E1
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000003e23172d228bde46435f03a48e7484e351abd410
Arg [1] : 000000000000000000000000b564a5767a00ee9075cac561c427643286f8f4e1
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$1,296.29
Net Worth in GLMR
Token Allocations
ETH
87.06%
GLMR
12.94%
POL
0.00%
Multichain Portfolio | 35 Chains
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.