ETH Price: $3,195.18 (-3.81%)

Contract

0xC16FF25860E87afFe92BcdD81D1eA498726F2dDf
 

Overview

ETH Balance

0.594531827468596887 ETH

Eth Value

$1,899.63 (@ $3,195.18/ETH)

Token Holdings

Multichain Info

Transaction Hash
Method
Block
From
To
Burn Batch189426642024-01-05 17:51:11379 days ago1704477071IN
0xC16FF258...8726F2dDf
0.00329247 ETH0.0107233931.49982728
Burn Batch189060342023-12-31 14:23:47384 days ago1704032627IN
0xC16FF258...8726F2dDf
0.00313088 ETH0.0064916119.11394674
Burn Batch188956592023-12-30 3:25:35386 days ago1703906735IN
0xC16FF258...8726F2dDf
0.00369645 ETH0.0045025214.3
Recover Health187690352023-12-12 8:52:35404 days ago1702371155IN
0xC16FF258...8726F2dDf
0 ETH0.0030884638.45917126
Claim Fees187682232023-12-12 6:08:47404 days ago1702361327IN
0xC16FF258...8726F2dDf
0 ETH0.0038270730.31011318
Recover Health187682132023-12-12 6:06:47404 days ago1702361207IN
0xC16FF258...8726F2dDf
0 ETH0.0027720132.88427895
Burn Batch187623812023-12-11 10:30:47405 days ago1702290647IN
0xC16FF258...8726F2dDf
0.00226233 ETH0.0109463629.06149665
Burn Batch187548402023-12-10 9:13:11406 days ago1702199591IN
0xC16FF258...8726F2dDf
0.00939174 ETH0.0052933424.96201762
Burn Batch187521892023-12-10 0:18:59406 days ago1702167539IN
0xC16FF258...8726F2dDf
0.00654424 ETH0.007336824
Stake187380192023-12-08 0:38:35408 days ago1701995915IN
0xC16FF258...8726F2dDf
0 ETH0.0067796948.97668813
Claim Fees187380162023-12-08 0:37:59408 days ago1701995879IN
0xC16FF258...8726F2dDf
0 ETH0.0031187552.38163414
Claim Rewards187380142023-12-08 0:37:35408 days ago1701995855IN
0xC16FF258...8726F2dDf
0 ETH0.0076846252.10975262
Recover Health187380122023-12-08 0:37:11408 days ago1701995831IN
0xC16FF258...8726F2dDf
0 ETH0.0040507249.02537717
Burn Batch187324222023-12-07 5:46:11409 days ago1701927971IN
0xC16FF258...8726F2dDf
0.00914941 ETH0.0106719530.97442315
Burn Batch187272912023-12-06 12:28:59410 days ago1701865739IN
0xC16FF258...8726F2dDf
0.0062615 ETH0.0098710648.33283819
Burn Batch187270792023-12-06 11:46:23410 days ago1701863183IN
0xC16FF258...8726F2dDf
0.00678637 ETH0.0169218449.55196768
Burn Batch187194762023-12-05 10:13:11411 days ago1701771191IN
0xC16FF258...8726F2dDf
0.0043629 ETH0.0079438138.58393115
Burn Batch187183222023-12-05 6:21:11411 days ago1701757271IN
0xC16FF258...8726F2dDf
0.00618071 ETH0.0154749442.35
Burn Batch187130432023-12-04 12:36:47412 days ago1701693407IN
0xC16FF258...8726F2dDf
0.00630167 ETH0.015430576
Burn Batch187122072023-12-04 9:48:35412 days ago1701683315IN
0xC16FF258...8726F2dDf
0.01171394 ETH0.0108203531.88693346
Burn Batch187059432023-12-03 12:44:23413 days ago1701607463IN
0xC16FF258...8726F2dDf
0.01155239 ETH0.0051194325.19568591
Burn Batch187054622023-12-03 11:07:23413 days ago1701601643IN
0xC16FF258...8726F2dDf
0.00605932 ETH0.006606728.74116352
Burn Batch187046692023-12-03 8:26:59413 days ago1701592019IN
0xC16FF258...8726F2dDf
0.01139082 ETH0.0086851725.33435506
Recover Health187037342023-12-03 5:18:11413 days ago1701580691IN
0xC16FF258...8726F2dDf
0 ETH0.002544830.79946213
Burn Batch186910962023-12-01 10:54:11415 days ago1701428051IN
0xC16FF258...8726F2dDf
0.01114851 ETH0.0089836729.37040756
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block
From
To
189426642024-01-05 17:51:11379 days ago1704477071
0xC16FF258...8726F2dDf
0.00003259 ETH
189426642024-01-05 17:51:11379 days ago1704477071
0xC16FF258...8726F2dDf
0.00000003 ETH
189060342023-12-31 14:23:47384 days ago1704032627
0xC16FF258...8726F2dDf
0.00003099 ETH
189060342023-12-31 14:23:47384 days ago1704032627
0xC16FF258...8726F2dDf
0.00000003 ETH
188956592023-12-30 3:25:35386 days ago1703906735
0xC16FF258...8726F2dDf
0.00003659 ETH
188956592023-12-30 3:25:35386 days ago1703906735
0xC16FF258...8726F2dDf
0.00000003 ETH
187682232023-12-12 6:08:47404 days ago1702361327
0xC16FF258...8726F2dDf
0.07029736 ETH
187623812023-12-11 10:30:47405 days ago1702290647
0xC16FF258...8726F2dDf
0.00002239 ETH
187623812023-12-11 10:30:47405 days ago1702290647
0xC16FF258...8726F2dDf
0.00000004 ETH
187548402023-12-10 9:13:11406 days ago1702199591
0xC16FF258...8726F2dDf
0.00009298 ETH
187548402023-12-10 9:13:11406 days ago1702199591
0xC16FF258...8726F2dDf
0.00000015 ETH
187521892023-12-10 0:18:59406 days ago1702167539
0xC16FF258...8726F2dDf
0.00006479 ETH
187521892023-12-10 0:18:59406 days ago1702167539
0xC16FF258...8726F2dDf
0.0000001 ETH
187380162023-12-08 0:37:59408 days ago1701995879
0xC16FF258...8726F2dDf
0.0607096 ETH
187324222023-12-07 5:46:11409 days ago1701927971
0xC16FF258...8726F2dDf
0.00009058 ETH
187324222023-12-07 5:46:11409 days ago1701927971
0xC16FF258...8726F2dDf
0.00000018 ETH
187272912023-12-06 12:28:59410 days ago1701865739
0xC16FF258...8726F2dDf
0.00006199 ETH
187272912023-12-06 12:28:59410 days ago1701865739
0xC16FF258...8726F2dDf
0.00000012 ETH
187270792023-12-06 11:46:23410 days ago1701863183
0xC16FF258...8726F2dDf
0.00006718 ETH
187270792023-12-06 11:46:23410 days ago1701863183
0xC16FF258...8726F2dDf
0.00000019 ETH
187194762023-12-05 10:13:11411 days ago1701771191
0xC16FF258...8726F2dDf
0.00004319 ETH
187194762023-12-05 10:13:11411 days ago1701771191
0xC16FF258...8726F2dDf
0.00000013 ETH
187183222023-12-05 6:21:11411 days ago1701757271
0xC16FF258...8726F2dDf
0.00006119 ETH
187183222023-12-05 6:21:11411 days ago1701757271
0xC16FF258...8726F2dDf
0.00000013 ETH
187130432023-12-04 12:36:47412 days ago1701693407
0xC16FF258...8726F2dDf
0.00006239 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
GDXen

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 33 : GDXen.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "abdk-libraries-solidity/ABDKMath64x64.sol";
import "./interfaces/IBurnRedeemable.sol";
import "./GDXenERC20.sol";
import "./XecERC20.sol";
import "./XENCrypto.sol";
import "./Xec.sol";

