ETH Price: $3,689.07 (+3.36%)

Token

ERC-20: ()
 

Overview

Max Total Supply

0

Holders

32

Market

Volume (24H)

N/A

Min Price (24H)

N/A

Max Price (24H)

N/A
0x5c8c76f2e990f194462dc5f8a8c76ba16966ed42
Loading...
Loading
Loading...
Loading
Loading...
Loading

Click here to update the token information / general information
# Exchange Pair Price  24H Volume % Volume

Contract Source Code Verified (Exact Match)

Contract Name:
TimeswapV2LiquidityToken

Compiler Version
v0.8.8+commit.dddeac2f

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 39 : TimeswapV2LiquidityToken.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {ITimeswapV2Option} from "@timeswap-labs/v2-option/contracts/interfaces/ITimeswapV2Option.sol";
import {OptionFactoryLibrary} from "@timeswap-labs/v2-option/contracts/libraries/OptionFactory.sol";
import {TimeswapV2OptionPosition} from "@timeswap-labs/v2-option/contracts/enums/Position.sol";

import {ITimeswapV2Pool} from "@timeswap-labs/v2-pool/contracts/interfaces/ITimeswapV2Pool.sol";
import {PoolFactoryLibrary} from "@timeswap-labs/v2-pool/contracts/libraries/PoolFactory.sol";
import {ReentrancyGuard} from "@timeswap-labs/v2-pool/contracts/libraries/ReentrancyGuard.sol";

import {TimeswapV2PoolCollectTransactionFeesAndShortReturnedParam} from "@timeswap-labs/v2-pool/contracts/structs/Param.sol";

import {ITimeswapV2LiquidityToken} from "./interfaces/ITimeswapV2LiquidityToken.sol";

import {ITimeswapV2LiquidityTokenMintCallback} from "./interfaces/callbacks/ITimeswapV2LiquidityTokenMintCallback.sol";
import {ITimeswapV2LiquidityTokenBurnCallback} from "./interfaces/callbacks/ITimeswapV2LiquidityTokenBurnCallback.sol";
import {ITimeswapV2LiquidityTokenCollectCallback} from "./interfaces/callbacks/ITimeswapV2LiquidityTokenCollectCallback.sol";

import {ERC1155Enumerable} from "./base/ERC1155Enumerable.sol";
import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

import {TimeswapV2LiquidityTokenPosition, PositionLibrary} from "./structs/Position.sol";
import {FeesPosition, FeesPositionLibrary} from "./structs/FeesPosition.sol";
import {PoolPosition, PoolPositionLibrary} from "./structs/PoolPosition.sol";
import {TimeswapV2LiquidityTokenMintParam, TimeswapV2LiquidityTokenBurnParam, TimeswapV2LiquidityTokenCollectParam, ParamLibrary} from "./structs/Param.sol";
import {TimeswapV2LiquidityTokenMintCallbackParam, TimeswapV2LiquidityTokenBurnCallbackParam, TimeswapV2LiquidityTokenCollectCallbackParam} from "./structs/CallbackParam.sol";
import {Error} from "@timeswap-labs/v2-library/contracts/Error.sol";

/// @title An implementation for TS-V2 liquidity token system
/// @author Timeswap Labs
contract TimeswapV2LiquidityToken is ITimeswapV2LiquidityToken, ERC1155Enumerable {
  using ReentrancyGuard for uint96;

  using PositionLibrary for TimeswapV2LiquidityTokenPosition;
  using FeesPositionLibrary for FeesPosition;
  using PoolPositionLibrary for PoolPosition;

  address public immutable optionFactory;
  address public immutable poolFactory;

  constructor(
    address chosenOptionFactory,
    address chosenPoolFactory,
    string memory uri
  ) ERC1155("Timeswap V2 Liquidity Token") {
    optionFactory = chosenOptionFactory;
    poolFactory = chosenPoolFactory;
    _setURI(uri);
  }

  mapping(bytes32 => uint96) private reentrancyGuards;

  mapping(uint256 => TimeswapV2LiquidityTokenPosition) private _timeswapV2LiquidityTokenPositions;

  mapping(bytes32 => uint256) private _timeswapV2LiquidityTokenPositionIds;

  mapping(uint256 => PoolPosition) private _poolPositions;

  mapping(uint256 => mapping(address => FeesPosition)) private _feesPositions;

  mapping(uint256 => uint256) private _totalSupply;

  uint256 private counter;

  function changeInteractedIfNecessary(bytes32 key) private {
    if (reentrancyGuards[key] == ReentrancyGuard.NOT_INTERACTED) reentrancyGuards[key] = ReentrancyGuard.NOT_ENTERED;
  }

  /// @dev internal function to start the reentrancy guard
  function raiseGuard(bytes32 key) private {
    reentrancyGuards[key].check();
    reentrancyGuards[key] = ReentrancyGuard.ENTERED;
  }

  /// @dev internal function to end the reentrancy guard
  function lowerGuard(bytes32 key) private {
    reentrancyGuards[key] = ReentrancyGuard.NOT_ENTERED;
  }

  /// @inheritdoc ITimeswapV2LiquidityToken
  function positionOf(
    address owner,
    TimeswapV2LiquidityTokenPosition calldata timeswapV2LiquidityTokenPosition
  ) external view override returns (uint256 amount) {
    amount = balanceOf(owner, _timeswapV2LiquidityTokenPositionIds[timeswapV2LiquidityTokenPosition.toKey()]);
  }

  /// @inheritdoc ITimeswapV2LiquidityToken
  function feesEarnedAndShortReturnedGrowth(
    TimeswapV2LiquidityTokenPosition calldata timeswapV2LiquidityTokenPosition
  )
    external
    view
    override
    returns (uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth, uint256 shortReturnedGrowth)
  {
    uint256 id = _timeswapV2LiquidityTokenPositionIds[timeswapV2LiquidityTokenPosition.toKey()];

    if (_totalSupply[id] == 0) {
      PoolPosition memory poolPosition = _poolPositions[id];

      long0FeeGrowth = poolPosition.long0FeeGrowth;
      long1FeeGrowth = poolPosition.long1FeeGrowth;
      shortFeeGrowth = poolPosition.shortFeeGrowth;
      shortReturnedGrowth = poolPosition.shortReturnedGrowth;
    } else {
      (, address poolPair) = PoolFactoryLibrary.getWithCheck(
        optionFactory,
        poolFactory,
        timeswapV2LiquidityTokenPosition.token0,
        timeswapV2LiquidityTokenPosition.token1
      );

      (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned) = ITimeswapV2Pool(poolPair)
        .feesEarnedAndShortReturnedOf(
          timeswapV2LiquidityTokenPosition.strike,
          timeswapV2LiquidityTokenPosition.maturity,
          address(this)
        );

      (long0FeeGrowth, long1FeeGrowth, shortFeeGrowth, shortReturnedGrowth) = _poolPositions[id]
        .getFeesAndShortReturnedGrowth(uint160(_totalSupply[id]), long0Fees, long1Fees, shortFees, shortReturned);
    }
  }

  /// @inheritdoc ITimeswapV2LiquidityToken
  function feesEarnedAndShortReturnedGrowth(
    TimeswapV2LiquidityTokenPosition calldata timeswapV2LiquidityTokenPosition,
    uint96 durationForward
  )
    external
    view
    override
    returns (uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth, uint256 shortReturnedGrowth)
  {
    uint256 id = _timeswapV2LiquidityTokenPositionIds[timeswapV2LiquidityTokenPosition.toKey()];

    if (_totalSupply[id] == 0) {
      PoolPosition memory poolPosition = _poolPositions[id];

      long0FeeGrowth = poolPosition.long0FeeGrowth;
      long1FeeGrowth = poolPosition.long1FeeGrowth;
      shortFeeGrowth = poolPosition.shortFeeGrowth;
      shortReturnedGrowth = poolPosition.shortReturnedGrowth;
    } else {
      (, address poolPair) = PoolFactoryLibrary.getWithCheck(
        optionFactory,
        poolFactory,
        timeswapV2LiquidityTokenPosition.token0,
        timeswapV2LiquidityTokenPosition.token1
      );

      (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned) = ITimeswapV2Pool(poolPair)
        .feesEarnedAndShortReturnedOf(
          timeswapV2LiquidityTokenPosition.strike,
          timeswapV2LiquidityTokenPosition.maturity,
          address(this),
          durationForward
        );

      (long0FeeGrowth, long1FeeGrowth, shortFeeGrowth, shortReturnedGrowth) = _poolPositions[id]
        .getFeesAndShortReturnedGrowth(uint160(_totalSupply[id]), long0Fees, long1Fees, shortFees, shortReturned);
    }
  }

  /// @inheritdoc ITimeswapV2LiquidityToken
  function feesEarnedAndShortReturnedOf(
    address owner,
    TimeswapV2LiquidityTokenPosition calldata timeswapV2LiquidityTokenPosition
  ) external view returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned) {
    uint256 id = _timeswapV2LiquidityTokenPositionIds[timeswapV2LiquidityTokenPosition.toKey()];

    if (_totalSupply[id] == 0) {
      FeesPosition memory feesPosition = _feesPositions[id][owner];

      long0Fees = feesPosition.long0Fees;
      long1Fees = feesPosition.long1Fees;
      shortFees = feesPosition.shortFees;
      shortReturned = feesPosition.shortReturned;
    } else {
      (, address poolPair) = PoolFactoryLibrary.getWithCheck(
        optionFactory,
        poolFactory,
        timeswapV2LiquidityTokenPosition.token0,
        timeswapV2LiquidityTokenPosition.token1
      );

      (long0Fees, long1Fees, shortFees, shortReturned) = ITimeswapV2Pool(poolPair).feesEarnedAndShortReturnedOf(
        timeswapV2LiquidityTokenPosition.strike,
        timeswapV2LiquidityTokenPosition.maturity,
        address(this)
      );

      (
        uint256 long0FeeGrowth,
        uint256 long1FeeGrowth,
        uint256 shortFeeGrowth,
        uint256 shortReturnedGrowth
      ) = _poolPositions[id].getFeesAndShortReturnedGrowth(
          uint160(_totalSupply[id]),
          long0Fees,
          long1Fees,
          shortFees,
          shortReturned
        );

      FeesPosition memory feesPosition = _feesPositions[id][owner];

      (long0Fees, long1Fees, shortFees, shortReturned) = feesPosition.feesEarnedAndShortReturnedOf(
        uint160(balanceOf(owner, id)),
        long0FeeGrowth,
        long1FeeGrowth,
        shortFeeGrowth,
        shortReturnedGrowth
      );
    }
  }

  /// @inheritdoc ITimeswapV2LiquidityToken
  function feesEarnedAndShortReturnedOf(
    address owner,
    TimeswapV2LiquidityTokenPosition calldata timeswapV2LiquidityTokenPosition,
    uint96 durationForward
  ) external view returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned) {
    uint256 id = _timeswapV2LiquidityTokenPositionIds[timeswapV2LiquidityTokenPosition.toKey()];

    if (_totalSupply[id] == 0) {
      FeesPosition memory feesPosition = _feesPositions[id][owner];

      long0Fees = feesPosition.long0Fees;
      long1Fees = feesPosition.long1Fees;
      shortFees = feesPosition.shortFees;
      shortReturned = feesPosition.shortReturned;
    } else {
      (, address poolPair) = PoolFactoryLibrary.getWithCheck(
        optionFactory,
        poolFactory,
        timeswapV2LiquidityTokenPosition.token0,
        timeswapV2LiquidityTokenPosition.token1
      );

      (long0Fees, long1Fees, shortFees, shortReturned) = ITimeswapV2Pool(poolPair).feesEarnedAndShortReturnedOf(
        timeswapV2LiquidityTokenPosition.strike,
        timeswapV2LiquidityTokenPosition.maturity,
        address(this),
        durationForward
      );

      (
        uint256 long0FeeGrowth,
        uint256 long1FeeGrowth,
        uint256 shortFeeGrowth,
        uint256 shortReturnedGrowth
      ) = _poolPositions[id].getFeesAndShortReturnedGrowth(
          uint160(_totalSupply[id]),
          long0Fees,
          long1Fees,
          shortFees,
          shortReturned
        );

      FeesPosition memory feesPosition = _feesPositions[id][owner];

      (long0Fees, long1Fees, shortFees, shortReturned) = feesPosition.feesEarnedAndShortReturnedOf(
        uint160(balanceOf(owner, id)),
        long0FeeGrowth,
        long1FeeGrowth,
        shortFeeGrowth,
        shortReturnedGrowth
      );
    }
  }

  /// @inheritdoc ITimeswapV2LiquidityToken
  function transferTokenPositionFrom(
    address from,
    address to,
    TimeswapV2LiquidityTokenPosition calldata timeswapV2LiquidityTokenPosition,
    uint160 liquidityAmount,
    bytes calldata erc1155Data
  ) external {
    safeTransferFrom(
      from,
      to,
      _timeswapV2LiquidityTokenPositionIds[timeswapV2LiquidityTokenPosition.toKey()],
      liquidityAmount,
      erc1155Data
    );
  }

  /// @inheritdoc ITimeswapV2LiquidityToken
  function mint(TimeswapV2LiquidityTokenMintParam calldata param) external returns (bytes memory data) {
    ParamLibrary.check(param);

    TimeswapV2LiquidityTokenPosition memory timeswapV2LiquidityTokenPosition = TimeswapV2LiquidityTokenPosition({
      token0: param.token0,
      token1: param.token1,
      strike: param.strike,
      maturity: param.maturity
    });

    bytes32 key = timeswapV2LiquidityTokenPosition.toKey();
    uint256 id = _timeswapV2LiquidityTokenPositionIds[key];

    // if the position does not exist, create it
    if (id == 0) {
      id = (++counter);
      _timeswapV2LiquidityTokenPositions[id] = timeswapV2LiquidityTokenPosition;
      _timeswapV2LiquidityTokenPositionIds[key] = id;
    }

    changeInteractedIfNecessary(key);
    raiseGuard(key);

    (, address poolPair) = PoolFactoryLibrary.getWithCheck(optionFactory, poolFactory, param.token0, param.token1);

    // calculate the amount of liquidity tokens to mint
    uint160 liquidityBalanceTarget = ITimeswapV2Pool(poolPair).liquidityOf(
      param.strike,
      param.maturity,
      address(this)
    ) + param.liquidityAmount;

    // mint the liquidity tokens to the recipient
    _mint(param.to, id, param.liquidityAmount, param.erc1155Data);

    // ask the msg.sender to transfer the liquidity to this contract
    data = ITimeswapV2LiquidityTokenMintCallback(msg.sender).timeswapV2LiquidityTokenMintCallback(
      TimeswapV2LiquidityTokenMintCallbackParam({
        token0: param.token0,
        token1: param.token1,
        strike: param.strike,
        maturity: param.maturity,
        liquidityAmount: param.liquidityAmount,
        data: param.data
      })
    );

    // check if the enough liquidity amount target is received
    Error.checkEnough(
      ITimeswapV2Pool(poolPair).liquidityOf(param.strike, param.maturity, address(this)),
      liquidityBalanceTarget
    );

    // stop the reentrancy guard
    lowerGuard(key);
  }

  /// @inheritdoc ITimeswapV2LiquidityToken
  function burn(TimeswapV2LiquidityTokenBurnParam calldata param) external returns (bytes memory data) {
    ParamLibrary.check(param);

    bytes32 key = TimeswapV2LiquidityTokenPosition({
      token0: param.token0,
      token1: param.token1,
      strike: param.strike,
      maturity: param.maturity
    }).toKey();

    raiseGuard(key);

    (, address poolPair) = PoolFactoryLibrary.getWithCheck(optionFactory, poolFactory, param.token0, param.token1);

    // transfer the equivalent liquidity amount to the recipient from pool
    ITimeswapV2Pool(poolPair).transferLiquidity(param.strike, param.maturity, param.to, param.liquidityAmount);

    if (param.data.length != 0)
      data = ITimeswapV2LiquidityTokenBurnCallback(msg.sender).timeswapV2LiquidityTokenBurnCallback(
        TimeswapV2LiquidityTokenBurnCallbackParam({
          token0: param.token0,
          token1: param.token1,
          strike: param.strike,
          maturity: param.maturity,
          liquidityAmount: param.liquidityAmount,
          data: param.data
        })
      );

    // burn the liquidity tokens from the msg.sender
    _burn(msg.sender, _timeswapV2LiquidityTokenPositionIds[key], param.liquidityAmount);

    // stop the guard for reentrancy
    lowerGuard(key);
  }

  /// @inheritdoc ITimeswapV2LiquidityToken
  function collect(
    TimeswapV2LiquidityTokenCollectParam calldata param
  )
    external
    returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned, bytes memory data)
  {
    ParamLibrary.check(param);

    bytes32 key = TimeswapV2LiquidityTokenPosition({
      token0: param.token0,
      token1: param.token1,
      strike: param.strike,
      maturity: param.maturity
    }).toKey();

    // start the reentrancy guard
    raiseGuard(key);

    uint256 id = _timeswapV2LiquidityTokenPositionIds[key];

    if (!(param.from == msg.sender || isApprovedForAll(param.from, msg.sender))) revert NotApprovedToTransferFees();

    _updateFeesPositions(param.from, address(0), id, 0);

    (long0Fees, long1Fees, shortFees, shortReturned) = _feesPositions[id][param.from].getFeesAndShortReturned(
      param.long0FeesDesired,
      param.long1FeesDesired,
      param.shortFeesDesired,
      param.shortReturnedDesired
    );

    address optionPair = OptionFactoryLibrary.getWithCheck(optionFactory, param.token0, param.token1);

    if (long0Fees != 0)
      ITimeswapV2Option(optionPair).transferPosition(
        param.strike,
        param.maturity,
        param.long0FeesTo,
        TimeswapV2OptionPosition.Long0,
        long0Fees
      );

    if (long1Fees != 0)
      ITimeswapV2Option(optionPair).transferPosition(
        param.strike,
        param.maturity,
        param.long1FeesTo,
        TimeswapV2OptionPosition.Long1,
        long1Fees
      );

    if (shortFees + shortReturned != 0)
      ITimeswapV2Option(optionPair).transferPosition(
        param.strike,
        param.maturity,
        param.shortFeesTo,
        TimeswapV2OptionPosition.Short,
        shortFees + shortReturned
      );

    if (param.data.length != 0)
      data = ITimeswapV2LiquidityTokenCollectCallback(msg.sender).timeswapV2LiquidityTokenCollectCallback(
        TimeswapV2LiquidityTokenCollectCallbackParam({
          token0: param.token0,
          token1: param.token1,
          strike: param.strike,
          maturity: param.maturity,
          long0Fees: long0Fees,
          long1Fees: long1Fees,
          shortFees: shortFees,
          shortReturned: shortReturned,
          data: param.data
        })
      );

    // burn the desired fees and short returned from the fees position
    _feesPositions[id][param.from].burn(long0Fees, long1Fees, shortFees, shortReturned);

    // stop the reentrancy guard
    lowerGuard(key);
  }

  /// @dev utilises the beforeToken transfer hook for updating the fee positions
  function _beforeTokenTransfer(
    address operator,
    address from,
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory data
  ) internal override {
    super._beforeTokenTransfer(operator, from, to, ids, amounts, data);

    for (uint256 i; i < ids.length; ) {
      if (amounts[i] != 0) _updateFeesPositions(from, to, ids[i], amounts[i]);

      unchecked {
        ++i;
      }
    }
  }

  /// @dev updates fee positions
  function _updateFeesPositions(address from, address to, uint256 id, uint256 amount) private {
    if (from != to) {
      TimeswapV2LiquidityTokenPosition memory timeswapV2LiquidityTokenPosition = _timeswapV2LiquidityTokenPositions[id];

      (, address poolPair) = PoolFactoryLibrary.getWithCheck(
        optionFactory,
        poolFactory,
        timeswapV2LiquidityTokenPosition.token0,
        timeswapV2LiquidityTokenPosition.token1
      );

      (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned) = ITimeswapV2Pool(poolPair)
        .collectTransactionFeesAndShortReturned(
          TimeswapV2PoolCollectTransactionFeesAndShortReturnedParam({
            strike: timeswapV2LiquidityTokenPosition.strike,
            maturity: timeswapV2LiquidityTokenPosition.maturity,
            long0FeesTo: address(this),
            long1FeesTo: address(this),
            shortFeesTo: address(this),
            shortReturnedTo: address(this),
            long0FeesRequested: timeswapV2LiquidityTokenPosition.maturity > block.timestamp ? type(uint256).max : 0,
            long1FeesRequested: timeswapV2LiquidityTokenPosition.maturity > block.timestamp ? type(uint256).max : 0,
            shortFeesRequested: type(uint256).max,
            shortReturnedRequested: type(uint256).max
          })
        );

      uint160 totalLiquidity = uint160(_totalSupply[id]);

      PoolPosition storage poolPosition = _poolPositions[id];

      if (totalLiquidity != 0) poolPosition.update(totalLiquidity, long0Fees, long1Fees, shortFees, shortReturned);

      if (from != address(0)) {
        FeesPosition storage feesPosition = _feesPositions[id][from];
        feesPosition.update(
          uint160(balanceOf(from, id)),
          poolPosition.long0FeeGrowth,
          poolPosition.long1FeeGrowth,
          poolPosition.shortFeeGrowth,
          poolPosition.shortReturnedGrowth
        );
      }

      if (to != address(0)) {
        FeesPosition storage feesPosition = _feesPositions[id][to];
        feesPosition.update(
          uint160(balanceOf(to, id)),
          poolPosition.long0FeeGrowth,
          poolPosition.long1FeeGrowth,
          poolPosition.shortFeeGrowth,
          poolPosition.shortReturnedGrowth
        );
      }

      if (from == address(0)) _totalSupply[id] += amount;
      if (to == address(0)) _totalSupply[id] -= amount;
    }
  }
}

File 2 of 39 : ERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/ERC1155.sol)

pragma solidity ^0.8.0;

import "./IERC1155.sol";
import "./IERC1155Receiver.sol";
import "./extensions/IERC1155MetadataURI.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/introspection/ERC165.sol";

/**
 * @dev Implementation of the basic standard multi-token.
 * See https://eips.ethereum.org/EIPS/eip-1155
 * Originally based on code by Enjin: https://github.com/enjin/erc-1155
 *
 * _Available since v3.1._
 */
contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
    using Address for address;

    // Mapping from token ID to account balances
    mapping(uint256 => mapping(address => uint256)) private _balances;

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

    // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
    string private _uri;

    /**
     * @dev See {_setURI}.
     */
    constructor(string memory uri_) {
        _setURI(uri_);
    }

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

    /**
     * @dev See {IERC1155MetadataURI-uri}.
     *
     * This implementation returns the same URI for *all* token types. It relies
     * on the token type ID substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * Clients calling this function must replace the `\{id\}` substring with the
     * actual token type ID.
     */
    function uri(uint256) public view virtual override returns (string memory) {
        return _uri;
    }

    /**
     * @dev See {IERC1155-balanceOf}.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) public view virtual override returns (uint256) {
        require(account != address(0), "ERC1155: address zero is not a valid owner");
        return _balances[id][account];
    }

    /**
     * @dev See {IERC1155-balanceOfBatch}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] memory accounts,
        uint256[] memory ids
    ) public view virtual override returns (uint256[] memory) {
        require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch");

        uint256[] memory batchBalances = new uint256[](accounts.length);

        for (uint256 i = 0; i < accounts.length; ++i) {
            batchBalances[i] = balanceOf(accounts[i], ids[i]);
        }

        return batchBalances;
    }

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

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

    /**
     * @dev See {IERC1155-safeTransferFrom}.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public virtual override {
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not token owner or approved"
        );
        _safeTransferFrom(from, to, id, amount, data);
    }

    /**
     * @dev See {IERC1155-safeBatchTransferFrom}.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) public virtual override {
        require(
            from == _msgSender() || isApprovedForAll(from, _msgSender()),
            "ERC1155: caller is not token owner or approved"
        );
        _safeBatchTransferFrom(from, to, ids, amounts, data);
    }

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual {
        require(to != address(0), "ERC1155: transfer to the zero address");

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

        _beforeTokenTransfer(operator, from, to, ids, amounts, data);

        uint256 fromBalance = _balances[id][from];
        require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
        unchecked {
            _balances[id][from] = fromBalance - amount;
        }
        _balances[id][to] += amount;

        emit TransferSingle(operator, from, to, id, amount);

        _afterTokenTransfer(operator, from, to, ids, amounts, data);

        _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
        require(to != address(0), "ERC1155: transfer to the zero address");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; ++i) {
            uint256 id = ids[i];
            uint256 amount = amounts[i];

            uint256 fromBalance = _balances[id][from];
            require(fromBalance >= amount, "ERC1155: insufficient balance for transfer");
            unchecked {
                _balances[id][from] = fromBalance - amount;
            }
            _balances[id][to] += amount;
        }

        emit TransferBatch(operator, from, to, ids, amounts);

        _afterTokenTransfer(operator, from, to, ids, amounts, data);

        _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data);
    }

    /**
     * @dev Sets a new URI for all token types, by relying on the token type ID
     * substitution mechanism
     * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].
     *
     * By this mechanism, any occurrence of the `\{id\}` substring in either the
     * URI or any of the amounts in the JSON file at said URI will be replaced by
     * clients with the token type ID.
     *
     * For example, the `https://token-cdn-domain/\{id\}.json` URI would be
     * interpreted by clients as
     * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
     * for token type ID 0x4cce0.
     *
     * See {uri}.
     *
     * Because these URIs cannot be meaningfully represented by the {URI} event,
     * this function emits no events.
     */
    function _setURI(string memory newuri) internal virtual {
        _uri = newuri;
    }

    /**
     * @dev Creates `amount` tokens of token type `id`, and assigns them to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function _mint(address to, uint256 id, uint256 amount, bytes memory data) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

        _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

        _balances[id][to] += amount;
        emit TransferSingle(operator, address(0), to, id, amount);

        _afterTokenTransfer(operator, address(0), to, ids, amounts, data);

        _doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data);
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function _mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        require(to != address(0), "ERC1155: mint to the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, address(0), to, ids, amounts, data);

        for (uint256 i = 0; i < ids.length; i++) {
            _balances[ids[i]][to] += amounts[i];
        }

        emit TransferBatch(operator, address(0), to, ids, amounts);

        _afterTokenTransfer(operator, address(0), to, ids, amounts, data);

        _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data);
    }

    /**
     * @dev Destroys `amount` tokens of token type `id` from `from`
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `from` must have at least `amount` tokens of token type `id`.
     */
    function _burn(address from, uint256 id, uint256 amount) internal virtual {
        require(from != address(0), "ERC1155: burn from the zero address");

        address operator = _msgSender();
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

        _beforeTokenTransfer(operator, from, address(0), ids, amounts, "");

        uint256 fromBalance = _balances[id][from];
        require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
        unchecked {
            _balances[id][from] = fromBalance - amount;
        }

        emit TransferSingle(operator, from, address(0), id, amount);

        _afterTokenTransfer(operator, from, address(0), ids, amounts, "");
    }

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     */
    function _burnBatch(address from, uint256[] memory ids, uint256[] memory amounts) internal virtual {
        require(from != address(0), "ERC1155: burn from the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, address(0), ids, amounts, "");

        for (uint256 i = 0; i < ids.length; i++) {
            uint256 id = ids[i];
            uint256 amount = amounts[i];

            uint256 fromBalance = _balances[id][from];
            require(fromBalance >= amount, "ERC1155: burn amount exceeds balance");
            unchecked {
                _balances[id][from] = fromBalance - amount;
            }
        }

        emit TransferBatch(operator, from, address(0), ids, amounts);

        _afterTokenTransfer(operator, from, address(0), ids, amounts, "");
    }

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

    /**
     * @dev Hook that is called before any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `ids` and `amounts` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {}

    /**
     * @dev Hook that is called after any token transfer. This includes minting
     * and burning, as well as batched variants.
     *
     * The same hook is called on both single and batched variants. For single
     * transfers, the length of the `id` and `amount` arrays will be 1.
     *
     * Calling conditions (for each `id` and `amount` pair):
     *
     * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * of token type `id` will be  transferred to `to`.
     * - When `from` is zero, `amount` tokens of token type `id` will be minted
     * for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens of token type `id`
     * will be burned.
     * - `from` and `to` are never both zero.
     * - `ids` and `amounts` have the same, non-zero length.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {}

    function _doSafeTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) {
                if (response != IERC1155Receiver.onERC1155Received.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non-ERC1155Receiver implementer");
            }
        }
    }

    function _doSafeBatchTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try IERC1155Receiver(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns (
                bytes4 response
            ) {
                if (response != IERC1155Receiver.onERC1155BatchReceived.selector) {
                    revert("ERC1155: ERC1155Receiver rejected tokens");
                }
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert("ERC1155: transfer to non-ERC1155Receiver implementer");
            }
        }
    }

    function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) {
        uint256[] memory array = new uint256[](1);
        array[0] = element;

        return array;
    }
}

File 3 of 39 : IERC1155MetadataURI.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol)

pragma solidity ^0.8.0;

import "../IERC1155.sol";

/**
 * @dev Interface of the optional ERC1155MetadataExtension interface, as defined
 * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155MetadataURI is IERC1155 {
    /**
     * @dev Returns the URI for token type `id`.
     *
     * If the `\{id\}` substring is present in the URI, it must be replaced by
     * clients with the actual token type ID.
     */
    function uri(uint256 id) external view returns (string memory);
}

