ETH Price: $3,286.98 (-1.60%)

Contract

0x5954aB967Bc958940b7EB73ee84797Dc8a2AFbb9
 
Transaction Hash
Method
Block
From
To
Withdraw Self BA...214633292024-12-23 6:14:112 mins ago1734934451IN
Apecoin: Staking
0 ETH0.000523395.86763838
Claim Self BAYC214633242024-12-23 6:13:113 mins ago1734934391IN
Apecoin: Staking
0 ETH0.000745085.63595002
Claim Self MAYC214632272024-12-23 5:53:4722 mins ago1734933227IN
Apecoin: Staking
0 ETH0.00036164.51530487
Claim Self MAYC214631402024-12-23 5:36:2340 mins ago1734932183IN
Apecoin: Staking
0 ETH0.000405565.06426465
Claim Self MAYC214630552024-12-23 5:18:5957 mins ago1734931139IN
Apecoin: Staking
0 ETH0.000304424.8333204
Withdraw Self Ap...214630502024-12-23 5:17:5958 mins ago1734931079IN
Apecoin: Staking
0 ETH0.000473345.02386908
Claim Self Ape C...214630462024-12-23 5:17:111 hrs ago1734931031IN
Apecoin: Staking
0 ETH0.000568075.1036063
Deposit MAYC214628902024-12-23 4:45:591 hr ago1734929159IN
Apecoin: Staking
0 ETH0.000357615.30247564
Claim Self MAYC214628852024-12-23 4:44:591 hr ago1734929099IN
Apecoin: Staking
0 ETH0.000326495.18382013
Claim Self MAYC214628812024-12-23 4:44:111 hr ago1734929051IN
Apecoin: Staking
0 ETH0.000453355.66096825
Claim Self MAYC214628762024-12-23 4:43:111 hr ago1734928991IN
Apecoin: Staking
0 ETH0.000452645.65214947
Withdraw Self Ap...214628602024-12-23 4:39:591 hr ago1734928799IN
Apecoin: Staking
0 ETH0.000447634.02164925
Claim Self MAYC214626712024-12-23 4:01:592 hrs ago1734926519IN
Apecoin: Staking
0 ETH0.000795566.18109345
Deposit BAYC214626692024-12-23 4:01:352 hrs ago1734926495IN
Apecoin: Staking
0 ETH0.000378655.61983554
Claim Self BAYC214626662024-12-23 4:00:592 hrs ago1734926459IN
Apecoin: Staking
0 ETH0.000430135.10462742
Claim Self BAYC214626652024-12-23 4:00:472 hrs ago1734926447IN
Apecoin: Staking
0 ETH0.000693335.2445152
Claim Self MAYC214626532024-12-23 3:58:232 hrs ago1734926303IN
Apecoin: Staking
0 ETH0.000677045.28844924
Deposit MAYC214622672024-12-23 2:40:233 hrs ago1734921623IN
Apecoin: Staking
0 ETH0.000392295.43015141
Claim Self MAYC214622632024-12-23 2:39:233 hrs ago1734921563IN
Apecoin: Staking
0 ETH0.001369425.29535965
Deposit MAYC214622612024-12-23 2:38:593 hrs ago1734921539IN
Apecoin: Staking
0 ETH0.00039035.40261379
Claim Self BAYC214622552024-12-23 2:37:473 hrs ago1734921467IN
Apecoin: Staking
0 ETH0.001027645.58586264
Claim Self BAKC214622532024-12-23 2:37:233 hrs ago1734921443IN
Apecoin: Staking
0 ETH0.000948535.89433705
Claim Self MAYC214622502024-12-23 2:36:473 hrs ago1734921407IN
Apecoin: Staking
0 ETH0.001191095.95992527
Claim Self BAYC214622462024-12-23 2:35:593 hrs ago1734921359IN
Apecoin: Staking
0 ETH0.000767465.80520761
Withdraw BAYC214620582024-12-23 1:58:234 hrs ago1734919103IN
Apecoin: Staking
0 ETH0.000668417.79041745
View all transactions

Latest 1 internal transaction

Advanced mode:
Parent Transaction Hash Block
From
To
177939212023-07-28 20:26:11513 days ago1690575971
Apecoin: Staking
0.01013339 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ApeCoinStaking

Compiler Version
v0.8.10+commit.fc410830

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 15 : ApeCoinStaking.sol
//SPDX-License-Identifier: MIT

/*
ApeStake Smart Contract Disclaimer

The ApeStake smart contract (the “Smart Contract”) was developed at the direction of the ApeCoin DAO community pursuant
to a grant by the Ape Foundation.  The grant instructs the development of the Smart Contract and the developer’s user
interface to enable a non-exclusive, user friendly means of access to the rewards program offered to the APE community
by the Ape Foundation pursuant to the specifications set forth in AIPs 21/22. The Smart Contract is made up of free,
public, open-source or source-available software deployed on the Ethereum Blockchain.

Use Disclaimer.
Your use of the Smart Contract involves various risks, including, but not limited to, losses while digital
assets are being supplied and/or removed from the Smart Contract, losses due to the volatility of token price,
risks in connection with your personal wallet access, system failures, opportunity loss while participating in the
Smart Contract, loss of tokens in connection with non-fungible token transfers, risk of cyber attack and/or security
breach, risk of legal uncertainty and/or changes in legal environment, and additional risks which may be based upon
utilization of any third party other than the Smart Contract developer who provides you with access to the Smart
Contract. Before using the Smart Contract, you should review the relevant documentation to make sure you understand
how the Smart Contract works. Additionally, because you may be able to access the Smart Contract through other web or
mobile interfaces than the Smart Contract developer’s user interface provided pursuant to the Ape Foundation grant,
you are responsible for doing your own diligence on those interfaces to understand the fees and risks they present.

THE SMART CONTRACT IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
The developer was contracted by APE Foundation to develop the initial code to implement AIP 21/22.
The developer does not own or control the staking rewards program, which is run on the Smart Contracts deployed on
the Ethereum blockchain.  Upgrades and modifications will be managed in a community-driven way by holders of the APE
governance token and may be undertaken and/or implemented with no involvement of the developer.

No liability.
No developer or entity involved in creating the Smart Contract or “platform as a service” will be liable for any
claims or damages whatsoever associated with your use, inability to use, or your interaction with the Smart Contract
or the developer’s user interface provided pursuant to the Ape Foundation grant, including any direct, indirect,
incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens,
or anything else of value.

Access to Third Parties.
Any party who uses or provides access to the Smart Contract to third parties must (a) not provide such access in
violation of any applicable law or regulation, (b) inform such third parties of any and all risks, and (c) is solely
responsible to such third parties for any and all liability, claims or damages relating to such party’s provision of
access to the Smart Contract.
*/
pragma solidity 0.8.10;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";

/**
 * @title ApeCoin Staking Contract
 * @notice Stake ApeCoin across four different pools that release hourly rewards
 * @author HorizenLabs
 */
