ETH Price: $3,131.01 (-5.56%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Token Holdings

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Instant Swap Tok...215066812024-12-29 7:37:5929 days ago1735457879IN
Pulsar Protocol: TWAMM
0 ETH0.000921923.35220247
Instant Swap Tok...214235512024-12-17 16:48:3540 days ago1734454115IN
Pulsar Protocol: TWAMM
0 ETH0.0069676925.93526731
Instant Swap Tok...214004402024-12-14 11:24:4744 days ago1734175487IN
Pulsar Protocol: TWAMM
0 ETH0.002140768.51087288
Withdraw Liquidi...212332622024-11-21 2:55:5967 days ago1732157759IN
Pulsar Protocol: TWAMM
0 ETH0.0031678310.6
Instant Swap Tok...212232582024-11-19 17:25:2368 days ago1732037123IN
Pulsar Protocol: TWAMM
0 ETH0.006458224.03884341
Withdraw Liquidi...210190212024-10-22 5:26:2397 days ago1729574783IN
Pulsar Protocol: TWAMM
0 ETH0.001906726.03504063
Instant Swap Tok...210043442024-10-20 4:17:1199 days ago1729397831IN
Pulsar Protocol: TWAMM
0 ETH0.001832226.6630138
Instant Swap Tok...209991562024-10-19 10:55:59100 days ago1729335359IN
Pulsar Protocol: TWAMM
0 ETH0.002068797.70118387
Instant Swap Tok...207776992024-09-18 13:13:11131 days ago1726665191IN
Pulsar Protocol: TWAMM
0 ETH0.002017088.01916669
Instant Swap Tok...207698602024-09-17 10:54:11132 days ago1726570451IN
Pulsar Protocol: TWAMM
0 ETH0.000863343.43232281
Instant Swap Tok...205504882024-08-17 19:39:59162 days ago1723923599IN
Pulsar Protocol: TWAMM
0 ETH0.000301991.10618123
Withdraw Liquidi...205481502024-08-17 11:49:11163 days ago1723895351IN
Pulsar Protocol: TWAMM
0 ETH0.000432861.29981107
Instant Swap Tok...205265432024-08-14 11:22:23166 days ago1723634543IN
Pulsar Protocol: TWAMM
0 ETH0.000691962.57609545
Instant Swap Tok...205241322024-08-14 3:17:59166 days ago1723605479IN
Pulsar Protocol: TWAMM
0 ETH0.00027781
Instant Swap Tok...205191862024-08-13 10:44:35167 days ago1723545875IN
Pulsar Protocol: TWAMM
0 ETH0.000466581.85513125
Withdraw Liquidi...204534332024-08-04 6:35:59176 days ago1722753359IN
Pulsar Protocol: TWAMM
0 ETH0.000023271
Withdraw Liquidi...204534332024-08-04 6:35:59176 days ago1722753359IN
Pulsar Protocol: TWAMM
0 ETH0.000023260.99953741
Withdraw Liquidi...202226132024-07-03 1:10:23208 days ago1719969023IN
Pulsar Protocol: TWAMM
0 ETH0.001379864.36760603
Instant Swap Tok...201583222024-06-24 1:39:35217 days ago1719193175IN
Pulsar Protocol: TWAMM
0 ETH0.000603912.40068956
Instant Swap Tok...201583132024-06-24 1:37:47217 days ago1719193067IN
Pulsar Protocol: TWAMM
0 ETH0.0007242.62167543
Instant Swap Tok...201456872024-06-22 7:14:59219 days ago1719040499IN
Pulsar Protocol: TWAMM
0 ETH0.000709512.56917973
Instant Swap Tok...201386962024-06-21 7:47:11220 days ago1718956031IN
Pulsar Protocol: TWAMM
0 ETH0.001182834.28273287
Instant Swap Tok...201374922024-06-21 3:44:47220 days ago1718941487IN
Pulsar Protocol: TWAMM
0 ETH0.000990853.566211
Withdraw Liquidi...201374582024-06-21 3:37:59220 days ago1718941079IN
Pulsar Protocol: TWAMM
0 ETH0.001123713.37420981
Instant Swap Tok...201099262024-06-17 7:09:47224 days ago1718608187IN
Pulsar Protocol: TWAMM
0 ETH0.000980653.65019666
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
TWAMM

Compiler Version
v0.8.9+commit.e5eed63a

Optimization Enabled:
Yes with 200 runs

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

pragma solidity ^0.8.9;

import "./interfaces/ITWAMM.sol";
import "./interfaces/IPair.sol";
import "./interfaces/IFactory.sol";
import "./interfaces/IWETH.sol";
import "./libraries/Library.sol";
import "./libraries/TransferHelper.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract TWAMM is ITWAMM {
    using Library for address;
    using SafeERC20 for IERC20;

    address public immutable override factory;
    address public immutable override WETH;

    modifier ensure(uint256 deadline) {
        require(deadline >= block.timestamp, "TWAMM: Expired");
        _;
    }

    constructor(address _factory, address _WETH) {
        factory = _factory;
        WETH = _WETH;
        IFactory(factory).initialize(address(this));
    }

    receive() external payable {
        assert(msg.sender == WETH); // only accept ETH via fallback from the WETH contract
    }

    function obtainReserves(
        address token0,
        address token1
    ) external view override returns (uint256 reserve0, uint256 reserve1) {
        (reserve0, reserve1) = Library.getReserves(factory, token0, token1);
    }

    function obtainTotalSupply(
        address token0,
        address token1
    ) external view override returns (uint256) {
        if (IFactory(factory).getPair(token0, token1) == address(0)) {
            return 0;
        } else {
            address pair = IFactory(factory).getPair(token0, token1);
            return IPair(pair).getTotalSupply();
        }
    }

    function obtainPairAddress(
        address token0,
        address token1
    ) external view override returns (address) {
        return Library.pairFor(factory, token0, token1);
    }

    function createPairWrapper(
        address token0,
        address token1,
        uint256 deadline
    ) external virtual override ensure(deadline) returns (address pair) {
        require(
            IFactory(factory).getPair(token0, token1) == address(0),
            "Pair Existing Already!"
        );
        pair = IFactory(factory).createPair(token0, token1);
    }

    function addInitialLiquidity(
        address token0,
        address token1,
        uint256 amount0,
        uint256 amount1,
        uint256 deadline
    )
        external
        virtual
        override
        ensure(deadline)
        returns (uint256 lpTokenAmount)
    {
        // create the pair if it doesn't exist yet
        if (IFactory(factory).getPair(token0, token1) == address(0)) {
            IFactory(factory).createPair(token0, token1);
        }

        address pair = Library.pairFor(factory, token0, token1);
        IERC20(token0).safeTransferFrom(msg.sender, pair, amount0);
        IERC20(token1).safeTransferFrom(msg.sender, pair, amount1);

        (uint256 amountA, uint256 amountB) = Library.sortAmounts(
            token0,
            token1,
            amount0,
            amount1
        );
        lpTokenAmount = IPair(pair).provideInitialLiquidity(
            msg.sender,
            amountA,
            amountB
        );
    }

    function addInitialLiquidityETH(
        address token,
        uint256 amountToken,
        uint256 amountETH,
        uint256 deadline
    )
        external
        payable
        virtual
        override
        ensure(deadline)
        returns (uint256 lpTokenAmount)
    {
        // create the pair if it doesn't exist yet
        if (IFactory(factory).getPair(token, WETH) == address(0)) {
            IFactory(factory).createPair(token, WETH);
        }

        address pair = Library.pairFor(factory, token, WETH);
        IERC20(token).safeTransferFrom(msg.sender, pair, amountToken);
        IWETH(WETH).deposit{value: amountETH}();
        IERC20(WETH).safeTransfer(pair, amountETH);

        (uint256 amountA, uint256 amountB) = Library.sortAmounts(
            token,
            WETH,
            amountToken,
            amountETH
        );
        lpTokenAmount = IPair(pair).provideInitialLiquidity(
            msg.sender,
            amountA,
            amountB
        );

        // refund dust eth, if any
        if (msg.value > amountETH) {
            TransferHelper.safeTransferETH(msg.sender, msg.value - amountETH);
        }
    }

    function addLiquidity(
        address token0,
        address token1,
        uint256 lpTokenAmount,
        uint256 amountIn0Max,
        uint256 amountIn1Max,
        uint256 deadline
    )
        external
        virtual
        override
        ensure(deadline)
        returns (uint256 amountIn0, uint256 amountIn1)
    {
        address pair = Library.pairFor(factory, token0, token1);
        IPair(pair).executeVirtualOrders(block.number);
        {
            // scope to avoid stack too deep errors
            (uint256 reserve0, uint256 reserve1) = Library.getReserves(
                factory,
                token0,
                token1
            );
            uint256 totalSupplyLP = IPair(pair).getTotalSupply();
            amountIn0 = (lpTokenAmount * reserve0) / totalSupplyLP;
            amountIn1 = (lpTokenAmount * reserve1) / totalSupplyLP;
        }

        require(
            amountIn0 <= amountIn0Max && amountIn1 <= amountIn1Max,
            "Excessive Input Amount"
        );
        IERC20(token0).safeTransferFrom(msg.sender, pair, amountIn0);
        IERC20(token1).safeTransferFrom(msg.sender, pair, amountIn1);
        IPair(pair).provideLiquidity(msg.sender, lpTokenAmount);
    }

    function addLiquidityETH(
        address token,
        uint256 lpTokenAmount,
        uint256 amountTokenInMax,
        uint256 amountETHInMax,
        uint256 deadline
    )
        external
        payable
        virtual
        override
        ensure(deadline)
        returns (uint256 amountTokenIn, uint256 amountETHIn)
    {
        address pair = Library.pairFor(factory, token, WETH);
        IPair(pair).executeVirtualOrders(block.number);
        {
            // scope to avoid stack too deep errors
            (uint256 reserveToken, uint256 reserveETH) = Library.getReserves(
                factory,
                token,
                WETH
            );
            uint256 totalSupplyLP = IPair(pair).getTotalSupply();
            amountTokenIn = (lpTokenAmount * reserveToken) / totalSupplyLP;
            amountETHIn = (lpTokenAmount * reserveETH) / totalSupplyLP;
        }

        require(
            amountTokenIn <= amountTokenInMax && amountETHIn <= amountETHInMax,
            "Excessive Input Amount"
        );
        IERC20(token).safeTransferFrom(msg.sender, pair, amountTokenIn);
        IWETH(WETH).deposit{value: amountETHIn}();
        IERC20(WETH).safeTransfer(pair, amountETHIn);
        IPair(pair).provideLiquidity(msg.sender, lpTokenAmount);

        // refund dust eth, if any
        if (msg.value > amountETHIn)
            TransferHelper.safeTransferETH(msg.sender, msg.value - amountETHIn);
    }

    function withdrawLiquidity(
        address token0,
        address token1,
        uint256 lpTokenAmount,
        uint256 amountOut0Min,
        uint256 amountOut1Min,
        uint256 deadline
    )
        external
        virtual
        override
        ensure(deadline)
        returns (uint256 amountOut0, uint256 amountOut1)
    {
        address pair = Library.pairFor(factory, token0, token1);
        {
            // scope to avoid stack too deep errors
            (uint256 amountOutA, uint256 amountOutB) = IPair(pair)
                .removeLiquidity(msg.sender, lpTokenAmount);
            (amountOut0, amountOut1) = Library.sortAmounts(
                token0,
                token1,
                amountOutA,
                amountOutB
            );
        }

        require(
            amountOut0 >= amountOut0Min && amountOut1 >= amountOut1Min,
            "Insufficient Output Amount"
        );
        require(
            IERC20(token0).balanceOf(address(this)) >= amountOut0 &&
                IERC20(token1).balanceOf(address(this)) >= amountOut1,
            "Inaccurate Amount for Tokens."
        );
        IERC20(token0).safeTransfer(msg.sender, amountOut0);
        IERC20(token1).safeTransfer(msg.sender, amountOut1);
    }

    function withdrawLiquidityETH(
        address token,
        uint256 lpTokenAmount,
        uint256 amountTokenOutMin,
        uint256 amountETHOutMin,
        uint256 deadline
    )
        external
        virtual
        override
        ensure(deadline)
        returns (uint256 amountTokenOut, uint256 amountETHOut)
    {
        address pair = Library.pairFor(factory, token, WETH);
        {
            // scope to avoid stack too deep errors
            (uint256 amountOutA, uint256 amountOutB) = IPair(pair)
                .removeLiquidity(msg.sender, lpTokenAmount);
            (amountTokenOut, amountETHOut) = Library.sortAmounts(
                token,
                WETH,
                amountOutA,
                amountOutB
            );
        }

        require(
            amountTokenOut >= amountTokenOutMin &&
                amountETHOut >= amountETHOutMin,
            "Insufficient Output Amount"
        );
        require(
            IERC20(token).balanceOf(address(this)) >= amountTokenOut &&
                IWETH(WETH).balanceOf(address(this)) >= amountETHOut,
            "Inaccurate Amount for Tokens."
        );
        IERC20(token).safeTransfer(msg.sender, amountTokenOut);
        IWETH(WETH).withdraw(amountETHOut);
        TransferHelper.safeTransferETH(msg.sender, amountETHOut);
    }

    function instantSwapTokenToToken(
        address token0,
        address token1,
        uint256 amountIn,
        uint256 amountOutMin,
        uint256 deadline
    ) external virtual override ensure(deadline) returns (uint256 amountOut) {
        address pair = Library.pairFor(factory, token0, token1);
        IERC20(token0).safeTransferFrom(msg.sender, pair, amountIn);
        (address tokenA, ) = Library.sortTokens(token0, token1);

        if (tokenA == token0) {
            amountOut = IPair(pair).instantSwapFromAToB(msg.sender, amountIn);
        } else {
            amountOut = IPair(pair).instantSwapFromBToA(msg.sender, amountIn);
        }

        require(amountOut >= amountOutMin, "Insufficient Output Amount");
        require(
            IERC20(token1).balanceOf(address(this)) >= amountOut,
            "Inaccurate Amount for Token."
        );
        IERC20(token1).safeTransfer(msg.sender, amountOut);
    }

    function instantSwapTokenToETH(
        address token,
        uint256 amountTokenIn,
        uint256 amountETHOutMin,
        uint256 deadline
    )
        external
        virtual
        override
        ensure(deadline)
        returns (uint256 amountETHOut)
    {
        address pair = Library.pairFor(factory, token, WETH);
        IERC20(token).safeTransferFrom(msg.sender, pair, amountTokenIn);
        (address tokenA, ) = Library.sortTokens(token, WETH);

        if (tokenA == token) {
            amountETHOut = IPair(pair).instantSwapFromAToB(
                msg.sender,
                amountTokenIn
            );
        } else {
            amountETHOut = IPair(pair).instantSwapFromBToA(
                msg.sender,
                amountTokenIn
            );
        }

        require(amountETHOut >= amountETHOutMin, "Insufficient Output Amount");
        require(
            IWETH(WETH).balanceOf(address(this)) >= amountETHOut,
            "Inaccurate Amount for WETH."
        );
        IWETH(WETH).withdraw(amountETHOut);
        TransferHelper.safeTransferETH(msg.sender, amountETHOut);
    }

    function instantSwapETHToToken(
        address token,
        uint256 amountETHIn,
        uint256 amountTokenOutMin,
        uint256 deadline
    )
        external
        payable
        virtual
        override
        ensure(deadline)
        returns (uint256 amountTokenOut)
    {
        address pair = Library.pairFor(factory, WETH, token);
        IWETH(WETH).deposit{value: amountETHIn}();
        IERC20(WETH).safeTransfer(pair, amountETHIn);
        (address tokenA, ) = Library.sortTokens(WETH, token);

        if (tokenA == WETH) {
            amountTokenOut = IPair(pair).instantSwapFromAToB(
                msg.sender,
                amountETHIn
            );
        } else {
            amountTokenOut = IPair(pair).instantSwapFromBToA(
                msg.sender,
                amountETHIn
            );
        }

        require(
            amountTokenOut >= amountTokenOutMin,
            "Insufficient Output Amount"
        );
        require(
            IERC20(token).balanceOf(address(this)) >= amountTokenOut,
            "Inaccurate Amount for Token."
        );
        IERC20(token).safeTransfer(msg.sender, amountTokenOut);

        // refund dust eth, if any
        if (msg.value > amountETHIn)
            TransferHelper.safeTransferETH(msg.sender, msg.value - amountETHIn);
    }

    function longTermSwapTokenToToken(
        address token0,
        address token1,
        uint256 amountIn,
        uint256 numberOfBlockIntervals,
        uint256 deadline
    ) external virtual override ensure(deadline) returns (uint256 orderId) {
        address pair = Library.pairFor(factory, token0, token1);
        IERC20(token0).safeTransferFrom(msg.sender, pair, amountIn);
        (address tokenA, ) = Library.sortTokens(token0, token1);

        if (tokenA == token0) {
            orderId = IPair(pair).longTermSwapFromAToB(
                msg.sender,
                amountIn,
                numberOfBlockIntervals
            );
        } else {
            orderId = IPair(pair).longTermSwapFromBToA(
                msg.sender,
                amountIn,
                numberOfBlockIntervals
            );
        }
    }

    function longTermSwapTokenToETH(
        address token,
        uint256 amountTokenIn,
        uint256 numberOfBlockIntervals,
        uint256 deadline
    ) external virtual override ensure(deadline) returns (uint256 orderId) {
        address pair = Library.pairFor(factory, token, WETH);
        IERC20(token).safeTransferFrom(msg.sender, pair, amountTokenIn);
        (address tokenA, ) = Library.sortTokens(token, WETH);

        if (tokenA == token) {
            orderId = IPair(pair).longTermSwapFromAToB(
                msg.sender,
                amountTokenIn,
                numberOfBlockIntervals
            );
        } else {
            orderId = IPair(pair).longTermSwapFromBToA(
                msg.sender,
                amountTokenIn,
                numberOfBlockIntervals
            );
        }
    }

    function longTermSwapETHToToken(
        address token,
        uint256 amountETHIn,
        uint256 numberOfBlockIntervals,
        uint256 deadline
    )
        external
        payable
        virtual
        override
        ensure(deadline)
        returns (uint256 orderId)
    {
        address pair = Library.pairFor(factory, WETH, token);
        IWETH(WETH).deposit{value: amountETHIn}();
        IERC20(WETH).safeTransfer(pair, amountETHIn);
        (address tokenA, ) = Library.sortTokens(WETH, token);

        if (tokenA == WETH) {
            orderId = IPair(pair).longTermSwapFromAToB(
                msg.sender,
                amountETHIn,
                numberOfBlockIntervals
            );
        } else {
            orderId = IPair(pair).longTermSwapFromBToA(
                msg.sender,
                amountETHIn,
                numberOfBlockIntervals
            );
        }

        // refund dust eth, if any
        if (msg.value > amountETHIn)
            TransferHelper.safeTransferETH(msg.sender, msg.value - amountETHIn);
    }

    function cancelTermSwapTokenToToken(
        address token0,
        address token1,
        uint256 orderId,
        uint256 deadline
    )
        external
        virtual
        override
        ensure(deadline)
        returns (uint256 unsoldAmount, uint256 purchasedAmount)
    {
        address pair = Library.pairFor(factory, token0, token1);
        address tokenSell = IPair(pair).getOrderDetails(orderId).sellTokenId;
        address tokenBuy = IPair(pair).getOrderDetails(orderId).buyTokenId;
        require(
            tokenSell == token0 && tokenBuy == token1,
            "Wrong Sell Or Buy Token"
        );

        (unsoldAmount, purchasedAmount) = IPair(pair).cancelLongTermSwap(
            msg.sender,
            orderId
        );

        require(
            IERC20(token0).balanceOf(address(this)) >= unsoldAmount &&
                IERC20(token1).balanceOf(address(this)) >= purchasedAmount,
            "Inaccurate Amount for Tokens."
        );
        IERC20(token0).safeTransfer(msg.sender, unsoldAmount);
        IERC20(token1).safeTransfer(msg.sender, purchasedAmount);
    }

    function cancelTermSwapTokenToETH(
        address token,
        uint256 orderId,
        uint256 deadline
    )
        external
        virtual
        override
        ensure(deadline)
        returns (uint256 unsoldTokenAmount, uint256 purchasedETHAmount)
    {
        address pair = Library.pairFor(factory, token, WETH);
        address tokenSell = IPair(pair).getOrderDetails(orderId).sellTokenId;
        address tokenBuy = IPair(pair).getOrderDetails(orderId).buyTokenId;
        require(
            tokenSell == token && tokenBuy == WETH,
            "Wrong Sell Or Buy Token"
        );

        (unsoldTokenAmount, purchasedETHAmount) = IPair(pair)
            .cancelLongTermSwap(msg.sender, orderId);

        require(
            IERC20(token).balanceOf(address(this)) >= unsoldTokenAmount &&
                IWETH(WETH).balanceOf(address(this)) >= purchasedETHAmount,
            "Inaccurate Amount for Tokens."
        );
        IERC20(token).safeTransfer(msg.sender, unsoldTokenAmount);
        IWETH(WETH).withdraw(purchasedETHAmount);
        TransferHelper.safeTransferETH(msg.sender, purchasedETHAmount);
    }

    function cancelTermSwapETHToToken(
        address token,
        uint256 orderId,
        uint256 deadline
    )
        external
        virtual
        override
        ensure(deadline)
        returns (uint256 unsoldETHAmount, uint256 purchasedTokenAmount)
    {
        address pair = Library.pairFor(factory, WETH, token);
        address tokenSell = IPair(pair).getOrderDetails(orderId).sellTokenId;
        address tokenBuy = IPair(pair).getOrderDetails(orderId).buyTokenId;
        require(
            tokenSell == WETH && tokenBuy == token,
            "Wrong Sell Or Buy Token"
        );

        (unsoldETHAmount, purchasedTokenAmount) = IPair(pair)
            .cancelLongTermSwap(msg.sender, orderId);

        require(
            IERC20(token).balanceOf(address(this)) >= purchasedTokenAmount &&
                IWETH(WETH).balanceOf(address(this)) >= unsoldETHAmount,
            "Inaccurate Amount for Tokens."
        );
        IERC20(token).safeTransfer(msg.sender, purchasedTokenAmount);
        IWETH(WETH).withdraw(unsoldETHAmount);
        TransferHelper.safeTransferETH(msg.sender, unsoldETHAmount);
    }

    function withdrawProceedsFromTermSwapTokenToToken(
        address token0,
        address token1,
        uint256 orderId,
        uint256 deadline
    ) external virtual override ensure(deadline) returns (uint256 proceeds) {
        address pair = Library.pairFor(factory, token0, token1);
        address tokenSell = IPair(pair).getOrderDetails(orderId).sellTokenId;
        address tokenBuy = IPair(pair).getOrderDetails(orderId).buyTokenId;
        require(
            tokenSell == token0 && tokenBuy == token1,
            "Wrong Sell Or Buy Token"
        );

        proceeds = IPair(pair).withdrawProceedsFromLongTermSwap(
            msg.sender,
            orderId
        );

        require(
            IERC20(token1).balanceOf(address(this)) >= proceeds,
            "Inaccurate Amount for Token."
        );
        IERC20(token1).safeTransfer(msg.sender, proceeds);
    }

    function withdrawProceedsFromTermSwapTokenToETH(
        address token,
        uint256 orderId,
        uint256 deadline
    ) external virtual override ensure(deadline) returns (uint256 proceedsETH) {
        address pair = Library.pairFor(factory, token, WETH);
        address tokenSell = IPair(pair).getOrderDetails(orderId).sellTokenId;
        address tokenBuy = IPair(pair).getOrderDetails(orderId).buyTokenId;
        require(
            tokenSell == token && tokenBuy == WETH,
            "Wrong Sell Or Buy Token"
        );

        proceedsETH = IPair(pair).withdrawProceedsFromLongTermSwap(
            msg.sender,
            orderId
        );

        require(
            IWETH(WETH).balanceOf(address(this)) >= proceedsETH,
            "Inaccurate Amount for WETH."
        );
        IWETH(WETH).withdraw(proceedsETH);
        TransferHelper.safeTransferETH(msg.sender, proceedsETH);
    }

    function withdrawProceedsFromTermSwapETHToToken(
        address token,
        uint256 orderId,
        uint256 deadline
    )
        external
        virtual
        override
        ensure(deadline)
        returns (uint256 proceedsToken)
    {
        address pair = Library.pairFor(factory, WETH, token);
        address tokenSell = IPair(pair).getOrderDetails(orderId).sellTokenId;
        address tokenBuy = IPair(pair).getOrderDetails(orderId).buyTokenId;
        require(
            tokenSell == WETH && tokenBuy == token,
            "Wrong Sell Or Buy Token"
        );

        proceedsToken = IPair(pair).withdrawProceedsFromLongTermSwap(
            msg.sender,
            orderId
        );

        require(
            IERC20(token).balanceOf(address(this)) >= proceedsToken,
            "Inaccurate Amount for Token."
        );
        IERC20(token).safeTransfer(msg.sender, proceedsToken);
    }

    function executeVirtualOrdersWrapper(
        address pair,
        uint256 blockNumber
    ) external virtual override {
        IPair(pair).executeVirtualOrders(blockNumber);
    }
}