File 4 of 39 : IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 *
 * _Available since v3.1._
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
     */
    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);

    /**
     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
     * transfers.
     */
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /**
     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
     * `approved`.
     */
    event ApprovalForAll(address indexed account, address indexed operator, bool approved);

    /**
     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
     *
     * If an {URI} event was emitted for `id`, the standard
     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
     * returned by {IERC1155MetadataURI-uri}.
     */
    event URI(string value, uint256 indexed id);

    /**
     * @dev Returns the amount of tokens of token type `id` owned by `account`.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function balanceOf(address account, uint256 id) external view returns (uint256);

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
     *
     * Requirements:
     *
     * - `accounts` and `ids` must have the same length.
     */
    function balanceOfBatch(
        address[] calldata accounts,
        uint256[] calldata ids
    ) external view returns (uint256[] memory);

    /**
     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
     *
     * Emits an {ApprovalForAll} event.
     *
     * Requirements:
     *
     * - `operator` cannot be the caller.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
     *
     * See {setApprovalForAll}.
     */
    function isApprovedForAll(address account, address operator) external view returns (bool);

    /**
     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
     *
     * Emits a {TransferSingle} event.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
     * - `from` must have a balance of tokens of type `id` of at least `amount`.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
     * acceptance magic value.
     */
    function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * Emits a {TransferBatch} event.
     *
     * Requirements:
     *
     * - `ids` and `amounts` must have the same length.
     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
     * acceptance magic value.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}

File 5 of 39 : IERC1155Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev _Available since v3.1._
 */
interface IERC1155Receiver is IERC165 {
    /**
     * @dev Handles the receipt of a single ERC1155 token type. This function is
     * called at the end of a `safeTransferFrom` after the balance has been updated.
     *
     * NOTE: To accept the transfer, this must return
     * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
     * (i.e. 0xf23a6e61, or its own function selector).
     *
     * @param operator The address which initiated the transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param id The ID of the token being transferred
     * @param value The amount of tokens being transferred
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
     */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);

    /**
     * @dev Handles the receipt of a multiple ERC1155 token types. This function
     * is called at the end of a `safeBatchTransferFrom` after the balances have
     * been updated.
     *
     * NOTE: To accept the transfer(s), this must return
     * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
     * (i.e. 0xbc197c81, or its own function selector).
     *
     * @param operator The address which initiated the batch transfer (i.e. msg.sender)
     * @param from The address which previously owned the token
     * @param ids An array containing ids of each token being transferred (order and length must match values array)
     * @param values An array containing amounts of each token being transferred (order and length must match ids array)
     * @param data Additional data with no specified format
     * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
     */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);
}

File 6 of 39 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/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.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

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

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

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

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

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

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

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

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

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

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

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

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

File 7 of 39 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

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

pragma solidity ^0.8.0;

import "./IERC165.sol";

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

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

pragma solidity ^0.8.0;

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

File 10 of 39 : Error.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @title Library for errors
/// @author Timeswap Labs
/// @dev Common error messages
library Error {
  /// @dev Reverts when input is zero.
  error ZeroInput();

  /// @dev Reverts when output is zero.
  error ZeroOutput();

  /// @dev Reverts when a value cannot be zero.
  error CannotBeZero();

  /// @dev Reverts when a pool already have liquidity.
  /// @param liquidity The liquidity amount that already existed in the pool.
  error AlreadyHaveLiquidity(uint160 liquidity);

  /// @dev Reverts when a pool requires liquidity.
  error RequireLiquidity();

  /// @dev Reverts when a given address is the zero address.
  error ZeroAddress();

  /// @dev Reverts when the maturity given is not withing uint96.
  /// @param maturity The maturity being inquired.
  error IncorrectMaturity(uint256 maturity);

  /// @dev Reverts when an option of given strike and maturity is still inactive.
  /// @param strike The chosen strike.
  /// @param maturity The chosen maturity.
  error InactiveOption(uint256 strike, uint256 maturity);

  /// @dev Reverts when a pool of given strike and maturity is still inactive.
  /// @param strike The chosen strike.
  /// @param maturity The chosen maturity.
  error InactivePool(uint256 strike, uint256 maturity);

  /// @dev Reverts when a liquidity token is inactive.
  error InactiveLiquidityTokenChoice();

  /// @dev Reverts when the square root interest rate is zero.
  /// @param strike The chosen strike.
  /// @param maturity The chosen maturity.
  error ZeroSqrtInterestRate(uint256 strike, uint256 maturity);

  /// @dev Reverts when the maturity is already matured.
  /// @param maturity The maturity.
  /// @param blockTimestamp The current block timestamp.
  error AlreadyMatured(uint256 maturity, uint96 blockTimestamp);

  /// @dev Reverts when the maturity is still active.
  /// @param maturity The maturity.
  /// @param blockTimestamp The current block timestamp.
  error StillActive(uint256 maturity, uint96 blockTimestamp);

  /// @dev Token amount not received.
  /// @param minuend The amount being subtracted.
  /// @param subtrahend The amount subtracting.
  error NotEnoughReceived(uint256 minuend, uint256 subtrahend);

  /// @dev The deadline of a transaction has been reached.
  /// @param deadline The deadline set.
  error DeadlineReached(uint256 deadline);

  /// @dev Reverts when input is zero.
  function zeroInput() internal pure {
    revert ZeroInput();
  }

  /// @dev Reverts when output is zero.
  function zeroOutput() internal pure {
    revert ZeroOutput();
  }

  /// @dev Reverts when a value cannot be zero.
  function cannotBeZero() internal pure {
    revert CannotBeZero();
  }

  /// @dev Reverts when a pool already have liquidity.
  /// @param liquidity The liquidity amount that already existed in the pool.
  function alreadyHaveLiquidity(uint160 liquidity) internal pure {
    revert AlreadyHaveLiquidity(liquidity);
  }

  /// @dev Reverts when a pool requires liquidity.
  function requireLiquidity() internal pure {
    revert RequireLiquidity();
  }

  /// @dev Reverts when a given address is the zero address.
  function zeroAddress() internal pure {
    revert ZeroAddress();
  }

  /// @dev Reverts when the maturity given is not withing uint96.
  /// @param maturity The maturity being inquired.
  function incorrectMaturity(uint256 maturity) internal pure {
    revert IncorrectMaturity(maturity);
  }

  /// @dev Reverts when the maturity is already matured.
  /// @param maturity The maturity.
  /// @param blockTimestamp The current block timestamp.
  function alreadyMatured(uint256 maturity, uint96 blockTimestamp) internal pure {
    revert AlreadyMatured(maturity, blockTimestamp);
  }

  /// @dev Reverts when the maturity is still active.
  /// @param maturity The maturity.
  /// @param blockTimestamp The current block timestamp.
  function stillActive(uint256 maturity, uint96 blockTimestamp) internal pure {
    revert StillActive(maturity, blockTimestamp);
  }

  /// @dev The deadline of a transaction has been reached.
  /// @param deadline The deadline set.
  function deadlineReached(uint256 deadline) internal pure {
    revert DeadlineReached(deadline);
  }

  /// @dev Reverts when an option of given strike and maturity is still inactive.
  /// @param strike The chosen strike.
  function inactiveOptionChoice(uint256 strike, uint256 maturity) internal pure {
    revert InactiveOption(strike, maturity);
  }

  /// @dev Reverts when a pool of given strike and maturity is still inactive.
  /// @param strike The chosen strike.
  /// @param maturity The chosen maturity.
  function inactivePoolChoice(uint256 strike, uint256 maturity) internal pure {
    revert InactivePool(strike, maturity);
  }

  /// @dev Reverts when the square root interest rate is zero.
  /// @param strike The chosen strike.
  /// @param maturity The chosen maturity.
  function zeroSqrtInterestRate(uint256 strike, uint256 maturity) internal pure {
    revert ZeroSqrtInterestRate(strike, maturity);
  }

  /// @dev Reverts when a liquidity token is inactive.
  function inactiveLiquidityTokenChoice() internal pure {
    revert InactiveLiquidityTokenChoice();
  }

  /// @dev Reverts when token amount not received.
  /// @param balance The balance amount being subtracted.
  /// @param balanceTarget The amount target.
  function checkEnough(uint256 balance, uint256 balanceTarget) internal pure {
    if (balance < balanceTarget) revert NotEnoughReceived(balance, balanceTarget);
  }
}

File 11 of 39 : FullMath.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

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

/// @title Library for math utils for uint512
/// @author Timeswap Labs
library FullMath {
  using Math for uint256;

  /// @dev Reverts when modulo by zero.
  error ModuloByZero();

  /// @dev Reverts when add512 overflows over uint512.
  /// @param addendA0 The least significant part of first addend.
  /// @param addendA1 The most significant part of first addend.
  /// @param addendB0 The least significant part of second addend.
  /// @param addendB1 The most significant part of second addend.
  error AddOverflow(uint256 addendA0, uint256 addendA1, uint256 addendB0, uint256 addendB1);

  /// @dev Reverts when sub512 underflows.
  /// @param minuend0 The least significant part of minuend.
  /// @param minuend1 The most significant part of minuend.
  /// @param subtrahend0 The least significant part of subtrahend.
  /// @param subtrahend1 The most significant part of subtrahend.
  error SubUnderflow(uint256 minuend0, uint256 minuend1, uint256 subtrahend0, uint256 subtrahend1);

  /// @dev Reverts when div512To256 overflows over uint256.
  /// @param dividend0 The least significant part of dividend.
  /// @param dividend1 The most significant part of dividend.
  /// @param divisor The divisor.
  error DivOverflow(uint256 dividend0, uint256 dividend1, uint256 divisor);

  /// @dev Reverts when mulDiv overflows over uint256.
  /// @param multiplicand The multiplicand.
  /// @param multiplier The multiplier.
  /// @param divisor The divisor.
  error MulDivOverflow(uint256 multiplicand, uint256 multiplier, uint256 divisor);

  /// @dev Calculates the sum of two uint512 numbers.
  /// @notice Reverts on overflow over uint512.
  /// @param addendA0 The least significant part of addendA.
  /// @param addendA1 The most significant part of addendA.
  /// @param addendB0 The least significant part of addendB.
  /// @param addendB1 The most significant part of addendB.
  /// @return sum0 The least significant part of sum.
  /// @return sum1 The most significant part of sum.
  function add512(
    uint256 addendA0,
    uint256 addendA1,
    uint256 addendB0,
    uint256 addendB1
  ) internal pure returns (uint256 sum0, uint256 sum1) {
    uint256 carry;
    assembly {
      sum0 := add(addendA0, addendB0)
      carry := lt(sum0, addendA0)
      sum1 := add(add(addendA1, addendB1), carry)
    }

    if (carry == 0 ? addendA1 > sum1 : (sum1 == 0 || addendA1 > sum1 - 1))
      revert AddOverflow(addendA0, addendA1, addendB0, addendB1);
  }

  /// @dev Calculates the difference of two uint512 numbers.
  /// @notice Reverts on underflow.
  /// @param minuend0 The least significant part of minuend.
  /// @param minuend1 The most significant part of minuend.
  /// @param subtrahend0 The least significant part of subtrahend.
  /// @param subtrahend1 The most significant part of subtrahend.
  /// @return difference0 The least significant part of difference.
  /// @return difference1 The most significant part of difference.
  function sub512(
    uint256 minuend0,
    uint256 minuend1,
    uint256 subtrahend0,
    uint256 subtrahend1
  ) internal pure returns (uint256 difference0, uint256 difference1) {
    assembly {
      difference0 := sub(minuend0, subtrahend0)
      difference1 := sub(sub(minuend1, subtrahend1), lt(minuend0, subtrahend0))
    }

    if (subtrahend1 > minuend1 || (subtrahend1 == minuend1 && subtrahend0 > minuend0))
      revert SubUnderflow(minuend0, minuend1, subtrahend0, subtrahend1);
  }

  /// @dev Calculate the product of two uint256 numbers that may result to uint512 product.
  /// @notice Can never overflow.
  /// @param multiplicand The multiplicand.
  /// @param multiplier The multiplier.
  /// @return product0 The least significant part of product.
  /// @return product1 The most significant part of product.
  function mul512(uint256 multiplicand, uint256 multiplier) internal pure returns (uint256 product0, uint256 product1) {
    assembly {
      let mm := mulmod(multiplicand, multiplier, not(0))
      product0 := mul(multiplicand, multiplier)
      product1 := sub(sub(mm, product0), lt(mm, product0))
    }
  }

  /// @dev Divide 2 to 256 power by the divisor.
  /// @dev Rounds down the result.
  /// @notice Reverts when divide by zero.
  /// @param divisor The divisor.
  /// @return quotient The quotient.
  function div256(uint256 divisor) private pure returns (uint256 quotient) {
    if (divisor == 0) revert Math.DivideByZero();
    assembly {
      quotient := add(div(sub(0, divisor), divisor), 1)
    }
  }

  /// @dev Compute 2 to 256 power modulo the given value.
  /// @notice Reverts when modulo by zero.
  /// @param value The given value.
  /// @return result The result.
  function mod256(uint256 value) private pure returns (uint256 result) {
    if (value == 0) revert ModuloByZero();
    assembly {
      result := mod(sub(0, value), value)
    }
  }

  /// @dev Divide a uint512 number by uint256 number to return a uint512 number.
  /// @dev Rounds down the result.
  /// @param dividend0 The least significant part of dividend.
  /// @param dividend1 The most significant part of dividend.
  /// @param divisor The divisor.
  /// @param quotient0 The least significant part of quotient.
  /// @param quotient1 The most significant part of quotient.
  function div512(
    uint256 dividend0,
    uint256 dividend1,
    uint256 divisor
  ) private pure returns (uint256 quotient0, uint256 quotient1) {
    if (dividend1 == 0) quotient0 = dividend0.div(divisor, false);
    else {
      uint256 q = div256(divisor);
      uint256 r = mod256(divisor);
      while (dividend1 != 0) {
        (uint256 t0, uint256 t1) = mul512(dividend1, q);
        (quotient0, quotient1) = add512(quotient0, quotient1, t0, t1);
        (t0, t1) = mul512(dividend1, r);
        (dividend0, dividend1) = add512(t0, t1, dividend0, 0);
      }
      (quotient0, quotient1) = add512(quotient0, quotient1, dividend0.div(divisor, false), 0);
    }
  }

  /// @dev Divide a uint512 number by a uint256 number.
  /// @dev Reverts when result is greater than uint256.
  /// @notice Skips div512 if dividend1 is zero.
  /// @param dividend0 The least significant part of dividend.
  /// @param dividend1 The most significant part of dividend.
  /// @param divisor The divisor.
  /// @param roundUp Round up the result when true. Round down if false.
  /// @param quotient The quotient.
  function div512To256(
    uint256 dividend0,
    uint256 dividend1,
    uint256 divisor,
    bool roundUp
  ) internal pure returns (uint256 quotient) {
    uint256 quotient1;
    (quotient, quotient1) = div512(dividend0, dividend1, divisor);

    if (quotient1 != 0) revert DivOverflow(dividend0, dividend1, divisor);

    if (roundUp) {
      (uint256 productA0, uint256 productA1) = mul512(quotient, divisor);
      if (dividend1 > productA1 || dividend0 > productA0) quotient++;
    }
  }

  /// @dev Divide a uint512 number by a uint256 number.
  /// @notice Skips div512 if dividend1 is zero.
  /// @param dividend0 The least significant part of dividend.
  /// @param dividend1 The most significant part of dividend.
  /// @param divisor The divisor.
  /// @param roundUp Round up the result when true. Round down if false.
  /// @param quotient0 The least significant part of quotient.
  /// @param quotient1 The most significant part of quotient.
  function div512(
    uint256 dividend0,
    uint256 dividend1,
    uint256 divisor,
    bool roundUp
  ) internal pure returns (uint256 quotient0, uint256 quotient1) {
    (quotient0, quotient1) = div512(dividend0, dividend1, divisor);

    if (roundUp) {
      (uint256 productA0, uint256 productA1) = mul512(quotient0, divisor);
      productA1 += (quotient1 * divisor);
      if (dividend1 > productA1 || dividend0 > productA0) {
        if (quotient0 == type(uint256).max) {
          quotient0 = 0;
          quotient1++;
        } else quotient0++;
      }
    }
  }

  /// @dev Multiply two uint256 number then divide it by a uint256 number.
  /// @notice Skips mulDiv if product of multiplicand and multiplier is uint256 number.
  /// @dev Reverts when result is greater than uint256.
  /// @param multiplicand The multiplicand.
  /// @param multiplier The multiplier.
  /// @param divisor The divisor.
  /// @param roundUp Round up the result when true. Round down if false.
  /// @return result The result.
  function mulDiv(
    uint256 multiplicand,
    uint256 multiplier,
    uint256 divisor,
    bool roundUp
  ) internal pure returns (uint256 result) {
    (uint256 product0, uint256 product1) = mul512(multiplicand, multiplier);

    // Handle non-overflow cases, 256 by 256 division
    if (product1 == 0) return result = product0.div(divisor, roundUp);

    // Make sure the result is less than 2**256.
    // Also prevents divisor == 0
    if (divisor <= product1) revert MulDivOverflow(multiplicand, multiplier, divisor);

    unchecked {
      ///////////////////////////////////////////////
      // 512 by 256 division.
      ///////////////////////////////////////////////

      // Make division exact by subtracting the remainder from [product1 product0]
      // Compute remainder using mulmod
      uint256 remainder;
      assembly {
        remainder := mulmod(multiplicand, multiplier, divisor)
      }
      // Subtract 256 bit number from 512 bit number
      assembly {
        product1 := sub(product1, gt(remainder, product0))
        product0 := sub(product0, remainder)
      }

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

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

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

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

      // Because the division is now exact we can divide by multiplying
      // with the modular inverse of divisor. 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 product1
      // is no longer required.
      result = product0 * inv;
    }

    if (roundUp && mulmod(multiplicand, multiplier, divisor) != 0) result++;
  }

  /// @dev Get the square root of a uint512 number.
  /// @param value0 The least significant of the number.
  /// @param value1 The most significant of the number.
  /// @param roundUp Round up the result when true. Round down if false.
  /// @return result The result.
  function sqrt512(uint256 value0, uint256 value1, bool roundUp) internal pure returns (uint256 result) {
    if (value1 == 0) result = value0.sqrt(roundUp);
    else {
      uint256 estimate = sqrt512Estimate(value0, value1, type(uint256).max);
      result = type(uint256).max;
      while (estimate < result) {
        result = estimate;
        estimate = sqrt512Estimate(value0, value1, estimate);
      }

      if (roundUp) {
        (uint256 product0, uint256 product1) = mul512(result, result);
        if (value1 > product1 || value0 > product0) result++;
      }
    }
  }

  /// @dev An iterative process of getting sqrt512 following Newtonian method.
  /// @param value0 The least significant of the number.
  /// @param value1 The most significant of the number.
  /// @param currentEstimate The current estimate of the iteration.
  /// @param estimate The new estimate of the iteration.
  function sqrt512Estimate(
    uint256 value0,
    uint256 value1,
    uint256 currentEstimate
  ) private pure returns (uint256 estimate) {
    uint256 r0 = div512To256(value0, value1, currentEstimate, false);
    uint256 r1;
    (r0, r1) = add512(r0, 0, currentEstimate, 0);
    estimate = div512To256(r0, r1, 2, false);
  }
}

File 12 of 39 : Math.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @title Library for math related utils
/// @author Timeswap Labs
library Math {
  /// @dev Reverts when divide by zero.
  error DivideByZero();
  error Overflow();

  /// @dev Add two uint256.
  /// @notice May overflow.
  /// @param addend1 The first addend.
  /// @param addend2 The second addend.
  /// @return sum The sum.
  function unsafeAdd(uint256 addend1, uint256 addend2) internal pure returns (uint256 sum) {
    unchecked {
      sum = addend1 + addend2;
    }
  }

  /// @dev Subtract two uint256.
  /// @notice May underflow.
  /// @param minuend The minuend.
  /// @param subtrahend The subtrahend.
  /// @return difference The difference.
  function unsafeSub(uint256 minuend, uint256 subtrahend) internal pure returns (uint256 difference) {
    unchecked {
      difference = minuend - subtrahend;
    }
  }

  /// @dev Multiply two uint256.
  /// @notice May overflow.
  /// @param multiplicand The multiplicand.
  /// @param multiplier The multiplier.
  /// @return product The product.
  function unsafeMul(uint256 multiplicand, uint256 multiplier) internal pure returns (uint256 product) {
    unchecked {
      product = multiplicand * multiplier;
    }
  }

  /// @dev Divide two uint256.
  /// @notice Reverts when divide by zero.
  /// @param dividend The dividend.
  /// @param divisor The divisor.
  //// @param roundUp Round up the result when true. Round down if false.
  /// @return quotient The quotient.
  function div(uint256 dividend, uint256 divisor, bool roundUp) internal pure returns (uint256 quotient) {
    quotient = dividend / divisor;

    if (roundUp && dividend % divisor != 0) quotient++;
  }

  /// @dev Shift right a uint256 number.
  /// @param dividend The dividend.
  /// @param divisorBit The divisor in bits.
  /// @param roundUp True if ceiling the result. False if floor the result.
  /// @return quotient The quotient.
  function shr(uint256 dividend, uint8 divisorBit, bool roundUp) internal pure returns (uint256 quotient) {
    quotient = dividend >> divisorBit;

    if (roundUp && dividend % (1 << divisorBit) != 0) quotient++;
  }

  /// @dev Gets the square root of a value.
  /// @param value The value being square rooted.
  /// @param roundUp Round up the result when true. Round down if false.
  /// @return result The resulting value of the square root.
  function sqrt(uint256 value, bool roundUp) internal pure returns (uint256 result) {
    if (value == type(uint256).max) return result = type(uint128).max;
    if (value == 0) return 0;
    unchecked {
      uint256 estimate = (value + 1) >> 1;
      result = value;
      while (estimate < result) {
        result = estimate;
        estimate = (value / estimate + estimate) >> 1;
      }
    }

    if (roundUp && result * result < value) result++;
  }

  /// @dev Gets the min of two uint256 number.
  /// @param value1 The first value to be compared.
  /// @param value2 The second value to be compared.
  /// @return result The min result.
  function min(uint256 value1, uint256 value2) internal pure returns (uint256 result) {
    return value1 < value2 ? value1 : value2;
  }
}

File 13 of 39 : Position.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @dev The three type of native token positions.
/// @dev Long0 is denominated as the underlying Token0.
/// @dev Long1 is denominated as the underlying Token1.
/// @dev When strike greater than uint128 then Short is denominated as Token0 (the base token denomination).
/// @dev When strike is uint128 then Short is denominated as Token1 (the base token denomination).
enum TimeswapV2OptionPosition {
  Long0,
  Long1,
  Short
}

/// @title library for position utils
/// @author Timeswap Labs
/// @dev Helper functions for the TimeswapOptionPosition enum.
library PositionLibrary {
  /// @dev Reverts when the given type of position is invalid.
  error InvalidPosition();

  /// @dev Checks that the position input is correct.
  /// @param position The position input.
  function check(TimeswapV2OptionPosition position) internal pure {
    if (uint256(position) >= 3) revert InvalidPosition();
  }
}

File 14 of 39 : Transaction.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @dev The different input for the mint transaction.
enum TimeswapV2OptionMint {
  GivenTokensAndLongs,
  GivenShorts
}

/// @dev The different input for the burn transaction.
enum TimeswapV2OptionBurn {
  GivenTokensAndLongs,
  GivenShorts
}

/// @dev The different input for the swap transaction.
enum TimeswapV2OptionSwap {
  GivenToken0AndLong0,
  GivenToken1AndLong1
}

/// @dev The different input for the collect transaction.
enum TimeswapV2OptionCollect {
  GivenShort,
  GivenToken0,
  GivenToken1
}

/// @title library for transaction checks
/// @author Timeswap Labs
/// @dev Helper functions for the all enums in this module.
library TransactionLibrary {
  /// @dev Reverts when the given type of transaction is invalid.
  error InvalidTransaction();

  /// @dev checks that the given input is correct.
  /// @param transaction the mint transaction input.
  function check(TimeswapV2OptionMint transaction) internal pure {
    if (uint256(transaction) >= 2) revert InvalidTransaction();
  }

  /// @dev checks that the given input is correct.
  /// @param transaction the burn transaction input.
  function check(TimeswapV2OptionBurn transaction) internal pure {
    if (uint256(transaction) >= 2) revert InvalidTransaction();
  }

  /// @dev checks that the given input is correct.
  /// @param transaction the swap transaction input.
  function check(TimeswapV2OptionSwap transaction) internal pure {
    if (uint256(transaction) >= 2) revert InvalidTransaction();
  }

  /// @dev checks that the given input is correct.
  /// @param transaction the collect transaction input.
  function check(TimeswapV2OptionCollect transaction) internal pure {
    if (uint256(transaction) >= 3) revert InvalidTransaction();
  }
}

File 15 of 39 : ITimeswapV2Option.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {TimeswapV2OptionPosition} from "../enums/Position.sol";
import {TimeswapV2OptionMintParam, TimeswapV2OptionBurnParam, TimeswapV2OptionSwapParam, TimeswapV2OptionCollectParam} from "../structs/Param.sol";
import {StrikeAndMaturity} from "../structs/StrikeAndMaturity.sol";

/// @title An interface for a contract that deploys Timeswap V2 Option pair contracts
/// @notice A Timeswap V2 Option pair facilitates option mechanics between any two assets that strictly conform
/// to the ERC20 specification.
interface ITimeswapV2Option {
  /* ===== EVENT ===== */

  /// @dev Emits when a position is transferred.
  /// @param strike The strike ratio of token1 per token0 of the position.
  /// @param maturity The maturity of the position.
  /// @param from The address of the caller of the transferPosition function.
  /// @param to The address of the recipient of the position.
  /// @param position The type of position transferred. More information in the Position module.
  /// @param amount The amount of balance transferred.
  event TransferPosition(
    uint256 indexed strike,
    uint256 indexed maturity,
    address from,
    address to,
    TimeswapV2OptionPosition position,
    uint256 amount
  );

  /// @dev Emits when a mint transaction is called.
  /// @param strike The strike ratio of token1 per token0 of the option.
  /// @param maturity The maturity of the option.
  /// @param caller The address of the caller of the mint function.
  /// @param long0To The address of the recipient of long token0 position.
  /// @param long1To The address of the recipient of long token1 position.
  /// @param shortTo The address of the recipient of short position.
  /// @param token0AndLong0Amount The amount of token0 deposited and long0 minted.
  /// @param token1AndLong1Amount The amount of token1 deposited and long1 minted.
  /// @param shortAmount The amount of short minted.
  event Mint(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address long0To,
    address long1To,
    address shortTo,
    uint256 token0AndLong0Amount,
    uint256 token1AndLong1Amount,
    uint256 shortAmount
  );

  /// @dev Emits when a burn transaction is called.
  /// @param strike The strike ratio of token1 per token0 of the option.
  /// @param maturity The maturity of the option.
  /// @param caller The address of the caller of the mint function.
  /// @param token0To The address of the recipient of token0.
  /// @param token1To The address of the recipient of token1.
  /// @param token0AndLong0Amount The amount of token0 withdrawn and long0 burnt.
  /// @param token1AndLong1Amount The amount of token1 withdrawn and long1 burnt.
  /// @param shortAmount The amount of short burnt.
  event Burn(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address token0To,
    address token1To,
    uint256 token0AndLong0Amount,
    uint256 token1AndLong1Amount,
    uint256 shortAmount
  );