contract GDXen is Context, ReentrancyGuard, IBurnRedeemable {
    using SafeERC20 for GDXenERC20;
    using SafeERC20 for XecERC20;
    using Math for uint256;
    using ABDKMath64x64 for int128;
    using ABDKMath64x64 for uint256;

    GDXenERC20 public gdxen;

    XecERC20 public xecToken;

    Xec public xec;

    XENCrypto public xen;

    address public teamAddress;

    uint256 public constant MAX_BPS = 100_000;

    uint256 public constant XEN_BATCH_AMOUNT = 2_000_000 ether;
    // 2 multiple
    uint256 public constant PROTOCOL_FEE_AMPLIFIER = 2;
    // protocol fee base
    uint256 public constant PROTOCOL_FEE_BASE = 1e15;

    uint256 public constant SCALING_FACTOR = 1e40;

    uint256 public constant SCALING_FACTOR_5 = 1e5;

    uint256 public constant HEALTH_E = 102;

    uint256 public constant HEALTH_K = 2;

    uint256 public constant HEALTH_A = 1;

    uint256 public constant HEALTH_INIT = 100;

    uint256 public immutable i_initialTimestamp;

    uint256 public immutable i_periodDuration;

    uint256 public currentCycleReward;

    uint256 public lastCycleReward;

    uint256 public pendingStake;

    uint256 public currentCycle;

    uint256 public lastStartedCycle;

    uint256 public previousStartedCycle;

    uint256 public currentStartedCycle;

    uint256 public pendingStakeWithdrawal;

    uint256 public pendingFees;

    uint256 public totalNumberOfBatchesBurned;

    mapping(address => uint256) public accCycleBatchesBurned;

    mapping(uint256 => uint256) public cycleTotalBatchesBurned;

    mapping(address => mapping(uint256 => uint256)) public accBurnedBatches;

    mapping(address => uint256) public lastActiveCycle;

    mapping(address => uint256) public accRewards;

    mapping(address => uint256) public accAccruedFees;

    mapping(uint256 => uint256) public rewardPerCycle;

    mapping(uint256 => uint256) public summedCycleStakes;

    mapping(address => uint256) public lastFeeUpdateCycle;

    mapping(uint256 => uint256) public cycleAccruedFees;

    mapping(uint256 => uint256) public cycleFeesPerStakeSummed;

    mapping(address => mapping(uint256 => uint256)) public accStakeCycle;

    mapping(address => uint256) public accWithdrawableStake;

    mapping(address => uint256) public accFirstStake;

    mapping(address => uint256) public accSecondStake;

    mapping(address => uint256) public firstBurnCycle;

    mapping(address => bool) public isOldUser;

    event FeesClaimed(
        uint256 indexed cycle,
        address indexed account,
        uint256 fees
    );

    event Staked(
        uint256 indexed cycle,
        address indexed account,
        uint256 amount
    );

    event Unstaked(
        uint256 indexed cycle,
        address indexed account,
        uint256 amount
    );
    event RewardsClaimed(
        uint256 indexed cycle,
        address indexed account,
        uint256 reward
    );

    event NewCycleStarted(
        uint256 indexed cycle,
        uint256 calculatedCycleReward,
        uint256 summedCycleStakes
    );

    event Burn(address indexed userAddress, uint256 batchNumber);

    event RecoverHealth(address indexed userAddress, uint256 health);

    event InviteNewUser(
        address indexed userAddress,
        address indexed referrerAddress
    );

    modifier gasWrapper(uint256 batchNumber) {
        uint256 startGas = gasleft();
        _;

        uint256 discount = (batchNumber * (MAX_BPS - 5 * batchNumber));

        uint256 healthDiscount = (HEALTH_INIT +
            HEALTH_INIT -
            getHealth(_msgSender()));

        uint256 transferXecAmount = (batchNumber * XEN_BATCH_AMOUNT) / 1000;

        uint256 xecAmount = xec.getBurnedXec(address(xen), transferXecAmount);

        uint256 xecProtocolFee = xec.getXecFee(xecAmount);

        uint256 protocolFee = (((PROTOCOL_FEE_BASE * discount) / MAX_BPS) *
            PROTOCOL_FEE_AMPLIFIER *
            healthDiscount) / HEALTH_INIT;
        require(
            msg.value >= protocolFee + xecProtocolFee,
            "GDXen: value less than protocol fee"
        );

        xec.burnXenFromGdxen{value: xecProtocolFee}(
            transferXecAmount,
            msg.sender
        );
        totalNumberOfBatchesBurned += batchNumber;
        cycleTotalBatchesBurned[currentCycle] += batchNumber;
        accBurnedBatches[_msgSender()][currentCycle] += batchNumber;
        accCycleBatchesBurned[_msgSender()] += batchNumber;
        cycleAccruedFees[currentCycle] += protocolFee;
        sendViaCall(
            payable(msg.sender),
            msg.value - protocolFee - xecProtocolFee
        );
    }

    constructor(
        address xenAddress,
        address xecTokenAddress,
        address xecAddress
    ) {
        gdxen = new GDXenERC20();
        xecToken = XecERC20(xecTokenAddress);
        xec = Xec(xecAddress);
        i_initialTimestamp = block.timestamp;
        i_periodDuration = 1 days;
        currentCycleReward = 20000 * 1e18;
        summedCycleStakes[0] = 20000 * 1e18;
        rewardPerCycle[0] = 20000 * 1e18;
        xen = XENCrypto(xenAddress);
        teamAddress = msg.sender;
    }

    function onTokenBurned(address user, uint256 amount) external {
        require(msg.sender == address(xen), "GDXen: illegal callback caller");
        calculateCycle();
        updateCycleFeesPerStakeSummed();
        setUpNewCycle();
        updateStats(user);
        lastActiveCycle[user] = currentCycle;
        emit Burn(user, amount);
    }

    function burnBatch(
        address referrerAddress,
        uint256 batchNumber
    ) external payable nonReentrant gasWrapper(batchNumber) {
        require(batchNumber <= 10000, "GDXen: maxim batch number is 10000");
        require(batchNumber > 0, "GDXen: min batch number is 1");
        require(
            xen.balanceOf(msg.sender) >= batchNumber * XEN_BATCH_AMOUNT,
            "GDXen: not enough tokens for burn"
        );

        require(referrerAddress != msg.sender, "GDXen: referrer is self");

        if (!isOldUser[msg.sender]) {
            if (batchNumber >= 100) {
                xec.awardXec(referrerAddress);
                emit InviteNewUser(msg.sender, referrerAddress);
            }

            isOldUser[msg.sender] = true;

            firstBurnCycle[msg.sender] = getCurrentCycle();
        }

        IBurnableToken(xen).burn(msg.sender, batchNumber * XEN_BATCH_AMOUNT);
    }

    function recoverHealth() public nonReentrant {
        require(
            getHealth(msg.sender) < HEALTH_INIT,
            "GDXen: health greater than 100"
        );
        calculateCycle();

        require(isOldUser[msg.sender], "GDXenViews: not old user");
        uint256 health = getHealth(msg.sender);

        uint256 recoverHealthAmount = HEALTH_INIT - health;

        uint256 burnXec = calculateBurnXec(recoverHealthAmount);

        require(
            xecToken.balanceOf(msg.sender) >= burnXec,
            "GDXen: not enough tokens for burn"
        );

        xecToken.safeTransferFrom(msg.sender, address(this), burnXec);

        firstBurnCycle[msg.sender] = getCurrentCycle();

        xecToken.burn(burnXec);

        emit RecoverHealth(msg.sender, recoverHealthAmount);
    }

    function claimRewards() external nonReentrant {
        calculateCycle();
        updateCycleFeesPerStakeSummed();
        updateStats(_msgSender());
        uint256 reward = accRewards[_msgSender()] -
            accWithdrawableStake[_msgSender()];

        require(reward > 0, "GDXen: account has no rewards");

        require(getHealth(_msgSender()) >= 100, "GDXen: health less than 100");

        accRewards[_msgSender()] -= reward;
        if (lastStartedCycle == currentStartedCycle) {
            pendingStakeWithdrawal += reward;
        } else {
            summedCycleStakes[currentCycle] =
                summedCycleStakes[currentCycle] -
                reward;
        }

        gdxen.mintReward(_msgSender(), reward);
        emit RewardsClaimed(currentCycle, _msgSender(), reward);
    }

    function claimFees() external nonReentrant {
        calculateCycle();
        updateCycleFeesPerStakeSummed();
        updateStats(_msgSender());

        require(getHealth(_msgSender()) >= 100, "GDXen: health less than 100");

        uint256 fees = accAccruedFees[_msgSender()];
        require(fees > 0, "GDXen: amount is zero");
        accAccruedFees[_msgSender()] = 0;
        sendViaCall(payable(_msgSender()), fees);
        emit FeesClaimed(getCurrentCycle(), _msgSender(), fees);
    }

    function stake(uint256 amount) external nonReentrant {
        calculateCycle();
        updateCycleFeesPerStakeSummed();
        updateStats(_msgSender());
        require(amount > 0, "GDXen: amount is zero");
        if (!isOldUser[msg.sender]) {
            isOldUser[msg.sender] = true;
            firstBurnCycle[msg.sender] = getCurrentCycle();
        }
        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;

        gdxen.safeTransferFrom(_msgSender(), address(this), amount);
        emit Staked(cycleToSet, _msgSender(), amount);
    }

    function unstake(uint256 amount) external nonReentrant {
        calculateCycle();
        updateCycleFeesPerStakeSummed();
        updateStats(_msgSender());
        require(amount > 0, "GDXen: amount is zero");
        require(getHealth(_msgSender()) >= 100, "GDXen: health less than 100");
        require(
            amount <= accWithdrawableStake[_msgSender()],
            "GDXen: amount greater than withdrawable stake"
        );

        if (lastStartedCycle == currentStartedCycle) {
            pendingStakeWithdrawal += amount;
        } else {
            summedCycleStakes[currentCycle] -= amount;
        }

        accWithdrawableStake[_msgSender()] -= amount;
        accRewards[_msgSender()] -= amount;

        gdxen.safeTransfer(_msgSender(), amount);
        emit Unstaked(currentCycle, _msgSender(), amount);
    }

    function getCurrentCycle() public view returns (uint256) {
        return (block.timestamp - i_initialTimestamp) / i_periodDuration;
    }

    function calculateBurnXec(
        uint256 _recoverHealth
    ) public view returns (uint256) {
        uint256 T = getCurrentCycle();
        uint256 E = 107;

        uint256 burnXec = ((T + 1)
            .fromUInt()
            .log_2()
            .mul(E.fromUInt())
            .toUInt() *
            10 ** xecToken.decimals() *
            _recoverHealth) / 1e2;
        return burnXec;
    }

    function getHealth(address account) public view returns (uint256) {
        uint256 HEALTH_X = getCurrentCycle() - firstBurnCycle[msg.sender];

        if (HEALTH_X == 0 || !isOldUser[account]) {
            return 100;
        }

        uint256 health = 0;
        if (HEALTH_X > 116) {
            return health;
        }

        uint256 HEALTH_KXA = HEALTH_K * (HEALTH_X ** HEALTH_A);

        uint256 HEALTH_KXA_30_QUOT = HEALTH_KXA / 30;

        uint256 HEALTH_KXA_30_REM = HEALTH_KXA % 30;
        if (HEALTH_KXA_30_QUOT > 0) {
            health =
                HEALTH_INIT *
                ((1 * SCALING_FACTOR_5 ** (2 + HEALTH_KXA_30_QUOT)) /
                    (
                        ((((HEALTH_E ** 30 * SCALING_FACTOR_5) / 1e2 ** 30) **
                            HEALTH_KXA_30_QUOT) *
                            ((HEALTH_E ** HEALTH_KXA_30_REM *
                                SCALING_FACTOR_5) / 1e2 ** HEALTH_KXA_30_REM))
                    ));
        } else {
            health =
                HEALTH_INIT *
                ((1 * SCALING_FACTOR_5 ** 2) /
                    (
                        ((HEALTH_E ** HEALTH_KXA_30_REM * SCALING_FACTOR_5) /
                            1e2 ** HEALTH_KXA_30_REM)
                    ));
        }
        return health / SCALING_FACTOR_5;
    }

    function calculateCycle() internal {
        uint256 calculatedCycle = getCurrentCycle();

        if (calculatedCycle > currentCycle) {
            currentCycle = calculatedCycle;
        }
    }

    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;
        }
    }

    function setUpNewCycle() internal {
        if (rewardPerCycle[currentCycle] == 0) {
            lastCycleReward = currentCycleReward;

            uint256 calculatedCycleReward = (lastCycleReward * 20000) / 20080;

            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]
            );
        }
    }

    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;
                }
            }
        }
    }

    function sendViaCall(address payable to, uint256 amount) internal {
        (bool sent, ) = to.call{value: amount}("");
        require(sent, "GDXen: failed to send amount");
    }

    function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
        return interfaceId == type(IBurnRedeemable).interfaceId;
    }
}

File 2 of 33 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 3 of 33 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC165.sol)

pragma solidity ^0.8.0;

import "../utils/introspection/IERC165.sol";

File 4 of 33 : IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)

pragma solidity ^0.8.0;

interface IERC5267 {
    /**
     * @dev MAY be emitted to signal that the domain could have changed.
     */
    event EIP712DomainChanged();

    /**
     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
     * signature.
     */
    function eip712Domain()
        external
        view
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        );
}

File 5 of 33 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

File 6 of 33 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * 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}.
     *
     * 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 default value returned by this function, unless
     * it's 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 {}
}

File 7 of 33 : draft-ERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/draft-ERC20Permit.sol)

pragma solidity ^0.8.0;

// EIP-2612 is Final as of 2022-11-01. This file is deprecated.

import "./ERC20Permit.sol";

File 8 of 33 : ERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/ERC20Permit.sol)

pragma solidity ^0.8.0;

import "./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();
    }
}

File 9 of 33 : IERC20Metadata.sol
// 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);
}

File 10 of 33 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 11 of 33 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

File 12 of 33 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/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;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.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));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    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");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
     * 0 before setting it to a non-zero value.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    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");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation 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).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 13 of 33 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 14 of 33 : Context.sol
// 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;
    }
}

File 15 of 33 : Counters.sol
// 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;
    }
}

File 16 of 33 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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 message) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32")
            mstore(0x1c, hash)
            message := keccak256(0x00, 0x3c)
        }
    }

    /**
     * @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 data) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, "\x19\x01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            data := keccak256(ptr, 0x42)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Data with intended validator, created from a
     * `validator` and `data` according to the version 0 of EIP-191.
     *
     * See {recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x00", validator, data));
    }
}

File 17 of 33 : EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.8;

import "./ECDSA.sol";
import "../ShortStrings.sol";
import "../../interfaces/IERC5267.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].
 *
 * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
 * separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the
 * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
 *
 * _Available since v3.4._
 *
 * @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
 */
abstract contract EIP712 is IERC5267 {
    using ShortStrings for *;

    bytes32 private constant _TYPE_HASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

    // 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 _cachedDomainSeparator;
    uint256 private immutable _cachedChainId;
    address private immutable _cachedThis;

    bytes32 private immutable _hashedName;
    bytes32 private immutable _hashedVersion;

    ShortString private immutable _name;
    ShortString private immutable _version;
    string private _nameFallback;
    string private _versionFallback;

    /**
     * @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) {
        _name = name.toShortStringWithFallback(_nameFallback);
        _version = version.toShortStringWithFallback(_versionFallback);
        _hashedName = keccak256(bytes(name));
        _hashedVersion = keccak256(bytes(version));

        _cachedChainId = block.chainid;
        _cachedDomainSeparator = _buildDomainSeparator();
        _cachedThis = address(this);
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
            return _cachedDomainSeparator;
        } else {
            return _buildDomainSeparator();
        }
    }

    function _buildDomainSeparator() private view returns (bytes32) {
        return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, 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);
    }

    /**
     * @dev See {EIP-5267}.
     *
     * _Available since v4.9._
     */
    function eip712Domain()
        public
        view
        virtual
        override
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        )
    {
        return (
            hex"0f", // 01111
            _name.toStringWithFallback(_nameFallback),
            _version.toStringWithFallback(_versionFallback),
            block.chainid,
            address(this),
            bytes32(0),
            new uint256[](0)
        );
    }
}

File 18 of 33 : IERC165.sol
// 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);
}

File 19 of 33 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.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) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1, "Math: mulDiv overflow");

            ///////////////////////////////////////////////
            // 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 256, 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 << 3) < value ? 1 : 0);
        }
    }
}

File 20 of 33 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 21 of 33 : ShortStrings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/ShortStrings.sol)

pragma solidity ^0.8.8;

import "./StorageSlot.sol";

// | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |
// | length  | 0x                                                              BB |
type ShortString is bytes32;

