false
true
0

Contract Address Details

0x0A393AEF6dbCd7e7088AcF323f9d28b093B9aB5a

Contract Name
BosonRouter
Creator
0x9266f0–e444ba at 0x450e08–f76348
Balance
0 PLS ( )
Tokens
Fetching tokens...
Transactions
5,585 Transactions
Transfers
0 Transfers
Gas Used
0
Last Balance Update
26733534
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
This contract has been verified via Sourcify. View contract in Sourcify repository
Contract name:
BosonRouter




Optimization enabled
true
Compiler version
v0.7.6+commit.7338295f




Optimization runs
200
EVM Version
istanbul




Verified at
2026-04-22T13:29:41.214369Z

Constructor Arguments

00000000000000000000000019c10a47c9356efd0e4377411db627636ee9e3c6000000000000000000000000caf39b7bcfc3aed00d62488d3668230b7599cf05000000000000000000000000244154f58e9bf6c15c3a09846efb7becfe92a880

Arg [0] (address) : 0x19c10a47c9356efd0e4377411db627636ee9e3c6
Arg [1] (address) : 0xcaf39b7bcfc3aed00d62488d3668230b7599cf05
Arg [2] (address) : 0x244154f58e9bf6c15c3a09846efb7becfe92a880

              

contracts/BosonRouter.sol

// SPDX-License-Identifier: LGPL-3.0-or-later
pragma solidity 0.7.6;
pragma abicoder v2;

import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "./interfaces/IVoucherKernel.sol";
import "./interfaces/IERC20WithPermit.sol";
import "./interfaces/ITokenRegistry.sol";
import "./interfaces/IBosonRouter.sol";
import "./interfaces/ICashier.sol";
import "./interfaces/IGate.sol";
import "./interfaces/ITokenWrapper.sol";
import {PaymentMethod} from "./UsingHelpers.sol";
import "./libs/SafeERC20WithPermit.sol";

/**
 * @title Contract for interacting with Boson Protocol from the user's perspective.
 * @notice There are multiple permutations of the requestCreateOrder and requestVoucher functions.
 * Each function name is suffixed with a payment type that denotes the currency type of the
 * payment and deposits. The options are:
 *
 * ETHETH  - Price and deposits are specified in ETH
 * ETHTKN - Price is specified in ETH and deposits are specified in tokens
 * TKNTKN - Price and deposits are specified in tokens
 * TKNETH - Price is specified in tokens and the deposits are specified in ETH
 *
 * The functions that process payments and/or deposits in tokens do so using EIP-2612 permit functionality
 *
 */