File 2 of 20 : ITWAMM.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

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

    function WETH() external view returns (address);

    function obtainReserves(
        address token0,
        address token1
    ) external view returns (uint256 reserve0, uint256 reserve1);

    function obtainTotalSupply(
        address token0,
        address token1
    ) external view returns (uint256);

    function obtainPairAddress(
        address token0,
        address token1
    ) external view returns (address);

    function createPairWrapper(
        address token0,
        address token1,
        uint256 deadline
    ) external returns (address pair);

    function addInitialLiquidity(
        address token0,
        address token1,
        uint256 amount0,
        uint256 amount1,
        uint256 deadline
    ) external returns (uint256 lpTokenAmount);

    function addInitialLiquidityETH(
        address token,
        uint256 amountToken,
        uint256 amountETH,
        uint256 deadline
    ) external payable returns (uint256 lpTokenAmount);

    function addLiquidity(
        address token0,
        address token1,
        uint256 lpTokenAmount,
        uint256 amountIn0Max,
        uint256 amountIn1Max,
        uint256 deadline
    ) external returns (uint256 amountIn0, uint256 amountIn1);

    function addLiquidityETH(
        address token,
        uint256 lpTokenAmount,
        uint256 amountTokenInMax,
        uint256 amountETHInMax,
        uint256 deadline
    ) external payable returns (uint256 amountTokenIn, uint256 amountETHIn);

    function withdrawLiquidity(
        address token0,
        address token1,
        uint256 lpTokenAmount,
        uint256 amountOut0Min,
        uint256 amountOut1Min,
        uint256 deadline
    ) external returns (uint256 amountOut0, uint256 amountOut1);

    function withdrawLiquidityETH(
        address token,
        uint256 lpTokenAmount,
        uint256 amountTokenOutMin,
        uint256 amountETHOutMin,
        uint256 deadline
    ) external returns (uint256 amountTokenOut, uint256 amountETHOut);

    function instantSwapTokenToToken(
        address token0,
        address token1,
        uint256 amountIn,
        uint256 amountOutMin,
        uint256 deadline
    ) external returns (uint256 amountOut);

    function instantSwapTokenToETH(
        address token,
        uint256 amountTokenIn,
        uint256 amountETHOutMin,
        uint256 deadline
    ) external returns (uint256 amountETHOut);

    function instantSwapETHToToken(
        address token,
        uint256 amountETHIn,
        uint256 amountTokenOutMin,
        uint256 deadline
    ) external payable returns (uint256 amountTokenOut);

    function longTermSwapTokenToToken(
        address token0,
        address token1,
        uint256 amountIn,
        uint256 numberOfBlockIntervals,
        uint256 deadline
    ) external returns (uint256 orderId);

    function longTermSwapTokenToETH(
        address token,
        uint256 amountTokenIn,
        uint256 numberOfBlockIntervals,
        uint256 deadline
    ) external returns (uint256 orderId);

    function longTermSwapETHToToken(
        address token,
        uint256 amountETHIn,
        uint256 numberOfBlockIntervals,
        uint256 deadline
    ) external payable returns (uint256 orderId);

    function cancelTermSwapTokenToToken(
        address token0,
        address token1,
        uint256 orderId,
        uint256 deadline
    ) external returns (uint256 unsoldAmount, uint256 purchasedAmount);

    function cancelTermSwapTokenToETH(
        address token,
        uint256 orderId,
        uint256 deadline
    ) external returns (uint256 unsoldTokenAmount, uint256 purchasedETHAmount);

    function cancelTermSwapETHToToken(
        address token,
        uint256 orderId,
        uint256 deadline
    ) external returns (uint256 unsoldETHAmount, uint256 purchasedTokenAmount);

    function withdrawProceedsFromTermSwapTokenToToken(
        address token0,
        address token1,
        uint256 orderId,
        uint256 deadline
    ) external returns (uint256 proceeds);

    function withdrawProceedsFromTermSwapTokenToETH(
        address token,
        uint256 orderId,
        uint256 deadline
    ) external returns (uint256 proceedsETH);

    function withdrawProceedsFromTermSwapETHToToken(
        address token,
        uint256 orderId,
        uint256 deadline
    ) external returns (uint256 proceedsToken);

    function executeVirtualOrdersWrapper(
        address pair,
        uint256 blockNumber
    ) external;
}