contract ApeCoinStaking is Ownable {

    using SafeCast for uint256;
    using SafeCast for int256;

    /// @notice State for ApeCoin, BAYC, MAYC, and Pair Pools
    struct Pool {
        uint48 lastRewardedTimestampHour;
        uint16 lastRewardsRangeIndex;
        uint96 stakedAmount;
        uint96 accumulatedRewardsPerShare;
        TimeRange[] timeRanges;
    }

    /// @notice Pool rules valid for a given duration of time.
    /// @dev All TimeRange timestamp values must represent whole hours
    struct TimeRange {
        uint48 startTimestampHour;
        uint48 endTimestampHour;
        uint96 rewardsPerHour;
        uint96 capPerPosition;
    }

    /// @dev Convenience struct for front-end applications
    struct PoolUI {
        uint256 poolId;
        uint256 stakedAmount;
        TimeRange currentTimeRange;
    }

    /// @dev Per address amount and reward tracking
    struct Position {
        uint256 stakedAmount;
        int256 rewardsDebt;
    }
    mapping (address => Position) public addressPosition;

    /// @dev Struct for depositing and withdrawing from the BAYC and MAYC NFT pools
    struct SingleNft {
        uint32 tokenId;
        uint224 amount;
    }
    /// @dev Struct for depositing from the BAKC (Pair) pool
    struct PairNftDepositWithAmount {
        uint32 mainTokenId;
        uint32 bakcTokenId;
        uint184 amount;
    }
    /// @dev Struct for withdrawing from the BAKC (Pair) pool
    struct PairNftWithdrawWithAmount {
        uint32 mainTokenId;
        uint32 bakcTokenId;
        uint184 amount;
        bool isUncommit;
    }
    /// @dev Struct for claiming from an NFT pool
    struct PairNft {
        uint128 mainTokenId;
        uint128 bakcTokenId;
    }
    /// @dev NFT paired status.  Can be used bi-directionally (BAYC/MAYC -> BAKC) or (BAKC -> BAYC/MAYC)
    struct PairingStatus {
        uint248 tokenId;
        bool isPaired;
    }

    // @dev UI focused payload
    struct DashboardStake {
        uint256 poolId;
        uint256 tokenId;
        uint256 deposited;
        uint256 unclaimed;
        uint256 rewards24hr;
        DashboardPair pair;
    }
    /// @dev Sub struct for DashboardStake
    struct DashboardPair {
        uint256 mainTokenId;
        uint256 mainTypePoolId;
    }
    /// @dev Placeholder for pair status, used by ApeCoin Pool
    DashboardPair private NULL_PAIR = DashboardPair(0, 0);

    /// @notice Internal ApeCoin amount for distributing staking reward claims
    IERC20 public immutable apeCoin;
    uint256 private constant APE_COIN_PRECISION = 1e18;
    uint256 private constant MIN_DEPOSIT = 1 * APE_COIN_PRECISION;
    uint256 private constant SECONDS_PER_HOUR = 3600;
    uint256 private constant SECONDS_PER_MINUTE = 60;

    uint256 constant APECOIN_POOL_ID = 0;
    uint256 constant BAYC_POOL_ID = 1;
    uint256 constant MAYC_POOL_ID = 2;
    uint256 constant BAKC_POOL_ID = 3;
    Pool[4] public pools;

    /// @dev NFT contract mapping per pool
    mapping(uint256 => ERC721Enumerable) public nftContracts;
    /// @dev poolId => tokenId => nft position
    mapping(uint256 => mapping(uint256 => Position)) public nftPosition;
    /// @dev main type pool ID: 1: BAYC 2: MAYC => main token ID => bakc token ID
    mapping(uint256 => mapping(uint256 => PairingStatus)) public mainToBakc;
    /// @dev bakc Token ID => main type pool ID: 1: BAYC 2: MAYC => main token ID
    mapping(uint256 => mapping(uint256 => PairingStatus)) public bakcToMain;

    /** Custom Events */
    event UpdatePool(
        uint256 indexed poolId,
        uint256 lastRewardedBlock,
        uint256 stakedAmount,
        uint256 accumulatedRewardsPerShare
    );
    event Deposit(
        address indexed user,
        uint256 amount,
        address recipient
    );
    event DepositNft(
        address indexed user,
        uint256 indexed poolId,
        uint256 amount,
        uint256 tokenId
    );
    event DepositPairNft(
        address indexed user,
        uint256 amount,
        uint256 mainTypePoolId,
        uint256 mainTokenId,
        uint256 bakcTokenId
    );
    event Withdraw(
        address indexed user,
        uint256 amount,
        address recipient
    );
    event WithdrawNft(
        address indexed user,
        uint256 indexed poolId,
        uint256 amount,
        address recipient,
        uint256 tokenId
    );
    event WithdrawPairNft(
        address indexed user,
        uint256 amount,
        uint256 mainTypePoolId,
        uint256 mainTokenId,
        uint256 bakcTokenId
    );
    event ClaimRewards(
        address indexed user,
        uint256 amount,
        address recipient
    );
    event ClaimRewardsNft(
        address indexed user,
        uint256 indexed poolId,
        uint256 amount,
        uint256 tokenId
    );
    event ClaimRewardsPairNft(
        address indexed user,
        uint256 amount,
        uint256 mainTypePoolId,
        uint256 mainTokenId,
        uint256 bakcTokenId
    );

    error DepositMoreThanOneAPE();
    error InvalidPoolId();
    error StartMustBeGreaterThanEnd();
    error StartNotWholeHour();
    error EndNotWholeHour();
    error StartMustEqualLastEnd();
    error CallerNotOwner();
    error MainTokenNotOwnedOrPaired();
    error BAKCNotOwnedOrPaired();
    error BAKCAlreadyPaired();
    error ExceededCapAmount();
    error NotOwnerOfMain();
    error NotOwnerOfBAKC();
    error ProvidedTokensNotPaired();
    error ExceededStakedAmount();
    error NeitherTokenInPairOwnedByCaller();
    error SplitPairCantPartiallyWithdraw();
    error UncommitWrongParameters();

    /**
     * @notice Construct a new ApeCoinStaking instance
     * @param _apeCoinContractAddress The ApeCoin ERC20 contract address
     * @param _baycContractAddress The BAYC NFT contract address
     * @param _maycContractAddress The MAYC NFT contract address
     * @param _bakcContractAddress The BAKC NFT contract address
     */
    constructor(
        address _apeCoinContractAddress,
        address _baycContractAddress,
        address _maycContractAddress,
        address _bakcContractAddress
    ) {
        apeCoin = IERC20(_apeCoinContractAddress);
        nftContracts[BAYC_POOL_ID] = ERC721Enumerable(_baycContractAddress);
        nftContracts[MAYC_POOL_ID] = ERC721Enumerable(_maycContractAddress);
        nftContracts[BAKC_POOL_ID] = ERC721Enumerable(_bakcContractAddress);
    }

    // Deposit/Commit Methods

    /**
     * @notice Deposit ApeCoin to the ApeCoin Pool
     * @param _amount Amount in ApeCoin
     * @param _recipient Address the deposit it stored to
     * @dev ApeCoin deposit must be >= 1 ApeCoin
     */
    function depositApeCoin(uint256 _amount, address _recipient) public {
        if (_amount < MIN_DEPOSIT) revert DepositMoreThanOneAPE();
        updatePool(APECOIN_POOL_ID);

        Position storage position = addressPosition[_recipient];
        _deposit(APECOIN_POOL_ID, position, _amount);

        apeCoin.transferFrom(msg.sender, address(this), _amount);

        emit Deposit(msg.sender, _amount, _recipient);
    }

    /**
     * @notice Deposit ApeCoin to the ApeCoin Pool
     * @param _amount Amount in ApeCoin
     * @dev Deposit on behalf of msg.sender. ApeCoin deposit must be >= 1 ApeCoin
     */
    function depositSelfApeCoin(uint256 _amount) external {
        depositApeCoin(_amount, msg.sender);
    }

    /**
     * @notice Deposit ApeCoin to the BAYC Pool
     * @param _nfts Array of SingleNft structs
     * @dev Commits 1 or more BAYC NFTs, each with an ApeCoin amount to the BAYC pool.\
     * Each BAYC committed must attach an ApeCoin amount >= 1 ApeCoin and <= the BAYC pool cap amount.
     */
    function depositBAYC(SingleNft[] calldata _nfts) external {
        _depositNft(BAYC_POOL_ID, _nfts);
    }

    /**
     * @notice Deposit ApeCoin to the MAYC Pool
     * @param _nfts Array of SingleNft structs
     * @dev Commits 1 or more MAYC NFTs, each with an ApeCoin amount to the MAYC pool.\
     * Each MAYC committed must attach an ApeCoin amount >= 1 ApeCoin and <= the MAYC pool cap amount.
     */
    function depositMAYC(SingleNft[] calldata _nfts) external {
        _depositNft(MAYC_POOL_ID, _nfts);
    }

    /**
     * @notice Deposit ApeCoin to the Pair Pool, where Pair = (BAYC + BAKC) or (MAYC + BAKC)
     * @param _baycPairs Array of PairNftDepositWithAmount structs
     * @param _maycPairs Array of PairNftDepositWithAmount structs
     * @dev Commits 1 or more Pairs, each with an ApeCoin amount to the Pair pool.\
     * Each BAKC committed must attach an ApeCoin amount >= 1 ApeCoin and <= the Pair pool cap amount.\
     * Example 1: BAYC + BAKC + 1 ApeCoin:  [[0, 0, "1000000000000000000"],[]]\
     * Example 2: MAYC + BAKC + 1 ApeCoin:  [[], [0, 0, "1000000000000000000"]]\
     * Example 3: (BAYC + BAKC + 1 ApeCoin) and (MAYC + BAKC + 1 ApeCoin): [[0, 0, "1000000000000000000"], [0, 1, "1000000000000000000"]]
     */
    function depositBAKC(PairNftDepositWithAmount[] calldata _baycPairs, PairNftDepositWithAmount[] calldata _maycPairs) external {
        updatePool(BAKC_POOL_ID);
        _depositPairNft(BAYC_POOL_ID, _baycPairs);
        _depositPairNft(MAYC_POOL_ID, _maycPairs);
    }

    // Claim Rewards Methods

    /**
     * @notice Claim rewards for msg.sender and send to recipient
     * @param _recipient Address to send claim reward to
     */
    function claimApeCoin(address _recipient) public {
        updatePool(APECOIN_POOL_ID);

        Position storage position = addressPosition[msg.sender];
        uint256 rewardsToBeClaimed = _claim(APECOIN_POOL_ID, position, _recipient);

        emit ClaimRewards(msg.sender, rewardsToBeClaimed, _recipient);
    }

    /// @notice Claim and send rewards
    function claimSelfApeCoin() external {
        claimApeCoin(msg.sender);
    }

    /**
     * @notice Claim rewards for array of BAYC NFTs and send to recipient
     * @param _nfts Array of NFTs owned and committed by the msg.sender
     * @param _recipient Address to send claim reward to
     */
    function claimBAYC(uint256[] calldata _nfts, address _recipient) external {
        _claimNft(BAYC_POOL_ID, _nfts, _recipient);
    }

    /**
     * @notice Claim rewards for array of BAYC NFTs
     * @param _nfts Array of NFTs owned and committed by the msg.sender
     */
    function claimSelfBAYC(uint256[] calldata _nfts) external {
        _claimNft(BAYC_POOL_ID, _nfts, msg.sender);
    }

    /**
     * @notice Claim rewards for array of MAYC NFTs and send to recipient
     * @param _nfts Array of NFTs owned and committed by the msg.sender
     * @param _recipient Address to send claim reward to
     */
    function claimMAYC(uint256[] calldata _nfts, address _recipient) external {
        _claimNft(MAYC_POOL_ID, _nfts, _recipient);
    }

    /**
     * @notice Claim rewards for array of MAYC NFTs
     * @param _nfts Array of NFTs owned and committed by the msg.sender
     */
    function claimSelfMAYC(uint256[] calldata _nfts) external {
        _claimNft(MAYC_POOL_ID, _nfts, msg.sender);
    }

    /**
     * @notice Claim rewards for array of Paired NFTs and send to recipient
     * @param _baycPairs Array of Paired BAYC NFTs owned and committed by the msg.sender
     * @param _maycPairs Array of Paired MAYC NFTs owned and committed by the msg.sender
     * @param _recipient Address to send claim reward to
     */
    function claimBAKC(PairNft[] calldata _baycPairs, PairNft[] calldata _maycPairs, address _recipient) public {
        updatePool(BAKC_POOL_ID);
        _claimPairNft(BAYC_POOL_ID, _baycPairs, _recipient);
        _claimPairNft(MAYC_POOL_ID, _maycPairs, _recipient);
    }

    /**
     * @notice Claim rewards for array of Paired NFTs
     * @param _baycPairs Array of Paired BAYC NFTs owned and committed by the msg.sender
     * @param _maycPairs Array of Paired MAYC NFTs owned and committed by the msg.sender
     */
    function claimSelfBAKC(PairNft[] calldata _baycPairs, PairNft[] calldata _maycPairs) external {
        claimBAKC(_baycPairs, _maycPairs, msg.sender);
    }

    // Uncommit/Withdraw Methods

    /**
     * @notice Withdraw staked ApeCoin from the ApeCoin pool.  Performs an automatic claim as part of the withdraw process.
     * @param _amount Amount of ApeCoin
     * @param _recipient Address to send withdraw amount and claim to
     */
    function withdrawApeCoin(uint256 _amount, address _recipient) public {
        updatePool(APECOIN_POOL_ID);

        Position storage position = addressPosition[msg.sender];
        if (_amount == position.stakedAmount) {
            uint256 rewardsToBeClaimed = _claim(APECOIN_POOL_ID, position, _recipient);
            emit ClaimRewards(msg.sender, rewardsToBeClaimed, _recipient);
        }
        _withdraw(APECOIN_POOL_ID, position, _amount);

        apeCoin.transfer(_recipient, _amount);

        emit Withdraw(msg.sender, _amount, _recipient);
    }

    /**
     * @notice Withdraw staked ApeCoin from the ApeCoin pool.  If withdraw is total staked amount, performs an automatic claim.
     * @param _amount Amount of ApeCoin
     */
    function withdrawSelfApeCoin(uint256 _amount) external {
        withdrawApeCoin(_amount, msg.sender);
    }

    /**
     * @notice Withdraw staked ApeCoin from the BAYC pool.  If withdraw is total staked amount, performs an automatic claim.
     * @param _nfts Array of BAYC NFT's with staked amounts
     * @param _recipient Address to send withdraw amount and claim to
     */
    function withdrawBAYC(SingleNft[] calldata _nfts, address _recipient) external {
        _withdrawNft(BAYC_POOL_ID, _nfts, _recipient);
    }

    /**
     * @notice Withdraw staked ApeCoin from the BAYC pool.  If withdraw is total staked amount, performs an automatic claim.
     * @param _nfts Array of BAYC NFT's with staked amounts
     */
    function withdrawSelfBAYC(SingleNft[] calldata _nfts) external {
        _withdrawNft(BAYC_POOL_ID, _nfts, msg.sender);
    }

    /**
     * @notice Withdraw staked ApeCoin from the MAYC pool.  If withdraw is total staked amount, performs an automatic claim.
     * @param _nfts Array of MAYC NFT's with staked amounts
     * @param _recipient Address to send withdraw amount and claim to
     */
    function withdrawMAYC(SingleNft[] calldata _nfts, address _recipient) external {
        _withdrawNft(MAYC_POOL_ID, _nfts, _recipient);
    }

    /**
     * @notice Withdraw staked ApeCoin from the MAYC pool.  If withdraw is total staked amount, performs an automatic claim.
     * @param _nfts Array of MAYC NFT's with staked amounts
     */
    function withdrawSelfMAYC(SingleNft[] calldata _nfts) external {
        _withdrawNft(MAYC_POOL_ID, _nfts, msg.sender);
    }

    /**
     * @notice Withdraw staked ApeCoin from the Pair pool.  If withdraw is total staked amount, performs an automatic claim.
     * @param _baycPairs Array of Paired BAYC NFT's with staked amounts and isUncommit boolean
     * @param _maycPairs Array of Paired MAYC NFT's with staked amounts and isUncommit boolean
     * @dev if pairs have split ownership and BAKC is attempting a withdraw, the withdraw must be for the total staked amount
     */
    function withdrawBAKC(PairNftWithdrawWithAmount[] calldata _baycPairs, PairNftWithdrawWithAmount[] calldata _maycPairs) external {
        updatePool(BAKC_POOL_ID);
        _withdrawPairNft(BAYC_POOL_ID, _baycPairs);
        _withdrawPairNft(MAYC_POOL_ID, _maycPairs);
    }

    // Time Range Methods

    /**
     * @notice Add single time range with a given rewards per hour for a given pool
     * @dev In practice one Time Range will represent one quarter (defined by `_startTimestamp`and `_endTimeStamp` as whole hours)
     * where the rewards per hour is constant for a given pool.
     * @param _poolId Available pool values 0-3
     * @param _amount Total amount of ApeCoin to be distributed over the range
     * @param _startTimestamp Whole hour timestamp representation
     * @param _endTimeStamp Whole hour timestamp representation
     * @param _capPerPosition Per position cap amount determined by poolId
     */
    function addTimeRange(
        uint256 _poolId,
        uint256 _amount,
        uint256 _startTimestamp,
        uint256 _endTimeStamp,
        uint256 _capPerPosition) external onlyOwner
    {
        if (_poolId > BAKC_POOL_ID) revert InvalidPoolId();
        if (_startTimestamp >= _endTimeStamp) revert StartMustBeGreaterThanEnd();
        if (getMinute(_startTimestamp) > 0 || getSecond(_startTimestamp) > 0) revert StartNotWholeHour();
        if (getMinute(_endTimeStamp) > 0 || getSecond(_endTimeStamp) > 0) revert EndNotWholeHour();

        Pool storage pool = pools[_poolId];
        uint256 length = pool.timeRanges.length;
        if (length > 0) {
            if (_startTimestamp != pool.timeRanges[length - 1].endTimestampHour) revert StartMustEqualLastEnd();
        }

        uint256 hoursInSeconds = _endTimeStamp - _startTimestamp;
        uint256 rewardsPerHour = _amount * SECONDS_PER_HOUR / hoursInSeconds;

        TimeRange memory next = TimeRange(_startTimestamp.toUint48(), _endTimeStamp.toUint48(),
            rewardsPerHour.toUint96(), _capPerPosition.toUint96());
        pool.timeRanges.push(next);
    }

    /**
     * @notice Removes the last Time Range for a given pool.
     * @param _poolId Available pool values 0-3
     */
    function removeLastTimeRange(uint256 _poolId) external onlyOwner {
        pools[_poolId].timeRanges.pop();
    }

    /**
     * @notice Lookup method for a TimeRange struct
     * @return TimeRange A Pool's timeRanges struct by index.
     * @param _poolId Available pool values 0-3
     * @param _index Target index in a Pool's timeRanges array
     */
    function getTimeRangeBy(uint256 _poolId, uint256 _index) public view returns (TimeRange memory) {
        return pools[_poolId].timeRanges[_index];
    }

    // Pool Methods

    /**
     * @notice Lookup available rewards for a pool over a given time range
     * @return uint256 The amount of ApeCoin rewards to be distributed by pool for a given time range
     * @return uint256 The amount of time ranges
     * @param _poolId Available pool values 0-3
     * @param _from Whole hour timestamp representation
     * @param _to Whole hour timestamp representation
     */
    function rewardsBy(uint256 _poolId, uint256 _from, uint256 _to) public view returns (uint256, uint256) {
        Pool memory pool = pools[_poolId];

        uint256 currentIndex = pool.lastRewardsRangeIndex;
        if(_to < pool.timeRanges[0].startTimestampHour) return (0, currentIndex);

        while(_from > pool.timeRanges[currentIndex].endTimestampHour && _to > pool.timeRanges[currentIndex].endTimestampHour) {
            unchecked {
                ++currentIndex;
            }
        }

        uint256 rewards;
        TimeRange memory current;
        uint256 startTimestampHour;
        uint256 endTimestampHour;
        uint256 length = pool.timeRanges.length;
        for(uint256 i = currentIndex; i < length;) {
            current = pool.timeRanges[i];
            startTimestampHour = _from <= current.startTimestampHour ? current.startTimestampHour : _from;
            endTimestampHour = _to <= current.endTimestampHour ? _to : current.endTimestampHour;

            rewards = rewards + (endTimestampHour - startTimestampHour) * current.rewardsPerHour / SECONDS_PER_HOUR;

            if(_to <= endTimestampHour) {
                return (rewards, i);
            }
            unchecked {
                ++i;
            }
        }

        return (rewards, length - 1);
    }

    /**
     * @notice Updates reward variables `lastRewardedTimestampHour`, `accumulatedRewardsPerShare` and `lastRewardsRangeIndex`
     * for a given pool.
     * @param _poolId Available pool values 0-3
     */
    function updatePool(uint256 _poolId) public {
        Pool storage pool = pools[_poolId];

        if (block.timestamp < pool.timeRanges[0].startTimestampHour) return;
        if (block.timestamp <= pool.lastRewardedTimestampHour + SECONDS_PER_HOUR) return;

        uint48 lastTimestampHour = pool.timeRanges[pool.timeRanges.length-1].endTimestampHour;
        uint48 previousTimestampHour = getPreviousTimestampHour().toUint48();

        if (pool.stakedAmount == 0) {
            pool.lastRewardedTimestampHour = previousTimestampHour > lastTimestampHour ? lastTimestampHour : previousTimestampHour;
            return;
        }

        (uint256 rewards, uint256 index) = rewardsBy(_poolId, pool.lastRewardedTimestampHour, previousTimestampHour);
        if (pool.lastRewardsRangeIndex != index) {
            pool.lastRewardsRangeIndex = index.toUint16();
        }
        pool.accumulatedRewardsPerShare = (pool.accumulatedRewardsPerShare + (rewards * APE_COIN_PRECISION) / pool.stakedAmount).toUint96();
        pool.lastRewardedTimestampHour = previousTimestampHour > lastTimestampHour ? lastTimestampHour : previousTimestampHour;

        emit UpdatePool(_poolId, pool.lastRewardedTimestampHour, pool.stakedAmount, pool.accumulatedRewardsPerShare);
    }

    // Read Methods

    function getCurrentTimeRangeIndex(Pool memory pool) private view returns (uint256) {
        uint256 current = pool.lastRewardsRangeIndex;

        if (block.timestamp < pool.timeRanges[current].startTimestampHour) return current;
        for(current = pool.lastRewardsRangeIndex; current < pool.timeRanges.length; ++current) {
            TimeRange memory currentTimeRange = pool.timeRanges[current];
            if (currentTimeRange.startTimestampHour <= block.timestamp && block.timestamp <= currentTimeRange.endTimestampHour) return current;
        }
        revert("distribution ended");
    }

    /**
     * @notice Fetches a PoolUI struct (poolId, stakedAmount, currentTimeRange) for each reward pool
     * @return PoolUI for ApeCoin.
     * @return PoolUI for BAYC.
     * @return PoolUI for MAYC.
     * @return PoolUI for BAKC.
     */
    function getPoolsUI() public view returns (PoolUI memory, PoolUI memory, PoolUI memory, PoolUI memory) {
        Pool memory apeCoinPool = pools[0];
        Pool memory baycPool = pools[1];
        Pool memory maycPool = pools[2];
        Pool memory bakcPool = pools[3];
        uint256 current = getCurrentTimeRangeIndex(apeCoinPool);
        return (PoolUI(0,apeCoinPool.stakedAmount, apeCoinPool.timeRanges[current]),
                PoolUI(1,baycPool.stakedAmount, baycPool.timeRanges[current]),
                PoolUI(2,maycPool.stakedAmount, maycPool.timeRanges[current]),
                PoolUI(3,bakcPool.stakedAmount, bakcPool.timeRanges[current]));
    }

    /**
     * @notice Fetches an address total staked amount, used by voting contract
     * @return amount uint256 staked amount for all pools.
     * @param _address An Ethereum address
     */
    function stakedTotal(address _address) external view returns (uint256) {
        uint256 total = addressPosition[_address].stakedAmount;

        total += _stakedTotal(BAYC_POOL_ID, _address);
        total += _stakedTotal(MAYC_POOL_ID, _address);
        total += _stakedTotalPair(_address);

        return total;
    }

    function _stakedTotal(uint256 _poolId, address _addr) private view returns (uint256) {
        uint256 total = 0;
        uint256 nftCount = nftContracts[_poolId].balanceOf(_addr);
        for(uint256 i = 0; i < nftCount; ++i) {
            uint256 tokenId = nftContracts[_poolId].tokenOfOwnerByIndex(_addr, i);
            total += nftPosition[_poolId][tokenId].stakedAmount;
        }

        return total;
    }

    function _stakedTotalPair(address _addr) private view returns (uint256) {
        uint256 total = 0;

        uint256 nftCount = nftContracts[BAYC_POOL_ID].balanceOf(_addr);
        for(uint256 i = 0; i < nftCount; ++i) {
            uint256 baycTokenId = nftContracts[BAYC_POOL_ID].tokenOfOwnerByIndex(_addr, i);
            if (mainToBakc[BAYC_POOL_ID][baycTokenId].isPaired) {
                uint256 bakcTokenId = mainToBakc[BAYC_POOL_ID][baycTokenId].tokenId;
                total += nftPosition[BAKC_POOL_ID][bakcTokenId].stakedAmount;
            }
        }

        nftCount = nftContracts[MAYC_POOL_ID].balanceOf(_addr);
        for(uint256 i = 0; i < nftCount; ++i) {
            uint256 maycTokenId = nftContracts[MAYC_POOL_ID].tokenOfOwnerByIndex(_addr, i);
            if (mainToBakc[MAYC_POOL_ID][maycTokenId].isPaired) {
                uint256 bakcTokenId = mainToBakc[MAYC_POOL_ID][maycTokenId].tokenId;
                total += nftPosition[BAKC_POOL_ID][bakcTokenId].stakedAmount;
            }
        }

        return total;
    }

    /**
     * @notice Fetches a DashboardStake = [poolId, tokenId, deposited, unclaimed, rewards24Hrs, paired] \
     * for each pool, for an Ethereum address
     * @return dashboardStakes An array of DashboardStake structs
     * @param _address An Ethereum address
     */
    function getAllStakes(address _address) public view returns (DashboardStake[] memory) {

        DashboardStake memory apeCoinStake = getApeCoinStake(_address);
        DashboardStake[] memory baycStakes = getBaycStakes(_address);
        DashboardStake[] memory maycStakes = getMaycStakes(_address);
        DashboardStake[] memory bakcStakes = getBakcStakes(_address);
        DashboardStake[] memory splitStakes = getSplitStakes(_address);

        uint256 count = (baycStakes.length + maycStakes.length + bakcStakes.length + splitStakes.length + 1);
        DashboardStake[] memory allStakes = new DashboardStake[](count);

        uint256 offset = 0;
        allStakes[offset] = apeCoinStake;
        ++offset;

        for(uint256 i = 0; i < baycStakes.length; ++i) {
            allStakes[offset] = baycStakes[i];
            ++offset;
        }

        for(uint256 i = 0; i < maycStakes.length; ++i) {
            allStakes[offset] = maycStakes[i];
            ++offset;
        }

        for(uint256 i = 0; i < bakcStakes.length; ++i) {
            allStakes[offset] = bakcStakes[i];
            ++offset;
        }

        for(uint256 i = 0; i < splitStakes.length; ++i) {
            allStakes[offset] = splitStakes[i];
            ++offset;
        }

        return allStakes;
    }

    /**
     * @notice Fetches a DashboardStake for the ApeCoin pool
     * @return dashboardStake A dashboardStake struct
     * @param _address An Ethereum address
     */
    function getApeCoinStake(address _address) public view returns (DashboardStake memory) {
        uint256 tokenId = 0;
        uint256 deposited = addressPosition[_address].stakedAmount;
        uint256 unclaimed = deposited > 0 ? this.pendingRewards(0, _address, tokenId) : 0;
        uint256 rewards24Hrs = deposited > 0 ? _estimate24HourRewards(0, _address, 0) : 0;

        return DashboardStake(APECOIN_POOL_ID, tokenId, deposited, unclaimed, rewards24Hrs, NULL_PAIR);
    }

    /**
     * @notice Fetches an array of DashboardStakes for the BAYC pool
     * @return dashboardStakes An array of DashboardStake structs
     */
    function getBaycStakes(address _address) public view returns (DashboardStake[] memory) {
        return _getStakes(_address, BAYC_POOL_ID);
    }

    /**
     * @notice Fetches an array of DashboardStakes for the MAYC pool
     * @return dashboardStakes An array of DashboardStake structs
     */
    function getMaycStakes(address _address) public view returns (DashboardStake[] memory) {
        return _getStakes(_address, MAYC_POOL_ID);
    }

    /**
     * @notice Fetches an array of DashboardStakes for the BAKC pool
     * @return dashboardStakes An array of DashboardStake structs
     */
    function getBakcStakes(address _address) public view returns (DashboardStake[] memory) {
        return _getStakes(_address, BAKC_POOL_ID);
    }

    /**
     * @notice Fetches an array of DashboardStakes for the Pair Pool when ownership is split \
     * ie (BAYC/MAYC) and BAKC in pair pool have different owners.
     * @return dashboardStakes An array of DashboardStake structs
     * @param _address An Ethereum address
     */
    function getSplitStakes(address _address) public view returns (DashboardStake[] memory) {
        uint256 baycSplits = _getSplitStakeCount(nftContracts[BAYC_POOL_ID].balanceOf(_address), _address, BAYC_POOL_ID);
        uint256 maycSplits = _getSplitStakeCount(nftContracts[MAYC_POOL_ID].balanceOf(_address), _address, MAYC_POOL_ID);
        uint256 totalSplits = baycSplits + maycSplits;

        if(totalSplits == 0) {
            return new DashboardStake[](0);
        }

        DashboardStake[] memory baycSplitStakes = _getSplitStakes(baycSplits, _address, BAYC_POOL_ID);
        DashboardStake[] memory maycSplitStakes = _getSplitStakes(maycSplits, _address, MAYC_POOL_ID);

        DashboardStake[] memory splitStakes = new DashboardStake[](totalSplits);
        uint256 offset = 0;
        for(uint256 i = 0; i < baycSplitStakes.length; ++i) {
            splitStakes[offset] = baycSplitStakes[i];
            ++offset;
        }

        for(uint256 i = 0; i < maycSplitStakes.length; ++i) {
            splitStakes[offset] = maycSplitStakes[i];
            ++offset;
        }

        return splitStakes;
    }

    function _getSplitStakes(uint256 splits, address _address, uint256 _mainPoolId) private view returns (DashboardStake[] memory) {

        DashboardStake[] memory dashboardStakes = new DashboardStake[](splits);
        uint256 counter;

        for(uint256 i = 0; i < nftContracts[_mainPoolId].balanceOf(_address); ++i) {
            uint256 mainTokenId = nftContracts[_mainPoolId].tokenOfOwnerByIndex(_address, i);
            if(mainToBakc[_mainPoolId][mainTokenId].isPaired) {
                uint256 bakcTokenId = mainToBakc[_mainPoolId][mainTokenId].tokenId;
                address currentOwner = nftContracts[BAKC_POOL_ID].ownerOf(bakcTokenId);

                /* Split Pair Check*/
                if (currentOwner != _address) {
                    uint256 deposited = nftPosition[BAKC_POOL_ID][bakcTokenId].stakedAmount;
                    uint256 unclaimed = deposited > 0 ? this.pendingRewards(BAKC_POOL_ID, currentOwner, bakcTokenId) : 0;
                    uint256 rewards24Hrs = deposited > 0 ? _estimate24HourRewards(BAKC_POOL_ID, currentOwner, bakcTokenId): 0;

                    DashboardPair memory pair = NULL_PAIR;
                    if(bakcToMain[bakcTokenId][_mainPoolId].isPaired) {
                        pair = DashboardPair(bakcToMain[bakcTokenId][_mainPoolId].tokenId, _mainPoolId);
                    }

                    DashboardStake memory dashboardStake = DashboardStake(BAKC_POOL_ID, bakcTokenId, deposited, unclaimed, rewards24Hrs, pair);
                    dashboardStakes[counter] = dashboardStake;
                    ++counter;
                }
            }
        }

        return dashboardStakes;
    }

    function _getSplitStakeCount(uint256 nftCount, address _address, uint256 _mainPoolId) private view returns (uint256) {
        uint256 splitCount;
        for(uint256 i = 0; i < nftCount; ++i) {
            uint256 mainTokenId = nftContracts[_mainPoolId].tokenOfOwnerByIndex(_address, i);
            if(mainToBakc[_mainPoolId][mainTokenId].isPaired) {
                uint256 bakcTokenId = mainToBakc[_mainPoolId][mainTokenId].tokenId;
                address currentOwner = nftContracts[BAKC_POOL_ID].ownerOf(bakcTokenId);
                if (currentOwner != _address) {
                    ++splitCount;
                }
            }
        }

        return splitCount;
    }

    function _getStakes(address _address, uint256 _poolId) private view returns (DashboardStake[] memory) {
        uint256 nftCount = nftContracts[_poolId].balanceOf(_address);
        DashboardStake[] memory dashboardStakes = nftCount > 0 ? new DashboardStake[](nftCount) : new DashboardStake[](0);

        if(nftCount == 0) {
            return dashboardStakes;
        }

        for(uint256 i = 0; i < nftCount; ++i) {
            uint256 tokenId = nftContracts[_poolId].tokenOfOwnerByIndex(_address, i);
            uint256 deposited = nftPosition[_poolId][tokenId].stakedAmount;
            uint256 unclaimed = deposited > 0 ? this.pendingRewards(_poolId, _address, tokenId) : 0;
            uint256 rewards24Hrs = deposited > 0 ? _estimate24HourRewards(_poolId, _address, tokenId): 0;

            DashboardPair memory pair = NULL_PAIR;
            if(_poolId == BAKC_POOL_ID) {
                if(bakcToMain[tokenId][BAYC_POOL_ID].isPaired) {
                    pair = DashboardPair(bakcToMain[tokenId][BAYC_POOL_ID].tokenId, BAYC_POOL_ID);
                } else if(bakcToMain[tokenId][MAYC_POOL_ID].isPaired) {
                    pair = DashboardPair(bakcToMain[tokenId][MAYC_POOL_ID].tokenId, MAYC_POOL_ID);
                }
            }

            DashboardStake memory dashboardStake = DashboardStake(_poolId, tokenId, deposited, unclaimed, rewards24Hrs, pair);
            dashboardStakes[i] = dashboardStake;
        }

        return dashboardStakes;
    }

    function _estimate24HourRewards(uint256 _poolId, address _address, uint256 _tokenId) private view returns (uint256) {
        Pool memory pool = pools[_poolId];
        Position memory position = _poolId == 0 ? addressPosition[_address]: nftPosition[_poolId][_tokenId];

        TimeRange memory rewards = getTimeRangeBy(_poolId, pool.lastRewardsRangeIndex);
        return (position.stakedAmount * uint256(rewards.rewardsPerHour) * 24) / uint256(pool.stakedAmount);
    }

    /**
     * @notice Fetches the current amount of claimable ApeCoin rewards for a given position from a given pool.
     * @return uint256 value of pending rewards
     * @param _poolId Available pool values 0-3
     * @param _address Address to lookup Position for
     * @param _tokenId An NFT id
     */
    function pendingRewards(uint256 _poolId, address _address, uint256 _tokenId) external view returns (uint256) {
        Pool memory pool = pools[_poolId];
        Position memory position = _poolId == 0 ? addressPosition[_address]: nftPosition[_poolId][_tokenId];

        (uint256 rewardsSinceLastCalculated,) = rewardsBy(_poolId, pool.lastRewardedTimestampHour, getPreviousTimestampHour());
        uint256 accumulatedRewardsPerShare = pool.accumulatedRewardsPerShare;

        if (block.timestamp > pool.lastRewardedTimestampHour + SECONDS_PER_HOUR && pool.stakedAmount != 0) {
            accumulatedRewardsPerShare = accumulatedRewardsPerShare + rewardsSinceLastCalculated * APE_COIN_PRECISION / pool.stakedAmount;
        }
        return ((position.stakedAmount * accumulatedRewardsPerShare).toInt256() - position.rewardsDebt).toUint256() / APE_COIN_PRECISION;
    }

    // Convenience methods for timestamp calculation

    /// @notice the minutes (0 to 59) of a timestamp
    function getMinute(uint256 timestamp) internal pure returns (uint256 minute) {
        uint256 secs = timestamp % SECONDS_PER_HOUR;
        minute = secs / SECONDS_PER_MINUTE;
    }

    /// @notice the seconds (0 to 59) of a timestamp
    function getSecond(uint256 timestamp) internal pure returns (uint256 second) {
        second = timestamp % SECONDS_PER_MINUTE;
    }

    /// @notice the previous whole hour of a timestamp
    function getPreviousTimestampHour() internal view returns (uint256) {
        return block.timestamp - (getMinute(block.timestamp) * 60 + getSecond(block.timestamp));
    }

    // Private Methods - shared logic
    function _deposit(uint256 _poolId, Position storage _position, uint256 _amount) private {
        Pool storage pool = pools[_poolId];

        _position.stakedAmount += _amount;
        pool.stakedAmount += _amount.toUint96();
        _position.rewardsDebt += (_amount * pool.accumulatedRewardsPerShare).toInt256();
    }

    function _depositNft(uint256 _poolId, SingleNft[] calldata _nfts) private {
        updatePool(_poolId);
        uint256 tokenId;
        uint256 amount;
        Position storage position;
        uint256 length = _nfts.length;
        uint256 totalDeposit;
        for(uint256 i; i < length;) {
            tokenId = _nfts[i].tokenId;
            position = nftPosition[_poolId][tokenId];
            if (position.stakedAmount == 0) {
                if (nftContracts[_poolId].ownerOf(tokenId) != msg.sender) revert CallerNotOwner();
            }
            amount = _nfts[i].amount;
            _depositNftGuard(_poolId, position, amount);
            totalDeposit += amount;
            emit DepositNft(msg.sender, _poolId, amount, tokenId);
            unchecked {
                ++i;
            }
        }
        if (totalDeposit > 0) apeCoin.transferFrom(msg.sender, address(this), totalDeposit);
    }

    function _depositPairNft(uint256 mainTypePoolId, PairNftDepositWithAmount[] calldata _nfts) private {
        uint256 length = _nfts.length;
        uint256 totalDeposit;
        PairNftDepositWithAmount memory pair;
        Position storage position;
        for(uint256 i; i < length;) {
            pair = _nfts[i];
            position = nftPosition[BAKC_POOL_ID][pair.bakcTokenId];

            if(position.stakedAmount == 0) {
                if (nftContracts[mainTypePoolId].ownerOf(pair.mainTokenId) != msg.sender
                    || mainToBakc[mainTypePoolId][pair.mainTokenId].isPaired) revert MainTokenNotOwnedOrPaired();
                if (nftContracts[BAKC_POOL_ID].ownerOf(pair.bakcTokenId) != msg.sender
                    || bakcToMain[pair.bakcTokenId][mainTypePoolId].isPaired) revert BAKCNotOwnedOrPaired();

                mainToBakc[mainTypePoolId][pair.mainTokenId] = PairingStatus(pair.bakcTokenId, true);
                bakcToMain[pair.bakcTokenId][mainTypePoolId] = PairingStatus(pair.mainTokenId, true);
            } else if (pair.mainTokenId != bakcToMain[pair.bakcTokenId][mainTypePoolId].tokenId
                || pair.bakcTokenId != mainToBakc[mainTypePoolId][pair.mainTokenId].tokenId)
                    revert BAKCAlreadyPaired();

            _depositNftGuard(BAKC_POOL_ID, position, pair.amount);
            totalDeposit += pair.amount;
            emit DepositPairNft(msg.sender, pair.amount, mainTypePoolId, pair.mainTokenId, pair.bakcTokenId);
            unchecked {
                ++i;
            }
        }
        if (totalDeposit > 0) apeCoin.transferFrom(msg.sender, address(this), totalDeposit);
    }

    function _depositNftGuard(uint256 _poolId, Position storage _position, uint256 _amount) private {
        if (_amount < MIN_DEPOSIT) revert DepositMoreThanOneAPE();
        if (_amount + _position.stakedAmount > pools[_poolId].timeRanges[pools[_poolId].lastRewardsRangeIndex].capPerPosition)
            revert ExceededCapAmount();

        _deposit(_poolId, _position, _amount);
    }

    function _claim(uint256 _poolId, Position storage _position, address _recipient) private returns (uint256 rewardsToBeClaimed) {
        Pool storage pool = pools[_poolId];

        int256 accumulatedApeCoins = (_position.stakedAmount * uint256(pool.accumulatedRewardsPerShare)).toInt256();
        rewardsToBeClaimed = (accumulatedApeCoins - _position.rewardsDebt).toUint256() / APE_COIN_PRECISION;

        _position.rewardsDebt = accumulatedApeCoins;

        if (rewardsToBeClaimed != 0) {
            apeCoin.transfer(_recipient, rewardsToBeClaimed);
        }
    }

    function _claimNft(uint256 _poolId, uint256[] calldata _nfts, address _recipient) private {
        updatePool(_poolId);
        uint256 tokenId;
        uint256 rewardsToBeClaimed;
        uint256 length = _nfts.length;
        for(uint256 i; i < length;) {
            tokenId = _nfts[i];
            if (nftContracts[_poolId].ownerOf(tokenId) != msg.sender) revert CallerNotOwner();
            Position storage position = nftPosition[_poolId][tokenId];
            rewardsToBeClaimed = _claim(_poolId, position, _recipient);
            emit ClaimRewardsNft(msg.sender, _poolId, rewardsToBeClaimed, tokenId);
            unchecked {
                ++i;
            }
        }
    }

    function _claimPairNft(uint256 mainTypePoolId, PairNft[] calldata _pairs, address _recipient) private {
        uint256 length = _pairs.length;
        uint256 mainTokenId;
        uint256 bakcTokenId;
        Position storage position;
        PairingStatus storage mainToSecond;
        PairingStatus storage secondToMain;
        for(uint256 i; i < length;) {
            mainTokenId = _pairs[i].mainTokenId;
            if (nftContracts[mainTypePoolId].ownerOf(mainTokenId) != msg.sender) revert NotOwnerOfMain();

            bakcTokenId = _pairs[i].bakcTokenId;
            if (nftContracts[BAKC_POOL_ID].ownerOf(bakcTokenId) != msg.sender) revert NotOwnerOfBAKC();

            mainToSecond = mainToBakc[mainTypePoolId][mainTokenId];
            secondToMain = bakcToMain[bakcTokenId][mainTypePoolId];

            if (mainToSecond.tokenId != bakcTokenId || !mainToSecond.isPaired
                || secondToMain.tokenId != mainTokenId || !secondToMain.isPaired) revert ProvidedTokensNotPaired();

            position = nftPosition[BAKC_POOL_ID][bakcTokenId];
            uint256 rewardsToBeClaimed = _claim(BAKC_POOL_ID, position, _recipient);
            emit ClaimRewardsPairNft(msg.sender, rewardsToBeClaimed, mainTypePoolId, mainTokenId, bakcTokenId);
            unchecked {
                ++i;
            }
        }
    }

    function _withdraw(uint256 _poolId, Position storage _position, uint256 _amount) private {
        if (_amount > _position.stakedAmount) revert ExceededStakedAmount();

        Pool storage pool = pools[_poolId];

        _position.stakedAmount -= _amount;
        pool.stakedAmount -= _amount.toUint96();
        _position.rewardsDebt -= (_amount * pool.accumulatedRewardsPerShare).toInt256();
    }

    function _withdrawNft(uint256 _poolId, SingleNft[] calldata _nfts, address _recipient) private {
        updatePool(_poolId);
        uint256 tokenId;
        uint256 amount;
        uint256 length = _nfts.length;
        uint256 totalWithdraw;
        Position storage position;
        for(uint256 i; i < length;) {
            tokenId = _nfts[i].tokenId;
            if (nftContracts[_poolId].ownerOf(tokenId) != msg.sender) revert CallerNotOwner();

            amount = _nfts[i].amount;
            position = nftPosition[_poolId][tokenId];
            if (amount == position.stakedAmount) {
                uint256 rewardsToBeClaimed = _claim(_poolId, position, _recipient);
                emit ClaimRewardsNft(msg.sender, _poolId, rewardsToBeClaimed, tokenId);
            }
            _withdraw(_poolId, position, amount);
            totalWithdraw += amount;
            emit WithdrawNft(msg.sender, _poolId, amount, _recipient, tokenId);
            unchecked {
                ++i;
            }
        }
        if (totalWithdraw > 0) apeCoin.transfer(_recipient, totalWithdraw);
    }

    function _withdrawPairNft(uint256 mainTypePoolId, PairNftWithdrawWithAmount[] calldata _nfts) private {
        address mainTokenOwner;
        address bakcOwner;
        PairNftWithdrawWithAmount memory pair;
        PairingStatus storage mainToSecond;
        PairingStatus storage secondToMain;
        Position storage position;
        uint256 length = _nfts.length;
        for(uint256 i; i < length;) {
            pair = _nfts[i];
            mainTokenOwner = nftContracts[mainTypePoolId].ownerOf(pair.mainTokenId);
            bakcOwner = nftContracts[BAKC_POOL_ID].ownerOf(pair.bakcTokenId);

            if (mainTokenOwner != msg.sender) {
                if (bakcOwner != msg.sender) revert NeitherTokenInPairOwnedByCaller();
            }

            mainToSecond = mainToBakc[mainTypePoolId][pair.mainTokenId];
            secondToMain = bakcToMain[pair.bakcTokenId][mainTypePoolId];

            if (mainToSecond.tokenId != pair.bakcTokenId || !mainToSecond.isPaired
                || secondToMain.tokenId != pair.mainTokenId || !secondToMain.isPaired) revert ProvidedTokensNotPaired();

            position = nftPosition[BAKC_POOL_ID][pair.bakcTokenId];
            if(!pair.isUncommit) {
                if(pair.amount == position.stakedAmount) revert UncommitWrongParameters();
            }
            if (mainTokenOwner != bakcOwner) {
                if (!pair.isUncommit) revert SplitPairCantPartiallyWithdraw();
            }

            if (pair.isUncommit) {
                uint256 rewardsToBeClaimed = _claim(BAKC_POOL_ID, position, bakcOwner);
                mainToBakc[mainTypePoolId][pair.mainTokenId] = PairingStatus(0, false);
                bakcToMain[pair.bakcTokenId][mainTypePoolId] = PairingStatus(0, false);
                emit ClaimRewardsPairNft(msg.sender, rewardsToBeClaimed, mainTypePoolId, pair.mainTokenId, pair.bakcTokenId);
            }
            uint256 finalAmountToWithdraw = pair.isUncommit ? position.stakedAmount: pair.amount;
            _withdraw(BAKC_POOL_ID, position, finalAmountToWithdraw);
            apeCoin.transfer(mainTokenOwner, finalAmountToWithdraw);
            emit WithdrawPairNft(msg.sender, finalAmountToWithdraw, mainTypePoolId, pair.mainTokenId, pair.bakcTokenId);
            unchecked {
                ++i;
            }
        }
    }

}

