Contract 0x55a14661d94c2ce307ab918bb9564545282c2454 3

 

Contract Overview

Balance:
0 ETH

ETH Value:
$0.00

Token:
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x6fb9ac1df1dd9cd4b9b3c4c030bc7f0dcf3c3b4384477de9de110b90e035276dTrade2135975112024-05-21 17:20:4113 hrs 52 mins ago0x21ffc2e7592e34c7fd15c8c8417f1e5354f0d044 IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000889 0.0155
0x378fe8d2d8d0f215a53e1456a32dceffe8f3cfa0a9fa291acb575148680a0de4Multicall2124373532024-05-18 6:26:144 days 47 mins ago0x3c9c0cea108ef12072f3b03cd60e0a5a7f71b9a0 IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.0000265 0.01
0xc940a781d408d7ae1bc01fddcd1fe860bf153b53d6cdc2c416c50d2e66c1f559Multicall2120358902024-05-17 1:41:025 days 5 hrs ago0x21ffc2e7592e34c7fd15c8c8417f1e5354f0d044 IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00002616 0.01
0x12407db7dc278f56190f3bee61ec64671962648528106279fd2228da04984767Multicall2114748962024-05-15 9:44:076 days 21 hrs ago0x93bcd1459d14d867bfedcabb8bc539669e1ef46f IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.000003710.01
0xca8a9a068bc7c2748f4152be575c3d85c701d1c32adebba15ec12e41c88ea119Trade2114748452024-05-15 9:43:566 days 21 hrs ago0x93bcd1459d14d867bfedcabb8bc539669e1ef46f IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.000003180.01
0x8c3ef4f8fe20e33a8ba8a17cb1b12c1ba904fe741a45e82fba215ff75be3e34eMulticall2114738462024-05-15 9:39:286 days 21 hrs ago0x93bcd1459d14d867bfedcabb8bc539669e1ef46f IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.000026250.01
0xdc7735ad78ce311e8c79713b49db10601c03a8f97859f4fa0206477bc6fd88c1Multicall2110297372024-05-14 2:14:308 days 4 hrs ago0x21ffc2e7592e34c7fd15c8c8417f1e5354f0d044 IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000437 0.01
0x1242809c736ccea4d94de59d2888a0ecc0721d6269fbfa52c242f2b11869bf4bMulticall2110296572024-05-14 2:14:108 days 4 hrs ago0x21ffc2e7592e34c7fd15c8c8417f1e5354f0d044 IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000415 0.01
0xf715a102e16483256fcb52dad82eaa17a30bc67027135bf2270c379246707f02Multicall2110285352024-05-14 2:09:298 days 5 hrs ago0x21ffc2e7592e34c7fd15c8c8417f1e5354f0d044 IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000305 0.01
0xf1ca3844c30bc2c3fd7170b5c26facaba7e1dd2bff2fe363e095a6bebb49beb1Trade2107522082024-05-13 6:37:029 days 36 mins ago0x93bcd1459d14d867bfedcabb8bc539669e1ef46f IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.000003190.01
0x3803670cc4f8c9c5203e0e11543b920737dd45dfb9436040ba31dcfe9d3b83b3Multicall2106899792024-05-13 2:12:239 days 5 hrs ago0x93bcd1459d14d867bfedcabb8bc539669e1ef46f IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00002620.01
0x5ba9025c35e538966f5cc95e89f1367d830a83dea151290c85ddf73b5f1321d7Multicall2106890522024-05-13 2:08:329 days 5 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000226 0.01
0x30d4f8e64a3fe1daab174f221ba78a301dcbbcef51291312b4f9d71846cda685Withdraw Obligat...2106882652024-05-13 2:05:149 days 5 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000098 0.01
0xffec3fef8667b3c191c613bc3bd181411fde90bd94df8c13cddf42f64bc3497eAdd Liquidity2095086182024-05-09 15:37:2812 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.0000052 0.01
0x96fae2c649dd77a41513143f013fa4df32e5c2601c2722ecb806ff67da24e7f1Add Liquidity2095084182024-05-09 15:36:3712 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000721 0.01
0xc43d2c86f793f482575a93936384092bb57044b012802f5132db0ce34a62c8f5Trade2095080902024-05-09 15:35:1412 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000279 0.01
0xded362289fc1f36ea73bfd66c835f37328d27440b4236a1167988eb6f598f906Trade2095072932024-05-09 15:31:4612 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000462 0.01
0x42191df1a6c07692b7fa5ccdaf66a6681cadbae1f04ed608336327ad9de6fcccTrade2095071442024-05-09 15:31:0812 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000345 0.010428
0x65305447c0beb88f2e8b8079d15594f52080ebdca3ac3afde90409d81ebdb181Add Liquidity2095063822024-05-09 15:27:5612 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000591 0.01
0xf468b2ec0127f2cef4b5ce6b8ea890675367dc668266e9a80e47fc24c165675cMulticall2095057292024-05-09 15:25:1112 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00002669 0.01
0xf59586eb72ea2629897aff34dc5b73bde64c4dbe63ed53d46d2be366cf334d4eTrade2095048732024-05-09 15:21:3612 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000263 0.01
0x97765ddb80261f3bb8e5afc73f794dd32d32dcc3ee8bba1cdc54ccbdb7d078bbTrade2095046422024-05-09 15:20:3812 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000262 0.01
0xafd1bff04523b22c157e84175bfd3a10cf0d7d036f0cca33774f21f5a20d59e8Multicall2095031522024-05-09 15:14:2512 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000398 0.010644
0x15ef69e9d0dcb49f5e70c7bee0f234f53eaaeec58c47437a3a96b5c9d98ae4e3Multicall2095029852024-05-09 15:13:4312 days 15 hrs ago0x22ca9b22095de647c28debc4dea2cb252dfd531a IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000227 0.011948
0x06eb6267ecca6a8c281eec6463e9d795d191f171f2c2676dfb8077cc4c92ae75Multicall2094955452024-05-09 14:42:3812 days 16 hrs ago0x93bcd1459d14d867bfedcabb8bc539669e1ef46f IN  0x55a14661d94c2ce307ab918bb9564545282c24540 ETH0.00000440.01
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.

Contract Source Code Verified (Exact Match)

Contract Name:
Manager

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 61 : Manager.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

import { ERC721Enumerable, ERC721 } from "@oz/token/ERC721/extensions/ERC721Enumerable.sol";
import { ERC20Burnable } from "@oz/token/ERC20/extensions/ERC20Burnable.sol";
import { Multicall } from "@oz/utils/Multicall.sol";
import { FullMath } from "@uniswap/v3-core/contracts/libraries/FullMath.sol";
import { FixedPoint128 } from "@uniswap/v3-core/contracts/libraries/FixedPoint128.sol";
import { BattleInitializer } from "./base/BattleInitializer.sol";
import { LiquidityManagement } from "./base/LiquidityManagement.sol";
import { PeripheryImmutableState } from "./base/PeripheryImmutableState.sol";
import { IBattleActions } from "core/interfaces/battle/IBattleActions.sol";
import { BattleTradeParams, BattleBurnParams } from "core/params/coreParams.sol";
import { TradeType } from "core/types/enums.sol";
import { TickMath } from "core/libs/TickMath.sol";
import { Errors } from "core/errors/Errors.sol";
import { IArenaCreation } from "core/interfaces/IArena.sol";
import { IBattleState } from "core/interfaces/battle/IBattleState.sol";
import { IManagerState } from "./interfaces/IManagerState.sol";
import { IManager } from "./interfaces/IManager.sol";
import { IManagerLiquidity } from "./interfaces/IManagerActions.sol";
import { AddLiqParams, TradeParams } from "periphery/params/peripheryParams.sol";
import { PositionState, Position } from "./types/common.sol";
import { CallbackValidation } from "./libs/CallbackValidation.sol";
import { PositionInfo, BattleKey, GrowthX128, Owed, LiquidityType, Outcome } from "core/types/common.sol";

/// @title Manager
/// @notice Sets up the necessary state variables, mappings, and inheritance
/// to handle position NFTs, manage liquidity, and interact with the battle contracts

contract Manager is IManager, Multicall, ERC721Enumerable, PeripheryImmutableState, BattleInitializer, LiquidityManagement {
    uint256 public override nextId;
    mapping(uint256 => Position) private _positions;

    modifier isAuthorizedForToken(uint256 tokenId) {
        require(_isApprovedOrOwner(msg.sender, tokenId), "Not approved");
        _;
    }

    constructor(address _arena, address _weth) ERC721("Divergence Protocol Positions NFT", "DIVER-POS") PeripheryImmutableState(_arena, _weth) { }

    /// @notice Adds liquidity to a battle contract, mints a new token representing the liquidity position
    /// records the position information for later reference.
    /// @return tokenId The ID of the NFT that represents the liquidity position
    /// @return liquidity The amount of liquidity for this position
    function addLiquidity(AddLiqParams calldata params) external override returns (uint256 tokenId, uint128 liquidity) {
        if (block.timestamp > params.deadline) {
            revert Errors.Deadline();
        }
        address battleAddr;
        (liquidity, battleAddr) = _addLiquidity(params);
        tokenId = nextId;
        bytes32 pk = keccak256(abi.encodePacked(address(this), params.tickLower, params.tickUpper));
        _positions[tokenId] = Position({
            tokenId: tokenId,
            battleAddr: battleAddr,
            tickLower: params.tickLower,
            tickUpper: params.tickUpper,
            liquidity: liquidity,
            liquidityType: params.liquidityType,
            seed: params.amount,
            insideLast: IBattleState(battleAddr).positions(pk).insideLast,
            owed: Owed(0, 0, 0, 0),
            state: PositionState.LiquidityAdded,
            spearObligation: 0,
            shieldObligation: 0
        });
        nextId++;
        emit LiquidityAdded(battleAddr, params.recipient, tokenId, liquidity, params.liquidityType, params.amount);
        _safeMint(params.recipient, tokenId);
    }

    /// @notice Updates the growth of fees and token deltas as of the last action on the individual position
    function updateInsideLast(PositionInfo memory pb, Position storage pm) private {
        unchecked {
            pm.owed.fee += uint128(FullMath.mulDiv(pb.insideLast.fee - pm.insideLast.fee, pm.liquidity, FixedPoint128.Q128));
            pm.owed.collateralIn +=
                uint128(FullMath.mulDiv(pb.insideLast.collateralIn - pm.insideLast.collateralIn, pm.liquidity, FixedPoint128.Q128));
            pm.owed.spearOut += uint128(FullMath.mulDiv(pb.insideLast.spearOut - pm.insideLast.spearOut, pm.liquidity, FixedPoint128.Q128));
            pm.owed.shieldOut += uint128(FullMath.mulDiv(pb.insideLast.shieldOut - pm.insideLast.shieldOut, pm.liquidity, FixedPoint128.Q128));
            pm.insideLast = pb.insideLast;
        }
    }

    /// @notice Removes liquidity from the pool, given the tokenId of a position. Only to be called once by the liquidity provider.
    /// @param tokenId The ID of the NFT that represents the liquidity position
    /// @return collateral The amount of collateral to be received by the liqudity provider
    /// @return spear The amount of Spear to be received by the liquidity provider
    /// @return shield The amount of Shield to be received by the liquidity provider
    /// @return spearObligation The obligatory reserve of collateral amount for settling spear tokens sold by the position
    /// @return shieldObligation The obligatory reserve of collateral amount for settling shield tokens sold by the position
    function removeLiquidity(uint256 tokenId)
        external
        override
        isAuthorizedForToken(tokenId)
        returns (uint256 collateral, uint256 spear, uint256 shield, uint256 spearObligation, uint256 shieldObligation)
    {
        // pm => position in manager
        Position memory pmMemory = _positions[tokenId];
        if (pmMemory.state != PositionState.LiquidityAdded) {
            revert Errors.LiquidityNotAdded();
        }

        BattleBurnParams memory bp;
        bp.tickLower = pmMemory.tickLower;
        bp.tickUpper = pmMemory.tickUpper;
        bp.liquidityType = pmMemory.liquidityType;
        bp.liquidityAmount = pmMemory.liquidity;

        IBattleActions(pmMemory.battleAddr).burn(bp);

        // pb => position in battle
        PositionInfo memory pb =
            IBattleState(pmMemory.battleAddr).positions(keccak256(abi.encodePacked(address(this), pmMemory.tickLower, pmMemory.tickUpper)));

        Position storage pmStorage = _positions[tokenId];
        updateInsideLast(pb, pmStorage);
        (collateral, spear, shield, spearObligation, shieldObligation) = getObligation(pmStorage);
        collateral += pmStorage.owed.fee;
        pmStorage.state = PositionState.LiquidityRemoved;
        pmStorage.spearObligation = spearObligation;
        pmStorage.shieldObligation = shieldObligation;

        IBattleActions(pmMemory.battleAddr).collect(ownerOf(tokenId), collateral, spear, shield);

        emit LiquidityRemoved(tokenId, collateral, spear > shield ? spear : shield);
    }

    /// @notice Calculates the obligatory reserve of collateral amounts for settling sold spear and shield amounts
    /// The remaining collateral/spear/shield token amounts receivable for a given position.
    /// @param pm The position for which to calculate the obligation amounts and receivable token amounts
    /// @return collateral The amount of collateral that can be received by the liqudity provider
    /// @return spear The remaining spear amount that can be received by the liqudity provider, after adjusting for obligations
    /// @return shield The remaining shield amount that can be received by the liqudity provider, after adjusting for obligations
    /// @return spearObligation The obligatory reserve of collateral amount for settling spear tokens sold by the position
    /// @return shieldObligation The obligatory reserve of collateral amount for settling shield tokens sold by the position
    function getObligation(Position memory pm)
        private
        pure
        returns (uint256 collateral, uint256 spear, uint256 shield, uint256 spearObligation, uint256 shieldObligation)
    {
        if (pm.liquidityType == LiquidityType.COLLATERAL) {
            spearObligation = pm.owed.spearOut;
            shieldObligation = pm.owed.shieldOut;
            uint256 obligation = spearObligation > shieldObligation ? spearObligation : shieldObligation;
            // minus 1 to avoid rounding error, ensuring the reserved collateral is enough to pay the obligation
            collateral = pm.owed.collateralIn + pm.seed == obligation ? 0 : pm.owed.collateralIn + pm.seed - obligation - 1;
        } else if (pm.liquidityType == LiquidityType.SPEAR) {
            spearObligation = pm.owed.spearOut > pm.seed ? pm.owed.spearOut - pm.seed : 0;
            shieldObligation = pm.owed.shieldOut;
            uint256 obligation = spearObligation > shieldObligation ? spearObligation : shieldObligation;
            // minus 1 to avoid rounding error, ensuring the reserved collateral is enough to pay the obligation
            collateral = pm.owed.collateralIn == obligation ? 0 : pm.owed.collateralIn - obligation - 1;
            if (pm.seed > pm.owed.spearOut) {
                spear = pm.seed - pm.owed.spearOut;
            }
        } else {
            spearObligation = pm.owed.spearOut;
            shieldObligation = pm.owed.shieldOut > pm.seed ? pm.owed.shieldOut - pm.seed : 0;
            uint256 obligation = spearObligation > shieldObligation ? spearObligation : shieldObligation;
            // minus 1 to avoid rounding error, ensuring the reserved collateral is enough to pay the obligation
            collateral = pm.owed.collateralIn == obligation ? 0 : pm.owed.collateralIn - obligation - 1;
            if (pm.seed > pm.owed.shieldOut) {
                shield = pm.seed - pm.owed.shieldOut;
            }
        }
    }

    /// @notice Returns the amount of collateral reserved for options that settle out-of-money.
    /// Can be called once after expiry by the liquidity provider and must be called after liquidity has been removed.
    /// @param tokenId The ID of the NFT that represents the liquidity position
    function withdrawObligation(uint256 tokenId) external override isAuthorizedForToken(tokenId) {
        Position memory pm = _positions[tokenId];

        if (pm.state != PositionState.LiquidityRemoved) {
            revert Errors.LiquidityNotRemoved();
        }
        Outcome rr = IBattleState(pm.battleAddr).battleOutcome();
        bool isSpearLess = pm.spearObligation < pm.shieldObligation;
        uint256 toLp;
        if (rr == Outcome.ONGOING) {
            revert Errors.BattleNotEnd();
        } else if (rr == Outcome.SPEAR_WIN) {
            if (isSpearLess) {
                toLp = pm.shieldObligation - pm.spearObligation;
            }
        } else {
            if (!isSpearLess) {
                toLp = pm.spearObligation - pm.shieldObligation;
            }
        }
        if (toLp > 0) {
            IBattleActions(pm.battleAddr).withdrawObligation(ownerOf(tokenId), toLp);
        }
        _positions[tokenId].state = PositionState.ObligationWithdrawn;
        emit ObligationWithdrawn(pm.battleAddr, tokenId, toLp);
    }

    /// @notice Returns the amount of collateral reserved for the liquidity providers' open short interest.
    /// The LP gets one collateral for sending one spear or shield token back to the pool to close the net amount of short options exposure.
    /// Can be called once before expiry by the LP and must be called after liquidity has been removed.
    /// @param tokenId The ID of the NFT that represents the liquidity position
    function redeemObligation(uint256 tokenId) external override isAuthorizedForToken(tokenId) {
        Position memory pm = _positions[tokenId];
        if (pm.state != PositionState.LiquidityRemoved) {
            revert Errors.LiquidityNotRemoved();
        }
        Outcome rr = IBattleState(pm.battleAddr).battleOutcome();
        if (rr != Outcome.ONGOING) {
            revert Errors.BattleEnd();
        }
        if (pm.spearObligation != pm.shieldObligation) {
            (uint256 diff, address stoken) = pm.spearObligation > pm.shieldObligation
                ? (pm.spearObligation - pm.shieldObligation, IBattleState(pm.battleAddr).spear())
                : (pm.shieldObligation - pm.spearObligation, IBattleState(pm.battleAddr).shield());
            ERC20Burnable(stoken).burnFrom(msg.sender, diff);
            IBattleActions(pm.battleAddr).withdrawObligation(ownerOf(tokenId), diff);
            _positions[tokenId].state = PositionState.ObligationRedeemed;
            emit ObligationRedeemed(pm.battleAddr, tokenId, diff);
        }
    }

    /// @notice Calls the battle contract to execute a trade
    /// @return amountIn The collateral amount to be swapped in based on the direction of the swap
    /// @return amountOut The amount to be received, of either spear or shield token, based on the direction of the swap
    /// @return amountFee The amount of fee in collateral token to be spent for the trade
    function trade(TradeParams calldata p) external override returns (uint256 amountIn, uint256 amountOut, uint256 amountFee) {
        if (block.timestamp > p.deadline) {
            revert Errors.Deadline();
        }

        address battle = IArenaCreation(arena).getBattle(p.battleKey);
        if (battle == address(0)) {
            revert Errors.BattleNotExist();
        }

        BattleTradeParams memory tps;
        tps.recipient = p.recipient;
        tps.tradeType = p.tradeType;
        tps.amountSpecified = p.amountSpecified;
        tps.data = abi.encode(TradeCallbackData({ battleKey: p.battleKey, payer: msg.sender }));
        if (p.sqrtPriceLimitX96 == 0) {
            if (p.tradeType == TradeType.BUY_SPEAR) {
                tps.sqrtPriceLimitX96 = TickMath.MIN_SQRT_RATIO + 1;
            } else {
                tps.sqrtPriceLimitX96 = TickMath.MAX_SQRT_RATIO - 1;
            }
        } else {
            tps.sqrtPriceLimitX96 = p.sqrtPriceLimitX96;
        }

        // call battle
        (amountIn, amountOut, amountFee) = IBattleActions(battle).trade(tps);
        if (amountOut < p.amountOutMin) {
            revert Errors.Slippage();
        }
        emit Traded(p.recipient, p.tradeType, amountIn, amountOut);
    }

    /// @notice Called to msg.sender after executing a swap via Manager.
    /// @param cAmount The amount of collateral transferred in the trade
    /// @param sAmount The amount of spear or shield transferred in the trade
    /// @param _data Data passed through by the caller
    function tradeCallback(uint256 cAmount, uint256 sAmount, bytes calldata _data) external override {
        TradeCallbackData memory data = abi.decode(_data, (TradeCallbackData));
        CallbackValidation.verifyCallback(arena, data.battleKey);
        pay(data.battleKey.collateral, data.payer, msg.sender, cAmount);
    }

    /// @notice Retrieves the position data for the given TokenId
    /// @param tokenId The ID of the NFT that represents the liquidity position
    function positions(uint256 tokenId) external view override returns (Position memory) {
        return _positions[tokenId];
    }
}

File 2 of 61 : ERC721Enumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (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 See {ERC721-_beforeTokenTransfer}.
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 firstTokenId,
        uint256 batchSize
    ) internal virtual override {
        super._beforeTokenTransfer(from, to, firstTokenId, batchSize);

        if (batchSize > 1) {
            // Will only trigger during construction. Batch transferring (minting) is not available afterwards.
            revert("ERC721Enumerable: consecutive transfers not supported");
        }

        uint256 tokenId = firstTokenId;

        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 3 of 61 : ERC20Burnable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/extensions/ERC20Burnable.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20Burnable is Context, ERC20 {
    /**
     * @dev Destroys `amount` tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 amount) public virtual {
        _burn(_msgSender(), amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, deducting from the caller's
     * allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `amount`.
     */
    function burnFrom(address account, uint256 amount) public virtual {
        _spendAllowance(account, _msgSender(), amount);
        _burn(account, amount);
    }
}

File 4 of 61 : Multicall.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Multicall.sol)