File 3 of 20 : 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 4 of 20 : 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 5 of 20 : IWETH.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

interface IWETH {
    function deposit() external payable;

    function transfer(address to, uint256 value) external returns (bool);

    function withdraw(uint256) external;

    function balanceOf(address) external returns (uint256);
}

File 6 of 20 : Library.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

import "../interfaces/IPair.sol";
import "../interfaces/IFactory.sol";
import "../Pair.sol";

library Library {
    // returns sorted token addresses, used to handle return values from pairs sorted in this order
    function sortTokens(
        address token0,
        address token1
    ) public pure returns (address tokenA, address tokenB) {
        require(token0 != token1, "Library: Identical Addresses");
        (tokenA, tokenB) = token0 < token1
            ? (token0, token1)
            : (token1, token0);
        require(tokenA != address(0), "Library: Zero Address");
    }

    // calculates the CREATE2 address for a pair without making any external calls
    function pairFor(
        address factory,
        address token0,
        address token1
    ) public view returns (address pair) {
        (address tokenA, address tokenB) = sortTokens(token0, token1);
        bytes memory bytecode = type(Pair).creationCode;
        bytes memory bytecodeArg = abi.encodePacked(
            bytecode,
            abi.encode(tokenA, tokenB, IFactory(factory).twammAdd())
        );
        pair = address(
            uint160(
                uint256(
                    keccak256(
                        abi.encodePacked(
                            bytes1(0xff),
                            factory,
                            keccak256(abi.encodePacked(tokenA, tokenB)),
                            keccak256(bytecodeArg)
                        )
                    )
                )
            )
        );
    }

    // fetches and sorts the reserves for a pair
    function getReserves(
        address factory,
        address token0,
        address token1
    ) public view returns (uint256 reserve0, uint256 reserve1) {
        (address tokenA, ) = sortTokens(token0, token1);
        uint256 reserveA = IPair(pairFor(factory, token0, token1))
            .tokenAReserves();
        uint256 reserveB = IPair(pairFor(factory, token0, token1))
            .tokenBReserves();
        (reserve0, reserve1) = token0 == tokenA
            ? (reserveA, reserveB)
            : (reserveB, reserveA);
    }

    // sorts the amounts for tokens
    function sortAmounts(
        address token0,
        address token1,
        uint256 amount0,
        uint256 amount1
    ) public pure returns (uint256 amountA, uint256 amountB) {
        (address tokenA, ) = sortTokens(token0, token1);
        (amountA, amountB) = token0 == tokenA
            ? (amount0, amount1)
            : (amount1, amount0);
    }

    // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
    function quote(
        uint256 amount0,
        uint256 reserve0,
        uint256 reserve1
    ) public pure returns (uint256 amount1) {
        require(amount0 > 0, "Library: Insufficient Amount");
        require(
            reserve0 > 0 && reserve1 > 0,
            "Library: Insufficient_Liquidity"
        );
        amount1 = (amount0 * reserve1) / reserve0;
    }
}

File 7 of 20 : TransferHelper.sol
// SPDX-License-Identifier: GPL-3.0-or-later

pragma solidity ^0.8.9;

// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
    function safeApprove(address token, address to, uint256 value) public {
        // bytes4(keccak256(bytes('approve(address,uint256)')));
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(0x095ea7b3, to, value)
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "TransferHelper::safeApprove: approve failed"
        );
    }

    function safeTransfer(address token, address to, uint256 value) public {
        // bytes4(keccak256(bytes('transfer(address,uint256)')));
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(0xa9059cbb, to, value)
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "TransferHelper::safeTransfer: transfer failed"
        );
    }

    function safeTransferFrom(
        address token,
        address from,
        address to,
        uint256 value
    ) public {
        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
        (bool success, bytes memory data) = token.call(
            abi.encodeWithSelector(0x23b872dd, from, to, value)
        );
        require(
            success && (data.length == 0 || abi.decode(data, (bool))),
            "TransferHelper::transferFrom: transferFrom failed"
        );
    }

    function safeTransferETH(address to, uint256 value) public {
        (bool success, ) = to.call{value: value}(new bytes(0));
        require(
            success,
            "TransferHelper::safeTransferETH: ETH transfer failed"
        );
    }
}