contract BosonRouter is
    IBosonRouter,
    Pausable,
    ReentrancyGuard,
    Ownable
{
    using Address for address payable;
    using SafeMath for uint256;

    address private cashierAddress;
    address private voucherKernel;
    address private tokenRegistry;

    mapping (address => bool) private approvedGates;
    mapping(uint256 => address) private voucherSetToGateContract;

    event LogOrderCreated(
        uint256 indexed _tokenIdSupply,
        address indexed _seller,
        uint256 _quantity,
        PaymentMethod _paymentType
    );

    event LogConditionalOrderCreated(
        uint256 indexed _tokenIdSupply,
        address indexed _gateAddress,
        uint256 indexed _conditionalTokenId,
        Condition _condition,
        uint256 _threshold
    );

    event LogVoucherKernelSet(address _newVoucherKernel, address _triggeredBy);
    event LogTokenRegistrySet(address _newTokenRegistry, address _triggeredBy);
    event LogCashierSet(address _newCashier, address _triggeredBy);

    event LogGateApprovalChanged(
        address indexed _gateAddress,
        bool _approved
    );

    /**
     * @notice Make sure the given gate address is approved
     * @param _gateAddress - the address to validate approval for
     */
    modifier onlyApprovedGate(address _gateAddress) {
        require(approvedGates[_gateAddress], "INVALID_GATE");
        _;
    }

    /**
     * @notice Checking if a non-zero address is provided, otherwise reverts.
     */
    modifier notZeroAddress(address _tokenAddress) {
        require(_tokenAddress != address(0), "0A"); //zero address
        _;
    }

    /**
     * @notice Replacement of onlyOwner modifier. If the caller is not the owner of the contract, reverts.
     */
    modifier onlyRouterOwner() {
        require(owner() == _msgSender(), "NO"); //not owner
        _;
    }

    /**
     * @notice Acts as a modifier, but it's cheaper. Checks whether provided value corresponds to the limits in the TokenRegistry.
     * @param _value the specified value is per voucher set level. E.g. deposit * qty should not be greater or equal to the limit in the TokenRegistry (ETH).
     */
    function notAboveETHLimit(uint256 _value) internal view {
        require(
            _value <= ITokenRegistry(tokenRegistry).getETHLimit(),
            "AL" // above limit
        );
    }

    /**
     * @notice Acts as a modifier, but it's cheaper. Checks whether provided value corresponds to the limits in the TokenRegistry.
     * @param _tokenAddress the token address which, we are getting the limits for.
     * @param _value the specified value is per voucher set level. E.g. deposit * qty should not be greater or equal to the limit in the TokenRegistry (ETH).
     */
    function notAboveTokenLimit(address _tokenAddress, uint256 _value)
        internal
        view
    {
        require(
            _value <= ITokenRegistry(tokenRegistry).getTokenLimit(_tokenAddress),
            "AL" //above limit
        );
    }

    /**
     * @notice Construct and initialze the contract. Iniialises associated contract addresses
     * @param _voucherKernel address of the associated VocherKernal contract instance
     * @param _tokenRegistry address of the associated TokenRegistry contract instance
     * @param _cashierAddress address of the associated Cashier contract instance
     */
    constructor(
        address _voucherKernel,
        address _tokenRegistry,
        address _cashierAddress
    )   notZeroAddress(_voucherKernel)
        notZeroAddress(_tokenRegistry)
        notZeroAddress(_cashierAddress)
    {
        voucherKernel = _voucherKernel;
        tokenRegistry = _tokenRegistry;
        cashierAddress = _cashierAddress;
        emit LogVoucherKernelSet(_voucherKernel, msg.sender);
        emit LogTokenRegistrySet(_tokenRegistry, msg.sender);
        emit LogCashierSet(_cashierAddress, msg.sender);
    }

    /**
     * @notice Set the approval status for a given Gate contract
     * @param _gateAddress - the address of the gate contract
     * @param _approved - approval status for the gate
     */
    function setGateApproval(address _gateAddress, bool _approved)
        external
        onlyOwner
        notZeroAddress(_gateAddress)
    {
        require(approvedGates[_gateAddress] != _approved, "NO_CHANGE");
        approvedGates[_gateAddress] = _approved;
        emit LogGateApprovalChanged(_gateAddress, _approved);
    }

    /**
     * @notice Pause the Cashier && the Voucher Kernel contracts in case of emergency.
     * All functions related to creating requestCreateOrder, requestVoucher, redeem, refund, complain, cancelOrFault,
     * cancelOrFaultVoucherSet, or withdraw will be paused and cannot be executed.
     * The withdrawEthOnDisaster function is a special function in the Cashier contract for withdrawing funds if contract is paused.
     */
    function pause() external override onlyRouterOwner() {
        _pause();
        if (!Pausable(voucherKernel).paused()) { 
            IVoucherKernel(voucherKernel).pause();
            ICashier(cashierAddress).pause();
        }
    }

    /**
     * @notice Unpause the Cashier && the Voucher Kernel contracts.
     * All functions related to creating requestCreateOrder, requestVoucher, redeem, refund, complain, cancelOrFault,
     * cancelOrFaultVoucherSet, or withdraw will be unpaused.
     */
    function unpause() external override onlyRouterOwner() {
        require(ICashier(cashierAddress).canUnpause(), "UF"); //unpaused forbidden

        _unpause();
        if (Pausable(voucherKernel).paused()) { 
            IVoucherKernel(voucherKernel).unpause();
            ICashier(cashierAddress).unpause();
        }        
    }

    /**
     * @notice Issuer/Seller offers promise as supply token and needs to escrow the deposit. A supply token is
     * also known as a voucher set. Payment and deposits are specified in ETH.
     * @param _metadata metadata which is required for creation of a voucher set
     * Metadata array is used for consistency across the permutations of similar functions.
     * Some functions require other parameters, and the number of parameters causes stack too deep error.
     * The use of the matadata array mitigates the stack too deep error.
     *
     * uint256 _validFrom = _metadata[0];
     * uint256 _validTo = _metadata[1];
     * uint256 _price = _metadata[2];
     * uint256 _depositSe = _metadata[3];
     * uint256 _depositBu = _metadata[4];
     * uint256 _quantity = _metadata[5];
     */
    function requestCreateOrderETHETH(uint256[] calldata _metadata)
        external
        payable
        virtual
        override
        nonReentrant
        whenNotPaused
    {
        checkLimits(_metadata, address(0), address(0), 0);
        requestCreateOrder(_metadata, PaymentMethod.ETHETH, address(0), address(0), 0);
    }

    /**
     * @notice Issuer/Seller offers promise as supply token and needs to escrow the deposit. A supply token is also known as a voucher set.
     * The supply token/voucher set created should only be available to buyers who own a specific token of type ERC721, ERC1155, or ERC20.
     * This is the "condition" under which a buyer may commit to redeem a voucher that is part of the voucher set created by this function.
     * Payment and deposits are specified in ETH.
     * @param _metadata metadata which is required for creation of a voucher set
     * Metadata array is used for consistency across the permutations of similar functions.
     * Some functions require other parameters, and the number of parameters causes stack too deep error.
     * The use of the matadata array mitigates the stack too deep error.
     *
     * uint256 _validFrom = _metadata[0];
     * uint256 _validTo = _metadata[1];
     * uint256 _price = _metadata[2];
     * uint256 _depositSe = _metadata[3];
     * uint256 _depositBu = _metadata[4];
     * uint256 _quantity = _metadata[5];
     *
     * @param _conditionalCommitInfo struct that contains data pertaining to conditional commit:
     *
     * uint256 conditionalTokenId - Id of the conditional token, ownership of which is a condition for committing to redeem a voucher
     * in the voucher set created by this function.
     *
     * uint256 threshold - the number that the balance of a tokenId must be greater than or equal to. Not used for OWNERSHIP condition
     *
     * Condition condition - condition that will be checked when a user commits using a conditional token
     *
     * address gateAddress - address of a gate contract that will handle the interaction between the BosonRouter contract and the conditional token,
     * ownership of which is a condition for committing to redeem a voucher in the voucher set created by this function.
     *
     * bool registerConditionalCommit - indicates whether Gate.registerVoucherSetId should be called. Gate.registerVoucherSetId can also be called separately
     */
    function requestCreateOrderETHETHConditional(
        uint256[] calldata _metadata, 
        ConditionalCommitInfo calldata _conditionalCommitInfo)
        external
        payable
        override
        nonReentrant
        whenNotPaused
        onlyApprovedGate(_conditionalCommitInfo.gateAddress)
    {
        checkLimits(_metadata, address(0), address(0), 0);
        uint256 tokenIdSupply = requestCreateOrder(_metadata, PaymentMethod.ETHETH, address(0), address(0), 0);
        finalizeConditionalOrder(tokenIdSupply, _conditionalCommitInfo);
    }


    /**
     * @notice Issuer/Seller offers promise as supply token and needs to escrow the deposit. A supply token is
     * also known as a voucher set. Price and deposits are specified in tokens.
     * @param _tokenPriceAddress address of the token to be used for the price
     * @param _tokenDepositAddress address of the token to be used for the deposits
     * @param _tokensSent total number of tokens sent. Must be equal to seller deposit * quantity
     * @param _deadline deadline after which permit signature is no longer valid. See EIP-2612
     * @param _v signature component used to verify the permit. See EIP-2612
     * @param _r signature component used to verify the permit. See EIP-2612
     * @param _s signature component used to verify the permit. See EIP-2612
     * @param _metadata metadata which is required for creation of a voucher set
     * Metadata array is used for consistency across the permutations of similar functions.
     * Some functions require other parameters, and the number of parameters causes stack too deep error.
     * The use of the matadata array mitigates the stack too deep error.
     *
     * uint256 _validFrom = _metadata[0];
     * uint256 _validTo = _metadata[1];
     * uint256 _price = _metadata[2];
     * uint256 _depositSe = _metadata[3];
     * uint256 _depositBu = _metadata[4];
     * uint256 _quantity = _metadata[5];
     */
    function requestCreateOrderTKNTKNWithPermit(
        address _tokenPriceAddress,
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata
    )
    external
    override
    nonReentrant
    {
        requestCreateOrderTKNTKNWithPermitInternal(
            _tokenPriceAddress,
            _tokenDepositAddress,
            _tokensSent,
            _deadline,
            _v,
            _r,
            _s,
            _metadata
        );
    }

    /**
     * @notice Issuer/Seller offers promise as supply token and needs to escrow the deposit. A supply token is also known as a voucher set.
     * The supply token/voucher set created should only be available to buyers who own a specific token of type ERC721, ERC1155, or ERC20.
     * This is the "condition" under which a buyer may commit to redeem a voucher that is part of the voucher set created by this function.
     * Price and deposits are specified in tokens.
     * @param _tokenPriceAddress address of the token to be used for the price
     * @param _tokenDepositAddress address of the token to be used for the deposits
     * @param _tokensSent total number of tokens sent. Must be equal to seller deposit * quantity
     * @param _deadline deadline after which permit signature is no longer valid. See EIP-2612
     * @param _v signature component used to verify the permit. See EIP-2612
     * @param _r signature component used to verify the permit. See EIP-2612
     * @param _s signature component used to verify the permit. See EIP-2612
     * @param _metadata metadata which is required for creation of a voucher set
     * Metadata array is used for consistency across the permutations of similar functions.
     * Some functions require other parameters, and the number of parameters causes stack too deep error.
     * The use of the matadata array mitigates the stack too deep error.
     *
     * uint256 _validFrom = _metadata[0];
     * uint256 _validTo = _metadata[1];
     * uint256 _price = _metadata[2];
     * uint256 _depositSe = _metadata[3];
     * uint256 _depositBu = _metadata[4];
     * uint256 _quantity = _metadata[5];
     *
     * @param _conditionalCommitInfo struct that contains data pertaining to conditional commit:
     *
     * uint256 conditionalTokenId - Id of the conditional token, ownership of which is a condition for committing to redeem a voucher
     * in the voucher set created by this function.
     *
     * uint256 threshold - the number that the balance of a tokenId must be greater than or equal to. Not used for OWNERSHIP condition
     *
     * Condition condition - condition that will be checked when a user commits using a conditional token
     *
     * address gateAddress - address of a gate contract that will handle the interaction between the BosonRouter contract and the conditional token,
     * ownership of which is a condition for committing to redeem a voucher in the voucher set created by this function.
     *
     * bool registerConditionalCommit - indicates whether Gate.registerVoucherSetId should be called. Gate.registerVoucherSetId can also be called separately
     */
    function requestCreateOrderTKNTKNWithPermitConditional(
        address _tokenPriceAddress,
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata,
        ConditionalCommitInfo calldata _conditionalCommitInfo
    )
    external
    override
    nonReentrant
    onlyApprovedGate(_conditionalCommitInfo.gateAddress)
    {
        uint256 tokenIdSupply = requestCreateOrderTKNTKNWithPermitInternal(
            _tokenPriceAddress,
            _tokenDepositAddress,
            _tokensSent,
            _deadline,
            _v,
            _r,
            _s,
            _metadata
        );

        finalizeConditionalOrder(tokenIdSupply, _conditionalCommitInfo);
    
    }

    /**
     * @notice Issuer/Seller offers promise as supply token and needs to escrow the deposit. A supply token is
     * also known as a voucher set. Price is specified in ETH and deposits are specified in tokens.
     * @param _tokenDepositAddress address of the token to be used for the deposits
     * @param _tokensSent total number of tokens sent. Must be equal to seller deposit * quantity
     * @param _deadline deadline after which permit signature is no longer valid. See EIP-2612
     * @param _v signature component used to verify the permit. See EIP-2612
     * @param _r signature component used to verify the permit. See EIP-2612
     * @param _s signature component used to verify the permit. See EIP-2612
     * @param _metadata metadata which is required for creation of a voucher set
     * Metadata array is used for consistency across the permutations of similar functions.
     * Some functions require other parameters, and the number of parameters causes stack too deep error.
     * The use of the matadata array mitigates the stack too deep error.
     *
     * uint256 _validFrom = _metadata[0];
     * uint256 _validTo = _metadata[1];
     * uint256 _price = _metadata[2];
     * uint256 _depositSe = _metadata[3];
     * uint256 _depositBu = _metadata[4];
     * uint256 _quantity = _metadata[5];
     */
    function requestCreateOrderETHTKNWithPermit(
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata
    )
    external
    override
    nonReentrant
    {
        requestCreateOrderETHTKNWithPermitInternal( _tokenDepositAddress,
         _tokensSent,
         _deadline,
         _v,
         _r,
         _s,
        _metadata);

    }

    /**
     * @notice Issuer/Seller offers promise as supply token and needs to escrow the deposit. A supply token is also known as a voucher set.
     * The supply token/voucher set created should only be available to buyers who own a specific token of type ERC721, ERC1155, or ERC20.
     * This is the "condition" under which a buyer may commit to redeem a voucher that is part of the voucher set created by this function.
     * Price is specified in ETH and deposits are specified in tokens.
     * @param _tokenDepositAddress address of the token to be used for the deposits
     * @param _tokensSent total number of tokens sent. Must be equal to seller deposit * quantity
     * @param _deadline deadline after which permit signature is no longer valid. See EIP-2612
     * @param _v signature component used to verify the permit. See EIP-2612
     * @param _r signature component used to verify the permit. See EIP-2612
     * @param _s signature component used to verify the permit. See EIP-2612
     * @param _metadata metadata which is required for creation of a voucher set
     * Metadata array is used for consistency across the permutations of similar functions.
     * Some functions require other parameters, and the number of parameters causes stack too deep error.
     * The use of the matadata array mitigates the stack too deep error.
     *
     * uint256 _validFrom = _metadata[0];
     * uint256 _validTo = _metadata[1];
     * uint256 _price = _metadata[2];
     * uint256 _depositSe = _metadata[3];
     * uint256 _depositBu = _metadata[4];
     * uint256 _quantity = _metadata[5];
     *
     * @param _conditionalCommitInfo struct that contains data pertaining to conditional commit:
     *
     * uint256 conditionalTokenId - Id of the conditional token, ownership of which is a condition for committing to redeem a voucher
     * in the voucher set created by this function.
     *
     * uint256 threshold - the number that the balance of a tokenId must be greater than or equal to. Not used for OWNERSHIP condition
     *
     * Condition condition - condition that will be checked when a user commits using a conditional token
     *
     * address gateAddress - address of a gate contract that will handle the interaction between the BosonRouter contract and the conditional token,
     * ownership of which is a condition for committing to redeem a voucher in the voucher set created by this function.
     *
     * 
     */
    function requestCreateOrderETHTKNWithPermitConditional(
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata,
        ConditionalCommitInfo calldata _conditionalCommitInfo
    )
    external
    override
    nonReentrant
    onlyApprovedGate(_conditionalCommitInfo.gateAddress)
    {
        uint256 tokenIdSupply = requestCreateOrderETHTKNWithPermitInternal( _tokenDepositAddress,
         _tokensSent,
         _deadline,
         _v,
         _r,
         _s,
        _metadata);

       finalizeConditionalOrder(tokenIdSupply, _conditionalCommitInfo);
    }

    /**
     * @notice Issuer/Seller offers promise as supply token and needs to escrow the deposit. A supply token is
     * also known as a voucher set. Price is specified in tokens and the deposits are specified in ETH.
     * Since the price, which is specified in tokens, is not collected when a voucher set is created, there is no need to call
     * permit or transferFrom on the token at this time. The address of the price token is only recorded.
     * @param _tokenPriceAddress address of the token to be used for the deposits
     * @param _metadata metadata which is required for creation of a voucher set
     *  Metadata array is used for consistency across the permutations of similar functions.
     *  Some functions require other parameters, and the number of parameters causes stack too deep error.
     *  The use of the matadata array mitigates the stack too deep error.
     *
     * uint256 _validFrom = _metadata[0];
     * uint256 _validTo = _metadata[1];
     * uint256 _price = _metadata[2];
     * uint256 _depositSe = _metadata[3];
     * uint256 _depositBu = _metadata[4];
     * uint256 _quantity = _metadata[5];
     */
    function requestCreateOrderTKNETH(
        address _tokenPriceAddress,
        uint256[] calldata _metadata
    )
    external
    payable
    override
    nonReentrant
    {
        requestCreateOrderTKNETHInternal(_tokenPriceAddress, _metadata);
    }

    /**
     * @notice Issuer/Seller offers promise as supply token and needs to escrow the deposit. A supply token is also known as a voucher set.
     * The supply token/voucher set created should only be available to buyers who own a specific specific token of type ERC721, ERC1155, or ERC20.
     * This is the "condition" under which a buyer may commit to redeem a voucher that is part of the voucher set created by this function.
     * Price is specified in tokens and the deposits are specified in ETH.
     * Since the price, which is specified in tokens, is not collected when a voucher set is created, there is no need to call
     * permit or transferFrom on the token at this time. The address of the price token is only recorded.
     * @param _tokenPriceAddress address of the token to be used for the deposits
     * @param _metadata metadata which is required for creation of a voucher set
     *  Metadata array is used for consistency across the permutations of similar functions.
     *  Some functions require other parameters, and the number of parameters causes stack too deep error.
     *  The use of the matadata array mitigates the stack too deep error.
     *
     * uint256 _validFrom = _metadata[0];
     * uint256 _validTo = _metadata[1];
     * uint256 _price = _metadata[2];
     * uint256 _depositSe = _metadata[3];
     * uint256 _depositBu = _metadata[4];
     * uint256 _quantity = _metadata[5];
     *
     * @param _conditionalCommitInfo struct that contains data pertaining to conditional commit:
     *
     * uint256 conditionalTokenId - Id of the conditional token, ownership of which is a condition for committing to redeem a voucher
     * in the voucher set created by this function.
     *
     * uint256 threshold - the number that the balance of a tokenId must be greater than or equal to. Not used for OWNERSHIP condition
     *
     * Condition condition - condition that will be checked when a user commits using a conditional token
     *
     * address gateAddress - address of a gate contract that will handle the interaction between the BosonRouter contract and the conditional token,
     * ownership of which is a condition for committing to redeem a voucher in the voucher set created by this function.
     *
     * bool registerConditionalCommit - indicates whether Gate.registerVoucherSetId should be called. Gate.registerVoucherSetId can also be called separately
     */
    function requestCreateOrderTKNETHConditional(
        address _tokenPriceAddress,
        uint256[] calldata _metadata,
        ConditionalCommitInfo calldata _conditionalCommitInfo
    )
    external
    payable
    override
    nonReentrant
    onlyApprovedGate(_conditionalCommitInfo.gateAddress)
    {
        uint256 tokenIdSupply = requestCreateOrderTKNETHInternal(_tokenPriceAddress, _metadata);
        finalizeConditionalOrder(tokenIdSupply, _conditionalCommitInfo);
    }

    /**
     * @notice Buyer requests/commits to redeem a voucher and receives Voucher Token in return.
     * Price and deposit are specified in ETH
     * @param _tokenIdSupply    ID of the supply token
     * @param _issuer           Address of the issuer of the supply token
     */
    function requestVoucherETHETH(uint256 _tokenIdSupply, address _issuer)
    external
    payable
    override
    nonReentrant
    whenNotPaused
    {
        // check if _tokenIdSupply mapped to gate contract
        // if yes, deactivate (user,_tokenIdSupply) to prevent double spending
        deactivateConditionalCommit(_tokenIdSupply);

        uint256 weiReceived = msg.value;

        //checks
        (uint256 price, uint256 depositBu) = IVoucherKernel(voucherKernel)
            .getBuyerOrderCosts(_tokenIdSupply);
        require(price.add(depositBu) == weiReceived, "IF"); //invalid funds

        addEscrowAmountAndFillOrder(_tokenIdSupply, _issuer, PaymentMethod.ETHETH);
    }

    /**
     * @notice Buyer requests/commits to redeem a voucher and receives Voucher Token in return.
     * Price and deposit is specified in tokens.
     * @param _tokenIdSupply ID of the supply token
     * @param _issuer Address of the issuer of the supply token
     * @param _tokensSent total number of tokens sent. Must be equal to buyer deposit plus price
     * @param _deadline deadline after which permit signature is no longer valid. See EIP-2612
     * @param _vPrice v signature component  used to verify the permit on the price token. See EIP-2612
     * @param _rPrice r signature component used to verify the permit on the price token. See EIP-2612
     * @param _sPrice s signature component used to verify the permit on the price token. See EIP-2612
     * @param _vDeposit v signature component  used to verify the permit on the deposit token. See EIP-2612
     * @param _rDeposit r signature component used to verify the permit on the deposit token. See EIP-2612
     * @param _sDeposit s signature component used to verify the permit on the deposit token. See EIP-2612
     */
    function requestVoucherTKNTKNWithPermit(
        uint256 _tokenIdSupply,
        address _issuer,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _vPrice,
        bytes32 _rPrice,
        bytes32 _sPrice, // tokenPrice
        uint8 _vDeposit,
        bytes32 _rDeposit,
        bytes32 _sDeposit // tokenDeposits
    ) external override nonReentrant whenNotPaused {
        // check if _tokenIdSupply mapped to gate contract
        // if yes, deactivate (user,_tokenIdSupply) to prevent double spending
        deactivateConditionalCommit(_tokenIdSupply);

        (uint256 price, uint256 depositBu) = IVoucherKernel(voucherKernel)
            .getBuyerOrderCosts(_tokenIdSupply);
        require(_tokensSent.sub(depositBu) == price, "IF"); //invalid funds

        address tokenPriceAddress = IVoucherKernel(voucherKernel)
            .getVoucherPriceToken(_tokenIdSupply);
        address tokenDepositAddress = IVoucherKernel(voucherKernel)
            .getVoucherDepositToken(_tokenIdSupply);

        permitTransferFromAndAddEscrow(
            tokenPriceAddress,
            price,
            _deadline,
            _vPrice,
            _rPrice,
            _sPrice
        );

        permitTransferFromAndAddEscrow(
            tokenDepositAddress,
            depositBu,
            _deadline,
            _vDeposit,
            _rDeposit,
            _sDeposit
        );

        IVoucherKernel(voucherKernel).fillOrder(
            _tokenIdSupply,
            _issuer,
            msg.sender,
            PaymentMethod.TKNTKN
        );
    }

    /**
     * @notice Buyer requests/commits to redeem a voucher and receives Voucher Token in return.
     * Price and deposit is specified in tokens. The same token is used for both the price and deposit.
     * @param _tokenIdSupply ID of the supply token
     * @param _issuer address of the issuer of the supply token
     * @param _tokensSent total number of tokens sent. Must be equal to buyer deposit plus price
     * @param _deadline deadline after which permit signature is no longer valid. See EIP-2612
     * @param _v signature component used to verify the permit. See EIP-2612
     * @param _r signature component used to verify the permit. See EIP-2612
     * @param _s signature component used to verify the permit. See EIP-2612
     */
    function requestVoucherTKNTKNSameWithPermit(
        uint256 _tokenIdSupply,
        address _issuer,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) external override nonReentrant whenNotPaused {
        // check if _tokenIdSupply mapped to gate contract
        // if yes, deactivate (user,_tokenIdSupply) to prevent double spending
        deactivateConditionalCommit(_tokenIdSupply);

        (uint256 price, uint256 depositBu) = IVoucherKernel(voucherKernel)
            .getBuyerOrderCosts(_tokenIdSupply);
        require(_tokensSent.sub(depositBu) == price, "IF"); //invalid funds

        address tokenPriceAddress = IVoucherKernel(voucherKernel)
            .getVoucherPriceToken(_tokenIdSupply);
        address tokenDepositAddress = IVoucherKernel(voucherKernel)
            .getVoucherDepositToken(_tokenIdSupply);

        require(tokenPriceAddress == tokenDepositAddress, "TOKENS_ARE_NOT_THE_SAME"); //invalid caller

        // If tokenPriceAddress && tokenPriceAddress are the same
        // practically it's not of importance to each we are sending the funds
        permitTransferFromAndAddEscrow(
            tokenPriceAddress,
            _tokensSent,
            _deadline,
            _v,
            _r,
            _s
        );

        IVoucherKernel(voucherKernel).fillOrder(
            _tokenIdSupply,
            _issuer,
            msg.sender,
            PaymentMethod.TKNTKN
        );
    }

    /**
     * @notice Buyer requests/commits to redeem a voucher and receives Voucher Token in return.
     * Price is specified in ETH and deposit is specified in tokens
     * @param _tokenIdSupply ID of the supply token
     * @param _issuer address of the issuer of the supply token
     * @param _tokensDeposit number of tokens sent to cover buyer deposit
     * @param _deadline deadline after which permit signature is no longer valid. See EIP-2612
     * @param _v signature component used to verify the permit. See EIP-2612
     * @param _r signature component used to verify the permit. See EIP-2612
     * @param _s signature component used to verify the permit. See EIP-2612
     */
    function requestVoucherETHTKNWithPermit(
        uint256 _tokenIdSupply,
        address _issuer,
        uint256 _tokensDeposit,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) external payable override nonReentrant whenNotPaused {
        // check if _tokenIdSupply mapped to gate contract
        // if yes, deactivate (user,_tokenIdSupply) to prevent double spending
        deactivateConditionalCommit(_tokenIdSupply);

        (uint256 price, uint256 depositBu) = IVoucherKernel(voucherKernel)
            .getBuyerOrderCosts(_tokenIdSupply);
        require(price == msg.value, "IP"); //invalid price
        require(depositBu == _tokensDeposit, "ID"); // invalid deposit

        address tokenDepositAddress = IVoucherKernel(voucherKernel)
            .getVoucherDepositToken(_tokenIdSupply);

        permitTransferFromAndAddEscrow(
            tokenDepositAddress,
            _tokensDeposit,
            _deadline,
            _v,
            _r,
            _s
        );

        addEscrowAmountAndFillOrder(_tokenIdSupply, _issuer, PaymentMethod.ETHTKN);
    }

    /**
     * @notice Buyer requests/commits to redeem a voucher and receives Voucher Token in return.
     * Price is specified in tokens and the deposit is specified in ETH
     * @param _tokenIdSupply ID of the supply token
     * @param _issuer address of the issuer of the supply token
     * @param _tokensPrice number of tokens sent to cover price
     * @param _deadline deadline after which permit signature is no longer valid. See EIP-2612
     * @param _v signature component used to verify the permit. See EIP-2612
     * @param _r signature component used to verify the permit. See EIP-2612
     * @param _s signature component used to verify the permit. See EIP-2612
     */
    function requestVoucherTKNETHWithPermit(
        uint256 _tokenIdSupply,
        address _issuer,
        uint256 _tokensPrice,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) external payable virtual override nonReentrant whenNotPaused {
        // check if _tokenIdSupply mapped to gate contract
        // if yes, deactivate (user,_tokenIdSupply) to prevent double spending
        deactivateConditionalCommit(_tokenIdSupply);

        (uint256 price, uint256 depositBu) = IVoucherKernel(voucherKernel)
            .getBuyerOrderCosts(_tokenIdSupply);
        require(price == _tokensPrice, "IP"); //invalid price
        require(depositBu == msg.value, "ID"); // invalid deposit

        address tokenPriceAddress = IVoucherKernel(voucherKernel)
            .getVoucherPriceToken(_tokenIdSupply);        

        permitTransferFromAndAddEscrow(
            tokenPriceAddress,
            price,
            _deadline,
            _v,
            _r,
            _s
        );

        addEscrowAmountAndFillOrder(_tokenIdSupply, _issuer, PaymentMethod.TKNETH);
    }

    /**
     * @notice Seller burns the remaining supply in the voucher set in case it's s/he no longer wishes to sell them.
     * Remaining seller deposit in escrow account is withdrawn and sent back to the seller
     * @param _tokenIdSupply an ID of a supply token (ERC-1155) which will be burned and for which deposits will be returned
     */
    function requestCancelOrFaultVoucherSet(uint256 _tokenIdSupply)
        external
        override
        nonReentrant
        whenNotPaused
    {
        uint256 _burnedSupplyQty = IVoucherKernel(voucherKernel)
            .cancelOrFaultVoucherSet(_tokenIdSupply, msg.sender);
        ICashier(cashierAddress).withdrawDepositsSe(
            _tokenIdSupply,
            _burnedSupplyQty,
            msg.sender
        );
    }

    /**
     * @notice Redemption of the vouchers promise
     * @param _tokenIdVoucher   ID of the voucher
     */
    function redeem(uint256 _tokenIdVoucher) external override {
        IVoucherKernel(voucherKernel).redeem(_tokenIdVoucher, msg.sender);
    }

    /**
     * @notice Refunding a voucher
     * @param _tokenIdVoucher   ID of the voucher
     */
    function refund(uint256 _tokenIdVoucher) external override {
        IVoucherKernel(voucherKernel).refund(_tokenIdVoucher, msg.sender);
    }

    /**
     * @notice Issue a complaint for a voucher
     * @param _tokenIdVoucher   ID of the voucher
     */
    function complain(uint256 _tokenIdVoucher) external override {
        IVoucherKernel(voucherKernel).complain(_tokenIdVoucher, msg.sender);
    }

    /**
     * @notice Cancel/Fault transaction by the Seller, admitting to a fault or backing out of the deal
     * @param _tokenIdVoucher   ID of the voucher
     */
    function cancelOrFault(uint256 _tokenIdVoucher) external override {
        IVoucherKernel(voucherKernel).cancelOrFault(
            _tokenIdVoucher,
            msg.sender
        );
    }

    /**
     * @notice Get the address of Cashier contract
     * @return Address of Cashier address
     */
    function getCashierAddress() external view override returns (address) {
        return cashierAddress;
    }

    /**
     * @notice Get the address of Voucher Kernel contract
     * @return Address of Voucher Kernel contract
     */
    function getVoucherKernelAddress()
        external
        view
        override
        returns (address)
    {
        return voucherKernel;
    }

    /**
     * @notice Get the address of Token Registry contract
     * @return Address of Token Registrycontract
     */
    function getTokenRegistryAddress()
        external
        view
        override
        returns (address)
    {
        return tokenRegistry;
    }

    /**
     * @notice Get the address of the gate contract that handles conditional commit of certain voucher set
     * @param _tokenIdSupply    ID of the supply token
     * @return Address of the gate contract or zero address if there is no conditional commit
     */
    function getVoucherSetToGateContract(uint256 _tokenIdSupply)
        external
        view
        override
        returns (address)
    {
        return voucherSetToGateContract[_tokenIdSupply];
    }

    /**
     * @notice Call permit on either a token directly or on a token wrapper
     * @param _token Address of the token owner who is approving tokens to be transferred by spender
     * @param _tokenOwner Address of the token owner who is approving tokens to be transferred by spender
     * @param _spender Address of the party who is transferring tokens on owner's behalf
     * @param _value Number of tokens to be transferred
     * @param _deadline Time after which this permission to transfer is no longer valid. See EIP-2612
     * @param _v Part of the owner's signatue. See EIP-2612
     * @param _r Part of the owner's signatue. See EIP-2612
     * @param _s Part of the owner's signatue. See EIP-2612
     */
    function _permit(
        address _token,
        address _tokenOwner,
        address _spender,
        uint256 _value,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) internal {
        address tokenWrapper = ITokenRegistry(tokenRegistry)
            .getTokenWrapperAddress(_token);
        require(tokenWrapper != address(0), "UNSUPPORTED_TOKEN");

        //The BosonToken contract conforms to this spec, so it will be callable this way
        //if it's address is mapped to itself in the TokenRegistry
        ITokenWrapper(tokenWrapper).permit(
            _tokenOwner,
            _spender,
            _value,
            _deadline,
            _v,
            _r,
            _s
        );
    }

    /**
     * @notice Add amount to escrow and fill order (only order, were ETH involved)
     * @param _tokenIdSupply    ID of the supply token
     * @param _issuer           Address of the issuer of the supply token
     * * @param _paymentMethod  might be ETHETH, ETHTKN, TKNETH
     */    
    function addEscrowAmountAndFillOrder(uint256 _tokenIdSupply, address _issuer, PaymentMethod _paymentMethod) internal {
        //record funds in escrow ...
        ICashier(cashierAddress).addEscrowAmount{value: msg.value}(msg.sender);

        // fill order
        IVoucherKernel(voucherKernel).fillOrder(
            _tokenIdSupply,
            _issuer,
            msg.sender,
            _paymentMethod
        );        
    }

    /**
     * @notice Transfer tokens to cashier and adds it to escrow
     * @param _tokenAddress tokens that are transfered
     * @param _amount       amount of tokens to transfer (expected permit)
     */
    function transferFromAndAddEscrow(address _tokenAddress, uint256 _amount)
        internal
    {
        SafeERC20WithPermit.safeTransferFrom(
            IERC20WithPermit(_tokenAddress),
            msg.sender,
            address(cashierAddress),
            _amount
        );

        ICashier(cashierAddress).addEscrowTokensAmount(
            _tokenAddress,
            msg.sender,
            _amount
        );
    }

    /**
     * @notice Calls token that implements permits, transfer tokens from there to cashier and adds it to escrow
     * @param _tokenAddress tokens that are transfered
     * @param _amount       amount of tokens to transfer
     * @param _deadline Time after which this permission to transfer is no longer valid
     * @param _v Part of the owner's signatue
     * @param _r Part of the owner's signatue
     * @param _s Part of the owner's signatue
     */
    function permitTransferFromAndAddEscrow(
        address _tokenAddress,
        uint256 _amount,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) internal {
        _permit(
            _tokenAddress,
            msg.sender,
            address(this),
            _amount,
            _deadline,
            _v,
            _r,
            _s
        );

        transferFromAndAddEscrow(_tokenAddress, _amount);
    }

    /**
     * @notice Checks if supplied values are within set limits
     *  @param _metadata metadata which is required for creation of a voucher
     *  Metadata array is used as in some scenarios we need several more params, as we need to recover
     *  owner address in order to permit the contract to transfer funds on his behalf.
     *  Since the params get too many, we end up in situation that the stack is too deep.
     *
     *  uint256 _validFrom = _metadata[0];
     *  uint256 _validTo = _metadata[1];
     *  uint256 _price = _metadata[2];
     *  uint256 _depositSe = _metadata[3];
     *  uint256 _depositBu = _metadata[4];
     *  uint256 _quantity = _metadata[5];
     * @param _tokenPriceAddress     token address which will hold the funds for the price of the voucher
     * @param _tokenDepositAddress  token address which will hold the funds for the deposits of the voucher
     * @param _tokensSent     tokens sent to cashier contract
     */
    function checkLimits(
        uint256[] calldata _metadata,
        address _tokenPriceAddress,
        address _tokenDepositAddress,
        uint256 _tokensSent
    ) internal view {
        // check price limits. If price address == 0 -> prices in ETH
        if (_tokenPriceAddress == address(0)) {
            notAboveETHLimit(_metadata[2].mul(_metadata[5]));
        } else {
            notAboveTokenLimit(
                _tokenPriceAddress,
                _metadata[2].mul(_metadata[5])
            );
        }

        // check deposit limits. If deposit address == 0 -> deposits in ETH
        if (_tokenDepositAddress == address(0)) {
            notAboveETHLimit(_metadata[3].mul(_metadata[5]));
            notAboveETHLimit(_metadata[4].mul(_metadata[5]));
            require(_metadata[3].mul(_metadata[5]) == msg.value, "IF"); //invalid funds
        } else {
            notAboveTokenLimit(
                _tokenDepositAddress,
                _metadata[3].mul(_metadata[5])
            );
            notAboveTokenLimit(
                _tokenDepositAddress,
                _metadata[4].mul(_metadata[5])
            );
            require(_metadata[3].mul(_metadata[5]) == _tokensSent, "IF"); //invalid funds
        }
    }

    /**
     * @notice Internal function called by other TKNTKN requestCreateOrder functions to decrease code duplication.
     * Price and deposits are specified in tokens.
     * @param _tokenPriceAddress address of the token to be used for the price
     * @param _tokenDepositAddress address of the token to be used for the deposits
     * @param _tokensSent total number of tokens sent. Must be equal to seller deposit * quantity
     * @param _deadline deadline after which permit signature is no longer valid. See EIP-2612
     * @param _v signature component used to verify the permit. See EIP-2612
     * @param _r signature component used to verify the permit. See EIP-2612
     * @param _s signature component used to verify the permit. See EIP-2612
     * @param _metadata metadata which is required for creation of a voucher set
     * Metadata array is used for consistency across the permutations of similar functions.
     * Some functions require other parameters, and the number of parameters causes stack too deep error.
     * The use of the matadata array mitigates the stack too deep error.
     *
     * uint256 _validFrom = _metadata[0];
     * uint256 _validTo = _metadata[1];
     * uint256 _price = _metadata[2];
     * uint256 _depositSe = _metadata[3];
     * uint256 _depositBu = _metadata[4];
     * uint256 _quantity = _metadata[5];
     */
    function requestCreateOrderTKNTKNWithPermitInternal(
        address _tokenPriceAddress,
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata
    ) internal whenNotPaused notZeroAddress(_tokenPriceAddress) notZeroAddress(_tokenDepositAddress) returns (uint256) {
        checkLimits(
            _metadata,
            _tokenPriceAddress,
            _tokenDepositAddress,
            _tokensSent
        );

        _permit(
            _tokenDepositAddress,
            msg.sender,
            address(this),
            _tokensSent,
            _deadline,
            _v,
            _r,
            _s
        );

        return
            requestCreateOrder(
                _metadata,
                PaymentMethod.TKNTKN,
                _tokenPriceAddress,
                _tokenDepositAddress,
                _tokensSent
            );
    }

    function requestCreateOrderETHTKNWithPermitInternal(
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata
    ) internal whenNotPaused notZeroAddress(_tokenDepositAddress) returns (uint256) {
        checkLimits(_metadata, address(0), _tokenDepositAddress, _tokensSent);

        _permit(
            _tokenDepositAddress,
            msg.sender,
            address(this),
            _tokensSent,
            _deadline,
            _v,
            _r,
            _s
        );

        return requestCreateOrder(
            _metadata,
            PaymentMethod.ETHTKN,
            address(0),
            _tokenDepositAddress,
            _tokensSent
        );
    }

    function requestCreateOrderTKNETHInternal(
        address _tokenPriceAddress,
        uint256[] calldata _metadata
    ) internal whenNotPaused notZeroAddress(_tokenPriceAddress) returns (uint256) {
        checkLimits(_metadata, _tokenPriceAddress, address(0), 0);

        return requestCreateOrder(_metadata, PaymentMethod.TKNETH, _tokenPriceAddress, address(0), 0);
    }

    /**
     * @notice Internal helper that
     * - creates Token Supply Id
     * - creates payment method
     * - adds escrow ammount
     * - transfers tokens (if needed)
     * @param _metadata metadata which is required for creation of a voucher
     *  Metadata array is used as in some scenarios we need several more params, as we need to recover
     *  owner address in order to permit the contract to transfer funds on his behalf.
     *  Since the params get too many, we end up in situation that the stack is too deep.
     *
     *  uint256 _validFrom = _metadata[0];
     *  uint256 _validTo = _metadata[1];
     *  uint256 _price = _metadata[2];
     *  uint256 _depositSe = _metadata[3];
     *  uint256 _depositBu = _metadata[4];
     *  uint256 _quantity = _metadata[5];
     * @param _paymentMethod  might be ETHETH, ETHTKN, TKNETH or TKNTKN
     * @param _tokenPriceAddress     token address which will hold the funds for the price of the voucher
     * @param _tokenDepositAddress  token address which will hold the funds for the deposits of the voucher
     * @param _tokensSent     tokens sent to cashier contract
     */
    function requestCreateOrder(
        uint256[] calldata _metadata,
        PaymentMethod _paymentMethod,
        address _tokenPriceAddress,
        address _tokenDepositAddress,
        uint256 _tokensSent
    ) internal returns (uint256) {
        //record funds in escrow ...
        if (_tokenDepositAddress == address(0)) {
            ICashier(cashierAddress).addEscrowAmount{value: msg.value}(
                msg.sender
            );
        } else {
            transferFromAndAddEscrow(_tokenDepositAddress, _tokensSent);
        }
        
        uint256 tokenIdSupply = IVoucherKernel(voucherKernel)
            .createTokenSupplyId(
                msg.sender,
                _metadata[0],
                _metadata[1],
                _metadata[2],
                _metadata[3],
                _metadata[4],
                _metadata[5]
            );

        IVoucherKernel(voucherKernel).createPaymentMethod(
            tokenIdSupply,
            _paymentMethod,
            _tokenPriceAddress,
            _tokenDepositAddress
        );              

        emit LogOrderCreated(
            tokenIdSupply,
            msg.sender,
            _metadata[5],
            _paymentMethod
        );

        return tokenIdSupply;
    }

    /**
     * @notice finalizes creating of conditional order
     * @param _tokenIdSupply    ID of the supply token
     * @param _conditionalCommitInfo struct that contains data pertaining to conditional commit:
     *
     * uint256 conditionalTokenId - Id of the conditional token, ownership of which is a condition for committing to redeem a voucher
     * in the voucher set created by this function.
     *
     * uint256 threshold - the number that the balance of a tokenId must be greater than or equal to. Not used for OWNERSHIP condition
     *
     * Condition condition - condition that will be checked when a user commits using a conditional token
     *
     * address gateAddress - address of a gate contract that will handle the interaction between the BosonRouter contract and the conditional token,
     * ownership of which is a condition for committing to redeem a voucher in the voucher set created by this function.
     *
     * bool registerConditionalCommit - indicates whether Gate.registerVoucherSetId should be called. Gate.registerVoucherSetId can also be called separately
     */
    function finalizeConditionalOrder(uint256 _tokenIdSupply, ConditionalCommitInfo calldata _conditionalCommitInfo) internal {
        voucherSetToGateContract[_tokenIdSupply] = _conditionalCommitInfo.gateAddress;

        emit LogConditionalOrderCreated(_tokenIdSupply, _conditionalCommitInfo.gateAddress, _conditionalCommitInfo.conditionalTokenId, _conditionalCommitInfo.condition, _conditionalCommitInfo.threshold);

        if (_conditionalCommitInfo.registerConditionalCommit) {
            IGate(_conditionalCommitInfo.gateAddress).registerVoucherSetId(
                _tokenIdSupply,
                _conditionalCommitInfo
            );
        }
    }

    /**
     * @notice check if _tokenIdSupply mapped to gate contract,
     * if it does, deactivate (user,_tokenIdSupply) to prevent double spending
     * @param _tokenIdSupply    ID of the supply token
     */
    function deactivateConditionalCommit(uint256 _tokenIdSupply) internal {
        if (voucherSetToGateContract[_tokenIdSupply] != address(0)) {
            IGate gateContract = IGate(
                voucherSetToGateContract[_tokenIdSupply]
            );
            require(gateContract.check(msg.sender, _tokenIdSupply),"NE"); // not eligible
            gateContract.deactivate(msg.sender, _tokenIdSupply);
        }
    }

    /**
     * @notice Set the address of the VoucherKernel contract
     * @param _voucherKernelAddress   The address of the VoucherKernel contract
     */
    function setVoucherKernelAddress(address _voucherKernelAddress)
        external
        onlyOwner
        notZeroAddress(_voucherKernelAddress)
        whenPaused
    {
        voucherKernel = _voucherKernelAddress;

        emit LogVoucherKernelSet(_voucherKernelAddress, msg.sender);
    }

    /**
     * @notice Set the address of the TokenRegistry contract
     * @param _tokenRegistryAddress   The address of the TokenRegistry contract
     */
    function setTokenRegistryAddress(address _tokenRegistryAddress)
        external
        onlyOwner
        notZeroAddress(_tokenRegistryAddress)
        whenPaused
    {
        tokenRegistry = _tokenRegistryAddress;

        emit LogTokenRegistrySet(_tokenRegistryAddress, msg.sender);
    }

    /**
     * @notice Set the address of the Cashier contract
     * @param _cashierAddress   The address of the Cashier contract
     */
    function setCashierAddress(address _cashierAddress)
        external
        onlyOwner
        notZeroAddress(_cashierAddress)
        whenPaused
    {
        cashierAddress = _cashierAddress;

        emit LogCashierSet(_cashierAddress, msg.sender);
    }
}
        

