ETH Price: $2,693.79 (-0.73%)

Contract

0x594EBeD1E29319e22614b07C026c72EAD946A22b
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
IkaniV2_1Staking

Compiler Version
v0.8.9+commit.e5eed63a

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 26 : IkaniV2_1Staking.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { IS2_1Admin } from "./impl/IS2_1Admin.sol";
import { IS2Core } from "../v2/impl/IS2Core.sol";
import { IS2_1Erc20 } from "./impl/IS2_1Erc20.sol";
import { IS2Getters } from "../v2/impl/IS2Getters.sol";
import { IS2Storage } from "../v2/impl/IS2Storage.sol";
import { MinHeap } from "../v2/lib/MinHeap.sol";

/**
 * @title IkaniV2_1Staking
 * @author Cyborg Labs, LLC
 *
 * @dev Implements ERC-721 in-place staking with rewards.
 *
 *  Rewards are earned at a configurable base rate per staked NFT, with four bonus multipliers:
 *
 *    - Account-level (i.e. owner-level) bonuses:
 *      - Number of unique staked fabric traits
 *      - Number of unique staked season traits
 *
 *    - Token-level bonuses:
 *      - Foil trait
 *      - Staked duration checkpoints
 */
contract IkaniV2_1Staking is
    IS2_1Admin,
    IS2Getters
{
    //---------------- Constructor ----------------//

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor(
        address ikani,
        address rewardsErc20
    )
        IS2_1Erc20(rewardsErc20)
        IS2Storage(ikani)
    {
        _disableInitializers();
    }
}

File 2 of 26 : IS2_1Admin.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { IERC721Upgradeable } from "../../../deps/oz_cu_4_7_2/IERC721Upgradeable.sol";
import { SafeCastUpgradeable } from "../../../deps/oz_cu_4_7_2/SafeCastUpgradeable.sol";

import { IIkaniERC20 } from "../../../erc20/interfaces/IIkaniERC20.sol";
import { IS2_1Core } from "./IS2_1Core.sol";
import { IS2Roles } from "../../v2/impl/IS2Roles.sol";

/**
 * @title IS2_1Admin
 * @author Cyborg Labs, LLC
 *
 *  Role-restricted functions.
 */