  /// @dev Emits when a swap transaction is called.
  /// @param strike The strike ratio of token1 per token0 of the option.
  /// @param maturity The maturity of the option.
  /// @param caller The address of the caller of the mint function.
  /// @param tokenTo The address of the recipient of token0 or token1.
  /// @param longTo The address of the recipient of long token0 or long token1.
  /// @param isLong0toLong1 The direction of the swap. More information in the Transaction module.
  /// @param token0AndLong0Amount If the direction is from long0 to long1, the amount of token0 withdrawn and long0 burnt.
  /// If the direction is from long1 to long0, the amount of token0 deposited and long0 minted.
  /// @param token1AndLong1Amount If the direction is from long0 to long1, the amount of token1 deposited and long1 minted.
  /// If the direction is from long1 to long0, the amount of token1 withdrawn and long1 burnt.
  event Swap(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address tokenTo,
    address longTo,
    bool isLong0toLong1,
    uint256 token0AndLong0Amount,
    uint256 token1AndLong1Amount
  );

  /// @dev Emits when a collect transaction is called.
  /// @param strike The strike ratio of token1 per token0 of the option.
  /// @param maturity The maturity of the option.
  /// @param caller The address of the caller of the mint function.
  /// @param token0To The address of the recipient of token0.
  /// @param token1To The address of the recipient of token1.
  /// @param long0AndToken0Amount The amount of token0 withdrawn.
  /// @param long1AndToken1Amount The amount of token1 withdrawn.
  /// @param shortAmount The amount of short burnt.
  event Collect(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address token0To,
    address token1To,
    uint256 long0AndToken0Amount,
    uint256 long1AndToken1Amount,
    uint256 shortAmount
  );

  /* ===== VIEW ===== */

  /// @dev Returns the factory address that deployed this contract.
  function optionFactory() external view returns (address);

  /// @dev Returns the first ERC20 token address of the pair.
  function token0() external view returns (address);

  /// @dev Returns the second ERC20 token address of the pair.
  function token1() external view returns (address);

  /// @dev Get the strike and maturity of the option in the option enumeration list.
  /// @param id The chosen index.
  function getByIndex(uint256 id) external view returns (StrikeAndMaturity memory);

  /// @dev Number of options being interacted.
  function numberOfOptions() external view returns (uint256);

  /// @dev Returns the total position of the option.
  /// @param strike The strike ratio of token1 per token0 of the position.
  /// @param maturity The maturity of the position.
  /// @param position The type of position inquired. More information in the Position module.
  /// @return balance The total position.
  function totalPosition(
    uint256 strike,
    uint256 maturity,
    TimeswapV2OptionPosition position
  ) external view returns (uint256 balance);

  /// @dev Returns the position of an owner of the option.
  /// @param strike The strike ratio of token1 per token0 of the position.
  /// @param maturity The maturity of the position.
  /// @param owner The address of the owner of the position.
  /// @param position The type of position inquired. More information in the Position module.
  /// @return balance The user position.
  function positionOf(
    uint256 strike,
    uint256 maturity,
    address owner,
    TimeswapV2OptionPosition position
  ) external view returns (uint256 balance);

  /* ===== UPDATE ===== */

  /// @dev Transfer position to another address.
  /// @param strike The strike ratio of token1 per token0 of the position.
  /// @param maturity The maturity of the position.
  /// @param to The address of the recipient of the position.
  /// @param position The type of position transferred. More information in the Position module.
  /// @param amount The amount of balance transferred.
  function transferPosition(
    uint256 strike,
    uint256 maturity,
    address to,
    TimeswapV2OptionPosition position,
    uint256 amount
  ) external;

  /// @dev Mint position.
  /// Mint long token0 position when token0 is deposited.
  /// Mint long token1 position when token1 is deposited.
  /// @dev Can only be called before the maturity of the pool.
  /// @param param The parameters for the mint function.
  /// @return token0AndLong0Amount The amount of token0 deposited and long0 minted.
  /// @return token1AndLong1Amount The amount of token1 deposited and long1 minted.
  /// @return shortAmount The amount of short minted.
  /// @return data The additional data return.
  function mint(
    TimeswapV2OptionMintParam calldata param
  )
    external
    returns (uint256 token0AndLong0Amount, uint256 token1AndLong1Amount, uint256 shortAmount, bytes memory data);

  /// @dev Burn short position.
  /// Withdraw token0, when long token0 is burnt.
  /// Withdraw token1, when long token1 is burnt.
  /// @dev Can only be called before the maturity of the pool.
  /// @param param The parameters for the burn function.
  /// @return token0AndLong0Amount The amount of token0 withdrawn and long0 burnt.
  /// @return token1AndLong1Amount The amount of token1 withdrawn and long1 burnt.
  /// @return shortAmount The amount of short burnt.
  function burn(
    TimeswapV2OptionBurnParam calldata param
  )
    external
    returns (uint256 token0AndLong0Amount, uint256 token1AndLong1Amount, uint256 shortAmount, bytes memory data);

  /// @dev If the direction is from long token0 to long token1, burn long token0 and mint equivalent long token1,
  /// also deposit token1 and withdraw token0.
  /// If the direction is from long token1 to long token0, burn long token1 and mint equivalent long token0,
  /// also deposit token0 and withdraw token1.
  /// @dev Can only be called before the maturity of the pool.
  /// @param param The parameters for the swap function.
  /// @return token0AndLong0Amount If direction is Long0ToLong1, the amount of token0 withdrawn and long0 burnt.
  /// If direction is Long1ToLong0, the amount of token0 deposited and long0 minted.
  /// @return token1AndLong1Amount If direction is Long0ToLong1, the amount of token1 deposited and long1 minted.
  /// If direction is Long1ToLong0, the amount of token1 withdrawn and long1 burnt.
  /// @return data The additional data return.
  function swap(
    TimeswapV2OptionSwapParam calldata param
  ) external returns (uint256 token0AndLong0Amount, uint256 token1AndLong1Amount, bytes memory data);

  /// @dev Burn short position, withdraw token0 and token1.
  /// @dev Can only be called after the maturity of the pool.
  /// @param param The parameters for the collect function.
  /// @return token0Amount The amount of token0 withdrawn.
  /// @return token1Amount The amount of token1 withdrawn.
  /// @return shortAmount The amount of short burnt.
  function collect(
    TimeswapV2OptionCollectParam calldata param
  ) external returns (uint256 token0Amount, uint256 token1Amount, uint256 shortAmount, bytes memory data);
}

File 16 of 39 : ITimeswapV2OptionFactory.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @title The interface for the contract that deploys Timeswap V2 Option pair contracts
/// @notice The Timeswap V2 Option Factory facilitates creation of Timeswap V2 Options pair.
interface ITimeswapV2OptionFactory {
  /* ===== EVENT ===== */

  /// @dev Emits when a new Timeswap V2 Option contract is created.
  /// @param caller The address of the caller of create function.
  /// @param token0 The first ERC20 token address of the pair.
  /// @param token1 The second ERC20 token address of the pair.
  /// @param optionPair The address of the Timeswap V2 Option contract created.
  event Create(address indexed caller, address indexed token0, address indexed token1, address optionPair);

  /* ===== VIEW ===== */

  /// @dev Returns the address of a Timeswap V2 Option.
  /// @dev Returns a zero address if the Timeswap V2 Option does not exist.
  /// @notice The token0 address must be smaller than token1 address.
  /// @param token0 The first ERC20 token address of the pair.
  /// @param token1 The second ERC20 token address of the pair.
  /// @return optionPair The address of the Timeswap V2 Option contract or a zero address.
  function get(address token0, address token1) external view returns (address optionPair);

  /// @dev Get the address of the option pair in the option pair enumeration list.
  /// @param id The chosen index.
  function getByIndex(uint256 id) external view returns (address optionPair);

  /// @dev The number of option pairs deployed.
  function numberOfPairs() external view returns (uint256);

  /* ===== UPDATE ===== */

  /// @dev Creates a Timeswap V2 Option based on pair parameters.
  /// @dev Cannot create a duplicate Timeswap V2 Option with the same pair parameters.
  /// @notice The token0 address must be smaller than token1 address.
  /// @param token0 The first ERC20 token address of the pair.
  /// @param token1 The second ERC20 token address of the pair.
  /// @param optionPair The address of the Timeswap V2 Option contract created.
  function create(address token0, address token1) external returns (address optionPair);
}

File 17 of 39 : OptionFactory.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {Error} from "@timeswap-labs/v2-library/contracts/Error.sol";

import {OptionPairLibrary} from "./OptionPair.sol";

import {ITimeswapV2OptionFactory} from "../interfaces/ITimeswapV2OptionFactory.sol";

/// @title library for option utils
/// @author Timeswap Labs
library OptionFactoryLibrary {
  using OptionPairLibrary for address;

  /// @dev reverts if the factory is the zero address.
  error ZeroFactoryAddress();

  /// @dev check if the factory address is not zero.
  /// @param optionFactory The factory address.
  function checkNotZeroFactory(address optionFactory) internal pure {
    if (optionFactory == address(0)) revert ZeroFactoryAddress();
  }

  /// @dev Helper function to get the option pair address.
  /// @param optionFactory The address of the option factory.
  /// @param token0 The smaller ERC20 address of the pair.
  /// @param token1 The larger ERC20 address of the pair.
  /// @return optionPair The result option pair address.
  function get(address optionFactory, address token0, address token1) internal view returns (address optionPair) {
    optionPair = ITimeswapV2OptionFactory(optionFactory).get(token0, token1);
  }

  /// @dev Helper function to get the option pair address.
  /// @notice reverts when the option pair does not exist.
  /// @param optionFactory The address of the option factory.
  /// @param token0 The smaller ERC20 address of the pair.
  /// @param token1 The larger ERC20 address of the pair.
  /// @return optionPair The result option pair address.
  function getWithCheck(
    address optionFactory,
    address token0,
    address token1
  ) internal view returns (address optionPair) {
    optionPair = get(optionFactory, token0, token1);
    if (optionPair == address(0)) Error.zeroAddress();
  }
}

File 18 of 39 : OptionPair.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @title library for optionPair utils
/// @author Timeswap Labs
library OptionPairLibrary {
  /// @dev Reverts when option address is zero.
  error ZeroOptionAddress();

  /// @dev Reverts when the pair has incorrect format.
  /// @param token0 The first ERC20 token address of the pair.
  /// @param token1 The second ERC20 token address of the pair.
  error InvalidOptionPair(address token0, address token1);

  /// @dev Reverts when the Timeswap V2 Option already exist.
  /// @param token0 The first ERC20 token address of the pair.
  /// @param token1 The second ERC20 token address of the pair.
  /// @param optionPair The address of the existed Pair contract.
  error OptionPairAlreadyExisted(address token0, address token1, address optionPair);

  /// @dev Checks if option address is not zero.
  /// @param optionPair The option pair address being inquired.
  function checkNotZeroAddress(address optionPair) internal pure {
    if (optionPair == address(0)) revert ZeroOptionAddress();
  }

  /// @dev Check if the pair tokens is in correct format.
  /// @notice Reverts if token0 is greater than or equal token1.
  /// @param token0 The first ERC20 token address of the pair.
  /// @param token1 The second ERC20 token address of the pair.
  function checkCorrectFormat(address token0, address token1) internal pure {
    if (token0 >= token1) revert InvalidOptionPair(token0, token1);
  }

  /// @dev Check if the pair already existed.
  /// @notice Reverts if the pair is not a zero address.
  /// @param token0 The first ERC20 token address of the pair.
  /// @param token1 The second ERC20 token address of the pair.
  /// @param optionPair The address of the existed Pair contract.
  function checkDoesNotExist(address token0, address token1, address optionPair) internal pure {
    if (optionPair != address(0)) revert OptionPairAlreadyExisted(token0, token1, optionPair);
  }
}

File 19 of 39 : Param.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {Error} from "@timeswap-labs/v2-library/contracts/Error.sol";

import {TimeswapV2OptionMint, TimeswapV2OptionBurn, TimeswapV2OptionSwap, TimeswapV2OptionCollect, TransactionLibrary} from "../enums/Transaction.sol";

/// @dev The parameter to call the mint function.
/// @param strike The strike of the option.
/// @param maturity The maturity of the option.
/// @param long0To The recipient of long0 positions.
/// @param long1To The recipient of long1 positions.
/// @param shortTo The recipient of short positions.
/// @param transaction The type of mint transaction, more information in Transaction module.
/// @param amount0 If transaction is givenTokensAndLongs, the amount of token0 deposited, and amount of long0 position minted.
/// If transaction is givenShorts, the amount of short minted, where the equivalent strike converted amount is long0 positions.
/// @param amount1 If transaction is givenTokensAndLongs, the amount of token1 deposited, and amount of long1 position minted.
/// If transaction is givenShorts, the amount of short minted, where the equivalent strike converted amount is long1 positions.
/// @param data The data to be sent to the function, which will go to the mint callback.
struct TimeswapV2OptionMintParam {
  uint256 strike;
  uint256 maturity;
  address long0To;
  address long1To;
  address shortTo;
  TimeswapV2OptionMint transaction;
  uint256 amount0;
  uint256 amount1;
  bytes data;
}

/// @dev The parameter to call the burn function.
/// @param strike The strike of the option.
/// @param maturity The maturity of the option.
/// @param token0To The recipient of token0 withdrawn.
/// @param token1To The recipient of token1 withdrawn.
/// @param transaction The type of burn transaction, more information in Transaction module.
/// @param amount0 If transaction is givenTokensAndLongs, the amount of token0 withdrawn, and amount of long0 position burnt.
/// If transaction is givenShorts, the amount of short burnt, where the equivalent strike converted amount is long0 positions.
/// @param amount1 If transaction is givenTokensAndLongs, the amount of token1 withdrawn, and amount of long1 position burnt.
/// If transaction is givenShorts, the amount of short burnt, where the equivalent strike converted amount is long1 positions.
/// @param data The data to be sent to the function, which will go to the burn callback.
/// @notice If data length is zero, skips the callback.
struct TimeswapV2OptionBurnParam {
  uint256 strike;
  uint256 maturity;
  address token0To;
  address token1To;
  TimeswapV2OptionBurn transaction;
  uint256 amount0;
  uint256 amount1;
  bytes data;
}

/// @dev The parameter to call the swap function.
/// @param strike The strike of the option.
/// @param maturity The maturity of the option.
/// @param tokenTo The recipient of token0 when isLong0ToLong1 or token1 when isLong1ToLong0.
/// @param longTo The recipient of long1 positions when isLong0ToLong1 or long0 when isLong1ToLong0.
/// @param isLong0ToLong1 Transform long0 positions to long1 positions when true. Transform long1 positions to long0 positions when false.
/// @param transaction The type of swap transaction, more information in Transaction module.
/// @param amount If isLong0ToLong1 and transaction is GivenToken0AndLong0, this is the amount of token0 withdrawn, and the amount of long0 position burnt.
/// If isLong1ToLong0 and transaction is GivenToken0AndLong0, this is the amount of token0 to be deposited, and the amount of long0 position minted.
/// If isLong0ToLong1 and transaction is GivenToken1AndLong1, this is the amount of token1 to be deposited, and the amount of long1 position minted.
/// If isLong1ToLong0 and transaction is GivenToken1AndLong1, this is the amount of token1 withdrawn, and the amount of long1 position burnt.
/// @param data The data to be sent to the function, which will go to the swap callback.
struct TimeswapV2OptionSwapParam {
  uint256 strike;
  uint256 maturity;
  address tokenTo;
  address longTo;
  bool isLong0ToLong1;
  TimeswapV2OptionSwap transaction;
  uint256 amount;
  bytes data;
}

/// @dev The parameter to call the collect function.
/// @param strike The strike of the option.
/// @param maturity The maturity of the option.
/// @param token0To The recipient of token0 withdrawn.
/// @param token1To The recipient of token1 withdrawn.
/// @param transaction The type of collect transaction, more information in Transaction module.
/// @param amount If transaction is GivenShort, the amount of short position burnt.
/// If transaction is GivenToken0, the amount of token0 withdrawn.
/// If transaction is GivenToken1, the amount of token1 withdrawn.
/// @param data The data to be sent to the function, which will go to the collect callback.
/// @notice If data length is zero, skips the callback.
struct TimeswapV2OptionCollectParam {
  uint256 strike;
  uint256 maturity;
  address token0To;
  address token1To;
  TimeswapV2OptionCollect transaction;
  uint256 amount;
  bytes data;
}

library ParamLibrary {
  /// @dev Sanity checks
  /// @param param the parameter for mint transaction.
  /// @param blockTimestamp the current block timestamp.
  function check(TimeswapV2OptionMintParam memory param, uint96 blockTimestamp) internal pure {
    if (param.strike == 0) Error.zeroInput();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.maturity < blockTimestamp) Error.alreadyMatured(param.maturity, blockTimestamp);
    if (param.shortTo == address(0)) Error.zeroAddress();
    if (param.long0To == address(0)) Error.zeroAddress();
    if (param.long1To == address(0)) Error.zeroAddress();
    TransactionLibrary.check(param.transaction);
    if (param.amount0 == 0 && param.amount1 == 0) Error.zeroInput();
  }

  /// @dev Sanity checks
  /// @param param the parameter for burn transaction.
  /// @param blockTimestamp the current block timestamp.
  function check(TimeswapV2OptionBurnParam memory param, uint96 blockTimestamp) internal pure {
    if (param.strike == 0) Error.zeroInput();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.maturity < blockTimestamp) Error.alreadyMatured(param.maturity, blockTimestamp);
    if (param.token0To == address(0)) Error.zeroAddress();
    if (param.token1To == address(0)) Error.zeroAddress();
    TransactionLibrary.check(param.transaction);
    if (param.amount0 == 0 && param.amount1 == 0) Error.zeroInput();
  }

  /// @dev Sanity checks
  /// @param param the parameter for swap transaction.
  /// @param blockTimestamp the current block timestamp.
  function check(TimeswapV2OptionSwapParam memory param, uint96 blockTimestamp) internal pure {
    if (param.strike == 0) Error.zeroInput();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.maturity < blockTimestamp) Error.alreadyMatured(param.maturity, blockTimestamp);
    if (param.tokenTo == address(0)) Error.zeroAddress();
    if (param.longTo == address(0)) Error.zeroAddress();
    TransactionLibrary.check(param.transaction);
    if (param.amount == 0) Error.zeroInput();
  }

  /// @dev Sanity checks
  /// @param param the parameter for collect transaction.
  /// @param blockTimestamp the current block timestamp.
  function check(TimeswapV2OptionCollectParam memory param, uint96 blockTimestamp) internal pure {
    if (param.strike == 0) Error.zeroInput();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.maturity >= blockTimestamp) Error.stillActive(param.maturity, blockTimestamp);
    if (param.token0To == address(0)) Error.zeroAddress();
    if (param.token1To == address(0)) Error.zeroAddress();
    TransactionLibrary.check(param.transaction);
    if (param.amount == 0) Error.zeroInput();
  }
}

File 20 of 39 : StrikeAndMaturity.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @dev A data with strike and maturity data.
/// @param strike The strike.
/// @param maturity The maturity.
struct StrikeAndMaturity {
  uint256 strike;
  uint256 maturity;
}

File 21 of 39 : Transaction.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @dev The different kind of mint transactions.
enum TimeswapV2PoolMint {
  GivenLiquidity,
  GivenLong,
  GivenShort,
  GivenLarger
}

/// @dev The different kind of burn transactions.
enum TimeswapV2PoolBurn {
  GivenLiquidity,
  GivenLong,
  GivenShort,
  GivenSmaller
}

/// @dev The different kind of deleverage transactions.
enum TimeswapV2PoolDeleverage {
  GivenDeltaSqrtInterestRate,
  GivenLong,
  GivenShort,
  GivenSum
}

/// @dev The different kind of leverage transactions.
enum TimeswapV2PoolLeverage {
  GivenDeltaSqrtInterestRate,
  GivenLong,
  GivenShort,
  GivenSum
}

/// @dev The different kind of rebalance transactions.
enum TimeswapV2PoolRebalance {
  GivenLong0,
  GivenLong1
}

library TransactionLibrary {
  /// @dev Reverts when the given type of transaction is invalid.
  error InvalidTransaction();

  /// @dev Function to revert with the error InvalidTransaction.
  function invalidTransaction() internal pure {
    revert InvalidTransaction();
  }

  /// @dev Sanity checks for the mint parameters.
  function check(TimeswapV2PoolMint transaction) internal pure {
    if (uint256(transaction) >= 4) revert InvalidTransaction();
  }

  /// @dev Sanity checks for the burn parameters.
  function check(TimeswapV2PoolBurn transaction) internal pure {
    if (uint256(transaction) >= 4) revert InvalidTransaction();
  }

  /// @dev Sanity checks for the deleverage parameters.
  function check(TimeswapV2PoolDeleverage transaction) internal pure {
    if (uint256(transaction) >= 4) revert InvalidTransaction();
  }

  /// @dev Sanity checks for the leverage parameters.
  function check(TimeswapV2PoolLeverage transaction) internal pure {
    if (uint256(transaction) >= 4) revert InvalidTransaction();
  }

  /// @dev Sanity checks for the rebalance parameters.
  function check(TimeswapV2PoolRebalance transaction) internal pure {
    if (uint256(transaction) >= 2) revert InvalidTransaction();
  }
}

File 22 of 39 : IOwnableTwoSteps.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

interface IOwnableTwoSteps {
  /// @dev Emits when the pending owner is chosen.
  /// @param pendingOwner The new pending owner.
  event SetOwner(address pendingOwner);

  /// @dev Emits when the pending owner accepted and become the new owner.
  /// @param owner The new owner.
  event AcceptOwner(address owner);

  /// @dev The address of the current owner.
  /// @return address
  function owner() external view returns (address);

  /// @dev The address of the current pending owner.
  /// @notice The address can be zero which signifies no pending owner.
  /// @return address
  function pendingOwner() external view returns (address);

  /// @dev The owner sets the new pending owner.
  /// @notice Can only be called by the owner.
  /// @param chosenPendingOwner The newly chosen pending owner.
  function setPendingOwner(address chosenPendingOwner) external;

  /// @dev The pending owner accepts being the new owner.
  /// @notice Can only be called by the pending owner.
  function acceptOwner() external;
}

File 23 of 39 : ITimeswapV2Pool.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {StrikeAndMaturity} from "@timeswap-labs/v2-option/contracts/structs/StrikeAndMaturity.sol";

import {TimeswapV2PoolCollectProtocolFeesParam, TimeswapV2PoolCollectTransactionFeesAndShortReturnedParam, TimeswapV2PoolMintParam, TimeswapV2PoolBurnParam, TimeswapV2PoolDeleverageParam, TimeswapV2PoolLeverageParam, TimeswapV2PoolRebalanceParam} from "../structs/Param.sol";

/// @title An interface for Timeswap V2 Pool contract.
interface ITimeswapV2Pool {
  /// @dev Emits when liquidity position is transferred.
  /// @param strike The strike of the option and pool.
  /// @param maturity The maturity of the option and pool.
  /// @param from The sender of liquidity position.
  /// @param to The receipeint of liquidity position.
  /// @param liquidityAmount The amount of liquidity position transferred.
  event TransferLiquidity(
    uint256 indexed strike,
    uint256 indexed maturity,
    address from,
    address to,
    uint160 liquidityAmount
  );

  /// @dev Emits when protocol fees are withdrawn by the factory contract owner.
  /// @param strike The strike of the option and pool.
  /// @param maturity The maturity of the option and pool.
  /// @param caller The caller of the collectProtocolFees function.
  /// @param long0To The recipient of long0 position fees.
  /// @param long1To The recipient of long1 position fees.
  /// @param shortTo The recipient of short position fees.
  /// @param long0Amount The amount of long0 position fees withdrawn.
  /// @param long1Amount The amount of long1 position fees withdrawn.
  /// @param shortAmount The amount of short position fees withdrawn.
  event CollectProtocolFees(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address long0To,
    address long1To,
    address shortTo,
    uint256 long0Amount,
    uint256 long1Amount,
    uint256 shortAmount
  );

  /// @dev Emits when transaction fees are withdrawn by a liquidity provider.
  /// @param strike The strike of the option and pool.
  /// @param maturity The maturity of the option and pool.
  /// @param caller The caller of the collectTransactionFees function.
  /// @param long0FeesTo The recipient of long0 position fees.
  /// @param long1FeesTo The recipient of long1 position fees.
  /// @param shortFeesTo The recipient of short position fees.
  /// @param shortReturnedTo The recipient of short position returned.
  /// @param long0Fees The amount of long0 position fees withdrawn.
  /// @param long1Fees The amount of long1 position fees withdrawn.
  /// @param shortFees The amount of short position fees withdrawn.
  /// @param shortReturned The amount of short position returned withdrawn.
  event CollectTransactionFeesAndShortReturned(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address long0FeesTo,
    address long1FeesTo,
    address shortFeesTo,
    address shortReturnedTo,
    uint256 long0Fees,
    uint256 long1Fees,
    uint256 shortFees,
    uint256 shortReturned
  );

  /// @dev Emits when the mint transaction is called.
  /// @param strike The strike of the option and pool.
  /// @param maturity The maturity of the option and pool.
  /// @param caller The caller of the mint function.
  /// @param to The recipient of liquidity positions.
  /// @param liquidityAmount The amount of liquidity positions minted.
  /// @param long0Amount The amount of long0 positions deposited.
  /// @param long1Amount The amount of long1 positions deposited.
  /// @param shortAmount The amount of short positions deposited.
  event Mint(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address to,
    uint160 liquidityAmount,
    uint256 long0Amount,
    uint256 long1Amount,
    uint256 shortAmount
  );

  /// @dev Emits when the burn transaction is called.
  /// @param strike The strike of the option and pool.
  /// @param maturity The maturity of the option and pool.
  /// @param caller The caller of the burn function.
  /// @param long0To The recipient of long0 positions.
  /// @param long1To The recipient of long1 positions.
  /// @param shortTo The recipient of short positions.
  /// @param liquidityAmount The amount of liquidity positions burnt.
  /// @param long0Amount The amount of long0 positions withdrawn.
  /// @param long1Amount The amount of long1 positions withdrawn.
  /// @param shortAmount The amount of short positions withdrawn.
  event Burn(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address long0To,
    address long1To,
    address shortTo,
    uint160 liquidityAmount,
    uint256 long0Amount,
    uint256 long1Amount,
    uint256 shortAmount
  );

  /// @dev Emits when deleverage transaction is called.
  /// @param strike The strike of the option and pool.
  /// @param maturity The maturity of the option and pool.
  /// @param caller The caller of the deleverage function.
  /// @param to The recipient of short positions.
  /// @param long0Amount The amount of long0 positions deposited.
  /// @param long1Amount The amount of long1 positions deposited.
  /// @param shortAmount The amount of short positions withdrawn.
  event Deleverage(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address to,
    uint256 long0Amount,
    uint256 long1Amount,
    uint256 shortAmount
  );

  /// @dev Emits when leverage transaction is called.
  /// @param strike The strike of the option and pool.
  /// @param maturity The maturity of the option and pool.
  /// @param caller The caller of the leverage function.
  /// @param long0To The recipient of long0 positions.
  /// @param long1To The recipient of long1 positions.
  /// @param long0Amount The amount of long0 positions withdrawn.
  /// @param long1Amount The amount of long1 positions withdrawn.
  /// @param shortAmount The amount of short positions deposited.
  event Leverage(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address long0To,
    address long1To,
    uint256 long0Amount,
    uint256 long1Amount,
    uint256 shortAmount
  );

  /// @dev Emits when rebalance transaction is called.
  /// @param strike The strike of the option and pool.
  /// @param maturity The maturity of the option and pool.
  /// @param caller The caller of the rebalance function.
  /// @param to If isLong0ToLong1 then recipient of long0 positions, ekse recipient of long1 positions.
  /// @param isLong0ToLong1 Long0ToLong1 if true. Long1ToLong0 if false.
  /// @param long0Amount If isLong0ToLong1, amount of long0 positions deposited.
  /// If isLong1ToLong0, amount of long0 positions withdrawn.
  /// @param long1Amount If isLong0ToLong1, amount of long1 positions withdrawn.
  /// If isLong1ToLong0, amount of long1 positions deposited.
  event Rebalance(
    uint256 indexed strike,
    uint256 indexed maturity,
    address indexed caller,
    address to,
    bool isLong0ToLong1,
    uint256 long0Amount,
    uint256 long1Amount
  );