/

// SPDX-License-Identifier: LGPL-3.0-or-later

pragma solidity 0.7.6;

import "./../UsingHelpers.sol";

interface ICashier {
    /**
     * @notice Pause the Cashier && the Voucher Kernel contracts in case of emergency.
     * All functions related to creating new batch, requestVoucher or withdraw will be paused, hence cannot be executed.
     * There is special function for withdrawing funds if contract is paused.
     */
    function pause() external;

    /**
     * @notice Unpause the Cashier && the Voucher Kernel contracts.
     * All functions related to creating new batch, requestVoucher or withdraw will be unpaused.
     */
    function unpause() external;

    function canUnpause() external view returns (bool);

    /**
     * @notice Trigger withdrawals of what funds are releasable
     * The caller of this function triggers transfers to all involved entities (pool, issuer, token holder), also paying for gas.
     * @dev This function would be optimized a lot, here verbose for readability.
     * @param _tokenIdVoucher  ID of a voucher token (ERC-721) to try withdraw funds from
     */
    function withdraw(uint256 _tokenIdVoucher) external;

    function withdrawSingle(uint256 _tokenIdVoucher, Entity _to) external;

    /**
     * @notice External function for withdrawing deposits. Caller must be the seller of the goods, otherwise reverts.
     * @notice Seller triggers withdrawals of remaining deposits for a given supply, in case the voucher set is no longer in exchange.
     * @param _tokenIdSupply an ID of a supply token (ERC-1155) which will be burned and deposits will be returned for
     * @param _burnedQty burned quantity that the deposits should be withdrawn for
     * @param _messageSender owner of the voucher set
     */
    function withdrawDepositsSe(
        uint256 _tokenIdSupply,
        uint256 _burnedQty,
        address payable _messageSender
    ) external;

    /**
     * @notice Get the amount in escrow of an address
     * @param _account  The address of an account to query
     * @return          The balance in escrow
     */
    function getEscrowAmount(address _account) external view returns (uint256);

    /**
     * @notice Update the amount in escrow of an address with the new value, based on VoucherSet/Voucher interaction
     * @param _account  The address of an account to query
     */
    function addEscrowAmount(address _account) external payable;

    /**
     * @notice Update the amount in escrowTokens of an address with the new value, based on VoucherSet/Voucher interaction
     * @param _token  The address of a token to query
     * @param _account  The address of an account to query
     * @param _newAmount  New amount to be set
     */
    function addEscrowTokensAmount(
        address _token,
        address _account,
        uint256 _newAmount
    ) external;

    /**
     * @notice Hook which will be triggered when a _tokenIdVoucher will be transferred. Escrow funds should be allocated to the new owner.
     * @param _from prev owner of the _tokenIdVoucher
     * @param _to next owner of the _tokenIdVoucher
     * @param _tokenIdVoucher _tokenIdVoucher that has been transferred
     */
    function onVoucherTransfer(
        address _from,
        address _to,
        uint256 _tokenIdVoucher
    ) external;

    /**
     * @notice After the transfer happens the _tokenSupplyId should be updated in the promise. Escrow funds for the deposits (If in ETH) should be allocated to the new owner as well.
     * @param _from prev owner of the _tokenSupplyId
     * @param _to next owner of the _tokenSupplyId
     * @param _tokenSupplyId _tokenSupplyId for transfer
     * @param _value qty which has been transferred
     */
    function onVoucherSetTransfer(
        address _from,
        address _to,
        uint256 _tokenSupplyId,
        uint256 _value
    ) external;

    /**
     * @notice Get the address of Voucher Kernel contract
     * @return Address of Voucher Kernel contract
     */
    function getVoucherKernelAddress() external view returns (address);

    /**
     * @notice Get the address of Boson Router contract
     * @return Address of Boson Router contract
     */
    function getBosonRouterAddress() external view returns (address);

    /**
     * @notice Get the address of the Vouchers contract, an ERC721 contract
     * @return Address of Vouchers contract
     */
    function getVoucherTokenAddress() external view returns (address);

    /**
     * @notice Get the address of the VoucherSets token contract, an ERC155 contract
     * @return Address of VoucherSets contract
     */
    function getVoucherSetTokenAddress() external view returns (address);

    /**
     * @notice Ensure whether or not contract has been set to disaster state
     * @return disasterState
     */
    function isDisasterStateSet() external view returns (bool);

    /**
     * @notice Get the amount in escrow of an address
     * @param _token  The address of a token to query
     * @param _account  The address of an account to query
     * @return          The balance in escrow
     */
    function getEscrowTokensAmount(address _token, address _account)
        external
        view
        returns (uint256);

    /**
     * @notice Set the address of the BR contract
     * @param _bosonRouterAddress   The address of the Cashier contract
     */
    function setBosonRouterAddress(address _bosonRouterAddress) external;

    /**
     * @notice Set the address of the VoucherKernel contract
     * @param _voucherKernelAddress   The address of the VoucherKernel contract
     */
    function setVoucherKernelAddress(address _voucherKernelAddress) external;

    /**
     * @notice Set the address of the Vouchers token contract, an ERC721 contract
     * @param _voucherTokenAddress   The address of the Vouchers token contract
     */
    function setVoucherTokenAddress(address _voucherTokenAddress) external;

    /**
     * @notice Set the address of the Voucher Sets token contract, an ERC1155 contract
     * @param _voucherSetTokenAddress   The address of the Voucher Sets token contract
     */
    function setVoucherSetTokenAddress(address _voucherSetTokenAddress)
        external;
}
          

/

// SPDX-License-Identifier: LGPL-3.0-or-later
pragma solidity 0.7.6;

import "./../UsingHelpers.sol";

interface IVoucherKernel {
    /**
     * @notice Pause the process of interaction with voucherID's (ERC-721), in case of emergency.
     * Only Cashier contract is in control of this function.
     */
    function pause() external;

    /**
     * @notice Unpause the process of interaction with voucherID's (ERC-721).
     * Only Cashier contract is in control of this function.
     */
    function unpause() external;

    /**
     * @notice Creating a new promise for goods or services.
     * Can be reused, e.g. for making different batches of these (but not in prototype).
     * @param _seller      seller of the promise
     * @param _validFrom   Start of valid period
     * @param _validTo     End of valid period
     * @param _price       Price (payment amount)
     * @param _depositSe   Seller's deposit
     * @param _depositBu   Buyer's deposit
     */
    function createTokenSupplyId(
        address _seller,
        uint256 _validFrom,
        uint256 _validTo,
        uint256 _price,
        uint256 _depositSe,
        uint256 _depositBu,
        uint256 _quantity
    ) external returns (uint256);

    /**
     * @notice Creates a Payment method struct recording the details on how the seller requires to receive Price and Deposits for a certain Voucher Set.
     * @param _tokenIdSupply     _tokenIdSupply of the voucher set this is related to
     * @param _paymentMethod  might be ETHETH, ETHTKN, TKNETH or TKNTKN
     * @param _tokenPrice   token address which will hold the funds for the price of the voucher
     * @param _tokenDeposits   token address which will hold the funds for the deposits of the voucher
     */
    function createPaymentMethod(
        uint256 _tokenIdSupply,
        PaymentMethod _paymentMethod,
        address _tokenPrice,
        address _tokenDeposits
    ) external;

    /**
     * @notice Mark voucher token that the payment was released
     * @param _tokenIdVoucher   ID of the voucher token
     */
    function setPaymentReleased(uint256 _tokenIdVoucher) external;

    /**
     * @notice Mark voucher token that the deposits were released
     * @param _tokenIdVoucher   ID of the voucher token
     * @param _to               recipient, one of {ISSUER, HOLDER, POOL}
     * @param _amount           amount that was released in the transaction
     */
    function setDepositsReleased(
        uint256 _tokenIdVoucher,
        Entity _to,
        uint256 _amount
    ) external;