pragma solidity ^0.8.0;

import "./Address.sol";

/**
 * @dev Provides a function to batch together multiple calls in a single external call.
 *
 * _Available since v4.1._
 */
abstract contract Multicall {
    /**
     * @dev Receives and executes a batch of function calls on this contract.
     */
    function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            results[i] = Address.functionDelegateCall(address(this), data[i]);
        }
        return results;
    }
}

File 5 of 61 : FullMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title Contains 512-bit math functions
/// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
/// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
library FullMath {
    /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
    function mulDiv(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = a * b
            // Compute the product mod 2**256 and mod 2**256 - 1
            // then use the Chinese Remainder Theorem to reconstruct
            // the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2**256 + prod0
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(a, b, not(0))
                prod0 := mul(a, b)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division
            if (prod1 == 0) {
                require(denominator > 0);
                assembly {
                    result := div(prod0, denominator)
                }
                return result;
            }

            // Make sure the result is less than 2**256.
            // Also prevents denominator == 0
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0]
            // Compute remainder using mulmod
            uint256 remainder;
            assembly {
                remainder := mulmod(a, b, denominator)
            }
            // Subtract 256 bit number from 512 bit number
            assembly {
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator
            // Compute largest power of two divisor of denominator.
            // Always >= 1.
            uint256 twos = (0 - denominator) & denominator;
            // Divide denominator by power of two
            assembly {
                denominator := div(denominator, twos)
            }

            // Divide [prod1 prod0] by the factors of two
            assembly {
                prod0 := div(prod0, twos)
            }
            // Shift in bits from prod1 into prod0. For this we need
            // to flip `twos` such that it is 2**256 / twos.
            // If twos is zero, then it becomes one
            assembly {
                twos := add(div(sub(0, twos), twos), 1)
            }
            prod0 |= prod1 * twos;

            // Invert denominator mod 2**256
            // Now that denominator is an odd number, it has an inverse
            // modulo 2**256 such that denominator * inv = 1 mod 2**256.
            // Compute the inverse by starting with a seed that is correct
            // correct for four bits. That is, denominator * inv = 1 mod 2**4
            uint256 inv = (3 * denominator) ^ 2;
            // Now use Newton-Raphson iteration to improve the precision.
            // Thanks to Hensel's lifting lemma, this also works in modular
            // arithmetic, doubling the correct bits in each step.
            inv *= 2 - denominator * inv; // inverse mod 2**8
            inv *= 2 - denominator * inv; // inverse mod 2**16
            inv *= 2 - denominator * inv; // inverse mod 2**32
            inv *= 2 - denominator * inv; // inverse mod 2**64
            inv *= 2 - denominator * inv; // inverse mod 2**128
            inv *= 2 - denominator * inv; // inverse mod 2**256

            // Because the division is now exact we can divide by multiplying
            // with the modular inverse of denominator. This will give us the
            // correct result modulo 2**256. Since the precoditions guarantee
            // that the outcome is less than 2**256, this is the final result.
            // We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inv;
            return result;
        }
    }

    /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
    /// @param a The multiplicand
    /// @param b The multiplier
    /// @param denominator The divisor
    /// @return result The 256-bit result
    function mulDivRoundingUp(
        uint256 a,
        uint256 b,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            result = mulDiv(a, b, denominator);
            if (mulmod(a, b, denominator) > 0) {
                require(result < type(uint256).max);
                result++;
            }
        }
    }
}

File 6 of 61 : FixedPoint128.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;

/// @title FixedPoint128
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
library FixedPoint128 {
    uint256 internal constant Q128 = 0x100000000000000000000000000000000;
}

File 7 of 61 : BattleInitializer.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import { IBattleInitializer } from "../interfaces/IBattleInitializer.sol";
import { IArenaCreation } from "core/interfaces/IArena.sol";
import { IBattleInit } from "core/interfaces/battle/IBattleInit.sol";
import { IBattleState } from "core/interfaces/battle/IBattleState.sol";
import { TickMath } from "core/libs/TickMath.sol";
import { CreateAndInitBattleParams } from "periphery/params/peripheryParams.sol";
import { PeripheryImmutableState } from "./PeripheryImmutableState.sol";
import { Errors } from "core/errors/Errors.sol";

abstract contract BattleInitializer is IBattleInitializer, PeripheryImmutableState {
    function createAndInitializeBattle(CreateAndInitBattleParams calldata params) external override returns (address battle) {
        battle = IArenaCreation(arena).getBattle(params.bk);
        if (battle == address(0)) {
            (battle) = IArenaCreation(arena).createBattle(params);
        } else {
            revert Errors.BattleExisted();
        }
    }
}

File 8 of 61 : LiquidityManagement.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import { SqrtPriceMath } from "@uniswap/v3-core/contracts/libraries/SqrtPriceMath.sol";
import { IArenaCreation } from "core/interfaces/IArena.sol";
import { IBattleActions } from "core/interfaces/battle/IBattleActions.sol";
import { IBattleState } from "core/interfaces/battle/IBattleState.sol";
import { BattleKey } from "core/types/common.sol";
import { TickMath } from "core/libs/TickMath.sol";
import { Errors } from "core/errors/Errors.sol";
import { LiquidityType } from "core/types/enums.sol";
import { IMintCallback } from "core/interfaces/callback/IMintCallback.sol";
import { BattleMintParams } from "core/params/coreParams.sol";
import { DiverLiquidityAmounts } from "../libs/DiverLiquidityAmounts.sol";
import { CallbackValidation } from "../libs/CallbackValidation.sol";
import { PeripheryPayments } from "./PeripheryPayments.sol";
import { AddLiqParams } from "../params/peripheryParams.sol";
import { PeripheryImmutableState } from "./PeripheryImmutableState.sol";

abstract contract LiquidityManagement is IMintCallback, PeripheryImmutableState, PeripheryPayments {
    struct MintCallbackData {
        BattleKey battleKey;
        address token;
        address payer;
    }

    /// @notice Called to msg.sender after minting liquidity to a position
    /// @param amountOwed The amount of tokens owed for the minted liquidity
    /// @param data Any data passed through by the caller
    function mintCallback(uint256 amountOwed, bytes calldata data) external override {
        MintCallbackData memory decode = abi.decode(data, (MintCallbackData));
        CallbackValidation.verifyCallback(arena, decode.battleKey);
        if (amountOwed > 0) {
            pay(decode.token, decode.payer, msg.sender, amountOwed);
        }
    }

    /// @notice Add liquidity to an initialized pool
    /// @return liquidityAmount The amount of liquidity to add
    /// @return battleAddr The address to which an AMM pool is created
    function _addLiquidity(AddLiqParams memory params) internal returns (uint128 liquidityAmount, address battleAddr) {
        battleAddr = IArenaCreation(arena).getBattle(params.battleKey);
        if (battleAddr == address(0)) {
            revert Errors.BattleNotExist();
        }
        (uint160 sqrtPriceX96,,) = IBattleState(battleAddr).slot0();
        if (sqrtPriceX96 < params.minSqrtPriceX96 || sqrtPriceX96 > params.maxSqrtPriceX96) {
            revert Errors.Slippage();
        }
        if (params.liquidityType == LiquidityType.COLLATERAL) {
            liquidityAmount = DiverLiquidityAmounts.getLiquidityFromCs(
                sqrtPriceX96, TickMath.getSqrtRatioAtTick(params.tickLower), TickMath.getSqrtRatioAtTick(params.tickUpper), params.amount
            );
        } else {
            liquidityAmount = DiverLiquidityAmounts.getLiquidityFromSToken(
                TickMath.getSqrtRatioAtTick(params.tickLower), TickMath.getSqrtRatioAtTick(params.tickUpper), params.amount
            );
        }

        address token;
        if (params.liquidityType == LiquidityType.COLLATERAL) {
            token = params.battleKey.collateral;
        } else if (params.liquidityType == LiquidityType.SPEAR) {
            (address spear,) = IBattleState(battleAddr).spearAndShield();
            token = spear;
        } else {
            (, address shield) = IBattleState(battleAddr).spearAndShield();
            token = shield;
        }

        IBattleActions(battleAddr).mint(
            BattleMintParams({
                recipient: params.recipient,
                tickLower: params.tickLower,
                tickUpper: params.tickUpper,
                liquidityType: params.liquidityType,
                amount: liquidityAmount,
                seed: params.amount,
                data: abi.encode(MintCallbackData({ battleKey: params.battleKey, token: token, payer: msg.sender }))
            })
        );
    }
}

File 9 of 61 : PeripheryImmutableState.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { IPeripheryImmutableState } from "../interfaces/IPeripheryImmutableState.sol";
import { Errors } from "core/errors/Errors.sol";

abstract contract PeripheryImmutableState is IPeripheryImmutableState {
    address public immutable arena;
    address public immutable WETH9;

    constructor(address _arena, address _WETH9) {
        if (_arena == address(0) || _WETH9 == address(0)) {
            revert Errors.ZeroValue();
        }
        arena = _arena;
        WETH9 = _WETH9;
    }
}

File 10 of 61 : IBattleActions.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { BattleMintParams, BattleBurnParams, BattleTradeParams } from "core/params/coreParams.sol";
import { PositionInfo, TradeType, Outcome, LiquidityType } from "core/types/common.sol";

interface IBattleMintBurn {
    /// @param sender The address used for minting liquidity
    /// @param liquidityType The type of token used as liquidity
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param liquidity The amount of liquidity minted
    /// @param seedAmount The amount of tokens used for minting liquidity, per collateral, spear or shield liquidityType
    event Minted(address indexed sender, LiquidityType liquidityType, int24 tickLower, int24 tickUpper, uint128 liquidity, uint256 seedAmount);

    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param liquidityType The type of token used as liquidity
    /// @param liquidityAmount The amount of liquidity burned
    event Burned(int24 tickLower, int24 tickUpper, LiquidityType liquidityType, uint128 liquidityAmount);

    /// @notice Mint liquidity
    /// @param mp The params for minting liquidity
    function mint(BattleMintParams memory mp) external;

    /// @notice Burn liquidity
    /// @param BurnParams The params for burning liquidity
    function burn(BattleBurnParams memory BurnParams) external;

    /// @notice Transfers collateral/spear/shield tokens to the liquidity provider. Only called by the manager contract
    /// @param recipient The address who receive collateral/spear/shield tokens
    /// @param cAmount The amount of collateral to be transfered
    /// @param spAmount The amount of spear to be transfered
    /// @param shAmount The amount of shield to be transfered
    function collect(address recipient, uint256 cAmount, uint256 spAmount, uint256 shAmount) external;
}

/// @title IBattleTrade
interface IBattleTrade {
    /// @notice Swap collateral for spear or shield tokens
    /// @param recipient The address who receive spear or shield tokens
    /// @param liquidity liquity in battle after trade
    /// @param amountIn The amount of token input
    /// @param amountOut The amount of token output
    /// @param tradeType BUY_SPEAR or BUY_SHIELD
    /// @param sqrtPriceX96 The sqrt price of the battle after the trade
    /// @param tick The tick of the battle after the trade
    event Traded(
        address indexed recipient, uint128 liquidity, uint256 amountIn, uint256 amountOut, TradeType tradeType, uint160 sqrtPriceX96, int24 tick
    );

    /// @notice Swap collateral for spear or shield tokens
    /// @param tp The params for the trade
    /// @return cAmount The amount of collateral paid by the trader
    /// @return sAmount The amount of spear or shield tokens received by the trader
    /// @return fAmount The amount of fee in collateral token to be spent for the trade
    function trade(BattleTradeParams memory tp) external returns (uint256 cAmount, uint256 sAmount, uint256 fAmount);
}

interface IBattleBase {
    event ObligationWithdrawed(address recipient, uint256 amount);

    event InternalInitialized(address indexed battleInternal, int24 tick, uint160 sqrtPriceX96, uint256 startTS, uint256 endTS);

    event Settled(address indexed sender, Outcome battleResult, uint256 ts, uint256 price);

    event Exercised(address indexed sender, bool spearWin, uint256 amount);

    event ProtocolFeeCollected(address recipient, uint256 amount);

    /// @notice Settles the battle and determines the outcome.
    /// The Battle contract will fetch the price of underlying asset, and determines the outcome.
    /// Once settled, a pool's address is not reused for new battles
    function settle() external;

    /// @notice After settlement, an in-the-money spear or shield token is exercised for one collateral.
    /// eg. Alice bought 100 spear. If the outcome is spear_win, she can
    /// claim 100 collateral minus an exercise fee by calling this function.
    function exercise() external;

    /// @notice Enables the liquidity provider to withdraw the collateral amount reserved for settlement. Only called by the manager contract.
    /// @param recipient The liquidity provider address to receive collateral
    /// @param amount the amount of collateral to be received
    function withdrawObligation(address recipient, uint256 amount) external;

    /// @notice Allows the accumulated protocol fee to be collected. Can only be called by the owner.
    function collectProtocolFee(address recipient) external;
}

interface IBattleActions is IBattleMintBurn, IBattleTrade, IBattleBase { }

File 11 of 61 : coreParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { BattleBurnParams } from "./BattleBurnParams.sol";
import { BattleMintParams } from "./BattleMintParams.sol";
import { BattleTradeParams } from "./BattleTradeParams.sol";
import { ComputeTradeStepParams } from "./ComputeTradeStepParams.sol";
import { CreateBattleParams } from "./CreateBattleParams.sol";
import { DeploymentParams } from "./DeploymentParams.sol";
import { ModifyPositionParams } from "./ModifyPositionParams.sol";
import { UpdatePositionParams } from "./UpdatePositionParams.sol";

File 12 of 61 : enums.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

enum LiquidityType {
    COLLATERAL,
    SPEAR,
    SHIELD
}

enum Outcome {
    ONGOING, // battle is ongoing
    SPEAR_WIN, // calls expire in-the-money
    SHIELD_WIN // puts expire in-the-money
}

enum TradeType {
    BUY_SPEAR,
    BUY_SHIELD
}

File 13 of 61 : TickMath.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { TickMath as UniTickMath } from "@uniswap/v3-core/contracts/libraries/TickMath.sol";
import { Errors } from "core/errors/Errors.sol";

/// @notice Math library for computing sqrt prices from ticks and vice versa. Sets the minimum and maximum of ticks and sqrt prices.
/// As digital calls and puts are priced between [0.01, 0.99] per collateral, per put-call parity, the sqrtPrice is the sqrt ratio of
/// shieldPrice/spearPrice is between [sqrt(1/99), sqrt(99)].
/// Computes sqrtPrice for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers.

library TickMath {
    int24 internal constant MIN_TICK = -45953;
    int24 internal constant MAX_TICK = 45953;

    uint160 internal constant MIN_SQRT_RATIO = 7_962_927_413_460_596_097_951_659_957;
    uint160 internal constant MAX_SQRT_RATIO = 788_290_713_886_932_820_263_790_562_376;

    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        if (!(tick >= MIN_TICK && tick <= MAX_TICK)) {
            revert Errors.TickInvalid();
        }
        return UniTickMath.getSqrtRatioAtTick(tick);
    }

    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) {
            revert Errors.PriceInvalid();
        }
        return UniTickMath.getTickAtSqrtRatio(sqrtPriceX96);
    }
}

File 14 of 61 : Errors.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

library Errors {
    error BattleNotEnd();
    error BattleEnd();
    error BattleSettled();
    error BattleNotExist();
    error BattleExisted();
    error Deadline();
    error InsufficientCollateral();
    error InsufficientSpear();
    error InsufficientShield();
    error InitTwice();
    error Insufficient();
    error LiquidityNotRemoved();
    error LiquidityNotAdded();
    error Locked();
    error NotSupported();
    error NotSupportedExpiries();
    error NotWETH9();
    error OnlyOwner();
    error OnlyBattle();
    error OnlyManager();
    error OraclePriceError();
    error PriceInvalid();
    error Slippage();
    error TickOrderInvalid();
    error TickInvalid();
    error TradeError();
    error ZeroValue();
    error EmptyTrade();
}

File 15 of 61 : IArena.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { Fee, BattleKey, Outcome } from "core/types/common.sol";
import { CreateAndInitBattleParams } from "periphery/params/peripheryParams.sol";

interface IArenaAdmin {
    event FeeChanged(string underlying, Fee fee);
    event CollateralWhitelistChanged(address collateral, bool state);
    event UnderlyingWhitelistChanged(string underlying, bool state, Fee fee);
    event PermissionlessChanged(bool state);
    event SupportedChanged(address collateralToken, string underlying, bool isSupported);
    event ManagerChanged(address old, address _new);
    event OracleChanged(address old, address _new);

    function setFeeForUnderlying(string calldata underlying, Fee calldata newFee) external;
    function setCollateralWhitelist(address collateral, bool isSupported) external;
    function setUnderlyingWhitelist(string memory underlying, bool isSupported, Fee calldata fee) external;
    function setPermissionless() external;
    function setManager(address _manager) external;
    function setOracle(address _oracle) external;
}

interface IArenaCreation {
    event BattleCreated(BattleKey bk, address battleAddr, address spear, address shield, Fee fee);

    /// @notice Create a new battle
    /// @param params Params for creating a new battle
    /// @return battleAddr new battle address
    function createBattle(CreateAndInitBattleParams memory params) external returns (address battleAddr);

    /// @notice Get the address of the existing battle or address(0) if not found
    function getBattle(BattleKey memory battleKey) external view returns (address battleAddr);
}

interface IArenaState {
    struct BattleInfo {
        address battle;
        BattleKey bk;
        uint160 sqrtPriceX96;
        int24 tick;
        uint256 startTS;
        uint256 endTS;
        address spear;
        address shield;
        Outcome result;
    }

    function getAllBattles() external view returns (BattleInfo[] memory);
}

interface IArena is IArenaAdmin, IArenaCreation, IArenaState { }

File 16 of 61 : IBattleState.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "core/types/common.sol";

interface IBattleState {
    /// @notice Retrieves position info for a given position key
    /// @param pk positon key
    /// @param info Information about the position
    function positions(bytes32 pk) external view returns (PositionInfo memory info);

    /// @notice The result of battle.
    /// @return result check different battle result type in enums.sol
    function battleOutcome() external view returns (Outcome);

    /// @notice Returns the BattleKey that uniquely identifies a battle
    function battleKey() external view returns (BattleKey memory key);

    /// @notice Get Manager address in this battle
    function manager() external view returns (address);

    /// @notice BaseInfo includes current sqrtPriceX96, current tick
    function slot0() external view returns (uint160 sqrtPriceX96, int24 tick, bool unlocked);

    function spearAndShield() external view returns (address, address);

    function startAndEndTS() external view returns (uint256, uint256);

    function spearBalanceOf(address account) external view returns (uint256 amount);

    function shieldBalanceOf(address account) external view returns (uint256 amount);

    function spear() external view returns (address);

    function shield() external view returns (address);

    function getInsideLast(int24 tickLower, int24 tickUpper) external view returns (GrowthX128 memory);

    function fee() external view returns (uint256, uint256, uint256);
}

File 17 of 61 : IManagerState.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { PositionState, Position } from "../types/common.sol";

interface IManagerState {
    /**
     * @notice Get the position belonging to an nft
     */
    function positions(uint256 tokenId) external view returns (Position memory);

    function nextId() external view returns (uint256);
}

File 18 of 61 : IManager.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { IManagerActions } from "./IManagerActions.sol";
import { IManagerState } from "./IManagerState.sol";
import { IBattleInitializer } from "./IBattleInitializer.sol";
import { IPeripheryImmutableState } from "./IPeripheryImmutableState.sol";

interface IManager is IBattleInitializer, IManagerActions, IManagerState { }

File 19 of 61 : IManagerActions.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { Owed, LiquidityType, TradeType } from "core/types/common.sol";
import { ITradeCallback } from "core/interfaces/callback/ITradeCallback.sol";
import { AddLiqParams, TradeParams } from "periphery/params/peripheryParams.sol";

interface IManagerLiquidity {
    /// @notice Emitted when liquidity is added
    /// @param battleAddress The address of the battle
    /// @param owner The owner of the position and nft
    /// @param tokenId The id of the nft
    /// @param liquidity The amount of liquidity added to nft
    /// @param liquidityType Specifies the type of liquidity seeded to the position is collateral, spear, or shield
    /// @param seedAmount The token amount provided for the position, of the collateral, spear or shield liquidity type
    event LiquidityAdded(
        address indexed battleAddress, address indexed owner, uint256 tokenId, uint128 liquidity, LiquidityType liquidityType, uint256 seedAmount
    );

    /// @notice Emitted when liquidity is removed
    /// @param tokenId The id of the nft
    /// @param collateralAmount The amount of collateral that lp got
    /// @param stokenAmount The amount of spear/shield that lp got
    event LiquidityRemoved(uint256 tokenId, uint256 collateralAmount, uint256 stokenAmount);

    event ObligationWithdrawn(address battle, uint256 tokenId, uint256 amount);

    event ObligationRedeemed(address battle, uint256 tokenId, uint256 amount);

    /// @notice Adds liquidity to the protocol.
    /// @param params The params for adding liquidity
    /// @return tokenId The id of the nft
    /// @return liquidity The amount of added liquidity
    function addLiquidity(AddLiqParams calldata params) external returns (uint256 tokenId, uint128 liquidity);