File 2 of 15 : 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 3 of 15 : SafeCast.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 SafeCast {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248) {
        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 4 of 15 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

File 5 of 15 : ERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../ERC721.sol";
import "./IERC721Enumerable.sol";

/**
 * @dev This implements an optional extension of {ERC721} defined in the EIP that adds
 * enumerability of all the token ids in the contract as well as all token ids owned by each
 * account.
 */
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
    // Mapping from owner to list of owned token IDs
    mapping(address => mapping(uint256 => uint256)) private _ownedTokens;

    // Mapping from token ID to index of the owner tokens list
    mapping(uint256 => uint256) private _ownedTokensIndex;

    // Array with all token ids, used for enumeration
    uint256[] private _allTokens;

    // Mapping from token id to position in the allTokens array
    mapping(uint256 => uint256) private _allTokensIndex;

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

    /**
     * @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
        require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
        return _ownedTokens[owner][index];
    }

    /**
     * @dev See {IERC721Enumerable-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _allTokens.length;
    }

    /**
     * @dev See {IERC721Enumerable-tokenByIndex}.
     */
    function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
        require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
        return _allTokens[index];
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, tokenId);

        if (from == address(0)) {
            _addTokenToAllTokensEnumeration(tokenId);
        } else if (from != to) {
            _removeTokenFromOwnerEnumeration(from, tokenId);
        }
        if (to == address(0)) {
            _removeTokenFromAllTokensEnumeration(tokenId);
        } else if (to != from) {
            _addTokenToOwnerEnumeration(to, tokenId);
        }
    }

    /**
     * @dev Private function to add a token to this extension's ownership-tracking data structures.
     * @param to address representing the new owner of the given token ID
     * @param tokenId uint256 ID of the token to be added to the tokens list of the given address
     */
    function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
        uint256 length = ERC721.balanceOf(to);
        _ownedTokens[to][length] = tokenId;
        _ownedTokensIndex[tokenId] = length;
    }

    /**
     * @dev Private function to add a token to this extension's token tracking data structures.
     * @param tokenId uint256 ID of the token to be added to the tokens list
     */
    function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
        _allTokensIndex[tokenId] = _allTokens.length;
        _allTokens.push(tokenId);
    }

    /**
     * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
     * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
     * gas optimizations e.g. when performing a transfer operation (avoiding double writes).
     * This has O(1) time complexity, but alters the order of the _ownedTokens array.
     * @param from address representing the previous owner of the given token ID
     * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
     */
    function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
        // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
        uint256 tokenIndex = _ownedTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary
        if (tokenIndex != lastTokenIndex) {
            uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];

            _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
            _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
        }

        // This also deletes the contents at the last position of the array
        delete _ownedTokensIndex[tokenId];
        delete _ownedTokens[from][lastTokenIndex];
    }

    /**
     * @dev Private function to remove a token from this extension's token tracking data structures.
     * This has O(1) time complexity, but alters the order of the _allTokens array.
     * @param tokenId uint256 ID of the token to be removed from the tokens list
     */
    function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
        // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
        // then delete the last slot (swap and pop).

        uint256 lastTokenIndex = _allTokens.length - 1;
        uint256 tokenIndex = _allTokensIndex[tokenId];

        // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
        // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
        // an 'if' statement (like in _removeTokenFromOwnerEnumeration)
        uint256 lastTokenId = _allTokens[lastTokenIndex];

        _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
        _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index

        // This also deletes the contents at the last position of the array
        delete _allTokensIndex[tokenId];
        _allTokens.pop();
    }
}

File 6 of 15 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

File 7 of 15 : ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/ERC721.sol)

pragma solidity ^0.8.0;

import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
 * the Metadata extension, but not including the Enumerable extension, which is available separately as
 * {ERC721Enumerable}.
 */
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
    using Address for address;
    using Strings for uint256;

    // Token name
    string private _name;

    // Token symbol
    string private _symbol;

    // Mapping from token ID to owner address
    mapping(uint256 => address) private _owners;

    // Mapping owner address to token count
    mapping(address => uint256) private _balances;

    // Mapping from token ID to approved address
    mapping(uint256 => address) private _tokenApprovals;

    // Mapping from owner to operator approvals
    mapping(address => mapping(address => bool)) private _operatorApprovals;

    /**
     * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

    /**
     * @dev See {IERC721-balanceOf}.
     */
    function balanceOf(address owner) public view virtual override returns (uint256) {
        require(owner != address(0), "ERC721: address zero is not a valid owner");
        return _balances[owner];
    }

    /**
     * @dev See {IERC721-ownerOf}.
     */
    function ownerOf(uint256 tokenId) public view virtual override returns (address) {
        address owner = _owners[tokenId];
        require(owner != address(0), "ERC721: invalid token ID");
        return owner;
    }

    /**
     * @dev See {IERC721Metadata-name}.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev See {IERC721Metadata-symbol}.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev See {IERC721Metadata-tokenURI}.
     */
    function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
        _requireMinted(tokenId);

        string memory baseURI = _baseURI();
        return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
    }

    /**
     * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
     * token will be the concatenation of the `baseURI` and the `tokenId`. Empty
     * by default, can be overridden in child contracts.
     */
    function _baseURI() internal view virtual returns (string memory) {
        return "";
    }

    /**
     * @dev See {IERC721-approve}.
     */
    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not token owner nor approved for all"
        );

        _approve(to, tokenId);
    }

    /**
     * @dev See {IERC721-getApproved}.
     */
    function getApproved(uint256 tokenId) public view virtual override returns (address) {
        _requireMinted(tokenId);

        return _tokenApprovals[tokenId];
    }

    /**
     * @dev See {IERC721-setApprovalForAll}.
     */
    function setApprovalForAll(address operator, bool approved) public virtual override {
        _setApprovalForAll(_msgSender(), operator, approved);
    }

    /**
     * @dev See {IERC721-isApprovedForAll}.
     */
    function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
        return _operatorApprovals[owner][operator];
    }

    /**
     * @dev See {IERC721-transferFrom}.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        //solhint-disable-next-line max-line-length
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved");

        _transfer(from, to, tokenId);
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public virtual override {
        safeTransferFrom(from, to, tokenId, "");
    }

    /**
     * @dev See {IERC721-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes memory data
    ) public virtual override {
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner nor approved");
        _safeTransfer(from, to, tokenId, data);
    }

    /**
     * @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.
     *
     * `data` is additional data, it has no specified format and it is sent in call to `to`.
     *
     * This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
     * implement alternative mechanisms to perform token transfer, such as signature-based.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeTransfer(
        address from,
        address to,
        uint256 tokenId,
        bytes memory data
    ) internal virtual {
        _transfer(from, to, tokenId);
        require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
    }

    /**
     * @dev Returns whether `tokenId` exists.
     *
     * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
     *
     * Tokens start existing when they are minted (`_mint`),
     * and stop existing when they are burned (`_burn`).
     */
    function _exists(uint256 tokenId) internal view virtual returns (bool) {
        return _owners[tokenId] != address(0);
    }

    /**
     * @dev Returns whether `spender` is allowed to manage `tokenId`.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
        address owner = ERC721.ownerOf(tokenId);
        return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
    }

    /**
     * @dev Safely mints `tokenId` and transfers it to `to`.
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function _safeMint(address to, uint256 tokenId) internal virtual {
        _safeMint(to, tokenId, "");
    }

    /**
     * @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
     * forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
     */
    function _safeMint(
        address to,
        uint256 tokenId,
        bytes memory data
    ) internal virtual {
        _mint(to, tokenId);
        require(
            _checkOnERC721Received(address(0), to, tokenId, data),
            "ERC721: transfer to non ERC721Receiver implementer"
        );
    }

    /**
     * @dev Mints `tokenId` and transfers it to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
     *
     * Requirements:
     *
     * - `tokenId` must not exist.
     * - `to` cannot be the zero address.
     *
     * Emits a {Transfer} event.
     */
    function _mint(address to, uint256 tokenId) internal virtual {
        require(to != address(0), "ERC721: mint to the zero address");
        require(!_exists(tokenId), "ERC721: token already minted");

        _beforeTokenTransfer(address(0), to, tokenId);

        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(address(0), to, tokenId);

        _afterTokenTransfer(address(0), to, tokenId);
    }

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

        _beforeTokenTransfer(owner, address(0), tokenId);

        // Clear approvals
        _approve(address(0), tokenId);

        _balances[owner] -= 1;
        delete _owners[tokenId];

        emit Transfer(owner, address(0), tokenId);

        _afterTokenTransfer(owner, address(0), tokenId);
    }

    /**
     * @dev Transfers `tokenId` from `from` to `to`.
     *  As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     *
     * Emits a {Transfer} event.
     */
    function _transfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
        require(to != address(0), "ERC721: transfer to the zero address");

        _beforeTokenTransfer(from, to, tokenId);

        // Clear approvals from the previous owner
        _approve(address(0), tokenId);

        _balances[from] -= 1;
        _balances[to] += 1;
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

        _afterTokenTransfer(from, to, tokenId);
    }

    /**
     * @dev Approve `to` to operate on `tokenId`
     *
     * Emits an {Approval} event.
     */
    function _approve(address to, uint256 tokenId) internal virtual {
        _tokenApprovals[tokenId] = to;
        emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
    }

    /**
     * @dev Approve `operator` to operate on all of `owner` tokens
     *
     * Emits an {ApprovalForAll} event.
     */
    function _setApprovalForAll(
        address owner,
        address operator,
        bool approved
    ) internal virtual {
        require(owner != operator, "ERC721: approve to caller");
        _operatorApprovals[owner][operator] = approved;
        emit ApprovalForAll(owner, operator, approved);
    }

    /**
     * @dev Reverts if the `tokenId` has not been minted yet.
     */
    function _requireMinted(uint256 tokenId) internal view virtual {
        require(_exists(tokenId), "ERC721: invalid token ID");
    }

    /**
     * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
     * The call is not executed if the target address is not a contract.
     *
     * @param from address representing the previous owner of the given token ID
     * @param to target address that will receive the tokens
     * @param tokenId uint256 ID of the token to be transferred
     * @param data bytes optional data to send along with the call
     * @return bool whether the call correctly returned the expected magic value
     */
    function _checkOnERC721Received(
        address from,
        address to,
        uint256 tokenId,
        bytes memory data
    ) private returns (bool) {
        if (to.isContract()) {
            try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
                return retval == IERC721Receiver.onERC721Received.selector;
            } catch (bytes memory reason) {
                if (reason.length == 0) {
                    revert("ERC721: transfer to non ERC721Receiver implementer");
                } else {
                    /// @solidity memory-safe-assembly
                    assembly {
                        revert(add(32, reason), mload(reason))
                    }
                }
            }
        } else {
            return true;
        }
    }

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
     * transferred to `to`.
     * - When `from` is zero, `tokenId` will be minted for `to`.
     * - When `to` is zero, ``from``'s `tokenId` will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal virtual {}
}