    /**
     * @notice Tells if part of the deposit, belonging to entity, was released already
     * @param _tokenIdVoucher   ID of the voucher token
     * @param _to               recipient, one of {ISSUER, HOLDER, POOL}
     */
    function isDepositReleased(uint256 _tokenIdVoucher, Entity _to)
        external
        returns (bool);

    /**
     * @notice Redemption of the vouchers promise
     * @param _tokenIdVoucher   ID of the voucher
     * @param _messageSender owner of the voucher
     */
    function redeem(uint256 _tokenIdVoucher, address _messageSender) external;

    /**
     * @notice Refunding a voucher
     * @param _tokenIdVoucher   ID of the voucher
     * @param _messageSender owner of the voucher
     */
    function refund(uint256 _tokenIdVoucher, address _messageSender) external;

    /**
     * @notice Issue a complain for a voucher
     * @param _tokenIdVoucher   ID of the voucher
     * @param _messageSender owner of the voucher
     */
    function complain(uint256 _tokenIdVoucher, address _messageSender) external;

    /**
     * @notice Cancel/Fault transaction by the Seller, admitting to a fault or backing out of the deal
     * @param _tokenIdVoucher   ID of the voucher
     * @param _messageSender owner of the voucher set (seller)
     */
    function cancelOrFault(uint256 _tokenIdVoucher, address _messageSender)
        external;

    /**
     * @notice Cancel/Fault transaction by the Seller, cancelling the remaining uncommitted voucher set so that seller prevents buyers from committing to vouchers for items no longer in exchange.
     * @param _tokenIdSupply   ID of the voucher
     * @param _issuer   owner of the voucher
     */
    function cancelOrFaultVoucherSet(uint256 _tokenIdSupply, address _issuer)
        external
        returns (uint256);

    /**
     * @notice Fill Voucher Order, iff funds paid, then extract & mint NFT to the voucher holder
     * @param _tokenIdSupply   ID of the supply token (ERC-1155)
     * @param _issuer          Address of the token's issuer
     * @param _holder          Address of the recipient of the voucher (ERC-721)
     * @param _paymentMethod   method being used for that particular order that needs to be fulfilled
     */
    function fillOrder(
        uint256 _tokenIdSupply,
        address _issuer,
        address _holder,
        PaymentMethod _paymentMethod
    ) external;

    /**
     * @notice Mark voucher token as expired
     * @param _tokenIdVoucher   ID of the voucher token
     */
    function triggerExpiration(uint256 _tokenIdVoucher) external;

    /**
     * @notice Mark voucher token to the final status
     * @param _tokenIdVoucher   ID of the voucher token
     */
    function triggerFinalizeVoucher(uint256 _tokenIdVoucher) external;

    /**
     * @notice Set the address of the new holder of a _tokenIdSupply on transfer
     * @param _tokenIdSupply   _tokenIdSupply which will be transferred
     * @param _newSeller   new holder of the supply
     */
    function setSupplyHolderOnTransfer(
        uint256 _tokenIdSupply,
        address _newSeller
    ) external;

    /**
     * @notice Set the general cancelOrFault period, should be used sparingly as it has significant consequences. Here done simply for demo purposes.
     * @param _cancelFaultPeriod   the new value for cancelOrFault period (in number of seconds)
     */
    function setCancelFaultPeriod(uint256 _cancelFaultPeriod) external;

    /**
     * @notice Set the address of the Boson Router contract
     * @param _bosonRouterAddress   The address of the BR contract
     */
    function setBosonRouterAddress(address _bosonRouterAddress) external;

    /**
     * @notice Set the address of the Cashier contract
     * @param _cashierAddress   The address of the Cashier contract
     */
    function setCashierAddress(address _cashierAddress) external;

    /**
     * @notice Set the address of the Vouchers token contract, an ERC721 contract
     * @param _voucherTokenAddress   The address of the Vouchers token contract
     */
    function setVoucherTokenAddress(address _voucherTokenAddress) external;

    /**
     * @notice Set the address of the Voucher Sets token contract, an ERC1155 contract
     * @param _voucherSetTokenAddress   The address of the Voucher Sets token contract
     */
    function setVoucherSetTokenAddress(address _voucherSetTokenAddress)
        external;

    /**
     * @notice Set the general complain period, should be used sparingly as it has significant consequences. Here done simply for demo purposes.
     * @param _complainPeriod   the new value for complain period (in number of seconds)
     */
    function setComplainPeriod(uint256 _complainPeriod) external;

    /**
     * @notice Get the promise ID at specific index
     * @param _idx  Index in the array of promise keys
     * @return      Promise ID
     */
    function getPromiseKey(uint256 _idx) external view returns (bytes32);

    /**
     * @notice Get the address of the token where the price for the supply is held
     * @param _tokenIdSupply   ID of the voucher token
     * @return                  Address of the token
     */
    function getVoucherPriceToken(uint256 _tokenIdSupply)
        external
        view
        returns (address);

    /**
     * @notice Get the address of the token where the deposits for the supply are held
     * @param _tokenIdSupply   ID of the voucher token
     * @return                  Address of the token
     */
    function getVoucherDepositToken(uint256 _tokenIdSupply)
        external
        view
        returns (address);

    /**
     * @notice Get Buyer costs required to make an order for a supply token
     * @param _tokenIdSupply   ID of the supply token
     * @return                  returns a tuple (Payment amount, Buyer's deposit)
     */
    function getBuyerOrderCosts(uint256 _tokenIdSupply)
        external
        view
        returns (uint256, uint256);

    /**
     * @notice Get Seller deposit
     * @param _tokenIdSupply   ID of the supply token
     * @return                  returns sellers deposit
     */
    function getSellerDeposit(uint256 _tokenIdSupply)
        external
        view
        returns (uint256);

    /**
     * @notice Get the promise ID from a voucher token
     * @param _tokenIdVoucher   ID of the voucher token
     * @return                  ID of the promise
     */
    function getIdSupplyFromVoucher(uint256 _tokenIdVoucher)
        external
        pure
        returns (uint256);

    /**
     * @notice Get the promise ID from a voucher token
     * @param _tokenIdVoucher   ID of the voucher token
     * @return                  ID of the promise
     */
    function getPromiseIdFromVoucherId(uint256 _tokenIdVoucher)
        external
        view
        returns (bytes32);

    /**
     * @notice Get all necessary funds for a supply token
     * @param _tokenIdSupply   ID of the supply token
     * @return                  returns a tuple (Payment amount, Seller's deposit, Buyer's deposit)
     */
    function getOrderCosts(uint256 _tokenIdSupply)
        external
        view
        returns (
            uint256,
            uint256,
            uint256
        );

    /**
     * @notice Get the remaining quantity left in supply of tokens (e.g ERC-721 left in ERC-1155) of an account
     * @param _tokenSupplyId  Token supply ID
     * @param _owner    holder of the Token Supply
     * @return          remaining quantity
     */
    function getRemQtyForSupply(uint256 _tokenSupplyId, address _owner)
        external
        view
        returns (uint256);

    /**
     * @notice Get the payment method for a particular _tokenIdSupply
     * @param _tokenIdSupply   ID of the voucher supply token
     * @return                  payment method
     */
    function getVoucherPaymentMethod(uint256 _tokenIdSupply)
        external
        view
        returns (PaymentMethod);

    /**
     * @notice Get the current status of a voucher
     * @param _tokenIdVoucher   ID of the voucher token
     * @return                  Status of the voucher (via enum)
     */
    function getVoucherStatus(uint256 _tokenIdVoucher)
        external
        view
        returns (
            uint8,
            bool,
            bool,
            uint256,
            uint256
        );

    /**
     * @notice Get the holder of a supply
     * @param _tokenIdSupply    _tokenIdSupply ID of the order (aka VoucherSet) which is mapped to the corresponding Promise.
     * @return                  Address of the holder
     */
    function getSupplyHolder(uint256 _tokenIdSupply)
        external
        view
        returns (address);

    /**
     * @notice Get the issuer of a voucher
     * @param _voucherTokenId ID of the voucher token
     * @return                Address of the seller, when voucher was created
     */
    function getVoucherSeller(uint256 _voucherTokenId)
        external
        view
        returns (address);

    /**
     * @notice Get the holder of a voucher
     * @param _tokenIdVoucher   ID of the voucher token
     * @return                  Address of the holder
     */
    function getVoucherHolder(uint256 _tokenIdVoucher)
        external
        view
        returns (address);

    /**
     * @notice Checks whether a voucher is in valid period for redemption (between start date and end date)
     * @param _tokenIdVoucher ID of the voucher token
     */
    function isInValidityPeriod(uint256 _tokenIdVoucher)
        external
        view
        returns (bool);

    /**
     * @notice Checks whether a voucher is in valid state to be transferred. If either payments or deposits are released, voucher could not be transferred
     * @param _tokenIdVoucher ID of the voucher token
     */
    function isVoucherTransferable(uint256 _tokenIdVoucher)
        external
        view
        returns (bool);

    /**
     * @notice Get address of the Boson Router contract to which this contract points
     * @return Address of the Boson Router contract
     */
    function getBosonRouterAddress() external view returns (address);

    /**
     * @notice Get address of the Cashier contract to which this contract points
     * @return Address of the Cashier contract
     */
    function getCashierAddress() external view returns (address);

    /**
     * @notice Get the token nonce for a seller
     * @param _seller Address of the seller
     * @return The seller's
     */
    function getTokenNonce(address _seller) external view returns (uint256);

    /**
     * @notice Get the current type Id
     * @return type Id
     */
    function getTypeId() external view returns (uint256);

    /**
     * @notice Get the complain period
     * @return complain period
     */
    function getComplainPeriod() external view returns (uint256);

    /**
     * @notice Get the cancel or fault period
     * @return cancel or fault period
     */
    function getCancelFaultPeriod() external view returns (uint256);

    /**
     * @notice Get promise data not retrieved by other accessor functions
     * @param _promiseKey   ID of the promise
     * @return promise data not returned by other accessor methods
     */
    function getPromiseData(bytes32 _promiseKey)
        external
        view
        returns (
            bytes32,
            uint256,
            uint256,
            uint256,
            uint256
        );

    /**
     * @notice Get the promise ID from a voucher set
     * @param _tokenIdSupply   ID of the voucher token
     * @return                  ID of the promise
     */
    function getPromiseIdFromSupplyId(uint256 _tokenIdSupply)
        external
        view
        returns (bytes32);

    /**
     * @notice Get the address of the Vouchers token contract, an ERC721 contract
     * @return Address of Vouchers contract
     */
    function getVoucherTokenAddress() external view returns (address);

    /**
     * @notice Get the address of the VoucherSets token contract, an ERC155 contract
     * @return Address of VoucherSets contract
     */
    function getVoucherSetTokenAddress() external view returns (address);
}
          

/

// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

import "./Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor () {
        _paused = false;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        require(!paused(), "Pausable: paused");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        require(paused(), "Pausable: not paused");
        _;
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
          

/

// SPDX-License-Identifier: LGPL-3.0-or-later
pragma solidity 0.7.6;

interface ITokenWrapper {
    event LogTokenAddressChanged(
        address indexed _newWrapperAddress,
        address indexed _triggeredBy
    );

    event LogPermitCalledOnToken(
        address indexed _tokenAddress,
        address indexed _owner,
        address indexed _spender,
        uint256 _value
    );

    /**
     * @notice Provides a way to make calls to the permit function of tokens in a uniform way
     * @param _owner Address of the token owner who is approving tokens to be transferred by spender
     * @param _spender Address of the party who is transferring tokens on owner's behalf
     * @param _value Number of tokens to be transferred
     * @param _deadline Time after which this permission to transfer is no longer valid
     * @param _v Part of the owner's signatue
     * @param _r Part of the owner's signatue
     * @param _s Part of the owner's signatue
     */
    function permit(
        address _owner,
        address _spender,
        uint256 _value,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) external;

    /**
     * @notice Set the address of the wrapper contract for the token. The wrapper is used to, for instance, allow the Boson Protocol functions that use permit functionality to work in a uniform way.
     * @param _tokenAddress Address of the token which will be updated.
     */
    function setTokenAddress(address _tokenAddress) external;

    /**
     * @notice Get the address of the token wrapped by this contract
     * @return Address of the token wrapper contract
     */
    function getTokenAddress() external view returns (address);
}
          

/

// SPDX-License-Identifier: LGPL-3.0-or-later

pragma solidity 0.7.6;
pragma abicoder v2;

import "./../UsingHelpers.sol";

interface IGate {
    /**
     * @notice Registers connection between setID and tokenID
     * @param _tokenIdSupply an ID of a supply token (ERC-1155)
     * @param _conditionalCommitInfo struct that contains data pertaining to conditional commit:
     *
     * uint256 conditionalTokenId - Id of the conditional token, ownership of which is a condition for committing to redeem a voucher
     * in the voucher set created by this function.
     *
     * uint256 threshold - the number that the balance of a tokenId must be greater than or equal to. Not used for OWNERSHIP condition
     *
     * Condition condition - condition that will be checked when a user commits using a conditional token
     *
     * address gateAddress - address of a gate contract that will handle the interaction between the BosonRouter contract and the conditional token,
     * ownership of which is a condition for committing to redeem a voucher in the voucher set created by this function.
     *
     * bool registerConditionalCommit - indicates whether Gate.registerVoucherSetId should be called. Gate.registerVoucherSetId can also be called separately
     */
    function registerVoucherSetId(
        uint256 _tokenIdSupply,
        ConditionalCommitInfo calldata _conditionalCommitInfo
    ) external;

    /**
     * @notice Checks if user possesses the required conditional token for given voucher set
     * @param _user user address
     * @param _tokenIdSupply an ID of a supply token (ERC-1155) [voucherSetID]
     * @return true if user possesses conditional token, and the token is not deactivated
     */
    function check(address _user, uint256 _tokenIdSupply)
        external
        view
        returns (bool);

    /**
     * @notice Stores information that certain user already claimed
     * @param _user user address
     * @param _tokenIdSupply an ID of a supply token (ERC-1155) [voucherSetID]
     */
    function deactivate(address _user, uint256 _tokenIdSupply) external;
}
          

/

// SPDX-License-Identifier: MIT

pragma solidity ^0.7.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 () {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

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

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        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 {
        emit OwnershipTransferred(_owner, address(0));
        _owner = 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");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}
          

/

// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

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

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (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");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private 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

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}
          

/

// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when 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.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) return (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}
          

/

// SPDX-License-Identifier: MIT

pragma solidity ^0.7.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 make 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;
    }
}
          

/

// SPDX-License-Identifier: LGPL-3.0-or-later

pragma solidity 0.7.6;

import "../interfaces/IERC20WithPermit.sol";
import "@openzeppelin/contracts/utils/Address.sol";

/**
 * @title SafeERC20WithPermit
 * @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 SafeERC20WithPermit for IERC20WithPermit;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20WithPermit {
    using Address for address;

    function safeTransferFrom(
        IERC20WithPermit _token,
        address _from,
        address _to,
        uint256 _value
    ) internal {
        _callOptionalReturn(
            _token,
            abi.encodeWithSelector(
                _token.transferFrom.selector,
                _from,
                _to,
                _value
            )
        );
    }

    /**
     * @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(IERC20WithPermit _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,
            "SafeERC20WithPermit: low-level call failed"
        );
        if (returndata.length > 0) {
            // Return data is optional
            // solhint-disable-next-line max-line-length
            require(
                abi.decode(returndata, (bool)),
                "SafeERC20WithPermit: ERC20WithPermit operation did not succeed"
            );
        }
    }
}
          

/

// SPDX-License-Identifier: LGPL-3.0-or-later

pragma solidity 0.7.6;

interface ITokenRegistry {
    /**
     * @notice Set new limit for a token. It's used while seller tries to create a voucher. The limit is determined by a voucher set. Voucher price * quantity, seller deposit * quantity, buyer deposit * qty must be below the limit.
     * @param _tokenAddress Address of the token which will be updated.
     * @param _newLimit New limit which will be set. It must comply to the decimals of the token, so the limit is set in the correct decimals.
     */
    function setTokenLimit(address _tokenAddress, uint256 _newLimit) external;

    /**
     * @notice Get the maximum allowed token limit for the specified Token.
     * @param _tokenAddress Address of the token which will be update.
     * @return The max limit for this token
     */
    function getTokenLimit(address _tokenAddress)
        external
        view
        returns (uint256);

    /**
     * @notice Set new limit for ETH. It's used while seller tries to create a voucher. The limit is determined by a voucher set. Voucher price * quantity, seller deposit * quantity, buyer deposit * qty must be below the limit.
     * @param _newLimit New limit which will be set.
     */
    function setETHLimit(uint256 _newLimit) external;

    /**
     * @notice Get the maximum allowed ETH limit to set as price of voucher, buyer deposit or seller deposit.
     * @return The max ETH limit
     */
    function getETHLimit() external view returns (uint256);

    /**
     * @notice Set the address of the wrapper contract for the token. The wrapper is used to, for instance, allow the Boson Protocol functions that use permit functionality to work in a uniform way.
     * @param _tokenAddress Address of the token which will be updated.
     * @param _wrapperAddress Address of the wrapper contract
     */
    function setTokenWrapperAddress(
        address _tokenAddress,
        address _wrapperAddress
    ) external;

    /**
     * @notice Get the address of the token wrapper contract for the specified token
     * @param _tokenAddress Address of the token which will be updated.
     * @return Address of the token wrapper contract
     */
    function getTokenWrapperAddress(address _tokenAddress)
        external
        view
        returns (address);
}
          

/

// SPDX-License-Identifier: LGPL-3.0-or-later
pragma solidity 0.7.6;

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

interface IERC20WithPermit is IERC20 {
    function name() external view returns (string memory);

    function symbol() external view returns (string memory);

    function decimals() external pure returns (uint8);

    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);

    // solhint-disable-next-line func-name-mixedcase
    function PERMIT_TYPEHASH() external pure returns (bytes32);

    function nonces(address _owner) external view returns (uint256);

    function permit(
        address _owner,
        address _spender,
        uint256 _value,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) external;
}
          

/IERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.7.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

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

/

// SPDX-License-Identifier: LGPL-3.0-or-later

pragma solidity 0.7.6;

// Those are the payment methods we are using throughout the system.
// Depending on how to user choose to interact with it's funds we store the method, so we could distribute its tokens afterwise
enum PaymentMethod {
    ETHETH,
    ETHTKN,
    TKNETH,
    TKNTKN
}

enum Entity {ISSUER, HOLDER, POOL}

enum VoucherState {FINAL, CANCEL_FAULT, COMPLAIN, EXPIRE, REFUND, REDEEM, COMMIT}
/*  Status of the voucher in 8 bits:
    [6:COMMITTED] [5:REDEEMED] [4:REFUNDED] [3:EXPIRED] [2:COMPLAINED] [1:CANCELORFAULT] [0:FINAL]
*/

