ETH Price: $2,601.88 (-1.71%)

Token

ClipperDirect Pool Token (CLPRDRPL)
 

Overview

Max Total Supply

7,093.014486738047241163 CLPRDRPL

Holders

131

Market

Onchain Market Cap

$0.00

Circulating Supply Market Cap

-

Other Info

Token Contract (WITH 18 Decimals)

Filtered by Token Holder
aeight.eth
Balance
0 CLPRDRPL

Value
$0.00
0x21d14e2c2bfcfa07de7999e08c4b0256293de748
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:
ClipperVerifiedCaravelExchange

Compiler Version
v0.8.4+commit.c7e474f2

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 19 : ClipperVerifiedCaravelExchange.sol
//SPDX-License-Identifier: Copyright 2021 Shipyard Software, Inc.
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "@prb/math/contracts/PRBMathSD59x18.sol";

import "./interfaces/WrapperContractInterface.sol";
import "./ClipperCaravelExchange.sol";

contract ClipperVerifiedCaravelExchange is ClipperCaravelExchange {
  using SafeERC20 for IERC20;
  using PRBMathSD59x18 for int256;
  using SafeCast for uint256;
  using SafeCast for int256;

  uint256 constant ONE_IN_DEFAULT_DECIMALS = 1e18;
  int256 constant SIGNED_ONE_IN_DEFAULT_DECIMALS = int256(ONE_IN_DEFAULT_DECIMALS);
  uint256 constant ONE_IN_PRICE_DECIMALS = 1e8;
  uint256 constant THE_YEAR_THREE_THOUSAND = 32503708800;

  struct UtilStruct {
    uint256 qX;
    uint256 qY;
    uint256 decimalMultiplierX;
    uint256 decimalMultiplierY;
  }

  constructor(address theSigner, address theWrapper, address[] memory tokens)
    ClipperCaravelExchange(theSigner, theWrapper, tokens){
      // Set up decimals
      uint i;
      for(i=0; i < tokens.length; i++){
        _sync(tokens[i]);
      }
  }

  function _sync(address token) internal override {
    lastBalances[token] = makeWriteValue(
      IERC20Metadata(token).decimals(),
      uint32(0),
      tokenBalance(token)
    );
  }

  function confirmUniqueDecimals(address token) internal view returns (uint8 decimals, uint32 newHash, uint256 currentBalance) {
    uint256 _current = lastBalances[token];
    decimals = uint8(_current >> 248);
    currentBalance = uint256(uint216(_current));
    uint32 lastHash = uint32(_current >> 216);
    newHash = uint32(block.number+uint256(uint160(tx.origin)));
    require(newHash != lastHash, "Clipper: Failed tx uniqueness");
  }

  // Hash:
  // uint8 decimals -> set on initiation and maintained
  // uint32 securityHash
  // uint216 actualBalance

  function makeWriteValue(uint8 decimals, uint32 newHash, uint256 newBalance) internal pure returns (uint256) {
    return (uint256(decimals) << 248) + (uint256(newHash) << 216) + uint256(newBalance.toUint216());
  }

  function setBalance(address token, uint256 newBalance) internal override {
    (uint8 decimals, uint32 newHash, ) = confirmUniqueDecimals(token);
    lastBalances[token] = makeWriteValue(decimals, newHash, newBalance);
  }

  function increaseBalance(address token, uint256 increaseAmount) internal override {
    (uint8 decimals, uint32 newHash, uint256 curBalance) = confirmUniqueDecimals(token);
    lastBalances[token] = makeWriteValue(decimals, newHash, curBalance+increaseAmount);
  }

  function decreaseBalance(address token, uint256 decreaseAmount) internal override {
    (uint8 decimals, uint32 newHash, uint256 curBalance) = confirmUniqueDecimals(token);
    lastBalances[token] = makeWriteValue(decimals, newHash, curBalance-decreaseAmount);
  }

  function getLastBalance(address token) public view override returns (uint256) {
    return uint256(uint216(lastBalances[token]));
  }

  function getLastBalanceAndDecimalMultiplier(address token) internal view returns (uint256 balance, uint256 decimalMultiplier) {
    uint256 _theBalance = lastBalances[token];
    balance = uint256(uint216(_theBalance));
    uint256 decimals = _theBalance >> 248;
    unchecked {
      if(decimals==18){
        decimalMultiplier = 1;
      } else if(decimals < 18){
        decimalMultiplier = 10**(18-decimals);
      } else {
        revert("Invalid decimals");
      }
    }
  }

  /* SWAP Functionality */

  function inputRequiresVerification(uint256 potentiallyPackedGoodUntil) internal pure returns (bool) {
    return potentiallyPackedGoodUntil > THE_YEAR_THREE_THOUSAND;
  }

  function unpackAndCheckInvariant(address inputToken, uint256 inputAmount,
    address outputToken, uint256 outputAmount,
    uint256 packedGoodUntil) internal view returns (uint256) {

    UtilStruct memory s;

    (uint256 pX, uint256 pY,uint256 wX, uint256 wY, uint256 k) = unpackGoodUntil(packedGoodUntil);
    (s.qX, s.decimalMultiplierX) = getLastBalanceAndDecimalMultiplier(inputToken);
    (s.qY, s.decimalMultiplierY) = getLastBalanceAndDecimalMultiplier(outputToken);

    require(
        swapIncreasesInvariant(
          inputAmount * s.decimalMultiplierX, pX, s.qX * s.decimalMultiplierX, wX,
          outputAmount * s.decimalMultiplierY, pY, s.qY * s.decimalMultiplierY, wY,
          k),
        "Clipper: Invariant");

    return uint256(uint32(packedGoodUntil));
  }

  function unpackGoodUntil(uint256 packedGoodUntil) public pure
    returns (uint256 pX, uint256 pY, uint256 wX, uint256 wY, uint256 k) {
    /*
        * Input asset price in 8 decimals - uint64
        * Output asset price in 8 decimals - uint64
        * k value in 18 decimals - uint64
        * Input asset weight - uint16
        * Output asset weight - uint16
        * Current good until value - uint32 - can be taken as uint256(uint32(packedGoodUntil))
    */
    // goodUntil = uint256(uint32(packedGoodUntil));
    packedGoodUntil = packedGoodUntil >> 32;
    wY = uint256(uint16(packedGoodUntil));
    packedGoodUntil = packedGoodUntil >> 16;
    wX = uint256(uint16(packedGoodUntil));
    packedGoodUntil = packedGoodUntil >> 16;
    k = uint256(uint64(packedGoodUntil));
    packedGoodUntil = packedGoodUntil >> 64;
    pY = uint256(uint64(packedGoodUntil));
    packedGoodUntil = packedGoodUntil >> 64;
    pX = uint256(uint64(packedGoodUntil));
  }

  /*
  Before calling:
  Set qX = lastBalances[inAsset];
  Set qY = lastBalances[outAsset];

  Multiply all quantities (q and in/out) by 10**(18-asset.decimals()).
  This puts all quantities in 18 decimals.

  Assumed decimals:
  K: 18
  Quantities: 18 (ONE_IN_DEFAULT_DECIMALS = 1e18)
  Prices: 8 (ONE_IN_PRICE_DECIMALS = 1e8)
  Weights: 0 (100 = 100)
  */
  function swapIncreasesInvariant(uint256 inX, uint256 pX, uint256 qX, uint256 wX,
    uint256 outY, uint256 pY, uint256 qY, uint256 wY,
    uint256 k) internal pure returns (bool) {

    uint256 invariantBefore;
    uint256 invariantAfter;
    {
      uint256 pqX = pX * qX / ONE_IN_PRICE_DECIMALS;
      uint256 pqwXk = fractionalPow(pqX * wX, k);
      if (pqwXk > 0) {
        invariantBefore += (ONE_IN_DEFAULT_DECIMALS * pqX) / pqwXk;
      }

      uint256 pqY = pY * qY / ONE_IN_PRICE_DECIMALS;
      uint256 pqwYk = fractionalPow(pqY * wY, k);
      if (pqwYk > 0) {
        invariantBefore += (ONE_IN_DEFAULT_DECIMALS * pqY) / pqwYk;
      }
    }
    {
      uint256 pqXinX = (pX * (qX + inX)) / ONE_IN_PRICE_DECIMALS;
      uint256 pqwXinXk = fractionalPow(pqXinX * wX, k);
      if (pqwXinXk > 0) {
        invariantAfter += (ONE_IN_DEFAULT_DECIMALS * pqXinX) / pqwXinXk;
      }

      uint256 pqYoutY = pY * (qY - outY) / ONE_IN_PRICE_DECIMALS;
      uint256 pqwYoutYk = fractionalPow(pqYoutY * wY, k);
      if (pqwYoutYk > 0) {
        invariantAfter += (ONE_IN_DEFAULT_DECIMALS * pqYoutY) / pqwYoutYk;
      }
    }
    return invariantAfter > invariantBefore;
  }

  function fractionalPow(uint256 input, uint256 pow) internal pure returns (uint256) {
    if (input == 0) {
      return 0;
    } else {
      // input^(pow/1e18) -> exp2( (pow * log2( input ) / 1e18 ) )
      return exp2((int256(pow) * log2(input.toInt256())) / SIGNED_ONE_IN_DEFAULT_DECIMALS);
    }
  }

  function exp2(int256 x) internal pure returns (uint256) {
    return x.exp2().toUint256();
  }

  function log2(int256 x) internal pure returns (int256 y) {
    y = x.log2();
  }

  // Don't need a separate "transmit" function here since it's already payable
  // Gas optimized - no balance checks
  // Don't need fairOutput checks since exactly inputAmount is wrapped
  function sellEthForToken(address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external override receivedInTime(goodUntil) payable {
    /* CHECKS */
    require(isToken(outputToken), "Clipper: Invalid token");
    // Wrap ETH (as balance or value) as input. This will revert if insufficient balance is provided
    safeEthSend(WRAPPER_CONTRACT, inputAmount);
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(WRAPPER_CONTRACT, outputToken, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);

    if(inputRequiresVerification(goodUntil)) {
      require(unpackAndCheckInvariant(WRAPPER_CONTRACT, inputAmount, outputToken, outputAmount, goodUntil) >= block.timestamp,
          "Clipper: Expired");
    }

    /* EFFECTS */
    increaseBalance(WRAPPER_CONTRACT, inputAmount);
    decreaseBalance(outputToken, outputAmount);

    /* INTERACTIONS */
    IERC20(outputToken).safeTransfer(destinationAddress, outputAmount);

    emit Swapped(WRAPPER_CONTRACT, outputToken, destinationAddress, inputAmount, outputAmount, auxiliaryData);
  }

  // Mostly copied from gas-optimized swap functionality
  function sellTokenForEth(address inputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external override receivedInTime(goodUntil) {
    /* CHECKS */
    require(isToken(inputToken), "Clipper: Invalid token");
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(inputToken, WRAPPER_CONTRACT, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);
    
    // Check that enough input token has been transmitted
    uint256 currentInputBalance = tokenBalance(inputToken);
    uint256 actualInput = currentInputBalance - getLastBalance(inputToken);
    uint256 fairOutput = calculateFairOutput(inputAmount, actualInput, outputAmount);

    if(inputRequiresVerification(goodUntil)) {
      require(unpackAndCheckInvariant(inputToken, actualInput, WRAPPER_CONTRACT, fairOutput, goodUntil) >= block.timestamp,
          "Clipper: Expired");
    }

    /* EFFECTS */
    setBalance(inputToken, currentInputBalance);
    decreaseBalance(WRAPPER_CONTRACT, fairOutput);

    /* INTERACTIONS */
    // Unwrap and forward ETH, without sync
    WrapperContractInterface(WRAPPER_CONTRACT).withdraw(fairOutput);
    safeEthSend(destinationAddress, fairOutput);

    emit Swapped(inputToken, WRAPPER_CONTRACT, destinationAddress, actualInput, fairOutput, auxiliaryData);
  }

  // Gas optimized, no balance checks
  // No need to check fairOutput since the inputToken pull works
  function transmitAndSellTokenForEth(address inputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external override receivedInTime(goodUntil) {
    /* CHECKS */
    require(isToken(inputToken), "Clipper: Invalid token");
    // Will revert if msg.sender has insufficient balance
    IERC20(inputToken).safeTransferFrom(msg.sender, address(this), inputAmount);
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(inputToken, WRAPPER_CONTRACT, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);

    if(inputRequiresVerification(goodUntil)) {
      require(unpackAndCheckInvariant(inputToken, inputAmount, WRAPPER_CONTRACT, outputAmount, goodUntil) >= block.timestamp,
          "Clipper: Expired");
    }

    /* EFFECTS */
    increaseBalance(inputToken, inputAmount);
    decreaseBalance(WRAPPER_CONTRACT, outputAmount);

    /* INTERACTIONS */
    // Unwrap and forward ETH, we've already updated the balance
    WrapperContractInterface(WRAPPER_CONTRACT).withdraw(outputAmount);
    safeEthSend(destinationAddress, outputAmount);

    emit Swapped(inputToken, WRAPPER_CONTRACT, destinationAddress, inputAmount, outputAmount, auxiliaryData);
  }

  // all-in-one transfer from msg.sender to destinationAddress.
  // Gas optimized - never checks balances
  // No need to check fairOutput since the inputToken pull works
  function transmitAndSwap(address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external override receivedInTime(goodUntil) {
    /* CHECKS */
    require(isToken(inputToken) && isToken(outputToken), "Clipper: Invalid tokens");
    // Will revert if msg.sender has insufficient balance
    IERC20(inputToken).safeTransferFrom(msg.sender, address(this), inputAmount);
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(inputToken, outputToken, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);

    if(inputRequiresVerification(goodUntil)) {
      require(unpackAndCheckInvariant(inputToken, inputAmount, outputToken, outputAmount, goodUntil) >= block.timestamp,
          "Clipper: Expired");
    }

    /* EFFECTS */
    increaseBalance(inputToken, inputAmount);
    decreaseBalance(outputToken, outputAmount);

    /* INTERACTIONS */
    IERC20(outputToken).safeTransfer(destinationAddress, outputAmount);

    emit Swapped(inputToken, outputToken, destinationAddress, inputAmount, outputAmount, auxiliaryData);
  }

  // Gas optimized - single token balance check for input
  // output is dead-reckoned and scaled back if necessary
  function swap(address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) public override receivedInTime(goodUntil) {
    /* CHECKS */
    require(isToken(inputToken) && isToken(outputToken), "Clipper: Invalid tokens");

    { // Avoid stack too deep
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(inputToken, outputToken, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);
    }

    // Get fair output value
    uint256 currentInputBalance = tokenBalance(inputToken);
    uint256 actualInput = currentInputBalance-getLastBalance(inputToken);    
    uint256 fairOutput = calculateFairOutput(inputAmount, actualInput, outputAmount);

    if(inputRequiresVerification(goodUntil)) {
      require(unpackAndCheckInvariant(inputToken, actualInput, outputToken, fairOutput, goodUntil) >= block.timestamp,
          "Clipper: Expired");
    }

    /* EFFECTS */
    setBalance(inputToken, currentInputBalance);
    decreaseBalance(outputToken, fairOutput);

    /* INTERACTIONS */
    IERC20(outputToken).safeTransfer(destinationAddress, fairOutput);

    emit Swapped(inputToken, outputToken, destinationAddress, actualInput, fairOutput, auxiliaryData);
  }

}

File 2 of 19 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

File 3 of 19 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) external returns (bool);
}

File 4 of 19 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";

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

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

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

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

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

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

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

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

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

File 5 of 19 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 *  Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
 *  See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 *  In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 6 of 19 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/math/SafeCast.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 7 of 19 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

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

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

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

File 8 of 19 : PRBMathSD59x18.sol
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.8.4;

import "./PRBMath.sol";

/// @title PRBMathSD59x18
/// @author Paul Razvan Berg
/// @notice Smart contract library for advanced fixed-point math that works with int256 numbers considered to have 18
/// trailing decimals. We call this number representation signed 59.18-decimal fixed-point, since the numbers can have
/// a sign and there can be up to 59 digits in the integer part and up to 18 decimals in the fractional part. The numbers
/// are bound by the minimum and the maximum values permitted by the Solidity type int256.
library PRBMathSD59x18 {
    /// @dev log2(e) as a signed 59.18-decimal fixed-point number.
    int256 internal constant LOG2_E = 1_442695040888963407;

    /// @dev Half the SCALE number.
    int256 internal constant HALF_SCALE = 5e17;

    /// @dev The maximum value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MAX_SD59x18 =
        57896044618658097711785492504343953926634992332820282019728_792003956564819967;

    /// @dev The maximum whole value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MAX_WHOLE_SD59x18 =
        57896044618658097711785492504343953926634992332820282019728_000000000000000000;

    /// @dev The minimum value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MIN_SD59x18 =
        -57896044618658097711785492504343953926634992332820282019728_792003956564819968;

    /// @dev The minimum whole value a signed 59.18-decimal fixed-point number can have.
    int256 internal constant MIN_WHOLE_SD59x18 =
        -57896044618658097711785492504343953926634992332820282019728_000000000000000000;

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

    /// INTERNAL FUNCTIONS ///

    /// @notice Calculate the absolute value of x.
    ///
    /// @dev Requirements:
    /// - x must be greater than MIN_SD59x18.
    ///
    /// @param x The number to calculate the absolute value for.
    /// @param result The absolute value of x.
    function abs(int256 x) internal pure returns (int256 result) {
        unchecked {
            if (x == MIN_SD59x18) {
                revert PRBMathSD59x18__AbsInputTooSmall();
            }
            result = x < 0 ? -x : x;
        }
    }

    /// @notice Calculates the arithmetic average of x and y, rounding down.
    /// @param x The first operand as a signed 59.18-decimal fixed-point number.
    /// @param y The second operand as a signed 59.18-decimal fixed-point number.
    /// @return result The arithmetic average as a signed 59.18-decimal fixed-point number.
    function avg(int256 x, int256 y) internal pure returns (int256 result) {
        // The operations can never overflow.
        unchecked {
            int256 sum = (x >> 1) + (y >> 1);
            if (sum < 0) {
                // If at least one of x and y is odd, we add 1 to the result. This is because shifting negative numbers to the
                // right rounds down to infinity.
                assembly {
                    result := add(sum, and(or(x, y), 1))
                }
            } else {
                // If both x and y are odd, we add 1 to the result. This is because if both numbers are odd, the 0.5
                // remainder gets truncated twice.
                result = sum + (x & y & 1);
            }
        }
    }

    /// @notice Yields the least greatest signed 59.18 decimal fixed-point number greater than or equal to x.
    ///
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    ///
    /// Requirements:
    /// - x must be less than or equal to MAX_WHOLE_SD59x18.
    ///
    /// @param x The signed 59.18-decimal fixed-point number to ceil.
    /// @param result The least integer greater than or equal to x, as a signed 58.18-decimal fixed-point number.
    function ceil(int256 x) internal pure returns (int256 result) {
        if (x > MAX_WHOLE_SD59x18) {
            revert PRBMathSD59x18__CeilOverflow(x);
        }
        unchecked {
            int256 remainder = x % SCALE;
            if (remainder == 0) {
                result = x;
            } else {
                // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                result = x - remainder;
                if (x > 0) {
                    result += SCALE;
                }
            }
        }
    }

    /// @notice Divides two signed 59.18-decimal fixed-point numbers, returning a new signed 59.18-decimal fixed-point number.
    ///
    /// @dev Variant of "mulDiv" that works with signed numbers. Works by computing the signs and the absolute values separately.
    ///
    /// Requirements:
    /// - All from "PRBMath.mulDiv".
    /// - None of the inputs can be MIN_SD59x18.
    /// - The denominator cannot be zero.
    /// - The result must fit within int256.
    ///
    /// Caveats:
    /// - All from "PRBMath.mulDiv".
    ///
    /// @param x The numerator as a signed 59.18-decimal fixed-point number.
    /// @param y The denominator as a signed 59.18-decimal fixed-point number.
    /// @param result The quotient as a signed 59.18-decimal fixed-point number.
    function div(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == MIN_SD59x18 || y == MIN_SD59x18) {
            revert PRBMathSD59x18__DivInputTooSmall();
        }

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

        // Compute the absolute value of (x*SCALE)÷y. The result must fit within int256.
        uint256 rAbs = PRBMath.mulDiv(ax, uint256(SCALE), ay);
        if (rAbs > uint256(MAX_SD59x18)) {
            revert PRBMathSD59x18__DivOverflow(rAbs);
        }

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

        // XOR over sx and sy. This is basically checking whether the inputs have the same sign. If yes, the result
        // should be positive. Otherwise, it should be negative.
        result = sx ^ sy == 1 ? -int256(rAbs) : int256(rAbs);
    }

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

    /// @notice Calculates the natural exponent of x.
    ///
    /// @dev Based on the insight that e^x = 2^(x * log2(e)).
    ///
    /// Requirements:
    /// - All from "log2".
    /// - x must be less than 133.084258667509499441.
    ///
    /// Caveats:
    /// - All from "exp2".
    /// - For any x less than -41.446531673892822322, the result is zero.
    ///
    /// @param x The exponent as a signed 59.18-decimal fixed-point number.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function exp(int256 x) internal pure returns (int256 result) {
        // Without this check, the value passed to "exp2" would be less than -59.794705707972522261.
        if (x < -41_446531673892822322) {
            return 0;
        }

        // Without this check, the value passed to "exp2" would be greater than 192.
        if (x >= 133_084258667509499441) {
            revert PRBMathSD59x18__ExpInputTooBig(x);
        }

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

    /// @notice Calculates the binary exponent of x using the binary fraction method.
    ///
    /// @dev See https://ethereum.stackexchange.com/q/79903/24693.
    ///
    /// Requirements:
    /// - x must be 192 or less.
    /// - The result must fit within MAX_SD59x18.
    ///
    /// Caveats:
    /// - For any x less than -59.794705707972522261, the result is zero.
    ///
    /// @param x The exponent as a signed 59.18-decimal fixed-point number.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function exp2(int256 x) internal pure returns (int256 result) {
        // This works because 2^(-x) = 1/2^x.
        if (x < 0) {
            // 2^59.794705707972522262 is the maximum number whose inverse does not truncate down to zero.
            if (x < -59_794705707972522261) {
                return 0;
            }

            // Do the fixed-point inversion inline to save gas. The numerator is SCALE * SCALE.
            unchecked {
                result = 1e36 / exp2(-x);
            }
        } else {
            // 2^192 doesn't fit within the 192.64-bit format used internally in this function.
            if (x >= 192e18) {
                revert PRBMathSD59x18__Exp2InputTooBig(x);
            }

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

                // Safe to convert the result to int256 directly because the maximum input allowed is 192.
                result = int256(PRBMath.exp2(x192x64));
            }
        }
    }

    /// @notice Yields the greatest signed 59.18 decimal fixed-point number less than or equal to x.
    ///
    /// @dev Optimized for fractional value inputs, because for every whole value there are (1e18 - 1) fractional counterparts.
    /// See https://en.wikipedia.org/wiki/Floor_and_ceiling_functions.
    ///
    /// Requirements:
    /// - x must be greater than or equal to MIN_WHOLE_SD59x18.
    ///
    /// @param x The signed 59.18-decimal fixed-point number to floor.
    /// @param result The greatest integer less than or equal to x, as a signed 58.18-decimal fixed-point number.
    function floor(int256 x) internal pure returns (int256 result) {
        if (x < MIN_WHOLE_SD59x18) {
            revert PRBMathSD59x18__FloorUnderflow(x);
        }
        unchecked {
            int256 remainder = x % SCALE;
            if (remainder == 0) {
                result = x;
            } else {
                // Solidity uses C fmod style, which returns a modulus with the same sign as x.
                result = x - remainder;
                if (x < 0) {
                    result -= SCALE;
                }
            }
        }
    }

    /// @notice Yields the excess beyond the floor of x for positive numbers and the part of the number to the right
    /// of the radix point for negative numbers.
    /// @dev Based on the odd function definition. https://en.wikipedia.org/wiki/Fractional_part
    /// @param x The signed 59.18-decimal fixed-point number to get the fractional part of.
    /// @param result The fractional part of x as a signed 59.18-decimal fixed-point number.
    function frac(int256 x) internal pure returns (int256 result) {
        unchecked {
            result = x % SCALE;
        }
    }

    /// @notice Converts a number from basic integer form to signed 59.18-decimal fixed-point representation.
    ///
    /// @dev Requirements:
    /// - x must be greater than or equal to MIN_SD59x18 divided by SCALE.
    /// - x must be less than or equal to MAX_SD59x18 divided by SCALE.
    ///
    /// @param x The basic integer to convert.
    /// @param result The same number in signed 59.18-decimal fixed-point representation.
    function fromInt(int256 x) internal pure returns (int256 result) {
        unchecked {
            if (x < MIN_SD59x18 / SCALE) {
                revert PRBMathSD59x18__FromIntUnderflow(x);
            }
            if (x > MAX_SD59x18 / SCALE) {
                revert PRBMathSD59x18__FromIntOverflow(x);
            }
            result = x * SCALE;
        }
    }

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

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

            // The product cannot be negative.
            if (xy < 0) {
                revert PRBMathSD59x18__GmNegativeProduct(x, y);
            }

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

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

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

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

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

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

    /// @notice Calculates the binary logarithm of x.
    ///
    /// @dev Based on the iterative approximation algorithm.
    /// https://en.wikipedia.org/wiki/Binary_logarithm#Iterative_approximation
    ///
    /// Requirements:
    /// - x must be greater than zero.
    ///
    /// Caveats:
    /// - The results are not perfectly accurate to the last decimal, due to the lossy precision of the iterative approximation.
    ///
    /// @param x The signed 59.18-decimal fixed-point number for which to calculate the binary logarithm.
    /// @return result The binary logarithm as a signed 59.18-decimal fixed-point number.
    function log2(int256 x) internal pure returns (int256 result) {
        if (x <= 0) {
            revert PRBMathSD59x18__LogInputTooSmall(x);
        }
        unchecked {
            // This works because log2(x) = -log2(1/x).
            int256 sign;
            if (x >= SCALE) {
                sign = 1;
            } else {
                sign = -1;
                // Do the fixed-point inversion inline to save gas. The numerator is SCALE * SCALE.
                assembly {
                    x := div(1000000000000000000000000000000000000, x)
                }
            }

            // Calculate the integer part of the logarithm and add it to the result and finally calculate y = x * 2^(-n).
            uint256 n = PRBMath.mostSignificantBit(uint256(x / SCALE));

            // The integer part of the logarithm as a signed 59.18-decimal fixed-point number. The operation can't overflow
            // because n is maximum 255, SCALE is 1e18 and sign is either 1 or -1.
            result = int256(n) * SCALE;

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

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

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

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

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

    /// @notice Multiplies two signed 59.18-decimal fixed-point numbers together, returning a new signed 59.18-decimal
    /// fixed-point number.
    ///
    /// @dev Variant of "mulDiv" that works with signed numbers and employs constant folding, i.e. the denominator is
    /// always 1e18.
    ///
    /// Requirements:
    /// - All from "PRBMath.mulDivFixedPoint".
    /// - None of the inputs can be MIN_SD59x18
    /// - The result must fit within MAX_SD59x18.
    ///
    /// Caveats:
    /// - The body is purposely left uncommented; see the NatSpec comments in "PRBMath.mulDiv" to understand how this works.
    ///
    /// @param x The multiplicand as a signed 59.18-decimal fixed-point number.
    /// @param y The multiplier as a signed 59.18-decimal fixed-point number.
    /// @return result The product as a signed 59.18-decimal fixed-point number.
    function mul(int256 x, int256 y) internal pure returns (int256 result) {
        if (x == MIN_SD59x18 || y == MIN_SD59x18) {
            revert PRBMathSD59x18__MulInputTooSmall();
        }

        unchecked {
            uint256 ax;
            uint256 ay;
            ax = x < 0 ? uint256(-x) : uint256(x);
            ay = y < 0 ? uint256(-y) : uint256(y);

            uint256 rAbs = PRBMath.mulDivFixedPoint(ax, ay);
            if (rAbs > uint256(MAX_SD59x18)) {
                revert PRBMathSD59x18__MulOverflow(rAbs);
            }

            uint256 sx;
            uint256 sy;
            assembly {
                sx := sgt(x, sub(0, 1))
                sy := sgt(y, sub(0, 1))
            }
            result = sx ^ sy == 1 ? -int256(rAbs) : int256(rAbs);
        }
    }

    /// @notice Returns PI as a signed 59.18-decimal fixed-point number.
    function pi() internal pure returns (int256 result) {
        result = 3_141592653589793238;
    }

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

    /// @notice Raises x (signed 59.18-decimal fixed-point number) to the power of y (basic unsigned integer) using the
    /// famous algorithm "exponentiation by squaring".
    ///
    /// @dev See https://en.wikipedia.org/wiki/Exponentiation_by_squaring
    ///
    /// Requirements:
    /// - All from "abs" and "PRBMath.mulDivFixedPoint".
    /// - The result must fit within MAX_SD59x18.
    ///
    /// Caveats:
    /// - All from "PRBMath.mulDivFixedPoint".
    /// - Assumes 0^0 is 1.
    ///
    /// @param x The base as a signed 59.18-decimal fixed-point number.
    /// @param y The exponent as an uint256.
    /// @return result The result as a signed 59.18-decimal fixed-point number.
    function powu(int256 x, uint256 y) internal pure returns (int256 result) {
        uint256 xAbs = uint256(abs(x));

        // Calculate the first iteration of the loop in advance.
        uint256 rAbs = y & 1 > 0 ? xAbs : uint256(SCALE);

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

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

        // The result must fit within the 59.18-decimal fixed-point representation.
        if (rAbs > uint256(MAX_SD59x18)) {
            revert PRBMathSD59x18__PowuOverflow(rAbs);
        }

        // Is the base negative and the exponent an odd number?
        bool isNegative = x < 0 && y & 1 == 1;
        result = isNegative ? -int256(rAbs) : int256(rAbs);
    }

    /// @notice Returns 1 as a signed 59.18-decimal fixed-point number.
    function scale() internal pure returns (int256 result) {
        result = SCALE;
    }

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

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

File 9 of 19 : WrapperContractInterface.sol
//SPDX-License-Identifier: Copyright 2021 Shipyard Software, Inc.
pragma solidity ^0.8.0;

interface WrapperContractInterface {
  function withdraw(uint256 amount) external;
}

File 10 of 19 : ClipperCaravelExchange.sol
//SPDX-License-Identifier: Copyright 2021 Shipyard Software, Inc.
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";

import "./interfaces/WrapperContractInterface.sol";

import "./ClipperCommonExchange.sol";

contract ClipperCaravelExchange is ClipperCommonExchange, Ownable {
  using SafeCast for uint256;
  using SafeERC20 for IERC20;
  using EnumerableSet for EnumerableSet.AddressSet;

  modifier receivedInTime(uint256 goodUntil){
    require(block.timestamp <= goodUntil, "Clipper: Expired");
    _;
  }

  constructor(address theSigner, address theWrapper, address[] memory tokens)
    ClipperCommonExchange(theSigner, theWrapper, tokens)
    {}

  function addAsset(address token) external onlyOwner {
    assetSet.add(token);
    _sync(token);
  }

  function tokenBalance(address token) internal view returns (uint256) {
    (bool success, bytes memory data) = token.staticcall(abi.encodeWithSelector(IERC20.balanceOf.selector, address(this)));
    require(success && data.length >= 32);
    return abi.decode(data, (uint256));
  }

  function _sync(address token) internal virtual override {
    setBalance(token, tokenBalance(token));
  }

  function confirmUnique(address token) internal view returns (uint32 newHash, uint256 currentBalance) {
    uint256 _current = lastBalances[token];
    currentBalance = uint256(uint224(_current));
    uint32 lastHash = uint32(_current >> 224);
    newHash = uint32(block.number+uint256(uint160(tx.origin)));
    require(newHash != lastHash, "Clipper: Failed tx uniqueness");
  }

  function makeWriteValue(uint32 newHash, uint256 newBalance) internal pure returns (uint256) {
    return (uint256(newHash) << 224) + uint256(newBalance.toUint224());
  }

  function setBalance(address token, uint256 newBalance) internal virtual {
    (uint32 newHash, ) = confirmUnique(token);
    lastBalances[token] = makeWriteValue(newHash, newBalance);
  }

  function increaseBalance(address token, uint256 increaseAmount) internal virtual {
    (uint32 newHash, uint256 curBalance) = confirmUnique(token);
    lastBalances[token] = makeWriteValue(newHash, curBalance+increaseAmount);
  }

  function decreaseBalance(address token, uint256 decreaseAmount) internal virtual {
    (uint32 newHash, uint256 curBalance) = confirmUnique(token);
    lastBalances[token] = makeWriteValue(newHash, curBalance-decreaseAmount);
  }

  function getLastBalance(address token) public view virtual override returns (uint256) {
    return uint256(uint224(lastBalances[token]));
  }

  // Can deposit raw ETH by attaching as msg.value
  function deposit(address sender, uint256[] calldata depositAmounts, uint256 nDays, uint256 poolTokens, uint256 goodUntil, Signature calldata theSignature) public payable override receivedInTime(goodUntil){
    if(msg.value > 0){
      safeEthSend(WRAPPER_CONTRACT, msg.value);
    }
    // Make sure the depositor is allowed
    require(msg.sender==sender, "Listed sender does not match msg.sender");
    bytes32 depositDigest = createDepositDigest(sender, depositAmounts, nDays, poolTokens, goodUntil);
    // Revert if it's signed by the wrong address
    verifyDigestSignature(depositDigest, theSignature);

    // Check deposit amounts, syncing as we go
    uint i=0;
    uint n = depositAmounts.length;
    while(i < n){
      uint256 allegedDeposit = depositAmounts[i];
      if(allegedDeposit > 0){
        address _token = tokenAt(i);
        uint256 currentBalance = tokenBalance(_token);
        require(currentBalance - getLastBalance(_token) >= allegedDeposit, "Insufficient token deposit");
        setBalance(_token, currentBalance);
      }
      i++;
    }
    // OK now we're good
    _mintOrVesting(sender, nDays, poolTokens);
    emit Deposited(sender, poolTokens, nDays);
  }

  function depositSingleAsset(address sender, address inputToken, uint256 inputAmount, uint256 nDays, uint256 poolTokens, uint256 goodUntil, Signature calldata theSignature) public payable override receivedInTime(goodUntil){
    if(msg.value > 0){
      safeEthSend(WRAPPER_CONTRACT, msg.value);
    }
    // Make sure the depositor is allowed
    require(msg.sender==sender && isToken(inputToken), "Invalid input");

    // Check the signature
    bytes32 depositDigest = createSingleDepositDigest(sender, inputToken, inputAmount, nDays, poolTokens, goodUntil);
    // Revert if it's signed by the wrong address
    verifyDigestSignature(depositDigest, theSignature);

    // Check deposit amount and sync balance
    uint256 currentBalance = tokenBalance(inputToken);
    require(currentBalance - getLastBalance(inputToken) >= inputAmount, "Insufficient token deposit");
    // sync the balance
    setBalance(inputToken, currentBalance);

    // OK now we're good
    _mintOrVesting(sender, nDays, poolTokens);
    emit Deposited(sender, poolTokens, nDays);
  }

  /* WITHDRAWAL FUNCTIONALITY */
  
  /* Single asset withdrawal functionality */

  function withdrawSingleAsset(address tokenHolder, uint256 poolTokenAmountToBurn, address assetAddress, uint256 assetAmount, uint256 goodUntil, Signature calldata theSignature) external override receivedInTime(goodUntil) {
    /* CHECKS */
    require(msg.sender==tokenHolder, "tokenHolder does not match msg.sender");
    
    bool sendEthBack;
    if(assetAddress == CLIPPER_ETH_SIGIL) {
      assetAddress = WRAPPER_CONTRACT;
      sendEthBack = true;
    }

    bytes32 withdrawalDigest = createWithdrawalDigest(tokenHolder, poolTokenAmountToBurn, assetAddress, assetAmount, goodUntil);
    // Reverts if it's signed by the wrong address
    verifyDigestSignature(withdrawalDigest, theSignature);

    /* EFFECTS */
    // Reverts if pool token balance is insufficient
    _burn(msg.sender, poolTokenAmountToBurn);
    
    // Reverts if the pool's balance of the token is insufficient  
    decreaseBalance(assetAddress, assetAmount);

    /* INTERACTIONS */
    if(sendEthBack) {
      WrapperContractInterface(WRAPPER_CONTRACT).withdraw(assetAmount);
      safeEthSend(msg.sender, assetAmount);
    } else {
      IERC20(assetAddress).safeTransfer(msg.sender, assetAmount);
    }

    emit AssetWithdrawn(tokenHolder, poolTokenAmountToBurn, assetAddress, assetAmount);
  }

  /* SWAP Functionality */

  // Don't need a separate "transmit" function here since it's already payable
  // Gas optimized - no balance checks
  // Don't need fairOutput checks since exactly inputAmount is wrapped
  function sellEthForToken(address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external virtual override receivedInTime(goodUntil) payable {
    /* CHECKS */
    require(isToken(outputToken), "Clipper: Invalid token");
    // Wrap ETH (as balance or value) as input. This will revert if insufficient balance is provided
    safeEthSend(WRAPPER_CONTRACT, inputAmount);
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(WRAPPER_CONTRACT, outputToken, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);

    /* EFFECTS */
    increaseBalance(WRAPPER_CONTRACT, inputAmount);
    decreaseBalance(outputToken, outputAmount);

    /* INTERACTIONS */
    IERC20(outputToken).safeTransfer(destinationAddress, outputAmount);

    emit Swapped(WRAPPER_CONTRACT, outputToken, destinationAddress, inputAmount, outputAmount, auxiliaryData);
  }

  // Mostly copied from gas-optimized swap functionality
  function sellTokenForEth(address inputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external virtual override receivedInTime(goodUntil) {
    /* CHECKS */
    require(isToken(inputToken), "Clipper: Invalid token");
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(inputToken, WRAPPER_CONTRACT, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);
    
    // Check that enough input token has been transmitted
    uint256 currentInputBalance = tokenBalance(inputToken);
    uint256 actualInput = currentInputBalance - getLastBalance(inputToken);
    uint256 fairOutput = calculateFairOutput(inputAmount, actualInput, outputAmount);


    /* EFFECTS */
    setBalance(inputToken, currentInputBalance);
    decreaseBalance(WRAPPER_CONTRACT, fairOutput);

    /* INTERACTIONS */
    // Unwrap and forward ETH, without sync
    WrapperContractInterface(WRAPPER_CONTRACT).withdraw(fairOutput);
    safeEthSend(destinationAddress, fairOutput);

    emit Swapped(inputToken, WRAPPER_CONTRACT, destinationAddress, actualInput, fairOutput, auxiliaryData);
  }

  function transmitAndDepositSingleAsset(address inputToken, uint256 inputAmount, uint256 nDays, uint256 poolTokens, uint256 goodUntil, Signature calldata theSignature) external virtual override receivedInTime(goodUntil){
    // Make sure the depositor is allowed
    require(isToken(inputToken), "Invalid input");

    // Will revert if msg.sender has insufficient balance
    IERC20(inputToken).safeTransferFrom(msg.sender, address(this), inputAmount);

    // Check the signature
    bytes32 depositDigest = createSingleDepositDigest(msg.sender, inputToken, inputAmount, nDays, poolTokens, goodUntil);
    // Revert if it's signed by the wrong address
    verifyDigestSignature(depositDigest, theSignature);

    // sync the deposited asset
    increaseBalance(inputToken, inputAmount);

    // OK now we're good
    _mintOrVesting(msg.sender, nDays, poolTokens);
    emit Deposited(msg.sender, poolTokens, nDays);
  }

  // Gas optimized, no balance checks
  // No need to check fairOutput since the inputToken pull works
  function transmitAndSellTokenForEth(address inputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external virtual override receivedInTime(goodUntil) {
    /* CHECKS */
    require(isToken(inputToken), "Clipper: Invalid token");
    // Will revert if msg.sender has insufficient balance
    IERC20(inputToken).safeTransferFrom(msg.sender, address(this), inputAmount);
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(inputToken, WRAPPER_CONTRACT, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);

    /* EFFECTS */
    increaseBalance(inputToken, inputAmount);
    decreaseBalance(WRAPPER_CONTRACT, outputAmount);

    /* INTERACTIONS */
    // Unwrap and forward ETH, we've already updated the balance
    WrapperContractInterface(WRAPPER_CONTRACT).withdraw(outputAmount);
    safeEthSend(destinationAddress, outputAmount);

    emit Swapped(inputToken, WRAPPER_CONTRACT, destinationAddress, inputAmount, outputAmount, auxiliaryData);
  }

  // all-in-one transfer from msg.sender to destinationAddress.
  // Gas optimized - never checks balances
  // No need to check fairOutput since the inputToken pull works
  function transmitAndSwap(address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external virtual override receivedInTime(goodUntil) {
    /* CHECKS */
    require(isToken(inputToken) && isToken(outputToken), "Clipper: Invalid tokens");
    // Will revert if msg.sender has insufficient balance
    IERC20(inputToken).safeTransferFrom(msg.sender, address(this), inputAmount);
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(inputToken, outputToken, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);

    /* EFFECTS */
    increaseBalance(inputToken, inputAmount);
    decreaseBalance(outputToken, outputAmount);

    /* INTERACTIONS */
    IERC20(outputToken).safeTransfer(destinationAddress, outputAmount);

    emit Swapped(inputToken, outputToken, destinationAddress, inputAmount, outputAmount, auxiliaryData);
  }

  // Gas optimized - single token balance check for input
  // output is dead-reckoned and scaled back if necessary
  function swap(address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) public virtual override receivedInTime(goodUntil) {
    /* CHECKS */
    require(isToken(inputToken) && isToken(outputToken), "Clipper: Invalid tokens");

    { // Avoid stack too deep
    // Revert if it's signed by the wrong address    
    bytes32 digest = createSwapDigest(inputToken, outputToken, inputAmount, outputAmount, goodUntil, destinationAddress);
    verifyDigestSignature(digest, theSignature);
    }

    // Get fair output value
    uint256 currentInputBalance = tokenBalance(inputToken);
    uint256 actualInput = currentInputBalance-getLastBalance(inputToken);    
    uint256 fairOutput = calculateFairOutput(inputAmount, actualInput, outputAmount);


    /* EFFECTS */
    setBalance(inputToken, currentInputBalance);
    decreaseBalance(outputToken, fairOutput);

    /* INTERACTIONS */
    IERC20(outputToken).safeTransfer(destinationAddress, fairOutput);

    emit Swapped(inputToken, outputToken, destinationAddress, actualInput, fairOutput, auxiliaryData);
  }

}

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

pragma solidity ^0.8.0;

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

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

File 12 of 19 : draft-IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

File 13 of 19 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)

pragma solidity ^0.8.1;

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

        return account.code.length > 0;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    struct SD59x18 {
        int256 value;
    }

    struct UD60x18 {
        uint256 value;
    }

    /// STORAGE ///

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

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

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

    /// FUNCTIONS ///

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

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

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

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

    /// @notice Calculates floor(x*y÷denominator) with full precision.
    ///
    /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv.
    ///
    /// Requirements:
    /// - The denominator cannot be zero.
    /// - The result must fit within uint256.
    ///
    /// Caveats:
    /// - This function does not work with fixed-point numbers.
    ///
    /// @param x The multiplicand as an uint256.
    /// @param y The multiplier as an uint256.
    /// @param denominator The divisor as an uint256.
    /// @return result The result as an uint256.
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
        // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
        // variables such that product = prod1 * 2^256 + prod0.
        uint256 prod0; // Least significant 256 bits of the product
        uint256 prod1; // Most significant 256 bits of the product
        assembly {
            let mm := mulmod(x, y, not(0))
            prod0 := mul(x, y)
            prod1 := sub(sub(mm, prod0), lt(mm, prod0))
        }

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

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

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

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

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

        // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
        // See https://cs.stackexchange.com/q/138556/92363.
        unchecked {
            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 lpotdod = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by lpotdod.
                denominator := div(denominator, lpotdod)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

File 15 of 19 : ClipperCommonExchange.sol
//SPDX-License-Identifier: Copyright 2021 Shipyard Software, Inc.
pragma solidity ^0.8.0;


import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import "./interfaces/WrapperContractInterface.sol";

abstract contract ClipperCommonExchange is ERC20, ReentrancyGuard {

  using SafeERC20 for IERC20;
  using EnumerableSet for EnumerableSet.AddressSet;

  struct Signature {
    uint8 v;
    bytes32 r;
    bytes32 s;
  }

  struct Deposit {
      uint lockedUntil;
      uint256 poolTokenAmount;
  }

  uint256 constant ONE_IN_TEN_DECIMALS = 1e10;
  // Allow for inputs up to 0.5% more than quoted values to have scaled output.
  // Inputs higher than this value just get 0.5% more.
  uint256 constant MAX_ALLOWED_OVER_TEN_DECIMALS = ONE_IN_TEN_DECIMALS+50*1e6;

  // Signer is passed in on construction, hence "immutable"
  address immutable public DESIGNATED_SIGNER;
  address immutable public WRAPPER_CONTRACT;
  // Constant values for EIP-712 signing
  bytes32 immutable DOMAIN_SEPARATOR;
  string constant VERSION = "1.0.0";
  string constant NAME = "ClipperDirect";

  address constant CLIPPER_ETH_SIGIL = address(0);

  bytes32 constant EIP712DOMAIN_TYPEHASH = keccak256(
     abi.encodePacked("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
  );

  bytes32 constant OFFERSTRUCT_TYPEHASH = keccak256(
    abi.encodePacked("OfferStruct(address input_token,address output_token,uint256 input_amount,uint256 output_amount,uint256 good_until,address destination_address)")
  );

  bytes32 constant DEPOSITSTRUCT_TYPEHASH = keccak256(
    abi.encodePacked("DepositStruct(address sender,uint256[] deposit_amounts,uint256 days_locked,uint256 pool_tokens,uint256 good_until)")
  );

  bytes32 constant SINGLEDEPOSITSTRUCT_TYPEHASH = keccak256(
    abi.encodePacked("SingleDepositStruct(address sender,address token,uint256 amount,uint256 days_locked,uint256 pool_tokens,uint256 good_until)")
  );

  bytes32 constant WITHDRAWALSTRUCT_TYPEHASH = keccak256(
    abi.encodePacked("WithdrawalStruct(address token_holder,uint256 pool_token_amount_to_burn,address asset_address,uint256 asset_amount,uint256 good_until)")
  );

  // Assets
  // lastBalances: used for "transmit then swap then sync" modality
  // assetSet is a set of keys that have lastBalances
  mapping(address => uint256) public lastBalances;
  EnumerableSet.AddressSet assetSet;


  // Allows lookup
  mapping(address => Deposit) public vestingDeposits;

  // Events
  event Swapped(
    address indexed inAsset,
    address indexed outAsset,
    address indexed recipient,
    uint256 inAmount,
    uint256 outAmount,
    bytes auxiliaryData
  );

  event Deposited(
    address indexed depositor,
    uint256 poolTokens,
    uint256 nDays
  );

  event Withdrawn(
    address indexed withdrawer,
    uint256 poolTokens,
    uint256 fractionOfPool
  );

  event AssetWithdrawn(
    address indexed withdrawer,
    uint256 poolTokens,    
    address indexed assetAddress,
    uint256 assetAmount
  );

  // Take in the designated signer address and the token list
  constructor(address theSigner, address theWrapper, address[] memory tokens) ERC20("ClipperDirect Pool Token", "CLPRDRPL") {
    DESIGNATED_SIGNER = theSigner;
    uint i;
    uint n = tokens.length;
    while(i < n) {
        assetSet.add(tokens[i]);
        i++;
    }
    DOMAIN_SEPARATOR = createDomainSeparator(NAME, VERSION, address(this));
    WRAPPER_CONTRACT = theWrapper;
  }

  // Allows the receipt of ETH directly
  receive() external payable {
  }

  function safeEthSend(address recipient, uint256 howMuch) internal {
    (bool success, ) = payable(recipient).call{value: howMuch}("");
    require(success, "Call with value failed");
  }

  /* TOKEN AND ASSET FUNCTIONS */
  function nTokens() public view returns (uint) {
    return assetSet.length();
  }

  function tokenAt(uint i) public view returns (address) {
    return assetSet.at(i);
  }

  function isToken(address token) public view returns (bool) {
    return assetSet.contains(token);
  }

  function _sync(address token) internal virtual;

  // Can be overridden as in Caravel
  function getLastBalance(address token) public view virtual returns (uint256) {
    return lastBalances[token];
  }

  function allTokensBalance() external view returns (uint256[] memory, address[] memory, uint256){
    uint n = nTokens();
    uint256[] memory balances = new uint256[](n);
    address[] memory tokens = new address[](n);
    for (uint i = 0; i < n; i++) {
      address token = tokenAt(i);
      balances[i] = getLastBalance(token);
      tokens[i] = token;
    }

    return (balances, tokens, totalSupply());
  }

  // nonReentrant asset transfer
  function transferAsset(address token, address recipient, uint256 amount) internal nonReentrant {
    IERC20(token).safeTransfer(recipient, amount);
    // We never want to transfer an asset without sync'ing
    _sync(token);
  }

  function calculateFairOutput(uint256 statedInput, uint256 actualInput, uint256 statedOutput) internal pure returns (uint256) {
    if(actualInput == statedInput) {
      return statedOutput;
    } else {
      uint256 theFraction = (ONE_IN_TEN_DECIMALS*actualInput)/statedInput;
      if(theFraction >= MAX_ALLOWED_OVER_TEN_DECIMALS) {
        return (MAX_ALLOWED_OVER_TEN_DECIMALS*statedOutput)/ONE_IN_TEN_DECIMALS;
      } else {
        return (theFraction*statedOutput)/ONE_IN_TEN_DECIMALS;
      }
    }
  }

  /* DEPOSIT FUNCTIONALITY */
  function canUnlockDeposit(address theAddress) public view returns (bool) {
      Deposit storage myDeposit = vestingDeposits[theAddress];
      return (myDeposit.poolTokenAmount > 0) && (myDeposit.lockedUntil <= block.timestamp);
  }

  function unlockDeposit() external returns (uint256 poolTokens) {
    require(canUnlockDeposit(msg.sender), "ClipperDirect: Deposit cannot be unlocked");
    poolTokens = vestingDeposits[msg.sender].poolTokenAmount;
    delete vestingDeposits[msg.sender];

    _transfer(address(this), msg.sender, poolTokens);
  }

  function _mintOrVesting(address sender, uint256 nDays, uint256 poolTokens) internal {
    if(nDays==0){
      // No vesting period required - mint tokens directly for the user
      _mint(sender, poolTokens);
    } else {
      // Set up a vesting deposit for the sender
      _createVestingDeposit(sender, nDays, poolTokens);
    }
  }

  // Mints tokens to this contract to hold for vesting
  function _createVestingDeposit(address theAddress, uint256 nDays, uint256 numPoolTokens) internal {
    require(nDays > 0, "ClipperDirect: Cannot create vesting deposit without positive vesting period");
    require(vestingDeposits[theAddress].poolTokenAmount==0, "ClipperDirect: Depositor already has an active deposit");

    Deposit memory myDeposit = Deposit({
      lockedUntil: block.timestamp + (nDays * 1 days),
      poolTokenAmount: numPoolTokens
    });
    vestingDeposits[theAddress] = myDeposit;
    _mint(address(this), numPoolTokens);
  }

  function transmitAndDeposit(uint256[] calldata depositAmounts, uint256 nDays, uint256 poolTokens, uint256 goodUntil, Signature calldata theSignature) external {
    uint i=0;
    uint n = depositAmounts.length;
    while(i < n){
      uint256 transferAmount = depositAmounts[i];
      if(transferAmount > 0){
        IERC20(tokenAt(i)).safeTransferFrom(msg.sender, address(this), transferAmount);
      }
      i++;
    }
    deposit(msg.sender, depositAmounts, nDays, poolTokens, goodUntil, theSignature);
  }

  function transmitAndDepositSingleAsset(address inputToken, uint256 inputAmount, uint256 nDays, uint256 poolTokens, uint256 goodUntil, Signature calldata theSignature) external virtual;

  function deposit(address sender, uint256[] calldata depositAmounts, uint256 nDays, uint256 poolTokens, uint256 goodUntil, Signature calldata theSignature) public payable virtual;

  function depositSingleAsset(address sender, address inputToken, uint256 inputAmount, uint256 nDays, uint256 poolTokens, uint256 goodUntil, Signature calldata theSignature) public payable virtual;

  /* WITHDRAWAL FUNCTIONALITY */
  function _proportionalWithdrawal(uint256 myFraction) internal {
    uint256 toTransfer;

    uint i;
    uint n = nTokens();
    while(i < n) {
        address theToken = tokenAt(i);
        toTransfer = (myFraction*getLastBalance(theToken)) / ONE_IN_TEN_DECIMALS;
        // syncs done automatically on transfer
        transferAsset(theToken, msg.sender, toTransfer);
        i++;
    }
  }

  function burnToWithdraw(uint256 amount) external {
    // Capture the fraction first, before burning
    uint256 theFractionBaseTen = (ONE_IN_TEN_DECIMALS*amount)/totalSupply();
    
    // Reverts if balance is insufficient
    _burn(msg.sender, amount);

    _proportionalWithdrawal(theFractionBaseTen);
    emit Withdrawn(msg.sender, amount, theFractionBaseTen);
  }

  function withdrawSingleAsset(address tokenHolder, uint256 poolTokenAmountToBurn, address assetAddress, uint256 assetAmount, uint256 goodUntil, Signature calldata theSignature) external virtual;

  /* SWAP Functionality: Virtual */
  function sellEthForToken(address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external payable virtual;
  function sellTokenForEth(address inputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external virtual;
  function transmitAndSellTokenForEth(address inputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external virtual;
  function transmitAndSwap(address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) external virtual;
  function swap(address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress, Signature calldata theSignature, bytes calldata auxiliaryData) public virtual;

  /* SIGNING Functionality */
  function createDomainSeparator(string memory name, string memory version, address theSigner) internal view returns (bytes32) {
    return keccak256(abi.encode(
        EIP712DOMAIN_TYPEHASH,
        keccak256(abi.encodePacked(name)),
        keccak256(abi.encodePacked(version)),
        uint256(block.chainid),
        theSigner
      ));
  }

  function hashInputOffer(address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress) internal pure returns (bytes32) {
    return keccak256(abi.encode(
            OFFERSTRUCT_TYPEHASH,
            inputToken,
            outputToken,
            inputAmount,
            outputAmount,
            goodUntil,
            destinationAddress
        ));
  }

  function hashDeposit(address sender, uint256[] calldata depositAmounts, uint256 daysLocked, uint256 poolTokens, uint256 goodUntil) internal pure returns (bytes32) {
    bytes32 depositAmountsHash = keccak256(abi.encodePacked(depositAmounts));
    return keccak256(abi.encode(
        DEPOSITSTRUCT_TYPEHASH,
        sender,
        depositAmountsHash,
        daysLocked,
        poolTokens,
        goodUntil
      ));
  }

  function hashSingleDeposit(address sender, address inputToken, uint256 inputAmount, uint256 daysLocked, uint256 poolTokens, uint256 goodUntil) internal pure returns (bytes32) {
    return keccak256(abi.encode(
        SINGLEDEPOSITSTRUCT_TYPEHASH,
        sender,
        inputToken,
        inputAmount,
        daysLocked,
        poolTokens,
        goodUntil
      ));
  }

  function hashWithdrawal(address tokenHolder, uint256 poolTokenAmountToBurn, address assetAddress, uint256 assetAmount,
                    uint256 goodUntil) internal pure returns (bytes32) {
    return keccak256(abi.encode(
        WITHDRAWALSTRUCT_TYPEHASH,
        tokenHolder,
        poolTokenAmountToBurn,
        assetAddress,
        assetAmount,
        goodUntil
      ));
  }

  function createSwapDigest(address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount, uint256 goodUntil, address destinationAddress) internal view returns (bytes32 digest){
    bytes32 hashedInput = hashInputOffer(inputToken, outputToken, inputAmount, outputAmount, goodUntil, destinationAddress);    
    digest = ECDSA.toTypedDataHash(DOMAIN_SEPARATOR, hashedInput);
  }

  function createDepositDigest(address sender, uint256[] calldata depositAmounts, uint256 nDays, uint256 poolTokens, uint256 goodUntil) internal view returns (bytes32 depositDigest){
    bytes32 hashedInput = hashDeposit(sender, depositAmounts, nDays, poolTokens, goodUntil);    
    depositDigest = ECDSA.toTypedDataHash(DOMAIN_SEPARATOR, hashedInput);
  }

  function createSingleDepositDigest(address sender, address inputToken, uint256 inputAmount, uint256 nDays, uint256 poolTokens, uint256 goodUntil) internal view returns (bytes32 depositDigest){
    bytes32 hashedInput = hashSingleDeposit(sender, inputToken, inputAmount, nDays, poolTokens, goodUntil);
    depositDigest = ECDSA.toTypedDataHash(DOMAIN_SEPARATOR, hashedInput);
  }

  function createWithdrawalDigest(address tokenHolder, uint256 poolTokenAmountToBurn, address assetAddress, uint256 assetAmount,
                    uint256 goodUntil) internal view returns (bytes32 withdrawalDigest){
    bytes32 hashedInput = hashWithdrawal(tokenHolder, poolTokenAmountToBurn, assetAddress, assetAmount, goodUntil);
    withdrawalDigest = ECDSA.toTypedDataHash(DOMAIN_SEPARATOR, hashedInput);
  }

  function verifyDigestSignature(bytes32 theDigest, Signature calldata theSignature) internal view {
    address signingAddress = ecrecover(theDigest, theSignature.v, theSignature.r, theSignature.s);

    require(signingAddress==DESIGNATED_SIGNER, "Message signed by incorrect address");
  }

}

File 16 of 19 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 17 of 19 : ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

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

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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

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

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

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

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

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

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

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

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

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

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

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

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

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

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

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

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

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
        }
        _totalSupply -= amount;

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

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

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

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

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

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

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

File 18 of 19 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS,
        InvalidSignatureV
    }

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        // Check the signature length
        // - case 65: r,s,v signature (standard)
        // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else if (signature.length == 64) {
            bytes32 r;
            bytes32 vs;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                vs := mload(add(signature, 0x40))
            }
            return tryRecover(hash, r, vs);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, signature);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
        uint8 v = uint8((uint256(vs) >> 255) + 27);
        return tryRecover(hash, v, r, s);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     *
     * _Available since v4.2._
     */
    function recover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, r, vs);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS);
        }
        if (v != 27 && v != 28) {
            return (address(0), RecoverError.InvalidSignatureV);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature);
        }

        return (signer, RecoverError.NoError);
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address) {
        (address recovered, RecoverError error) = tryRecover(hash, v, r, s);
        _throwError(error);
        return recovered;
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}

File 19 of 19 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

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

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

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

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

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":"theSigner","type":"address"},{"internalType":"address","name":"theWrapper","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"int256","name":"x","type":"int256"}],"name":"PRBMathSD59x18__Exp2InputTooBig","type":"error"},{"inputs":[{"internalType":"int256","name":"x","type":"int256"}],"name":"PRBMathSD59x18__LogInputTooSmall","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"poolTokens","type":"uint256"},{"indexed":true,"internalType":"address","name":"assetAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"assetAmount","type":"uint256"}],"name":"AssetWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"poolTokens","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nDays","type":"uint256"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"inAsset","type":"address"},{"indexed":true,"internalType":"address","name":"outAsset","type":"address"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"inAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"outAmount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"auxiliaryData","type":"bytes"}],"name":"Swapped","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"withdrawer","type":"address"},{"indexed":false,"internalType":"uint256","name":"poolTokens","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fractionOfPool","type":"uint256"}],"name":"Withdrawn","type":"event"},{"inputs":[],"name":"DESIGNATED_SIGNER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WRAPPER_CONTRACT","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"addAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"allTokensBalance","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"address[]","name":"","type":"address[]"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnToWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"theAddress","type":"address"}],"name":"canUnlockDeposit","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256[]","name":"depositAmounts","type":"uint256[]"},{"internalType":"uint256","name":"nDays","type":"uint256"},{"internalType":"uint256","name":"poolTokens","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"internalType":"uint256","name":"nDays","type":"uint256"},{"internalType":"uint256","name":"poolTokens","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"}],"name":"depositSingleAsset","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"getLastBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"isToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastBalances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"internalType":"address","name":"destinationAddress","type":"address"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"},{"internalType":"bytes","name":"auxiliaryData","type":"bytes"}],"name":"sellEthForToken","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"internalType":"address","name":"destinationAddress","type":"address"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"},{"internalType":"bytes","name":"auxiliaryData","type":"bytes"}],"name":"sellTokenForEth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"internalType":"address","name":"destinationAddress","type":"address"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"},{"internalType":"bytes","name":"auxiliaryData","type":"bytes"}],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"i","type":"uint256"}],"name":"tokenAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"depositAmounts","type":"uint256[]"},{"internalType":"uint256","name":"nDays","type":"uint256"},{"internalType":"uint256","name":"poolTokens","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"}],"name":"transmitAndDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"internalType":"uint256","name":"nDays","type":"uint256"},{"internalType":"uint256","name":"poolTokens","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"}],"name":"transmitAndDepositSingleAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"internalType":"address","name":"destinationAddress","type":"address"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"},{"internalType":"bytes","name":"auxiliaryData","type":"bytes"}],"name":"transmitAndSellTokenForEth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"internalType":"address","name":"destinationAddress","type":"address"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"},{"internalType":"bytes","name":"auxiliaryData","type":"bytes"}],"name":"transmitAndSwap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unlockDeposit","outputs":[{"internalType":"uint256","name":"poolTokens","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"packedGoodUntil","type":"uint256"}],"name":"unpackGoodUntil","outputs":[{"internalType":"uint256","name":"pX","type":"uint256"},{"internalType":"uint256","name":"pY","type":"uint256"},{"internalType":"uint256","name":"wX","type":"uint256"},{"internalType":"uint256","name":"wY","type":"uint256"},{"internalType":"uint256","name":"k","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"vestingDeposits","outputs":[{"internalType":"uint256","name":"lockedUntil","type":"uint256"},{"internalType":"uint256","name":"poolTokenAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenHolder","type":"address"},{"internalType":"uint256","name":"poolTokenAmountToBurn","type":"uint256"},{"internalType":"address","name":"assetAddress","type":"address"},{"internalType":"uint256","name":"assetAmount","type":"uint256"},{"internalType":"uint256","name":"goodUntil","type":"uint256"},{"components":[{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct ClipperCommonExchange.Signature","name":"theSignature","type":"tuple"}],"name":"withdrawSingleAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60e06040523480156200001157600080fd5b506040516200559f3803806200559f83398101604081905262000034916200072f565b8282828282826040518060400160405280601881526020017f436c697070657244697265637420506f6f6c20546f6b656e00000000000000008152506040518060400160405280600881526020016710d314149114941360c21b8152508160039080519060200190620000a992919062000676565b508051620000bf90600490602084019062000676565b50506001600555506001600160601b0319606084901b1660805280516000905b8082101562000141576200012b8383815181106200010d57634e487b7160e01b600052603260045260246000fd5b602002602001015160076200022760201b62001d271790919060201c565b5081620001388162000917565b925050620000df565b620001966040518060400160405280600d81526020016c10db1a5c1c195c911a5c9958dd609a1b815250604051806040016040528060058152602001640312e302e360dc1b815250306200024760201b60201c565b60c05250505060601b6001600160601b03191660a05250620001bf620001b93390565b62000374565b50505060005b81518110156200021d5762000208828281518110620001f457634e487b7160e01b600052603260045260246000fd5b6020026020010151620003c660201b60201c565b80620002148162000917565b915050620001c5565b5050505062000961565b60006200023e836001600160a01b0384166200046e565b90505b92915050565b6000604051602001620002be907f454950373132446f6d61696e28737472696e67206e616d652c737472696e672081527f76657273696f6e2c75696e7432353620636861696e49642c6164647265737320602082015271766572696679696e67436f6e74726163742960701b604082015260520190565b6040516020818303038152906040528051906020012084604051602001620002e791906200086e565b60405160208183030381529060405280519060200120846040516020016200031091906200086e565b60408051601f1981840301815282825280516020918201209083019490945281019190915260608101919091524660808201526001600160a01b03831660a082015260c0016040516020818303038152906040528051906020012090509392505050565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b62000452816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156200040457600080fd5b505afa15801562000419573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200043f919062000844565b60006200044c84620004c0565b62000598565b6001600160a01b03909116600090815260066020526040902055565b6000818152600183016020526040812054620004b75750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915562000241565b50600062000241565b604080513060248083019190915282518083039091018152604490910182526020810180516001600160e01b03166370a0823160e01b1790529051600091829182916001600160a01b038616916200051991906200086e565b600060405180830381855afa9150503d806000811462000556576040519150601f19603f3d011682016040523d82523d6000602084013e6200055b565b606091505b50915091508180156200057057506020815110155b6200057a57600080fd5b808060200190518101906200059091906200082b565b949350505050565b6000620005b0826200060460201b62001d3c1760201c565b6001600160d81b0316620005f863ffffffff60d81b60d886901b167fff0000000000000000000000000000000000000000000000000000000000000060f888901b166200088c565b6200059091906200088c565b60006001600160d81b03821115620006725760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663136206269747360c81b606482015260840160405180910390fd5b5090565b8280546200068490620008da565b90600052602060002090601f016020900481019282620006a85760008555620006f3565b82601f10620006c357805160ff1916838001178555620006f3565b82800160010185558215620006f3579182015b82811115620006f3578251825591602001919060010190620006d6565b50620006729291505b80821115620006725760008155600101620006fc565b80516001600160a01b03811681146200072a57600080fd5b919050565b60008060006060848603121562000744578283fd5b6200074f8462000712565b925060206200076081860162000712565b60408601519093506001600160401b03808211156200077d578384fd5b818701915087601f83011262000791578384fd5b815181811115620007a657620007a66200094b565b8060051b604051601f19603f83011681018181108582111715620007ce57620007ce6200094b565b604052828152858101935084860182860187018c1015620007ed578788fd5b8795505b838610156200081a57620008058162000712565b855260019590950194938601938601620007f1565b508096505050505050509250925092565b6000602082840312156200083d578081fd5b5051919050565b60006020828403121562000856578081fd5b815160ff8116811462000867578182fd5b9392505050565b6000825162000882818460208701620008a7565b9190910192915050565b60008219821115620008a257620008a262000935565b500190565b60005b83811015620008c4578181015183820152602001620008aa565b83811115620008d4576000848401525b50505050565b600181811c90821680620008ef57607f821691505b602082108114156200091157634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156200092e576200092e62000935565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b60805160601c60a05160601c60c051614b7562000a2a600039600081816121fa01526129e301526000818161050d01528181610a5301528181610a7f01528181610acd01528181610b1801528181610b710152818161111c0152818161119e015281816111f10152818161122c015281816112a601528181611327015281816115a2015281816116110152818161173901528181611aaa01528181611af901528181611b4c01528181611b870152611c010152600081816105f5015261229f0152614b756000f3fe6080604052600436106102295760003560e01c80635250d7301161012357806395d89b41116100ab578063c72da66a1161006f578063c72da66a146106f5578063dd62ed3e14610715578063eb1c645314610735578063ecc7633d14610755578063f2fde38b1461078257600080fd5b806395d89b4114610637578063a457c2d71461064c578063a9059cbb1461066c578063c0d5ebfd1461068c578063c325a549146106ac57600080fd5b8063715018a6116100f2578063715018a61461059d57806387e08c25146105b25780638da5cb5b146105c55780638dda8f3f146105e357806392a91a3a1461061757600080fd5b80635250d730146104e85780635aecdda5146104fb57806362fb4e011461054757806370a082311461056757600080fd5b806329d0c8fc116101b15780633721f29c116101755780633721f29c146103f9578063377a368c1461047357806339509351146104885780633b26e4eb146104a85780634cb6864c146104c857600080fd5b806329d0c8fc1461035d5780632b651a6c1461037d578063313ce5671461039d57806334cb3d7f146103b9578063368dfc18146103d957600080fd5b80631b6a8759116101f85780631b6a8759146102cf5780631dc6f5a5146102e457806323b872dd1461030857806327a9b42414610328578063298410e51461033d57600080fd5b806306fdde0314610235578063095ea7b31461026057806318160ddd1461029057806319f37361146102af57600080fd5b3661023057005b600080fd5b34801561024157600080fd5b5061024a6107a2565b604051610257919061488b565b60405180910390f35b34801561026c57600080fd5b5061028061027b366004614566565b610834565b6040519015158152602001610257565b34801561029c57600080fd5b506002545b604051908152602001610257565b3480156102bb57600080fd5b506102806102ca36600461435b565b61084e565b3480156102db57600080fd5b506102a161085b565b3480156102f057600080fd5b506102f961086c565b604051610257939291906147ff565b34801561031457600080fd5b506102806103233660046143a7565b6109d9565b61033b6103363660046145ef565b6109ff565b005b34801561034957600080fd5b5061033b61035836600461435b565b610bd0565b34801561036957600080fd5b5061033b6103783660046146cf565b610bf0565b34801561038957600080fd5b5061033b6103983660046143e2565b610c7c565b3480156103a957600080fd5b5060405160128152602001610257565b3480156103c557600080fd5b506102a16103d436600461435b565b610e0b565b3480156103e557600080fd5b5061033b6103f4366004614751565b610e2f565b34801561040557600080fd5b5061044b610414366004614751565b60c081901c9167ffffffffffffffff608083901c81169261ffff603082901c811693602083901c9091169260409290921c90911690565b604080519586526020860194909452928401919091526060830152608082015260a001610257565b34801561047f57600080fd5b506102a1610ea7565b34801561049457600080fd5b506102806104a3366004614566565b610f3e565b3480156104b457600080fd5b5061033b6104c33660046143e2565b610f60565b3480156104d457600080fd5b5061033b6104e33660046145ef565b6110ce565b61033b6104f63660046144f3565b6112fb565b34801561050757600080fd5b5061052f7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610257565b34801561055357600080fd5b5061033b61056236600461458f565b611508565b34801561057357600080fd5b506102a161058236600461435b565b6001600160a01b031660009081526020819052604090205490565b3480156105a957600080fd5b5061033b6116f9565b61033b6105c0366004614488565b61170d565b3480156105d157600080fd5b50600a546001600160a01b031661052f565b3480156105ef57600080fd5b5061052f7f000000000000000000000000000000000000000000000000000000000000000081565b34801561062357600080fd5b5061052f610632366004614751565b6118a6565b34801561064357600080fd5b5061024a6118b3565b34801561065857600080fd5b50610280610667366004614566565b6118c2565b34801561067857600080fd5b50610280610687366004614566565b611948565b34801561069857600080fd5b5061033b6106a7366004614682565b611956565b3480156106b857600080fd5b506106e06106c736600461435b565b6009602052600090815260409020805460019091015482565b60408051928352602083019190915201610257565b34801561070157600080fd5b5061033b6107103660046145ef565b611a47565b34801561072157600080fd5b506102a1610730366004614375565b611c56565b34801561074157600080fd5b5061028061075036600461435b565b611c81565b34801561076157600080fd5b506102a161077036600461435b565b60066020526000908152604090205481565b34801561078e57600080fd5b5061033b61079d36600461435b565b611cb1565b6060600380546107b190614a94565b80601f01602080910402602001604051908101604052809291908181526020018280546107dd90614a94565b801561082a5780601f106107ff5761010080835404028352916020019161082a565b820191906000526020600020905b81548152906001019060200180831161080d57829003601f168201915b5050505050905090565b600033610842818585611da9565b60019150505b92915050565b6000610848600783611ecd565b60006108676007611eef565b905090565b60608060008061087a61085b565b905060008167ffffffffffffffff8111156108a557634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156108ce578160200160208202803683370190505b50905060008267ffffffffffffffff8111156108fa57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610923578160200160208202803683370190505b50905060005b838110156109bf57600061093c826118a6565b905061094781610e0b565b84838151811061096757634e487b7160e01b600052603260045260246000fd5b6020026020010181815250508083838151811061099457634e487b7160e01b600052603260045260246000fd5b6001600160a01b039092166020928302919091019091015250806109b781614ac9565b915050610929565b5081816109cb60025490565b955095509550505050909192565b6000336109e7858285611ef9565b6109f2858585611f73565b60019150505b9392505050565b8480421115610a295760405162461bcd60e51b8152600401610a20906148be565b60405180910390fd5b610a328961084e565b610a4e5760405162461bcd60e51b8152600401610a20906148e8565b610a787f000000000000000000000000000000000000000000000000000000000000000089612141565b6000610aa87f00000000000000000000000000000000000000000000000000000000000000008b8b8b8b8b6121e2565b9050610ab4818661222b565b610ac2876407915f3c801090565b15610b135742610af57f00000000000000000000000000000000000000000000000000000000000000008b8d8c8c61232a565b1015610b135760405162461bcd60e51b8152600401610a20906148be565b610b3d7f00000000000000000000000000000000000000000000000000000000000000008a612454565b610b478a896124a0565b610b5b6001600160a01b038b16878a6124c4565b856001600160a01b03168a6001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316600080516020614b208339815191528c8c8989604051610bbc9493929190614918565b60405180910390a450505050505050505050565b610bd8612527565b610be3600782611d27565b50610bed81612581565b50565b6000855b80821015610c63576000888884818110610c1e57634e487b7160e01b600052603260045260246000fd5b9050602002013590506000811115610c5057610c50333083610c3f876118a6565b6001600160a01b031692919061261c565b82610c5a81614ac9565b93505050610bf4565b610c72338989898989896112fb565b5050505050505050565b8480421115610c9d5760405162461bcd60e51b8152600401610a20906148be565b610ca68a61084e565b8015610cb65750610cb68961084e565b610cfc5760405162461bcd60e51b8152602060048201526017602482015276436c69707065723a20496e76616c696420746f6b656e7360481b6044820152606401610a20565b6000610d0c8b8b8b8b8b8b6121e2565b9050610d18818661222b565b506000610d248b612654565b90506000610d318c610e0b565b610d3b9083614a51565b90506000610d4a8b838c612724565b9050610d5a896407915f3c801090565b15610d8b5742610d6d8e848f858e61232a565b1015610d8b5760405162461bcd60e51b8152600401610a20906148be565b610d958d846127ad565b610d9f8c826124a0565b610db36001600160a01b038d1689836124c4565b876001600160a01b03168c6001600160a01b03168e6001600160a01b0316600080516020614b2083398151915285858b8b604051610df49493929190614918565b60405180910390a450505050505050505050505050565b6001600160a01b03166000908152600660205260409020546001600160d81b031690565b6000610e3a60025490565b610e49836402540be400614a32565b610e53919061499b565b9050610e5f33836127eb565b610e6881612939565b604080518381526020810183905233917f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc6910160405180910390a25050565b6000610eb233611c81565b610f105760405162461bcd60e51b815260206004820152602960248201527f436c69707065724469726563743a204465706f7369742063616e6e6f74206265604482015268081d5b9b1bd8dad95960ba1b6064820152608401610a20565b50336000818152600960205260408120600181018054918390559190915590610f3b90309083611f73565b90565b600033610842818585610f518383611c56565b610f5b9190614955565b611da9565b8480421115610f815760405162461bcd60e51b8152600401610a20906148be565b610f8a8a61084e565b8015610f9a5750610f9a8961084e565b610fe05760405162461bcd60e51b8152602060048201526017602482015276436c69707065723a20496e76616c696420746f6b656e7360481b6044820152606401610a20565b610ff56001600160a01b038b1633308b61261c565b60006110058b8b8b8b8b8b6121e2565b9050611011818661222b565b61101f876407915f3c801090565b1561105057426110328c8b8d8c8c61232a565b10156110505760405162461bcd60e51b8152600401610a20906148be565b61105a8b8a612454565b6110648a896124a0565b6110786001600160a01b038b16878a6124c4565b856001600160a01b03168a6001600160a01b03168c6001600160a01b0316600080516020614b208339815191528c8c89896040516110b99493929190614918565b60405180910390a45050505050505050505050565b84804211156110ef5760405162461bcd60e51b8152600401610a20906148be565b6110f88961084e565b6111145760405162461bcd60e51b8152600401610a20906148e8565b60006111448a7f00000000000000000000000000000000000000000000000000000000000000008b8b8b8b6121e2565b9050611150818661222b565b600061115b8b612654565b905060006111688c610e0b565b6111729083614a51565b905060006111818c838d612724565b90506111918a6407915f3c801090565b156111e257426111c48e847f0000000000000000000000000000000000000000000000000000000000000000858f61232a565b10156111e25760405162461bcd60e51b8152600401610a20906148be565b6111ec8d846127ad565b6112167f0000000000000000000000000000000000000000000000000000000000000000826124a0565b604051632e1a7d4d60e01b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561127857600080fd5b505af115801561128c573d6000803e3d6000fd5b5050505061129a8982612141565b886001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168e6001600160a01b0316600080516020614b2083398151915285858c8c604051610df49493929190614918565b818042111561131c5760405162461bcd60e51b8152600401610a20906148be565b341561134c5761134c7f000000000000000000000000000000000000000000000000000000000000000034612141565b336001600160a01b038916146113b45760405162461bcd60e51b815260206004820152602760248201527f4c69737465642073656e64657220646f6573206e6f74206d61746368206d73676044820152661739b2b73232b960c91b6064820152608401610a20565b60006113c48989898989896129a1565b90506113d0818461222b565b6000875b808210156114ac5760008a8a848181106113fe57634e487b7160e01b600052603260045260246000fd5b905060200201359050600081111561149957600061141b846118a6565b9050600061142882612654565b90508261143483610e0b565b61143e9083614a51565b101561148c5760405162461bcd60e51b815260206004820152601a60248201527f496e73756666696369656e7420746f6b656e206465706f7369740000000000006044820152606401610a20565b61149682826127ad565b50505b826114a381614ac9565b935050506113d4565b6114b78b89896129b2565b60408051888152602081018a90526001600160a01b038d16917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a25050505050505050505050565b81804211156115295760405162461bcd60e51b8152600401610a20906148be565b336001600160a01b0388161461158f5760405162461bcd60e51b815260206004820152602560248201527f746f6b656e486f6c64657220646f6573206e6f74206d61746368206d73672e7360448201526432b73232b960d91b6064820152608401610a20565b60006001600160a01b0386166115c657507f0000000000000000000000000000000000000000000000000000000000000000945060015b60006115d589898989896129cc565b90506115e1818561222b565b6115eb33896127eb565b6115f587876124a0565b811561168457604051632e1a7d4d60e01b8152600481018790527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561165d57600080fd5b505af1158015611671573d6000803e3d6000fd5b5050505061167f3387612141565b611698565b6116986001600160a01b03881633886124c4565b866001600160a01b0316896001600160a01b03167f41e79959bad1d45680578f8a544fb5af76d72b04090e65a51b4d0eaab959a9ab8a896040516116e6929190918252602082015260400190565b60405180910390a3505050505050505050565b611701612527565b61170b6000612a13565b565b818042111561172e5760405162461bcd60e51b8152600401610a20906148be565b341561175e5761175e7f000000000000000000000000000000000000000000000000000000000000000034612141565b336001600160a01b03891614801561177a575061177a8761084e565b6117b65760405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a59081a5b9c1d5d609a1b6044820152606401610a20565b60006117c6898989898989612a65565b90506117d2818461222b565b60006117dd89612654565b9050876117e98a610e0b565b6117f39083614a51565b10156118415760405162461bcd60e51b815260206004820152601a60248201527f496e73756666696369656e7420746f6b656e206465706f7369740000000000006044820152606401610a20565b61184b89826127ad565b6118568a88886129b2565b60408051878152602081018990526001600160a01b038c16917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a250505050505050505050565b6000610848600783612a76565b6060600480546107b190614a94565b600033816118d08286611c56565b9050838110156119305760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610a20565b61193d8286868403611da9565b506001949350505050565b600033610842818585611f73565b81804211156119775760405162461bcd60e51b8152600401610a20906148be565b6119808761084e565b6119bc5760405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a59081a5b9c1d5d609a1b6044820152606401610a20565b6119d16001600160a01b03881633308961261c565b60006119e1338989898989612a65565b90506119ed818461222b565b6119f78888612454565b611a023387876129b2565b604080518681526020810188905233917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a25050505050505050565b8480421115611a685760405162461bcd60e51b8152600401610a20906148be565b611a718961084e565b611a8d5760405162461bcd60e51b8152600401610a20906148e8565b611aa26001600160a01b038a1633308b61261c565b6000611ad28a7f00000000000000000000000000000000000000000000000000000000000000008b8b8b8b6121e2565b9050611ade818661222b565b611aec876407915f3c801090565b15611b3d5742611b1f8b8b7f00000000000000000000000000000000000000000000000000000000000000008c8c61232a565b1015611b3d5760405162461bcd60e51b8152600401610a20906148be565b611b478a8a612454565b611b717f0000000000000000000000000000000000000000000000000000000000000000896124a0565b604051632e1a7d4d60e01b8152600481018990527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015611bd357600080fd5b505af1158015611be7573d6000803e3d6000fd5b50505050611bf58689612141565b856001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168b6001600160a01b0316600080516020614b208339815191528c8c8989604051610bbc9493929190614918565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b03811660009081526009602052604081206001810154158015906109f857505442101592915050565b611cb9612527565b6001600160a01b038116611d1e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610a20565b610bed81612a13565b60006109f8836001600160a01b038416612a82565b60006001600160d81b03821115611da55760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663136206269747360c81b6064820152608401610a20565b5090565b6001600160a01b038316611e0b5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610a20565b6001600160a01b038216611e6c5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610a20565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038116600090815260018301602052604081205415156109f8565b6000610848825490565b6000611f058484611c56565b90506000198114611f6d5781811015611f605760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610a20565b611f6d8484848403611da9565b50505050565b6001600160a01b038316611fd75760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610a20565b6001600160a01b0382166120395760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610a20565b6001600160a01b038316600090815260208190526040902054818110156120b15760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610a20565b6001600160a01b038085166000908152602081905260408082208585039055918516815290812080548492906120e8908490614955565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161213491815260200190565b60405180910390a3611f6d565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461218e576040519150601f19603f3d011682016040523d82523d6000602084013e612193565b606091505b50509050806121dd5760405162461bcd60e51b815260206004820152601660248201527510d85b1b081dda5d1a081d985b1d594819985a5b195960521b6044820152606401610a20565b505050565b6000806121f3888888888888612ad1565b905061221f7f000000000000000000000000000000000000000000000000000000000000000082612c09565b98975050505050505050565b600060018361223d6020850185614781565b604080516000815260208181018084529490945260ff9092168282015291850135606082015290840135608082015260a0016020604051602081039080840390855afa158015612291573d6000803e3d6000fd5b5050506020604051035190507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316816001600160a01b0316146121dd5760405162461bcd60e51b815260206004820152602360248201527f4d657373616765207369676e656420627920696e636f7272656374206164647260448201526265737360e81b6064820152608401610a20565b60006123576040518060800160405280600081526020016000815260200160008152602001600081525090565b60c083901c67ffffffffffffffff608085901c81169061ffff603087901c811691602088901c90911690604088901c166123908c612c49565b604088015286526123a08a612c49565b6060880152602087015260408601516123fc906123bd908d614a32565b6040880151885188916123cf91614a32565b868a606001518e6123e09190614a32565b898c606001518d602001516123f59190614a32565b8989612cde565b61243d5760405162461bcd60e51b815260206004820152601260248201527110db1a5c1c195c8e88125b9d985c9a585b9d60721b6044820152606401610a20565b505063ffffffff9095169998505050505050505050565b600080600061246285612e93565b9194509250905061247d83836124788785614955565b612f34565b6001600160a01b0390951660009081526006602052604090209490945550505050565b60008060006124ae85612e93565b9194509250905061247d83836124788785614a51565b6040516001600160a01b0383166024820152604481018290526121dd90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612f77565b600a546001600160a01b0316331461170b5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a20565b612600816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156125bd57600080fd5b505afa1580156125d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125f5919061479d565b600061247884612654565b6001600160a01b03909116600090815260066020526040902055565b6040516001600160a01b0380851660248301528316604482015260648101829052611f6d9085906323b872dd60e01b906084016124f0565b604080513060248083019190915282518083039091018152604490910182526020810180516001600160e01b03166370a0823160e01b1790529051600091829182916001600160a01b038616916126ab91906147e3565b600060405180830381855afa9150503d80600081146126e6576040519150601f19603f3d011682016040523d82523d6000602084013e6126eb565b606091505b50915091508180156126ff57506020815110155b61270857600080fd5b8080602001905181019061271c9190614769565b949350505050565b6000838314156127355750806109f8565b600084612747856402540be400614a32565b612751919061499b565b90506127666402540be4006302faf080614955565b811061279d576402540be40083612781826302faf080614955565b61278b9190614a32565b612795919061499b565b9150506109f8565b6402540be40061278b8483614a32565b6000806127b984612e93565b50915091506127c9828285612f34565b6001600160a01b03909416600090815260066020526040902093909355505050565b6001600160a01b03821661284b5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610a20565b6001600160a01b038216600090815260208190526040902054818110156128bf5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610a20565b6001600160a01b03831660009081526020819052604081208383039055600280548492906128ee908490614a51565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b600080600061294661085b565b90505b80821015611f6d57600061295c836118a6565b90506402540be40061296d82610e0b565b6129779087614a32565b612981919061499b565b935061298e813386613049565b8261299881614ac9565b93505050612949565b6000806121f38888888888886130c8565b816129c1576121dd83826131fc565b6121dd8383836132db565b6000806129dc878787878761344f565b9050612a087f000000000000000000000000000000000000000000000000000000000000000082612c09565b979650505050505050565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000806121f388888888888861356c565b60006109f8838361366d565b6000818152600183016020526040812054612ac957508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610848565b506000610848565b6000604051602001612b90907f4f66666572537472756374286164647265737320696e7075745f746f6b656e2c81527f61646472657373206f75747075745f746f6b656e2c75696e7432353620696e7060208201527f75745f616d6f756e742c75696e74323536206f75747075745f616d6f756e742c60408201527f75696e7432353620676f6f645f756e74696c2c6164647265737320646573746960608201526e6e6174696f6e5f616464726573732960881b6080820152608f0190565b60408051601f198184030181528282528051602091820120908301526001600160a01b03808a169183019190915280881660608301526080820187905260a0820186905260c08201859052831660e0820152610100015b6040516020818303038152906040528051906020012090509695505050505050565b60405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b6001600160a01b0381166000908152600660205260408120546001600160d81b038116919060f881901c6012811415612c855760019250612cd7565b6012811015612c9c5780601203600a0a9250612cd7565b60405162461bcd60e51b815260206004820152601060248201526f496e76616c696420646563696d616c7360801b6044820152606401610a20565b5050915091565b60008080806305f5e100612cf28c8e614a32565b612cfc919061499b565b90506000612d13612d0d8c84614a32565b876136a5565b90508015612d455780612d2e83670de0b6b3a7640000614a32565b612d38919061499b565b612d429085614955565b93505b60006305f5e100612d568a8c614a32565b612d60919061499b565b90506000612d77612d718a84614a32565b896136a5565b90508015612da95780612d9283670de0b6b3a7640000614a32565b612d9c919061499b565b612da69087614955565b95505b5050505060006305f5e1008d8c612dc09190614955565b612dca908e614a32565b612dd4919061499b565b90506000612de5612d0d8c84614a32565b90508015612e175780612e0083670de0b6b3a7640000614a32565b612e0a919061499b565b612e149084614955565b92505b60006305f5e100612e288c8b614a51565b612e32908c614a32565b612e3c919061499b565b90506000612e4d612d718a84614a32565b90508015612e7f5780612e6883670de0b6b3a7640000614a32565b612e72919061499b565b612e7c9086614955565b94505b50505091109b9a5050505050505050505050565b6001600160a01b03811660009081526006602052604081205460f881901c91906001600160d81b0381169060d881901c612ecd3243614955565b93508063ffffffff168463ffffffff161415612f2b5760405162461bcd60e51b815260206004820152601d60248201527f436c69707065723a204661696c656420747820756e697175656e6573730000006044820152606401610a20565b50509193909250565b6000612f3f82611d3c565b6001600160d81b0316612f6d63ffffffff60d81b60d886901b166001600160f81b031960f888901b16614955565b61271c9190614955565b6000612fcc826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166136f19092919063ffffffff16565b8051909150156121dd5780806020019051810190612fea9190614731565b6121dd5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a20565b6002600554141561309c5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610a20565b60026005556130b56001600160a01b03841683836124c4565b6130be83612581565b5050600160055550565b60008086866040516020016130de9291906147b9565b604051602081830303815290604052805190602001209050604051602001613190907f4465706f73697453747275637428616464726573732073656e6465722c75696e81527f743235365b5d206465706f7369745f616d6f756e74732c75696e74323536206460208201527f6179735f6c6f636b65642c75696e7432353620706f6f6c5f746f6b656e732c75604082015271696e7432353620676f6f645f756e74696c2960701b606082015260720190565b60408051601f198184030181528282528051602091820120908301526001600160a01b038a1690820152606081018290526080810186905260a0810185905260c0810184905260e001604051602081830303815290604052805190602001209150509695505050505050565b6001600160a01b0382166132525760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610a20565b80600260008282546132649190614955565b90915550506001600160a01b03821660009081526020819052604081208054839290613291908490614955565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b600082116133665760405162461bcd60e51b815260206004820152604c60248201527f436c69707065724469726563743a2043616e6e6f74206372656174652076657360448201527f74696e67206465706f73697420776974686f757420706f73697469766520766560648201526b1cdd1a5b99c81c195c9a5bd960a21b608482015260a401610a20565b6001600160a01b038316600090815260096020526040902060010154156133ee5760405162461bcd60e51b815260206004820152603660248201527f436c69707065724469726563743a204465706f7369746f7220616c7265616479604482015275081a185cc8185b881858dd1a5d994819195c1bdcda5d60521b6064820152608401610a20565b60006040518060400160405280846201518061340a9190614a32565b6134149042614955565b815260209081018490526001600160a01b0386166000908152600982526040902082518155908201516001909101559050611f6d30836131fc565b6000604051602001613505907f5769746864726177616c537472756374286164647265737320746f6b656e5f6881527f6f6c6465722c75696e7432353620706f6f6c5f746f6b656e5f616d6f756e745f60208201527f746f5f6275726e2c616464726573732061737365745f616464726573732c756960408201527f6e743235362061737365745f616d6f756e742c75696e7432353620676f6f645f606082015265756e74696c2960d01b608082015260860190565b60408051808303601f190181528282528051602091820120818401526001600160a01b039889168383015260608301979097529490961660808701525060a085019190915260c0808501919091528151808503909101815260e09093019052815191012090565b6000604051602001613613907f53696e676c654465706f73697453747275637428616464726573732073656e6481527f65722c6164647265737320746f6b656e2c75696e7432353620616d6f756e742c60208201527f75696e7432353620646179735f6c6f636b65642c75696e7432353620706f6f6c60408201527f5f746f6b656e732c75696e7432353620676f6f645f756e74696c2900000000006060820152607b0190565b60408051601f198184030181528282528051602091820120908301526001600160a01b03808a1691830191909152871660608201526080810186905260a0810185905260c0810184905260e0810183905261010001612be7565b600082600001828154811061369257634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905092915050565b6000826136b457506000610848565b6136ea670de0b6b3a76400006136d16136cc86613700565b61376a565b6136db90856149af565b6136e5919061496d565b613775565b9050610848565b606061271c8484600085613788565b60006001600160ff1b03821115611da55760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608401610a20565b6000610848826138ae565b60006108486137838361398d565b613a38565b6060824710156137e95760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a20565b6001600160a01b0385163b6138405760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a20565b600080866001600160a01b0316858760405161385c91906147e3565b60006040518083038185875af1925050503d8060008114613899576040519150601f19603f3d011682016040523d82523d6000602084013e61389e565b606091505b5091509150612a08828286613a8a565b60008082136138d35760405163309fa7dd60e11b815260048101839052602401610a20565b6000670de0b6b3a764000083126138ec57506001613906565b6000199050826ec097ce7bc90715b34b9f10000000000492505b600061391b670de0b6b3a76400008505613ac3565b670de0b6b3a7640000808202945090915084821d9081141561393f57505002919050565b6706f05b59d3b200005b600081131561398457670de0b6b3a7640000828002059150671bc16d674ec80000821261397c579384019360019190911d905b60011d613949565b50505002919050565b6000808212156139ef5768033dd1780914b97114198212156139b157506000919050565b6139bd8260000361398d565b6ec097ce7bc90715b34b9f1000000000816139e857634e487b7160e01b600052601260045260246000fd5b0592915050565b680a688906bd8b0000008212613a1b5760405163e69458f960e01b815260048101839052602401610a20565b670de0b6b3a7640000604083901b046109f881613ba7565b919050565b600080821215611da55760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152606401610a20565b60608315613a995750816109f8565b825115613aa95782518084602001fd5b8160405162461bcd60e51b8152600401610a20919061488b565b6000600160801b8210613ae357608091821c91613ae09082614955565b90505b680100000000000000008210613b0657604091821c91613b039082614955565b90505b6401000000008210613b2557602091821c91613b229082614955565b90505b620100008210613b4257601091821c91613b3f9082614955565b90505b6101008210613b5e57600891821c91613b5b9082614955565b90505b60108210613b7957600491821c91613b769082614955565b90505b60048210613b9457600291821c91613b919082614955565b90505b60028210613a3357610848600182614955565b600160bf1b678000000000000000821615613bcb5768016a09e667f3bcc9090260401c5b674000000000000000821615613bea576801306fe0a31b7152df0260401c5b672000000000000000821615613c09576801172b83c7d517adce0260401c5b671000000000000000821615613c285768010b5586cf9890f62a0260401c5b670800000000000000821615613c47576801059b0d31585743ae0260401c5b670400000000000000821615613c6657680102c9a3e778060ee70260401c5b670200000000000000821615613c855768010163da9fb33356d80260401c5b670100000000000000821615613ca457680100b1afa5abcbed610260401c5b6680000000000000821615613cc25768010058c86da1c09ea20260401c5b6640000000000000821615613ce0576801002c605e2e8cec500260401c5b6620000000000000821615613cfe57680100162f3904051fa10260401c5b6610000000000000821615613d1c576801000b175effdc76ba0260401c5b6608000000000000821615613d3a57680100058ba01fb9f96d0260401c5b6604000000000000821615613d585768010002c5cc37da94920260401c5b6602000000000000821615613d76576801000162e525ee05470260401c5b6601000000000000821615613d945768010000b17255775c040260401c5b65800000000000821615613db1576801000058b91b5bc9ae0260401c5b65400000000000821615613dce57680100002c5c89d5ec6d0260401c5b65200000000000821615613deb5768010000162e43f4f8310260401c5b65100000000000821615613e0857680100000b1721bcfc9a0260401c5b65080000000000821615613e255768010000058b90cf1e6e0260401c5b65040000000000821615613e42576801000002c5c863b73f0260401c5b65020000000000821615613e5f57680100000162e430e5a20260401c5b65010000000000821615613e7c576801000000b1721835510260401c5b648000000000821615613e9857680100000058b90c0b490260401c5b644000000000821615613eb45768010000002c5c8601cc0260401c5b642000000000821615613ed0576801000000162e42fff00260401c5b641000000000821615613eec5768010000000b17217fbb0260401c5b640800000000821615613f08576801000000058b90bfce0260401c5b640400000000821615613f2457680100000002c5c85fe30260401c5b640200000000821615613f405768010000000162e42ff10260401c5b640100000000821615613f5c57680100000000b17217f80260401c5b6380000000821615613f775768010000000058b90bfc0260401c5b6340000000821615613f92576801000000002c5c85fe0260401c5b6320000000821615613fad57680100000000162e42ff0260401c5b6310000000821615613fc8576801000000000b17217f0260401c5b6308000000821615613fe357680100000000058b90c00260401c5b6304000000821615613ffe5768010000000002c5c8600260401c5b6302000000821615614019576801000000000162e4300260401c5b63010000008216156140345768010000000000b172180260401c5b6280000082161561404e576801000000000058b90c0260401c5b6240000082161561406857680100000000002c5c860260401c5b622000008216156140825768010000000000162e430260401c5b6210000082161561409c57680100000000000b17210260401c5b620800008216156140b65768010000000000058b910260401c5b620400008216156140d0576801000000000002c5c80260401c5b620200008216156140ea57680100000000000162e40260401c5b62010000821615614104576801000000000000b1720260401c5b61800082161561411d57680100000000000058b90260401c5b6140008216156141365768010000000000002c5d0260401c5b61200082161561414f576801000000000000162e0260401c5b6110008216156141685768010000000000000b170260401c5b610800821615614181576801000000000000058c0260401c5b61040082161561419a57680100000000000002c60260401c5b6102008216156141b357680100000000000001630260401c5b6101008216156141cc57680100000000000000b10260401c5b60808216156141e457680100000000000000590260401c5b60408216156141fc576801000000000000002c0260401c5b602082161561421457680100000000000000160260401c5b601082161561422c576801000000000000000b0260401c5b600882161561424457680100000000000000060260401c5b600482161561425c57680100000000000000030260401c5b600282161561427457680100000000000000010260401c5b600182161561428c57680100000000000000010260401c5b670de0b6b3a76400000260409190911c60bf031c90565b80356001600160a01b0381168114613a3357600080fd5b60008083601f8401126142cb578182fd5b50813567ffffffffffffffff8111156142e2578182fd5b6020830191508360208260051b85010111156142fd57600080fd5b9250929050565b60008083601f840112614315578182fd5b50813567ffffffffffffffff81111561432c578182fd5b6020830191508360208285010111156142fd57600080fd5b600060608284031215614355578081fd5b50919050565b60006020828403121561436c578081fd5b6109f8826142a3565b60008060408385031215614387578081fd5b614390836142a3565b915061439e602084016142a3565b90509250929050565b6000806000606084860312156143bb578081fd5b6143c4846142a3565b92506143d2602085016142a3565b9150604084013590509250925092565b60008060008060008060008060006101408a8c031215614400578485fd5b6144098a6142a3565b985061441760208b016142a3565b975060408a0135965060608a0135955060808a0135945061443a60a08b016142a3565b93506144498b60c08c01614344565b92506101208a013567ffffffffffffffff811115614465578283fd5b6144718c828d01614304565b915080935050809150509295985092959850929598565b6000806000806000806000610120888a0312156144a3578283fd5b6144ac886142a3565b96506144ba602089016142a3565b955060408801359450606088013593506080880135925060a088013591506144e58960c08a01614344565b905092959891949750929550565b6000806000806000806000610100888a03121561450e578283fd5b614517886142a3565b9650602088013567ffffffffffffffff811115614532578384fd5b61453e8a828b016142ba565b9097509550506040880135935060608801359250608088013591506144e58960a08a01614344565b60008060408385031215614578578182fd5b614581836142a3565b946020939093013593505050565b60008060008060008061010087890312156145a8578182fd5b6145b1876142a3565b9550602087013594506145c6604088016142a3565b935060608701359250608087013591506145e38860a08901614344565b90509295509295509295565b600080600080600080600080610120898b03121561460b578182fd5b614614896142a3565b975060208901359650604089013595506060890135945061463760808a016142a3565b93506146468a60a08b01614344565b925061010089013567ffffffffffffffff811115614662578283fd5b61466e8b828c01614304565b999c989b5096995094979396929594505050565b600080600080600080610100878903121561469b578384fd5b6146a4876142a3565b9550602087013594506040870135935060608701359250608087013591506145e38860a08901614344565b60008060008060008060e087890312156146e7578384fd5b863567ffffffffffffffff8111156146fd578485fd5b61470989828a016142ba565b9097509550506020870135935060408701359250606087013591506145e38860808901614344565b600060208284031215614742578081fd5b815180151581146109f8578182fd5b600060208284031215614762578081fd5b5035919050565b60006020828403121561477a578081fd5b5051919050565b600060208284031215614792578081fd5b81356109f881614b10565b6000602082840312156147ae578081fd5b81516109f881614b10565b60006001600160fb1b038311156147ce578081fd5b8260051b808584379190910190815292915050565b600082516147f5818460208701614a68565b9190910192915050565b606080825284519082018190526000906020906080840190828801845b828110156148385781518452928401929084019060010161481c565b50505083810382850152855180825286830191830190845b818110156148755783516001600160a01b031683529284019291840191600101614850565b5050809350505050826040830152949350505050565b60208152600082518060208401526148aa816040850160208701614a68565b601f01601f19169190910160400192915050565b60208082526010908201526f10db1a5c1c195c8e88115e1c1a5c995960821b604082015260600190565b60208082526016908201527521b634b83832b91d1024b73b30b634b2103a37b5b2b760511b604082015260600190565b84815283602082015260606040820152816060820152818360808301376000818301608090810191909152601f909201601f191601019392505050565b6000821982111561496857614968614ae4565b500190565b60008261497c5761497c614afa565b600160ff1b82146000198414161561499657614996614ae4565b500590565b6000826149aa576149aa614afa565b500490565b60006001600160ff1b03818413828413808216868404861116156149d5576149d5614ae4565b600160ff1b848712828116878305891216156149f3576149f3614ae4565b858712925087820587128484161615614a0e57614a0e614ae4565b87850587128184161615614a2457614a24614ae4565b505050929093029392505050565b6000816000190483118215151615614a4c57614a4c614ae4565b500290565b600082821015614a6357614a63614ae4565b500390565b60005b83811015614a83578181015183820152602001614a6b565b83811115611f6d5750506000910152565b600181811c90821680614aa857607f821691505b6020821081141561435557634e487b7160e01b600052602260045260246000fd5b6000600019821415614add57614add614ae4565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b60ff81168114610bed57600080fdfe4be05c8d54f5e056ab2cfa033e9f582057001268c3e28561bb999d35d2c8f2c8a264697066735822122054eacf1c3231a2523257c519d79262964b4be9e403a0eb5ad3c52aa89ebbc4e264736f6c6343000804003300000000000000000000000008938a61ba9523298dbcacee0cda5b371fb7f1f8000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000050000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

Deployed Bytecode

0x6080604052600436106102295760003560e01c80635250d7301161012357806395d89b41116100ab578063c72da66a1161006f578063c72da66a146106f5578063dd62ed3e14610715578063eb1c645314610735578063ecc7633d14610755578063f2fde38b1461078257600080fd5b806395d89b4114610637578063a457c2d71461064c578063a9059cbb1461066c578063c0d5ebfd1461068c578063c325a549146106ac57600080fd5b8063715018a6116100f2578063715018a61461059d57806387e08c25146105b25780638da5cb5b146105c55780638dda8f3f146105e357806392a91a3a1461061757600080fd5b80635250d730146104e85780635aecdda5146104fb57806362fb4e011461054757806370a082311461056757600080fd5b806329d0c8fc116101b15780633721f29c116101755780633721f29c146103f9578063377a368c1461047357806339509351146104885780633b26e4eb146104a85780634cb6864c146104c857600080fd5b806329d0c8fc1461035d5780632b651a6c1461037d578063313ce5671461039d57806334cb3d7f146103b9578063368dfc18146103d957600080fd5b80631b6a8759116101f85780631b6a8759146102cf5780631dc6f5a5146102e457806323b872dd1461030857806327a9b42414610328578063298410e51461033d57600080fd5b806306fdde0314610235578063095ea7b31461026057806318160ddd1461029057806319f37361146102af57600080fd5b3661023057005b600080fd5b34801561024157600080fd5b5061024a6107a2565b604051610257919061488b565b60405180910390f35b34801561026c57600080fd5b5061028061027b366004614566565b610834565b6040519015158152602001610257565b34801561029c57600080fd5b506002545b604051908152602001610257565b3480156102bb57600080fd5b506102806102ca36600461435b565b61084e565b3480156102db57600080fd5b506102a161085b565b3480156102f057600080fd5b506102f961086c565b604051610257939291906147ff565b34801561031457600080fd5b506102806103233660046143a7565b6109d9565b61033b6103363660046145ef565b6109ff565b005b34801561034957600080fd5b5061033b61035836600461435b565b610bd0565b34801561036957600080fd5b5061033b6103783660046146cf565b610bf0565b34801561038957600080fd5b5061033b6103983660046143e2565b610c7c565b3480156103a957600080fd5b5060405160128152602001610257565b3480156103c557600080fd5b506102a16103d436600461435b565b610e0b565b3480156103e557600080fd5b5061033b6103f4366004614751565b610e2f565b34801561040557600080fd5b5061044b610414366004614751565b60c081901c9167ffffffffffffffff608083901c81169261ffff603082901c811693602083901c9091169260409290921c90911690565b604080519586526020860194909452928401919091526060830152608082015260a001610257565b34801561047f57600080fd5b506102a1610ea7565b34801561049457600080fd5b506102806104a3366004614566565b610f3e565b3480156104b457600080fd5b5061033b6104c33660046143e2565b610f60565b3480156104d457600080fd5b5061033b6104e33660046145ef565b6110ce565b61033b6104f63660046144f3565b6112fb565b34801561050757600080fd5b5061052f7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6040516001600160a01b039091168152602001610257565b34801561055357600080fd5b5061033b61056236600461458f565b611508565b34801561057357600080fd5b506102a161058236600461435b565b6001600160a01b031660009081526020819052604090205490565b3480156105a957600080fd5b5061033b6116f9565b61033b6105c0366004614488565b61170d565b3480156105d157600080fd5b50600a546001600160a01b031661052f565b3480156105ef57600080fd5b5061052f7f00000000000000000000000008938a61ba9523298dbcacee0cda5b371fb7f1f881565b34801561062357600080fd5b5061052f610632366004614751565b6118a6565b34801561064357600080fd5b5061024a6118b3565b34801561065857600080fd5b50610280610667366004614566565b6118c2565b34801561067857600080fd5b50610280610687366004614566565b611948565b34801561069857600080fd5b5061033b6106a7366004614682565b611956565b3480156106b857600080fd5b506106e06106c736600461435b565b6009602052600090815260409020805460019091015482565b60408051928352602083019190915201610257565b34801561070157600080fd5b5061033b6107103660046145ef565b611a47565b34801561072157600080fd5b506102a1610730366004614375565b611c56565b34801561074157600080fd5b5061028061075036600461435b565b611c81565b34801561076157600080fd5b506102a161077036600461435b565b60066020526000908152604090205481565b34801561078e57600080fd5b5061033b61079d36600461435b565b611cb1565b6060600380546107b190614a94565b80601f01602080910402602001604051908101604052809291908181526020018280546107dd90614a94565b801561082a5780601f106107ff5761010080835404028352916020019161082a565b820191906000526020600020905b81548152906001019060200180831161080d57829003601f168201915b5050505050905090565b600033610842818585611da9565b60019150505b92915050565b6000610848600783611ecd565b60006108676007611eef565b905090565b60608060008061087a61085b565b905060008167ffffffffffffffff8111156108a557634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156108ce578160200160208202803683370190505b50905060008267ffffffffffffffff8111156108fa57634e487b7160e01b600052604160045260246000fd5b604051908082528060200260200182016040528015610923578160200160208202803683370190505b50905060005b838110156109bf57600061093c826118a6565b905061094781610e0b565b84838151811061096757634e487b7160e01b600052603260045260246000fd5b6020026020010181815250508083838151811061099457634e487b7160e01b600052603260045260246000fd5b6001600160a01b039092166020928302919091019091015250806109b781614ac9565b915050610929565b5081816109cb60025490565b955095509550505050909192565b6000336109e7858285611ef9565b6109f2858585611f73565b60019150505b9392505050565b8480421115610a295760405162461bcd60e51b8152600401610a20906148be565b60405180910390fd5b610a328961084e565b610a4e5760405162461bcd60e51b8152600401610a20906148e8565b610a787f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc289612141565b6000610aa87f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28b8b8b8b8b6121e2565b9050610ab4818661222b565b610ac2876407915f3c801090565b15610b135742610af57f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28b8d8c8c61232a565b1015610b135760405162461bcd60e51b8152600401610a20906148be565b610b3d7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28a612454565b610b478a896124a0565b610b5b6001600160a01b038b16878a6124c4565b856001600160a01b03168a6001600160a01b03167f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316600080516020614b208339815191528c8c8989604051610bbc9493929190614918565b60405180910390a450505050505050505050565b610bd8612527565b610be3600782611d27565b50610bed81612581565b50565b6000855b80821015610c63576000888884818110610c1e57634e487b7160e01b600052603260045260246000fd5b9050602002013590506000811115610c5057610c50333083610c3f876118a6565b6001600160a01b031692919061261c565b82610c5a81614ac9565b93505050610bf4565b610c72338989898989896112fb565b5050505050505050565b8480421115610c9d5760405162461bcd60e51b8152600401610a20906148be565b610ca68a61084e565b8015610cb65750610cb68961084e565b610cfc5760405162461bcd60e51b8152602060048201526017602482015276436c69707065723a20496e76616c696420746f6b656e7360481b6044820152606401610a20565b6000610d0c8b8b8b8b8b8b6121e2565b9050610d18818661222b565b506000610d248b612654565b90506000610d318c610e0b565b610d3b9083614a51565b90506000610d4a8b838c612724565b9050610d5a896407915f3c801090565b15610d8b5742610d6d8e848f858e61232a565b1015610d8b5760405162461bcd60e51b8152600401610a20906148be565b610d958d846127ad565b610d9f8c826124a0565b610db36001600160a01b038d1689836124c4565b876001600160a01b03168c6001600160a01b03168e6001600160a01b0316600080516020614b2083398151915285858b8b604051610df49493929190614918565b60405180910390a450505050505050505050505050565b6001600160a01b03166000908152600660205260409020546001600160d81b031690565b6000610e3a60025490565b610e49836402540be400614a32565b610e53919061499b565b9050610e5f33836127eb565b610e6881612939565b604080518381526020810183905233917f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc6910160405180910390a25050565b6000610eb233611c81565b610f105760405162461bcd60e51b815260206004820152602960248201527f436c69707065724469726563743a204465706f7369742063616e6e6f74206265604482015268081d5b9b1bd8dad95960ba1b6064820152608401610a20565b50336000818152600960205260408120600181018054918390559190915590610f3b90309083611f73565b90565b600033610842818585610f518383611c56565b610f5b9190614955565b611da9565b8480421115610f815760405162461bcd60e51b8152600401610a20906148be565b610f8a8a61084e565b8015610f9a5750610f9a8961084e565b610fe05760405162461bcd60e51b8152602060048201526017602482015276436c69707065723a20496e76616c696420746f6b656e7360481b6044820152606401610a20565b610ff56001600160a01b038b1633308b61261c565b60006110058b8b8b8b8b8b6121e2565b9050611011818661222b565b61101f876407915f3c801090565b1561105057426110328c8b8d8c8c61232a565b10156110505760405162461bcd60e51b8152600401610a20906148be565b61105a8b8a612454565b6110648a896124a0565b6110786001600160a01b038b16878a6124c4565b856001600160a01b03168a6001600160a01b03168c6001600160a01b0316600080516020614b208339815191528c8c89896040516110b99493929190614918565b60405180910390a45050505050505050505050565b84804211156110ef5760405162461bcd60e51b8152600401610a20906148be565b6110f88961084e565b6111145760405162461bcd60e51b8152600401610a20906148e8565b60006111448a7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28b8b8b8b6121e2565b9050611150818661222b565b600061115b8b612654565b905060006111688c610e0b565b6111729083614a51565b905060006111818c838d612724565b90506111918a6407915f3c801090565b156111e257426111c48e847f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2858f61232a565b10156111e25760405162461bcd60e51b8152600401610a20906148be565b6111ec8d846127ad565b6112167f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2826124a0565b604051632e1a7d4d60e01b8152600481018290527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561127857600080fd5b505af115801561128c573d6000803e3d6000fd5b5050505061129a8982612141565b886001600160a01b03167f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b03168e6001600160a01b0316600080516020614b2083398151915285858c8c604051610df49493929190614918565b818042111561131c5760405162461bcd60e51b8152600401610a20906148be565b341561134c5761134c7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc234612141565b336001600160a01b038916146113b45760405162461bcd60e51b815260206004820152602760248201527f4c69737465642073656e64657220646f6573206e6f74206d61746368206d73676044820152661739b2b73232b960c91b6064820152608401610a20565b60006113c48989898989896129a1565b90506113d0818461222b565b6000875b808210156114ac5760008a8a848181106113fe57634e487b7160e01b600052603260045260246000fd5b905060200201359050600081111561149957600061141b846118a6565b9050600061142882612654565b90508261143483610e0b565b61143e9083614a51565b101561148c5760405162461bcd60e51b815260206004820152601a60248201527f496e73756666696369656e7420746f6b656e206465706f7369740000000000006044820152606401610a20565b61149682826127ad565b50505b826114a381614ac9565b935050506113d4565b6114b78b89896129b2565b60408051888152602081018a90526001600160a01b038d16917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a25050505050505050505050565b81804211156115295760405162461bcd60e51b8152600401610a20906148be565b336001600160a01b0388161461158f5760405162461bcd60e51b815260206004820152602560248201527f746f6b656e486f6c64657220646f6573206e6f74206d61746368206d73672e7360448201526432b73232b960d91b6064820152608401610a20565b60006001600160a01b0386166115c657507f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2945060015b60006115d589898989896129cc565b90506115e1818561222b565b6115eb33896127eb565b6115f587876124a0565b811561168457604051632e1a7d4d60e01b8152600481018790527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b15801561165d57600080fd5b505af1158015611671573d6000803e3d6000fd5b5050505061167f3387612141565b611698565b6116986001600160a01b03881633886124c4565b866001600160a01b0316896001600160a01b03167f41e79959bad1d45680578f8a544fb5af76d72b04090e65a51b4d0eaab959a9ab8a896040516116e6929190918252602082015260400190565b60405180910390a3505050505050505050565b611701612527565b61170b6000612a13565b565b818042111561172e5760405162461bcd60e51b8152600401610a20906148be565b341561175e5761175e7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc234612141565b336001600160a01b03891614801561177a575061177a8761084e565b6117b65760405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a59081a5b9c1d5d609a1b6044820152606401610a20565b60006117c6898989898989612a65565b90506117d2818461222b565b60006117dd89612654565b9050876117e98a610e0b565b6117f39083614a51565b10156118415760405162461bcd60e51b815260206004820152601a60248201527f496e73756666696369656e7420746f6b656e206465706f7369740000000000006044820152606401610a20565b61184b89826127ad565b6118568a88886129b2565b60408051878152602081018990526001600160a01b038c16917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a250505050505050505050565b6000610848600783612a76565b6060600480546107b190614a94565b600033816118d08286611c56565b9050838110156119305760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610a20565b61193d8286868403611da9565b506001949350505050565b600033610842818585611f73565b81804211156119775760405162461bcd60e51b8152600401610a20906148be565b6119808761084e565b6119bc5760405162461bcd60e51b815260206004820152600d60248201526c125b9d985b1a59081a5b9c1d5d609a1b6044820152606401610a20565b6119d16001600160a01b03881633308961261c565b60006119e1338989898989612a65565b90506119ed818461222b565b6119f78888612454565b611a023387876129b2565b604080518681526020810188905233917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a25050505050505050565b8480421115611a685760405162461bcd60e51b8152600401610a20906148be565b611a718961084e565b611a8d5760405162461bcd60e51b8152600401610a20906148e8565b611aa26001600160a01b038a1633308b61261c565b6000611ad28a7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28b8b8b8b6121e2565b9050611ade818661222b565b611aec876407915f3c801090565b15611b3d5742611b1f8b8b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28c8c61232a565b1015611b3d5760405162461bcd60e51b8152600401610a20906148be565b611b478a8a612454565b611b717f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2896124a0565b604051632e1a7d4d60e01b8152600481018990527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015611bd357600080fd5b505af1158015611be7573d6000803e3d6000fd5b50505050611bf58689612141565b856001600160a01b03167f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b03168b6001600160a01b0316600080516020614b208339815191528c8c8989604051610bbc9493929190614918565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b03811660009081526009602052604081206001810154158015906109f857505442101592915050565b611cb9612527565b6001600160a01b038116611d1e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610a20565b610bed81612a13565b60006109f8836001600160a01b038416612a82565b60006001600160d81b03821115611da55760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20326044820152663136206269747360c81b6064820152608401610a20565b5090565b6001600160a01b038316611e0b5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610a20565b6001600160a01b038216611e6c5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610a20565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038116600090815260018301602052604081205415156109f8565b6000610848825490565b6000611f058484611c56565b90506000198114611f6d5781811015611f605760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401610a20565b611f6d8484848403611da9565b50505050565b6001600160a01b038316611fd75760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610a20565b6001600160a01b0382166120395760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610a20565b6001600160a01b038316600090815260208190526040902054818110156120b15760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610a20565b6001600160a01b038085166000908152602081905260408082208585039055918516815290812080548492906120e8908490614955565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161213491815260200190565b60405180910390a3611f6d565b6000826001600160a01b03168260405160006040518083038185875af1925050503d806000811461218e576040519150601f19603f3d011682016040523d82523d6000602084013e612193565b606091505b50509050806121dd5760405162461bcd60e51b815260206004820152601660248201527510d85b1b081dda5d1a081d985b1d594819985a5b195960521b6044820152606401610a20565b505050565b6000806121f3888888888888612ad1565b905061221f7faca1869732de658f8d0e60c8b1d1fe4261c5b45296c1b72dc1d035c354a49f1d82612c09565b98975050505050505050565b600060018361223d6020850185614781565b604080516000815260208181018084529490945260ff9092168282015291850135606082015290840135608082015260a0016020604051602081039080840390855afa158015612291573d6000803e3d6000fd5b5050506020604051035190507f00000000000000000000000008938a61ba9523298dbcacee0cda5b371fb7f1f86001600160a01b0316816001600160a01b0316146121dd5760405162461bcd60e51b815260206004820152602360248201527f4d657373616765207369676e656420627920696e636f7272656374206164647260448201526265737360e81b6064820152608401610a20565b60006123576040518060800160405280600081526020016000815260200160008152602001600081525090565b60c083901c67ffffffffffffffff608085901c81169061ffff603087901c811691602088901c90911690604088901c166123908c612c49565b604088015286526123a08a612c49565b6060880152602087015260408601516123fc906123bd908d614a32565b6040880151885188916123cf91614a32565b868a606001518e6123e09190614a32565b898c606001518d602001516123f59190614a32565b8989612cde565b61243d5760405162461bcd60e51b815260206004820152601260248201527110db1a5c1c195c8e88125b9d985c9a585b9d60721b6044820152606401610a20565b505063ffffffff9095169998505050505050505050565b600080600061246285612e93565b9194509250905061247d83836124788785614955565b612f34565b6001600160a01b0390951660009081526006602052604090209490945550505050565b60008060006124ae85612e93565b9194509250905061247d83836124788785614a51565b6040516001600160a01b0383166024820152604481018290526121dd90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612f77565b600a546001600160a01b0316331461170b5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610a20565b612600816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156125bd57600080fd5b505afa1580156125d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125f5919061479d565b600061247884612654565b6001600160a01b03909116600090815260066020526040902055565b6040516001600160a01b0380851660248301528316604482015260648101829052611f6d9085906323b872dd60e01b906084016124f0565b604080513060248083019190915282518083039091018152604490910182526020810180516001600160e01b03166370a0823160e01b1790529051600091829182916001600160a01b038616916126ab91906147e3565b600060405180830381855afa9150503d80600081146126e6576040519150601f19603f3d011682016040523d82523d6000602084013e6126eb565b606091505b50915091508180156126ff57506020815110155b61270857600080fd5b8080602001905181019061271c9190614769565b949350505050565b6000838314156127355750806109f8565b600084612747856402540be400614a32565b612751919061499b565b90506127666402540be4006302faf080614955565b811061279d576402540be40083612781826302faf080614955565b61278b9190614a32565b612795919061499b565b9150506109f8565b6402540be40061278b8483614a32565b6000806127b984612e93565b50915091506127c9828285612f34565b6001600160a01b03909416600090815260066020526040902093909355505050565b6001600160a01b03821661284b5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b6064820152608401610a20565b6001600160a01b038216600090815260208190526040902054818110156128bf5760405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e604482015261636560f01b6064820152608401610a20565b6001600160a01b03831660009081526020819052604081208383039055600280548492906128ee908490614a51565b90915550506040518281526000906001600160a01b038516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b600080600061294661085b565b90505b80821015611f6d57600061295c836118a6565b90506402540be40061296d82610e0b565b6129779087614a32565b612981919061499b565b935061298e813386613049565b8261299881614ac9565b93505050612949565b6000806121f38888888888886130c8565b816129c1576121dd83826131fc565b6121dd8383836132db565b6000806129dc878787878761344f565b9050612a087faca1869732de658f8d0e60c8b1d1fe4261c5b45296c1b72dc1d035c354a49f1d82612c09565b979650505050505050565b600a80546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6000806121f388888888888861356c565b60006109f8838361366d565b6000818152600183016020526040812054612ac957508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610848565b506000610848565b6000604051602001612b90907f4f66666572537472756374286164647265737320696e7075745f746f6b656e2c81527f61646472657373206f75747075745f746f6b656e2c75696e7432353620696e7060208201527f75745f616d6f756e742c75696e74323536206f75747075745f616d6f756e742c60408201527f75696e7432353620676f6f645f756e74696c2c6164647265737320646573746960608201526e6e6174696f6e5f616464726573732960881b6080820152608f0190565b60408051601f198184030181528282528051602091820120908301526001600160a01b03808a169183019190915280881660608301526080820187905260a0820186905260c08201859052831660e0820152610100015b6040516020818303038152906040528051906020012090509695505050505050565b60405161190160f01b6020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b6001600160a01b0381166000908152600660205260408120546001600160d81b038116919060f881901c6012811415612c855760019250612cd7565b6012811015612c9c5780601203600a0a9250612cd7565b60405162461bcd60e51b815260206004820152601060248201526f496e76616c696420646563696d616c7360801b6044820152606401610a20565b5050915091565b60008080806305f5e100612cf28c8e614a32565b612cfc919061499b565b90506000612d13612d0d8c84614a32565b876136a5565b90508015612d455780612d2e83670de0b6b3a7640000614a32565b612d38919061499b565b612d429085614955565b93505b60006305f5e100612d568a8c614a32565b612d60919061499b565b90506000612d77612d718a84614a32565b896136a5565b90508015612da95780612d9283670de0b6b3a7640000614a32565b612d9c919061499b565b612da69087614955565b95505b5050505060006305f5e1008d8c612dc09190614955565b612dca908e614a32565b612dd4919061499b565b90506000612de5612d0d8c84614a32565b90508015612e175780612e0083670de0b6b3a7640000614a32565b612e0a919061499b565b612e149084614955565b92505b60006305f5e100612e288c8b614a51565b612e32908c614a32565b612e3c919061499b565b90506000612e4d612d718a84614a32565b90508015612e7f5780612e6883670de0b6b3a7640000614a32565b612e72919061499b565b612e7c9086614955565b94505b50505091109b9a5050505050505050505050565b6001600160a01b03811660009081526006602052604081205460f881901c91906001600160d81b0381169060d881901c612ecd3243614955565b93508063ffffffff168463ffffffff161415612f2b5760405162461bcd60e51b815260206004820152601d60248201527f436c69707065723a204661696c656420747820756e697175656e6573730000006044820152606401610a20565b50509193909250565b6000612f3f82611d3c565b6001600160d81b0316612f6d63ffffffff60d81b60d886901b166001600160f81b031960f888901b16614955565b61271c9190614955565b6000612fcc826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166136f19092919063ffffffff16565b8051909150156121dd5780806020019051810190612fea9190614731565b6121dd5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610a20565b6002600554141561309c5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610a20565b60026005556130b56001600160a01b03841683836124c4565b6130be83612581565b5050600160055550565b60008086866040516020016130de9291906147b9565b604051602081830303815290604052805190602001209050604051602001613190907f4465706f73697453747275637428616464726573732073656e6465722c75696e81527f743235365b5d206465706f7369745f616d6f756e74732c75696e74323536206460208201527f6179735f6c6f636b65642c75696e7432353620706f6f6c5f746f6b656e732c75604082015271696e7432353620676f6f645f756e74696c2960701b606082015260720190565b60408051601f198184030181528282528051602091820120908301526001600160a01b038a1690820152606081018290526080810186905260a0810185905260c0810184905260e001604051602081830303815290604052805190602001209150509695505050505050565b6001600160a01b0382166132525760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401610a20565b80600260008282546132649190614955565b90915550506001600160a01b03821660009081526020819052604081208054839290613291908490614955565b90915550506040518181526001600160a01b038316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b600082116133665760405162461bcd60e51b815260206004820152604c60248201527f436c69707065724469726563743a2043616e6e6f74206372656174652076657360448201527f74696e67206465706f73697420776974686f757420706f73697469766520766560648201526b1cdd1a5b99c81c195c9a5bd960a21b608482015260a401610a20565b6001600160a01b038316600090815260096020526040902060010154156133ee5760405162461bcd60e51b815260206004820152603660248201527f436c69707065724469726563743a204465706f7369746f7220616c7265616479604482015275081a185cc8185b881858dd1a5d994819195c1bdcda5d60521b6064820152608401610a20565b60006040518060400160405280846201518061340a9190614a32565b6134149042614955565b815260209081018490526001600160a01b0386166000908152600982526040902082518155908201516001909101559050611f6d30836131fc565b6000604051602001613505907f5769746864726177616c537472756374286164647265737320746f6b656e5f6881527f6f6c6465722c75696e7432353620706f6f6c5f746f6b656e5f616d6f756e745f60208201527f746f5f6275726e2c616464726573732061737365745f616464726573732c756960408201527f6e743235362061737365745f616d6f756e742c75696e7432353620676f6f645f606082015265756e74696c2960d01b608082015260860190565b60408051808303601f190181528282528051602091820120818401526001600160a01b039889168383015260608301979097529490961660808701525060a085019190915260c0808501919091528151808503909101815260e09093019052815191012090565b6000604051602001613613907f53696e676c654465706f73697453747275637428616464726573732073656e6481527f65722c6164647265737320746f6b656e2c75696e7432353620616d6f756e742c60208201527f75696e7432353620646179735f6c6f636b65642c75696e7432353620706f6f6c60408201527f5f746f6b656e732c75696e7432353620676f6f645f756e74696c2900000000006060820152607b0190565b60408051601f198184030181528282528051602091820120908301526001600160a01b03808a1691830191909152871660608201526080810186905260a0810185905260c0810184905260e0810183905261010001612be7565b600082600001828154811061369257634e487b7160e01b600052603260045260246000fd5b9060005260206000200154905092915050565b6000826136b457506000610848565b6136ea670de0b6b3a76400006136d16136cc86613700565b61376a565b6136db90856149af565b6136e5919061496d565b613775565b9050610848565b606061271c8484600085613788565b60006001600160ff1b03821115611da55760405162461bcd60e51b815260206004820152602860248201527f53616665436173743a2076616c756520646f65736e27742066697420696e2061604482015267371034b73a191a9b60c11b6064820152608401610a20565b6000610848826138ae565b60006108486137838361398d565b613a38565b6060824710156137e95760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610a20565b6001600160a01b0385163b6138405760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610a20565b600080866001600160a01b0316858760405161385c91906147e3565b60006040518083038185875af1925050503d8060008114613899576040519150601f19603f3d011682016040523d82523d6000602084013e61389e565b606091505b5091509150612a08828286613a8a565b60008082136138d35760405163309fa7dd60e11b815260048101839052602401610a20565b6000670de0b6b3a764000083126138ec57506001613906565b6000199050826ec097ce7bc90715b34b9f10000000000492505b600061391b670de0b6b3a76400008505613ac3565b670de0b6b3a7640000808202945090915084821d9081141561393f57505002919050565b6706f05b59d3b200005b600081131561398457670de0b6b3a7640000828002059150671bc16d674ec80000821261397c579384019360019190911d905b60011d613949565b50505002919050565b6000808212156139ef5768033dd1780914b97114198212156139b157506000919050565b6139bd8260000361398d565b6ec097ce7bc90715b34b9f1000000000816139e857634e487b7160e01b600052601260045260246000fd5b0592915050565b680a688906bd8b0000008212613a1b5760405163e69458f960e01b815260048101839052602401610a20565b670de0b6b3a7640000604083901b046109f881613ba7565b919050565b600080821215611da55760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f7369746976656044820152606401610a20565b60608315613a995750816109f8565b825115613aa95782518084602001fd5b8160405162461bcd60e51b8152600401610a20919061488b565b6000600160801b8210613ae357608091821c91613ae09082614955565b90505b680100000000000000008210613b0657604091821c91613b039082614955565b90505b6401000000008210613b2557602091821c91613b229082614955565b90505b620100008210613b4257601091821c91613b3f9082614955565b90505b6101008210613b5e57600891821c91613b5b9082614955565b90505b60108210613b7957600491821c91613b769082614955565b90505b60048210613b9457600291821c91613b919082614955565b90505b60028210613a3357610848600182614955565b600160bf1b678000000000000000821615613bcb5768016a09e667f3bcc9090260401c5b674000000000000000821615613bea576801306fe0a31b7152df0260401c5b672000000000000000821615613c09576801172b83c7d517adce0260401c5b671000000000000000821615613c285768010b5586cf9890f62a0260401c5b670800000000000000821615613c47576801059b0d31585743ae0260401c5b670400000000000000821615613c6657680102c9a3e778060ee70260401c5b670200000000000000821615613c855768010163da9fb33356d80260401c5b670100000000000000821615613ca457680100b1afa5abcbed610260401c5b6680000000000000821615613cc25768010058c86da1c09ea20260401c5b6640000000000000821615613ce0576801002c605e2e8cec500260401c5b6620000000000000821615613cfe57680100162f3904051fa10260401c5b6610000000000000821615613d1c576801000b175effdc76ba0260401c5b6608000000000000821615613d3a57680100058ba01fb9f96d0260401c5b6604000000000000821615613d585768010002c5cc37da94920260401c5b6602000000000000821615613d76576801000162e525ee05470260401c5b6601000000000000821615613d945768010000b17255775c040260401c5b65800000000000821615613db1576801000058b91b5bc9ae0260401c5b65400000000000821615613dce57680100002c5c89d5ec6d0260401c5b65200000000000821615613deb5768010000162e43f4f8310260401c5b65100000000000821615613e0857680100000b1721bcfc9a0260401c5b65080000000000821615613e255768010000058b90cf1e6e0260401c5b65040000000000821615613e42576801000002c5c863b73f0260401c5b65020000000000821615613e5f57680100000162e430e5a20260401c5b65010000000000821615613e7c576801000000b1721835510260401c5b648000000000821615613e9857680100000058b90c0b490260401c5b644000000000821615613eb45768010000002c5c8601cc0260401c5b642000000000821615613ed0576801000000162e42fff00260401c5b641000000000821615613eec5768010000000b17217fbb0260401c5b640800000000821615613f08576801000000058b90bfce0260401c5b640400000000821615613f2457680100000002c5c85fe30260401c5b640200000000821615613f405768010000000162e42ff10260401c5b640100000000821615613f5c57680100000000b17217f80260401c5b6380000000821615613f775768010000000058b90bfc0260401c5b6340000000821615613f92576801000000002c5c85fe0260401c5b6320000000821615613fad57680100000000162e42ff0260401c5b6310000000821615613fc8576801000000000b17217f0260401c5b6308000000821615613fe357680100000000058b90c00260401c5b6304000000821615613ffe5768010000000002c5c8600260401c5b6302000000821615614019576801000000000162e4300260401c5b63010000008216156140345768010000000000b172180260401c5b6280000082161561404e576801000000000058b90c0260401c5b6240000082161561406857680100000000002c5c860260401c5b622000008216156140825768010000000000162e430260401c5b6210000082161561409c57680100000000000b17210260401c5b620800008216156140b65768010000000000058b910260401c5b620400008216156140d0576801000000000002c5c80260401c5b620200008216156140ea57680100000000000162e40260401c5b62010000821615614104576801000000000000b1720260401c5b61800082161561411d57680100000000000058b90260401c5b6140008216156141365768010000000000002c5d0260401c5b61200082161561414f576801000000000000162e0260401c5b6110008216156141685768010000000000000b170260401c5b610800821615614181576801000000000000058c0260401c5b61040082161561419a57680100000000000002c60260401c5b6102008216156141b357680100000000000001630260401c5b6101008216156141cc57680100000000000000b10260401c5b60808216156141e457680100000000000000590260401c5b60408216156141fc576801000000000000002c0260401c5b602082161561421457680100000000000000160260401c5b601082161561422c576801000000000000000b0260401c5b600882161561424457680100000000000000060260401c5b600482161561425c57680100000000000000030260401c5b600282161561427457680100000000000000010260401c5b600182161561428c57680100000000000000010260401c5b670de0b6b3a76400000260409190911c60bf031c90565b80356001600160a01b0381168114613a3357600080fd5b60008083601f8401126142cb578182fd5b50813567ffffffffffffffff8111156142e2578182fd5b6020830191508360208260051b85010111156142fd57600080fd5b9250929050565b60008083601f840112614315578182fd5b50813567ffffffffffffffff81111561432c578182fd5b6020830191508360208285010111156142fd57600080fd5b600060608284031215614355578081fd5b50919050565b60006020828403121561436c578081fd5b6109f8826142a3565b60008060408385031215614387578081fd5b614390836142a3565b915061439e602084016142a3565b90509250929050565b6000806000606084860312156143bb578081fd5b6143c4846142a3565b92506143d2602085016142a3565b9150604084013590509250925092565b60008060008060008060008060006101408a8c031215614400578485fd5b6144098a6142a3565b985061441760208b016142a3565b975060408a0135965060608a0135955060808a0135945061443a60a08b016142a3565b93506144498b60c08c01614344565b92506101208a013567ffffffffffffffff811115614465578283fd5b6144718c828d01614304565b915080935050809150509295985092959850929598565b6000806000806000806000610120888a0312156144a3578283fd5b6144ac886142a3565b96506144ba602089016142a3565b955060408801359450606088013593506080880135925060a088013591506144e58960c08a01614344565b905092959891949750929550565b6000806000806000806000610100888a03121561450e578283fd5b614517886142a3565b9650602088013567ffffffffffffffff811115614532578384fd5b61453e8a828b016142ba565b9097509550506040880135935060608801359250608088013591506144e58960a08a01614344565b60008060408385031215614578578182fd5b614581836142a3565b946020939093013593505050565b60008060008060008061010087890312156145a8578182fd5b6145b1876142a3565b9550602087013594506145c6604088016142a3565b935060608701359250608087013591506145e38860a08901614344565b90509295509295509295565b600080600080600080600080610120898b03121561460b578182fd5b614614896142a3565b975060208901359650604089013595506060890135945061463760808a016142a3565b93506146468a60a08b01614344565b925061010089013567ffffffffffffffff811115614662578283fd5b61466e8b828c01614304565b999c989b5096995094979396929594505050565b600080600080600080610100878903121561469b578384fd5b6146a4876142a3565b9550602087013594506040870135935060608701359250608087013591506145e38860a08901614344565b60008060008060008060e087890312156146e7578384fd5b863567ffffffffffffffff8111156146fd578485fd5b61470989828a016142ba565b9097509550506020870135935060408701359250606087013591506145e38860808901614344565b600060208284031215614742578081fd5b815180151581146109f8578182fd5b600060208284031215614762578081fd5b5035919050565b60006020828403121561477a578081fd5b5051919050565b600060208284031215614792578081fd5b81356109f881614b10565b6000602082840312156147ae578081fd5b81516109f881614b10565b60006001600160fb1b038311156147ce578081fd5b8260051b808584379190910190815292915050565b600082516147f5818460208701614a68565b9190910192915050565b606080825284519082018190526000906020906080840190828801845b828110156148385781518452928401929084019060010161481c565b50505083810382850152855180825286830191830190845b818110156148755783516001600160a01b031683529284019291840191600101614850565b5050809350505050826040830152949350505050565b60208152600082518060208401526148aa816040850160208701614a68565b601f01601f19169190910160400192915050565b60208082526010908201526f10db1a5c1c195c8e88115e1c1a5c995960821b604082015260600190565b60208082526016908201527521b634b83832b91d1024b73b30b634b2103a37b5b2b760511b604082015260600190565b84815283602082015260606040820152816060820152818360808301376000818301608090810191909152601f909201601f191601019392505050565b6000821982111561496857614968614ae4565b500190565b60008261497c5761497c614afa565b600160ff1b82146000198414161561499657614996614ae4565b500590565b6000826149aa576149aa614afa565b500490565b60006001600160ff1b03818413828413808216868404861116156149d5576149d5614ae4565b600160ff1b848712828116878305891216156149f3576149f3614ae4565b858712925087820587128484161615614a0e57614a0e614ae4565b87850587128184161615614a2457614a24614ae4565b505050929093029392505050565b6000816000190483118215151615614a4c57614a4c614ae4565b500290565b600082821015614a6357614a63614ae4565b500390565b60005b83811015614a83578181015183820152602001614a6b565b83811115611f6d5750506000910152565b600181811c90821680614aa857607f821691505b6020821081141561435557634e487b7160e01b600052602260045260246000fd5b6000600019821415614add57614add614ae4565b5060010190565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052601260045260246000fd5b60ff81168114610bed57600080fdfe4be05c8d54f5e056ab2cfa033e9f582057001268c3e28561bb999d35d2c8f2c8a264697066735822122054eacf1c3231a2523257c519d79262964b4be9e403a0eb5ad3c52aa89ebbc4e264736f6c63430008040033

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

00000000000000000000000008938a61ba9523298dbcacee0cda5b371fb7f1f8000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000050000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

-----Decoded View---------------
Arg [0] : theSigner (address): 0x08938a61BA9523298dbCAceE0cda5B371FB7f1F8
Arg [1] : theWrapper (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [2] : tokens (address[]): 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599,0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,0xdAC17F958D2ee523a2206206994597C13D831ec7,0x6B175474E89094C44Da98b954EedeAC495271d0F,0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 00000000000000000000000008938a61ba9523298dbcacee0cda5b371fb7f1f8
Arg [1] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000060
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000005
Arg [4] : 0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599
Arg [5] : 000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Arg [6] : 000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec7
Arg [7] : 0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f
Arg [8] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2


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.