  error Quote();

  /* ===== VIEW ===== */

  /// @dev Returns the factory address that deployed this contract.
  function poolFactory() external view returns (address);

  /// @dev Returns the Timeswap V2 Option of the pair.
  function optionPair() external view returns (address);

  /// @dev Returns the transaction fee earned by the liquidity providers.
  function transactionFee() external view returns (uint256);

  /// @dev Returns the protocol fee earned by the protocol.
  function protocolFee() external view returns (uint256);

  /// @dev Get the strike and maturity of the pool in the pool enumeration list.
  /// @param id The chosen index.
  function getByIndex(uint256 id) external view returns (StrikeAndMaturity memory);

  /// @dev Get the number of pools being interacted.
  function numberOfPools() external view returns (uint256);

  /// @dev Returns the total amount of liquidity in the pool.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @return liquidityAmount The liquidity amount of the pool.
  function totalLiquidity(uint256 strike, uint256 maturity) external view returns (uint160 liquidityAmount);

  /// @dev Returns the square root of the interest rate of the pool.
  /// @dev the square root of interest rate is z/(x+y) where z is the short amount, x+y is the long0 amount, and y is the long1 amount.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @return rate The square root of the interest rate of the pool.
  function sqrtInterestRate(uint256 strike, uint256 maturity) external view returns (uint160 rate);

  /// @dev Returns the amount of liquidity owned by the given address.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @param owner The address to query the liquidity of.
  /// @return liquidityAmount The amount of liquidity owned by the given address.
  function liquidityOf(uint256 strike, uint256 maturity, address owner) external view returns (uint160 liquidityAmount);

  /// @dev It calculates the global fee and global short returned growth, which is fee increased per unit of liquidity token.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @return long0FeeGrowth The global fee increased per unit of liquidity token for long0.
  /// @return long1FeeGrowth The global fee increased per unit of liquidity token for long1.
  /// @return shortFeeGrowth The global fee increased per unit of liquidity token for short.
  /// @return shortReturnedGrowth The global returned increased per unit of liquidity token for short.
  function feesEarnedAndShortReturnedGrowth(
    uint256 strike,
    uint256 maturity
  )
    external
    view
    returns (uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth, uint256 shortReturnedGrowth);

  /// @dev It calculates the global fee and global short returned growth, which is fee increased per unit of liquidity token.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @param durationForward The duration of time moved forward.
  /// @return long0FeeGrowth The global fee increased per unit of liquidity token for long0.
  /// @return long1FeeGrowth The global fee increased per unit of liquidity token for long1.
  /// @return shortFeeGrowth The global fee increased per unit of liquidity token for short.
  /// @return shortReturnedGrowth The global returned increased per unit of liquidity token for short.
  function feesEarnedAndShortReturnedGrowth(
    uint256 strike,
    uint256 maturity,
    uint96 durationForward
  )
    external
    view
    returns (uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth, uint256 shortReturnedGrowth);

  /// @dev It calculates the fee earned and global short returned growth, which is short returned per unit of liquidity token.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @param owner The address to query the fees earned of.
  /// @return long0Fees The amount of long0 fees owned by the given address.
  /// @return long1Fees The amount of long1 fees owned by the given address.
  /// @return shortFees The amount of short fees owned by the given address.
  /// @return shortReturned The amount of short returned owned by the given address.
  function feesEarnedAndShortReturnedOf(
    uint256 strike,
    uint256 maturity,
    address owner
  ) external view returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned);

  /// @dev It calculates the fee earned and global short returned growth, which is short returned per unit of liquidity token.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @param owner The address to query the fees earned of.
  /// @param durationForward The duration of time moved forward.
  /// @return long0Fees The amount of long0 fees owned by the given address.
  /// @return long1Fees The amount of long1 fees owned by the given address.
  /// @return shortFees The amount of short fees owned by the given address.
  /// @return shortReturned The amount of short returned owned by the given address.
  function feesEarnedAndShortReturnedOf(
    uint256 strike,
    uint256 maturity,
    address owner,
    uint96 durationForward
  ) external view returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned);

  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @return long0ProtocolFees The amount of long0 protocol fees owned by the owner of the factory contract.
  /// @return long1ProtocolFees The amount of long1 protocol fees owned by the owner of the factory contract.
  /// @return shortProtocolFees The amount of short protocol fees owned by the owner of the factory contract.
  function protocolFeesEarned(
    uint256 strike,
    uint256 maturity
  ) external view returns (uint256 long0ProtocolFees, uint256 long1ProtocolFees, uint256 shortProtocolFees);

  /// @dev Returns the amount of long0 and long1 in the pool.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @return long0Amount The amount of long0 in the pool.
  /// @return long1Amount The amount of long1 in the pool.
  function totalLongBalance(
    uint256 strike,
    uint256 maturity
  ) external view returns (uint256 long0Amount, uint256 long1Amount);

  /// @dev Returns the amount of long0 and long1 adjusted for the protocol and transaction fee.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @return long0Amount The amount of long0 in the pool, adjusted for the protocol and transaction fee.
  /// @return long1Amount The amount of long1 in the pool, adjusted for the protocol and transaction fee.
  function totalLongBalanceAdjustFees(
    uint256 strike,
    uint256 maturity
  ) external view returns (uint256 long0Amount, uint256 long1Amount);

  /// @dev Returns the amount of sum of long0 and long1 converted to base denomination in the pool.
  /// @dev Returns the amount of short positions in the pool.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @return longAmount The amount of sum of long0 and long1 converted to base denomination in the pool.
  /// @return shortAmount The amount of short in the pool.
  function totalPositions(
    uint256 strike,
    uint256 maturity
  ) external view returns (uint256 longAmount, uint256 shortAmount);

  /* ===== UPDATE ===== */

  /// @dev Transfer liquidity positions to another address.
  /// @notice Does not transfer the transaction fees earned by the sender.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @param to The recipient of the liquidity positions.
  /// @param liquidityAmount The amount of liquidity positions transferred
  function transferLiquidity(uint256 strike, uint256 maturity, address to, uint160 liquidityAmount) external;

  /// @dev initializes the pool with the given parameters.
  /// @param strike The strike price of the pool.
  /// @param maturity The maturity of the pool.
  /// @param rate The square root of the interest rate of the pool.
  function initialize(uint256 strike, uint256 maturity, uint160 rate) external;

  /// @dev Collects the protocol fees of the pool.
  /// @dev only protocol owner can call this function.
  /// @dev if the owner enters an amount which is greater than the fee amount they have earned, withdraw only the amount they have.
  /// @param param The parameters of the collectProtocolFees.
  /// @return long0Amount The amount of long0 collected.
  /// @return long1Amount The amount of long1 collected.
  /// @return shortAmount The amount of short collected.
  function collectProtocolFees(
    TimeswapV2PoolCollectProtocolFeesParam calldata param
  ) external returns (uint256 long0Amount, uint256 long1Amount, uint256 shortAmount);

  /// @dev Collects the transaction fees of the pool.
  /// @dev only liquidity provider can call this function.
  /// @dev if the owner enters an amount which is greater than the fee amount they have earned, withdraw only the amount they have.
  /// @param param The parameters of the collectTransactionFee.
  /// @return long0Fees The amount of long0 fees collected.
  /// @return long1Fees The amount of long1 fees collected.
  /// @return shortFees The amount of short fees collected.
  /// @return shortReturned The amount of short returned collected.
  function collectTransactionFeesAndShortReturned(
    TimeswapV2PoolCollectTransactionFeesAndShortReturnedParam calldata param
  ) external returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned);

  /// @dev deposit Short and Long tokens and mints Liquidity
  /// @dev can be only called before the maturity.
  /// @param param it is a struct that contains the parameters of the mint function
  /// @return liquidityAmount The amount of liquidity minted.
  /// @return long0Amount The amount of long0 deposited.
  /// @return long1Amount The amount of long1 deposited.
  /// @return shortAmount The amount of short deposited.
  /// @return data the data used for the callbacks.
  function mint(
    TimeswapV2PoolMintParam calldata param
  )
    external
    returns (uint160 liquidityAmount, uint256 long0Amount, uint256 long1Amount, uint256 shortAmount, bytes memory data);

  /// @dev deposit Short and Long tokens and mints Liquidity
  /// @dev can be only called before the maturity.
  /// @notice Will always revert with error Quote after the final callback.
  /// @param param it is a struct that contains the parameters of the mint function.
  /// @param durationForward The duration of time moved forward.
  /// @return liquidityAmount The amount of liquidity minted.
  /// @return long0Amount The amount of long0 deposited.
  /// @return long1Amount The amount of long1 deposited.
  /// @return shortAmount The amount of short deposited.
  /// @return data the data used for the callbacks.
  function mint(
    TimeswapV2PoolMintParam calldata param,
    uint96 durationForward
  )
    external
    returns (uint160 liquidityAmount, uint256 long0Amount, uint256 long1Amount, uint256 shortAmount, bytes memory data);

  /// @dev burn Liquidity and receive Short and Long tokens
  /// @dev can be only called before the maturity.
  /// @dev after the maturity of the pool, the long0 and long1 tokens are zero. And the short tokens are added into the transaction fees.
  /// @dev if the user wants to burn the liquidity after the maturity, they should call the collectTransactionFee function.
  /// @param param it is a struct that contains the parameters of the burn function
  /// @return liquidityAmount The amount of liquidity burned.
  /// @return long0Amount The amount of long0 withdrawn.
  /// @return long1Amount The amount of long1 withdrawn.
  /// @return shortAmount The amount of short withdrawn.
  /// @return data the data used for the callbacks.
  function burn(
    TimeswapV2PoolBurnParam calldata param
  )
    external
    returns (uint160 liquidityAmount, uint256 long0Amount, uint256 long1Amount, uint256 shortAmount, bytes memory data);

  /// @dev burn Liquidity and receive Short and Long tokens
  /// @dev can be only called before the maturity.
  /// @dev after the maturity of the pool, the long0 and long1 tokens are zero. And the short tokens are added into the transaction fees.
  /// @dev if the user wants to burn the liquidity after the maturity, they should call the collectTransactionFee function.
  /// @notice Will always revert with error Quote after the final callback.
  /// @param param it is a struct that contains the parameters of the burn function.
  /// @param durationForward The duration of time moved forward.
  /// @return liquidityAmount The amount of liquidity burned.
  /// @return long0Amount The amount of long0 withdrawn.
  /// @return long1Amount The amount of long1 withdrawn.
  /// @return shortAmount The amount of short withdrawn.
  /// @return data the data used for the callbacks.
  function burn(
    TimeswapV2PoolBurnParam calldata param,
    uint96 durationForward
  )
    external
    returns (uint160 liquidityAmount, uint256 long0Amount, uint256 long1Amount, uint256 shortAmount, bytes memory data);

  /// @dev deposit Long tokens and receive Short tokens
  /// @dev can be only called before the maturity.
  /// @param param it is a struct that contains the parameters of the deleverage function
  /// @return long0Amount The amount of long0 deposited.
  /// @return long1Amount The amount of long1 deposited.
  /// @return shortAmount The amount of short received.
  /// @return data the data used for the callbacks.
  function deleverage(
    TimeswapV2PoolDeleverageParam calldata param
  ) external returns (uint256 long0Amount, uint256 long1Amount, uint256 shortAmount, bytes memory data);

  /// @dev deposit Long tokens and receive Short tokens
  /// @dev can be only called before the maturity.
  /// @notice Will always revert with error Quote after the final callback.
  /// @param param it is a struct that contains the parameters of the deleverage function.
  /// @param durationForward The duration of time moved forward.
  /// @return long0Amount The amount of long0 deposited.
  /// @return long1Amount The amount of long1 deposited.
  /// @return shortAmount The amount of short received.
  /// @return data the data used for the callbacks.
  function deleverage(
    TimeswapV2PoolDeleverageParam calldata param,
    uint96 durationForward
  ) external returns (uint256 long0Amount, uint256 long1Amount, uint256 shortAmount, bytes memory data);

  /// @dev deposit Short tokens and receive Long tokens
  /// @dev can be only called before the maturity.
  /// @param param it is a struct that contains the parameters of the leverage function.
  /// @return long0Amount The amount of long0 received.
  /// @return long1Amount The amount of long1 received.
  /// @return shortAmount The amount of short deposited.
  /// @return data the data used for the callbacks.
  function leverage(
    TimeswapV2PoolLeverageParam calldata param
  ) external returns (uint256 long0Amount, uint256 long1Amount, uint256 shortAmount, bytes memory data);

  /// @dev deposit Short tokens and receive Long tokens
  /// @dev can be only called before the maturity.
  /// @notice Will always revert with error Quote after the final callback.
  /// @param param it is a struct that contains the parameters of the leverage function.
  /// @param durationForward The duration of time moved forward.
  /// @return long0Amount The amount of long0 received.
  /// @return long1Amount The amount of long1 received.
  /// @return shortAmount The amount of short deposited.
  /// @return data the data used for the callbacks.
  function leverage(
    TimeswapV2PoolLeverageParam calldata param,
    uint96 durationForward
  ) external returns (uint256 long0Amount, uint256 long1Amount, uint256 shortAmount, bytes memory data);

  /// @dev Deposit Long0 to receive Long1 or deposit Long1 to receive Long0.
  /// @dev can be only called before the maturity.
  /// @param param it is a struct that contains the parameters of the rebalance function
  /// @return long0Amount The amount of long0 received/deposited.
  /// @return long1Amount The amount of long1 deposited/received.
  /// @return data the data used for the callbacks.
  function rebalance(
    TimeswapV2PoolRebalanceParam calldata param
  ) external returns (uint256 long0Amount, uint256 long1Amount, bytes memory data);
}

File 24 of 39 : ITimeswapV2PoolFactory.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

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

/// @title The interface for the contract that deploys Timeswap V2 Pool pair contracts
/// @notice The Timeswap V2 Pool Factory facilitates creation of Timeswap V2 Pool pair.
interface ITimeswapV2PoolFactory is IOwnableTwoSteps {
  /* ===== EVENT ===== */

  /// @dev Emits when a new Timeswap V2 Pool contract is created.
  /// @param caller The address of the caller of create function.
  /// @param option The address of the option contract used by the pool.
  /// @param poolPair The address of the Timeswap V2 Pool contract created.
  event Create(address indexed caller, address indexed option, address indexed poolPair);

  /* ===== VIEW ===== */

  /// @dev Returns the address of the Timeswap V2 Option factory contract utilized by Timeswap V2 Pool factory contract.
  function optionFactory() external view returns (address);

  /// @dev Returns the fixed transaction fee used by all created Timeswap V2 Pool contract.
  function transactionFee() external view returns (uint256);

  /// @dev Returns the fixed protocol fee used by all created Timeswap V2 Pool contract.
  function protocolFee() external view returns (uint256);

  /// @dev Returns the address of a Timeswap V2 Pool.
  /// @dev Returns a zero address if the Timeswap V2 Pool does not exist.
  /// @param option The address of the option contract used by the pool.
  /// @return poolPair The address of the Timeswap V2 Pool contract or a zero address.
  function get(address option) external view returns (address poolPair);

  /// @dev Returns the address of a Timeswap V2 Pool.
  /// @dev Returns a zero address if the Timeswap V2 Pool does not exist.
  /// @param token0 The address of the smaller sized address of ERC20.
  /// @param token1 The address of the larger sized address of ERC20.
  /// @return poolPair The address of the Timeswap V2 Pool contract or a zero address.
  function get(address token0, address token1) external view returns (address poolPair);

  function getByIndex(uint256 id) external view returns (address optionPair);

  function numberOfPairs() external view returns (uint256);

  /* ===== UPDATE ===== */

  /// @dev Creates a Timeswap V2 Pool based on option parameter.
  /// @dev Cannot create a duplicate Timeswap V2 Pool with the same option parameter.
  /// @param token0 The address of the smaller sized address of ERC20.
  /// @param token1 The address of the larger sized address of ERC20.
  /// @param poolPair The address of the Timeswap V2 Pool contract created.
  function create(address token0, address token1) external returns (address poolPair);
}

File 25 of 39 : FeeCalculation.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {Math} from "@timeswap-labs/v2-library/contracts/Math.sol";
import {FullMath} from "@timeswap-labs/v2-library/contracts/FullMath.sol";

import {TimeswapV2OptionPosition} from "@timeswap-labs/v2-option/contracts/enums/Position.sol";

///@title library for fees related calculations
library FeeCalculation {
  using Math for uint256;

  event ReceiveTransactionFees(TimeswapV2OptionPosition position, uint256 fees);

  /// @dev Reverts when fee overflow.
  error FeeOverflow();

  /// @dev reverts to overflow fee.
  function feeOverflow() private pure {
    revert FeeOverflow();
  }

  /// @dev Updates the new fee growth and protocol fee given the current fee growth and protocol fee.
  /// @param position The position to be updated.
  /// @param liquidity The current liquidity in the pool.
  /// @param feeGrowth The current feeGrowth in the pool.
  /// @param protocolFees The current protocolFees in the pool.
  /// @param fees The fees to be earned.
  /// @param protocolFee The protocol fee rate.
  /// @return newFeeGrowth The newly updated fee growth.
  /// @return newProtocolFees The newly updated protocol fees.
  function update(
    TimeswapV2OptionPosition position,
    uint160 liquidity,
    uint256 feeGrowth,
    uint256 protocolFees,
    uint256 fees,
    uint256 protocolFee
  ) internal returns (uint256 newFeeGrowth, uint256 newProtocolFees) {
    uint256 protocolFeesToAdd = getFeesRemoval(fees, protocolFee);
    uint256 transactionFees = fees.unsafeSub(protocolFeesToAdd);

    newFeeGrowth = feeGrowth.unsafeAdd(getFeeGrowth(transactionFees, liquidity));

    newProtocolFees = protocolFees + protocolFeesToAdd;

    emit ReceiveTransactionFees(position, transactionFees);
  }

  /// @dev get the fee given the last fee growth and the global fee growth
  /// @notice returns zero if the last fee growth is equal to the global fee growth
  /// @param liquidity The current liquidity in the pool.
  /// @param lastFeeGrowth The previous global fee growth when owner enters.
  /// @param globalFeeGrowth The current global fee growth.
  function getFees(uint160 liquidity, uint256 lastFeeGrowth, uint256 globalFeeGrowth) internal pure returns (uint256) {
    return
      globalFeeGrowth != lastFeeGrowth
        ? FullMath.mulDiv(liquidity, globalFeeGrowth.unsafeSub(lastFeeGrowth), uint256(1) << 128, false)
        : 0;
  }

  /// @dev Adds the fees to the amount.
  /// @param amount The original amount.
  /// @param fee The transaction fee rate.
  function addFees(uint256 amount, uint256 fee) internal pure returns (uint256) {
    return FullMath.mulDiv(amount, (uint256(1) << 16), (uint256(1) << 16).unsafeSub(fee), true);
  }

  /// @dev Removes the fees from the amount.
  /// @param amount The original amount.
  /// @param fee The transaction fee rate.
  function removeFees(uint256 amount, uint256 fee) internal pure returns (uint256) {
    return FullMath.mulDiv(amount, (uint256(1) << 16).unsafeSub(fee), uint256(1) << 16, false);
  }

  /// @dev Get the fees from an amount with fees.
  /// @param amount The amount with fees.
  /// @param fee The transaction fee rate.
  function getFeesRemoval(uint256 amount, uint256 fee) internal pure returns (uint256) {
    return FullMath.mulDiv(amount, fee, uint256(1) << 16, true);
  }

  /// @dev Get the fees from an amount.
  /// @param amount The amount with fees.
  /// @param fee The transaction fee rate.
  function getFeesAdditional(uint256 amount, uint256 fee) internal pure returns (uint256) {
    return FullMath.mulDiv(amount, fee, (uint256(1) << 16).unsafeSub(fee), true);
  }

  /// @dev Get the fee growth.
  /// @param feeAmount The fee amount.
  /// @param liquidity The current liquidity in the pool.
  function getFeeGrowth(uint256 feeAmount, uint160 liquidity) internal pure returns (uint256) {
    return FullMath.mulDiv(feeAmount, uint256(1) << 128, liquidity, false);
  }
}

File 26 of 39 : PoolFactory.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {OptionFactoryLibrary} from "@timeswap-labs/v2-option/contracts/libraries/OptionFactory.sol";

import {ITimeswapV2PoolFactory} from "../interfaces/ITimeswapV2PoolFactory.sol";

import {Error} from "@timeswap-labs/v2-library/contracts/Error.sol";

/// @title library for calculating poolFactory functions
/// @author Timeswap Labs
library PoolFactoryLibrary {
  using OptionFactoryLibrary for address;

  /// @dev Reverts when pool factory address is zero.
  error ZeroFactoryAddress();

  /// @dev Checks if the pool factory address is zero.
  /// @param poolFactory The pool factory address which is needed to be checked.
  function checkNotZeroFactory(address poolFactory) internal pure {
    if (poolFactory == address(0)) revert ZeroFactoryAddress();
  }

  /// @dev Get the option pair address and pool pair address.
  /// @param optionFactory The option factory contract address.
  /// @param poolFactory The pool factory contract address.
  /// @param token0 The address of the smaller address ERC20 token contract.
  /// @param token1 The address of the larger address ERC20 token contract.
  /// @return optionPair The retrieved option pair address. Zero address if not deployed.
  /// @return poolPair The retrieved pool pair address. Zero address if not deployed.
  function get(
    address optionFactory,
    address poolFactory,
    address token0,
    address token1
  ) internal view returns (address optionPair, address poolPair) {
    optionPair = optionFactory.get(token0, token1);

    poolPair = ITimeswapV2PoolFactory(poolFactory).get(optionPair);
  }

  /// @dev Get the option pair address and pool pair address.
  /// @notice Reverts when the option or the pool is not deployed.
  /// @param optionFactory The option factory contract address.
  /// @param poolFactory The pool factory contract address.
  /// @param token0 The address of the smaller address ERC20 token contract.
  /// @param token1 The address of the larger address ERC20 token contract.
  /// @return optionPair The retrieved option pair address.
  /// @return poolPair The retrieved pool pair address.
  function getWithCheck(
    address optionFactory,
    address poolFactory,
    address token0,
    address token1
  ) internal view returns (address optionPair, address poolPair) {
    optionPair = optionFactory.getWithCheck(token0, token1);

    poolPair = ITimeswapV2PoolFactory(poolFactory).get(optionPair);

    if (poolPair == address(0)) Error.zeroAddress();
  }
}

File 27 of 39 : ReentrancyGuard.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @title library for renentrancy protection
/// @author Timeswap Labs
library ReentrancyGuard {
  /// @dev Reverts when their is a reentrancy to a single option.
  error NoReentrantCall();

  /// @dev Reverts when the option, pool, or token id is not interacted yet.
  error NotInteracted();

  /// @dev The initial state which must be change to NOT_ENTERED when first interacting.
  uint96 internal constant NOT_INTERACTED = 0;

  /// @dev The initial and ending state of balanceTarget in the Option struct.
  uint96 internal constant NOT_ENTERED = 1;

  /// @dev The state where the contract is currently being interacted with.
  uint96 internal constant ENTERED = 2;

  /// @dev Check if there is a reentrancy in an option.
  /// @notice Reverts when balanceTarget is not zero.
  /// @param reentrancyGuard The balance being inquired.
  function check(uint96 reentrancyGuard) internal pure {
    if (reentrancyGuard == NOT_INTERACTED) revert NotInteracted();
    if (reentrancyGuard == ENTERED) revert NoReentrantCall();
  }
}

File 28 of 39 : Param.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {Error} from "@timeswap-labs/v2-library/contracts/Error.sol";

import {TimeswapV2PoolMint, TimeswapV2PoolBurn, TimeswapV2PoolDeleverage, TimeswapV2PoolLeverage, TimeswapV2PoolRebalance, TransactionLibrary} from "../enums/Transaction.sol";

/// @dev The parameter for collectProtocolFees functions.
/// @param strike The strike price of the pool.
/// @param maturity The maturity of the pool.
/// @param long0To The recipient of long0 positions.
/// @param long1To The recipient of long1 positions.
/// @param shortTo The recipient of short positions.
/// @param long0Requested The maximum amount of long0 positions wanted.
/// @param long1Requested The maximum amount of long1 positions wanted.
/// @param shortRequested The maximum amount of short positions wanted.
struct TimeswapV2PoolCollectProtocolFeesParam {
  uint256 strike;
  uint256 maturity;
  address long0To;
  address long1To;
  address shortTo;
  uint256 long0Requested;
  uint256 long1Requested;
  uint256 shortRequested;
}

/// @dev The parameter for collectTransactionFeesAndShortReturned functions.
/// @param strike The strike price of the pool.
/// @param maturity The maturity of the pool.
/// @param long0FeesTo The recipient of long0 fees.
/// @param long1FeesTo The recipient of long1 fees.
/// @param shortFeesTo The recipient of short fees.
/// @param shortReturnedTo The recipient of short returned.
/// @param long0FeesRequested The maximum amount of long0 fees wanted.
/// @param long1FeesRequested The maximum amount of long1 fees wanted.
/// @param shortFeesRequested The maximum amount of short fees wanted.
/// @param shortReturnedRequested The maximum amount of short returned wanted.
struct TimeswapV2PoolCollectTransactionFeesAndShortReturnedParam {
  uint256 strike;
  uint256 maturity;
  address long0FeesTo;
  address long1FeesTo;
  address shortFeesTo;
  address shortReturnedTo;
  uint256 long0FeesRequested;
  uint256 long1FeesRequested;
  uint256 shortFeesRequested;
  uint256 shortReturnedRequested;
}

/// @dev The parameter for mint function.
/// @param strike The strike price of the pool.
/// @param maturity The maturity of the pool.
/// @param to The recipient of liquidity positions.
/// @param transaction The type of mint transaction, more information in Transaction module.
/// @param delta If transaction is GivenLiquidity, the amount of liquidity minted. Note that this value must be uint160.
/// If transaction is GivenLong, the amount of long position in base denomination to be deposited.
/// If transaction is GivenShort, the amount of short position to be deposited.
/// @param data The data to be sent to the function, which will go to the mint choice callback.
struct TimeswapV2PoolMintParam {
  uint256 strike;
  uint256 maturity;
  address to;
  TimeswapV2PoolMint transaction;
  uint256 delta;
  bytes data;
}

/// @dev The parameter for burn function.
/// @param strike The strike price of the pool.
/// @param maturity The maturity of the pool.
/// @param long0To The recipient of long0 positions.
/// @param long1To The recipient of long1 positions.
/// @param shortTo The recipient of short positions.
/// @param transaction The type of burn transaction, more information in Transaction module.
/// @param delta If transaction is GivenLiquidity, the amount of liquidity burnt. Note that this value must be uint160.
/// If transaction is GivenLong, the amount of long position in base denomination to be withdrawn.
/// If transaction is GivenShort, the amount of short position to be withdrawn.
/// @param data The data to be sent to the function, which will go to the burn choice callback.
struct TimeswapV2PoolBurnParam {
  uint256 strike;
  uint256 maturity;
  address long0To;
  address long1To;
  address shortTo;
  TimeswapV2PoolBurn transaction;
  uint256 delta;
  bytes data;
}

/// @dev The parameter for deleverage function.
/// @param strike The strike price of the pool.
/// @param maturity The maturity of the pool.
/// @param to The recipient of short positions.
/// @param transaction The type of deleverage transaction, more information in Transaction module.
/// @param delta If transaction is GivenDeltaSqrtInterestRate, the decrease in square root interest rate.
/// If transaction is GivenLong, the amount of long position in base denomination to be deposited.
/// If transaction is GivenShort, the amount of short position to be withdrawn.
/// If transaction is  GivenSum, the sum amount of long position in base denomination to be deposited, and short position to be withdrawn.
/// @param data The data to be sent to the function, which will go to the deleverage choice callback.
struct TimeswapV2PoolDeleverageParam {
  uint256 strike;
  uint256 maturity;
  address to;
  TimeswapV2PoolDeleverage transaction;
  uint256 delta;
  bytes data;
}