/**
 * @dev This library provides functions to convert short memory strings
 * into a `ShortString` type that can be used as an immutable variable.
 *
 * Strings of arbitrary length can be optimized using this library if
 * they are short enough (up to 31 bytes) by packing them with their
 * length (1 byte) in a single EVM word (32 bytes). Additionally, a
 * fallback mechanism can be used for every other case.
 *
 * Usage example:
 *
 * ```solidity
 * contract Named {
 *     using ShortStrings for *;
 *
 *     ShortString private immutable _name;
 *     string private _nameFallback;
 *
 *     constructor(string memory contractName) {
 *         _name = contractName.toShortStringWithFallback(_nameFallback);
 *     }
 *
 *     function name() external view returns (string memory) {
 *         return _name.toStringWithFallback(_nameFallback);
 *     }
 * }
 * ```
 */
library ShortStrings {
    // Used as an identifier for strings longer than 31 bytes.
    bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;

    error StringTooLong(string str);
    error InvalidShortString();

    /**
     * @dev Encode a string of at most 31 chars into a `ShortString`.
     *
     * This will trigger a `StringTooLong` error is the input string is too long.
     */
    function toShortString(string memory str) internal pure returns (ShortString) {
        bytes memory bstr = bytes(str);
        if (bstr.length > 31) {
            revert StringTooLong(str);
        }
        return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
    }

    /**
     * @dev Decode a `ShortString` back to a "normal" string.
     */
    function toString(ShortString sstr) internal pure returns (string memory) {
        uint256 len = byteLength(sstr);
        // using `new string(len)` would work locally but is not memory safe.
        string memory str = new string(32);
        /// @solidity memory-safe-assembly
        assembly {
            mstore(str, len)
            mstore(add(str, 0x20), sstr)
        }
        return str;
    }

    /**
     * @dev Return the length of a `ShortString`.
     */
    function byteLength(ShortString sstr) internal pure returns (uint256) {
        uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
        if (result > 31) {
            revert InvalidShortString();
        }
        return result;
    }

    /**
     * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
     */
    function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
        if (bytes(value).length < 32) {
            return toShortString(value);
        } else {
            StorageSlot.getStringSlot(store).value = value;
            return ShortString.wrap(_FALLBACK_SENTINEL);
        }
    }

    /**
     * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     */
    function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
        if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
            return toString(value);
        } else {
            return store;
        }
    }

    /**
     * @dev Return the length of a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     *
     * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
     * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
     */
    function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
        if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
            return byteLength(value);
        } else {
            return bytes(store).length;
        }
    }
}

File 22 of 33 : StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
 * _Available since v4.9 for `string`, `bytes`._
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