abstract contract IS2_1Admin is
    IS2_1Core,
    IS2Roles
{
    using SafeCastUpgradeable for uint256;

    //---------------- External Functions ----------------//

    function pause()
        external
        onlyRole(PAUSER_ROLE)
    {
        _pause();
    }

    function unpause()
        external
        onlyRole(UNPAUSER_ROLE)
    {
        _unpause();
    }

    function setBaseRate(
        uint32 baseRate
    )
        external
        onlyRole(BASE_RATE_CONTROLLER_ROLE)
    {
        _setBaseRate(baseRate);
    }

    function adminUnstake(
        address owner,
        uint256[] calldata tokenIds,
        bytes32 receipt,
        bytes calldata receiptData
    )
        external
        onlyRole(UNSTAKE_CONTROLLER_ROLE)
        whenNotPaused
    {
        // Verify owner.
        _requireSameOwnerAndAuthorized(owner, tokenIds, true);

        // Get the updated rewards context and new rewards.
        (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

        // Unstake the tokens.
        context = _unstake(context, owner, tokenIds);

        // Update storage for the account.
        _SETTLEMENT_CONTEXT_[owner] = context;
        _REWARDS_[owner] += rewardsDiff;

        emit AdminUnstaked(owner, tokenIds, receipt, receiptData);
    }

    function adminUnstake2(
        uint256[] calldata tokenIds,
        bytes32 receipt,
        bytes[] calldata receiptData
    )
        external
        onlyRole(UNSTAKE_CONTROLLER_ROLE)
        whenNotPaused
    {
        uint256 n = tokenIds.length;

        for (uint256 i = 0; i < n;) {
            uint256 tokenId = tokenIds[i];
            bytes calldata innerReceiptData = receiptData[i];

            // Get owner.
            address owner = IERC721Upgradeable(IKANI).ownerOf(tokenId);

            // Get the updated rewards context and new rewards.
            (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

            // Unstake the token.
            uint256[] memory innerTokenIds = new uint256[](1);
            innerTokenIds[0] = tokenId;
            context = _unstake(context, owner, innerTokenIds);

            // Update storage for the account.
            _SETTLEMENT_CONTEXT_[owner] = context;
            _REWARDS_[owner] += rewardsDiff;

            emit AdminUnstaked(owner, innerTokenIds, receipt, innerReceiptData);

            unchecked { ++i; }
        }
    }

    function adminClaimRewards(
        address owner
    )
        external
        onlyRole(CLAIM_CONTROLLER_ROLE)
        whenNotPaused
    {
        _claimRewards(owner, owner);
    }

    function adminClaimRewardsAndBurnWithPermit(
        address owner,
        uint256 burnAmount,
        bytes32 burnReceipt,
        bytes calldata burnReceiptData,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s

    )
        external
        onlyRole(CLAIM_CONTROLLER_ROLE)
        onlyRole(BURN_CONTROLLER_ROLE)
        whenNotPaused
    {
        _claimRewards(owner, owner);
        _burnErc20(owner, burnAmount, burnReceipt, burnReceiptData, deadline, v, r, s);
    }

    //---------------- Internal Functions ----------------//

    function _setBaseRate(
        uint32 baseRate
    )
        internal
    {
        // The base rate at index zero is always zero.
        // The first configured base rate is at index one.
        unchecked {
            _RATE_CHANGES_[++_NUM_RATE_CHANGES_] = RateChange({
                baseRate: baseRate,
                timestamp: block.timestamp.toUint32()
            });
        }

        emit SetBaseRate(baseRate);
    }
}

File 3 of 26 : IS2Core.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { AddressUpgradeable } from "../../../deps/oz_cu_4_7_2/AddressUpgradeable.sol";
import { IERC721Upgradeable } from "../../../deps/oz_cu_4_7_2/IERC721Upgradeable.sol";
import { SafeCastUpgradeable } from "../../../deps/oz_cu_4_7_2/SafeCastUpgradeable.sol";

import { IIkaniV2 } from "../../../nft/v2/interfaces/IIkaniV2.sol";

import { IS2Lib } from "../lib/IS2Lib.sol";
import { MinHeap } from "../lib/MinHeap.sol";
import { IS2Erc20 } from "./IS2Erc20.sol";

/**
 * @title IS2Core
 * @author Cyborg Labs, LLC
 */
abstract contract IS2Core is
    IS2Erc20
{
    using SafeCastUpgradeable for uint256;

    //---------------- External Functions ----------------//

    /**
     * @notice Stake one or more tokens owned by a single owner.
     *
     *  Will revert if any of the tokens are already staked.
     *  Will revert if the same token is included more than once.
     */
    function stake(
        address owner,
        uint256[] calldata tokenIds
    )
        external
        whenNotPaused
    {
        // Verify owner and authorization.
        _requireSameOwnerAndAuthorized(owner, tokenIds, false);

        // Get the updated rewards context and new rewards.
        (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

        // Stake the tokens.
        context = _stake(context, owner, tokenIds, new uint256[](0));

        // Update storage for the account.
        _SETTLEMENT_CONTEXT_[owner] = context;
        if (rewardsDiff != 0) {
            _REWARDS_[owner] += rewardsDiff;
        }
    }

    function unstake(
        address owner,
        uint256[] calldata tokenIds
    )
        external
        whenNotPaused
    {
        // Verify owner and authorization.
        _requireSameOwnerAndAuthorized(owner, tokenIds, false);

        // Get the updated rewards context and new rewards.
        (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

        // Unstake the tokens.
        context = _unstake(context, owner, tokenIds);

        // Update storage for the account.
        _SETTLEMENT_CONTEXT_[owner] = context;
        _REWARDS_[owner] += rewardsDiff;
    }

    function batchSafeTransferFromStaked(
        address owner,
        address recipient,
        uint256[] calldata tokenIds
    )
        external
        whenNotPaused
    {
        require(
            msg.sender == owner,
            "Only owner can transfer staked"
        );

        // Verify owner.
        _requireSameOwnerAndAuthorized(owner, tokenIds, true);

        // Get the updated rewards context and new rewards.
        (
            SettlementContext memory ownerContext,
            uint256 ownerRewardsDiff
        ) = _settleAccount(owner);
        (
            SettlementContext memory recipientContext,
            uint256 recipientRewardsDiff
        ) = _settleAccount(recipient);

        // Get the staked timestamps.
        uint256 n = tokenIds.length;
        uint256[] memory stakedTimestamps = new uint256[](n);
        for (uint256 i = 0; i < n;) {
            stakedTimestamps[i] = _TOKEN_STAKING_STATE_[tokenIds[i]].timestamp;
            unchecked { ++i; }
        }

        // Unstake and restake the tokens.
        ownerContext = _unstake(ownerContext, owner, tokenIds);
        recipientContext = _stake(recipientContext, recipient, tokenIds, stakedTimestamps);

        // Update storage for the accounts.
        _SETTLEMENT_CONTEXT_[owner] = ownerContext;
        _REWARDS_[owner] += ownerRewardsDiff;
        _SETTLEMENT_CONTEXT_[recipient] = recipientContext;
        _REWARDS_[recipient] += recipientRewardsDiff;

        // Do transfers last, since a “safe” transfer can execute arbitrary smart contract code.
        // This is important to prevent reentrancy attacks.
        for (uint256 i = 0; i < n;) {
            IERC721Upgradeable(IKANI).safeTransferFrom(owner, recipient, tokenIds[i]);
            unchecked { ++i; }
        }
    }

    /**
     * @notice Claim all rewards for the account.
     *
     *  This function can be called with eth_call (e.g. callStatic in ethers.js) to get the
     *  current unclaimed rewards balance for an account.
     */
    function claimRewards(
        address owner,
        address recipient
    )
        external
        whenNotPaused
        returns (uint256)
    {
        require(
            msg.sender == owner,
            "Sender is not owner"
        );
        return _claimRewards(owner, recipient);
    }

    function claimAndBurnRewards(
        address owner,
        uint256 burnAmount,
        bytes32 burnReceipt,
        bytes calldata burnReceiptData,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    )
        external
        whenNotPaused
    {
        require(
            msg.sender == owner,
            "Sender is not owner"
        );
        _claimRewards(owner, owner);
        _burnErc20(owner, burnAmount, burnReceipt, burnReceiptData, deadline, v, r, s);
    }

    /**
     * @notice Settle rewards for an account.
     *
     *  Note: There is no access control on this function.
     */
    function settleRewards(
        address owner
    )
        external
        whenNotPaused
        returns (uint256)
    {
        return _settleRewards(owner);
    }

    //---------------- Internal Functions ----------------//

    function _settleRewards(
        address owner
    )
        internal
        returns (uint256)
    {
        uint256 rewardsOld = _REWARDS_[owner];

        // Get the updated rewards context and new rewards.
        (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

        uint256 rewardsNew = rewardsOld + rewardsDiff;

        // Update storage.
        _SETTLEMENT_CONTEXT_[owner] = context;
        _REWARDS_[owner] = rewardsNew;

        return _getErc20Amount(rewardsNew);
    }

    function _claimRewards(
        address owner,
        address recipient
    )
        internal
        returns (uint256)
    {
        uint256 rewardsOld = _REWARDS_[owner];

        // Get the updated rewards context and new rewards.
        (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

        // Update storage.
        _SETTLEMENT_CONTEXT_[owner] = context;
        _REWARDS_[owner] = 0;

        // Mint the rewards amount.
        uint256 rewardsNew = rewardsOld + rewardsDiff;
        uint256 erc20Amount = _issueRewards(recipient, rewardsNew);

        emit ClaimedRewards(owner, erc20Amount);

        return erc20Amount;
    }

    function _stake(
        SettlementContext memory initialContext,
        address owner,
        uint256[] calldata tokenIds,
        uint256[] memory maybeStakingStartTimestamps
    )
        internal
        returns (SettlementContext memory context)
    {
        context = initialContext;
        uint256 n = tokenIds.length;

        for (uint256 i = 0; i < n;) {
            uint256 tokenId = tokenIds[i];

            // Get the current staking state for the token.
            TokenStakingState memory stakingState = _TOKEN_STAKING_STATE_[tokenId];

            // Require that the token is not currently staked.
            // Note that this will revert if the same token appeared twice in the list.
            require(
                stakingState.timestamp == 0,
                "Already staked"
            );

            // The timestamp to use as the staking start timestamp for the token.
            uint256 stakingStartTimestamp = maybeStakingStartTimestamps.length > 0
                ? maybeStakingStartTimestamps[i]
                : block.timestamp;

            Checkpoint memory checkpoint;
            (context, checkpoint) = IS2Lib.stakeLogic(
                context,
                IIkaniV2(IKANI).getPoemTraits(tokenId),
                stakingStartTimestamp,
                stakingState.nonce,
                tokenId
            );

            // Update storage for the token.
            if (checkpoint.timestamp != 0) {
                IS2Lib._insertCheckpoint(_CHECKPOINTS_[owner], checkpoint);
            }
            _TOKEN_STAKING_STATE_[tokenId].timestamp = stakingStartTimestamp.toUint32();

            emit Staked(owner, tokenId, stakingStartTimestamp);

            unchecked { ++i; }
        }
    }

    function _unstake(
        SettlementContext memory initialContext,
        address owner,
        uint256[] calldata tokenIds
    )
        internal
        returns (SettlementContext memory context)
    {
        context = initialContext;
        uint256 n = tokenIds.length;

        for (uint256 i = 0; i < n;) {
            uint256 tokenId = tokenIds[i];

            // Get the current staking state for the token.
            TokenStakingState memory stakingState = _TOKEN_STAKING_STATE_[tokenId];

            // Require that the token is currently staked.
            // Note that this will revert if the same token appeared twice in the list.
            require(
                stakingState.timestamp != 0,
                "Not staked"
            );

            context = IS2Lib.unstakeLogic(
                context,
                IIkaniV2(IKANI).getPoemTraits(tokenId),
                stakingState.timestamp
            );

            // Update storage for the token.
            unchecked {
                _TOKEN_STAKING_STATE_[tokenId] = TokenStakingState({
                    timestamp: 0,
                    nonce: stakingState.nonce + 1
                });
            }

            emit Unstaked(owner, tokenId);

            unchecked { ++i; }
        }
    }

    function _requireSameOwnerAndAuthorized(
        address owner,
        uint256[] calldata tokenIds,
        bool alreadyAuthorized
    )
        internal
        view
    {
        address sender = msg.sender;
        bool senderIsOwner = sender == owner;
        uint256 n = tokenIds.length;

        // Verify owner and authorization.
        for (uint256 i = 0; i < n;) {
            uint256 tokenId = tokenIds[i];

            require(
                IERC721Upgradeable(IKANI).ownerOf(tokenId) == owner,
                "Wrong owner"
            );
            require(
                alreadyAuthorized || senderIsOwner || _isApproved(sender, owner, tokenId),
                "Not authorized to stake/unstake"
            );

            unchecked { ++i; }
        }
    }

    function _settleAccount(
        address owner
    )
        internal
        returns (
            SettlementContext memory context,
            uint256 rewardsDiff
        )
    {
        (context, rewardsDiff) = IS2Lib.settleAccountAndGetOwedRewards(
            _SETTLEMENT_CONTEXT_[owner],
            _RATE_CHANGES_,
            _CHECKPOINTS_[owner],
            _TOKEN_STAKING_STATE_,
            _NUM_RATE_CHANGES_
        );
    }

    function _isApproved(
        address spender,
        address owner,
        uint256 tokenId
    )
        internal
        view
        returns (bool)
    {
        return (
            IERC721Upgradeable(IKANI).isApprovedForAll(owner, spender) ||
            IERC721Upgradeable(IKANI).getApproved(tokenId) == spender
        );
    }
}

File 4 of 26 : IS2_1Erc20.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { IERC20 } from "../../../deps/oz_c_4_7_2/IERC20.sol";

import { IIkaniERC20 } from "../../../erc20/interfaces/IIkaniERC20.sol";

import { IS2Storage } from "../../v2/impl/IS2Storage.sol";

/**
 * @title IS2_1Erc20
 * @author Cyborg Labs, LLC
 *
 * @notice Handles interactions with the ERC20 token.
 */
abstract contract IS2_1Erc20 is
    IS2Storage
{
    //---------------- Constants ----------------//

    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address public immutable REWARDS_ERC20;

    uint256 private constant REWARDS_CONVERSION_FACTOR = 1e6;

    //---------------- Constructor ----------------//

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor(
        address rewardsErc20
    ) {
        REWARDS_ERC20 = rewardsErc20;
    }

    //---------------- Internal Functions ----------------//

    function _issueRewards(
        address recipient,
        uint256 rewardsAmount
    )
        internal
        returns (uint256)
    {
        uint256 erc20Amount = _getErc20Amount(rewardsAmount);
        // Note: Not using SafeERC20, to save a bit of gas, since this is our own token.
        IERC20(REWARDS_ERC20).transfer(
            recipient,
            erc20Amount
        );
        return erc20Amount;
    }

    function _burnErc20(
        address owner,
        uint256 burnAmount,
        bytes32 burnReceipt,
        bytes calldata burnReceiptData,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    )
        internal
    {
        IIkaniERC20(REWARDS_ERC20).burnWithPermit(
            owner,
            burnAmount,
            burnReceipt,
            burnReceiptData,
            deadline,
            v,
            r,
            s
        );
    }

    function _getErc20Amount(
        uint256 rewardsAmount
    )
        internal
        pure
        returns (uint256)
    {
        return rewardsAmount * REWARDS_CONVERSION_FACTOR;
    }
}

File 5 of 26 : IS2Getters.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { IIkaniV2 } from "../../../nft/v2/interfaces/IIkaniV2.sol";
import { IS2Lib } from "../lib/IS2Lib.sol";
import { IS2Storage } from "./IS2Storage.sol";

/**
 * @title IS2Getters
 * @author Cyborg Labs, LLC
 *
 * @dev Simple getter functions that are only needed externally.
 */
abstract contract IS2Getters is
    IS2Storage
{
    //---------------- Constants ----------------//

    /// @dev Must match the value in IS2Lib.sol.
    uint256 public constant MULTIPLIER_BASE = 1e6;

    //---------------- External Functions ----------------//

    function isStaked(
        uint256 tokenId
    )
        external
        view
        override
        returns (bool)
    {
        return _TOKEN_STAKING_STATE_[tokenId].timestamp != 0;
    }

    function getStakedTimestamp(
        uint256 tokenId
    )
        external
        view
        returns (uint256)
    {
        return _TOKEN_STAKING_STATE_[tokenId].timestamp;
    }

    function getHistoricalBaseRate(
        uint256 i
    )
        external
        view
        returns (RateChange memory)
    {
        require(
            i <= _NUM_RATE_CHANGES_,
            "Invalid base rate index"
        );
        return _RATE_CHANGES_[i];
    }

    function getNumBaseRateChanges()
        external
        view
        returns (uint256)
    {
        return _NUM_RATE_CHANGES_;
    }

    function getAccountRewardsMultiplier(
        address account
    )
        external
        view
        returns (uint256)
    {
        return IS2Lib.getAccountRewardsMultiplier(_SETTLEMENT_CONTEXT_[account]);
    }

    function getFabricsRewardsMultiplier(
        address account
    )
        external
        view
        returns (uint256)
    {
        return IS2Lib.getFabricsRewardsMultiplier(_SETTLEMENT_CONTEXT_[account]);
    }

    function getSeasonsRewardsMultiplier(
        address account
    )
        external
        view
        returns (uint256)
    {
        return IS2Lib.getSeasonsRewardsMultiplier(_SETTLEMENT_CONTEXT_[account]);
    }

    function getNumFabricsStaked(
        address account
    )
        external
        view
        returns (uint256)
    {
        return IS2Lib.getNumFabricsStaked(_SETTLEMENT_CONTEXT_[account]);
    }

    function getNumSeasonsStaked(
        address account
    )
        external
        view
        returns (uint256)
    {
        return IS2Lib.getNumSeasonsStaked(_SETTLEMENT_CONTEXT_[account]);
    }

    /**
     * @notice Get the token rewards rate for a token.
     */
    function getTokenRewardsRate(
        uint256 tokenId
    )
        external
        view
        returns (uint256)
    {
        return (
            getBaseRate() *
            getDurationRewardsMultiplier(tokenId) *
            getFoilRewardsMultiplier(tokenId) /
            (MULTIPLIER_BASE * MULTIPLIER_BASE)
        );
    }

    /**
     * @notice Get the staked duration level for a token.
     */
    function getDurationLevel(
        uint256 tokenId
    )
        external
        view
        returns (uint256)
    {
        uint256 stakedTimestamp = _TOKEN_STAKING_STATE_[tokenId].timestamp;
        uint256 stakedDuration = block.timestamp - stakedTimestamp;
        return IS2Lib.getLevelForStakedDuration(stakedDuration);
    }

    //---------------- Public Functions ----------------//

    function getBaseRate()
        public
        view
        returns (uint256)
    {
        return _RATE_CHANGES_[_NUM_RATE_CHANGES_].baseRate;
    }

    function getDurationRewardsMultiplier(
        uint256 tokenId
    )
        public
        view
        returns (uint256)
    {
        uint256 stakedTimestamp = _TOKEN_STAKING_STATE_[tokenId].timestamp;

        // If the token is not staked, return multipler of 1.
        if (stakedTimestamp == 0) {
            return MULTIPLIER_BASE;
        }

        uint256 stakedDuration = block.timestamp - stakedTimestamp;
        return IS2Lib.getStakedDurationRewardsMultiplier(stakedDuration);
    }

    function getFoilRewardsMultiplier(
        uint256 tokenId
    )
        public
        view
        returns (uint256)
    {
        IIkaniV2.PoemTraits memory traits = IIkaniV2(IKANI).getPoemTraits(tokenId);
        return IS2Lib.getFoilRewardsMultiplier(traits);
    }
}

File 6 of 26 : IS2Storage.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { AccessControlUpgradeable } from "../../../deps/oz_cu_4_7_2/AccessControlUpgradeable.sol";
import { PausableUpgradeable } from "../../../deps/oz_cu_4_7_2/PausableUpgradeable.sol";

import { IIkaniV2Staking } from "../interfaces/IIkaniV2Staking.sol";
import { MinHeap } from "../lib/MinHeap.sol";

/**
 * @title IS2Storage
 * @author Cyborg Labs, LLC
 */
abstract contract IS2Storage is
    AccessControlUpgradeable,
    PausableUpgradeable,
    IIkaniV2Staking
{
    //---------------- Constants ----------------//

    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address public immutable IKANI;

    //---------------- Constructor ----------------//

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor(
        address ikani
    ) {
        IKANI = ikani;
    }

    //---------------- Storage ----------------//

    /// @dev Storage gap to allow for flexibility in contract upgrades.
    uint256[1_000_000] private __gap;

    /// @dev Historical record of all changes to the global base rewards rate.
    ///
    ///  The base rate at index zero is always zero.
    ///  The first configured base rate is at index one.
    mapping(uint256 => RateChange) internal _RATE_CHANGES_;

    /// @dev The number of changes to the global base rewards rate.
    uint256 internal _NUM_RATE_CHANGES_;

    /// @dev The rewards state and settlement info for an account.
    mapping(address => SettlementContext) internal _SETTLEMENT_CONTEXT_;

    /// @dev The priority queue of unlockable duration-based bonus points for an account.
    ///
    ///  These are encoded as IIkaniV2Staking.Checkpoint structs and ordered by timestamp.
    mapping(address => MinHeap.Heap) internal _CHECKPOINTS_;

    /// @dev The settled rewards held by an account.
    ///
    ///  Converts to an ERC-20 amount as specified in IS2Erc20.sol.
    mapping(address => uint256) internal _REWARDS_;

    /// @dev The staking state of a token, including the timestamp and nonce.
    ///
    ///  timestamp  The timestamp when the token was staked, if currently staked, otherwise zero.
    ///  nonce      The number of times the token has been unstaked.
    mapping(uint256 => TokenStakingState) internal _TOKEN_STAKING_STATE_;
}

File 7 of 26 : MinHeap.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

/**
 * @title IkaniV2Staking
 * @author Cyborg Labs, LLC
 *
 * @dev Priority queue implemented as a heap.
 */
library MinHeap {

    struct Heap {
        mapping(uint256 => uint256) data;
        uint256 length;
    }

    function insert(
        Heap storage _heap_,
        uint256 value
    )
        internal
    {
        unchecked {
            uint256 index = _heap_.length + 1;
            _heap_.length = index;

            while (index != 1) {
                uint256 parentIndex = index >> 1;
                uint256 parentValue = _heap_.data[parentIndex];
                if (parentValue <= value) {
                    break;
                }
                _heap_.data[index] = parentValue;
                index = parentIndex;
            }

            _heap_.data[index] = value;
        }
    }

    function unsafePeek(
        Heap storage _heap_
    )
        internal
        view
        returns (uint256)
    {
        return _heap_.data[1];
    }

    function safePeek(
        Heap storage _heap_
    )
        internal
        view
        returns (uint256)
    {
        require(
            _heap_.length != 0,
            "Heap is empty"
        );
        return _heap_.data[1];
    }

    function popMin(
        Heap storage _heap_
    )
        internal
    {
        unchecked {
            // We implicitly move the last value to the top of the heap, and heapify it down.
            uint256 oldLength = _heap_.length--;
            uint256 lastValue = _heap_.data[oldLength];

            if (oldLength == 1) {
                return;
            }

            uint256 index = 1;
            uint256 leftChildIndex = 2;
            uint256 rightChildIndex = 3;

            // While there is a left child...
            while (leftChildIndex < oldLength) {

                // Get the smaller of the left child and (if it exists) the right child.
                uint256 childIndex = leftChildIndex;
                uint256 childValue = _heap_.data[leftChildIndex];
                if (rightChildIndex < oldLength) {
                    uint256 rightChildValue = _heap_.data[rightChildIndex];
                    if (rightChildValue < childValue) {
                        childIndex = rightChildIndex;
                        childValue = rightChildValue;
                    }
                }

                // If the child value is smaller than our value, bring the child up.
                if (childValue < lastValue) {
                    _heap_.data[index] = childValue;
                    index = childIndex;
                } else {
                    break;
                }

                leftChildIndex = index << 1;
                rightChildIndex = leftChildIndex + 1;
            }

            _heap_.data[index] = lastValue;
        }
    }
}

File 8 of 26 : IERC721Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721Upgradeable is IERC165Upgradeable {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 9 of 26 : SafeCastUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/math/SafeCast.sol)

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCastUpgradeable {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248) {
        require(value >= type(int248).min && value <= type(int248).max, "SafeCast: value doesn't fit in 248 bits");
        return int248(value);
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240) {
        require(value >= type(int240).min && value <= type(int240).max, "SafeCast: value doesn't fit in 240 bits");
        return int240(value);
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232) {
        require(value >= type(int232).min && value <= type(int232).max, "SafeCast: value doesn't fit in 232 bits");
        return int232(value);
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224) {
        require(value >= type(int224).min && value <= type(int224).max, "SafeCast: value doesn't fit in 224 bits");
        return int224(value);
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216) {
        require(value >= type(int216).min && value <= type(int216).max, "SafeCast: value doesn't fit in 216 bits");
        return int216(value);
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208) {
        require(value >= type(int208).min && value <= type(int208).max, "SafeCast: value doesn't fit in 208 bits");
        return int208(value);
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200) {
        require(value >= type(int200).min && value <= type(int200).max, "SafeCast: value doesn't fit in 200 bits");
        return int200(value);
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192) {
        require(value >= type(int192).min && value <= type(int192).max, "SafeCast: value doesn't fit in 192 bits");
        return int192(value);
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184) {
        require(value >= type(int184).min && value <= type(int184).max, "SafeCast: value doesn't fit in 184 bits");
        return int184(value);
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176) {
        require(value >= type(int176).min && value <= type(int176).max, "SafeCast: value doesn't fit in 176 bits");
        return int176(value);
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168) {
        require(value >= type(int168).min && value <= type(int168).max, "SafeCast: value doesn't fit in 168 bits");
        return int168(value);
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160) {
        require(value >= type(int160).min && value <= type(int160).max, "SafeCast: value doesn't fit in 160 bits");
        return int160(value);
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152) {
        require(value >= type(int152).min && value <= type(int152).max, "SafeCast: value doesn't fit in 152 bits");
        return int152(value);
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144) {
        require(value >= type(int144).min && value <= type(int144).max, "SafeCast: value doesn't fit in 144 bits");
        return int144(value);
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136) {
        require(value >= type(int136).min && value <= type(int136).max, "SafeCast: value doesn't fit in 136 bits");
        return int136(value);
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128) {
        require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
        return int128(value);
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120) {
        require(value >= type(int120).min && value <= type(int120).max, "SafeCast: value doesn't fit in 120 bits");
        return int120(value);
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112) {
        require(value >= type(int112).min && value <= type(int112).max, "SafeCast: value doesn't fit in 112 bits");
        return int112(value);
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104) {
        require(value >= type(int104).min && value <= type(int104).max, "SafeCast: value doesn't fit in 104 bits");
        return int104(value);
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96) {
        require(value >= type(int96).min && value <= type(int96).max, "SafeCast: value doesn't fit in 96 bits");
        return int96(value);
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88) {
        require(value >= type(int88).min && value <= type(int88).max, "SafeCast: value doesn't fit in 88 bits");
        return int88(value);
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80) {
        require(value >= type(int80).min && value <= type(int80).max, "SafeCast: value doesn't fit in 80 bits");
        return int80(value);
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72) {
        require(value >= type(int72).min && value <= type(int72).max, "SafeCast: value doesn't fit in 72 bits");
        return int72(value);
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64) {
        require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
        return int64(value);
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56) {
        require(value >= type(int56).min && value <= type(int56).max, "SafeCast: value doesn't fit in 56 bits");
        return int56(value);
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48) {
        require(value >= type(int48).min && value <= type(int48).max, "SafeCast: value doesn't fit in 48 bits");
        return int48(value);
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40) {
        require(value >= type(int40).min && value <= type(int40).max, "SafeCast: value doesn't fit in 40 bits");
        return int40(value);
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32) {
        require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
        return int32(value);
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24) {
        require(value >= type(int24).min && value <= type(int24).max, "SafeCast: value doesn't fit in 24 bits");
        return int24(value);
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16) {
        require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
        return int16(value);
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8) {
        require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
        return int8(value);
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 10 of 26 : IIkaniERC20.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

interface IIkaniERC20 {

    //---------------- Events ----------------//

    event Minted(
        address indexed to,
        uint256 amount,
        bytes32 indexed receipt,
        bytes receiptData
    );

    event Burned(
        address indexed from,
        uint256 amount,
        bytes32 indexed receipt,
        bytes receiptData
    );

    //---------------- Functions ----------------//

    function mint(
        address to,
        uint256 amount,
        bytes32 receipt,
        bytes calldata receiptData
    )
        external;

    function burn(
        address from,
        uint256 amount,
        bytes32 receipt,
        bytes calldata receiptData
    )
        external;

    function burnWithPermit(
        address from,
        uint256 amount,
        bytes32 receipt,
        bytes calldata receiptData,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    )
        external;

    function burnFrom(
        address from,
        uint256 amount,
        bytes32 receipt,
        bytes calldata receiptData
    )
        external;
}

File 11 of 26 : IS2_1Core.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { AddressUpgradeable } from "../../../deps/oz_cu_4_7_2/AddressUpgradeable.sol";
import { IERC721Upgradeable } from "../../../deps/oz_cu_4_7_2/IERC721Upgradeable.sol";
import { SafeCastUpgradeable } from "../../../deps/oz_cu_4_7_2/SafeCastUpgradeable.sol";

import { IIkaniV2 } from "../../../nft/v2/interfaces/IIkaniV2.sol";

import { IS2Lib } from "../../v2/lib/IS2Lib.sol";
import { MinHeap } from "../../v2/lib/MinHeap.sol";
import { IS2_1Erc20 } from "./IS2_1Erc20.sol";

/**
 * @title IS2_1Core
 * @author Cyborg Labs, LLC
 */
abstract contract IS2_1Core is
    IS2_1Erc20
{
    using SafeCastUpgradeable for uint256;

    //---------------- External Functions ----------------//

    /**
     * @notice Stake one or more tokens owned by a single owner.
     *
     *  Will revert if any of the tokens are already staked.
     *  Will revert if the same token is included more than once.
     */
    function stake(
        address owner,
        uint256[] calldata tokenIds
    )
        external
        whenNotPaused
    {
        // Verify owner and authorization.
        _requireSameOwnerAndAuthorized(owner, tokenIds, false);

        // Get the updated rewards context and new rewards.
        (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

        // Stake the tokens.
        context = _stake(context, owner, tokenIds, new uint256[](0));

        // Update storage for the account.
        _SETTLEMENT_CONTEXT_[owner] = context;
        if (rewardsDiff != 0) {
            _REWARDS_[owner] += rewardsDiff;
        }
    }

    function unstake(
        address owner,
        uint256[] calldata tokenIds
    )
        external
        whenNotPaused
    {
        // Verify owner and authorization.
        _requireSameOwnerAndAuthorized(owner, tokenIds, false);

        // Get the updated rewards context and new rewards.
        (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

        // Unstake the tokens.
        context = _unstake(context, owner, tokenIds);

        // Update storage for the account.
        _SETTLEMENT_CONTEXT_[owner] = context;
        _REWARDS_[owner] += rewardsDiff;
    }

    function batchSafeTransferFromStaked(
        address owner,
        address recipient,
        uint256[] calldata tokenIds
    )
        external
        whenNotPaused
    {
        require(
            msg.sender == owner,
            "Only owner can transfer staked"
        );

        // Verify owner.
        _requireSameOwnerAndAuthorized(owner, tokenIds, true);

        // Get the updated rewards context and new rewards.
        (
            SettlementContext memory ownerContext,
            uint256 ownerRewardsDiff
        ) = _settleAccount(owner);
        (
            SettlementContext memory recipientContext,
            uint256 recipientRewardsDiff
        ) = _settleAccount(recipient);

        // Get the staked timestamps.
        uint256 n = tokenIds.length;
        uint256[] memory stakedTimestamps = new uint256[](n);
        for (uint256 i = 0; i < n;) {
            stakedTimestamps[i] = _TOKEN_STAKING_STATE_[tokenIds[i]].timestamp;
            unchecked { ++i; }
        }

        // Unstake and restake the tokens.
        ownerContext = _unstake(ownerContext, owner, tokenIds);
        recipientContext = _stake(recipientContext, recipient, tokenIds, stakedTimestamps);

        // Update storage for the accounts.
        _SETTLEMENT_CONTEXT_[owner] = ownerContext;
        _REWARDS_[owner] += ownerRewardsDiff;
        _SETTLEMENT_CONTEXT_[recipient] = recipientContext;
        _REWARDS_[recipient] += recipientRewardsDiff;

        // Do transfers last, since a “safe” transfer can execute arbitrary smart contract code.
        // This is important to prevent reentrancy attacks.
        for (uint256 i = 0; i < n;) {
            IERC721Upgradeable(IKANI).safeTransferFrom(owner, recipient, tokenIds[i]);
            unchecked { ++i; }
        }
    }

    /**
     * @notice Claim all rewards for the account.
     *
     *  This function can be called with eth_call (e.g. callStatic in ethers.js) to get the
     *  current unclaimed rewards balance for an account.
     */
    function claimRewards(
        address owner,
        address recipient
    )
        external
        whenNotPaused
        returns (uint256)
    {
        require(
            msg.sender == owner,
            "Sender is not owner"
        );
        return _claimRewards(owner, recipient);
    }

    function claimAndBurnRewards(
        address owner,
        uint256 burnAmount,
        bytes32 burnReceipt,
        bytes calldata burnReceiptData,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    )
        external
        whenNotPaused
    {
        require(
            msg.sender == owner,
            "Sender is not owner"
        );
        _claimRewards(owner, owner);
        _burnErc20(owner, burnAmount, burnReceipt, burnReceiptData, deadline, v, r, s);
    }

    /**
     * @notice Settle rewards for an account.
     *
     *  Note: There is no access control on this function.
     */
    function settleRewards(
        address owner
    )
        external
        whenNotPaused
        returns (uint256)
    {
        return _settleRewards(owner);
    }

    //---------------- Internal Functions ----------------//

    function _settleRewards(
        address owner
    )
        internal
        returns (uint256)
    {
        uint256 rewardsOld = _REWARDS_[owner];

        // Get the updated rewards context and new rewards.
        (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

        uint256 rewardsNew = rewardsOld + rewardsDiff;

        // Update storage.
        _SETTLEMENT_CONTEXT_[owner] = context;
        _REWARDS_[owner] = rewardsNew;

        return _getErc20Amount(rewardsNew);
    }

    function _claimRewards(
        address owner,
        address recipient
    )
        internal
        returns (uint256)
    {
        uint256 rewardsOld = _REWARDS_[owner];

        // Get the updated rewards context and new rewards.
        (SettlementContext memory context, uint256 rewardsDiff) = _settleAccount(owner);

        // Update storage.
        _SETTLEMENT_CONTEXT_[owner] = context;
        _REWARDS_[owner] = 0;

        // Mint the rewards amount.
        uint256 rewardsNew = rewardsOld + rewardsDiff;
        uint256 erc20Amount = _issueRewards(recipient, rewardsNew);

        emit ClaimedRewards(owner, erc20Amount);

        return erc20Amount;
    }

    function _stake(
        SettlementContext memory initialContext,
        address owner,
        uint256[] calldata tokenIds,
        uint256[] memory maybeStakingStartTimestamps
    )
        internal
        returns (SettlementContext memory context)
    {
        context = initialContext;
        uint256 n = tokenIds.length;

        for (uint256 i = 0; i < n;) {
            uint256 tokenId = tokenIds[i];

            // Get the current staking state for the token.
            TokenStakingState memory stakingState = _TOKEN_STAKING_STATE_[tokenId];

            // Require that the token is not currently staked.
            // Note that this will revert if the same token appeared twice in the list.
            require(
                stakingState.timestamp == 0,
                "Already staked"
            );

            // The timestamp to use as the staking start timestamp for the token.
            uint256 stakingStartTimestamp = maybeStakingStartTimestamps.length > 0
                ? maybeStakingStartTimestamps[i]
                : block.timestamp;

            Checkpoint memory checkpoint;
            (context, checkpoint) = IS2Lib.stakeLogic(
                context,
                IIkaniV2(IKANI).getPoemTraits(tokenId),
                stakingStartTimestamp,
                stakingState.nonce,
                tokenId
            );

            // Update storage for the token.
            if (checkpoint.timestamp != 0) {
                IS2Lib._insertCheckpoint(_CHECKPOINTS_[owner], checkpoint);
            }
            _TOKEN_STAKING_STATE_[tokenId].timestamp = stakingStartTimestamp.toUint32();

            emit Staked(owner, tokenId, stakingStartTimestamp);

            unchecked { ++i; }
        }
    }

    function _unstake(
        SettlementContext memory initialContext,
        address owner,
        uint256[] memory tokenIds
    )
        internal
        returns (SettlementContext memory context)
    {
        context = initialContext;
        uint256 n = tokenIds.length;

        for (uint256 i = 0; i < n;) {
            uint256 tokenId = tokenIds[i];

            // Get the current staking state for the token.
            TokenStakingState memory stakingState = _TOKEN_STAKING_STATE_[tokenId];

            // Require that the token is currently staked.
            // Note that this will revert if the same token appeared twice in the list.
            require(
                stakingState.timestamp != 0,
                "Not staked"
            );

            context = IS2Lib.unstakeLogic(
                context,
                IIkaniV2(IKANI).getPoemTraits(tokenId),
                stakingState.timestamp
            );

            // Update storage for the token.
            unchecked {
                _TOKEN_STAKING_STATE_[tokenId] = TokenStakingState({
                    timestamp: 0,
                    nonce: stakingState.nonce + 1
                });
            }

            emit Unstaked(owner, tokenId);

            unchecked { ++i; }
        }
    }

    function _requireSameOwnerAndAuthorized(
        address owner,
        uint256[] calldata tokenIds,
        bool alreadyAuthorized
    )
        internal
        view
    {
        address sender = msg.sender;
        bool senderIsOwner = sender == owner;
        uint256 n = tokenIds.length;

        // Verify owner and authorization.
        for (uint256 i = 0; i < n;) {
            uint256 tokenId = tokenIds[i];

            require(
                IERC721Upgradeable(IKANI).ownerOf(tokenId) == owner,
                "Wrong owner"
            );
            require(
                alreadyAuthorized || senderIsOwner || _isApproved(sender, owner, tokenId),
                "Not authorized to stake/unstake"
            );

            unchecked { ++i; }
        }
    }

    function _settleAccount(
        address owner
    )
        internal
        returns (
            SettlementContext memory context,
            uint256 rewardsDiff
        )
    {
        (context, rewardsDiff) = IS2Lib.settleAccountAndGetOwedRewards(
            _SETTLEMENT_CONTEXT_[owner],
            _RATE_CHANGES_,
            _CHECKPOINTS_[owner],
            _TOKEN_STAKING_STATE_,
            _NUM_RATE_CHANGES_
        );
    }

    function _isApproved(
        address spender,
        address owner,
        uint256 tokenId
    )
        internal
        view
        returns (bool)
    {
        return (
            IERC721Upgradeable(IKANI).isApprovedForAll(owner, spender) ||
            IERC721Upgradeable(IKANI).getApproved(tokenId) == spender
        );
    }
}

File 12 of 26 : IS2Roles.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { IS2Storage } from "./IS2Storage.sol";

/**
 * @title IS2Storage
 * @author Cyborg Labs, LLC
 */
abstract contract IS2Roles is
    IS2Storage
{
    //---------------- Constants ----------------//

    bytes32 public constant PAUSER_ROLE = keccak256('PAUSER_ROLE');
    bytes32 public constant UNPAUSER_ROLE = keccak256('UNPAUSER_ROLE');
    bytes32 public constant BASE_RATE_CONTROLLER_ROLE = keccak256('BASE_RATE_CONTROLLER_ROLE');
    bytes32 public constant BURN_CONTROLLER_ROLE = keccak256('BURN_CONTROLLER_ROLE');
    bytes32 public constant CLAIM_CONTROLLER_ROLE = keccak256('CLAIM_CONTROLLER_ROLE');
    bytes32 public constant UNSTAKE_CONTROLLER_ROLE = keccak256('UNSTAKE_CONTROLLER_ROLE');
}

File 13 of 26 : IERC165Upgradeable.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 IERC165Upgradeable {
    /**
     * @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 14 of 26 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

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

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

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

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

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

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

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

    /**
     * @dev 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 15 of 26 : IIkaniV2.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

/**
 * @title IIkaniV2
 * @author Cyborg Labs, LLC
 *
 * @notice Interface for the IkaniV1 ERC-721 NFT contract.
 */
interface IIkaniV2 {

    //---------------- Enums ----------------//

    enum Theme {
        NULL,
        SKY,
        OCEAN,
        MOUNTAIN,
        FLOWERS,
        TBA_THEME_5,
        TBA_THEME_6,
        TBA_THEME_7,
        TBA_THEME_8
    }

    enum Season {
        NONE,
        SPRING,
        SUMMER,
        AUTUMN,
        WINTER
    }

    enum Fabric {
        NULL,
        KOYAMAKI,
        SEIGAIHA,
        NAMI,
        KUMO,
        TBA_FABRIC_5,
        TBA_FABRIC_6,
        TBA_FABRIC_7,
        TBA_FABRIC_8
    }

    enum Foil {
        NONE,
        GOLD,
        PLATINUM,
        SUI_GENERIS
    }

    //---------------- Structs ----------------//

    /**
     * @notice The poem metadata traits.
     */
    struct PoemTraits {
        Theme theme;
        Season season;
        Fabric fabric;
        Foil foil;
    }

    /**
     * @notice Information about a series within the collection.
     */
    struct Series {
        string name;
        bytes32 provenanceHash;
        uint256 poemCreationDeadline;
        uint256 maxTokenIdExclusive;
        uint256 startingIndexBlockNumber;
        uint256 startingIndex;
        bool startingIndexWasSet;
    }

    /**
     * @notice Arguments to be signed by the mint authority to authorize a mint.
     */
    struct MintArgs {
        uint256 seriesIndex;
        uint256 mintPrice;
        uint256 maxTokenIdExclusive;
        uint256 nonce;
    }

    //---------------- Events ----------------//

    event SetRoyaltyReceiver(
        address royaltyReceiver
    );

    event SetRoyaltyBips(
        uint256 royaltyBips
    );

    event SetSeriesInfo(
        uint256 indexed seriesIndex,
        string name,
        bytes32 provenanceHash
    );

    event AdvancedPoemCreationDeadline(
        uint256 indexed seriesIndex,
        uint256 poemCreationDeadline
    );

    event ResetSeriesStartingIndexBlockNumber(
        uint256 indexed seriesIndex,
        uint256 startingIndexBlockNumber
    );

    event SetSeriesStartingIndex(
        uint256 indexed seriesIndex,
        uint256 startingIndex
    );

    event EndedSeries(
        uint256 indexed seriesIndex,
        uint256 poemCreationDeadline,
        uint256 maxTokenIdExclusive,
        uint256 startingIndexBlockNumber
    );

    event FinishedPoem(
        uint256 indexed tokenId
    );

    //---------------- Functions ----------------//

    function getPoemTraits(
        uint256 tokenId
    )
        external
        view
        returns (IIkaniV2.PoemTraits memory);
}

File 16 of 26 : IS2Lib.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { SafeCastUpgradeable } from "../../../deps/oz_cu_4_7_2/SafeCastUpgradeable.sol";

import { IIkaniV2 } from "../../../nft/v2/interfaces/IIkaniV2.sol";
import { IIkaniV2Staking } from "../interfaces/IIkaniV2Staking.sol";
import { MinHeap } from "../lib/MinHeap.sol";

library IS2Lib {
    using MinHeap for MinHeap.Heap;
    using SafeCastUpgradeable for uint256;

    //---------------- Constants ----------------//

    uint256 internal constant MULTIPLIER_BASE = 1e6;
    uint256 internal constant MULTIPLIER_BASE_2 = MULTIPLIER_BASE ** 2;

    uint256 internal constant BASE_POINTS_NO_FOIL = 1e6;
    uint256 internal constant BASE_POINTS_GOLD = 1.5e6;
    uint256 internal constant BASE_POINTS_PLATINUM = 2.25e6;
    uint256 internal constant BASE_POINTS_SUI_GENERIS = 3.375e6;

    uint256 internal constant SEASONS_MULTIPLIER_2 = 1.05e6;
    uint256 internal constant SEASONS_MULTIPLIER_3 = 1.12e6;
    uint256 internal constant SEASONS_MULTIPLIER_4 = 1.25e6;

    uint256 internal constant FABRICS_MULTIPLIER_2 = 1.05e6;
    uint256 internal constant FABRICS_MULTIPLIER_3 = 1.12e6;
    uint256 internal constant FABRICS_MULTIPLIER_4 = 1.25e6;

    uint256 internal constant LEVEL_MULTIPLIER_1 = 1.05e6;
    uint256 internal constant LEVEL_MULTIPLIER_2 = 1.1e6;
    uint256 internal constant LEVEL_MULTIPLIER_3 = 1.2e6;
    uint256 internal constant LEVEL_MULTIPLIER_4 = 1.3e6;

    uint256 internal constant LEVEL_DURATION_1 = 1 weeks;
    uint256 internal constant LEVEL_DURATION_2 = 2 weeks;
    uint256 internal constant LEVEL_DURATION_3 = 4 weeks;
    uint256 internal constant LEVEL_DURATION_4 = 12 weeks;

    uint256 internal constant LAST_LEVEL = 4;

    //---------------- External Functions ----------------//

    /**
     * @dev Settle rewards to current timestamp, returning updated context and new rewards.
     *
     *  After calling this function, the returned updated context should be saved to storage.
     *  The new rewards should also be saved to storage (or spent).
     */
    function settleAccountAndGetOwedRewards(
        IIkaniV2Staking.SettlementContext memory intialContext,
        mapping(uint256 => IIkaniV2Staking.RateChange) storage _rate_changes_,
        MinHeap.Heap storage _checkpoints_,
        mapping(uint256 => IIkaniV2Staking.TokenStakingState) storage _token_staking_state_,
        uint256 globalNumRateChanges
    )
        external
        returns (
            IIkaniV2Staking.SettlementContext memory context,
            uint256 newRewards
        )
    {
        context = intialContext;
        newRewards = 0;

        if (context.timestamp == block.timestamp) {
            // Short-circuit.
            return (context, newRewards);
        }

        if (context.points == 0) {
            // Short-circuit.
            //
            // TODO: Clarify the note below.
            //
            // Note: We don't remove old checkpoints from the heap at this time. It's important
            // that any old checkpoints are invalidated by the change in staking nonce, otherwise
            // this function would revert when trying to settle a checkpoint whose timestamp is
            // less than the context timestamp.
            context.timestamp = block.timestamp.toUint32();
            context.numRateChanges = globalNumRateChanges.toUint32();

            // Get the current base rate.
            context.baseRate = _rate_changes_[globalNumRateChanges].baseRate;

            return (context, newRewards);
        }

        // Load into memory any rate changes that need to be applied.
        uint256 numRateChangesToApply = globalNumRateChanges - context.numRateChanges;
        IIkaniV2Staking.RateChange[] memory rateChanges = (
            new IIkaniV2Staking.RateChange[](numRateChangesToApply)
        );
        for (uint256 i = 0; i < numRateChangesToApply;) {
            unchecked {
                rateChanges[i] = _rate_changes_[context.numRateChanges + i + 1];
                ++i;
            }
        }

        // Iterate over the checkpoints in chronological order.
        while (_checkpoints_.length > 0) {
            IIkaniV2Staking.Checkpoint memory checkpoint;

            {
                uint256 checkpointUint = _checkpoints_.unsafePeek();

                // Get the threshold for checkpoints that have been reached.
                uint256 checkpointThreshold;
                unchecked {
                    checkpointThreshold = (block.timestamp + 1) << 224;
                }

                // Stop iterating if the next checkpoint has not been reached.
                if (checkpointUint >= checkpointThreshold) {
                    break;
                }

                // If the checkpoint was reached, remove it from the heap and process it.
                _checkpoints_.popMin();

                // Parse the checkpoint.
                checkpoint = _decodeCheckpoint(checkpointUint);
            }

            // Ignore and discard the checkpoint if it is no longer valid.
            // A checkpoint is no longer valid if the associated token was unstaked since the
            // checkpoint was created.
            {
                // TODO: Optimize by caching these?
                IIkaniV2Staking.TokenStakingState memory stakingState = (
                    _token_staking_state_[checkpoint.tokenId]
                );
                if (checkpoint.stakedNonce != stakingState.nonce) {
                    continue;
                }
                if (stakingState.timestamp == 0) {
                    // TODO: Remove.
                    //
                    // This check is redundant, and this continue should never be reached.
                    // Keeping it just for now.
                    // revert('Sanity check failed');
                    continue;
                }
            }

            // Process any rate changes that occurred before the checkpoint.
            while (context.numRateChanges < globalNumRateChanges) {
                uint256 rateIndex = (
                    numRateChangesToApply + context.numRateChanges - globalNumRateChanges
                );

                if (rateChanges[rateIndex].timestamp >= checkpoint.timestamp) {
                    break;
                }

                newRewards += _settleAccountToTimestamp(context, rateChanges[rateIndex].timestamp);
                context.timestamp = rateChanges[rateIndex].timestamp;

                context.baseRate = rateChanges[rateIndex].baseRate;
                ++context.numRateChanges;
            }

            // Settle up to the checkpoint timestamp.
            newRewards += _settleAccountToTimestamp(context, checkpoint.timestamp);
            context.timestamp = checkpoint.timestamp;

            // Add points from the checkpoint.
            uint256 level = uint256(checkpoint.level);
            uint256 bonusPoints;
            {
                bonusPoints = _getBonusPointsFromLevel(
                    uint256(checkpoint.basePoints),
                    level
                ).toUint32();
            }
            {
                context.points += bonusPoints.toUint32();
            }

            // Add next checkpoint if there is a next checkpoint.
            if (level < LAST_LEVEL) {
                checkpoint = _getNextCheckpoint(checkpoint);
                _insertCheckpoint(_checkpoints_, checkpoint);
            }
        }

        // Process any remaining rate changes and settle up to each one.
        while (context.numRateChanges < globalNumRateChanges) {
            IIkaniV2Staking.RateChange memory rateChange = rateChanges[
                numRateChangesToApply + context.numRateChanges - globalNumRateChanges
            ];

            newRewards += _settleAccountToTimestamp(context, rateChange.timestamp);
            context.timestamp = rateChange.timestamp;

            context.baseRate = rateChange.baseRate;
            ++context.numRateChanges;
        }

        // Settle up to the current timestamp.
        newRewards += _settleAccountToTimestamp(context, block.timestamp);
        context.timestamp = block.timestamp.toUint32();
    }

    function stakeLogic(
        IIkaniV2Staking.SettlementContext memory intialContext,
        IIkaniV2.PoemTraits memory traits,
        uint256 stakingStartTimestamp,
        uint256 stakedNonce,
        uint256 tokenId
    )
        external
        view
        returns (
            IIkaniV2Staking.SettlementContext memory context,
            IIkaniV2Staking.Checkpoint memory checkpoint
        )
    {
        context = intialContext;

        // Get base points (affected by foil).
        uint256 basePoints = getFoilRewardsMultiplier(traits);

        // Determine level and points (affected by staked duration).
        uint256 stakedDuration = block.timestamp - stakingStartTimestamp;
        uint256 level = getLevelForStakedDuration(stakedDuration);
        uint256 points = (
            basePoints *
            _getLevelRewardsMultiplier(level) /
            MULTIPLIER_BASE
        );

        // If applicable, add a checkpoint for the next increase in points.
        if (level < LAST_LEVEL) {
            uint256 nextLevel;
            unchecked {
                nextLevel = level + 1;
            }
            uint256 checkpointTimestamp = stakingStartTimestamp + _getDurationForLevel(nextLevel);
            checkpoint = IIkaniV2Staking.Checkpoint({
                timestamp: checkpointTimestamp.toUint32(),
                level: nextLevel.toUint32(),
                basePoints: basePoints.toUint32(),
                stakedNonce: stakedNonce.toUint32(),
                tokenId: tokenId.toUint128()
            });
        }

        // Update the trait counts, acount-level multiplier, and points for the account.
        context = _addTraitsToToken(context, traits);
        context.multiplier = getAccountRewardsMultiplier(context).toUint32();
        context.points += points.toUint32();
    }

    function unstakeLogic(
        IIkaniV2Staking.SettlementContext memory intialContext,
        IIkaniV2.PoemTraits memory traits,
        uint256 stakedTimestamp
    )
        external
        view
        returns (
            IIkaniV2Staking.SettlementContext memory context
        )
    {
        context = intialContext;

        // Get base points (affected by foil).
        uint256 basePoints = getFoilRewardsMultiplier(traits);

        // Determine points (affected by staked duration).
        uint256 stakedDuration = block.timestamp - stakedTimestamp;
        uint256 points = (
            basePoints *
            getStakedDurationRewardsMultiplier(stakedDuration) /
            MULTIPLIER_BASE
        );

        // Update the trait counts, acount-level multiplier, and points for the account.
        context = _subtractTraitsFromToken(context, traits);
        context.multiplier = getAccountRewardsMultiplier(context).toUint32();
        context.points -= points.toUint32();

    }

    //---------------- Public State-Changing Functions ----------------//

    function _insertCheckpoint(
        MinHeap.Heap storage _checkpoints_,
        IIkaniV2Staking.Checkpoint memory checkpoint
    )
        public
    {
        uint256 checkpointUint = (
            (uint256(checkpoint.timestamp) << 224) +
            (uint256(checkpoint.level) << 192) +
            (uint256(checkpoint.basePoints) << 160) +
            (uint256(checkpoint.stakedNonce) << 128) +
            checkpoint.tokenId
        );
        _checkpoints_.insert(checkpointUint);
    }

    //---------------- Public Pure Functions ----------------//

    function getFoilRewardsMultiplier(
        IIkaniV2.PoemTraits memory traits
    )
        public
        pure
        returns (uint256)
    {
        if (traits.foil == IIkaniV2.Foil.NONE) {
            return BASE_POINTS_NO_FOIL;
        } else if (traits.foil == IIkaniV2.Foil.GOLD) {
            return BASE_POINTS_GOLD;
        } else if (traits.foil == IIkaniV2.Foil.PLATINUM) {
            return BASE_POINTS_PLATINUM;
        } else if (traits.foil == IIkaniV2.Foil.SUI_GENERIS) {
            return BASE_POINTS_SUI_GENERIS;
        }

        // Sanity check.
        revert("Unknown foil");
    }

    function getStakedDurationRewardsMultiplier(
        uint256 stakedDuration
    )
        public
        pure
        returns (uint256)
    {
        if (stakedDuration < LEVEL_DURATION_1) {
            return MULTIPLIER_BASE;
        } else if (stakedDuration < LEVEL_DURATION_2) {
            return LEVEL_MULTIPLIER_1;
        } else if (stakedDuration < LEVEL_DURATION_3) {
            return LEVEL_MULTIPLIER_2;
        } else if (stakedDuration < LEVEL_DURATION_4) {
            return LEVEL_MULTIPLIER_3;
        }
        return LEVEL_MULTIPLIER_4;
    }

    function getAccountRewardsMultiplier(
        IIkaniV2Staking.SettlementContext memory context
    )
        public
        pure
        returns (uint256)
    {
        uint256 fabricsMultiplier = getFabricsRewardsMultiplier(context);
        uint256 seasonsMultiplier = getSeasonsRewardsMultiplier(context);
        return fabricsMultiplier * seasonsMultiplier / MULTIPLIER_BASE;
    }

    function getFabricsRewardsMultiplier(
        IIkaniV2Staking.SettlementContext memory context
    )
        public
        pure
        returns (uint256)
    {
        uint256 uniqueFabricsCount = getNumFabricsStaked(context);
        if (uniqueFabricsCount == 4)  {
            return FABRICS_MULTIPLIER_4;
        } else if (uniqueFabricsCount == 3)  {
            return FABRICS_MULTIPLIER_3;
        } else if (uniqueFabricsCount == 2)  {
            return FABRICS_MULTIPLIER_2;
        }
        return MULTIPLIER_BASE;
    }

    function getSeasonsRewardsMultiplier(
        IIkaniV2Staking.SettlementContext memory context
    )
        public
        pure
        returns (uint256)
    {
        uint256 uniqueSeasonsCount = getNumSeasonsStaked(context);
        if (uniqueSeasonsCount == 4)  {
            return SEASONS_MULTIPLIER_4;
        } else if (uniqueSeasonsCount == 3)  {
            return SEASONS_MULTIPLIER_3;
        } else if (uniqueSeasonsCount == 2)  {
            return SEASONS_MULTIPLIER_2;
        }
        return MULTIPLIER_BASE;
    }

    function getNumFabricsStaked(
        IIkaniV2Staking.SettlementContext memory context
    )
        public
        pure
        returns (uint256)
    {
        unchecked {
            return (
                _toUint256(context.fabricKoyamaki > 0) +
                _toUint256(context.fabricSeigaiha > 0) +
                _toUint256(context.fabricNami > 0) +
                _toUint256(context.fabricKumo > 0)
            );
        }
    }

    function getNumSeasonsStaked(
        IIkaniV2Staking.SettlementContext memory context
    )
        public
        pure
        returns (uint256)
    {
        unchecked {
            return (
                _toUint256(context.seasonSpring > 0) +
                _toUint256(context.seasonSummer > 0) +
                _toUint256(context.seasonAutumn > 0) +
                _toUint256(context.seasonWinter > 0)
            );
        }
    }

    function getLevelForStakedDuration(
        uint256 stakedDuration
    )
        public
        pure
        returns (uint256)
    {
        if (stakedDuration < LEVEL_DURATION_1) {
            return 0;
        } else if (stakedDuration < LEVEL_DURATION_2) {
            return 1;
        } else if (stakedDuration < LEVEL_DURATION_3) {
            return 2;
        } else if (stakedDuration < LEVEL_DURATION_4) {
            return 3;
        }
        return LAST_LEVEL; // 4
    }

    //---------------- Private Pure Functions ----------------//

    function _getLevelRewardsMultiplier(
        uint256 level
    )
        private
        pure
        returns (uint256)
    {
        if (level == 0) {
            return MULTIPLIER_BASE;
        } else if (level == 1) {
            return LEVEL_MULTIPLIER_1;
        } else if (level == 2) {
            return LEVEL_MULTIPLIER_2;
        } else if (level == 3) {
            return LEVEL_MULTIPLIER_3;
        } else if (level == 4) {
            return LEVEL_MULTIPLIER_4;
        }

        // Sanity check.
        revert("Unknown level");
    }

    function _getDurationForLevel(
        uint256 level
    )
        private
        pure
        returns (uint256)
    {
        // Note: This function cannot be called with level = 0.
        if (level == 1) {
            return LEVEL_DURATION_1;
        } else if (level == 2) {
            return LEVEL_DURATION_2;
        } else if (level == 3) {
            return LEVEL_DURATION_3;
        } else if (level == 4) {
            return LEVEL_DURATION_4;
        }

        // Sanity check.
        revert("Unknown level");
    }

    function _addTraitsToToken(
        IIkaniV2Staking.SettlementContext memory context,
        IIkaniV2.PoemTraits memory traits
    )
        private
        pure
        returns (IIkaniV2Staking.SettlementContext memory)
    {
        // TODO: Optimize.
        context.seasonSpring += _toUint8(traits.season == IIkaniV2.Season.SPRING);
        context.seasonSummer += _toUint8(traits.season == IIkaniV2.Season.SUMMER);
        context.seasonAutumn += _toUint8(traits.season == IIkaniV2.Season.AUTUMN);
        context.seasonWinter += _toUint8(traits.season == IIkaniV2.Season.WINTER);
        context.fabricKoyamaki += _toUint8(traits.fabric == IIkaniV2.Fabric.KOYAMAKI);
        context.fabricSeigaiha += _toUint8(traits.fabric == IIkaniV2.Fabric.SEIGAIHA);
        context.fabricNami += _toUint8(traits.fabric == IIkaniV2.Fabric.NAMI);
        context.fabricKumo += _toUint8(traits.fabric == IIkaniV2.Fabric.KUMO);

        return context;
    }

    function _subtractTraitsFromToken(
        IIkaniV2Staking.SettlementContext memory context,
        IIkaniV2.PoemTraits memory traits
    )
        private
        pure
        returns (IIkaniV2Staking.SettlementContext memory)
    {
        // TODO: Optimize.
        context.seasonSpring -= _toUint8(traits.season == IIkaniV2.Season.SPRING);
        context.seasonSummer -= _toUint8(traits.season == IIkaniV2.Season.SUMMER);
        context.seasonAutumn -= _toUint8(traits.season == IIkaniV2.Season.AUTUMN);
        context.seasonWinter -= _toUint8(traits.season == IIkaniV2.Season.WINTER);
        context.fabricKoyamaki -= _toUint8(traits.fabric == IIkaniV2.Fabric.KOYAMAKI);
        context.fabricSeigaiha -= _toUint8(traits.fabric == IIkaniV2.Fabric.SEIGAIHA);
        context.fabricNami -= _toUint8(traits.fabric == IIkaniV2.Fabric.NAMI);
        context.fabricKumo -= _toUint8(traits.fabric == IIkaniV2.Fabric.KUMO);

        return context;
    }

    function _settleAccountToTimestamp(
        IIkaniV2Staking.SettlementContext memory context,
        uint256 timestamp
    )
        private
        pure
        returns (uint256)
    {
        uint256 timeDelta = timestamp - context.timestamp;
        uint256 rewards = (
            timeDelta *
            context.baseRate *
            context.points *
            context.multiplier /
            MULTIPLIER_BASE_2
        );

        return rewards;
    }

    function _getNextCheckpoint(
        IIkaniV2Staking.Checkpoint memory checkpoint
    )
        private
        pure
        returns (IIkaniV2Staking.Checkpoint memory)
    {
        // Assumption: checkpoint.level < LAST_LEVEL
        uint256 timestampDiff;
        unchecked {
            uint32 newLevel = ++checkpoint.level;
            if (newLevel == 2) {
                timestampDiff = LEVEL_DURATION_2 - LEVEL_DURATION_1;
            } else if (newLevel == 3) {
                timestampDiff = LEVEL_DURATION_3 - LEVEL_DURATION_2;
            } else if (newLevel == 4) {
                timestampDiff = LEVEL_DURATION_4 - LEVEL_DURATION_3;
            }
        }
        checkpoint.timestamp += timestampDiff.toUint32();
        return checkpoint;
    }

    function _getBonusPointsFromLevel(
        uint256 basePoints,
        uint256 level
    )
        private
        pure
        returns (uint256)
    {
        // example params:
        //              no foil: base points 1e6
        //                 gold: base points 1.2e6
        //   level 1 multiplier: 1.1e6
        //   level 2 multiplier: 1.2e6
        //                 base: 1e6
        //
        // then the bonus points that are unlocked are
        //
        // no foil, level 1: (1.1e6 - 1.0e6) * 1e6 / base = 0.1e6
        // no foil, level 2: (1.2e6 - 1.1e6) * 1e6 / base = 0.1e6
        //    gold, level 1: (1.1e6 - 1.0e6) * 1.2e6 / base = 0.12e6
        //    gold, level 2: (1.2e6 - 1.1e6) * 1.2e6 / base = 0.12e6
        //
        // result:
        //   no foil: 1e6 -> 1.1e6 -> 1.2e6
        //      gold: 1.2e6 -> 1.32e6 -> 1.44e6
        //
        // Assume this function will not be called with level = 0.
        uint256 diff = (
            _getLevelRewardsMultiplier(level) -
            _getLevelRewardsMultiplier(level - 1)
        );
        return basePoints * diff / MULTIPLIER_BASE;
    }

    function _decodeCheckpoint(
        uint256 checkpointUint
    )
        private
        pure
        returns (
            IIkaniV2Staking.Checkpoint memory checkpoint
        )
    {
        // Truncate (unsafe cast).
        checkpoint.timestamp = uint32(checkpointUint >> 224);
        checkpoint.level = uint32(checkpointUint >> 192);
        checkpoint.basePoints = uint32(checkpointUint >> 160);
        checkpoint.stakedNonce = uint32(checkpointUint >> 128);
        checkpoint.tokenId = uint128(checkpointUint);
    }

    function _toUint8(bool x)
        private
        pure
        returns (uint8 r)
    {
        assembly { r := x }
    }

    function _toUint256(bool x)
        private
        pure
        returns (uint256 r)
    {
        assembly { r := x }
    }
}

File 17 of 26 : IIkaniV2Staking.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

/**
 * @title IIkaniV2Staking
 * @author Cyborg Labs, LLC
 *
 * @notice Interface for the IIkaniV2Staking features of the IkaniV1 ERC-721 NFT contract.
 */
interface IIkaniV2Staking {

    //---------------- Structs ----------------//

    struct RateChange {
        uint32 baseRate;
        uint32 timestamp;
    }

    struct SettlementContext {
        // The timestamp of the last settlement of this account.
        uint32 timestamp;
        // The number of global rate changes taken into account as of the last settlement
        // of this account.
        uint32 numRateChanges;
        // The global base earning rate.
        uint32 baseRate;
        // The current number of points for the account's staked tokens.
        uint32 points;
        // Current multiplier derived from the account's staked traits.
        uint32 multiplier;
        // The trait counts for the account's staked tokens.
        uint8 fabricKoyamaki;
        uint8 fabricSeigaiha;
        uint8 fabricNami;
        uint8 fabricKumo;
        uint8 fabricTba5;
        uint8 fabricTba6;
        uint8 fabricTba7;
        uint8 fabricTba8;
        uint8 seasonSpring;
        uint8 seasonSummer;
        uint8 seasonAutumn;
        uint8 seasonWinter;
    }

    struct Checkpoint {
        uint128 tokenId;
        uint32 stakedNonce;
        uint32 basePoints;
        uint32 level;
        uint32 timestamp;
    }

    struct TokenStakingState {
        uint32 timestamp;
        uint32 nonce;
    }

    //---------------- Events ----------------//

    event SetBaseRate(
        uint256 baseRate
    );

    event AdminUnstaked(
        address indexed owner,
        uint256[] indexed tokenIds,
        bytes32 indexed receipt,
        bytes receiptData
    );

    event Staked(
        address indexed owner,
        uint256 indexed tokenId,
        uint256 stakingStartTimestamp
    );

    event Unstaked(
        address indexed owner,
        uint256 indexed tokenId
    );

    event ClaimedRewards(
        address indexed owner,
        uint256 amount
    );

    //---------------- Functions ----------------//

    function isStaked(
        uint256 tokenId
    )
        external
        view
        returns (bool);
}

File 18 of 26 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

File 19 of 26 : AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControlUpgradeable.sol";
import "./ContextUpgradeable.sol";
import "./StringsUpgradeable.sol";
import "./ERC165Upgradeable.sol";
import "./Initializable.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
    function __AccessControl_init() internal onlyInitializing {
    }

    function __AccessControl_init_unchained() internal onlyInitializing {
    }
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        StringsUpgradeable.toHexString(account),
                        " is missing role ",
                        StringsUpgradeable.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 20 of 26 : PausableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "./ContextUpgradeable.sol";
import "./Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

File 21 of 26 : IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControlUpgradeable {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

File 22 of 26 : ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

import "./Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

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

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library StringsUpgradeable {
    bytes16 private constant _HEX_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) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

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

File 24 of 26 : ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165Upgradeable.sol";
import "./Initializable.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
    function __ERC165_init() internal onlyInitializing {
    }

    function __ERC165_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165Upgradeable).interfaceId;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

File 25 of 26 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "./AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original
     * initialization step. This is essential to configure modules that are added through upgrades and that require
     * initialization.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized < type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }
}

File 26 of 26 : IS2Erc20.sol
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.0;

import { IERC20 } from "../../../deps/oz_c_4_7_2/IERC20.sol";

import { IIkaniERC20 } from "../../../erc20/interfaces/IIkaniERC20.sol";

import { IS2Storage } from "./IS2Storage.sol";

/**
 * @title IS2Erc20
 * @author Cyborg Labs, LLC
 *
 * @notice Handles interactions with the ERC20 token.
 */
abstract contract IS2Erc20 is
    IS2Storage
{
    //---------------- Constants ----------------//

    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable REWARDS_ERC20;

    uint256 private constant REWARDS_CONVERSION_FACTOR = 1e6;

    //---------------- Constructor ----------------//

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor(
        address rewardsErc20
    ) {
        REWARDS_ERC20 = rewardsErc20;
    }

    //---------------- Internal Functions ----------------//

    function _issueRewards(
        address recipient,
        uint256 rewardsAmount
    )
        internal
        returns (uint256)
    {
        uint256 erc20Amount = _getErc20Amount(rewardsAmount);
        // Note: Not using SafeERC20, to save a bit of gas, since this is our own token.
        IERC20(REWARDS_ERC20).transfer(
            recipient,
            erc20Amount
        );
        return erc20Amount;
    }

    function _burnErc20(
        address owner,
        uint256 burnAmount,
        bytes32 burnReceipt,
        bytes calldata burnReceiptData,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    )
        internal
    {
        IIkaniERC20(REWARDS_ERC20).burnWithPermit(
            owner,
            burnAmount,
            burnReceipt,
            burnReceiptData,
            deadline,
            v,
            r,
            s
        );
    }

    function _getErc20Amount(
        uint256 rewardsAmount
    )
        internal
        pure
        returns (uint256)
    {
        return rewardsAmount * REWARDS_CONVERSION_FACTOR;
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "berlin",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {
    "contracts/staking/v2/lib/IS2Lib.sol": {
      "IS2Lib": "0xac25c2fb42b08ebab4d185efe4f9c8a430d97b1e"
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"ikani","type":"address"},{"internalType":"address","name":"rewardsErc20","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"indexed":true,"internalType":"bytes32","name":"receipt","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"receiptData","type":"bytes"}],"name":"AdminUnstaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ClaimedRewards","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"baseRate","type":"uint256"}],"name":"SetBaseRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakingStartTimestamp","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Unstaked","type":"event"},{"inputs":[],"name":"BASE_RATE_CONTROLLER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BURN_CONTROLLER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CLAIM_CONTROLLER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"IKANI","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MULTIPLIER_BASE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REWARDS_ERC20","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNPAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNSTAKE_CONTROLLER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"adminClaimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"burnAmount","type":"uint256"},{"internalType":"bytes32","name":"burnReceipt","type":"bytes32"},{"internalType":"bytes","name":"burnReceiptData","type":"bytes"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"adminClaimRewardsAndBurnWithPermit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"internalType":"bytes32","name":"receipt","type":"bytes32"},{"internalType":"bytes","name":"receiptData","type":"bytes"}],"name":"adminUnstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"internalType":"bytes32","name":"receipt","type":"bytes32"},{"internalType":"bytes[]","name":"receiptData","type":"bytes[]"}],"name":"adminUnstake2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"batchSafeTransferFromStaked","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"burnAmount","type":"uint256"},{"internalType":"bytes32","name":"burnReceipt","type":"bytes32"},{"internalType":"bytes","name":"burnReceiptData","type":"bytes"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"claimAndBurnRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"recipient","type":"address"}],"name":"claimRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getAccountRewardsMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBaseRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getDurationLevel","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getDurationRewardsMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getFabricsRewardsMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getFoilRewardsMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"}],"name":"getHistoricalBaseRate","outputs":[{"components":[{"internalType":"uint32","name":"baseRate","type":"uint32"},{"internalType":"uint32","name":"timestamp","type":"uint32"}],"internalType":"struct IIkaniV2Staking.RateChange","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNumBaseRateChanges","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getNumFabricsStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getNumSeasonsStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"getSeasonsRewardsMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getStakedTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getTokenRewardsRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"isStaked","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"baseRate","type":"uint32"}],"name":"setBaseRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"settleRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60c06040523480156200001157600080fd5b5060405162004d8f38038062004d8f833981016040819052620000349162000138565b6001600160a01b03808316608052811660a0526200005162000059565b505062000170565b600054610100900460ff1615620000c65760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff908116101562000119576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b80516001600160a01b03811681146200013357600080fd5b919050565b600080604083850312156200014c57600080fd5b62000157836200011b565b915062000167602084016200011b565b90509250929050565b60805160a051614bb3620001dc6000396000818161043d01528181612a45015261386101526000818161035b01528181610fe401528181611f2b0152818161203401528181612bc201528181612ea9015281816134d00152818161395a01526139e80152614bb36000f3fe608060405234801561001057600080fd5b50600436106102745760003560e01c80638662489c11610151578063bb14d20e116100c3578063d547741f11610087578063d547741f1461063c578063e63ab1e91461064f578063eb9feb7614610676578063f1e42ccd14610689578063f97136af1461069c578063fb1bb9de146106a657600080fd5b8063bb14d20e146105e6578063c10cdf94146105f9578063c9a3911e14610603578063cf2601ca14610616578063d0899bad1461062957600080fd5b80639f729a6e116101155780639f729a6e14610531578063a0f1deb214610544578063a217fddf1461056c578063a408829214610574578063b655d0c41461059b578063baa51f86146105bc57600080fd5b80638662489c146104be57806386907ef3146104d157806387244843146104e45780638ed0462f146104f757806391d148541461051e57600080fd5b806337a96fcd116101ea5780635c975abb116101ae5780635c975abb1461045f5780635dbe47561461046a5780636f23cb191461047d578063718b6c66146104905780638456cb59146104a3578063863325f6146104ab57600080fd5b806337a96fcd146103f757806337d5b5141461040a578063384085b21461041d5780633f4ba83a1461043057806354322d841461043857600080fd5b8063248a9ca31161023c578063248a9ca3146103335780632e85556d146103565780632f2ff15d1461039557806330d863ff146103aa578063356221fc146103bd57806336568abe146103e457600080fd5b806301ffc9a7146102795780630ae5dec7146102a15780630dbb8b10146102c2578063183224ce146102e957806323ed48a214610320575b600080fd5b61028c610287366004613d47565b6106cd565b60405190151581526020015b60405180910390f35b6102b46102af366004613d86565b610704565b604051908152602001610298565b6102b47fd732b487a91d56c42b88fd4b1d271f12f03f244b8857e8b4270cc835dab3dc5981565b6102fc6102f7366004613da3565b6107a4565b60408051825163ffffffff9081168252602093840151169281019290925201610298565b6102b461032e366004613d86565b61084a565b6102b4610341366004613da3565b60009081526065602052604090206001015490565b61037d7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610298565b6103a86103a3366004613dbc565b61089a565b005b6103a86103b8366004613e43565b6108c4565b6102b47f8585736fef124c318e85f82b5ce4c5d3878b7ff2fff2191b60ef74595a59a7b481565b6103a86103f2366004613dbc565b610941565b6103a8610405366004613d86565b6109bf565b6102b4610418366004613d86565b6109fb565b6103a861042b366004613e43565b610a4b565b6103a8610ad0565b61037d7f000000000000000000000000000000000000000000000000000000000000000081565b60975460ff1661028c565b6103a8610478366004613f20565b610b05565b6102b461048b366004613d86565b610e30565b6102b461049e366004613da3565b610e48565b6103a8610f0a565b6103a86104b9366004613f74565b610f3c565b6103a86104cc366004613fed565b6113f8565b6102b46104df366004613da3565b6117ae565b6103a86104f2366004614078565b61180b565b6102b47fcdebdf9373e7e5c847c3e6cb50c46a7442f1e563a69477a7263d23c6f732684981565b61028c61052c366004613dbc565b611fe6565b6102b461053f366004613da3565b612011565b6102b4610552366004613da3565b6000908152620f430e602052604090205463ffffffff1690565b6102b4600081565b6102b47f700a6a86f87f295447af4608d910099313633af610c1fbf9da48c91659ea46f181565b620f430a546000908152620f4309602052604090205463ffffffff166102b4565b61028c6105ca366004613da3565b6000908152620f430e602052604090205463ffffffff16151590565b6102b46105f4366004613d86565b61213f565b620f430a546102b4565b6103a8610611366004613f20565b61218f565b6102b4610624366004613d86565b6124ab565b6102b4610637366004613da3565b6124fb565b6103a861064a366004613dbc565b612556565b6102b47f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b6103a86106843660046140ee565b61257b565b6102b461069736600461410b565b6125ae565b6102b4620f424081565b6102b47f427da25fe773164f88948d3e215c94b6554e2ed5e5f203a821c9f2f6131cf75a81565b60006001600160e01b03198216637965db0b60e01b14806106fe57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6001600160a01b0381166000908152620f430b6020526040808220905163f41a545360e01b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163f41a5453916107549190600401614269565b60206040518083038186803b15801561076c57600080fd5b505af4158015610780573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106fe9190614278565b6040805180820190915260008082526020820152620f430a548211156108115760405162461bcd60e51b815260206004820152601760248201527f496e76616c69642062617365207261746520696e64657800000000000000000060448201526064015b60405180910390fd5b506000908152620f4309602090815260409182902082518084019093525463ffffffff8082168452640100000000909104169082015290565b6001600160a01b0381166000908152620f430b60205260408082209051637d0c0db960e11b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163fa181b72916107549190600401614269565b6000828152606560205260409020600101546108b581612610565b6108bf838361261a565b505050565b6108cc6126a0565b336001600160a01b038a161461091a5760405162461bcd60e51b815260206004820152601360248201527229b2b73232b91034b9903737ba1037bbb732b960691b6044820152606401610808565b610924898a6126e8565b50610936898989898989898989612a2e565b505050505050505050565b6001600160a01b03811633146109b15760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610808565b6109bb8282612ac7565b5050565b7f700a6a86f87f295447af4608d910099313633af610c1fbf9da48c91659ea46f16109e981612610565b6109f16126a0565b6108bf82836126e8565b6001600160a01b0381166000908152620f430b6020526040808220905163547fecb960e01b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163547fecb9916107549190600401614269565b7f700a6a86f87f295447af4608d910099313633af610c1fbf9da48c91659ea46f1610a7581612610565b7fcdebdf9373e7e5c847c3e6cb50c46a7442f1e563a69477a7263d23c6f7326849610a9f81612610565b610aa76126a0565b610ab18b8c6126e8565b50610ac38b8b8b8b8b8b8b8b8b612a2e565b5050505050505050505050565b7f427da25fe773164f88948d3e215c94b6554e2ed5e5f203a821c9f2f6131cf75a610afa81612610565b610b02612b2e565b50565b610b0d6126a0565b610b1a8383836000612b80565b600080610b2685612d11565b91509150610b688286868680806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250612de192505050565b915081620f430b6000876001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505080620f430d6000876001600160a01b03166001600160a01b031681526020019081526020016000206000828254610e2491906142a7565b90915550505050505050565b6000610e3a6126a0565b6106fe82613058565b919050565b6000818152620f430e602052604081205463ffffffff1680610e6f5750620f424092915050565b6000610e7b82426142bf565b604051633bf46d2960e11b81526004810182905290915073ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e906377e8da52906024015b60206040518083038186803b158015610eca57600080fd5b505af4158015610ede573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f029190614278565b949350505050565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a610f3481612610565b610b02613353565b7fd732b487a91d56c42b88fd4b1d271f12f03f244b8857e8b4270cc835dab3dc59610f6681612610565b610f6e6126a0565b8460005b818110156113ee576000888883818110610f8e57610f8e6142d6565b905060200201359050366000878785818110610fac57610fac6142d6565b9050602002810190610fbe91906142ec565b6040516331a9108f60e11b81526004810186905291935091506000906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636352211e9060240160206040518083038186803b15801561102657600080fd5b505afa15801561103a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061105e9190614332565b905060008061106c83612d11565b604080516001808252818301909252929450909250600091906020808301908036833701905050905086816000815181106110a9576110a96142d6565b6020026020010181815250506110c0838583612de1565b925082620f430b6000866001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505081620f430d6000866001600160a01b03166001600160a01b03168152602001908152602001600020600082825461137c91906142a7565b90915550506040518d90611391908390614365565b6040518091039020856001600160a01b03167f1c3faf66cba9b4c4b916ac285c4e22b9647b7f00eadcb4ca01a5a10b65b18ebc89896040516113d49291906143c4565b60405180910390a487600101975050505050505050610f72565b5050505050505050565b7fd732b487a91d56c42b88fd4b1d271f12f03f244b8857e8b4270cc835dab3dc5961142281612610565b61142a6126a0565b6114378787876001612b80565b60008061144389612d11565b91509150611485828a8a8a80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250612de192505050565b915081620f430b60008b6001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505080620f430d60008b6001600160a01b03166001600160a01b03168152602001908152602001600020600082825461174191906142a7565b90915550506040518690611758908a908a906143d8565b60405180910390208a6001600160a01b03167f1c3faf66cba9b4c4b916ac285c4e22b9647b7f00eadcb4ca01a5a10b65b18ebc888860405161179b9291906143c4565b60405180910390a4505050505050505050565b6000818152620f430e602052604081205463ffffffff16816117d082426142bf565b604051630b21e43b60e31b81526004810182905290915073ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9063590f21d890602401610eb2565b6118136126a0565b336001600160a01b0385161461186b5760405162461bcd60e51b815260206004820152601e60248201527f4f6e6c79206f776e65722063616e207472616e73666572207374616b656400006044820152606401610808565b6118788483836001612b80565b60008061188486612d11565b9150915060008061189487612d11565b9092509050846000816001600160401b038111156118b4576118b461434f565b6040519080825280602002602001820160405280156118dd578160200160208202803683370190505b50905060005b8281101561194d57620f430e60008a8a84818110611903576119036142d6565b6020908102929092013583525081019190915260400160002054825163ffffffff9091169083908390811061193a5761193a6142d6565b60209081029190910101526001016118e3565b5061198c868b8a8a80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250612de192505050565b955061199b848a8a8a85613390565b935085620f430b60008c6001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505084620f430d60008c6001600160a01b03166001600160a01b031681526020019081526020016000206000828254611c5791906142a7565b9250508190555083620f430b60008b6001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505082620f430d60008b6001600160a01b03166001600160a01b031681526020019081526020016000206000828254611f1891906142a7565b90915550600090505b82811015610ac3577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166342842e0e8c8c8c8c86818110611f6c57611f6c6142d6565b6040516001600160e01b031960e088901b1681526001600160a01b03958616600482015294909316602485015250602090910201356044820152606401600060405180830381600087803b158015611fc357600080fd5b505af1158015611fd7573d6000803e3d6000fd5b50505050806001019050611f21565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60405163269f5cb960e01b81526004810182905260009081906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063269f5cb99060240160806040518083038186803b15801561207657600080fd5b505afa15801561208a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120ae9190614478565b6040516331e9c30f60e21b815290915073ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9063c7a70c3c906120e8908490600401614592565b60206040518083038186803b15801561210057600080fd5b505af4158015612114573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121389190614278565b9392505050565b6001600160a01b0381166000908152620f430b602052604080822090516372e1603160e11b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163e5c2c062916107549190600401614269565b6121976126a0565b6121a48383836000612b80565b6000806121b085612d11565b90925090506121ed8286868660006040519080825280602002602001820160405280156121e7578160200160208202803683370190505b50613390565b915081620f430b6000876001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff160217905550905050806000146124a4576001600160a01b0385166000908152620f430d602052604081208054839290610e249084906142a7565b5050505050565b6001600160a01b0381166000908152620f430b60205260408082209051637ba0aaf560e11b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163f74155ea916107549190600401614269565b600061250a620f4240806145a0565b61251383612011565b61251c84610e48565b620f430a546000908152620f4309602052604090205463ffffffff1661254291906145a0565b61254c91906145a0565b6106fe91906145bf565b60008281526065602052604090206001015461257181612610565b6108bf8383612ac7565b7f8585736fef124c318e85f82b5ce4c5d3878b7ff2fff2191b60ef74595a59a7b46125a581612610565b6109bb8261372a565b60006125b86126a0565b336001600160a01b038416146126065760405162461bcd60e51b815260206004820152601360248201527229b2b73232b91034b9903737ba1037bbb732b960691b6044820152606401610808565b61213883836126e8565b610b0281336137d3565b6126248282611fe6565b6109bb5760008281526065602090815260408083206001600160a01b03851684529091529020805460ff1916600117905561265c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60975460ff16156126e65760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610808565b565b6001600160a01b0382166000908152620f430d6020526040812054818061270e86612d11565b9150915081620f430b6000886001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff1602179055509050506000620f430d6000886001600160a01b03166001600160a01b0316815260200190815260200160002081905550600081846129d091906142a7565b905060006129de878361382c565b9050876001600160a01b03167f2d5429efdeca7741a8cd94067b18d988bc4e5f1d5b8272c37b7bfc31e9bfa32c82604051612a1b91815260200190565b60405180910390a2979650505050505050565b604051636380303360e11b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063c700606690612a8a908c908c908c908c908c908c908c908c908c906004016145e1565b600060405180830381600087803b158015612aa457600080fd5b505af1158015612ab8573d6000803e3d6000fd5b50505050505050505050505050565b612ad18282611fe6565b156109bb5760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b612b366138e7565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b336001600160a01b03851681148360005b818110156113ee576000878783818110612bad57612bad6142d6565b905060200201359050886001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316636352211e836040518263ffffffff1660e01b8152600401612c0e91815260200190565b60206040518083038186803b158015612c2657600080fd5b505afa158015612c3a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c5e9190614332565b6001600160a01b031614612ca25760405162461bcd60e51b815260206004820152600b60248201526a2bb937b7339037bbb732b960a91b6044820152606401610808565b8580612cab5750835b80612cbc5750612cbc858a83613930565b612d085760405162461bcd60e51b815260206004820152601f60248201527f4e6f7420617574686f72697a656420746f207374616b652f756e7374616b65006044820152606401610808565b50600101612b91565b612d19613cbb565b6001600160a01b0382166000908152620f430b60209081526040808320620f430c909252808320620f430a5491516324e948eb60e21b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e936393a523ac93612d86939192620f43099291620f430e9160040161463c565b6102406040518083038186803b158015612d9f57600080fd5b505af4158015612db3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dd791906147ce565b9094909350915050565b612de9613cbb565b508051839060005b8181101561304f576000848281518110612e0d57612e0d6142d6565b6020908102919091018101516000818152620f430e835260409081902081518083019092525463ffffffff808216808452640100000000909204169382019390935290925090612e8c5760405162461bcd60e51b815260206004820152600a602482015269139bdd081cdd185ad95960b21b6044820152606401610808565b73ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e637726dc4f867f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663269f5cb9866040518263ffffffff1660e01b8152600401612ef591815260200190565b60806040518083038186803b158015612f0d57600080fd5b505afa158015612f21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f459190614478565b84516040516001600160e01b031960e086901b168152612f6a9392919060040161492a565b6102206040518083038186803b158015612f8357600080fd5b505af4158015612f97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fbb919061495c565b604080518082018252600080825260208581015160010163ffffffff908116828501908152888452620f430e90925284832093518454925182166401000000000267ffffffffffffffff1990931691161717909155905191965083916001600160a01b038a16917f0f5bb82176feb1b5e747e28471aa92156a04d9f3ab9f45f28e2d704232b93f7591a35050600101612df1565b50509392505050565b6001600160a01b0381166000908152620f430d6020526040812054818061307e85612d11565b9092509050600061308f82856142a7565b905082620f430b6000886001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505080620f430d6000886001600160a01b03166001600160a01b031681526020019081526020016000208190555061334981613a96565b9695505050505050565b61335b6126a0565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612b633390565b613398613cbb565b50848260005b8181101561371f5760008686838181106133ba576133ba6142d6565b602090810292909201356000818152620f430e845260409081902081518083019092525463ffffffff80821680845264010000000090920416948201949094529093509115905061343e5760405162461bcd60e51b815260206004820152600e60248201526d105b1c9958591e481cdd185ad95960921b6044820152606401610808565b60008087511161344e5742613469565b868481518110613460576134606142d6565b60200260200101515b6040805160a081018252600080825260208201819052818301819052606082018190526080820152905163269f5cb960e01b8152600481018690529192509073ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e90633ad9726c9089906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063269f5cb99060240160806040518083038186803b15801561351257600080fd5b505afa158015613526573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061354a9190614478565b858760200151896040518663ffffffff1660e01b8152600401613571959493929190614979565b6102c06040518083038186803b15801561358a57600080fd5b505af415801561359e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135c291906149bb565b6080810151919850915063ffffffff161561369e576001600160a01b038b166000908152620f430c6020908152604091829020825163c6043c7760e01b8152600481019190915283516001600160801b031660248201529083015163ffffffff90811660448301529183015182166064820152606083015182166084820152608083015190911660a482015273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9063c6043c779060c40160006040518083038186803b15801561368557600080fd5b505af4158015613699573d6000803e3d6000fd5b505050505b6136a782613aa5565b6000858152620f430e6020908152604091829020805463ffffffff191663ffffffff94909416939093179092555183815285916001600160a01b038e16917f1449c6dd7851abc30abf37f57715f492010519147cc2652fbc38202c18a6ee90910160405180910390a38460010194505050505061339e565b505095945050505050565b60405180604001604052808263ffffffff16815260200161374a42613aa5565b63ffffffff908116909152620f430a8054600101908190556000908152620f43096020908152604091829020845181549583015185166401000000000267ffffffffffffffff1990961690851617949094179093555190831681527f16bacabd495cd45d904b6dc6184eabc5a6d654a4ee84569a5489ee7b20bc4364910160405180910390a150565b6137dd8282611fe6565b6109bb576137ea81613b0e565b6137f5836020613b20565b604051602001613806929190614a9c565b60408051601f198184030181529082905262461bcd60e51b825261080891600401614b11565b60008061383883613a96565b60405163a9059cbb60e01b81526001600160a01b038681166004830152602482018390529192507f00000000000000000000000000000000000000000000000000000000000000009091169063a9059cbb90604401602060405180830381600087803b1580156138a757600080fd5b505af11580156138bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138df9190614b44565b509392505050565b60975460ff166126e65760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610808565b60405163e985e9c560e01b81526001600160a01b03838116600483015284811660248301526000917f00000000000000000000000000000000000000000000000000000000000000009091169063e985e9c59060440160206040518083038186803b15801561399e57600080fd5b505afa1580156139b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139d69190614b44565b80610f025750836001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663081812fc846040518263ffffffff1660e01b8152600401613a3491815260200190565b60206040518083038186803b158015613a4c57600080fd5b505afa158015613a60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a849190614332565b6001600160a01b031614949350505050565b60006106fe620f4240836145a0565b600063ffffffff821115613b0a5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b6064820152608401610808565b5090565b60606106fe6001600160a01b03831660145b60606000613b2f8360026145a0565b613b3a9060026142a7565b6001600160401b03811115613b5157613b5161434f565b6040519080825280601f01601f191660200182016040528015613b7b576020820181803683370190505b509050600360fc1b81600081518110613b9657613b966142d6565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110613bc557613bc56142d6565b60200101906001600160f81b031916908160001a9053506000613be98460026145a0565b613bf49060016142a7565b90505b6001811115613c6c576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110613c2857613c286142d6565b1a60f81b828281518110613c3e57613c3e6142d6565b60200101906001600160f81b031916908160001a90535060049490941c93613c6581614b66565b9050613bf7565b5083156121385760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610808565b6040805161022081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081018290526101c081018290526101e0810182905261020081019190915290565b600060208284031215613d5957600080fd5b81356001600160e01b03198116811461213857600080fd5b6001600160a01b0381168114610b0257600080fd5b600060208284031215613d9857600080fd5b813561213881613d71565b600060208284031215613db557600080fd5b5035919050565b60008060408385031215613dcf57600080fd5b823591506020830135613de181613d71565b809150509250929050565b60008083601f840112613dfe57600080fd5b5081356001600160401b03811115613e1557600080fd5b602083019150836020828501011115613e2d57600080fd5b9250929050565b60ff81168114610b0257600080fd5b60008060008060008060008060006101008a8c031215613e6257600080fd5b8935613e6d81613d71565b985060208a0135975060408a0135965060608a01356001600160401b03811115613e9657600080fd5b613ea28c828d01613dec565b90975095505060808a0135935060a08a0135613ebd81613e34565b8093505060c08a0135915060e08a013590509295985092959850929598565b60008083601f840112613eee57600080fd5b5081356001600160401b03811115613f0557600080fd5b6020830191508360208260051b8501011115613e2d57600080fd5b600080600060408486031215613f3557600080fd5b8335613f4081613d71565b925060208401356001600160401b03811115613f5b57600080fd5b613f6786828701613edc565b9497909650939450505050565b600080600080600060608688031215613f8c57600080fd5b85356001600160401b0380821115613fa357600080fd5b613faf89838a01613edc565b9097509550602088013594506040880135915080821115613fcf57600080fd5b50613fdc88828901613edc565b969995985093965092949392505050565b6000806000806000806080878903121561400657600080fd5b863561401181613d71565b955060208701356001600160401b038082111561402d57600080fd5b6140398a838b01613edc565b909750955060408901359450606089013591508082111561405957600080fd5b5061406689828a01613dec565b979a9699509497509295939492505050565b6000806000806060858703121561408e57600080fd5b843561409981613d71565b935060208501356140a981613d71565b925060408501356001600160401b038111156140c457600080fd5b6140d087828801613edc565b95989497509550505050565b63ffffffff81168114610b0257600080fd5b60006020828403121561410057600080fd5b8135612138816140dc565b6000806040838503121561411e57600080fd5b823561412981613d71565b91506020830135613de181613d71565b805463ffffffff8082168452602082811c821690850152604082811c821690850152606082811c821690850152608082811c8216908501525060ff61418860a08501828460a01c1660ff169052565b61419c60c08501828460a81c1660ff169052565b6141b060e08501828460b01c1660ff169052565b6141c56101008501828460b81c1660ff169052565b6141da6101208501828460c01c1660ff169052565b6141ef6101408501828460c81c1660ff169052565b6142046101608501828460d01c1660ff169052565b6142196101808501828460d81c1660ff169052565b61422e6101a08501828460e01c1660ff169052565b6142436101c08501828460e81c1660ff169052565b6142586101e08501828460f01c1660ff169052565b5060f881901c610200840152505050565b61022081016106fe8284614139565b60006020828403121561428a57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156142ba576142ba614291565b500190565b6000828210156142d1576142d1614291565b500390565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261430357600080fd5b8301803591506001600160401b0382111561431d57600080fd5b602001915036819003821315613e2d57600080fd5b60006020828403121561434457600080fd5b815161213881613d71565b634e487b7160e01b600052604160045260246000fd5b815160009082906020808601845b8381101561438f57815185529382019390820190600101614373565b50929695505050505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b602081526000610f0260208301848661439b565b60006001600160fb1b038311156143ee57600080fd5b8260051b80858437600092019182525092915050565b60405161022081016001600160401b038111828210171561443557634e487b7160e01b600052604160045260246000fd5b60405290565b60405160a081016001600160401b038111828210171561443557634e487b7160e01b600052604160045260246000fd5b60098110610b0257600080fd5b60006080828403121561448a57600080fd5b604051608081018181106001600160401b03821117156144ba57634e487b7160e01b600052604160045260246000fd5b60405282516144c88161446b565b81526020830151600581106144dc57600080fd5b602082015260408301516144ef8161446b565b604082015260608301516004811061450657600080fd5b60608201529392505050565b634e487b7160e01b600052602160045260246000fd5b60098110610b0257610b02614512565b805161454381614528565b825260208101516005811061455a5761455a614512565b6020830152604081015161456d81614528565b604083015260608101516004811061458757614587614512565b806060840152505050565b608081016106fe8284614538565b60008160001904831182151516156145ba576145ba614291565b500290565b6000826145dc57634e487b7160e01b600052601260045260246000fd5b500490565b600061010060018060a01b038c1683528a6020840152896040840152806060840152614610818401898b61439b565b91505085608083015260ff851660a08301528360c08301528260e08301529a9950505050505050505050565b6102a0810161464b8288614139565b856102208301528461024083015283610260830152826102808301529695505050505050565b8051610e43816140dc565b8051610e4381613e34565b6000610220828403121561469a57600080fd5b6146a2614404565b90506146ad82614671565b81526146bb60208301614671565b60208201526146cc60408301614671565b60408201526146dd60608301614671565b60608201526146ee60808301614671565b60808201526146ff60a0830161467c565b60a082015261471060c0830161467c565b60c082015261472160e0830161467c565b60e082015261010061473481840161467c565b9082015261012061474683820161467c565b9082015261014061475883820161467c565b9082015261016061476a83820161467c565b9082015261018061477c83820161467c565b908201526101a061478e83820161467c565b908201526101c06147a083820161467c565b908201526101e06147b283820161467c565b908201526102006147c483820161467c565b9082015292915050565b60008061024083850312156147e257600080fd5b6147ec8484614687565b915061022083015190509250929050565b805163ffffffff168252602081015161481e602084018263ffffffff169052565b506040810151614836604084018263ffffffff169052565b50606081015161484e606084018263ffffffff169052565b506080810151614866608084018263ffffffff169052565b5060a081015161487b60a084018260ff169052565b5060c081015161489060c084018260ff169052565b5060e08101516148a560e084018260ff169052565b506101008181015160ff90811691840191909152610120808301518216908401526101408083015182169084015261016080830151821690840152610180808301518216908401526101a0808301518216908401526101c0808301518216908401526101e0808301518216908401526102008083015191821681850152905b50505050565b6102c0810161493982866147fd565b614947610220830185614538565b63ffffffff83166102a0830152949350505050565b6000610220828403121561496f57600080fd5b6121388383614687565b610300810161498882886147fd565b614996610220830187614538565b846102a083015263ffffffff84166102c0830152826102e08301529695505050505050565b6000808284036102c08112156149d057600080fd5b6149da8585614687565b925060a061021f19820112156149ef57600080fd5b506149f861443b565b6102208401516001600160801b0381168114614a1357600080fd5b8152610240840151614a24816140dc565b6020820152610260840151614a38816140dc565b6040820152610280840151614a4c816140dc565b60608201526102a0840151614a60816140dc565b6080820152919491935090915050565b60005b83811015614a8b578181015183820152602001614a73565b838111156149245750506000910152565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614ad4816017850160208801614a70565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351614b05816028840160208801614a70565b01602801949350505050565b6020815260008251806020840152614b30816040850160208701614a70565b601f01601f19169190910160400192915050565b600060208284031215614b5657600080fd5b8151801515811461213857600080fd5b600081614b7557614b75614291565b50600019019056fea26469706673582212206639a0f9e5c41916b80db46f2b70892546d7d3f222d130e3c76d1f0d4e71f00164736f6c63430008090033000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c036000000000000000000000000a203b4af1e1fdda5f76bed36a63c7a6ef3e308ff

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102745760003560e01c80638662489c11610151578063bb14d20e116100c3578063d547741f11610087578063d547741f1461063c578063e63ab1e91461064f578063eb9feb7614610676578063f1e42ccd14610689578063f97136af1461069c578063fb1bb9de146106a657600080fd5b8063bb14d20e146105e6578063c10cdf94146105f9578063c9a3911e14610603578063cf2601ca14610616578063d0899bad1461062957600080fd5b80639f729a6e116101155780639f729a6e14610531578063a0f1deb214610544578063a217fddf1461056c578063a408829214610574578063b655d0c41461059b578063baa51f86146105bc57600080fd5b80638662489c146104be57806386907ef3146104d157806387244843146104e45780638ed0462f146104f757806391d148541461051e57600080fd5b806337a96fcd116101ea5780635c975abb116101ae5780635c975abb1461045f5780635dbe47561461046a5780636f23cb191461047d578063718b6c66146104905780638456cb59146104a3578063863325f6146104ab57600080fd5b806337a96fcd146103f757806337d5b5141461040a578063384085b21461041d5780633f4ba83a1461043057806354322d841461043857600080fd5b8063248a9ca31161023c578063248a9ca3146103335780632e85556d146103565780632f2ff15d1461039557806330d863ff146103aa578063356221fc146103bd57806336568abe146103e457600080fd5b806301ffc9a7146102795780630ae5dec7146102a15780630dbb8b10146102c2578063183224ce146102e957806323ed48a214610320575b600080fd5b61028c610287366004613d47565b6106cd565b60405190151581526020015b60405180910390f35b6102b46102af366004613d86565b610704565b604051908152602001610298565b6102b47fd732b487a91d56c42b88fd4b1d271f12f03f244b8857e8b4270cc835dab3dc5981565b6102fc6102f7366004613da3565b6107a4565b60408051825163ffffffff9081168252602093840151169281019290925201610298565b6102b461032e366004613d86565b61084a565b6102b4610341366004613da3565b60009081526065602052604090206001015490565b61037d7f000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c03681565b6040516001600160a01b039091168152602001610298565b6103a86103a3366004613dbc565b61089a565b005b6103a86103b8366004613e43565b6108c4565b6102b47f8585736fef124c318e85f82b5ce4c5d3878b7ff2fff2191b60ef74595a59a7b481565b6103a86103f2366004613dbc565b610941565b6103a8610405366004613d86565b6109bf565b6102b4610418366004613d86565b6109fb565b6103a861042b366004613e43565b610a4b565b6103a8610ad0565b61037d7f000000000000000000000000a203b4af1e1fdda5f76bed36a63c7a6ef3e308ff81565b60975460ff1661028c565b6103a8610478366004613f20565b610b05565b6102b461048b366004613d86565b610e30565b6102b461049e366004613da3565b610e48565b6103a8610f0a565b6103a86104b9366004613f74565b610f3c565b6103a86104cc366004613fed565b6113f8565b6102b46104df366004613da3565b6117ae565b6103a86104f2366004614078565b61180b565b6102b47fcdebdf9373e7e5c847c3e6cb50c46a7442f1e563a69477a7263d23c6f732684981565b61028c61052c366004613dbc565b611fe6565b6102b461053f366004613da3565b612011565b6102b4610552366004613da3565b6000908152620f430e602052604090205463ffffffff1690565b6102b4600081565b6102b47f700a6a86f87f295447af4608d910099313633af610c1fbf9da48c91659ea46f181565b620f430a546000908152620f4309602052604090205463ffffffff166102b4565b61028c6105ca366004613da3565b6000908152620f430e602052604090205463ffffffff16151590565b6102b46105f4366004613d86565b61213f565b620f430a546102b4565b6103a8610611366004613f20565b61218f565b6102b4610624366004613d86565b6124ab565b6102b4610637366004613da3565b6124fb565b6103a861064a366004613dbc565b612556565b6102b47f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b6103a86106843660046140ee565b61257b565b6102b461069736600461410b565b6125ae565b6102b4620f424081565b6102b47f427da25fe773164f88948d3e215c94b6554e2ed5e5f203a821c9f2f6131cf75a81565b60006001600160e01b03198216637965db0b60e01b14806106fe57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6001600160a01b0381166000908152620f430b6020526040808220905163f41a545360e01b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163f41a5453916107549190600401614269565b60206040518083038186803b15801561076c57600080fd5b505af4158015610780573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106fe9190614278565b6040805180820190915260008082526020820152620f430a548211156108115760405162461bcd60e51b815260206004820152601760248201527f496e76616c69642062617365207261746520696e64657800000000000000000060448201526064015b60405180910390fd5b506000908152620f4309602090815260409182902082518084019093525463ffffffff8082168452640100000000909104169082015290565b6001600160a01b0381166000908152620f430b60205260408082209051637d0c0db960e11b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163fa181b72916107549190600401614269565b6000828152606560205260409020600101546108b581612610565b6108bf838361261a565b505050565b6108cc6126a0565b336001600160a01b038a161461091a5760405162461bcd60e51b815260206004820152601360248201527229b2b73232b91034b9903737ba1037bbb732b960691b6044820152606401610808565b610924898a6126e8565b50610936898989898989898989612a2e565b505050505050505050565b6001600160a01b03811633146109b15760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610808565b6109bb8282612ac7565b5050565b7f700a6a86f87f295447af4608d910099313633af610c1fbf9da48c91659ea46f16109e981612610565b6109f16126a0565b6108bf82836126e8565b6001600160a01b0381166000908152620f430b6020526040808220905163547fecb960e01b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163547fecb9916107549190600401614269565b7f700a6a86f87f295447af4608d910099313633af610c1fbf9da48c91659ea46f1610a7581612610565b7fcdebdf9373e7e5c847c3e6cb50c46a7442f1e563a69477a7263d23c6f7326849610a9f81612610565b610aa76126a0565b610ab18b8c6126e8565b50610ac38b8b8b8b8b8b8b8b8b612a2e565b5050505050505050505050565b7f427da25fe773164f88948d3e215c94b6554e2ed5e5f203a821c9f2f6131cf75a610afa81612610565b610b02612b2e565b50565b610b0d6126a0565b610b1a8383836000612b80565b600080610b2685612d11565b91509150610b688286868680806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250612de192505050565b915081620f430b6000876001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505080620f430d6000876001600160a01b03166001600160a01b031681526020019081526020016000206000828254610e2491906142a7565b90915550505050505050565b6000610e3a6126a0565b6106fe82613058565b919050565b6000818152620f430e602052604081205463ffffffff1680610e6f5750620f424092915050565b6000610e7b82426142bf565b604051633bf46d2960e11b81526004810182905290915073ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e906377e8da52906024015b60206040518083038186803b158015610eca57600080fd5b505af4158015610ede573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f029190614278565b949350505050565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a610f3481612610565b610b02613353565b7fd732b487a91d56c42b88fd4b1d271f12f03f244b8857e8b4270cc835dab3dc59610f6681612610565b610f6e6126a0565b8460005b818110156113ee576000888883818110610f8e57610f8e6142d6565b905060200201359050366000878785818110610fac57610fac6142d6565b9050602002810190610fbe91906142ec565b6040516331a9108f60e11b81526004810186905291935091506000906001600160a01b037f000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c0361690636352211e9060240160206040518083038186803b15801561102657600080fd5b505afa15801561103a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061105e9190614332565b905060008061106c83612d11565b604080516001808252818301909252929450909250600091906020808301908036833701905050905086816000815181106110a9576110a96142d6565b6020026020010181815250506110c0838583612de1565b925082620f430b6000866001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505081620f430d6000866001600160a01b03166001600160a01b03168152602001908152602001600020600082825461137c91906142a7565b90915550506040518d90611391908390614365565b6040518091039020856001600160a01b03167f1c3faf66cba9b4c4b916ac285c4e22b9647b7f00eadcb4ca01a5a10b65b18ebc89896040516113d49291906143c4565b60405180910390a487600101975050505050505050610f72565b5050505050505050565b7fd732b487a91d56c42b88fd4b1d271f12f03f244b8857e8b4270cc835dab3dc5961142281612610565b61142a6126a0565b6114378787876001612b80565b60008061144389612d11565b91509150611485828a8a8a80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250612de192505050565b915081620f430b60008b6001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505080620f430d60008b6001600160a01b03166001600160a01b03168152602001908152602001600020600082825461174191906142a7565b90915550506040518690611758908a908a906143d8565b60405180910390208a6001600160a01b03167f1c3faf66cba9b4c4b916ac285c4e22b9647b7f00eadcb4ca01a5a10b65b18ebc888860405161179b9291906143c4565b60405180910390a4505050505050505050565b6000818152620f430e602052604081205463ffffffff16816117d082426142bf565b604051630b21e43b60e31b81526004810182905290915073ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9063590f21d890602401610eb2565b6118136126a0565b336001600160a01b0385161461186b5760405162461bcd60e51b815260206004820152601e60248201527f4f6e6c79206f776e65722063616e207472616e73666572207374616b656400006044820152606401610808565b6118788483836001612b80565b60008061188486612d11565b9150915060008061189487612d11565b9092509050846000816001600160401b038111156118b4576118b461434f565b6040519080825280602002602001820160405280156118dd578160200160208202803683370190505b50905060005b8281101561194d57620f430e60008a8a84818110611903576119036142d6565b6020908102929092013583525081019190915260400160002054825163ffffffff9091169083908390811061193a5761193a6142d6565b60209081029190910101526001016118e3565b5061198c868b8a8a80806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250612de192505050565b955061199b848a8a8a85613390565b935085620f430b60008c6001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505084620f430d60008c6001600160a01b03166001600160a01b031681526020019081526020016000206000828254611c5791906142a7565b9250508190555083620f430b60008b6001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505082620f430d60008b6001600160a01b03166001600160a01b031681526020019081526020016000206000828254611f1891906142a7565b90915550600090505b82811015610ac3577f000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c0366001600160a01b03166342842e0e8c8c8c8c86818110611f6c57611f6c6142d6565b6040516001600160e01b031960e088901b1681526001600160a01b03958616600482015294909316602485015250602090910201356044820152606401600060405180830381600087803b158015611fc357600080fd5b505af1158015611fd7573d6000803e3d6000fd5b50505050806001019050611f21565b60009182526065602090815260408084206001600160a01b0393909316845291905290205460ff1690565b60405163269f5cb960e01b81526004810182905260009081906001600160a01b037f000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c036169063269f5cb99060240160806040518083038186803b15801561207657600080fd5b505afa15801561208a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120ae9190614478565b6040516331e9c30f60e21b815290915073ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9063c7a70c3c906120e8908490600401614592565b60206040518083038186803b15801561210057600080fd5b505af4158015612114573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121389190614278565b9392505050565b6001600160a01b0381166000908152620f430b602052604080822090516372e1603160e11b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163e5c2c062916107549190600401614269565b6121976126a0565b6121a48383836000612b80565b6000806121b085612d11565b90925090506121ed8286868660006040519080825280602002602001820160405280156121e7578160200160208202803683370190505b50613390565b915081620f430b6000876001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff160217905550905050806000146124a4576001600160a01b0385166000908152620f430d602052604081208054839290610e249084906142a7565b5050505050565b6001600160a01b0381166000908152620f430b60205260408082209051637ba0aaf560e11b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9163f74155ea916107549190600401614269565b600061250a620f4240806145a0565b61251383612011565b61251c84610e48565b620f430a546000908152620f4309602052604090205463ffffffff1661254291906145a0565b61254c91906145a0565b6106fe91906145bf565b60008281526065602052604090206001015461257181612610565b6108bf8383612ac7565b7f8585736fef124c318e85f82b5ce4c5d3878b7ff2fff2191b60ef74595a59a7b46125a581612610565b6109bb8261372a565b60006125b86126a0565b336001600160a01b038416146126065760405162461bcd60e51b815260206004820152601360248201527229b2b73232b91034b9903737ba1037bbb732b960691b6044820152606401610808565b61213883836126e8565b610b0281336137d3565b6126248282611fe6565b6109bb5760008281526065602090815260408083206001600160a01b03851684529091529020805460ff1916600117905561265c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60975460ff16156126e65760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610808565b565b6001600160a01b0382166000908152620f430d6020526040812054818061270e86612d11565b9150915081620f430b6000886001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff1602179055509050506000620f430d6000886001600160a01b03166001600160a01b0316815260200190815260200160002081905550600081846129d091906142a7565b905060006129de878361382c565b9050876001600160a01b03167f2d5429efdeca7741a8cd94067b18d988bc4e5f1d5b8272c37b7bfc31e9bfa32c82604051612a1b91815260200190565b60405180910390a2979650505050505050565b604051636380303360e11b81526001600160a01b037f000000000000000000000000a203b4af1e1fdda5f76bed36a63c7a6ef3e308ff169063c700606690612a8a908c908c908c908c908c908c908c908c908c906004016145e1565b600060405180830381600087803b158015612aa457600080fd5b505af1158015612ab8573d6000803e3d6000fd5b50505050505050505050505050565b612ad18282611fe6565b156109bb5760008281526065602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b612b366138e7565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b336001600160a01b03851681148360005b818110156113ee576000878783818110612bad57612bad6142d6565b905060200201359050886001600160a01b03167f000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c0366001600160a01b0316636352211e836040518263ffffffff1660e01b8152600401612c0e91815260200190565b60206040518083038186803b158015612c2657600080fd5b505afa158015612c3a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c5e9190614332565b6001600160a01b031614612ca25760405162461bcd60e51b815260206004820152600b60248201526a2bb937b7339037bbb732b960a91b6044820152606401610808565b8580612cab5750835b80612cbc5750612cbc858a83613930565b612d085760405162461bcd60e51b815260206004820152601f60248201527f4e6f7420617574686f72697a656420746f207374616b652f756e7374616b65006044820152606401610808565b50600101612b91565b612d19613cbb565b6001600160a01b0382166000908152620f430b60209081526040808320620f430c909252808320620f430a5491516324e948eb60e21b815273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e936393a523ac93612d86939192620f43099291620f430e9160040161463c565b6102406040518083038186803b158015612d9f57600080fd5b505af4158015612db3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612dd791906147ce565b9094909350915050565b612de9613cbb565b508051839060005b8181101561304f576000848281518110612e0d57612e0d6142d6565b6020908102919091018101516000818152620f430e835260409081902081518083019092525463ffffffff808216808452640100000000909204169382019390935290925090612e8c5760405162461bcd60e51b815260206004820152600a602482015269139bdd081cdd185ad95960b21b6044820152606401610808565b73ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e637726dc4f867f000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c0366001600160a01b031663269f5cb9866040518263ffffffff1660e01b8152600401612ef591815260200190565b60806040518083038186803b158015612f0d57600080fd5b505afa158015612f21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f459190614478565b84516040516001600160e01b031960e086901b168152612f6a9392919060040161492a565b6102206040518083038186803b158015612f8357600080fd5b505af4158015612f97573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fbb919061495c565b604080518082018252600080825260208581015160010163ffffffff908116828501908152888452620f430e90925284832093518454925182166401000000000267ffffffffffffffff1990931691161717909155905191965083916001600160a01b038a16917f0f5bb82176feb1b5e747e28471aa92156a04d9f3ab9f45f28e2d704232b93f7591a35050600101612df1565b50509392505050565b6001600160a01b0381166000908152620f430d6020526040812054818061307e85612d11565b9092509050600061308f82856142a7565b905082620f430b6000886001600160a01b03166001600160a01b0316815260200190815260200160002060008201518160000160006101000a81548163ffffffff021916908363ffffffff16021790555060208201518160000160046101000a81548163ffffffff021916908363ffffffff16021790555060408201518160000160086101000a81548163ffffffff021916908363ffffffff160217905550606082015181600001600c6101000a81548163ffffffff021916908363ffffffff16021790555060808201518160000160106101000a81548163ffffffff021916908363ffffffff16021790555060a08201518160000160146101000a81548160ff021916908360ff16021790555060c08201518160000160156101000a81548160ff021916908360ff16021790555060e08201518160000160166101000a81548160ff021916908360ff1602179055506101008201518160000160176101000a81548160ff021916908360ff1602179055506101208201518160000160186101000a81548160ff021916908360ff1602179055506101408201518160000160196101000a81548160ff021916908360ff16021790555061016082015181600001601a6101000a81548160ff021916908360ff16021790555061018082015181600001601b6101000a81548160ff021916908360ff1602179055506101a082015181600001601c6101000a81548160ff021916908360ff1602179055506101c082015181600001601d6101000a81548160ff021916908360ff1602179055506101e082015181600001601e6101000a81548160ff021916908360ff16021790555061020082015181600001601f6101000a81548160ff021916908360ff16021790555090505080620f430d6000886001600160a01b03166001600160a01b031681526020019081526020016000208190555061334981613a96565b9695505050505050565b61335b6126a0565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258612b633390565b613398613cbb565b50848260005b8181101561371f5760008686838181106133ba576133ba6142d6565b602090810292909201356000818152620f430e845260409081902081518083019092525463ffffffff80821680845264010000000090920416948201949094529093509115905061343e5760405162461bcd60e51b815260206004820152600e60248201526d105b1c9958591e481cdd185ad95960921b6044820152606401610808565b60008087511161344e5742613469565b868481518110613460576134606142d6565b60200260200101515b6040805160a081018252600080825260208201819052818301819052606082018190526080820152905163269f5cb960e01b8152600481018690529192509073ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e90633ad9726c9089906001600160a01b037f000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c036169063269f5cb99060240160806040518083038186803b15801561351257600080fd5b505afa158015613526573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061354a9190614478565b858760200151896040518663ffffffff1660e01b8152600401613571959493929190614979565b6102c06040518083038186803b15801561358a57600080fd5b505af415801561359e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135c291906149bb565b6080810151919850915063ffffffff161561369e576001600160a01b038b166000908152620f430c6020908152604091829020825163c6043c7760e01b8152600481019190915283516001600160801b031660248201529083015163ffffffff90811660448301529183015182166064820152606083015182166084820152608083015190911660a482015273ac25c2fb42b08ebab4d185efe4f9c8a430d97b1e9063c6043c779060c40160006040518083038186803b15801561368557600080fd5b505af4158015613699573d6000803e3d6000fd5b505050505b6136a782613aa5565b6000858152620f430e6020908152604091829020805463ffffffff191663ffffffff94909416939093179092555183815285916001600160a01b038e16917f1449c6dd7851abc30abf37f57715f492010519147cc2652fbc38202c18a6ee90910160405180910390a38460010194505050505061339e565b505095945050505050565b60405180604001604052808263ffffffff16815260200161374a42613aa5565b63ffffffff908116909152620f430a8054600101908190556000908152620f43096020908152604091829020845181549583015185166401000000000267ffffffffffffffff1990961690851617949094179093555190831681527f16bacabd495cd45d904b6dc6184eabc5a6d654a4ee84569a5489ee7b20bc4364910160405180910390a150565b6137dd8282611fe6565b6109bb576137ea81613b0e565b6137f5836020613b20565b604051602001613806929190614a9c565b60408051601f198184030181529082905262461bcd60e51b825261080891600401614b11565b60008061383883613a96565b60405163a9059cbb60e01b81526001600160a01b038681166004830152602482018390529192507f000000000000000000000000a203b4af1e1fdda5f76bed36a63c7a6ef3e308ff9091169063a9059cbb90604401602060405180830381600087803b1580156138a757600080fd5b505af11580156138bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138df9190614b44565b509392505050565b60975460ff166126e65760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610808565b60405163e985e9c560e01b81526001600160a01b03838116600483015284811660248301526000917f000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c0369091169063e985e9c59060440160206040518083038186803b15801561399e57600080fd5b505afa1580156139b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139d69190614b44565b80610f025750836001600160a01b03167f000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c0366001600160a01b031663081812fc846040518263ffffffff1660e01b8152600401613a3491815260200190565b60206040518083038186803b158015613a4c57600080fd5b505afa158015613a60573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a849190614332565b6001600160a01b031614949350505050565b60006106fe620f4240836145a0565b600063ffffffff821115613b0a5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b6064820152608401610808565b5090565b60606106fe6001600160a01b03831660145b60606000613b2f8360026145a0565b613b3a9060026142a7565b6001600160401b03811115613b5157613b5161434f565b6040519080825280601f01601f191660200182016040528015613b7b576020820181803683370190505b509050600360fc1b81600081518110613b9657613b966142d6565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110613bc557613bc56142d6565b60200101906001600160f81b031916908160001a9053506000613be98460026145a0565b613bf49060016142a7565b90505b6001811115613c6c576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110613c2857613c286142d6565b1a60f81b828281518110613c3e57613c3e6142d6565b60200101906001600160f81b031916908160001a90535060049490941c93613c6581614b66565b9050613bf7565b5083156121385760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610808565b6040805161022081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081018290526101c081018290526101e0810182905261020081019190915290565b600060208284031215613d5957600080fd5b81356001600160e01b03198116811461213857600080fd5b6001600160a01b0381168114610b0257600080fd5b600060208284031215613d9857600080fd5b813561213881613d71565b600060208284031215613db557600080fd5b5035919050565b60008060408385031215613dcf57600080fd5b823591506020830135613de181613d71565b809150509250929050565b60008083601f840112613dfe57600080fd5b5081356001600160401b03811115613e1557600080fd5b602083019150836020828501011115613e2d57600080fd5b9250929050565b60ff81168114610b0257600080fd5b60008060008060008060008060006101008a8c031215613e6257600080fd5b8935613e6d81613d71565b985060208a0135975060408a0135965060608a01356001600160401b03811115613e9657600080fd5b613ea28c828d01613dec565b90975095505060808a0135935060a08a0135613ebd81613e34565b8093505060c08a0135915060e08a013590509295985092959850929598565b60008083601f840112613eee57600080fd5b5081356001600160401b03811115613f0557600080fd5b6020830191508360208260051b8501011115613e2d57600080fd5b600080600060408486031215613f3557600080fd5b8335613f4081613d71565b925060208401356001600160401b03811115613f5b57600080fd5b613f6786828701613edc565b9497909650939450505050565b600080600080600060608688031215613f8c57600080fd5b85356001600160401b0380821115613fa357600080fd5b613faf89838a01613edc565b9097509550602088013594506040880135915080821115613fcf57600080fd5b50613fdc88828901613edc565b969995985093965092949392505050565b6000806000806000806080878903121561400657600080fd5b863561401181613d71565b955060208701356001600160401b038082111561402d57600080fd5b6140398a838b01613edc565b909750955060408901359450606089013591508082111561405957600080fd5b5061406689828a01613dec565b979a9699509497509295939492505050565b6000806000806060858703121561408e57600080fd5b843561409981613d71565b935060208501356140a981613d71565b925060408501356001600160401b038111156140c457600080fd5b6140d087828801613edc565b95989497509550505050565b63ffffffff81168114610b0257600080fd5b60006020828403121561410057600080fd5b8135612138816140dc565b6000806040838503121561411e57600080fd5b823561412981613d71565b91506020830135613de181613d71565b805463ffffffff8082168452602082811c821690850152604082811c821690850152606082811c821690850152608082811c8216908501525060ff61418860a08501828460a01c1660ff169052565b61419c60c08501828460a81c1660ff169052565b6141b060e08501828460b01c1660ff169052565b6141c56101008501828460b81c1660ff169052565b6141da6101208501828460c01c1660ff169052565b6141ef6101408501828460c81c1660ff169052565b6142046101608501828460d01c1660ff169052565b6142196101808501828460d81c1660ff169052565b61422e6101a08501828460e01c1660ff169052565b6142436101c08501828460e81c1660ff169052565b6142586101e08501828460f01c1660ff169052565b5060f881901c610200840152505050565b61022081016106fe8284614139565b60006020828403121561428a57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b600082198211156142ba576142ba614291565b500190565b6000828210156142d1576142d1614291565b500390565b634e487b7160e01b600052603260045260246000fd5b6000808335601e1984360301811261430357600080fd5b8301803591506001600160401b0382111561431d57600080fd5b602001915036819003821315613e2d57600080fd5b60006020828403121561434457600080fd5b815161213881613d71565b634e487b7160e01b600052604160045260246000fd5b815160009082906020808601845b8381101561438f57815185529382019390820190600101614373565b50929695505050505050565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b602081526000610f0260208301848661439b565b60006001600160fb1b038311156143ee57600080fd5b8260051b80858437600092019182525092915050565b60405161022081016001600160401b038111828210171561443557634e487b7160e01b600052604160045260246000fd5b60405290565b60405160a081016001600160401b038111828210171561443557634e487b7160e01b600052604160045260246000fd5b60098110610b0257600080fd5b60006080828403121561448a57600080fd5b604051608081018181106001600160401b03821117156144ba57634e487b7160e01b600052604160045260246000fd5b60405282516144c88161446b565b81526020830151600581106144dc57600080fd5b602082015260408301516144ef8161446b565b604082015260608301516004811061450657600080fd5b60608201529392505050565b634e487b7160e01b600052602160045260246000fd5b60098110610b0257610b02614512565b805161454381614528565b825260208101516005811061455a5761455a614512565b6020830152604081015161456d81614528565b604083015260608101516004811061458757614587614512565b806060840152505050565b608081016106fe8284614538565b60008160001904831182151516156145ba576145ba614291565b500290565b6000826145dc57634e487b7160e01b600052601260045260246000fd5b500490565b600061010060018060a01b038c1683528a6020840152896040840152806060840152614610818401898b61439b565b91505085608083015260ff851660a08301528360c08301528260e08301529a9950505050505050505050565b6102a0810161464b8288614139565b856102208301528461024083015283610260830152826102808301529695505050505050565b8051610e43816140dc565b8051610e4381613e34565b6000610220828403121561469a57600080fd5b6146a2614404565b90506146ad82614671565b81526146bb60208301614671565b60208201526146cc60408301614671565b60408201526146dd60608301614671565b60608201526146ee60808301614671565b60808201526146ff60a0830161467c565b60a082015261471060c0830161467c565b60c082015261472160e0830161467c565b60e082015261010061473481840161467c565b9082015261012061474683820161467c565b9082015261014061475883820161467c565b9082015261016061476a83820161467c565b9082015261018061477c83820161467c565b908201526101a061478e83820161467c565b908201526101c06147a083820161467c565b908201526101e06147b283820161467c565b908201526102006147c483820161467c565b9082015292915050565b60008061024083850312156147e257600080fd5b6147ec8484614687565b915061022083015190509250929050565b805163ffffffff168252602081015161481e602084018263ffffffff169052565b506040810151614836604084018263ffffffff169052565b50606081015161484e606084018263ffffffff169052565b506080810151614866608084018263ffffffff169052565b5060a081015161487b60a084018260ff169052565b5060c081015161489060c084018260ff169052565b5060e08101516148a560e084018260ff169052565b506101008181015160ff90811691840191909152610120808301518216908401526101408083015182169084015261016080830151821690840152610180808301518216908401526101a0808301518216908401526101c0808301518216908401526101e0808301518216908401526102008083015191821681850152905b50505050565b6102c0810161493982866147fd565b614947610220830185614538565b63ffffffff83166102a0830152949350505050565b6000610220828403121561496f57600080fd5b6121388383614687565b610300810161498882886147fd565b614996610220830187614538565b846102a083015263ffffffff84166102c0830152826102e08301529695505050505050565b6000808284036102c08112156149d057600080fd5b6149da8585614687565b925060a061021f19820112156149ef57600080fd5b506149f861443b565b6102208401516001600160801b0381168114614a1357600080fd5b8152610240840151614a24816140dc565b6020820152610260840151614a38816140dc565b6040820152610280840151614a4c816140dc565b60608201526102a0840151614a60816140dc565b6080820152919491935090915050565b60005b83811015614a8b578181015183820152602001614a73565b838111156149245750506000910152565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614ad4816017850160208801614a70565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351614b05816028840160208801614a70565b01602801949350505050565b6020815260008251806020840152614b30816040850160208701614a70565b601f01601f19169190910160400192915050565b600060208284031215614b5657600080fd5b8151801515811461213857600080fd5b600081614b7557614b75614291565b50600019019056fea26469706673582212206639a0f9e5c41916b80db46f2b70892546d7d3f222d130e3c76d1f0d4e71f00164736f6c63430008090033

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

000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c036000000000000000000000000a203b4af1e1fdda5f76bed36a63c7a6ef3e308ff

-----Decoded View---------------
Arg [0] : ikani (address): 0xC232599b4359bEb071b435134AB7AEf3EC78C036
Arg [1] : rewardsErc20 (address): 0xA203b4Af1e1fDDA5F76bEd36a63C7a6ef3E308Ff

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000c232599b4359beb071b435134ab7aef3ec78c036
Arg [1] : 000000000000000000000000a203b4af1e1fdda5f76bed36a63c7a6ef3e308ff


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

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.