/// @dev The parameter for leverage function.
/// @param strike The strike price of the pool.
/// @param maturity The maturity of the pool.
/// @param long0To The recipient of long0 positions.
/// @param long1To The recipient of long1 positions.
/// @param transaction The type of leverage transaction, more information in Transaction module.
/// @param delta If transaction is GivenDeltaSqrtInterestRate, the increase in square root interest rate.
/// If transaction is GivenLong, the amount of long position in base denomination to be withdrawn.
/// If transaction is GivenShort, the amount of short position to be deposited.
/// If transaction is  GivenSum, the sum amount of long position in base denomination to be withdrawn, and short position to be deposited.
/// @param data The data to be sent to the function, which will go to the leverage choice callback.
struct TimeswapV2PoolLeverageParam {
  uint256 strike;
  uint256 maturity;
  address long0To;
  address long1To;
  TimeswapV2PoolLeverage transaction;
  uint256 delta;
  bytes data;
}

/// @dev The parameter for rebalance function.
/// @param strike The strike price of the pool.
/// @param maturity The maturity of the pool.
/// @param to When Long0ToLong1, the recipient of long1 positions.
/// When Long1ToLong0, the recipient of long0 positions.
/// @param isLong0ToLong1 Long0ToLong1 when true. Long1ToLong0 when false.
/// @param transaction The type of rebalance transaction, more information in Transaction module.
/// @param delta If transaction is GivenLong0 and Long0ToLong1, the amount of long0 positions to be deposited.
/// If transaction is GivenLong0 and Long1ToLong0, the amount of long1 positions to be withdrawn.
/// If transaction is GivenLong1 and Long0ToLong1, the amount of long1 positions to be withdrawn.
/// If transaction is GivenLong1 and Long1ToLong0, the amount of long1 positions to be deposited.
/// @param data The data to be sent to the function, which will go to the rebalance callback.
struct TimeswapV2PoolRebalanceParam {
  uint256 strike;
  uint256 maturity;
  address to;
  bool isLong0ToLong1;
  TimeswapV2PoolRebalance transaction;
  uint256 delta;
  bytes data;
}

library ParamLibrary {
  /// @dev Sanity checks
  /// @param param the parameter for collectProtocolFees transaction.
  function check(TimeswapV2PoolCollectProtocolFeesParam memory param) internal pure {
    if (param.long0To == address(0) || param.long1To == address(0) || param.shortTo == address(0)) Error.zeroAddress();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if ((param.long0Requested == 0 && param.long1Requested == 0 && param.shortRequested == 0) || param.strike == 0)
      Error.zeroInput();
  }

  /// @dev Sanity checks
  /// @param param the parameter for collectTransactionFeesAndShortReturned transaction.
  function check(TimeswapV2PoolCollectTransactionFeesAndShortReturnedParam memory param) internal pure {
    if (
      param.long0FeesTo == address(0) ||
      param.long1FeesTo == address(0) ||
      param.shortFeesTo == address(0) ||
      param.shortReturnedTo == address(0)
    ) Error.zeroAddress();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (
      (param.long0FeesRequested == 0 &&
        param.long1FeesRequested == 0 &&
        param.shortFeesRequested == 0 &&
        param.shortReturnedRequested == 0) || param.strike == 0
    ) Error.zeroInput();
  }

  /// @dev Sanity checks
  /// @param param the parameter for mint transaction.
  /// @param blockTimestamp the current block timestamp.
  function check(TimeswapV2PoolMintParam memory param, uint96 blockTimestamp) internal pure {
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.maturity < blockTimestamp) Error.alreadyMatured(param.maturity, blockTimestamp);
    if (param.to == address(0)) Error.zeroAddress();
    TransactionLibrary.check(param.transaction);
    if (param.delta == 0 || param.strike == 0) Error.zeroInput();
  }

  /// @dev Sanity checks
  /// @param param the parameter for burn transaction.
  /// @param blockTimestamp the current block timestamp.
  function check(TimeswapV2PoolBurnParam memory param, uint96 blockTimestamp) internal pure {
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.maturity < blockTimestamp) Error.alreadyMatured(param.maturity, blockTimestamp);
    if (param.long0To == address(0) || param.long1To == address(0) || param.shortTo == address(0)) Error.zeroAddress();

    TransactionLibrary.check(param.transaction);
    if (param.delta == 0 || param.strike == 0) Error.zeroInput();
  }

  /// @dev Sanity checks
  /// @param param the parameter for deleverage transaction.
  /// @param blockTimestamp the current block timestamp.
  function check(TimeswapV2PoolDeleverageParam memory param, uint96 blockTimestamp) internal pure {
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.maturity < blockTimestamp) Error.alreadyMatured(param.maturity, blockTimestamp);
    if (param.to == address(0)) Error.zeroAddress();
    TransactionLibrary.check(param.transaction);
    if (param.delta == 0 || param.strike == 0) Error.zeroInput();
  }

  /// @dev Sanity checks
  /// @param param the parameter for leverage transaction.
  /// @param blockTimestamp the current block timestamp.
  function check(TimeswapV2PoolLeverageParam memory param, uint96 blockTimestamp) internal pure {
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.maturity < blockTimestamp) Error.alreadyMatured(param.maturity, blockTimestamp);
    if (param.long0To == address(0) || param.long1To == address(0)) Error.zeroAddress();

    TransactionLibrary.check(param.transaction);
    if (param.delta == 0 || param.strike == 0) Error.zeroInput();
  }

  /// @dev Sanity checks
  /// @param param the parameter for rebalance transaction.
  /// @param blockTimestamp the current block timestamp.
  function check(TimeswapV2PoolRebalanceParam memory param, uint96 blockTimestamp) internal pure {
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.maturity < blockTimestamp) Error.alreadyMatured(param.maturity, blockTimestamp);
    if (param.to == address(0)) Error.zeroAddress();
    TransactionLibrary.check(param.transaction);
    if (param.delta == 0 || param.strike == 0) Error.zeroInput();
  }
}

File 29 of 39 : ERC1155Enumerable.sol
// SPDX-License-Identifier: BUSL-1.1
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/ERC721Enumerable.sol)

pragma solidity ^0.8.0;

import {ERC1155} from "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

import {IERC1155Enumerable} from "../interfaces/IERC1155Enumerable.sol";

/// Extension of {ERC1155} that adds
/// enumerability of all the token ids in the contract as well as all token ids owned by each
/// account.
abstract contract ERC1155Enumerable is IERC1155Enumerable, ERC1155 {
  // Mapping from owner to list of owned token IDs
  mapping(address => uint256[]) private _ownedTokens; // An index of all tokens

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

  mapping(uint256 => uint256) private _idTotalSupply;

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

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

  /// @inheritdoc IERC1155Enumerable
  function tokenOfOwnerByIndex(address owner, uint256 index) external view override returns (uint256) {
    return _ownedTokens[owner][index];
  }

  /// @inheritdoc IERC1155Enumerable
  function totalIds() external view override returns (uint256) {
    return _allTokens.length;
  }

  /// @inheritdoc IERC1155Enumerable
  function totalSupply(uint256 id) external view override returns (uint256) {
    return _idTotalSupply[id];
  }

  /// @inheritdoc IERC1155Enumerable
  function tokenByIndex(uint256 index) external view override returns (uint256) {
    return _allTokens[index];
  }

  /// @dev Hook that is called before any token transfer. This includes minting
  /// and burning.
  function _beforeTokenTransfer(
    address,
    address from,
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory
  ) internal virtual override {
    for (uint256 i; i < ids.length; ) {
      if (amounts[i] != 0) _addTokenEnumeration(from, to, ids[i], amounts[i]);

      unchecked {
        ++i;
      }
    }
  }

  /// @dev Add token enumeration list if necessary.
  function _addTokenEnumeration(address from, address to, uint256 id, uint256 amount) internal {
    if (from == address(0)) {
      if (_idTotalSupply[id] == 0 && _additionalConditionAddTokenToAllTokensEnumeration(id))
        _addTokenToAllTokensEnumeration(id);
      _idTotalSupply[id] += amount;
    }

    if (to != address(0) && to != from) {
      if (balanceOf(to, id) == 0 && _additionalConditionAddTokenToOwnerEnumeration(to, id))
        _addTokenToOwnerEnumeration(to, id);
    }
  }

  /// @dev Any additional condition to add token enumeration when overridden.
  function _additionalConditionAddTokenToAllTokensEnumeration(uint256) internal virtual returns (bool) {
    return true;
  }

  /// @dev Any additional condition to add token enumeration when overridden.
  function _additionalConditionAddTokenToOwnerEnumeration(address, uint256) internal virtual returns (bool) {
    return true;
  }

  /// @dev Hook that is called after any token transfer. This includes minting
  /// and burning.
  function _afterTokenTransfer(
    address,
    address from,
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory
  ) internal virtual override {
    for (uint256 i; i < ids.length; ) {
      if (amounts[i] != 0) _removeTokenEnumeration(from, to, ids[i], amounts[i]);

      unchecked {
        ++i;
      }
    }
  }

  /// @dev Remove token enumeration list if necessary.
  function _removeTokenEnumeration(address from, address to, uint256 id, uint256 amount) internal {
    if (to == address(0)) {
      _idTotalSupply[id] -= amount;
      if (_idTotalSupply[id] == 0 && _additionalConditionRemoveTokenFromAllTokensEnumeration(id))
        _removeTokenFromAllTokensEnumeration(id);
    }

    if (from != address(0) && from != to) {
      if (balanceOf(from, id) == 0 && _additionalConditionRemoveTokenFromOwnerEnumeration(from, id))
        _removeTokenFromOwnerEnumeration(from, id);
    }
  }

  /// @dev Any additional condition to remove token enumeration when overridden.
  function _additionalConditionRemoveTokenFromAllTokensEnumeration(uint256) internal virtual returns (bool) {
    return true;
  }

  /// @dev Any additional condition to remove token enumeration when overridden.
  function _additionalConditionRemoveTokenFromOwnerEnumeration(address, uint256) internal virtual returns (bool) {
    return true;
  }

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

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

  /// @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
  /// while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
  /// gas optimizations e.g. when performing a transfer operation (avoiding double writes).
  /// This has O(1) time complexity, but alters the order of the _ownedTokens array.
  /// @param from address representing the previous owner of the given token ID
  /// @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
  function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
    uint256 lastTokenIndex = _ownedTokens[from].length - 1;
    uint256 tokenIndex = _ownedTokensIndex[from][tokenId];

    if (tokenIndex != lastTokenIndex) {
      uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];

      _ownedTokens[from][tokenIndex] = lastTokenId;
      _ownedTokensIndex[from][lastTokenId] = tokenIndex;
    }

    delete _ownedTokensIndex[from][tokenId];
    _ownedTokens[from].pop();
  }

  /// @dev Private function to remove a token from this extension's token tracking data structures.
  /// This has O(1) time complexity, but alters the order of the _allTokens array.
  /// @param tokenId uint256 ID of the token to be removed from the tokens list
  function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
    uint256 lastTokenIndex = _allTokens.length - 1;
    uint256 tokenIndex = _allTokensIndex[tokenId];

    if (tokenIndex != lastTokenIndex) {
      uint256 lastTokenId = _allTokens[lastTokenIndex];

      _allTokens[tokenIndex] = lastTokenId;
      _allTokensIndex[lastTokenId] = tokenIndex;
    }

    delete _allTokensIndex[tokenId];
    _allTokens.pop();
  }
}

File 30 of 39 : ITimeswapV2LiquidityTokenBurnCallback.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {TimeswapV2LiquidityTokenBurnCallbackParam} from "../../structs/CallbackParam.sol";

interface ITimeswapV2LiquidityTokenBurnCallback {
  /// @dev Callback for `ITimeswapV2LiquidityToken.burn`
  function timeswapV2LiquidityTokenBurnCallback(
    TimeswapV2LiquidityTokenBurnCallbackParam calldata param
  ) external returns (bytes memory data);
}

File 31 of 39 : ITimeswapV2LiquidityTokenCollectCallback.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {TimeswapV2LiquidityTokenCollectCallbackParam} from "../../structs/CallbackParam.sol";

interface ITimeswapV2LiquidityTokenCollectCallback {
  /// @dev Callback for `ITimeswapV2LiquidityToken.collect`
  function timeswapV2LiquidityTokenCollectCallback(
    TimeswapV2LiquidityTokenCollectCallbackParam calldata param
  ) external returns (bytes memory data);
}

File 32 of 39 : ITimeswapV2LiquidityTokenMintCallback.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {TimeswapV2LiquidityTokenMintCallbackParam} from "../../structs/CallbackParam.sol";

interface ITimeswapV2LiquidityTokenMintCallback {
  /// @dev Callback for `ITimeswapV2LiquidityToken.mint`
  function timeswapV2LiquidityTokenMintCallback(
    TimeswapV2LiquidityTokenMintCallbackParam calldata param
  ) external returns (bytes memory data);
}

File 33 of 39 : IERC1155Enumerable.sol
// SPDX-License-Identifier: BUSL-1.1
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

/// @title ERC-1155 Token Standard, optional enumeration extension
/// @dev See https://eips.ethereum.org/EIPS/eip-721
interface IERC1155Enumerable is IERC1155 {
  /// @dev Returns the total amount of ids with positive supply stored by the contract.
  function totalIds() external view returns (uint256);

  /// @dev Returns the total supply of a token given its id.
  /// @param id The index of the queried token.
  function totalSupply(uint256 id) external view returns (uint256);

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

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

File 34 of 39 : ITimeswapV2LiquidityToken.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

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

import {TimeswapV2LiquidityTokenPosition} from "../structs/Position.sol";
import {TimeswapV2LiquidityTokenMintParam, TimeswapV2LiquidityTokenBurnParam, TimeswapV2LiquidityTokenCollectParam} from "../structs/Param.sol";

/// @title An interface for TS-V2 liquidity token system
interface ITimeswapV2LiquidityToken is IERC1155Enumerable {
  error NotApprovedToTransferFees();

  /// @dev Returns the option factory address.
  /// @return optionFactory The option factory address.
  function optionFactory() external view returns (address);

  /// @dev Returns the pool factory address.
  /// @return poolFactory The pool factory address.
  function poolFactory() external view returns (address);

  /// @dev Returns the position Balance of the owner
  /// @param owner The owner of the token
  /// @param position The liquidity position
  function positionOf(
    address owner,
    TimeswapV2LiquidityTokenPosition calldata position
  ) external view returns (uint256 amount);

  /// @dev Returns the fee and short returned growth of the pool
  /// @param position The liquidity position
  /// @return long0FeeGrowth The long0 fee growth
  /// @return long1FeeGrowth The long1 fee growth
  /// @return shortFeeGrowth The short fee growth
  /// @return shortReturnedGrowth The short returned growth
  function feesEarnedAndShortReturnedGrowth(
    TimeswapV2LiquidityTokenPosition calldata position
  )
    external
    view
    returns (uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth, uint256 shortReturnedGrowth);

  /// @dev Returns the fee and short returned growth of the pool
  /// @param position The liquidity position
  /// @param durationForward The time duration forward
  /// @return long0FeeGrowth The long0 fee growth
  /// @return long1FeeGrowth The long1 fee growth
  /// @return shortFeeGrowth The short fee growth
  /// @return shortReturnedGrowth The short returned growth
  function feesEarnedAndShortReturnedGrowth(
    TimeswapV2LiquidityTokenPosition calldata position,
    uint96 durationForward
  )
    external
    view
    returns (uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth, uint256 shortReturnedGrowth);

  /// @param owner The address to query the fees earned and short returned of.
  /// @param position The liquidity token position.
  /// @return long0Fees The amount of long0 fees owned by the given address.
  /// @return long1Fees The amount of long1 fees owned by the given address.
  /// @return shortFees The amount of short fees owned by the given address.
  /// @return shortReturned The amount of short returned owned by the given address.
  function feesEarnedAndShortReturnedOf(
    address owner,
    TimeswapV2LiquidityTokenPosition calldata position
  ) external view returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned);

  /// @param owner The address to query the fees earned and short returned of.
  /// @param position The liquidity token position.
  /// @param durationForward The time duration forward
  /// @return long0Fees The amount of long0 fees owned by the given address.
  /// @return long1Fees The amount of long1 fees owned by the given address.
  /// @return shortFees The amount of short fees owned by the given address.
  /// @return shortReturned The amount of short returned owned by the given address.
  function feesEarnedAndShortReturnedOf(
    address owner,
    TimeswapV2LiquidityTokenPosition calldata position,
    uint96 durationForward
  ) external view returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned);

  /// @dev Transfers position token TimeswapV2Token from `from` to `to`
  /// @param from The address to transfer position token from
  /// @param to The address to transfer position token to
  /// @param position The TimeswapV2Token Position to transfer
  /// @param liquidityAmount The amount of TimeswapV2Token Position to transfer
  /// @param erc1155Data Aribtrary custom data for erc1155 transfer
  function transferTokenPositionFrom(
    address from,
    address to,
    TimeswapV2LiquidityTokenPosition calldata position,
    uint160 liquidityAmount,
    bytes calldata erc1155Data
  ) external;

  /// @dev mints TimeswapV2LiquidityToken as per the liqudityAmount
  /// @param param The TimeswapV2LiquidityTokenMintParam
  /// @return data Arbitrary data
  function mint(TimeswapV2LiquidityTokenMintParam calldata param) external returns (bytes memory data);

  /// @dev burns TimeswapV2LiquidityToken as per the liqudityAmount
  /// @param param The TimeswapV2LiquidityTokenBurnParam
  /// @return data Arbitrary data
  function burn(TimeswapV2LiquidityTokenBurnParam calldata param) external returns (bytes memory data);

  /// @dev collects fees as per the fees desired
  /// @param param The TimeswapV2LiquidityTokenBurnParam
  /// @return long0Fees Fees for long0
  /// @return long1Fees Fees for long1
  /// @return shortFees Fees for short
  /// @return shortReturned Short Returned
  function collect(
    TimeswapV2LiquidityTokenCollectParam calldata param
  )
    external
    returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned, bytes memory data);
}

File 35 of 39 : CallbackParam.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

/// @dev parameter for minting Timeswap V2 Tokens
/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param long0Amount The amount of long0 deposited.
/// @param long1Amount The amount of long1 deposited.
/// @param shortAmount The amount of short deposited.
/// @param data Arbitrary data passed to the callback.
struct TimeswapV2TokenMintCallbackParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  uint256 long0Amount;
  uint256 long1Amount;
  uint256 shortAmount;
  bytes data;
}

/// @dev parameter for burning Timeswap V2 Tokens
/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param long0Amount The amount of long0 withdrawn.
/// @param long1Amount The amount of long1 withdrawn.
/// @param shortAmount The amount of short withdrawn.
/// @param data Arbitrary data passed to the callback, initalize as empty if not required.
struct TimeswapV2TokenBurnCallbackParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  uint256 long0Amount;
  uint256 long1Amount;
  uint256 shortAmount;
  bytes data;
}

/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param liquidity The amount of liquidity increase.
/// @param data data
struct TimeswapV2LiquidityTokenMintCallbackParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  uint160 liquidityAmount;
  bytes data;
}

/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param liquidity The amount of liquidity decrease.
/// @param data data
struct TimeswapV2LiquidityTokenBurnCallbackParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  uint160 liquidityAmount;
  bytes data;
}

/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param long0Fees The amount of long0 fees withdrawn.
/// @param long1Fees The amount of long1 fees withdrawn.
/// @param shortFees The amount of short fees withdrawn.
/// @param shortReturned The amount of short returned withdrawn.
/// @param data data
struct TimeswapV2LiquidityTokenCollectCallbackParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  uint256 long0Fees;
  uint256 long1Fees;
  uint256 shortFees;
  uint256 shortReturned;
  bytes data;
}

File 36 of 39 : FeesPosition.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {FeeCalculation} from "@timeswap-labs/v2-pool/contracts/libraries/FeeCalculation.sol";
import {Math} from "@timeswap-labs/v2-library/contracts/Math.sol";

struct FeesPosition {
  uint256 long0FeeGrowth;
  uint256 long1FeeGrowth;
  uint256 shortFeeGrowth;
  uint256 shortReturnedGrowth;
  uint256 long0Fees;
  uint256 long1Fees;
  uint256 shortFees;
  uint256 shortReturned;
}

/// @title library for calulating the fees earned
library FeesPositionLibrary {
  /// @dev returns the fees earned and short returned for a given position, liquidity and respective fee growths
  function feesEarnedAndShortReturnedOf(
    FeesPosition memory feesPosition,
    uint160 liquidity,
    uint256 long0FeeGrowth,
    uint256 long1FeeGrowth,
    uint256 shortFeeGrowth,
    uint256 shortReturnedGrowth
  ) internal pure returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned) {
    long0Fees = feesPosition.long0Fees + FeeCalculation.getFees(liquidity, feesPosition.long0FeeGrowth, long0FeeGrowth);
    long1Fees = feesPosition.long1Fees + FeeCalculation.getFees(liquidity, feesPosition.long1FeeGrowth, long1FeeGrowth);
    shortFees = feesPosition.shortFees + FeeCalculation.getFees(liquidity, feesPosition.shortFeeGrowth, shortFeeGrowth);
    shortReturned =
      feesPosition.shortReturned +
      FeeCalculation.getFees(liquidity, feesPosition.shortReturnedGrowth, shortReturnedGrowth);
  }

  /// @dev update fee for a given position, liquidity and respective feeGrowth
  function update(
    FeesPosition storage feesPosition,
    uint160 liquidity,
    uint256 long0FeeGrowth,
    uint256 long1FeeGrowth,
    uint256 shortFeeGrowth,
    uint256 shortReturnedGrowth
  ) internal {
    if (liquidity != 0) {
      feesPosition.long0Fees += FeeCalculation.getFees(liquidity, feesPosition.long0FeeGrowth, long0FeeGrowth);
      feesPosition.long1Fees += FeeCalculation.getFees(liquidity, feesPosition.long1FeeGrowth, long1FeeGrowth);
      feesPosition.shortFees += FeeCalculation.getFees(liquidity, feesPosition.shortFeeGrowth, shortFeeGrowth);
      feesPosition.shortReturned += FeeCalculation.getFees(
        liquidity,
        feesPosition.shortReturnedGrowth,
        shortReturnedGrowth
      );
    }

    feesPosition.long0FeeGrowth = long0FeeGrowth;
    feesPosition.long1FeeGrowth = long1FeeGrowth;
    feesPosition.shortFeeGrowth = shortFeeGrowth;
    feesPosition.shortReturnedGrowth = shortReturnedGrowth;
  }

  /// @dev get the fees and short returned given the position
  function getFeesAndShortReturned(
    FeesPosition storage feesPosition,
    uint256 long0FeesDesired,
    uint256 long1FeesDesired,
    uint256 shortFeesDesired,
    uint256 shortReturnedDesired
  ) internal view returns (uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint256 shortReturned) {
    long0Fees = Math.min(feesPosition.long0Fees, long0FeesDesired);
    long1Fees = Math.min(feesPosition.long1Fees, long1FeesDesired);
    shortFees = Math.min(feesPosition.shortFees, shortFeesDesired);
    shortReturned = Math.min(feesPosition.shortReturned, shortReturnedDesired);
  }

  /// @dev remove fees and short returned from the position
  function burn(
    FeesPosition storage feesPosition,
    uint256 long0Fees,
    uint256 long1Fees,
    uint256 shortFees,
    uint256 shortReturned
  ) internal {
    feesPosition.long0Fees -= long0Fees;
    feesPosition.long1Fees -= long1Fees;
    feesPosition.shortFees -= shortFees;
    feesPosition.shortReturned -= shortReturned;
  }
}

File 37 of 39 : Param.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {Error} from "@timeswap-labs/v2-library/contracts/Error.sol";

/// @dev parameter for minting Timeswap V2 Tokens
/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param long0To The address of the recipient of TimeswapV2Token representing long0 position.
/// @param long1To The address of the recipient of TimeswapV2Token representing long1 position.
/// @param shortTo The address of the recipient of TimeswapV2Token representing short position.
/// @param long0Amount The amount of long0 deposited.
/// @param long1Amount The amount of long1 deposited.
/// @param shortAmount The amount of short deposited.
/// @param data Arbitrary data passed to the callback.
struct TimeswapV2TokenMintParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  address long0To;
  address long1To;
  address shortTo;
  uint256 long0Amount;
  uint256 long1Amount;
  uint256 shortAmount;
  bytes data;
}

/// @dev parameter for burning Timeswap V2 Tokens
/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param long0To  The address of the recipient of long token0 position.
/// @param long1To The address of the recipient of long token1 position.
/// @param shortTo The address of the recipient of short position.
/// @param long0Amount  The amount of TimeswapV2Token long0  deposited and equivalent long0 position is withdrawn.
/// @param long1Amount The amount of TimeswapV2Token long1 deposited and equivalent long1 position is withdrawn.
/// @param shortAmount The amount of TimeswapV2Token short deposited and equivalent short position is withdrawn,
/// @param data Arbitrary data passed to the callback, initalize as empty if not required.
struct TimeswapV2TokenBurnParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  address long0To;
  address long1To;
  address shortTo;
  uint256 long0Amount;
  uint256 long1Amount;
  uint256 shortAmount;
  bytes data;
}

/// @dev parameter for minting Timeswap V2 Liquidity Tokens
/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param to The address of the recipient of TimeswapV2LiquidityToken.
/// @param liquidityAmount The amount of liquidity token deposited.
/// @param data Arbitrary data passed to the callback.
/// @param erc1155Data Arbitrary custojm data passed through erc115 minting.
struct TimeswapV2LiquidityTokenMintParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  address to;
  uint160 liquidityAmount;
  bytes data;
  bytes erc1155Data;
}

/// @dev parameter for burning Timeswap V2 Liquidity Tokens
/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param to The address of the recipient of the liquidity token.
/// @param liquidityAmount The amount of liquidity token withdrawn.
/// @param data Arbitrary data passed to the callback, initalize as empty if not required.
struct TimeswapV2LiquidityTokenBurnParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  address to;
  uint160 liquidityAmount;
  bytes data;
}

/// @dev parameter for collecting fees and shortReturned from Timeswap V2 Liquidity Tokens
/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param from The address of the owner of the fees and shortReturned;
/// @param long0FeesTo The address of the recipient of the long0 fees.
/// @param long1FeesTo The address of the recipient of the long1 fees.
/// @param shortFeesTo The address of the recipient of the short fees.
/// @param shortReturnedTo The address of the recipient of the short returned.
/// @param long0FeesDesired The maximum amount of long0Fees desired to be withdrawn.
/// @param long1FeesDesired The maximum amount of long1Fees desired to be withdrawn.
/// @param shortFeesDesired The maximum amount of shortFees desired to be withdrawn.
/// @param shortReturnedDesired The maximum amount of shortReturned desired to be withdrawn.
/// @param data Arbitrary data passed to the callback, initalize as empty if not required.
struct TimeswapV2LiquidityTokenCollectParam {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  address from;
  address long0FeesTo;
  address long1FeesTo;
  address shortFeesTo;
  address shortReturnedTo;
  uint256 long0FeesDesired;
  uint256 long1FeesDesired;
  uint256 shortFeesDesired;
  uint256 shortReturnedDesired;
  bytes data;
}

library ParamLibrary {
  /// @dev Sanity checks for token mint.
  function check(TimeswapV2TokenMintParam memory param) internal pure {
    if (param.long0To == address(0) || param.long1To == address(0) || param.shortTo == address(0)) Error.zeroAddress();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.long0Amount == 0 && param.long1Amount == 0 && param.shortAmount == 0) Error.zeroInput();
  }

  /// @dev Sanity checks for token burn.
  function check(TimeswapV2TokenBurnParam memory param) internal pure {
    if (param.long0To == address(0) || param.long1To == address(0) || param.shortTo == address(0)) Error.zeroAddress();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.long0Amount == 0 && param.long1Amount == 0 && param.shortAmount == 0) Error.zeroInput();
  }

  /// @dev Sanity checks for liquidity token mint.
  function check(TimeswapV2LiquidityTokenMintParam memory param) internal pure {
    if (param.to == address(0)) Error.zeroAddress();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.liquidityAmount == 0) Error.zeroInput();
  }

  /// @dev Sanity checks for liquidity token burn.
  function check(TimeswapV2LiquidityTokenBurnParam memory param) internal pure {
    if (param.to == address(0)) Error.zeroAddress();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (param.liquidityAmount == 0) Error.zeroInput();
  }

  /// @dev Sanity checks for liquidity token collect.
  function check(TimeswapV2LiquidityTokenCollectParam memory param) internal pure {
    if (
      param.from == address(0) ||
      param.long0FeesTo == address(0) ||
      param.long1FeesTo == address(0) ||
      param.shortFeesTo == address(0) ||
      param.shortReturnedTo == address(0)
    ) Error.zeroAddress();
    if (param.maturity > type(uint96).max) Error.incorrectMaturity(param.maturity);
    if (
      param.long0FeesDesired == 0 &&
      param.long1FeesDesired == 0 &&
      param.shortFeesDesired == 0 &&
      param.shortReturnedDesired == 0
    ) Error.zeroInput();
  }
}