File 8 of 20 : 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 9 of 20 : 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 10 of 20 : 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 11 of 20 : 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 12 of 20 : 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 13 of 20 : 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 14 of 20 : 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 15 of 20 : 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 20 : 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 17 of 20 : 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 18 of 20 : 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 19 of 20 : 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 20 of 20 : 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;
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {
    "contracts/libraries/Library.sol": {
      "Library": "0x818bae51c49175d18acab069cb23b6c7ea62a619"
    },
    "contracts/libraries/TransferHelper.sol": {
      "TransferHelper": "0x44338b6e22bb6b1e97d218754b3d8d6a61f6a689"
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"amount0","type":"uint256"},{"internalType":"uint256","name":"amount1","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addInitialLiquidity","outputs":[{"internalType":"uint256","name":"lpTokenAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountToken","type":"uint256"},{"internalType":"uint256","name":"amountETH","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addInitialLiquidityETH","outputs":[{"internalType":"uint256","name":"lpTokenAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"lpTokenAmount","type":"uint256"},{"internalType":"uint256","name":"amountIn0Max","type":"uint256"},{"internalType":"uint256","name":"amountIn1Max","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"amountIn0","type":"uint256"},{"internalType":"uint256","name":"amountIn1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"lpTokenAmount","type":"uint256"},{"internalType":"uint256","name":"amountTokenInMax","type":"uint256"},{"internalType":"uint256","name":"amountETHInMax","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidityETH","outputs":[{"internalType":"uint256","name":"amountTokenIn","type":"uint256"},{"internalType":"uint256","name":"amountETHIn","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"cancelTermSwapETHToToken","outputs":[{"internalType":"uint256","name":"unsoldETHAmount","type":"uint256"},{"internalType":"uint256","name":"purchasedTokenAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"cancelTermSwapTokenToETH","outputs":[{"internalType":"uint256","name":"unsoldTokenAmount","type":"uint256"},{"internalType":"uint256","name":"purchasedETHAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"cancelTermSwapTokenToToken","outputs":[{"internalType":"uint256","name":"unsoldAmount","type":"uint256"},{"internalType":"uint256","name":"purchasedAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"createPairWrapper","outputs":[{"internalType":"address","name":"pair","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pair","type":"address"},{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"executeVirtualOrdersWrapper","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountETHIn","type":"uint256"},{"internalType":"uint256","name":"amountTokenOutMin","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"instantSwapETHToToken","outputs":[{"internalType":"uint256","name":"amountTokenOut","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountTokenIn","type":"uint256"},{"internalType":"uint256","name":"amountETHOutMin","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"instantSwapTokenToETH","outputs":[{"internalType":"uint256","name":"amountETHOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"instantSwapTokenToToken","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountETHIn","type":"uint256"},{"internalType":"uint256","name":"numberOfBlockIntervals","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"longTermSwapETHToToken","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amountTokenIn","type":"uint256"},{"internalType":"uint256","name":"numberOfBlockIntervals","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"longTermSwapTokenToETH","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"numberOfBlockIntervals","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"longTermSwapTokenToToken","outputs":[{"internalType":"uint256","name":"orderId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"}],"name":"obtainPairAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"}],"name":"obtainReserves","outputs":[{"internalType":"uint256","name":"reserve0","type":"uint256"},{"internalType":"uint256","name":"reserve1","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"}],"name":"obtainTotalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"lpTokenAmount","type":"uint256"},{"internalType":"uint256","name":"amountOut0Min","type":"uint256"},{"internalType":"uint256","name":"amountOut1Min","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"withdrawLiquidity","outputs":[{"internalType":"uint256","name":"amountOut0","type":"uint256"},{"internalType":"uint256","name":"amountOut1","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"lpTokenAmount","type":"uint256"},{"internalType":"uint256","name":"amountTokenOutMin","type":"uint256"},{"internalType":"uint256","name":"amountETHOutMin","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"withdrawLiquidityETH","outputs":[{"internalType":"uint256","name":"amountTokenOut","type":"uint256"},{"internalType":"uint256","name":"amountETHOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"withdrawProceedsFromTermSwapETHToToken","outputs":[{"internalType":"uint256","name":"proceedsToken","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"withdrawProceedsFromTermSwapTokenToETH","outputs":[{"internalType":"uint256","name":"proceedsETH","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"orderId","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"withdrawProceedsFromTermSwapTokenToToken","outputs":[{"internalType":"uint256","name":"proceeds","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60c06040523480156200001157600080fd5b5060405162005fc738038062005fc78339810160408190526200003491620000bf565b6001600160a01b03828116608081905290821660a05260405163189acdbd60e31b815230600482015263c4d66de890602401600060405180830381600087803b1580156200008157600080fd5b505af115801562000096573d6000803e3d6000fd5b505050505050620000f7565b80516001600160a01b0381168114620000ba57600080fd5b919050565b60008060408385031215620000d357600080fd5b620000de83620000a2565b9150620000ee60208401620000a2565b90509250929050565b60805160a051615c9d6200032a6000396000818161017a01528181610373015281816105770152818161064401528181610716015281816107a7015281816108250152818161087001528181610a8901528181610c2801528181610d9501528181610e6201528181610fb20152818161113701528181611354015281816114d9015281816116620152818161172f015281816129e301528181612b1501528181612c5c01528181612d29015281816133a501528181613423015281816134a1015281816134fe0152818161357c01528181613ac701528181613b8a01528181613d5f01528181613e4701528181613f5d015281816140fc015281816141ee015281816142ce015281816147880152818161484b01528181614a6d01528181614aeb01528181614b6901528181614bc601528181614c4401528181614ecb01528181614fe00152818161518201526152000152600081816103fa0152818161054001528181610615015281816106f201528181610a6501528181610f9001528181611332015281816118220152818161191901528181611b9001528181611c4a01528181611d3f01528181611e0601528181611ebb01528181611f780152818161219a01528181612595015281816128d0015281816129bf01528181612e570152818161316c0152818161322c015281816133830152818161379d01528181613aa301528181613f39015281816143fc0152818161476401528181614a4b01528181614ea70152614fbe0152615c9d6000f3fe60806040526004361061016a5760003560e01c8063ad5c4648116100d1578063d14821db1161008a578063efa49fdf11610064578063efa49fdf1461049c578063f202ce9d146104bc578063f375f661146104dc578063f6f1e306146104ef57600080fd5b8063d14821db1461043c578063db893e241461045c578063e9728f3e1461047c57600080fd5b8063ad5c464814610361578063af6602b114610395578063bca78e33146103b5578063c3a4c3e9146103d5578063c45a0155146103e8578063cd743e3e1461041c57600080fd5b80633a0c7cab116101235780633a0c7cab146102a157806345786c2f146102c157806349a76c7b146102e15780636b301b18146103015780638caa0171146103215780639782dfe61461034157600080fd5b80630ea9fab2146101ae57806320b4ec51146101d45780632a5e4abc146102095780633151e2ce146102295780633351733f146102495780633567cb511461026957600080fd5b366101a957336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146101a7576101a76155e3565b005b600080fd5b6101c16101bc366004615611565b610502565b6040519081526020015b60405180910390f35b3480156101e057600080fd5b506101f46101ef36600461564c565b610a0f565b604080519283526020830191909152016101cb565b34801561021557600080fd5b506101c161022436600461564c565b610f3b565b34801561023557600080fd5b506101f461024436600461564c565b6112dc565b34801561025557600080fd5b506101f4610264366004615681565b6117cc565b34801561027557600080fd5b506102896102843660046156da565b611b5e565b6040516001600160a01b0390911681526020016101cb565b3480156102ad57600080fd5b506102896102bc366004615713565b611c15565b3480156102cd57600080fd5b506101c16102dc366004615754565b611dd1565b3480156102ed57600080fd5b506101f46102fc3660046157a5565b612144565b34801561030d57600080fd5b506101c161031c366004615754565b612540565b34801561032d57600080fd5b506101f461033c3660046156da565b6128b1565b34801561034d57600080fd5b506101f461035c3660046157eb565b612969565b34801561036d57600080fd5b506102897f000000000000000000000000000000000000000000000000000000000000000081565b3480156103a157600080fd5b506101c16103b03660046157a5565b612e02565b3480156103c157600080fd5b506101c16103d03660046156da565b613158565b6101c16103e3366004615611565b61332e565b3480156103f457600080fd5b506102897f000000000000000000000000000000000000000000000000000000000000000081565b34801561042857600080fd5b506101c1610437366004615754565b613748565b34801561044857600080fd5b506101a761045736600461582f565b6139f0565b34801561046857600080fd5b506101c1610477366004615611565b613a4e565b34801561048857600080fd5b506101c161049736600461564c565b613ee4565b3480156104a857600080fd5b506101f46104b7366004615681565b6143a6565b3480156104c857600080fd5b506101c16104d7366004615611565b61470f565b6101c16104ea366004615611565b6149f6565b6101f46104fd3660046157eb565b614e51565b6000814281101561052e5760405162461bcd60e51b81526004016105259061585b565b60405180910390fd5b60405163e6a4390560e01b81526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e6a439059061059f908a907f000000000000000000000000000000000000000000000000000000000000000090600401615883565b60206040518083038186803b1580156105b757600080fd5b505afa1580156105cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ef91906158ad565b6001600160a01b031614156106c0576040516364e329cb60e11b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063c9c653969061066c9089907f000000000000000000000000000000000000000000000000000000000000000090600401615883565b602060405180830381600087803b15801561068657600080fd5b505af115801561069a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106be91906158ad565b505b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e29061073e907f0000000000000000000000000000000000000000000000000000000000000000908b907f0000000000000000000000000000000000000000000000000000000000000000906004016158ca565b60206040518083038186803b15801561075657600080fd5b505af415801561076a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078e91906158ad565b90506107a56001600160a01b038816338389615302565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0866040518263ffffffff1660e01b81526004016000604051808303818588803b15801561080057600080fd5b505af1158015610814573d6000803e3d6000fd5b506108509350506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016915083905087615373565b60008073818bae51c49175d18acab069cb23b6c7ea62a619635d9172638a7f00000000000000000000000000000000000000000000000000000000000000008b8b6040518563ffffffff1660e01b81526004016108b094939291906158ed565b604080518083038186803b1580156108c757600080fd5b505af41580156108db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108ff9190615916565b6040516337cea16960e11b815291935091506001600160a01b03841690636f9d42d2906109349033908690869060040161593a565b602060405180830381600087803b15801561094e57600080fd5b505af1158015610962573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610986919061595b565b945086341115610a03577344338b6e22bb6b1e97d218754b3d8d6a61f6a689637c4368c1336109b58a3461598a565b6040518363ffffffff1660e01b81526004016109d29291906159a1565b60006040518083038186803b1580156109ea57600080fd5b505af41580156109fe573d6000803e3d6000fd5b505050505b50505050949350505050565b6000808242811015610a335760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290610ab1907f0000000000000000000000000000000000000000000000000000000000000000908b907f0000000000000000000000000000000000000000000000000000000000000000906004016158ca565b60206040518083038186803b158015610ac957600080fd5b505af4158015610add573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0191906158ad565b60405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b158015610b4857600080fd5b505afa158015610b5c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b8091906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018990529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b158015610bcb57600080fd5b505afa158015610bdf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c0391906159f2565b61010001519050886001600160a01b0316826001600160a01b0316148015610c5c57507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b0316145b610c785760405162461bcd60e51b815260040161052590615a7e565b6040516310ae628560e21b81526001600160a01b038416906342b98a1490610ca69033908c906004016159a1565b6040805180830381600087803b158015610cbf57600080fd5b505af1158015610cd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cf79190615916565b6040516370a0823160e01b8152306004820152919750955086906001600160a01b038b16906370a082319060240160206040518083038186803b158015610d3d57600080fd5b505afa158015610d51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d75919061595b565b10158015610e1c57506040516370a0823160e01b815230600482015285907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381600087803b158015610de157600080fd5b505af1158015610df5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e19919061595b565b10155b610e385760405162461bcd60e51b815260040161052590615ab5565b610e4c6001600160a01b038a163388615373565b604051632e1a7d4d60e01b8152600481018690527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015610eae57600080fd5b505af1158015610ec2573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c19150610eff90339089906004016159a1565b60006040518083038186803b158015610f1757600080fd5b505af4158015610f2b573d6000803e3d6000fd5b5050505050505050935093915050565b60008142811015610f5e5760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290610fdc907f0000000000000000000000000000000000000000000000000000000000000000907f0000000000000000000000000000000000000000000000000000000000000000908b906004016158ca565b60206040518083038186803b158015610ff457600080fd5b505af4158015611008573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061102c91906158ad565b60405163ec7dd7bb60e01b8152600481018790529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b15801561107357600080fd5b505afa158015611087573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ab91906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b1580156110f657600080fd5b505afa15801561110a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061112e91906159f2565b610100015190507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161480156111875750876001600160a01b0316816001600160a01b0316145b6111a35760405162461bcd60e51b815260040161052590615a7e565b6040516309dfa7e960e11b81526001600160a01b038416906313bf4fd2906111d19033908b906004016159a1565b602060405180830381600087803b1580156111eb57600080fd5b505af11580156111ff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611223919061595b565b6040516370a0823160e01b815230600482015290955085906001600160a01b038a16906370a082319060240160206040518083038186803b15801561126757600080fd5b505afa15801561127b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061129f919061595b565b10156112bd5760405162461bcd60e51b815260040161052590615aec565b6112d16001600160a01b0389163387615373565b505050509392505050565b60008082428110156113005760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e29061137e907f0000000000000000000000000000000000000000000000000000000000000000907f0000000000000000000000000000000000000000000000000000000000000000908c906004016158ca565b60206040518083038186803b15801561139657600080fd5b505af41580156113aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ce91906158ad565b60405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b15801561141557600080fd5b505afa158015611429573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144d91906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018990529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b15801561149857600080fd5b505afa1580156114ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114d091906159f2565b610100015190507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b03161480156115295750886001600160a01b0316816001600160a01b0316145b6115455760405162461bcd60e51b815260040161052590615a7e565b6040516310ae628560e21b81526001600160a01b038416906342b98a14906115739033908c906004016159a1565b6040805180830381600087803b15801561158c57600080fd5b505af11580156115a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115c49190615916565b6040516370a0823160e01b8152306004820152919750955085906001600160a01b038b16906370a082319060240160206040518083038186803b15801561160a57600080fd5b505afa15801561161e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611642919061595b565b101580156116e957506040516370a0823160e01b815230600482015286907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381600087803b1580156116ae57600080fd5b505af11580156116c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116e6919061595b565b10155b6117055760405162461bcd60e51b815260040161052590615ab5565b6117196001600160a01b038a163387615373565b604051632e1a7d4d60e01b8152600481018790527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561177b57600080fd5b505af115801561178f573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c19150610eff9033908a906004016159a1565b60008082428110156117f05760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e29061184e907f0000000000000000000000000000000000000000000000000000000000000000908e908e906004016158ca565b60206040518083038186803b15801561186657600080fd5b505af415801561187a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189e91906158ad565b604051632e0ae37560e01b81524360048201529091506001600160a01b03821690632e0ae37590602401600060405180830381600087803b1580156118e257600080fd5b505af11580156118f6573d6000803e3d6000fd5b5050505060008073818bae51c49175d18acab069cb23b6c7ea62a61963327494617f00000000000000000000000000000000000000000000000000000000000000008e8e6040518463ffffffff1660e01b8152600401611958939291906158ca565b604080518083038186803b15801561196f57600080fd5b505af4158015611983573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119a79190615916565b915091506000836001600160a01b031663c4e41b226040518163ffffffff1660e01b815260040160206040518083038186803b1580156119e657600080fd5b505afa1580156119fa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1e919061595b565b905080611a2b848d615b23565b611a359190615b42565b965080611a42838d615b23565b611a4c9190615b42565b9550505050868411158015611a615750858311155b611aa65760405162461bcd60e51b8152602060048201526016602482015275115e18d95cdcda5d9948125b9c1d5d08105b5bdd5b9d60521b6044820152606401610525565b611abb6001600160a01b038b16338387615302565b611ad06001600160a01b038a16338386615302565b6040516302ff530960e51b81526001600160a01b03821690635fea612090611afe9033908c906004016159a1565b6040805180830381600087803b158015611b1757600080fd5b505af1158015611b2b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b4f9190615916565b50505050965096945050505050565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290611bbc907f000000000000000000000000000000000000000000000000000000000000000090879087906004016158ca565b60206040518083038186803b158015611bd457600080fd5b505af4158015611be8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c0c91906158ad565b90505b92915050565b60008142811015611c385760405162461bcd60e51b81526004016105259061585b565b60405163e6a4390560e01b81526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e6a4390590611c899089908990600401615883565b60206040518083038186803b158015611ca157600080fd5b505afa158015611cb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cd991906158ad565b6001600160a01b031614611d285760405162461bcd60e51b815260206004820152601660248201527550616972204578697374696e6720416c72656164792160501b6044820152606401610525565b6040516364e329cb60e11b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063c9c6539690611d769088908890600401615883565b602060405180830381600087803b158015611d9057600080fd5b505af1158015611da4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dc891906158ad565b95945050505050565b60008142811015611df45760405162461bcd60e51b81526004016105259061585b565b60405163e6a4390560e01b81526000907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e6a4390590611e45908b908b90600401615883565b60206040518083038186803b158015611e5d57600080fd5b505afa158015611e71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e9591906158ad565b6001600160a01b03161415611f46576040516364e329cb60e11b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063c9c6539690611ef2908a908a90600401615883565b602060405180830381600087803b158015611f0c57600080fd5b505af1158015611f20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4491906158ad565b505b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290611fa4907f0000000000000000000000000000000000000000000000000000000000000000908c908c906004016158ca565b60206040518083038186803b158015611fbc57600080fd5b505af4158015611fd0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ff491906158ad565b905061200b6001600160a01b038916338389615302565b6120206001600160a01b038816338388615302565b60008073818bae51c49175d18acab069cb23b6c7ea62a619635d9172638b8b8b8b6040518563ffffffff1660e01b815260040161206094939291906158ed565b604080518083038186803b15801561207757600080fd5b505af415801561208b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120af9190615916565b6040516337cea16960e11b815291935091506001600160a01b03841690636f9d42d2906120e49033908690869060040161593a565b602060405180830381600087803b1580156120fe57600080fd5b505af1158015612112573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612136919061595b565b9a9950505050505050505050565b60008082428110156121685760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906121c6907f0000000000000000000000000000000000000000000000000000000000000000908c908c906004016158ca565b60206040518083038186803b1580156121de57600080fd5b505af41580156121f2573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221691906158ad565b60405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b15801561225d57600080fd5b505afa158015612271573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061229591906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018990529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b1580156122e057600080fd5b505afa1580156122f4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231891906159f2565b61010001519050896001600160a01b0316826001600160a01b03161480156123515750886001600160a01b0316816001600160a01b0316145b61236d5760405162461bcd60e51b815260040161052590615a7e565b6040516310ae628560e21b81526001600160a01b038416906342b98a149061239b9033908c906004016159a1565b6040805180830381600087803b1580156123b457600080fd5b505af11580156123c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123ec9190615916565b6040516370a0823160e01b8152306004820152919750955086906001600160a01b038c16906370a082319060240160206040518083038186803b15801561243257600080fd5b505afa158015612446573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061246a919061595b565b101580156124ef57506040516370a0823160e01b815230600482015285906001600160a01b038b16906370a082319060240160206040518083038186803b1580156124b457600080fd5b505afa1580156124c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124ec919061595b565b10155b61250b5760405162461bcd60e51b815260040161052590615ab5565b61251f6001600160a01b038b163388615373565b6125336001600160a01b038a163387615373565b5050505094509492505050565b600081428110156125635760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906125c1907f0000000000000000000000000000000000000000000000000000000000000000908c908c906004016158ca565b60206040518083038186803b1580156125d957600080fd5b505af41580156125ed573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061261191906158ad565b90506126286001600160a01b038916338389615302565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690612664908c908c90600401615883565b604080518083038186803b15801561267b57600080fd5b505af415801561268f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126b39190615b64565b509050886001600160a01b0316816001600160a01b031614156127575760405163d5d859c160e01b81526001600160a01b0383169063d5d859c1906126fe9033908b906004016159a1565b602060405180830381600087803b15801561271857600080fd5b505af115801561272c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612750919061595b565b93506127da565b604051639c48a8f960e01b81526001600160a01b03831690639c48a8f9906127859033908b906004016159a1565b602060405180830381600087803b15801561279f57600080fd5b505af11580156127b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127d7919061595b565b93505b858410156127fa5760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284906001600160a01b038a16906370a082319060240160206040518083038186803b15801561283b57600080fd5b505afa15801561284f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612873919061595b565b10156128915760405162461bcd60e51b815260040161052590615aec565b6128a56001600160a01b0389163386615373565b50505095945050505050565b60008073818bae51c49175d18acab069cb23b6c7ea62a61963327494617f000000000000000000000000000000000000000000000000000000000000000086866040518463ffffffff1660e01b815260040161290f939291906158ca565b604080518083038186803b15801561292657600080fd5b505af415801561293a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061295e9190615916565b909590945092505050565b600080824281101561298d5760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290612a0b907f0000000000000000000000000000000000000000000000000000000000000000908d907f0000000000000000000000000000000000000000000000000000000000000000906004016158ca565b60206040518083038186803b158015612a2357600080fd5b505af4158015612a37573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a5b91906158ad565b9050600080826001600160a01b031663a201ccf6338c6040518363ffffffff1660e01b8152600401612a8e9291906159a1565b6040805180830381600087803b158015612aa757600080fd5b505af1158015612abb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612adf9190615916565b604051635d91726360e01b8152919350915073818bae51c49175d18acab069cb23b6c7ea62a61990635d91726390612b41908e907f000000000000000000000000000000000000000000000000000000000000000090879087906004016158ed565b604080518083038186803b158015612b5857600080fd5b505af4158015612b6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b909190615916565b90965094505050868410801590612ba75750858310155b612bc35760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284906001600160a01b038b16906370a082319060240160206040518083038186803b158015612c0457600080fd5b505afa158015612c18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c3c919061595b565b10158015612ce357506040516370a0823160e01b815230600482015283907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381600087803b158015612ca857600080fd5b505af1158015612cbc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ce0919061595b565b10155b612cff5760405162461bcd60e51b815260040161052590615ab5565b612d136001600160a01b038a163386615373565b604051632e1a7d4d60e01b8152600481018490527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015612d7557600080fd5b505af1158015612d89573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c19150612dc690339087906004016159a1565b60006040518083038186803b158015612dde57600080fd5b505af4158015612df2573d6000803e3d6000fd5b5050505050509550959350505050565b60008142811015612e255760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290612e83907f0000000000000000000000000000000000000000000000000000000000000000908b908b906004016158ca565b60206040518083038186803b158015612e9b57600080fd5b505af4158015612eaf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ed391906158ad565b60405163ec7dd7bb60e01b8152600481018790529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b158015612f1a57600080fd5b505afa158015612f2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f5291906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b158015612f9d57600080fd5b505afa158015612fb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fd591906159f2565b61010001519050886001600160a01b0316826001600160a01b031614801561300e5750876001600160a01b0316816001600160a01b0316145b61302a5760405162461bcd60e51b815260040161052590615a7e565b6040516309dfa7e960e11b81526001600160a01b038416906313bf4fd2906130589033908b906004016159a1565b602060405180830381600087803b15801561307257600080fd5b505af1158015613086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130aa919061595b565b6040516370a0823160e01b815230600482015290955085906001600160a01b038a16906370a082319060240160206040518083038186803b1580156130ee57600080fd5b505afa158015613102573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613126919061595b565b10156131445760405162461bcd60e51b815260040161052590615aec565b610a036001600160a01b0389163387615373565b60405163e6a4390560e01b815260009081907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063e6a43905906131ab9087908790600401615883565b60206040518083038186803b1580156131c357600080fd5b505afa1580156131d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131fb91906158ad565b6001600160a01b0316141561321257506000611c0f565b60405163e6a4390560e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e6a43905906132639087908790600401615883565b60206040518083038186803b15801561327b57600080fd5b505afa15801561328f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132b391906158ad565b9050806001600160a01b031663c4e41b226040518163ffffffff1660e01b815260040160206040518083038186803b1580156132ee57600080fd5b505afa158015613302573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613326919061595b565b915050611c0f565b600081428110156133515760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906133cf907f0000000000000000000000000000000000000000000000000000000000000000907f0000000000000000000000000000000000000000000000000000000000000000908c906004016158ca565b60206040518083038186803b1580156133e757600080fd5b505af41580156133fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061341f91906158ad565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b15801561347c57600080fd5b505af1158015613490573d6000803e3d6000fd5b506134cc9350506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016915083905088615373565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690613528907f0000000000000000000000000000000000000000000000000000000000000000908c90600401615883565b604080518083038186803b15801561353f57600080fd5b505af4158015613553573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135779190615b64565b5090507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b0316141561363d57604051635ef083bf60e11b81526001600160a01b0383169063bde1077e906135e49033908b908b9060040161593a565b602060405180830381600087803b1580156135fe57600080fd5b505af1158015613612573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613636919061595b565b93506136c2565b60405163659509c560e01b81526001600160a01b0383169063659509c59061366d9033908b908b9060040161593a565b602060405180830381600087803b15801561368757600080fd5b505af115801561369b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136bf919061595b565b93505b8634111561373d577344338b6e22bb6b1e97d218754b3d8d6a61f6a689637c4368c1336136ef8a3461598a565b6040518363ffffffff1660e01b815260040161370c9291906159a1565b60006040518083038186803b15801561372457600080fd5b505af4158015613738573d6000803e3d6000fd5b505050505b505050949350505050565b6000814281101561376b5760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906137c9907f0000000000000000000000000000000000000000000000000000000000000000908c908c906004016158ca565b60206040518083038186803b1580156137e157600080fd5b505af41580156137f5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061381991906158ad565b90506138306001600160a01b038916338389615302565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa569061386c908c908c90600401615883565b604080518083038186803b15801561388357600080fd5b505af4158015613897573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138bb9190615b64565b509050886001600160a01b0316816001600160a01b0316141561396157604051635ef083bf60e11b81526001600160a01b0383169063bde1077e906139089033908b908b9060040161593a565b602060405180830381600087803b15801561392257600080fd5b505af1158015613936573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061395a919061595b565b93506128a5565b60405163659509c560e01b81526001600160a01b0383169063659509c5906139919033908b908b9060040161593a565b602060405180830381600087803b1580156139ab57600080fd5b505af11580156139bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139e3919061595b565b9998505050505050505050565b604051632e0ae37560e01b8152600481018290526001600160a01b03831690632e0ae37590602401600060405180830381600087803b158015613a3257600080fd5b505af1158015613a46573d6000803e3d6000fd5b505050505050565b60008142811015613a715760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290613aef907f0000000000000000000000000000000000000000000000000000000000000000908b907f0000000000000000000000000000000000000000000000000000000000000000906004016158ca565b60206040518083038186803b158015613b0757600080fd5b505af4158015613b1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b3f91906158ad565b9050613b566001600160a01b038816338389615302565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690613bb2908b907f000000000000000000000000000000000000000000000000000000000000000090600401615883565b604080518083038186803b158015613bc957600080fd5b505af4158015613bdd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c019190615b64565b509050876001600160a01b0316816001600160a01b03161415613ca55760405163d5d859c160e01b81526001600160a01b0383169063d5d859c190613c4c9033908b906004016159a1565b602060405180830381600087803b158015613c6657600080fd5b505af1158015613c7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c9e919061595b565b9350613d28565b604051639c48a8f960e01b81526001600160a01b03831690639c48a8f990613cd39033908b906004016159a1565b602060405180830381600087803b158015613ced57600080fd5b505af1158015613d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d25919061595b565b93505b85841015613d485760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284907f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381600087803b158015613dab57600080fd5b505af1158015613dbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613de3919061595b565b1015613e315760405162461bcd60e51b815260206004820152601b60248201527f496e616363757261746520416d6f756e7420666f7220574554482e00000000006044820152606401610525565b604051632e1a7d4d60e01b8152600481018590527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015613e9357600080fd5b505af1158015613ea7573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c1915061370c90339088906004016159a1565b60008142811015613f075760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290613f85907f0000000000000000000000000000000000000000000000000000000000000000908a907f0000000000000000000000000000000000000000000000000000000000000000906004016158ca565b60206040518083038186803b158015613f9d57600080fd5b505af4158015613fb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613fd591906158ad565b60405163ec7dd7bb60e01b8152600481018790529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b15801561401c57600080fd5b505afa158015614030573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061405491906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b15801561409f57600080fd5b505afa1580156140b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140d791906159f2565b61010001519050876001600160a01b0316826001600160a01b031614801561413057507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b0316145b61414c5760405162461bcd60e51b815260040161052590615a7e565b6040516309dfa7e960e11b81526001600160a01b038416906313bf4fd29061417a9033908b906004016159a1565b602060405180830381600087803b15801561419457600080fd5b505af11580156141a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141cc919061595b565b6040516370a0823160e01b815230600482015290955085906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190602401602060405180830381600087803b15801561423257600080fd5b505af1158015614246573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061426a919061595b565b10156142b85760405162461bcd60e51b815260206004820152601b60248201527f496e616363757261746520416d6f756e7420666f7220574554482e00000000006044820152606401610525565b604051632e1a7d4d60e01b8152600481018690527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561431a57600080fd5b505af115801561432e573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c1915061436b90339089906004016159a1565b60006040518083038186803b15801561438357600080fd5b505af4158015614397573d6000803e3d6000fd5b50505050505050509392505050565b60008082428110156143ca5760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290614428907f0000000000000000000000000000000000000000000000000000000000000000908e908e906004016158ca565b60206040518083038186803b15801561444057600080fd5b505af4158015614454573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061447891906158ad565b9050600080826001600160a01b031663a201ccf6338c6040518363ffffffff1660e01b81526004016144ab9291906159a1565b6040805180830381600087803b1580156144c457600080fd5b505af11580156144d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144fc9190615916565b604051635d91726360e01b8152919350915073818bae51c49175d18acab069cb23b6c7ea62a61990635d9172639061453e908f908f90879087906004016158ed565b604080518083038186803b15801561455557600080fd5b505af4158015614569573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061458d9190615916565b909650945050508684108015906145a45750858310155b6145c05760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284906001600160a01b038c16906370a082319060240160206040518083038186803b15801561460157600080fd5b505afa158015614615573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614639919061595b565b101580156146be57506040516370a0823160e01b815230600482015283906001600160a01b038b16906370a082319060240160206040518083038186803b15801561468357600080fd5b505afa158015614697573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146bb919061595b565b10155b6146da5760405162461bcd60e51b815260040161052590615ab5565b6146ee6001600160a01b038b163386615373565b6147026001600160a01b038a163385615373565b5050965096945050505050565b600081428110156147325760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906147b0907f0000000000000000000000000000000000000000000000000000000000000000908b907f0000000000000000000000000000000000000000000000000000000000000000906004016158ca565b60206040518083038186803b1580156147c857600080fd5b505af41580156147dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061480091906158ad565b90506148176001600160a01b038816338389615302565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690614873908b907f000000000000000000000000000000000000000000000000000000000000000090600401615883565b604080518083038186803b15801561488a57600080fd5b505af415801561489e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148c29190615b64565b509050876001600160a01b0316816001600160a01b0316141561496857604051635ef083bf60e11b81526001600160a01b0383169063bde1077e9061490f9033908b908b9060040161593a565b602060405180830381600087803b15801561492957600080fd5b505af115801561493d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614961919061595b565b935061373d565b60405163659509c560e01b81526001600160a01b0383169063659509c5906149989033908b908b9060040161593a565b602060405180830381600087803b1580156149b257600080fd5b505af11580156149c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149ea919061595b565b98975050505050505050565b60008142811015614a195760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290614a97907f0000000000000000000000000000000000000000000000000000000000000000907f0000000000000000000000000000000000000000000000000000000000000000908c906004016158ca565b60206040518083038186803b158015614aaf57600080fd5b505af4158015614ac3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ae791906158ad565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b158015614b4457600080fd5b505af1158015614b58573d6000803e3d6000fd5b50614b949350506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016915083905088615373565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690614bf0907f0000000000000000000000000000000000000000000000000000000000000000908c90600401615883565b604080518083038186803b158015614c0757600080fd5b505af4158015614c1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614c3f9190615b64565b5090507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b03161415614d035760405163d5d859c160e01b81526001600160a01b0383169063d5d859c190614caa9033908b906004016159a1565b602060405180830381600087803b158015614cc457600080fd5b505af1158015614cd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614cfc919061595b565b9350614d86565b604051639c48a8f960e01b81526001600160a01b03831690639c48a8f990614d319033908b906004016159a1565b602060405180830381600087803b158015614d4b57600080fd5b505af1158015614d5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d83919061595b565b93505b85841015614da65760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284906001600160a01b038a16906370a082319060240160206040518083038186803b158015614de757600080fd5b505afa158015614dfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e1f919061595b565b1015614e3d5760405162461bcd60e51b815260040161052590615aec565b6136c26001600160a01b0389163386615373565b6000808242811015614e755760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290614ef3907f0000000000000000000000000000000000000000000000000000000000000000908d907f0000000000000000000000000000000000000000000000000000000000000000906004016158ca565b60206040518083038186803b158015614f0b57600080fd5b505af4158015614f1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614f4391906158ad565b604051632e0ae37560e01b81524360048201529091506001600160a01b03821690632e0ae37590602401600060405180830381600087803b158015614f8757600080fd5b505af1158015614f9b573d6000803e3d6000fd5b5050505060008073818bae51c49175d18acab069cb23b6c7ea62a61963327494617f00000000000000000000000000000000000000000000000000000000000000008d7f00000000000000000000000000000000000000000000000000000000000000006040518463ffffffff1660e01b815260040161501d939291906158ca565b604080518083038186803b15801561503457600080fd5b505af4158015615048573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061506c9190615916565b915091506000836001600160a01b031663c4e41b226040518163ffffffff1660e01b815260040160206040518083038186803b1580156150ab57600080fd5b505afa1580156150bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906150e3919061595b565b9050806150f0848d615b23565b6150fa9190615b42565b965080615107838d615b23565b6151119190615b42565b95505050508684111580156151265750858311155b61516b5760405162461bcd60e51b8152602060048201526016602482015275115e18d95cdcda5d9948125b9c1d5d08105b5bdd5b9d60521b6044820152606401610525565b6151806001600160a01b038a16338387615302565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0846040518263ffffffff1660e01b81526004016000604051808303818588803b1580156151db57600080fd5b505af11580156151ef573d6000803e3d6000fd5b5061522b9350506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016915083905085615373565b6040516302ff530960e51b81526001600160a01b03821690635fea6120906152599033908c906004016159a1565b6040805180830381600087803b15801561527257600080fd5b505af1158015615286573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906152aa9190615916565b5050823411156152f6577344338b6e22bb6b1e97d218754b3d8d6a61f6a689637c4368c1336152d9863461598a565b6040518363ffffffff1660e01b8152600401612dc69291906159a1565b50509550959350505050565b6040516001600160a01b038085166024830152831660448201526064810182905261536d9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152615397565b50505050565b6153928363a9059cbb60e01b84846040516024016153369291906159a1565b505050565b60006153ec826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166154699092919063ffffffff16565b805190915015615392578080602001905181019061540a9190615bca565b6153925760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610525565b60606154788484600085615482565b90505b9392505050565b6060824710156154e35760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610525565b843b6155315760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610525565b600080866001600160a01b0316858760405161554d9190615c18565b60006040518083038185875af1925050503d806000811461558a576040519150601f19603f3d011682016040523d82523d6000602084013e61558f565b606091505b509150915061559f8282866155aa565b979650505050505050565b606083156155b957508161547b565b8251156155c95782518084602001fd5b8160405162461bcd60e51b81526004016105259190615c34565b634e487b7160e01b600052600160045260246000fd5b6001600160a01b038116811461560e57600080fd5b50565b6000806000806080858703121561562757600080fd5b8435615632816155f9565b966020860135965060408601359560600135945092505050565b60008060006060848603121561566157600080fd5b833561566c816155f9565b95602085013595506040909401359392505050565b60008060008060008060c0878903121561569a57600080fd5b86356156a5816155f9565b955060208701356156b5816155f9565b95989597505050506040840135936060810135936080820135935060a0909101359150565b600080604083850312156156ed57600080fd5b82356156f8816155f9565b91506020830135615708816155f9565b809150509250929050565b60008060006060848603121561572857600080fd5b8335615733816155f9565b92506020840135615743816155f9565b929592945050506040919091013590565b600080600080600060a0868803121561576c57600080fd5b8535615777816155f9565b94506020860135615787816155f9565b94979496505050506040830135926060810135926080909101359150565b600080600080608085870312156157bb57600080fd5b84356157c6816155f9565b935060208501356157d6816155f9565b93969395505050506040820135916060013590565b600080600080600060a0868803121561580357600080fd5b853561580e816155f9565b97602087013597506040870135966060810135965060800135945092505050565b6000806040838503121561584257600080fd5b823561584d816155f9565b946020939093013593505050565b6020808252600e908201526d1515d053534e88115e1c1a5c995960921b604082015260600190565b6001600160a01b0392831681529116602082015260400190565b80516158a8816155f9565b919050565b6000602082840312156158bf57600080fd5b815161547b816155f9565b6001600160a01b0393841681529183166020830152909116604082015260600190565b6001600160a01b0394851681529290931660208301526040820152606081019190915260800190565b6000806040838503121561592957600080fd5b505080516020909101519092909150565b6001600160a01b039390931683526020830191909152604082015260600190565b60006020828403121561596d57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008282101561599c5761599c615974565b500390565b6001600160a01b03929092168252602082015260400190565b604051610120810167ffffffffffffffff811182821017156159ec57634e487b7160e01b600052604160045260246000fd5b60405290565b60006101208284031215615a0557600080fd5b615a0d6159ba565b825181526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a0820152615a4f60c0840161589d565b60c0820152615a6060e0840161589d565b60e0820152610100615a7381850161589d565b908201529392505050565b60208082526017908201527f57726f6e672053656c6c204f722042757920546f6b656e000000000000000000604082015260600190565b6020808252601d908201527f496e616363757261746520416d6f756e7420666f7220546f6b656e732e000000604082015260600190565b6020808252601c908201527f496e616363757261746520416d6f756e7420666f7220546f6b656e2e00000000604082015260600190565b6000816000190483118215151615615b3d57615b3d615974565b500290565b600082615b5f57634e487b7160e01b600052601260045260246000fd5b500490565b60008060408385031215615b7757600080fd5b8251615b82816155f9565b6020840151909250615708816155f9565b6020808252601a908201527f496e73756666696369656e74204f757470757420416d6f756e74000000000000604082015260600190565b600060208284031215615bdc57600080fd5b8151801515811461547b57600080fd5b60005b83811015615c07578181015183820152602001615bef565b8381111561536d5750506000910152565b60008251615c2a818460208701615bec565b9190910192915050565b6020815260008251806020840152615c53816040850160208701615bec565b601f01601f1916919091016040019291505056fea2646970667358221220bd6c1404b6402e783e862e07854c396c2825917c04e2e23aff805e56fdda52ef64736f6c63430008090033000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

Deployed Bytecode

0x60806040526004361061016a5760003560e01c8063ad5c4648116100d1578063d14821db1161008a578063efa49fdf11610064578063efa49fdf1461049c578063f202ce9d146104bc578063f375f661146104dc578063f6f1e306146104ef57600080fd5b8063d14821db1461043c578063db893e241461045c578063e9728f3e1461047c57600080fd5b8063ad5c464814610361578063af6602b114610395578063bca78e33146103b5578063c3a4c3e9146103d5578063c45a0155146103e8578063cd743e3e1461041c57600080fd5b80633a0c7cab116101235780633a0c7cab146102a157806345786c2f146102c157806349a76c7b146102e15780636b301b18146103015780638caa0171146103215780639782dfe61461034157600080fd5b80630ea9fab2146101ae57806320b4ec51146101d45780632a5e4abc146102095780633151e2ce146102295780633351733f146102495780633567cb511461026957600080fd5b366101a957336001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216146101a7576101a76155e3565b005b600080fd5b6101c16101bc366004615611565b610502565b6040519081526020015b60405180910390f35b3480156101e057600080fd5b506101f46101ef36600461564c565b610a0f565b604080519283526020830191909152016101cb565b34801561021557600080fd5b506101c161022436600461564c565b610f3b565b34801561023557600080fd5b506101f461024436600461564c565b6112dc565b34801561025557600080fd5b506101f4610264366004615681565b6117cc565b34801561027557600080fd5b506102896102843660046156da565b611b5e565b6040516001600160a01b0390911681526020016101cb565b3480156102ad57600080fd5b506102896102bc366004615713565b611c15565b3480156102cd57600080fd5b506101c16102dc366004615754565b611dd1565b3480156102ed57600080fd5b506101f46102fc3660046157a5565b612144565b34801561030d57600080fd5b506101c161031c366004615754565b612540565b34801561032d57600080fd5b506101f461033c3660046156da565b6128b1565b34801561034d57600080fd5b506101f461035c3660046157eb565b612969565b34801561036d57600080fd5b506102897f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b3480156103a157600080fd5b506101c16103b03660046157a5565b612e02565b3480156103c157600080fd5b506101c16103d03660046156da565b613158565b6101c16103e3366004615611565b61332e565b3480156103f457600080fd5b506102897f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f81565b34801561042857600080fd5b506101c1610437366004615754565b613748565b34801561044857600080fd5b506101a761045736600461582f565b6139f0565b34801561046857600080fd5b506101c1610477366004615611565b613a4e565b34801561048857600080fd5b506101c161049736600461564c565b613ee4565b3480156104a857600080fd5b506101f46104b7366004615681565b6143a6565b3480156104c857600080fd5b506101c16104d7366004615611565b61470f565b6101c16104ea366004615611565b6149f6565b6101f46104fd3660046157eb565b614e51565b6000814281101561052e5760405162461bcd60e51b81526004016105259061585b565b60405180910390fd5b60405163e6a4390560e01b81526000907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f6001600160a01b03169063e6a439059061059f908a907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290600401615883565b60206040518083038186803b1580156105b757600080fd5b505afa1580156105cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ef91906158ad565b6001600160a01b031614156106c0576040516364e329cb60e11b81526001600160a01b037f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f169063c9c653969061066c9089907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290600401615883565b602060405180830381600087803b15801561068657600080fd5b505af115801561069a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106be91906158ad565b505b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e29061073e907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908b907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906004016158ca565b60206040518083038186803b15801561075657600080fd5b505af415801561076a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078e91906158ad565b90506107a56001600160a01b038816338389615302565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0866040518263ffffffff1660e01b81526004016000604051808303818588803b15801561080057600080fd5b505af1158015610814573d6000803e3d6000fd5b506108509350506001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216915083905087615373565b60008073818bae51c49175d18acab069cb23b6c7ea62a619635d9172638a7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28b8b6040518563ffffffff1660e01b81526004016108b094939291906158ed565b604080518083038186803b1580156108c757600080fd5b505af41580156108db573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108ff9190615916565b6040516337cea16960e11b815291935091506001600160a01b03841690636f9d42d2906109349033908690869060040161593a565b602060405180830381600087803b15801561094e57600080fd5b505af1158015610962573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610986919061595b565b945086341115610a03577344338b6e22bb6b1e97d218754b3d8d6a61f6a689637c4368c1336109b58a3461598a565b6040518363ffffffff1660e01b81526004016109d29291906159a1565b60006040518083038186803b1580156109ea57600080fd5b505af41580156109fe573d6000803e3d6000fd5b505050505b50505050949350505050565b6000808242811015610a335760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290610ab1907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908b907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906004016158ca565b60206040518083038186803b158015610ac957600080fd5b505af4158015610add573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b0191906158ad565b60405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b158015610b4857600080fd5b505afa158015610b5c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b8091906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018990529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b158015610bcb57600080fd5b505afa158015610bdf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c0391906159f2565b61010001519050886001600160a01b0316826001600160a01b0316148015610c5c57507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316816001600160a01b0316145b610c785760405162461bcd60e51b815260040161052590615a7e565b6040516310ae628560e21b81526001600160a01b038416906342b98a1490610ca69033908c906004016159a1565b6040805180830381600087803b158015610cbf57600080fd5b505af1158015610cd3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cf79190615916565b6040516370a0823160e01b8152306004820152919750955086906001600160a01b038b16906370a082319060240160206040518083038186803b158015610d3d57600080fd5b505afa158015610d51573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d75919061595b565b10158015610e1c57506040516370a0823160e01b815230600482015285907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316906370a0823190602401602060405180830381600087803b158015610de157600080fd5b505af1158015610df5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e19919061595b565b10155b610e385760405162461bcd60e51b815260040161052590615ab5565b610e4c6001600160a01b038a163388615373565b604051632e1a7d4d60e01b8152600481018690527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015610eae57600080fd5b505af1158015610ec2573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c19150610eff90339089906004016159a1565b60006040518083038186803b158015610f1757600080fd5b505af4158015610f2b573d6000803e3d6000fd5b5050505050505050935093915050565b60008142811015610f5e5760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290610fdc907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2908b906004016158ca565b60206040518083038186803b158015610ff457600080fd5b505af4158015611008573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061102c91906158ad565b60405163ec7dd7bb60e01b8152600481018790529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b15801561107357600080fd5b505afa158015611087573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110ab91906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b1580156110f657600080fd5b505afa15801561110a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061112e91906159f2565b610100015190507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b03161480156111875750876001600160a01b0316816001600160a01b0316145b6111a35760405162461bcd60e51b815260040161052590615a7e565b6040516309dfa7e960e11b81526001600160a01b038416906313bf4fd2906111d19033908b906004016159a1565b602060405180830381600087803b1580156111eb57600080fd5b505af11580156111ff573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611223919061595b565b6040516370a0823160e01b815230600482015290955085906001600160a01b038a16906370a082319060240160206040518083038186803b15801561126757600080fd5b505afa15801561127b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061129f919061595b565b10156112bd5760405162461bcd60e51b815260040161052590615aec565b6112d16001600160a01b0389163387615373565b505050509392505050565b60008082428110156113005760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e29061137e907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2908c906004016158ca565b60206040518083038186803b15801561139657600080fd5b505af41580156113aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ce91906158ad565b60405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b15801561141557600080fd5b505afa158015611429573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061144d91906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018990529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b15801561149857600080fd5b505afa1580156114ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114d091906159f2565b610100015190507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316826001600160a01b03161480156115295750886001600160a01b0316816001600160a01b0316145b6115455760405162461bcd60e51b815260040161052590615a7e565b6040516310ae628560e21b81526001600160a01b038416906342b98a14906115739033908c906004016159a1565b6040805180830381600087803b15801561158c57600080fd5b505af11580156115a0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115c49190615916565b6040516370a0823160e01b8152306004820152919750955085906001600160a01b038b16906370a082319060240160206040518083038186803b15801561160a57600080fd5b505afa15801561161e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611642919061595b565b101580156116e957506040516370a0823160e01b815230600482015286907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316906370a0823190602401602060405180830381600087803b1580156116ae57600080fd5b505af11580156116c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116e6919061595b565b10155b6117055760405162461bcd60e51b815260040161052590615ab5565b6117196001600160a01b038a163387615373565b604051632e1a7d4d60e01b8152600481018790527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561177b57600080fd5b505af115801561178f573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c19150610eff9033908a906004016159a1565b60008082428110156117f05760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e29061184e907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908e908e906004016158ca565b60206040518083038186803b15801561186657600080fd5b505af415801561187a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061189e91906158ad565b604051632e0ae37560e01b81524360048201529091506001600160a01b03821690632e0ae37590602401600060405180830381600087803b1580156118e257600080fd5b505af11580156118f6573d6000803e3d6000fd5b5050505060008073818bae51c49175d18acab069cb23b6c7ea62a61963327494617f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f8e8e6040518463ffffffff1660e01b8152600401611958939291906158ca565b604080518083038186803b15801561196f57600080fd5b505af4158015611983573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119a79190615916565b915091506000836001600160a01b031663c4e41b226040518163ffffffff1660e01b815260040160206040518083038186803b1580156119e657600080fd5b505afa1580156119fa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1e919061595b565b905080611a2b848d615b23565b611a359190615b42565b965080611a42838d615b23565b611a4c9190615b42565b9550505050868411158015611a615750858311155b611aa65760405162461bcd60e51b8152602060048201526016602482015275115e18d95cdcda5d9948125b9c1d5d08105b5bdd5b9d60521b6044820152606401610525565b611abb6001600160a01b038b16338387615302565b611ad06001600160a01b038a16338386615302565b6040516302ff530960e51b81526001600160a01b03821690635fea612090611afe9033908c906004016159a1565b6040805180830381600087803b158015611b1757600080fd5b505af1158015611b2b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b4f9190615916565b50505050965096945050505050565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290611bbc907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f90879087906004016158ca565b60206040518083038186803b158015611bd457600080fd5b505af4158015611be8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c0c91906158ad565b90505b92915050565b60008142811015611c385760405162461bcd60e51b81526004016105259061585b565b60405163e6a4390560e01b81526000907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f6001600160a01b03169063e6a4390590611c899089908990600401615883565b60206040518083038186803b158015611ca157600080fd5b505afa158015611cb5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cd991906158ad565b6001600160a01b031614611d285760405162461bcd60e51b815260206004820152601660248201527550616972204578697374696e6720416c72656164792160501b6044820152606401610525565b6040516364e329cb60e11b81526001600160a01b037f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f169063c9c6539690611d769088908890600401615883565b602060405180830381600087803b158015611d9057600080fd5b505af1158015611da4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611dc891906158ad565b95945050505050565b60008142811015611df45760405162461bcd60e51b81526004016105259061585b565b60405163e6a4390560e01b81526000907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f6001600160a01b03169063e6a4390590611e45908b908b90600401615883565b60206040518083038186803b158015611e5d57600080fd5b505afa158015611e71573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e9591906158ad565b6001600160a01b03161415611f46576040516364e329cb60e11b81526001600160a01b037f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f169063c9c6539690611ef2908a908a90600401615883565b602060405180830381600087803b158015611f0c57600080fd5b505af1158015611f20573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f4491906158ad565b505b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290611fa4907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908c908c906004016158ca565b60206040518083038186803b158015611fbc57600080fd5b505af4158015611fd0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ff491906158ad565b905061200b6001600160a01b038916338389615302565b6120206001600160a01b038816338388615302565b60008073818bae51c49175d18acab069cb23b6c7ea62a619635d9172638b8b8b8b6040518563ffffffff1660e01b815260040161206094939291906158ed565b604080518083038186803b15801561207757600080fd5b505af415801561208b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120af9190615916565b6040516337cea16960e11b815291935091506001600160a01b03841690636f9d42d2906120e49033908690869060040161593a565b602060405180830381600087803b1580156120fe57600080fd5b505af1158015612112573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612136919061595b565b9a9950505050505050505050565b60008082428110156121685760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906121c6907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908c908c906004016158ca565b60206040518083038186803b1580156121de57600080fd5b505af41580156121f2573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061221691906158ad565b60405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b15801561225d57600080fd5b505afa158015612271573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061229591906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018990529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b1580156122e057600080fd5b505afa1580156122f4573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231891906159f2565b61010001519050896001600160a01b0316826001600160a01b03161480156123515750886001600160a01b0316816001600160a01b0316145b61236d5760405162461bcd60e51b815260040161052590615a7e565b6040516310ae628560e21b81526001600160a01b038416906342b98a149061239b9033908c906004016159a1565b6040805180830381600087803b1580156123b457600080fd5b505af11580156123c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123ec9190615916565b6040516370a0823160e01b8152306004820152919750955086906001600160a01b038c16906370a082319060240160206040518083038186803b15801561243257600080fd5b505afa158015612446573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061246a919061595b565b101580156124ef57506040516370a0823160e01b815230600482015285906001600160a01b038b16906370a082319060240160206040518083038186803b1580156124b457600080fd5b505afa1580156124c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124ec919061595b565b10155b61250b5760405162461bcd60e51b815260040161052590615ab5565b61251f6001600160a01b038b163388615373565b6125336001600160a01b038a163387615373565b5050505094509492505050565b600081428110156125635760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906125c1907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908c908c906004016158ca565b60206040518083038186803b1580156125d957600080fd5b505af41580156125ed573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061261191906158ad565b90506126286001600160a01b038916338389615302565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690612664908c908c90600401615883565b604080518083038186803b15801561267b57600080fd5b505af415801561268f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126b39190615b64565b509050886001600160a01b0316816001600160a01b031614156127575760405163d5d859c160e01b81526001600160a01b0383169063d5d859c1906126fe9033908b906004016159a1565b602060405180830381600087803b15801561271857600080fd5b505af115801561272c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612750919061595b565b93506127da565b604051639c48a8f960e01b81526001600160a01b03831690639c48a8f9906127859033908b906004016159a1565b602060405180830381600087803b15801561279f57600080fd5b505af11580156127b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127d7919061595b565b93505b858410156127fa5760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284906001600160a01b038a16906370a082319060240160206040518083038186803b15801561283b57600080fd5b505afa15801561284f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612873919061595b565b10156128915760405162461bcd60e51b815260040161052590615aec565b6128a56001600160a01b0389163386615373565b50505095945050505050565b60008073818bae51c49175d18acab069cb23b6c7ea62a61963327494617f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f86866040518463ffffffff1660e01b815260040161290f939291906158ca565b604080518083038186803b15801561292657600080fd5b505af415801561293a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061295e9190615916565b909590945092505050565b600080824281101561298d5760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290612a0b907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908d907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906004016158ca565b60206040518083038186803b158015612a2357600080fd5b505af4158015612a37573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a5b91906158ad565b9050600080826001600160a01b031663a201ccf6338c6040518363ffffffff1660e01b8152600401612a8e9291906159a1565b6040805180830381600087803b158015612aa757600080fd5b505af1158015612abb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612adf9190615916565b604051635d91726360e01b8152919350915073818bae51c49175d18acab069cb23b6c7ea62a61990635d91726390612b41908e907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290879087906004016158ed565b604080518083038186803b158015612b5857600080fd5b505af4158015612b6c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b909190615916565b90965094505050868410801590612ba75750858310155b612bc35760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284906001600160a01b038b16906370a082319060240160206040518083038186803b158015612c0457600080fd5b505afa158015612c18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c3c919061595b565b10158015612ce357506040516370a0823160e01b815230600482015283907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316906370a0823190602401602060405180830381600087803b158015612ca857600080fd5b505af1158015612cbc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ce0919061595b565b10155b612cff5760405162461bcd60e51b815260040161052590615ab5565b612d136001600160a01b038a163386615373565b604051632e1a7d4d60e01b8152600481018490527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015612d7557600080fd5b505af1158015612d89573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c19150612dc690339087906004016159a1565b60006040518083038186803b158015612dde57600080fd5b505af4158015612df2573d6000803e3d6000fd5b5050505050509550959350505050565b60008142811015612e255760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290612e83907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908b908b906004016158ca565b60206040518083038186803b158015612e9b57600080fd5b505af4158015612eaf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ed391906158ad565b60405163ec7dd7bb60e01b8152600481018790529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b158015612f1a57600080fd5b505afa158015612f2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f5291906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b158015612f9d57600080fd5b505afa158015612fb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fd591906159f2565b61010001519050886001600160a01b0316826001600160a01b031614801561300e5750876001600160a01b0316816001600160a01b0316145b61302a5760405162461bcd60e51b815260040161052590615a7e565b6040516309dfa7e960e11b81526001600160a01b038416906313bf4fd2906130589033908b906004016159a1565b602060405180830381600087803b15801561307257600080fd5b505af1158015613086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130aa919061595b565b6040516370a0823160e01b815230600482015290955085906001600160a01b038a16906370a082319060240160206040518083038186803b1580156130ee57600080fd5b505afa158015613102573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613126919061595b565b10156131445760405162461bcd60e51b815260040161052590615aec565b610a036001600160a01b0389163387615373565b60405163e6a4390560e01b815260009081907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f6001600160a01b03169063e6a43905906131ab9087908790600401615883565b60206040518083038186803b1580156131c357600080fd5b505afa1580156131d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131fb91906158ad565b6001600160a01b0316141561321257506000611c0f565b60405163e6a4390560e01b81526000906001600160a01b037f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f169063e6a43905906132639087908790600401615883565b60206040518083038186803b15801561327b57600080fd5b505afa15801561328f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132b391906158ad565b9050806001600160a01b031663c4e41b226040518163ffffffff1660e01b815260040160206040518083038186803b1580156132ee57600080fd5b505afa158015613302573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613326919061595b565b915050611c0f565b600081428110156133515760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906133cf907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2908c906004016158ca565b60206040518083038186803b1580156133e757600080fd5b505af41580156133fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061341f91906158ad565b90507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b15801561347c57600080fd5b505af1158015613490573d6000803e3d6000fd5b506134cc9350506001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216915083905088615373565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690613528907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2908c90600401615883565b604080518083038186803b15801561353f57600080fd5b505af4158015613553573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135779190615b64565b5090507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316816001600160a01b0316141561363d57604051635ef083bf60e11b81526001600160a01b0383169063bde1077e906135e49033908b908b9060040161593a565b602060405180830381600087803b1580156135fe57600080fd5b505af1158015613612573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613636919061595b565b93506136c2565b60405163659509c560e01b81526001600160a01b0383169063659509c59061366d9033908b908b9060040161593a565b602060405180830381600087803b15801561368757600080fd5b505af115801561369b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906136bf919061595b565b93505b8634111561373d577344338b6e22bb6b1e97d218754b3d8d6a61f6a689637c4368c1336136ef8a3461598a565b6040518363ffffffff1660e01b815260040161370c9291906159a1565b60006040518083038186803b15801561372457600080fd5b505af4158015613738573d6000803e3d6000fd5b505050505b505050949350505050565b6000814281101561376b5760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906137c9907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908c908c906004016158ca565b60206040518083038186803b1580156137e157600080fd5b505af41580156137f5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061381991906158ad565b90506138306001600160a01b038916338389615302565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa569061386c908c908c90600401615883565b604080518083038186803b15801561388357600080fd5b505af4158015613897573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138bb9190615b64565b509050886001600160a01b0316816001600160a01b0316141561396157604051635ef083bf60e11b81526001600160a01b0383169063bde1077e906139089033908b908b9060040161593a565b602060405180830381600087803b15801561392257600080fd5b505af1158015613936573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061395a919061595b565b93506128a5565b60405163659509c560e01b81526001600160a01b0383169063659509c5906139919033908b908b9060040161593a565b602060405180830381600087803b1580156139ab57600080fd5b505af11580156139bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139e3919061595b565b9998505050505050505050565b604051632e0ae37560e01b8152600481018290526001600160a01b03831690632e0ae37590602401600060405180830381600087803b158015613a3257600080fd5b505af1158015613a46573d6000803e3d6000fd5b505050505050565b60008142811015613a715760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290613aef907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908b907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906004016158ca565b60206040518083038186803b158015613b0757600080fd5b505af4158015613b1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b3f91906158ad565b9050613b566001600160a01b038816338389615302565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690613bb2908b907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290600401615883565b604080518083038186803b158015613bc957600080fd5b505af4158015613bdd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c019190615b64565b509050876001600160a01b0316816001600160a01b03161415613ca55760405163d5d859c160e01b81526001600160a01b0383169063d5d859c190613c4c9033908b906004016159a1565b602060405180830381600087803b158015613c6657600080fd5b505af1158015613c7a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c9e919061595b565b9350613d28565b604051639c48a8f960e01b81526001600160a01b03831690639c48a8f990613cd39033908b906004016159a1565b602060405180830381600087803b158015613ced57600080fd5b505af1158015613d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d25919061595b565b93505b85841015613d485760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316906370a0823190602401602060405180830381600087803b158015613dab57600080fd5b505af1158015613dbf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613de3919061595b565b1015613e315760405162461bcd60e51b815260206004820152601b60248201527f496e616363757261746520416d6f756e7420666f7220574554482e00000000006044820152606401610525565b604051632e1a7d4d60e01b8152600481018590527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015613e9357600080fd5b505af1158015613ea7573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c1915061370c90339088906004016159a1565b60008142811015613f075760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290613f85907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908a907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906004016158ca565b60206040518083038186803b158015613f9d57600080fd5b505af4158015613fb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613fd591906158ad565b60405163ec7dd7bb60e01b8152600481018790529091506000906001600160a01b0383169063ec7dd7bb906024016101206040518083038186803b15801561401c57600080fd5b505afa158015614030573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061405491906159f2565b60e0015160405163ec7dd7bb60e01b8152600481018890529091506000906001600160a01b0384169063ec7dd7bb906024016101206040518083038186803b15801561409f57600080fd5b505afa1580156140b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906140d791906159f2565b61010001519050876001600160a01b0316826001600160a01b031614801561413057507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316816001600160a01b0316145b61414c5760405162461bcd60e51b815260040161052590615a7e565b6040516309dfa7e960e11b81526001600160a01b038416906313bf4fd29061417a9033908b906004016159a1565b602060405180830381600087803b15801561419457600080fd5b505af11580156141a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141cc919061595b565b6040516370a0823160e01b815230600482015290955085906001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216906370a0823190602401602060405180830381600087803b15801561423257600080fd5b505af1158015614246573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061426a919061595b565b10156142b85760405162461bcd60e51b815260206004820152601b60248201527f496e616363757261746520416d6f756e7420666f7220574554482e00000000006044820152606401610525565b604051632e1a7d4d60e01b8152600481018690527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561431a57600080fd5b505af115801561432e573d6000803e3d6000fd5b5050604051637c4368c160e01b81527344338b6e22bb6b1e97d218754b3d8d6a61f6a6899250637c4368c1915061436b90339089906004016159a1565b60006040518083038186803b15801561438357600080fd5b505af4158015614397573d6000803e3d6000fd5b50505050505050509392505050565b60008082428110156143ca5760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290614428907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908e908e906004016158ca565b60206040518083038186803b15801561444057600080fd5b505af4158015614454573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061447891906158ad565b9050600080826001600160a01b031663a201ccf6338c6040518363ffffffff1660e01b81526004016144ab9291906159a1565b6040805180830381600087803b1580156144c457600080fd5b505af11580156144d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144fc9190615916565b604051635d91726360e01b8152919350915073818bae51c49175d18acab069cb23b6c7ea62a61990635d9172639061453e908f908f90879087906004016158ed565b604080518083038186803b15801561455557600080fd5b505af4158015614569573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061458d9190615916565b909650945050508684108015906145a45750858310155b6145c05760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284906001600160a01b038c16906370a082319060240160206040518083038186803b15801561460157600080fd5b505afa158015614615573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614639919061595b565b101580156146be57506040516370a0823160e01b815230600482015283906001600160a01b038b16906370a082319060240160206040518083038186803b15801561468357600080fd5b505afa158015614697573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146bb919061595b565b10155b6146da5760405162461bcd60e51b815260040161052590615ab5565b6146ee6001600160a01b038b163386615373565b6147026001600160a01b038a163385615373565b5050965096945050505050565b600081428110156147325760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e2906147b0907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908b907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906004016158ca565b60206040518083038186803b1580156147c857600080fd5b505af41580156147dc573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061480091906158ad565b90506148176001600160a01b038816338389615302565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690614873908b907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290600401615883565b604080518083038186803b15801561488a57600080fd5b505af415801561489e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148c29190615b64565b509050876001600160a01b0316816001600160a01b0316141561496857604051635ef083bf60e11b81526001600160a01b0383169063bde1077e9061490f9033908b908b9060040161593a565b602060405180830381600087803b15801561492957600080fd5b505af115801561493d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614961919061595b565b935061373d565b60405163659509c560e01b81526001600160a01b0383169063659509c5906149989033908b908b9060040161593a565b602060405180830381600087803b1580156149b257600080fd5b505af11580156149c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906149ea919061595b565b98975050505050505050565b60008142811015614a195760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290614a97907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2908c906004016158ca565b60206040518083038186803b158015614aaf57600080fd5b505af4158015614ac3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614ae791906158ad565b90507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0876040518263ffffffff1660e01b81526004016000604051808303818588803b158015614b4457600080fd5b505af1158015614b58573d6000803e3d6000fd5b50614b949350506001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216915083905088615373565b604051632a26552b60e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a6199063544caa5690614bf0907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2908c90600401615883565b604080518083038186803b158015614c0757600080fd5b505af4158015614c1b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614c3f9190615b64565b5090507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316816001600160a01b03161415614d035760405163d5d859c160e01b81526001600160a01b0383169063d5d859c190614caa9033908b906004016159a1565b602060405180830381600087803b158015614cc457600080fd5b505af1158015614cd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614cfc919061595b565b9350614d86565b604051639c48a8f960e01b81526001600160a01b03831690639c48a8f990614d319033908b906004016159a1565b602060405180830381600087803b158015614d4b57600080fd5b505af1158015614d5f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614d83919061595b565b93505b85841015614da65760405162461bcd60e51b815260040161052590615b93565b6040516370a0823160e01b815230600482015284906001600160a01b038a16906370a082319060240160206040518083038186803b158015614de757600080fd5b505afa158015614dfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614e1f919061595b565b1015614e3d5760405162461bcd60e51b815260040161052590615aec565b6136c26001600160a01b0389163386615373565b6000808242811015614e755760405162461bcd60e51b81526004016105259061585b565b6040516336c8e07160e11b815260009073818bae51c49175d18acab069cb23b6c7ea62a61990636d91c0e290614ef3907f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f908d907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2906004016158ca565b60206040518083038186803b158015614f0b57600080fd5b505af4158015614f1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190614f4391906158ad565b604051632e0ae37560e01b81524360048201529091506001600160a01b03821690632e0ae37590602401600060405180830381600087803b158015614f8757600080fd5b505af1158015614f9b573d6000803e3d6000fd5b5050505060008073818bae51c49175d18acab069cb23b6c7ea62a61963327494617f000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f8d7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26040518463ffffffff1660e01b815260040161501d939291906158ca565b604080518083038186803b15801561503457600080fd5b505af4158015615048573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061506c9190615916565b915091506000836001600160a01b031663c4e41b226040518163ffffffff1660e01b815260040160206040518083038186803b1580156150ab57600080fd5b505afa1580156150bf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906150e3919061595b565b9050806150f0848d615b23565b6150fa9190615b42565b965080615107838d615b23565b6151119190615b42565b95505050508684111580156151265750858311155b61516b5760405162461bcd60e51b8152602060048201526016602482015275115e18d95cdcda5d9948125b9c1d5d08105b5bdd5b9d60521b6044820152606401610525565b6151806001600160a01b038a16338387615302565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0846040518263ffffffff1660e01b81526004016000604051808303818588803b1580156151db57600080fd5b505af11580156151ef573d6000803e3d6000fd5b5061522b9350506001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc216915083905085615373565b6040516302ff530960e51b81526001600160a01b03821690635fea6120906152599033908c906004016159a1565b6040805180830381600087803b15801561527257600080fd5b505af1158015615286573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906152aa9190615916565b5050823411156152f6577344338b6e22bb6b1e97d218754b3d8d6a61f6a689637c4368c1336152d9863461598a565b6040518363ffffffff1660e01b8152600401612dc69291906159a1565b50509550959350505050565b6040516001600160a01b038085166024830152831660448201526064810182905261536d9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152615397565b50505050565b6153928363a9059cbb60e01b84846040516024016153369291906159a1565b505050565b60006153ec826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166154699092919063ffffffff16565b805190915015615392578080602001905181019061540a9190615bca565b6153925760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610525565b60606154788484600085615482565b90505b9392505050565b6060824710156154e35760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610525565b843b6155315760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610525565b600080866001600160a01b0316858760405161554d9190615c18565b60006040518083038185875af1925050503d806000811461558a576040519150601f19603f3d011682016040523d82523d6000602084013e61558f565b606091505b509150915061559f8282866155aa565b979650505050505050565b606083156155b957508161547b565b8251156155c95782518084602001fd5b8160405162461bcd60e51b81526004016105259190615c34565b634e487b7160e01b600052600160045260246000fd5b6001600160a01b038116811461560e57600080fd5b50565b6000806000806080858703121561562757600080fd5b8435615632816155f9565b966020860135965060408601359560600135945092505050565b60008060006060848603121561566157600080fd5b833561566c816155f9565b95602085013595506040909401359392505050565b60008060008060008060c0878903121561569a57600080fd5b86356156a5816155f9565b955060208701356156b5816155f9565b95989597505050506040840135936060810135936080820135935060a0909101359150565b600080604083850312156156ed57600080fd5b82356156f8816155f9565b91506020830135615708816155f9565b809150509250929050565b60008060006060848603121561572857600080fd5b8335615733816155f9565b92506020840135615743816155f9565b929592945050506040919091013590565b600080600080600060a0868803121561576c57600080fd5b8535615777816155f9565b94506020860135615787816155f9565b94979496505050506040830135926060810135926080909101359150565b600080600080608085870312156157bb57600080fd5b84356157c6816155f9565b935060208501356157d6816155f9565b93969395505050506040820135916060013590565b600080600080600060a0868803121561580357600080fd5b853561580e816155f9565b97602087013597506040870135966060810135965060800135945092505050565b6000806040838503121561584257600080fd5b823561584d816155f9565b946020939093013593505050565b6020808252600e908201526d1515d053534e88115e1c1a5c995960921b604082015260600190565b6001600160a01b0392831681529116602082015260400190565b80516158a8816155f9565b919050565b6000602082840312156158bf57600080fd5b815161547b816155f9565b6001600160a01b0393841681529183166020830152909116604082015260600190565b6001600160a01b0394851681529290931660208301526040820152606081019190915260800190565b6000806040838503121561592957600080fd5b505080516020909101519092909150565b6001600160a01b039390931683526020830191909152604082015260600190565b60006020828403121561596d57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008282101561599c5761599c615974565b500390565b6001600160a01b03929092168252602082015260400190565b604051610120810167ffffffffffffffff811182821017156159ec57634e487b7160e01b600052604160045260246000fd5b60405290565b60006101208284031215615a0557600080fd5b615a0d6159ba565b825181526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a0820152615a4f60c0840161589d565b60c0820152615a6060e0840161589d565b60e0820152610100615a7381850161589d565b908201529392505050565b60208082526017908201527f57726f6e672053656c6c204f722042757920546f6b656e000000000000000000604082015260600190565b6020808252601d908201527f496e616363757261746520416d6f756e7420666f7220546f6b656e732e000000604082015260600190565b6020808252601c908201527f496e616363757261746520416d6f756e7420666f7220546f6b656e2e00000000604082015260600190565b6000816000190483118215151615615b3d57615b3d615974565b500290565b600082615b5f57634e487b7160e01b600052601260045260246000fd5b500490565b60008060408385031215615b7757600080fd5b8251615b82816155f9565b6020840151909250615708816155f9565b6020808252601a908201527f496e73756666696369656e74204f757470757420416d6f756e74000000000000604082015260600190565b600060208284031215615bdc57600080fd5b8151801515811461547b57600080fd5b60005b83811015615c07578181015183820152602001615bef565b8381111561536d5750506000910152565b60008251615c2a818460208701615bec565b9190910192915050565b6020815260008251806020840152615c53816040850160208701615bec565b601f01601f1916919091016040019291505056fea2646970667358221220bd6c1404b6402e783e862e07854c396c2825917c04e2e23aff805e56fdda52ef64736f6c63430008090033

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

000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

-----Decoded View---------------
Arg [0] : _factory (address): 0x408f66057163d829a30D4d466092c6B0eebb692f
Arg [1] : _WETH (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 000000000000000000000000408f66057163d829a30d4d466092c6b0eebb692f
Arg [1] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

OVERVIEW

TWAMM contract fully supports all the basic requirements of a user-friendly offering instant swap, term swap, and liquidity management functionality.

Validator Index Block Amount
View All Withdrawals

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

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