enum Condition {NOT_SET, BALANCE, OWNERSHIP} //Describes what kind of condition must be met for a conditional commit

struct ConditionalCommitInfo {
    uint256 conditionalTokenId;
    uint256 threshold;
    Condition condition;
    address gateAddress;
    bool registerConditionalCommit;
}

uint8 constant ONE = 1;

struct VoucherDetails {
    uint256 tokenIdSupply;
    uint256 tokenIdVoucher;
    address issuer;
    address holder;
    uint256 price;
    uint256 depositSe;
    uint256 depositBu;
    PaymentMethod paymentMethod;
    VoucherStatus currStatus;
}

struct VoucherStatus {
    address seller;
    uint8 status;
    bool isPaymentReleased;
    bool isDepositsReleased;
    DepositsReleased depositReleased;
    uint256 complainPeriodStart;
    uint256 cancelFaultPeriodStart;
}

struct DepositsReleased {
    uint8 status;
    uint248 releasedAmount;
}

/**
    * @notice Based on its lifecycle, voucher can have many different statuses. Checks whether a voucher is in Committed state.
    * @param _status current status of a voucher.
    */
function isStateCommitted(uint8 _status) pure returns (bool) {
    return _status == determineStatus(0, VoucherState.COMMIT);
}

/**
    * @notice Based on its lifecycle, voucher can have many different statuses. Checks whether a voucher is in RedemptionSigned state.
    * @param _status current status of a voucher.
    */
function isStateRedemptionSigned(uint8 _status)
    pure
    returns (bool)
{
    return _status == determineStatus(determineStatus(0, VoucherState.COMMIT), VoucherState.REDEEM);
}

/**
    * @notice Based on its lifecycle, voucher can have many different statuses. Checks whether a voucher is in Refunded state.
    * @param _status current status of a voucher.
    */
function isStateRefunded(uint8 _status) pure returns (bool) {
    return _status == determineStatus(determineStatus(0, VoucherState.COMMIT), VoucherState.REFUND);
}

/**
    * @notice Based on its lifecycle, voucher can have many different statuses. Checks whether a voucher is in Expired state.
    * @param _status current status of a voucher.
    */
function isStateExpired(uint8 _status) pure returns (bool) {
    return _status == determineStatus(determineStatus(0, VoucherState.COMMIT), VoucherState.EXPIRE);
}

/**
    * @notice Based on its lifecycle, voucher can have many different statuses. Checks the current status a voucher is at.
    * @param _status current status of a voucher.
    * @param _idx status to compare.
    */
function isStatus(uint8 _status, VoucherState _idx) pure returns (bool) {
    return (_status >> uint8(_idx)) & ONE == 1;
}

/**
    * @notice Set voucher status.
    * @param _status previous status.
    * @param _changeIdx next status.
    */
function determineStatus(uint8 _status, VoucherState _changeIdx)
    pure
    returns (uint8)
{
    return _status | (ONE << uint8(_changeIdx));
}
          

/

// SPDX-License-Identifier: LGPL-3.0-or-later

pragma solidity 0.7.6;
pragma abicoder v2;

import "./../UsingHelpers.sol";

interface IBosonRouter {
    function pause() external;

    function unpause() external;

    /**
     * @notice Issuer/Seller offers promises as supply tokens and needs to escrow the deposit
        @param _metadata metadata which is required for creation of a voucher
        Metadata array is used as in some scenarios we need several more params, as we need to recover 
        owner address in order to permit the contract to transfer funds in his behalf. 
        Since the params get too many, we end up in situation that the stack is too deep.
        
        uint256 _validFrom = _metadata[0];
        uint256 _validTo = _metadata[1];
        uint256 _price = _metadata[2];
        uint256 _depositSe = _metadata[3];
        uint256 _depositBu = _metadata[4];
        uint256 _quantity = _metadata[5];
     */
    function requestCreateOrderETHETH(uint256[] calldata _metadata)
        external
        payable;

    function requestCreateOrderETHETHConditional(
        uint256[] calldata _metadata,
        ConditionalCommitInfo calldata _conditionalCommitInfo
    ) external payable;

    function requestCreateOrderTKNTKNWithPermit(
        address _tokenPriceAddress,
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata
    ) external;

    function requestCreateOrderTKNTKNWithPermitConditional(
        address _tokenPriceAddress,
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata,
        ConditionalCommitInfo calldata _conditionalCommitInfo
    ) external;

    function requestCreateOrderETHTKNWithPermit(
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata
    ) external;

    function requestCreateOrderETHTKNWithPermitConditional(
        address _tokenDepositAddress,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s,
        uint256[] calldata _metadata,
        ConditionalCommitInfo calldata _conditionalCommitInfo
    ) external;

    function requestCreateOrderTKNETH(
        address _tokenPriceAddress,
        uint256[] calldata _metadata
    ) external payable;

    function requestCreateOrderTKNETHConditional(
        address _tokenPriceAddress,
        uint256[] calldata _metadata,
        ConditionalCommitInfo calldata _conditionalCommitInfo
    ) external payable;

    /**
     * @notice Consumer requests/buys a voucher by filling an order and receiving a Voucher Token in return
     * @param _tokenIdSupply    ID of the supply token
     * @param _issuer           Address of the issuer of the supply token
     */
    function requestVoucherETHETH(uint256 _tokenIdSupply, address _issuer)
        external
        payable;

    function requestVoucherTKNTKNWithPermit(
        uint256 _tokenIdSupply,
        address _issuer,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _vPrice,
        bytes32 _rPrice,
        bytes32 _sPrice, // tokenPrice
        uint8 _vDeposit,
        bytes32 _rDeposit,
        bytes32 _sDeposit // tokenDeposits
    ) external;

    function requestVoucherTKNTKNSameWithPermit(
        uint256 _tokenIdSupply,
        address _issuer,
        uint256 _tokensSent,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) external;

    function requestVoucherETHTKNWithPermit(
        uint256 _tokenIdSupply,
        address _issuer,
        uint256 _tokensDeposit,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) external payable;

    function requestVoucherTKNETHWithPermit(
        uint256 _tokenIdSupply,
        address _issuer,
        uint256 _tokensPrice,
        uint256 _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) external payable;

    /**
     * @notice Seller burns the remaining supply and withdrawal of the locked deposits for them are being sent back.
     * @param _tokenIdSupply an ID of a supply token (ERC-1155) which will be burned and deposits will be returned for
     */
    function requestCancelOrFaultVoucherSet(uint256 _tokenIdSupply) external;

    /**
     * @notice Redemption of the vouchers promise
     * @param _tokenIdVoucher   ID of the voucher
     */
    function redeem(uint256 _tokenIdVoucher) external;

    /**
     * @notice Refunding a voucher
     * @param _tokenIdVoucher   ID of the voucher
     */
    function refund(uint256 _tokenIdVoucher) external;

    /**
     * @notice Issue a complain for a voucher
     * @param _tokenIdVoucher   ID of the voucher
     */
    function complain(uint256 _tokenIdVoucher) external;

    /**
     * @notice Cancel/Fault transaction by the Seller, admitting to a fault or backing out of the deal
     * @param _tokenIdVoucher   ID of the voucher
     */
    function cancelOrFault(uint256 _tokenIdVoucher) external;

    /**
     * @notice Get the address of Cashier contract
     * @return Address of Cashier address
     */
    function getCashierAddress() external view returns (address);

    /**
     * @notice Get the address of Voucher Kernel contract
     * @return Address of Voucher Kernel contract
     */
    function getVoucherKernelAddress() external view returns (address);

    /**
     * @notice Get the address gate contract that handles conditional commit of certain voucher set
     * @param _tokenIdSupply    ID of the supply token
     * @return Address of the gate contract or zero address if there is no conditional commit
     */
    function getVoucherSetToGateContract(uint256 _tokenIdSupply)
        external
        view
        returns (address);

    function getTokenRegistryAddress() external view returns (address);
}
          

/

// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <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 GSN 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 payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}
          

Compiler Settings