File 38 of 39 : PoolPosition.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {FeeCalculation} from "@timeswap-labs/v2-pool/contracts/libraries/FeeCalculation.sol";

struct PoolPosition {
  uint256 long0FeeGrowth;
  uint256 long1FeeGrowth;
  uint256 shortFeeGrowth;
  uint256 shortReturnedGrowth;
}

library PoolPositionLibrary {
  /// @dev update fee for a given position, liquidity and respective feeGrowth
  function update(
    PoolPosition storage poolPosition,
    uint160 liquidity,
    uint256 long0Fees,
    uint256 long1Fees,
    uint256 shortFees,
    uint256 shortReturned
  ) internal {
    poolPosition.long0FeeGrowth += FeeCalculation.getFeeGrowth(long0Fees, liquidity);
    poolPosition.long1FeeGrowth += FeeCalculation.getFeeGrowth(long1Fees, liquidity);
    poolPosition.shortFeeGrowth += FeeCalculation.getFeeGrowth(shortFees, liquidity);
    poolPosition.shortReturnedGrowth += FeeCalculation.getFeeGrowth(shortReturned, liquidity);
  }

  function getFeesAndShortReturnedGrowth(
    PoolPosition memory poolPosition,
    uint160 liquidity,
    uint256 long0Fees,
    uint256 long1Fees,
    uint256 shortFees,
    uint256 shortReturned
  )
    internal
    pure
    returns (uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth, uint256 shortReturnedGrowth)
  {
    long0FeeGrowth = poolPosition.long0FeeGrowth + FeeCalculation.getFeeGrowth(long0Fees, liquidity);
    long1FeeGrowth = poolPosition.long1FeeGrowth + FeeCalculation.getFeeGrowth(long1Fees, liquidity);
    shortFeeGrowth = poolPosition.shortFeeGrowth + FeeCalculation.getFeeGrowth(shortFees, liquidity);
    shortReturnedGrowth = poolPosition.shortReturnedGrowth + FeeCalculation.getFeeGrowth(shortReturned, liquidity);
  }
}

File 39 of 39 : Position.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.8;

import {TimeswapV2OptionPosition} from "@timeswap-labs/v2-option/contracts/enums/Position.sol";

/// @dev Struct for Token
/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
/// @param position The position of the option.
struct TimeswapV2TokenPosition {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
  TimeswapV2OptionPosition position;
}

/// @dev Struct for Liquidity Token
/// @param token0 The first ERC20 token address of the pair.
/// @param token1 The second ERC20 token address of the pair.
/// @param strike  The strike ratio of token1 per token0 of the option.
/// @param maturity The maturity of the option.
struct TimeswapV2LiquidityTokenPosition {
  address token0;
  address token1;
  uint256 strike;
  uint256 maturity;
}

library PositionLibrary {
  /// @dev return keccak for key management for Token.
  function toKey(TimeswapV2TokenPosition memory timeswapV2TokenPosition) internal pure returns (bytes32) {
    return keccak256(abi.encode(timeswapV2TokenPosition));
  }

  /// @dev return keccak for key management for Liquidity Token.
  function toKey(
    TimeswapV2LiquidityTokenPosition memory timeswapV2LiquidityTokenPosition
  ) internal pure returns (bytes32) {
    return keccak256(abi.encode(timeswapV2LiquidityTokenPosition));
  }
}

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

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"chosenOptionFactory","type":"address"},{"internalType":"address","name":"chosenPoolFactory","type":"address"},{"internalType":"string","name":"uri","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"maturity","type":"uint256"}],"name":"IncorrectMaturity","type":"error"},{"inputs":[{"internalType":"uint256","name":"multiplicand","type":"uint256"},{"internalType":"uint256","name":"multiplier","type":"uint256"},{"internalType":"uint256","name":"divisor","type":"uint256"}],"name":"MulDivOverflow","type":"error"},{"inputs":[],"name":"NoReentrantCall","type":"error"},{"inputs":[],"name":"NotApprovedToTransferFees","type":"error"},{"inputs":[{"internalType":"uint256","name":"minuend","type":"uint256"},{"internalType":"uint256","name":"subtrahend","type":"uint256"}],"name":"NotEnoughReceived","type":"error"},{"inputs":[],"name":"NotInteracted","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"inputs":[],"name":"ZeroInput","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"strike","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint160","name":"liquidityAmount","type":"uint160"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct TimeswapV2LiquidityTokenBurnParam","name":"param","type":"tuple"}],"name":"burn","outputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"strike","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"long0FeesTo","type":"address"},{"internalType":"address","name":"long1FeesTo","type":"address"},{"internalType":"address","name":"shortFeesTo","type":"address"},{"internalType":"address","name":"shortReturnedTo","type":"address"},{"internalType":"uint256","name":"long0FeesDesired","type":"uint256"},{"internalType":"uint256","name":"long1FeesDesired","type":"uint256"},{"internalType":"uint256","name":"shortFeesDesired","type":"uint256"},{"internalType":"uint256","name":"shortReturnedDesired","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct TimeswapV2LiquidityTokenCollectParam","name":"param","type":"tuple"}],"name":"collect","outputs":[{"internalType":"uint256","name":"long0Fees","type":"uint256"},{"internalType":"uint256","name":"long1Fees","type":"uint256"},{"internalType":"uint256","name":"shortFees","type":"uint256"},{"internalType":"uint256","name":"shortReturned","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"strike","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"}],"internalType":"struct TimeswapV2LiquidityTokenPosition","name":"timeswapV2LiquidityTokenPosition","type":"tuple"}],"name":"feesEarnedAndShortReturnedGrowth","outputs":[{"internalType":"uint256","name":"long0FeeGrowth","type":"uint256"},{"internalType":"uint256","name":"long1FeeGrowth","type":"uint256"},{"internalType":"uint256","name":"shortFeeGrowth","type":"uint256"},{"internalType":"uint256","name":"shortReturnedGrowth","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"strike","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"}],"internalType":"struct TimeswapV2LiquidityTokenPosition","name":"timeswapV2LiquidityTokenPosition","type":"tuple"},{"internalType":"uint96","name":"durationForward","type":"uint96"}],"name":"feesEarnedAndShortReturnedGrowth","outputs":[{"internalType":"uint256","name":"long0FeeGrowth","type":"uint256"},{"internalType":"uint256","name":"long1FeeGrowth","type":"uint256"},{"internalType":"uint256","name":"shortFeeGrowth","type":"uint256"},{"internalType":"uint256","name":"shortReturnedGrowth","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"strike","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"}],"internalType":"struct TimeswapV2LiquidityTokenPosition","name":"timeswapV2LiquidityTokenPosition","type":"tuple"},{"internalType":"uint96","name":"durationForward","type":"uint96"}],"name":"feesEarnedAndShortReturnedOf","outputs":[{"internalType":"uint256","name":"long0Fees","type":"uint256"},{"internalType":"uint256","name":"long1Fees","type":"uint256"},{"internalType":"uint256","name":"shortFees","type":"uint256"},{"internalType":"uint256","name":"shortReturned","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"strike","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"}],"internalType":"struct TimeswapV2LiquidityTokenPosition","name":"timeswapV2LiquidityTokenPosition","type":"tuple"}],"name":"feesEarnedAndShortReturnedOf","outputs":[{"internalType":"uint256","name":"long0Fees","type":"uint256"},{"internalType":"uint256","name":"long1Fees","type":"uint256"},{"internalType":"uint256","name":"shortFees","type":"uint256"},{"internalType":"uint256","name":"shortReturned","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"strike","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint160","name":"liquidityAmount","type":"uint160"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"bytes","name":"erc1155Data","type":"bytes"}],"internalType":"struct TimeswapV2LiquidityTokenMintParam","name":"param","type":"tuple"}],"name":"mint","outputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"optionFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"strike","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"}],"internalType":"struct TimeswapV2LiquidityTokenPosition","name":"timeswapV2LiquidityTokenPosition","type":"tuple"}],"name":"positionOf","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalIds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"components":[{"internalType":"address","name":"token0","type":"address"},{"internalType":"address","name":"token1","type":"address"},{"internalType":"uint256","name":"strike","type":"uint256"},{"internalType":"uint256","name":"maturity","type":"uint256"}],"internalType":"struct TimeswapV2LiquidityTokenPosition","name":"timeswapV2LiquidityTokenPosition","type":"tuple"},{"internalType":"uint160","name":"liquidityAmount","type":"uint160"},{"internalType":"bytes","name":"erc1155Data","type":"bytes"}],"name":"transferTokenPositionFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]