    /// @notice Removes liquidity from the pool, given the tokenId of a position. Only to be called once by the liquidity provider.
    /// @param tokenId The ID of the NFT that represents the liquidity position
    /// @return collateral The amount of collateral to be received by the liqudity provider
    /// @return spear The amount of Spear to be received by the liquidity provider
    /// @return shield The amount of Shield to be received by the liquidity provider
    /// @return spearObligation The obligatory reserve of collateral amount for settling spear tokens sold by the position
    /// @return shieldObligation The obligatory reserve of collateral amount for settling shield tokens sold by the position
    function removeLiquidity(uint256 tokenId)
        external
        returns (uint256 collateral, uint256 spear, uint256 shield, uint256 spearObligation, uint256 shieldObligation);

    /// @notice Returns the amount of collateral reserved for options that settle out-of-money.
    /// Can be called once after expiry by the liquidity provider and must be called after liquidity has been removed.
    /// @param tokenId The ID of the NFT that represents the liquidity position
    function withdrawObligation(uint256 tokenId) external;

    /// @notice Returns the amount of collateral reserved for the liquidity providers' open short interest.
    /// The LP gets one collateral for sending one spear or shield token back to the pool to close the net amount of short options exposure.
    /// Can be called once before expiry by the LP and must be called after liquidity has been removed.
    /// @param tokenId The ID of the NFT that represents the liquidity position
    function redeemObligation(uint256 tokenId) external;
}

interface IManagerTrade is ITradeCallback {
    event Traded(address recipient, TradeType tradeType, uint256 amountIn, uint256 amountOut);

    /// @notice Calls the battle contract to execute a trade
    /// @param mtp The params of trade in manager contract
    /// @return amountIn The collateral amount to be swapped in based on the direction of the swap
    /// @return amountOut The amount to be received, of either spear or shield token, based on the direction of the swap
    /// @return amountFee The amount of fee in collateral token to be spent for the trade
    function trade(TradeParams calldata mtp) external returns (uint256, uint256, uint256);
}

interface IManagerActions is IManagerLiquidity, IManagerTrade { }

File 20 of 61 : peripheryParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { BattleKey, LiquidityType, TradeType } from "core/types/common.sol";

/// @param bk The battle key
/// @param sqrtPriceX96 The start sqrt price of the battle
struct CreateAndInitBattleParams {
    BattleKey bk;
    uint160 sqrtPriceX96;
}

/// @notice Parameters for adding liquidity
/// @param battleKey The battle key
/// @param recipient The address that receives nft
/// @param tickLower The lower tick boundary of the position
/// @param tickUpper The upper tick boundary of the position
/// @param liquidityType Specifies the type of liquidity added to the position is collateral, spear, or shield
/// @param amount The amount of collateral/spear/shield to add
/// @param deadline The deadline of the transaction
struct AddLiqParams {
    BattleKey battleKey;
    address recipient;
    int24 tickLower;
    int24 tickUpper;
    uint160 minSqrtPriceX96;
    uint160 maxSqrtPriceX96;
    LiquidityType liquidityType;
    uint128 amount;
    uint256 deadline;
}

/// @param battleKey The battle key
/// @param tradeType The trade type, BUY_SPEAR or BUY_SHIELD
/// @param amountSpecified How much collateral input or SToken output amount to be swapped in/out
/// @param recipient The address that receives spear or shield tokens
/// @param amountOutMin The minimum amount of spear or shield tokens to receive
/// @param sqrtPriceLimitX96 The max/min price when trading ends
/// @param deadline The deadline of the transaction
struct TradeParams {
    BattleKey battleKey;
    TradeType tradeType;
    int256 amountSpecified;
    address recipient;
    uint256 amountOutMin;
    uint160 sqrtPriceLimitX96;
    uint256 deadline;
}

File 21 of 61 : common.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { GrowthX128, Owed, LiquidityType } from "core/types/common.sol";

enum PositionState {
    LiquidityAdded,
    LiquidityRemoved,
    ObligationWithdrawn,
    ObligationRedeemed
}

struct Position {
    uint256 tokenId;
    address battleAddr;
    int24 tickLower;
    int24 tickUpper;
    uint128 liquidity;
    LiquidityType liquidityType; // The chosen liquidity type can be Collateral, Spear, or Shield
    uint256 seed; //The amount of tokens from the LP for the given liquidity type |
    GrowthX128 insideLast; // GrowthX128 info per unit of liquidity inside the a position's bound as of the last action
    Owed owed; // the amounts of fees and deltas of collateral, Spear and Shield tokens that are owed to a position
    PositionState state; // obligation will be set when liquidity is removed
    uint256 spearObligation; //The obligatory reserve of collateral amount for settling spear tokens sold by the position
    uint256 shieldObligation; //The obligatory reserve of collateral amount for settling shield tokens sold by the position
}

File 22 of 61 : CallbackValidation.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import { BattleKey } from "core/types/common.sol";
import { IArenaCreation } from "core/interfaces/IArena.sol";
import { Errors } from "core/errors/Errors.sol";

library CallbackValidation {
    function verifyCallback(address arenaAddr, BattleKey memory battleKey) internal view {
        require(IArenaCreation(arenaAddr).getBattle(battleKey) == msg.sender, "onlyBattle");
        if (IArenaCreation(arenaAddr).getBattle(battleKey) != msg.sender) {
            revert Errors.OnlyBattle();
        }
    }
}

File 23 of 61 : common.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { LiquidityType, Outcome, TradeType } from "core/types/enums.sol";

struct BattleKey {
    /// @dev The address of the token used as collateral in the battle, eg: usdt/usdc
    address collateral;
    /// @dev The underlying asset symbol, such as btc, eth, etc
    string underlying;
    /// @dev end time of the battle
    uint256 expiries;
    /// @dev strike price of the options within the pool
    uint256 strikeValue;
}

struct Fee {
    /// @dev The fee ratio taken on every trade
    uint256 transactionFee;
    /// @dev The portion of transaction fee that goes to the protocol
    uint256 protocolFee;
    /// @dev The exercise fee paid by those who call exercise()
    uint256 exerciseFee;
}

struct GrowthX128 {
    /// @dev The all-time growth in transaction fee, per unit of liquidity, in collateral token
    uint256 fee;
    /// @dev The all-time growth in the received collateral inputs, per unit of liquidity, as options premium
    uint256 collateralIn;
    /// @dev The all-time growth in Spear token outputs per unit of liquidity
    uint256 spearOut;
    /// @dev The all-time growth in Shield token outputs per unit of liquidity
    uint256 shieldOut;
}

/// @notice tracking the GrowthX128 amounts owed to a position
struct Owed {
    /// @dev The amount of transaction fee owed to the position as of the last computation
    uint128 fee;
    /// @dev The collateral inputs owed to the position as of the last computation
    uint128 collateralIn;
    /// @dev The Spear token outputs owed to the position as of the last computation
    uint128 spearOut;
    /// @dev The Shield token outputs owed to the position as of the last computation
    uint128 shieldOut;
}

struct TickInfo {
    /// @dev The total amount of liquidity that the pool uses either at tickLower or tickUpper
    uint128 liquidityGross;
    /// @dev The amount of liquidity added (subtracted) when tick is crossed from left to right (right to left)
    int128 liquidityNet;
    /// @dev The GrowthX128 info recorded on the other side of the tick from the current tick
    GrowthX128 outside;
    /// @dev Whether the tick is initialized
    bool initialized;
}

struct PositionInfo {
    /// @dev The amount of usable liquidity
    uint128 liquidity;
    /// @dev The GrowthX128 info per unit of liquidity inside the a position's bound as of the last action
    GrowthX128 insideLast;
}

File 24 of 61 : ERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.2) (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 = _ownerOf(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 or 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 or 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 or 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 the owner of the `tokenId`. Does NOT revert if token doesn't exist
     */
    function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
        return _owners[tokenId];
    }

    /**
     * @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 _ownerOf(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, 1);

        // Check that tokenId was not minted by `_beforeTokenTransfer` hook
        require(!_exists(tokenId), "ERC721: token already minted");

        unchecked {
            // Will not overflow unless all 2**256 token ids are minted to the same owner.
            // Given that tokens are minted one by one, it is impossible in practice that
            // this ever happens. Might change if we allow batch minting.
            // The ERC fails to describe this case.
            _balances[to] += 1;
        }

        _owners[tokenId] = to;

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

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

    /**
     * @dev Destroys `tokenId`.
     * The approval is cleared when the token is burned.
     * This is an internal function that does not check if the sender is authorized to operate on the token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     *
     * Emits a {Transfer} event.
     */
    function _burn(uint256 tokenId) internal virtual {
        address owner = ERC721.ownerOf(tokenId);

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

        // Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook
        owner = ERC721.ownerOf(tokenId);

        // Clear approvals
        delete _tokenApprovals[tokenId];

        unchecked {
            // Cannot overflow, as that would require more tokens to be burned/transferred
            // out than the owner initially received through minting and transferring in.
            _balances[owner] -= 1;
        }
        delete _owners[tokenId];

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

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

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

        // Check that tokenId was not transferred by `_beforeTokenTransfer` hook
        require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");

        // Clear approvals from the previous owner
        delete _tokenApprovals[tokenId];

        unchecked {
            // `_balances[from]` cannot overflow for the same reason as described in `_burn`:
            // `from`'s balance is the number of token held, which is at least one before the current
            // transfer.
            // `_balances[to]` could overflow in the conditions described in `_mint`. That would require
            // all 2**256 token ids to be minted, which in practice is impossible.
            _balances[from] -= 1;
            _balances[to] += 1;
        }
        _owners[tokenId] = to;

        emit Transfer(from, to, tokenId);

        _afterTokenTransfer(from, to, tokenId, 1);
    }

    /**
     * @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. If {ERC721Consecutive} is
     * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
     * - When `from` is zero, the tokens will be minted for `to`.
     * - When `to` is zero, ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     * - `batchSize` is non-zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 firstTokenId,
        uint256 batchSize
    ) internal virtual {}

    /**
     * @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is
     * used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
     *
     * Calling conditions:
     *
     * - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.
     * - When `from` is zero, the tokens were minted for `to`.
     * - When `to` is zero, ``from``'s tokens were burned.
     * - `from` and `to` are never both zero.
     * - `batchSize` is non-zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address from,
        address to,
        uint256 firstTokenId,
        uint256 batchSize
    ) internal virtual {}

    /**
     * @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
     *
     * WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant
     * being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such
     * that `ownerOf(tokenId)` is `a`.
     */
    // solhint-disable-next-line func-name-mixedcase
    function __unsafe_increaseBalance(address account, uint256 amount) internal {
        _balances[account] += amount;
    }
}

File 25 of 61 : 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 26 of 61 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

    mapping(address => mapping(address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual override returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual override returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless this function is
     * overridden;
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual override returns (uint8) {
        return 18;
    }

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

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

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

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

File 27 of 61 : 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 28 of 61 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

File 29 of 61 : IBattleInitializer.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { CreateAndInitBattleParams } from "periphery/params/peripheryParams.sol";

interface IBattleInitializer {
    function createAndInitializeBattle(CreateAndInitBattleParams memory params) external returns (address battle);
}

File 30 of 61 : IBattleInit.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { DeploymentParams } from "core/params/coreParams.sol";

interface IBattleInit {
    function init(DeploymentParams memory params) external;
}

File 31 of 61 : SqrtPriceMath.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {SafeCast} from './SafeCast.sol';

import {FullMath} from './FullMath.sol';
import {UnsafeMath} from './UnsafeMath.sol';
import {FixedPoint96} from './FixedPoint96.sol';

/// @title Functions based on Q64.96 sqrt price and liquidity
/// @notice Contains the math that uses square root of price as a Q64.96 and liquidity to compute deltas
library SqrtPriceMath {
    using SafeCast for uint256;

    /// @notice Gets the next sqrt price given a delta of token0
    /// @dev Always rounds up, because in the exact output case (increasing price) we need to move the price at least
    /// far enough to get the desired output amount, and in the exact input case (decreasing price) we need to move the
    /// price less in order to not send too much output.
    /// The most precise formula for this is liquidity * sqrtPX96 / (liquidity +- amount * sqrtPX96),
    /// if this is impossible because of overflow, we calculate liquidity / (liquidity / sqrtPX96 +- amount).
    /// @param sqrtPX96 The starting price, i.e. before accounting for the token0 delta
    /// @param liquidity The amount of usable liquidity
    /// @param amount How much of token0 to add or remove from virtual reserves
    /// @param add Whether to add or remove the amount of token0
    /// @return The price after adding or removing amount, depending on add
    function getNextSqrtPriceFromAmount0RoundingUp(
        uint160 sqrtPX96,
        uint128 liquidity,
        uint256 amount,
        bool add
    ) internal pure returns (uint160) {
        // we short circuit amount == 0 because the result is otherwise not guaranteed to equal the input price
        if (amount == 0) return sqrtPX96;
        uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;

        if (add) {
            unchecked {
                uint256 product;
                if ((product = amount * sqrtPX96) / amount == sqrtPX96) {
                    uint256 denominator = numerator1 + product;
                    if (denominator >= numerator1)
                        // always fits in 160 bits
                        return uint160(FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator));
                }
            }
            // denominator is checked for overflow
            return uint160(UnsafeMath.divRoundingUp(numerator1, (numerator1 / sqrtPX96) + amount));
        } else {
            unchecked {
                uint256 product;
                // if the product overflows, we know the denominator underflows
                // in addition, we must check that the denominator does not underflow
                require((product = amount * sqrtPX96) / amount == sqrtPX96 && numerator1 > product);
                uint256 denominator = numerator1 - product;
                return FullMath.mulDivRoundingUp(numerator1, sqrtPX96, denominator).toUint160();
            }
        }
    }

    /// @notice Gets the next sqrt price given a delta of token1
    /// @dev Always rounds down, because in the exact output case (decreasing price) we need to move the price at least
    /// far enough to get the desired output amount, and in the exact input case (increasing price) we need to move the
    /// price less in order to not send too much output.
    /// The formula we compute is within <1 wei of the lossless version: sqrtPX96 +- amount / liquidity
    /// @param sqrtPX96 The starting price, i.e., before accounting for the token1 delta
    /// @param liquidity The amount of usable liquidity
    /// @param amount How much of token1 to add, or remove, from virtual reserves
    /// @param add Whether to add, or remove, the amount of token1
    /// @return The price after adding or removing `amount`
    function getNextSqrtPriceFromAmount1RoundingDown(
        uint160 sqrtPX96,
        uint128 liquidity,
        uint256 amount,
        bool add
    ) internal pure returns (uint160) {
        // if we're adding (subtracting), rounding down requires rounding the quotient down (up)
        // in both cases, avoid a mulDiv for most inputs
        if (add) {
            uint256 quotient = (
                amount <= type(uint160).max
                    ? (amount << FixedPoint96.RESOLUTION) / liquidity
                    : FullMath.mulDiv(amount, FixedPoint96.Q96, liquidity)
            );

            return (uint256(sqrtPX96) + quotient).toUint160();
        } else {
            uint256 quotient = (
                amount <= type(uint160).max
                    ? UnsafeMath.divRoundingUp(amount << FixedPoint96.RESOLUTION, liquidity)
                    : FullMath.mulDivRoundingUp(amount, FixedPoint96.Q96, liquidity)
            );

            require(sqrtPX96 > quotient);
            // always fits 160 bits
            unchecked {
                return uint160(sqrtPX96 - quotient);
            }
        }
    }

    /// @notice Gets the next sqrt price given an input amount of token0 or token1
    /// @dev Throws if price or liquidity are 0, or if the next price is out of bounds
    /// @param sqrtPX96 The starting price, i.e., before accounting for the input amount
    /// @param liquidity The amount of usable liquidity
    /// @param amountIn How much of token0, or token1, is being swapped in
    /// @param zeroForOne Whether the amount in is token0 or token1
    /// @return sqrtQX96 The price after adding the input amount to token0 or token1
    function getNextSqrtPriceFromInput(
        uint160 sqrtPX96,
        uint128 liquidity,
        uint256 amountIn,
        bool zeroForOne
    ) internal pure returns (uint160 sqrtQX96) {
        require(sqrtPX96 > 0);
        require(liquidity > 0);

        // round to make sure that we don't pass the target price
        return
            zeroForOne
                ? getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountIn, true)
                : getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountIn, true);
    }

    /// @notice Gets the next sqrt price given an output amount of token0 or token1
    /// @dev Throws if price or liquidity are 0 or the next price is out of bounds
    /// @param sqrtPX96 The starting price before accounting for the output amount
    /// @param liquidity The amount of usable liquidity
    /// @param amountOut How much of token0, or token1, is being swapped out
    /// @param zeroForOne Whether the amount out is token0 or token1
    /// @return sqrtQX96 The price after removing the output amount of token0 or token1
    function getNextSqrtPriceFromOutput(
        uint160 sqrtPX96,
        uint128 liquidity,
        uint256 amountOut,
        bool zeroForOne
    ) internal pure returns (uint160 sqrtQX96) {
        require(sqrtPX96 > 0);
        require(liquidity > 0);

        // round to make sure that we pass the target price
        return
            zeroForOne
                ? getNextSqrtPriceFromAmount1RoundingDown(sqrtPX96, liquidity, amountOut, false)
                : getNextSqrtPriceFromAmount0RoundingUp(sqrtPX96, liquidity, amountOut, false);
    }

    /// @notice Gets the amount0 delta between two prices
    /// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper),
    /// i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The amount of usable liquidity
    /// @param roundUp Whether to round the amount up or down
    /// @return amount0 Amount of token0 required to cover a position of size liquidity between the two passed prices
    function getAmount0Delta(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity,
        bool roundUp
    ) internal pure returns (uint256 amount0) {
        unchecked {
            if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

            uint256 numerator1 = uint256(liquidity) << FixedPoint96.RESOLUTION;
            uint256 numerator2 = sqrtRatioBX96 - sqrtRatioAX96;

            require(sqrtRatioAX96 > 0);

            return
                roundUp
                    ? UnsafeMath.divRoundingUp(
                        FullMath.mulDivRoundingUp(numerator1, numerator2, sqrtRatioBX96),
                        sqrtRatioAX96
                    )
                    : FullMath.mulDiv(numerator1, numerator2, sqrtRatioBX96) / sqrtRatioAX96;
        }
    }

    /// @notice Gets the amount1 delta between two prices
    /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower))
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The amount of usable liquidity
    /// @param roundUp Whether to round the amount up, or down
    /// @return amount1 Amount of token1 required to cover a position of size liquidity between the two passed prices
    function getAmount1Delta(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity,
        bool roundUp
    ) internal pure returns (uint256 amount1) {
        unchecked {
            if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

            return
                roundUp
                    ? FullMath.mulDivRoundingUp(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96)
                    : FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
        }
    }

    /// @notice Helper that gets signed token0 delta
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The change in liquidity for which to compute the amount0 delta
    /// @return amount0 Amount of token0 corresponding to the passed liquidityDelta between the two prices
    function getAmount0Delta(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        int128 liquidity
    ) internal pure returns (int256 amount0) {
        unchecked {
            return
                liquidity < 0
                    ? -getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()
                    : getAmount0Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();
        }
    }

    /// @notice Helper that gets signed token1 delta
    /// @param sqrtRatioAX96 A sqrt price
    /// @param sqrtRatioBX96 Another sqrt price
    /// @param liquidity The change in liquidity for which to compute the amount1 delta
    /// @return amount1 Amount of token1 corresponding to the passed liquidityDelta between the two prices
    function getAmount1Delta(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        int128 liquidity
    ) internal pure returns (int256 amount1) {
        unchecked {
            return
                liquidity < 0
                    ? -getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(-liquidity), false).toInt256()
                    : getAmount1Delta(sqrtRatioAX96, sqrtRatioBX96, uint128(liquidity), true).toInt256();
        }
    }
}

File 32 of 61 : IMintCallback.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IMintCallback {
    function mintCallback(uint256 amountOwed, bytes calldata data) external;
}

File 33 of 61 : DiverLiquidityAmounts.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import { FullMath } from "@uniswap/v3-core/contracts/libraries/FullMath.sol";
import { FixedPoint96 } from "@uniswap/v3-core/contracts/libraries/FixedPoint96.sol";
import { SafeCast } from "@oz/utils/math/SafeCast.sol";
import { LiquidityAmounts } from "@uniswap/v3-periphery/contracts/libraries/LiquidityAmounts.sol";