{"remappings":[],"optimizer":{"runs":200,"enabled":true},"metadata":{"bytecodeHash":"ipfs"},"libraries":{},"evmVersion":"istanbul","compilationTarget":{"contracts/BosonRouter.sol":"BosonRouter"}}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_voucherKernel","internalType":"address"},{"type":"address","name":"_tokenRegistry","internalType":"address"},{"type":"address","name":"_cashierAddress","internalType":"address"}]},{"type":"event","name":"LogCashierSet","inputs":[{"type":"address","name":"_newCashier","internalType":"address","indexed":false},{"type":"address","name":"_triggeredBy","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"LogConditionalOrderCreated","inputs":[{"type":"uint256","name":"_tokenIdSupply","internalType":"uint256","indexed":true},{"type":"address","name":"_gateAddress","internalType":"address","indexed":true},{"type":"uint256","name":"_conditionalTokenId","internalType":"uint256","indexed":true},{"type":"uint8","name":"_condition","internalType":"enum Condition","indexed":false},{"type":"uint256","name":"_threshold","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"LogGateApprovalChanged","inputs":[{"type":"address","name":"_gateAddress","internalType":"address","indexed":true},{"type":"bool","name":"_approved","internalType":"bool","indexed":false}],"anonymous":false},{"type":"event","name":"LogOrderCreated","inputs":[{"type":"uint256","name":"_tokenIdSupply","internalType":"uint256","indexed":true},{"type":"address","name":"_seller","internalType":"address","indexed":true},{"type":"uint256","name":"_quantity","internalType":"uint256","indexed":false},{"type":"uint8","name":"_paymentType","internalType":"enum PaymentMethod","indexed":false}],"anonymous":false},{"type":"event","name":"LogTokenRegistrySet","inputs":[{"type":"address","name":"_newTokenRegistry","internalType":"address","indexed":false},{"type":"address","name":"_triggeredBy","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"LogVoucherKernelSet","inputs":[{"type":"address","name":"_newVoucherKernel","internalType":"address","indexed":false},{"type":"address","name":"_triggeredBy","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"Paused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"Unpaused","inputs":[{"type":"address","name":"account","internalType":"address","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"cancelOrFault","inputs":[{"type":"uint256","name":"_tokenIdVoucher","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"complain","inputs":[{"type":"uint256","name":"_tokenIdVoucher","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getCashierAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getTokenRegistryAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getVoucherKernelAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getVoucherSetToGateContract","inputs":[{"type":"uint256","name":"_tokenIdSupply","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"pause","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"paused","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"redeem","inputs":[{"type":"uint256","name":"_tokenIdVoucher","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"refund","inputs":[{"type":"uint256","name":"_tokenIdVoucher","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"requestCancelOrFaultVoucherSet","inputs":[{"type":"uint256","name":"_tokenIdSupply","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"requestCreateOrderETHETH","inputs":[{"type":"uint256[]","name":"_metadata","internalType":"uint256[]"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"requestCreateOrderETHETHConditional","inputs":[{"type":"uint256[]","name":"_metadata","internalType":"uint256[]"},{"type":"tuple","name":"_conditionalCommitInfo","internalType":"struct ConditionalCommitInfo","components":[{"type":"uint256","name":"conditionalTokenId","internalType":"uint256"},{"type":"uint256","name":"threshold","internalType":"uint256"},{"type":"uint8","name":"condition","internalType":"enum Condition"},{"type":"address","name":"gateAddress","internalType":"address"},{"type":"bool","name":"registerConditionalCommit","internalType":"bool"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"requestCreateOrderETHTKNWithPermit","inputs":[{"type":"address","name":"_tokenDepositAddress","internalType":"address"},{"type":"uint256","name":"_tokensSent","internalType":"uint256"},{"type":"uint256","name":"_deadline","internalType":"uint256"},{"type":"uint8","name":"_v","internalType":"uint8"},{"type":"bytes32","name":"_r","internalType":"bytes32"},{"type":"bytes32","name":"_s","internalType":"bytes32"},{"type":"uint256[]","name":"_metadata","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"requestCreateOrderETHTKNWithPermitConditional","inputs":[{"type":"address","name":"_tokenDepositAddress","internalType":"address"},{"type":"uint256","name":"_tokensSent","internalType":"uint256"},{"type":"uint256","name":"_deadline","internalType":"uint256"},{"type":"uint8","name":"_v","internalType":"uint8"},{"type":"bytes32","name":"_r","internalType":"bytes32"},{"type":"bytes32","name":"_s","internalType":"bytes32"},{"type":"uint256[]","name":"_metadata","internalType":"uint256[]"},{"type":"tuple","name":"_conditionalCommitInfo","internalType":"struct ConditionalCommitInfo","components":[{"type":"uint256","name":"conditionalTokenId","internalType":"uint256"},{"type":"uint256","name":"threshold","internalType":"uint256"},{"type":"uint8","name":"condition","internalType":"enum Condition"},{"type":"address","name":"gateAddress","internalType":"address"},{"type":"bool","name":"registerConditionalCommit","internalType":"bool"}]}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"requestCreateOrderTKNETH","inputs":[{"type":"address","name":"_tokenPriceAddress","internalType":"address"},{"type":"uint256[]","name":"_metadata","internalType":"uint256[]"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"requestCreateOrderTKNETHConditional","inputs":[{"type":"address","name":"_tokenPriceAddress","internalType":"address"},{"type":"uint256[]","name":"_metadata","internalType":"uint256[]"},{"type":"tuple","name":"_conditionalCommitInfo","internalType":"struct ConditionalCommitInfo","components":[{"type":"uint256","name":"conditionalTokenId","internalType":"uint256"},{"type":"uint256","name":"threshold","internalType":"uint256"},{"type":"uint8","name":"condition","internalType":"enum Condition"},{"type":"address","name":"gateAddress","internalType":"address"},{"type":"bool","name":"registerConditionalCommit","internalType":"bool"}]}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"requestCreateOrderTKNTKNWithPermit","inputs":[{"type":"address","name":"_tokenPriceAddress","internalType":"address"},{"type":"address","name":"_tokenDepositAddress","internalType":"address"},{"type":"uint256","name":"_tokensSent","internalType":"uint256"},{"type":"uint256","name":"_deadline","internalType":"uint256"},{"type":"uint8","name":"_v","internalType":"uint8"},{"type":"bytes32","name":"_r","internalType":"bytes32"},{"type":"bytes32","name":"_s","internalType":"bytes32"},{"type":"uint256[]","name":"_metadata","internalType":"uint256[]"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"requestCreateOrderTKNTKNWithPermitConditional","inputs":[{"type":"address","name":"_tokenPriceAddress","internalType":"address"},{"type":"address","name":"_tokenDepositAddress","internalType":"address"},{"type":"uint256","name":"_tokensSent","internalType":"uint256"},{"type":"uint256","name":"_deadline","internalType":"uint256"},{"type":"uint8","name":"_v","internalType":"uint8"},{"type":"bytes32","name":"_r","internalType":"bytes32"},{"type":"bytes32","name":"_s","internalType":"bytes32"},{"type":"uint256[]","name":"_metadata","internalType":"uint256[]"},{"type":"tuple","name":"_conditionalCommitInfo","internalType":"struct ConditionalCommitInfo","components":[{"type":"uint256","name":"conditionalTokenId","internalType":"uint256"},{"type":"uint256","name":"threshold","internalType":"uint256"},{"type":"uint8","name":"condition","internalType":"enum Condition"},{"type":"address","name":"gateAddress","internalType":"address"},{"type":"bool","name":"registerConditionalCommit","internalType":"bool"}]}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"requestVoucherETHETH","inputs":[{"type":"uint256","name":"_tokenIdSupply","internalType":"uint256"},{"type":"address","name":"_issuer","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"requestVoucherETHTKNWithPermit","inputs":[{"type":"uint256","name":"_tokenIdSupply","internalType":"uint256"},{"type":"address","name":"_issuer","internalType":"address"},{"type":"uint256","name":"_tokensDeposit","internalType":"uint256"},{"type":"uint256","name":"_deadline","internalType":"uint256"},{"type":"uint8","name":"_v","internalType":"uint8"},{"type":"bytes32","name":"_r","internalType":"bytes32"},{"type":"bytes32","name":"_s","internalType":"bytes32"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"requestVoucherTKNETHWithPermit","inputs":[{"type":"uint256","name":"_tokenIdSupply","internalType":"uint256"},{"type":"address","name":"_issuer","internalType":"address"},{"type":"uint256","name":"_tokensPrice","internalType":"uint256"},{"type":"uint256","name":"_deadline","internalType":"uint256"},{"type":"uint8","name":"_v","internalType":"uint8"},{"type":"bytes32","name":"_r","internalType":"bytes32"},{"type":"bytes32","name":"_s","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"requestVoucherTKNTKNSameWithPermit","inputs":[{"type":"uint256","name":"_tokenIdSupply","internalType":"uint256"},{"type":"address","name":"_issuer","internalType":"address"},{"type":"uint256","name":"_tokensSent","internalType":"uint256"},{"type":"uint256","name":"_deadline","internalType":"uint256"},{"type":"uint8","name":"_v","internalType":"uint8"},{"type":"bytes32","name":"_r","internalType":"bytes32"},{"type":"bytes32","name":"_s","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"requestVoucherTKNTKNWithPermit","inputs":[{"type":"uint256","name":"_tokenIdSupply","internalType":"uint256"},{"type":"address","name":"_issuer","internalType":"address"},{"type":"uint256","name":"_tokensSent","internalType":"uint256"},{"type":"uint256","name":"_deadline","internalType":"uint256"},{"type":"uint8","name":"_vPrice","internalType":"uint8"},{"type":"bytes32","name":"_rPrice","internalType":"bytes32"},{"type":"bytes32","name":"_sPrice","internalType":"bytes32"},{"type":"uint8","name":"_vDeposit","internalType":"uint8"},{"type":"bytes32","name":"_rDeposit","internalType":"bytes32"},{"type":"bytes32","name":"_sDeposit","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCashierAddress","inputs":[{"type":"address","name":"_cashierAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setGateApproval","inputs":[{"type":"address","name":"_gateAddress","internalType":"address"},{"type":"bool","name":"_approved","internalType":"bool"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTokenRegistryAddress","inputs":[{"type":"address","name":"_tokenRegistryAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setVoucherKernelAddress","inputs":[{"type":"address","name":"_voucherKernelAddress","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unpause","inputs":[]}]
              

Contract Creation Code

0x60806040523480156200001157600080fd5b506040516200427f3803806200427f83398101604081905262000034916200023d565b6000805460ff19168155600180556200004c6200021c565b600280546001600160a01b0319166001600160a01b038316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a350826001600160a01b038116620000cd5760405162461bcd60e51b8152600401620000c490620002a0565b60405180910390fd5b826001600160a01b038116620000f75760405162461bcd60e51b8152600401620000c490620002a0565b826001600160a01b038116620001215760405162461bcd60e51b8152600401620000c490620002a0565b600480546001600160a01b038089166001600160a01b0319928316179092556005805488841690831617905560038054928716929091169190911790556040517f94d4208cb05337821fef5da6205084b70818af988524d8a2609a53a1ac1033d19062000192908890339062000286565b60405180910390a17f31d91a51396c4dd6a866b29210f1038e7c63a854057ddef76f1578addaf643f08533604051620001cd92919062000286565b60405180910390a17fcd124a0a6c3182c7bb77b8052823a4bf7d0a4c90016ffc4d53b969f98d3f8b8884336040516200020892919062000286565b60405180910390a1505050505050620002bc565b3390565b80516001600160a01b03811681146200023857600080fd5b919050565b60008060006060848603121562000252578283fd5b6200025d8462000220565b92506200026d6020850162000220565b91506200027d6040850162000220565b90509250925092565b6001600160a01b0392831681529116602082015260400190565b602080825260029082015261304160f01b604082015260600190565b613fb380620002cc6000396000f3fe6080604052600436106101e35760003560e01c8063ad7f049311610102578063d7e308bd11610095578063e3f5d2d511610064578063e3f5d2d5146104f0578063ef07b4cc14610505578063f2fde38b14610525578063f9d9309914610545576101e3565b8063d7e308bd1461048a578063d95be43a1461049d578063db006a75146104bd578063dea7f423146104dd576101e3565b8063c241649a116100d1578063c241649a14610422578063c930666e14610442578063caed989714610462578063cf4e794d14610477576101e3565b8063ad7f0493146103af578063b2c076c8146103c2578063bc16ba47146103e2578063c099a7c414610402576101e3565b80635c975abb1161017a5780638456cb59116101495780638456cb59146103525780638503b5c9146103675780638da5cb5b1461037a57806392fcbdc11461039c576101e3565b80635c975abb146102df5780636ad0cfe11461030a578063715018a61461031d578063765e0fb814610332576101e3565b8063284f0923116101b6578063284f09231461026a5780632bcb22881461028a5780633f4ba83a146102aa57806358555ab8146102bf576101e3565b80630bd74705146101e85780631a245b8e1461020a578063231e0f511461022a578063278ecde11461024a575b600080fd5b3480156101f457600080fd5b50610208610203366004613909565b61055a565b005b34801561021657600080fd5b5061020861022536600461395d565b6106e7565b34801561023657600080fd5b506102086102453660046136c4565b610a00565b34801561025657600080fd5b50610208610265366004613909565b610b29565b34801561027657600080fd5b50610208610285366004613909565b610b8f565b34801561029657600080fd5b506102086102a5366004613787565b610bc0565b3480156102b657600080fd5b50610208610c76565b3480156102cb57600080fd5b506102086102da366004613481565b610ea4565b3480156102eb57600080fd5b506102f4610fd6565b6040516103019190613b6d565b60405180910390f35b610208610318366004613939565b610fdf565b34801561032957600080fd5b50610208611149565b34801561033e57600080fd5b5061020861034d366004613909565b6111f5565b34801561035e57600080fd5b50610208611226565b61020861037536600461365e565b611396565b34801561038657600080fd5b5061038f611436565b6040516103019190613a86565b6102086103aa36600461395d565b611445565b6102086103bd36600461395d565b611657565b3480156103ce57600080fd5b506102086103dd3660046139c1565b611859565b3480156103ee57600080fd5b506102086103fd3660046136fc565b611b8e565b34801561040e57600080fd5b5061020861041d366004613481565b611bf8565b34801561042e57600080fd5b5061020861043d3660046134b9565b611d1e565b34801561044e57600080fd5b5061020861045d36600461355a565b611d7a565b34801561046e57600080fd5b5061038f611e32565b610208610485366004613864565b611e41565b61020861049836600461360b565b611f42565b3480156104a957600080fd5b506102086104b8366004613481565b611fa2565b3480156104c957600080fd5b506102086104d8366004613909565b6120c8565b6102086104eb366004613824565b6120f9565b3480156104fc57600080fd5b5061038f6121b9565b34801561051157600080fd5b5061038f610520366004613909565b6121c8565b34801561053157600080fd5b50610208610540366004613481565b6121e6565b34801561055157600080fd5b5061038f6122e9565b600260015414156105a0576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556105ad610fd6565b156105f2576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b600480546040516322af217960e11b81526000926001600160a01b039092169163455e42f291610626918691339101613d27565b602060405180830381600087803b15801561064057600080fd5b505af1158015610654573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106789190613921565b600354604051632990c23f60e11b81529192506001600160a01b031690635321847e906106ad90859085903390600401613e26565b600060405180830381600087803b1580156106c757600080fd5b505af11580156106db573d6000803e3d6000fd5b50506001805550505050565b6002600154141561072d576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b600260015561073a610fd6565b1561077f576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b610788876122f8565b60048054604051633eb53ba560e21b815260009283926001600160a01b03169163fad4ee94916107ba918d9101613d1e565b604080518083038186803b1580156107d157600080fd5b505afa1580156107e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108099190613a4b565b9092509050816108198883612427565b1461083f5760405162461bcd60e51b815260040161083690613c3a565b60405180910390fd5b6004805460405163e875a61360e01b81526000926001600160a01b039092169163e875a61391610871918e9101613d1e565b60206040518083038186803b15801561088957600080fd5b505afa15801561089d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c1919061349d565b60048054604051639a751bbd60e01b81529293506000926001600160a01b0390911691639a751bbd916108f6918f9101613d1e565b60206040518083038186803b15801561090e57600080fd5b505afa158015610922573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610946919061349d565b9050806001600160a01b0316826001600160a01b0316146109795760405162461bcd60e51b815260040161083690613be7565b610987828a8a8a8a8a612489565b60048054604051632417f08f60e21b81526001600160a01b039091169163905fc23c916109bd918f918f91339160039101613d3e565b600060405180830381600087803b1580156109d757600080fd5b505af11580156109eb573d6000803e3d6000fd5b50506001805550505050505050505050505050565b610a086124a3565b6001600160a01b0316610a19611436565b6001600160a01b031614610a62576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b816001600160a01b038116610a895760405162461bcd60e51b815260040161083690613c79565b6001600160a01b03831660009081526006602052604090205460ff1615158215151415610ac85760405162461bcd60e51b815260040161083690613c56565b6001600160a01b03831660008181526006602052604090819020805460ff1916851515179055517f15635ac22e35b377e346d03ece59297a10454eb8b7713b664c69f4bcaf2aaa6190610b1c908590613b6d565b60405180910390a2505050565b60048054604051631eb489b760e21b81526001600160a01b0390911691637ad226dc91610b5a918591339101613d27565b600060405180830381600087803b158015610b7457600080fd5b505af1158015610b88573d6000803e3d6000fd5b5050505050565b600480546040516366db9a0960e01b81526001600160a01b03909116916366db9a0991610b5a918591339101613d27565b60026001541415610c06576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556001600160a01b0360608201351660008181526006602052604090205460ff16610c475760405162461bcd60e51b815260040161083690613c95565b6000610c598b8b8b8b8b8b8b8b6124a7565b9050610c658184612559565b505060018055505050505050505050565b610c7e6124a3565b6001600160a01b0316610c8f611436565b6001600160a01b031614610cb55760405162461bcd60e51b815260040161083690613baf565b600360009054906101000a90046001600160a01b03166001600160a01b031663ae04884e6040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0357600080fd5b505afa158015610d17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3b91906138d3565b610d575760405162461bcd60e51b815260040161083690613c1e565b610d5f612653565b6004805460408051635c975abb60e01b815290516001600160a01b0390921692635c975abb928282019260209290829003018186803b158015610da157600080fd5b505afa158015610db5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd991906138d3565b15610ea2576004805460408051631fa5d41d60e11b815290516001600160a01b0390921692633f4ba83a92828201926000929082900301818387803b158015610e2157600080fd5b505af1158015610e35573d6000803e3d6000fd5b50505050600360009054906101000a90046001600160a01b03166001600160a01b0316633f4ba83a6040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610e8957600080fd5b505af1158015610e9d573d6000803e3d6000fd5b505050505b565b610eac6124a3565b6001600160a01b0316610ebd611436565b6001600160a01b031614610f06576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b806001600160a01b038116610f2d5760405162461bcd60e51b815260040161083690613c79565b610f35610fd6565b610f7d576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b600580546001600160a01b0319166001600160a01b0384161790556040517f31d91a51396c4dd6a866b29210f1038e7c63a854057ddef76f1578addaf643f090610fca9084903390613aee565b60405180910390a15050565b60005460ff1690565b60026001541415611025576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611032610fd6565b15611077576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b611080826122f8565b60048054604051633eb53ba560e21b8152349260009283926001600160a01b039091169163fad4ee94916110b691899101613d1e565b604080518083038186803b1580156110cd57600080fd5b505afa1580156110e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111059190613a4b565b90925090508261111583836126f3565b146111325760405162461bcd60e51b815260040161083690613c3a565b61113e85856000612754565b505060018055505050565b6111516124a3565b6001600160a01b0316611162611436565b6001600160a01b0316146111ab576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b6002546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600280546001600160a01b0319169055565b60048054604051631ebaf54360e31b81526001600160a01b039091169163f5d7aa1891610b5a918591339101613d27565b61122e6124a3565b6001600160a01b031661123f611436565b6001600160a01b0316146112655760405162461bcd60e51b815260040161083690613baf565b61126d612824565b6004805460408051635c975abb60e01b815290516001600160a01b0390921692635c975abb928282019260209290829003018186803b1580156112af57600080fd5b505afa1580156112c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112e791906138d3565b610ea2576004805460408051638456cb5960e01b815290516001600160a01b0390921692638456cb5992828201926000929082900301818387803b15801561132e57600080fd5b505af1158015611342573d6000803e3d6000fd5b50505050600360009054906101000a90046001600160a01b03166001600160a01b0316638456cb596040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610e8957600080fd5b600260015414156113dc576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556001600160a01b0360608201351660008181526006602052604090205460ff1661141d5760405162461bcd60e51b815260040161083690613c95565b600061142a8686866128a7565b90506106db8184612559565b6002546001600160a01b031690565b6002600154141561148b576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611498610fd6565b156114dd576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6114e6876122f8565b60048054604051633eb53ba560e21b815260009283926001600160a01b03169163fad4ee9491611518918d9101613d1e565b604080518083038186803b15801561152f57600080fd5b505afa158015611543573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115679190613a4b565b9150915034821461158a5760405162461bcd60e51b815260040161083690613ce6565b8681146115a95760405162461bcd60e51b815260040161083690613b93565b60048054604051639a751bbd60e01b81526000926001600160a01b0390921691639a751bbd916115db918e9101613d1e565b60206040518083038186803b1580156115f357600080fd5b505afa158015611607573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061162b919061349d565b905061163b818989898989612489565b6116478a8a6001612754565b5050600180555050505050505050565b6002600154141561169d576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556116aa610fd6565b156116ef576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6116f8876122f8565b60048054604051633eb53ba560e21b815260009283926001600160a01b03169163fad4ee949161172a918d9101613d1e565b604080518083038186803b15801561174157600080fd5b505afa158015611755573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117799190613a4b565b9150915086821461179c5760405162461bcd60e51b815260040161083690613ce6565b3481146117bb5760405162461bcd60e51b815260040161083690613b93565b6004805460405163e875a61360e01b81526000926001600160a01b039092169163e875a613916117ed918e9101613d1e565b60206040518083038186803b15801561180557600080fd5b505afa158015611819573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061183d919061349d565b905061184d818489898989612489565b6116478a8a6002612754565b6002600154141561189f576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556118ac610fd6565b156118f1576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6118fa8a6122f8565b600080600460009054906101000a90046001600160a01b03166001600160a01b031663fad4ee948d6040518263ffffffff1660e01b815260040161193e9190613d1e565b604080518083038186803b15801561195557600080fd5b505afa158015611969573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198d9190613a4b565b90925090508161199d8b83612427565b146119ba5760405162461bcd60e51b815260040161083690613c3a565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663e875a6138e6040518263ffffffff1660e01b81526004016119fd9190613d1e565b60206040518083038186803b158015611a1557600080fd5b505afa158015611a29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a4d919061349d565b90506000600460009054906101000a90046001600160a01b03166001600160a01b0316639a751bbd8f6040518263ffffffff1660e01b8152600401611a929190613d1e565b60206040518083038186803b158015611aaa57600080fd5b505afa158015611abe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ae2919061349d565b9050611af282858d8d8d8d612489565b611b0081848d8a8a8a612489565b600460009054906101000a90046001600160a01b03166001600160a01b031663905fc23c8f8f3360036040518563ffffffff1660e01b8152600401611b489493929190613d3e565b600060405180830381600087803b158015611b6257600080fd5b505af1158015611b76573d6000803e3d6000fd5b50506001805550505050505050505050505050505050565b60026001541415611bd4576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611be988888888888888886124a7565b50506001805550505050505050565b611c006124a3565b6001600160a01b0316611c11611436565b6001600160a01b031614611c5a576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b806001600160a01b038116611c815760405162461bcd60e51b815260040161083690613c79565b611c89610fd6565b611cd1576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b600380546001600160a01b0319166001600160a01b0384161790556040517fcd124a0a6c3182c7bb77b8052823a4bf7d0a4c90016ffc4d53b969f98d3f8b8890610fca9084903390613aee565b60026001541415611d64576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611647898989898989898989612944565b60026001541415611dc0576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556001600160a01b0360608201351660008181526006602052604090205460ff16611e015760405162461bcd60e51b815260040161083690613c95565b6000611e148c8c8c8c8c8c8c8c8c612944565b9050611e208184612559565b50506001805550505050505050505050565b6005546001600160a01b031690565b60026001541415611e87576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611e94610fd6565b15611ed9576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6001600160a01b0360608201351660008181526006602052604090205460ff16611f155760405162461bcd60e51b815260040161083690613c95565b611f2484846000806000612a1d565b6000611f368585600080600080612bab565b905061113e8184612559565b60026001541415611f88576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611f988383836128a7565b5050600180555050565b611faa6124a3565b6001600160a01b0316611fbb611436565b6001600160a01b031614612004576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b806001600160a01b03811661202b5760405162461bcd60e51b815260040161083690613c79565b612033610fd6565b61207b576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b600480546001600160a01b0319166001600160a01b0384161790556040517f94d4208cb05337821fef5da6205084b70818af988524d8a2609a53a1ac1033d190610fca9084903390613aee565b60048054604051633def417960e11b81526001600160a01b0390911691637bde82f291610b5a918591339101613d27565b6002600154141561213f576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b600260015561214c610fd6565b15612191576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6121a082826000806000612a1d565b6121b08282600080600080612bab565b50506001805550565b6004546001600160a01b031690565b6000818152600760205260409020546001600160a01b03165b919050565b6121ee6124a3565b6001600160a01b03166121ff611436565b6001600160a01b031614612248576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b6001600160a01b03811661228d5760405162461bcd60e51b8152600401808060200182810382526026815260200180613e896026913960400191505060405180910390fd5b6002546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600280546001600160a01b0319166001600160a01b0392909216919091179055565b6003546001600160a01b031690565b6000818152600760205260409020546001600160a01b03161561242457600081815260076020526040908190205490516396fb721760e01b81526001600160a01b039091169081906396fb7217906123569033908690600401613a9a565b60206040518083038186803b15801561236e57600080fd5b505afa158015612382573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123a691906138d3565b6123c25760405162461bcd60e51b815260040161083690613d02565b60405163f1218c1b60e01b81526001600160a01b0382169063f1218c1b906123f09033908690600401613a9a565b600060405180830381600087803b15801561240a57600080fd5b505af115801561241e573d6000803e3d6000fd5b50505050505b50565b60008282111561247e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b508082035b92915050565b6124998633308888888888612df6565b61241e8686612f14565b3390565b60006124b1610fd6565b156124f6576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b886001600160a01b03811661251d5760405162461bcd60e51b815260040161083690613c79565b61252b848460008d8d612a1d565b61253b8a33308c8c8c8c8c612df6565b61254b8484600160008e8e612bab565b9a9950505050505050505050565b6125696080820160608301613481565b600083815260076020526040902080546001600160a01b0319166001600160a01b039290921691909117905580356125a76080830160608401613481565b6001600160a01b0316837fb95d1961837654ca0ccf4d5f6b495b5d1a1059204c352288301b87cc7abad4856125e260608601604087016138ef565b85602001356040516125f5929190613b78565b60405180910390a461260d60a08201608083016138b7565b1561264f576126226080820160608301613481565b6001600160a01b0316637f0d201083836040518363ffffffff1660e01b81526004016123f0929190613db4565b5050565b61265b610fd6565b6126a3576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6126d66124a3565b604080516001600160a01b039092168252519081900360200190a1565b60008282018381101561274d576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b600354604051631994684560e01b81526001600160a01b03909116906319946845903490612786903390600401613a86565b6000604051808303818588803b15801561279f57600080fd5b505af11580156127b3573d6000803e3d6000fd5b505060048054604051632417f08f60e21b81526001600160a01b03909116945063905fc23c93506127ed9250879187913391889101613d3e565b600060405180830381600087803b15801561280757600080fd5b505af115801561281b573d6000803e3d6000fd5b50505050505050565b61282c610fd6565b15612871576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586126d66124a3565b60006128b1610fd6565b156128f6576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b836001600160a01b03811661291d5760405162461bcd60e51b815260040161083690613c79565b61292b848487600080612a1d565b61293b8484600288600080612bab565b95945050505050565b600061294e610fd6565b15612993576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b896001600160a01b0381166129ba5760405162461bcd60e51b815260040161083690613c79565b896001600160a01b0381166129e15760405162461bcd60e51b815260040161083690613c79565b6129ee85858e8e8e612a1d565b6129fe8b33308d8d8d8d8d612df6565b612a0d858560038f8f8f612bab565b9c9b505050505050505050505050565b6001600160a01b038316612a7157612a6c612a6786866005818110612a3e57fe5b9050602002013587876002818110612a5257fe5b90506020020135612f6290919063ffffffff16565b612fbb565b612a9e565b612a9e83612a9987876005818110612a8557fe5b9050602002013588886002818110612a5257fe5b613060565b6001600160a01b038216612b2d57612ad3612a6786866005818110612abf57fe5b9050602002013587876003818110612a5257fe5b612afa612a6786866005818110612ae657fe5b9050602002013587876004818110612a5257fe5b34612b0b86866005818110612abf57fe5b14612b285760405162461bcd60e51b815260040161083690613c3a565b610b88565b612b5582612a9987876005818110612b4157fe5b9050602002013588886003818110612a5257fe5b612b7d82612a9987876005818110612b6957fe5b9050602002013588886004818110612a5257fe5b80612b8e86866005818110612abf57fe5b14610b885760405162461bcd60e51b815260040161083690613c3a565b60006001600160a01b038316612c2457600354604051631994684560e01b81526001600160a01b03909116906319946845903490612bed903390600401613a86565b6000604051808303818588803b158015612c0657600080fd5b505af1158015612c1a573d6000803e3d6000fd5b5050505050612c2e565b612c2e8383612f14565b6004546000906001600160a01b03166304fbe031338a8a8581612c4d57fe5b905060200201358b8b6001818110612c6157fe5b905060200201358c8c6002818110612c7557fe5b905060200201358d8d6003818110612c8957fe5b905060200201358e8e6004818110612c9d57fe5b905060200201358f8f6005818110612cb157fe5b905060200201356040518863ffffffff1660e01b8152600401612cda9796959493929190613ab3565b602060405180830381600087803b158015612cf457600080fd5b505af1158015612d08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d2c9190613921565b600480546040516319eb920160e31b81529293506001600160a01b03169163cf5c900891612d629185918b918b918b9101613d7d565b600060405180830381600087803b158015612d7c57600080fd5b505af1158015612d90573d6000803e3d6000fd5b50505050336001600160a01b0316817f9cd76efe5f04f329bc3381df2c7d9749916aa2213a2823c6c7b37f0d16f1018d8a8a6005818110612dcd57fe5b9050602002013589604051612de3929190613d69565b60405180910390a3979650505050505050565b600554604051633ab6ad2560e01b81526000916001600160a01b031690633ab6ad2590612e27908c90600401613a86565b60206040518083038186803b158015612e3f57600080fd5b505afa158015612e53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e77919061349d565b90506001600160a01b038116612e9f5760405162461bcd60e51b815260040161083690613cbb565b60405163d505accf60e01b81526001600160a01b0382169063d505accf90612ed7908b908b908b908b908b908b908b90600401613b2c565b600060405180830381600087803b158015612ef157600080fd5b505af1158015612f05573d6000803e3d6000fd5b50505050505050505050505050565b600354612f2e90839033906001600160a01b0316846130ff565b6003546040516302853b5d60e31b81526001600160a01b0390911690631429dae8906123f090859033908690600401613b08565b600082612f7157506000612483565b82820282848281612f7e57fe5b041461274d5760405162461bcd60e51b8152600401808060200182810382526021815260200180613ed56021913960400191505060405180910390fd5b600560009054906101000a90046001600160a01b03166001600160a01b0316630f878aed6040518163ffffffff1660e01b815260040160206040518083038186803b15801561300957600080fd5b505afa15801561301d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130419190613921565b8111156124245760405162461bcd60e51b815260040161083690613bcb565b600554604051635a860c8760e01b81526001600160a01b0390911690635a860c8790613090908590600401613a86565b60206040518083038186803b1580156130a857600080fd5b505afa1580156130bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130e09190613921565b81111561264f5760405162461bcd60e51b815260040161083690613bcb565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052610e9d9085906000613184826040518060600160405280602a8152602001613f54602a91396001600160a01b03861691906131e5565b8051909150156131e0578080602001905160208110156131a357600080fd5b50516131e05760405162461bcd60e51b815260040180806020018281038252603e815260200180613f16603e913960400191505060405180910390fd5b505050565b60606131f484846000856131fc565b949350505050565b60608247101561323d5760405162461bcd60e51b8152600401808060200182810382526026815260200180613eaf6026913960400191505060405180910390fd5b61324685613357565b613297576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b602083106132d55780518252601f1990920191602091820191016132b6565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613337576040519150601f19603f3d011682016040523d82523d6000602084013e61333c565b606091505b509150915061334c82828661335d565b979650505050505050565b3b151590565b6060831561336c57508161274d565b82511561337c5782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156133c65781810151838201526020016133ae565b50505050905090810190601f1680156133f35780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b60008083601f840112613412578182fd5b50813567ffffffffffffffff811115613429578182fd5b602083019150836020808302850101111561344357600080fd5b9250929050565b8035600381106121e157600080fd5b600060a0828403121561346a578081fd5b50919050565b803560ff811681146121e157600080fd5b600060208284031215613492578081fd5b813561274d81613e45565b6000602082840312156134ae578081fd5b815161274d81613e45565b60008060008060008060008060006101008a8c0312156134d7578485fd5b89356134e281613e45565b985060208a01356134f281613e45565b975060408a0135965060608a0135955061350e60808b01613470565b945060a08a0135935060c08a0135925060e08a013567ffffffffffffffff811115613537578283fd5b6135438c828d01613401565b915080935050809150509295985092959850929598565b6000806000806000806000806000806101a08b8d031215613579578081fd5b8a3561358481613e45565b995060208b013561359481613e45565b985060408b0135975060608b013596506135b060808c01613470565b955060a08b0135945060c08b0135935060e08b013567ffffffffffffffff8111156135d9578182fd5b6135e58d828e01613401565b90945092506135fa90508c6101008d01613459565b90509295989b9194979a5092959850565b60008060006040848603121561361f578283fd5b833561362a81613e45565b9250602084013567ffffffffffffffff811115613645578283fd5b61365186828701613401565b9497909650939450505050565b60008060008060e08587031215613673578384fd5b843561367e81613e45565b9350602085013567ffffffffffffffff811115613699578384fd5b6136a587828801613401565b90945092506136b990508660408701613459565b905092959194509250565b600080604083850312156136d6578182fd5b82356136e181613e45565b915060208301356136f181613e5a565b809150509250929050565b60008060008060008060008060e0898b031215613717578384fd5b883561372281613e45565b9750602089013596506040890135955061373e60608a01613470565b94506080890135935060a0890135925060c089013567ffffffffffffffff811115613767578283fd5b6137738b828c01613401565b999c989b5096995094979396929594505050565b60008060008060008060008060006101808a8c0312156137a5578283fd5b89356137b081613e45565b985060208a0135975060408a013596506137cc60608b01613470565b955060808a0135945060a08a0135935060c08a013567ffffffffffffffff8111156137f5578384fd5b6138018c828d01613401565b909450925061381590508b60e08c01613459565b90509295985092959850929598565b60008060208385031215613836578182fd5b823567ffffffffffffffff81111561384c578283fd5b61385885828601613401565b90969095509350505050565b600080600060c08486031215613878578081fd5b833567ffffffffffffffff81111561388e578182fd5b61389a86828701613401565b90945092506138ae90508560208601613459565b90509250925092565b6000602082840312156138c8578081fd5b813561274d81613e5a565b6000602082840312156138e4578081fd5b815161274d81613e5a565b600060208284031215613900578081fd5b61274d8261344a565b60006020828403121561391a578081fd5b5035919050565b600060208284031215613932578081fd5b5051919050565b6000806040838503121561394b578182fd5b8235915060208301356136f181613e45565b600080600080600080600060e0888a031215613977578081fd5b87359650602088013561398981613e45565b955060408801359450606088013593506139a560808901613470565b925060a0880135915060c0880135905092959891949750929550565b6000806000806000806000806000806101408b8d0312156139e0578384fd5b8a35995060208b01356139f281613e45565b985060408b0135975060608b01359650613a0e60808c01613470565b955060a08b0135945060c08b01359350613a2a60e08c01613470565b92506101008b013591506101208b013590509295989b9194979a5092959850565b60008060408385031215613a5d578182fd5b505080516020909101519092909150565b60038110613a7857fe5b9052565b60048110613a7857fe5b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03979097168752602087019590955260408601939093526060850191909152608084015260a083015260c082015260e00190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b901515815260200190565b60408101613b868285613a6e565b8260208301529392505050565b602080825260029082015261125160f21b604082015260600190565b6020808252600290820152614e4f60f01b604082015260600190565b602080825260029082015261105360f21b604082015260600190565b60208082526017908201527f544f4b454e535f4152455f4e4f545f5448455f53414d45000000000000000000604082015260600190565b6020808252600290820152612aa360f11b604082015260600190565b60208082526002908201526124a360f11b604082015260600190565b6020808252600990820152684e4f5f4348414e474560b81b604082015260600190565b602080825260029082015261304160f01b604082015260600190565b6020808252600c908201526b494e56414c49445f4741544560a01b604082015260600190565b6020808252601190820152702aa729aaa82827a92a22a22faa27a5a2a760791b604082015260600190565b602080825260029082015261049560f41b604082015260600190565b6020808252600290820152614e4560f01b604082015260600190565b90815260200190565b9182526001600160a01b0316602082015260400190565b8481526001600160a01b038481166020830152831660408201526080810161293b6060830184613a7c565b8281526040810161274d6020830184613a7c565b84815260808101613d916020830186613a7c565b6001600160a01b0393841660408301529190921660609092019190915292915050565b600060c0820190508382528235602083015260208301356040830152613ddc6040840161344a565b613de96060840182613a6e565b506060830135613df881613e45565b6001600160a01b0316608083810191909152830135613e1681613e5a565b80151560a0840152509392505050565b92835260208301919091526001600160a01b0316604082015260600190565b6001600160a01b038116811461242457600080fd5b801515811461242457600080fdfe5265656e7472616e637947756172643a207265656e7472616e742063616c6c004f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572536166654552433230576974685065726d69743a204552433230576974685065726d6974206f7065726174696f6e20646964206e6f742073756363656564536166654552433230576974685065726d69743a206c6f772d6c6576656c2063616c6c206661696c6564a2646970667358221220f92d63a194256a60bd1b7da14a6c9a4e46c7a24e4af8711f1fd3ca53754f71f464736f6c6343000706003300000000000000000000000019c10a47c9356efd0e4377411db627636ee9e3c6000000000000000000000000caf39b7bcfc3aed00d62488d3668230b7599cf05000000000000000000000000244154f58e9bf6c15c3a09846efb7becfe92a880

Deployed ByteCode

0x6080604052600436106101e35760003560e01c8063ad7f049311610102578063d7e308bd11610095578063e3f5d2d511610064578063e3f5d2d5146104f0578063ef07b4cc14610505578063f2fde38b14610525578063f9d9309914610545576101e3565b8063d7e308bd1461048a578063d95be43a1461049d578063db006a75146104bd578063dea7f423146104dd576101e3565b8063c241649a116100d1578063c241649a14610422578063c930666e14610442578063caed989714610462578063cf4e794d14610477576101e3565b8063ad7f0493146103af578063b2c076c8146103c2578063bc16ba47146103e2578063c099a7c414610402576101e3565b80635c975abb1161017a5780638456cb59116101495780638456cb59146103525780638503b5c9146103675780638da5cb5b1461037a57806392fcbdc11461039c576101e3565b80635c975abb146102df5780636ad0cfe11461030a578063715018a61461031d578063765e0fb814610332576101e3565b8063284f0923116101b6578063284f09231461026a5780632bcb22881461028a5780633f4ba83a146102aa57806358555ab8146102bf576101e3565b80630bd74705146101e85780631a245b8e1461020a578063231e0f511461022a578063278ecde11461024a575b600080fd5b3480156101f457600080fd5b50610208610203366004613909565b61055a565b005b34801561021657600080fd5b5061020861022536600461395d565b6106e7565b34801561023657600080fd5b506102086102453660046136c4565b610a00565b34801561025657600080fd5b50610208610265366004613909565b610b29565b34801561027657600080fd5b50610208610285366004613909565b610b8f565b34801561029657600080fd5b506102086102a5366004613787565b610bc0565b3480156102b657600080fd5b50610208610c76565b3480156102cb57600080fd5b506102086102da366004613481565b610ea4565b3480156102eb57600080fd5b506102f4610fd6565b6040516103019190613b6d565b60405180910390f35b610208610318366004613939565b610fdf565b34801561032957600080fd5b50610208611149565b34801561033e57600080fd5b5061020861034d366004613909565b6111f5565b34801561035e57600080fd5b50610208611226565b61020861037536600461365e565b611396565b34801561038657600080fd5b5061038f611436565b6040516103019190613a86565b6102086103aa36600461395d565b611445565b6102086103bd36600461395d565b611657565b3480156103ce57600080fd5b506102086103dd3660046139c1565b611859565b3480156103ee57600080fd5b506102086103fd3660046136fc565b611b8e565b34801561040e57600080fd5b5061020861041d366004613481565b611bf8565b34801561042e57600080fd5b5061020861043d3660046134b9565b611d1e565b34801561044e57600080fd5b5061020861045d36600461355a565b611d7a565b34801561046e57600080fd5b5061038f611e32565b610208610485366004613864565b611e41565b61020861049836600461360b565b611f42565b3480156104a957600080fd5b506102086104b8366004613481565b611fa2565b3480156104c957600080fd5b506102086104d8366004613909565b6120c8565b6102086104eb366004613824565b6120f9565b3480156104fc57600080fd5b5061038f6121b9565b34801561051157600080fd5b5061038f610520366004613909565b6121c8565b34801561053157600080fd5b50610208610540366004613481565b6121e6565b34801561055157600080fd5b5061038f6122e9565b600260015414156105a0576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556105ad610fd6565b156105f2576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b600480546040516322af217960e11b81526000926001600160a01b039092169163455e42f291610626918691339101613d27565b602060405180830381600087803b15801561064057600080fd5b505af1158015610654573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106789190613921565b600354604051632990c23f60e11b81529192506001600160a01b031690635321847e906106ad90859085903390600401613e26565b600060405180830381600087803b1580156106c757600080fd5b505af11580156106db573d6000803e3d6000fd5b50506001805550505050565b6002600154141561072d576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b600260015561073a610fd6565b1561077f576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b610788876122f8565b60048054604051633eb53ba560e21b815260009283926001600160a01b03169163fad4ee94916107ba918d9101613d1e565b604080518083038186803b1580156107d157600080fd5b505afa1580156107e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108099190613a4b565b9092509050816108198883612427565b1461083f5760405162461bcd60e51b815260040161083690613c3a565b60405180910390fd5b6004805460405163e875a61360e01b81526000926001600160a01b039092169163e875a61391610871918e9101613d1e565b60206040518083038186803b15801561088957600080fd5b505afa15801561089d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c1919061349d565b60048054604051639a751bbd60e01b81529293506000926001600160a01b0390911691639a751bbd916108f6918f9101613d1e565b60206040518083038186803b15801561090e57600080fd5b505afa158015610922573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610946919061349d565b9050806001600160a01b0316826001600160a01b0316146109795760405162461bcd60e51b815260040161083690613be7565b610987828a8a8a8a8a612489565b60048054604051632417f08f60e21b81526001600160a01b039091169163905fc23c916109bd918f918f91339160039101613d3e565b600060405180830381600087803b1580156109d757600080fd5b505af11580156109eb573d6000803e3d6000fd5b50506001805550505050505050505050505050565b610a086124a3565b6001600160a01b0316610a19611436565b6001600160a01b031614610a62576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b816001600160a01b038116610a895760405162461bcd60e51b815260040161083690613c79565b6001600160a01b03831660009081526006602052604090205460ff1615158215151415610ac85760405162461bcd60e51b815260040161083690613c56565b6001600160a01b03831660008181526006602052604090819020805460ff1916851515179055517f15635ac22e35b377e346d03ece59297a10454eb8b7713b664c69f4bcaf2aaa6190610b1c908590613b6d565b60405180910390a2505050565b60048054604051631eb489b760e21b81526001600160a01b0390911691637ad226dc91610b5a918591339101613d27565b600060405180830381600087803b158015610b7457600080fd5b505af1158015610b88573d6000803e3d6000fd5b5050505050565b600480546040516366db9a0960e01b81526001600160a01b03909116916366db9a0991610b5a918591339101613d27565b60026001541415610c06576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556001600160a01b0360608201351660008181526006602052604090205460ff16610c475760405162461bcd60e51b815260040161083690613c95565b6000610c598b8b8b8b8b8b8b8b6124a7565b9050610c658184612559565b505060018055505050505050505050565b610c7e6124a3565b6001600160a01b0316610c8f611436565b6001600160a01b031614610cb55760405162461bcd60e51b815260040161083690613baf565b600360009054906101000a90046001600160a01b03166001600160a01b031663ae04884e6040518163ffffffff1660e01b815260040160206040518083038186803b158015610d0357600080fd5b505afa158015610d17573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d3b91906138d3565b610d575760405162461bcd60e51b815260040161083690613c1e565b610d5f612653565b6004805460408051635c975abb60e01b815290516001600160a01b0390921692635c975abb928282019260209290829003018186803b158015610da157600080fd5b505afa158015610db5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610dd991906138d3565b15610ea2576004805460408051631fa5d41d60e11b815290516001600160a01b0390921692633f4ba83a92828201926000929082900301818387803b158015610e2157600080fd5b505af1158015610e35573d6000803e3d6000fd5b50505050600360009054906101000a90046001600160a01b03166001600160a01b0316633f4ba83a6040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610e8957600080fd5b505af1158015610e9d573d6000803e3d6000fd5b505050505b565b610eac6124a3565b6001600160a01b0316610ebd611436565b6001600160a01b031614610f06576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b806001600160a01b038116610f2d5760405162461bcd60e51b815260040161083690613c79565b610f35610fd6565b610f7d576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b600580546001600160a01b0319166001600160a01b0384161790556040517f31d91a51396c4dd6a866b29210f1038e7c63a854057ddef76f1578addaf643f090610fca9084903390613aee565b60405180910390a15050565b60005460ff1690565b60026001541415611025576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611032610fd6565b15611077576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b611080826122f8565b60048054604051633eb53ba560e21b8152349260009283926001600160a01b039091169163fad4ee94916110b691899101613d1e565b604080518083038186803b1580156110cd57600080fd5b505afa1580156110e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111059190613a4b565b90925090508261111583836126f3565b146111325760405162461bcd60e51b815260040161083690613c3a565b61113e85856000612754565b505060018055505050565b6111516124a3565b6001600160a01b0316611162611436565b6001600160a01b0316146111ab576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b6002546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600280546001600160a01b0319169055565b60048054604051631ebaf54360e31b81526001600160a01b039091169163f5d7aa1891610b5a918591339101613d27565b61122e6124a3565b6001600160a01b031661123f611436565b6001600160a01b0316146112655760405162461bcd60e51b815260040161083690613baf565b61126d612824565b6004805460408051635c975abb60e01b815290516001600160a01b0390921692635c975abb928282019260209290829003018186803b1580156112af57600080fd5b505afa1580156112c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112e791906138d3565b610ea2576004805460408051638456cb5960e01b815290516001600160a01b0390921692638456cb5992828201926000929082900301818387803b15801561132e57600080fd5b505af1158015611342573d6000803e3d6000fd5b50505050600360009054906101000a90046001600160a01b03166001600160a01b0316638456cb596040518163ffffffff1660e01b8152600401600060405180830381600087803b158015610e8957600080fd5b600260015414156113dc576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556001600160a01b0360608201351660008181526006602052604090205460ff1661141d5760405162461bcd60e51b815260040161083690613c95565b600061142a8686866128a7565b90506106db8184612559565b6002546001600160a01b031690565b6002600154141561148b576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611498610fd6565b156114dd576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6114e6876122f8565b60048054604051633eb53ba560e21b815260009283926001600160a01b03169163fad4ee9491611518918d9101613d1e565b604080518083038186803b15801561152f57600080fd5b505afa158015611543573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115679190613a4b565b9150915034821461158a5760405162461bcd60e51b815260040161083690613ce6565b8681146115a95760405162461bcd60e51b815260040161083690613b93565b60048054604051639a751bbd60e01b81526000926001600160a01b0390921691639a751bbd916115db918e9101613d1e565b60206040518083038186803b1580156115f357600080fd5b505afa158015611607573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061162b919061349d565b905061163b818989898989612489565b6116478a8a6001612754565b5050600180555050505050505050565b6002600154141561169d576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556116aa610fd6565b156116ef576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6116f8876122f8565b60048054604051633eb53ba560e21b815260009283926001600160a01b03169163fad4ee949161172a918d9101613d1e565b604080518083038186803b15801561174157600080fd5b505afa158015611755573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117799190613a4b565b9150915086821461179c5760405162461bcd60e51b815260040161083690613ce6565b3481146117bb5760405162461bcd60e51b815260040161083690613b93565b6004805460405163e875a61360e01b81526000926001600160a01b039092169163e875a613916117ed918e9101613d1e565b60206040518083038186803b15801561180557600080fd5b505afa158015611819573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061183d919061349d565b905061184d818489898989612489565b6116478a8a6002612754565b6002600154141561189f576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556118ac610fd6565b156118f1576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6118fa8a6122f8565b600080600460009054906101000a90046001600160a01b03166001600160a01b031663fad4ee948d6040518263ffffffff1660e01b815260040161193e9190613d1e565b604080518083038186803b15801561195557600080fd5b505afa158015611969573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198d9190613a4b565b90925090508161199d8b83612427565b146119ba5760405162461bcd60e51b815260040161083690613c3a565b6000600460009054906101000a90046001600160a01b03166001600160a01b031663e875a6138e6040518263ffffffff1660e01b81526004016119fd9190613d1e565b60206040518083038186803b158015611a1557600080fd5b505afa158015611a29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a4d919061349d565b90506000600460009054906101000a90046001600160a01b03166001600160a01b0316639a751bbd8f6040518263ffffffff1660e01b8152600401611a929190613d1e565b60206040518083038186803b158015611aaa57600080fd5b505afa158015611abe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ae2919061349d565b9050611af282858d8d8d8d612489565b611b0081848d8a8a8a612489565b600460009054906101000a90046001600160a01b03166001600160a01b031663905fc23c8f8f3360036040518563ffffffff1660e01b8152600401611b489493929190613d3e565b600060405180830381600087803b158015611b6257600080fd5b505af1158015611b76573d6000803e3d6000fd5b50506001805550505050505050505050505050505050565b60026001541415611bd4576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611be988888888888888886124a7565b50506001805550505050505050565b611c006124a3565b6001600160a01b0316611c11611436565b6001600160a01b031614611c5a576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b806001600160a01b038116611c815760405162461bcd60e51b815260040161083690613c79565b611c89610fd6565b611cd1576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b600380546001600160a01b0319166001600160a01b0384161790556040517fcd124a0a6c3182c7bb77b8052823a4bf7d0a4c90016ffc4d53b969f98d3f8b8890610fca9084903390613aee565b60026001541415611d64576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611647898989898989898989612944565b60026001541415611dc0576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b60026001556001600160a01b0360608201351660008181526006602052604090205460ff16611e015760405162461bcd60e51b815260040161083690613c95565b6000611e148c8c8c8c8c8c8c8c8c612944565b9050611e208184612559565b50506001805550505050505050505050565b6005546001600160a01b031690565b60026001541415611e87576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611e94610fd6565b15611ed9576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6001600160a01b0360608201351660008181526006602052604090205460ff16611f155760405162461bcd60e51b815260040161083690613c95565b611f2484846000806000612a1d565b6000611f368585600080600080612bab565b905061113e8184612559565b60026001541415611f88576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b6002600155611f988383836128a7565b5050600180555050565b611faa6124a3565b6001600160a01b0316611fbb611436565b6001600160a01b031614612004576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b806001600160a01b03811661202b5760405162461bcd60e51b815260040161083690613c79565b612033610fd6565b61207b576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b600480546001600160a01b0319166001600160a01b0384161790556040517f94d4208cb05337821fef5da6205084b70818af988524d8a2609a53a1ac1033d190610fca9084903390613aee565b60048054604051633def417960e11b81526001600160a01b0390911691637bde82f291610b5a918591339101613d27565b6002600154141561213f576040805162461bcd60e51b815260206004820152601f6024820152600080516020613e69833981519152604482015290519081900360640190fd5b600260015561214c610fd6565b15612191576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6121a082826000806000612a1d565b6121b08282600080600080612bab565b50506001805550565b6004546001600160a01b031690565b6000818152600760205260409020546001600160a01b03165b919050565b6121ee6124a3565b6001600160a01b03166121ff611436565b6001600160a01b031614612248576040805162461bcd60e51b81526020600482018190526024820152600080516020613ef6833981519152604482015290519081900360640190fd5b6001600160a01b03811661228d5760405162461bcd60e51b8152600401808060200182810382526026815260200180613e896026913960400191505060405180910390fd5b6002546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600280546001600160a01b0319166001600160a01b0392909216919091179055565b6003546001600160a01b031690565b6000818152600760205260409020546001600160a01b03161561242457600081815260076020526040908190205490516396fb721760e01b81526001600160a01b039091169081906396fb7217906123569033908690600401613a9a565b60206040518083038186803b15801561236e57600080fd5b505afa158015612382573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123a691906138d3565b6123c25760405162461bcd60e51b815260040161083690613d02565b60405163f1218c1b60e01b81526001600160a01b0382169063f1218c1b906123f09033908690600401613a9a565b600060405180830381600087803b15801561240a57600080fd5b505af115801561241e573d6000803e3d6000fd5b50505050505b50565b60008282111561247e576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b508082035b92915050565b6124998633308888888888612df6565b61241e8686612f14565b3390565b60006124b1610fd6565b156124f6576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b886001600160a01b03811661251d5760405162461bcd60e51b815260040161083690613c79565b61252b848460008d8d612a1d565b61253b8a33308c8c8c8c8c612df6565b61254b8484600160008e8e612bab565b9a9950505050505050505050565b6125696080820160608301613481565b600083815260076020526040902080546001600160a01b0319166001600160a01b039290921691909117905580356125a76080830160608401613481565b6001600160a01b0316837fb95d1961837654ca0ccf4d5f6b495b5d1a1059204c352288301b87cc7abad4856125e260608601604087016138ef565b85602001356040516125f5929190613b78565b60405180910390a461260d60a08201608083016138b7565b1561264f576126226080820160608301613481565b6001600160a01b0316637f0d201083836040518363ffffffff1660e01b81526004016123f0929190613db4565b5050565b61265b610fd6565b6126a3576040805162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b604482015290519081900360640190fd5b6000805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6126d66124a3565b604080516001600160a01b039092168252519081900360200190a1565b60008282018381101561274d576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b600354604051631994684560e01b81526001600160a01b03909116906319946845903490612786903390600401613a86565b6000604051808303818588803b15801561279f57600080fd5b505af11580156127b3573d6000803e3d6000fd5b505060048054604051632417f08f60e21b81526001600160a01b03909116945063905fc23c93506127ed9250879187913391889101613d3e565b600060405180830381600087803b15801561280757600080fd5b505af115801561281b573d6000803e3d6000fd5b50505050505050565b61282c610fd6565b15612871576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b6000805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586126d66124a3565b60006128b1610fd6565b156128f6576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b836001600160a01b03811661291d5760405162461bcd60e51b815260040161083690613c79565b61292b848487600080612a1d565b61293b8484600288600080612bab565b95945050505050565b600061294e610fd6565b15612993576040805162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b604482015290519081900360640190fd5b896001600160a01b0381166129ba5760405162461bcd60e51b815260040161083690613c79565b896001600160a01b0381166129e15760405162461bcd60e51b815260040161083690613c79565b6129ee85858e8e8e612a1d565b6129fe8b33308d8d8d8d8d612df6565b612a0d858560038f8f8f612bab565b9c9b505050505050505050505050565b6001600160a01b038316612a7157612a6c612a6786866005818110612a3e57fe5b9050602002013587876002818110612a5257fe5b90506020020135612f6290919063ffffffff16565b612fbb565b612a9e565b612a9e83612a9987876005818110612a8557fe5b9050602002013588886002818110612a5257fe5b613060565b6001600160a01b038216612b2d57612ad3612a6786866005818110612abf57fe5b9050602002013587876003818110612a5257fe5b612afa612a6786866005818110612ae657fe5b9050602002013587876004818110612a5257fe5b34612b0b86866005818110612abf57fe5b14612b285760405162461bcd60e51b815260040161083690613c3a565b610b88565b612b5582612a9987876005818110612b4157fe5b9050602002013588886003818110612a5257fe5b612b7d82612a9987876005818110612b6957fe5b9050602002013588886004818110612a5257fe5b80612b8e86866005818110612abf57fe5b14610b885760405162461bcd60e51b815260040161083690613c3a565b60006001600160a01b038316612c2457600354604051631994684560e01b81526001600160a01b03909116906319946845903490612bed903390600401613a86565b6000604051808303818588803b158015612c0657600080fd5b505af1158015612c1a573d6000803e3d6000fd5b5050505050612c2e565b612c2e8383612f14565b6004546000906001600160a01b03166304fbe031338a8a8581612c4d57fe5b905060200201358b8b6001818110612c6157fe5b905060200201358c8c6002818110612c7557fe5b905060200201358d8d6003818110612c8957fe5b905060200201358e8e6004818110612c9d57fe5b905060200201358f8f6005818110612cb157fe5b905060200201356040518863ffffffff1660e01b8152600401612cda9796959493929190613ab3565b602060405180830381600087803b158015612cf457600080fd5b505af1158015612d08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d2c9190613921565b600480546040516319eb920160e31b81529293506001600160a01b03169163cf5c900891612d629185918b918b918b9101613d7d565b600060405180830381600087803b158015612d7c57600080fd5b505af1158015612d90573d6000803e3d6000fd5b50505050336001600160a01b0316817f9cd76efe5f04f329bc3381df2c7d9749916aa2213a2823c6c7b37f0d16f1018d8a8a6005818110612dcd57fe5b9050602002013589604051612de3929190613d69565b60405180910390a3979650505050505050565b600554604051633ab6ad2560e01b81526000916001600160a01b031690633ab6ad2590612e27908c90600401613a86565b60206040518083038186803b158015612e3f57600080fd5b505afa158015612e53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e77919061349d565b90506001600160a01b038116612e9f5760405162461bcd60e51b815260040161083690613cbb565b60405163d505accf60e01b81526001600160a01b0382169063d505accf90612ed7908b908b908b908b908b908b908b90600401613b2c565b600060405180830381600087803b158015612ef157600080fd5b505af1158015612f05573d6000803e3d6000fd5b50505050505050505050505050565b600354612f2e90839033906001600160a01b0316846130ff565b6003546040516302853b5d60e31b81526001600160a01b0390911690631429dae8906123f090859033908690600401613b08565b600082612f7157506000612483565b82820282848281612f7e57fe5b041461274d5760405162461bcd60e51b8152600401808060200182810382526021815260200180613ed56021913960400191505060405180910390fd5b600560009054906101000a90046001600160a01b03166001600160a01b0316630f878aed6040518163ffffffff1660e01b815260040160206040518083038186803b15801561300957600080fd5b505afa15801561301d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130419190613921565b8111156124245760405162461bcd60e51b815260040161083690613bcb565b600554604051635a860c8760e01b81526001600160a01b0390911690635a860c8790613090908590600401613a86565b60206040518083038186803b1580156130a857600080fd5b505afa1580156130bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130e09190613921565b81111561264f5760405162461bcd60e51b815260040161083690613bcb565b604080516001600160a01b0380861660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b179052610e9d9085906000613184826040518060600160405280602a8152602001613f54602a91396001600160a01b03861691906131e5565b8051909150156131e0578080602001905160208110156131a357600080fd5b50516131e05760405162461bcd60e51b815260040180806020018281038252603e815260200180613f16603e913960400191505060405180910390fd5b505050565b60606131f484846000856131fc565b949350505050565b60608247101561323d5760405162461bcd60e51b8152600401808060200182810382526026815260200180613eaf6026913960400191505060405180910390fd5b61324685613357565b613297576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b600080866001600160a01b031685876040518082805190602001908083835b602083106132d55780518252601f1990920191602091820191016132b6565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114613337576040519150601f19603f3d011682016040523d82523d6000602084013e61333c565b606091505b509150915061334c82828661335d565b979650505050505050565b3b151590565b6060831561336c57508161274d565b82511561337c5782518084602001fd5b8160405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156133c65781810151838201526020016133ae565b50505050905090810190601f1680156133f35780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b60008083601f840112613412578182fd5b50813567ffffffffffffffff811115613429578182fd5b602083019150836020808302850101111561344357600080fd5b9250929050565b8035600381106121e157600080fd5b600060a0828403121561346a578081fd5b50919050565b803560ff811681146121e157600080fd5b600060208284031215613492578081fd5b813561274d81613e45565b6000602082840312156134ae578081fd5b815161274d81613e45565b60008060008060008060008060006101008a8c0312156134d7578485fd5b89356134e281613e45565b985060208a01356134f281613e45565b975060408a0135965060608a0135955061350e60808b01613470565b945060a08a0135935060c08a0135925060e08a013567ffffffffffffffff811115613537578283fd5b6135438c828d01613401565b915080935050809150509295985092959850929598565b6000806000806000806000806000806101a08b8d031215613579578081fd5b8a3561358481613e45565b995060208b013561359481613e45565b985060408b0135975060608b013596506135b060808c01613470565b955060a08b0135945060c08b0135935060e08b013567ffffffffffffffff8111156135d9578182fd5b6135e58d828e01613401565b90945092506135fa90508c6101008d01613459565b90509295989b9194979a5092959850565b60008060006040848603121561361f578283fd5b833561362a81613e45565b9250602084013567ffffffffffffffff811115613645578283fd5b61365186828701613401565b9497909650939450505050565b60008060008060e08587031215613673578384fd5b843561367e81613e45565b9350602085013567ffffffffffffffff811115613699578384fd5b6136a587828801613401565b90945092506136b990508660408701613459565b905092959194509250565b600080604083850312156136d6578182fd5b82356136e181613e45565b915060208301356136f181613e5a565b809150509250929050565b60008060008060008060008060e0898b031215613717578384fd5b883561372281613e45565b9750602089013596506040890135955061373e60608a01613470565b94506080890135935060a0890135925060c089013567ffffffffffffffff811115613767578283fd5b6137738b828c01613401565b999c989b5096995094979396929594505050565b60008060008060008060008060006101808a8c0312156137a5578283fd5b89356137b081613e45565b985060208a0135975060408a013596506137cc60608b01613470565b955060808a0135945060a08a0135935060c08a013567ffffffffffffffff8111156137f5578384fd5b6138018c828d01613401565b909450925061381590508b60e08c01613459565b90509295985092959850929598565b60008060208385031215613836578182fd5b823567ffffffffffffffff81111561384c578283fd5b61385885828601613401565b90969095509350505050565b600080600060c08486031215613878578081fd5b833567ffffffffffffffff81111561388e578182fd5b61389a86828701613401565b90945092506138ae90508560208601613459565b90509250925092565b6000602082840312156138c8578081fd5b813561274d81613e5a565b6000602082840312156138e4578081fd5b815161274d81613e5a565b600060208284031215613900578081fd5b61274d8261344a565b60006020828403121561391a578081fd5b5035919050565b600060208284031215613932578081fd5b5051919050565b6000806040838503121561394b578182fd5b8235915060208301356136f181613e45565b600080600080600080600060e0888a031215613977578081fd5b87359650602088013561398981613e45565b955060408801359450606088013593506139a560808901613470565b925060a0880135915060c0880135905092959891949750929550565b6000806000806000806000806000806101408b8d0312156139e0578384fd5b8a35995060208b01356139f281613e45565b985060408b0135975060608b01359650613a0e60808c01613470565b955060a08b0135945060c08b01359350613a2a60e08c01613470565b92506101008b013591506101208b013590509295989b9194979a5092959850565b60008060408385031215613a5d578182fd5b505080516020909101519092909150565b60038110613a7857fe5b9052565b60048110613a7857fe5b6001600160a01b0391909116815260200190565b6001600160a01b03929092168252602082015260400190565b6001600160a01b03979097168752602087019590955260408601939093526060850191909152608084015260a083015260c082015260e00190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b901515815260200190565b60408101613b868285613a6e565b8260208301529392505050565b602080825260029082015261125160f21b604082015260600190565b6020808252600290820152614e4f60f01b604082015260600190565b602080825260029082015261105360f21b604082015260600190565b60208082526017908201527f544f4b454e535f4152455f4e4f545f5448455f53414d45000000000000000000604082015260600190565b6020808252600290820152612aa360f11b604082015260600190565b60208082526002908201526124a360f11b604082015260600190565b6020808252600990820152684e4f5f4348414e474560b81b604082015260600190565b602080825260029082015261304160f01b604082015260600190565b6020808252600c908201526b494e56414c49445f4741544560a01b604082015260600190565b6020808252601190820152702aa729aaa82827a92a22a22faa27a5a2a760791b604082015260600190565b602080825260029082015261049560f41b604082015260600190565b6020808252600290820152614e4560f01b604082015260600190565b90815260200190565b9182526001600160a01b0316602082015260400190565b8481526001600160a01b038481166020830152831660408201526080810161293b6060830184613a7c565b8281526040810161274d6020830184613a7c565b84815260808101613d916020830186613a7c565b6001600160a01b0393841660408301529190921660609092019190915292915050565b600060c0820190508382528235602083015260208301356040830152613ddc6040840161344a565b613de96060840182613a6e565b506060830135613df881613e45565b6001600160a01b0316608083810191909152830135613e1681613e5a565b80151560a0840152509392505050565b92835260208301919091526001600160a01b0316604082015260600190565b6001600160a01b038116811461242457600080fd5b801515811461242457600080fdfe5265656e7472616e637947756172643a207265656e7472616e742063616c6c004f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373416464726573733a20696e73756666696369656e742062616c616e636520666f722063616c6c536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572536166654552433230576974685065726d69743a204552433230576974685065726d6974206f7065726174696f6e20646964206e6f742073756363656564536166654552433230576974685065726d69743a206c6f772d6c6576656c2063616c6c206661696c6564a2646970667358221220f92d63a194256a60bd1b7da14a6c9a4e46c7a24e4af8711f1fd3ca53754f71f464736f6c63430007060033