File 8 of 15 : IERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Enumerable is IERC721 {
    /**
     * @dev Returns the total amount of tokens stored by the contract.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns a token ID owned by `owner` at a given `index` of its token list.
     * Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
     */
    function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);

    /**
     * @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
     * Use along with {totalSupply} to enumerate all tokens.
     */
    function tokenByIndex(uint256 index) external view returns (uint256);
}

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

pragma solidity ^0.8.0;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @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 10 of 15 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity ^0.8.0;

/**
 * @title ERC721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

File 11 of 15 : IERC721Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC721.sol";

/**
 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension
 * @dev See https://eips.ethereum.org/EIPS/eip-721
 */
interface IERC721Metadata is IERC721 {
    /**
     * @dev Returns the token collection name.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the token collection symbol.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
     */
    function tokenURI(uint256 tokenId) external view returns (string memory);
}

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

        return account.code.length > 0;
    }

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(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) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason 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 {
            // 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 13 of 15 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    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 14 of 15 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.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 ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 15 of 15 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_apeCoinContractAddress","type":"address"},{"internalType":"address","name":"_baycContractAddress","type":"address"},{"internalType":"address","name":"_maycContractAddress","type":"address"},{"internalType":"address","name":"_bakcContractAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BAKCAlreadyPaired","type":"error"},{"inputs":[],"name":"BAKCNotOwnedOrPaired","type":"error"},{"inputs":[],"name":"CallerNotOwner","type":"error"},{"inputs":[],"name":"DepositMoreThanOneAPE","type":"error"},{"inputs":[],"name":"EndNotWholeHour","type":"error"},{"inputs":[],"name":"ExceededCapAmount","type":"error"},{"inputs":[],"name":"ExceededStakedAmount","type":"error"},{"inputs":[],"name":"InvalidPoolId","type":"error"},{"inputs":[],"name":"MainTokenNotOwnedOrPaired","type":"error"},{"inputs":[],"name":"NeitherTokenInPairOwnedByCaller","type":"error"},{"inputs":[],"name":"NotOwnerOfBAKC","type":"error"},{"inputs":[],"name":"NotOwnerOfMain","type":"error"},{"inputs":[],"name":"ProvidedTokensNotPaired","type":"error"},{"inputs":[],"name":"SplitPairCantPartiallyWithdraw","type":"error"},{"inputs":[],"name":"StartMustBeGreaterThanEnd","type":"error"},{"inputs":[],"name":"StartMustEqualLastEnd","type":"error"},{"inputs":[],"name":"StartNotWholeHour","type":"error"},{"inputs":[],"name":"UncommitWrongParameters","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"}],"name":"ClaimRewards","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"poolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ClaimRewardsNft","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mainTypePoolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mainTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bakcTokenId","type":"uint256"}],"name":"ClaimRewardsPairNft","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"poolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"DepositNft","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mainTypePoolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mainTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bakcTokenId","type":"uint256"}],"name":"DepositPairNft","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"poolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lastRewardedBlock","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"accumulatedRewardsPerShare","type":"uint256"}],"name":"UpdatePool","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"}],"name":"Withdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"poolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"WithdrawNft","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mainTypePoolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mainTokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"bakcTokenId","type":"uint256"}],"name":"WithdrawPairNft","type":"event"},{"inputs":[{"internalType":"uint256","name":"_poolId","type":"uint256"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_startTimestamp","type":"uint256"},{"internalType":"uint256","name":"_endTimeStamp","type":"uint256"},{"internalType":"uint256","name":"_capPerPosition","type":"uint256"}],"name":"addTimeRange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"addressPosition","outputs":[{"internalType":"uint256","name":"stakedAmount","type":"uint256"},{"internalType":"int256","name":"rewardsDebt","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"apeCoin","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"bakcToMain","outputs":[{"internalType":"uint248","name":"tokenId","type":"uint248"},{"internalType":"bool","name":"isPaired","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"name":"claimApeCoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint128","name":"mainTokenId","type":"uint128"},{"internalType":"uint128","name":"bakcTokenId","type":"uint128"}],"internalType":"struct ApeCoinStaking.PairNft[]","name":"_baycPairs","type":"tuple[]"},{"components":[{"internalType":"uint128","name":"mainTokenId","type":"uint128"},{"internalType":"uint128","name":"bakcTokenId","type":"uint128"}],"internalType":"struct ApeCoinStaking.PairNft[]","name":"_maycPairs","type":"tuple[]"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"claimBAKC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_nfts","type":"uint256[]"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"claimBAYC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_nfts","type":"uint256[]"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"claimMAYC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimSelfApeCoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint128","name":"mainTokenId","type":"uint128"},{"internalType":"uint128","name":"bakcTokenId","type":"uint128"}],"internalType":"struct ApeCoinStaking.PairNft[]","name":"_baycPairs","type":"tuple[]"},{"components":[{"internalType":"uint128","name":"mainTokenId","type":"uint128"},{"internalType":"uint128","name":"bakcTokenId","type":"uint128"}],"internalType":"struct ApeCoinStaking.PairNft[]","name":"_maycPairs","type":"tuple[]"}],"name":"claimSelfBAKC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_nfts","type":"uint256[]"}],"name":"claimSelfBAYC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_nfts","type":"uint256[]"}],"name":"claimSelfMAYC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"depositApeCoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"mainTokenId","type":"uint32"},{"internalType":"uint32","name":"bakcTokenId","type":"uint32"},{"internalType":"uint184","name":"amount","type":"uint184"}],"internalType":"struct ApeCoinStaking.PairNftDepositWithAmount[]","name":"_baycPairs","type":"tuple[]"},{"components":[{"internalType":"uint32","name":"mainTokenId","type":"uint32"},{"internalType":"uint32","name":"bakcTokenId","type":"uint32"},{"internalType":"uint184","name":"amount","type":"uint184"}],"internalType":"struct ApeCoinStaking.PairNftDepositWithAmount[]","name":"_maycPairs","type":"tuple[]"}],"name":"depositBAKC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"tokenId","type":"uint32"},{"internalType":"uint224","name":"amount","type":"uint224"}],"internalType":"struct ApeCoinStaking.SingleNft[]","name":"_nfts","type":"tuple[]"}],"name":"depositBAYC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"tokenId","type":"uint32"},{"internalType":"uint224","name":"amount","type":"uint224"}],"internalType":"struct ApeCoinStaking.SingleNft[]","name":"_nfts","type":"tuple[]"}],"name":"depositMAYC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"depositSelfApeCoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getAllStakes","outputs":[{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"deposited","type":"uint256"},{"internalType":"uint256","name":"unclaimed","type":"uint256"},{"internalType":"uint256","name":"rewards24hr","type":"uint256"},{"components":[{"internalType":"uint256","name":"mainTokenId","type":"uint256"},{"internalType":"uint256","name":"mainTypePoolId","type":"uint256"}],"internalType":"struct ApeCoinStaking.DashboardPair","name":"pair","type":"tuple"}],"internalType":"struct ApeCoinStaking.DashboardStake[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getApeCoinStake","outputs":[{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"deposited","type":"uint256"},{"internalType":"uint256","name":"unclaimed","type":"uint256"},{"internalType":"uint256","name":"rewards24hr","type":"uint256"},{"components":[{"internalType":"uint256","name":"mainTokenId","type":"uint256"},{"internalType":"uint256","name":"mainTypePoolId","type":"uint256"}],"internalType":"struct ApeCoinStaking.DashboardPair","name":"pair","type":"tuple"}],"internalType":"struct ApeCoinStaking.DashboardStake","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getBakcStakes","outputs":[{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"deposited","type":"uint256"},{"internalType":"uint256","name":"unclaimed","type":"uint256"},{"internalType":"uint256","name":"rewards24hr","type":"uint256"},{"components":[{"internalType":"uint256","name":"mainTokenId","type":"uint256"},{"internalType":"uint256","name":"mainTypePoolId","type":"uint256"}],"internalType":"struct ApeCoinStaking.DashboardPair","name":"pair","type":"tuple"}],"internalType":"struct ApeCoinStaking.DashboardStake[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getBaycStakes","outputs":[{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"deposited","type":"uint256"},{"internalType":"uint256","name":"unclaimed","type":"uint256"},{"internalType":"uint256","name":"rewards24hr","type":"uint256"},{"components":[{"internalType":"uint256","name":"mainTokenId","type":"uint256"},{"internalType":"uint256","name":"mainTypePoolId","type":"uint256"}],"internalType":"struct ApeCoinStaking.DashboardPair","name":"pair","type":"tuple"}],"internalType":"struct ApeCoinStaking.DashboardStake[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getMaycStakes","outputs":[{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"deposited","type":"uint256"},{"internalType":"uint256","name":"unclaimed","type":"uint256"},{"internalType":"uint256","name":"rewards24hr","type":"uint256"},{"components":[{"internalType":"uint256","name":"mainTokenId","type":"uint256"},{"internalType":"uint256","name":"mainTypePoolId","type":"uint256"}],"internalType":"struct ApeCoinStaking.DashboardPair","name":"pair","type":"tuple"}],"internalType":"struct ApeCoinStaking.DashboardStake[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoolsUI","outputs":[{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"stakedAmount","type":"uint256"},{"components":[{"internalType":"uint48","name":"startTimestampHour","type":"uint48"},{"internalType":"uint48","name":"endTimestampHour","type":"uint48"},{"internalType":"uint96","name":"rewardsPerHour","type":"uint96"},{"internalType":"uint96","name":"capPerPosition","type":"uint96"}],"internalType":"struct ApeCoinStaking.TimeRange","name":"currentTimeRange","type":"tuple"}],"internalType":"struct ApeCoinStaking.PoolUI","name":"","type":"tuple"},{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"stakedAmount","type":"uint256"},{"components":[{"internalType":"uint48","name":"startTimestampHour","type":"uint48"},{"internalType":"uint48","name":"endTimestampHour","type":"uint48"},{"internalType":"uint96","name":"rewardsPerHour","type":"uint96"},{"internalType":"uint96","name":"capPerPosition","type":"uint96"}],"internalType":"struct ApeCoinStaking.TimeRange","name":"currentTimeRange","type":"tuple"}],"internalType":"struct ApeCoinStaking.PoolUI","name":"","type":"tuple"},{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"stakedAmount","type":"uint256"},{"components":[{"internalType":"uint48","name":"startTimestampHour","type":"uint48"},{"internalType":"uint48","name":"endTimestampHour","type":"uint48"},{"internalType":"uint96","name":"rewardsPerHour","type":"uint96"},{"internalType":"uint96","name":"capPerPosition","type":"uint96"}],"internalType":"struct ApeCoinStaking.TimeRange","name":"currentTimeRange","type":"tuple"}],"internalType":"struct ApeCoinStaking.PoolUI","name":"","type":"tuple"},{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"stakedAmount","type":"uint256"},{"components":[{"internalType":"uint48","name":"startTimestampHour","type":"uint48"},{"internalType":"uint48","name":"endTimestampHour","type":"uint48"},{"internalType":"uint96","name":"rewardsPerHour","type":"uint96"},{"internalType":"uint96","name":"capPerPosition","type":"uint96"}],"internalType":"struct ApeCoinStaking.TimeRange","name":"currentTimeRange","type":"tuple"}],"internalType":"struct ApeCoinStaking.PoolUI","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"getSplitStakes","outputs":[{"components":[{"internalType":"uint256","name":"poolId","type":"uint256"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"deposited","type":"uint256"},{"internalType":"uint256","name":"unclaimed","type":"uint256"},{"internalType":"uint256","name":"rewards24hr","type":"uint256"},{"components":[{"internalType":"uint256","name":"mainTokenId","type":"uint256"},{"internalType":"uint256","name":"mainTypePoolId","type":"uint256"}],"internalType":"struct ApeCoinStaking.DashboardPair","name":"pair","type":"tuple"}],"internalType":"struct ApeCoinStaking.DashboardStake[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId","type":"uint256"},{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getTimeRangeBy","outputs":[{"components":[{"internalType":"uint48","name":"startTimestampHour","type":"uint48"},{"internalType":"uint48","name":"endTimestampHour","type":"uint48"},{"internalType":"uint96","name":"rewardsPerHour","type":"uint96"},{"internalType":"uint96","name":"capPerPosition","type":"uint96"}],"internalType":"struct ApeCoinStaking.TimeRange","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"mainToBakc","outputs":[{"internalType":"uint248","name":"tokenId","type":"uint248"},{"internalType":"bool","name":"isPaired","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"nftContracts","outputs":[{"internalType":"contract ERC721Enumerable","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"nftPosition","outputs":[{"internalType":"uint256","name":"stakedAmount","type":"uint256"},{"internalType":"int256","name":"rewardsDebt","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId","type":"uint256"},{"internalType":"address","name":"_address","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"pendingRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"pools","outputs":[{"internalType":"uint48","name":"lastRewardedTimestampHour","type":"uint48"},{"internalType":"uint16","name":"lastRewardsRangeIndex","type":"uint16"},{"internalType":"uint96","name":"stakedAmount","type":"uint96"},{"internalType":"uint96","name":"accumulatedRewardsPerShare","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId","type":"uint256"}],"name":"removeLastTimeRange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId","type":"uint256"},{"internalType":"uint256","name":"_from","type":"uint256"},{"internalType":"uint256","name":"_to","type":"uint256"}],"name":"rewardsBy","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"stakedTotal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId","type":"uint256"}],"name":"updatePool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"withdrawApeCoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"mainTokenId","type":"uint32"},{"internalType":"uint32","name":"bakcTokenId","type":"uint32"},{"internalType":"uint184","name":"amount","type":"uint184"},{"internalType":"bool","name":"isUncommit","type":"bool"}],"internalType":"struct ApeCoinStaking.PairNftWithdrawWithAmount[]","name":"_baycPairs","type":"tuple[]"},{"components":[{"internalType":"uint32","name":"mainTokenId","type":"uint32"},{"internalType":"uint32","name":"bakcTokenId","type":"uint32"},{"internalType":"uint184","name":"amount","type":"uint184"},{"internalType":"bool","name":"isUncommit","type":"bool"}],"internalType":"struct ApeCoinStaking.PairNftWithdrawWithAmount[]","name":"_maycPairs","type":"tuple[]"}],"name":"withdrawBAKC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"tokenId","type":"uint32"},{"internalType":"uint224","name":"amount","type":"uint224"}],"internalType":"struct ApeCoinStaking.SingleNft[]","name":"_nfts","type":"tuple[]"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"withdrawBAYC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"tokenId","type":"uint32"},{"internalType":"uint224","name":"amount","type":"uint224"}],"internalType":"struct ApeCoinStaking.SingleNft[]","name":"_nfts","type":"tuple[]"},{"internalType":"address","name":"_recipient","type":"address"}],"name":"withdrawMAYC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawSelfApeCoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"tokenId","type":"uint32"},{"internalType":"uint224","name":"amount","type":"uint224"}],"internalType":"struct ApeCoinStaking.SingleNft[]","name":"_nfts","type":"tuple[]"}],"name":"withdrawSelfBAYC","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"tokenId","type":"uint32"},{"internalType":"uint224","name":"amount","type":"uint224"}],"internalType":"struct ApeCoinStaking.SingleNft[]","name":"_nfts","type":"tuple[]"}],"name":"withdrawSelfMAYC","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60e0604052600060a081905260c081905260028190556003553480156200002557600080fd5b5060405162005d8d38038062005d8d83398101604081905262000048916200016f565b620000533362000102565b6001600160a01b03938416608052600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c80549385166001600160a01b03199485161790557f5d6016397a73f5e079297ac5a36fef17b4d9c3831618e63ab105738020ddd72080549285169284169290921790915560036000527fc0da782485e77ae272268ae0a3ff44c1552ecb60b3743924de17a815e0a3cfd78054919093169116179055620001cc565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b03811681146200016a57600080fd5b919050565b600080600080608085870312156200018657600080fd5b620001918562000152565b9350620001a16020860162000152565b9250620001b16040860162000152565b9150620001c16060860162000152565b905092959194509250565b608051615b74620002196000396000818161058801528181611c160152818161221a015281816136ee0152818161396901528181613bb90152818161413b01526146eb0152615b746000f3fe608060405234801561001057600080fd5b50600436106102735760003560e01c80639860037e11610151578063d346cbd9116100c3578063e4e8184711610087578063e4e81847146106b5578063ed23c906146106c8578063f2fde38b146106db578063f4c6f602146106ee578063f567918914610701578063fe31446c1461071457600080fd5b8063d346cbd914610649578063d363dc171461065c578063d7464ee91461066f578063d9f11fb214610682578063e0347e4f146106a257600080fd5b8063aceb362911610115578063aceb3629146105aa578063b4f95752146105bd578063b682e859146105fd578063bb628f2014610610578063bd5023a914610623578063c63389c31461063657600080fd5b80639860037e146104dd57806398ada4a2146104f05780639dcaafb414610522578063ac4afa3814610535578063ac7ad9ba1461058357600080fd5b8063304f88c0116101ea578063715018a6116101ae578063715018a61461047e578063770dade5146104865780637f60d3381461049e5780638279e760146104b15780638da5cb5b146104b95780638ecbffa7146104ca57600080fd5b8063304f88c0146103d3578063381b46821461043257806346583a051461044557806351eb05a61461045857806357a263001461046b57600080fd5b80630bb4d82a1161023c5780630bb4d82a146103255780630ed368f11461036657806320a325d01461037957806326fb22491461038c5780632c018f911461039f5780632ee2de66146103c057600080fd5b8062191b441461027857806304238994146102a157806305ece226146102b457806307f5fa4a146102f057806309e833c614610305575b600080fd5b61028b6102863660046150d0565b610727565b6040516102989190615134565b60405180910390f35b61028b6102af3660046150d0565b61073a565b6102db6102c23660046150d0565b6001602081905260009182526040909120805491015482565b60408051928352602083019190915201610298565b6103036102fe3660046151cd565b6109c2565b005b610318610313366004615250565b6109ed565b60405161029891906152b3565b61034e6103333660046152c1565b600c602052600090815260409020546001600160a01b031681565b6040516001600160a01b039091168152602001610298565b61028b6103743660046150d0565b610aa3565b61030361038736600461531e565b610d88565b61030361039a3660046153a3565b610d99565b6103b26103ad36600461540e565b610dc1565b604051908152602001610298565b6103036103ce3660046150d0565b611018565b6104136103e1366004615250565b600e6020908152600092835260408084209091529082529020546001600160f81b03811690600160f81b900460ff1682565b604080516001600160f81b039093168352901515602083015201610298565b61030361044036600461531e565b611089565b610303610453366004615446565b611096565b6103036104663660046152c1565b6110a2565b61030361047936600461547b565b611333565b610303611345565b61048e611359565b60405161029894939291906154f1565b6103036104ac3660046152c1565b61187c565b610303611889565b6000546001600160a01b031661034e565b6103036104d8366004615446565b611892565b61028b6104eb3660046150d0565b61189e565b6102db6104fe366004615250565b600d6020908152600092835260408084209091529082529020805460019091015482565b6103036105303660046152c1565b6118ab565b6105486105433660046152c1565b6118b5565b6040805165ffffffffffff909516855261ffff90931660208501526001600160601b0391821692840192909252166060820152608001610298565b61034e7f000000000000000000000000000000000000000000000000000000000000000081565b6103036105b8366004615532565b6118fe565b6104136105cb366004615250565b600f6020908152600092835260408084209091529082529020546001600160f81b03811690600160f81b900460ff1682565b61030361060b36600461547b565b61190b565b61030361061e366004615569565b611918565b6103036106313660046155a4565b611b94565b610303610644366004615446565b611ccc565b610303610657366004615618565b611cd9565b61030361066a3660046152c1565b611cfb565b6102db61067d366004615677565b611d6a565b6106956106903660046150d0565b61205e565b60405161029891906156a3565b6103036106b03660046156b1565b612172565b6103036106c33660046155a4565b61217f565b6103036106d6366004615532565b6122d5565b6103036106e93660046150d0565b6122e2565b61028b6106fc3660046150d0565b61235d565b6103b261070f3660046150d0565b61236a565b610303610722366004615446565b6123cd565b60606107348260036123da565b92915050565b606060006107478361205e565b905060006107548461189e565b905060006107618561235d565b9050600061076e86610727565b9050600061077b87610aa3565b9050600081518351855187516107919190615726565b61079b9190615726565b6107a59190615726565b6107b0906001615726565b90506000816001600160401b038111156107cc576107cc61573e565b60405190808252806020026020018201604052801561080557816020015b6107f2615028565b8152602001906001900390816107ea5790505b50905060008782828151811061081d5761081d615754565b6020026020010181905250806108329061576a565b905060005b87518110156108935787818151811061085257610852615754565b602002602001015183838151811061086c5761086c615754565b6020026020010181905250816108819061576a565b915061088c8161576a565b9050610837565b5060005b86518110156108f3578681815181106108b2576108b2615754565b60200260200101518383815181106108cc576108cc615754565b6020026020010181905250816108e19061576a565b91506108ec8161576a565b9050610897565b5060005b85518110156109535785818151811061091257610912615754565b602002602001015183838151811061092c5761092c615754565b6020026020010181905250816109419061576a565b915061094c8161576a565b90506108f7565b5060005b84518110156109b35784818151811061097257610972615754565b602002602001015183838151811061098c5761098c615754565b6020026020010181905250816109a19061576a565b91506109ac8161576a565b9050610957565b50909998505050505050505050565b6109cc60036110a2565b6109d9600186868461279b565b6109e6600284848461279b565b5050505050565b60408051608081018252600080825260208201819052918101829052606081019190915260048360048110610a2457610a24615754565b600202016001018281548110610a3c57610a3c615754565b6000918252602091829020604080516080810182526002909302909101805465ffffffffffff8082168552600160301b820416948401949094526001600160601b03600160601b909404841691830191909152600101549091166060820152905092915050565b60016000908152600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c546040516370a0823160e01b81526001600160a01b03848116600483015260609392610b4b929116906370a0823190602401602060405180830381865afa158015610b1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b439190615785565b846001612a90565b60026000908152600c6020527f5d6016397a73f5e079297ac5a36fef17b4d9c3831618e63ab105738020ddd720546040516370a0823160e01b81526001600160a01b0387811660048301529394509192610bf4929116906370a0823190602401602060405180830381865afa158015610bc8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bec9190615785565b856002612a90565b90506000610c028284615726565b905080610c44576040805160008082526020820190925290610c3a565b610c27615028565b815260200190600190039081610c1f5790505b5095945050505050565b6000610c5284876001612c2d565b90506000610c6284886002612c2d565b90506000836001600160401b03811115610c7e57610c7e61573e565b604051908082528060200260200182016040528015610cb757816020015b610ca4615028565b815260200190600190039081610c9c5790505b5090506000805b8451811015610d1a57848181518110610cd957610cd9615754565b6020026020010151838381518110610cf357610cf3615754565b602002602001018190525081610d089061576a565b9150610d138161576a565b9050610cbe565b5060005b8351811015610d7a57838181518110610d3957610d39615754565b6020026020010151838381518110610d5357610d53615754565b602002602001018190525081610d689061576a565b9150610d738161576a565b9050610d1e565b509098975050505050505050565b610d95600183833361304d565b5050565b610da360036110a2565b610daf6001858561319a565b610dbb6002838361319a565b50505050565b60008060048560048110610dd757610dd7615754565b6040805160a08101825260029290920292909201805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526001820180548551818402810184019096528086529394929360808601939260009084015b82821015610ec85760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b90910481169284019290925260019081015490911660608301529083529092019101610e56565b50505050815250509050600085600014610efa576000868152600d602090815260408083208784529091529020610f13565b6001600160a01b03851660009081526001602052604090205b604080518082019091528154815260019091015460208201528251909150600090610f4a90889065ffffffffffff1661067d6137e0565b50606084015184519192506001600160601b031690610f7490610e109065ffffffffffff16615726565b42118015610f8e575060408401516001600160601b031615155b15610fca5760408401516001600160601b0316610fb3670de0b6b3a76400008461579e565b610fbd91906157d3565b610fc79082615726565b90505b670de0b6b3a76400006110028460200151610ff3848760000151610fee919061579e565b613818565b610ffd91906157e7565b613886565b61100c91906157d3565b98975050505050505050565b61102260006110a2565b3360009081526001602052604081209061103d8183856138d8565b604080518281526001600160a01b038616602082015291925033917f030f754a3e747235920c21afeca14e881b260d41c7e657ada6c0b049f7eebca991015b60405180910390a2505050565b610d95600283833361304d565b610d95600183836139ee565b6000600482600481106110b7576110b7615754565b600202019050806001016000815481106110d3576110d3615754565b600091825260209091206002909102015465ffffffffffff164210156110f7575050565b805461110e90610e109065ffffffffffff16615726565b4211611118575050565b6001808201805460009261112b91615826565b8154811061113b5761113b615754565b6000918252602082206002909102015465ffffffffffff600160301b90910416915061116d6111686137e0565b613c39565b8354909150600160401b90046001600160601b03166111c4578165ffffffffffff168165ffffffffffff16116111a357806111a5565b815b835465ffffffffffff191665ffffffffffff9190911617909255505050565b825460009081906111e390879065ffffffffffff908116908616611d6a565b86549193509150600160301b900461ffff1681146112245761120481613ca0565b855461ffff91909116600160301b0267ffff000000000000199091161785555b845461127790600160401b90046001600160601b031661124c670de0b6b3a76400008561579e565b61125691906157d3565b86546112729190600160a01b90046001600160601b0316615726565b613d03565b85546001600160601b0391909116600160a01b026001600160a01b0390911617855565ffffffffffff808516908416116112b157826112b3565b835b855465ffffffffffff191665ffffffffffff9190911690811780875560408051928352600160401b82046001600160601b039081166020850152600160a01b9092049091169082015286907f3be3541fc42237d611b30329040bfa4569541d156560acdbbae57640d20b8f469060600160405180910390a2505050505050565b611340600284848461304d565b505050565b61134d613d6b565b6113576000613dc5565b565b611361615078565b611369615078565b611371615078565b611379615078565b6040805160a0810182526004805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b909204909116606084015260058054855181840281018401909652808652600095608086019390929190879084015b828210156114615760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016113ef565b505050915250506040805160a0810182526006805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526007805485518184028101840190965280865295965060009593949293608086019392879084015b828210156115545760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016114e2565b505050915250506040805160a0810182526008805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526009805485518184028101840190965280865295965060009593949293608086019392879084015b828210156116475760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016115d5565b505050915250506040805160a081018252600a805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b9092049091166060840152600b805485518184028101840190965280865295965060009593949293608086019392879084015b8282101561173a5760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016116c8565b50505050815250509050600061174f85613e15565b905060405180606001604052806000815260200186604001516001600160601b031681526020018660800151838151811061178c5761178c615754565b602002602001015181525060405180606001604052806001815260200186604001516001600160601b03168152602001866080015184815181106117d2576117d2615754565b602002602001015181525060405180606001604052806002815260200186604001516001600160601b031681526020018660800151858151811061181857611818615754565b602002602001015181525060405180606001604052806003815260200186604001516001600160601b031681526020018660800151868151811061185e5761185e615754565b60200260200101518152509850985098509850505050505090919293565b611886813361217f565b50565b61135733611018565b610d95600283836139ee565b60606107348260016123da565b6118868133611b94565b600481600481106118c557600080fd5b600202015465ffffffffffff8116915061ffff600160301b820416906001600160601b03600160401b8204811691600160a01b90041684565b6113406001848484613f16565b611340600184848461304d565b611920613d6b565b60038511156119425760405163015f4fdd60e31b815260040160405180910390fd5b8183106119625760405163d67e310960e01b815260040160405180910390fd5b600061196d846141c1565b11806119815750600061197f846141dd565b115b1561199f5760405163f7985df160e01b815260040160405180910390fd5b60006119aa836141c1565b11806119be575060006119bc836141dd565b115b156119dc57604051638b853e2560e01b815260040160405180910390fd5b6000600486600481106119f1576119f1615754565b6002020190506000816001018054905090506000811115611a6c5781600101600182611a1d9190615826565b81548110611a2d57611a2d615754565b6000918252602090912060029091020154600160301b900465ffffffffffff168514611a6c57604051639424dcd960e01b815260040160405180910390fd5b6000611a788686615826565b9050600081611a89610e108a61579e565b611a9391906157d3565b905060006040518060800160405280611aab8a613c39565b65ffffffffffff168152602001611ac189613c39565b65ffffffffffff168152602001611ad784613d03565b6001600160601b03168152602001611aee88613d03565b6001600160601b0390811690915260019687018054808901825560009182526020918290208451600290920201805492850151604086015165ffffffffffff9384166bffffffffffffffffffffffff1995861617600160301b9490921693909302176bffffffffffffffffffffffff60601b1916600160601b92851692909202919091178155606090930151929097018054909716911617909455505050505050505050565b611ba7670de0b6b3a7640000600161579e565b821015611bc65760405162a1ceb560e71b815260040160405180910390fd5b611bd060006110a2565b6001600160a01b038116600090815260016020526040812090611bf49082856141ea565b6040516323b872dd60e01b8152336004820152306024820152604481018490527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015611c67573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8b919061584b565b50604080518481526001600160a01b038416602082015233917fe31c7b8d08ee7db0afa68782e1028ef92305caeea8626633ad44d413e30f6b2f910161107c565b610d956002838333613f16565b611ce360036110a2565b611cef600185856142a2565b610dbb600283836142a2565b611d03613d6b565b60048160048110611d1657611d16615754565b60020201600101805480611d2c57611d2c615868565b60008281526020902060026000199092019182020180546001600160c01b031916815560010180546bffffffffffffffffffffffff19169055905550565b600080600060048660048110611d8257611d82615754565b6040805160a08101825260029290920292909201805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526001820180548551818402810184019096528086529394929360808601939260009084015b82821015611e735760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b90910481169284019290925260019081015490911660608301529083529092019101611e01565b505050508152505090506000816020015161ffff1690508160800151600081518110611ea157611ea1615754565b60200260200101516000015165ffffffffffff16851015611ec9576000935091506120569050565b81608001518181518110611edf57611edf615754565b60200260200101516020015165ffffffffffff1686118015611f29575081608001518181518110611f1257611f12615754565b60200260200101516020015165ffffffffffff1685115b15611f3657600101611ec9565b60408051608081018252600080825260208201819052918101829052606081018290526080840151516000908190855b8181101561203d5787608001518181518110611f8457611f84615754565b60200260200101519450846000015165ffffffffffff168c1115611fa8578b611fb3565b845165ffffffffffff165b9350846020015165ffffffffffff168b1115611fdb57846020015165ffffffffffff16611fdd565b8a5b9250610e1085604001516001600160601b03168585611ffc9190615826565b612006919061579e565b61201091906157d3565b61201a9087615726565b9550828b116120355794985093965061205695505050505050565b600101611f66565b508461204a600183615826565b98509850505050505050505b935093915050565b612066615028565b6001600160a01b038216600090815260016020526040812054818161208c576000612102565b604051632c018f9160e01b8152600060048201526001600160a01b0386166024820152604481018490523090632c018f9190606401602060405180830381865afa1580156120de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121029190615785565b90506000808311612114576000612121565b6121216000876000614769565b6040805160c08101825260008152602080820197909752808201959095526060850193909352608084015250805180820190915260025481526003549281019290925260a081019190915292915050565b610dbb84848484336109c2565b61218960006110a2565b33600090815260016020526040902080548314156121f75760006121af600083856138d8565b604080518281526001600160a01b038616602082015291925033917f030f754a3e747235920c21afeca14e881b260d41c7e657ada6c0b049f7eebca9910160405180910390a2505b6122036000828561493d565b60405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063a9059cbb90612251908590879060040161587e565b6020604051808303816000875af1158015612270573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612294919061584b565b50604080518481526001600160a01b038416602082015233917f56c54ba9bd38d8fd62012e42c7ee564519b09763c426d331b3661b537ead19b2910161107c565b6113406002848484613f16565b6122ea613d6b565b6001600160a01b0381166123545760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084015b60405180910390fd5b61188681613dc5565b60606107348260026123da565b6001600160a01b0381166000908152600160208190526040822054906123909084614a0c565b61239a9082615726565b90506123a7600284614a0c565b6123b19082615726565b90506123bc83614b5a565b6123c69082615726565b9392505050565b610d956001838333613f16565b6000818152600c60205260408082205490516370a0823160e01b81526001600160a01b0385811660048301526060939216906370a0823190602401602060405180830381865afa158015612432573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124569190615785565b90506000808211612498576040805160008082526020820190925290612492565b61247f615028565b8152602001906001900390816124775790505b506124eb565b816001600160401b038111156124b0576124b061573e565b6040519080825280602002602001820160405280156124e957816020015b6124d6615028565b8152602001906001900390816124ce5790505b505b9050816124fb5791506107349050565b60005b82811015612792576000858152600c6020526040808220549051632f745c5960e01b81526001600160a01b0390911690632f745c5990612544908a90869060040161587e565b602060405180830381865afa158015612561573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125859190615785565b6000878152600d60209081526040808320848452909152812054919250816125ae576000612624565b604051632c018f9160e01b8152600481018990526001600160a01b038a166024820152604481018490523090632c018f9190606401602060405180830381865afa158015612600573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126249190615785565b90506000808311612636576000612641565b612641898b86614769565b604080518082019091526002548152600380546020830152919250908a141561272c576000858152600f6020908152604080832060018452909152902054600160f81b900460ff16156126ca57506040805180820182526000868152600f6020908152838220600180845290825293909120546001600160f81b0316825281019190915261272c565b6000858152600f6020908152604080832060028452909152902054600160f81b900460ff161561272c57506040805180820182526000868152600f6020908152838220600280845290825293909120546001600160f81b031682528101919091525b60006040518060c001604052808c81526020018781526020018681526020018581526020018481526020018381525090508088888151811061277057612770615754565b60200260200101819052505050505050508061278b9061576a565b90506124fe565b50949350505050565b81600080808080805b86811015612a83578989828181106127be576127be615754565b6127d49260206040909202019081019150615897565b60008c8152600c6020526040908190205490516331a9108f60e11b81526001600160801b039290921660048301819052975033916001600160a01b0390911690636352211e90602401602060405180830381865afa15801561283a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061285e91906158c0565b6001600160a01b03161461288557604051632b19ae7560e01b815260040160405180910390fd5b89898281811061289757612897615754565b90506040020160200160208101906128af9190615897565b6003600052600c602052600080516020615b1f833981519152546040516331a9108f60e11b81526001600160801b039290921660048301819052965033916001600160a01b0390911690636352211e90602401602060405180830381865afa15801561291f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061294391906158c0565b6001600160a01b03161461296a57604051632c8348bb60e01b815260040160405180910390fd5b60008b8152600e602090815260408083208984528252808320888452600f83528184208f8552909252909120815491945092506001600160f81b0316851415806129bd57508254600160f81b900460ff16155b806129d2575081546001600160f81b03168614155b806129e657508154600160f81b900460ff16155b15612a04576040516366640ced60e11b815260040160405180910390fd5b6000858152600080516020615aff833981519152602052604081209450612a2d6003868b6138d8565b60408051828152602081018f90529081018990526060810188905290915033907f89d57e873af45054d40b801ca64ca06a1627c5682ab9be494a9f2846ef157d8a9060800160405180910390a2506001016127a4565b5050505050505050505050565b60008060005b85811015612792576000848152600c6020526040808220549051632f745c5960e01b81526001600160a01b0390911690632f745c5990612adc908990869060040161587e565b602060405180830381865afa158015612af9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b1d9190615785565b6000868152600e60209081526040808320848452909152902054909150600160f81b900460ff1615612c1c576000858152600e6020908152604080832084845282528083205460038452600c909252600080516020615b1f8339815191525490516331a9108f60e11b81526001600160f81b039092166004830181905292916001600160a01b0390911690636352211e90602401602060405180830381865afa158015612bce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bf291906158c0565b9050876001600160a01b0316816001600160a01b031614612c1957612c168561576a565b94505b50505b50612c268161576a565b9050612a96565b60606000846001600160401b03811115612c4957612c4961573e565b604051908082528060200260200182016040528015612c8257816020015b612c6f615028565b815260200190600190039081612c675790505b5090506000805b6000858152600c6020526040908190205490516370a0823160e01b81526001600160a01b038881166004830152909116906370a0823190602401602060405180830381865afa158015612ce0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d049190615785565b811015613042576000858152600c6020526040808220549051632f745c5960e01b81526001600160a01b0390911690632f745c5990612d49908a90869060040161587e565b602060405180830381865afa158015612d66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d8a9190615785565b6000878152600e60209081526040808320848452909152902054909150600160f81b900460ff1615613031576000868152600e6020908152604080832084845282528083205460038452600c909252600080516020615b1f8339815191525490516331a9108f60e11b81526001600160f81b039092166004830181905292916001600160a01b0390911690636352211e90602401602060405180830381865afa158015612e3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e5f91906158c0565b9050886001600160a01b0316816001600160a01b03161461302e576000828152600080516020615aff83398151915260205260408120549081612ea3576000612f19565b604051632c018f9160e01b8152600360048201526001600160a01b0384166024820152604481018590523090632c018f9190606401602060405180830381865afa158015612ef5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f199190615785565b90506000808311612f2b576000612f37565b612f3760038587614769565b905060006002604051806040016040529081600082015481526020016001820154815250509050600f600087815260200190815260200160002060008d8152602001908152602001600020600001601f9054906101000a900460ff1615612fcc57506040805180820182526000878152600f60209081528382208f83528152929020546001600160f81b031681529081018c90525b60006040518060c0016040528060038152602001888152602001868152602001858152602001848152602001838152509050808b8b8151811061301157613011615754565b6020026020010181905250896130269061576a565b995050505050505b50505b5061303b8161576a565b9050612c89565b509095945050505050565b613056846110a2565b60008083815b818110156131905786868281811061307657613076615754565b60008b8152600c60209081526040918290205491516331a9108f60e11b81529202939093013560048201819052965033926001600160a01b03169150636352211e90602401602060405180830381865afa1580156130d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130fc91906158c0565b6001600160a01b03161461312357604051632e6c18c960e11b815260040160405180910390fd5b6000888152600d6020908152604080832087845290915290206131478982886138d8565b60408051828152602081018890529195508a9133917fd334b3114fc25cbd72389ff9c361d5f8b0924e35fa237c65ac209a2cdcf4ba13910160405180910390a35060010161305c565b5050505050505050565b604080516080810182526000808252602082018190529181018290526060810182905281906000808086815b81811015612a83578989828181106131e0576131e0615754565b9050608002018036038101906131f6919061590d565b60008c8152600c60205260409081902054825191516331a9108f60e11b815263ffffffff90921660048301529197506001600160a01b0390911690636352211e90602401602060405180830381865afa158015613257573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061327b91906158c0565b6003600052600c6020908152600080516020615b1f83398151915254908801516040516331a9108f60e11b815263ffffffff90911660048201529199506001600160a01b031690636352211e90602401602060405180830381865afa1580156132e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061330c91906158c0565b96506001600160a01b0388163314613347576001600160a01b038716331461334757604051634a2f386560e01b815260040160405180910390fd5b600e60008c81526020019081526020016000206000876000015163ffffffff1681526020019081526020016000209450600f6000876020015163ffffffff16815260200190815260200160002060008c81526020019081526020016000209350856020015163ffffffff168560000160009054906101000a90046001600160f81b03166001600160f81b03161415806133e957508454600160f81b900460ff16155b806134075750855184546001600160f81b031663ffffffff90911614155b8061341b57508354600160f81b900460ff16155b15613439576040516366640ced60e11b815260040160405180910390fd5b60036000908152600d60209081528781015163ffffffff168252600080516020615aff83398151915290526040902060608701519093506134a357825460408701516001600160b81b031614156134a35760405163230a658160e11b815260040160405180910390fd5b866001600160a01b0316886001600160a01b0316146134de5785606001516134de5760405163e373a08560e01b815260040160405180910390fd5b8560600151156136a85760006134f66003858a6138d8565b9050604051806040016040528060006001600160f81b0316815260200160001515815250600e60008e81526020019081526020016000206000896000015163ffffffff16815260200190815260200160002060008201518160000160006101000a8154816001600160f81b0302191690836001600160f81b03160217905550602082015181600001601f6101000a81548160ff021916908315150217905550905050604051806040016040528060006001600160f81b0316815260200160001515815250600f6000896020015163ffffffff16815260200190815260200160002060008e815260200190815260200160002060008201518160000160006101000a8154816001600160f81b0302191690836001600160f81b03160217905550602082015181600001601f6101000a81548160ff021916908315150217905550905050336001600160a01b03167f89d57e873af45054d40b801ca64ca06a1627c5682ab9be494a9f2846ef157d8a828e8a600001518b6020015160405161369e9493929190938452602084019290925263ffffffff908116604084015216606082015260800190565b60405180910390a2505b600086606001516136c65786604001516001600160b81b03166136c9565b83545b90506136d76003858361493d565b60405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063a9059cbb90613725908c90859060040161587e565b6020604051808303816000875af1158015613744573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613768919061584b565b50336001600160a01b03167f63a13470c4507d4f2c9d1bad1b7d603229456f8ebe7d3048d5cd8a02cf8d1ee6828e8a600001518b602001516040516137cf9493929190938452602084019290925263ffffffff908116604084015216606082015260800190565b60405180910390a2506001016131c6565b60006137eb426141dd565b6137f4426141c1565b6137ff90603c61579e565b6138099190615726565b6138139042615826565b905090565b60006001600160ff1b038211156138825760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b606482015260840161234b565b5090565b6000808212156138825760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f736974697665604482015260640161234b565b600080600485600481106138ee576138ee615754565b600202018054855491925060009161391b91610fee91600160a01b9091046001600160601b03169061579e565b9050670de0b6b3a7640000613939866001015483610ffd91906157e7565b61394391906157d3565b60018601829055925082156139e55760405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063a9059cbb906139a0908790879060040161587e565b6020604051808303816000875af11580156139bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139e3919061584b565b505b50509392505050565b6139f7836110a2565b600080808381805b82811015613b9057878782818110613a1957613a19615754565b613a2f9260206040909202019081019150615999565b60008a8152600d6020908152604080832063ffffffff9490941680845293909152902080549197509450613afe576000898152600c6020526040908190205490516331a9108f60e11b81526004810188905233916001600160a01b031690636352211e90602401602060405180830381865afa158015613ab3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ad791906158c0565b6001600160a01b031614613afe57604051632e6c18c960e11b815260040160405180910390fd5b878782818110613b1057613b10615754565b9050604002016020016020810190613b2891906159b4565b6001600160e01b03169450613b3e898587614f51565b613b488583615726565b60408051878152602081018990529193508a9133917f8863bdbe28273fa04cbc67c9e51785cff607a419b43ee367e4c3c01edb1d7b56910160405180910390a36001016139ff565b508015613190576040516323b872dd60e01b8152336004820152306024820152604481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af1158015613c0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c2e919061584b565b505050505050505050565b600065ffffffffffff8211156138825760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526538206269747360d01b606482015260840161234b565b600061ffff8211156138825760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b606482015260840161234b565b60006001600160601b038211156138825760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203960448201526536206269747360d01b606482015260840161234b565b6000546001600160a01b031633146113575760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161234b565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080826020015161ffff16905082608001518181518110613e3957613e39615754565b60200260200101516000015165ffffffffffff16421015613e5a5792915050565b50602082015161ffff165b826080015151811015613ed957600083608001518281518110613e8a57613e8a615754565b6020026020010151905042816000015165ffffffffffff1611158015613ebc5750806020015165ffffffffffff164211155b15613ec8575092915050565b50613ed28161576a565b9050613e65565b60405162461bcd60e51b8152602060048201526012602482015271191a5cdd1c9a589d5d1a5bdb88195b99195960721b604482015260640161234b565b613f1f846110a2565b600080838180805b8381101561411d57888882818110613f4157613f41615754565b613f579260206040909202019081019150615999565b60008b8152600c6020526040908190205490516331a9108f60e11b815263ffffffff9290921660048301819052975033916001600160a01b0390911690636352211e90602401602060405180830381865afa158015613fba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613fde91906158c0565b6001600160a01b03161461400557604051632e6c18c960e11b815260040160405180910390fd5b88888281811061401757614017615754565b905060400201602001602081019061402f91906159b4565b60008b8152600d602090815260408083208a8452909152902080546001600160e01b0392909216965092508514156140b057600061406e8b848a6138d8565b60408051828152602081018a90529192508c9133917fd334b3114fc25cbd72389ff9c361d5f8b0924e35fa237c65ac209a2cdcf4ba13910160405180910390a3505b6140bb8a838761493d565b6140c58584615726565b604080518781526001600160a01b038a1660208201529081018890529093508a9033907f46916533b23d6665275e4143ec7eeb4b6b4ae92178ebbfe99f112564d2c7b1aa9060600160405180910390a3600101613f27565b508115613c2e5760405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063a9059cbb90614172908990869060040161587e565b6020604051808303816000875af1158015614191573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141b5919061584b565b50505050505050505050565b6000806141d0610e10846159dd565b90506123c6603c826157d3565b6000610734603c836159dd565b6000600484600481106141ff576141ff615754565b600202019050818360000160008282546142199190615726565b90915550614228905082613d03565b8154829060089061424a908490600160401b90046001600160601b03166159f1565b82546101009290920a6001600160601b0381810219909316918316021790915582546142849250610fee91600160a01b909104168461579e565b8360010160008282546142979190615a1c565b909155505050505050565b604080516060810182526000808252602082018190529181018290528291906000805b848110156146c2578686828181106142df576142df615754565b9050606002018036038101906142f59190615a5d565b60036000908152600d60209081528083015163ffffffff168252600080516020615aff83398151915290526040902080549194509250614590576000888152600c60205260409081902054845191516331a9108f60e11b815263ffffffff909216600483015233916001600160a01b0390911690636352211e90602401602060405180830381865afa15801561438f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143b391906158c0565b6001600160a01b03161415806143f057506000888152600e60209081526040808320865163ffffffff168452909152902054600160f81b900460ff165b1561440e576040516351fedda960e11b815260040160405180910390fd5b6003600052600c6020908152600080516020615b1f83398151915254908401516040516331a9108f60e11b815263ffffffff909116600482015233916001600160a01b031690636352211e90602401602060405180830381865afa15801561447a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061449e91906158c0565b6001600160a01b03161415806144dc575060208381015163ffffffff166000908152600f825260408082208b83529092522054600160f81b900460ff165b156144fa57604051636f395b0f60e11b815260040160405180910390fd5b6040805180820182526020808601805163ffffffff9081168452600183850181815260008f8152600e86528781208b51851682528652878120965191511515600160f81b9081026001600160f81b0393841617909755875180890189528b518516815280870193845294519093168352600f85528683208f84529094529490209051935115159092029216919091179055614623565b60208381015163ffffffff9081166000908152600f835260408082208c8352909352919091205484516001600160f81b03909116911614158061460557506000888152600e60209081526040808320865163ffffffff9081168552908352922054908501516001600160f81b03909116911614155b156146235760405163ba52c1b560e01b815260040160405180910390fd5b61463c60038385604001516001600160b81b0316614f51565b6040830151614654906001600160b81b031685615726565b604084810151855160208088015184516001600160b81b0390941684529083018d905263ffffffff91821683850152166060820152905191955033917fb3f27c1805319c01731f5717816fcfc579c3452c5ff4ffadc41284a7288f24ef9181900360800190a26001016142c5565b508215614760576040516323b872dd60e01b8152336004820152306024820152604481018490527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906323b872dd906064016020604051808303816000875af115801561473c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613190919061584b565b50505050505050565b6000806004856004811061477f5761477f615754565b6040805160a08101825260029290920292909201805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526001820180548551818402810184019096528086529394929360808601939260009084015b828210156148705760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016147fe565b505050508152505090506000856000146148a2576000868152600d6020908152604080832087845290915290206148bb565b6001600160a01b03851660009081526001602052604090205b60405180604001604052908160008201548152602001600182015481525050905060006148f087846020015161ffff166109ed565b905082604001516001600160601b031681604001516001600160601b0316836000015161491d919061579e565b61492890601861579e565b61493291906157d3565b979650505050505050565b815481111561495f57604051639acaefc760e01b815260040160405180910390fd5b60006004846004811061497457614974615754565b6002020190508183600001600082825461498e9190615826565b9091555061499d905082613d03565b815482906008906149bf908490600160401b90046001600160601b0316615ad6565b82546101009290920a6001600160601b0381810219909316918316021790915582546149f99250610fee91600160a01b909104168461579e565b83600101600082825461429791906157e7565b6000828152600c60205260408082205490516370a0823160e01b81526001600160a01b038481166004830152839283929116906370a0823190602401602060405180830381865afa158015614a65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a899190615785565b905060005b81811015614b50576000868152600c6020526040808220549051632f745c5960e01b81526001600160a01b0390911690632f745c5990614ad4908990869060040161587e565b602060405180830381865afa158015614af1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b159190615785565b6000888152600d60209081526040808320848452909152902054909150614b3c9085615726565b93505080614b499061576a565b9050614a8e565b5090949350505050565b60016000908152600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c546040516370a0823160e01b81526001600160a01b038481166004830152839283929116906370a0823190602401602060405180830381865afa158015614bd2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bf69190615785565b905060005b81811015614d535760016000908152600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c54604051632f745c5960e01b81526001600160a01b0390911690632f745c5990614c60908990869060040161587e565b602060405180830381865afa158015614c7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ca19190615785565b60008181527fa7c5ba7114a813b50159add3a36832908dc83db71d0b9a24c2ad0f83be9582076020526040902054909150600160f81b900460ff1615614d425760008181527fa7c5ba7114a813b50159add3a36832908dc83db71d0b9a24c2ad0f83be95820760209081526040808320546001600160f81b0316808452600080516020615aff83398151915290925290912054614d3e9086615726565b9450505b50614d4c8161576a565b9050614bfb565b506002600052600c6020527f5d6016397a73f5e079297ac5a36fef17b4d9c3831618e63ab105738020ddd720546040516370a0823160e01b81526001600160a01b038681166004830152909116906370a0823190602401602060405180830381865afa158015614dc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614deb9190615785565b905060005b81811015614f485760026000908152600c6020527f5d6016397a73f5e079297ac5a36fef17b4d9c3831618e63ab105738020ddd72054604051632f745c5960e01b81526001600160a01b0390911690632f745c5990614e55908990869060040161587e565b602060405180830381865afa158015614e72573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e969190615785565b60008181527f9adb202b1492743bc00c81d33cdc6423fa8c79109027eb6a845391e8fc1f04816020526040902054909150600160f81b900460ff1615614f375760008181527f9adb202b1492743bc00c81d33cdc6423fa8c79109027eb6a845391e8fc1f048160209081526040808320546001600160f81b0316808452600080516020615aff83398151915290925290912054614f339086615726565b9450505b50614f418161576a565b9050614df0565b50909392505050565b614f64670de0b6b3a7640000600161579e565b811015614f835760405162a1ceb560e71b815260040160405180910390fd5b60048360048110614f9657614f96615754565b6002020160010160048460048110614fb057614fb0615754565b60020201548154600160301b90910461ffff16908110614fd257614fd2615754565b600091825260209091206001600290920201015482546001600160601b0390911690614ffe9083615726565b111561501d57604051633c0eb0dd60e21b815260040160405180910390fd5b6113408383836141ea565b6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001615073604051806040016040528060008152602001600081525090565b905290565b6040518060600160405280600081526020016000815260200161507360408051608081018252600080825260208201819052918101829052606081019190915290565b6001600160a01b038116811461188657600080fd5b6000602082840312156150e257600080fd5b81356123c6816150bb565b805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a0810151805160a0840152602081015160c0840152505050565b6020808252825182820181905260009190848201906040850190845b81811015615176576151638385516150ed565b9284019260e09290920191600101615150565b50909695505050505050565b60008083601f84011261519457600080fd5b5081356001600160401b038111156151ab57600080fd5b6020830191508360208260061b85010111156151c657600080fd5b9250929050565b6000806000806000606086880312156151e557600080fd5b85356001600160401b03808211156151fc57600080fd5b61520889838a01615182565b9097509550602088013591508082111561522157600080fd5b5061522e88828901615182565b9094509250506040860135615242816150bb565b809150509295509295909350565b6000806040838503121561526357600080fd5b50508035926020909101359150565b65ffffffffffff8082511683528060208301511660208401525060408101516001600160601b03808216604085015280606084015116606085015250505050565b608081016107348284615272565b6000602082840312156152d357600080fd5b5035919050565b60008083601f8401126152ec57600080fd5b5081356001600160401b0381111561530357600080fd5b6020830191508360208260051b85010111156151c657600080fd5b6000806020838503121561533157600080fd5b82356001600160401b0381111561534757600080fd5b615353858286016152da565b90969095509350505050565b60008083601f84011261537157600080fd5b5081356001600160401b0381111561538857600080fd5b6020830191508360208260071b85010111156151c657600080fd5b600080600080604085870312156153b957600080fd5b84356001600160401b03808211156153d057600080fd5b6153dc8883890161535f565b909650945060208701359150808211156153f557600080fd5b506154028782880161535f565b95989497509550505050565b60008060006060848603121561542357600080fd5b833592506020840135615435816150bb565b929592945050506040919091013590565b6000806020838503121561545957600080fd5b82356001600160401b0381111561546f57600080fd5b61535385828601615182565b60008060006040848603121561549057600080fd5b83356001600160401b038111156154a657600080fd5b6154b2868287016152da565b90945092505060208401356154c6816150bb565b809150509250925092565b805182526020810151602083015260408101516113406040840182615272565b610300810161550082876154d1565b61550d60c08301866154d1565b61551b6101808301856154d1565b6155296102408301846154d1565b95945050505050565b60008060006040848603121561554757600080fd5b83356001600160401b0381111561555d57600080fd5b6154b286828701615182565b600080600080600060a0868803121561558157600080fd5b505083359560208501359550604085013594606081013594506080013592509050565b600080604083850312156155b757600080fd5b8235915060208301356155c9816150bb565b809150509250929050565b60008083601f8401126155e657600080fd5b5081356001600160401b038111156155fd57600080fd5b6020830191508360206060830285010111156151c657600080fd5b6000806000806040858703121561562e57600080fd5b84356001600160401b038082111561564557600080fd5b615651888389016155d4565b9096509450602087013591508082111561566a57600080fd5b50615402878288016155d4565b60008060006060848603121561568c57600080fd5b505081359360208301359350604090920135919050565b60e0810161073482846150ed565b600080600080604085870312156156c757600080fd5b84356001600160401b03808211156156de57600080fd5b6156ea88838901615182565b9096509450602087013591508082111561570357600080fd5b5061540287828801615182565b634e487b7160e01b600052601160045260246000fd5b6000821982111561573957615739615710565b500190565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600060001982141561577e5761577e615710565b5060010190565b60006020828403121561579757600080fd5b5051919050565b60008160001904831182151516156157b8576157b8615710565b500290565b634e487b7160e01b600052601260045260246000fd5b6000826157e2576157e26157bd565b500490565b60008083128015600160ff1b85018412161561580557615805615710565b6001600160ff1b038401831381161561582057615820615710565b50500390565b60008282101561583857615838615710565b500390565b801515811461188657600080fd5b60006020828403121561585d57600080fd5b81516123c68161583d565b634e487b7160e01b600052603160045260246000fd5b6001600160a01b03929092168252602082015260400190565b6000602082840312156158a957600080fd5b81356001600160801b03811681146123c657600080fd5b6000602082840312156158d257600080fd5b81516123c6816150bb565b803563ffffffff811681146158f157600080fd5b919050565b80356001600160b81b03811681146158f157600080fd5b60006080828403121561591f57600080fd5b604051608081018181106001600160401b038211171561594f57634e487b7160e01b600052604160045260246000fd5b60405261595b836158dd565b8152615969602084016158dd565b602082015261597a604084016158f6565b6040820152606083013561598d8161583d565b60608201529392505050565b6000602082840312156159ab57600080fd5b6123c6826158dd565b6000602082840312156159c657600080fd5b81356001600160e01b03811681146123c657600080fd5b6000826159ec576159ec6157bd565b500690565b60006001600160601b03808316818516808303821115615a1357615a13615710565b01949350505050565b600080821280156001600160ff1b0384900385131615615a3e57615a3e615710565b600160ff1b8390038412811615615a5757615a57615710565b50500190565b600060608284031215615a6f57600080fd5b604051606081018181106001600160401b0382111715615a9f57634e487b7160e01b600052604160045260246000fd5b604052615aab836158dd565b8152615ab9602084016158dd565b6020820152615aca604084016158f6565b60408201529392505050565b60006001600160601b0383811690831681811015615af657615af6615710565b03939250505056fe26b4a10d0f0b04925c23bd4480ee147c916e5e87a7d68206a533dad160ac81e2c0da782485e77ae272268ae0a3ff44c1552ecb60b3743924de17a815e0a3cfd7a2646970667358221220bd4bd0caba5cbe67828994269b695246befece3b19535639581f2dde7c8a987464736f6c634300080a00330000000000000000000000004d224452801aced8b2f0aebe155379bb5d594381000000000000000000000000bc4ca0eda7647a8ab7c2061c2e118a18a936f13d00000000000000000000000060e4d786628fea6478f785a6d7e704777c86a7c6000000000000000000000000ba30e5f9bb24caa003e9f2f0497ad287fdf95623

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102735760003560e01c80639860037e11610151578063d346cbd9116100c3578063e4e8184711610087578063e4e81847146106b5578063ed23c906146106c8578063f2fde38b146106db578063f4c6f602146106ee578063f567918914610701578063fe31446c1461071457600080fd5b8063d346cbd914610649578063d363dc171461065c578063d7464ee91461066f578063d9f11fb214610682578063e0347e4f146106a257600080fd5b8063aceb362911610115578063aceb3629146105aa578063b4f95752146105bd578063b682e859146105fd578063bb628f2014610610578063bd5023a914610623578063c63389c31461063657600080fd5b80639860037e146104dd57806398ada4a2146104f05780639dcaafb414610522578063ac4afa3814610535578063ac7ad9ba1461058357600080fd5b8063304f88c0116101ea578063715018a6116101ae578063715018a61461047e578063770dade5146104865780637f60d3381461049e5780638279e760146104b15780638da5cb5b146104b95780638ecbffa7146104ca57600080fd5b8063304f88c0146103d3578063381b46821461043257806346583a051461044557806351eb05a61461045857806357a263001461046b57600080fd5b80630bb4d82a1161023c5780630bb4d82a146103255780630ed368f11461036657806320a325d01461037957806326fb22491461038c5780632c018f911461039f5780632ee2de66146103c057600080fd5b8062191b441461027857806304238994146102a157806305ece226146102b457806307f5fa4a146102f057806309e833c614610305575b600080fd5b61028b6102863660046150d0565b610727565b6040516102989190615134565b60405180910390f35b61028b6102af3660046150d0565b61073a565b6102db6102c23660046150d0565b6001602081905260009182526040909120805491015482565b60408051928352602083019190915201610298565b6103036102fe3660046151cd565b6109c2565b005b610318610313366004615250565b6109ed565b60405161029891906152b3565b61034e6103333660046152c1565b600c602052600090815260409020546001600160a01b031681565b6040516001600160a01b039091168152602001610298565b61028b6103743660046150d0565b610aa3565b61030361038736600461531e565b610d88565b61030361039a3660046153a3565b610d99565b6103b26103ad36600461540e565b610dc1565b604051908152602001610298565b6103036103ce3660046150d0565b611018565b6104136103e1366004615250565b600e6020908152600092835260408084209091529082529020546001600160f81b03811690600160f81b900460ff1682565b604080516001600160f81b039093168352901515602083015201610298565b61030361044036600461531e565b611089565b610303610453366004615446565b611096565b6103036104663660046152c1565b6110a2565b61030361047936600461547b565b611333565b610303611345565b61048e611359565b60405161029894939291906154f1565b6103036104ac3660046152c1565b61187c565b610303611889565b6000546001600160a01b031661034e565b6103036104d8366004615446565b611892565b61028b6104eb3660046150d0565b61189e565b6102db6104fe366004615250565b600d6020908152600092835260408084209091529082529020805460019091015482565b6103036105303660046152c1565b6118ab565b6105486105433660046152c1565b6118b5565b6040805165ffffffffffff909516855261ffff90931660208501526001600160601b0391821692840192909252166060820152608001610298565b61034e7f0000000000000000000000004d224452801aced8b2f0aebe155379bb5d59438181565b6103036105b8366004615532565b6118fe565b6104136105cb366004615250565b600f6020908152600092835260408084209091529082529020546001600160f81b03811690600160f81b900460ff1682565b61030361060b36600461547b565b61190b565b61030361061e366004615569565b611918565b6103036106313660046155a4565b611b94565b610303610644366004615446565b611ccc565b610303610657366004615618565b611cd9565b61030361066a3660046152c1565b611cfb565b6102db61067d366004615677565b611d6a565b6106956106903660046150d0565b61205e565b60405161029891906156a3565b6103036106b03660046156b1565b612172565b6103036106c33660046155a4565b61217f565b6103036106d6366004615532565b6122d5565b6103036106e93660046150d0565b6122e2565b61028b6106fc3660046150d0565b61235d565b6103b261070f3660046150d0565b61236a565b610303610722366004615446565b6123cd565b60606107348260036123da565b92915050565b606060006107478361205e565b905060006107548461189e565b905060006107618561235d565b9050600061076e86610727565b9050600061077b87610aa3565b9050600081518351855187516107919190615726565b61079b9190615726565b6107a59190615726565b6107b0906001615726565b90506000816001600160401b038111156107cc576107cc61573e565b60405190808252806020026020018201604052801561080557816020015b6107f2615028565b8152602001906001900390816107ea5790505b50905060008782828151811061081d5761081d615754565b6020026020010181905250806108329061576a565b905060005b87518110156108935787818151811061085257610852615754565b602002602001015183838151811061086c5761086c615754565b6020026020010181905250816108819061576a565b915061088c8161576a565b9050610837565b5060005b86518110156108f3578681815181106108b2576108b2615754565b60200260200101518383815181106108cc576108cc615754565b6020026020010181905250816108e19061576a565b91506108ec8161576a565b9050610897565b5060005b85518110156109535785818151811061091257610912615754565b602002602001015183838151811061092c5761092c615754565b6020026020010181905250816109419061576a565b915061094c8161576a565b90506108f7565b5060005b84518110156109b35784818151811061097257610972615754565b602002602001015183838151811061098c5761098c615754565b6020026020010181905250816109a19061576a565b91506109ac8161576a565b9050610957565b50909998505050505050505050565b6109cc60036110a2565b6109d9600186868461279b565b6109e6600284848461279b565b5050505050565b60408051608081018252600080825260208201819052918101829052606081019190915260048360048110610a2457610a24615754565b600202016001018281548110610a3c57610a3c615754565b6000918252602091829020604080516080810182526002909302909101805465ffffffffffff8082168552600160301b820416948401949094526001600160601b03600160601b909404841691830191909152600101549091166060820152905092915050565b60016000908152600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c546040516370a0823160e01b81526001600160a01b03848116600483015260609392610b4b929116906370a0823190602401602060405180830381865afa158015610b1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b439190615785565b846001612a90565b60026000908152600c6020527f5d6016397a73f5e079297ac5a36fef17b4d9c3831618e63ab105738020ddd720546040516370a0823160e01b81526001600160a01b0387811660048301529394509192610bf4929116906370a0823190602401602060405180830381865afa158015610bc8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bec9190615785565b856002612a90565b90506000610c028284615726565b905080610c44576040805160008082526020820190925290610c3a565b610c27615028565b815260200190600190039081610c1f5790505b5095945050505050565b6000610c5284876001612c2d565b90506000610c6284886002612c2d565b90506000836001600160401b03811115610c7e57610c7e61573e565b604051908082528060200260200182016040528015610cb757816020015b610ca4615028565b815260200190600190039081610c9c5790505b5090506000805b8451811015610d1a57848181518110610cd957610cd9615754565b6020026020010151838381518110610cf357610cf3615754565b602002602001018190525081610d089061576a565b9150610d138161576a565b9050610cbe565b5060005b8351811015610d7a57838181518110610d3957610d39615754565b6020026020010151838381518110610d5357610d53615754565b602002602001018190525081610d689061576a565b9150610d738161576a565b9050610d1e565b509098975050505050505050565b610d95600183833361304d565b5050565b610da360036110a2565b610daf6001858561319a565b610dbb6002838361319a565b50505050565b60008060048560048110610dd757610dd7615754565b6040805160a08101825260029290920292909201805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526001820180548551818402810184019096528086529394929360808601939260009084015b82821015610ec85760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b90910481169284019290925260019081015490911660608301529083529092019101610e56565b50505050815250509050600085600014610efa576000868152600d602090815260408083208784529091529020610f13565b6001600160a01b03851660009081526001602052604090205b604080518082019091528154815260019091015460208201528251909150600090610f4a90889065ffffffffffff1661067d6137e0565b50606084015184519192506001600160601b031690610f7490610e109065ffffffffffff16615726565b42118015610f8e575060408401516001600160601b031615155b15610fca5760408401516001600160601b0316610fb3670de0b6b3a76400008461579e565b610fbd91906157d3565b610fc79082615726565b90505b670de0b6b3a76400006110028460200151610ff3848760000151610fee919061579e565b613818565b610ffd91906157e7565b613886565b61100c91906157d3565b98975050505050505050565b61102260006110a2565b3360009081526001602052604081209061103d8183856138d8565b604080518281526001600160a01b038616602082015291925033917f030f754a3e747235920c21afeca14e881b260d41c7e657ada6c0b049f7eebca991015b60405180910390a2505050565b610d95600283833361304d565b610d95600183836139ee565b6000600482600481106110b7576110b7615754565b600202019050806001016000815481106110d3576110d3615754565b600091825260209091206002909102015465ffffffffffff164210156110f7575050565b805461110e90610e109065ffffffffffff16615726565b4211611118575050565b6001808201805460009261112b91615826565b8154811061113b5761113b615754565b6000918252602082206002909102015465ffffffffffff600160301b90910416915061116d6111686137e0565b613c39565b8354909150600160401b90046001600160601b03166111c4578165ffffffffffff168165ffffffffffff16116111a357806111a5565b815b835465ffffffffffff191665ffffffffffff9190911617909255505050565b825460009081906111e390879065ffffffffffff908116908616611d6a565b86549193509150600160301b900461ffff1681146112245761120481613ca0565b855461ffff91909116600160301b0267ffff000000000000199091161785555b845461127790600160401b90046001600160601b031661124c670de0b6b3a76400008561579e565b61125691906157d3565b86546112729190600160a01b90046001600160601b0316615726565b613d03565b85546001600160601b0391909116600160a01b026001600160a01b0390911617855565ffffffffffff808516908416116112b157826112b3565b835b855465ffffffffffff191665ffffffffffff9190911690811780875560408051928352600160401b82046001600160601b039081166020850152600160a01b9092049091169082015286907f3be3541fc42237d611b30329040bfa4569541d156560acdbbae57640d20b8f469060600160405180910390a2505050505050565b611340600284848461304d565b505050565b61134d613d6b565b6113576000613dc5565b565b611361615078565b611369615078565b611371615078565b611379615078565b6040805160a0810182526004805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b909204909116606084015260058054855181840281018401909652808652600095608086019390929190879084015b828210156114615760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016113ef565b505050915250506040805160a0810182526006805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526007805485518184028101840190965280865295965060009593949293608086019392879084015b828210156115545760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016114e2565b505050915250506040805160a0810182526008805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526009805485518184028101840190965280865295965060009593949293608086019392879084015b828210156116475760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016115d5565b505050915250506040805160a081018252600a805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b9092049091166060840152600b805485518184028101840190965280865295965060009593949293608086019392879084015b8282101561173a5760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016116c8565b50505050815250509050600061174f85613e15565b905060405180606001604052806000815260200186604001516001600160601b031681526020018660800151838151811061178c5761178c615754565b602002602001015181525060405180606001604052806001815260200186604001516001600160601b03168152602001866080015184815181106117d2576117d2615754565b602002602001015181525060405180606001604052806002815260200186604001516001600160601b031681526020018660800151858151811061181857611818615754565b602002602001015181525060405180606001604052806003815260200186604001516001600160601b031681526020018660800151868151811061185e5761185e615754565b60200260200101518152509850985098509850505050505090919293565b611886813361217f565b50565b61135733611018565b610d95600283836139ee565b60606107348260016123da565b6118868133611b94565b600481600481106118c557600080fd5b600202015465ffffffffffff8116915061ffff600160301b820416906001600160601b03600160401b8204811691600160a01b90041684565b6113406001848484613f16565b611340600184848461304d565b611920613d6b565b60038511156119425760405163015f4fdd60e31b815260040160405180910390fd5b8183106119625760405163d67e310960e01b815260040160405180910390fd5b600061196d846141c1565b11806119815750600061197f846141dd565b115b1561199f5760405163f7985df160e01b815260040160405180910390fd5b60006119aa836141c1565b11806119be575060006119bc836141dd565b115b156119dc57604051638b853e2560e01b815260040160405180910390fd5b6000600486600481106119f1576119f1615754565b6002020190506000816001018054905090506000811115611a6c5781600101600182611a1d9190615826565b81548110611a2d57611a2d615754565b6000918252602090912060029091020154600160301b900465ffffffffffff168514611a6c57604051639424dcd960e01b815260040160405180910390fd5b6000611a788686615826565b9050600081611a89610e108a61579e565b611a9391906157d3565b905060006040518060800160405280611aab8a613c39565b65ffffffffffff168152602001611ac189613c39565b65ffffffffffff168152602001611ad784613d03565b6001600160601b03168152602001611aee88613d03565b6001600160601b0390811690915260019687018054808901825560009182526020918290208451600290920201805492850151604086015165ffffffffffff9384166bffffffffffffffffffffffff1995861617600160301b9490921693909302176bffffffffffffffffffffffff60601b1916600160601b92851692909202919091178155606090930151929097018054909716911617909455505050505050505050565b611ba7670de0b6b3a7640000600161579e565b821015611bc65760405162a1ceb560e71b815260040160405180910390fd5b611bd060006110a2565b6001600160a01b038116600090815260016020526040812090611bf49082856141ea565b6040516323b872dd60e01b8152336004820152306024820152604481018490527f0000000000000000000000004d224452801aced8b2f0aebe155379bb5d5943816001600160a01b0316906323b872dd906064016020604051808303816000875af1158015611c67573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8b919061584b565b50604080518481526001600160a01b038416602082015233917fe31c7b8d08ee7db0afa68782e1028ef92305caeea8626633ad44d413e30f6b2f910161107c565b610d956002838333613f16565b611ce360036110a2565b611cef600185856142a2565b610dbb600283836142a2565b611d03613d6b565b60048160048110611d1657611d16615754565b60020201600101805480611d2c57611d2c615868565b60008281526020902060026000199092019182020180546001600160c01b031916815560010180546bffffffffffffffffffffffff19169055905550565b600080600060048660048110611d8257611d82615754565b6040805160a08101825260029290920292909201805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526001820180548551818402810184019096528086529394929360808601939260009084015b82821015611e735760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b90910481169284019290925260019081015490911660608301529083529092019101611e01565b505050508152505090506000816020015161ffff1690508160800151600081518110611ea157611ea1615754565b60200260200101516000015165ffffffffffff16851015611ec9576000935091506120569050565b81608001518181518110611edf57611edf615754565b60200260200101516020015165ffffffffffff1686118015611f29575081608001518181518110611f1257611f12615754565b60200260200101516020015165ffffffffffff1685115b15611f3657600101611ec9565b60408051608081018252600080825260208201819052918101829052606081018290526080840151516000908190855b8181101561203d5787608001518181518110611f8457611f84615754565b60200260200101519450846000015165ffffffffffff168c1115611fa8578b611fb3565b845165ffffffffffff165b9350846020015165ffffffffffff168b1115611fdb57846020015165ffffffffffff16611fdd565b8a5b9250610e1085604001516001600160601b03168585611ffc9190615826565b612006919061579e565b61201091906157d3565b61201a9087615726565b9550828b116120355794985093965061205695505050505050565b600101611f66565b508461204a600183615826565b98509850505050505050505b935093915050565b612066615028565b6001600160a01b038216600090815260016020526040812054818161208c576000612102565b604051632c018f9160e01b8152600060048201526001600160a01b0386166024820152604481018490523090632c018f9190606401602060405180830381865afa1580156120de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121029190615785565b90506000808311612114576000612121565b6121216000876000614769565b6040805160c08101825260008152602080820197909752808201959095526060850193909352608084015250805180820190915260025481526003549281019290925260a081019190915292915050565b610dbb84848484336109c2565b61218960006110a2565b33600090815260016020526040902080548314156121f75760006121af600083856138d8565b604080518281526001600160a01b038616602082015291925033917f030f754a3e747235920c21afeca14e881b260d41c7e657ada6c0b049f7eebca9910160405180910390a2505b6122036000828561493d565b60405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000004d224452801aced8b2f0aebe155379bb5d594381169063a9059cbb90612251908590879060040161587e565b6020604051808303816000875af1158015612270573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612294919061584b565b50604080518481526001600160a01b038416602082015233917f56c54ba9bd38d8fd62012e42c7ee564519b09763c426d331b3661b537ead19b2910161107c565b6113406002848484613f16565b6122ea613d6b565b6001600160a01b0381166123545760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084015b60405180910390fd5b61188681613dc5565b60606107348260026123da565b6001600160a01b0381166000908152600160208190526040822054906123909084614a0c565b61239a9082615726565b90506123a7600284614a0c565b6123b19082615726565b90506123bc83614b5a565b6123c69082615726565b9392505050565b610d956001838333613f16565b6000818152600c60205260408082205490516370a0823160e01b81526001600160a01b0385811660048301526060939216906370a0823190602401602060405180830381865afa158015612432573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124569190615785565b90506000808211612498576040805160008082526020820190925290612492565b61247f615028565b8152602001906001900390816124775790505b506124eb565b816001600160401b038111156124b0576124b061573e565b6040519080825280602002602001820160405280156124e957816020015b6124d6615028565b8152602001906001900390816124ce5790505b505b9050816124fb5791506107349050565b60005b82811015612792576000858152600c6020526040808220549051632f745c5960e01b81526001600160a01b0390911690632f745c5990612544908a90869060040161587e565b602060405180830381865afa158015612561573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125859190615785565b6000878152600d60209081526040808320848452909152812054919250816125ae576000612624565b604051632c018f9160e01b8152600481018990526001600160a01b038a166024820152604481018490523090632c018f9190606401602060405180830381865afa158015612600573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126249190615785565b90506000808311612636576000612641565b612641898b86614769565b604080518082019091526002548152600380546020830152919250908a141561272c576000858152600f6020908152604080832060018452909152902054600160f81b900460ff16156126ca57506040805180820182526000868152600f6020908152838220600180845290825293909120546001600160f81b0316825281019190915261272c565b6000858152600f6020908152604080832060028452909152902054600160f81b900460ff161561272c57506040805180820182526000868152600f6020908152838220600280845290825293909120546001600160f81b031682528101919091525b60006040518060c001604052808c81526020018781526020018681526020018581526020018481526020018381525090508088888151811061277057612770615754565b60200260200101819052505050505050508061278b9061576a565b90506124fe565b50949350505050565b81600080808080805b86811015612a83578989828181106127be576127be615754565b6127d49260206040909202019081019150615897565b60008c8152600c6020526040908190205490516331a9108f60e11b81526001600160801b039290921660048301819052975033916001600160a01b0390911690636352211e90602401602060405180830381865afa15801561283a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061285e91906158c0565b6001600160a01b03161461288557604051632b19ae7560e01b815260040160405180910390fd5b89898281811061289757612897615754565b90506040020160200160208101906128af9190615897565b6003600052600c602052600080516020615b1f833981519152546040516331a9108f60e11b81526001600160801b039290921660048301819052965033916001600160a01b0390911690636352211e90602401602060405180830381865afa15801561291f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061294391906158c0565b6001600160a01b03161461296a57604051632c8348bb60e01b815260040160405180910390fd5b60008b8152600e602090815260408083208984528252808320888452600f83528184208f8552909252909120815491945092506001600160f81b0316851415806129bd57508254600160f81b900460ff16155b806129d2575081546001600160f81b03168614155b806129e657508154600160f81b900460ff16155b15612a04576040516366640ced60e11b815260040160405180910390fd5b6000858152600080516020615aff833981519152602052604081209450612a2d6003868b6138d8565b60408051828152602081018f90529081018990526060810188905290915033907f89d57e873af45054d40b801ca64ca06a1627c5682ab9be494a9f2846ef157d8a9060800160405180910390a2506001016127a4565b5050505050505050505050565b60008060005b85811015612792576000848152600c6020526040808220549051632f745c5960e01b81526001600160a01b0390911690632f745c5990612adc908990869060040161587e565b602060405180830381865afa158015612af9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b1d9190615785565b6000868152600e60209081526040808320848452909152902054909150600160f81b900460ff1615612c1c576000858152600e6020908152604080832084845282528083205460038452600c909252600080516020615b1f8339815191525490516331a9108f60e11b81526001600160f81b039092166004830181905292916001600160a01b0390911690636352211e90602401602060405180830381865afa158015612bce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bf291906158c0565b9050876001600160a01b0316816001600160a01b031614612c1957612c168561576a565b94505b50505b50612c268161576a565b9050612a96565b60606000846001600160401b03811115612c4957612c4961573e565b604051908082528060200260200182016040528015612c8257816020015b612c6f615028565b815260200190600190039081612c675790505b5090506000805b6000858152600c6020526040908190205490516370a0823160e01b81526001600160a01b038881166004830152909116906370a0823190602401602060405180830381865afa158015612ce0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d049190615785565b811015613042576000858152600c6020526040808220549051632f745c5960e01b81526001600160a01b0390911690632f745c5990612d49908a90869060040161587e565b602060405180830381865afa158015612d66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d8a9190615785565b6000878152600e60209081526040808320848452909152902054909150600160f81b900460ff1615613031576000868152600e6020908152604080832084845282528083205460038452600c909252600080516020615b1f8339815191525490516331a9108f60e11b81526001600160f81b039092166004830181905292916001600160a01b0390911690636352211e90602401602060405180830381865afa158015612e3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e5f91906158c0565b9050886001600160a01b0316816001600160a01b03161461302e576000828152600080516020615aff83398151915260205260408120549081612ea3576000612f19565b604051632c018f9160e01b8152600360048201526001600160a01b0384166024820152604481018590523090632c018f9190606401602060405180830381865afa158015612ef5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f199190615785565b90506000808311612f2b576000612f37565b612f3760038587614769565b905060006002604051806040016040529081600082015481526020016001820154815250509050600f600087815260200190815260200160002060008d8152602001908152602001600020600001601f9054906101000a900460ff1615612fcc57506040805180820182526000878152600f60209081528382208f83528152929020546001600160f81b031681529081018c90525b60006040518060c0016040528060038152602001888152602001868152602001858152602001848152602001838152509050808b8b8151811061301157613011615754565b6020026020010181905250896130269061576a565b995050505050505b50505b5061303b8161576a565b9050612c89565b509095945050505050565b613056846110a2565b60008083815b818110156131905786868281811061307657613076615754565b60008b8152600c60209081526040918290205491516331a9108f60e11b81529202939093013560048201819052965033926001600160a01b03169150636352211e90602401602060405180830381865afa1580156130d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130fc91906158c0565b6001600160a01b03161461312357604051632e6c18c960e11b815260040160405180910390fd5b6000888152600d6020908152604080832087845290915290206131478982886138d8565b60408051828152602081018890529195508a9133917fd334b3114fc25cbd72389ff9c361d5f8b0924e35fa237c65ac209a2cdcf4ba13910160405180910390a35060010161305c565b5050505050505050565b604080516080810182526000808252602082018190529181018290526060810182905281906000808086815b81811015612a83578989828181106131e0576131e0615754565b9050608002018036038101906131f6919061590d565b60008c8152600c60205260409081902054825191516331a9108f60e11b815263ffffffff90921660048301529197506001600160a01b0390911690636352211e90602401602060405180830381865afa158015613257573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061327b91906158c0565b6003600052600c6020908152600080516020615b1f83398151915254908801516040516331a9108f60e11b815263ffffffff90911660048201529199506001600160a01b031690636352211e90602401602060405180830381865afa1580156132e8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061330c91906158c0565b96506001600160a01b0388163314613347576001600160a01b038716331461334757604051634a2f386560e01b815260040160405180910390fd5b600e60008c81526020019081526020016000206000876000015163ffffffff1681526020019081526020016000209450600f6000876020015163ffffffff16815260200190815260200160002060008c81526020019081526020016000209350856020015163ffffffff168560000160009054906101000a90046001600160f81b03166001600160f81b03161415806133e957508454600160f81b900460ff16155b806134075750855184546001600160f81b031663ffffffff90911614155b8061341b57508354600160f81b900460ff16155b15613439576040516366640ced60e11b815260040160405180910390fd5b60036000908152600d60209081528781015163ffffffff168252600080516020615aff83398151915290526040902060608701519093506134a357825460408701516001600160b81b031614156134a35760405163230a658160e11b815260040160405180910390fd5b866001600160a01b0316886001600160a01b0316146134de5785606001516134de5760405163e373a08560e01b815260040160405180910390fd5b8560600151156136a85760006134f66003858a6138d8565b9050604051806040016040528060006001600160f81b0316815260200160001515815250600e60008e81526020019081526020016000206000896000015163ffffffff16815260200190815260200160002060008201518160000160006101000a8154816001600160f81b0302191690836001600160f81b03160217905550602082015181600001601f6101000a81548160ff021916908315150217905550905050604051806040016040528060006001600160f81b0316815260200160001515815250600f6000896020015163ffffffff16815260200190815260200160002060008e815260200190815260200160002060008201518160000160006101000a8154816001600160f81b0302191690836001600160f81b03160217905550602082015181600001601f6101000a81548160ff021916908315150217905550905050336001600160a01b03167f89d57e873af45054d40b801ca64ca06a1627c5682ab9be494a9f2846ef157d8a828e8a600001518b6020015160405161369e9493929190938452602084019290925263ffffffff908116604084015216606082015260800190565b60405180910390a2505b600086606001516136c65786604001516001600160b81b03166136c9565b83545b90506136d76003858361493d565b60405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000004d224452801aced8b2f0aebe155379bb5d594381169063a9059cbb90613725908c90859060040161587e565b6020604051808303816000875af1158015613744573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613768919061584b565b50336001600160a01b03167f63a13470c4507d4f2c9d1bad1b7d603229456f8ebe7d3048d5cd8a02cf8d1ee6828e8a600001518b602001516040516137cf9493929190938452602084019290925263ffffffff908116604084015216606082015260800190565b60405180910390a2506001016131c6565b60006137eb426141dd565b6137f4426141c1565b6137ff90603c61579e565b6138099190615726565b6138139042615826565b905090565b60006001600160ff1b038211156138825760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b606482015260840161234b565b5090565b6000808212156138825760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f736974697665604482015260640161234b565b600080600485600481106138ee576138ee615754565b600202018054855491925060009161391b91610fee91600160a01b9091046001600160601b03169061579e565b9050670de0b6b3a7640000613939866001015483610ffd91906157e7565b61394391906157d3565b60018601829055925082156139e55760405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000004d224452801aced8b2f0aebe155379bb5d594381169063a9059cbb906139a0908790879060040161587e565b6020604051808303816000875af11580156139bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139e3919061584b565b505b50509392505050565b6139f7836110a2565b600080808381805b82811015613b9057878782818110613a1957613a19615754565b613a2f9260206040909202019081019150615999565b60008a8152600d6020908152604080832063ffffffff9490941680845293909152902080549197509450613afe576000898152600c6020526040908190205490516331a9108f60e11b81526004810188905233916001600160a01b031690636352211e90602401602060405180830381865afa158015613ab3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ad791906158c0565b6001600160a01b031614613afe57604051632e6c18c960e11b815260040160405180910390fd5b878782818110613b1057613b10615754565b9050604002016020016020810190613b2891906159b4565b6001600160e01b03169450613b3e898587614f51565b613b488583615726565b60408051878152602081018990529193508a9133917f8863bdbe28273fa04cbc67c9e51785cff607a419b43ee367e4c3c01edb1d7b56910160405180910390a36001016139ff565b508015613190576040516323b872dd60e01b8152336004820152306024820152604481018290527f0000000000000000000000004d224452801aced8b2f0aebe155379bb5d5943816001600160a01b0316906323b872dd906064016020604051808303816000875af1158015613c0a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c2e919061584b565b505050505050505050565b600065ffffffffffff8211156138825760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526538206269747360d01b606482015260840161234b565b600061ffff8211156138825760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b606482015260840161234b565b60006001600160601b038211156138825760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203960448201526536206269747360d01b606482015260840161234b565b6000546001600160a01b031633146113575760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161234b565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600080826020015161ffff16905082608001518181518110613e3957613e39615754565b60200260200101516000015165ffffffffffff16421015613e5a5792915050565b50602082015161ffff165b826080015151811015613ed957600083608001518281518110613e8a57613e8a615754565b6020026020010151905042816000015165ffffffffffff1611158015613ebc5750806020015165ffffffffffff164211155b15613ec8575092915050565b50613ed28161576a565b9050613e65565b60405162461bcd60e51b8152602060048201526012602482015271191a5cdd1c9a589d5d1a5bdb88195b99195960721b604482015260640161234b565b613f1f846110a2565b600080838180805b8381101561411d57888882818110613f4157613f41615754565b613f579260206040909202019081019150615999565b60008b8152600c6020526040908190205490516331a9108f60e11b815263ffffffff9290921660048301819052975033916001600160a01b0390911690636352211e90602401602060405180830381865afa158015613fba573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613fde91906158c0565b6001600160a01b03161461400557604051632e6c18c960e11b815260040160405180910390fd5b88888281811061401757614017615754565b905060400201602001602081019061402f91906159b4565b60008b8152600d602090815260408083208a8452909152902080546001600160e01b0392909216965092508514156140b057600061406e8b848a6138d8565b60408051828152602081018a90529192508c9133917fd334b3114fc25cbd72389ff9c361d5f8b0924e35fa237c65ac209a2cdcf4ba13910160405180910390a3505b6140bb8a838761493d565b6140c58584615726565b604080518781526001600160a01b038a1660208201529081018890529093508a9033907f46916533b23d6665275e4143ec7eeb4b6b4ae92178ebbfe99f112564d2c7b1aa9060600160405180910390a3600101613f27565b508115613c2e5760405163a9059cbb60e01b81526001600160a01b037f0000000000000000000000004d224452801aced8b2f0aebe155379bb5d594381169063a9059cbb90614172908990869060040161587e565b6020604051808303816000875af1158015614191573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141b5919061584b565b50505050505050505050565b6000806141d0610e10846159dd565b90506123c6603c826157d3565b6000610734603c836159dd565b6000600484600481106141ff576141ff615754565b600202019050818360000160008282546142199190615726565b90915550614228905082613d03565b8154829060089061424a908490600160401b90046001600160601b03166159f1565b82546101009290920a6001600160601b0381810219909316918316021790915582546142849250610fee91600160a01b909104168461579e565b8360010160008282546142979190615a1c565b909155505050505050565b604080516060810182526000808252602082018190529181018290528291906000805b848110156146c2578686828181106142df576142df615754565b9050606002018036038101906142f59190615a5d565b60036000908152600d60209081528083015163ffffffff168252600080516020615aff83398151915290526040902080549194509250614590576000888152600c60205260409081902054845191516331a9108f60e11b815263ffffffff909216600483015233916001600160a01b0390911690636352211e90602401602060405180830381865afa15801561438f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143b391906158c0565b6001600160a01b03161415806143f057506000888152600e60209081526040808320865163ffffffff168452909152902054600160f81b900460ff165b1561440e576040516351fedda960e11b815260040160405180910390fd5b6003600052600c6020908152600080516020615b1f83398151915254908401516040516331a9108f60e11b815263ffffffff909116600482015233916001600160a01b031690636352211e90602401602060405180830381865afa15801561447a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061449e91906158c0565b6001600160a01b03161415806144dc575060208381015163ffffffff166000908152600f825260408082208b83529092522054600160f81b900460ff165b156144fa57604051636f395b0f60e11b815260040160405180910390fd5b6040805180820182526020808601805163ffffffff9081168452600183850181815260008f8152600e86528781208b51851682528652878120965191511515600160f81b9081026001600160f81b0393841617909755875180890189528b518516815280870193845294519093168352600f85528683208f84529094529490209051935115159092029216919091179055614623565b60208381015163ffffffff9081166000908152600f835260408082208c8352909352919091205484516001600160f81b03909116911614158061460557506000888152600e60209081526040808320865163ffffffff9081168552908352922054908501516001600160f81b03909116911614155b156146235760405163ba52c1b560e01b815260040160405180910390fd5b61463c60038385604001516001600160b81b0316614f51565b6040830151614654906001600160b81b031685615726565b604084810151855160208088015184516001600160b81b0390941684529083018d905263ffffffff91821683850152166060820152905191955033917fb3f27c1805319c01731f5717816fcfc579c3452c5ff4ffadc41284a7288f24ef9181900360800190a26001016142c5565b508215614760576040516323b872dd60e01b8152336004820152306024820152604481018490527f0000000000000000000000004d224452801aced8b2f0aebe155379bb5d5943816001600160a01b0316906323b872dd906064016020604051808303816000875af115801561473c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613190919061584b565b50505050505050565b6000806004856004811061477f5761477f615754565b6040805160a08101825260029290920292909201805465ffffffffffff8116835261ffff600160301b8204166020808501919091526001600160601b03600160401b8304811685870152600160a01b90920490911660608401526001820180548551818402810184019096528086529394929360808601939260009084015b828210156148705760008481526020908190206040805160808101825260028602909201805465ffffffffffff8082168552600160301b820416848601526001600160601b03600160601b909104811692840192909252600190810154909116606083015290835290920191016147fe565b505050508152505090506000856000146148a2576000868152600d6020908152604080832087845290915290206148bb565b6001600160a01b03851660009081526001602052604090205b60405180604001604052908160008201548152602001600182015481525050905060006148f087846020015161ffff166109ed565b905082604001516001600160601b031681604001516001600160601b0316836000015161491d919061579e565b61492890601861579e565b61493291906157d3565b979650505050505050565b815481111561495f57604051639acaefc760e01b815260040160405180910390fd5b60006004846004811061497457614974615754565b6002020190508183600001600082825461498e9190615826565b9091555061499d905082613d03565b815482906008906149bf908490600160401b90046001600160601b0316615ad6565b82546101009290920a6001600160601b0381810219909316918316021790915582546149f99250610fee91600160a01b909104168461579e565b83600101600082825461429791906157e7565b6000828152600c60205260408082205490516370a0823160e01b81526001600160a01b038481166004830152839283929116906370a0823190602401602060405180830381865afa158015614a65573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614a899190615785565b905060005b81811015614b50576000868152600c6020526040808220549051632f745c5960e01b81526001600160a01b0390911690632f745c5990614ad4908990869060040161587e565b602060405180830381865afa158015614af1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614b159190615785565b6000888152600d60209081526040808320848452909152902054909150614b3c9085615726565b93505080614b499061576a565b9050614a8e565b5090949350505050565b60016000908152600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c546040516370a0823160e01b81526001600160a01b038481166004830152839283929116906370a0823190602401602060405180830381865afa158015614bd2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614bf69190615785565b905060005b81811015614d535760016000908152600c6020527fd421a5181c571bba3f01190c922c3b2a896fc1d84e86c9f17ac10e67ebef8b5c54604051632f745c5960e01b81526001600160a01b0390911690632f745c5990614c60908990869060040161587e565b602060405180830381865afa158015614c7d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ca19190615785565b60008181527fa7c5ba7114a813b50159add3a36832908dc83db71d0b9a24c2ad0f83be9582076020526040902054909150600160f81b900460ff1615614d425760008181527fa7c5ba7114a813b50159add3a36832908dc83db71d0b9a24c2ad0f83be95820760209081526040808320546001600160f81b0316808452600080516020615aff83398151915290925290912054614d3e9086615726565b9450505b50614d4c8161576a565b9050614bfb565b506002600052600c6020527f5d6016397a73f5e079297ac5a36fef17b4d9c3831618e63ab105738020ddd720546040516370a0823160e01b81526001600160a01b038681166004830152909116906370a0823190602401602060405180830381865afa158015614dc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614deb9190615785565b905060005b81811015614f485760026000908152600c6020527f5d6016397a73f5e079297ac5a36fef17b4d9c3831618e63ab105738020ddd72054604051632f745c5960e01b81526001600160a01b0390911690632f745c5990614e55908990869060040161587e565b602060405180830381865afa158015614e72573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e969190615785565b60008181527f9adb202b1492743bc00c81d33cdc6423fa8c79109027eb6a845391e8fc1f04816020526040902054909150600160f81b900460ff1615614f375760008181527f9adb202b1492743bc00c81d33cdc6423fa8c79109027eb6a845391e8fc1f048160209081526040808320546001600160f81b0316808452600080516020615aff83398151915290925290912054614f339086615726565b9450505b50614f418161576a565b9050614df0565b50909392505050565b614f64670de0b6b3a7640000600161579e565b811015614f835760405162a1ceb560e71b815260040160405180910390fd5b60048360048110614f9657614f96615754565b6002020160010160048460048110614fb057614fb0615754565b60020201548154600160301b90910461ffff16908110614fd257614fd2615754565b600091825260209091206001600290920201015482546001600160601b0390911690614ffe9083615726565b111561501d57604051633c0eb0dd60e21b815260040160405180910390fd5b6113408383836141ea565b6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001615073604051806040016040528060008152602001600081525090565b905290565b6040518060600160405280600081526020016000815260200161507360408051608081018252600080825260208201819052918101829052606081019190915290565b6001600160a01b038116811461188657600080fd5b6000602082840312156150e257600080fd5b81356123c6816150bb565b805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a0810151805160a0840152602081015160c0840152505050565b6020808252825182820181905260009190848201906040850190845b81811015615176576151638385516150ed565b9284019260e09290920191600101615150565b50909695505050505050565b60008083601f84011261519457600080fd5b5081356001600160401b038111156151ab57600080fd5b6020830191508360208260061b85010111156151c657600080fd5b9250929050565b6000806000806000606086880312156151e557600080fd5b85356001600160401b03808211156151fc57600080fd5b61520889838a01615182565b9097509550602088013591508082111561522157600080fd5b5061522e88828901615182565b9094509250506040860135615242816150bb565b809150509295509295909350565b6000806040838503121561526357600080fd5b50508035926020909101359150565b65ffffffffffff8082511683528060208301511660208401525060408101516001600160601b03808216604085015280606084015116606085015250505050565b608081016107348284615272565b6000602082840312156152d357600080fd5b5035919050565b60008083601f8401126152ec57600080fd5b5081356001600160401b0381111561530357600080fd5b6020830191508360208260051b85010111156151c657600080fd5b6000806020838503121561533157600080fd5b82356001600160401b0381111561534757600080fd5b615353858286016152da565b90969095509350505050565b60008083601f84011261537157600080fd5b5081356001600160401b0381111561538857600080fd5b6020830191508360208260071b85010111156151c657600080fd5b600080600080604085870312156153b957600080fd5b84356001600160401b03808211156153d057600080fd5b6153dc8883890161535f565b909650945060208701359150808211156153f557600080fd5b506154028782880161535f565b95989497509550505050565b60008060006060848603121561542357600080fd5b833592506020840135615435816150bb565b929592945050506040919091013590565b6000806020838503121561545957600080fd5b82356001600160401b0381111561546f57600080fd5b61535385828601615182565b60008060006040848603121561549057600080fd5b83356001600160401b038111156154a657600080fd5b6154b2868287016152da565b90945092505060208401356154c6816150bb565b809150509250925092565b805182526020810151602083015260408101516113406040840182615272565b610300810161550082876154d1565b61550d60c08301866154d1565b61551b6101808301856154d1565b6155296102408301846154d1565b95945050505050565b60008060006040848603121561554757600080fd5b83356001600160401b0381111561555d57600080fd5b6154b286828701615182565b600080600080600060a0868803121561558157600080fd5b505083359560208501359550604085013594606081013594506080013592509050565b600080604083850312156155b757600080fd5b8235915060208301356155c9816150bb565b809150509250929050565b60008083601f8401126155e657600080fd5b5081356001600160401b038111156155fd57600080fd5b6020830191508360206060830285010111156151c657600080fd5b6000806000806040858703121561562e57600080fd5b84356001600160401b038082111561564557600080fd5b615651888389016155d4565b9096509450602087013591508082111561566a57600080fd5b50615402878288016155d4565b60008060006060848603121561568c57600080fd5b505081359360208301359350604090920135919050565b60e0810161073482846150ed565b600080600080604085870312156156c757600080fd5b84356001600160401b03808211156156de57600080fd5b6156ea88838901615182565b9096509450602087013591508082111561570357600080fd5b5061540287828801615182565b634e487b7160e01b600052601160045260246000fd5b6000821982111561573957615739615710565b500190565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600060001982141561577e5761577e615710565b5060010190565b60006020828403121561579757600080fd5b5051919050565b60008160001904831182151516156157b8576157b8615710565b500290565b634e487b7160e01b600052601260045260246000fd5b6000826157e2576157e26157bd565b500490565b60008083128015600160ff1b85018412161561580557615805615710565b6001600160ff1b038401831381161561582057615820615710565b50500390565b60008282101561583857615838615710565b500390565b801515811461188657600080fd5b60006020828403121561585d57600080fd5b81516123c68161583d565b634e487b7160e01b600052603160045260246000fd5b6001600160a01b03929092168252602082015260400190565b6000602082840312156158a957600080fd5b81356001600160801b03811681146123c657600080fd5b6000602082840312156158d257600080fd5b81516123c6816150bb565b803563ffffffff811681146158f157600080fd5b919050565b80356001600160b81b03811681146158f157600080fd5b60006080828403121561591f57600080fd5b604051608081018181106001600160401b038211171561594f57634e487b7160e01b600052604160045260246000fd5b60405261595b836158dd565b8152615969602084016158dd565b602082015261597a604084016158f6565b6040820152606083013561598d8161583d565b60608201529392505050565b6000602082840312156159ab57600080fd5b6123c6826158dd565b6000602082840312156159c657600080fd5b81356001600160e01b03811681146123c657600080fd5b6000826159ec576159ec6157bd565b500690565b60006001600160601b03808316818516808303821115615a1357615a13615710565b01949350505050565b600080821280156001600160ff1b0384900385131615615a3e57615a3e615710565b600160ff1b8390038412811615615a5757615a57615710565b50500190565b600060608284031215615a6f57600080fd5b604051606081018181106001600160401b0382111715615a9f57634e487b7160e01b600052604160045260246000fd5b604052615aab836158dd565b8152615ab9602084016158dd565b6020820152615aca604084016158f6565b60408201529392505050565b60006001600160601b0383811690831681811015615af657615af6615710565b03939250505056fe26b4a10d0f0b04925c23bd4480ee147c916e5e87a7d68206a533dad160ac81e2c0da782485e77ae272268ae0a3ff44c1552ecb60b3743924de17a815e0a3cfd7a2646970667358221220bd4bd0caba5cbe67828994269b695246befece3b19535639581f2dde7c8a987464736f6c634300080a0033

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

0000000000000000000000004d224452801aced8b2f0aebe155379bb5d594381000000000000000000000000bc4ca0eda7647a8ab7c2061c2e118a18a936f13d00000000000000000000000060e4d786628fea6478f785a6d7e704777c86a7c6000000000000000000000000ba30e5f9bb24caa003e9f2f0497ad287fdf95623

-----Decoded View---------------
Arg [0] : _apeCoinContractAddress (address): 0x4d224452801ACEd8B2F0aebE155379bb5D594381
Arg [1] : _baycContractAddress (address): 0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D
Arg [2] : _maycContractAddress (address): 0x60E4d786628Fea6478F785A6d7e704777c86a7c6
Arg [3] : _bakcContractAddress (address): 0xba30E5F9Bb24caa003E9f2f0497Ad287FDF95623

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 0000000000000000000000004d224452801aced8b2f0aebe155379bb5d594381
Arg [1] : 000000000000000000000000bc4ca0eda7647a8ab7c2061c2e118a18a936f13d
Arg [2] : 00000000000000000000000060e4d786628fea6478f785a6d7e704777c86a7c6
Arg [3] : 000000000000000000000000ba30e5f9bb24caa003e9f2f0497ad287fdf95623


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.