library DiverLiquidityAmounts {
    using SafeCast for uint256;
    /// @notice Computes the amount of liquidity to be received by the pool, for a given amount of collateral and price range. The formula is:
    ///  L = ΔC*sqrtPrice*sqrt(P_h)/(sqrt(P_h) - sqrtPrice +
    /// sqrt(P_h)*sqrtPrice**2 - sqrtPrice*sqrt(P_h)*sqrt(P_l))
    /// @param sqrtRatioX96 The current square root ratio|
    /// @param sqrtRatioAX96 A sqrt ratio
    /// @param sqrtRatioBX96 Another sqrt ratio
    /// @param amount The seed collateral amount for minting the liquidity position
    /// @return liquidity The amount of liquidity to be received by the pool

    function getLiquidityFromCs(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount
    )
        internal
        pure
        returns (uint128 liquidity)
    {
        if (sqrtRatioAX96 > sqrtRatioBX96) {
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        }
        if (sqrtRatioX96 <= sqrtRatioAX96) {
            liquidity = LiquidityAmounts.getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            uint256 multi = FullMath.mulDivRoundingUp(sqrtRatioX96, sqrtRatioBX96, FixedPoint96.Q96);
            uint256 denominator = FullMath.mulDivRoundingUp(sqrtRatioX96 - sqrtRatioAX96, multi, FixedPoint96.Q96) + sqrtRatioBX96 - sqrtRatioX96;
            uint256 multi2 = FullMath.mulDiv(sqrtRatioX96, sqrtRatioBX96, FixedPoint96.Q96);
            liquidity = FullMath.mulDiv(amount * multi2, 1, denominator).toUint128();
        } else {
            liquidity = LiquidityAmounts.getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount);
        }
    }

    /// @notice Computes the amount of liquidity to be received by the pool, for a given amount of Spear or Shield tokens and price range. The formula
    /// is:
    /**
     * @dev liquidity = (amount * sqrtRatioAX96 * sqrtRatioBX96) / (
     * (sqrtRatioBX96 - sqrtRatioAX96) * (1 +
     * sqrtRatioAX96 * sqrtRatioBX96));
     */
    /// @param sqrtRatioAX96 A sqrt ratio
    /// @param sqrtRatioBX96 Another sqrt ratio
    /// @param amount The seed Spear or Shield amount for minting the liquidity position
    /// @return liquidity The amount of liquidity to be received by the pool

    function getLiquidityFromSToken(uint160 sqrtRatioAX96, uint160 sqrtRatioBX96, uint256 amount) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) {
            (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        }
        uint256 product = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);
        liquidity = (FullMath.mulDiv(amount * sqrtRatioAX96, sqrtRatioBX96, sqrtRatioBX96 - sqrtRatioAX96) / (FixedPoint96.Q96 + product)).toUint128();
    }
}

File 34 of 61 : PeripheryPayments.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import { IERC20 } from "@oz/token/ERC20/IERC20.sol";
import { TransferHelper } from "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
import { Errors } from "core/errors/Errors.sol";
import { IWETH9 } from "../interfaces/external/IWETH9.sol";
import { PeripheryImmutableState } from "./PeripheryImmutableState.sol";

abstract contract PeripheryPayments is PeripheryImmutableState {
    receive() external payable {
        if (msg.sender != WETH9) {
            revert Errors.NotWETH9();
        }
    }

    /// @notice Handles the payment of tokens or ETH from one address to another
    /// @param tokenAddr The address of the token to pay
    /// @param payer The account that should pay the tokens
    /// @param recipient The account that should receive the tokens
    /// @param value The amount to pay
    function pay(address tokenAddr, address payer, address recipient, uint256 value) internal {
        if (tokenAddr == WETH9 && address(this).balance >= value) {
            IWETH9(WETH9).deposit{ value: value }();
            IWETH9(WETH9).transfer(recipient, value);
        } else {
            TransferHelper.safeTransferFrom(tokenAddr, payer, recipient, value);
        }
    }
}

File 35 of 61 : IPeripheryImmutableState.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

interface IPeripheryImmutableState {
    function arena() external view returns (address);
    function WETH9() external view returns (address);
}

File 36 of 61 : BattleBurnParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { LiquidityType } from "core/types/common.sol";

struct BattleBurnParams {
    int24 tickLower; //The lower tick boundary of the position for which to burn liquidity
    int24 tickUpper; //The upper tick boundary of the position for which to burn liquidity
    LiquidityType liquidityType; //The chosen liquidity type can be Collateral, Spear, or Shield
    uint128 liquidityAmount; //The amount of liquidity to be burnt
}

File 37 of 61 : BattleMintParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { LiquidityType } from "core/types/enums.sol";

struct BattleMintParams {
    address recipient; //The address for which the liquidity will be added
    int24 tickLower; //The lower tick boundary of the position in which to add liquidity
    int24 tickUpper; //The upper tick boundary of the position in which to add liquidity
    LiquidityType liquidityType; //The chosen liquidity type can be Collateral, Spear, or Shield
    uint128 amount; // The amount of liquidity to be added
    uint128 seed; //The seed amount for the given liquidity type
    bytes data;
}

File 38 of 61 : BattleTradeParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { TradeType } from "core/types/enums.sol";

struct BattleTradeParams {
    address recipient; //The address to receive the output of the swap
    TradeType tradeType; //whether to buy spear or buy shield
    int256 amountSpecified; //The amount of the swap, which implicitly configures the swap as exact input of collateral or exact output of spear or
        // shield token delta
    uint160 sqrtPriceLimitX96; // The Q64.96 sqrtPrice limit
    bytes data;
}

File 39 of 61 : ComputeTradeStepParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { TradeType } from "core/types/common.sol";

struct ComputeTradeStepParams {
    TradeType tradeType; //whether to buy spear or buy shield
    uint160 sqrtRatioCurrentX96; //The current sqrt ratio of the pool
    uint160 sqrtRatioTargetX96; //The price that cannot be exceeded, from which the direction of the swap is inferred
    uint128 liquidity; // The usable liquidity
    int256 amountRemaining; //How much input or output amount is remaining to be swapped in/out
    uint256 unit; //The token decimal unit, e.g. a token with 18 decimals has a unit of 10**18
}

File 40 of 61 : CreateBattleParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

struct CreateBattleParams {
    address collateralToken; //The supported collateral token address for the battle
    string underlying; //The underlying asset symbol
    uint256 expiries; //The of expiry timestamp of the battle
    uint256 strikeValue; //The value of an option's strike price
}

File 41 of 61 : DeploymentParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { BattleKey, Fee } from "core/types/common.sol";

struct DeploymentParams {
    address arenaAddr; //The address for the arena contract
    BattleKey battleKey; //The battle Key containing a pool's specifications
    address oracleAddr; //The address for the oracle
    address cOracleAddr; //the contract address for a chainlink price feed
    Fee fee; // The fee structure for the battle
    address spear; //The address of the Spear tokens for a pool
    address shield; // The address of the Shield tokens for a pool
    address manager; //The address for the manager contract
    uint160 sqrtPriceX96; //The starting sqrt ratio when initiating a battle
}

File 42 of 61 : ModifyPositionParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { LiquidityType } from "core/types/enums.sol";

struct ModifyPositionParams {
    int24 tickLower; //The lower tick boundary of the position
    int24 tickUpper; //The upper tick boundary of the position
    LiquidityType liquidityType; //The chosen liquidity type can be Collateral, Spear, or Shield
    int128 liquidityDelta; //The change in liquidity
}

File 43 of 61 : UpdatePositionParams.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

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

struct UpdatePositionParams {
    ModifyPositionParams mpParams;
    int24 tick; //the current tick
}