60c06040523480156200001157600080fd5b506040516200500438038062005004833981016040819052620000349162000194565b60408051808201909152601b81527f54696d6573776170205632204c697175696469747920546f6b656e000000000060208201526200007381620000a2565b506001600160601b0319606084811b821660805283901b1660a0526200009981620000a2565b505050620002d5565b8051620000b7906002906020840190620000bb565b5050565b828054620000c99062000298565b90600052602060002090601f016020900481019282620000ed576000855562000138565b82601f106200010857805160ff191683800117855562000138565b8280016001018555821562000138579182015b82811115620001385782518255916020019190600101906200011b565b50620001469291506200014a565b5090565b5b808211156200014657600081556001016200014b565b80516001600160a01b03811681146200017957600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b600080600060608486031215620001aa57600080fd5b620001b58462000161565b92506020620001c681860162000161565b60408601519093506001600160401b0380821115620001e457600080fd5b818701915087601f830112620001f957600080fd5b8151818111156200020e576200020e6200017e565b604051601f8201601f19908116603f011681019083821181831017156200023957620002396200017e565b816040528281528a868487010111156200025257600080fd5b600093505b8284101562000276578484018601518185018701529285019262000257565b82841115620002885760008684830101525b8096505050505050509250925092565b600181811c90821680620002ad57607f821691505b60208210811415620002cf57634e487b7160e01b600052602260045260246000fd5b50919050565b60805160601c60a05160601c614c9a6200036a600039600081816102220152818161062501528181610f93015281816112eb01528181611747015281816119d401528181611d18015261248b01526000818161032a0152818161060401528181610af201528181610f72015281816112ca01528181611726015281816119b301528181611cf701526124690152614c9a6000f3fe608060405234801561001057600080fd5b506004361061014c5760003560e01c8063767de2ff116100c3578063b3461c871161007c578063b3461c8714610325578063bd85b0391461034c578063bf0343f61461036c578063d53693391461037f578063e985e9c514610392578063f242432a146103ce57600080fd5b8063767de2ff146102b35780637680a765146102c65780637ae217fa146102d95780637c229f16146102ec5780637d341b6b146102ff578063a22cb4651461031257600080fd5b80632f745c59116101155780632f745c5914610202578063390a5ba5146102155780634219dc401461021d5780634e1273f41461025c5780634f6ccce71461027c5780635cb39b4b1461028f57600080fd5b8062fdd58e1461015157806301ffc9a7146101775780630e89341c1461019a578063222d5b1e146101ba5780632eb2c2d6146101ed575b600080fd5b61016461015f366004613aa9565b6103e1565b6040519081526020015b60405180910390f35b61018a610185366004613aeb565b610477565b604051901515815260200161016e565b6101ad6101a8366004613b08565b6104c9565b60405161016e9190613b79565b6101cd6101c8366004613ba4565b61055d565b60408051948552602085019390935291830152606082015260800161016e565b6102006101fb366004613d87565b610776565b005b610164610210366004613aa9565b6107c2565b600654610164565b6102447f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161016e565b61026f61026a366004613e34565b6107ff565b60405161016e9190613f3b565b61016461028a366004613b08565b610928565b6102a261029d366004613f4e565b61094f565b60405161016e959493929190613f89565b6101cd6102c1366004613fd6565b610e90565b6101ad6102d436600461401c565b6111a5565b6101cd6102e7366004614057565b611644565b6101ad6102fa36600461408d565b61192f565b6101cd61030d3660046140c7565b611c55565b6102006103203660046140f2565b611e61565b6102447f000000000000000000000000000000000000000000000000000000000000000081565b61016461035a366004613b08565b60009081526005602052604090205490565b61020061037a366004614130565b611e70565b61016461038d366004614057565b611ee8565b61018a6103a03660046141eb565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205460ff1690565b6102006103dc366004614219565b611f1e565b60006001600160a01b0383166104515760405162461bcd60e51b815260206004820152602a60248201527f455243313135353a2061646472657373207a65726f206973206e6f742061207660448201526930b634b21037bbb732b960b11b60648201526084015b60405180910390fd5b506000908152602081815260408083206001600160a01b03949094168352929052205490565b60006001600160e01b03198216636cdb3d1360e11b14806104a857506001600160e01b031982166303a24d0760e21b145b806104c357506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600280546104d890614281565b80601f016020809104026020016040519081016040528092919081815260200182805461050490614281565b80156105515780601f1061052657610100808354040283529160200191610551565b820191906000526020600020905b81548152906001019060200180831161053457829003601f168201915b50505050509050919050565b600080808080600a8161057d610578368a90038a018a6142b6565b611f63565b8152602001908152602001600020549050600d600082815260200190815260200160002054600014156105fd576000818152600b602090815260409182902082516080810184528154808252600183015493820184905260028301549482018590526003909201546060909101819052909750909550909350915061076e565b60006106667f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000061065160208b018b61432a565b61066160408c0160208d0161432a565b611fbd565b6040805163c0d27cc560e01b8152908a0135600482015260608a01356024820152306044820152909250600091508190819081906001600160a01b0386169063c0d27cc59060640160806040518083038186803b1580156106c657600080fd5b505afa1580156106da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106fe9190614347565b60008a8152600d6020908152604080832054600b835292819020815160808101835281548152600182015493810193909352600281015491830191909152600301546060820152949850929650909450925061075e919086868686612072565b929c50909a509850965050505050505b509193509193565b6001600160a01b038516331480610792575061079285336103a0565b6107ae5760405162461bcd60e51b81526004016104489061437d565b6107bb85858585856120ee565b5050505050565b6001600160a01b03821660009081526003602052604081208054839081106107ec576107ec6143cb565b9060005260206000200154905092915050565b606081518351146108645760405162461bcd60e51b815260206004820152602960248201527f455243313135353a206163636f756e747320616e6420696473206c656e677468604482015268040dad2e6dac2e8c6d60bb1b6064820152608401610448565b600083516001600160401b0381111561087f5761087f613bc0565b6040519080825280602002602001820160405280156108a8578160200160208202803683370190505b50905060005b8451811015610920576108f38582815181106108cc576108cc6143cb565b60200260200101518583815181106108e6576108e66143cb565b60200260200101516103e1565b828281518110610905576109056143cb565b6020908102919091010152610919816143f7565b90506108ae565b509392505050565b60006006828154811061093d5761093d6143cb565b90600052602060002001549050919050565b6000808080606061096761096287614412565b6122df565b60408051608081019091526000906109cb908061098760208b018b61432a565b6001600160a01b031681526020018960200160208101906109a8919061432a565b6001600160a01b031681526040808b0135602083015260608b0135910152611f63565b90506109d6816123b8565b6000818152600a6020526040902054336109f660a08a0160808b0161432a565b6001600160a01b03161480610a425750610a42610a1960a08a0160808b0161432a565b6001600160a01b0316600090815260016020908152604080832033845290915290205460ff1690565b610a5f5760405163a411173560e01b815260040160405180910390fd5b610a7c610a7260a08a0160808b0161432a565b60008360006123fa565b610ae18861012001358961014001358a61016001358b6101800135600c600087815260200190815260200160002060008e6080016020810190610abf919061432a565b6001600160a01b03168152602081019190915260400160002093929190612741565b929950909750955093506000610b337f0000000000000000000000000000000000000000000000000000000000000000610b1e60208c018c61432a565b610b2e60408d0160208e0161432a565b612793565b90508715610bba576001600160a01b03811663b2ceca7760408b013560608c0135610b6460c08e0160a08f0161432a565b60008d6040518663ffffffff1660e01b8152600401610b87959493929190614514565b600060405180830381600087803b158015610ba157600080fd5b505af1158015610bb5573d6000803e3d6000fd5b505050505b8615610c3f576001600160a01b03811663b2ceca7760408b013560608c0135610be960e08e0160c08f0161432a565b60018c6040518663ffffffff1660e01b8152600401610c0c959493929190614514565b600060405180830381600087803b158015610c2657600080fd5b505af1158015610c3a573d6000803e3d6000fd5b505050505b610c498587614562565b15610cd7576001600160a01b03811663b2ceca7760408b013560608c0135610c786101008e0160e08f0161432a565b6002610c848b8d614562565b6040518663ffffffff1660e01b8152600401610ca4959493929190614514565b600060405180830381600087803b158015610cbe57600080fd5b505af1158015610cd2573d6000803e3d6000fd5b505050505b610ce56101a08a018a61457a565b159050610e2a576040805161012081019091523390636e3d9ae89080610d0e60208e018e61432a565b6001600160a01b031681526020018c6020016020810190610d2f919061432a565b6001600160a01b031681526020018c6040013581526020018c6060013581526020018b81526020018a81526020018981526020018881526020018c806101a00190610d7a919061457a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509152506040516001600160e01b031960e084901b168152610dd191906004016145c7565b600060405180830381600087803b158015610deb57600080fd5b505af1158015610dff573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610e27919081019061465b565b93505b610e7b88888888600c600088815260200190815260200160002060008f6080016020810190610e59919061432a565b6001600160a01b031681526020810191909152604001600020939291906127b8565b610e8483612829565b50505091939590929450565b600080808080600a81610eab610578368b90038b018b6142b6565b8152602001908152602001600020549050600d60008281526020019081526020016000205460001415610f6b576000818152600c602090815260408083206001600160a01b038c1684528252918290208251610100810184528154815260018201549281019290925260028101549282019290925260038201546060820152600482015460808201819052600583015460a08301819052600684015460c0840181905260079094015460e09093018390529097509550909350915061119b565b6000610fcf7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000610fbf60208c018c61432a565b61066160408d0160208e0161432a565b6040805163de64af9360e01b8152908b0135600482015260608b013560248201523060448201526001600160601b038a1660648201529092506001600160a01b038316915063de64af939060840160806040518083038186803b15801561103557600080fd5b505afa158015611049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061106d9190614347565b6000868152600d6020908152604080832054600b83528184208251608081018452815481526001820154948101949094526002810154928401929092526003909101546060830152959b509399509197509550918291829182916110d4918c8c8c8c612072565b93509350935093506000600c600088815260200190815260200160002060008f6001600160a01b03166001600160a01b031681526020019081526020016000206040518061010001604052908160008201548152602001600182015481526020016002820154815260200160038201548152602001600482015481526020016005820154815260200160068201548152602001600782015481525050905061118a61117f8f896103e1565b82908787878761284a565b929d50909b50995097505050505050505b5093509350935093565b60606111b86111b3836146dc565b6128ce565b6040805160808101909152600090806111d4602086018661432a565b6001600160a01b031681526020018460200160208101906111f5919061432a565b6001600160a01b03168152604080860135602083015260608601359101529050600061122082611f63565b6000818152600a6020526040902054909150806112b157600e60008154611246906143f7565b91829055506000818152600960209081526040808320875181546001600160a01b039182166001600160a01b0319918216178355848a01516001840180549190931691161790558188015160028201556060880151600390910155858352600a909152902081905590505b6112ba82612922565b6112c3826123b8565b60006113277f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000061131760208a018a61432a565b61066160408b0160208c0161432a565b91506000905061133d60c0880160a0890161432a565b6040805163f78333a360e01b8152908901356004820152606089013560248201523060448201526001600160a01b0384169063f78333a39060640160206040518083038186803b15801561139057600080fd5b505afa1580156113a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113c891906147a1565b6113d291906147be565b90506114486113e760a0890160808a0161432a565b846113f860c08b0160a08c0161432a565b6001600160a01b031661140e60e08c018c61457a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061296092505050565b6040805160c08101909152339063bef8f8f5908061146960208c018c61432a565b6001600160a01b031681526020018a602001602081019061148a919061432a565b6001600160a01b031681526020018a6040013581526020018a6060013581526020018a60a00160208101906114bf919061432a565b6001600160a01b031681526020016114da60c08c018c61457a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509152506040516001600160e01b031960e084901b168152611531919060040161483e565b600060405180830381600087803b15801561154b57600080fd5b505af115801561155f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611587919081019061465b565b6040805163f78333a360e01b815290890135600482015260608901356024820152306044820152909650611631906001600160a01b0384169063f78333a39060640160206040518083038186803b1580156115e157600080fd5b505afa1580156115f5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061161991906147a1565b6001600160a01b0316826001600160a01b0316612a92565b61163a84612829565b5050505050919050565b600080808080600a8161165f610578368a90038a018a6142b6565b8152602001908152602001600020549050600d6000828152602001908152602001600020546000141561171f576000818152600c602090815260408083206001600160a01b038b1684528252918290208251610100810184528154815260018201549281019290925260028101549282019290925260038201546060820152600482015460808201819052600583015460a08301819052600684015460c0840181905260079094015460e090930183905290975095509093509150611925565b60006117737f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000061065160208b018b61432a565b6040805163c0d27cc560e01b8152908a0135600482015260608a013560248201523060448201529092506001600160a01b038316915063c0d27cc59060640160806040518083038186803b1580156117ca57600080fd5b505afa1580156117de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118029190614347565b6000868152600d6020908152604080832054600b83528184208251608081018452815481526001820154948101949094526002810154928401929092526003909101546060830152959b50939950919750955091829182918291611869918c8c8c8c612072565b93509350935093506000600c600088815260200190815260200160002060008e6001600160a01b03166001600160a01b031681526020019081526020016000206040518061010001604052908160008201548152602001600182015481526020016002820154815260200160038201548152602001600482015481526020016005820154815260200160068201548152602001600782015481525050905061191461117f8e896103e1565b929d50909b50995097505050505050505b5092959194509250565b606061193d6111b383614851565b60408051608081019091526000906119a1908061195d602087018761432a565b6001600160a01b0316815260200185602001602081019061197e919061432a565b6001600160a01b0316815260408087013560208301526060870135910152611f63565b90506119ac816123b8565b6000611a107f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611a00602088018861432a565b6106616040890160208a0161432a565b9150506001600160a01b03811663c0e0c4c660408601356060870135611a3c60a0890160808a0161432a565b611a4c60c08a0160a08b0161432a565b6040516001600160e01b031960e087901b168152600481019490945260248401929092526001600160a01b039081166044840152166064820152608401600060405180830381600087803b158015611aa357600080fd5b505af1158015611ab7573d6000803e3d6000fd5b50611ac99250505060c085018561457a565b159050611c12576040805160c08101909152339063aef2b3349080611af1602089018961432a565b6001600160a01b03168152602001876020016020810190611b12919061432a565b6001600160a01b0316815260200187604001358152602001876060013581526020018760a0016020810190611b47919061432a565b6001600160a01b03168152602001611b6260c089018961457a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509152506040516001600160e01b031960e084901b168152611bb9919060040161483e565b600060405180830381600087803b158015611bd357600080fd5b505af1158015611be7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611c0f919081019061465b565b92505b6000828152600a6020526040902054611c45903390611c3760c0880160a0890161432a565b6001600160a01b0316612abd565b611c4e82612829565b5050919050565b600080808080600a81611c70610578368b90038b018b6142b6565b8152602001908152602001600020549050600d60008281526020019081526020016000205460001415611cf0576000818152600b6020908152604091829020825160808101845281548082526001830154938201849052600283015494820185905260039092015460609091018190529097509095509093509150611925565b6000611d447f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000610fbf60208c018c61432a565b6040805163de64af9360e01b8152908b0135600482015260608b013560248201523060448201526001600160601b038a166064820152909250600091508190819081906001600160a01b0386169063de64af939060840160806040518083038186803b158015611db357600080fd5b505afa158015611dc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611deb9190614347565b60008a8152600d6020908152604080832054600b8352928190208151608081018352815481526001820154938101939093526002810154918301919091526003015460608201529498509296509094509250611e4b919086868686612072565b929f919e509c50909a5098505050505050505050565b611e6c338383612c57565b5050565b611ee08686600a6000611e8b610578368b90038b018b6142b6565b815260200190815260200160002054866001600160a01b031686868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611f1e92505050565b505050505050565b6000611f1783600a83611f03610578368890038801886142b6565b8152602001908152602001600020546103e1565b9392505050565b6001600160a01b038516331480611f3a5750611f3a85336103a0565b611f565760405162461bcd60e51b81526004016104489061437d565b6107bb8585858585612d38565b6040805182516001600160a01b03908116602080840191909152840151168183015290820151606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b600080611fd46001600160a01b0387168585612793565b6040516330af0bbf60e21b81526001600160a01b0380831660048301529193509086169063c2bc2efc9060240160206040518083038186803b15801561201957600080fd5b505afa15801561202d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061205191906147a1565b90506001600160a01b03811661206957612069612e7e565b94509492505050565b600080600080612082888a612e97565b8a5161208e9190614562565b935061209a878a612e97565b8a602001516120a99190614562565b92506120b5868a612e97565b8a604001516120c49190614562565b91506120d0858a612e97565b8a606001516120df9190614562565b90509650965096509692505050565b81518351146121505760405162461bcd60e51b815260206004820152602860248201527f455243313135353a2069647320616e6420616d6f756e7473206c656e677468206044820152670dad2e6dac2e8c6d60c31b6064820152608401610448565b6001600160a01b0384166121765760405162461bcd60e51b8152600401610448906148ee565b33612185818787878787612eb2565b60005b845181101561226b5760008582815181106121a5576121a56143cb565b6020026020010151905060008583815181106121c3576121c36143cb565b602090810291909101810151600084815280835260408082206001600160a01b038e1683529093529190912054909150818110156122135760405162461bcd60e51b815260040161044890614933565b6000838152602081815260408083206001600160a01b038e8116855292528083208585039055908b16825281208054849290612250908490614562565b9250508190555050505080612264906143f7565b9050612188565b50846001600160a01b0316866001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb87876040516122bb92919061497d565b60405180910390a46122d1818787878787612f33565b611ee0818787878787612fa6565b60808101516001600160a01b03161580612304575060a08101516001600160a01b0316155b8061231a575060c08101516001600160a01b0316155b80612330575060e08101516001600160a01b0316155b8061234757506101008101516001600160a01b0316155b1561235457612354612e7e565b60608101516001600160601b031015612374576123748160600151613111565b61012081015115801561238a5750610140810151155b80156123995750610160810151155b80156123a85750610180810151155b156123b5576123b561312d565b50565b6000818152600860205260409020546123d9906001600160601b0316613146565b600090815260086020526040902080546001600160601b0319166002179055565b826001600160a01b0316846001600160a01b03161461273b576000828152600960209081526040808320815160808101835281546001600160a01b039081168083526001840154909116948201859052600283015493820193909352600390910154606082015292916124b1917f0000000000000000000000000000000000000000000000000000000000000000917f00000000000000000000000000000000000000000000000000000000000000009190611fbd565b915050600080600080846001600160a01b03166382b9008f6040518061014001604052808960400151815260200189606001518152602001306001600160a01b03168152602001306001600160a01b03168152602001306001600160a01b03168152602001306001600160a01b03168152602001428a606001511161253757600061253b565b6000195b8152602001428a6060015111612552576000612556565b6000195b815260200160001981526020016000198152506040518263ffffffff1660e01b815260040161258591906149a2565b608060405180830381600087803b15801561259f57600080fd5b505af11580156125b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125d79190614347565b60008c8152600d6020908152604080832054600b9092529091209498509296509094509250906001600160a01b0382161561261a5761261a818388888888613198565b6001600160a01b038c161561268e576000600c60008c815260200190815260200160002060008e6001600160a01b03166001600160a01b03168152602001908152602001600020905061268c6126708e8d6103e1565b835460018501546002860154600387015486949392919061322b565b505b6001600160a01b038b16156126ce5760008a8152600c602090815260408083206001600160a01b038f16845290915290206126cc6126708d8d6103e1565b505b6001600160a01b038c166127005760008a8152600d6020526040812080548b92906126fa908490614562565b90915550505b6001600160a01b038b166127325760008a8152600d6020526040812080548b929061272c908490614a57565b90915550505b50505050505050505b50505050565b6000806000806127558960040154896132f9565b93506127658960050154886132f9565b92506127758960060154876132f9565b91506127858960070154866132f9565b905095509550955095915050565b60006127a084848461330f565b90506001600160a01b038116611f1757611f17612e7e565b838560040160008282546127cc9190614a57565b92505081905550828560050160008282546127e79190614a57565b92505081905550818560060160008282546128029190614a57565b925050819055508085600701600082825461281d9190614a57565b90915550505050505050565b600090815260086020526040902080546001600160601b0319166001179055565b60008060008061285f898b600001518a61339c565b8a6080015161286e9190614562565b935061287f898b602001518961339c565b8a60a0015161288e9190614562565b925061289f898b604001518861339c565b8a60c001516128ae9190614562565b91506128bf898b606001518761339c565b8a60e001516120df9190614562565b60808101516001600160a01b03166128e8576128e8612e7e565b60608101516001600160601b031015612908576129088160600151613111565b60a08101516001600160a01b03166123b5576123b561312d565b6000818152600860205260409020546001600160601b03166123b557600081815260086020526040902080546001600160601b031916600117905550565b6001600160a01b0384166129c05760405162461bcd60e51b815260206004820152602160248201527f455243313135353a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b6064820152608401610448565b3360006129cc856133c9565b905060006129d9856133c9565b90506129ea83600089858589612eb2565b6000868152602081815260408083206001600160a01b038b16845290915281208054879290612a1a908490614562565b909155505060408051878152602081018790526001600160a01b03808a1692600092918716917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62910160405180910390a4612a7a83600089858589612f33565b612a8983600089898989613414565b50505050505050565b80821015611e6c57604051631c22ff0160e21b81526004810183905260248101829052604401610448565b6001600160a01b038316612b1f5760405162461bcd60e51b815260206004820152602360248201527f455243313135353a206275726e2066726f6d20746865207a65726f206164647260448201526265737360e81b6064820152608401610448565b336000612b2b846133c9565b90506000612b38846133c9565b9050612b5883876000858560405180602001604052806000815250612eb2565b6000858152602081815260408083206001600160a01b038a16845290915290205484811015612bd55760405162461bcd60e51b8152602060048201526024808201527f455243313135353a206275726e20616d6f756e7420657863656564732062616c604482015263616e636560e01b6064820152608401610448565b6000868152602081815260408083206001600160a01b038b81168086529184528285208a8703905582518b81529384018a90529092908816917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62910160405180910390a4612a8984886000868660405180602001604052806000815250612f33565b816001600160a01b0316836001600160a01b03161415612ccb5760405162461bcd60e51b815260206004820152602960248201527f455243313135353a2073657474696e6720617070726f76616c20737461747573604482015268103337b91039b2b63360b91b6064820152608401610448565b6001600160a01b03838116600081815260016020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b038416612d5e5760405162461bcd60e51b8152600401610448906148ee565b336000612d6a856133c9565b90506000612d77856133c9565b9050612d87838989858589612eb2565b6000868152602081815260408083206001600160a01b038c16845290915290205485811015612dc85760405162461bcd60e51b815260040161044890614933565b6000878152602081815260408083206001600160a01b038d8116855292528083208985039055908a16825281208054889290612e05908490614562565b909155505060408051888152602081018890526001600160a01b03808b16928c821692918816917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62910160405180910390a4612e65848a8a86868a612f33565b612e73848a8a8a8a8a613414565b505050505050505050565b60405163d92e233d60e01b815260040160405180910390fd5b6000611f1783600160801b6001600160a01b038516846134de565b612ec08686868686866135da565b60005b8351811015612a8957828181518110612ede57612ede6143cb565b6020026020010151600014612f2b57612f2b8686868481518110612f0457612f046143cb565b6020026020010151868581518110612f1e57612f1e6143cb565b60200260200101516123fa565b600101612ec3565b60005b8351811015612a8957828181518110612f5157612f516143cb565b6020026020010151600014612f9e57612f9e8686868481518110612f7757612f776143cb565b6020026020010151868581518110612f9157612f916143cb565b602002602001015161364d565b600101612f36565b6001600160a01b0384163b15611ee05760405163bc197c8160e01b81526001600160a01b0385169063bc197c8190612fea9089908990889088908890600401614a6e565b602060405180830381600087803b15801561300457600080fd5b505af1925050508015613034575060408051601f3d908101601f1916820190925261303191810190614acc565b60015b6130e157613040614ae9565b806308c379a0141561307a5750613055614b05565b80613060575061307c565b8060405162461bcd60e51b81526004016104489190613b79565b505b60405162461bcd60e51b815260206004820152603460248201527f455243313135353a207472616e7366657220746f206e6f6e2d455243313135356044820152732932b1b2b4bb32b91034b6b83632b6b2b73a32b960611b6064820152608401610448565b6001600160e01b0319811663bc197c8160e01b14612a895760405162461bcd60e51b815260040161044890614b8e565b6040516335f135d360e01b815260048101829052602401610448565b60405163af458c0760e01b815260040160405180910390fd5b6001600160601b03811661316d5760405163e2228b1560e01b815260040160405180910390fd5b6001600160601b038116600214156123b55760405163865a6de560e01b815260040160405180910390fd5b6131a28486612e97565b8660000160008282546131b59190614562565b909155506131c590508386612e97565b8660010160008282546131d89190614562565b909155506131e890508286612e97565b8660020160008282546131fb9190614562565b9091555061320b90508186612e97565b86600301600082825461321e9190614562565b9091555050505050505050565b6001600160a01b038516156132dd576132498587600001548661339c565b86600401600082825461325c9190614562565b925050819055506132728587600101548561339c565b8660050160008282546132859190614562565b9250508190555061329b8587600201548461339c565b8660060160008282546132ae9190614562565b925050819055506132c48587600301548361339c565b8660070160008282546132d79190614562565b90915550505b9285556001850191909155600284015560039092019190915550565b60008183106133085781611f17565b5090919050565b60405163d81e842360e01b81526001600160a01b03838116600483015282811660248301526000919085169063d81e84239060440160206040518083038186803b15801561335c57600080fd5b505afa158015613370573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061339491906147a1565b949350505050565b6000828214156133ad576000613394565b6133946001600160a01b038516848403600160801b60006134de565b60408051600180825281830190925260609160009190602080830190803683370190505090508281600081518110613403576134036143cb565b602090810291909101015292915050565b6001600160a01b0384163b15611ee05760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e61906134589089908990889088908890600401614bd6565b602060405180830381600087803b15801561347257600080fd5b505af19250505080156134a2575060408051601f3d908101601f1916820190925261349f91810190614acc565b60015b6134ae57613040614ae9565b6001600160e01b0319811663f23a6e6160e01b14612a895760405162461bcd60e51b815260040161044890614b8e565b60008060006134ed87876136f9565b91509150806000141561350e57613505828686613718565b92505050613394565b80851161353f5760405163362ced0960e11b8152600481018890526024810187905260448101869052606401610448565b600085878909600087810388169788900497600260038a028118808b02820302808b02820302808b02820302808b02820302808b02820302808b029091030291819003819004600101868411909503948502929095039490940417928302935084905080156135bd575084806135b7576135b7614c10565b86880915155b156135d057826135cc816143f7565b9350505b5050949350505050565b60005b8351811015612a89578281815181106135f8576135f86143cb565b602002602001015160001461364557613645868686848151811061361e5761361e6143cb565b6020026020010151868581518110613638576136386143cb565b6020026020010151613753565b6001016135dd565b6001600160a01b0383166136a65760008281526005602052604081208054839290613679908490614a57565b9091555050600082815260056020526040902054158015613698575060015b156136a6576136a68261387c565b6001600160a01b038416158015906136d05750826001600160a01b0316846001600160a01b031614155b1561273b576136df84836103e1565b1580156136ea575060015b1561273b5761273b8483613938565b6000806000198385098385029250828110838203039150509250929050565b60006137248385614c26565b905081801561373b57506137388385614c3a565b15155b15611f17578061374a816143f7565b95945050505050565b6001600160a01b0384166137ec5760008281526005602052604090205415801561377b575060015b156137c8576137c882600680546000838152600760205260408120829055600182018355919091527ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f0155565b600082815260056020526040812080548392906137e6908490614562565b90915550505b6001600160a01b038316158015906138165750836001600160a01b0316836001600160a01b031614155b1561273b5761382583836103e1565b158015613830575060015b1561273b576001600160a01b038316600090815260036020818152604080842080546004845282862088875284529185208290559282526001810183559183529091200182905561273b565b60065460009061388e90600190614a57565b6000838152600760205260409020549091508082146138fd576000600683815481106138bc576138bc6143cb565b9060005260206000200154905080600683815481106138dd576138dd6143cb565b600091825260208083209091019290925591825260079052604090208190555b600083815260076020526040812055600680548061391d5761391d614c4e565b60019003818190600052602060002001600090559055505050565b6001600160a01b03821660009081526003602052604081205461395d90600190614a57565b6001600160a01b0384166000908152600460209081526040808320868452909152902054909150808214613a2b576001600160a01b03841660009081526003602052604081208054849081106139b5576139b56143cb565b906000526020600020015490508060036000876001600160a01b03166001600160a01b0316815260200190815260200160002083815481106139f9576139f96143cb565b60009182526020808320909101929092556001600160a01b038716815260048252604080822093825292909152208190555b6001600160a01b038416600081815260046020908152604080832087845282528083208390559282526003905220805480613a6857613a68614c4e565b6001900381819060005260206000200160009055905550505050565b6001600160a01b03811681146123b557600080fd5b8035613aa481613a84565b919050565b60008060408385031215613abc57600080fd5b8235613ac781613a84565b946020939093013593505050565b6001600160e01b0319811681146123b557600080fd5b600060208284031215613afd57600080fd5b8135611f1781613ad5565b600060208284031215613b1a57600080fd5b5035919050565b60005b83811015613b3c578181015183820152602001613b24565b8381111561273b5750506000910152565b60008151808452613b65816020860160208601613b21565b601f01601f19169290920160200192915050565b602081526000611f176020830184613b4d565b600060808284031215613b9e57600080fd5b50919050565b600060808284031215613bb657600080fd5b611f178383613b8c565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b0381118282101715613bfb57613bfb613bc0565b6040525050565b6040516101c081016001600160401b0381118282101715613c2557613c25613bc0565b60405290565b60405161010081016001600160401b0381118282101715613c2557613c25613bc0565b60405160e081016001600160401b0381118282101715613c2557613c25613bc0565b60006001600160401b03821115613c8957613c89613bc0565b5060051b60200190565b600082601f830112613ca457600080fd5b81356020613cb182613c70565b604051613cbe8282613bd6565b83815260059390931b8501820192828101915086841115613cde57600080fd5b8286015b84811015613cf95780358352918301918301613ce2565b509695505050505050565b60006001600160401b03821115613d1d57613d1d613bc0565b50601f01601f191660200190565b600082601f830112613d3c57600080fd5b8135613d4781613d04565b604051613d548282613bd6565b828152856020848701011115613d6957600080fd5b82602086016020830137600092810160200192909252509392505050565b600080600080600060a08688031215613d9f57600080fd5b8535613daa81613a84565b94506020860135613dba81613a84565b935060408601356001600160401b0380821115613dd657600080fd5b613de289838a01613c93565b94506060880135915080821115613df857600080fd5b613e0489838a01613c93565b93506080880135915080821115613e1a57600080fd5b50613e2788828901613d2b565b9150509295509295909350565b60008060408385031215613e4757600080fd5b82356001600160401b0380821115613e5e57600080fd5b818501915085601f830112613e7257600080fd5b81356020613e7f82613c70565b604051613e8c8282613bd6565b83815260059390931b8501820192828101915089841115613eac57600080fd5b948201945b83861015613ed3578535613ec481613a84565b82529482019490820190613eb1565b96505086013592505080821115613ee957600080fd5b50613ef685828601613c93565b9150509250929050565b600081518084526020808501945080840160005b83811015613f3057815187529582019590820190600101613f14565b509495945050505050565b602081526000611f176020830184613f00565b600060208284031215613f6057600080fd5b81356001600160401b03811115613f7657600080fd5b82016101c08185031215611f1757600080fd5b85815284602082015283604082015282606082015260a060808201526000613fb460a0830184613b4d565b979650505050505050565b80356001600160601b0381168114613aa457600080fd5b600080600060c08486031215613feb57600080fd5b8335613ff681613a84565b92506140058560208601613b8c565b915061401360a08501613fbf565b90509250925092565b60006020828403121561402e57600080fd5b81356001600160401b0381111561404457600080fd5b82016101008185031215611f1757600080fd5b60008060a0838503121561406a57600080fd5b823561407581613a84565b91506140848460208501613b8c565b90509250929050565b60006020828403121561409f57600080fd5b81356001600160401b038111156140b557600080fd5b820160e08185031215611f1757600080fd5b60008060a083850312156140da57600080fd5b6140e48484613b8c565b915061408460808401613fbf565b6000806040838503121561410557600080fd5b823561411081613a84565b91506020830135801515811461412557600080fd5b809150509250929050565b600080600080600080610100878903121561414a57600080fd5b863561415581613a84565b9550602087013561416581613a84565b94506141748860408901613b8c565b935060c087013561418481613a84565b925060e08701356001600160401b03808211156141a057600080fd5b818901915089601f8301126141b457600080fd5b8135818111156141c357600080fd5b8a60208285010111156141d557600080fd5b6020830194508093505050509295509295509295565b600080604083850312156141fe57600080fd5b823561420981613a84565b9150602083013561412581613a84565b600080600080600060a0868803121561423157600080fd5b853561423c81613a84565b9450602086013561424c81613a84565b9350604086013592506060860135915060808601356001600160401b0381111561427557600080fd5b613e2788828901613d2b565b600181811c9082168061429557607f821691505b60208210811415613b9e57634e487b7160e01b600052602260045260246000fd5b6000608082840312156142c857600080fd5b604051608081018181106001600160401b03821117156142ea576142ea613bc0565b60405282356142f881613a84565b8152602083013561430881613a84565b6020820152604083810135908201526060928301359281019290925250919050565b60006020828403121561433c57600080fd5b8135611f1781613a84565b6000806000806080858703121561435d57600080fd5b505082516020840151604085015160609095015191969095509092509050565b6020808252602e908201527f455243313135353a2063616c6c6572206973206e6f7420746f6b656e206f776e60408201526d195c881bdc88185c1c1c9bdd995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060001982141561440b5761440b6143e1565b5060010190565b60006101c0823603121561442557600080fd5b61442d613c02565b61443683613a99565b815261444460208401613a99565b6020820152604083013560408201526060830135606082015261446960808401613a99565b608082015261447a60a08401613a99565b60a082015261448b60c08401613a99565b60c082015261449c60e08401613a99565b60e08201526101006144af818501613a99565b9082015261012083810135908201526101408084013590820152610160808401359082015261018080840135908201526101a0808401356001600160401b038111156144fa57600080fd5b61450636828701613d2b565b918301919091525092915050565b858152602081018590526001600160a01b038416604082015260a081016003841061454f57634e487b7160e01b600052602160045260246000fd5b6060820193909352608001529392505050565b60008219821115614575576145756143e1565b500190565b6000808335601e1984360301811261459157600080fd5b8301803591506001600160401b038211156145ab57600080fd5b6020019150368190038213156145c057600080fd5b9250929050565b602081526145e16020820183516001600160a01b03169052565b600060208301516145fd60408401826001600160a01b03169052565b506040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e0830151610100818185015280850151915050610120808185015250613394610140840182613b4d565b60006020828403121561466d57600080fd5b81516001600160401b0381111561468357600080fd5b8201601f8101841361469457600080fd5b805161469f81613d04565b6040516146ac8282613bd6565b8281528660208486010111156146c157600080fd5b6146d2836020830160208701613b21565b9695505050505050565b600061010082360312156146ef57600080fd5b6146f7613c2b565b61470083613a99565b815261470e60208401613a99565b6020820152604083013560408201526060830135606082015261473360808401613a99565b608082015261474460a08401613a99565b60a082015260c08301356001600160401b038082111561476357600080fd5b61476f36838701613d2b565b60c084015260e085013591508082111561478857600080fd5b5061479536828601613d2b565b60e08301525092915050565b6000602082840312156147b357600080fd5b8151611f1781613a84565b60006001600160a01b038281168482168083038211156147e0576147e06143e1565b01949350505050565b600060018060a01b0380835116845280602084015116602085015260408301516040850152606083015160608501528060808401511660808501525060a082015160c060a085015261339460c0850182613b4d565b602081526000611f1760208301846147e9565b600060e0823603121561486357600080fd5b61486b613c4e565b61487483613a99565b815261488260208401613a99565b602082015260408301356040820152606083013560608201526148a760808401613a99565b60808201526148b860a08401613a99565b60a082015260c08301356001600160401b038111156148d657600080fd5b6148e236828601613d2b565b60c08301525092915050565b60208082526025908201527f455243313135353a207472616e7366657220746f20746865207a65726f206164604082015264647265737360d81b606082015260800190565b6020808252602a908201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60408201526939103a3930b739b332b960b11b606082015260800190565b6040815260006149906040830185613f00565b828103602084015261374a8185613f00565b600061014082019050825182526020830151602083015260408301516149d360408401826001600160a01b03169052565b5060608301516149ee60608401826001600160a01b03169052565b506080830151614a0960808401826001600160a01b03169052565b5060a0830151614a2460a08401826001600160a01b03169052565b5060c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525092915050565b600082821015614a6957614a696143e1565b500390565b6001600160a01b0386811682528516602082015260a060408201819052600090614a9a90830186613f00565b8281036060840152614aac8186613f00565b90508281036080840152614ac08185613b4d565b98975050505050505050565b600060208284031215614ade57600080fd5b8151611f1781613ad5565b600060033d1115614b025760046000803e5060005160e01c5b90565b600060443d1015614b135790565b6040516003193d81016004833e81513d6001600160401b038160248401118184111715614b4257505050505090565b8285019150815181811115614b5a5750505050505090565b843d8701016020828501011115614b745750505050505090565b614b8360208286010187613bd6565b509095945050505050565b60208082526028908201527f455243313135353a204552433131353552656365697665722072656a656374656040820152676420746f6b656e7360c01b606082015260800190565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090613fb490830184613b4d565b634e487b7160e01b600052601260045260246000fd5b600082614c3557614c35614c10565b500490565b600082614c4957614c49614c10565b500690565b634e487b7160e01b600052603160045260246000fdfea2646970667358221220cd01625efe0843efd50c5551683211298b88c6b64b9b1708aa53fc5af2c2a13264736f6c6343000808003300000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c400000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061014c5760003560e01c8063767de2ff116100c3578063b3461c871161007c578063b3461c8714610325578063bd85b0391461034c578063bf0343f61461036c578063d53693391461037f578063e985e9c514610392578063f242432a146103ce57600080fd5b8063767de2ff146102b35780637680a765146102c65780637ae217fa146102d95780637c229f16146102ec5780637d341b6b146102ff578063a22cb4651461031257600080fd5b80632f745c59116101155780632f745c5914610202578063390a5ba5146102155780634219dc401461021d5780634e1273f41461025c5780634f6ccce71461027c5780635cb39b4b1461028f57600080fd5b8062fdd58e1461015157806301ffc9a7146101775780630e89341c1461019a578063222d5b1e146101ba5780632eb2c2d6146101ed575b600080fd5b61016461015f366004613aa9565b6103e1565b6040519081526020015b60405180910390f35b61018a610185366004613aeb565b610477565b604051901515815260200161016e565b6101ad6101a8366004613b08565b6104c9565b60405161016e9190613b79565b6101cd6101c8366004613ba4565b61055d565b60408051948552602085019390935291830152606082015260800161016e565b6102006101fb366004613d87565b610776565b005b610164610210366004613aa9565b6107c2565b600654610164565b6102447f00000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c81565b6040516001600160a01b03909116815260200161016e565b61026f61026a366004613e34565b6107ff565b60405161016e9190613f3b565b61016461028a366004613b08565b610928565b6102a261029d366004613f4e565b61094f565b60405161016e959493929190613f89565b6101cd6102c1366004613fd6565b610e90565b6101ad6102d436600461401c565b6111a5565b6101cd6102e7366004614057565b611644565b6101ad6102fa36600461408d565b61192f565b6101cd61030d3660046140c7565b611c55565b6102006103203660046140f2565b611e61565b6102447f00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c481565b61016461035a366004613b08565b60009081526005602052604090205490565b61020061037a366004614130565b611e70565b61016461038d366004614057565b611ee8565b61018a6103a03660046141eb565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205460ff1690565b6102006103dc366004614219565b611f1e565b60006001600160a01b0383166104515760405162461bcd60e51b815260206004820152602a60248201527f455243313135353a2061646472657373207a65726f206973206e6f742061207660448201526930b634b21037bbb732b960b11b60648201526084015b60405180910390fd5b506000908152602081815260408083206001600160a01b03949094168352929052205490565b60006001600160e01b03198216636cdb3d1360e11b14806104a857506001600160e01b031982166303a24d0760e21b145b806104c357506301ffc9a760e01b6001600160e01b03198316145b92915050565b6060600280546104d890614281565b80601f016020809104026020016040519081016040528092919081815260200182805461050490614281565b80156105515780601f1061052657610100808354040283529160200191610551565b820191906000526020600020905b81548152906001019060200180831161053457829003601f168201915b50505050509050919050565b600080808080600a8161057d610578368a90038a018a6142b6565b611f63565b8152602001908152602001600020549050600d600082815260200190815260200160002054600014156105fd576000818152600b602090815260409182902082516080810184528154808252600183015493820184905260028301549482018590526003909201546060909101819052909750909550909350915061076e565b60006106667f00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c47f00000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c61065160208b018b61432a565b61066160408c0160208d0161432a565b611fbd565b6040805163c0d27cc560e01b8152908a0135600482015260608a01356024820152306044820152909250600091508190819081906001600160a01b0386169063c0d27cc59060640160806040518083038186803b1580156106c657600080fd5b505afa1580156106da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106fe9190614347565b60008a8152600d6020908152604080832054600b835292819020815160808101835281548152600182015493810193909352600281015491830191909152600301546060820152949850929650909450925061075e919086868686612072565b929c50909a509850965050505050505b509193509193565b6001600160a01b038516331480610792575061079285336103a0565b6107ae5760405162461bcd60e51b81526004016104489061437d565b6107bb85858585856120ee565b5050505050565b6001600160a01b03821660009081526003602052604081208054839081106107ec576107ec6143cb565b9060005260206000200154905092915050565b606081518351146108645760405162461bcd60e51b815260206004820152602960248201527f455243313135353a206163636f756e747320616e6420696473206c656e677468604482015268040dad2e6dac2e8c6d60bb1b6064820152608401610448565b600083516001600160401b0381111561087f5761087f613bc0565b6040519080825280602002602001820160405280156108a8578160200160208202803683370190505b50905060005b8451811015610920576108f38582815181106108cc576108cc6143cb565b60200260200101518583815181106108e6576108e66143cb565b60200260200101516103e1565b828281518110610905576109056143cb565b6020908102919091010152610919816143f7565b90506108ae565b509392505050565b60006006828154811061093d5761093d6143cb565b90600052602060002001549050919050565b6000808080606061096761096287614412565b6122df565b60408051608081019091526000906109cb908061098760208b018b61432a565b6001600160a01b031681526020018960200160208101906109a8919061432a565b6001600160a01b031681526040808b0135602083015260608b0135910152611f63565b90506109d6816123b8565b6000818152600a6020526040902054336109f660a08a0160808b0161432a565b6001600160a01b03161480610a425750610a42610a1960a08a0160808b0161432a565b6001600160a01b0316600090815260016020908152604080832033845290915290205460ff1690565b610a5f5760405163a411173560e01b815260040160405180910390fd5b610a7c610a7260a08a0160808b0161432a565b60008360006123fa565b610ae18861012001358961014001358a61016001358b6101800135600c600087815260200190815260200160002060008e6080016020810190610abf919061432a565b6001600160a01b03168152602081019190915260400160002093929190612741565b929950909750955093506000610b337f00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c4610b1e60208c018c61432a565b610b2e60408d0160208e0161432a565b612793565b90508715610bba576001600160a01b03811663b2ceca7760408b013560608c0135610b6460c08e0160a08f0161432a565b60008d6040518663ffffffff1660e01b8152600401610b87959493929190614514565b600060405180830381600087803b158015610ba157600080fd5b505af1158015610bb5573d6000803e3d6000fd5b505050505b8615610c3f576001600160a01b03811663b2ceca7760408b013560608c0135610be960e08e0160c08f0161432a565b60018c6040518663ffffffff1660e01b8152600401610c0c959493929190614514565b600060405180830381600087803b158015610c2657600080fd5b505af1158015610c3a573d6000803e3d6000fd5b505050505b610c498587614562565b15610cd7576001600160a01b03811663b2ceca7760408b013560608c0135610c786101008e0160e08f0161432a565b6002610c848b8d614562565b6040518663ffffffff1660e01b8152600401610ca4959493929190614514565b600060405180830381600087803b158015610cbe57600080fd5b505af1158015610cd2573d6000803e3d6000fd5b505050505b610ce56101a08a018a61457a565b159050610e2a576040805161012081019091523390636e3d9ae89080610d0e60208e018e61432a565b6001600160a01b031681526020018c6020016020810190610d2f919061432a565b6001600160a01b031681526020018c6040013581526020018c6060013581526020018b81526020018a81526020018981526020018881526020018c806101a00190610d7a919061457a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509152506040516001600160e01b031960e084901b168152610dd191906004016145c7565b600060405180830381600087803b158015610deb57600080fd5b505af1158015610dff573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610e27919081019061465b565b93505b610e7b88888888600c600088815260200190815260200160002060008f6080016020810190610e59919061432a565b6001600160a01b031681526020810191909152604001600020939291906127b8565b610e8483612829565b50505091939590929450565b600080808080600a81610eab610578368b90038b018b6142b6565b8152602001908152602001600020549050600d60008281526020019081526020016000205460001415610f6b576000818152600c602090815260408083206001600160a01b038c1684528252918290208251610100810184528154815260018201549281019290925260028101549282019290925260038201546060820152600482015460808201819052600583015460a08301819052600684015460c0840181905260079094015460e09093018390529097509550909350915061119b565b6000610fcf7f00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c47f00000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c610fbf60208c018c61432a565b61066160408d0160208e0161432a565b6040805163de64af9360e01b8152908b0135600482015260608b013560248201523060448201526001600160601b038a1660648201529092506001600160a01b038316915063de64af939060840160806040518083038186803b15801561103557600080fd5b505afa158015611049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061106d9190614347565b6000868152600d6020908152604080832054600b83528184208251608081018452815481526001820154948101949094526002810154928401929092526003909101546060830152959b509399509197509550918291829182916110d4918c8c8c8c612072565b93509350935093506000600c600088815260200190815260200160002060008f6001600160a01b03166001600160a01b031681526020019081526020016000206040518061010001604052908160008201548152602001600182015481526020016002820154815260200160038201548152602001600482015481526020016005820154815260200160068201548152602001600782015481525050905061118a61117f8f896103e1565b82908787878761284a565b929d50909b50995097505050505050505b5093509350935093565b60606111b86111b3836146dc565b6128ce565b6040805160808101909152600090806111d4602086018661432a565b6001600160a01b031681526020018460200160208101906111f5919061432a565b6001600160a01b03168152604080860135602083015260608601359101529050600061122082611f63565b6000818152600a6020526040902054909150806112b157600e60008154611246906143f7565b91829055506000818152600960209081526040808320875181546001600160a01b039182166001600160a01b0319918216178355848a01516001840180549190931691161790558188015160028201556060880151600390910155858352600a909152902081905590505b6112ba82612922565b6112c3826123b8565b60006113277f00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c47f00000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c61131760208a018a61432a565b61066160408b0160208c0161432a565b91506000905061133d60c0880160a0890161432a565b6040805163f78333a360e01b8152908901356004820152606089013560248201523060448201526001600160a01b0384169063f78333a39060640160206040518083038186803b15801561139057600080fd5b505afa1580156113a4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113c891906147a1565b6113d291906147be565b90506114486113e760a0890160808a0161432a565b846113f860c08b0160a08c0161432a565b6001600160a01b031661140e60e08c018c61457a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061296092505050565b6040805160c08101909152339063bef8f8f5908061146960208c018c61432a565b6001600160a01b031681526020018a602001602081019061148a919061432a565b6001600160a01b031681526020018a6040013581526020018a6060013581526020018a60a00160208101906114bf919061432a565b6001600160a01b031681526020016114da60c08c018c61457a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509152506040516001600160e01b031960e084901b168152611531919060040161483e565b600060405180830381600087803b15801561154b57600080fd5b505af115801561155f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611587919081019061465b565b6040805163f78333a360e01b815290890135600482015260608901356024820152306044820152909650611631906001600160a01b0384169063f78333a39060640160206040518083038186803b1580156115e157600080fd5b505afa1580156115f5573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061161991906147a1565b6001600160a01b0316826001600160a01b0316612a92565b61163a84612829565b5050505050919050565b600080808080600a8161165f610578368a90038a018a6142b6565b8152602001908152602001600020549050600d6000828152602001908152602001600020546000141561171f576000818152600c602090815260408083206001600160a01b038b1684528252918290208251610100810184528154815260018201549281019290925260028101549282019290925260038201546060820152600482015460808201819052600583015460a08301819052600684015460c0840181905260079094015460e090930183905290975095509093509150611925565b60006117737f00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c47f00000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c61065160208b018b61432a565b6040805163c0d27cc560e01b8152908a0135600482015260608a013560248201523060448201529092506001600160a01b038316915063c0d27cc59060640160806040518083038186803b1580156117ca57600080fd5b505afa1580156117de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118029190614347565b6000868152600d6020908152604080832054600b83528184208251608081018452815481526001820154948101949094526002810154928401929092526003909101546060830152959b50939950919750955091829182918291611869918c8c8c8c612072565b93509350935093506000600c600088815260200190815260200160002060008e6001600160a01b03166001600160a01b031681526020019081526020016000206040518061010001604052908160008201548152602001600182015481526020016002820154815260200160038201548152602001600482015481526020016005820154815260200160068201548152602001600782015481525050905061191461117f8e896103e1565b929d50909b50995097505050505050505b5092959194509250565b606061193d6111b383614851565b60408051608081019091526000906119a1908061195d602087018761432a565b6001600160a01b0316815260200185602001602081019061197e919061432a565b6001600160a01b0316815260408087013560208301526060870135910152611f63565b90506119ac816123b8565b6000611a107f00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c47f00000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c611a00602088018861432a565b6106616040890160208a0161432a565b9150506001600160a01b03811663c0e0c4c660408601356060870135611a3c60a0890160808a0161432a565b611a4c60c08a0160a08b0161432a565b6040516001600160e01b031960e087901b168152600481019490945260248401929092526001600160a01b039081166044840152166064820152608401600060405180830381600087803b158015611aa357600080fd5b505af1158015611ab7573d6000803e3d6000fd5b50611ac99250505060c085018561457a565b159050611c12576040805160c08101909152339063aef2b3349080611af1602089018961432a565b6001600160a01b03168152602001876020016020810190611b12919061432a565b6001600160a01b0316815260200187604001358152602001876060013581526020018760a0016020810190611b47919061432a565b6001600160a01b03168152602001611b6260c089018961457a565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050509152506040516001600160e01b031960e084901b168152611bb9919060040161483e565b600060405180830381600087803b158015611bd357600080fd5b505af1158015611be7573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611c0f919081019061465b565b92505b6000828152600a6020526040902054611c45903390611c3760c0880160a0890161432a565b6001600160a01b0316612abd565b611c4e82612829565b5050919050565b600080808080600a81611c70610578368b90038b018b6142b6565b8152602001908152602001600020549050600d60008281526020019081526020016000205460001415611cf0576000818152600b6020908152604091829020825160808101845281548082526001830154938201849052600283015494820185905260039092015460609091018190529097509095509093509150611925565b6000611d447f00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c47f00000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c610fbf60208c018c61432a565b6040805163de64af9360e01b8152908b0135600482015260608b013560248201523060448201526001600160601b038a166064820152909250600091508190819081906001600160a01b0386169063de64af939060840160806040518083038186803b158015611db357600080fd5b505afa158015611dc7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611deb9190614347565b60008a8152600d6020908152604080832054600b8352928190208151608081018352815481526001820154938101939093526002810154918301919091526003015460608201529498509296509094509250611e4b919086868686612072565b929f919e509c50909a5098505050505050505050565b611e6c338383612c57565b5050565b611ee08686600a6000611e8b610578368b90038b018b6142b6565b815260200190815260200160002054866001600160a01b031686868080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250611f1e92505050565b505050505050565b6000611f1783600a83611f03610578368890038801886142b6565b8152602001908152602001600020546103e1565b9392505050565b6001600160a01b038516331480611f3a5750611f3a85336103a0565b611f565760405162461bcd60e51b81526004016104489061437d565b6107bb8585858585612d38565b6040805182516001600160a01b03908116602080840191909152840151168183015290820151606080830191909152820151608082015260009060a001604051602081830303815290604052805190602001209050919050565b600080611fd46001600160a01b0387168585612793565b6040516330af0bbf60e21b81526001600160a01b0380831660048301529193509086169063c2bc2efc9060240160206040518083038186803b15801561201957600080fd5b505afa15801561202d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061205191906147a1565b90506001600160a01b03811661206957612069612e7e565b94509492505050565b600080600080612082888a612e97565b8a5161208e9190614562565b935061209a878a612e97565b8a602001516120a99190614562565b92506120b5868a612e97565b8a604001516120c49190614562565b91506120d0858a612e97565b8a606001516120df9190614562565b90509650965096509692505050565b81518351146121505760405162461bcd60e51b815260206004820152602860248201527f455243313135353a2069647320616e6420616d6f756e7473206c656e677468206044820152670dad2e6dac2e8c6d60c31b6064820152608401610448565b6001600160a01b0384166121765760405162461bcd60e51b8152600401610448906148ee565b33612185818787878787612eb2565b60005b845181101561226b5760008582815181106121a5576121a56143cb565b6020026020010151905060008583815181106121c3576121c36143cb565b602090810291909101810151600084815280835260408082206001600160a01b038e1683529093529190912054909150818110156122135760405162461bcd60e51b815260040161044890614933565b6000838152602081815260408083206001600160a01b038e8116855292528083208585039055908b16825281208054849290612250908490614562565b9250508190555050505080612264906143f7565b9050612188565b50846001600160a01b0316866001600160a01b0316826001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb87876040516122bb92919061497d565b60405180910390a46122d1818787878787612f33565b611ee0818787878787612fa6565b60808101516001600160a01b03161580612304575060a08101516001600160a01b0316155b8061231a575060c08101516001600160a01b0316155b80612330575060e08101516001600160a01b0316155b8061234757506101008101516001600160a01b0316155b1561235457612354612e7e565b60608101516001600160601b031015612374576123748160600151613111565b61012081015115801561238a5750610140810151155b80156123995750610160810151155b80156123a85750610180810151155b156123b5576123b561312d565b50565b6000818152600860205260409020546123d9906001600160601b0316613146565b600090815260086020526040902080546001600160601b0319166002179055565b826001600160a01b0316846001600160a01b03161461273b576000828152600960209081526040808320815160808101835281546001600160a01b039081168083526001840154909116948201859052600283015493820193909352600390910154606082015292916124b1917f00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c4917f00000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c9190611fbd565b915050600080600080846001600160a01b03166382b9008f6040518061014001604052808960400151815260200189606001518152602001306001600160a01b03168152602001306001600160a01b03168152602001306001600160a01b03168152602001306001600160a01b03168152602001428a606001511161253757600061253b565b6000195b8152602001428a6060015111612552576000612556565b6000195b815260200160001981526020016000198152506040518263ffffffff1660e01b815260040161258591906149a2565b608060405180830381600087803b15801561259f57600080fd5b505af11580156125b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125d79190614347565b60008c8152600d6020908152604080832054600b9092529091209498509296509094509250906001600160a01b0382161561261a5761261a818388888888613198565b6001600160a01b038c161561268e576000600c60008c815260200190815260200160002060008e6001600160a01b03166001600160a01b03168152602001908152602001600020905061268c6126708e8d6103e1565b835460018501546002860154600387015486949392919061322b565b505b6001600160a01b038b16156126ce5760008a8152600c602090815260408083206001600160a01b038f16845290915290206126cc6126708d8d6103e1565b505b6001600160a01b038c166127005760008a8152600d6020526040812080548b92906126fa908490614562565b90915550505b6001600160a01b038b166127325760008a8152600d6020526040812080548b929061272c908490614a57565b90915550505b50505050505050505b50505050565b6000806000806127558960040154896132f9565b93506127658960050154886132f9565b92506127758960060154876132f9565b91506127858960070154866132f9565b905095509550955095915050565b60006127a084848461330f565b90506001600160a01b038116611f1757611f17612e7e565b838560040160008282546127cc9190614a57565b92505081905550828560050160008282546127e79190614a57565b92505081905550818560060160008282546128029190614a57565b925050819055508085600701600082825461281d9190614a57565b90915550505050505050565b600090815260086020526040902080546001600160601b0319166001179055565b60008060008061285f898b600001518a61339c565b8a6080015161286e9190614562565b935061287f898b602001518961339c565b8a60a0015161288e9190614562565b925061289f898b604001518861339c565b8a60c001516128ae9190614562565b91506128bf898b606001518761339c565b8a60e001516120df9190614562565b60808101516001600160a01b03166128e8576128e8612e7e565b60608101516001600160601b031015612908576129088160600151613111565b60a08101516001600160a01b03166123b5576123b561312d565b6000818152600860205260409020546001600160601b03166123b557600081815260086020526040902080546001600160601b031916600117905550565b6001600160a01b0384166129c05760405162461bcd60e51b815260206004820152602160248201527f455243313135353a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b6064820152608401610448565b3360006129cc856133c9565b905060006129d9856133c9565b90506129ea83600089858589612eb2565b6000868152602081815260408083206001600160a01b038b16845290915281208054879290612a1a908490614562565b909155505060408051878152602081018790526001600160a01b03808a1692600092918716917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62910160405180910390a4612a7a83600089858589612f33565b612a8983600089898989613414565b50505050505050565b80821015611e6c57604051631c22ff0160e21b81526004810183905260248101829052604401610448565b6001600160a01b038316612b1f5760405162461bcd60e51b815260206004820152602360248201527f455243313135353a206275726e2066726f6d20746865207a65726f206164647260448201526265737360e81b6064820152608401610448565b336000612b2b846133c9565b90506000612b38846133c9565b9050612b5883876000858560405180602001604052806000815250612eb2565b6000858152602081815260408083206001600160a01b038a16845290915290205484811015612bd55760405162461bcd60e51b8152602060048201526024808201527f455243313135353a206275726e20616d6f756e7420657863656564732062616c604482015263616e636560e01b6064820152608401610448565b6000868152602081815260408083206001600160a01b038b81168086529184528285208a8703905582518b81529384018a90529092908816917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62910160405180910390a4612a8984886000868660405180602001604052806000815250612f33565b816001600160a01b0316836001600160a01b03161415612ccb5760405162461bcd60e51b815260206004820152602960248201527f455243313135353a2073657474696e6720617070726f76616c20737461747573604482015268103337b91039b2b63360b91b6064820152608401610448565b6001600160a01b03838116600081815260016020908152604080832094871680845294825291829020805460ff191686151590811790915591519182527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a3505050565b6001600160a01b038416612d5e5760405162461bcd60e51b8152600401610448906148ee565b336000612d6a856133c9565b90506000612d77856133c9565b9050612d87838989858589612eb2565b6000868152602081815260408083206001600160a01b038c16845290915290205485811015612dc85760405162461bcd60e51b815260040161044890614933565b6000878152602081815260408083206001600160a01b038d8116855292528083208985039055908a16825281208054889290612e05908490614562565b909155505060408051888152602081018890526001600160a01b03808b16928c821692918816917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62910160405180910390a4612e65848a8a86868a612f33565b612e73848a8a8a8a8a613414565b505050505050505050565b60405163d92e233d60e01b815260040160405180910390fd5b6000611f1783600160801b6001600160a01b038516846134de565b612ec08686868686866135da565b60005b8351811015612a8957828181518110612ede57612ede6143cb565b6020026020010151600014612f2b57612f2b8686868481518110612f0457612f046143cb565b6020026020010151868581518110612f1e57612f1e6143cb565b60200260200101516123fa565b600101612ec3565b60005b8351811015612a8957828181518110612f5157612f516143cb565b6020026020010151600014612f9e57612f9e8686868481518110612f7757612f776143cb565b6020026020010151868581518110612f9157612f916143cb565b602002602001015161364d565b600101612f36565b6001600160a01b0384163b15611ee05760405163bc197c8160e01b81526001600160a01b0385169063bc197c8190612fea9089908990889088908890600401614a6e565b602060405180830381600087803b15801561300457600080fd5b505af1925050508015613034575060408051601f3d908101601f1916820190925261303191810190614acc565b60015b6130e157613040614ae9565b806308c379a0141561307a5750613055614b05565b80613060575061307c565b8060405162461bcd60e51b81526004016104489190613b79565b505b60405162461bcd60e51b815260206004820152603460248201527f455243313135353a207472616e7366657220746f206e6f6e2d455243313135356044820152732932b1b2b4bb32b91034b6b83632b6b2b73a32b960611b6064820152608401610448565b6001600160e01b0319811663bc197c8160e01b14612a895760405162461bcd60e51b815260040161044890614b8e565b6040516335f135d360e01b815260048101829052602401610448565b60405163af458c0760e01b815260040160405180910390fd5b6001600160601b03811661316d5760405163e2228b1560e01b815260040160405180910390fd5b6001600160601b038116600214156123b55760405163865a6de560e01b815260040160405180910390fd5b6131a28486612e97565b8660000160008282546131b59190614562565b909155506131c590508386612e97565b8660010160008282546131d89190614562565b909155506131e890508286612e97565b8660020160008282546131fb9190614562565b9091555061320b90508186612e97565b86600301600082825461321e9190614562565b9091555050505050505050565b6001600160a01b038516156132dd576132498587600001548661339c565b86600401600082825461325c9190614562565b925050819055506132728587600101548561339c565b8660050160008282546132859190614562565b9250508190555061329b8587600201548461339c565b8660060160008282546132ae9190614562565b925050819055506132c48587600301548361339c565b8660070160008282546132d79190614562565b90915550505b9285556001850191909155600284015560039092019190915550565b60008183106133085781611f17565b5090919050565b60405163d81e842360e01b81526001600160a01b03838116600483015282811660248301526000919085169063d81e84239060440160206040518083038186803b15801561335c57600080fd5b505afa158015613370573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061339491906147a1565b949350505050565b6000828214156133ad576000613394565b6133946001600160a01b038516848403600160801b60006134de565b60408051600180825281830190925260609160009190602080830190803683370190505090508281600081518110613403576134036143cb565b602090810291909101015292915050565b6001600160a01b0384163b15611ee05760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e61906134589089908990889088908890600401614bd6565b602060405180830381600087803b15801561347257600080fd5b505af19250505080156134a2575060408051601f3d908101601f1916820190925261349f91810190614acc565b60015b6134ae57613040614ae9565b6001600160e01b0319811663f23a6e6160e01b14612a895760405162461bcd60e51b815260040161044890614b8e565b60008060006134ed87876136f9565b91509150806000141561350e57613505828686613718565b92505050613394565b80851161353f5760405163362ced0960e11b8152600481018890526024810187905260448101869052606401610448565b600085878909600087810388169788900497600260038a028118808b02820302808b02820302808b02820302808b02820302808b02820302808b029091030291819003819004600101868411909503948502929095039490940417928302935084905080156135bd575084806135b7576135b7614c10565b86880915155b156135d057826135cc816143f7565b9350505b5050949350505050565b60005b8351811015612a89578281815181106135f8576135f86143cb565b602002602001015160001461364557613645868686848151811061361e5761361e6143cb565b6020026020010151868581518110613638576136386143cb565b6020026020010151613753565b6001016135dd565b6001600160a01b0383166136a65760008281526005602052604081208054839290613679908490614a57565b9091555050600082815260056020526040902054158015613698575060015b156136a6576136a68261387c565b6001600160a01b038416158015906136d05750826001600160a01b0316846001600160a01b031614155b1561273b576136df84836103e1565b1580156136ea575060015b1561273b5761273b8483613938565b6000806000198385098385029250828110838203039150509250929050565b60006137248385614c26565b905081801561373b57506137388385614c3a565b15155b15611f17578061374a816143f7565b95945050505050565b6001600160a01b0384166137ec5760008281526005602052604090205415801561377b575060015b156137c8576137c882600680546000838152600760205260408120829055600182018355919091527ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f0155565b600082815260056020526040812080548392906137e6908490614562565b90915550505b6001600160a01b038316158015906138165750836001600160a01b0316836001600160a01b031614155b1561273b5761382583836103e1565b158015613830575060015b1561273b576001600160a01b038316600090815260036020818152604080842080546004845282862088875284529185208290559282526001810183559183529091200182905561273b565b60065460009061388e90600190614a57565b6000838152600760205260409020549091508082146138fd576000600683815481106138bc576138bc6143cb565b9060005260206000200154905080600683815481106138dd576138dd6143cb565b600091825260208083209091019290925591825260079052604090208190555b600083815260076020526040812055600680548061391d5761391d614c4e565b60019003818190600052602060002001600090559055505050565b6001600160a01b03821660009081526003602052604081205461395d90600190614a57565b6001600160a01b0384166000908152600460209081526040808320868452909152902054909150808214613a2b576001600160a01b03841660009081526003602052604081208054849081106139b5576139b56143cb565b906000526020600020015490508060036000876001600160a01b03166001600160a01b0316815260200190815260200160002083815481106139f9576139f96143cb565b60009182526020808320909101929092556001600160a01b038716815260048252604080822093825292909152208190555b6001600160a01b038416600081815260046020908152604080832087845282528083208390559282526003905220805480613a6857613a68614c4e565b6001900381819060005260206000200160009055905550505050565b6001600160a01b03811681146123b557600080fd5b8035613aa481613a84565b919050565b60008060408385031215613abc57600080fd5b8235613ac781613a84565b946020939093013593505050565b6001600160e01b0319811681146123b557600080fd5b600060208284031215613afd57600080fd5b8135611f1781613ad5565b600060208284031215613b1a57600080fd5b5035919050565b60005b83811015613b3c578181015183820152602001613b24565b8381111561273b5750506000910152565b60008151808452613b65816020860160208601613b21565b601f01601f19169290920160200192915050565b602081526000611f176020830184613b4d565b600060808284031215613b9e57600080fd5b50919050565b600060808284031215613bb657600080fd5b611f178383613b8c565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b0381118282101715613bfb57613bfb613bc0565b6040525050565b6040516101c081016001600160401b0381118282101715613c2557613c25613bc0565b60405290565b60405161010081016001600160401b0381118282101715613c2557613c25613bc0565b60405160e081016001600160401b0381118282101715613c2557613c25613bc0565b60006001600160401b03821115613c8957613c89613bc0565b5060051b60200190565b600082601f830112613ca457600080fd5b81356020613cb182613c70565b604051613cbe8282613bd6565b83815260059390931b8501820192828101915086841115613cde57600080fd5b8286015b84811015613cf95780358352918301918301613ce2565b509695505050505050565b60006001600160401b03821115613d1d57613d1d613bc0565b50601f01601f191660200190565b600082601f830112613d3c57600080fd5b8135613d4781613d04565b604051613d548282613bd6565b828152856020848701011115613d6957600080fd5b82602086016020830137600092810160200192909252509392505050565b600080600080600060a08688031215613d9f57600080fd5b8535613daa81613a84565b94506020860135613dba81613a84565b935060408601356001600160401b0380821115613dd657600080fd5b613de289838a01613c93565b94506060880135915080821115613df857600080fd5b613e0489838a01613c93565b93506080880135915080821115613e1a57600080fd5b50613e2788828901613d2b565b9150509295509295909350565b60008060408385031215613e4757600080fd5b82356001600160401b0380821115613e5e57600080fd5b818501915085601f830112613e7257600080fd5b81356020613e7f82613c70565b604051613e8c8282613bd6565b83815260059390931b8501820192828101915089841115613eac57600080fd5b948201945b83861015613ed3578535613ec481613a84565b82529482019490820190613eb1565b96505086013592505080821115613ee957600080fd5b50613ef685828601613c93565b9150509250929050565b600081518084526020808501945080840160005b83811015613f3057815187529582019590820190600101613f14565b509495945050505050565b602081526000611f176020830184613f00565b600060208284031215613f6057600080fd5b81356001600160401b03811115613f7657600080fd5b82016101c08185031215611f1757600080fd5b85815284602082015283604082015282606082015260a060808201526000613fb460a0830184613b4d565b979650505050505050565b80356001600160601b0381168114613aa457600080fd5b600080600060c08486031215613feb57600080fd5b8335613ff681613a84565b92506140058560208601613b8c565b915061401360a08501613fbf565b90509250925092565b60006020828403121561402e57600080fd5b81356001600160401b0381111561404457600080fd5b82016101008185031215611f1757600080fd5b60008060a0838503121561406a57600080fd5b823561407581613a84565b91506140848460208501613b8c565b90509250929050565b60006020828403121561409f57600080fd5b81356001600160401b038111156140b557600080fd5b820160e08185031215611f1757600080fd5b60008060a083850312156140da57600080fd5b6140e48484613b8c565b915061408460808401613fbf565b6000806040838503121561410557600080fd5b823561411081613a84565b91506020830135801515811461412557600080fd5b809150509250929050565b600080600080600080610100878903121561414a57600080fd5b863561415581613a84565b9550602087013561416581613a84565b94506141748860408901613b8c565b935060c087013561418481613a84565b925060e08701356001600160401b03808211156141a057600080fd5b818901915089601f8301126141b457600080fd5b8135818111156141c357600080fd5b8a60208285010111156141d557600080fd5b6020830194508093505050509295509295509295565b600080604083850312156141fe57600080fd5b823561420981613a84565b9150602083013561412581613a84565b600080600080600060a0868803121561423157600080fd5b853561423c81613a84565b9450602086013561424c81613a84565b9350604086013592506060860135915060808601356001600160401b0381111561427557600080fd5b613e2788828901613d2b565b600181811c9082168061429557607f821691505b60208210811415613b9e57634e487b7160e01b600052602260045260246000fd5b6000608082840312156142c857600080fd5b604051608081018181106001600160401b03821117156142ea576142ea613bc0565b60405282356142f881613a84565b8152602083013561430881613a84565b6020820152604083810135908201526060928301359281019290925250919050565b60006020828403121561433c57600080fd5b8135611f1781613a84565b6000806000806080858703121561435d57600080fd5b505082516020840151604085015160609095015191969095509092509050565b6020808252602e908201527f455243313135353a2063616c6c6572206973206e6f7420746f6b656e206f776e60408201526d195c881bdc88185c1c1c9bdd995960921b606082015260800190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060001982141561440b5761440b6143e1565b5060010190565b60006101c0823603121561442557600080fd5b61442d613c02565b61443683613a99565b815261444460208401613a99565b6020820152604083013560408201526060830135606082015261446960808401613a99565b608082015261447a60a08401613a99565b60a082015261448b60c08401613a99565b60c082015261449c60e08401613a99565b60e08201526101006144af818501613a99565b9082015261012083810135908201526101408084013590820152610160808401359082015261018080840135908201526101a0808401356001600160401b038111156144fa57600080fd5b61450636828701613d2b565b918301919091525092915050565b858152602081018590526001600160a01b038416604082015260a081016003841061454f57634e487b7160e01b600052602160045260246000fd5b6060820193909352608001529392505050565b60008219821115614575576145756143e1565b500190565b6000808335601e1984360301811261459157600080fd5b8301803591506001600160401b038211156145ab57600080fd5b6020019150368190038213156145c057600080fd5b9250929050565b602081526145e16020820183516001600160a01b03169052565b600060208301516145fd60408401826001600160a01b03169052565b506040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015160e083015260e0830151610100818185015280850151915050610120808185015250613394610140840182613b4d565b60006020828403121561466d57600080fd5b81516001600160401b0381111561468357600080fd5b8201601f8101841361469457600080fd5b805161469f81613d04565b6040516146ac8282613bd6565b8281528660208486010111156146c157600080fd5b6146d2836020830160208701613b21565b9695505050505050565b600061010082360312156146ef57600080fd5b6146f7613c2b565b61470083613a99565b815261470e60208401613a99565b6020820152604083013560408201526060830135606082015261473360808401613a99565b608082015261474460a08401613a99565b60a082015260c08301356001600160401b038082111561476357600080fd5b61476f36838701613d2b565b60c084015260e085013591508082111561478857600080fd5b5061479536828601613d2b565b60e08301525092915050565b6000602082840312156147b357600080fd5b8151611f1781613a84565b60006001600160a01b038281168482168083038211156147e0576147e06143e1565b01949350505050565b600060018060a01b0380835116845280602084015116602085015260408301516040850152606083015160608501528060808401511660808501525060a082015160c060a085015261339460c0850182613b4d565b602081526000611f1760208301846147e9565b600060e0823603121561486357600080fd5b61486b613c4e565b61487483613a99565b815261488260208401613a99565b602082015260408301356040820152606083013560608201526148a760808401613a99565b60808201526148b860a08401613a99565b60a082015260c08301356001600160401b038111156148d657600080fd5b6148e236828601613d2b565b60c08301525092915050565b60208082526025908201527f455243313135353a207472616e7366657220746f20746865207a65726f206164604082015264647265737360d81b606082015260800190565b6020808252602a908201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60408201526939103a3930b739b332b960b11b606082015260800190565b6040815260006149906040830185613f00565b828103602084015261374a8185613f00565b600061014082019050825182526020830151602083015260408301516149d360408401826001600160a01b03169052565b5060608301516149ee60608401826001600160a01b03169052565b506080830151614a0960808401826001600160a01b03169052565b5060a0830151614a2460a08401826001600160a01b03169052565b5060c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525092915050565b600082821015614a6957614a696143e1565b500390565b6001600160a01b0386811682528516602082015260a060408201819052600090614a9a90830186613f00565b8281036060840152614aac8186613f00565b90508281036080840152614ac08185613b4d565b98975050505050505050565b600060208284031215614ade57600080fd5b8151611f1781613ad5565b600060033d1115614b025760046000803e5060005160e01c5b90565b600060443d1015614b135790565b6040516003193d81016004833e81513d6001600160401b038160248401118184111715614b4257505050505090565b8285019150815181811115614b5a5750505050505090565b843d8701016020828501011115614b745750505050505090565b614b8360208286010187613bd6565b509095945050505050565b60208082526028908201527f455243313135353a204552433131353552656365697665722072656a656374656040820152676420746f6b656e7360c01b606082015260800190565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090613fb490830184613b4d565b634e487b7160e01b600052601260045260246000fd5b600082614c3557614c35614c10565b500490565b600082614c4957614c49614c10565b500690565b634e487b7160e01b600052603160045260246000fdfea2646970667358221220cd01625efe0843efd50c5551683211298b88c6b64b9b1708aa53fc5af2c2a13264736f6c63430008080033

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

00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c400000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : chosenOptionFactory (address): 0x17385e95cb74A20150E4fA092Aa72D57330896C4
Arg [1] : chosenPoolFactory (address): 0x97509c65Ff29C268F0D283A41201Be6b4090354c
Arg [2] : uri (string):

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 00000000000000000000000017385e95cb74a20150e4fa092aa72d57330896c4
Arg [1] : 00000000000000000000000097509c65ff29c268f0d283a41201be6b4090354c
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000060
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000000


Loading...
Loading
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A token is a representation of an on-chain or off-chain asset. The token page shows information such as price, total supply, holders, transfers and social links. Learn more about this page in our Knowledge Base.