Contract 0x336a2f76d2be24e7cb6f468665a4277d4d617d00 1

 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0xc4d7d034815fc8d77455d0f0099d9178de852e55295ab632e3279135fce10740Set Fee To Sette...504847822023-01-03 7:29:20451 days 5 hrs ago0xcb3a9bfc9f99e75e922a516eed04d9f62e83a28e IN  Pulsar Protocol: Factory0 ETH0.00002379 0.1
0x32710d6148ca4f1e4dfbd43483b4090701b641d3f75fdb95c89ee17314d0b8b7Set Fee To504842562023-01-03 7:26:28451 days 5 hrs ago0xcb3a9bfc9f99e75e922a516eed04d9f62e83a28e IN  Pulsar Protocol: Factory0 ETH0.00002401 0.1
0x8865098fabeb32902d8965ac74d4f073a9c695090bed142b6ab7f9ecf27aa470Set Fee Arg504839112023-01-03 7:24:29451 days 5 hrs ago0xcb3a9bfc9f99e75e922a516eed04d9f62e83a28e IN  Pulsar Protocol: Factory0 ETH0.00002393 0.1
0xc41ef29918efb40fa12784d84966051e7b8e7cf8cac1b13c41d1c40e88becb97Set Fee Arg504838472023-01-03 7:24:09451 days 5 hrs ago0xcb3a9bfc9f99e75e922a516eed04d9f62e83a28e IN  Pulsar Protocol: Factory0 ETH0.00002564 0.1
0x851f7b264dbe089e6ac594a2c4f985af9579db902efc021f468f575f286c78240x60806040504763492023-01-03 6:39:35451 days 6 hrs ago0xcb3a9bfc9f99e75e922a516eed04d9f62e83a28e IN  Create: Factory0 ETH0.00138339 0.1
[ Download CSV Export 
Latest 25 internal transaction
Parent Txn Hash Block From To Value
0x443f7022ad3b7cbbe79632a91e64cbbfe88f46490cec1cbf86ce9c6dfc5bf25c1169833042023-08-01 5:17:44241 days 7 hrs ago Pulsar Protocol: Factory  Contract Creation0 ETH
0x91db360e34737ef22194c8b7762a08da7adb28731c104c792f15c01aed2c33081169832112023-08-01 5:17:20241 days 7 hrs ago Pulsar Protocol: Factory  Contract Creation0 ETH
0x8033c1cf5d0c7119b3bac8fee60417ab6df363d7cb701dc8e2c26fa2d91706ae1169830832023-08-01 5:16:45241 days 7 hrs ago Pulsar Protocol: Factory  Contract Creation0 ETH
0xd38bcbb4f902a1d5c965765d2635c796909e1efe24edde09edaa721d866f3dd91169829942023-08-01 5:16:21241 days 7 hrs ago Pulsar Protocol: Factory  Contract Creation0 ETH
0x760139d012a2c21da1531a13f2ab9115ec2d72f974d479fae1a1121a840e3cdf1169828722023-08-01 5:15:48241 days 7 hrs ago Pulsar Protocol: Factory  Contract Creation0 ETH
0x5f61d81fbb9f685abf7668a665524d22ded798f2ce4a0230997bb62d79ec970f1169826882023-08-01 5:15:01241 days 7 hrs ago Pulsar Protocol: Factory  Contract Creation0 ETH
0xd0332c2a004abb531c67729f5df9699aca1fd42218553612af5b07872219f278720582042023-03-21 8:21:59374 days 4 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0xc1bde4b4499c0f9fb5fee9a45e2a0f0ec6278cc82a44bfed82dab2b99dedf996720537092023-03-21 8:03:35374 days 4 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0x4aa8c5084948d91610c27dd022f4736602d0a91439dc5339032149c4c96b3d64720491592023-03-21 7:44:46374 days 4 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0xf96cd9d92d01d7c3c8ee47b02e9d7c8b779beed0a462f24e3980c344b3ad5482720359662023-03-21 6:50:41374 days 5 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0x4421e3438500d9eb48596a5e8a7732a4b5bf5e5accc3e3a25ef508c606a7a6a3720349472023-03-21 6:46:33374 days 5 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0x56e07d305284d5ff6d7d0cf5bd681c6025a96cd606e15b1f74b125b045873e55720319292023-03-21 6:34:02374 days 6 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0x286f6370eba0f48127993946e03e00e45c8629ee4105573642f8ad9b9551e14b720300582023-03-21 6:26:28374 days 6 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0xc97ee1a8ee734966adb895de816618e9d39016a759752174c0a208a99cfdf482720080792023-03-21 4:55:49374 days 7 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0xe5f61b7f19faae110439f2f591f1ef31ac6e117ec4580b6635502104cee7678f719873742023-03-21 3:29:47374 days 9 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0xa60d58f41b6f08ed0a668637ab7570342ff65543b40d820e8e88fb8a62592663719499882023-03-21 0:53:23374 days 11 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0xf3f2d56d98b4ea112542ce9db34a18893d6abab8e1b400932719f10b8573baac719363302023-03-20 23:54:46374 days 12 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0xda23ca7749f516ce8141327e3bc530cd52a1f9c947e8ca9b18a257a304567609719277972023-03-20 23:18:38374 days 13 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0x1008125161a2e4cb2e2423d96eb6460cb7b93e661df0c164ed9bf7e0908f9215719110952023-03-20 22:06:28374 days 14 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0x3d1d74593b5e7447f10a2796d0aa877b00195739ff79903f9004df0284f43660718543512023-03-20 18:07:09374 days 18 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0xead50cc253668617e9cfb426b2d8dfdee54641496e120e2b0ac2657c0cfcaa05717832222023-03-20 13:14:03374 days 23 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0x33217436453901c095af0103d327e0a4ce5c52704d87b092ee239ae7496dc66f717317632023-03-20 9:43:06375 days 2 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0x9043041de4578ec038bb6af8bf9ab42468a284098a5e72ed5f9fedc562752e0d717289252023-03-20 9:31:29375 days 3 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0xd8c22237ee81673d93e093fe2ca14efa1b5e13f0d5be86da009e46c2735fdf3a717241562023-03-20 9:11:53375 days 3 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
0x9d95ba478a6c72bbce30d04951d017ccc97a760743fd6306ddf53c3c3d02bf50717040172023-03-20 7:48:47375 days 4 hrs ago Pulsar Protocol: TWAMM Pulsar Protocol: Factory0 ETH
[ Download CSV Export 
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:
Factory

Compiler Version
v0.8.9+commit.e5eed63a

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 18 : Factory.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

import "./interfaces/IFactory.sol";
import "./Pair.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract Factory is IFactory, Initializable {
    mapping(address => mapping(address => address)) public override getPair;
    address[] public override allPairs;

    uint32 public override feeArg;
    address public override feeTo;
    address public override feeToSetter;
    address public override twammAdd;

    constructor(address _feeToSetter) {
        feeToSetter = _feeToSetter;
    }

    function allPairsLength() external view override returns (uint256) {
        return allPairs.length;
    }

    function initialize(address _twammAdd) external override initializer {
        twammAdd = _twammAdd;
    }

    function createPair(
        address token0,
        address token1
    ) external override returns (address pair) {
        require(
            msg.sender == twammAdd,
            "Invalid User, Only TWAMM Can Create Pair"
        );
        require(twammAdd != address(0), "Factory Not Initialized By TWAMM Yet");
        require(token0 != token1, "Factory: Identical Addresses");

        (address tokenA, address tokenB) = token0 < token1
            ? (token0, token1)
            : (token1, token0);
        require(tokenA != address(0), "Factory: Zero Address");
        require(getPair[tokenA][tokenB] == address(0), "Factory: Pair Exists"); // single check is sufficient

        bytes memory bytecode = type(Pair).creationCode;
        bytes memory bytecodeArg = abi.encodePacked(
            bytecode,
            abi.encode(tokenA, tokenB, twammAdd)
        );
        bytes32 salt = keccak256(abi.encodePacked(tokenA, tokenB));
        assembly {
            pair := create2(0, add(bytecodeArg, 0x20), mload(bytecodeArg), salt)
        }
        require(pair != address(0), "Create2: Failed On Deploy");
        getPair[tokenA][tokenB] = pair;
        getPair[tokenB][tokenA] = pair; // populate mapping in the reverse direction
        allPairs.push(pair);
        emit PairCreated(tokenA, tokenB, pair, allPairs.length);
    }

    function setFeeArg(uint32 _feeArg) external override {
        require(msg.sender == feeToSetter, "Factory: Forbidden");
        feeArg = _feeArg;
    }

    function setFeeTo(address _feeTo) external override {
        require(msg.sender == feeToSetter, "Factory: Forbidden");
        feeTo = _feeTo;
    }

    function setFeeToSetter(address _feeToSetter) external override {
        require(msg.sender == feeToSetter, "Factory: Forbidden");
        feeToSetter = _feeToSetter;
    }
}

File 2 of 18 : IFactory.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

interface IFactory {
    event PairCreated(
        address indexed tokenA,
        address indexed tokenB,
        address pair,
        uint256
    );

    function getPair(
        address token0,
        address token1
    ) external view returns (address pair);

    function allPairs(uint256) external view returns (address pair);

    function feeArg() external view returns (uint32);

    function feeTo() external view returns (address);

    function feeToSetter() external view returns (address);

    function allPairsLength() external view returns (uint256);

    function initialize(address _twammAdd) external;

    function twammAdd() external view returns (address);

    function createPair(
        address token0,
        address token1
    ) external returns (address pair);

    function setFeeArg(uint32) external;

    function setFeeTo(address) external;

    function setFeeToSetter(address) external;
}

File 3 of 18 : Pair.sol
// SPDX-License-Identifier: GPL-3.0-or-later

// Inspired by https://www.paradigm.xyz/2021/07/twamm
// https://github.com/para-dave/twamm
// FrankieIsLost MVP code implementation: https://github.com/FrankieIsLost/TWAMM

pragma solidity ^0.8.9;

import "./interfaces/IPair.sol";
import "./interfaces/IFactory.sol";
import "./libraries/LongTermOrders.sol";
import "./libraries/BinarySearchTree.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@rari-capital/solmate/src/utils/ReentrancyGuard.sol";
import "prb-math/contracts/PRBMathUD60x18.sol";

contract Pair is IPair, ERC20, ReentrancyGuard {
    using LongTermOrdersLib for LongTermOrdersLib.LongTermOrders;
    using BinarySearchTreeLib for BinarySearchTreeLib.Tree;
    using SafeERC20 for IERC20;
    using PRBMathUD60x18 for uint256;

    address public override factory;
    address public override tokenA;
    address public override tokenB;
    address private twamm;
    uint256 public override rootKLast;

    ///@notice fee for LP providers, 4 decimal places, i.e. 30 = 0.3%
    uint256 public constant LP_FEE = 30;

    ///@notice interval between blocks that are eligible for order expiry
    uint256 public constant orderBlockInterval = 5;

    ///@notice map token addresses to current amm reserves
    mapping(address => uint256) public override reserveMap;

    ///@notice data structure to handle long term orders
    LongTermOrdersLib.LongTermOrders internal longTermOrders;

    constructor(
        address _tokenA,
        address _tokenB,
        address _twamm
    ) ERC20("Pulsar-LP", "PUL-LP") {
        factory = msg.sender;
        tokenA = _tokenA;
        tokenB = _tokenB;
        twamm = _twamm;
        longTermOrders.initialize(
            tokenA,
            tokenB,
            twamm,
            block.number,
            orderBlockInterval
        );
    }

    ///@notice pair contract caller check
    modifier checkCaller() {
        require(msg.sender == twamm, "Invalid Caller");
        _;
    }

    ///@notice get tokenA reserves
    function tokenAReserves() public view override returns (uint256) {
        return reserveMap[tokenA];
    }

    ///@notice get tokenB reserves
    function tokenBReserves() public view override returns (uint256) {
        return reserveMap[tokenB];
    }

    ///@notice get LP total supply
    function getTotalSupply() public view override returns (uint256) {
        return totalSupply();
    }

    // if fee is on, mint liquidity equivalent to 1/(feeArg+1)th of the growth in sqrt(k)
    function mintFee(
        uint256 reserveA,
        uint256 reserveB
    ) private returns (bool feeOn) {
        uint32 feeArg = IFactory(factory).feeArg();
        address feeTo = IFactory(factory).feeTo();
        feeOn = feeTo != address(0);

        if (feeOn) {
            if (rootKLast != 0) {
                uint256 rootK = reserveA
                    .fromUint()
                    .sqrt()
                    .mul(reserveB.fromUint().sqrt())
                    .toUint();
                if (rootK > rootKLast) {
                    uint256 numerator = totalSupply() * (rootK - rootKLast);
                    uint256 denominator = rootK * feeArg + rootKLast;
                    uint256 liquidity = numerator / denominator;
                    if (liquidity > 0) _mint(feeTo, liquidity);
                }
            }
        } else if (rootKLast != 0) {
            rootKLast = 0;
        }
    }

    ///@notice provide initial liquidity to the amm. This sets the relative price between tokens
    function provideInitialLiquidity(
        address to,
        uint256 amountA,
        uint256 amountB
    )
        external
        override
        checkCaller
        nonReentrant
        returns (uint256 lpTokenAmount)
    {
        require(amountA > 0 && amountB > 0, "Invalid Amount");
        require(totalSupply() == 0, "Liquidity Has Already Been Provided");

        reserveMap[tokenA] = amountA;
        reserveMap[tokenB] = amountB;

        //initial LP amount is the geometric mean of supplied tokens
        lpTokenAmount = amountA
            .fromUint()
            .sqrt()
            .mul(amountB.fromUint().sqrt())
            .toUint();

        bool feeOn = mintFee(0, 0);
        _mint(to, lpTokenAmount);

        if (feeOn) rootKLast = lpTokenAmount;
        emit InitialLiquidityProvided(to, lpTokenAmount, amountA, amountB);
    }

    ///@notice provide liquidity to the AMM
    ///@param lpTokenAmount number of lp tokens to mint with new liquidity
    function provideLiquidity(
        address to,
        uint256 lpTokenAmount
    )
        external
        override
        checkCaller
        nonReentrant
        returns (uint256 amountAIn, uint256 amountBIn)
    {
        //execute virtual orders
        longTermOrders.executeVirtualOrdersUntilSpecifiedBlock(
            reserveMap,
            block.number
        );

        require(lpTokenAmount > 0, "Invalid Amount");
        require(totalSupply() != 0, "No Liquidity Has Been Provided Yet");

        uint256 reserveA = reserveMap[tokenA];
        uint256 reserveB = reserveMap[tokenB];

        //the ratio between the number of underlying tokens and the number of lp tokens must remain invariant after mint
        amountAIn = (lpTokenAmount * reserveA) / totalSupply();
        amountBIn = (lpTokenAmount * reserveB) / totalSupply();

        reserveMap[tokenA] += amountAIn;
        reserveMap[tokenB] += amountBIn;

        bool feeOn = mintFee(reserveA, reserveB);
        _mint(to, lpTokenAmount);

        if (feeOn)
            rootKLast = reserveMap[tokenA]
                .fromUint()
                .sqrt()
                .mul(reserveMap[tokenB].fromUint().sqrt())
                .toUint();
        emit LiquidityProvided(to, lpTokenAmount, amountAIn, amountBIn);
    }

    ///@notice remove liquidity to the AMM
    ///@param lpTokenAmount number of lp tokens to burn
    function removeLiquidity(
        address to,
        uint256 lpTokenAmount
    )
        external
        override
        checkCaller
        nonReentrant
        returns (uint256 amountAOut, uint256 amountBOut)
    {
        //execute virtual orders
        longTermOrders.executeVirtualOrdersUntilSpecifiedBlock(
            reserveMap,
            block.number
        );

        require(lpTokenAmount > 0, "Invalid Amount");
        require(
            lpTokenAmount < totalSupply(),
            "Not Enough Lp Tokens Available"
        );

        uint256 reserveA = reserveMap[tokenA];
        uint256 reserveB = reserveMap[tokenB];

        //the ratio between the number of underlying tokens and the number of lp tokens must remain invariant after burn
        amountAOut = (reserveA * lpTokenAmount) / totalSupply();
        amountBOut = (reserveB * lpTokenAmount) / totalSupply();

        reserveMap[tokenA] -= amountAOut;
        reserveMap[tokenB] -= amountBOut;

        bool feeOn = mintFee(reserveA, reserveB);
        _burn(to, lpTokenAmount);

        IERC20(tokenA).safeTransfer(twamm, amountAOut);
        IERC20(tokenB).safeTransfer(twamm, amountBOut);

        if (feeOn)
            rootKLast = reserveMap[tokenA]
                .fromUint()
                .sqrt()
                .mul(reserveMap[tokenB].fromUint().sqrt())
                .toUint();
        emit LiquidityRemoved(to, lpTokenAmount, amountAOut, amountBOut);
    }

    ///@notice instant swap a given amount of tokenA against embedded amm
    function instantSwapFromAToB(
        address sender,
        uint256 amountAIn
    ) external override checkCaller nonReentrant returns (uint256 amountBOut) {
        require(
            reserveMap[tokenA] > 0 && reserveMap[tokenB] > 0,
            "Insufficient Liquidity"
        );
        require(amountAIn > 0, "Invalid Amount");
        amountBOut = performInstantSwap(tokenA, tokenB, amountAIn);

        emit InstantSwapAToB(sender, amountAIn, amountBOut);
    }

    ///@notice create a long term order to swap from tokenA
    ///@param amountAIn total amount of token A to swap
    ///@param numberOfBlockIntervals number of block intervals over which to execute long term order
    function longTermSwapFromAToB(
        address sender,
        uint256 amountAIn,
        uint256 numberOfBlockIntervals
    ) external override checkCaller nonReentrant returns (uint256 orderId) {
        require(
            reserveMap[tokenA] > 0 && reserveMap[tokenB] > 0,
            "Insufficient Liquidity"
        );
        require(amountAIn > 0, "Invalid Amount");
        orderId = longTermOrders.longTermSwapFromAToB(
            sender,
            amountAIn,
            numberOfBlockIntervals,
            reserveMap
        );

        emit LongTermSwapAToB(sender, amountAIn, orderId);
    }

    ///@notice instant swap a given amount of tokenB against embedded amm
    function instantSwapFromBToA(
        address sender,
        uint256 amountBIn
    ) external override checkCaller nonReentrant returns (uint256 amountAOut) {
        require(
            reserveMap[tokenA] > 0 && reserveMap[tokenB] > 0,
            "Insufficient Liquidity"
        );
        require(amountBIn > 0, "Invalid Amount");
        amountAOut = performInstantSwap(tokenB, tokenA, amountBIn);

        emit InstantSwapBToA(sender, amountBIn, amountAOut);
    }

    ///@notice create a long term order to swap from tokenB
    ///@param amountBIn total amount of tokenB to swap
    ///@param numberOfBlockIntervals number of block intervals over which to execute long term order
    function longTermSwapFromBToA(
        address sender,
        uint256 amountBIn,
        uint256 numberOfBlockIntervals
    ) external override checkCaller nonReentrant returns (uint256 orderId) {
        require(
            reserveMap[tokenA] > 0 && reserveMap[tokenB] > 0,
            "Insufficient Liquidity"
        );
        require(amountBIn > 0, "Invalid Amount");
        orderId = longTermOrders.longTermSwapFromBToA(
            sender,
            amountBIn,
            numberOfBlockIntervals,
            reserveMap
        );

        emit LongTermSwapBToA(sender, amountBIn, orderId);
    }

    ///@notice stop the execution of a long term order
    function cancelLongTermSwap(
        address sender,
        uint256 orderId
    )
        external
        override
        checkCaller
        nonReentrant
        returns (uint256 unsoldAmount, uint256 purchasedAmount)
    {
        (unsoldAmount, purchasedAmount) = longTermOrders.cancelLongTermSwap(
            sender,
            orderId,
            reserveMap
        );

        emit CancelLongTermOrder(
            sender,
            orderId,
            unsoldAmount,
            purchasedAmount
        );
    }

    ///@notice withdraw proceeds from a long term swap
    function withdrawProceedsFromLongTermSwap(
        address sender,
        uint256 orderId
    ) external override checkCaller nonReentrant returns (uint256 proceeds) {
        proceeds = longTermOrders.withdrawProceedsFromLongTermSwap(
            sender,
            orderId,
            reserveMap
        );

        emit WithdrawProceedsFromLongTermOrder(sender, orderId, proceeds);
    }

    ///@notice private function which implements instant swap logic
    function performInstantSwap(
        address from,
        address to,
        uint256 amountIn
    ) private checkCaller returns (uint256 amountOutMinusFee) {
        //execute virtual orders
        longTermOrders.executeVirtualOrdersUntilSpecifiedBlock(
            reserveMap,
            block.number
        );

        uint256 reserveFrom = reserveMap[from];
        uint256 reserveTo = reserveMap[to];
        //constant product formula
        uint256 amountOut = (reserveTo * amountIn) / (reserveFrom + amountIn);

        //charge LP fee
        amountOutMinusFee = (amountOut * (10000 - LP_FEE)) / 10000;

        reserveMap[from] += amountIn;
        reserveMap[to] -= amountOutMinusFee;

        IERC20(to).safeTransfer(twamm, amountOutMinusFee);
    }

    ///@notice get pair orders total amount
    function getPairOrdersAmount() external view override returns (uint256) {
        return longTermOrders.orderId;
    }

    ///@notice get user order details
    function getOrderDetails(
        uint256 orderId
    ) external view override returns (LongTermOrdersLib.Order memory) {
        return longTermOrders.orderMap[orderId];
    }

    ///@notice returns the user order reward factor
    function getOrderRewardFactor(
        uint256 orderId
    )
        external
        view
        override
        returns (
            uint256 orderRewardFactorAtSubmission,
            uint256 orderRewardFactorAtExpiring
        )
    {
        address orderSellToken = longTermOrders.orderMap[orderId].sellTokenId;
        uint256 orderExpirationBlock = longTermOrders
            .orderMap[orderId]
            .expirationBlock;
        orderRewardFactorAtSubmission = longTermOrders
            .OrderPoolMap[orderSellToken]
            .rewardFactorAtSubmission[orderId];
        orderRewardFactorAtExpiring = longTermOrders
            .OrderPoolMap[orderSellToken]
            .rewardFactorAtBlock[orderExpirationBlock];
    }

    ///@notice returns the current state of the twamm
    function getTWAMMState()
        external
        view
        override
        returns (
            uint256 lastVirtualOrderBlock,
            uint256 tokenASalesRate,
            uint256 tokenBSalesRate,
            uint256 orderPoolARewardFactor,
            uint256 orderPoolBRewardFactor
        )
    {
        lastVirtualOrderBlock = longTermOrders.lastVirtualOrderBlock;
        tokenASalesRate = longTermOrders.OrderPoolMap[tokenA].currentSalesRate;
        tokenBSalesRate = longTermOrders.OrderPoolMap[tokenB].currentSalesRate;
        orderPoolARewardFactor = longTermOrders
            .OrderPoolMap[tokenA]
            .rewardFactor;
        orderPoolBRewardFactor = longTermOrders
            .OrderPoolMap[tokenB]
            .rewardFactor;
    }

    ///@notice returns cumulative sales rate of orders ending on this block number
    function getTWAMMSalesRateEnding(
        uint256 blockNumber
    )
        external
        view
        override
        returns (
            uint256 orderPoolASalesRateEnding,
            uint256 orderPoolBSalesRateEnding
        )
    {
        orderPoolASalesRateEnding = longTermOrders
            .OrderPoolMap[tokenA]
            .salesRateEndingPerBlock[blockNumber];
        orderPoolBSalesRateEnding = longTermOrders
            .OrderPoolMap[tokenB]
            .salesRateEndingPerBlock[blockNumber];
    }

    ///@notice returns expiries list since last executed
    function getExpiriesSinceLastExecuted()
        external
        view
        override
        returns (uint256[] memory)
    {
        return
            longTermOrders
                .expiryBlockTreeSinceLastExecution
                .getFutureExpiriesList();
    }

    ///@notice get user orderIds
    function userIdsCheck(
        address userAddress
    ) external view override returns (uint256[] memory) {
        return longTermOrders.orderIdMap[userAddress];
    }

    ///@notice get user order status based on Ids
    function orderIdStatusCheck(
        uint256 orderId
    ) external view override returns (bool) {
        return longTermOrders.orderIdStatusMap[orderId];
    }

    ///@notice convenience function to execute virtual orders. Note that this already happens
    ///before most interactions with the AMM
    function executeVirtualOrders(uint256 blockNumber) public override {
        longTermOrders.executeVirtualOrdersUntilSpecifiedBlock(
            reserveMap,
            blockNumber
        );
    }
}

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

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

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

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

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

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

File 5 of 18 : IPair.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

import "../libraries/LongTermOrders.sol";

interface IPair {
    function factory() external view returns (address);

    function tokenA() external view returns (address);

    function tokenB() external view returns (address);

    function rootKLast() external view returns (uint256);

    function LP_FEE() external pure returns (uint256);

    function orderBlockInterval() external pure returns (uint256);

    function reserveMap(address) external view returns (uint256);

    function tokenAReserves() external view returns (uint256);

    function tokenBReserves() external view returns (uint256);

    function getTotalSupply() external view returns (uint256);

    event InitialLiquidityProvided(
        address indexed addr,
        uint256 lpTokenAmount,
        uint256 amountA,
        uint256 amountB
    );
    event LiquidityProvided(
        address indexed addr,
        uint256 lpTokenAmount,
        uint256 amountAIn,
        uint256 amountBIn
    );
    event LiquidityRemoved(
        address indexed addr,
        uint256 lpTokenAmount,
        uint256 amountAOut,
        uint256 amountBOut
    );
    event InstantSwapAToB(
        address indexed addr,
        uint256 amountAIn,
        uint256 amountBOut
    );
    event InstantSwapBToA(
        address indexed addr,
        uint256 amountBIn,
        uint256 amountAOut
    );
    event LongTermSwapAToB(
        address indexed addr,
        uint256 amountAIn,
        uint256 orderId
    );
    event LongTermSwapBToA(
        address indexed addr,
        uint256 amountBIn,
        uint256 orderId
    );
    event CancelLongTermOrder(
        address indexed addr,
        uint256 orderId,
        uint256 unsoldAmount,
        uint256 purchasedAmount
    );
    event WithdrawProceedsFromLongTermOrder(
        address indexed addr,
        uint256 orderId,
        uint256 proceeds
    );

    function provideInitialLiquidity(
        address to,
        uint256 amountA,
        uint256 amountB
    ) external returns (uint256 lpTokenAmount);

    function provideLiquidity(
        address to,
        uint256 lpTokenAmount
    ) external returns (uint256 amountAIn, uint256 amountBIn);

    function removeLiquidity(
        address to,
        uint256 lpTokenAmount
    ) external returns (uint256 amountAOut, uint256 amountBOut);

    function instantSwapFromAToB(
        address sender,
        uint256 amountAIn
    ) external returns (uint256 amountBOut);

    function longTermSwapFromAToB(
        address sender,
        uint256 amountAIn,
        uint256 numberOfBlockIntervals
    ) external returns (uint256 orderId);

    function instantSwapFromBToA(
        address sender,
        uint256 amountBIn
    ) external returns (uint256 amountAOut);

    function longTermSwapFromBToA(
        address sender,
        uint256 amountBIn,
        uint256 numberOfBlockIntervals
    ) external returns (uint256 orderId);

    function cancelLongTermSwap(
        address sender,
        uint256 orderId
    ) external returns (uint256 unsoldAmount, uint256 purchasedAmount);

    function withdrawProceedsFromLongTermSwap(
        address sender,
        uint256 orderId
    ) external returns (uint256 proceeds);

    function getPairOrdersAmount() external view returns (uint256);

    function getOrderDetails(
        uint256 orderId
    ) external view returns (LongTermOrdersLib.Order memory);

    function getOrderRewardFactor(
        uint256 orderId
    )
        external
        view
        returns (
            uint256 orderRewardFactorAtSubmission,
            uint256 orderRewardFactorAtExpiring
        );

    function getTWAMMState()
        external
        view
        returns (
            uint256 lastVirtualOrderBlock,
            uint256 tokenASalesRate,
            uint256 tokenBSalesRate,
            uint256 orderPoolARewardFactor,
            uint256 orderPoolBRewardFactor
        );

    function getTWAMMSalesRateEnding(
        uint256 blockNumber
    )
        external
        view
        returns (
            uint256 orderPoolASalesRateEnding,
            uint256 orderPoolBSalesRateEnding
        );

    function getExpiriesSinceLastExecuted()
        external
        view
        returns (uint256[] memory);

    function userIdsCheck(
        address userAddress
    ) external view returns (uint256[] memory);

    function orderIdStatusCheck(uint256 orderId) external view returns (bool);

    function executeVirtualOrders(uint256 blockNumber) external;
}

File 6 of 18 : LongTermOrders.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
// import "prb-math/contracts/PRBMathSD59x18.sol";
import "./OrderPool.sol";
import "./BinarySearchTree.sol";

///@notice This library handles the state and execution of long term orders.
library LongTermOrdersLib {
    //using PRBMathSD59x18 for int256;
    using OrderPoolLib for OrderPoolLib.OrderPool;
    using BinarySearchTreeLib for BinarySearchTreeLib.Tree;
    using SafeERC20 for IERC20;

    ///@notice fee for LP providers, 4 decimal places, i.e. 30 = 0.3%
    uint256 public constant LP_FEE = 30;

    ///@notice information associated with a long term order
    struct Order {
        uint256 id;
        uint256 submitBlock;
        uint256 expirationBlock;
        uint256 saleRate;
        uint256 sellAmount;
        uint256 buyAmount;
        address owner;
        address sellTokenId;
        address buyTokenId;
    }

    ///@notice structure contains full state related to long term orders
    struct LongTermOrders {
        ///@notice minimum block interval between order expiries
        uint256 orderBlockInterval;
        ///@notice last virtual orders were executed immediately before this block
        uint256 lastVirtualOrderBlock;
        ///@notice token pair being traded in embedded amm
        address tokenA;
        address tokenB;
        ///@notice useful addresses for TWAMM transactions
        address refTWAMM;
        ///@notice mapping from token address to pool that is selling that token
        ///we maintain two order pools, one for each token that is tradable in the AMM
        mapping(address => OrderPoolLib.OrderPool) OrderPoolMap;
        ///@notice incrementing counter for order ids
        uint256 orderId;
        ///@notice mapping from order ids to Orders
        mapping(uint256 => Order) orderMap;
        ///@notice mapping from account address to its corresponding list of order ids
        mapping(address => uint256[]) orderIdMap;
        ///@notice mapping from order id to its status (false for nonactive true for active)
        mapping(uint256 => bool) orderIdStatusMap;
        ///@notice record all expiry blocks since the latest executed block
        BinarySearchTreeLib.Tree expiryBlockTreeSinceLastExecution;
    }

    ///@notice initialize state
    function initialize(
        LongTermOrders storage self,
        address tokenA,
        address tokenB,
        address refTWAMM,
        uint256 lastVirtualOrderBlock,
        uint256 orderBlockInterval
    ) public {
        self.tokenA = tokenA;
        self.tokenB = tokenB;
        self.refTWAMM = refTWAMM;
        self.lastVirtualOrderBlock = lastVirtualOrderBlock;
        self.orderBlockInterval = orderBlockInterval;
        self.expiryBlockTreeSinceLastExecution.insert(
            lastVirtualOrderBlock - (lastVirtualOrderBlock % orderBlockInterval)
        );
    }

    ///@notice long term swap token A for token B. Amount represents total amount being sold, numberOfBlockIntervals determines when order expires
    function longTermSwapFromAToB(
        LongTermOrders storage self,
        address sender,
        uint256 amountA,
        uint256 numberOfBlockIntervals,
        mapping(address => uint256) storage reserveMap
    ) public returns (uint256) {
        return
            performLongTermSwap(
                self,
                self.tokenA,
                self.tokenB,
                sender,
                amountA,
                numberOfBlockIntervals,
                reserveMap
            );
    }

    ///@notice long term swap token B for token A. Amount represents total amount being sold, numberOfBlockIntervals determines when order expires
    function longTermSwapFromBToA(
        LongTermOrders storage self,
        address sender,
        uint256 amountB,
        uint256 numberOfBlockIntervals,
        mapping(address => uint256) storage reserveMap
    ) public returns (uint256) {
        return
            performLongTermSwap(
                self,
                self.tokenB,
                self.tokenA,
                sender,
                amountB,
                numberOfBlockIntervals,
                reserveMap
            );
    }

    ///@notice adds long term swap to order pool
    function performLongTermSwap(
        LongTermOrders storage self,
        address from,
        address to,
        address sender,
        uint256 amount,
        uint256 numberOfBlockIntervals,
        mapping(address => uint256) storage reserveMap
    ) private returns (uint256) {
        //determine the selling rate based on number of blocks to expiry and total amount
        uint256 currentBlock = block.number;
        uint256 lastExpiryBlock = currentBlock -
            (currentBlock % self.orderBlockInterval);
        uint256 orderExpiry = self.orderBlockInterval *
            (numberOfBlockIntervals + 1) +
            lastExpiryBlock;
        uint256 sellingRate = (amount * 10000) / (orderExpiry - currentBlock); //multiply by 10000 to reduce precision loss

        //insert order expiry and update virtual order state
        self.expiryBlockTreeSinceLastExecution.insert(orderExpiry);
        executeVirtualOrdersUntilSpecifiedBlock(self, reserveMap, block.number);

        //add order to correct pool
        OrderPoolLib.OrderPool storage OrderPool = self.OrderPoolMap[from];
        OrderPool.depositOrder(self.orderId, sellingRate, orderExpiry);

        //add to order map
        self.orderMap[self.orderId] = Order(
            self.orderId,
            currentBlock,
            orderExpiry,
            sellingRate,
            0,
            0,
            sender,
            from,
            to
        );

        // add user's corresponding orderId to orderId mapping list content
        self.orderIdMap[sender].push(self.orderId);

        self.orderIdStatusMap[self.orderId] = true;

        return self.orderId++;
    }

    ///@notice cancel long term swap, pay out unsold tokens and well as purchased tokens
    function cancelLongTermSwap(
        LongTermOrders storage self,
        address sender,
        uint256 orderId,
        mapping(address => uint256) storage reserveMap
    ) public returns (uint256, uint256) {
        //update virtual order state
        executeVirtualOrdersUntilSpecifiedBlock(self, reserveMap, block.number);

        Order storage order = self.orderMap[orderId];

        require(self.orderIdStatusMap[orderId] == true, "Order Invalid");
        require(order.owner == sender, "Sender Must Be Order Owner");

        OrderPoolLib.OrderPool storage OrderPoolSell = self.OrderPoolMap[
            order.sellTokenId
        ];
        OrderPoolLib.OrderPool storage OrderPoolBuy = self.OrderPoolMap[
            order.buyTokenId
        ];

        (uint256 unsoldAmount, uint256 purchasedAmount) = OrderPoolSell
            .cancelOrder(orderId);
        require(
            unsoldAmount > 0 || purchasedAmount > 0,
            "No Proceeds To Withdraw"
        );

        order.sellAmount =
            ((block.number - order.submitBlock) * order.saleRate) /
            10000;
        order.buyAmount += purchasedAmount;

        if (
            OrderPoolSell.salesRateEndingPerBlock[order.expirationBlock] == 0 &&
            OrderPoolBuy.salesRateEndingPerBlock[order.expirationBlock] == 0
        ) {
            self.expiryBlockTreeSinceLastExecution.deleteNode(
                order.expirationBlock
            );
        }

        // delete orderId from account list
        self.orderIdStatusMap[orderId] = false;

        //transfer to owner
        IERC20(order.buyTokenId).safeTransfer(self.refTWAMM, purchasedAmount);
        IERC20(order.sellTokenId).safeTransfer(self.refTWAMM, unsoldAmount);

        return (unsoldAmount, purchasedAmount);
    }

    ///@notice withdraw proceeds from a long term swap (can be expired or ongoing)
    function withdrawProceedsFromLongTermSwap(
        LongTermOrders storage self,
        address sender,
        uint256 orderId,
        mapping(address => uint256) storage reserveMap
    ) public returns (uint256) {
        //update virtual order state
        executeVirtualOrdersUntilSpecifiedBlock(self, reserveMap, block.number);

        Order storage order = self.orderMap[orderId];

        require(self.orderIdStatusMap[orderId] == true, "Order Invalid");
        require(order.owner == sender, "Sender Must Be Order Owner");

        OrderPoolLib.OrderPool storage OrderPool = self.OrderPoolMap[
            order.sellTokenId
        ];
        uint256 proceeds = OrderPool.withdrawProceeds(orderId);
        require(proceeds > 0, "No Proceeds To Withdraw");

        order.buyAmount += proceeds;

        if (order.expirationBlock <= block.number) {
            // delete orderId from account list
            self.orderIdStatusMap[orderId] = false;
            order.sellAmount =
                ((order.expirationBlock - order.submitBlock) * order.saleRate) /
                10000;
        } else {
            order.sellAmount =
                ((block.number - order.submitBlock) * order.saleRate) /
                10000;
        }

        //transfer to owner
        IERC20(order.buyTokenId).safeTransfer(self.refTWAMM, proceeds);

        return proceeds;
    }

    ///@notice executes all virtual orders between current lastVirtualOrderBlock and blockNumber
    //also handles orders that expire at end of final block. This assumes that no orders expire inside the given interval
    function executeVirtualTradesAndOrderExpiries(
        LongTermOrders storage self,
        mapping(address => uint256) storage reserveMap,
        uint256 blockNumber
    ) private {
        //amount sold from virtual trades
        uint256 blockNumberIncrement = blockNumber - self.lastVirtualOrderBlock;
        uint256 tokenASellAmount = (self
            .OrderPoolMap[self.tokenA]
            .currentSalesRate * blockNumberIncrement) / 10000;
        uint256 tokenBSellAmount = (self
            .OrderPoolMap[self.tokenB]
            .currentSalesRate * blockNumberIncrement) / 10000;

        //initial amm balance
        uint256 tokenAStart = reserveMap[self.tokenA];
        uint256 tokenBStart = reserveMap[self.tokenB];

        //updated balances from sales
        (
            uint256 tokenAOut,
            uint256 tokenBOut,
            uint256 ammEndTokenA,
            uint256 ammEndTokenB
        ) = computeVirtualBalances(
                tokenAStart,
                tokenBStart,
                tokenASellAmount,
                tokenBSellAmount
            );

        //charge LP fee
        ammEndTokenA += (tokenAOut * LP_FEE) / 10000;
        ammEndTokenB += (tokenBOut * LP_FEE) / 10000;

        tokenAOut = (tokenAOut * (10000 - LP_FEE)) / 10000;
        tokenBOut = (tokenBOut * (10000 - LP_FEE)) / 10000;

        //update balances reserves
        reserveMap[self.tokenA] = ammEndTokenA;
        reserveMap[self.tokenB] = ammEndTokenB;

        //distribute proceeds to pools
        OrderPoolLib.OrderPool storage OrderPoolA = self.OrderPoolMap[
            self.tokenA
        ];
        OrderPoolLib.OrderPool storage OrderPoolB = self.OrderPoolMap[
            self.tokenB
        ];

        OrderPoolA.distributePayment(tokenBOut);
        OrderPoolB.distributePayment(tokenAOut);

        //handle orders expiring at end of interval
        OrderPoolA.updateStateFromBlockExpiry(blockNumber);
        OrderPoolB.updateStateFromBlockExpiry(blockNumber);

        //update last virtual trade block
        self.lastVirtualOrderBlock = blockNumber;
    }

    ///@notice executes all virtual orders until specified block, includ current block.
    function executeVirtualOrdersUntilSpecifiedBlock(
        LongTermOrders storage self,
        mapping(address => uint256) storage reserveMap,
        uint256 blockNumber
    ) public {
        require(
            blockNumber <= block.number &&
                blockNumber >= self.lastVirtualOrderBlock,
            "Specified Block Number Invalid!"
        );

        OrderPoolLib.OrderPool storage OrderPoolA = self.OrderPoolMap[
            self.tokenA
        ];
        OrderPoolLib.OrderPool storage OrderPoolB = self.OrderPoolMap[
            self.tokenB
        ];

        // get list of expiryBlocks given points that are divisible by int blockInterval
        // then trim the tree to have root tree to be node correponding to the last argument (%5=0)
        self.expiryBlockTreeSinceLastExecution.processExpiriesListNTrimTree(
            self.lastVirtualOrderBlock -
                (self.lastVirtualOrderBlock % self.orderBlockInterval),
            blockNumber - (blockNumber % self.orderBlockInterval)
        );
        uint256[] storage expiriesList = self
            .expiryBlockTreeSinceLastExecution
            .getExpiriesList();

        for (uint256 i = 0; i < expiriesList.length; i++) {
            if (
                (OrderPoolA.salesRateEndingPerBlock[expiriesList[i]] > 0 ||
                    OrderPoolB.salesRateEndingPerBlock[expiriesList[i]] > 0) &&
                (expiriesList[i] > self.lastVirtualOrderBlock &&
                    expiriesList[i] < blockNumber)
            ) {
                executeVirtualTradesAndOrderExpiries(
                    self,
                    reserveMap,
                    expiriesList[i]
                );
            }
        }

        executeVirtualTradesAndOrderExpiries(self, reserveMap, blockNumber);
    }

    ///@notice computes the result of virtual trades by the token pools
    function computeVirtualBalances(
        uint256 tokenAStart,
        uint256 tokenBStart,
        uint256 tokenAIn,
        uint256 tokenBIn
    )
        private
        pure
        returns (
            uint256 tokenAOut,
            uint256 tokenBOut,
            uint256 ammEndTokenA,
            uint256 ammEndTokenB
        )
    {
        // if (
        //     tokenAStart == 0 ||
        //     tokenBStart == 0 ||
        //     tokenAIn == 0 ||
        //     tokenBIn == 0
        // ) {
        //     //in the case where only one pool is selling, we just perform a normal swap
        //constant product formula
        tokenAOut =
            ((tokenAStart + tokenAIn) * tokenBIn) /
            (tokenBStart + tokenBIn);
        tokenBOut =
            ((tokenBStart + tokenBIn) * tokenAIn) /
            (tokenAStart + tokenAIn);
        ammEndTokenA = tokenAStart + tokenAIn - tokenAOut;
        ammEndTokenB = tokenBStart + tokenBIn - tokenBOut;
    }
    //     //when both pools sell, we use the TWAMM formula
    //     else {
    //         //signed, fixed point arithmetic
    //         int256 aIn = int256(tokenAIn).fromInt();
    //         int256 bIn = int256(tokenBIn).fromInt();
    //         int256 aStart = int256(tokenAStart).fromInt();
    //         int256 bStart = int256(tokenBStart).fromInt();
    //         int256 k = aStart.mul(bStart);

    //         int256 c = computeC(aStart, bStart, aIn, bIn);
    //         int256 endA = computeAmmEndTokenA(aIn, bIn, c, k, aStart, bStart);
    //         int256 endB = aStart.div(endA).mul(bStart);

    //         int256 outA = aStart + aIn - endA;
    //         int256 outB = bStart + bIn - endB;
    //         require(outA >= 0 && outB >= 0, "Invalid Amount");

    //         return (
    //             uint256(outA.toInt()),
    //             uint256(outB.toInt()),
    //             uint256(endA.toInt()),
    //             uint256(endB.toInt())
    //         );
    //     }
    // }

    // //helper function for TWAMM formula computation, helps avoid stack depth errors
    // function computeC(
    //     int256 tokenAStart,
    //     int256 tokenBStart,
    //     int256 tokenAIn,
    //     int256 tokenBIn
    // ) private pure returns (int256 c) {
    //     int256 c1 = tokenAStart.sqrt().mul(tokenBIn.sqrt());
    //     int256 c2 = tokenBStart.sqrt().mul(tokenAIn.sqrt());
    //     int256 cNumerator = c1 - c2;
    //     int256 cDenominator = c1 + c2;
    //     c = cNumerator.div(cDenominator);
    // }

    // //helper function for TWAMM formula computation, helps avoid stack depth errors
    // function computeAmmEndTokenA(
    //     int256 tokenAIn,
    //     int256 tokenBIn,
    //     int256 c,
    //     int256 k,
    //     int256 aStart,
    //     int256 bStart
    // ) private pure returns (int256 ammEndTokenA) {
    //     //rearranged for numerical stability
    //     int256 eNumerator = PRBMathSD59x18.fromInt(4).mul(tokenAIn).sqrt().mul(
    //         tokenBIn.sqrt()
    //     );
    //     int256 eDenominator = aStart.sqrt().mul(bStart.sqrt()).inv();
    //     int256 exponent = eNumerator.mul(eDenominator).exp();
    //     require(exponent > PRBMathSD59x18.abs(c), "Invalid Amount");
    //     int256 fraction = (exponent + c).div(exponent - c);
    //     int256 scaling = k.div(tokenBIn).sqrt().mul(tokenAIn.sqrt());
    //     ammEndTokenA = fraction.mul(scaling);
    // }
}

File 7 of 18 : BinarySearchTree.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

library BinarySearchTreeLib {
    uint256 private constant TIME_EXTENSION = 50400;

    struct Node {
        uint256 parent;
        uint256 value;
        uint256 left;
        uint256 right;
    }

    struct Tree {
        uint256 root;
        uint256 rootLast;
        mapping(uint256 => Node) nodes;
        mapping(uint256 => uint256[]) rootToList;
        mapping(uint256 => uint256[]) futureExpiries; //map from last divisible root to a list of exipiries sine that root. not ordered
    }

    // helper function for insert
    function insertHelper(
        Tree storage self,
        uint256 newValue,
        uint256 nodeId
    ) public {
        // current node
        Node memory curNode = self.nodes[nodeId];
        // if value exists, no need to insert
        if (newValue != curNode.value) {
            if (newValue < curNode.value) {
                if (curNode.left == 0) {
                    self.nodes[curNode.value].left = newValue;
                    self.nodes[newValue] = Node(curNode.value, newValue, 0, 0);
                } else {
                    insertHelper(self, newValue, curNode.left);
                }
            } else {
                if (curNode.right == 0) {
                    self.nodes[curNode.value].right = newValue;
                    self.nodes[newValue] = Node(curNode.value, newValue, 0, 0);
                } else {
                    insertHelper(self, newValue, curNode.right);
                }
            }
        }
    }

    function insert(Tree storage self, uint256 newValue) public {
        // no tree exists
        if (self.root == 0) {
            self.root = newValue;
            self.rootLast = newValue;
            self.nodes[newValue] = Node(0, newValue, 0, 0);
            self.futureExpiries[self.root].push(newValue);
        } else {
            insertHelper(self, newValue, self.root);
        }
    }

    function returnListHelperEx(
        Tree storage self,
        uint256 start,
        uint256 end,
        uint256 nodeId,
        uint256 extension
    ) public {
        if (start <= end && end < extension) {
            // current node
            Node memory curNode = self.nodes[nodeId];
            if (curNode.value != 0) {
                if (curNode.value > start) {
                    returnListHelperEx(
                        self,
                        start,
                        end,
                        curNode.left,
                        extension
                    );
                }

                if (curNode.value <= end && curNode.value >= start) {
                    if (
                        self.rootToList[self.root].length == 0 ||
                        (self.rootToList[self.root].length > 0 &&
                            self.rootToList[self.root][
                                self.rootToList[self.root].length - 1
                            ] !=
                            curNode.value)
                    ) {
                        self.rootToList[self.root].push(curNode.value);
                    }
                }

                if (curNode.value <= extension && curNode.value > end) {
                    if (
                        self.futureExpiries[self.root].length == 0 ||
                        (self.futureExpiries[self.root].length > 0 &&
                            self.futureExpiries[self.root][
                                self.futureExpiries[self.root].length - 1
                            ] !=
                            curNode.value)
                    ) {
                        self.futureExpiries[self.root].push(curNode.value);
                    }
                }

                if (curNode.value < extension) {
                    returnListHelperEx(
                        self,
                        start,
                        end,
                        curNode.right,
                        extension
                    );
                }
            }
        }
    }

    function deleteNodeHelper(
        Tree storage self,
        uint256 deleteValue,
        uint256 nodeId
    ) public returns (uint256 newValue) {
        Node memory curNode = self.nodes[nodeId];
        if (curNode.value == deleteValue) {
            newValue = deleteLeaf(self, curNode.value);
        } else if (curNode.value < deleteValue) {
            if (curNode.right == 0) {
                newValue = 0;
            } else {
                newValue = deleteNodeHelper(self, deleteValue, curNode.right);
            }
        } else {
            if (curNode.left == 0) {
                newValue = 0;
            } else {
                newValue = deleteNodeHelper(self, deleteValue, curNode.left);
            }
        }
    }

    function deleteLeaf(
        Tree storage self,
        uint256 nodeId
    ) public returns (uint256 newNodeId) {
        Node memory curNode = self.nodes[nodeId];
        if (curNode.left != 0) {
            uint256 tempValue = curNode.left;
            while (self.nodes[tempValue].right != 0) {
                tempValue = self.nodes[tempValue].right;
            }
            if (tempValue != curNode.left) {
                if (curNode.parent != 0) {
                    if (curNode.value < curNode.parent) {
                        self.nodes[curNode.parent].left = tempValue;
                    } else {
                        self.nodes[curNode.parent].right = tempValue;
                    }
                }

                if (curNode.right != 0) {
                    self.nodes[curNode.right].parent = tempValue;
                }

                self.nodes[curNode.left].parent = tempValue;
                curNode.value = tempValue;

                deleteNodeHelper(self, tempValue, curNode.left);
                self.nodes[tempValue] = curNode;
                self.nodes[nodeId] = Node(0, 0, 0, 0);
            } else {
                if (curNode.parent != 0) {
                    if (curNode.value < curNode.parent) {
                        self.nodes[curNode.parent].left = curNode.left;
                    } else {
                        self.nodes[curNode.parent].right = curNode.left;
                    }
                }

                if (curNode.right != 0) {
                    self.nodes[curNode.right].parent = curNode.left;
                }

                self.nodes[curNode.left].parent = curNode.parent;
                self.nodes[curNode.left].right = curNode.right;
                self.nodes[nodeId] = Node(0, 0, 0, 0);
            }
            newNodeId = tempValue;
        } else if (curNode.left == 0 && curNode.right != 0) {
            uint256 tempValue = curNode.right;
            if (curNode.parent != 0) {
                if (curNode.value < curNode.parent) {
                    self.nodes[curNode.parent].left = tempValue;
                } else {
                    self.nodes[curNode.parent].right = tempValue;
                }
            }

            self.nodes[curNode.right].parent = curNode.parent;
            self.nodes[nodeId] = Node(0, 0, 0, 0);
            newNodeId = tempValue;
        } else {
            if (curNode.parent != 0) {
                if (curNode.value < curNode.parent) {
                    self.nodes[curNode.parent].left = 0;
                } else {
                    self.nodes[curNode.parent].right = 0;
                }
            }
            self.nodes[nodeId] = Node(0, 0, 0, 0);
            newNodeId = 0;
        }
    }

    function deleteNode(
        Tree storage self,
        uint256 deleteValue
    ) public returns (uint256 newRoot) {
        if (deleteValue != self.root) {
            deleteNodeHelper(self, deleteValue, self.root);
            newRoot = self.root;
        } else {
            newRoot = deleteLeaf(self, self.root);
            self.root = newRoot;
        }
    }

    function trimTreeHelper(
        Tree storage self,
        uint256 start,
        uint256 end,
        uint256 nodeId
    ) public {
        if (start <= end) {
            // current node
            Node memory curNode = self.nodes[nodeId];
            if (curNode.value != 0) {
                if (curNode.value < start) {
                    trimTreeHelper(self, start, end, curNode.right);
                } else if (curNode.value >= start && curNode.value <= end) {
                    uint256 newNodeId = deleteLeaf(self, curNode.value);
                    if (newNodeId != 0) {
                        trimTreeHelper(self, start, end, newNodeId);
                    }
                } else {
                    trimTreeHelper(self, start, end, curNode.left);
                }
            }
        }
    }

    function trimTree(
        Tree storage self,
        uint256 start,
        uint256 end
    ) public returns (uint256 newRoot) {
        if (start <= end) {
            // current root
            Node memory rootNode = self.nodes[self.root];
            if (rootNode.value != 0) {
                if (rootNode.value < start) {
                    trimTreeHelper(self, start, end, rootNode.right);
                    newRoot = self.root;
                } else if (rootNode.value >= start && rootNode.value <= end) {
                    newRoot = deleteNode(self, rootNode.value);
                    if (newRoot != 0) {
                        newRoot = trimTree(self, start, end);
                    }
                } else {
                    trimTreeHelper(self, start, end, rootNode.left);
                    newRoot = self.root;
                }
            }
        }
    }

    function processExpiriesListNTrimTree(
        Tree storage self,
        uint256 start,
        uint256 end
    ) public {
        if (self.root != 0) {
            //must have a tree
            delete self.futureExpiries[self.root];
            self.futureExpiries[self.root].push(end);
            if (self.root == self.rootLast) {
                delete self.rootToList[self.root];
            }
            returnListHelperEx(
                self,
                start,
                end,
                self.root,
                end + TIME_EXTENSION
            );
            self.rootLast = self.root;
            trimTree(self, start, end);
        }
    }

    function getExpiriesList(
        Tree storage self
    ) public view returns (uint256[] storage) {
        return self.rootToList[self.rootLast];
    }

    function getFutureExpiriesList(
        Tree storage self
    ) public view returns (uint256[] storage) {
        return self.futureExpiries[self.rootLast];
    }
}

File 8 of 18 : ERC20.sol
// SPDX-License-Identifier: MIT

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.zeppelin.solutions/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:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, 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}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), 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}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address sender,
        address recipient,
        uint256 amount
    ) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);

        uint256 currentAllowance = _allowances[sender][_msgSender()];
        require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
        unchecked {
            _approve(sender, _msgSender(), currentAllowance - 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) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][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) {
        uint256 currentAllowance = _allowances[_msgSender()][spender];
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(_msgSender(), spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `sender` to `recipient`.
     *
     * 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:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        uint256 senderBalance = _balances[sender];
        require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[sender] = senderBalance - amount;
        }
        _balances[recipient] += amount;

        emit Transfer(sender, recipient, amount);

        _afterTokenTransfer(sender, recipient, 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;
        _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;
        }
        _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 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 9 of 18 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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 `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
        address recipient,
        uint256 amount
    ) external returns (bool);

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

File 10 of 18 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 11 of 18 : ReentrancyGuard.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Gas optimized reentrancy protection for smart contracts.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/ReentrancyGuard.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
    uint256 private reentrancyStatus = 1;

    modifier nonReentrant() {
        require(reentrancyStatus == 1, "REENTRANCY");

        reentrancyStatus = 2;

        _;

        reentrancyStatus = 1;
    }
}

File 12 of 18 : PRBMathUD60x18.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;

import "./PRBMath.sol";

/// @title PRBMathUD60x18
/// @author Paul Razvan Berg
/// @notice Smart contract library for advanced fixed-point math that works with uint256 numbers considered to have 18
/// trailing decimals. We call this number representation unsigned 60.18-decimal fixed-point, since there can be up to 60
/// digits in the integer part and up to 18 decimals in the fractional part. The numbers are bound by the minimum and the
/// maximum values permitted by the Solidity type uint256.
library PRBMathUD60x18 {
    /// @dev Half the SCALE number.
    uint256 internal constant HALF_SCALE = 5e17;

    /// @dev log2(e) as an unsigned 60.18-decimal fixed-point number.
    uint256 internal constant LOG2_E = 1_442695040888963407;

    /// @dev The maximum value an unsigned 60.18-decimal fixed-point number can have.
    uint256 internal constant MAX_UD60x18 =
        115792089237316195423570985008687907853269984665640564039457_584007913129639935;

    /// @dev The maximum whole value an unsigned 60.18-decimal fixed-point number can have.
    uint256 internal constant MAX_WHOLE_UD60x18 =
        115792089237316195423570985008687907853269984665640564039457_000000000000000000;

    /// @dev How many trailing decimals can be represented.
    uint256 internal constant SCALE = 1e18;

    /// @notice Calculates the arithmetic average of x and y, rounding down.
    /// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
    /// @return result The arithmetic average as an unsigned 60.18-decimal fixed-point number.
    function avg(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // The operations can never overflow.
        unchecked {
            // The last operand checks if both x and y are odd and if that is the case, we add 1 to the result. We need
            // to do this because if both numbers are odd, the 0.5 remainder gets truncated twice.
            result = (x >> 1) + (y >> 1) + (x & y & 1);
        }
    }

    /// @notice Yields the least unsigned 60.18 decimal fixed-point number greater than or equal to x.
    ///
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    ///
    /// Requirements:
    /// - x must be less than or equal to MAX_WHOLE_UD60x18.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number to ceil.
    /// @param result The least integer greater than or equal to x, as an unsigned 60.18-decimal fixed-point number.
    function ceil(uint256 x) internal pure returns (uint256 result) {
        if (x > MAX_WHOLE_UD60x18) {
            revert PRBMathUD60x18__CeilOverflow(x);
        }
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "SCALE - remainder" but faster.
            let delta := sub(SCALE, remainder)

            // Equivalent to "x + delta * (remainder > 0 ? 1 : 0)" but faster.
            result := add(x, mul(delta, gt(remainder, 0)))
        }
    }

    /// @notice Divides two unsigned 60.18-decimal fixed-point numbers, returning a new unsigned 60.18-decimal fixed-point number.
    ///
    /// @dev Uses mulDiv to enable overflow-safe multiplication and division.
    ///
    /// Requirements:
    /// - The denominator cannot be zero.
    ///
    /// @param x The numerator as an unsigned 60.18-decimal fixed-point number.
    /// @param y The denominator as an unsigned 60.18-decimal fixed-point number.
    /// @param result The quotient as an unsigned 60.18-decimal fixed-point number.
    function div(uint256 x, uint256 y) internal pure returns (uint256 result) {
        result = PRBMath.mulDiv(x, SCALE, y);
    }

    /// @notice Returns Euler's number as an unsigned 60.18-decimal fixed-point number.
    /// @dev See https://en.wikipedia.org/wiki/E_(mathematical_constant).
    function e() internal pure returns (uint256 result) {
        result = 2_718281828459045235;
    }

    /// @notice Calculates the natural exponent of x.
    ///
    /// @dev Based on the insight that e^x = 2^(x * log2(e)).
    ///
    /// Requirements:
    /// - All from "log2".
    /// - x must be less than 133.084258667509499441.
    ///
    /// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp(uint256 x) internal pure returns (uint256 result) {
        // Without this check, the value passed to "exp2" would be greater than 192.
        if (x >= 133_084258667509499441) {
            revert PRBMathUD60x18__ExpInputTooBig(x);
        }

        // Do the fixed-point multiplication inline to save gas.
        unchecked {
            uint256 doubleScaleProduct = x * LOG2_E;
            result = exp2((doubleScaleProduct + HALF_SCALE) / SCALE);
        }
    }

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    ///
    /// @dev See https://ethereum.stackexchange.com/q/79903/24693.
    ///
    /// Requirements:
    /// - x must be 192 or less.
    /// - The result must fit within MAX_UD60x18.
    ///
    /// @param x The exponent as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp2(uint256 x) internal pure returns (uint256 result) {
        // 2^192 doesn't fit within the 192.64-bit format used internally in this function.
        if (x >= 192e18) {
            revert PRBMathUD60x18__Exp2InputTooBig(x);
        }

        unchecked {
            // Convert x to the 192.64-bit fixed-point format.
            uint256 x192x64 = (x << 64) / SCALE;

            // Pass x to the PRBMath.exp2 function, which uses the 192.64-bit fixed-point number representation.
            result = PRBMath.exp2(x192x64);
        }
    }

    /// @notice Yields the greatest unsigned 60.18 decimal fixed-point number less than or equal to x.
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    /// @param x The unsigned 60.18-decimal fixed-point number to floor.
    /// @param result The greatest integer less than or equal to x, as an unsigned 60.18-decimal fixed-point number.
    function floor(uint256 x) internal pure returns (uint256 result) {
        assembly {
            // Equivalent to "x % SCALE" but faster.
            let remainder := mod(x, SCALE)

            // Equivalent to "x - remainder * (remainder > 0 ? 1 : 0)" but faster.
            result := sub(x, mul(remainder, gt(remainder, 0)))
        }
    }

    /// @notice Yields the excess beyond the floor of x.
    /// @dev Based on the odd function definition https://en.wikipedia.org/wiki/Fractional_part.
    /// @param x The unsigned 60.18-decimal fixed-point number to get the fractional part of.
    /// @param result The fractional part of x as an unsigned 60.18-decimal fixed-point number.
    function frac(uint256 x) internal pure returns (uint256 result) {
        assembly {
            result := mod(x, SCALE)
        }
    }

    /// @notice Converts a number from basic integer form to unsigned 60.18-decimal fixed-point representation.
    ///
    /// @dev Requirements:
    /// - x must be less than or equal to MAX_UD60x18 divided by SCALE.
    ///
    /// @param x The basic integer to convert.
    /// @param result The same number in unsigned 60.18-decimal fixed-point representation.
    function fromUint(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            if (x > MAX_UD60x18 / SCALE) {
                revert PRBMathUD60x18__FromUintOverflow(x);
            }
            result = x * SCALE;
        }
    }

    /// @notice Calculates geometric mean of x and y, i.e. sqrt(x * y), rounding down.
    ///
    /// @dev Requirements:
    /// - x * y must fit within MAX_UD60x18, lest it overflows.
    ///
    /// @param x The first operand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The second operand as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function gm(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            return 0;
        }

        unchecked {
            // Checking for overflow this way is faster than letting Solidity do it.
            uint256 xy = x * y;
            if (xy / x != y) {
                revert PRBMathUD60x18__GmOverflow(x, y);
            }

            // We don't need to multiply by the SCALE here because the x*y product had already picked up a factor of SCALE
            // during multiplication. See the comments within the "sqrt" function.
            result = PRBMath.sqrt(xy);
        }
    }

    /// @notice Calculates 1 / x, rounding toward zero.
    ///
    /// @dev Requirements:
    /// - x cannot be zero.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the inverse.
    /// @return result The inverse as an unsigned 60.18-decimal fixed-point number.
    function inv(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            // 1e36 is SCALE * SCALE.
            result = 1e36 / x;
        }
    }

    /// @notice Calculates the natural logarithm of x.
    ///
    /// @dev Based on the insight that ln(x) = log2(x) / log2(e).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    /// - This doesn't return exactly 1 for 2.718281828459045235, for that we would need more fine-grained precision.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the natural logarithm.
    /// @return result The natural logarithm as an unsigned 60.18-decimal fixed-point number.
    function ln(uint256 x) internal pure returns (uint256 result) {
        // Do the fixed-point multiplication inline to save gas. This is overflow-safe because the maximum value that log2(x)
        // can return is 196205294292027477728.
        unchecked {
            result = (log2(x) * SCALE) / LOG2_E;
        }
    }

    /// @notice Calculates the common logarithm of x.
    ///
    /// @dev First checks if x is an exact power of ten and it stops if yes. If it's not, calculates the common
    /// logarithm based on the insight that log10(x) = log2(x) / log2(10).
    ///
    /// Requirements:
    /// - All from "log2".
    ///
    /// Caveats:
    /// - All from "log2".
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the common logarithm.
    /// @return result The common logarithm as an unsigned 60.18-decimal fixed-point number.
    function log10(uint256 x) internal pure returns (uint256 result) {
        if (x < SCALE) {
            revert PRBMathUD60x18__LogInputTooSmall(x);
        }

        // Note that the "mul" in this block is the assembly multiplication operation, not the "mul" function defined
        // in this contract.
        // prettier-ignore
        assembly {
            switch x
            case 1 { result := mul(SCALE, sub(0, 18)) }
            case 10 { result := mul(SCALE, sub(1, 18)) }
            case 100 { result := mul(SCALE, sub(2, 18)) }
            case 1000 { result := mul(SCALE, sub(3, 18)) }
            case 10000 { result := mul(SCALE, sub(4, 18)) }
            case 100000 { result := mul(SCALE, sub(5, 18)) }
            case 1000000 { result := mul(SCALE, sub(6, 18)) }
            case 10000000 { result := mul(SCALE, sub(7, 18)) }
            case 100000000 { result := mul(SCALE, sub(8, 18)) }
            case 1000000000 { result := mul(SCALE, sub(9, 18)) }
            case 10000000000 { result := mul(SCALE, sub(10, 18)) }
            case 100000000000 { result := mul(SCALE, sub(11, 18)) }
            case 1000000000000 { result := mul(SCALE, sub(12, 18)) }
            case 10000000000000 { result := mul(SCALE, sub(13, 18)) }
            case 100000000000000 { result := mul(SCALE, sub(14, 18)) }
            case 1000000000000000 { result := mul(SCALE, sub(15, 18)) }
            case 10000000000000000 { result := mul(SCALE, sub(16, 18)) }
            case 100000000000000000 { result := mul(SCALE, sub(17, 18)) }
            case 1000000000000000000 { result := 0 }
            case 10000000000000000000 { result := SCALE }
            case 100000000000000000000 { result := mul(SCALE, 2) }
            case 1000000000000000000000 { result := mul(SCALE, 3) }
            case 10000000000000000000000 { result := mul(SCALE, 4) }
            case 100000000000000000000000 { result := mul(SCALE, 5) }
            case 1000000000000000000000000 { result := mul(SCALE, 6) }
            case 10000000000000000000000000 { result := mul(SCALE, 7) }
            case 100000000000000000000000000 { result := mul(SCALE, 8) }
            case 1000000000000000000000000000 { result := mul(SCALE, 9) }
            case 10000000000000000000000000000 { result := mul(SCALE, 10) }
            case 100000000000000000000000000000 { result := mul(SCALE, 11) }
            case 1000000000000000000000000000000 { result := mul(SCALE, 12) }
            case 10000000000000000000000000000000 { result := mul(SCALE, 13) }
            case 100000000000000000000000000000000 { result := mul(SCALE, 14) }
            case 1000000000000000000000000000000000 { result := mul(SCALE, 15) }
            case 10000000000000000000000000000000000 { result := mul(SCALE, 16) }
            case 100000000000000000000000000000000000 { result := mul(SCALE, 17) }
            case 1000000000000000000000000000000000000 { result := mul(SCALE, 18) }
            case 10000000000000000000000000000000000000 { result := mul(SCALE, 19) }
            case 100000000000000000000000000000000000000 { result := mul(SCALE, 20) }
            case 1000000000000000000000000000000000000000 { result := mul(SCALE, 21) }
            case 10000000000000000000000000000000000000000 { result := mul(SCALE, 22) }
            case 100000000000000000000000000000000000000000 { result := mul(SCALE, 23) }
            case 1000000000000000000000000000000000000000000 { result := mul(SCALE, 24) }
            case 10000000000000000000000000000000000000000000 { result := mul(SCALE, 25) }
            case 100000000000000000000000000000000000000000000 { result := mul(SCALE, 26) }
            case 1000000000000000000000000000000000000000000000 { result := mul(SCALE, 27) }
            case 10000000000000000000000000000000000000000000000 { result := mul(SCALE, 28) }
            case 100000000000000000000000000000000000000000000000 { result := mul(SCALE, 29) }
            case 1000000000000000000000000000000000000000000000000 { result := mul(SCALE, 30) }
            case 10000000000000000000000000000000000000000000000000 { result := mul(SCALE, 31) }
            case 100000000000000000000000000000000000000000000000000 { result := mul(SCALE, 32) }
            case 1000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 33) }
            case 10000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 34) }
            case 100000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 35) }
            case 1000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 36) }
            case 10000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 37) }
            case 100000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 38) }
            case 1000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 39) }
            case 10000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 40) }
            case 100000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 41) }
            case 1000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 42) }
            case 10000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 43) }
            case 100000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 44) }
            case 1000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 45) }
            case 10000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 46) }
            case 100000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 47) }
            case 1000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 48) }
            case 10000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 49) }
            case 100000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 50) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 51) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 52) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 53) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 54) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 55) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 56) }
            case 1000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 57) }
            case 10000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 58) }
            case 100000000000000000000000000000000000000000000000000000000000000000000000000000 { result := mul(SCALE, 59) }
            default {
                result := MAX_UD60x18
            }
        }

        if (result == MAX_UD60x18) {
            // Do the fixed-point division inline to save gas. The denominator is log2(10).
            unchecked {
                result = (log2(x) * SCALE) / 3_321928094887362347;
            }
        }
    }

    /// @notice Calculates the binary logarithm of x.
    ///
    /// @dev Based on the iterative approximation algorithm.
    /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
    ///
    /// Requirements:
    /// - x must be greater than or equal to SCALE, otherwise the result would be negative.
    ///
    /// Caveats:
    /// - The results are nor perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the binary logarithm.
    /// @return result The binary logarithm as an unsigned 60.18-decimal fixed-point number.
    function log2(uint256 x) internal pure returns (uint256 result) {
        if (x < SCALE) {
            revert PRBMathUD60x18__LogInputTooSmall(x);
        }
        unchecked {
            // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n).
            uint256 n = PRBMath.mostSignificantBit(x / SCALE);

            // The integer part of the logarithm as an unsigned 60.18-decimal fixed-point number. The operation can't overflow
            // because n is maximum 255 and SCALE is 1e18.
            result = n * SCALE;

            // This is y = x * 2^(-n).
            uint256 y = x >> n;

            // If y = 1, the fractional part is zero.
            if (y == SCALE) {
                return result;
            }

            // Calculate the fractional part via the iterative approximation.
            // The "delta >>= 1" part is equivalent to "delta /= 2", but shifting bits is faster.
            for (uint256 delta = HALF_SCALE; delta > 0; delta >>= 1) {
                y = (y * y) / SCALE;

                // Is y^2 > 2 and so in the range [2,4)?
                if (y >= 2 * SCALE) {
                    // Add the 2^(-m) factor to the logarithm.
                    result += delta;

                    // Corresponds to z/2 on Wikipedia.
                    y >>= 1;
                }
            }
        }
    }

    /// @notice Multiplies two unsigned 60.18-decimal fixed-point numbers together, returning a new unsigned 60.18-decimal
    /// fixed-point number.
    /// @dev See the documentation for the "PRBMath.mulDivFixedPoint" function.
    /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
    /// @return result The product as an unsigned 60.18-decimal fixed-point number.
    function mul(uint256 x, uint256 y) internal pure returns (uint256 result) {
        result = PRBMath.mulDivFixedPoint(x, y);
    }

    /// @notice Returns PI as an unsigned 60.18-decimal fixed-point number.
    function pi() internal pure returns (uint256 result) {
        result = 3_141592653589793238;
    }

    /// @notice Raises x to the power of y.
    ///
    /// @dev Based on the insight that x^y = 2^(log2(x) * y).
    ///
    /// Requirements:
    /// - All from "exp2", "log2" and "mul".
    ///
    /// Caveats:
    /// - All from "exp2", "log2" and "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x Number to raise to given power y, as an unsigned 60.18-decimal fixed-point number.
    /// @param y Exponent to raise x to, as an unsigned 60.18-decimal fixed-point number.
    /// @return result x raised to power y, as an unsigned 60.18-decimal fixed-point number.
    function pow(uint256 x, uint256 y) internal pure returns (uint256 result) {
        if (x == 0) {
            result = y == 0 ? SCALE : uint256(0);
        } else {
            result = exp2(mul(log2(x), y));
        }
    }

    /// @notice Raises x (unsigned 60.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the
    /// famous algorithm "exponentiation by squaring".
    ///
    /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring
    ///
    /// Requirements:
    /// - The result must fit within MAX_UD60x18.
    ///
    /// Caveats:
    /// - All from "mul".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x The base as an unsigned 60.18-decimal fixed-point number.
    /// @param y The exponent as an uint256.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function powu(uint256 x, uint256 y) internal pure returns (uint256 result) {
        // Calculate the first iteration of the loop in advance.
        result = y & 1 > 0 ? x : SCALE;

        // Equivalent to "for(y /= 2; y > 0; y /= 2)" but faster.
        for (y >>= 1; y > 0; y >>= 1) {
            x = PRBMath.mulDivFixedPoint(x, x);

            // Equivalent to "y % 2 == 1" but faster.
            if (y & 1 > 0) {
                result = PRBMath.mulDivFixedPoint(result, x);
            }
        }
    }

    /// @notice Returns 1 as an unsigned 60.18-decimal fixed-point number.
    function scale() internal pure returns (uint256 result) {
        result = SCALE;
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Requirements:
    /// - x must be less than MAX_UD60x18 / SCALE.
    ///
    /// @param x The unsigned 60.18-decimal fixed-point number for which to calculate the square root.
    /// @return result The result as an unsigned 60.18-decimal fixed-point .
    function sqrt(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            if (x > MAX_UD60x18 / SCALE) {
                revert PRBMathUD60x18__SqrtOverflow(x);
            }
            // Multiply x by the SCALE to account for the factor of SCALE that is picked up when multiplying two unsigned
            // 60.18-decimal fixed-point numbers together (in this case, those two numbers are both the square root).
            result = PRBMath.sqrt(x * SCALE);
        }
    }

    /// @notice Converts a unsigned 60.18-decimal fixed-point number to basic integer form, rounding down in the process.
    /// @param x The unsigned 60.18-decimal fixed-point number to convert.
    /// @return result The same number in basic integer form.
    function toUint(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            result = x / SCALE;
        }
    }
}

File 13 of 18 : OrderPool.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

import "prb-math/contracts/PRBMathUD60x18.sol";

///@notice An Order Pool is an abstraction for a pool of long term orders that sells a token at a constant rate to the embedded AMM.
///the order pool handles the logic for distributing the proceeds from these sales to the owners of the long term orders through a modified
///version of the staking algorithm from  https://uploads-ssl.webflow.com/5ad71ffeb79acc67c8bcdaba/5ad8d1193a40977462982470_scalable-reward-distribution-paper.pdf
library OrderPoolLib {
    using PRBMathUD60x18 for uint256;

    ///@notice you can think of this as a staking pool where all long term orders are staked.
    /// The pool is paid when virtual long term orders are executed, and each order is paid proportionally
    /// by the order's sale rate per block
    struct OrderPool {
        ///@notice current rate that tokens are being sold (per block)
        uint256 currentSalesRate;
        ///@notice sum of (salesProceeds_k / salesRate_k) over every period k. Stored as a fixed precision floating point number
        uint256 rewardFactor;
        ///@notice this maps block numbers to the cumulative sales rate of orders that expire on that block
        mapping(uint256 => uint256) salesRateEndingPerBlock;
        ///@notice map order ids to the block in which they expire
        mapping(uint256 => uint256) orderExpiry;
        ///@notice map order ids to their sales rate
        mapping(uint256 => uint256) salesRate;
        ///@notice reward factor per order at time of submission
        mapping(uint256 => uint256) rewardFactorAtSubmission;
        ///@notice reward factor at a specific block
        mapping(uint256 => uint256) rewardFactorAtBlock;
    }

    ///@notice distribute payment amount to pool (in the case of TWAMM, proceeds from trades against amm)
    function distributePayment(OrderPool storage self, uint256 amount) public {
        if (self.currentSalesRate != 0) {
            //floating point arithmetic
            self.rewardFactor += amount
                .fromUint()
                .mul(PRBMathUD60x18.fromUint(10000))
                .div(self.currentSalesRate.fromUint());
        }
    }

    ///@notice deposit an order into the order pool.
    function depositOrder(
        OrderPool storage self,
        uint256 orderId,
        uint256 amountPerBlock,
        uint256 orderExpiry
    ) public {
        self.currentSalesRate += amountPerBlock;
        self.rewardFactorAtSubmission[orderId] = self.rewardFactor;
        self.orderExpiry[orderId] = orderExpiry;
        self.salesRate[orderId] = amountPerBlock;
        self.salesRateEndingPerBlock[orderExpiry] += amountPerBlock;
    }

    ///@notice when orders expire after a given block, we need to update the state of the pool
    function updateStateFromBlockExpiry(
        OrderPool storage self,
        uint256 blockNumber
    ) public {
        uint256 ordersExpiring = self.salesRateEndingPerBlock[blockNumber];
        self.currentSalesRate -= ordersExpiring;
        self.rewardFactorAtBlock[blockNumber] = self.rewardFactor;
    }

    ///@notice cancel order and remove from the order pool
    function cancelOrder(
        OrderPool storage self,
        uint256 orderId
    ) public returns (uint256 unsoldAmount, uint256 purchasedAmount) {
        uint256 expiry = self.orderExpiry[orderId];
        require(expiry > block.number, "Order Already Finished");

        //calculate amount that wasn't sold, and needs to be returned
        uint256 salesRate = self.salesRate[orderId];
        uint256 blocksRemaining = expiry - block.number;
        unsoldAmount = (blocksRemaining * salesRate) / 10000;

        //calculate amount of other token that was purchased
        uint256 rewardFactorAtSubmission = self.rewardFactorAtSubmission[
            orderId
        ];
        purchasedAmount = (self.rewardFactor - rewardFactorAtSubmission)
            .mul(salesRate.fromUint())
            .div(PRBMathUD60x18.fromUint(10000))
            .toUint();

        //update state
        self.currentSalesRate -= salesRate;
        self.salesRate[orderId] = 0;
        self.orderExpiry[orderId] = 0;
        self.salesRateEndingPerBlock[expiry] -= salesRate;
    }

    ///@notice withdraw proceeds from pool for a given order. This can be done before or after the order has expired.
    //If the order has expired, we calculate the reward factor at time of expiry. If order has not yet expired, we
    //use current reward factor, and update the reward factor at time of staking (effectively creating a new order)
    function withdrawProceeds(
        OrderPool storage self,
        uint256 orderId
    ) public returns (uint256 totalReward) {
        uint256 stakedAmount = self.salesRate[orderId];
        require(stakedAmount > 0, "Sales Rate Amount Must Be Positive");
        uint256 orderExpiry = self.orderExpiry[orderId];
        uint256 rewardFactorAtSubmission = self.rewardFactorAtSubmission[
            orderId
        ];

        //if order has expired, we need to calculate the reward factor at expiry
        if (block.number >= orderExpiry) {
            uint256 rewardFactorAtExpiry = self.rewardFactorAtBlock[
                orderExpiry
            ];
            totalReward = (rewardFactorAtExpiry - rewardFactorAtSubmission)
                .mul(stakedAmount.fromUint())
                .div(PRBMathUD60x18.fromUint(10000))
                .toUint();
            //remove stake
            self.salesRate[orderId] = 0;
        }
        //if order has not yet expired, we just adjust the start
        else {
            totalReward = (self.rewardFactor - rewardFactorAtSubmission)
                .mul(stakedAmount.fromUint())
                .div(PRBMathUD60x18.fromUint(10000))
                .toUint();
            self.rewardFactorAtSubmission[orderId] = self.rewardFactor;
        }
    }
}

File 14 of 18 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @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
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

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

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

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

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

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

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

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

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 15 of 18 : PRBMath.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;

/// @notice Emitted when the result overflows uint256.
error PRBMath__MulDivFixedPointOverflow(uint256 prod1);

/// @notice Emitted when the result overflows uint256.
error PRBMath__MulDivOverflow(uint256 prod1, uint256 denominator);

/// @notice Emitted when one of the inputs is type(int256).min.
error PRBMath__MulDivSignedInputTooSmall();

/// @notice Emitted when the intermediary absolute result overflows int256.
error PRBMath__MulDivSignedOverflow(uint256 rAbs);

/// @notice Emitted when the input is MIN_SD59x18.
error PRBMathSD59x18__AbsInputTooSmall();

/// @notice Emitted when ceiling a number overflows SD59x18.
error PRBMathSD59x18__CeilOverflow(int256 x);

/// @notice Emitted when one of the inputs is MIN_SD59x18.
error PRBMathSD59x18__DivInputTooSmall();

/// @notice Emitted when one of the intermediary unsigned results overflows SD59x18.
error PRBMathSD59x18__DivOverflow(uint256 rAbs);

/// @notice Emitted when the input is greater than 133.084258667509499441.
error PRBMathSD59x18__ExpInputTooBig(int256 x);

/// @notice Emitted when the input is greater than 192.
error PRBMathSD59x18__Exp2InputTooBig(int256 x);

/// @notice Emitted when flooring a number underflows SD59x18.
error PRBMathSD59x18__FloorUnderflow(int256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format overflows SD59x18.
error PRBMathSD59x18__FromIntOverflow(int256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format underflows SD59x18.
error PRBMathSD59x18__FromIntUnderflow(int256 x);

/// @notice Emitted when the product of the inputs is negative.
error PRBMathSD59x18__GmNegativeProduct(int256 x, int256 y);

/// @notice Emitted when multiplying the inputs overflows SD59x18.
error PRBMathSD59x18__GmOverflow(int256 x, int256 y);

/// @notice Emitted when the input is less than or equal to zero.
error PRBMathSD59x18__LogInputTooSmall(int256 x);

/// @notice Emitted when one of the inputs is MIN_SD59x18.
error PRBMathSD59x18__MulInputTooSmall();

/// @notice Emitted when the intermediary absolute result overflows SD59x18.
error PRBMathSD59x18__MulOverflow(uint256 rAbs);

/// @notice Emitted when the intermediary absolute result overflows SD59x18.
error PRBMathSD59x18__PowuOverflow(uint256 rAbs);

/// @notice Emitted when the input is negative.
error PRBMathSD59x18__SqrtNegativeInput(int256 x);

/// @notice Emitted when the calculating the square root overflows SD59x18.
error PRBMathSD59x18__SqrtOverflow(int256 x);

/// @notice Emitted when addition overflows UD60x18.
error PRBMathUD60x18__AddOverflow(uint256 x, uint256 y);

/// @notice Emitted when ceiling a number overflows UD60x18.
error PRBMathUD60x18__CeilOverflow(uint256 x);

/// @notice Emitted when the input is greater than 133.084258667509499441.
error PRBMathUD60x18__ExpInputTooBig(uint256 x);

/// @notice Emitted when the input is greater than 192.
error PRBMathUD60x18__Exp2InputTooBig(uint256 x);

/// @notice Emitted when converting a basic integer to the fixed-point format format overflows UD60x18.
error PRBMathUD60x18__FromUintOverflow(uint256 x);

/// @notice Emitted when multiplying the inputs overflows UD60x18.
error PRBMathUD60x18__GmOverflow(uint256 x, uint256 y);

/// @notice Emitted when the input is less than 1.
error PRBMathUD60x18__LogInputTooSmall(uint256 x);

/// @notice Emitted when the calculating the square root overflows UD60x18.
error PRBMathUD60x18__SqrtOverflow(uint256 x);

/// @notice Emitted when subtraction underflows UD60x18.
error PRBMathUD60x18__SubUnderflow(uint256 x, uint256 y);

/// @dev Common mathematical functions used in both PRBMathSD59x18 and PRBMathUD60x18. Note that this shared library
/// does not always assume the signed 59.18-decimal fixed-point or the unsigned 60.18-decimal fixed-point
/// representation. When it does not, it is explicitly mentioned in the NatSpec documentation.
library PRBMath {
    /// STRUCTS ///

    struct SD59x18 {
        int256 value;
    }

    struct UD60x18 {
        uint256 value;
    }

    /// STORAGE ///

    /// @dev How many trailing decimals can be represented.
    uint256 internal constant SCALE = 1e18;

    /// @dev Largest power of two divisor of SCALE.
    uint256 internal constant SCALE_LPOTD = 262144;

    /// @dev SCALE inverted mod 2^256.
    uint256 internal constant SCALE_INVERSE =
        78156646155174841979727994598816262306175212592076161876661_508869554232690281;

    /// FUNCTIONS ///

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    /// @dev Has to use 192.64-bit fixed-point numbers.
    /// See https://ethereum.stackexchange.com/a/96594/24693.
    /// @param x The exponent as an unsigned 192.64-bit fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function exp2(uint256 x) internal pure returns (uint256 result) {
        unchecked {
            // Start from 0.5 in the 192.64-bit fixed-point format.
            result = 0x800000000000000000000000000000000000000000000000;

            // Multiply the result by root(2, 2^-i) when the bit at position i is 1. None of the intermediary results overflows
            // because the initial result is 2^191 and all magic factors are less than 2^65.
            if (x & 0x8000000000000000 > 0) {
                result = (result * 0x16A09E667F3BCC909) >> 64;
            }
            if (x & 0x4000000000000000 > 0) {
                result = (result * 0x1306FE0A31B7152DF) >> 64;
            }
            if (x & 0x2000000000000000 > 0) {
                result = (result * 0x1172B83C7D517ADCE) >> 64;
            }
            if (x & 0x1000000000000000 > 0) {
                result = (result * 0x10B5586CF9890F62A) >> 64;
            }
            if (x & 0x800000000000000 > 0) {
                result = (result * 0x1059B0D31585743AE) >> 64;
            }
            if (x & 0x400000000000000 > 0) {
                result = (result * 0x102C9A3E778060EE7) >> 64;
            }
            if (x & 0x200000000000000 > 0) {
                result = (result * 0x10163DA9FB33356D8) >> 64;
            }
            if (x & 0x100000000000000 > 0) {
                result = (result * 0x100B1AFA5ABCBED61) >> 64;
            }
            if (x & 0x80000000000000 > 0) {
                result = (result * 0x10058C86DA1C09EA2) >> 64;
            }
            if (x & 0x40000000000000 > 0) {
                result = (result * 0x1002C605E2E8CEC50) >> 64;
            }
            if (x & 0x20000000000000 > 0) {
                result = (result * 0x100162F3904051FA1) >> 64;
            }
            if (x & 0x10000000000000 > 0) {
                result = (result * 0x1000B175EFFDC76BA) >> 64;
            }
            if (x & 0x8000000000000 > 0) {
                result = (result * 0x100058BA01FB9F96D) >> 64;
            }
            if (x & 0x4000000000000 > 0) {
                result = (result * 0x10002C5CC37DA9492) >> 64;
            }
            if (x & 0x2000000000000 > 0) {
                result = (result * 0x1000162E525EE0547) >> 64;
            }
            if (x & 0x1000000000000 > 0) {
                result = (result * 0x10000B17255775C04) >> 64;
            }
            if (x & 0x800000000000 > 0) {
                result = (result * 0x1000058B91B5BC9AE) >> 64;
            }
            if (x & 0x400000000000 > 0) {
                result = (result * 0x100002C5C89D5EC6D) >> 64;
            }
            if (x & 0x200000000000 > 0) {
                result = (result * 0x10000162E43F4F831) >> 64;
            }
            if (x & 0x100000000000 > 0) {
                result = (result * 0x100000B1721BCFC9A) >> 64;
            }
            if (x & 0x80000000000 > 0) {
                result = (result * 0x10000058B90CF1E6E) >> 64;
            }
            if (x & 0x40000000000 > 0) {
                result = (result * 0x1000002C5C863B73F) >> 64;
            }
            if (x & 0x20000000000 > 0) {
                result = (result * 0x100000162E430E5A2) >> 64;
            }
            if (x & 0x10000000000 > 0) {
                result = (result * 0x1000000B172183551) >> 64;
            }
            if (x & 0x8000000000 > 0) {
                result = (result * 0x100000058B90C0B49) >> 64;
            }
            if (x & 0x4000000000 > 0) {
                result = (result * 0x10000002C5C8601CC) >> 64;
            }
            if (x & 0x2000000000 > 0) {
                result = (result * 0x1000000162E42FFF0) >> 64;
            }
            if (x & 0x1000000000 > 0) {
                result = (result * 0x10000000B17217FBB) >> 64;
            }
            if (x & 0x800000000 > 0) {
                result = (result * 0x1000000058B90BFCE) >> 64;
            }
            if (x & 0x400000000 > 0) {
                result = (result * 0x100000002C5C85FE3) >> 64;
            }
            if (x & 0x200000000 > 0) {
                result = (result * 0x10000000162E42FF1) >> 64;
            }
            if (x & 0x100000000 > 0) {
                result = (result * 0x100000000B17217F8) >> 64;
            }
            if (x & 0x80000000 > 0) {
                result = (result * 0x10000000058B90BFC) >> 64;
            }
            if (x & 0x40000000 > 0) {
                result = (result * 0x1000000002C5C85FE) >> 64;
            }
            if (x & 0x20000000 > 0) {
                result = (result * 0x100000000162E42FF) >> 64;
            }
            if (x & 0x10000000 > 0) {
                result = (result * 0x1000000000B17217F) >> 64;
            }
            if (x & 0x8000000 > 0) {
                result = (result * 0x100000000058B90C0) >> 64;
            }
            if (x & 0x4000000 > 0) {
                result = (result * 0x10000000002C5C860) >> 64;
            }
            if (x & 0x2000000 > 0) {
                result = (result * 0x1000000000162E430) >> 64;
            }
            if (x & 0x1000000 > 0) {
                result = (result * 0x10000000000B17218) >> 64;
            }
            if (x & 0x800000 > 0) {
                result = (result * 0x1000000000058B90C) >> 64;
            }
            if (x & 0x400000 > 0) {
                result = (result * 0x100000000002C5C86) >> 64;
            }
            if (x & 0x200000 > 0) {
                result = (result * 0x10000000000162E43) >> 64;
            }
            if (x & 0x100000 > 0) {
                result = (result * 0x100000000000B1721) >> 64;
            }
            if (x & 0x80000 > 0) {
                result = (result * 0x10000000000058B91) >> 64;
            }
            if (x & 0x40000 > 0) {
                result = (result * 0x1000000000002C5C8) >> 64;
            }
            if (x & 0x20000 > 0) {
                result = (result * 0x100000000000162E4) >> 64;
            }
            if (x & 0x10000 > 0) {
                result = (result * 0x1000000000000B172) >> 64;
            }
            if (x & 0x8000 > 0) {
                result = (result * 0x100000000000058B9) >> 64;
            }
            if (x & 0x4000 > 0) {
                result = (result * 0x10000000000002C5D) >> 64;
            }
            if (x & 0x2000 > 0) {
                result = (result * 0x1000000000000162E) >> 64;
            }
            if (x & 0x1000 > 0) {
                result = (result * 0x10000000000000B17) >> 64;
            }
            if (x & 0x800 > 0) {
                result = (result * 0x1000000000000058C) >> 64;
            }
            if (x & 0x400 > 0) {
                result = (result * 0x100000000000002C6) >> 64;
            }
            if (x & 0x200 > 0) {
                result = (result * 0x10000000000000163) >> 64;
            }
            if (x & 0x100 > 0) {
                result = (result * 0x100000000000000B1) >> 64;
            }
            if (x & 0x80 > 0) {
                result = (result * 0x10000000000000059) >> 64;
            }
            if (x & 0x40 > 0) {
                result = (result * 0x1000000000000002C) >> 64;
            }
            if (x & 0x20 > 0) {
                result = (result * 0x10000000000000016) >> 64;
            }
            if (x & 0x10 > 0) {
                result = (result * 0x1000000000000000B) >> 64;
            }
            if (x & 0x8 > 0) {
                result = (result * 0x10000000000000006) >> 64;
            }
            if (x & 0x4 > 0) {
                result = (result * 0x10000000000000003) >> 64;
            }
            if (x & 0x2 > 0) {
                result = (result * 0x10000000000000001) >> 64;
            }
            if (x & 0x1 > 0) {
                result = (result * 0x10000000000000001) >> 64;
            }

            // We're doing two things at the same time:
            //
            //   1. Multiply the result by 2^n + 1, where "2^n" is the integer part and the one is added to account for
            //      the fact that we initially set the result to 0.5. This is accomplished by subtracting from 191
            //      rather than 192.
            //   2. Convert the result to the unsigned 60.18-decimal fixed-point format.
            //
            // This works because 2^(191-ip) = 2^ip / 2^191, where "ip" is the integer part "2^n".
            result *= SCALE;
            result >>= (191 - (x >> 64));
        }
    }

    /// @notice Finds the zero-based index of the first one in the binary representation of x.
    /// @dev See the note on msb in the "Find First Set" Wikipedia article https://en.wikipedia.org/wiki/Find_first_set
    /// @param x The uint256 number for which to find the index of the most significant bit.
    /// @return msb The index of the most significant bit as an uint256.
    function mostSignificantBit(uint256 x) internal pure returns (uint256 msb) {
        if (x >= 2**128) {
            x >>= 128;
            msb += 128;
        }
        if (x >= 2**64) {
            x >>= 64;
            msb += 64;
        }
        if (x >= 2**32) {
            x >>= 32;
            msb += 32;
        }
        if (x >= 2**16) {
            x >>= 16;
            msb += 16;
        }
        if (x >= 2**8) {
            x >>= 8;
            msb += 8;
        }
        if (x >= 2**4) {
            x >>= 4;
            msb += 4;
        }
        if (x >= 2**2) {
            x >>= 2;
            msb += 2;
        }
        if (x >= 2**1) {
            // No need to shift x any more.
            msb += 1;
        }
    }

    /// @notice Calculates floor(x*y÷denominator) with full precision.
    ///
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
    ///
    /// Requirements:
    /// - The denominator cannot be zero.
    /// - The result must fit within uint256.
    ///
    /// Caveats:
    /// - This function does not work with fixed-point numbers.
    ///
    /// @param x The multiplicand as an uint256.
    /// @param y The multiplier as an uint256.
    /// @param denominator The divisor as an uint256.
    /// @return result The result as an uint256.
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        // 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) {
            unchecked {
                result = prod0 / denominator;
            }
            return result;
        }

        // Make sure the result is less than 2^256. Also prevents denominator == 0.
        if (prod1 >= denominator) {
            revert PRBMath__MulDivOverflow(prod1, denominator);
        }

        ///////////////////////////////////////////////
        // 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.
        unchecked {
            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 lpotdod = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by lpotdod.
                denominator := div(denominator, lpotdod)

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

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

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

            // 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 floor(x*y÷1e18) with full precision.
    ///
    /// @dev Variant of "mulDiv" with constant folding, i.e. in which the denominator is always 1e18. Before returning the
    /// final result, we add 1 if (x * y) % SCALE >= HALF_SCALE. Without this, 6.6e-19 would be truncated to 0 instead of
    /// being rounded to 1e-18.  See "Listing 6" and text above it at https://accu.org/index.php/journals/1717.
    ///
    /// Requirements:
    /// - The result must fit within uint256.
    ///
    /// Caveats:
    /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works.
    /// - It is assumed that the result can never be type(uint256).max when x and y solve the following two equations:
    ///     1. x * y = type(uint256).max * SCALE
    ///     2. (x * y) % SCALE >= SCALE / 2
    ///
    /// @param x The multiplicand as an unsigned 60.18-decimal fixed-point number.
    /// @param y The multiplier as an unsigned 60.18-decimal fixed-point number.
    /// @return result The result as an unsigned 60.18-decimal fixed-point number.
    function mulDivFixedPoint(uint256 x, uint256 y) internal pure returns (uint256 result) {
        uint256 prod0;
        uint256 prod1;
        assembly {
            let mm := mulmod(x, y, not(0))
            prod0 := mul(x, y)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

        if (prod1 >= SCALE) {
            revert PRBMath__MulDivFixedPointOverflow(prod1);
        }

        uint256 remainder;
        uint256 roundUpUnit;
        assembly {
            remainder := mulmod(x, y, SCALE)
            roundUpUnit := gt(remainder, 499999999999999999)
        }

        if (prod1 == 0) {
            unchecked {
                result = (prod0 / SCALE) + roundUpUnit;
                return result;
            }
        }

        assembly {
            result := add(
                mul(
                    or(
                        div(sub(prod0, remainder), SCALE_LPOTD),
                        mul(sub(prod1, gt(remainder, prod0)), add(div(sub(0, SCALE_LPOTD), SCALE_LPOTD), 1))
                    ),
                    SCALE_INVERSE
                ),
                roundUpUnit
            )
        }
    }

    /// @notice Calculates floor(x*y÷denominator) with full precision.
    ///
    /// @dev An extension of "mulDiv" for signed numbers. Works by computing the signs and the absolute values separately.
    ///
    /// Requirements:
    /// - None of the inputs can be type(int256).min.
    /// - The result must fit within int256.
    ///
    /// @param x The multiplicand as an int256.
    /// @param y The multiplier as an int256.
    /// @param denominator The divisor as an int256.
    /// @return result The result as an int256.
    function mulDivSigned(
        int256 x,
        int256 y,
        int256 denominator
    ) internal pure returns (int256 result) {
        if (x == type(int256).min || y == type(int256).min || denominator == type(int256).min) {
            revert PRBMath__MulDivSignedInputTooSmall();
        }

        // Get hold of the absolute values of x, y and the denominator.
        uint256 ax;
        uint256 ay;
        uint256 ad;
        unchecked {
            ax = x < 0 ? uint256(-x) : uint256(x);
            ay = y < 0 ? uint256(-y) : uint256(y);
            ad = denominator < 0 ? uint256(-denominator) : uint256(denominator);
        }

        // Compute the absolute value of (x*y)÷denominator. The result must fit within int256.
        uint256 rAbs = mulDiv(ax, ay, ad);
        if (rAbs > uint256(type(int256).max)) {
            revert PRBMath__MulDivSignedOverflow(rAbs);
        }

        // Get the signs of x, y and the denominator.
        uint256 sx;
        uint256 sy;
        uint256 sd;
        assembly {
            sx := sgt(x, sub(0, 1))
            sy := sgt(y, sub(0, 1))
            sd := sgt(denominator, sub(0, 1))
        }

        // XOR over sx, sy and sd. This is checking whether there are one or three negative signs in the inputs.
        // If yes, the result should be negative.
        result = sx ^ sy ^ sd == 0 ? -int256(rAbs) : int256(rAbs);
    }

    /// @notice Calculates the square root of x, rounding down.
    /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method.
    ///
    /// Caveats:
    /// - This function does not work with fixed-point numbers.
    ///
    /// @param x The uint256 number for which to calculate the square root.
    /// @return result The result as an uint256.
    function sqrt(uint256 x) internal pure returns (uint256 result) {
        if (x == 0) {
            return 0;
        }

        // Set the initial guess to the least power of two that is greater than or equal to sqrt(x).
        uint256 xAux = uint256(x);
        result = 1;
        if (xAux >= 0x100000000000000000000000000000000) {
            xAux >>= 128;
            result <<= 64;
        }
        if (xAux >= 0x10000000000000000) {
            xAux >>= 64;
            result <<= 32;
        }
        if (xAux >= 0x100000000) {
            xAux >>= 32;
            result <<= 16;
        }
        if (xAux >= 0x10000) {
            xAux >>= 16;
            result <<= 8;
        }
        if (xAux >= 0x100) {
            xAux >>= 8;
            result <<= 4;
        }
        if (xAux >= 0x10) {
            xAux >>= 4;
            result <<= 2;
        }
        if (xAux >= 0x8) {
            result <<= 1;
        }

        // The operations can never overflow because the result is max 2^127 when it enters this block.
        unchecked {
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1;
            result = (result + x / result) >> 1; // Seven iterations should be enough
            uint256 roundedDownResult = x / result;
            return result >= roundedDownResult ? roundedDownResult : result;
        }
    }
}

File 16 of 18 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT

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 17 of 18 : Context.sol
// SPDX-License-Identifier: MIT

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 18 of 18 : AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

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

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

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {
    "contracts/libraries/BinarySearchTree.sol": {
      "BinarySearchTreeLib": "0xe550967eac8ccd1c2d5fbf8fd6265b091e39ff3d"
    },
    "contracts/libraries/LongTermOrders.sol": {
      "LongTermOrdersLib": "0xb7f6625385425d034ef5930e034f2b79f7e002c7"
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenA","type":"address"},{"indexed":true,"internalType":"address","name":"tokenB","type":"address"},{"indexed":false,"internalType":"address","name":"pair","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"PairCreated","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allPairs","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allPairsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"}],"name":"createPair","outputs":[{"internalType":"address","name":"pair","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeArg","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeTo","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeToSetter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"getPair","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_twammAdd","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_feeArg","type":"uint32"}],"name":"setFeeArg","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeTo","type":"address"}],"name":"setFeeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeToSetter","type":"address"}],"name":"setFeeToSetter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"twammAdd","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

608060405234801561001057600080fd5b50604051613b1f380380613b1f83398101604081905261002f91610054565b600480546001600160a01b0319166001600160a01b0392909216919091179055610084565b60006020828403121561006657600080fd5b81516001600160a01b038116811461007d57600080fd5b9392505050565b613a8c806100936000396000f3fe60806040523480156200001157600080fd5b5060043610620000c35760003560e01c8063a2e74af6116200007a578063a2e74af6146200017e578063a55e5eed1462000195578063c4d66de814620001a9578063c9c6539614620001c0578063e6a4390514620001d7578063f46901ed146200020e57600080fd5b8063017e7e5814620000c8578063094b741514620001015780631e3dd18b1462000115578063574f2ba3146200012c57806379385548146200013e5780638904f3631462000165575b600080fd5b600354620000e49064010000000090046001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b600454620000e4906001600160a01b031681565b620000e46200012636600462000859565b62000225565b600254604051908152602001620000f8565b6003546200014f9063ffffffff1681565b60405163ffffffff9091168152602001620000f8565b6200017c6200017636600462000873565b62000250565b005b6200017c6200018f366004620008bf565b620002a2565b600554620000e4906001600160a01b031681565b6200017c620001ba366004620008bf565b620002f1565b620000e4620001d1366004620008dd565b620003cc565b620000e4620001e8366004620008dd565b60016020908152600092835260408084209091529082529020546001600160a01b031681565b6200017c6200021f366004620008bf565b620007f0565b600281815481106200023657600080fd5b6000918252602090912001546001600160a01b0316905081565b6004546001600160a01b03163314620002865760405162461bcd60e51b81526004016200027d9062000915565b60405180910390fd5b6003805463ffffffff191663ffffffff92909216919091179055565b6004546001600160a01b03163314620002cf5760405162461bcd60e51b81526004016200027d9062000915565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff166200030e5760005460ff161562000312565b303b155b620003775760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016200027d565b600054610100900460ff161580156200039a576000805461ffff19166101011790555b600580546001600160a01b0319166001600160a01b0384161790558015620003c8576000805461ff00191690555b5050565b6005546000906001600160a01b031633146200043c5760405162461bcd60e51b815260206004820152602860248201527f496e76616c696420557365722c204f6e6c79205457414d4d2043616e2043726560448201526730ba32902830b4b960c11b60648201526084016200027d565b6005546001600160a01b0316620004a25760405162461bcd60e51b8152602060048201526024808201527f466163746f7279204e6f7420496e697469616c697a6564204279205457414d4d6044820152630816595d60e21b60648201526084016200027d565b816001600160a01b0316836001600160a01b03161415620005065760405162461bcd60e51b815260206004820152601c60248201527f466163746f72793a204964656e746963616c204164647265737365730000000060448201526064016200027d565b600080836001600160a01b0316856001600160a01b0316106200052b5783856200052e565b84845b90925090506001600160a01b038216620005835760405162461bcd60e51b8152602060048201526015602482015274466163746f72793a205a65726f204164647265737360581b60448201526064016200027d565b6001600160a01b03828116600090815260016020908152604080832085851684529091529020541615620005f15760405162461bcd60e51b8152602060048201526014602482015273466163746f72793a20506169722045786973747360601b60448201526064016200027d565b60006040518060200162000605906200084b565b601f1982820381018352601f9091011660408181526005546001600160a01b03878116602085015286811692840192909252166060820152909150600090829060800160408051601f19818403018152908290526200066892916020016200097f565b60408051601f19818403018152908290526bffffffffffffffffffffffff19606087811b8216602085015286901b1660348301529150600090604801604051602081830303815290604052805190602001209050808251602084016000f595506001600160a01b038616620007205760405162461bcd60e51b815260206004820152601960248201527f437265617465323a204661696c6564204f6e204465706c6f790000000000000060448201526064016200027d565b6001600160a01b0385811660008181526001602081815260408084208a87168086529083528185208054978e166001600160a01b0319988916811790915584845282862087875284528286208054891682179055600280549586018155958690527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace9094018054909716841790965592548351928352908201527f0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9910160405180910390a3505050505092915050565b6004546001600160a01b031633146200081d5760405162461bcd60e51b81526004016200027d9062000915565b600380546001600160a01b0390921664010000000002640100000000600160c01b0319909216919091179055565b6130b680620009a183390190565b6000602082840312156200086c57600080fd5b5035919050565b6000602082840312156200088657600080fd5b813563ffffffff811681146200089b57600080fd5b9392505050565b80356001600160a01b0381168114620008ba57600080fd5b919050565b600060208284031215620008d257600080fd5b6200089b82620008a2565b60008060408385031215620008f157600080fd5b620008fc83620008a2565b91506200090c60208401620008a2565b90509250929050565b6020808252601290820152712330b1ba37b93c9d102337b93134b23232b760711b604082015260600190565b6000815160005b8181101562000964576020818501810151868301520162000948565b8181111562000974576000828601525b509290920192915050565b60006200099862000991838662000941565b8462000941565b94935050505056fe608060405260016005553480156200001657600080fd5b50604051620030b6380380620030b683398101604081905262000039916200023f565b6040805180820182526009815268050756c7361722d4c560bc1b602080830191825283518085019094526006845265050554c2d4c560d41b90840152815191929162000088916003916200017c565b5080516200009e9060049060208401906200017c565b505060068054336001600160a01b0319918216179091556007805482166001600160a01b038781169182179092556008805484168784169081179091556009805490941692861692831790935560405163b71522cf60e01b8152600c6004820152602481019190915260448101929092526064820152436084820152600560a482015273b7f6625385425d034ef5930e034f2b79f7e002c7915063b71522cf9060c40160006040518083038186803b1580156200015a57600080fd5b505af41580156200016f573d6000803e3d6000fd5b50505050505050620002c6565b8280546200018a9062000289565b90600052602060002090601f016020900481019282620001ae5760008555620001f9565b82601f10620001c957805160ff1916838001178555620001f9565b82800160010185558215620001f9579182015b82811115620001f9578251825591602001919060010190620001dc565b50620002079291506200020b565b5090565b5b808211156200020757600081556001016200020c565b80516001600160a01b03811681146200023a57600080fd5b919050565b6000806000606084860312156200025557600080fd5b620002608462000222565b9250620002706020850162000222565b9150620002806040850162000222565b90509250925092565b600181811c908216806200029e57607f821691505b60208210811415620002c057634e487b7160e01b600052602260045260246000fd5b50919050565b612de080620002d66000396000f3fe608060405234801561001057600080fd5b506004361061023d5760003560e01c806366f55ece1161013b578063a9059cbb116100b8578063ceb2894c1161007c578063ceb2894c146105fc578063d5d859c11461061c578063dd62ed3e1461062f578063e098ef9714610668578063ec7dd7bb1461067157600080fd5b8063a9059cbb146105b3578063b61aaa54146105c6578063bde1077e146105ce578063c45a0155146105e1578063c4e41b22146105f457600080fd5b806395d89b41116100ff57806395d89b411461051157806398267d2e146105195780639c48a8f91461057a578063a201ccf61461058d578063a457c2d7146105a057600080fd5b806366f55ece146103fa5780636726aec01461041d5780636f9d42d21461047857806370a082311461048b578063769b1cf4146104b457600080fd5b806337bc5e4a116101c95780635e3f27271161018d5780635e3f2727146103b15780635f64b55b146103b95780635fea6120146103cc57806360a9d505146103df578063659509c5146103e757600080fd5b806337bc5e4a1461032357806339509351146103365780633a8c885e146103495780633b4a6bc31461036957806342b98a141461038957600080fd5b806318160ddd1161021057806318160ddd146102cf57806323b872dd146102d757806325ca3964146102ea5780632e0ae375146102ff578063313ce5671461031457600080fd5b806306fdde0314610242578063095ea7b3146102605780630fc63d101461028357806313bf4fd2146102ae575b600080fd5b61024a610691565b6040516102579190612955565b60405180910390f35b61027361026e3660046129a0565b610723565b6040519015158152602001610257565b600754610296906001600160a01b031681565b6040516001600160a01b039091168152602001610257565b6102c16102bc3660046129a0565b61073a565b604051908152602001610257565b6002546102c1565b6102736102e53660046129cc565b61088a565b6102f2610936565b6040516102579190612a0d565b61031261030d366004612a51565b610a0f565b005b60405160128152602001610257565b6102f2610331366004612a6a565b610a83565b6102736103443660046129a0565b610aef565b6102c1610357366004612a6a565b600b6020526000908152604090205481565b6007546001600160a01b03166000908152600b60205260409020546102c1565b61039c6103973660046129a0565b610b2b565b60408051928352602083019190915201610257565b6102c1601e81565b600854610296906001600160a01b031681565b61039c6103da3660046129a0565b610c7f565b6102c1600581565b6102c16103f5366004612a87565b610f73565b610273610408366004612a51565b60009081526015602052604090205460ff1690565b61039c61042b366004612a51565b6007546001600160a01b0390811660009081526011602081815260408084208685526002908101835281852054600854909616855292825280842095845294909101905291909120549091565b6102c1610486366004612a87565b611140565b6102c1610499366004612a6a565b6001600160a01b031660009081526020819052604090205490565b61039c6104c2366004612a51565b600081815260136020908152604080832060078101546002909101546001600160a01b039091168452601183528184209484526005850183528184205490845260069094019091529020549091565b61024a6112e5565b600d546007546001600160a01b0390811660009081526011602090815260408083208054600854909516845292819020805460019485015494909101548251968752928601949094528401929092526060830152608082015260a001610257565b6102c16105883660046129a0565b6112f4565b61039c61059b3660046129a0565b611427565b6102736105ae3660046129a0565b6116f6565b6102736105c13660046129a0565b61178f565b6012546102c1565b6102c16105dc366004612a87565b61179c565b600654610296906001600160a01b031681565b6102c1611959565b6008546001600160a01b03166000908152600b60205260409020546102c1565b6102c161062a3660046129a0565b611969565b6102c161063d366004612abc565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6102c1600a5481565b61068461067f366004612a51565b611a9c565b6040516102579190612af5565b6060600380546106a090612b71565b80601f01602080910402602001604051908101604052809291908181526020018280546106cc90612b71565b80156107195780601f106106ee57610100808354040283529160200191610719565b820191906000526020600020905b8154815290600101906020018083116106fc57829003601f168201915b5050505050905090565b6000610730338484611b8f565b5060015b92915050565b6009546000906001600160a01b031633146107705760405162461bcd60e51b815260040161076790612bac565b60405180910390fd5b6005546001146107925760405162461bcd60e51b815260040161076790612bd4565b6002600555604051634b7446ff60e01b8152600c60048201526001600160a01b038416602482015260448101839052600b606482015273b7f6625385425d034ef5930e034f2b79f7e002c790634b7446ff9060840160206040518083038186803b1580156107ff57600080fd5b505af4158015610813573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108379190612bf8565b60408051848152602081018390529192506001600160a01b038516917f79ad14fdc35ed5b53e895a80c1e26ecfd7b87c91f1659e6aa84fefb0841a02a291015b60405180910390a2600160055592915050565b6000610897848484611cb4565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561091c5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610767565b6109298533858403611b8f565b60019150505b9392505050565b6040516378dbfc8160e11b81526016600482015260609073e550967eac8ccd1c2d5fbf8fd6265b091e39ff3d9063f1b7f9029060240160206040518083038186803b15801561098457600080fd5b505af4158015610998573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109bc9190612bf8565b80548060200260200160405190810160405280929190818152602001828054801561071957602002820191906000526020600020905b8154815260200190600101908083116109f2575050505050905090565b6040516357647c7f60e11b8152600c6004820152600b60248201526044810182905273b7f6625385425d034ef5930e034f2b79f7e002c79063aec8f8fe9060640160006040518083038186803b158015610a6857600080fd5b505af4158015610a7c573d6000803e3d6000fd5b5050505050565b6001600160a01b038116600090815260146020908152604091829020805483518184028101840190945280845260609392830182828015610ae357602002820191906000526020600020905b815481526020019060010190808311610acf575b50505050509050919050565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091610730918590610b26908690612c27565b611b8f565b60095460009081906001600160a01b03163314610b5a5760405162461bcd60e51b815260040161076790612bac565b600554600114610b7c5760405162461bcd60e51b815260040161076790612bd4565b60026005556040516303bdeec560e41b8152600c60048201526001600160a01b038516602482015260448101849052600b606482015273b7f6625385425d034ef5930e034f2b79f7e002c790633bdeec5090608401604080518083038186803b158015610be857600080fd5b505af4158015610bfc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c209190612c3f565b604080518681526020810184905290810182905291935091506001600160a01b038516907f5187cf882c722b1f3c2b67d751013259c0cb8f36161622ce83ae6b8f6f163f539060600160405180910390a2600160055590939092509050565b60095460009081906001600160a01b03163314610cae5760405162461bcd60e51b815260040161076790612bac565b600554600114610cd05760405162461bcd60e51b815260040161076790612bd4565b60026005556040516357647c7f60e11b8152600c6004820152600b602482015243604482015273b7f6625385425d034ef5930e034f2b79f7e002c79063aec8f8fe9060640160006040518083038186803b158015610d2d57600080fd5b505af4158015610d41573d6000803e3d6000fd5b5050505060008311610d655760405162461bcd60e51b815260040161076790612c63565b600254610dbf5760405162461bcd60e51b815260206004820152602260248201527f4e6f204c697175696469747920486173204265656e2050726f76696465642059604482015261195d60f21b6064820152608401610767565b6007546001600160a01b039081166000908152600b6020526040808220546008549093168252902054600254610df58387612c8b565b610dff9190612cc0565b9350610e0a60025490565b610e148287612c8b565b610e1e9190612cc0565b6007546001600160a01b03166000908152600b6020526040812080549295508692909190610e4d908490612c27565b90915550506008546001600160a01b03166000908152600b602052604081208054859290610e7c908490612c27565b9091555060009050610e8e8383611e84565b9050610e9a8787612062565b8015610f15576008546001600160a01b03166000908152600b6020526040902054610f1190610f0390610ed590610ed090612141565b61218e565b6007546001600160a01b03166000908152600b6020526040902054610efd90610ed090612141565b906121e0565b670de0b6b3a7640000900490565b600a555b60408051878152602081018790529081018590526001600160a01b038816907f3bca7014f4c0ccc8016338c79f4c00e82068dbadaf4f01ca5449040fdd39f500906060015b60405180910390a2505060016005555090939092509050565b6009546000906001600160a01b03163314610fa05760405162461bcd60e51b815260040161076790612bac565b600554600114610fc25760405162461bcd60e51b815260040161076790612bd4565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061100957506008546001600160a01b03166000908152600b602052604090205415155b6110255760405162461bcd60e51b815260040161076790612ce2565b600083116110455760405162461bcd60e51b815260040161076790612c63565b60405163233d824760e21b8152600c60048201526001600160a01b03851660248201526044810184905260648101839052600b608482015273b7f6625385425d034ef5930e034f2b79f7e002c790638cf6091c9060a40160206040518083038186803b1580156110b457600080fd5b505af41580156110c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ec9190612bf8565b60408051858152602081018390529192506001600160a01b038616917f3f9021da39409c8415526f6f5150f90f549aff31c146178262479dd87789440091015b60405180910390a260016005559392505050565b6009546000906001600160a01b0316331461116d5760405162461bcd60e51b815260040161076790612bac565b60055460011461118f5760405162461bcd60e51b815260040161076790612bd4565b600260055582158015906111a35750600082115b6111bf5760405162461bcd60e51b815260040161076790612c63565b6002541561121b5760405162461bcd60e51b815260206004820152602360248201527f4c69717569646974792048617320416c7265616479204265656e2050726f766960448201526219195960ea1b6064820152608401610767565b6007546001600160a01b039081166000908152600b6020526040808220869055600854909216815220829055611265610f03611259610ed085612141565b610efd610ed087612141565b90506000611274600080611e84565b90506112808583612062565b801561128c57600a8290555b60408051838152602081018690529081018490526001600160a01b038616907f9e20617171fe14c750c3beebe1b256358b9688a6e6047c4dd5e1e81c003c44b89060600160405180910390a25060016005559392505050565b6060600480546106a090612b71565b6009546000906001600160a01b031633146113215760405162461bcd60e51b815260040161076790612bac565b6005546001146113435760405162461bcd60e51b815260040161076790612bd4565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061138a57506008546001600160a01b03166000908152600b602052604090205415155b6113a65760405162461bcd60e51b815260040161076790612ce2565b600082116113c65760405162461bcd60e51b815260040161076790612c63565b6008546007546113e3916001600160a01b039081169116846121ec565b60408051848152602081018390529192506001600160a01b038516917f4af12e31478f230aa2cdfffcb6fe9525e6d1862db211087abb6fd8771ccdbe579101610877565b60095460009081906001600160a01b031633146114565760405162461bcd60e51b815260040161076790612bac565b6005546001146114785760405162461bcd60e51b815260040161076790612bd4565b60026005556040516357647c7f60e11b8152600c6004820152600b602482015243604482015273b7f6625385425d034ef5930e034f2b79f7e002c79063aec8f8fe9060640160006040518083038186803b1580156114d557600080fd5b505af41580156114e9573d6000803e3d6000fd5b505050506000831161150d5760405162461bcd60e51b815260040161076790612c63565b600254831061155e5760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420456e6f756768204c7020546f6b656e7320417661696c61626c6500006044820152606401610767565b6007546001600160a01b039081166000908152600b60205260408082205460085490931682529020546002546115948684612c8b565b61159e9190612cc0565b93506115a960025490565b6115b38683612c8b565b6115bd9190612cc0565b6007546001600160a01b03166000908152600b60205260408120805492955086929091906115ec908490612d12565b90915550506008546001600160a01b03166000908152600b60205260408120805485929061161b908490612d12565b909155506000905061162d8383611e84565b90506116398787612372565b600954600754611656916001600160a01b039182169116876124bd565b600954600854611673916001600160a01b039182169116866124bd565b80156116ad576008546001600160a01b03166000908152600b60205260409020546116a990610f0390610ed590610ed090612141565b600a555b60408051878152602081018790529081018590526001600160a01b038816907f1dc8bb69df2b8e91fbdcbfcf93d951b3f0000f085a95fe3f7946d6161439245d90606001610f5a565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156117785760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610767565b6117853385858403611b8f565b5060019392505050565b6000610730338484611cb4565b6009546000906001600160a01b031633146117c95760405162461bcd60e51b815260040161076790612bac565b6005546001146117eb5760405162461bcd60e51b815260040161076790612bd4565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061183257506008546001600160a01b03166000908152600b602052604090205415155b61184e5760405162461bcd60e51b815260040161076790612ce2565b6000831161186e5760405162461bcd60e51b815260040161076790612c63565b604051632d2f332560e11b8152600c60048201526001600160a01b03851660248201526044810184905260648101839052600b608482015273b7f6625385425d034ef5930e034f2b79f7e002c790635a5e664a9060a40160206040518083038186803b1580156118dd57600080fd5b505af41580156118f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119159190612bf8565b60408051858152602081018390529192506001600160a01b038616917f3118cfac1ed5d8e668c193690497d56fff82f1aabbdf08f598025b0dfe308727910161112c565b600061196460025490565b905090565b6009546000906001600160a01b031633146119965760405162461bcd60e51b815260040161076790612bac565b6005546001146119b85760405162461bcd60e51b815260040161076790612bd4565b60026005556007546001600160a01b03166000908152600b6020526040902054158015906119ff57506008546001600160a01b03166000908152600b602052604090205415155b611a1b5760405162461bcd60e51b815260040161076790612ce2565b60008211611a3b5760405162461bcd60e51b815260040161076790612c63565b600754600854611a58916001600160a01b039081169116846121ec565b60408051848152602081018390529192506001600160a01b038516917f4d8578764edd2464e6964176a4bbedef1497b6bed5dd14e0609ad9149a85e5fe9101610877565b611b0660405180610120016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681525090565b50600090815260136020908152604091829020825161012081018452815481526001820154928101929092526002810154928201929092526003820154606082015260048201546080820152600582015460a082015260068201546001600160a01b0390811660c08301526007830154811660e083015260089092015490911661010082015290565b6001600160a01b038316611bf15760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610767565b6001600160a01b038216611c525760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610767565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b038316611d185760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610767565b6001600160a01b038216611d7a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610767565b6001600160a01b03831660009081526020819052604090205481811015611df25760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610767565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290611e29908490612c27565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611e7591815260200190565b60405180910390a35b50505050565b600080600660009054906101000a90046001600160a01b03166001600160a01b031663793855486040518163ffffffff1660e01b815260040160206040518083038186803b158015611ed557600080fd5b505afa158015611ee9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f0d9190612d29565b90506000600660009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611f5f57600080fd5b505afa158015611f73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f979190612d4f565b6001600160a01b038116158015945090915061204c57600a5415612047576000611fd5610f03611fc9610ed088612141565b610efd610ed08a612141565b9050600a54811115612045576000600a5482611ff19190612d12565b600254611ffe9190612c8b565b90506000600a548563ffffffff16846120179190612c8b565b6120219190612c27565b9050600061202f8284612cc0565b90508015612041576120418582612062565b5050505b505b61205a565b600a541561205a576000600a555b505092915050565b6001600160a01b0382166120b85760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610767565b80600260008282546120ca9190612c27565b90915550506001600160a01b038216600090815260208190526040812080548392906120f7908490612c27565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f2182111561218057604051633492ffd960e01b815260048101839052602401610767565b50670de0b6b3a76400000290565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218211156121cd57604051636155b67d60e01b815260048101839052602401610767565b610734670de0b6b3a7640000830261250f565b600061092f838361268a565b6009546000906001600160a01b031633146122195760405162461bcd60e51b815260040161076790612bac565b6040516357647c7f60e11b8152600c6004820152600b602482015243604482015273b7f6625385425d034ef5930e034f2b79f7e002c79063aec8f8fe9060640160006040518083038186803b15801561227157600080fd5b505af4158015612285573d6000803e3d6000fd5b505050506001600160a01b038481166000908152600b6020526040808220549286168252812054906122b78584612c27565b6122c18684612c8b565b6122cb9190612cc0565b90506127106122db601e82612d12565b6122e59083612c8b565b6122ef9190612cc0565b6001600160a01b0388166000908152600b602052604081208054929650879290919061231c908490612c27565b90915550506001600160a01b0386166000908152600b602052604081208054869290612349908490612d12565b9091555050600954612368906001600160a01b038881169116866124bd565b5050509392505050565b6001600160a01b0382166123d25760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610767565b6001600160a01b038216600090815260208190526040902054818110156124465760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610767565b6001600160a01b0383166000908152602081905260408120838303905560028054849290612475908490612d12565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001611ca7565b505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526124b890849061274c565b60008161251e57506000919050565b50600181600160801b81106125385760409190911b9060801c5b6801000000000000000081106125535760209190911b9060401c5b640100000000811061256a5760109190911b9060201c5b62010000811061257f5760089190911b9060101c5b61010081106125935760049190911b9060081c5b601081106125a65760029190911b9060041c5b600881106125b657600182901b91505b60018284816125c7576125c7612caa565b048301901c915060018284816125df576125df612caa565b048301901c915060018284816125f7576125f7612caa565b048301901c9150600182848161260f5761260f612caa565b048301901c9150600182848161262757612627612caa565b048301901c9150600182848161263f5761263f612caa565b048301901c9150600182848161265757612657612caa565b048301901c9150600082848161266f5761266f612caa565b049050808310156126805782612682565b805b949350505050565b60008080600019848609848602925082811083820303915050670de0b6b3a764000081106126ce5760405163698d9a0160e11b815260048101829052602401610767565b600080670de0b6b3a76400008688099150506706f05b59d3b1ffff8111826127085780670de0b6b3a7640000850401945050505050610734565b620400008285030493909111909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b60006127a1826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661281e9092919063ffffffff16565b8051909150156124b857808060200190518101906127bf9190612d6c565b6124b85760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610767565b6060612682848460008585843b6128775760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610767565b600080866001600160a01b031685876040516128939190612d8e565b60006040518083038185875af1925050503d80600081146128d0576040519150601f19603f3d011682016040523d82523d6000602084013e6128d5565b606091505b50915091506128e58282866128f0565b979650505050505050565b606083156128ff57508161092f565b82511561290f5782518084602001fd5b8160405162461bcd60e51b81526004016107679190612955565b60005b8381101561294457818101518382015260200161292c565b83811115611e7e5750506000910152565b6020815260008251806020840152612974816040850160208701612929565b601f01601f19169190910160400192915050565b6001600160a01b038116811461299d57600080fd5b50565b600080604083850312156129b357600080fd5b82356129be81612988565b946020939093013593505050565b6000806000606084860312156129e157600080fd5b83356129ec81612988565b925060208401356129fc81612988565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b81811015612a4557835183529284019291840191600101612a29565b50909695505050505050565b600060208284031215612a6357600080fd5b5035919050565b600060208284031215612a7c57600080fd5b813561092f81612988565b600080600060608486031215612a9c57600080fd5b8335612aa781612988565b95602085013595506040909401359392505050565b60008060408385031215612acf57600080fd5b8235612ada81612988565b91506020830135612aea81612988565b809150509250929050565b600061012082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160018060a01b0380821660c08501528060e08601511660e085015250506101008084015161205a828501826001600160a01b03169052565b600181811c90821680612b8557607f821691505b60208210811415612ba657634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252600e908201526d24b73b30b634b21021b0b63632b960911b604082015260600190565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b600060208284031215612c0a57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115612c3a57612c3a612c11565b500190565b60008060408385031215612c5257600080fd5b505080516020909101519092909150565b6020808252600e908201526d125b9d985b1a5908105b5bdd5b9d60921b604082015260600190565b6000816000190483118215151615612ca557612ca5612c11565b500290565b634e487b7160e01b600052601260045260246000fd5b600082612cdd57634e487b7160e01b600052601260045260246000fd5b500490565b602080825260169082015275496e73756666696369656e74204c697175696469747960501b604082015260600190565b600082821015612d2457612d24612c11565b500390565b600060208284031215612d3b57600080fd5b815163ffffffff8116811461092f57600080fd5b600060208284031215612d6157600080fd5b815161092f81612988565b600060208284031215612d7e57600080fd5b8151801515811461092f57600080fd5b60008251612da0818460208701612929565b919091019291505056fea2646970667358221220a8e6ffe19eeb99683ee45faa2ddfc4c66807889e1bb4dca829ffb626d26a9ff864736f6c63430008090033a2646970667358221220de8ee54173930d97cf18a740c0ed65c54b98bd3a3cfc8da3dba0f96bd7b493d964736f6c63430008090033000000000000000000000000cb3a9bfc9f99e75e922a516eed04d9f62e83a28e

Deployed Bytecode

0x60806040523480156200001157600080fd5b5060043610620000c35760003560e01c8063a2e74af6116200007a578063a2e74af6146200017e578063a55e5eed1462000195578063c4d66de814620001a9578063c9c6539614620001c0578063e6a4390514620001d7578063f46901ed146200020e57600080fd5b8063017e7e5814620000c8578063094b741514620001015780631e3dd18b1462000115578063574f2ba3146200012c57806379385548146200013e5780638904f3631462000165575b600080fd5b600354620000e49064010000000090046001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b600454620000e4906001600160a01b031681565b620000e46200012636600462000859565b62000225565b600254604051908152602001620000f8565b6003546200014f9063ffffffff1681565b60405163ffffffff9091168152602001620000f8565b6200017c6200017636600462000873565b62000250565b005b6200017c6200018f366004620008bf565b620002a2565b600554620000e4906001600160a01b031681565b6200017c620001ba366004620008bf565b620002f1565b620000e4620001d1366004620008dd565b620003cc565b620000e4620001e8366004620008dd565b60016020908152600092835260408084209091529082529020546001600160a01b031681565b6200017c6200021f366004620008bf565b620007f0565b600281815481106200023657600080fd5b6000918252602090912001546001600160a01b0316905081565b6004546001600160a01b03163314620002865760405162461bcd60e51b81526004016200027d9062000915565b60405180910390fd5b6003805463ffffffff191663ffffffff92909216919091179055565b6004546001600160a01b03163314620002cf5760405162461bcd60e51b81526004016200027d9062000915565b600480546001600160a01b0319166001600160a01b0392909216919091179055565b600054610100900460ff166200030e5760005460ff161562000312565b303b155b620003775760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b60648201526084016200027d565b600054610100900460ff161580156200039a576000805461ffff19166101011790555b600580546001600160a01b0319166001600160a01b0384161790558015620003c8576000805461ff00191690555b5050565b6005546000906001600160a01b031633146200043c5760405162461bcd60e51b815260206004820152602860248201527f496e76616c696420557365722c204f6e6c79205457414d4d2043616e2043726560448201526730ba32902830b4b960c11b60648201526084016200027d565b6005546001600160a01b0316620004a25760405162461bcd60e51b8152602060048201526024808201527f466163746f7279204e6f7420496e697469616c697a6564204279205457414d4d6044820152630816595d60e21b60648201526084016200027d565b816001600160a01b0316836001600160a01b03161415620005065760405162461bcd60e51b815260206004820152601c60248201527f466163746f72793a204964656e746963616c204164647265737365730000000060448201526064016200027d565b600080836001600160a01b0316856001600160a01b0316106200052b5783856200052e565b84845b90925090506001600160a01b038216620005835760405162461bcd60e51b8152602060048201526015602482015274466163746f72793a205a65726f204164647265737360581b60448201526064016200027d565b6001600160a01b03828116600090815260016020908152604080832085851684529091529020541615620005f15760405162461bcd60e51b8152602060048201526014602482015273466163746f72793a20506169722045786973747360601b60448201526064016200027d565b60006040518060200162000605906200084b565b601f1982820381018352601f9091011660408181526005546001600160a01b03878116602085015286811692840192909252166060820152909150600090829060800160408051601f19818403018152908290526200066892916020016200097f565b60408051601f19818403018152908290526bffffffffffffffffffffffff19606087811b8216602085015286901b1660348301529150600090604801604051602081830303815290604052805190602001209050808251602084016000f595506001600160a01b038616620007205760405162461bcd60e51b815260206004820152601960248201527f437265617465323a204661696c6564204f6e204465706c6f790000000000000060448201526064016200027d565b6001600160a01b0385811660008181526001602081815260408084208a87168086529083528185208054978e166001600160a01b0319988916811790915584845282862087875284528286208054891682179055600280549586018155958690527f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace9094018054909716841790965592548351928352908201527f0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9910160405180910390a3505050505092915050565b6004546001600160a01b031633146200081d5760405162461bcd60e51b81526004016200027d9062000915565b600380546001600160a01b0390921664010000000002640100000000600160c01b0319909216919091179055565b6130b680620009a183390190565b6000602082840312156200086c57600080fd5b5035919050565b6000602082840312156200088657600080fd5b813563ffffffff811681146200089b57600080fd5b9392505050565b80356001600160a01b0381168114620008ba57600080fd5b919050565b600060208284031215620008d257600080fd5b6200089b82620008a2565b60008060408385031215620008f157600080fd5b620008fc83620008a2565b91506200090c60208401620008a2565b90509250929050565b6020808252601290820152712330b1ba37b93c9d102337b93134b23232b760711b604082015260600190565b6000815160005b8181101562000964576020818501810151868301520162000948565b8181111562000974576000828601525b509290920192915050565b60006200099862000991838662000941565b8462000941565b94935050505056fe608060405260016005553480156200001657600080fd5b50604051620030b6380380620030b683398101604081905262000039916200023f565b6040805180820182526009815268050756c7361722d4c560bc1b602080830191825283518085019094526006845265050554c2d4c560d41b90840152815191929162000088916003916200017c565b5080516200009e9060049060208401906200017c565b505060068054336001600160a01b0319918216179091556007805482166001600160a01b038781169182179092556008805484168784169081179091556009805490941692861692831790935560405163b71522cf60e01b8152600c6004820152602481019190915260448101929092526064820152436084820152600560a482015273b7f6625385425d034ef5930e034f2b79f7e002c7915063b71522cf9060c40160006040518083038186803b1580156200015a57600080fd5b505af41580156200016f573d6000803e3d6000fd5b50505050505050620002c6565b8280546200018a9062000289565b90600052602060002090601f016020900481019282620001ae5760008555620001f9565b82601f10620001c957805160ff1916838001178555620001f9565b82800160010185558215620001f9579182015b82811115620001f9578251825591602001919060010190620001dc565b50620002079291506200020b565b5090565b5b808211156200020757600081556001016200020c565b80516001600160a01b03811681146200023a57600080fd5b919050565b6000806000606084860312156200025557600080fd5b620002608462000222565b9250620002706020850162000222565b9150620002806040850162000222565b90509250925092565b600181811c908216806200029e57607f821691505b60208210811415620002c057634e487b7160e01b600052602260045260246000fd5b50919050565b612de080620002d66000396000f3fe608060405234801561001057600080fd5b506004361061023d5760003560e01c806366f55ece1161013b578063a9059cbb116100b8578063ceb2894c1161007c578063ceb2894c146105fc578063d5d859c11461061c578063dd62ed3e1461062f578063e098ef9714610668578063ec7dd7bb1461067157600080fd5b8063a9059cbb146105b3578063b61aaa54146105c6578063bde1077e146105ce578063c45a0155146105e1578063c4e41b22146105f457600080fd5b806395d89b41116100ff57806395d89b411461051157806398267d2e146105195780639c48a8f91461057a578063a201ccf61461058d578063a457c2d7146105a057600080fd5b806366f55ece146103fa5780636726aec01461041d5780636f9d42d21461047857806370a082311461048b578063769b1cf4146104b457600080fd5b806337bc5e4a116101c95780635e3f27271161018d5780635e3f2727146103b15780635f64b55b146103b95780635fea6120146103cc57806360a9d505146103df578063659509c5146103e757600080fd5b806337bc5e4a1461032357806339509351146103365780633a8c885e146103495780633b4a6bc31461036957806342b98a141461038957600080fd5b806318160ddd1161021057806318160ddd146102cf57806323b872dd146102d757806325ca3964146102ea5780632e0ae375146102ff578063313ce5671461031457600080fd5b806306fdde0314610242578063095ea7b3146102605780630fc63d101461028357806313bf4fd2146102ae575b600080fd5b61024a610691565b6040516102579190612955565b60405180910390f35b61027361026e3660046129a0565b610723565b6040519015158152602001610257565b600754610296906001600160a01b031681565b6040516001600160a01b039091168152602001610257565b6102c16102bc3660046129a0565b61073a565b604051908152602001610257565b6002546102c1565b6102736102e53660046129cc565b61088a565b6102f2610936565b6040516102579190612a0d565b61031261030d366004612a51565b610a0f565b005b60405160128152602001610257565b6102f2610331366004612a6a565b610a83565b6102736103443660046129a0565b610aef565b6102c1610357366004612a6a565b600b6020526000908152604090205481565b6007546001600160a01b03166000908152600b60205260409020546102c1565b61039c6103973660046129a0565b610b2b565b60408051928352602083019190915201610257565b6102c1601e81565b600854610296906001600160a01b031681565b61039c6103da3660046129a0565b610c7f565b6102c1600581565b6102c16103f5366004612a87565b610f73565b610273610408366004612a51565b60009081526015602052604090205460ff1690565b61039c61042b366004612a51565b6007546001600160a01b0390811660009081526011602081815260408084208685526002908101835281852054600854909616855292825280842095845294909101905291909120549091565b6102c1610486366004612a87565b611140565b6102c1610499366004612a6a565b6001600160a01b031660009081526020819052604090205490565b61039c6104c2366004612a51565b600081815260136020908152604080832060078101546002909101546001600160a01b039091168452601183528184209484526005850183528184205490845260069094019091529020549091565b61024a6112e5565b600d546007546001600160a01b0390811660009081526011602090815260408083208054600854909516845292819020805460019485015494909101548251968752928601949094528401929092526060830152608082015260a001610257565b6102c16105883660046129a0565b6112f4565b61039c61059b3660046129a0565b611427565b6102736105ae3660046129a0565b6116f6565b6102736105c13660046129a0565b61178f565b6012546102c1565b6102c16105dc366004612a87565b61179c565b600654610296906001600160a01b031681565b6102c1611959565b6008546001600160a01b03166000908152600b60205260409020546102c1565b6102c161062a3660046129a0565b611969565b6102c161063d366004612abc565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6102c1600a5481565b61068461067f366004612a51565b611a9c565b6040516102579190612af5565b6060600380546106a090612b71565b80601f01602080910402602001604051908101604052809291908181526020018280546106cc90612b71565b80156107195780601f106106ee57610100808354040283529160200191610719565b820191906000526020600020905b8154815290600101906020018083116106fc57829003601f168201915b5050505050905090565b6000610730338484611b8f565b5060015b92915050565b6009546000906001600160a01b031633146107705760405162461bcd60e51b815260040161076790612bac565b60405180910390fd5b6005546001146107925760405162461bcd60e51b815260040161076790612bd4565b6002600555604051634b7446ff60e01b8152600c60048201526001600160a01b038416602482015260448101839052600b606482015273b7f6625385425d034ef5930e034f2b79f7e002c790634b7446ff9060840160206040518083038186803b1580156107ff57600080fd5b505af4158015610813573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108379190612bf8565b60408051848152602081018390529192506001600160a01b038516917f79ad14fdc35ed5b53e895a80c1e26ecfd7b87c91f1659e6aa84fefb0841a02a291015b60405180910390a2600160055592915050565b6000610897848484611cb4565b6001600160a01b03841660009081526001602090815260408083203384529091529020548281101561091c5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610767565b6109298533858403611b8f565b60019150505b9392505050565b6040516378dbfc8160e11b81526016600482015260609073e550967eac8ccd1c2d5fbf8fd6265b091e39ff3d9063f1b7f9029060240160206040518083038186803b15801561098457600080fd5b505af4158015610998573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109bc9190612bf8565b80548060200260200160405190810160405280929190818152602001828054801561071957602002820191906000526020600020905b8154815260200190600101908083116109f2575050505050905090565b6040516357647c7f60e11b8152600c6004820152600b60248201526044810182905273b7f6625385425d034ef5930e034f2b79f7e002c79063aec8f8fe9060640160006040518083038186803b158015610a6857600080fd5b505af4158015610a7c573d6000803e3d6000fd5b5050505050565b6001600160a01b038116600090815260146020908152604091829020805483518184028101840190945280845260609392830182828015610ae357602002820191906000526020600020905b815481526020019060010190808311610acf575b50505050509050919050565b3360008181526001602090815260408083206001600160a01b03871684529091528120549091610730918590610b26908690612c27565b611b8f565b60095460009081906001600160a01b03163314610b5a5760405162461bcd60e51b815260040161076790612bac565b600554600114610b7c5760405162461bcd60e51b815260040161076790612bd4565b60026005556040516303bdeec560e41b8152600c60048201526001600160a01b038516602482015260448101849052600b606482015273b7f6625385425d034ef5930e034f2b79f7e002c790633bdeec5090608401604080518083038186803b158015610be857600080fd5b505af4158015610bfc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c209190612c3f565b604080518681526020810184905290810182905291935091506001600160a01b038516907f5187cf882c722b1f3c2b67d751013259c0cb8f36161622ce83ae6b8f6f163f539060600160405180910390a2600160055590939092509050565b60095460009081906001600160a01b03163314610cae5760405162461bcd60e51b815260040161076790612bac565b600554600114610cd05760405162461bcd60e51b815260040161076790612bd4565b60026005556040516357647c7f60e11b8152600c6004820152600b602482015243604482015273b7f6625385425d034ef5930e034f2b79f7e002c79063aec8f8fe9060640160006040518083038186803b158015610d2d57600080fd5b505af4158015610d41573d6000803e3d6000fd5b5050505060008311610d655760405162461bcd60e51b815260040161076790612c63565b600254610dbf5760405162461bcd60e51b815260206004820152602260248201527f4e6f204c697175696469747920486173204265656e2050726f76696465642059604482015261195d60f21b6064820152608401610767565b6007546001600160a01b039081166000908152600b6020526040808220546008549093168252902054600254610df58387612c8b565b610dff9190612cc0565b9350610e0a60025490565b610e148287612c8b565b610e1e9190612cc0565b6007546001600160a01b03166000908152600b6020526040812080549295508692909190610e4d908490612c27565b90915550506008546001600160a01b03166000908152600b602052604081208054859290610e7c908490612c27565b9091555060009050610e8e8383611e84565b9050610e9a8787612062565b8015610f15576008546001600160a01b03166000908152600b6020526040902054610f1190610f0390610ed590610ed090612141565b61218e565b6007546001600160a01b03166000908152600b6020526040902054610efd90610ed090612141565b906121e0565b670de0b6b3a7640000900490565b600a555b60408051878152602081018790529081018590526001600160a01b038816907f3bca7014f4c0ccc8016338c79f4c00e82068dbadaf4f01ca5449040fdd39f500906060015b60405180910390a2505060016005555090939092509050565b6009546000906001600160a01b03163314610fa05760405162461bcd60e51b815260040161076790612bac565b600554600114610fc25760405162461bcd60e51b815260040161076790612bd4565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061100957506008546001600160a01b03166000908152600b602052604090205415155b6110255760405162461bcd60e51b815260040161076790612ce2565b600083116110455760405162461bcd60e51b815260040161076790612c63565b60405163233d824760e21b8152600c60048201526001600160a01b03851660248201526044810184905260648101839052600b608482015273b7f6625385425d034ef5930e034f2b79f7e002c790638cf6091c9060a40160206040518083038186803b1580156110b457600080fd5b505af41580156110c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ec9190612bf8565b60408051858152602081018390529192506001600160a01b038616917f3f9021da39409c8415526f6f5150f90f549aff31c146178262479dd87789440091015b60405180910390a260016005559392505050565b6009546000906001600160a01b0316331461116d5760405162461bcd60e51b815260040161076790612bac565b60055460011461118f5760405162461bcd60e51b815260040161076790612bd4565b600260055582158015906111a35750600082115b6111bf5760405162461bcd60e51b815260040161076790612c63565b6002541561121b5760405162461bcd60e51b815260206004820152602360248201527f4c69717569646974792048617320416c7265616479204265656e2050726f766960448201526219195960ea1b6064820152608401610767565b6007546001600160a01b039081166000908152600b6020526040808220869055600854909216815220829055611265610f03611259610ed085612141565b610efd610ed087612141565b90506000611274600080611e84565b90506112808583612062565b801561128c57600a8290555b60408051838152602081018690529081018490526001600160a01b038616907f9e20617171fe14c750c3beebe1b256358b9688a6e6047c4dd5e1e81c003c44b89060600160405180910390a25060016005559392505050565b6060600480546106a090612b71565b6009546000906001600160a01b031633146113215760405162461bcd60e51b815260040161076790612bac565b6005546001146113435760405162461bcd60e51b815260040161076790612bd4565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061138a57506008546001600160a01b03166000908152600b602052604090205415155b6113a65760405162461bcd60e51b815260040161076790612ce2565b600082116113c65760405162461bcd60e51b815260040161076790612c63565b6008546007546113e3916001600160a01b039081169116846121ec565b60408051848152602081018390529192506001600160a01b038516917f4af12e31478f230aa2cdfffcb6fe9525e6d1862db211087abb6fd8771ccdbe579101610877565b60095460009081906001600160a01b031633146114565760405162461bcd60e51b815260040161076790612bac565b6005546001146114785760405162461bcd60e51b815260040161076790612bd4565b60026005556040516357647c7f60e11b8152600c6004820152600b602482015243604482015273b7f6625385425d034ef5930e034f2b79f7e002c79063aec8f8fe9060640160006040518083038186803b1580156114d557600080fd5b505af41580156114e9573d6000803e3d6000fd5b505050506000831161150d5760405162461bcd60e51b815260040161076790612c63565b600254831061155e5760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420456e6f756768204c7020546f6b656e7320417661696c61626c6500006044820152606401610767565b6007546001600160a01b039081166000908152600b60205260408082205460085490931682529020546002546115948684612c8b565b61159e9190612cc0565b93506115a960025490565b6115b38683612c8b565b6115bd9190612cc0565b6007546001600160a01b03166000908152600b60205260408120805492955086929091906115ec908490612d12565b90915550506008546001600160a01b03166000908152600b60205260408120805485929061161b908490612d12565b909155506000905061162d8383611e84565b90506116398787612372565b600954600754611656916001600160a01b039182169116876124bd565b600954600854611673916001600160a01b039182169116866124bd565b80156116ad576008546001600160a01b03166000908152600b60205260409020546116a990610f0390610ed590610ed090612141565b600a555b60408051878152602081018790529081018590526001600160a01b038816907f1dc8bb69df2b8e91fbdcbfcf93d951b3f0000f085a95fe3f7946d6161439245d90606001610f5a565b3360009081526001602090815260408083206001600160a01b0386168452909152812054828110156117785760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610767565b6117853385858403611b8f565b5060019392505050565b6000610730338484611cb4565b6009546000906001600160a01b031633146117c95760405162461bcd60e51b815260040161076790612bac565b6005546001146117eb5760405162461bcd60e51b815260040161076790612bd4565b60026005556007546001600160a01b03166000908152600b60205260409020541580159061183257506008546001600160a01b03166000908152600b602052604090205415155b61184e5760405162461bcd60e51b815260040161076790612ce2565b6000831161186e5760405162461bcd60e51b815260040161076790612c63565b604051632d2f332560e11b8152600c60048201526001600160a01b03851660248201526044810184905260648101839052600b608482015273b7f6625385425d034ef5930e034f2b79f7e002c790635a5e664a9060a40160206040518083038186803b1580156118dd57600080fd5b505af41580156118f1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119159190612bf8565b60408051858152602081018390529192506001600160a01b038616917f3118cfac1ed5d8e668c193690497d56fff82f1aabbdf08f598025b0dfe308727910161112c565b600061196460025490565b905090565b6009546000906001600160a01b031633146119965760405162461bcd60e51b815260040161076790612bac565b6005546001146119b85760405162461bcd60e51b815260040161076790612bd4565b60026005556007546001600160a01b03166000908152600b6020526040902054158015906119ff57506008546001600160a01b03166000908152600b602052604090205415155b611a1b5760405162461bcd60e51b815260040161076790612ce2565b60008211611a3b5760405162461bcd60e51b815260040161076790612c63565b600754600854611a58916001600160a01b039081169116846121ec565b60408051848152602081018390529192506001600160a01b038516917f4d8578764edd2464e6964176a4bbedef1497b6bed5dd14e0609ad9149a85e5fe9101610877565b611b0660405180610120016040528060008152602001600081526020016000815260200160008152602001600081526020016000815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b031681525090565b50600090815260136020908152604091829020825161012081018452815481526001820154928101929092526002810154928201929092526003820154606082015260048201546080820152600582015460a082015260068201546001600160a01b0390811660c08301526007830154811660e083015260089092015490911661010082015290565b6001600160a01b038316611bf15760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610767565b6001600160a01b038216611c525760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610767565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92591015b60405180910390a3505050565b6001600160a01b038316611d185760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610767565b6001600160a01b038216611d7a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610767565b6001600160a01b03831660009081526020819052604090205481811015611df25760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610767565b6001600160a01b03808516600090815260208190526040808220858503905591851681529081208054849290611e29908490612c27565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611e7591815260200190565b60405180910390a35b50505050565b600080600660009054906101000a90046001600160a01b03166001600160a01b031663793855486040518163ffffffff1660e01b815260040160206040518083038186803b158015611ed557600080fd5b505afa158015611ee9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f0d9190612d29565b90506000600660009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611f5f57600080fd5b505afa158015611f73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f979190612d4f565b6001600160a01b038116158015945090915061204c57600a5415612047576000611fd5610f03611fc9610ed088612141565b610efd610ed08a612141565b9050600a54811115612045576000600a5482611ff19190612d12565b600254611ffe9190612c8b565b90506000600a548563ffffffff16846120179190612c8b565b6120219190612c27565b9050600061202f8284612cc0565b90508015612041576120418582612062565b5050505b505b61205a565b600a541561205a576000600a555b505092915050565b6001600160a01b0382166120b85760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610767565b80600260008282546120ca9190612c27565b90915550506001600160a01b038216600090815260208190526040812080548392906120f7908490612c27565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f2182111561218057604051633492ffd960e01b815260048101839052602401610767565b50670de0b6b3a76400000290565b60007812725dd1d243aba0e75fe645cc4873f9e65afe688c928e1f218211156121cd57604051636155b67d60e01b815260048101839052602401610767565b610734670de0b6b3a7640000830261250f565b600061092f838361268a565b6009546000906001600160a01b031633146122195760405162461bcd60e51b815260040161076790612bac565b6040516357647c7f60e11b8152600c6004820152600b602482015243604482015273b7f6625385425d034ef5930e034f2b79f7e002c79063aec8f8fe9060640160006040518083038186803b15801561227157600080fd5b505af4158015612285573d6000803e3d6000fd5b505050506001600160a01b038481166000908152600b6020526040808220549286168252812054906122b78584612c27565b6122c18684612c8b565b6122cb9190612cc0565b90506127106122db601e82612d12565b6122e59083612c8b565b6122ef9190612cc0565b6001600160a01b0388166000908152600b602052604081208054929650879290919061231c908490612c27565b90915550506001600160a01b0386166000908152600b602052604081208054869290612349908490612d12565b9091555050600954612368906001600160a01b038881169116866124bd565b5050509392505050565b6001600160a01b0382166123d25760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610767565b6001600160a01b038216600090815260208190526040902054818110156124465760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610767565b6001600160a01b0383166000908152602081905260408120838303905560028054849290612475908490612d12565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef90602001611ca7565b505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b1790526124b890849061274c565b60008161251e57506000919050565b50600181600160801b81106125385760409190911b9060801c5b6801000000000000000081106125535760209190911b9060401c5b640100000000811061256a5760109190911b9060201c5b62010000811061257f5760089190911b9060101c5b61010081106125935760049190911b9060081c5b601081106125a65760029190911b9060041c5b600881106125b657600182901b91505b60018284816125c7576125c7612caa565b048301901c915060018284816125df576125df612caa565b048301901c915060018284816125f7576125f7612caa565b048301901c9150600182848161260f5761260f612caa565b048301901c9150600182848161262757612627612caa565b048301901c9150600182848161263f5761263f612caa565b048301901c9150600182848161265757612657612caa565b048301901c9150600082848161266f5761266f612caa565b049050808310156126805782612682565b805b949350505050565b60008080600019848609848602925082811083820303915050670de0b6b3a764000081106126ce5760405163698d9a0160e11b815260048101829052602401610767565b600080670de0b6b3a76400008688099150506706f05b59d3b1ffff8111826127085780670de0b6b3a7640000850401945050505050610734565b620400008285030493909111909103600160ee1b02919091177faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac106690201905092915050565b60006127a1826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661281e9092919063ffffffff16565b8051909150156124b857808060200190518101906127bf9190612d6c565b6124b85760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610767565b6060612682848460008585843b6128775760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610767565b600080866001600160a01b031685876040516128939190612d8e565b60006040518083038185875af1925050503d80600081146128d0576040519150601f19603f3d011682016040523d82523d6000602084013e6128d5565b606091505b50915091506128e58282866128f0565b979650505050505050565b606083156128ff57508161092f565b82511561290f5782518084602001fd5b8160405162461bcd60e51b81526004016107679190612955565b60005b8381101561294457818101518382015260200161292c565b83811115611e7e5750506000910152565b6020815260008251806020840152612974816040850160208701612929565b601f01601f19169190910160400192915050565b6001600160a01b038116811461299d57600080fd5b50565b600080604083850312156129b357600080fd5b82356129be81612988565b946020939093013593505050565b6000806000606084860312156129e157600080fd5b83356129ec81612988565b925060208401356129fc81612988565b929592945050506040919091013590565b6020808252825182820181905260009190848201906040850190845b81811015612a4557835183529284019291840191600101612a29565b50909695505050505050565b600060208284031215612a6357600080fd5b5035919050565b600060208284031215612a7c57600080fd5b813561092f81612988565b600080600060608486031215612a9c57600080fd5b8335612aa781612988565b95602085013595506040909401359392505050565b60008060408385031215612acf57600080fd5b8235612ada81612988565b91506020830135612aea81612988565b809150509250929050565b600061012082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160018060a01b0380821660c08501528060e08601511660e085015250506101008084015161205a828501826001600160a01b03169052565b600181811c90821680612b8557607f821691505b60208210811415612ba657634e487b7160e01b600052602260045260246000fd5b50919050565b6020808252600e908201526d24b73b30b634b21021b0b63632b960911b604082015260600190565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b600060208284031215612c0a57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115612c3a57612c3a612c11565b500190565b60008060408385031215612c5257600080fd5b505080516020909101519092909150565b6020808252600e908201526d125b9d985b1a5908105b5bdd5b9d60921b604082015260600190565b6000816000190483118215151615612ca557612ca5612c11565b500290565b634e487b7160e01b600052601260045260246000fd5b600082612cdd57634e487b7160e01b600052601260045260246000fd5b500490565b602080825260169082015275496e73756666696369656e74204c697175696469747960501b604082015260600190565b600082821015612d2457612d24612c11565b500390565b600060208284031215612d3b57600080fd5b815163ffffffff8116811461092f57600080fd5b600060208284031215612d6157600080fd5b815161092f81612988565b600060208284031215612d7e57600080fd5b8151801515811461092f57600080fd5b60008251612da0818460208701612929565b919091019291505056fea2646970667358221220a8e6ffe19eeb99683ee45faa2ddfc4c66807889e1bb4dca829ffb626d26a9ff864736f6c63430008090033a2646970667358221220de8ee54173930d97cf18a740c0ed65c54b98bd3a3cfc8da3dba0f96bd7b493d964736f6c63430008090033

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

000000000000000000000000cb3a9bfc9f99e75e922a516eed04d9f62e83a28e

-----Decoded View---------------
Arg [0] : _feeToSetter (address): 0xCB3A9BFC9f99E75E922a516EED04D9F62e83a28E

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000cb3a9bfc9f99e75e922a516eed04d9f62e83a28e


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.