File 44 of 61 : TickMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
library TickMath {
    error T();
    error R();

    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
    uint160 internal constant MIN_SQRT_RATIO = 4295128739;
    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;

    /// @notice Calculates sqrt(1.0001^tick) * 2^96
    /// @dev Throws if |tick| > max tick
    /// @param tick The input tick for the above formula
    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
    /// at the given tick
    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        unchecked {
            uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
            if (absTick > uint256(int256(MAX_TICK))) revert T();

            uint256 ratio = absTick & 0x1 != 0
                ? 0xfffcb933bd6fad37aa2d162d1a594001
                : 0x100000000000000000000000000000000;
            if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
            if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
            if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
            if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
            if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
            if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
            if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
            if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
            if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
            if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
            if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
            if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
            if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
            if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
            if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
            if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
            if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
            if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
            if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;

            if (tick > 0) ratio = type(uint256).max / ratio;

            // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
            // we then downcast because we know the result always fits within 160 bits due to our tick input constraint
            // we round up in the division so getTickAtSqrtRatio of the output price is always consistent
            sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
        }
    }

    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
    /// ever return.
    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        unchecked {
            // second inequality must be < because the price can never reach the price at the max tick
            if (!(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO)) revert R();
            uint256 ratio = uint256(sqrtPriceX96) << 32;

            uint256 r = ratio;
            uint256 msb = 0;

            assembly {
                let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(5, gt(r, 0xFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(4, gt(r, 0xFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(3, gt(r, 0xFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(2, gt(r, 0xF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(1, gt(r, 0x3))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := gt(r, 0x1)
                msb := or(msb, f)
            }

            if (msb >= 128) r = ratio >> (msb - 127);
            else r = ratio << (127 - msb);

            int256 log_2 = (int256(msb) - 128) << 64;

            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(63, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(62, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(61, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(60, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(59, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(58, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(57, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(56, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(55, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(54, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(53, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(52, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(51, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(50, f))
            }

            int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

            int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
            int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

            tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
        }
    }
}

File 45 of 61 : ITradeCallback.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { BattleKey } from "core/types/common.sol";
import { TradeType } from "core/types/enums.sol";

interface ITradeCallback {
    struct TradeCallbackData {
        address payer;
        BattleKey battleKey;
    }

    function tradeCallback(uint256 cAmount, uint256 sAmount, bytes calldata data) external;
}

File 46 of 61 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.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: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * 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 47 of 61 : 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 48 of 61 : 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 49 of 61 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

import "./math/Math.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

File 50 of 61 : 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 51 of 61 : 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 52 of 61 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

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

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 53 of 61 : SafeCast.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Safe casting methods
/// @notice Contains methods for safely casting between types
library SafeCast {
    /// @notice Cast a uint256 to a uint160, revert on overflow
    /// @param y The uint256 to be downcasted
    /// @return z The downcasted integer, now type uint160
    function toUint160(uint256 y) internal pure returns (uint160 z) {
        require((z = uint160(y)) == y);
    }

    /// @notice Cast a int256 to a int128, revert on overflow or underflow
    /// @param y The int256 to be downcasted
    /// @return z The downcasted integer, now type int128
    function toInt128(int256 y) internal pure returns (int128 z) {
        require((z = int128(y)) == y);
    }

    /// @notice Cast a uint256 to a int256, revert on overflow
    /// @param y The uint256 to be casted
    /// @return z The casted integer, now type int256
    function toInt256(uint256 y) internal pure returns (int256 z) {
        require(y < 2**255);
        z = int256(y);
    }
}

File 54 of 61 : UnsafeMath.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Math functions that do not check inputs or outputs
/// @notice Contains methods that perform common math functions but do not do any overflow or underflow checks
library UnsafeMath {
    /// @notice Returns ceil(x / y)
    /// @dev division by 0 has unspecified behavior, and must be checked externally
    /// @param x The dividend
    /// @param y The divisor
    /// @return z The quotient, ceil(x / y)
    function divRoundingUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
        assembly {
            z := add(div(x, y), gt(mod(x, y), 0))
        }
    }
}

File 55 of 61 : FixedPoint96.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.4.0;

/// @title FixedPoint96
/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)
/// @dev Used in SqrtPriceMath.sol
library FixedPoint96 {
    uint8 internal constant RESOLUTION = 96;
    uint256 internal constant Q96 = 0x1000000000000000000000000;
}

File 56 of 61 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 57 of 61 : LiquidityAmounts.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import '@uniswap/v3-core/contracts/libraries/FullMath.sol';
import '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol';

/// @title Liquidity amount functions
/// @notice Provides functions for computing liquidity amounts from token amounts and prices
library LiquidityAmounts {
    /// @notice Downcasts uint256 to uint128
    /// @param x The uint258 to be downcasted
    /// @return y The passed value, downcasted to uint128
    function toUint128(uint256 x) private pure returns (uint128 y) {
        require((y = uint128(x)) == x);
    }

    /// @notice Computes the amount of liquidity received for a given amount of token0 and price range
    /// @dev Calculates amount0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param amount0 The amount0 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount0(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        uint256 intermediate = FullMath.mulDiv(sqrtRatioAX96, sqrtRatioBX96, FixedPoint96.Q96);
        unchecked {
            return toUint128(FullMath.mulDiv(amount0, intermediate, sqrtRatioBX96 - sqrtRatioAX96));
        }
    }

    /// @notice Computes the amount of liquidity received for a given amount of token1 and price range
    /// @dev Calculates amount1 / (sqrt(upper) - sqrt(lower)).
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param amount1 The amount1 being sent in
    /// @return liquidity The amount of returned liquidity
    function getLiquidityForAmount1(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
        unchecked {
            return toUint128(FullMath.mulDiv(amount1, FixedPoint96.Q96, sqrtRatioBX96 - sqrtRatioAX96));
        }
    }

    /// @notice Computes the maximum amount of liquidity received for a given amount of token0, token1, the current
    /// pool prices and the prices at the tick boundaries
    /// @param sqrtRatioX96 A sqrt price representing the current pool prices
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param amount0 The amount of token0 being sent in
    /// @param amount1 The amount of token1 being sent in
    /// @return liquidity The maximum amount of liquidity received
    function getLiquidityForAmounts(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint256 amount0,
        uint256 amount1
    ) internal pure returns (uint128 liquidity) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            uint128 liquidity0 = getLiquidityForAmount0(sqrtRatioX96, sqrtRatioBX96, amount0);
            uint128 liquidity1 = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioX96, amount1);

            liquidity = liquidity0 < liquidity1 ? liquidity0 : liquidity1;
        } else {
            liquidity = getLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1);
        }
    }

    /// @notice Computes the amount of token0 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount0 The amount of token0
    function getAmount0ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0) {
        unchecked {
            if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

            return
                FullMath.mulDiv(
                    uint256(liquidity) << FixedPoint96.RESOLUTION,
                    sqrtRatioBX96 - sqrtRatioAX96,
                    sqrtRatioBX96
                ) / sqrtRatioAX96;
        }
    }

    /// @notice Computes the amount of token1 for a given amount of liquidity and a price range
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount1 The amount of token1
    function getAmount1ForLiquidity(
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        unchecked {
            return FullMath.mulDiv(liquidity, sqrtRatioBX96 - sqrtRatioAX96, FixedPoint96.Q96);
        }
    }

    /// @notice Computes the token0 and token1 value for a given amount of liquidity, the current
    /// pool prices and the prices at the tick boundaries
    /// @param sqrtRatioX96 A sqrt price representing the current pool prices
    /// @param sqrtRatioAX96 A sqrt price representing the first tick boundary
    /// @param sqrtRatioBX96 A sqrt price representing the second tick boundary
    /// @param liquidity The liquidity being valued
    /// @return amount0 The amount of token0
    /// @return amount1 The amount of token1
    function getAmountsForLiquidity(
        uint160 sqrtRatioX96,
        uint160 sqrtRatioAX96,
        uint160 sqrtRatioBX96,
        uint128 liquidity
    ) internal pure returns (uint256 amount0, uint256 amount1) {
        if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);

        if (sqrtRatioX96 <= sqrtRatioAX96) {
            amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
        } else if (sqrtRatioX96 < sqrtRatioBX96) {
            amount0 = getAmount0ForLiquidity(sqrtRatioX96, sqrtRatioBX96, liquidity);
            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioX96, liquidity);
        } else {
            amount1 = getAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
        }
    }
}

File 58 of 61 : TransferHelper.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;

import '@openzeppelin/contracts/token/ERC20/IERC20.sol';

library TransferHelper {
    /// @notice Transfers tokens from the targeted address to the given destination
    /// @notice Errors with 'STF' if transfer fails
    /// @param token The contract address of the token to be transferred
    /// @param from The originating address from which the tokens will be transferred
    /// @param to The destination address of the transfer
    /// @param value The amount to be transferred
    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value)
        );
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
    }

    /// @notice Transfers tokens from msg.sender to a recipient
    /// @dev Errors with ST if transfer fails
    /// @param token The contract address of the token which will be transferred
    /// @param to The recipient of the transfer
    /// @param value The value of the transfer
    function safeTransfer(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
    }

    /// @notice Approves the stipulated contract to spend the given allowance in the given token
    /// @dev Errors with 'SA' if transfer fails
    /// @param token The contract address of the token to be approved
    /// @param to The target of the approval
    /// @param value The amount of the given token the target will be allowed to spend
    function safeApprove(
        address token,
        address to,
        uint256 value
    ) internal {
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
    }

    /// @notice Transfers ETH to the recipient address
    /// @dev Fails with `STE`
    /// @param to The destination of the transfer
    /// @param value The value to be transferred
    function safeTransferETH(address to, uint256 value) internal {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(success, 'STE');
    }
}

File 59 of 61 : IWETH9.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.14;

import { IERC20 } from "@oz/token/ERC20/IERC20.sol";

interface IWETH9 is IERC20 {
    function deposit() external payable;

    function withdraw(uint256 amount) external;
}

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

pragma solidity ^0.8.0;

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

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

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

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

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
            // in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10**64) {
                value /= 10**64;
                result += 64;
            }
            if (value >= 10**32) {
                value /= 10**32;
                result += 32;
            }
            if (value >= 10**16) {
                value /= 10**16;
                result += 16;
            }
            if (value >= 10**8) {
                value /= 10**8;
                result += 8;
            }
            if (value >= 10**4) {
                value /= 10**4;
                result += 4;
            }
            if (value >= 10**2) {
                value /= 10**2;
                result += 2;
            }
            if (value >= 10**1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}

Settings
{
  "remappings": [
    "@std/=lib/forge-std/src/",
    "@oz/=lib/openzeppelin-contracts/contracts/",
    "@solmate/=lib/solmate/src/",
    "@diamond/=lib/diamond-3-hardhat/contracts/",
    "@solid/=lib/solidstate-solidity/contracts/",
    "@weth/=lib/canonical-weth/contracts/",
    "chainlink/=lib/chainlink/contracts/src/v0.8/",
    "@uniswap/=lib/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "core/=src/core/",
    "periphery/=src/periphery/",
    "test/=test/",
    "script/=script/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "solmate/=lib/solmate/src/",
    "v3-core/=lib/v3-core/contracts/",
    "v3-periphery/=lib/v3-periphery/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "libraries": {}
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_arena","type":"address"},{"internalType":"address","name":"_weth","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BattleEnd","type":"error"},{"inputs":[],"name":"BattleExisted","type":"error"},{"inputs":[],"name":"BattleNotEnd","type":"error"},{"inputs":[],"name":"BattleNotExist","type":"error"},{"inputs":[],"name":"Deadline","type":"error"},{"inputs":[],"name":"LiquidityNotAdded","type":"error"},{"inputs":[],"name":"LiquidityNotRemoved","type":"error"},{"inputs":[],"name":"NotWETH9","type":"error"},{"inputs":[],"name":"OnlyBattle","type":"error"},{"inputs":[],"name":"Slippage","type":"error"},{"inputs":[],"name":"T","type":"error"},{"inputs":[],"name":"TickInvalid","type":"error"},{"inputs":[],"name":"ZeroValue","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"approved","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"battleAddress","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"liquidity","type":"uint128"},{"indexed":false,"internalType":"enum LiquidityType","name":"liquidityType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"seedAmount","type":"uint256"}],"name":"LiquidityAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stokenAmount","type":"uint256"}],"name":"LiquidityRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"battle","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ObligationRedeemed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"battle","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ObligationWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"enum TradeType","name":"tradeType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"Traded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"collateral","type":"address"},{"internalType":"string","name":"underlying","type":"string"},{"internalType":"uint256","name":"expiries","type":"uint256"},{"internalType":"uint256","name":"strikeValue","type":"uint256"}],"internalType":"struct BattleKey","name":"battleKey","type":"tuple"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint160","name":"minSqrtPriceX96","type":"uint160"},{"internalType":"uint160","name":"maxSqrtPriceX96","type":"uint160"},{"internalType":"enum LiquidityType","name":"liquidityType","type":"uint8"},{"internalType":"uint128","name":"amount","type":"uint128"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct AddLiqParams","name":"params","type":"tuple"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint128","name":"liquidity","type":"uint128"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"arena","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"collateral","type":"address"},{"internalType":"string","name":"underlying","type":"string"},{"internalType":"uint256","name":"expiries","type":"uint256"},{"internalType":"uint256","name":"strikeValue","type":"uint256"}],"internalType":"struct BattleKey","name":"bk","type":"tuple"},{"internalType":"uint160","name":"sqrtPriceX96","type":"uint160"}],"internalType":"struct CreateAndInitBattleParams","name":"params","type":"tuple"}],"name":"createAndInitializeBattle","outputs":[{"internalType":"address","name":"battle","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountOwed","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"mintCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"positions","outputs":[{"components":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"address","name":"battleAddr","type":"address"},{"internalType":"int24","name":"tickLower","type":"int24"},{"internalType":"int24","name":"tickUpper","type":"int24"},{"internalType":"uint128","name":"liquidity","type":"uint128"},{"internalType":"enum LiquidityType","name":"liquidityType","type":"uint8"},{"internalType":"uint256","name":"seed","type":"uint256"},{"components":[{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256","name":"collateralIn","type":"uint256"},{"internalType":"uint256","name":"spearOut","type":"uint256"},{"internalType":"uint256","name":"shieldOut","type":"uint256"}],"internalType":"struct GrowthX128","name":"insideLast","type":"tuple"},{"components":[{"internalType":"uint128","name":"fee","type":"uint128"},{"internalType":"uint128","name":"collateralIn","type":"uint128"},{"internalType":"uint128","name":"spearOut","type":"uint128"},{"internalType":"uint128","name":"shieldOut","type":"uint128"}],"internalType":"struct Owed","name":"owed","type":"tuple"},{"internalType":"enum PositionState","name":"state","type":"uint8"},{"internalType":"uint256","name":"spearObligation","type":"uint256"},{"internalType":"uint256","name":"shieldObligation","type":"uint256"}],"internalType":"struct Position","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"redeemObligation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"removeLiquidity","outputs":[{"internalType":"uint256","name":"collateral","type":"uint256"},{"internalType":"uint256","name":"spear","type":"uint256"},{"internalType":"uint256","name":"shield","type":"uint256"},{"internalType":"uint256","name":"spearObligation","type":"uint256"},{"internalType":"uint256","name":"shieldObligation","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"collateral","type":"address"},{"internalType":"string","name":"underlying","type":"string"},{"internalType":"uint256","name":"expiries","type":"uint256"},{"internalType":"uint256","name":"strikeValue","type":"uint256"}],"internalType":"struct BattleKey","name":"battleKey","type":"tuple"},{"internalType":"enum TradeType","name":"tradeType","type":"uint8"},{"internalType":"int256","name":"amountSpecified","type":"int256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint160","name":"sqrtPriceLimitX96","type":"uint160"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct TradeParams","name":"p","type":"tuple"}],"name":"trade","outputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"cAmount","type":"uint256"},{"internalType":"uint256","name":"sAmount","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"tradeCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"withdrawObligation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60c06040523480156200001157600080fd5b5060405162005da038038062005da0833981016040819052620000349162000105565b818160405180606001604052806021815260200162005d7f6021913960408051808201909152600981526844495645522d504f5360b81b602082015260006200007e8382620001e2565b5060016200008d8282620001e2565b5050506001600160a01b0382161580620000ae57506001600160a01b038116155b15620000cd57604051637c946ed760e01b815260040160405180910390fd5b6001600160a01b039182166080521660a05250620002ae9050565b80516001600160a01b03811681146200010057600080fd5b919050565b600080604083850312156200011957600080fd5b6200012483620000e8565b91506200013460208401620000e8565b90509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200016857607f821691505b6020821081036200018957634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620001dd57600081815260208120601f850160051c81016020861015620001b85750805b601f850160051c820191505b81811015620001d957828155600101620001c4565b5050505b505050565b81516001600160401b03811115620001fe57620001fe6200013d565b62000216816200020f845462000153565b846200018f565b602080601f8311600181146200024e5760008415620002355750858301515b600019600386901b1c1916600185901b178555620001d9565b600085815260208120601f198616915b828110156200027f578886015182559484019460019091019084016200025e565b50858210156200029e5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b60805160a051615a656200031a600039600081816101d6015281816103d601528181612b2001528181612b660152612bfb01526000818161065d015281816108d301528181610c4801528181610cfb01528181610e570152818161102e01526131e70152615a656000f3fe6080604052600436106101c65760003560e01c80636352211e116100f7578063a22cb46511610095578063c87b56dd11610064578063c87b56dd146105e2578063e985e9c514610602578063fd3705f91461064b578063fde46ab01461067f57600080fd5b8063a22cb46514610538578063ac9650d814610558578063b402533f14610585578063b88d4fde146105c257600080fd5b8063894f9dbf116100d1578063894f9dbf1461048e57806395d89b41146104ae57806399fbab88146104c35780639c8f9f23146104f057600080fd5b80636352211e1461042e57806370a082311461044e5780638863b3e11461046e57600080fd5b80632e89815711610164578063467cc24e1161013e578063467cc24e146103a45780634aa4a4fc146103c45780634f6ccce7146103f857806361b8ce8c1461041857600080fd5b80632e898157146103445780632f745c591461036457806342842e0e1461038457600080fd5b8063095ea7b3116101a0578063095ea7b3146102aa57806314bc2ec1146102ca57806318160ddd1461030557806323b872dd1461032457600080fd5b806301ffc9a71461021b57806306fdde0314610250578063081812fc1461027257600080fd5b3661021657336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146102145760405163178e51ad60e11b815260040160405180910390fd5b005b600080fd5b34801561022757600080fd5b5061023b61023636600461477a565b61069f565b60405190151581526020015b60405180910390f35b34801561025c57600080fd5b506102656106ca565b60405161024791906147e7565b34801561027e57600080fd5b5061029261028d3660046147fa565b61075c565b6040516001600160a01b039091168152602001610247565b3480156102b657600080fd5b506102146102c5366004614833565b610783565b3480156102d657600080fd5b506102ea6102e536600461485f565b61089d565b60408051938452602084019290925290820152606001610247565b34801561031157600080fd5b506008545b604051908152602001610247565b34801561033057600080fd5b5061021461033f366004614899565b610c0b565b34801561035057600080fd5b5061029261035f3660046148da565b610c3c565b34801561037057600080fd5b5061031661037f366004614833565b610d91565b34801561039057600080fd5b5061021461039f366004614899565b610e27565b3480156103b057600080fd5b506102146103bf36600461495c565b610e42565b3480156103d057600080fd5b506102927f000000000000000000000000000000000000000000000000000000000000000081565b34801561040457600080fd5b506103166104133660046147fa565b610ea0565b34801561042457600080fd5b50610316600a5481565b34801561043a57600080fd5b506102926104493660046147fa565b610f33565b34801561045a57600080fd5b506103166104693660046149a7565b610f93565b34801561047a57600080fd5b506102146104893660046149c4565b611019565b34801561049a57600080fd5b506102146104a93660046147fa565b611072565b3480156104ba57600080fd5b50610265611556565b3480156104cf57600080fd5b506104e36104de3660046147fa565b611565565b6040516102479190614a50565b3480156104fc57600080fd5b5061051061050b3660046147fa565b6116e7565b604080519586526020860194909452928401919091526060830152608082015260a001610247565b34801561054457600080fd5b50610214610553366004614b90565b611d1c565b34801561056457600080fd5b50610578610573366004614bc9565b611d2b565b6040516102479190614c3d565b34801561059157600080fd5b506105a56105a0366004614c9f565b611e1f565b604080519283526001600160801b03909116602083015201610247565b3480156105ce57600080fd5b506102146105dd366004614dd2565b61225e565b3480156105ee57600080fd5b506102656105fd3660046147fa565b612290565b34801561060e57600080fd5b5061023b61061d366004614e51565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561065757600080fd5b506102927f000000000000000000000000000000000000000000000000000000000000000081565b34801561068b57600080fd5b5061021461069a3660046147fa565b612304565b60006001600160e01b0319821663780e9d6360e01b14806106c457506106c4826126c6565b92915050565b6060600080546106d990614e7f565b80601f016020809104026020016040519081016040528092919081815260200182805461070590614e7f565b80156107525780601f1061072757610100808354040283529160200191610752565b820191906000526020600020905b81548152906001019060200180831161073557829003601f168201915b5050505050905090565b600061076782612716565b506000908152600460205260409020546001600160a01b031690565b600061078e82610f33565b9050806001600160a01b0316836001600160a01b0316036108005760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084015b60405180910390fd5b336001600160a01b038216148061081c575061081c813361061d565b61088e5760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c00000060648201526084016107f7565b6108988383612778565b505050565b60008060008360c001354211156108c75760405163637910d560e11b815260040160405180910390fd5b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663809e93306109028780614eb9565b6040518263ffffffff1660e01b815260040161091e9190614f7c565b602060405180830381865afa15801561093b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095f9190614f8f565b90506001600160a01b038116610988576040516379e9ddf360e01b815260040160405180910390fd5b6109b96040805160a08101909152600080825260208201908152600060208201819052604082015260609081015290565b6109c960808701606088016149a7565b6001600160a01b031681526109e46040870160208801614fac565b816020019060018111156109fa576109fa614a16565b90816001811115610a0d57610a0d614a16565b90525060408087013582820152805180820190915233815260208101610a338880614eb9565b610a3c9061504f565b9052604051610a4e91906020016150a2565b60408051601f198184030181529190526080820152610a7360c0870160a088016149a7565b6001600160a01b0316600003610aed576000610a956040880160208901614fac565b6001811115610aa657610aa6614a16565b03610ad557610ac26b19bac7780d08f3ad7f0af7b560016150e5565b6001600160a01b03166060820152610b0c565b610ac260016c09f31acbab516e399f503dcc48615105565b610afd60c0870160a088016149a7565b6001600160a01b031660608201525b6040516320787ae360e01b81526001600160a01b038316906320787ae390610b38908490600401615135565b6060604051808303816000875af1158015610b57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b7b919061518d565b919650945092506080860135841015610ba7576040516307dd37f760e41b815260040160405180910390fd5b7f50cc78f0928389fe9467f4bb28e9b1e34608a464156b89bf64789a8ac9c60097610bd860808801606089016149a7565b610be86040890160208a01614fac565b8787604051610bfa94939291906151bb565b60405180910390a150509193909250565b610c1533826127e6565b610c315760405162461bcd60e51b81526004016107f7906151ea565b610898838383612865565b60006001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001663809e9330610c778480614eb9565b6040518263ffffffff1660e01b8152600401610c939190614f7c565b602060405180830381865afa158015610cb0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd49190614f8f565b90506001600160a01b038116610d735760405163d1d2d73b60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063d1d2d73b90610d30908590600401615237565b6020604051808303816000875af1158015610d4f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106c49190614f8f565b60405163f264a77960e01b815260040160405180910390fd5b919050565b6000610d9c83610f93565b8210610dfe5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016107f7565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b6108988383836040518060200160405280600081525061225e565b6000610e5082840184615290565b9050610e807f000000000000000000000000000000000000000000000000000000000000000082600001516129d6565b8315610e9a57610e9a816020015182604001513387612b1e565b50505050565b6000610eab60085490565b8210610f0e5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b60648201526084016107f7565b60088281548110610f2157610f2161533f565b90600052602060002001549050919050565b6000818152600260205260408120546001600160a01b0316806106c45760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b60448201526064016107f7565b60006001600160a01b038216610ffd5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b60648201526084016107f7565b506001600160a01b031660009081526003602052604090205490565b600061102782840184615355565b90506110577f000000000000000000000000000000000000000000000000000000000000000082602001516129d6565b602081015151815161106b91903388612b1e565b5050505050565b8061107d33826127e6565b6110995760405162461bcd60e51b81526004016107f7906153d4565b6000828152600b602090815260408083208151610180810183528154815260018201546001600160a01b03811694820194909452600160a01b8404600290810b93820193909352600160b81b909304820b6060840152818101546001600160801b0381166080850152909160a0840191600160801b900460ff169081111561112357611123614a16565b600281111561113457611134614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff16908111156111e0576111e0614a16565b60038111156111f1576111f1614a16565b8152600b8201546020820152600c9091015460409091015290506001816101200151600381111561122457611224614a16565b146112425760405163617e154d60e11b815260040160405180910390fd5b600081602001516001600160a01b03166361147e116040518163ffffffff1660e01b8152600401602060405180830381865afa158015611286573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112aa9190615407565b905060008160028111156112c0576112c0614a16565b146112de5760405163e8a6f8cf60e01b815260040160405180910390fd5b81610160015182610140015114610e9a5760008083610160015184610140015111611384578361014001518461016001516113199190615424565b84602001516001600160a01b03166370d39cff6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561135b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137f9190614f8f565b611400565b83610160015184610140015161139a9190615424565b84602001516001600160a01b03166398dfe4786040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114009190614f8f565b60405163079cc67960e41b81523360048201526024810183905291935091506001600160a01b038216906379cc679090604401600060405180830381600087803b15801561144d57600080fd5b505af1158015611461573d6000803e3d6000fd5b5050505083602001516001600160a01b031663d515de2b61148188610f33565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101859052604401600060405180830381600087803b1580156114c957600080fd5b505af11580156114dd573d6000803e3d6000fd5b5050506000878152600b6020908152604091829020600a01805460ff191660031790558681015182516001600160a01b0390911681529081018990529081018490527f2e4ce7434a1b88a268fdfe83e7c395e73be3ad6efab0b4772ff62a446a33861291506060015b60405180910390a1505050505050565b6060600180546106d990614e7f565b61156d6146ba565b6000828152600b60209081526040918290208251610180810184528154815260018201546001600160a01b03811693820193909352600160a01b8304600290810b94820194909452600160b81b909204830b6060830152828101546001600160801b03811660808401529192909160a0840191600160801b90910460ff16908111156115fb576115fb614a16565b600281111561160c5761160c614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff16908111156116b8576116b8614a16565b60038111156116c9576116c9614a16565b8152600b8201546020820152600c9091015460409091015292915050565b6000806000806000856116fa33826127e6565b6117165760405162461bcd60e51b81526004016107f7906153d4565b6000878152600b602090815260408083208151610180810183528154815260018201546001600160a01b03811694820194909452600160a01b8404600290810b93820193909352600160b81b909304820b6060840152818101546001600160801b0381166080850152909160a0840191600160801b900460ff16908111156117a0576117a0614a16565b60028111156117b1576117b1614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff169081111561185d5761185d614a16565b600381111561186e5761186e614a16565b8152600b8201546020820152600c909101546040909101529050600081610120015160038111156118a1576118a1614a16565b146118bf5760405163027b886560e61b815260040160405180910390fd5b6040805160808101825260008082526020820181815282840182815260608085019390935293850151600290810b845291850151820b905260a08401519192919081111561190f5761190f614a16565b9081600281111561192257611922614a16565b90525060808201516001600160801b0316606082015260208201516040516342e392e160e01b81526001600160a01b03909116906342e392e19061196a908490600401615437565b600060405180830381600087803b15801561198457600080fd5b505af1158015611998573d6000803e3d6000fd5b50505050600082602001516001600160a01b031663514ea4bf30856040015186606001516040516020016119f79392919060609390931b6bffffffffffffffffffffffff1916835260e891821b6014840152901b6017820152601a0190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b8152600401611a2b91815260200190565b60a060405180830381865afa158015611a48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a6c9190615492565b60008b8152600b60205260409020909150611a878282612c7e565b60408051610180810182528254815260018301546001600160a01b0381166020830152600160a01b8104600290810b93830193909352600160b81b9004820b6060820152818301546001600160801b0381166080830152611bef92849160a0840191600160801b90910460ff1690811115611b0457611b04614a16565b6002811115611b1557611b15614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff1690811115611bc157611bc1614a16565b6003811115611bd257611bd2614a16565b8152602001600b8201548152602001600c82015481525050612de2565b6008860154949e50929c50909a5098509650611c14906001600160801b03168b61550c565b600a8201805460ff19166001179055600b8201889055600c82018790556020850151909a506001600160a01b031663214f220f611c508d610f33565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018d9052604481018c9052606481018b9052608401600060405180830381600087803b158015611ca657600080fd5b505af1158015611cba573d6000803e3d6000fd5b505050507f0bb89aa54ed6940a7e7167bd262b2400d63945045ceff1a52a05f2601ed215f18b8b8a8c11611cee578a611cf0565b8b5b6040805193845260208401929092529082015260600160405180910390a1505050505091939590929450565b611d273383836130d6565b5050565b6060816001600160401b03811115611d4557611d45614cda565b604051908082528060200260200182016040528015611d7857816020015b6060815260200190600190039081611d635790505b50905060005b82811015611e1857611de830858584818110611d9c57611d9c61533f565b9050602002810190611dae919061551f565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506131a492505050565b828281518110611dfa57611dfa61533f565b60200260200101819052508080611e1090615565565b915050611d7e565b5092915050565b600080826101000135421115611e485760405163637910d560e11b815260040160405180910390fd5b6000611e5b611e56856155ae565b6131c9565b600a5494509092509050600030611e786060870160408801615677565b611e886080880160608901615677565b60405160609390931b6bffffffffffffffffffffffff1916602084015260e891821b6034840152901b6037820152603a01604051602081830303815290604052805190602001209050604051806101800160405280858152602001836001600160a01b03168152602001866040016020810190611f059190615677565b60020b8152602001611f1d6080880160608901615677565b60020b81526001600160801b0385166020820152604001611f4460e0880160c08901615694565b6002811115611f5557611f55614a16565b8152602001611f6b610100880160e089016156b1565b6001600160801b03168152602001836001600160a01b031663514ea4bf846040518263ffffffff1660e01b8152600401611fa791815260200190565b60a060405180830381865afa158015611fc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fe89190615492565b602090810151825260408051608080820183526000808352828501819052828401819052606080840182905286860193909352838601819052828601819052948101859052898552600b8452938290208551815592850151600184018054938701519287015162ffffff908116600160b81b0262ffffff60b81b1991909416600160a01b026001600160b81b03199095166001600160a01b0390931692909217939093171617905590820151600280830180546001600160801b039093166001600160801b031984168117825560a086015193919270ffffffffffffffffffffffffffffffffff199092161790600160801b9084908111156120ec576120ec614a16565b021790555060c082015160038281019190915560e0830151805160048401556020808201516005850155604080830151600686015560609283015160078601556101008601518051928101516001600160801b03938416600160801b9185168202176008880155918101519301519282169290911602176009830155610120830151600a830180549192909160ff191690600190849081111561219157612191614a16565b0217905550610140820151600b82015561016090910151600c90910155600a80549060006121be83615565565b909155506121d4905060408601602087016149a7565b6001600160a01b039081169083167f188615b8442f352b1f90be554f1b252160678fb2b17db63385a405ae1da5ef10868661221560e08b0160c08c01615694565b6122266101008c0160e08d016156b1565b60405161223694939291906156ce565b60405180910390a361225761225160408701602088016149a7565b85613611565b5050915091565b61226833836127e6565b6122845760405162461bcd60e51b81526004016107f7906151ea565b610e9a8484848461362b565b606061229b82612716565b60006122b260408051602081019091526000815290565b905060008151116122d257604051806020016040528060008152506122fd565b806122dc8461365e565b6040516020016122ed929190615705565b6040516020818303038152906040525b9392505050565b8061230f33826127e6565b61232b5760405162461bcd60e51b81526004016107f7906153d4565b6000828152600b602090815260408083208151610180810183528154815260018201546001600160a01b03811694820194909452600160a01b8404600290810b93820193909352600160b81b909304820b6060840152818101546001600160801b0381166080850152909160a0840191600160801b900460ff16908111156123b5576123b5614a16565b60028111156123c6576123c6614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff169081111561247257612472614a16565b600381111561248357612483614a16565b8152600b8201546020820152600c909101546040909101529050600181610120015160038111156124b6576124b6614a16565b146124d45760405163617e154d60e11b815260040160405180910390fd5b600081602001516001600160a01b03166361147e116040518163ffffffff1660e01b8152600401602060405180830381865afa158015612518573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061253c9190615407565b6101608301516101408401519192501160008083600281111561256157612561614a16565b0361257f5760405163c224a1d960e01b815260040160405180910390fd5b600183600281111561259357612593614a16565b036125bc5781156125b7578361014001518461016001516125b49190615424565b90505b6125da565b816125da578361016001518461014001516125d79190615424565b90505b801561265d5783602001516001600160a01b031663d515de2b6125fc88610f33565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b15801561264457600080fd5b505af1158015612658573d6000803e3d6000fd5b505050505b6000868152600b6020908152604091829020600a01805460ff191660021790558581015182516001600160a01b0390911681529081018890529081018290527f5162053cd26656b4db1c058010055f8c67f02bb69c7097d8f5e032c55a66a31090606001611546565b60006001600160e01b031982166380ac58cd60e01b14806126f757506001600160e01b03198216635b5e139f60e01b145b806106c457506301ffc9a760e01b6001600160e01b03198316146106c4565b6000818152600260205260409020546001600160a01b03166127755760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b60448201526064016107f7565b50565b600081815260046020526040902080546001600160a01b0319166001600160a01b03841690811790915581906127ad82610f33565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000806127f283610f33565b9050806001600160a01b0316846001600160a01b0316148061283957506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b8061285d5750836001600160a01b03166128528461075c565b6001600160a01b0316145b949350505050565b826001600160a01b031661287882610f33565b6001600160a01b03161461289e5760405162461bcd60e51b81526004016107f790615734565b6001600160a01b0382166129005760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016107f7565b61290d83838360016136f0565b826001600160a01b031661292082610f33565b6001600160a01b0316146129465760405162461bcd60e51b81526004016107f790615734565b600081815260046020908152604080832080546001600160a01b03199081169091556001600160a01b0387811680865260038552838620805460001901905590871680865283862080546001019055868652600290945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b604051630809e93360e41b815233906001600160a01b0384169063809e933090612a04908590600401615779565b602060405180830381865afa158015612a21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a459190614f8f565b6001600160a01b031614612a885760405162461bcd60e51b815260206004820152600a6024820152696f6e6c79426174746c6560b01b60448201526064016107f7565b604051630809e93360e41b815233906001600160a01b0384169063809e933090612ab6908590600401615779565b602060405180830381865afa158015612ad3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612af79190614f8f565b6001600160a01b031614611d2757604051631dd6046560e31b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316846001600160a01b0316148015612b5f5750804710155b15612c72577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015612bbf57600080fd5b505af1158015612bd3573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038681166004830152602482018690527f000000000000000000000000000000000000000000000000000000000000000016935063a9059cbb925060440190506020604051808303816000875af1158015612c48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c6c919061578c565b50610e9a565b610e9a8484848461381d565b60048101546020830151516002830154612ca992909103906001600160801b0316600160801b613927565b6008820180546001600160801b0380821690930183166001600160801b0319909116179055600582015460208085015101516002840154612cf493929091039116600160801b613927565b6008820180546001600160801b03600160801b8083048216909401811684029181169190911790915560068301546020850151604001516002850154612d409492909103921690613927565b6009820180546001600160801b0380821690930183166001600160801b031990911617905560078201546020840151606001516002840154612d8c93929091039116600160801b613927565b6009820180546001600160801b03600160801b8083048216909401811690930292169190911790556020918201518051600483015591820151600582015560408201516006820155606090910151600790910155565b600080808080808660a001516002811115612dff57612dff614a16565b03612ea857505061010084015160408101516060909101516001600160801b0391821691166000818311612e335781612e35565b825b9050808760c00151886101000151602001516001600160801b0316612e5a919061550c565b14612e9d576001818860c00151896101000151602001516001600160801b0316612e84919061550c565b612e8e9190615424565b612e989190615424565b612ea0565b60005b9550506130cd565b60018660a001516002811115612ec057612ec0614a16565b03612fcb578560c00151866101000151604001516001600160801b031611612ee9576000612f0b565b8560c00151866101000151604001516001600160801b0316612f0b9190615424565b9150856101000151606001516001600160801b031690506000818311612f315781612f33565b825b905080876101000151602001516001600160801b031614612f7d57600181886101000151602001516001600160801b0316612f6e9190615424565b612f789190615424565b612f80565b60005b9550866101000151604001516001600160801b03168760c001511115612fc557866101000151604001516001600160801b03168760c00151612fc29190615424565b94505b506130cd565b856101000151604001516001600160801b031691508560c00151866101000151606001516001600160801b031611613004576000613026565b8560c00151866101000151606001516001600160801b03166130269190615424565b905060008183116130375781613039565b825b905080876101000151602001516001600160801b03161461308357600181886101000151602001516001600160801b03166130749190615424565b61307e9190615424565b613086565b60005b9550866101000151606001516001600160801b03168760c0015111156130cb57866101000151606001516001600160801b03168760c001516130c89190615424565b93505b505b91939590929450565b816001600160a01b0316836001600160a01b0316036131375760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016107f7565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b60606122fd8383604051806060016040528060278152602001615a09602791396139d9565b8051604051630809e93360e41b815260009182916001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163809e93309161321b9190600401615779565b602060405180830381865afa158015613238573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061325c9190614f8f565b90506001600160a01b038116613285576040516379e9ddf360e01b815260040160405180910390fd5b6000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b8152600401606060405180830381865afa1580156132c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132e991906157a9565b5050905083608001516001600160a01b0316816001600160a01b0316108061332657508360a001516001600160a01b0316816001600160a01b0316115b15613344576040516307dd37f760e41b815260040160405180910390fd5b60008460c00151600281111561335c5761335c614a16565b0361339957613392816133728660400151613a51565b61337f8760600151613a51565b8760e001516001600160801b0316613a96565b92506133cc565b6133c96133a98560400151613a51565b6133b68660600151613a51565b8660e001516001600160801b0316613bc7565b92505b6000808560c0015160028111156133e5576133e5614a16565b036133f357508351516134e5565b60018560c00151600281111561340b5761340b614a16565b0361347d576000836001600160a01b031663af0923be6040518163ffffffff1660e01b81526004016040805180830381865afa15801561344f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061347391906157f6565b5091506134e59050565b6000836001600160a01b031663af0923be6040518163ffffffff1660e01b81526004016040805180830381865afa1580156134bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134e091906157f6565b925050505b826001600160a01b031663c1c816636040518060e0016040528088602001516001600160a01b03168152602001886040015160020b8152602001886060015160020b81526020018860c00151600281111561354257613542614a16565b8152602001876001600160801b031681526020018860e001516001600160801b0316815260200160405180606001604052808a600001518152602001866001600160a01b03168152602001336001600160a01b03168152506040516020016135aa9190615825565b6040516020818303038152906040528152506040518263ffffffff1660e01b81526004016135d89190615871565b600060405180830381600087803b1580156135f257600080fd5b505af1158015613606573d6000803e3d6000fd5b505050505050915091565b611d27828260405180602001604052806000815250613c5f565b613636848484612865565b61364284848484613c92565b610e9a5760405162461bcd60e51b81526004016107f7906158ef565b6060600061366b83613d90565b60010190506000816001600160401b0381111561368a5761368a614cda565b6040519080825280601f01601f1916602001820160405280156136b4576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846136be57509392505050565b600181111561375f5760405162461bcd60e51b815260206004820152603560248201527f455243373231456e756d657261626c653a20636f6e7365637574697665207472604482015274185b9cd9995c9cc81b9bdd081cdd5c1c1bdc9d1959605a1b60648201526084016107f7565b816001600160a01b0385166137bb576137b681600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b6137de565b836001600160a01b0316856001600160a01b0316146137de576137de8582613e68565b6001600160a01b0384166137fa576137f581613f05565b61106b565b846001600160a01b0316846001600160a01b03161461106b5761106b8482613fb4565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17905291516000928392908816916138819190615957565b6000604051808303816000865af19150503d80600081146138be576040519150601f19603f3d011682016040523d82523d6000602084013e6138c3565b606091505b50915091508180156138ed5750805115806138ed5750808060200190518101906138ed919061578c565b61391f5760405162461bcd60e51b815260206004820152600360248201526229aa2360e91b60448201526064016107f7565b505050505050565b6000808060001985870985870292508281108382030391505080600003613960576000841161395557600080fd5b5082900490506122fd565b80841161396c57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6060600080856001600160a01b0316856040516139f69190615957565b600060405180830381855af49150503d8060008114613a31576040519150601f19603f3d011682016040523d82523d6000602084013e613a36565b606091505b5091509150613a4786838387613ff8565b9695505050505050565b600061b38019600283900b12801590613a70575061b381600283900b13155b613a8d5760405163e7ec280d60e01b815260040160405180910390fd5b6106c482614071565b6000826001600160a01b0316846001600160a01b03161115613ab6579192915b836001600160a01b0316856001600160a01b031611613ae157613ada848484614394565b905061285d565b826001600160a01b0316856001600160a01b03161015613bb3576000613b1e866001600160a01b0316856001600160a01b0316600160601b6143f7565b905060006001600160a01b03808816908616613b51613b3d898b615105565b6001600160a01b031685600160601b6143f7565b613b5b919061550c565b613b659190615424565b90506000613b8a886001600160a01b0316876001600160a01b0316600160601b613927565b9050613ba9613ba4613b9c8388615969565b600185613927565b614437565b935050505061285d565b613bbe8484846144a4565b95945050505050565b6000826001600160a01b0316846001600160a01b03161115613be7579192915b6000613c0a856001600160a01b0316856001600160a01b0316600160601b613927565b9050613bbe613c1d82600160601b61550c565b613c55613c336001600160a01b03891687615969565b6001600160a01b038816613c478a8a615105565b6001600160a01b0316613927565b613ba49190615980565b613c6983836144e1565b613c766000848484613c92565b6108985760405162461bcd60e51b81526004016107f7906158ef565b60006001600160a01b0384163b15613d8857604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290613cd69033908990889088906004016159a2565b6020604051808303816000875af1925050508015613d11575060408051601f3d908101601f19168201909252613d0e918101906159d5565b60015b613d6e573d808015613d3f576040519150601f19603f3d011682016040523d82523d6000602084013e613d44565b606091505b508051600003613d665760405162461bcd60e51b81526004016107f7906158ef565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061285d565b50600161285d565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310613dcf5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310613dfb576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310613e1957662386f26fc10000830492506010015b6305f5e1008310613e31576305f5e100830492506008015b6127108310613e4557612710830492506004015b60648310613e57576064830492506002015b600a83106106c45760010192915050565b60006001613e7584610f93565b613e7f9190615424565b600083815260076020526040902054909150808214613ed2576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090613f1790600190615424565b60008381526009602052604081205460088054939450909284908110613f3f57613f3f61533f565b906000526020600020015490508060088381548110613f6057613f6061533f565b6000918252602080832090910192909255828152600990915260408082208490558582528120556008805480613f9857613f986159f2565b6001900381819060005260206000200160009055905550505050565b6000613fbf83610f93565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b60608315614067578251600003614060576001600160a01b0385163b6140605760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016107f7565b508161285d565b61285d838361467a565b60008060008360020b12614088578260020b614090565b8260020b6000035b9050620d89e88111156140b6576040516315e4079d60e11b815260040160405180910390fd5b6000816001166000036140cd57600160801b6140df565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615614113576ffff97272373d413259a46990580e213a0260801c5b6004821615614132576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615614151576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615614170576fffcb9843d60f6159c9db58835c9266440260801c5b602082161561418f576fff973b41fa98c081472e6896dfb254c00260801c5b60408216156141ae576fff2ea16466c96a3843ec78b326b528610260801c5b60808216156141cd576ffe5dee046a99a2a811c461f1969c30530260801c5b6101008216156141ed576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b61020082161561420d576ff987a7253ac413176f2b074cf7815e540260801c5b61040082161561422d576ff3392b0822b70005940c7a398e4b70f30260801c5b61080082161561424d576fe7159475a2c29b7443b29c7fa6e889d90260801c5b61100082161561426d576fd097f3bdfd2022b8845ad8f792aa58250260801c5b61200082161561428d576fa9f746462d870fdf8a65dc1f90e061e50260801c5b6140008216156142ad576f70d869a156d2a1b890bb3df62baf32f70260801c5b6180008216156142cd576f31be135f97d08fd981231505542fcfa60260801c5b620100008216156142ee576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b6202000082161561430e576e5d6af8dedb81196699c329225ee6040260801c5b6204000082161561432d576d2216e584f5fa1ea926041bedfe980260801c5b6208000082161561434a576b048a170391f7dc42444e8fa20260801c5b60008460020b131561436b57806000198161436757614367615941565b0490505b64010000000081061561437f576001614382565b60005b60ff16602082901c0192505050919050565b6000826001600160a01b0316846001600160a01b031611156143b4579192915b60006143d7856001600160a01b0316856001600160a01b0316600160601b613927565b9050613bbe6143f284838888036001600160a01b0316613927565b6146a4565b6000614404848484613927565b90506000828061441657614416615941565b84860911156122fd57600019811061442d57600080fd5b6001019392505050565b60006001600160801b038211156144a05760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b60648201526084016107f7565b5090565b6000826001600160a01b0316846001600160a01b031611156144c4579192915b61285d6143f283600160601b8787036001600160a01b0316613927565b6001600160a01b0382166145375760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016107f7565b6000818152600260205260409020546001600160a01b03161561459c5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016107f7565b6145aa6000838360016136f0565b6000818152600260205260409020546001600160a01b03161561460f5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016107f7565b6001600160a01b038216600081815260036020908152604080832080546001019055848352600290915280822080546001600160a01b0319168417905551839291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b81511561468a5781518083602001fd5b8060405162461bcd60e51b81526004016107f791906147e7565b806001600160801b0381168114610d8c57600080fd5b604080516101808101825260008082526020820181905291810182905260608101829052608081018290529060a08201908152602001600081526020016147226040518060800160405280600081526020016000815260200160008152602001600081525090565b81526040805160808101825260008082526020828101829052928201819052606082015291019081526020016000815260200160008152602001600081525090565b6001600160e01b03198116811461277557600080fd5b60006020828403121561478c57600080fd5b81356122fd81614764565b60005b838110156147b257818101518382015260200161479a565b50506000910152565b600081518084526147d3816020860160208601614797565b601f01601f19169290920160200192915050565b6020815260006122fd60208301846147bb565b60006020828403121561480c57600080fd5b5035919050565b6001600160a01b038116811461277557600080fd5b8035610d8c81614813565b6000806040838503121561484657600080fd5b823561485181614813565b946020939093013593505050565b60006020828403121561487157600080fd5b81356001600160401b0381111561488757600080fd5b820160e081850312156122fd57600080fd5b6000806000606084860312156148ae57600080fd5b83356148b981614813565b925060208401356148c981614813565b929592945050506040919091013590565b6000602082840312156148ec57600080fd5b81356001600160401b0381111561490257600080fd5b8201604081850312156122fd57600080fd5b60008083601f84011261492657600080fd5b5081356001600160401b0381111561493d57600080fd5b60208301915083602082850101111561495557600080fd5b9250929050565b60008060006040848603121561497157600080fd5b8335925060208401356001600160401b0381111561498e57600080fd5b61499a86828701614914565b9497909650939450505050565b6000602082840312156149b957600080fd5b81356122fd81614813565b600080600080606085870312156149da57600080fd5b843593506020850135925060408501356001600160401b038111156149fe57600080fd5b614a0a87828801614914565b95989497509550505050565b634e487b7160e01b600052602160045260246000fd5b60038110614a3c57614a3c614a16565b9052565b60048110614a3c57614a3c614a16565b81518152602080830151610240830191614a74908401826001600160a01b03169052565b506040830151614a89604084018260020b9052565b506060830151614a9e606084018260020b9052565b506080830151614ab960808401826001600160801b03169052565b5060a0830151614acc60a0840182614a2c565b5060c083015160c083015260e0830151614b0a60e0840182805182526020810151602083015260408101516040830152606081015160608301525050565b50610100830151610160614b4e8185018380516001600160801b03908116835260208083015182169084015260408083015182169084015260609182015116910152565b6101208501519150614b646101e0850183614a40565b61014085015161020085015280850151610220850152505092915050565b801515811461277557600080fd5b60008060408385031215614ba357600080fd5b8235614bae81614813565b91506020830135614bbe81614b82565b809150509250929050565b60008060208385031215614bdc57600080fd5b82356001600160401b0380821115614bf357600080fd5b818501915085601f830112614c0757600080fd5b813581811115614c1657600080fd5b8660208260051b8501011115614c2b57600080fd5b60209290920196919550909350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015614c9257603f19888603018452614c808583516147bb565b94509285019290850190600101614c64565b5092979650505050505050565b600060208284031215614cb157600080fd5b81356001600160401b03811115614cc757600080fd5b820161012081850312156122fd57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b0381118282101715614d1257614d12614cda565b60405290565b604080519081016001600160401b0381118282101715614d1257614d12614cda565b60405161012081016001600160401b0381118282101715614d1257614d12614cda565b60006001600160401b0380841115614d7757614d77614cda565b604051601f8501601f19908116603f01168101908282118183101715614d9f57614d9f614cda565b81604052809350858152868686011115614db857600080fd5b858560208301376000602087830101525050509392505050565b60008060008060808587031215614de857600080fd5b8435614df381614813565b93506020850135614e0381614813565b92506040850135915060608501356001600160401b03811115614e2557600080fd5b8501601f81018713614e3657600080fd5b614e4587823560208401614d5d565b91505092959194509250565b60008060408385031215614e6457600080fd5b8235614e6f81614813565b91506020830135614bbe81614813565b600181811c90821680614e9357607f821691505b602082108103614eb357634e487b7160e01b600052602260045260246000fd5b50919050565b60008235607e19833603018112614ecf57600080fd5b9190910192915050565b60008135614ee681614813565b6001600160a01b03168352602082013536839003601e19018112614f0957600080fd5b82016020810190356001600160401b03811115614f2557600080fd5b803603821315614f3457600080fd5b60806020860152806080860152808260a0870137600060a08287010152604084013560408601526060840135606086015260a0601f19601f8301168601019250505092915050565b6020815260006122fd6020830184614ed9565b600060208284031215614fa157600080fd5b81516122fd81614813565b600060208284031215614fbe57600080fd5b8135600281106122fd57600080fd5b600060808284031215614fdf57600080fd5b614fe7614cf0565b90508135614ff481614813565b815260208201356001600160401b0381111561500f57600080fd5b8201601f8101841361502057600080fd5b61502f84823560208401614d5d565b602083015250604082013560408201526060820135606082015292915050565b60006106c43683614fcd565b60018060a01b038151168252600060208201516080602085015261508260808501826147bb565b905060408301516040850152606083015160608501528091505092915050565b602080825282516001600160a01b03168282015282015160408083015260009061285d606084018261505b565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03818116838216019080821115611e1857611e186150cf565b6001600160a01b03828116828216039080821115611e1857611e186150cf565b60028110614a3c57614a3c614a16565b60208152600060018060a01b03808451166020840152602084015161515d6040850182615125565b506040840151606084015280606085015116608084015250608083015160a08084015261285d60c08401826147bb565b6000806000606084860312156151a257600080fd5b8351925060208401519150604084015190509250925092565b6001600160a01b0385168152608081016151d86020830186615125565b60408201939093526060015292915050565b6020808252602d908201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560408201526c1c881bdc88185c1c1c9bdd9959609a1b606082015260800190565b6020815260008235607e1984360301811261525157600080fd5b6040602084015261526760608401858301614ed9565b9050602084013561527781614813565b6001600160a01b03166040939093019290925250919050565b6000602082840312156152a257600080fd5b81356001600160401b03808211156152b957600080fd5b90830190606082860312156152cd57600080fd5b6040516060810181811083821117156152e8576152e8614cda565b6040528235828111156152fa57600080fd5b61530687828601614fcd565b8252506020830135915061531982614813565b8160208201526040830135925061532f83614813565b6040810192909252509392505050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561536757600080fd5b81356001600160401b038082111561537e57600080fd5b908301906040828603121561539257600080fd5b61539a614d18565b82356153a581614813565b81526020830135828111156153b957600080fd5b6153c587828601614fcd565b60208301525095945050505050565b6020808252600c908201526b139bdd08185c1c1c9bdd995960a21b604082015260600190565b6003811061277557600080fd5b60006020828403121561541957600080fd5b81516122fd816153fa565b818103818111156106c4576106c46150cf565b6000608082019050825160020b8252602083015160020b602083015260408301516154656040840182614a2c565b506060928301516001600160801b0316919092015290565b6001600160801b038116811461277557600080fd5b600081830360a08112156154a557600080fd5b6154ad614d18565b83516154b88161547d565b81526080601f19830112156154cc57600080fd5b6154d4614cf0565b915060208401518252604084015160208301526060840151604083015260808401516060830152816020820152809250505092915050565b808201808211156106c4576106c46150cf565b6000808335601e1984360301811261553657600080fd5b8301803591506001600160401b0382111561555057600080fd5b60200191503681900382131561495557600080fd5b600060018201615577576155776150cf565b5060010190565b8060020b811461277557600080fd5b8035610d8c8161557e565b8035610d8c816153fa565b8035610d8c8161547d565b600061012082360312156155c157600080fd5b6155c9614d3a565b82356001600160401b038111156155df57600080fd5b6155eb36828601614fcd565b8252506155fa60208401614828565b602082015261560b6040840161558d565b604082015261561c6060840161558d565b606082015261562d60808401614828565b608082015261563e60a08401614828565b60a082015261564f60c08401615598565b60c082015261566060e084016155a3565b60e082015261010092830135928101929092525090565b60006020828403121561568957600080fd5b81356122fd8161557e565b6000602082840312156156a657600080fd5b81356122fd816153fa565b6000602082840312156156c357600080fd5b81356122fd8161547d565b8481526001600160801b03848116602083015260808201906156f36040840186614a2c565b80841660608401525095945050505050565b60008351615717818460208801614797565b83519083019061572b818360208801614797565b01949350505050565b60208082526025908201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060408201526437bbb732b960d91b606082015260800190565b6020815260006122fd602083018461505b565b60006020828403121561579e57600080fd5b81516122fd81614b82565b6000806000606084860312156157be57600080fd5b83516157c981614813565b60208501519093506157da8161557e565b60408501519092506157eb81614b82565b809150509250925092565b6000806040838503121561580957600080fd5b825161581481614813565b6020840151909250614bbe81614813565b602081526000825160606020840152615841608084018261505b565b60208501516001600160a01b03908116604086810191909152909501519094166060909301929092525090919050565b6020815260018060a01b038251166020820152602082015160020b6040820152604082015160020b6060820152600060608301516158b26080840182614a2c565b5060808301516001600160801b0380821660a08501528060a08601511660c0850152505060c083015160e08084015261285d6101008401826147bb565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b634e487b7160e01b600052601260045260246000fd5b60008251614ecf818460208701614797565b80820281158282048414176106c4576106c46150cf565b60008261599d57634e487b7160e01b600052601260045260246000fd5b500490565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090613a47908301846147bb565b6000602082840312156159e757600080fd5b81516122fd81614764565b634e487b7160e01b600052603160045260246000fdfe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220355111d45eb56ca38c130ac6171ac7d5698181a3eadbbd6ebf53da84fa516c7664736f6c63430008130033446976657267656e63652050726f746f636f6c20506f736974696f6e73204e4654000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d50000000000000000000000000000000000000000000000000000000000000001

Deployed Bytecode

0x6080604052600436106101c65760003560e01c80636352211e116100f7578063a22cb46511610095578063c87b56dd11610064578063c87b56dd146105e2578063e985e9c514610602578063fd3705f91461064b578063fde46ab01461067f57600080fd5b8063a22cb46514610538578063ac9650d814610558578063b402533f14610585578063b88d4fde146105c257600080fd5b8063894f9dbf116100d1578063894f9dbf1461048e57806395d89b41146104ae57806399fbab88146104c35780639c8f9f23146104f057600080fd5b80636352211e1461042e57806370a082311461044e5780638863b3e11461046e57600080fd5b80632e89815711610164578063467cc24e1161013e578063467cc24e146103a45780634aa4a4fc146103c45780634f6ccce7146103f857806361b8ce8c1461041857600080fd5b80632e898157146103445780632f745c591461036457806342842e0e1461038457600080fd5b8063095ea7b3116101a0578063095ea7b3146102aa57806314bc2ec1146102ca57806318160ddd1461030557806323b872dd1461032457600080fd5b806301ffc9a71461021b57806306fdde0314610250578063081812fc1461027257600080fd5b3661021657336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000116146102145760405163178e51ad60e11b815260040160405180910390fd5b005b600080fd5b34801561022757600080fd5b5061023b61023636600461477a565b61069f565b60405190151581526020015b60405180910390f35b34801561025c57600080fd5b506102656106ca565b60405161024791906147e7565b34801561027e57600080fd5b5061029261028d3660046147fa565b61075c565b6040516001600160a01b039091168152602001610247565b3480156102b657600080fd5b506102146102c5366004614833565b610783565b3480156102d657600080fd5b506102ea6102e536600461485f565b61089d565b60408051938452602084019290925290820152606001610247565b34801561031157600080fd5b506008545b604051908152602001610247565b34801561033057600080fd5b5061021461033f366004614899565b610c0b565b34801561035057600080fd5b5061029261035f3660046148da565b610c3c565b34801561037057600080fd5b5061031661037f366004614833565b610d91565b34801561039057600080fd5b5061021461039f366004614899565b610e27565b3480156103b057600080fd5b506102146103bf36600461495c565b610e42565b3480156103d057600080fd5b506102927f000000000000000000000000000000000000000000000000000000000000000181565b34801561040457600080fd5b506103166104133660046147fa565b610ea0565b34801561042457600080fd5b50610316600a5481565b34801561043a57600080fd5b506102926104493660046147fa565b610f33565b34801561045a57600080fd5b506103166104693660046149a7565b610f93565b34801561047a57600080fd5b506102146104893660046149c4565b611019565b34801561049a57600080fd5b506102146104a93660046147fa565b611072565b3480156104ba57600080fd5b50610265611556565b3480156104cf57600080fd5b506104e36104de3660046147fa565b611565565b6040516102479190614a50565b3480156104fc57600080fd5b5061051061050b3660046147fa565b6116e7565b604080519586526020860194909452928401919091526060830152608082015260a001610247565b34801561054457600080fd5b50610214610553366004614b90565b611d1c565b34801561056457600080fd5b50610578610573366004614bc9565b611d2b565b6040516102479190614c3d565b34801561059157600080fd5b506105a56105a0366004614c9f565b611e1f565b604080519283526001600160801b03909116602083015201610247565b3480156105ce57600080fd5b506102146105dd366004614dd2565b61225e565b3480156105ee57600080fd5b506102656105fd3660046147fa565b612290565b34801561060e57600080fd5b5061023b61061d366004614e51565b6001600160a01b03918216600090815260056020908152604080832093909416825291909152205460ff1690565b34801561065757600080fd5b506102927f000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d581565b34801561068b57600080fd5b5061021461069a3660046147fa565b612304565b60006001600160e01b0319821663780e9d6360e01b14806106c457506106c4826126c6565b92915050565b6060600080546106d990614e7f565b80601f016020809104026020016040519081016040528092919081815260200182805461070590614e7f565b80156107525780601f1061072757610100808354040283529160200191610752565b820191906000526020600020905b81548152906001019060200180831161073557829003601f168201915b5050505050905090565b600061076782612716565b506000908152600460205260409020546001600160a01b031690565b600061078e82610f33565b9050806001600160a01b0316836001600160a01b0316036108005760405162461bcd60e51b815260206004820152602160248201527f4552433732313a20617070726f76616c20746f2063757272656e74206f776e656044820152603960f91b60648201526084015b60405180910390fd5b336001600160a01b038216148061081c575061081c813361061d565b61088e5760405162461bcd60e51b815260206004820152603d60248201527f4552433732313a20617070726f76652063616c6c6572206973206e6f7420746f60448201527f6b656e206f776e6572206f7220617070726f76656420666f7220616c6c00000060648201526084016107f7565b6108988383612778565b505050565b60008060008360c001354211156108c75760405163637910d560e11b815260040160405180910390fd5b60006001600160a01b037f000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d51663809e93306109028780614eb9565b6040518263ffffffff1660e01b815260040161091e9190614f7c565b602060405180830381865afa15801561093b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061095f9190614f8f565b90506001600160a01b038116610988576040516379e9ddf360e01b815260040160405180910390fd5b6109b96040805160a08101909152600080825260208201908152600060208201819052604082015260609081015290565b6109c960808701606088016149a7565b6001600160a01b031681526109e46040870160208801614fac565b816020019060018111156109fa576109fa614a16565b90816001811115610a0d57610a0d614a16565b90525060408087013582820152805180820190915233815260208101610a338880614eb9565b610a3c9061504f565b9052604051610a4e91906020016150a2565b60408051601f198184030181529190526080820152610a7360c0870160a088016149a7565b6001600160a01b0316600003610aed576000610a956040880160208901614fac565b6001811115610aa657610aa6614a16565b03610ad557610ac26b19bac7780d08f3ad7f0af7b560016150e5565b6001600160a01b03166060820152610b0c565b610ac260016c09f31acbab516e399f503dcc48615105565b610afd60c0870160a088016149a7565b6001600160a01b031660608201525b6040516320787ae360e01b81526001600160a01b038316906320787ae390610b38908490600401615135565b6060604051808303816000875af1158015610b57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b7b919061518d565b919650945092506080860135841015610ba7576040516307dd37f760e41b815260040160405180910390fd5b7f50cc78f0928389fe9467f4bb28e9b1e34608a464156b89bf64789a8ac9c60097610bd860808801606089016149a7565b610be86040890160208a01614fac565b8787604051610bfa94939291906151bb565b60405180910390a150509193909250565b610c1533826127e6565b610c315760405162461bcd60e51b81526004016107f7906151ea565b610898838383612865565b60006001600160a01b037f000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d51663809e9330610c778480614eb9565b6040518263ffffffff1660e01b8152600401610c939190614f7c565b602060405180830381865afa158015610cb0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd49190614f8f565b90506001600160a01b038116610d735760405163d1d2d73b60e01b81526001600160a01b037f000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d5169063d1d2d73b90610d30908590600401615237565b6020604051808303816000875af1158015610d4f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106c49190614f8f565b60405163f264a77960e01b815260040160405180910390fd5b919050565b6000610d9c83610f93565b8210610dfe5760405162461bcd60e51b815260206004820152602b60248201527f455243373231456e756d657261626c653a206f776e657220696e646578206f7560448201526a74206f6620626f756e647360a81b60648201526084016107f7565b506001600160a01b03919091166000908152600660209081526040808320938352929052205490565b6108988383836040518060200160405280600081525061225e565b6000610e5082840184615290565b9050610e807f000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d582600001516129d6565b8315610e9a57610e9a816020015182604001513387612b1e565b50505050565b6000610eab60085490565b8210610f0e5760405162461bcd60e51b815260206004820152602c60248201527f455243373231456e756d657261626c653a20676c6f62616c20696e646578206f60448201526b7574206f6620626f756e647360a01b60648201526084016107f7565b60088281548110610f2157610f2161533f565b90600052602060002001549050919050565b6000818152600260205260408120546001600160a01b0316806106c45760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b60448201526064016107f7565b60006001600160a01b038216610ffd5760405162461bcd60e51b815260206004820152602960248201527f4552433732313a2061646472657373207a65726f206973206e6f7420612076616044820152683634b21037bbb732b960b91b60648201526084016107f7565b506001600160a01b031660009081526003602052604090205490565b600061102782840184615355565b90506110577f000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d582602001516129d6565b602081015151815161106b91903388612b1e565b5050505050565b8061107d33826127e6565b6110995760405162461bcd60e51b81526004016107f7906153d4565b6000828152600b602090815260408083208151610180810183528154815260018201546001600160a01b03811694820194909452600160a01b8404600290810b93820193909352600160b81b909304820b6060840152818101546001600160801b0381166080850152909160a0840191600160801b900460ff169081111561112357611123614a16565b600281111561113457611134614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff16908111156111e0576111e0614a16565b60038111156111f1576111f1614a16565b8152600b8201546020820152600c9091015460409091015290506001816101200151600381111561122457611224614a16565b146112425760405163617e154d60e11b815260040160405180910390fd5b600081602001516001600160a01b03166361147e116040518163ffffffff1660e01b8152600401602060405180830381865afa158015611286573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112aa9190615407565b905060008160028111156112c0576112c0614a16565b146112de5760405163e8a6f8cf60e01b815260040160405180910390fd5b81610160015182610140015114610e9a5760008083610160015184610140015111611384578361014001518461016001516113199190615424565b84602001516001600160a01b03166370d39cff6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561135b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061137f9190614f8f565b611400565b83610160015184610140015161139a9190615424565b84602001516001600160a01b03166398dfe4786040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113dc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114009190614f8f565b60405163079cc67960e41b81523360048201526024810183905291935091506001600160a01b038216906379cc679090604401600060405180830381600087803b15801561144d57600080fd5b505af1158015611461573d6000803e3d6000fd5b5050505083602001516001600160a01b031663d515de2b61148188610f33565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101859052604401600060405180830381600087803b1580156114c957600080fd5b505af11580156114dd573d6000803e3d6000fd5b5050506000878152600b6020908152604091829020600a01805460ff191660031790558681015182516001600160a01b0390911681529081018990529081018490527f2e4ce7434a1b88a268fdfe83e7c395e73be3ad6efab0b4772ff62a446a33861291506060015b60405180910390a1505050505050565b6060600180546106d990614e7f565b61156d6146ba565b6000828152600b60209081526040918290208251610180810184528154815260018201546001600160a01b03811693820193909352600160a01b8304600290810b94820194909452600160b81b909204830b6060830152828101546001600160801b03811660808401529192909160a0840191600160801b90910460ff16908111156115fb576115fb614a16565b600281111561160c5761160c614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff16908111156116b8576116b8614a16565b60038111156116c9576116c9614a16565b8152600b8201546020820152600c9091015460409091015292915050565b6000806000806000856116fa33826127e6565b6117165760405162461bcd60e51b81526004016107f7906153d4565b6000878152600b602090815260408083208151610180810183528154815260018201546001600160a01b03811694820194909452600160a01b8404600290810b93820193909352600160b81b909304820b6060840152818101546001600160801b0381166080850152909160a0840191600160801b900460ff16908111156117a0576117a0614a16565b60028111156117b1576117b1614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff169081111561185d5761185d614a16565b600381111561186e5761186e614a16565b8152600b8201546020820152600c909101546040909101529050600081610120015160038111156118a1576118a1614a16565b146118bf5760405163027b886560e61b815260040160405180910390fd5b6040805160808101825260008082526020820181815282840182815260608085019390935293850151600290810b845291850151820b905260a08401519192919081111561190f5761190f614a16565b9081600281111561192257611922614a16565b90525060808201516001600160801b0316606082015260208201516040516342e392e160e01b81526001600160a01b03909116906342e392e19061196a908490600401615437565b600060405180830381600087803b15801561198457600080fd5b505af1158015611998573d6000803e3d6000fd5b50505050600082602001516001600160a01b031663514ea4bf30856040015186606001516040516020016119f79392919060609390931b6bffffffffffffffffffffffff1916835260e891821b6014840152901b6017820152601a0190565b604051602081830303815290604052805190602001206040518263ffffffff1660e01b8152600401611a2b91815260200190565b60a060405180830381865afa158015611a48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a6c9190615492565b60008b8152600b60205260409020909150611a878282612c7e565b60408051610180810182528254815260018301546001600160a01b0381166020830152600160a01b8104600290810b93830193909352600160b81b9004820b6060820152818301546001600160801b0381166080830152611bef92849160a0840191600160801b90910460ff1690811115611b0457611b04614a16565b6002811115611b1557611b15614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff1690811115611bc157611bc1614a16565b6003811115611bd257611bd2614a16565b8152602001600b8201548152602001600c82015481525050612de2565b6008860154949e50929c50909a5098509650611c14906001600160801b03168b61550c565b600a8201805460ff19166001179055600b8201889055600c82018790556020850151909a506001600160a01b031663214f220f611c508d610f33565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018d9052604481018c9052606481018b9052608401600060405180830381600087803b158015611ca657600080fd5b505af1158015611cba573d6000803e3d6000fd5b505050507f0bb89aa54ed6940a7e7167bd262b2400d63945045ceff1a52a05f2601ed215f18b8b8a8c11611cee578a611cf0565b8b5b6040805193845260208401929092529082015260600160405180910390a1505050505091939590929450565b611d273383836130d6565b5050565b6060816001600160401b03811115611d4557611d45614cda565b604051908082528060200260200182016040528015611d7857816020015b6060815260200190600190039081611d635790505b50905060005b82811015611e1857611de830858584818110611d9c57611d9c61533f565b9050602002810190611dae919061551f565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506131a492505050565b828281518110611dfa57611dfa61533f565b60200260200101819052508080611e1090615565565b915050611d7e565b5092915050565b600080826101000135421115611e485760405163637910d560e11b815260040160405180910390fd5b6000611e5b611e56856155ae565b6131c9565b600a5494509092509050600030611e786060870160408801615677565b611e886080880160608901615677565b60405160609390931b6bffffffffffffffffffffffff1916602084015260e891821b6034840152901b6037820152603a01604051602081830303815290604052805190602001209050604051806101800160405280858152602001836001600160a01b03168152602001866040016020810190611f059190615677565b60020b8152602001611f1d6080880160608901615677565b60020b81526001600160801b0385166020820152604001611f4460e0880160c08901615694565b6002811115611f5557611f55614a16565b8152602001611f6b610100880160e089016156b1565b6001600160801b03168152602001836001600160a01b031663514ea4bf846040518263ffffffff1660e01b8152600401611fa791815260200190565b60a060405180830381865afa158015611fc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fe89190615492565b602090810151825260408051608080820183526000808352828501819052828401819052606080840182905286860193909352838601819052828601819052948101859052898552600b8452938290208551815592850151600184018054938701519287015162ffffff908116600160b81b0262ffffff60b81b1991909416600160a01b026001600160b81b03199095166001600160a01b0390931692909217939093171617905590820151600280830180546001600160801b039093166001600160801b031984168117825560a086015193919270ffffffffffffffffffffffffffffffffff199092161790600160801b9084908111156120ec576120ec614a16565b021790555060c082015160038281019190915560e0830151805160048401556020808201516005850155604080830151600686015560609283015160078601556101008601518051928101516001600160801b03938416600160801b9185168202176008880155918101519301519282169290911602176009830155610120830151600a830180549192909160ff191690600190849081111561219157612191614a16565b0217905550610140820151600b82015561016090910151600c90910155600a80549060006121be83615565565b909155506121d4905060408601602087016149a7565b6001600160a01b039081169083167f188615b8442f352b1f90be554f1b252160678fb2b17db63385a405ae1da5ef10868661221560e08b0160c08c01615694565b6122266101008c0160e08d016156b1565b60405161223694939291906156ce565b60405180910390a361225761225160408701602088016149a7565b85613611565b5050915091565b61226833836127e6565b6122845760405162461bcd60e51b81526004016107f7906151ea565b610e9a8484848461362b565b606061229b82612716565b60006122b260408051602081019091526000815290565b905060008151116122d257604051806020016040528060008152506122fd565b806122dc8461365e565b6040516020016122ed929190615705565b6040516020818303038152906040525b9392505050565b8061230f33826127e6565b61232b5760405162461bcd60e51b81526004016107f7906153d4565b6000828152600b602090815260408083208151610180810183528154815260018201546001600160a01b03811694820194909452600160a01b8404600290810b93820193909352600160b81b909304820b6060840152818101546001600160801b0381166080850152909160a0840191600160801b900460ff16908111156123b5576123b5614a16565b60028111156123c6576123c6614a16565b81526003828101546020808401919091526040805160808082018352600487015482526005870154828501526006870154828401526007870154606080840191909152838701929092528251808201845260088801546001600160801b038082168352600160801b9182900481169683019690965260098901548087169583019590955290930490931682820152840152600a84015492019160ff169081111561247257612472614a16565b600381111561248357612483614a16565b8152600b8201546020820152600c909101546040909101529050600181610120015160038111156124b6576124b6614a16565b146124d45760405163617e154d60e11b815260040160405180910390fd5b600081602001516001600160a01b03166361147e116040518163ffffffff1660e01b8152600401602060405180830381865afa158015612518573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061253c9190615407565b6101608301516101408401519192501160008083600281111561256157612561614a16565b0361257f5760405163c224a1d960e01b815260040160405180910390fd5b600183600281111561259357612593614a16565b036125bc5781156125b7578361014001518461016001516125b49190615424565b90505b6125da565b816125da578361016001518461014001516125d79190615424565b90505b801561265d5783602001516001600160a01b031663d515de2b6125fc88610f33565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b15801561264457600080fd5b505af1158015612658573d6000803e3d6000fd5b505050505b6000868152600b6020908152604091829020600a01805460ff191660021790558581015182516001600160a01b0390911681529081018890529081018290527f5162053cd26656b4db1c058010055f8c67f02bb69c7097d8f5e032c55a66a31090606001611546565b60006001600160e01b031982166380ac58cd60e01b14806126f757506001600160e01b03198216635b5e139f60e01b145b806106c457506301ffc9a760e01b6001600160e01b03198316146106c4565b6000818152600260205260409020546001600160a01b03166127755760405162461bcd60e51b8152602060048201526018602482015277115490cdcc8c4e881a5b9d985b1a59081d1bdad95b88125160421b60448201526064016107f7565b50565b600081815260046020526040902080546001600160a01b0319166001600160a01b03841690811790915581906127ad82610f33565b6001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560405160405180910390a45050565b6000806127f283610f33565b9050806001600160a01b0316846001600160a01b0316148061283957506001600160a01b0380821660009081526005602090815260408083209388168352929052205460ff165b8061285d5750836001600160a01b03166128528461075c565b6001600160a01b0316145b949350505050565b826001600160a01b031661287882610f33565b6001600160a01b03161461289e5760405162461bcd60e51b81526004016107f790615734565b6001600160a01b0382166129005760405162461bcd60e51b8152602060048201526024808201527f4552433732313a207472616e7366657220746f20746865207a65726f206164646044820152637265737360e01b60648201526084016107f7565b61290d83838360016136f0565b826001600160a01b031661292082610f33565b6001600160a01b0316146129465760405162461bcd60e51b81526004016107f790615734565b600081815260046020908152604080832080546001600160a01b03199081169091556001600160a01b0387811680865260038552838620805460001901905590871680865283862080546001019055868652600290945282852080549092168417909155905184937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef91a4505050565b604051630809e93360e41b815233906001600160a01b0384169063809e933090612a04908590600401615779565b602060405180830381865afa158015612a21573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a459190614f8f565b6001600160a01b031614612a885760405162461bcd60e51b815260206004820152600a6024820152696f6e6c79426174746c6560b01b60448201526064016107f7565b604051630809e93360e41b815233906001600160a01b0384169063809e933090612ab6908590600401615779565b602060405180830381865afa158015612ad3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612af79190614f8f565b6001600160a01b031614611d2757604051631dd6046560e31b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000016001600160a01b0316846001600160a01b0316148015612b5f5750804710155b15612c72577f00000000000000000000000000000000000000000000000000000000000000016001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b158015612bbf57600080fd5b505af1158015612bd3573d6000803e3d6000fd5b505060405163a9059cbb60e01b81526001600160a01b038681166004830152602482018690527f000000000000000000000000000000000000000000000000000000000000000116935063a9059cbb925060440190506020604051808303816000875af1158015612c48573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c6c919061578c565b50610e9a565b610e9a8484848461381d565b60048101546020830151516002830154612ca992909103906001600160801b0316600160801b613927565b6008820180546001600160801b0380821690930183166001600160801b0319909116179055600582015460208085015101516002840154612cf493929091039116600160801b613927565b6008820180546001600160801b03600160801b8083048216909401811684029181169190911790915560068301546020850151604001516002850154612d409492909103921690613927565b6009820180546001600160801b0380821690930183166001600160801b031990911617905560078201546020840151606001516002840154612d8c93929091039116600160801b613927565b6009820180546001600160801b03600160801b8083048216909401811690930292169190911790556020918201518051600483015591820151600582015560408201516006820155606090910151600790910155565b600080808080808660a001516002811115612dff57612dff614a16565b03612ea857505061010084015160408101516060909101516001600160801b0391821691166000818311612e335781612e35565b825b9050808760c00151886101000151602001516001600160801b0316612e5a919061550c565b14612e9d576001818860c00151896101000151602001516001600160801b0316612e84919061550c565b612e8e9190615424565b612e989190615424565b612ea0565b60005b9550506130cd565b60018660a001516002811115612ec057612ec0614a16565b03612fcb578560c00151866101000151604001516001600160801b031611612ee9576000612f0b565b8560c00151866101000151604001516001600160801b0316612f0b9190615424565b9150856101000151606001516001600160801b031690506000818311612f315781612f33565b825b905080876101000151602001516001600160801b031614612f7d57600181886101000151602001516001600160801b0316612f6e9190615424565b612f789190615424565b612f80565b60005b9550866101000151604001516001600160801b03168760c001511115612fc557866101000151604001516001600160801b03168760c00151612fc29190615424565b94505b506130cd565b856101000151604001516001600160801b031691508560c00151866101000151606001516001600160801b031611613004576000613026565b8560c00151866101000151606001516001600160801b03166130269190615424565b905060008183116130375781613039565b825b905080876101000151602001516001600160801b03161461308357600181886101000151602001516001600160801b03166130749190615424565b61307e9190615424565b613086565b60005b9550866101000151606001516001600160801b03168760c0015111156130cb57866101000151606001516001600160801b03168760c001516130c89190615424565b93505b505b91939590929450565b816001600160a01b0316836001600160a01b0316036131375760405162461bcd60e51b815260206004820152601960248201527f4552433732313a20617070726f766520746f2063616c6c65720000000000000060448201526064016107f7565b6001600160a01b03838116600081815260056020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b60606122fd8383604051806060016040528060278152602001615a09602791396139d9565b8051604051630809e93360e41b815260009182916001600160a01b037f000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d5169163809e93309161321b9190600401615779565b602060405180830381865afa158015613238573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061325c9190614f8f565b90506001600160a01b038116613285576040516379e9ddf360e01b815260040160405180910390fd5b6000816001600160a01b0316633850c7bd6040518163ffffffff1660e01b8152600401606060405180830381865afa1580156132c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132e991906157a9565b5050905083608001516001600160a01b0316816001600160a01b0316108061332657508360a001516001600160a01b0316816001600160a01b0316115b15613344576040516307dd37f760e41b815260040160405180910390fd5b60008460c00151600281111561335c5761335c614a16565b0361339957613392816133728660400151613a51565b61337f8760600151613a51565b8760e001516001600160801b0316613a96565b92506133cc565b6133c96133a98560400151613a51565b6133b68660600151613a51565b8660e001516001600160801b0316613bc7565b92505b6000808560c0015160028111156133e5576133e5614a16565b036133f357508351516134e5565b60018560c00151600281111561340b5761340b614a16565b0361347d576000836001600160a01b031663af0923be6040518163ffffffff1660e01b81526004016040805180830381865afa15801561344f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061347391906157f6565b5091506134e59050565b6000836001600160a01b031663af0923be6040518163ffffffff1660e01b81526004016040805180830381865afa1580156134bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134e091906157f6565b925050505b826001600160a01b031663c1c816636040518060e0016040528088602001516001600160a01b03168152602001886040015160020b8152602001886060015160020b81526020018860c00151600281111561354257613542614a16565b8152602001876001600160801b031681526020018860e001516001600160801b0316815260200160405180606001604052808a600001518152602001866001600160a01b03168152602001336001600160a01b03168152506040516020016135aa9190615825565b6040516020818303038152906040528152506040518263ffffffff1660e01b81526004016135d89190615871565b600060405180830381600087803b1580156135f257600080fd5b505af1158015613606573d6000803e3d6000fd5b505050505050915091565b611d27828260405180602001604052806000815250613c5f565b613636848484612865565b61364284848484613c92565b610e9a5760405162461bcd60e51b81526004016107f7906158ef565b6060600061366b83613d90565b60010190506000816001600160401b0381111561368a5761368a614cda565b6040519080825280601f01601f1916602001820160405280156136b4576020820181803683370190505b5090508181016020015b600019016f181899199a1a9b1b9c1cb0b131b232b360811b600a86061a8153600a85049450846136be57509392505050565b600181111561375f5760405162461bcd60e51b815260206004820152603560248201527f455243373231456e756d657261626c653a20636f6e7365637574697665207472604482015274185b9cd9995c9cc81b9bdd081cdd5c1c1bdc9d1959605a1b60648201526084016107f7565b816001600160a01b0385166137bb576137b681600880546000838152600960205260408120829055600182018355919091527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee30155565b6137de565b836001600160a01b0316856001600160a01b0316146137de576137de8582613e68565b6001600160a01b0384166137fa576137f581613f05565b61106b565b846001600160a01b0316846001600160a01b03161461106b5761106b8482613fb4565b604080516001600160a01b0385811660248301528481166044830152606480830185905283518084039091018152608490920183526020820180516001600160e01b03166323b872dd60e01b17905291516000928392908816916138819190615957565b6000604051808303816000865af19150503d80600081146138be576040519150601f19603f3d011682016040523d82523d6000602084013e6138c3565b606091505b50915091508180156138ed5750805115806138ed5750808060200190518101906138ed919061578c565b61391f5760405162461bcd60e51b815260206004820152600360248201526229aa2360e91b60448201526064016107f7565b505050505050565b6000808060001985870985870292508281108382030391505080600003613960576000841161395557600080fd5b5082900490506122fd565b80841161396c57600080fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b6060600080856001600160a01b0316856040516139f69190615957565b600060405180830381855af49150503d8060008114613a31576040519150601f19603f3d011682016040523d82523d6000602084013e613a36565b606091505b5091509150613a4786838387613ff8565b9695505050505050565b600061b38019600283900b12801590613a70575061b381600283900b13155b613a8d5760405163e7ec280d60e01b815260040160405180910390fd5b6106c482614071565b6000826001600160a01b0316846001600160a01b03161115613ab6579192915b836001600160a01b0316856001600160a01b031611613ae157613ada848484614394565b905061285d565b826001600160a01b0316856001600160a01b03161015613bb3576000613b1e866001600160a01b0316856001600160a01b0316600160601b6143f7565b905060006001600160a01b03808816908616613b51613b3d898b615105565b6001600160a01b031685600160601b6143f7565b613b5b919061550c565b613b659190615424565b90506000613b8a886001600160a01b0316876001600160a01b0316600160601b613927565b9050613ba9613ba4613b9c8388615969565b600185613927565b614437565b935050505061285d565b613bbe8484846144a4565b95945050505050565b6000826001600160a01b0316846001600160a01b03161115613be7579192915b6000613c0a856001600160a01b0316856001600160a01b0316600160601b613927565b9050613bbe613c1d82600160601b61550c565b613c55613c336001600160a01b03891687615969565b6001600160a01b038816613c478a8a615105565b6001600160a01b0316613927565b613ba49190615980565b613c6983836144e1565b613c766000848484613c92565b6108985760405162461bcd60e51b81526004016107f7906158ef565b60006001600160a01b0384163b15613d8857604051630a85bd0160e11b81526001600160a01b0385169063150b7a0290613cd69033908990889088906004016159a2565b6020604051808303816000875af1925050508015613d11575060408051601f3d908101601f19168201909252613d0e918101906159d5565b60015b613d6e573d808015613d3f576040519150601f19603f3d011682016040523d82523d6000602084013e613d44565b606091505b508051600003613d665760405162461bcd60e51b81526004016107f7906158ef565b805181602001fd5b6001600160e01b031916630a85bd0160e11b14905061285d565b50600161285d565b60008072184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b8310613dcf5772184f03e93ff9f4daa797ed6e38ed64bf6a1f0160401b830492506040015b6d04ee2d6d415b85acef81000000008310613dfb576d04ee2d6d415b85acef8100000000830492506020015b662386f26fc100008310613e1957662386f26fc10000830492506010015b6305f5e1008310613e31576305f5e100830492506008015b6127108310613e4557612710830492506004015b60648310613e57576064830492506002015b600a83106106c45760010192915050565b60006001613e7584610f93565b613e7f9190615424565b600083815260076020526040902054909150808214613ed2576001600160a01b03841660009081526006602090815260408083208584528252808320548484528184208190558352600790915290208190555b5060009182526007602090815260408084208490556001600160a01b039094168352600681528383209183525290812055565b600854600090613f1790600190615424565b60008381526009602052604081205460088054939450909284908110613f3f57613f3f61533f565b906000526020600020015490508060088381548110613f6057613f6061533f565b6000918252602080832090910192909255828152600990915260408082208490558582528120556008805480613f9857613f986159f2565b6001900381819060005260206000200160009055905550505050565b6000613fbf83610f93565b6001600160a01b039093166000908152600660209081526040808320868452825280832085905593825260079052919091209190915550565b60608315614067578251600003614060576001600160a01b0385163b6140605760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016107f7565b508161285d565b61285d838361467a565b60008060008360020b12614088578260020b614090565b8260020b6000035b9050620d89e88111156140b6576040516315e4079d60e11b815260040160405180910390fd5b6000816001166000036140cd57600160801b6140df565b6ffffcb933bd6fad37aa2d162d1a5940015b70ffffffffffffffffffffffffffffffffff1690506002821615614113576ffff97272373d413259a46990580e213a0260801c5b6004821615614132576ffff2e50f5f656932ef12357cf3c7fdcc0260801c5b6008821615614151576fffe5caca7e10e4e61c3624eaa0941cd00260801c5b6010821615614170576fffcb9843d60f6159c9db58835c9266440260801c5b602082161561418f576fff973b41fa98c081472e6896dfb254c00260801c5b60408216156141ae576fff2ea16466c96a3843ec78b326b528610260801c5b60808216156141cd576ffe5dee046a99a2a811c461f1969c30530260801c5b6101008216156141ed576ffcbe86c7900a88aedcffc83b479aa3a40260801c5b61020082161561420d576ff987a7253ac413176f2b074cf7815e540260801c5b61040082161561422d576ff3392b0822b70005940c7a398e4b70f30260801c5b61080082161561424d576fe7159475a2c29b7443b29c7fa6e889d90260801c5b61100082161561426d576fd097f3bdfd2022b8845ad8f792aa58250260801c5b61200082161561428d576fa9f746462d870fdf8a65dc1f90e061e50260801c5b6140008216156142ad576f70d869a156d2a1b890bb3df62baf32f70260801c5b6180008216156142cd576f31be135f97d08fd981231505542fcfa60260801c5b620100008216156142ee576f09aa508b5b7a84e1c677de54f3e99bc90260801c5b6202000082161561430e576e5d6af8dedb81196699c329225ee6040260801c5b6204000082161561432d576d2216e584f5fa1ea926041bedfe980260801c5b6208000082161561434a576b048a170391f7dc42444e8fa20260801c5b60008460020b131561436b57806000198161436757614367615941565b0490505b64010000000081061561437f576001614382565b60005b60ff16602082901c0192505050919050565b6000826001600160a01b0316846001600160a01b031611156143b4579192915b60006143d7856001600160a01b0316856001600160a01b0316600160601b613927565b9050613bbe6143f284838888036001600160a01b0316613927565b6146a4565b6000614404848484613927565b90506000828061441657614416615941565b84860911156122fd57600019811061442d57600080fd5b6001019392505050565b60006001600160801b038211156144a05760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b60648201526084016107f7565b5090565b6000826001600160a01b0316846001600160a01b031611156144c4579192915b61285d6143f283600160601b8787036001600160a01b0316613927565b6001600160a01b0382166145375760405162461bcd60e51b815260206004820181905260248201527f4552433732313a206d696e7420746f20746865207a65726f206164647265737360448201526064016107f7565b6000818152600260205260409020546001600160a01b03161561459c5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016107f7565b6145aa6000838360016136f0565b6000818152600260205260409020546001600160a01b03161561460f5760405162461bcd60e51b815260206004820152601c60248201527f4552433732313a20746f6b656e20616c7265616479206d696e7465640000000060448201526064016107f7565b6001600160a01b038216600081815260036020908152604080832080546001019055848352600290915280822080546001600160a01b0319168417905551839291907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef908290a45050565b81511561468a5781518083602001fd5b8060405162461bcd60e51b81526004016107f791906147e7565b806001600160801b0381168114610d8c57600080fd5b604080516101808101825260008082526020820181905291810182905260608101829052608081018290529060a08201908152602001600081526020016147226040518060800160405280600081526020016000815260200160008152602001600081525090565b81526040805160808101825260008082526020828101829052928201819052606082015291019081526020016000815260200160008152602001600081525090565b6001600160e01b03198116811461277557600080fd5b60006020828403121561478c57600080fd5b81356122fd81614764565b60005b838110156147b257818101518382015260200161479a565b50506000910152565b600081518084526147d3816020860160208601614797565b601f01601f19169290920160200192915050565b6020815260006122fd60208301846147bb565b60006020828403121561480c57600080fd5b5035919050565b6001600160a01b038116811461277557600080fd5b8035610d8c81614813565b6000806040838503121561484657600080fd5b823561485181614813565b946020939093013593505050565b60006020828403121561487157600080fd5b81356001600160401b0381111561488757600080fd5b820160e081850312156122fd57600080fd5b6000806000606084860312156148ae57600080fd5b83356148b981614813565b925060208401356148c981614813565b929592945050506040919091013590565b6000602082840312156148ec57600080fd5b81356001600160401b0381111561490257600080fd5b8201604081850312156122fd57600080fd5b60008083601f84011261492657600080fd5b5081356001600160401b0381111561493d57600080fd5b60208301915083602082850101111561495557600080fd5b9250929050565b60008060006040848603121561497157600080fd5b8335925060208401356001600160401b0381111561498e57600080fd5b61499a86828701614914565b9497909650939450505050565b6000602082840312156149b957600080fd5b81356122fd81614813565b600080600080606085870312156149da57600080fd5b843593506020850135925060408501356001600160401b038111156149fe57600080fd5b614a0a87828801614914565b95989497509550505050565b634e487b7160e01b600052602160045260246000fd5b60038110614a3c57614a3c614a16565b9052565b60048110614a3c57614a3c614a16565b81518152602080830151610240830191614a74908401826001600160a01b03169052565b506040830151614a89604084018260020b9052565b506060830151614a9e606084018260020b9052565b506080830151614ab960808401826001600160801b03169052565b5060a0830151614acc60a0840182614a2c565b5060c083015160c083015260e0830151614b0a60e0840182805182526020810151602083015260408101516040830152606081015160608301525050565b50610100830151610160614b4e8185018380516001600160801b03908116835260208083015182169084015260408083015182169084015260609182015116910152565b6101208501519150614b646101e0850183614a40565b61014085015161020085015280850151610220850152505092915050565b801515811461277557600080fd5b60008060408385031215614ba357600080fd5b8235614bae81614813565b91506020830135614bbe81614b82565b809150509250929050565b60008060208385031215614bdc57600080fd5b82356001600160401b0380821115614bf357600080fd5b818501915085601f830112614c0757600080fd5b813581811115614c1657600080fd5b8660208260051b8501011115614c2b57600080fd5b60209290920196919550909350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015614c9257603f19888603018452614c808583516147bb565b94509285019290850190600101614c64565b5092979650505050505050565b600060208284031215614cb157600080fd5b81356001600160401b03811115614cc757600080fd5b820161012081850312156122fd57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b0381118282101715614d1257614d12614cda565b60405290565b604080519081016001600160401b0381118282101715614d1257614d12614cda565b60405161012081016001600160401b0381118282101715614d1257614d12614cda565b60006001600160401b0380841115614d7757614d77614cda565b604051601f8501601f19908116603f01168101908282118183101715614d9f57614d9f614cda565b81604052809350858152868686011115614db857600080fd5b858560208301376000602087830101525050509392505050565b60008060008060808587031215614de857600080fd5b8435614df381614813565b93506020850135614e0381614813565b92506040850135915060608501356001600160401b03811115614e2557600080fd5b8501601f81018713614e3657600080fd5b614e4587823560208401614d5d565b91505092959194509250565b60008060408385031215614e6457600080fd5b8235614e6f81614813565b91506020830135614bbe81614813565b600181811c90821680614e9357607f821691505b602082108103614eb357634e487b7160e01b600052602260045260246000fd5b50919050565b60008235607e19833603018112614ecf57600080fd5b9190910192915050565b60008135614ee681614813565b6001600160a01b03168352602082013536839003601e19018112614f0957600080fd5b82016020810190356001600160401b03811115614f2557600080fd5b803603821315614f3457600080fd5b60806020860152806080860152808260a0870137600060a08287010152604084013560408601526060840135606086015260a0601f19601f8301168601019250505092915050565b6020815260006122fd6020830184614ed9565b600060208284031215614fa157600080fd5b81516122fd81614813565b600060208284031215614fbe57600080fd5b8135600281106122fd57600080fd5b600060808284031215614fdf57600080fd5b614fe7614cf0565b90508135614ff481614813565b815260208201356001600160401b0381111561500f57600080fd5b8201601f8101841361502057600080fd5b61502f84823560208401614d5d565b602083015250604082013560408201526060820135606082015292915050565b60006106c43683614fcd565b60018060a01b038151168252600060208201516080602085015261508260808501826147bb565b905060408301516040850152606083015160608501528091505092915050565b602080825282516001600160a01b03168282015282015160408083015260009061285d606084018261505b565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03818116838216019080821115611e1857611e186150cf565b6001600160a01b03828116828216039080821115611e1857611e186150cf565b60028110614a3c57614a3c614a16565b60208152600060018060a01b03808451166020840152602084015161515d6040850182615125565b506040840151606084015280606085015116608084015250608083015160a08084015261285d60c08401826147bb565b6000806000606084860312156151a257600080fd5b8351925060208401519150604084015190509250925092565b6001600160a01b0385168152608081016151d86020830186615125565b60408201939093526060015292915050565b6020808252602d908201527f4552433732313a2063616c6c6572206973206e6f7420746f6b656e206f776e6560408201526c1c881bdc88185c1c1c9bdd9959609a1b606082015260800190565b6020815260008235607e1984360301811261525157600080fd5b6040602084015261526760608401858301614ed9565b9050602084013561527781614813565b6001600160a01b03166040939093019290925250919050565b6000602082840312156152a257600080fd5b81356001600160401b03808211156152b957600080fd5b90830190606082860312156152cd57600080fd5b6040516060810181811083821117156152e8576152e8614cda565b6040528235828111156152fa57600080fd5b61530687828601614fcd565b8252506020830135915061531982614813565b8160208201526040830135925061532f83614813565b6040810192909252509392505050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561536757600080fd5b81356001600160401b038082111561537e57600080fd5b908301906040828603121561539257600080fd5b61539a614d18565b82356153a581614813565b81526020830135828111156153b957600080fd5b6153c587828601614fcd565b60208301525095945050505050565b6020808252600c908201526b139bdd08185c1c1c9bdd995960a21b604082015260600190565b6003811061277557600080fd5b60006020828403121561541957600080fd5b81516122fd816153fa565b818103818111156106c4576106c46150cf565b6000608082019050825160020b8252602083015160020b602083015260408301516154656040840182614a2c565b506060928301516001600160801b0316919092015290565b6001600160801b038116811461277557600080fd5b600081830360a08112156154a557600080fd5b6154ad614d18565b83516154b88161547d565b81526080601f19830112156154cc57600080fd5b6154d4614cf0565b915060208401518252604084015160208301526060840151604083015260808401516060830152816020820152809250505092915050565b808201808211156106c4576106c46150cf565b6000808335601e1984360301811261553657600080fd5b8301803591506001600160401b0382111561555057600080fd5b60200191503681900382131561495557600080fd5b600060018201615577576155776150cf565b5060010190565b8060020b811461277557600080fd5b8035610d8c8161557e565b8035610d8c816153fa565b8035610d8c8161547d565b600061012082360312156155c157600080fd5b6155c9614d3a565b82356001600160401b038111156155df57600080fd5b6155eb36828601614fcd565b8252506155fa60208401614828565b602082015261560b6040840161558d565b604082015261561c6060840161558d565b606082015261562d60808401614828565b608082015261563e60a08401614828565b60a082015261564f60c08401615598565b60c082015261566060e084016155a3565b60e082015261010092830135928101929092525090565b60006020828403121561568957600080fd5b81356122fd8161557e565b6000602082840312156156a657600080fd5b81356122fd816153fa565b6000602082840312156156c357600080fd5b81356122fd8161547d565b8481526001600160801b03848116602083015260808201906156f36040840186614a2c565b80841660608401525095945050505050565b60008351615717818460208801614797565b83519083019061572b818360208801614797565b01949350505050565b60208082526025908201527f4552433732313a207472616e736665722066726f6d20696e636f72726563742060408201526437bbb732b960d91b606082015260800190565b6020815260006122fd602083018461505b565b60006020828403121561579e57600080fd5b81516122fd81614b82565b6000806000606084860312156157be57600080fd5b83516157c981614813565b60208501519093506157da8161557e565b60408501519092506157eb81614b82565b809150509250925092565b6000806040838503121561580957600080fd5b825161581481614813565b6020840151909250614bbe81614813565b602081526000825160606020840152615841608084018261505b565b60208501516001600160a01b03908116604086810191909152909501519094166060909301929092525090919050565b6020815260018060a01b038251166020820152602082015160020b6040820152604082015160020b6060820152600060608301516158b26080840182614a2c565b5060808301516001600160801b0380821660a08501528060a08601511660c0850152505060c083015160e08084015261285d6101008401826147bb565b60208082526032908201527f4552433732313a207472616e7366657220746f206e6f6e20455243373231526560408201527131b2b4bb32b91034b6b83632b6b2b73a32b960711b606082015260800190565b634e487b7160e01b600052601260045260246000fd5b60008251614ecf818460208701614797565b80820281158282048414176106c4576106c46150cf565b60008261599d57634e487b7160e01b600052601260045260246000fd5b500490565b6001600160a01b0385811682528416602082015260408101839052608060608201819052600090613a47908301846147bb565b6000602082840312156159e757600080fd5b81516122fd81614764565b634e487b7160e01b600052603160045260246000fdfe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220355111d45eb56ca38c130ac6171ac7d5698181a3eadbbd6ebf53da84fa516c7664736f6c63430008130033

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

000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d50000000000000000000000000000000000000000000000000000000000000001

-----Decoded View---------------
Arg [0] : _arena (address): 0xA0D812cAe2376b90951192319477eF5Fe3Ac56D5
Arg [1] : _weth (address): 0x0000000000000000000000000000000000000001

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000a0d812cae2376b90951192319477ef5fe3ac56d5
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000001


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.