File 23 of 33 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.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 `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
    }

    /**
     * @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);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 24 of 33 : ABDKMath64x64.sol
// 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);
      }
    }
  }
}

File 25 of 33 : GDXenERC20.sol
// 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 gdxen protocol.
 * The entire amount is minted by the main gdxen contract
 * (GDXen.sol - which is the owner of this contract)
 * directly to an account when it claims rewards.
 */
contract GDXenERC20 is ERC20Permit {
    /**
     * The address of the GDXen.sol contract instance.
     */
    address public immutable owner;

    /**
     * Sets the owner address.
     * Called from within the GDXen.sol constructor.
     */
    constructor() ERC20("GDXen Token", "GDXen") ERC20Permit("GDXen Token") {
        owner = msg.sender;
    }

    /**
     * The total supply is naturally capped by the distribution algorithm
     * implemented by the main gdxen 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, "GDXen: caller is not GDXen contract.");
        require(
            super.totalSupply() < 5010000000000000000000000,
            "GDXen: max supply already minted"
        );
        _mint(account, amount);
    }
}

File 26 of 33 : IBurnableToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

interface IBurnableToken {
    function burn(address user, uint256 amount) external;
}

File 27 of 33 : IBurnRedeemable.sol
// 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;
}

File 28 of 33 : IRankedMintingToken.sol
// 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;
}

File 29 of 33 : IStakingToken.sol
// 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;
}

File 30 of 33 : MathX.sol
// 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));
    }
}

File 31 of 33 : Xec.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "abdk-libraries-solidity/ABDKMath64x64.sol";
import "./interfaces/IBurnRedeemable.sol";
import "./XecERC20.sol";
import "./GDXen.sol";
import "./XENCrypto.sol";

contract Xec is Context, ReentrancyGuard, Ownable {
    using SafeERC20 for XecERC20;
    using Math for uint256;
    using ABDKMath64x64 for int128;
    using ABDKMath64x64 for uint256;
    // 0.0002 M
    uint256 public constant M = 2 ether / 10000;
    // 0.006 T
    uint256 public constant awardThreshold = 6 ether / 1000;

    uint256 public constant xecLockTime = 1 days;

    uint256 public constant xecMaxLockTime = 10 days;

    uint256 public constant A = 106;

    uint256 public constant aDecimal = 1e2;
    XecERC20 public xec;
    GDXen public gdxen;
    XENCrypto public xen;

    uint256 public totalBurnedGarbage;

    address[] public garbageTokens;

    mapping(address => uint256) public accClaimableXec;

    mapping(address => string) public garbageSymbols;

    mapping(address => uint256) public E_0;

    mapping(address => uint256) public lastBurnedTimeToClaim;

    event BurnGarbageToken(
        address indexed userAddress,
        uint256 garbageNumber,
        uint256 xecAmount
    );

    constructor(address xenAddress) {
        xec = new XecERC20();
        xen = XENCrypto(xenAddress);
    }

    function setGdxen(address _gdxen) external onlyOwner {
        require(_gdxen != address(0), "Xec: zero address");
        gdxen = GDXen(_gdxen);
    }

    function createGarbageLists(
        address _garbageAddress,
        uint256 _E_0
    ) external onlyOwner {
        require(_garbageAddress != address(0), "Xec: zero address");
        require(_E_0 > 0, "Xec: E_0 must be greater than 0");

        require(E_0[_garbageAddress] == 0, "Xec: garbage token already exists");

        garbageTokens.push(_garbageAddress);

        garbageSymbols[_garbageAddress] = IERC20Metadata(_garbageAddress)
            .symbol();

        E_0[_garbageAddress] = _E_0;
    }

    function onTokenBurned(address user, uint256 amount) external {
        require(msg.sender == address(xen), "Xec: caller is not XENCrypto");
    }

    function burnGarbage(
        address _garbageAddress,
        uint256 _amount,
        address _to
    ) public payable nonReentrant {
        require(_garbageAddress != address(0), "Xec: zero address");
        require(_amount > 0, "Xec: _amount must be greater than 0");

        require(
            IERC20(_garbageAddress).balanceOf(_msgSender()) >= _amount,
            "Xec: insufficient balance"
        );

        uint256 xecAmount = getBurnedXec(_garbageAddress, _amount);
        if (_garbageAddress == address(xen)) {
            IBurnableToken(xen).burn(_msgSender(), _amount);
        } else {
            IERC20(_garbageAddress).transferFrom(
                _msgSender(),
                address(0x000000000000000000000000000000000000dEaD),
                _amount
            );
        }

        uint256 userFee = getXecFee(xecAmount);

        require(msg.value >= userFee, "Xec: insufficient fee");

        if (msg.value >= awardThreshold) {
            xecAmount += xecAmount / 5;
        }

        totalBurnedGarbage += _amount;

        lastBurnedTimeToClaim[_to] = block.timestamp + getXecLockTime();

        accClaimableXec[_to] += xecAmount;

        emit BurnGarbageToken(_to, _amount, xecAmount);
    }

    function burnXenFromGdxen(uint256 _amount, address _to) external payable {
        require(msg.sender == address(gdxen), "Xec: caller is not GDXen");

        uint256 xecAmount = getBurnedXec(address(xen), _amount);

        totalBurnedGarbage += _amount;

        lastBurnedTimeToClaim[_to] = block.timestamp + getXecLockTime();

        accClaimableXec[_to] += xecAmount;
    }

    function claimXec() external nonReentrant {
        require(accClaimableXec[_msgSender()] > 0, "Xec: no claimable XEC");

        require(
            block.timestamp >= lastBurnedTimeToClaim[_msgSender()],
            "Xec: XEC is locked"
        );

        uint256 claimableXec = accClaimableXec[_msgSender()];

        accClaimableXec[_msgSender()] = 0;

        xec.mintReward(_msgSender(), claimableXec);
    }

    function awardXec(address _to) external nonReentrant {
        require(msg.sender == address(gdxen), "Xec: caller is not GDXen");

        accClaimableXec[_to] += 10 ether;
    }

    function withdraw() external onlyOwner {
        uint256 balance = address(this).balance;

        sendViaCall(payable(owner()), balance);
    }

    function sendViaCall(address payable to, uint256 amount) internal {
        (bool sent, ) = to.call{value: amount}("");
        require(sent, "Xec: failed to send amount");
    }

    function getBurnedXec(
        address _garbageAddress,
        uint256 _amount
    ) public view returns (uint256) {
        require(E_0[_garbageAddress] > 0, "Xec: E_0 must be greater than 0");

        uint256 decimals = IERC20Metadata(_garbageAddress).decimals();

        uint256 xecAmount = (_amount * E_0[_garbageAddress]) / 10 ** decimals;
        return xecAmount;
    }

    function getXecFee(uint256 _xecAmount) public view returns (uint256) {
        uint256 _M = M;
        uint256 _A = A;
        uint256 _aDecimal = aDecimal;

        uint256 currentCycle = Math.min(GDXen(gdxen).getCurrentCycle(), 30);

        uint256 fee = (_M *
            ((1 * _aDecimal ** (2 + currentCycle)) / (_A ** currentCycle))) /
            _aDecimal ** 2;

        uint256 totalFee = (fee * _xecAmount) / 10 ** XecERC20(xec).decimals();
        return totalFee;
    }

    function getXecLockTime() public view returns (uint256) {
        uint256 lockTime = xecLockTime;

        uint256 maxLockTime = xecMaxLockTime;

        uint256 currentCycle = GDXen(gdxen).getCurrentCycle();

        if (currentCycle > 0) {
            lockTime += (currentCycle / 10) * lockTime;
        }

        return Math.min(lockTime, maxLockTime);
    }

    function getAllGarbageTokens() public view returns (address[] memory) {
        return garbageTokens;
    }

    function supportsInterface(bytes4 interfaceId) public pure returns (bool) {
        return interfaceId == type(IBurnRedeemable).interfaceId;
    }
}

File 32 of 33 : XecERC20.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";

contract XecERC20 is ERC20Permit {
    /**
     * The address of the Xec.sol contract instance.
     */
    address public immutable owner;

    /**
     * Sets the owner address.
     * Called from within the Xec.sol constructor.
     */
    constructor() ERC20("Xec Token", "Xec") ERC20Permit("Xec Token") {
        owner = msg.sender;
    }

    /**
     * The total supply is naturally capped by the distribution algorithm
     * implemented by the main gdxen 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, "Xec: caller is not Xec contract.");
        _mint(account, amount);
    }

    function burn(uint256 amount) external {
        _burn(msg.sender, amount);
    }
}

File 33 of 33 : XENCrypto.sol
// 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);
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"xenAddress","type":"address"},{"internalType":"address","name":"xecTokenAddress","type":"address"},{"internalType":"address","name":"xecAddress","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":"address","name":"userAddress","type":"address"},{"indexed":true,"internalType":"address","name":"referrerAddress","type":"address"}],"name":"InviteNewUser","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":"userAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"health","type":"uint256"}],"name":"RecoverHealth","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":"HEALTH_A","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"HEALTH_E","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"HEALTH_INIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"HEALTH_K","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_BPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROTOCOL_FEE_AMPLIFIER","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROTOCOL_FEE_BASE","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":"SCALING_FACTOR_5","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"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"accBurnedBatches","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":"address","name":"referrerAddress","type":"address"},{"internalType":"uint256","name":"batchNumber","type":"uint256"}],"name":"burnBatch","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_recoverHealth","type":"uint256"}],"name":"calculateBurnXec","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","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":[{"internalType":"address","name":"","type":"address"}],"name":"firstBurnCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gdxen","outputs":[{"internalType":"contract GDXenERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentCycle","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getHealth","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":"","type":"address"}],"name":"isOldUser","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":[],"name":"recoverHealth","outputs":[],"stateMutability":"nonpayable","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":"teamAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","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":"xec","outputs":[{"internalType":"contract Xec","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"xecToken","outputs":[{"internalType":"contract XecERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"xen","outputs":[{"internalType":"contract XENCrypto","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

60c06040523480156200001157600080fd5b5060405162004b5b38038062004b5b83398101604081905262000034916200015d565b6001600055604051620000479062000132565b604051809103906000f08015801562000064573d6000803e3d6000fd5b50600180546001600160a01b03199081166001600160a01b03938416179091556002805482169483169490941790935560038054841692821692909217909155426080526201518060a05269043c33c19375648000006006819055600080527fd840e16649f6b9a295d95876f4633d3a6b10b55e8162971cf78afd886d5ec89b81905560166020527f0263c2b778d062355049effc2dece97bc6547ff8a88a3258daa512061c2153dd55600480548316939091169290921790915560058054339216919091179055620001a7565b611949806200321283390190565b80516001600160a01b03811681146200015857600080fd5b919050565b6000806000606084860312156200017357600080fd5b6200017e8462000140565b92506200018e6020850162000140565b91506200019e6040850162000140565b90509250925092565b60805160a051613037620001db6000396000818161053c0152611ce20152600081816106b60152611d0601526130376000f3fe6080604052600436106103505760003560e01c806391b30020116101c6578063bef51052116100f7578063db80a28c11610095578063ef4cadc51161006f578063ef4cadc514610a25578063f1b371e214610a48578063fa845ca914610a5e578063fd967f471461063e57600080fd5b8063db80a28c1461099e578063e60c90c4146109cb578063ed725e83146109f857600080fd5b8063c67c742d116100d1578063c67c742d14610926578063c8727c811461093b578063d294f09314610973578063d4432e4e1461098857600080fd5b8063bef51052146108b6578063c40af1ee146108e3578063c4235ae9146108f957600080fd5b8063bab2f55211610164578063bd1654bd1161013e578063bd1654bd14610573578063bd21c4b014610859578063be26ed7f14610874578063bebc9dfc1461088957600080fd5b8063bab2f552146107f6578063bc3dc8af1461080c578063bc7132901461082c57600080fd5b8063a95f1dac116101a0578063a95f1dac1461075b578063aabbb1bd14610771578063ad5ed479146107a9578063adc0f686146107c957600080fd5b806391b30020146106f8578063a694fc3a1461070e578063a707140b1461072e57600080fd5b8063304d3fae116102a0578063616b08af1161023e578063857f098111610218578063857f098114610655578063872e3b26146106845780638bd95563146106a45780639055c515146106d857600080fd5b8063616b08af1461060857806368f057691461062857806369ef02641461063e57600080fd5b8063436091c11161027a578063436091c11461059d578063543746b1146105b357806356b96bf5146105d35780635f5080b4146105f257600080fd5b8063304d3fae1461055e5780633119c40014610573578063372500ab1461058857600080fd5b8063138031581161030d5780631ed6380f116102e75780631ed6380f146104c7578063224438d1146104f45780632e17de781461050a5780632f7cdab01461052a57600080fd5b8063138031581461046557806317d9c47a1461047a5780631c75f085146104a757600080fd5b806301b0210a1461035557806301ffc9a71461037d57806306ab411c146103be5780630ad75292146103d35780630ece21541461040b57806312cb22ac14610438575b600080fd5b34801561036157600080fd5b5061036a606481565b6040519081526020015b60405180910390f35b34801561038957600080fd5b506103ae610398366004612c4e565b6001600160e01b03191663543746b160e01b1490565b6040519015158152602001610374565b3480156103ca57600080fd5b5061036a606681565b3480156103df57600080fd5b506001546103f3906001600160a01b031681565b6040516001600160a01b039091168152602001610374565b34801561041757600080fd5b5061036a610426366004612c78565b60196020526000908152604090205481565b34801561044457600080fd5b5061036a610453366004612cad565b60106020526000908152604090205481565b610478610473366004612ccf565b610a8b565b005b34801561048657600080fd5b5061036a610495366004612c78565b60116020526000908152604090205481565b3480156104b357600080fd5b506005546103f3906001600160a01b031681565b3480156104d357600080fd5b5061036a6104e2366004612cad565b601c6020526000908152604090205481565b34801561050057600080fd5b5061036a600e5481565b34801561051657600080fd5b50610478610525366004612c78565b611110565b34801561053657600080fd5b5061036a7f000000000000000000000000000000000000000000000000000000000000000081565b34801561056a57600080fd5b506104786112e3565b34801561057f57600080fd5b5061036a600281565b34801561059457600080fd5b50610478611535565b3480156105a957600080fd5b5061036a600a5481565b3480156105bf57600080fd5b506104786105ce366004612ccf565b61173b565b3480156105df57600080fd5b5061036a6a01a784379d99db4200000081565b3480156105fe57600080fd5b5061036a600b5481565b34801561061457600080fd5b5061036a610623366004612cad565b611814565b34801561063457600080fd5b5061036a600d5481565b34801561064a57600080fd5b5061036a620186a081565b34801561066157600080fd5b506103ae610670366004612cad565b602080526000908152604090205460ff1681565b34801561069057600080fd5b5061036a61069f366004612c78565b6119f4565b3480156106b057600080fd5b5061036a7f000000000000000000000000000000000000000000000000000000000000000081565b3480156106e457600080fd5b506004546103f3906001600160a01b031681565b34801561070457600080fd5b5061036a60065481565b34801561071a57600080fd5b50610478610729366004612c78565b611afd565b34801561073a57600080fd5b5061036a610749366004612cad565b60186020526000908152604090205481565b34801561076757600080fd5b5061036a60075481565b34801561077d57600080fd5b5061036a61078c366004612ccf565b601b60209081526000928352604080842090915290825290205481565b3480156107b557600080fd5b506002546103f3906001600160a01b031681565b3480156107d557600080fd5b5061036a6107e4366004612c78565b60166020526000908152604090205481565b34801561080257600080fd5b5061036a60095481565b34801561081857600080fd5b506003546103f3906001600160a01b031681565b34801561083857600080fd5b5061036a610847366004612cad565b60156020526000908152604090205481565b34801561086557600080fd5b5061036a66038d7ea4c6800081565b34801561088057600080fd5b5061036a611cde565b34801561089557600080fd5b5061036a6108a4366004612c78565b601a6020526000908152604090205481565b3480156108c257600080fd5b5061036a6108d1366004612cad565b601f6020526000908152604090205481565b3480156108ef57600080fd5b5061036a600f5481565b34801561090557600080fd5b5061036a610914366004612c78565b60176020526000908152604090205481565b34801561093257600080fd5b5061036a600181565b34801561094757600080fd5b5061036a610956366004612ccf565b601260209081526000928352604080842090915290825290205481565b34801561097f57600080fd5b50610478611d3a565b34801561099457600080fd5b5061036a60085481565b3480156109aa57600080fd5b5061036a6109b9366004612cad565b601e6020526000908152604090205481565b3480156109d757600080fd5b5061036a6109e6366004612cad565b601d6020526000908152604090205481565b348015610a0457600080fd5b5061036a610a13366004612cad565b60146020526000908152604090205481565b348015610a3157600080fd5b5061036a6b1d6329f1c35ca4bfabb9f56160281b81565b348015610a5457600080fd5b5061036a600c5481565b348015610a6a57600080fd5b5061036a610a79366004612cad565b60136020526000908152604090205481565b610a93611e04565b8060005a9050612710831115610afb5760405162461bcd60e51b815260206004820152602260248201527f474458656e3a206d6178696d206261746368206e756d62657220697320313030604482015261030360f41b60648201526084015b60405180910390fd5b60008311610b4b5760405162461bcd60e51b815260206004820152601c60248201527f474458656e3a206d696e206261746368206e756d6265722069732031000000006044820152606401610af2565b610b606a01a784379d99db4200000084612d0f565b600480546040516370a0823160e01b815233928101929092526001600160a01b0316906370a0823190602401602060405180830381865afa158015610ba9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bcd9190612d26565b1015610beb5760405162461bcd60e51b8152600401610af290612d3f565b336001600160a01b03851603610c435760405162461bcd60e51b815260206004820152601760248201527f474458656e3a2072656665727265722069732073656c660000000000000000006044820152606401610af2565b33600090815260208052604090205460ff16610d295760648310610cf75760035460405163dc8f2d6960e01b81526001600160a01b0386811660048301529091169063dc8f2d6990602401600060405180830381600087803b158015610ca857600080fd5b505af1158015610cbc573d6000803e3d6000fd5b50506040516001600160a01b03871692503391507fdca4f0ed9b7f82ec9b5c9c7f339e58882a8d9015768b67ed73134406fd92d09790600090a35b3360009081526020805260409020805460ff19166001179055610d18611cde565b336000908152601f60205260409020555b6004546001600160a01b0316639dc29fac33610d506a01a784379d99db4200000087612d0f565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015610d9657600080fd5b505af1158015610daa573d6000803e3d6000fd5b505050506000826005610dbd9190612d0f565b610dca90620186a0612d80565b610dd49084612d0f565b90506000610de133611814565b610dec606480612d93565b610df69190612d80565b905060006103e8610e126a01a784379d99db4200000087612d0f565b610e1c9190612dbc565b600354600480546040516329c7f80560e01b81526001600160a01b039182169281019290925260248201849052929350600092909116906329c7f80590604401602060405180830381865afa158015610e79573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e9d9190612d26565b60035460405163819c3f3b60e01b8152600481018390529192506000916001600160a01b039091169063819c3f3b90602401602060405180830381865afa158015610eec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f109190612d26565b905060006064856002620186a0610f2e8a66038d7ea4c68000612d0f565b610f389190612dbc565b610f429190612d0f565b610f4c9190612d0f565b610f569190612dbc565b9050610f628282612d93565b341015610fbd5760405162461bcd60e51b815260206004820152602360248201527f474458656e3a2076616c7565206c657373207468616e2070726f746f636f6c2060448201526266656560e81b6064820152608401610af2565b60035460405163280e630960e01b8152600481018690523360248201526001600160a01b039091169063280e63099084906044016000604051808303818588803b15801561100a57600080fd5b505af115801561101e573d6000803e3d6000fd5b505050505087600f60008282546110359190612d93565b9091555050600954600090815260116020526040812080548a929061105b908490612d93565b90915550503360009081526012602090815260408083206009548452909152812080548a929061108c908490612d93565b909155505033600090815260106020526040812080548a92906110b0908490612d93565b9091555050600954600090815260196020526040812080548392906110d6908490612d93565b909155506110fa905033836110eb8434612d80565b6110f59190612d80565b611e5d565b505050505050505061110c6001600055565b5050565b611118611e04565b611120611f05565b611128611f20565b61113133612062565b600081116111515760405162461bcd60e51b8152600401610af290612dd0565b606461115c33611814565b101561117a5760405162461bcd60e51b8152600401610af290612dff565b336000908152601c60205260409020548111156111ef5760405162461bcd60e51b815260206004820152602d60248201527f474458656e3a20616d6f756e742067726561746572207468616e20776974686460448201526c72617761626c65207374616b6560981b6064820152608401610af2565b600c54600a54036112175780600d600082825461120c9190612d93565b9091555061123e9050565b60095460009081526017602052604081208054839290611238908490612d80565b90915550505b336000908152601c60205260408120805483929061125d908490612d80565b90915550503360009081526014602052604081208054839290611281908490612d80565b909155505060015461129d906001600160a01b0316338361268c565b6009546040518281523391907f37375b03d8924bd8f076f11f8411b9962aa5c02fb489021507bc6bb6f850e3659060200160405180910390a36112e06001600055565b50565b6112eb611e04565b60646112f633611814565b106113435760405162461bcd60e51b815260206004820152601e60248201527f474458656e3a206865616c74682067726561746572207468616e2031303000006044820152606401610af2565b61134b611f05565b33600090815260208052604090205460ff166113a95760405162461bcd60e51b815260206004820152601860248201527f474458656e56696577733a206e6f74206f6c64207573657200000000000000006044820152606401610af2565b60006113b433611814565b905060006113c3826064612d80565b905060006113d0826119f4565b6002546040516370a0823160e01b815233600482015291925082916001600160a01b03909116906370a0823190602401602060405180830381865afa15801561141d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114419190612d26565b101561145f5760405162461bcd60e51b8152600401610af290612d3f565b600254611477906001600160a01b03163330846126ef565b61147f611cde565b336000908152601f602052604090819020919091556002549051630852cd8d60e31b8152600481018390526001600160a01b03909116906342966c6890602401600060405180830381600087803b1580156114d957600080fd5b505af11580156114ed573d6000803e3d6000fd5b50506040518481523392507ff8fc6e6bea4fbbdb2e72c44b7a05758fb4d348f9cac00a8960855dc5068ab65e915060200160405180910390a25050506115336001600055565b565b61153d611e04565b611545611f05565b61154d611f20565b61155633612062565b336000908152601c6020908152604080832054601490925282205461157b9190612d80565b9050600081116115cd5760405162461bcd60e51b815260206004820152601d60248201527f474458656e3a206163636f756e7420686173206e6f20726577617264730000006044820152606401610af2565b60646115d833611814565b10156115f65760405162461bcd60e51b8152600401610af290612dff565b3360009081526014602052604081208054839290611615908490612d80565b9091555050600c54600a54036116425780600d60008282546116379190612d93565b909155506116729050565b60095460009081526017602052604090205461165f908290612d80565b6009546000908152601760205260409020555b6001546001600160a01b0316639a49090e336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b1580156116cc57600080fd5b505af11580156116e0573d6000803e3d6000fd5b505050506116eb3390565b6001600160a01b03166009547f3300bdb359cfb956935bca32e9db727413eab1ca84341f2e36caea85bb7969688360405161172891815260200190565b60405180910390a3506115336001600055565b6004546001600160a01b031633146117955760405162461bcd60e51b815260206004820152601e60248201527f474458656e3a20696c6c6567616c2063616c6c6261636b2063616c6c657200006044820152606401610af2565b61179d611f05565b6117a5611f20565b6117ad61272d565b6117b682612062565b6009546001600160a01b038316600081815260136020526040908190209290925590517fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5906118089084815260200190565b60405180910390a25050565b336000908152601f6020526040812054819061182e611cde565b6118389190612d80565b905080158061185f57506001600160a01b038316600090815260208052604090205460ff16155b1561186d5750606492915050565b6000607482111561187f579392505050565b600061188c600184612f1a565b611897906002612d0f565b905060006118a6601e83612dbc565b905060006118b5601e84612f26565b9050811561197d576118c8816064612f1a565b620186a06118d7836066612f1a565b6118e19190612d0f565b6118eb9190612dbc565b82789f4f2726179a224501d762422c946590d91000000000000000620186a0611916601e6066612f3a565b6119209190612d0f565b61192a9190612dbc565b6119349190612f1a565b61193e9190612d0f565b611949836002612d93565b61195690620186a0612f1a565b611961906001612d0f565b61196b9190612dbc565b611976906064612d0f565b93506119dc565b611988816064612f1a565b620186a0611997836066612f1a565b6119a19190612d0f565b6119ab9190612dbc565b6119b96002620186a0612f3a565b6119c4906001612d0f565b6119ce9190612dbc565b6119d9906064612d0f565b93505b6119e9620186a085612dbc565b979650505050505050565b6000806119ff611cde565b90506000606b90506000606485600260009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a839190612f49565b611a8e90600a612f3a565b611acc611ac4611a9d87612889565b611abb611ab3611aae8b6001612d93565b612889565b600f0b6128a7565b600f0b9061298b565b600f0b6129dd565b67ffffffffffffffff16611ae09190612d0f565b611aea9190612d0f565b611af49190612dbc565b95945050505050565b611b05611e04565b611b0d611f05565b611b15611f20565b611b1e33612062565b60008111611b3e5760405162461bcd60e51b8152600401610af290612dd0565b33600090815260208052604090205460ff16611b86573360009081526020805260409020805460ff19166001179055611b75611cde565b336000908152601f60205260409020555b8060086000828254611b989190612d93565b9091555050600954600090611bae906001612d93565b9050600c54600a5403611bcc57600a54611bc9906001612d93565b90505b336000908152601d60205260409020548114801590611bfa5750336000908152601e60205260409020548114155b15611c5557336000908152601d60205260408120549003611c2c57336000908152601d60205260409020819055611c55565b336000908152601e60205260408120549003611c5557336000908152601e602052604090208190555b336000908152601b6020908152604080832084845290915281208054849290611c7f908490612d93565b9091555050600154611c9c906001600160a01b03163330856126ef565b604051828152339082907f18dcd430020e4d4899772fd94a8b40451dc5044dfb70bc46b532eeae431c864f9060200160405180910390a3506112e06001600055565b60007f0000000000000000000000000000000000000000000000000000000000000000611d2b7f000000000000000000000000000000000000000000000000000000000000000042612d80565b611d359190612dbc565b905090565b611d42611e04565b611d4a611f05565b611d52611f20565b611d5b33612062565b6064611d6633611814565b1015611d845760405162461bcd60e51b8152600401610af290612dff565b3360009081526015602052604090205480611db15760405162461bcd60e51b8152600401610af290612dd0565b33600081815260156020526040812055611dcb9082611e5d565b33611dd4611cde565b6040518381527f2227733fc4c8a9034cb58087dcf6995128b9c0233b038b03366aaf30c92b92d690602001611728565b600260005403611e565760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610af2565b6002600055565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611eaa576040519150601f19603f3d011682016040523d82523d6000602084013e611eaf565b606091505b5050905080611f005760405162461bcd60e51b815260206004820152601c60248201527f474458656e3a206661696c656420746f2073656e6420616d6f756e74000000006044820152606401610af2565b505050565b6000611f0f611cde565b90506009548111156112e057600955565b600c5460095414611f4357600a54611f39906001612d93565b600b55600c54600a555b600a54600954118015611f775750601a6000600a546001611f649190612d93565b8152602001908152602001600020546000145b1561153357600a5460009081526017602052604081205415611fed57600a54600090815260176020908152604080832054600e5460199093529220546b1d6329f1c35ca4bfabb9f56160281b91611fcd91612d93565b611fd79190612d0f565b611fe19190612dbc565b6000600e55905061201e565b60196000600a54815260200190815260200160002054600e60008282546120149190612d93565b9091555060009150505b600b546000908152601a602052604090205461203b908290612d93565b601a6000600a54600161204e9190612d93565b815260208101919091526040016000205550565b6001600160a01b0381166000908152601360205260409020546009541180156120a257506001600160a01b03811660009081526010602052604090205415155b15612145576001600160a01b0381166000818152601360209081526040808320548352601182528083205460168352818420549484526010909252822054919290916120ee9190612d0f565b6120f89190612dbc565b6001600160a01b038316600090815260146020526040812080549293508392909190612125908490612d93565b9091555050506001600160a01b0381166000908152601060205260408120555b600a5460095411801561217d5750600a54612161906001612d93565b6001600160a01b03821660009081526018602052604090205414155b15612276576001600160a01b0381166000908152601860209081526040808320548352601a91829052822054600a546b1d6329f1c35ca4bfabb9f56160281b93919291906121cc906001612d93565b8152602001908152602001600020546121e59190612d80565b6001600160a01b0383166000908152601460205260409020546122089190612d0f565b6122129190612dbc565b6001600160a01b0382166000908152601560205260409020546122359190612d93565b6001600160a01b038216600090815260156020526040902055600a5461225c906001612d93565b6001600160a01b0382166000908152601860205260409020555b6001600160a01b0381166000908152601d6020526040902054158015906122b657506001600160a01b0381166000908152601d6020526040902054600954115b156112e0576001600160a01b0381166000818152601b60209081526040808320601d8352818420548452825280832054938352601490915281208054839290612300908490612d93565b90915550506001600160a01b0382166000908152601c60205260408120805483929061232d908490612d93565b90915550506001600160a01b0382166000908152601d6020526040902054600a54612359906001612d93565b111561243e576001600160a01b0382166000908152601d60209081526040808320548352601a91829052822054600a546b1d6329f1c35ca4bfabb9f56160281b93919291906123a9906001612d93565b8152602001908152602001600020546123c29190612d80565b6001600160a01b0384166000908152601b60209081526040808320601d83528184205484529091529020546123f79190612d0f565b6124019190612dbc565b6001600160a01b0383166000908152601560205260409020546124249190612d93565b6001600160a01b0383166000908152601560205260409020555b6001600160a01b0382166000818152601b60209081526040808320601d83528184208054855290835281842084905593835292829055601e905220541561110c576001600160a01b0382166000908152601e6020526040902054600954111561265e576001600160a01b0382166000818152601b60209081526040808320601e83528184205484528252808320549383526014909152812080548392906124e6908490612d93565b90915550506001600160a01b0383166000908152601c602052604081208054839290612513908490612d93565b90915550506001600160a01b0383166000908152601e6020526040902054600a5461253f906001612d93565b1115612624576001600160a01b0383166000908152601e60209081526040808320548352601a91829052822054600a546b1d6329f1c35ca4bfabb9f56160281b939192919061258f906001612d93565b8152602001908152602001600020546125a89190612d80565b6001600160a01b0385166000908152601b60209081526040808320601e83528184205484529091529020546125dd9190612d0f565b6125e79190612dbc565b6001600160a01b03841660009081526015602052604090205461260a9190612d93565b6001600160a01b0384166000908152601560205260409020555b50506001600160a01b03166000818152601b60209081526040808320601e8084528285208054865291845291842084905593835290529055565b506001600160a01b03166000908152601e602081815260408084208054601d84529185209190915591905255565b6040516001600160a01b038316602482015260448101829052611f0090849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526129f9565b6040516001600160a01b03808516602483015283166044820152606481018290526127279085906323b872dd60e01b906084016126b8565b50505050565b6009546000908152601660205260408120549003611533576006546007819055600090614e709061276090614e20612d0f565b61276a9190612dbc565b60068190556009805460009081526016602090815260408083208590559254600c55600a5482526017905220549091506127a5908290612d93565b600c54600090815260176020526040812080549091906127c6908490612d93565b90915550506008541561280257600854600c54600090815260176020526040812080549091906127f7908490612d93565b909155505060006008555b600d541561283957600d54600c546000908152601760205260408120805490919061282e908490612d80565b90915550506000600d555b600954600c54600090815260176020908152604091829020548251858152918201527f0666a61c1092f5b86c2cfe6ea1ad0d9a36032c4fb92d285b4e43f662d48f19b4910160405180910390a250565b6000677fffffffffffffff8211156128a057600080fd5b5060401b90565b60008082600f0b136128b857600080fd5b6000600f83900b6801000000000000000081126128d7576040918201911d5b64010000000081126128eb576020918201911d5b6201000081126128fd576010918201911d5b610100811261290e576008918201911d5b6010811261291e576004918201911d5b6004811261292e576002918201911d5b6002811261293d576001820191505b603f19820160401b600f85900b607f8490031b6780000000000000005b60008113156129805790800260ff81901c8281029390930192607f011c9060011d61295a565b509095945050505050565b6000600f83810b9083900b0260401d6f7fffffffffffffffffffffffffffffff1981128015906129cb57506f7fffffffffffffffffffffffffffffff8113155b6129d457600080fd5b90505b92915050565b60008082600f0b12156129ef57600080fd5b50600f0b60401d90565b6000612a4e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612ace9092919063ffffffff16565b9050805160001480612a6f575080806020019051810190612a6f9190612f6c565b611f005760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610af2565b6060612add8484600085612ae5565b949350505050565b606082471015612b465760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610af2565b600080866001600160a01b03168587604051612b629190612fb2565b60006040518083038185875af1925050503d8060008114612b9f576040519150601f19603f3d011682016040523d82523d6000602084013e612ba4565b606091505b50915091506119e98783838760608315612c1f578251600003612c18576001600160a01b0385163b612c185760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610af2565b5081612add565b612add8383815115612c345781518083602001fd5b8060405162461bcd60e51b8152600401610af29190612fce565b600060208284031215612c6057600080fd5b81356001600160e01b0319811681146129d457600080fd5b600060208284031215612c8a57600080fd5b5035919050565b80356001600160a01b0381168114612ca857600080fd5b919050565b600060208284031215612cbf57600080fd5b612cc882612c91565b9392505050565b60008060408385031215612ce257600080fd5b612ceb83612c91565b946020939093013593505050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176129d7576129d7612cf9565b600060208284031215612d3857600080fd5b5051919050565b60208082526021908201527f474458656e3a206e6f7420656e6f75676820746f6b656e7320666f72206275726040820152603760f91b606082015260800190565b818103818111156129d7576129d7612cf9565b808201808211156129d7576129d7612cf9565b634e487b7160e01b600052601260045260246000fd5b600082612dcb57612dcb612da6565b500490565b602080825260159082015274474458656e3a20616d6f756e74206973207a65726f60581b604082015260600190565b6020808252601b908201527f474458656e3a206865616c7468206c657373207468616e203130300000000000604082015260600190565b600181815b80851115612e71578160001904821115612e5757612e57612cf9565b80851615612e6457918102915b93841c9390800290612e3b565b509250929050565b600082612e88575060016129d7565b81612e95575060006129d7565b8160018114612eab5760028114612eb557612ed1565b60019150506129d7565b60ff841115612ec657612ec6612cf9565b50506001821b6129d7565b5060208310610133831016604e8410600b8410161715612ef4575081810a6129d7565b612efe8383612e36565b8060001904821115612f1257612f12612cf9565b029392505050565b6000612cc88383612e79565b600082612f3557612f35612da6565b500690565b6000612cc860ff841683612e79565b600060208284031215612f5b57600080fd5b815160ff811681146129d457600080fd5b600060208284031215612f7e57600080fd5b815180151581146129d457600080fd5b60005b83811015612fa9578181015183820152602001612f91565b50506000910152565b60008251612fc4818460208701612f8e565b9190910192915050565b6020815260008251806020840152612fed816040850160208701612f8e565b601f01601f1916919091016040019291505056fea2646970667358221220e6756f0ee76b2baa66bec990aafe96fc4d3ab24180834e87fa32505b84bebc9f64736f6c634300081100336101806040523480156200001257600080fd5b506040518060400160405280600b81526020016a23a22c32b7102a37b5b2b760a91b81525080604051806040016040528060018152602001603160f81b8152506040518060400160405280600b81526020016a23a22c32b7102a37b5b2b760a91b8152506040518060400160405280600581526020016423a22c32b760d91b8152508160039081620000a59190620002d6565b506004620000b48282620002d6565b505050620000d26005836200019260201b620007671790919060201c565b61012052620000ef81600662000192602090811b6200076717901c565b61014052815160208084019190912060e052815190820120610100524660a0526200017d60e05161010051604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201529081019290925260608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b60805250503060c05250336101605262000417565b6000602083511015620001b257620001aa83620001e2565b9050620001dc565b82620001c9836200022e60201b620007981760201c565b90620001d69082620002d6565b5060ff90505b92915050565b600080829050601f8151111562000219578260405163305a27a960e01b8152600401620002109190620003a2565b60405180910390fd5b80516200022682620003f2565b179392505050565b90565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200025c57607f821691505b6020821081036200027d57634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620002d157600081815260208120601f850160051c81016020861015620002ac5750805b601f850160051c820191505b81811015620002cd57828155600101620002b8565b5050505b505050565b81516001600160401b03811115620002f257620002f262000231565b6200030a8162000303845462000247565b8462000283565b602080601f831160018114620003425760008415620003295750858301515b600019600386901b1c1916600185901b178555620002cd565b600085815260208120601f198616915b82811015620003735788860151825594840194600190910190840162000352565b5085821015620003925787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b600060208083528351808285015260005b81811015620003d157858101830151858201604001528201620003b3565b506000604082860101526040601f19601f8301168501019250505092915050565b805160208083015191908110156200027d5760001960209190910360031b1b16919050565b60805160a05160c05160e051610100516101205161014051610160516114c562000484600039600081816101fc0152610461015260006103f7015260006103cc01526000610bb701526000610b8f01526000610aea01526000610b1401526000610b3e01526114c56000f3fe608060405234801561001057600080fd5b506004361061010b5760003560e01c80637ecebe00116100a25780639a49090e116100715780639a49090e1461023e578063a457c2d714610253578063a9059cbb14610266578063d505accf14610279578063dd62ed3e1461028c57600080fd5b80637ecebe00146101c957806384b0196e146101dc5780638da5cb5b146101f757806395d89b411461023657600080fd5b8063313ce567116100de578063313ce567146101765780633644e51514610185578063395093511461018d57806370a08231146101a057600080fd5b806306fdde0314610110578063095ea7b31461012e57806318160ddd1461015157806323b872dd14610163575b600080fd5b61011861029f565b60405161012591906110e9565b60405180910390f35b61014161013c36600461111f565b610331565b6040519015158152602001610125565b6002545b604051908152602001610125565b610141610171366004611149565b61034b565b60405160128152602001610125565b61015561036f565b61014161019b36600461111f565b61037e565b6101556101ae366004611185565b6001600160a01b031660009081526020819052604090205490565b6101556101d7366004611185565b6103a0565b6101e46103be565b60405161012597969594939291906111a0565b61021e7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610125565b610118610447565b61025161024c36600461111f565b610456565b005b61014161026136600461111f565b61054f565b61014161027436600461111f565b6105ca565b610251610287366004611236565b6105d8565b61015561029a3660046112a9565b61073c565b6060600380546102ae906112dc565b80601f01602080910402602001604051908101604052809291908181526020018280546102da906112dc565b80156103275780601f106102fc57610100808354040283529160200191610327565b820191906000526020600020905b81548152906001019060200180831161030a57829003601f168201915b5050505050905090565b60003361033f81858561079b565b60019150505b92915050565b6000336103598582856108bf565b610364858585610939565b506001949350505050565b6000610379610add565b905090565b60003361033f818585610391838361073c565b61039b9190611310565b61079b565b6001600160a01b038116600090815260076020526040812054610345565b6000606080828080836103f27f00000000000000000000000000000000000000000000000000000000000000006005610c08565b61041d7f00000000000000000000000000000000000000000000000000000000000000006006610c08565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6060600480546102ae906112dc565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146104df5760405162461bcd60e51b8152602060048201526024808201527f474458656e3a2063616c6c6572206973206e6f7420474458656e20636f6e747260448201526330b1ba1760e11b60648201526084015b60405180910390fd5b6a0424e8a4eaca5ed74000006104f460025490565b106105415760405162461bcd60e51b815260206004820181905260248201527f474458656e3a206d617820737570706c7920616c7265616479206d696e74656460448201526064016104d6565b61054b8282610cac565b5050565b6000338161055d828661073c565b9050838110156105bd5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084016104d6565b610364828686840361079b565b60003361033f818585610939565b834211156106285760405162461bcd60e51b815260206004820152601d60248201527f45524332305065726d69743a206578706972656420646561646c696e6500000060448201526064016104d6565b60007f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886106578c610d6b565b6040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e00160405160208183030381529060405280519060200120905060006106b282610d93565b905060006106c282878787610dc0565b9050896001600160a01b0316816001600160a01b0316146107255760405162461bcd60e51b815260206004820152601e60248201527f45524332305065726d69743a20696e76616c6964207369676e6174757265000060448201526064016104d6565b6107308a8a8a61079b565b50505050505050505050565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b60006020835110156107835761077c83610de8565b9050610345565b8161078e8482611395565b5060ff9050610345565b90565b6001600160a01b0383166107fd5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016104d6565b6001600160a01b03821661085e5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016104d6565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006108cb848461073c565b9050600019811461093357818110156109265760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e636500000060448201526064016104d6565b610933848484840361079b565b50505050565b6001600160a01b03831661099d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016104d6565b6001600160a01b0382166109ff5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016104d6565b6001600160a01b03831660009081526020819052604090205481811015610a775760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b60648201526084016104d6565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610933565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148015610b3657507f000000000000000000000000000000000000000000000000000000000000000046145b15610b6057507f000000000000000000000000000000000000000000000000000000000000000090565b610379604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260009060c00160405160208183030381529060405280519060200120905090565b606060ff8314610c1b5761077c83610e2b565b818054610c27906112dc565b80601f0160208091040260200160405190810160405280929190818152602001828054610c53906112dc565b8015610ca05780601f10610c7557610100808354040283529160200191610ca0565b820191906000526020600020905b815481529060010190602001808311610c8357829003601f168201915b50505050509050610345565b6001600160a01b038216610d025760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016104d6565b8060026000828254610d149190611310565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b6001600160a01b03811660009081526007602052604090208054600181018255905b50919050565b6000610345610da0610add565b8360405161190160f01b8152600281019290925260228201526042902090565b6000806000610dd187878787610e6a565b91509150610dde81610f2e565b5095945050505050565b600080829050601f81511115610e13578260405163305a27a960e01b81526004016104d691906110e9565b8051610e1e82611455565b179392505050565b505050565b60606000610e388361107b565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0831115610ea15750600090506003610f25565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015610ef5573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116610f1e57600060019250925050610f25565b9150600090505b94509492505050565b6000816004811115610f4257610f42611479565b03610f4a5750565b6001816004811115610f5e57610f5e611479565b03610fab5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e6174757265000000000000000060448201526064016104d6565b6002816004811115610fbf57610fbf611479565b0361100c5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e6774680060448201526064016104d6565b600381600481111561102057611020611479565b036110785760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b60648201526084016104d6565b50565b600060ff8216601f81111561034557604051632cd44ac360e21b815260040160405180910390fd5b6000815180845260005b818110156110c9576020818501810151868301820152016110ad565b506000602082860101526020601f19601f83011685010191505092915050565b6020815260006110fc60208301846110a3565b9392505050565b80356001600160a01b038116811461111a57600080fd5b919050565b6000806040838503121561113257600080fd5b61113b83611103565b946020939093013593505050565b60008060006060848603121561115e57600080fd5b61116784611103565b925061117560208501611103565b9150604084013590509250925092565b60006020828403121561119757600080fd5b6110fc82611103565b60ff60f81b881681526000602060e0818401526111c060e084018a6110a3565b83810360408501526111d2818a6110a3565b606085018990526001600160a01b038816608086015260a0850187905284810360c0860152855180825283870192509083019060005b8181101561122457835183529284019291840191600101611208565b50909c9b505050505050505050505050565b600080600080600080600060e0888a03121561125157600080fd5b61125a88611103565b965061126860208901611103565b95506040880135945060608801359350608088013560ff8116811461128c57600080fd5b9699959850939692959460a0840135945060c09093013592915050565b600080604083850312156112bc57600080fd5b6112c583611103565b91506112d360208401611103565b90509250929050565b600181811c908216806112f057607f821691505b602082108103610d8d57634e487b7160e01b600052602260045260246000fd5b8082018082111561034557634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b601f821115610e2657600081815260208120601f850160051c8101602086101561136e5750805b601f850160051c820191505b8181101561138d5782815560010161137a565b505050505050565b815167ffffffffffffffff8111156113af576113af611331565b6113c3816113bd84546112dc565b84611347565b602080601f8311600181146113f857600084156113e05750858301515b600019600386901b1c1916600185901b17855561138d565b600085815260208120601f198616915b8281101561142757888601518255948401946001909101908401611408565b50858210156114455787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b80516020808301519190811015610d8d5760001960209190910360031b1b16919050565b634e487b7160e01b600052602160045260246000fdfea2646970667358221220953ddd014181360432c23a3661540c3ebd11f72cc3ddea25da3dcd3c42d878a664736f6c6343000811003300000000000000000000000006450dee7fd2fb8e39061434babcfc05599a6fb800000000000000000000000078be30f2a60d63244425aa2466b90ca677d5aa770000000000000000000000009b38b7212083ead287c1fcdd0827d9648ff19a0e

Deployed Bytecode

0x6080604052600436106103505760003560e01c806391b30020116101c6578063bef51052116100f7578063db80a28c11610095578063ef4cadc51161006f578063ef4cadc514610a25578063f1b371e214610a48578063fa845ca914610a5e578063fd967f471461063e57600080fd5b8063db80a28c1461099e578063e60c90c4146109cb578063ed725e83146109f857600080fd5b8063c67c742d116100d1578063c67c742d14610926578063c8727c811461093b578063d294f09314610973578063d4432e4e1461098857600080fd5b8063bef51052146108b6578063c40af1ee146108e3578063c4235ae9146108f957600080fd5b8063bab2f55211610164578063bd1654bd1161013e578063bd1654bd14610573578063bd21c4b014610859578063be26ed7f14610874578063bebc9dfc1461088957600080fd5b8063bab2f552146107f6578063bc3dc8af1461080c578063bc7132901461082c57600080fd5b8063a95f1dac116101a0578063a95f1dac1461075b578063aabbb1bd14610771578063ad5ed479146107a9578063adc0f686146107c957600080fd5b806391b30020146106f8578063a694fc3a1461070e578063a707140b1461072e57600080fd5b8063304d3fae116102a0578063616b08af1161023e578063857f098111610218578063857f098114610655578063872e3b26146106845780638bd95563146106a45780639055c515146106d857600080fd5b8063616b08af1461060857806368f057691461062857806369ef02641461063e57600080fd5b8063436091c11161027a578063436091c11461059d578063543746b1146105b357806356b96bf5146105d35780635f5080b4146105f257600080fd5b8063304d3fae1461055e5780633119c40014610573578063372500ab1461058857600080fd5b8063138031581161030d5780631ed6380f116102e75780631ed6380f146104c7578063224438d1146104f45780632e17de781461050a5780632f7cdab01461052a57600080fd5b8063138031581461046557806317d9c47a1461047a5780631c75f085146104a757600080fd5b806301b0210a1461035557806301ffc9a71461037d57806306ab411c146103be5780630ad75292146103d35780630ece21541461040b57806312cb22ac14610438575b600080fd5b34801561036157600080fd5b5061036a606481565b6040519081526020015b60405180910390f35b34801561038957600080fd5b506103ae610398366004612c4e565b6001600160e01b03191663543746b160e01b1490565b6040519015158152602001610374565b3480156103ca57600080fd5b5061036a606681565b3480156103df57600080fd5b506001546103f3906001600160a01b031681565b6040516001600160a01b039091168152602001610374565b34801561041757600080fd5b5061036a610426366004612c78565b60196020526000908152604090205481565b34801561044457600080fd5b5061036a610453366004612cad565b60106020526000908152604090205481565b610478610473366004612ccf565b610a8b565b005b34801561048657600080fd5b5061036a610495366004612c78565b60116020526000908152604090205481565b3480156104b357600080fd5b506005546103f3906001600160a01b031681565b3480156104d357600080fd5b5061036a6104e2366004612cad565b601c6020526000908152604090205481565b34801561050057600080fd5b5061036a600e5481565b34801561051657600080fd5b50610478610525366004612c78565b611110565b34801561053657600080fd5b5061036a7f000000000000000000000000000000000000000000000000000000000001518081565b34801561056a57600080fd5b506104786112e3565b34801561057f57600080fd5b5061036a600281565b34801561059457600080fd5b50610478611535565b3480156105a957600080fd5b5061036a600a5481565b3480156105bf57600080fd5b506104786105ce366004612ccf565b61173b565b3480156105df57600080fd5b5061036a6a01a784379d99db4200000081565b3480156105fe57600080fd5b5061036a600b5481565b34801561061457600080fd5b5061036a610623366004612cad565b611814565b34801561063457600080fd5b5061036a600d5481565b34801561064a57600080fd5b5061036a620186a081565b34801561066157600080fd5b506103ae610670366004612cad565b602080526000908152604090205460ff1681565b34801561069057600080fd5b5061036a61069f366004612c78565b6119f4565b3480156106b057600080fd5b5061036a7f0000000000000000000000000000000000000000000000000000000065536f6781565b3480156106e457600080fd5b506004546103f3906001600160a01b031681565b34801561070457600080fd5b5061036a60065481565b34801561071a57600080fd5b50610478610729366004612c78565b611afd565b34801561073a57600080fd5b5061036a610749366004612cad565b60186020526000908152604090205481565b34801561076757600080fd5b5061036a60075481565b34801561077d57600080fd5b5061036a61078c366004612ccf565b601b60209081526000928352604080842090915290825290205481565b3480156107b557600080fd5b506002546103f3906001600160a01b031681565b3480156107d557600080fd5b5061036a6107e4366004612c78565b60166020526000908152604090205481565b34801561080257600080fd5b5061036a60095481565b34801561081857600080fd5b506003546103f3906001600160a01b031681565b34801561083857600080fd5b5061036a610847366004612cad565b60156020526000908152604090205481565b34801561086557600080fd5b5061036a66038d7ea4c6800081565b34801561088057600080fd5b5061036a611cde565b34801561089557600080fd5b5061036a6108a4366004612c78565b601a6020526000908152604090205481565b3480156108c257600080fd5b5061036a6108d1366004612cad565b601f6020526000908152604090205481565b3480156108ef57600080fd5b5061036a600f5481565b34801561090557600080fd5b5061036a610914366004612c78565b60176020526000908152604090205481565b34801561093257600080fd5b5061036a600181565b34801561094757600080fd5b5061036a610956366004612ccf565b601260209081526000928352604080842090915290825290205481565b34801561097f57600080fd5b50610478611d3a565b34801561099457600080fd5b5061036a60085481565b3480156109aa57600080fd5b5061036a6109b9366004612cad565b601e6020526000908152604090205481565b3480156109d757600080fd5b5061036a6109e6366004612cad565b601d6020526000908152604090205481565b348015610a0457600080fd5b5061036a610a13366004612cad565b60146020526000908152604090205481565b348015610a3157600080fd5b5061036a6b1d6329f1c35ca4bfabb9f56160281b81565b348015610a5457600080fd5b5061036a600c5481565b348015610a6a57600080fd5b5061036a610a79366004612cad565b60136020526000908152604090205481565b610a93611e04565b8060005a9050612710831115610afb5760405162461bcd60e51b815260206004820152602260248201527f474458656e3a206d6178696d206261746368206e756d62657220697320313030604482015261030360f41b60648201526084015b60405180910390fd5b60008311610b4b5760405162461bcd60e51b815260206004820152601c60248201527f474458656e3a206d696e206261746368206e756d6265722069732031000000006044820152606401610af2565b610b606a01a784379d99db4200000084612d0f565b600480546040516370a0823160e01b815233928101929092526001600160a01b0316906370a0823190602401602060405180830381865afa158015610ba9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bcd9190612d26565b1015610beb5760405162461bcd60e51b8152600401610af290612d3f565b336001600160a01b03851603610c435760405162461bcd60e51b815260206004820152601760248201527f474458656e3a2072656665727265722069732073656c660000000000000000006044820152606401610af2565b33600090815260208052604090205460ff16610d295760648310610cf75760035460405163dc8f2d6960e01b81526001600160a01b0386811660048301529091169063dc8f2d6990602401600060405180830381600087803b158015610ca857600080fd5b505af1158015610cbc573d6000803e3d6000fd5b50506040516001600160a01b03871692503391507fdca4f0ed9b7f82ec9b5c9c7f339e58882a8d9015768b67ed73134406fd92d09790600090a35b3360009081526020805260409020805460ff19166001179055610d18611cde565b336000908152601f60205260409020555b6004546001600160a01b0316639dc29fac33610d506a01a784379d99db4200000087612d0f565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b158015610d9657600080fd5b505af1158015610daa573d6000803e3d6000fd5b505050506000826005610dbd9190612d0f565b610dca90620186a0612d80565b610dd49084612d0f565b90506000610de133611814565b610dec606480612d93565b610df69190612d80565b905060006103e8610e126a01a784379d99db4200000087612d0f565b610e1c9190612dbc565b600354600480546040516329c7f80560e01b81526001600160a01b039182169281019290925260248201849052929350600092909116906329c7f80590604401602060405180830381865afa158015610e79573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e9d9190612d26565b60035460405163819c3f3b60e01b8152600481018390529192506000916001600160a01b039091169063819c3f3b90602401602060405180830381865afa158015610eec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f109190612d26565b905060006064856002620186a0610f2e8a66038d7ea4c68000612d0f565b610f389190612dbc565b610f429190612d0f565b610f4c9190612d0f565b610f569190612dbc565b9050610f628282612d93565b341015610fbd5760405162461bcd60e51b815260206004820152602360248201527f474458656e3a2076616c7565206c657373207468616e2070726f746f636f6c2060448201526266656560e81b6064820152608401610af2565b60035460405163280e630960e01b8152600481018690523360248201526001600160a01b039091169063280e63099084906044016000604051808303818588803b15801561100a57600080fd5b505af115801561101e573d6000803e3d6000fd5b505050505087600f60008282546110359190612d93565b9091555050600954600090815260116020526040812080548a929061105b908490612d93565b90915550503360009081526012602090815260408083206009548452909152812080548a929061108c908490612d93565b909155505033600090815260106020526040812080548a92906110b0908490612d93565b9091555050600954600090815260196020526040812080548392906110d6908490612d93565b909155506110fa905033836110eb8434612d80565b6110f59190612d80565b611e5d565b505050505050505061110c6001600055565b5050565b611118611e04565b611120611f05565b611128611f20565b61113133612062565b600081116111515760405162461bcd60e51b8152600401610af290612dd0565b606461115c33611814565b101561117a5760405162461bcd60e51b8152600401610af290612dff565b336000908152601c60205260409020548111156111ef5760405162461bcd60e51b815260206004820152602d60248201527f474458656e3a20616d6f756e742067726561746572207468616e20776974686460448201526c72617761626c65207374616b6560981b6064820152608401610af2565b600c54600a54036112175780600d600082825461120c9190612d93565b9091555061123e9050565b60095460009081526017602052604081208054839290611238908490612d80565b90915550505b336000908152601c60205260408120805483929061125d908490612d80565b90915550503360009081526014602052604081208054839290611281908490612d80565b909155505060015461129d906001600160a01b0316338361268c565b6009546040518281523391907f37375b03d8924bd8f076f11f8411b9962aa5c02fb489021507bc6bb6f850e3659060200160405180910390a36112e06001600055565b50565b6112eb611e04565b60646112f633611814565b106113435760405162461bcd60e51b815260206004820152601e60248201527f474458656e3a206865616c74682067726561746572207468616e2031303000006044820152606401610af2565b61134b611f05565b33600090815260208052604090205460ff166113a95760405162461bcd60e51b815260206004820152601860248201527f474458656e56696577733a206e6f74206f6c64207573657200000000000000006044820152606401610af2565b60006113b433611814565b905060006113c3826064612d80565b905060006113d0826119f4565b6002546040516370a0823160e01b815233600482015291925082916001600160a01b03909116906370a0823190602401602060405180830381865afa15801561141d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114419190612d26565b101561145f5760405162461bcd60e51b8152600401610af290612d3f565b600254611477906001600160a01b03163330846126ef565b61147f611cde565b336000908152601f602052604090819020919091556002549051630852cd8d60e31b8152600481018390526001600160a01b03909116906342966c6890602401600060405180830381600087803b1580156114d957600080fd5b505af11580156114ed573d6000803e3d6000fd5b50506040518481523392507ff8fc6e6bea4fbbdb2e72c44b7a05758fb4d348f9cac00a8960855dc5068ab65e915060200160405180910390a25050506115336001600055565b565b61153d611e04565b611545611f05565b61154d611f20565b61155633612062565b336000908152601c6020908152604080832054601490925282205461157b9190612d80565b9050600081116115cd5760405162461bcd60e51b815260206004820152601d60248201527f474458656e3a206163636f756e7420686173206e6f20726577617264730000006044820152606401610af2565b60646115d833611814565b10156115f65760405162461bcd60e51b8152600401610af290612dff565b3360009081526014602052604081208054839290611615908490612d80565b9091555050600c54600a54036116425780600d60008282546116379190612d93565b909155506116729050565b60095460009081526017602052604090205461165f908290612d80565b6009546000908152601760205260409020555b6001546001600160a01b0316639a49090e336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b1580156116cc57600080fd5b505af11580156116e0573d6000803e3d6000fd5b505050506116eb3390565b6001600160a01b03166009547f3300bdb359cfb956935bca32e9db727413eab1ca84341f2e36caea85bb7969688360405161172891815260200190565b60405180910390a3506115336001600055565b6004546001600160a01b031633146117955760405162461bcd60e51b815260206004820152601e60248201527f474458656e3a20696c6c6567616c2063616c6c6261636b2063616c6c657200006044820152606401610af2565b61179d611f05565b6117a5611f20565b6117ad61272d565b6117b682612062565b6009546001600160a01b038316600081815260136020526040908190209290925590517fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5906118089084815260200190565b60405180910390a25050565b336000908152601f6020526040812054819061182e611cde565b6118389190612d80565b905080158061185f57506001600160a01b038316600090815260208052604090205460ff16155b1561186d5750606492915050565b6000607482111561187f579392505050565b600061188c600184612f1a565b611897906002612d0f565b905060006118a6601e83612dbc565b905060006118b5601e84612f26565b9050811561197d576118c8816064612f1a565b620186a06118d7836066612f1a565b6118e19190612d0f565b6118eb9190612dbc565b82789f4f2726179a224501d762422c946590d91000000000000000620186a0611916601e6066612f3a565b6119209190612d0f565b61192a9190612dbc565b6119349190612f1a565b61193e9190612d0f565b611949836002612d93565b61195690620186a0612f1a565b611961906001612d0f565b61196b9190612dbc565b611976906064612d0f565b93506119dc565b611988816064612f1a565b620186a0611997836066612f1a565b6119a19190612d0f565b6119ab9190612dbc565b6119b96002620186a0612f3a565b6119c4906001612d0f565b6119ce9190612dbc565b6119d9906064612d0f565b93505b6119e9620186a085612dbc565b979650505050505050565b6000806119ff611cde565b90506000606b90506000606485600260009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a839190612f49565b611a8e90600a612f3a565b611acc611ac4611a9d87612889565b611abb611ab3611aae8b6001612d93565b612889565b600f0b6128a7565b600f0b9061298b565b600f0b6129dd565b67ffffffffffffffff16611ae09190612d0f565b611aea9190612d0f565b611af49190612dbc565b95945050505050565b611b05611e04565b611b0d611f05565b611b15611f20565b611b1e33612062565b60008111611b3e5760405162461bcd60e51b8152600401610af290612dd0565b33600090815260208052604090205460ff16611b86573360009081526020805260409020805460ff19166001179055611b75611cde565b336000908152601f60205260409020555b8060086000828254611b989190612d93565b9091555050600954600090611bae906001612d93565b9050600c54600a5403611bcc57600a54611bc9906001612d93565b90505b336000908152601d60205260409020548114801590611bfa5750336000908152601e60205260409020548114155b15611c5557336000908152601d60205260408120549003611c2c57336000908152601d60205260409020819055611c55565b336000908152601e60205260408120549003611c5557336000908152601e602052604090208190555b336000908152601b6020908152604080832084845290915281208054849290611c7f908490612d93565b9091555050600154611c9c906001600160a01b03163330856126ef565b604051828152339082907f18dcd430020e4d4899772fd94a8b40451dc5044dfb70bc46b532eeae431c864f9060200160405180910390a3506112e06001600055565b60007f0000000000000000000000000000000000000000000000000000000000015180611d2b7f0000000000000000000000000000000000000000000000000000000065536f6742612d80565b611d359190612dbc565b905090565b611d42611e04565b611d4a611f05565b611d52611f20565b611d5b33612062565b6064611d6633611814565b1015611d845760405162461bcd60e51b8152600401610af290612dff565b3360009081526015602052604090205480611db15760405162461bcd60e51b8152600401610af290612dd0565b33600081815260156020526040812055611dcb9082611e5d565b33611dd4611cde565b6040518381527f2227733fc4c8a9034cb58087dcf6995128b9c0233b038b03366aaf30c92b92d690602001611728565b600260005403611e565760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610af2565b6002600055565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611eaa576040519150601f19603f3d011682016040523d82523d6000602084013e611eaf565b606091505b5050905080611f005760405162461bcd60e51b815260206004820152601c60248201527f474458656e3a206661696c656420746f2073656e6420616d6f756e74000000006044820152606401610af2565b505050565b6000611f0f611cde565b90506009548111156112e057600955565b600c5460095414611f4357600a54611f39906001612d93565b600b55600c54600a555b600a54600954118015611f775750601a6000600a546001611f649190612d93565b8152602001908152602001600020546000145b1561153357600a5460009081526017602052604081205415611fed57600a54600090815260176020908152604080832054600e5460199093529220546b1d6329f1c35ca4bfabb9f56160281b91611fcd91612d93565b611fd79190612d0f565b611fe19190612dbc565b6000600e55905061201e565b60196000600a54815260200190815260200160002054600e60008282546120149190612d93565b9091555060009150505b600b546000908152601a602052604090205461203b908290612d93565b601a6000600a54600161204e9190612d93565b815260208101919091526040016000205550565b6001600160a01b0381166000908152601360205260409020546009541180156120a257506001600160a01b03811660009081526010602052604090205415155b15612145576001600160a01b0381166000818152601360209081526040808320548352601182528083205460168352818420549484526010909252822054919290916120ee9190612d0f565b6120f89190612dbc565b6001600160a01b038316600090815260146020526040812080549293508392909190612125908490612d93565b9091555050506001600160a01b0381166000908152601060205260408120555b600a5460095411801561217d5750600a54612161906001612d93565b6001600160a01b03821660009081526018602052604090205414155b15612276576001600160a01b0381166000908152601860209081526040808320548352601a91829052822054600a546b1d6329f1c35ca4bfabb9f56160281b93919291906121cc906001612d93565b8152602001908152602001600020546121e59190612d80565b6001600160a01b0383166000908152601460205260409020546122089190612d0f565b6122129190612dbc565b6001600160a01b0382166000908152601560205260409020546122359190612d93565b6001600160a01b038216600090815260156020526040902055600a5461225c906001612d93565b6001600160a01b0382166000908152601860205260409020555b6001600160a01b0381166000908152601d6020526040902054158015906122b657506001600160a01b0381166000908152601d6020526040902054600954115b156112e0576001600160a01b0381166000818152601b60209081526040808320601d8352818420548452825280832054938352601490915281208054839290612300908490612d93565b90915550506001600160a01b0382166000908152601c60205260408120805483929061232d908490612d93565b90915550506001600160a01b0382166000908152601d6020526040902054600a54612359906001612d93565b111561243e576001600160a01b0382166000908152601d60209081526040808320548352601a91829052822054600a546b1d6329f1c35ca4bfabb9f56160281b93919291906123a9906001612d93565b8152602001908152602001600020546123c29190612d80565b6001600160a01b0384166000908152601b60209081526040808320601d83528184205484529091529020546123f79190612d0f565b6124019190612dbc565b6001600160a01b0383166000908152601560205260409020546124249190612d93565b6001600160a01b0383166000908152601560205260409020555b6001600160a01b0382166000818152601b60209081526040808320601d83528184208054855290835281842084905593835292829055601e905220541561110c576001600160a01b0382166000908152601e6020526040902054600954111561265e576001600160a01b0382166000818152601b60209081526040808320601e83528184205484528252808320549383526014909152812080548392906124e6908490612d93565b90915550506001600160a01b0383166000908152601c602052604081208054839290612513908490612d93565b90915550506001600160a01b0383166000908152601e6020526040902054600a5461253f906001612d93565b1115612624576001600160a01b0383166000908152601e60209081526040808320548352601a91829052822054600a546b1d6329f1c35ca4bfabb9f56160281b939192919061258f906001612d93565b8152602001908152602001600020546125a89190612d80565b6001600160a01b0385166000908152601b60209081526040808320601e83528184205484529091529020546125dd9190612d0f565b6125e79190612dbc565b6001600160a01b03841660009081526015602052604090205461260a9190612d93565b6001600160a01b0384166000908152601560205260409020555b50506001600160a01b03166000818152601b60209081526040808320601e8084528285208054865291845291842084905593835290529055565b506001600160a01b03166000908152601e602081815260408084208054601d84529185209190915591905255565b6040516001600160a01b038316602482015260448101829052611f0090849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526129f9565b6040516001600160a01b03808516602483015283166044820152606481018290526127279085906323b872dd60e01b906084016126b8565b50505050565b6009546000908152601660205260408120549003611533576006546007819055600090614e709061276090614e20612d0f565b61276a9190612dbc565b60068190556009805460009081526016602090815260408083208590559254600c55600a5482526017905220549091506127a5908290612d93565b600c54600090815260176020526040812080549091906127c6908490612d93565b90915550506008541561280257600854600c54600090815260176020526040812080549091906127f7908490612d93565b909155505060006008555b600d541561283957600d54600c546000908152601760205260408120805490919061282e908490612d80565b90915550506000600d555b600954600c54600090815260176020908152604091829020548251858152918201527f0666a61c1092f5b86c2cfe6ea1ad0d9a36032c4fb92d285b4e43f662d48f19b4910160405180910390a250565b6000677fffffffffffffff8211156128a057600080fd5b5060401b90565b60008082600f0b136128b857600080fd5b6000600f83900b6801000000000000000081126128d7576040918201911d5b64010000000081126128eb576020918201911d5b6201000081126128fd576010918201911d5b610100811261290e576008918201911d5b6010811261291e576004918201911d5b6004811261292e576002918201911d5b6002811261293d576001820191505b603f19820160401b600f85900b607f8490031b6780000000000000005b60008113156129805790800260ff81901c8281029390930192607f011c9060011d61295a565b509095945050505050565b6000600f83810b9083900b0260401d6f7fffffffffffffffffffffffffffffff1981128015906129cb57506f7fffffffffffffffffffffffffffffff8113155b6129d457600080fd5b90505b92915050565b60008082600f0b12156129ef57600080fd5b50600f0b60401d90565b6000612a4e826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612ace9092919063ffffffff16565b9050805160001480612a6f575080806020019051810190612a6f9190612f6c565b611f005760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610af2565b6060612add8484600085612ae5565b949350505050565b606082471015612b465760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610af2565b600080866001600160a01b03168587604051612b629190612fb2565b60006040518083038185875af1925050503d8060008114612b9f576040519150601f19603f3d011682016040523d82523d6000602084013e612ba4565b606091505b50915091506119e98783838760608315612c1f578251600003612c18576001600160a01b0385163b612c185760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610af2565b5081612add565b612add8383815115612c345781518083602001fd5b8060405162461bcd60e51b8152600401610af29190612fce565b600060208284031215612c6057600080fd5b81356001600160e01b0319811681146129d457600080fd5b600060208284031215612c8a57600080fd5b5035919050565b80356001600160a01b0381168114612ca857600080fd5b919050565b600060208284031215612cbf57600080fd5b612cc882612c91565b9392505050565b60008060408385031215612ce257600080fd5b612ceb83612c91565b946020939093013593505050565b634e487b7160e01b600052601160045260246000fd5b80820281158282048414176129d7576129d7612cf9565b600060208284031215612d3857600080fd5b5051919050565b60208082526021908201527f474458656e3a206e6f7420656e6f75676820746f6b656e7320666f72206275726040820152603760f91b606082015260800190565b818103818111156129d7576129d7612cf9565b808201808211156129d7576129d7612cf9565b634e487b7160e01b600052601260045260246000fd5b600082612dcb57612dcb612da6565b500490565b602080825260159082015274474458656e3a20616d6f756e74206973207a65726f60581b604082015260600190565b6020808252601b908201527f474458656e3a206865616c7468206c657373207468616e203130300000000000604082015260600190565b600181815b80851115612e71578160001904821115612e5757612e57612cf9565b80851615612e6457918102915b93841c9390800290612e3b565b509250929050565b600082612e88575060016129d7565b81612e95575060006129d7565b8160018114612eab5760028114612eb557612ed1565b60019150506129d7565b60ff841115612ec657612ec6612cf9565b50506001821b6129d7565b5060208310610133831016604e8410600b8410161715612ef4575081810a6129d7565b612efe8383612e36565b8060001904821115612f1257612f12612cf9565b029392505050565b6000612cc88383612e79565b600082612f3557612f35612da6565b500690565b6000612cc860ff841683612e79565b600060208284031215612f5b57600080fd5b815160ff811681146129d457600080fd5b600060208284031215612f7e57600080fd5b815180151581146129d457600080fd5b60005b83811015612fa9578181015183820152602001612f91565b50506000910152565b60008251612fc4818460208701612f8e565b9190910192915050565b6020815260008251806020840152612fed816040850160208701612f8e565b601f01601f1916919091016040019291505056fea2646970667358221220e6756f0ee76b2baa66bec990aafe96fc4d3ab24180834e87fa32505b84bebc9f64736f6c63430008110033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000006450dee7fd2fb8e39061434babcfc05599a6fb800000000000000000000000078be30f2a60d63244425aa2466b90ca677d5aa770000000000000000000000009b38b7212083ead287c1fcdd0827d9648ff19a0e

-----Decoded View---------------
Arg [0] : xenAddress (address): 0x06450dEe7FD2Fb8E39061434BAbCFC05599a6Fb8
Arg [1] : xecTokenAddress (address): 0x78BE30F2a60d63244425AA2466B90CA677d5Aa77
Arg [2] : xecAddress (address): 0x9b38b7212083EAD287C1FCDD0827d9648fF19a0e

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 00000000000000000000000006450dee7fd2fb8e39061434babcfc05599a6fb8
Arg [1] : 00000000000000000000000078be30f2a60d63244425aa2466b90ca677d5aa77
Arg [2] : 0000000000000000000000009b38b7212083ead287c1fcdd0827d9648ff19a0e


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
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.