ETH Price: $3,105.53 (-3.22%)
Gas: 8 Gwei

Contract

0x6958F5e95332D93D21af0D7B9Ca85B8212fEE0A5
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
Market Buy Order...167742952023-03-07 5:17:47485 days ago1678166267IN
0x: Forwarder V3
0.0001 ETH0.0078464325.97425369
Market Buy Order...166225812023-02-13 21:40:47507 days ago1676324447IN
0x: Forwarder V3
0.00001 ETH0.0073352528.32977978
Market Buy Order...160278902022-11-22 20:21:11590 days ago1669148471IN
0x: Forwarder V3
0.002 ETH0.007021925.83528833
Market Buy Order...159357162022-11-09 23:23:11603 days ago1668036191IN
0x: Forwarder V3
0.9 ETH0.0199143482.37780483
Market Buy Order...156473732022-09-30 16:33:59643 days ago1664555639IN
0x: Forwarder V3
0.01 ETH0.0048335822.53872157
Market Buy Order...156473672022-09-30 16:32:47643 days ago1664555567IN
0x: Forwarder V3
0.01 ETH0.0052680424.56455745
Market Buy Order...156200632022-09-26 20:56:47647 days ago1664225807IN
0x: Forwarder V3
0.00001 ETH0.0043623815.83202646
Market Buy Order...155593492022-09-18 8:49:35655 days ago1663490975IN
0x: Forwarder V3
0.0001025 ETH0.00026362
Market Buy Order...154499742022-09-01 1:23:16672 days ago1661995396IN
0x: Forwarder V3
0.014 ETH0.004019514.55371749
Market Buy Order...154489902022-08-31 21:34:24673 days ago1661981664IN
0x: Forwarder V3
0.02 ETH0.005834924.19758054
Market Buy Order...154489812022-08-31 21:32:40673 days ago1661981560IN
0x: Forwarder V3
0.014 ETH0.0078546328.00586095
Market Buy Order...154489702022-08-31 21:30:47673 days ago1661981447IN
0x: Forwarder V3
0.014 ETH0.0084032135.19729897
Market Buy Order...154489472022-08-31 21:25:17673 days ago1661981117IN
0x: Forwarder V3
0.014 ETH0.0068089425.35125772
Market Buy Order...154443132022-08-31 3:37:43673 days ago1661917063IN
0x: Forwarder V3
0.01 ETH0.004025515.17010644
Market Buy Order...154278072022-08-28 12:27:59676 days ago1661689679IN
0x: Forwarder V3
0.00000919 ETH0.000262692
Market Buy Order...153868602022-08-21 23:19:03683 days ago1661123943IN
0x: Forwarder V3
0.00017373 ETH0.000481182
Market Buy Order...153824332022-08-21 6:40:49683 days ago1661064049IN
0x: Forwarder V3
0.0009225 ETH0.000263482
Market Buy Order...153819222022-08-21 4:47:30683 days ago1661057250IN
0x: Forwarder V3
0.00000239 ETH0.000263372
Market Buy Order...147792982022-05-15 9:57:16781 days ago1652608636IN
0x: Forwarder V3
0.11843027 ETH0.0058205416.66933331
Market Buy Order...147792892022-05-15 9:54:58781 days ago1652608498IN
0x: Forwarder V3
0.11793693 ETH0.0045260413.34450982
Market Buy Order...147792892022-05-15 9:54:58781 days ago1652608498IN
0x: Forwarder V3
0.11793693 ETH0.0046595913.34450982
Market Buy Order...147792862022-05-15 9:54:12781 days ago1652608452IN
0x: Forwarder V3
0.11696747 ETH0.0046336713.27026575
Market Buy Order...147792832022-05-15 9:53:32781 days ago1652608412IN
0x: Forwarder V3
0.11797398 ETH0.0047154313.40750811
Market Buy Order...147792812022-05-15 9:53:00781 days ago1652608380IN
0x: Forwarder V3
0.11752493 ETH0.0046174513.22383411
Market Buy Order...147792722022-05-15 9:51:19781 days ago1652608279IN
0x: Forwarder V3
0.11404152 ETH0.0030108410.11781506
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To Value
167742952023-03-07 5:17:47485 days ago1678166267
0x: Forwarder V3
0.0001 ETH
166225812023-02-13 21:40:47507 days ago1676324447
0x: Forwarder V3
0.00001 ETH
160278902022-11-22 20:21:11590 days ago1669148471
0x: Forwarder V3
0.002 ETH
159357162022-11-09 23:23:11603 days ago1668036191
0x: Forwarder V3
0.9 ETH
156473732022-09-30 16:33:59643 days ago1664555639
0x: Forwarder V3
0.01 ETH
156473672022-09-30 16:32:47643 days ago1664555567
0x: Forwarder V3
0.01 ETH
156200632022-09-26 20:56:47647 days ago1664225807
0x: Forwarder V3
0.00001 ETH
155593492022-09-18 8:49:35655 days ago1663490975
0x: Forwarder V3
0.0001 ETH
155593492022-09-18 8:49:35655 days ago1663490975
0x: Forwarder V3
0.0000025 ETH
154499742022-09-01 1:23:16672 days ago1661995396
0x: Forwarder V3
0.014 ETH
154489902022-08-31 21:34:24673 days ago1661981664
0x: Forwarder V3
0.02 ETH
154489812022-08-31 21:32:40673 days ago1661981560
0x: Forwarder V3
0.014 ETH
154489702022-08-31 21:30:47673 days ago1661981447
0x: Forwarder V3
0.014 ETH
154489472022-08-31 21:25:17673 days ago1661981117
0x: Forwarder V3
0.014 ETH
154443132022-08-31 3:37:43673 days ago1661917063
0x: Forwarder V3
0.01 ETH
154278072022-08-28 12:27:59676 days ago1661689679
0x: Forwarder V3
0.00000897 ETH
154278072022-08-28 12:27:59676 days ago1661689679
0x: Forwarder V3
0.00000022 ETH
153868602022-08-21 23:19:03683 days ago1661123943
0x: Forwarder V3
0.0001695 ETH
153868602022-08-21 23:19:03683 days ago1661123943
0x: Forwarder V3
0.00000423 ETH
153824332022-08-21 6:40:49683 days ago1661064049
0x: Forwarder V3
0.0009 ETH
153824332022-08-21 6:40:49683 days ago1661064049
0x: Forwarder V3
0.0000225 ETH
153819222022-08-21 4:47:30683 days ago1661057250
0x: Forwarder V3
0.00000234 ETH
153819222022-08-21 4:47:30683 days ago1661057250
0x: Forwarder V3
0.00000005 ETH
147792982022-05-15 9:57:16781 days ago1652608636
0x: Forwarder V3
0.00127171 ETH
147792982022-05-15 9:57:16781 days ago1652608636
0x: Forwarder V3
0.00127171 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Forwarder

Compiler Version
v0.5.16+commit.9c3226ce

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, None license

Contract Source Code (Solidity)

/**
 *Submitted for verification at Etherscan.io on 2020-03-30
*/

pragma solidity ^0.5.9;
pragma experimental ABIEncoderV2;

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

// solhint-disable

// @dev Interface of the asset proxy's assetData.
// The asset proxies take an ABI encoded `bytes assetData` as argument.
// This argument is ABI encoded as one of the methods of this interface.
interface IAssetData {

    /// @dev Function signature for encoding ERC20 assetData.
    /// @param tokenAddress Address of ERC20Token contract.
    function ERC20Token(address tokenAddress)
        external;

    /// @dev Function signature for encoding ERC721 assetData.
    /// @param tokenAddress Address of ERC721 token contract.
    /// @param tokenId Id of ERC721 token to be transferred.
    function ERC721Token(
        address tokenAddress,
        uint256 tokenId
    )
        external;

    /// @dev Function signature for encoding ERC1155 assetData.
    /// @param tokenAddress Address of ERC1155 token contract.
    /// @param tokenIds Array of ids of tokens to be transferred.
    /// @param values Array of values that correspond to each token id to be transferred.
    ///        Note that each value will be multiplied by the amount being filled in the order before transferring.
    /// @param callbackData Extra data to be passed to receiver's `onERC1155Received` callback function.
    function ERC1155Assets(
        address tokenAddress,
        uint256[] calldata tokenIds,
        uint256[] calldata values,
        bytes calldata callbackData
    )
        external;

    /// @dev Function signature for encoding MultiAsset assetData.
    /// @param values Array of amounts that correspond to each asset to be transferred.
    ///        Note that each value will be multiplied by the amount being filled in the order before transferring.
    /// @param nestedAssetData Array of assetData fields that will be be dispatched to their correspnding AssetProxy contract.
    function MultiAsset(
        uint256[] calldata values,
        bytes[] calldata nestedAssetData
    )
        external;

    /// @dev Function signature for encoding StaticCall assetData.
    /// @param staticCallTargetAddress Address that will execute the staticcall.
    /// @param staticCallData Data that will be executed via staticcall on the staticCallTargetAddress.
    /// @param expectedReturnDataHash Keccak-256 hash of the expected staticcall return data.
    function StaticCall(
        address staticCallTargetAddress,
        bytes calldata staticCallData,
        bytes32 expectedReturnDataHash
    )
        external;

    /// @dev Function signature for encoding ERC20Bridge assetData.
    /// @param tokenAddress Address of token to transfer.
    /// @param bridgeAddress Address of the bridge contract.
    /// @param bridgeData Arbitrary data to be passed to the bridge contract.
    function ERC20Bridge(
        address tokenAddress,
        address bridgeAddress,
        bytes calldata bridgeData
    )
        external;
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

library LibEIP712 {

    // Hash of the EIP712 Domain Separator Schema
    // keccak256(abi.encodePacked(
    //     "EIP712Domain(",
    //     "string name,",
    //     "string version,",
    //     "uint256 chainId,",
    //     "address verifyingContract",
    //     ")"
    // ))
    bytes32 constant internal _EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;

    /// @dev Calculates a EIP712 domain separator.
    /// @param name The EIP712 domain name.
    /// @param version The EIP712 domain version.
    /// @param verifyingContract The EIP712 verifying contract.
    /// @return EIP712 domain separator.
    function hashEIP712Domain(
        string memory name,
        string memory version,
        uint256 chainId,
        address verifyingContract
    )
        internal
        pure
        returns (bytes32 result)
    {
        bytes32 schemaHash = _EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH;

        // Assembly for more efficient computing:
        // keccak256(abi.encodePacked(
        //     _EIP712_DOMAIN_SEPARATOR_SCHEMA_HASH,
        //     keccak256(bytes(name)),
        //     keccak256(bytes(version)),
        //     chainId,
        //     uint256(verifyingContract)
        // ))

        assembly {
            // Calculate hashes of dynamic data
            let nameHash := keccak256(add(name, 32), mload(name))
            let versionHash := keccak256(add(version, 32), mload(version))

            // Load free memory pointer
            let memPtr := mload(64)

            // Store params in memory
            mstore(memPtr, schemaHash)
            mstore(add(memPtr, 32), nameHash)
            mstore(add(memPtr, 64), versionHash)
            mstore(add(memPtr, 96), chainId)
            mstore(add(memPtr, 128), verifyingContract)

            // Compute hash
            result := keccak256(memPtr, 160)
        }
        return result;
    }

    /// @dev Calculates EIP712 encoding for a hash struct with a given domain hash.
    /// @param eip712DomainHash Hash of the domain domain separator data, computed
    ///                         with getDomainHash().
    /// @param hashStruct The EIP712 hash struct.
    /// @return EIP712 hash applied to the given EIP712 Domain.
    function hashEIP712Message(bytes32 eip712DomainHash, bytes32 hashStruct)
        internal
        pure
        returns (bytes32 result)
    {
        // Assembly for more efficient computing:
        // keccak256(abi.encodePacked(
        //     EIP191_HEADER,
        //     EIP712_DOMAIN_HASH,
        //     hashStruct
        // ));

        assembly {
            // Load free memory pointer
            let memPtr := mload(64)

            mstore(memPtr, 0x1901000000000000000000000000000000000000000000000000000000000000)  // EIP191 header
            mstore(add(memPtr, 2), eip712DomainHash)                                            // EIP712 domain hash
            mstore(add(memPtr, 34), hashStruct)                                                 // Hash of struct

            // Compute hash
            result := keccak256(memPtr, 66)
        }
        return result;
    }
}

library LibOrder {

    using LibOrder for Order;

    // Hash for the EIP712 Order Schema:
    // keccak256(abi.encodePacked(
    //     "Order(",
    //     "address makerAddress,",
    //     "address takerAddress,",
    //     "address feeRecipientAddress,",
    //     "address senderAddress,",
    //     "uint256 makerAssetAmount,",
    //     "uint256 takerAssetAmount,",
    //     "uint256 makerFee,",
    //     "uint256 takerFee,",
    //     "uint256 expirationTimeSeconds,",
    //     "uint256 salt,",
    //     "bytes makerAssetData,",
    //     "bytes takerAssetData,",
    //     "bytes makerFeeAssetData,",
    //     "bytes takerFeeAssetData",
    //     ")"
    // ))
    bytes32 constant internal _EIP712_ORDER_SCHEMA_HASH =
        0xf80322eb8376aafb64eadf8f0d7623f22130fd9491a221e902b713cb984a7534;

    // A valid order remains fillable until it is expired, fully filled, or cancelled.
    // An order's status is unaffected by external factors, like account balances.
    enum OrderStatus {
        INVALID,                     // Default value
        INVALID_MAKER_ASSET_AMOUNT,  // Order does not have a valid maker asset amount
        INVALID_TAKER_ASSET_AMOUNT,  // Order does not have a valid taker asset amount
        FILLABLE,                    // Order is fillable
        EXPIRED,                     // Order has already expired
        FULLY_FILLED,                // Order is fully filled
        CANCELLED                    // Order has been cancelled
    }

    // solhint-disable max-line-length
    /// @dev Canonical order structure.
    struct Order {
        address makerAddress;           // Address that created the order.
        address takerAddress;           // Address that is allowed to fill the order. If set to 0, any address is allowed to fill the order.
        address feeRecipientAddress;    // Address that will recieve fees when order is filled.
        address senderAddress;          // Address that is allowed to call Exchange contract methods that affect this order. If set to 0, any address is allowed to call these methods.
        uint256 makerAssetAmount;       // Amount of makerAsset being offered by maker. Must be greater than 0.
        uint256 takerAssetAmount;       // Amount of takerAsset being bid on by maker. Must be greater than 0.
        uint256 makerFee;               // Fee paid to feeRecipient by maker when order is filled.
        uint256 takerFee;               // Fee paid to feeRecipient by taker when order is filled.
        uint256 expirationTimeSeconds;  // Timestamp in seconds at which order expires.
        uint256 salt;                   // Arbitrary number to facilitate uniqueness of the order's hash.
        bytes makerAssetData;           // Encoded data that can be decoded by a specified proxy contract when transferring makerAsset. The leading bytes4 references the id of the asset proxy.
        bytes takerAssetData;           // Encoded data that can be decoded by a specified proxy contract when transferring takerAsset. The leading bytes4 references the id of the asset proxy.
        bytes makerFeeAssetData;        // Encoded data that can be decoded by a specified proxy contract when transferring makerFeeAsset. The leading bytes4 references the id of the asset proxy.
        bytes takerFeeAssetData;        // Encoded data that can be decoded by a specified proxy contract when transferring takerFeeAsset. The leading bytes4 references the id of the asset proxy.
    }
    // solhint-enable max-line-length

    /// @dev Order information returned by `getOrderInfo()`.
    struct OrderInfo {
        OrderStatus orderStatus;                    // Status that describes order's validity and fillability.
        bytes32 orderHash;                    // EIP712 typed data hash of the order (see LibOrder.getTypedDataHash).
        uint256 orderTakerAssetFilledAmount;  // Amount of order that has already been filled.
    }

    /// @dev Calculates the EIP712 typed data hash of an order with a given domain separator.
    /// @param order The order structure.
    /// @return EIP712 typed data hash of the order.
    function getTypedDataHash(Order memory order, bytes32 eip712ExchangeDomainHash)
        internal
        pure
        returns (bytes32 orderHash)
    {
        orderHash = LibEIP712.hashEIP712Message(
            eip712ExchangeDomainHash,
            order.getStructHash()
        );
        return orderHash;
    }

    /// @dev Calculates EIP712 hash of the order struct.
    /// @param order The order structure.
    /// @return EIP712 hash of the order struct.
    function getStructHash(Order memory order)
        internal
        pure
        returns (bytes32 result)
    {
        bytes32 schemaHash = _EIP712_ORDER_SCHEMA_HASH;
        bytes memory makerAssetData = order.makerAssetData;
        bytes memory takerAssetData = order.takerAssetData;
        bytes memory makerFeeAssetData = order.makerFeeAssetData;
        bytes memory takerFeeAssetData = order.takerFeeAssetData;

        // Assembly for more efficiently computing:
        // keccak256(abi.encodePacked(
        //     EIP712_ORDER_SCHEMA_HASH,
        //     uint256(order.makerAddress),
        //     uint256(order.takerAddress),
        //     uint256(order.feeRecipientAddress),
        //     uint256(order.senderAddress),
        //     order.makerAssetAmount,
        //     order.takerAssetAmount,
        //     order.makerFee,
        //     order.takerFee,
        //     order.expirationTimeSeconds,
        //     order.salt,
        //     keccak256(order.makerAssetData),
        //     keccak256(order.takerAssetData),
        //     keccak256(order.makerFeeAssetData),
        //     keccak256(order.takerFeeAssetData)
        // ));

        assembly {
            // Assert order offset (this is an internal error that should never be triggered)
            if lt(order, 32) {
                invalid()
            }

            // Calculate memory addresses that will be swapped out before hashing
            let pos1 := sub(order, 32)
            let pos2 := add(order, 320)
            let pos3 := add(order, 352)
            let pos4 := add(order, 384)
            let pos5 := add(order, 416)

            // Backup
            let temp1 := mload(pos1)
            let temp2 := mload(pos2)
            let temp3 := mload(pos3)
            let temp4 := mload(pos4)
            let temp5 := mload(pos5)

            // Hash in place
            mstore(pos1, schemaHash)
            mstore(pos2, keccak256(add(makerAssetData, 32), mload(makerAssetData)))        // store hash of makerAssetData
            mstore(pos3, keccak256(add(takerAssetData, 32), mload(takerAssetData)))        // store hash of takerAssetData
            mstore(pos4, keccak256(add(makerFeeAssetData, 32), mload(makerFeeAssetData)))  // store hash of makerFeeAssetData
            mstore(pos5, keccak256(add(takerFeeAssetData, 32), mload(takerFeeAssetData)))  // store hash of takerFeeAssetData
            result := keccak256(pos1, 480)

            // Restore
            mstore(pos1, temp1)
            mstore(pos2, temp2)
            mstore(pos3, temp3)
            mstore(pos4, temp4)
            mstore(pos5, temp5)
        }
        return result;
    }
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

library LibRichErrors {

    // bytes4(keccak256("Error(string)"))
    bytes4 internal constant STANDARD_ERROR_SELECTOR =
        0x08c379a0;

    // solhint-disable func-name-mixedcase
    /// @dev ABI encode a standard, string revert error payload.
    ///      This is the same payload that would be included by a `revert(string)`
    ///      solidity statement. It has the function signature `Error(string)`.
    /// @param message The error string.
    /// @return The ABI encoded error.
    function StandardError(
        string memory message
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            STANDARD_ERROR_SELECTOR,
            bytes(message)
        );
    }
    // solhint-enable func-name-mixedcase

    /// @dev Reverts an encoded rich revert reason `errorData`.
    /// @param errorData ABI encoded error data.
    function rrevert(bytes memory errorData)
        internal
        pure
    {
        assembly {
            revert(add(errorData, 0x20), mload(errorData))
        }
    }
}

library LibSafeMathRichErrors {

    // bytes4(keccak256("Uint256BinOpError(uint8,uint256,uint256)"))
    bytes4 internal constant UINT256_BINOP_ERROR_SELECTOR =
        0xe946c1bb;

    // bytes4(keccak256("Uint256DowncastError(uint8,uint256)"))
    bytes4 internal constant UINT256_DOWNCAST_ERROR_SELECTOR =
        0xc996af7b;

    enum BinOpErrorCodes {
        ADDITION_OVERFLOW,
        MULTIPLICATION_OVERFLOW,
        SUBTRACTION_UNDERFLOW,
        DIVISION_BY_ZERO
    }

    enum DowncastErrorCodes {
        VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT32,
        VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT64,
        VALUE_TOO_LARGE_TO_DOWNCAST_TO_UINT96
    }

    // solhint-disable func-name-mixedcase
    function Uint256BinOpError(
        BinOpErrorCodes errorCode,
        uint256 a,
        uint256 b
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            UINT256_BINOP_ERROR_SELECTOR,
            errorCode,
            a,
            b
        );
    }

    function Uint256DowncastError(
        DowncastErrorCodes errorCode,
        uint256 a
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            UINT256_DOWNCAST_ERROR_SELECTOR,
            errorCode,
            a
        );
    }
}

library LibSafeMath {

    function safeMul(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        if (c / a != b) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
                LibSafeMathRichErrors.BinOpErrorCodes.MULTIPLICATION_OVERFLOW,
                a,
                b
            ));
        }
        return c;
    }

    function safeDiv(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        if (b == 0) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
                LibSafeMathRichErrors.BinOpErrorCodes.DIVISION_BY_ZERO,
                a,
                b
            ));
        }
        uint256 c = a / b;
        return c;
    }

    function safeSub(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        if (b > a) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
                LibSafeMathRichErrors.BinOpErrorCodes.SUBTRACTION_UNDERFLOW,
                a,
                b
            ));
        }
        return a - b;
    }

    function safeAdd(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        uint256 c = a + b;
        if (c < a) {
            LibRichErrors.rrevert(LibSafeMathRichErrors.Uint256BinOpError(
                LibSafeMathRichErrors.BinOpErrorCodes.ADDITION_OVERFLOW,
                a,
                b
            ));
        }
        return c;
    }

    function max256(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        return a >= b ? a : b;
    }

    function min256(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        return a < b ? a : b;
    }
}

library LibMathRichErrors {

    // bytes4(keccak256("DivisionByZeroError()"))
    bytes internal constant DIVISION_BY_ZERO_ERROR =
        hex"a791837c";

    // bytes4(keccak256("RoundingError(uint256,uint256,uint256)"))
    bytes4 internal constant ROUNDING_ERROR_SELECTOR =
        0x339f3de2;

    // solhint-disable func-name-mixedcase
    function DivisionByZeroError()
        internal
        pure
        returns (bytes memory)
    {
        return DIVISION_BY_ZERO_ERROR;
    }

    function RoundingError(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            ROUNDING_ERROR_SELECTOR,
            numerator,
            denominator,
            target
        );
    }
}

library LibMath {

    using LibSafeMath for uint256;

    /// @dev Calculates partial value given a numerator and denominator rounded down.
    ///      Reverts if rounding error is >= 0.1%
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to calculate partial of.
    /// @return Partial value of target rounded down.
    function safeGetPartialAmountFloor(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (uint256 partialAmount)
    {
        if (isRoundingErrorFloor(
                numerator,
                denominator,
                target
        )) {
            LibRichErrors.rrevert(LibMathRichErrors.RoundingError(
                numerator,
                denominator,
                target
            ));
        }

        partialAmount = numerator.safeMul(target).safeDiv(denominator);
        return partialAmount;
    }

    /// @dev Calculates partial value given a numerator and denominator rounded down.
    ///      Reverts if rounding error is >= 0.1%
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to calculate partial of.
    /// @return Partial value of target rounded up.
    function safeGetPartialAmountCeil(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (uint256 partialAmount)
    {
        if (isRoundingErrorCeil(
                numerator,
                denominator,
                target
        )) {
            LibRichErrors.rrevert(LibMathRichErrors.RoundingError(
                numerator,
                denominator,
                target
            ));
        }

        // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
        //       ceil(a / b) = floor((a + b - 1) / b)
        // To implement `ceil(a / b)` using safeDiv.
        partialAmount = numerator.safeMul(target)
            .safeAdd(denominator.safeSub(1))
            .safeDiv(denominator);

        return partialAmount;
    }

    /// @dev Calculates partial value given a numerator and denominator rounded down.
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to calculate partial of.
    /// @return Partial value of target rounded down.
    function getPartialAmountFloor(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (uint256 partialAmount)
    {
        partialAmount = numerator.safeMul(target).safeDiv(denominator);
        return partialAmount;
    }

    /// @dev Calculates partial value given a numerator and denominator rounded down.
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to calculate partial of.
    /// @return Partial value of target rounded up.
    function getPartialAmountCeil(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (uint256 partialAmount)
    {
        // safeDiv computes `floor(a / b)`. We use the identity (a, b integer):
        //       ceil(a / b) = floor((a + b - 1) / b)
        // To implement `ceil(a / b)` using safeDiv.
        partialAmount = numerator.safeMul(target)
            .safeAdd(denominator.safeSub(1))
            .safeDiv(denominator);

        return partialAmount;
    }

    /// @dev Checks if rounding error >= 0.1% when rounding down.
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to multiply with numerator/denominator.
    /// @return Rounding error is present.
    function isRoundingErrorFloor(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (bool isError)
    {
        if (denominator == 0) {
            LibRichErrors.rrevert(LibMathRichErrors.DivisionByZeroError());
        }

        // The absolute rounding error is the difference between the rounded
        // value and the ideal value. The relative rounding error is the
        // absolute rounding error divided by the absolute value of the
        // ideal value. This is undefined when the ideal value is zero.
        //
        // The ideal value is `numerator * target / denominator`.
        // Let's call `numerator * target % denominator` the remainder.
        // The absolute error is `remainder / denominator`.
        //
        // When the ideal value is zero, we require the absolute error to
        // be zero. Fortunately, this is always the case. The ideal value is
        // zero iff `numerator == 0` and/or `target == 0`. In this case the
        // remainder and absolute error are also zero.
        if (target == 0 || numerator == 0) {
            return false;
        }

        // Otherwise, we want the relative rounding error to be strictly
        // less than 0.1%.
        // The relative error is `remainder / (numerator * target)`.
        // We want the relative error less than 1 / 1000:
        //        remainder / (numerator * denominator)  <  1 / 1000
        // or equivalently:
        //        1000 * remainder  <  numerator * target
        // so we have a rounding error iff:
        //        1000 * remainder  >=  numerator * target
        uint256 remainder = mulmod(
            target,
            numerator,
            denominator
        );
        isError = remainder.safeMul(1000) >= numerator.safeMul(target);
        return isError;
    }

    /// @dev Checks if rounding error >= 0.1% when rounding up.
    /// @param numerator Numerator.
    /// @param denominator Denominator.
    /// @param target Value to multiply with numerator/denominator.
    /// @return Rounding error is present.
    function isRoundingErrorCeil(
        uint256 numerator,
        uint256 denominator,
        uint256 target
    )
        internal
        pure
        returns (bool isError)
    {
        if (denominator == 0) {
            LibRichErrors.rrevert(LibMathRichErrors.DivisionByZeroError());
        }

        // See the comments in `isRoundingError`.
        if (target == 0 || numerator == 0) {
            // When either is zero, the ideal value and rounded value are zero
            // and there is no rounding error. (Although the relative error
            // is undefined.)
            return false;
        }
        // Compute remainder as before
        uint256 remainder = mulmod(
            target,
            numerator,
            denominator
        );
        remainder = denominator.safeSub(remainder) % denominator;
        isError = remainder.safeMul(1000) >= numerator.safeMul(target);
        return isError;
    }
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

library LibBytesRichErrors {

    enum InvalidByteOperationErrorCodes {
        FromLessThanOrEqualsToRequired,
        ToLessThanOrEqualsLengthRequired,
        LengthGreaterThanZeroRequired,
        LengthGreaterThanOrEqualsFourRequired,
        LengthGreaterThanOrEqualsTwentyRequired,
        LengthGreaterThanOrEqualsThirtyTwoRequired,
        LengthGreaterThanOrEqualsNestedBytesLengthRequired,
        DestinationLengthGreaterThanOrEqualSourceLengthRequired
    }

    // bytes4(keccak256("InvalidByteOperationError(uint8,uint256,uint256)"))
    bytes4 internal constant INVALID_BYTE_OPERATION_ERROR_SELECTOR =
        0x28006595;

    // solhint-disable func-name-mixedcase
    function InvalidByteOperationError(
        InvalidByteOperationErrorCodes errorCode,
        uint256 offset,
        uint256 required
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            INVALID_BYTE_OPERATION_ERROR_SELECTOR,
            errorCode,
            offset,
            required
        );
    }
}

library LibBytes {

    using LibBytes for bytes;

    /// @dev Gets the memory address for a byte array.
    /// @param input Byte array to lookup.
    /// @return memoryAddress Memory address of byte array. This
    ///         points to the header of the byte array which contains
    ///         the length.
    function rawAddress(bytes memory input)
        internal
        pure
        returns (uint256 memoryAddress)
    {
        assembly {
            memoryAddress := input
        }
        return memoryAddress;
    }

    /// @dev Gets the memory address for the contents of a byte array.
    /// @param input Byte array to lookup.
    /// @return memoryAddress Memory address of the contents of the byte array.
    function contentAddress(bytes memory input)
        internal
        pure
        returns (uint256 memoryAddress)
    {
        assembly {
            memoryAddress := add(input, 32)
        }
        return memoryAddress;
    }

    /// @dev Copies `length` bytes from memory location `source` to `dest`.
    /// @param dest memory address to copy bytes to.
    /// @param source memory address to copy bytes from.
    /// @param length number of bytes to copy.
    function memCopy(
        uint256 dest,
        uint256 source,
        uint256 length
    )
        internal
        pure
    {
        if (length < 32) {
            // Handle a partial word by reading destination and masking
            // off the bits we are interested in.
            // This correctly handles overlap, zero lengths and source == dest
            assembly {
                let mask := sub(exp(256, sub(32, length)), 1)
                let s := and(mload(source), not(mask))
                let d := and(mload(dest), mask)
                mstore(dest, or(s, d))
            }
        } else {
            // Skip the O(length) loop when source == dest.
            if (source == dest) {
                return;
            }

            // For large copies we copy whole words at a time. The final
            // word is aligned to the end of the range (instead of after the
            // previous) to handle partial words. So a copy will look like this:
            //
            //  ####
            //      ####
            //          ####
            //            ####
            //
            // We handle overlap in the source and destination range by
            // changing the copying direction. This prevents us from
            // overwriting parts of source that we still need to copy.
            //
            // This correctly handles source == dest
            //
            if (source > dest) {
                assembly {
                    // We subtract 32 from `sEnd` and `dEnd` because it
                    // is easier to compare with in the loop, and these
                    // are also the addresses we need for copying the
                    // last bytes.
                    length := sub(length, 32)
                    let sEnd := add(source, length)
                    let dEnd := add(dest, length)

                    // Remember the last 32 bytes of source
                    // This needs to be done here and not after the loop
                    // because we may have overwritten the last bytes in
                    // source already due to overlap.
                    let last := mload(sEnd)

                    // Copy whole words front to back
                    // Note: the first check is always true,
                    // this could have been a do-while loop.
                    // solhint-disable-next-line no-empty-blocks
                    for {} lt(source, sEnd) {} {
                        mstore(dest, mload(source))
                        source := add(source, 32)
                        dest := add(dest, 32)
                    }

                    // Write the last 32 bytes
                    mstore(dEnd, last)
                }
            } else {
                assembly {
                    // We subtract 32 from `sEnd` and `dEnd` because those
                    // are the starting points when copying a word at the end.
                    length := sub(length, 32)
                    let sEnd := add(source, length)
                    let dEnd := add(dest, length)

                    // Remember the first 32 bytes of source
                    // This needs to be done here and not after the loop
                    // because we may have overwritten the first bytes in
                    // source already due to overlap.
                    let first := mload(source)

                    // Copy whole words back to front
                    // We use a signed comparisson here to allow dEnd to become
                    // negative (happens when source and dest < 32). Valid
                    // addresses in local memory will never be larger than
                    // 2**255, so they can be safely re-interpreted as signed.
                    // Note: the first check is always true,
                    // this could have been a do-while loop.
                    // solhint-disable-next-line no-empty-blocks
                    for {} slt(dest, dEnd) {} {
                        mstore(dEnd, mload(sEnd))
                        sEnd := sub(sEnd, 32)
                        dEnd := sub(dEnd, 32)
                    }

                    // Write the first 32 bytes
                    mstore(dest, first)
                }
            }
        }
    }

    /// @dev Returns a slices from a byte array.
    /// @param b The byte array to take a slice from.
    /// @param from The starting index for the slice (inclusive).
    /// @param to The final index for the slice (exclusive).
    /// @return result The slice containing bytes at indices [from, to)
    function slice(
        bytes memory b,
        uint256 from,
        uint256 to
    )
        internal
        pure
        returns (bytes memory result)
    {
        // Ensure that the from and to positions are valid positions for a slice within
        // the byte array that is being used.
        if (from > to) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired,
                from,
                to
            ));
        }
        if (to > b.length) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired,
                to,
                b.length
            ));
        }

        // Create a new bytes structure and copy contents
        result = new bytes(to - from);
        memCopy(
            result.contentAddress(),
            b.contentAddress() + from,
            result.length
        );
        return result;
    }

    /// @dev Returns a slice from a byte array without preserving the input.
    /// @param b The byte array to take a slice from. Will be destroyed in the process.
    /// @param from The starting index for the slice (inclusive).
    /// @param to The final index for the slice (exclusive).
    /// @return result The slice containing bytes at indices [from, to)
    /// @dev When `from == 0`, the original array will match the slice. In other cases its state will be corrupted.
    function sliceDestructive(
        bytes memory b,
        uint256 from,
        uint256 to
    )
        internal
        pure
        returns (bytes memory result)
    {
        // Ensure that the from and to positions are valid positions for a slice within
        // the byte array that is being used.
        if (from > to) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.FromLessThanOrEqualsToRequired,
                from,
                to
            ));
        }
        if (to > b.length) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.ToLessThanOrEqualsLengthRequired,
                to,
                b.length
            ));
        }

        // Create a new bytes structure around [from, to) in-place.
        assembly {
            result := add(b, from)
            mstore(result, sub(to, from))
        }
        return result;
    }

    /// @dev Pops the last byte off of a byte array by modifying its length.
    /// @param b Byte array that will be modified.
    /// @return The byte that was popped off.
    function popLastByte(bytes memory b)
        internal
        pure
        returns (bytes1 result)
    {
        if (b.length == 0) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanZeroRequired,
                b.length,
                0
            ));
        }

        // Store last byte.
        result = b[b.length - 1];

        assembly {
            // Decrement length of byte array.
            let newLen := sub(mload(b), 1)
            mstore(b, newLen)
        }
        return result;
    }

    /// @dev Tests equality of two byte arrays.
    /// @param lhs First byte array to compare.
    /// @param rhs Second byte array to compare.
    /// @return True if arrays are the same. False otherwise.
    function equals(
        bytes memory lhs,
        bytes memory rhs
    )
        internal
        pure
        returns (bool equal)
    {
        // Keccak gas cost is 30 + numWords * 6. This is a cheap way to compare.
        // We early exit on unequal lengths, but keccak would also correctly
        // handle this.
        return lhs.length == rhs.length && keccak256(lhs) == keccak256(rhs);
    }

    /// @dev Reads an address from a position in a byte array.
    /// @param b Byte array containing an address.
    /// @param index Index in byte array of address.
    /// @return address from byte array.
    function readAddress(
        bytes memory b,
        uint256 index
    )
        internal
        pure
        returns (address result)
    {
        if (b.length < index + 20) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired,
                b.length,
                index + 20 // 20 is length of address
            ));
        }

        // Add offset to index:
        // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index)
        // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index)
        index += 20;

        // Read address from array memory
        assembly {
            // 1. Add index to address of bytes array
            // 2. Load 32-byte word from memory
            // 3. Apply 20-byte mask to obtain address
            result := and(mload(add(b, index)), 0xffffffffffffffffffffffffffffffffffffffff)
        }
        return result;
    }

    /// @dev Writes an address into a specific position in a byte array.
    /// @param b Byte array to insert address into.
    /// @param index Index in byte array of address.
    /// @param input Address to put into byte array.
    function writeAddress(
        bytes memory b,
        uint256 index,
        address input
    )
        internal
        pure
    {
        if (b.length < index + 20) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsTwentyRequired,
                b.length,
                index + 20 // 20 is length of address
            ));
        }

        // Add offset to index:
        // 1. Arrays are prefixed by 32-byte length parameter (add 32 to index)
        // 2. Account for size difference between address length and 32-byte storage word (subtract 12 from index)
        index += 20;

        // Store address into array memory
        assembly {
            // The address occupies 20 bytes and mstore stores 32 bytes.
            // First fetch the 32-byte word where we'll be storing the address, then
            // apply a mask so we have only the bytes in the word that the address will not occupy.
            // Then combine these bytes with the address and store the 32 bytes back to memory with mstore.

            // 1. Add index to address of bytes array
            // 2. Load 32-byte word from memory
            // 3. Apply 12-byte mask to obtain extra bytes occupying word of memory where we'll store the address
            let neighbors := and(
                mload(add(b, index)),
                0xffffffffffffffffffffffff0000000000000000000000000000000000000000
            )

            // Make sure input address is clean.
            // (Solidity does not guarantee this)
            input := and(input, 0xffffffffffffffffffffffffffffffffffffffff)

            // Store the neighbors and address into memory
            mstore(add(b, index), xor(input, neighbors))
        }
    }

    /// @dev Reads a bytes32 value from a position in a byte array.
    /// @param b Byte array containing a bytes32 value.
    /// @param index Index in byte array of bytes32 value.
    /// @return bytes32 value from byte array.
    function readBytes32(
        bytes memory b,
        uint256 index
    )
        internal
        pure
        returns (bytes32 result)
    {
        if (b.length < index + 32) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired,
                b.length,
                index + 32
            ));
        }

        // Arrays are prefixed by a 256 bit length parameter
        index += 32;

        // Read the bytes32 from array memory
        assembly {
            result := mload(add(b, index))
        }
        return result;
    }

    /// @dev Writes a bytes32 into a specific position in a byte array.
    /// @param b Byte array to insert <input> into.
    /// @param index Index in byte array of <input>.
    /// @param input bytes32 to put into byte array.
    function writeBytes32(
        bytes memory b,
        uint256 index,
        bytes32 input
    )
        internal
        pure
    {
        if (b.length < index + 32) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsThirtyTwoRequired,
                b.length,
                index + 32
            ));
        }

        // Arrays are prefixed by a 256 bit length parameter
        index += 32;

        // Read the bytes32 from array memory
        assembly {
            mstore(add(b, index), input)
        }
    }

    /// @dev Reads a uint256 value from a position in a byte array.
    /// @param b Byte array containing a uint256 value.
    /// @param index Index in byte array of uint256 value.
    /// @return uint256 value from byte array.
    function readUint256(
        bytes memory b,
        uint256 index
    )
        internal
        pure
        returns (uint256 result)
    {
        result = uint256(readBytes32(b, index));
        return result;
    }

    /// @dev Writes a uint256 into a specific position in a byte array.
    /// @param b Byte array to insert <input> into.
    /// @param index Index in byte array of <input>.
    /// @param input uint256 to put into byte array.
    function writeUint256(
        bytes memory b,
        uint256 index,
        uint256 input
    )
        internal
        pure
    {
        writeBytes32(b, index, bytes32(input));
    }

    /// @dev Reads an unpadded bytes4 value from a position in a byte array.
    /// @param b Byte array containing a bytes4 value.
    /// @param index Index in byte array of bytes4 value.
    /// @return bytes4 value from byte array.
    function readBytes4(
        bytes memory b,
        uint256 index
    )
        internal
        pure
        returns (bytes4 result)
    {
        if (b.length < index + 4) {
            LibRichErrors.rrevert(LibBytesRichErrors.InvalidByteOperationError(
                LibBytesRichErrors.InvalidByteOperationErrorCodes.LengthGreaterThanOrEqualsFourRequired,
                b.length,
                index + 4
            ));
        }

        // Arrays are prefixed by a 32 byte length field
        index += 32;

        // Read the bytes4 from array memory
        assembly {
            result := mload(add(b, index))
            // Solidity does not require us to clean the trailing bytes.
            // We do it anyway
            result := and(result, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000)
        }
        return result;
    }

    /// @dev Writes a new length to a byte array.
    ///      Decreasing length will lead to removing the corresponding lower order bytes from the byte array.
    ///      Increasing length may lead to appending adjacent in-memory bytes to the end of the byte array.
    /// @param b Bytes array to write new length to.
    /// @param length New length of byte array.
    function writeLength(bytes memory b, uint256 length)
        internal
        pure
    {
        assembly {
            mstore(b, length)
        }
    }
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IERC20Token {

    // solhint-disable no-simple-event-func-name
    event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 _value
    );

    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _value
    );

    /// @dev send `value` token to `to` from `msg.sender`
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return True if transfer was successful
    function transfer(address _to, uint256 _value)
        external
        returns (bool);

    /// @dev send `value` token to `to` from `from` on the condition it is approved by `from`
    /// @param _from The address of the sender
    /// @param _to The address of the recipient
    /// @param _value The amount of token to be transferred
    /// @return True if transfer was successful
    function transferFrom(
        address _from,
        address _to,
        uint256 _value
    )
        external
        returns (bool);

    /// @dev `msg.sender` approves `_spender` to spend `_value` tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @param _value The amount of wei to be approved for transfer
    /// @return Always true if the call has enough gas to complete execution
    function approve(address _spender, uint256 _value)
        external
        returns (bool);

    /// @dev Query total supply of token
    /// @return Total supply of token
    function totalSupply()
        external
        view
        returns (uint256);

    /// @param _owner The address from which the balance will be retrieved
    /// @return Balance of owner
    function balanceOf(address _owner)
        external
        view
        returns (uint256);

    /// @param _owner The address of the account owning tokens
    /// @param _spender The address of the account able to transfer the tokens
    /// @return Amount of remaining tokens allowed to spent
    function allowance(address _owner, address _spender)
        external
        view
        returns (uint256);
}

library LibERC20Token {
    bytes constant private DECIMALS_CALL_DATA = hex"313ce567";

    /// @dev Calls `IERC20Token(token).approve()`.
    ///      Reverts if `false` is returned or if the return
    ///      data length is nonzero and not 32 bytes.
    /// @param token The address of the token contract.
    /// @param spender The address that receives an allowance.
    /// @param allowance The allowance to set.
    function approve(
        address token,
        address spender,
        uint256 allowance
    )
        internal
    {
        bytes memory callData = abi.encodeWithSelector(
            IERC20Token(0).approve.selector,
            spender,
            allowance
        );
        _callWithOptionalBooleanResult(token, callData);
    }

    /// @dev Calls `IERC20Token(token).approve()` and sets the allowance to the
    ///      maximum if the current approval is not already >= an amount.
    ///      Reverts if `false` is returned or if the return
    ///      data length is nonzero and not 32 bytes.
    /// @param token The address of the token contract.
    /// @param spender The address that receives an allowance.
    /// @param amount The minimum allowance needed.
    function approveIfBelow(
        address token,
        address spender,
        uint256 amount
    )
        internal
    {
        if (IERC20Token(token).allowance(address(this), spender) < amount) {
            approve(token, spender, uint256(-1));
        }
    }

    /// @dev Calls `IERC20Token(token).transfer()`.
    ///      Reverts if `false` is returned or if the return
    ///      data length is nonzero and not 32 bytes.
    /// @param token The address of the token contract.
    /// @param to The address that receives the tokens
    /// @param amount Number of tokens to transfer.
    function transfer(
        address token,
        address to,
        uint256 amount
    )
        internal
    {
        bytes memory callData = abi.encodeWithSelector(
            IERC20Token(0).transfer.selector,
            to,
            amount
        );
        _callWithOptionalBooleanResult(token, callData);
    }

    /// @dev Calls `IERC20Token(token).transferFrom()`.
    ///      Reverts if `false` is returned or if the return
    ///      data length is nonzero and not 32 bytes.
    /// @param token The address of the token contract.
    /// @param from The owner of the tokens.
    /// @param to The address that receives the tokens
    /// @param amount Number of tokens to transfer.
    function transferFrom(
        address token,
        address from,
        address to,
        uint256 amount
    )
        internal
    {
        bytes memory callData = abi.encodeWithSelector(
            IERC20Token(0).transferFrom.selector,
            from,
            to,
            amount
        );
        _callWithOptionalBooleanResult(token, callData);
    }

    /// @dev Retrieves the number of decimals for a token.
    ///      Returns `18` if the call reverts.
    /// @param token The address of the token contract.
    /// @return tokenDecimals The number of decimals places for the token.
    function decimals(address token)
        internal
        view
        returns (uint8 tokenDecimals)
    {
        tokenDecimals = 18;
        (bool didSucceed, bytes memory resultData) = token.staticcall(DECIMALS_CALL_DATA);
        if (didSucceed && resultData.length == 32) {
            tokenDecimals = uint8(LibBytes.readUint256(resultData, 0));
        }
    }

    /// @dev Retrieves the allowance for a token, owner, and spender.
    ///      Returns `0` if the call reverts.
    /// @param token The address of the token contract.
    /// @param owner The owner of the tokens.
    /// @param spender The address the spender.
    /// @return allowance The allowance for a token, owner, and spender.
    function allowance(address token, address owner, address spender)
        internal
        view
        returns (uint256 allowance_)
    {
        (bool didSucceed, bytes memory resultData) = token.staticcall(
            abi.encodeWithSelector(
                IERC20Token(0).allowance.selector,
                owner,
                spender
            )
        );
        if (didSucceed && resultData.length == 32) {
            allowance_ = LibBytes.readUint256(resultData, 0);
        }
    }

    /// @dev Retrieves the balance for a token owner.
    ///      Returns `0` if the call reverts.
    /// @param token The address of the token contract.
    /// @param owner The owner of the tokens.
    /// @return balance The token balance of an owner.
    function balanceOf(address token, address owner)
        internal
        view
        returns (uint256 balance)
    {
        (bool didSucceed, bytes memory resultData) = token.staticcall(
            abi.encodeWithSelector(
                IERC20Token(0).balanceOf.selector,
                owner
            )
        );
        if (didSucceed && resultData.length == 32) {
            balance = LibBytes.readUint256(resultData, 0);
        }
    }

    /// @dev Executes a call on address `target` with calldata `callData`
    ///      and asserts that either nothing was returned or a single boolean
    ///      was returned equal to `true`.
    /// @param target The call target.
    /// @param callData The abi-encoded call data.
    function _callWithOptionalBooleanResult(
        address target,
        bytes memory callData
    )
        private
    {
        (bool didSucceed, bytes memory resultData) = target.call(callData);
        if (didSucceed) {
            if (resultData.length == 0) {
                return;
            }
            if (resultData.length == 32) {
                uint256 result = LibBytes.readUint256(resultData, 0);
                if (result == 1) {
                    return;
                }
            }
        }
        LibRichErrors.rrevert(resultData);
    }
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IERC721Token {

    /// @dev This emits when ownership of any NFT changes by any mechanism.
    ///      This event emits when NFTs are created (`from` == 0) and destroyed
    ///      (`to` == 0). Exception: during contract creation, any number of NFTs
    ///      may be created and assigned without emitting Transfer. At the time of
    ///      any transfer, the approved address for that NFT (if any) is reset to none.
    event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 indexed _tokenId
    );

    /// @dev This emits when the approved address for an NFT is changed or
    ///      reaffirmed. The zero address indicates there is no approved address.
    ///      When a Transfer event emits, this also indicates that the approved
    ///      address for that NFT (if any) is reset to none.
    event Approval(
        address indexed _owner,
        address indexed _approved,
        uint256 indexed _tokenId
    );

    /// @dev This emits when an operator is enabled or disabled for an owner.
    ///      The operator can manage all NFTs of the owner.
    event ApprovalForAll(
        address indexed _owner,
        address indexed _operator,
        bool _approved
    );

    /// @notice Transfers the ownership of an NFT from one address to another address
    /// @dev Throws unless `msg.sender` is the current owner, an authorized
    ///      perator, or the approved address for this NFT. Throws if `_from` is
    ///      not the current owner. Throws if `_to` is the zero address. Throws if
    ///      `_tokenId` is not a valid NFT. When transfer is complete, this function
    ///      checks if `_to` is a smart contract (code size > 0). If so, it calls
    ///      `onERC721Received` on `_to` and throws if the return value is not
    ///      `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`.
    /// @param _from The current owner of the NFT
    /// @param _to The new owner
    /// @param _tokenId The NFT to transfer
    /// @param _data Additional data with no specified format, sent in call to `_to`
    function safeTransferFrom(
        address _from,
        address _to,
        uint256 _tokenId,
        bytes calldata _data
    )
        external;

    /// @notice Transfers the ownership of an NFT from one address to another address
    /// @dev This works identically to the other function with an extra data parameter,
    ///      except this function just sets data to "".
    /// @param _from The current owner of the NFT
    /// @param _to The new owner
    /// @param _tokenId The NFT to transfer
    function safeTransferFrom(
        address _from,
        address _to,
        uint256 _tokenId
    )
        external;

    /// @notice Change or reaffirm the approved address for an NFT
    /// @dev The zero address indicates there is no approved address.
    ///      Throws unless `msg.sender` is the current NFT owner, or an authorized
    ///      operator of the current owner.
    /// @param _approved The new approved NFT controller
    /// @param _tokenId The NFT to approve
    function approve(address _approved, uint256 _tokenId)
        external;

    /// @notice Enable or disable approval for a third party ("operator") to manage
    ///         all of `msg.sender`'s assets
    /// @dev Emits the ApprovalForAll event. The contract MUST allow
    ///      multiple operators per owner.
    /// @param _operator Address to add to the set of authorized operators
    /// @param _approved True if the operator is approved, false to revoke approval
    function setApprovalForAll(address _operator, bool _approved)
        external;

    /// @notice Count all NFTs assigned to an owner
    /// @dev NFTs assigned to the zero address are considered invalid, and this
    ///      function throws for queries about the zero address.
    /// @param _owner An address for whom to query the balance
    /// @return The number of NFTs owned by `_owner`, possibly zero
    function balanceOf(address _owner)
        external
        view
        returns (uint256);

    /// @notice Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE
    ///         TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE
    ///         THEY MAY BE PERMANENTLY LOST
    /// @dev Throws unless `msg.sender` is the current owner, an authorized
    ///      operator, or the approved address for this NFT. Throws if `_from` is
    ///      not the current owner. Throws if `_to` is the zero address. Throws if
    ///      `_tokenId` is not a valid NFT.
    /// @param _from The current owner of the NFT
    /// @param _to The new owner
    /// @param _tokenId The NFT to transfer
    function transferFrom(
        address _from,
        address _to,
        uint256 _tokenId
    )
        public;

    /// @notice Find the owner of an NFT
    /// @dev NFTs assigned to zero address are considered invalid, and queries
    ///      about them do throw.
    /// @param _tokenId The identifier for an NFT
    /// @return The address of the owner of the NFT
    function ownerOf(uint256 _tokenId)
        public
        view
        returns (address);

    /// @notice Get the approved address for a single NFT
    /// @dev Throws if `_tokenId` is not a valid NFT.
    /// @param _tokenId The NFT to find the approved address for
    /// @return The approved address for this NFT, or the zero address if there is none
    function getApproved(uint256 _tokenId)
        public
        view
        returns (address);

    /// @notice Query if an address is an authorized operator for another address
    /// @param _owner The address that owns the NFTs
    /// @param _operator The address that acts on behalf of the owner
    /// @return True if `_operator` is an approved operator for `_owner`, false otherwise
    function isApprovedForAll(address _owner, address _operator)
        public
        view
        returns (bool);
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/// @title ERC-1155 Multi Token Standard
/// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1155.md
/// Note: The ERC-165 identifier for this interface is 0xd9b67a26.
interface IERC1155 {

    /// @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred,
    ///      including zero value transfers as well as minting or burning.
    /// Operator will always be msg.sender.
    /// Either event from address `0x0` signifies a minting operation.
    /// An event to address `0x0` signifies a burning or melting operation.
    /// The total value transferred from address 0x0 minus the total value transferred to 0x0 may
    /// be used by clients and exchanges to be added to the "circulating supply" for a given token ID.
    /// To define a token ID with no initial balance, the contract SHOULD emit the TransferSingle event
    /// from `0x0` to `0x0`, with the token creator as `_operator`.
    event TransferSingle(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256 id,
        uint256 value
    );

    /// @dev Either TransferSingle or TransferBatch MUST emit when tokens are transferred,
    ///      including zero value transfers as well as minting or burning.
    ///Operator will always be msg.sender.
    /// Either event from address `0x0` signifies a minting operation.
    /// An event to address `0x0` signifies a burning or melting operation.
    /// The total value transferred from address 0x0 minus the total value transferred to 0x0 may
    /// be used by clients and exchanges to be added to the "circulating supply" for a given token ID.
    /// To define multiple token IDs with no initial balance, this SHOULD emit the TransferBatch event
    /// from `0x0` to `0x0`, with the token creator as `_operator`.
    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    /// @dev MUST emit when an approval is updated.
    event ApprovalForAll(
        address indexed owner,
        address indexed operator,
        bool approved
    );

    /// @dev MUST emit when the URI is updated for a token ID.
    /// URIs are defined in RFC 3986.
    /// The URI MUST point a JSON file that conforms to the "ERC-1155 Metadata JSON Schema".
    event URI(
        string value,
        uint256 indexed id
    );

    /// @notice Transfers value amount of an _id from the _from address to the _to address specified.
    /// @dev MUST emit TransferSingle event on success.
    /// Caller must be approved to manage the _from account's tokens (see isApprovedForAll).
    /// MUST throw if `_to` is the zero address.
    /// MUST throw if balance of sender for token `_id` is lower than the `_value` sent.
    /// MUST throw on any other error.
    /// When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0).
    /// If so, it MUST call `onERC1155Received` on `_to` and revert if the return value
    /// is not `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`.
    /// @param from    Source address
    /// @param to      Target address
    /// @param id      ID of the token type
    /// @param value   Transfer amount
    /// @param data    Additional data with no specified format, sent in call to `_to`
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 value,
        bytes calldata data
    )
        external;

    /// @notice Send multiple types of Tokens from a 3rd party in one transfer (with safety call).
    /// @dev MUST emit TransferBatch event on success.
    /// Caller must be approved to manage the _from account's tokens (see isApprovedForAll).
    /// MUST throw if `_to` is the zero address.
    /// MUST throw if length of `_ids` is not the same as length of `_values`.
    ///  MUST throw if any of the balance of sender for token `_ids` is lower than the respective `_values` sent.
    /// MUST throw on any other error.
    /// When transfer is complete, this function MUST check if `_to` is a smart contract (code size > 0).
    /// If so, it MUST call `onERC1155BatchReceived` on `_to` and revert if the return value
    /// is not `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`.
    /// @param from    Source addresses
    /// @param to      Target addresses
    /// @param ids     IDs of each token type
    /// @param values  Transfer amounts per token type
    /// @param data    Additional data with no specified format, sent in call to `_to`
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    )
        external;

    /// @notice Enable or disable approval for a third party ("operator") to manage all of the caller's tokens.
    /// @dev MUST emit the ApprovalForAll event on success.
    /// @param operator  Address to add to the set of authorized operators
    /// @param approved  True if the operator is approved, false to revoke approval
    function setApprovalForAll(address operator, bool approved) external;

    /// @notice Queries the approval status of an operator for a given owner.
    /// @param owner     The owner of the Tokens
    /// @param operator  Address of authorized operator
    /// @return           True if the operator is approved, false if not
    function isApprovedForAll(address owner, address operator) external view returns (bool);

    /// @notice Get the balance of an account's Tokens.
    /// @param owner  The address of the token holder
    /// @param id     ID of the Token
    /// @return        The _owner's balance of the Token type requested
    function balanceOf(address owner, uint256 id) external view returns (uint256);

    /// @notice Get the balance of multiple account/token pairs
    /// @param owners The addresses of the token holders
    /// @param ids    ID of the Tokens
    /// @return        The _owner's balance of the Token types requested
    function balanceOfBatch(
        address[] calldata owners,
        uint256[] calldata ids
    )
        external
        view
        returns (uint256[] memory balances_);
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

library LibAssetDataTransferRichErrors {

    // bytes4(keccak256("UnsupportedAssetProxyError(bytes4)"))
    bytes4 internal constant UNSUPPORTED_ASSET_PROXY_ERROR_SELECTOR =
        0x7996a271;

    // bytes4(keccak256("Erc721AmountMustEqualOneError(uint256)"))
    bytes4 internal constant ERC721_AMOUNT_MUST_EQUAL_ONE_ERROR_SELECTOR =
        0xbaffa474;

    // solhint-disable func-name-mixedcase
    function UnsupportedAssetProxyError(
        bytes4 proxyId
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            UNSUPPORTED_ASSET_PROXY_ERROR_SELECTOR,
            proxyId
        );
    }

    function Erc721AmountMustEqualOneError(
        uint256 amount
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            ERC721_AMOUNT_MUST_EQUAL_ONE_ERROR_SELECTOR,
            amount
        );
    }
}

library LibAssetDataTransfer {

    using LibBytes for bytes;
    using LibSafeMath for uint256;
    using LibAssetDataTransfer for bytes;

    /// @dev Transfers given amount of asset to sender.
    /// @param assetData Byte array encoded for the respective asset proxy.
    /// @param from Address to transfer asset from.
    /// @param to Address to transfer asset to.
    /// @param amount Amount of asset to transfer to sender.
    function transferFrom(
        bytes memory assetData,
        address from,
        address to,
        uint256 amount
    )
        internal
    {
        if (amount == 0) {
            return;
        }

        bytes4 proxyId = assetData.readBytes4(0);

        if (
            proxyId == IAssetData(address(0)).ERC20Token.selector ||
            proxyId == IAssetData(address(0)).ERC20Bridge.selector
        ) {
            assetData.transferERC20Token(
                from,
                to,
                amount
            );
        } else if (proxyId == IAssetData(address(0)).ERC721Token.selector) {
            assetData.transferERC721Token(
                from,
                to,
                amount
            );
        } else if (proxyId == IAssetData(address(0)).ERC1155Assets.selector) {
            assetData.transferERC1155Assets(
                from,
                to,
                amount
            );
        } else if (proxyId == IAssetData(address(0)).MultiAsset.selector) {
            assetData.transferMultiAsset(
                from,
                to,
                amount
            );
        } else if (proxyId != IAssetData(address(0)).StaticCall.selector) {
            LibRichErrors.rrevert(LibAssetDataTransferRichErrors.UnsupportedAssetProxyError(
                proxyId
            ));
        }
    }

    ///@dev Transfer asset from sender to this contract.
    /// @param assetData Byte array encoded for the respective asset proxy.
    /// @param amount Amount of asset to transfer to sender.
    function transferIn(
        bytes memory assetData,
        uint256 amount
    )
        internal
    {
        assetData.transferFrom(
            msg.sender,
            address(this),
            amount
        );
    }

    ///@dev Transfer asset from this contract to sender.
    /// @param assetData Byte array encoded for the respective asset proxy.
    /// @param amount Amount of asset to transfer to sender.
    function transferOut(
        bytes memory assetData,
        uint256 amount
    )
        internal
    {
        assetData.transferFrom(
            address(this),
            msg.sender,
            amount
        );
    }

    /// @dev Decodes ERC20 or ERC20Bridge assetData and transfers given amount to sender.
    /// @param assetData Byte array encoded for the respective asset proxy.
    /// @param from Address to transfer asset from.
    /// @param to Address to transfer asset to.
    /// @param amount Amount of asset to transfer to sender.
    function transferERC20Token(
        bytes memory assetData,
        address from,
        address to,
        uint256 amount
    )
        internal
    {
        address token = assetData.readAddress(16);
        // Transfer tokens.
        if (from == address(this)) {
            LibERC20Token.transfer(
                token,
                to,
                amount
            );
        } else {
            LibERC20Token.transferFrom(
                token,
                from,
                to,
                amount
            );
        }
    }

    /// @dev Decodes ERC721 assetData and transfers given amount to sender.
    /// @param assetData Byte array encoded for the respective asset proxy.
    /// @param from Address to transfer asset from.
    /// @param to Address to transfer asset to.
    /// @param amount Amount of asset to transfer to sender.
    function transferERC721Token(
        bytes memory assetData,
        address from,
        address to,
        uint256 amount
    )
        internal
    {
        if (amount != 1) {
            LibRichErrors.rrevert(LibAssetDataTransferRichErrors.Erc721AmountMustEqualOneError(
                amount
            ));
        }
        // Decode asset data.
        address token = assetData.readAddress(16);
        uint256 tokenId = assetData.readUint256(36);

        // Perform transfer.
        IERC721Token(token).transferFrom(
            from,
            to,
            tokenId
        );
    }

    /// @dev Decodes ERC1155 assetData and transfers given amounts to sender.
    /// @param assetData Byte array encoded for the respective asset proxy.
    /// @param from Address to transfer asset from.
    /// @param to Address to transfer asset to.
    /// @param amount Amount of asset to transfer to sender.
    function transferERC1155Assets(
        bytes memory assetData,
        address from,
        address to,
        uint256 amount
    )
        internal
    {
        // Decode assetData
        // solhint-disable
        (
            address token,
            uint256[] memory ids,
            uint256[] memory values,
            bytes memory data
        ) = abi.decode(
            assetData.slice(4, assetData.length),
            (address, uint256[], uint256[], bytes)
        );
        // solhint-enable

        // Scale up values by `amount`
        uint256 length = values.length;
        uint256[] memory scaledValues = new uint256[](length);
        for (uint256 i = 0; i != length; i++) {
            scaledValues[i] = values[i].safeMul(amount);
        }

        // Execute `safeBatchTransferFrom` call
        // Either succeeds or throws
        IERC1155(token).safeBatchTransferFrom(
            from,
            to,
            ids,
            scaledValues,
            data
        );
    }

    /// @dev Decodes MultiAsset assetData and recursively transfers assets to sender.
    /// @param assetData Byte array encoded for the respective asset proxy.
    /// @param from Address to transfer asset from.
    /// @param to Address to transfer asset to.
    /// @param amount Amount of asset to transfer to sender.
    function transferMultiAsset(
        bytes memory assetData,
        address from,
        address to,
        uint256 amount
    )
        internal
    {
        // solhint-disable indent
        (uint256[] memory nestedAmounts, bytes[] memory nestedAssetData) = abi.decode(
            assetData.slice(4, assetData.length),
            (uint256[], bytes[])
        );
        // solhint-enable indent

        uint256 numNestedAssets = nestedAssetData.length;
        for (uint256 i = 0; i != numNestedAssets; i++) {
            transferFrom(
                nestedAssetData[i],
                from,
                to,
                amount.safeMul(nestedAmounts[i])
            );
        }
    }
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations \under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IEtherToken is
    IERC20Token
{
    function deposit()
        public
        payable;

    function withdraw(uint256 amount)
        public;
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

library LibFillResults {

    using LibSafeMath for uint256;

    struct BatchMatchedFillResults {
        FillResults[] left;              // Fill results for left orders
        FillResults[] right;             // Fill results for right orders
        uint256 profitInLeftMakerAsset;  // Profit taken from left makers
        uint256 profitInRightMakerAsset; // Profit taken from right makers
    }

    struct FillResults {
        uint256 makerAssetFilledAmount;  // Total amount of makerAsset(s) filled.
        uint256 takerAssetFilledAmount;  // Total amount of takerAsset(s) filled.
        uint256 makerFeePaid;            // Total amount of fees paid by maker(s) to feeRecipient(s).
        uint256 takerFeePaid;            // Total amount of fees paid by taker to feeRecipients(s).
        uint256 protocolFeePaid;         // Total amount of fees paid by taker to the staking contract.
    }

    struct MatchedFillResults {
        FillResults left;                // Amounts filled and fees paid of left order.
        FillResults right;               // Amounts filled and fees paid of right order.
        uint256 profitInLeftMakerAsset;  // Profit taken from the left maker
        uint256 profitInRightMakerAsset; // Profit taken from the right maker
    }

    /// @dev Calculates amounts filled and fees paid by maker and taker.
    /// @param order to be filled.
    /// @param takerAssetFilledAmount Amount of takerAsset that will be filled.
    /// @param protocolFeeMultiplier The current protocol fee of the exchange contract.
    /// @param gasPrice The gasprice of the transaction. This is provided so that the function call can continue
    ///        to be pure rather than view.
    /// @return fillResults Amounts filled and fees paid by maker and taker.
    function calculateFillResults(
        LibOrder.Order memory order,
        uint256 takerAssetFilledAmount,
        uint256 protocolFeeMultiplier,
        uint256 gasPrice
    )
        internal
        pure
        returns (FillResults memory fillResults)
    {
        // Compute proportional transfer amounts
        fillResults.takerAssetFilledAmount = takerAssetFilledAmount;
        fillResults.makerAssetFilledAmount = LibMath.safeGetPartialAmountFloor(
            takerAssetFilledAmount,
            order.takerAssetAmount,
            order.makerAssetAmount
        );
        fillResults.makerFeePaid = LibMath.safeGetPartialAmountFloor(
            takerAssetFilledAmount,
            order.takerAssetAmount,
            order.makerFee
        );
        fillResults.takerFeePaid = LibMath.safeGetPartialAmountFloor(
            takerAssetFilledAmount,
            order.takerAssetAmount,
            order.takerFee
        );

        // Compute the protocol fee that should be paid for a single fill.
        fillResults.protocolFeePaid = gasPrice.safeMul(protocolFeeMultiplier);

        return fillResults;
    }

    /// @dev Calculates fill amounts for the matched orders.
    ///      Each order is filled at their respective price point. However, the calculations are
    ///      carried out as though the orders are both being filled at the right order's price point.
    ///      The profit made by the leftOrder order goes to the taker (who matched the two orders).
    /// @param leftOrder First order to match.
    /// @param rightOrder Second order to match.
    /// @param leftOrderTakerAssetFilledAmount Amount of left order already filled.
    /// @param rightOrderTakerAssetFilledAmount Amount of right order already filled.
    /// @param protocolFeeMultiplier The current protocol fee of the exchange contract.
    /// @param gasPrice The gasprice of the transaction. This is provided so that the function call can continue
    ///        to be pure rather than view.
    /// @param shouldMaximallyFillOrders A value that indicates whether or not this calculation should use
    ///                                  the maximal fill order matching strategy.
    /// @param matchedFillResults Amounts to fill and fees to pay by maker and taker of matched orders.
    function calculateMatchedFillResults(
        LibOrder.Order memory leftOrder,
        LibOrder.Order memory rightOrder,
        uint256 leftOrderTakerAssetFilledAmount,
        uint256 rightOrderTakerAssetFilledAmount,
        uint256 protocolFeeMultiplier,
        uint256 gasPrice,
        bool shouldMaximallyFillOrders
    )
        internal
        pure
        returns (MatchedFillResults memory matchedFillResults)
    {
        // Derive maker asset amounts for left & right orders, given store taker assert amounts
        uint256 leftTakerAssetAmountRemaining = leftOrder.takerAssetAmount.safeSub(leftOrderTakerAssetFilledAmount);
        uint256 leftMakerAssetAmountRemaining = LibMath.safeGetPartialAmountFloor(
            leftOrder.makerAssetAmount,
            leftOrder.takerAssetAmount,
            leftTakerAssetAmountRemaining
        );
        uint256 rightTakerAssetAmountRemaining = rightOrder.takerAssetAmount.safeSub(rightOrderTakerAssetFilledAmount);
        uint256 rightMakerAssetAmountRemaining = LibMath.safeGetPartialAmountFloor(
            rightOrder.makerAssetAmount,
            rightOrder.takerAssetAmount,
            rightTakerAssetAmountRemaining
        );

        // Maximally fill the orders and pay out profits to the matcher in one or both of the maker assets.
        if (shouldMaximallyFillOrders) {
            matchedFillResults = _calculateMatchedFillResultsWithMaximalFill(
                leftOrder,
                rightOrder,
                leftMakerAssetAmountRemaining,
                leftTakerAssetAmountRemaining,
                rightMakerAssetAmountRemaining,
                rightTakerAssetAmountRemaining
            );
        } else {
            matchedFillResults = _calculateMatchedFillResults(
                leftOrder,
                rightOrder,
                leftMakerAssetAmountRemaining,
                leftTakerAssetAmountRemaining,
                rightMakerAssetAmountRemaining,
                rightTakerAssetAmountRemaining
            );
        }

        // Compute fees for left order
        matchedFillResults.left.makerFeePaid = LibMath.safeGetPartialAmountFloor(
            matchedFillResults.left.makerAssetFilledAmount,
            leftOrder.makerAssetAmount,
            leftOrder.makerFee
        );
        matchedFillResults.left.takerFeePaid = LibMath.safeGetPartialAmountFloor(
            matchedFillResults.left.takerAssetFilledAmount,
            leftOrder.takerAssetAmount,
            leftOrder.takerFee
        );

        // Compute fees for right order
        matchedFillResults.right.makerFeePaid = LibMath.safeGetPartialAmountFloor(
            matchedFillResults.right.makerAssetFilledAmount,
            rightOrder.makerAssetAmount,
            rightOrder.makerFee
        );
        matchedFillResults.right.takerFeePaid = LibMath.safeGetPartialAmountFloor(
            matchedFillResults.right.takerAssetFilledAmount,
            rightOrder.takerAssetAmount,
            rightOrder.takerFee
        );

        // Compute the protocol fee that should be paid for a single fill. In this
        // case this should be made the protocol fee for both the left and right orders.
        uint256 protocolFee = gasPrice.safeMul(protocolFeeMultiplier);
        matchedFillResults.left.protocolFeePaid = protocolFee;
        matchedFillResults.right.protocolFeePaid = protocolFee;

        // Return fill results
        return matchedFillResults;
    }

    /// @dev Adds properties of both FillResults instances.
    /// @param fillResults1 The first FillResults.
    /// @param fillResults2 The second FillResults.
    /// @return The sum of both fill results.
    function addFillResults(
        FillResults memory fillResults1,
        FillResults memory fillResults2
    )
        internal
        pure
        returns (FillResults memory totalFillResults)
    {
        totalFillResults.makerAssetFilledAmount = fillResults1.makerAssetFilledAmount.safeAdd(fillResults2.makerAssetFilledAmount);
        totalFillResults.takerAssetFilledAmount = fillResults1.takerAssetFilledAmount.safeAdd(fillResults2.takerAssetFilledAmount);
        totalFillResults.makerFeePaid = fillResults1.makerFeePaid.safeAdd(fillResults2.makerFeePaid);
        totalFillResults.takerFeePaid = fillResults1.takerFeePaid.safeAdd(fillResults2.takerFeePaid);
        totalFillResults.protocolFeePaid = fillResults1.protocolFeePaid.safeAdd(fillResults2.protocolFeePaid);

        return totalFillResults;
    }

    /// @dev Calculates part of the matched fill results for a given situation using the fill strategy that only
    ///      awards profit denominated in the left maker asset.
    /// @param leftOrder The left order in the order matching situation.
    /// @param rightOrder The right order in the order matching situation.
    /// @param leftMakerAssetAmountRemaining The amount of the left order maker asset that can still be filled.
    /// @param leftTakerAssetAmountRemaining The amount of the left order taker asset that can still be filled.
    /// @param rightMakerAssetAmountRemaining The amount of the right order maker asset that can still be filled.
    /// @param rightTakerAssetAmountRemaining The amount of the right order taker asset that can still be filled.
    /// @return MatchFillResults struct that does not include fees paid.
    function _calculateMatchedFillResults(
        LibOrder.Order memory leftOrder,
        LibOrder.Order memory rightOrder,
        uint256 leftMakerAssetAmountRemaining,
        uint256 leftTakerAssetAmountRemaining,
        uint256 rightMakerAssetAmountRemaining,
        uint256 rightTakerAssetAmountRemaining
    )
        private
        pure
        returns (MatchedFillResults memory matchedFillResults)
    {
        // Calculate fill results for maker and taker assets: at least one order will be fully filled.
        // The maximum amount the left maker can buy is `leftTakerAssetAmountRemaining`
        // The maximum amount the right maker can sell is `rightMakerAssetAmountRemaining`
        // We have two distinct cases for calculating the fill results:
        // Case 1.
        //   If the left maker can buy more than the right maker can sell, then only the right order is fully filled.
        //   If the left maker can buy exactly what the right maker can sell, then both orders are fully filled.
        // Case 2.
        //   If the left maker cannot buy more than the right maker can sell, then only the left order is fully filled.
        // Case 3.
        //   If the left maker can buy exactly as much as the right maker can sell, then both orders are fully filled.
        if (leftTakerAssetAmountRemaining > rightMakerAssetAmountRemaining) {
            // Case 1: Right order is fully filled
            matchedFillResults = _calculateCompleteRightFill(
                leftOrder,
                rightMakerAssetAmountRemaining,
                rightTakerAssetAmountRemaining
            );
        } else if (leftTakerAssetAmountRemaining < rightMakerAssetAmountRemaining) {
            // Case 2: Left order is fully filled
            matchedFillResults.left.makerAssetFilledAmount = leftMakerAssetAmountRemaining;
            matchedFillResults.left.takerAssetFilledAmount = leftTakerAssetAmountRemaining;
            matchedFillResults.right.makerAssetFilledAmount = leftTakerAssetAmountRemaining;
            // Round up to ensure the maker's exchange rate does not exceed the price specified by the order.
            // We favor the maker when the exchange rate must be rounded.
            matchedFillResults.right.takerAssetFilledAmount = LibMath.safeGetPartialAmountCeil(
                rightOrder.takerAssetAmount,
                rightOrder.makerAssetAmount,
                leftTakerAssetAmountRemaining // matchedFillResults.right.makerAssetFilledAmount
            );
        } else {
            // leftTakerAssetAmountRemaining == rightMakerAssetAmountRemaining
            // Case 3: Both orders are fully filled. Technically, this could be captured by the above cases, but
            //         this calculation will be more precise since it does not include rounding.
            matchedFillResults = _calculateCompleteFillBoth(
                leftMakerAssetAmountRemaining,
                leftTakerAssetAmountRemaining,
                rightMakerAssetAmountRemaining,
                rightTakerAssetAmountRemaining
            );
        }

        // Calculate amount given to taker
        matchedFillResults.profitInLeftMakerAsset = matchedFillResults.left.makerAssetFilledAmount.safeSub(
            matchedFillResults.right.takerAssetFilledAmount
        );

        return matchedFillResults;
    }

    /// @dev Calculates part of the matched fill results for a given situation using the maximal fill order matching
    ///      strategy.
    /// @param leftOrder The left order in the order matching situation.
    /// @param rightOrder The right order in the order matching situation.
    /// @param leftMakerAssetAmountRemaining The amount of the left order maker asset that can still be filled.
    /// @param leftTakerAssetAmountRemaining The amount of the left order taker asset that can still be filled.
    /// @param rightMakerAssetAmountRemaining The amount of the right order maker asset that can still be filled.
    /// @param rightTakerAssetAmountRemaining The amount of the right order taker asset that can still be filled.
    /// @return MatchFillResults struct that does not include fees paid.
    function _calculateMatchedFillResultsWithMaximalFill(
        LibOrder.Order memory leftOrder,
        LibOrder.Order memory rightOrder,
        uint256 leftMakerAssetAmountRemaining,
        uint256 leftTakerAssetAmountRemaining,
        uint256 rightMakerAssetAmountRemaining,
        uint256 rightTakerAssetAmountRemaining
    )
        private
        pure
        returns (MatchedFillResults memory matchedFillResults)
    {
        // If a maker asset is greater than the opposite taker asset, than there will be a spread denominated in that maker asset.
        bool doesLeftMakerAssetProfitExist = leftMakerAssetAmountRemaining > rightTakerAssetAmountRemaining;
        bool doesRightMakerAssetProfitExist = rightMakerAssetAmountRemaining > leftTakerAssetAmountRemaining;

        // Calculate the maximum fill results for the maker and taker assets. At least one of the orders will be fully filled.
        //
        // The maximum that the left maker can possibly buy is the amount that the right order can sell.
        // The maximum that the right maker can possibly buy is the amount that the left order can sell.
        //
        // If the left order is fully filled, profit will be paid out in the left maker asset. If the right order is fully filled,
        // the profit will be out in the right maker asset.
        //
        // There are three cases to consider:
        // Case 1.
        //   If the left maker can buy more than the right maker can sell, then only the right order is fully filled.
        // Case 2.
        //   If the right maker can buy more than the left maker can sell, then only the right order is fully filled.
        // Case 3.
        //   If the right maker can sell the max of what the left maker can buy and the left maker can sell the max of
        //   what the right maker can buy, then both orders are fully filled.
        if (leftTakerAssetAmountRemaining > rightMakerAssetAmountRemaining) {
            // Case 1: Right order is fully filled with the profit paid in the left makerAsset
            matchedFillResults = _calculateCompleteRightFill(
                leftOrder,
                rightMakerAssetAmountRemaining,
                rightTakerAssetAmountRemaining
            );
        } else if (rightTakerAssetAmountRemaining > leftMakerAssetAmountRemaining) {
            // Case 2: Left order is fully filled with the profit paid in the right makerAsset.
            matchedFillResults.left.makerAssetFilledAmount = leftMakerAssetAmountRemaining;
            matchedFillResults.left.takerAssetFilledAmount = leftTakerAssetAmountRemaining;
            // Round down to ensure the right maker's exchange rate does not exceed the price specified by the order.
            // We favor the right maker when the exchange rate must be rounded and the profit is being paid in the
            // right maker asset.
            matchedFillResults.right.makerAssetFilledAmount = LibMath.safeGetPartialAmountFloor(
                rightOrder.makerAssetAmount,
                rightOrder.takerAssetAmount,
                leftMakerAssetAmountRemaining
            );
            matchedFillResults.right.takerAssetFilledAmount = leftMakerAssetAmountRemaining;
        } else {
            // Case 3: The right and left orders are fully filled
            matchedFillResults = _calculateCompleteFillBoth(
                leftMakerAssetAmountRemaining,
                leftTakerAssetAmountRemaining,
                rightMakerAssetAmountRemaining,
                rightTakerAssetAmountRemaining
            );
        }

        // Calculate amount given to taker in the left order's maker asset if the left spread will be part of the profit.
        if (doesLeftMakerAssetProfitExist) {
            matchedFillResults.profitInLeftMakerAsset = matchedFillResults.left.makerAssetFilledAmount.safeSub(
                matchedFillResults.right.takerAssetFilledAmount
            );
        }

        // Calculate amount given to taker in the right order's maker asset if the right spread will be part of the profit.
        if (doesRightMakerAssetProfitExist) {
            matchedFillResults.profitInRightMakerAsset = matchedFillResults.right.makerAssetFilledAmount.safeSub(
                matchedFillResults.left.takerAssetFilledAmount
            );
        }

        return matchedFillResults;
    }

    /// @dev Calculates the fill results for the maker and taker in the order matching and writes the results
    ///      to the fillResults that are being collected on the order. Both orders will be fully filled in this
    ///      case.
    /// @param leftMakerAssetAmountRemaining The amount of the left maker asset that is remaining to be filled.
    /// @param leftTakerAssetAmountRemaining The amount of the left taker asset that is remaining to be filled.
    /// @param rightMakerAssetAmountRemaining The amount of the right maker asset that is remaining to be filled.
    /// @param rightTakerAssetAmountRemaining The amount of the right taker asset that is remaining to be filled.
    /// @return MatchFillResults struct that does not include fees paid or spreads taken.
    function _calculateCompleteFillBoth(
        uint256 leftMakerAssetAmountRemaining,
        uint256 leftTakerAssetAmountRemaining,
        uint256 rightMakerAssetAmountRemaining,
        uint256 rightTakerAssetAmountRemaining
    )
        private
        pure
        returns (MatchedFillResults memory matchedFillResults)
    {
        // Calculate the fully filled results for both orders.
        matchedFillResults.left.makerAssetFilledAmount = leftMakerAssetAmountRemaining;
        matchedFillResults.left.takerAssetFilledAmount = leftTakerAssetAmountRemaining;
        matchedFillResults.right.makerAssetFilledAmount = rightMakerAssetAmountRemaining;
        matchedFillResults.right.takerAssetFilledAmount = rightTakerAssetAmountRemaining;

        return matchedFillResults;
    }

    /// @dev Calculates the fill results for the maker and taker in the order matching and writes the results
    ///      to the fillResults that are being collected on the order.
    /// @param leftOrder The left order that is being maximally filled. All of the information about fill amounts
    ///                  can be derived from this order and the right asset remaining fields.
    /// @param rightMakerAssetAmountRemaining The amount of the right maker asset that is remaining to be filled.
    /// @param rightTakerAssetAmountRemaining The amount of the right taker asset that is remaining to be filled.
    /// @return MatchFillResults struct that does not include fees paid or spreads taken.
    function _calculateCompleteRightFill(
        LibOrder.Order memory leftOrder,
        uint256 rightMakerAssetAmountRemaining,
        uint256 rightTakerAssetAmountRemaining
    )
        private
        pure
        returns (MatchedFillResults memory matchedFillResults)
    {
        matchedFillResults.right.makerAssetFilledAmount = rightMakerAssetAmountRemaining;
        matchedFillResults.right.takerAssetFilledAmount = rightTakerAssetAmountRemaining;
        matchedFillResults.left.takerAssetFilledAmount = rightMakerAssetAmountRemaining;
        // Round down to ensure the left maker's exchange rate does not exceed the price specified by the order.
        // We favor the left maker when the exchange rate must be rounded and the profit is being paid in the
        // left maker asset.
        matchedFillResults.left.makerAssetFilledAmount = LibMath.safeGetPartialAmountFloor(
            leftOrder.makerAssetAmount,
            leftOrder.takerAssetAmount,
            rightMakerAssetAmountRemaining
        );

        return matchedFillResults;
    }
}

contract IExchangeCore {

    // Fill event is emitted whenever an order is filled.
    event Fill(
        address indexed makerAddress,         // Address that created the order.
        address indexed feeRecipientAddress,  // Address that received fees.
        bytes makerAssetData,                 // Encoded data specific to makerAsset.
        bytes takerAssetData,                 // Encoded data specific to takerAsset.
        bytes makerFeeAssetData,              // Encoded data specific to makerFeeAsset.
        bytes takerFeeAssetData,              // Encoded data specific to takerFeeAsset.
        bytes32 indexed orderHash,            // EIP712 hash of order (see LibOrder.getTypedDataHash).
        address takerAddress,                 // Address that filled the order.
        address senderAddress,                // Address that called the Exchange contract (msg.sender).
        uint256 makerAssetFilledAmount,       // Amount of makerAsset sold by maker and bought by taker.
        uint256 takerAssetFilledAmount,       // Amount of takerAsset sold by taker and bought by maker.
        uint256 makerFeePaid,                 // Amount of makerFeeAssetData paid to feeRecipient by maker.
        uint256 takerFeePaid,                 // Amount of takerFeeAssetData paid to feeRecipient by taker.
        uint256 protocolFeePaid               // Amount of eth or weth paid to the staking contract.
    );

    // Cancel event is emitted whenever an individual order is cancelled.
    event Cancel(
        address indexed makerAddress,         // Address that created the order.
        address indexed feeRecipientAddress,  // Address that would have recieved fees if order was filled.
        bytes makerAssetData,                 // Encoded data specific to makerAsset.
        bytes takerAssetData,                 // Encoded data specific to takerAsset.
        address senderAddress,                // Address that called the Exchange contract (msg.sender).
        bytes32 indexed orderHash             // EIP712 hash of order (see LibOrder.getTypedDataHash).
    );

    // CancelUpTo event is emitted whenever `cancelOrdersUpTo` is executed succesfully.
    event CancelUpTo(
        address indexed makerAddress,         // Orders cancelled must have been created by this address.
        address indexed orderSenderAddress,   // Orders cancelled must have a `senderAddress` equal to this address.
        uint256 orderEpoch                    // Orders with specified makerAddress and senderAddress with a salt less than this value are considered cancelled.
    );

    /// @dev Cancels all orders created by makerAddress with a salt less than or equal to the targetOrderEpoch
    ///      and senderAddress equal to msg.sender (or null address if msg.sender == makerAddress).
    /// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled.
    function cancelOrdersUpTo(uint256 targetOrderEpoch)
        external
        payable;

    /// @dev Fills the input order.
    /// @param order Order struct containing order specifications.
    /// @param takerAssetFillAmount Desired amount of takerAsset to sell.
    /// @param signature Proof that order has been created by maker.
    /// @return Amounts filled and fees paid by maker and taker.
    function fillOrder(
        LibOrder.Order memory order,
        uint256 takerAssetFillAmount,
        bytes memory signature
    )
        public
        payable
        returns (LibFillResults.FillResults memory fillResults);

    /// @dev After calling, the order can not be filled anymore.
    /// @param order Order struct containing order specifications.
    function cancelOrder(LibOrder.Order memory order)
        public
        payable;

    /// @dev Gets information about an order: status, hash, and amount filled.
    /// @param order Order to gather information on.
    /// @return OrderInfo Information about the order and its state.
    ///                   See LibOrder.OrderInfo for a complete description.
    function getOrderInfo(LibOrder.Order memory order)
        public
        view
        returns (LibOrder.OrderInfo memory orderInfo);
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IProtocolFees {

    // Logs updates to the protocol fee multiplier.
    event ProtocolFeeMultiplier(uint256 oldProtocolFeeMultiplier, uint256 updatedProtocolFeeMultiplier);

    // Logs updates to the protocolFeeCollector address.
    event ProtocolFeeCollectorAddress(address oldProtocolFeeCollector, address updatedProtocolFeeCollector);

    /// @dev Allows the owner to update the protocol fee multiplier.
    /// @param updatedProtocolFeeMultiplier The updated protocol fee multiplier.
    function setProtocolFeeMultiplier(uint256 updatedProtocolFeeMultiplier)
        external;

    /// @dev Allows the owner to update the protocolFeeCollector address.
    /// @param updatedProtocolFeeCollector The updated protocolFeeCollector contract address.
    function setProtocolFeeCollectorAddress(address updatedProtocolFeeCollector)
        external;

    /// @dev Returns the protocolFeeMultiplier
    function protocolFeeMultiplier()
        external
        view
        returns (uint256);

    /// @dev Returns the protocolFeeCollector address
    function protocolFeeCollector()
        external
        view
        returns (address);
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IMatchOrders {

    /// @dev Match complementary orders that have a profitable spread.
    ///      Each order is filled at their respective price point, and
    ///      the matcher receives a profit denominated in the left maker asset.
    /// @param leftOrders Set of orders with the same maker / taker asset.
    /// @param rightOrders Set of orders to match against `leftOrders`
    /// @param leftSignatures Proof that left orders were created by the left makers.
    /// @param rightSignatures Proof that right orders were created by the right makers.
    /// @return batchMatchedFillResults Amounts filled and profit generated.
    function batchMatchOrders(
        LibOrder.Order[] memory leftOrders,
        LibOrder.Order[] memory rightOrders,
        bytes[] memory leftSignatures,
        bytes[] memory rightSignatures
    )
        public
        payable
        returns (LibFillResults.BatchMatchedFillResults memory batchMatchedFillResults);

    /// @dev Match complementary orders that have a profitable spread.
    ///      Each order is maximally filled at their respective price point, and
    ///      the matcher receives a profit denominated in either the left maker asset,
    ///      right maker asset, or a combination of both.
    /// @param leftOrders Set of orders with the same maker / taker asset.
    /// @param rightOrders Set of orders to match against `leftOrders`
    /// @param leftSignatures Proof that left orders were created by the left makers.
    /// @param rightSignatures Proof that right orders were created by the right makers.
    /// @return batchMatchedFillResults Amounts filled and profit generated.
    function batchMatchOrdersWithMaximalFill(
        LibOrder.Order[] memory leftOrders,
        LibOrder.Order[] memory rightOrders,
        bytes[] memory leftSignatures,
        bytes[] memory rightSignatures
    )
        public
        payable
        returns (LibFillResults.BatchMatchedFillResults memory batchMatchedFillResults);

    /// @dev Match two complementary orders that have a profitable spread.
    ///      Each order is filled at their respective price point. However, the calculations are
    ///      carried out as though the orders are both being filled at the right order's price point.
    ///      The profit made by the left order goes to the taker (who matched the two orders).
    /// @param leftOrder First order to match.
    /// @param rightOrder Second order to match.
    /// @param leftSignature Proof that order was created by the left maker.
    /// @param rightSignature Proof that order was created by the right maker.
    /// @return matchedFillResults Amounts filled and fees paid by maker and taker of matched orders.
    function matchOrders(
        LibOrder.Order memory leftOrder,
        LibOrder.Order memory rightOrder,
        bytes memory leftSignature,
        bytes memory rightSignature
    )
        public
        payable
        returns (LibFillResults.MatchedFillResults memory matchedFillResults);

    /// @dev Match two complementary orders that have a profitable spread.
    ///      Each order is maximally filled at their respective price point, and
    ///      the matcher receives a profit denominated in either the left maker asset,
    ///      right maker asset, or a combination of both.
    /// @param leftOrder First order to match.
    /// @param rightOrder Second order to match.
    /// @param leftSignature Proof that order was created by the left maker.
    /// @param rightSignature Proof that order was created by the right maker.
    /// @return matchedFillResults Amounts filled by maker and taker of matched orders.
    function matchOrdersWithMaximalFill(
        LibOrder.Order memory leftOrder,
        LibOrder.Order memory rightOrder,
        bytes memory leftSignature,
        bytes memory rightSignature
    )
        public
        payable
        returns (LibFillResults.MatchedFillResults memory matchedFillResults);
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

library LibZeroExTransaction {

    using LibZeroExTransaction for ZeroExTransaction;

    // Hash for the EIP712 0x transaction schema
    // keccak256(abi.encodePacked(
    //    "ZeroExTransaction(",
    //    "uint256 salt,",
    //    "uint256 expirationTimeSeconds,",
    //    "uint256 gasPrice,",
    //    "address signerAddress,",
    //    "bytes data",
    //    ")"
    // ));
    bytes32 constant internal _EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH = 0xec69816980a3a3ca4554410e60253953e9ff375ba4536a98adfa15cc71541508;

    struct ZeroExTransaction {
        uint256 salt;                   // Arbitrary number to ensure uniqueness of transaction hash.
        uint256 expirationTimeSeconds;  // Timestamp in seconds at which transaction expires.
        uint256 gasPrice;               // gasPrice that transaction is required to be executed with.
        address signerAddress;          // Address of transaction signer.
        bytes data;                     // AbiV2 encoded calldata.
    }

    /// @dev Calculates the EIP712 typed data hash of a transaction with a given domain separator.
    /// @param transaction 0x transaction structure.
    /// @return EIP712 typed data hash of the transaction.
    function getTypedDataHash(ZeroExTransaction memory transaction, bytes32 eip712ExchangeDomainHash)
        internal
        pure
        returns (bytes32 transactionHash)
    {
        // Hash the transaction with the domain separator of the Exchange contract.
        transactionHash = LibEIP712.hashEIP712Message(
            eip712ExchangeDomainHash,
            transaction.getStructHash()
        );
        return transactionHash;
    }

    /// @dev Calculates EIP712 hash of the 0x transaction struct.
    /// @param transaction 0x transaction structure.
    /// @return EIP712 hash of the transaction struct.
    function getStructHash(ZeroExTransaction memory transaction)
        internal
        pure
        returns (bytes32 result)
    {
        bytes32 schemaHash = _EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH;
        bytes memory data = transaction.data;
        uint256 salt = transaction.salt;
        uint256 expirationTimeSeconds = transaction.expirationTimeSeconds;
        uint256 gasPrice = transaction.gasPrice;
        address signerAddress = transaction.signerAddress;

        // Assembly for more efficiently computing:
        // result = keccak256(abi.encodePacked(
        //     schemaHash,
        //     salt,
        //     expirationTimeSeconds,
        //     gasPrice,
        //     uint256(signerAddress),
        //     keccak256(data)
        // ));

        assembly {
            // Compute hash of data
            let dataHash := keccak256(add(data, 32), mload(data))

            // Load free memory pointer
            let memPtr := mload(64)

            mstore(memPtr, schemaHash)                                                                // hash of schema
            mstore(add(memPtr, 32), salt)                                                             // salt
            mstore(add(memPtr, 64), expirationTimeSeconds)                                            // expirationTimeSeconds
            mstore(add(memPtr, 96), gasPrice)                                                         // gasPrice
            mstore(add(memPtr, 128), and(signerAddress, 0xffffffffffffffffffffffffffffffffffffffff))  // signerAddress
            mstore(add(memPtr, 160), dataHash)                                                        // hash of data

            // Compute hash
            result := keccak256(memPtr, 192)
        }
        return result;
    }
}

contract ISignatureValidator {

   // Allowed signature types.
    enum SignatureType {
        Illegal,                     // 0x00, default value
        Invalid,                     // 0x01
        EIP712,                      // 0x02
        EthSign,                     // 0x03
        Wallet,                      // 0x04
        Validator,                   // 0x05
        PreSigned,                   // 0x06
        EIP1271Wallet,               // 0x07
        NSignatureTypes              // 0x08, number of signature types. Always leave at end.
    }

    event SignatureValidatorApproval(
        address indexed signerAddress,     // Address that approves or disapproves a contract to verify signatures.
        address indexed validatorAddress,  // Address of signature validator contract.
        bool isApproved                    // Approval or disapproval of validator contract.
    );

    /// @dev Approves a hash on-chain.
    ///      After presigning a hash, the preSign signature type will become valid for that hash and signer.
    /// @param hash Any 32-byte hash.
    function preSign(bytes32 hash)
        external
        payable;

    /// @dev Approves/unnapproves a Validator contract to verify signatures on signer's behalf.
    /// @param validatorAddress Address of Validator contract.
    /// @param approval Approval or disapproval of  Validator contract.
    function setSignatureValidatorApproval(
        address validatorAddress,
        bool approval
    )
        external
        payable;

    /// @dev Verifies that a hash has been signed by the given signer.
    /// @param hash Any 32-byte hash.
    /// @param signature Proof that the hash has been signed by signer.
    /// @return isValid `true` if the signature is valid for the given hash and signer.
    function isValidHashSignature(
        bytes32 hash,
        address signerAddress,
        bytes memory signature
    )
        public
        view
        returns (bool isValid);

    /// @dev Verifies that a signature for an order is valid.
    /// @param order The order.
    /// @param signature Proof that the order has been signed by signer.
    /// @return isValid true if the signature is valid for the given order and signer.
    function isValidOrderSignature(
        LibOrder.Order memory order,
        bytes memory signature
    )
        public
        view
        returns (bool isValid);

    /// @dev Verifies that a signature for a transaction is valid.
    /// @param transaction The transaction.
    /// @param signature Proof that the order has been signed by signer.
    /// @return isValid true if the signature is valid for the given transaction and signer.
    function isValidTransactionSignature(
        LibZeroExTransaction.ZeroExTransaction memory transaction,
        bytes memory signature
    )
        public
        view
        returns (bool isValid);

    /// @dev Verifies that an order, with provided order hash, has been signed
    ///      by the given signer.
    /// @param order The order.
    /// @param orderHash The hash of the order.
    /// @param signature Proof that the hash has been signed by signer.
    /// @return isValid True if the signature is valid for the given order and signer.
    function _isValidOrderWithHashSignature(
        LibOrder.Order memory order,
        bytes32 orderHash,
        bytes memory signature
    )
        internal
        view
        returns (bool isValid);

    /// @dev Verifies that a transaction, with provided order hash, has been signed
    ///      by the given signer.
    /// @param transaction The transaction.
    /// @param transactionHash The hash of the transaction.
    /// @param signature Proof that the hash has been signed by signer.
    /// @return isValid True if the signature is valid for the given transaction and signer.
    function _isValidTransactionWithHashSignature(
        LibZeroExTransaction.ZeroExTransaction memory transaction,
        bytes32 transactionHash,
        bytes memory signature
    )
        internal
        view
        returns (bool isValid);
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract ITransactions {

    // TransactionExecution event is emitted when a ZeroExTransaction is executed.
    event TransactionExecution(bytes32 indexed transactionHash);

    /// @dev Executes an Exchange method call in the context of signer.
    /// @param transaction 0x transaction containing salt, signerAddress, and data.
    /// @param signature Proof that transaction has been signed by signer.
    /// @return ABI encoded return data of the underlying Exchange function call.
    function executeTransaction(
        LibZeroExTransaction.ZeroExTransaction memory transaction,
        bytes memory signature
    )
        public
        payable
        returns (bytes memory);

    /// @dev Executes a batch of Exchange method calls in the context of signer(s).
    /// @param transactions Array of 0x transactions containing salt, signerAddress, and data.
    /// @param signatures Array of proofs that transactions have been signed by signer(s).
    /// @return Array containing ABI encoded return data for each of the underlying Exchange function calls.
    function batchExecuteTransactions(
        LibZeroExTransaction.ZeroExTransaction[] memory transactions,
        bytes[] memory signatures
    )
        public
        payable
        returns (bytes[] memory);

    /// @dev The current function will be called in the context of this address (either 0x transaction signer or `msg.sender`).
    ///      If calling a fill function, this address will represent the taker.
    ///      If calling a cancel function, this address will represent the maker.
    /// @return Signer of 0x transaction if entry point is `executeTransaction`.
    ///         `msg.sender` if entry point is any other function.
    function _getCurrentContextAddress()
        internal
        view
        returns (address);
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IAssetProxyDispatcher {

    // Logs registration of new asset proxy
    event AssetProxyRegistered(
        bytes4 id,              // Id of new registered AssetProxy.
        address assetProxy      // Address of new registered AssetProxy.
    );

    /// @dev Registers an asset proxy to its asset proxy id.
    ///      Once an asset proxy is registered, it cannot be unregistered.
    /// @param assetProxy Address of new asset proxy to register.
    function registerAssetProxy(address assetProxy)
        external;

    /// @dev Gets an asset proxy.
    /// @param assetProxyId Id of the asset proxy.
    /// @return The asset proxy registered to assetProxyId. Returns 0x0 if no proxy is registered.
    function getAssetProxy(bytes4 assetProxyId)
        external
        view
        returns (address);
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IWrapperFunctions {

    /// @dev Fills the input order. Reverts if exact takerAssetFillAmount not filled.
    /// @param order Order struct containing order specifications.
    /// @param takerAssetFillAmount Desired amount of takerAsset to sell.
    /// @param signature Proof that order has been created by maker.
    function fillOrKillOrder(
        LibOrder.Order memory order,
        uint256 takerAssetFillAmount,
        bytes memory signature
    )
        public
        payable
        returns (LibFillResults.FillResults memory fillResults);

    /// @dev Executes multiple calls of fillOrder.
    /// @param orders Array of order specifications.
    /// @param takerAssetFillAmounts Array of desired amounts of takerAsset to sell in orders.
    /// @param signatures Proofs that orders have been created by makers.
    /// @return Array of amounts filled and fees paid by makers and taker.
    function batchFillOrders(
        LibOrder.Order[] memory orders,
        uint256[] memory takerAssetFillAmounts,
        bytes[] memory signatures
    )
        public
        payable
        returns (LibFillResults.FillResults[] memory fillResults);

    /// @dev Executes multiple calls of fillOrKillOrder.
    /// @param orders Array of order specifications.
    /// @param takerAssetFillAmounts Array of desired amounts of takerAsset to sell in orders.
    /// @param signatures Proofs that orders have been created by makers.
    /// @return Array of amounts filled and fees paid by makers and taker.
    function batchFillOrKillOrders(
        LibOrder.Order[] memory orders,
        uint256[] memory takerAssetFillAmounts,
        bytes[] memory signatures
    )
        public
        payable
        returns (LibFillResults.FillResults[] memory fillResults);

    /// @dev Executes multiple calls of fillOrder. If any fill reverts, the error is caught and ignored.
    /// @param orders Array of order specifications.
    /// @param takerAssetFillAmounts Array of desired amounts of takerAsset to sell in orders.
    /// @param signatures Proofs that orders have been created by makers.
    /// @return Array of amounts filled and fees paid by makers and taker.
    function batchFillOrdersNoThrow(
        LibOrder.Order[] memory orders,
        uint256[] memory takerAssetFillAmounts,
        bytes[] memory signatures
    )
        public
        payable
        returns (LibFillResults.FillResults[] memory fillResults);

    /// @dev Executes multiple calls of fillOrder until total amount of takerAsset is sold by taker.
    ///      If any fill reverts, the error is caught and ignored.
    ///      NOTE: This function does not enforce that the takerAsset is the same for each order.
    /// @param orders Array of order specifications.
    /// @param takerAssetFillAmount Desired amount of takerAsset to sell.
    /// @param signatures Proofs that orders have been signed by makers.
    /// @return Amounts filled and fees paid by makers and taker.
    function marketSellOrdersNoThrow(
        LibOrder.Order[] memory orders,
        uint256 takerAssetFillAmount,
        bytes[] memory signatures
    )
        public
        payable
        returns (LibFillResults.FillResults memory fillResults);

    /// @dev Executes multiple calls of fillOrder until total amount of makerAsset is bought by taker.
    ///      If any fill reverts, the error is caught and ignored.
    ///      NOTE: This function does not enforce that the makerAsset is the same for each order.
    /// @param orders Array of order specifications.
    /// @param makerAssetFillAmount Desired amount of makerAsset to buy.
    /// @param signatures Proofs that orders have been signed by makers.
    /// @return Amounts filled and fees paid by makers and taker.
    function marketBuyOrdersNoThrow(
        LibOrder.Order[] memory orders,
        uint256 makerAssetFillAmount,
        bytes[] memory signatures
    )
        public
        payable
        returns (LibFillResults.FillResults memory fillResults);

    /// @dev Calls marketSellOrdersNoThrow then reverts if < takerAssetFillAmount has been sold.
    ///      NOTE: This function does not enforce that the takerAsset is the same for each order.
    /// @param orders Array of order specifications.
    /// @param takerAssetFillAmount Minimum amount of takerAsset to sell.
    /// @param signatures Proofs that orders have been signed by makers.
    /// @return Amounts filled and fees paid by makers and taker.
    function marketSellOrdersFillOrKill(
        LibOrder.Order[] memory orders,
        uint256 takerAssetFillAmount,
        bytes[] memory signatures
    )
        public
        payable
        returns (LibFillResults.FillResults memory fillResults);

    /// @dev Calls marketBuyOrdersNoThrow then reverts if < makerAssetFillAmount has been bought.
    ///      NOTE: This function does not enforce that the makerAsset is the same for each order.
    /// @param orders Array of order specifications.
    /// @param makerAssetFillAmount Minimum amount of makerAsset to buy.
    /// @param signatures Proofs that orders have been signed by makers.
    /// @return Amounts filled and fees paid by makers and taker.
    function marketBuyOrdersFillOrKill(
        LibOrder.Order[] memory orders,
        uint256 makerAssetFillAmount,
        bytes[] memory signatures
    )
        public
        payable
        returns (LibFillResults.FillResults memory fillResults);

    /// @dev Executes multiple calls of cancelOrder.
    /// @param orders Array of order specifications.
    function batchCancelOrders(LibOrder.Order[] memory orders)
        public
        payable;
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract ITransferSimulator {

    /// @dev This function may be used to simulate any amount of transfers
    /// As they would occur through the Exchange contract. Note that this function
    /// will always revert, even if all transfers are successful. However, it may
    /// be used with eth_call or with a try/catch pattern in order to simulate
    /// the results of the transfers.
    /// @param assetData Array of asset details, each encoded per the AssetProxy contract specification.
    /// @param fromAddresses Array containing the `from` addresses that correspond with each transfer.
    /// @param toAddresses Array containing the `to` addresses that correspond with each transfer.
    /// @param amounts Array containing the amounts that correspond to each transfer.
    /// @return This function does not return a value. However, it will always revert with
    /// `Error("TRANSFERS_SUCCESSFUL")` if all of the transfers were successful.
    function simulateDispatchTransferFromCalls(
        bytes[] memory assetData,
        address[] memory fromAddresses,
        address[] memory toAddresses,
        uint256[] memory amounts
    )
        public;
}

// solhint-disable no-empty-blocks
contract IExchange is
    IProtocolFees,
    IExchangeCore,
    IMatchOrders,
    ISignatureValidator,
    ITransactions,
    IAssetProxyDispatcher,
    ITransferSimulator,
    IWrapperFunctions
{}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

library LibWethUtilsRichErrors {

    // bytes4(keccak256("UnregisteredAssetProxyError()"))
    bytes4 internal constant UNREGISTERED_ASSET_PROXY_ERROR_SELECTOR =
        0xf3b96b8d;

    // bytes4(keccak256("InsufficientEthForFeeError(uint256,uint256)"))
    bytes4 internal constant INSUFFICIENT_ETH_FOR_FEE_ERROR_SELECTOR =
        0xecf40fd9;

    // bytes4(keccak256("DefaultFunctionWethContractOnlyError(address)"))
    bytes4 internal constant DEFAULT_FUNCTION_WETH_CONTRACT_ONLY_ERROR_SELECTOR =
        0x08b18698;

    // bytes4(keccak256("EthFeeLengthMismatchError(uint256,uint256)"))
    bytes4 internal constant ETH_FEE_LENGTH_MISMATCH_ERROR_SELECTOR =
        0x3ecb6ceb;

    // solhint-disable func-name-mixedcase
    function UnregisteredAssetProxyError()
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(UNREGISTERED_ASSET_PROXY_ERROR_SELECTOR);
    }

    function InsufficientEthForFeeError(
        uint256 ethFeeRequired,
        uint256 ethAvailable
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            INSUFFICIENT_ETH_FOR_FEE_ERROR_SELECTOR,
            ethFeeRequired,
            ethAvailable
        );
    }

    function DefaultFunctionWethContractOnlyError(
        address senderAddress
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            DEFAULT_FUNCTION_WETH_CONTRACT_ONLY_ERROR_SELECTOR,
            senderAddress
        );
    }

    function EthFeeLengthMismatchError(
        uint256 ethFeesLength,
        uint256 feeRecipientsLength
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            ETH_FEE_LENGTH_MISMATCH_ERROR_SELECTOR,
            ethFeesLength,
            feeRecipientsLength
        );
    }
}

contract MixinWethUtils {

    uint256 constant internal MAX_UINT256 = uint256(-1);

     // solhint-disable var-name-mixedcase
    IEtherToken internal WETH;
    bytes internal WETH_ASSET_DATA;
    // solhint-enable var-name-mixedcase

    using LibSafeMath for uint256;

    constructor (
        address exchange,
        address weth
    )
        public
    {
        WETH = IEtherToken(weth);
        WETH_ASSET_DATA = abi.encodeWithSelector(
            IAssetData(address(0)).ERC20Token.selector,
            weth
        );

        address proxyAddress = IExchange(exchange).getAssetProxy(IAssetData(address(0)).ERC20Token.selector);
        if (proxyAddress == address(0)) {
            LibRichErrors.rrevert(LibWethUtilsRichErrors.UnregisteredAssetProxyError());
        }
        WETH.approve(proxyAddress, MAX_UINT256);

        address protocolFeeCollector = IExchange(exchange).protocolFeeCollector();
        if (protocolFeeCollector != address(0)) {
            WETH.approve(protocolFeeCollector, MAX_UINT256);
        }
    }

    /// @dev Default payable function, this allows us to withdraw WETH
    function ()
        external
        payable
    {
        if (msg.sender != address(WETH)) {
            LibRichErrors.rrevert(LibWethUtilsRichErrors.DefaultFunctionWethContractOnlyError(
                msg.sender
            ));
        }
    }

    /// @dev Transfers ETH denominated fees to all feeRecipient addresses
    /// @param ethFeeAmounts Amounts of ETH, denominated in Wei, that are paid to corresponding feeRecipients.
    /// @param feeRecipients Addresses that will receive ETH when orders are filled.
    /// @return ethRemaining msg.value minus the amount of ETH spent on affiliate fees.
    function _transferEthFeesAndWrapRemaining(
        uint256[] memory ethFeeAmounts,
        address payable[] memory feeRecipients
    )
        internal
        returns (uint256 ethRemaining)
    {
        uint256 feesLen = ethFeeAmounts.length;
        // ethFeeAmounts len must equal feeRecipients len
        if (feesLen != feeRecipients.length) {
            LibRichErrors.rrevert(LibWethUtilsRichErrors.EthFeeLengthMismatchError(
                feesLen,
                feeRecipients.length
            ));
        }

        // This function is always called before any other function, so we assume that
        // the ETH remaining is the entire msg.value.
        ethRemaining = msg.value;

        for (uint256 i = 0; i != feesLen; i++) {
            uint256 ethFeeAmount = ethFeeAmounts[i];
            // Ensure there is enough ETH to pay the fee
            if (ethRemaining < ethFeeAmount) {
                LibRichErrors.rrevert(LibWethUtilsRichErrors.InsufficientEthForFeeError(
                    ethFeeAmount,
                    ethRemaining
                ));
            }
            // Decrease ethRemaining and transfer fee to corresponding feeRecipient
            ethRemaining = ethRemaining.safeSub(ethFeeAmount);
            feeRecipients[i].transfer(ethFeeAmount);
        }

        // Convert remaining ETH to WETH.
        WETH.deposit.value(ethRemaining)();

        return ethRemaining;
    }

    /// @dev Unwraps WETH and transfers ETH to msg.sender.
    /// @param transferAmount Amount of WETH balance to unwrap and transfer.
    function _unwrapAndTransferEth(
        uint256 transferAmount
    )
        internal
    {
        // Do nothing if amount is zero
        if (transferAmount > 0) {
            // Convert WETH to ETH
            WETH.withdraw(transferAmount);
            // Transfer ETH to sender
            msg.sender.transfer(transferAmount);
        }
    }
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IOwnable {

    /// @dev Emitted by Ownable when ownership is transferred.
    /// @param previousOwner The previous owner of the contract.
    /// @param newOwner The new owner of the contract.
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /// @dev Transfers ownership of the contract to a new address.
    /// @param newOwner The address that will become the owner.
    function transferOwnership(address newOwner)
        public;
}

library LibOwnableRichErrors {

    // bytes4(keccak256("OnlyOwnerError(address,address)"))
    bytes4 internal constant ONLY_OWNER_ERROR_SELECTOR =
        0x1de45ad1;

    // bytes4(keccak256("TransferOwnerToZeroError()"))
    bytes internal constant TRANSFER_OWNER_TO_ZERO_ERROR_BYTES =
        hex"e69edc3e";

    // solhint-disable func-name-mixedcase
    function OnlyOwnerError(
        address sender,
        address owner
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            ONLY_OWNER_ERROR_SELECTOR,
            sender,
            owner
        );
    }

    function TransferOwnerToZeroError()
        internal
        pure
        returns (bytes memory)
    {
        return TRANSFER_OWNER_TO_ZERO_ERROR_BYTES;
    }
}

contract Ownable is
    IOwnable
{
    /// @dev The owner of this contract.
    /// @return 0 The owner address.
    address public owner;

    constructor ()
        public
    {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        _assertSenderIsOwner();
        _;
    }

    /// @dev Change the owner of this contract.
    /// @param newOwner New owner address.
    function transferOwnership(address newOwner)
        public
        onlyOwner
    {
        if (newOwner == address(0)) {
            LibRichErrors.rrevert(LibOwnableRichErrors.TransferOwnerToZeroError());
        } else {
            owner = newOwner;
            emit OwnershipTransferred(msg.sender, newOwner);
        }
    }

    function _assertSenderIsOwner()
        internal
        view
    {
        if (msg.sender != owner) {
            LibRichErrors.rrevert(LibOwnableRichErrors.OnlyOwnerError(
                msg.sender,
                owner
            ));
        }
    }
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

library LibForwarderRichErrors {

    // bytes4(keccak256("UnregisteredAssetProxyError()"))
    bytes4 internal constant UNREGISTERED_ASSET_PROXY_ERROR_SELECTOR =
        0xf3b96b8d;

    // bytes4(keccak256("CompleteBuyFailedError(uint256,uint256)"))
    bytes4 internal constant COMPLETE_BUY_FAILED_ERROR_SELECTOR =
        0x91353a0c;

    // bytes4(keccak256("CompleteSellFailedError(uint256,uint256)"))
    bytes4 internal constant COMPLETE_SELL_FAILED_ERROR_SELECTOR =
        0x450a0219;

    // bytes4(keccak256("UnsupportedFeeError(bytes)"))
    bytes4 internal constant UNSUPPORTED_FEE_ERROR_SELECTOR =
        0x31360af1;

    // bytes4(keccak256("OverspentWethError(uint256,uint256)"))
    bytes4 internal constant OVERSPENT_WETH_ERROR_SELECTOR =
        0xcdcbed5d;

    // solhint-disable func-name-mixedcase
    function UnregisteredAssetProxyError()
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(UNREGISTERED_ASSET_PROXY_ERROR_SELECTOR);
    }

    function CompleteBuyFailedError(
        uint256 expectedAssetBuyAmount,
        uint256 actualAssetBuyAmount
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            COMPLETE_BUY_FAILED_ERROR_SELECTOR,
            expectedAssetBuyAmount,
            actualAssetBuyAmount
        );
    }

    function CompleteSellFailedError(
        uint256 expectedAssetSellAmount,
        uint256 actualAssetSellAmount
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            COMPLETE_SELL_FAILED_ERROR_SELECTOR,
            expectedAssetSellAmount,
            actualAssetSellAmount
        );
    }

    function UnsupportedFeeError(
        bytes memory takerFeeAssetData
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            UNSUPPORTED_FEE_ERROR_SELECTOR,
            takerFeeAssetData
        );
    }

    function OverspentWethError(
        uint256 wethSpent,
        uint256 msgValue
    )
        internal
        pure
        returns (bytes memory)
    {
        return abi.encodeWithSelector(
            OVERSPENT_WETH_ERROR_SELECTOR,
            wethSpent,
            msgValue
        );
    }
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IExchangeV2 {

    // solhint-disable max-line-length
    struct Order {
        address makerAddress;           // Address that created the order.
        address takerAddress;           // Address that is allowed to fill the order. If set to 0, any address is allowed to fill the order.
        address feeRecipientAddress;    // Address that will recieve fees when order is filled.
        address senderAddress;          // Address that is allowed to call Exchange contract methods that affect this order. If set to 0, any address is allowed to call these methods.
        uint256 makerAssetAmount;       // Amount of makerAsset being offered by maker. Must be greater than 0.
        uint256 takerAssetAmount;       // Amount of takerAsset being bid on by maker. Must be greater than 0.
        uint256 makerFee;               // Amount of ZRX paid to feeRecipient by maker when order is filled. If set to 0, no transfer of ZRX from maker to feeRecipient will be attempted.
        uint256 takerFee;               // Amount of ZRX paid to feeRecipient by taker when order is filled. If set to 0, no transfer of ZRX from taker to feeRecipient will be attempted.
        uint256 expirationTimeSeconds;  // Timestamp in seconds at which order expires.
        uint256 salt;                   // Arbitrary number to facilitate uniqueness of the order's hash.
        bytes makerAssetData;           // Encoded data that can be decoded by a specified proxy contract when transferring makerAsset. The last byte references the id of this proxy.
        bytes takerAssetData;           // Encoded data that can be decoded by a specified proxy contract when transferring takerAsset. The last byte references the id of this proxy.
    }
    // solhint-enable max-line-length

    struct FillResults {
        uint256 makerAssetFilledAmount;  // Total amount of makerAsset(s) filled.
        uint256 takerAssetFilledAmount;  // Total amount of takerAsset(s) filled.
        uint256 makerFeePaid;            // Total amount of ZRX paid by maker(s) to feeRecipient(s).
        uint256 takerFeePaid;            // Total amount of ZRX paid by taker to feeRecipients(s).
    }

    struct OrderInfo {
        uint8 orderStatus;                    // Status that describes order's validity and fillability.
        bytes32 orderHash;                    // EIP712 typed data hash of the order (see LibOrder.getTypedDataHash).
        uint256 orderTakerAssetFilledAmount;  // Amount of order that has already been filled.
    }

    /// @dev Fills the input order.
    /// @param order Order struct containing order specifications.
    /// @param takerAssetFillAmount Desired amount of takerAsset to sell.
    /// @param signature Proof that order has been created by maker.
    /// @return Amounts filled and fees paid by maker and taker.
    function fillOrder(
        Order memory order,
        uint256 takerAssetFillAmount,
        bytes memory signature
    )
        public
        returns (FillResults memory fillResults);

    /// @dev Gets information about an order: status, hash, and amount filled.
    /// @param order Order to gather information on.
    /// @return OrderInfo Information about the order and its state.
    ///         See LibOrder.OrderInfo for a complete description.
    function getOrderInfo(Order memory order)
        public
        returns (OrderInfo memory orderInfo);
}

contract MixinExchangeWrapper {

    // The v2 order id is the first 4 bytes of the ExchangeV2 order schema hash.
    // bytes4(keccak256(abi.encodePacked(
    //     "Order(",
    //     "address makerAddress,",
    //     "address takerAddress,",
    //     "address feeRecipientAddress,",
    //     "address senderAddress,",
    //     "uint256 makerAssetAmount,",
    //     "uint256 takerAssetAmount,",
    //     "uint256 makerFee,",
    //     "uint256 takerFee,",
    //     "uint256 expirationTimeSeconds,",
    //     "uint256 salt,",
    //     "bytes makerAssetData,",
    //     "bytes takerAssetData",
    //     ")"
    // )));
    bytes4 constant public EXCHANGE_V2_ORDER_ID = 0x770501f8;
    bytes4 constant internal ERC20_BRIDGE_PROXY_ID = 0xdc1600f3;

     // solhint-disable var-name-mixedcase
    IExchange internal EXCHANGE;
    IExchangeV2 internal EXCHANGE_V2;
    // solhint-enable var-name-mixedcase

    using LibBytes for bytes;
    using LibAssetDataTransfer for bytes;
    using LibSafeMath for uint256;

    constructor (
        address _exchange,
        address _exchangeV2
    )
        public
    {
        EXCHANGE = IExchange(_exchange);
        EXCHANGE_V2 = IExchangeV2(_exchangeV2);
    }

    struct SellFillResults {
        uint256 wethSpentAmount;
        uint256 makerAssetAcquiredAmount;
        uint256 protocolFeePaid;
    }

    /// @dev Fills the input order.
    ///      Returns false if the transaction would otherwise revert.
    /// @param order Order struct containing order specifications.
    /// @param takerAssetFillAmount Desired amount of takerAsset to sell.
    /// @param signature Proof that order has been created by maker.
    /// @return Amounts filled and fees paid by maker and taker.
    function _fillOrderNoThrow(
        LibOrder.Order memory order,
        uint256 takerAssetFillAmount,
        bytes memory signature
    )
        internal
        returns (LibFillResults.FillResults memory fillResults)
    {
        if (_isV2Order(order)) {
            return _fillV2OrderNoThrow(
                order,
                takerAssetFillAmount,
                signature
            );
        }

        return _fillV3OrderNoThrow(
            order,
            takerAssetFillAmount,
            signature
        );
    }

    /// @dev Executes a single call of fillOrder according to the wethSellAmount and
    ///      the amount already sold.
    /// @param order A single order specification.
    /// @param signature Signature for the given order.
    /// @param remainingTakerAssetFillAmount Remaining amount of WETH to sell.
    /// @return wethSpentAmount Amount of WETH spent on the given order.
    /// @return makerAssetAcquiredAmount Amount of maker asset acquired from the given order.
    function _marketSellSingleOrder(
        LibOrder.Order memory order,
        bytes memory signature,
        uint256 remainingTakerAssetFillAmount
    )
        internal
        returns (SellFillResults memory sellFillResults)
    {
        // If the maker asset is ERC20Bridge, take a snapshot of the Forwarder contract's balance.
        bytes4 makerAssetProxyId = order.makerAssetData.readBytes4(0);
        address tokenAddress;
        uint256 balanceBefore;
        if (makerAssetProxyId == ERC20_BRIDGE_PROXY_ID) {
            tokenAddress = order.makerAssetData.readAddress(16);
            balanceBefore = IERC20Token(tokenAddress).balanceOf(address(this));
        }
        // No taker fee or percentage fee
        if (
            order.takerFee == 0 ||
            _areUnderlyingAssetsEqual(order.takerFeeAssetData, order.makerAssetData)
        ) {
            // Attempt to sell the remaining amount of WETH
            LibFillResults.FillResults memory singleFillResults = _fillOrderNoThrow(
                order,
                remainingTakerAssetFillAmount,
                signature
            );

            sellFillResults.wethSpentAmount = singleFillResults.takerAssetFilledAmount;
            sellFillResults.protocolFeePaid = singleFillResults.protocolFeePaid;

            // Subtract fee from makerAssetFilledAmount for the net amount acquired.
            sellFillResults.makerAssetAcquiredAmount = singleFillResults.makerAssetFilledAmount
                .safeSub(singleFillResults.takerFeePaid);

        // WETH fee
        } else if (_areUnderlyingAssetsEqual(order.takerFeeAssetData, order.takerAssetData)) {

            // We will first sell WETH as the takerAsset, then use it to pay the takerFee.
            // This ensures that we reserve enough to pay the taker and protocol fees.
            uint256 takerAssetFillAmount = LibMath.getPartialAmountCeil(
                order.takerAssetAmount,
                order.takerAssetAmount.safeAdd(order.takerFee),
                remainingTakerAssetFillAmount
            );

            LibFillResults.FillResults memory singleFillResults = _fillOrderNoThrow(
                order,
                takerAssetFillAmount,
                signature
            );

            // WETH is also spent on the taker fee, so we add it here.
            sellFillResults.wethSpentAmount = singleFillResults.takerAssetFilledAmount
                .safeAdd(singleFillResults.takerFeePaid);
            sellFillResults.makerAssetAcquiredAmount = singleFillResults.makerAssetFilledAmount;
            sellFillResults.protocolFeePaid = singleFillResults.protocolFeePaid;

        // Unsupported fee
        } else {
            LibRichErrors.rrevert(LibForwarderRichErrors.UnsupportedFeeError(order.takerFeeAssetData));
        }

        // Account for the ERC20Bridge transfering more of the maker asset than expected.
        if (makerAssetProxyId == ERC20_BRIDGE_PROXY_ID) {
            uint256 balanceAfter = IERC20Token(tokenAddress).balanceOf(address(this));
            sellFillResults.makerAssetAcquiredAmount = LibSafeMath.max256(
                balanceAfter.safeSub(balanceBefore),
                sellFillResults.makerAssetAcquiredAmount
            );
        }

        order.makerAssetData.transferOut(sellFillResults.makerAssetAcquiredAmount);
        return sellFillResults;
    }

    /// @dev Synchronously executes multiple calls of fillOrder until total amount of WETH has been sold by taker.
    /// @param orders Array of order specifications.
    /// @param wethSellAmount Desired amount of WETH to sell.
    /// @param signatures Proofs that orders have been signed by makers.
    /// @return totalWethSpentAmount Total amount of WETH spent on the given orders.
    /// @return totalMakerAssetAcquiredAmount Total amount of maker asset acquired from the given orders.
    function _marketSellNoThrow(
        LibOrder.Order[] memory orders,
        uint256 wethSellAmount,
        bytes[] memory signatures
    )
        internal
        returns (
            uint256 totalWethSpentAmount,
            uint256 totalMakerAssetAcquiredAmount
        )
    {
        uint256 protocolFee = tx.gasprice.safeMul(EXCHANGE.protocolFeeMultiplier());

        for (uint256 i = 0; i != orders.length; i++) {
            // Preemptively skip to avoid division by zero in _marketSellSingleOrder
            if (orders[i].makerAssetAmount == 0 || orders[i].takerAssetAmount == 0) {
                continue;
            }

            // The remaining amount of WETH to sell
            uint256 remainingTakerAssetFillAmount = wethSellAmount
                .safeSub(totalWethSpentAmount);
            uint256 currentProtocolFee = _isV2Order(orders[i]) ? 0 : protocolFee;
            if (remainingTakerAssetFillAmount > currentProtocolFee) {
                // Do not count the protocol fee as part of the fill amount.
                remainingTakerAssetFillAmount = remainingTakerAssetFillAmount.safeSub(currentProtocolFee);
            } else {
                // Stop if we don't have at least enough ETH to pay another protocol fee.
                break;
            }

            SellFillResults memory sellFillResults = _marketSellSingleOrder(
                orders[i],
                signatures[i],
                remainingTakerAssetFillAmount
            );

            totalWethSpentAmount = totalWethSpentAmount
                .safeAdd(sellFillResults.wethSpentAmount)
                .safeAdd(sellFillResults.protocolFeePaid);
            totalMakerAssetAcquiredAmount = totalMakerAssetAcquiredAmount
                .safeAdd(sellFillResults.makerAssetAcquiredAmount);

            // Stop execution if the entire amount of WETH has been sold
            if (totalWethSpentAmount >= wethSellAmount) {
                break;
            }
        }
    }

    /// @dev Synchronously executes multiple calls of fillOrder until total amount of WETH (exclusive of protocol fee)
    ///      has been sold by taker.
    /// @param orders Array of order specifications.
    /// @param wethSellAmount Desired amount of WETH to sell.
    /// @param signatures Proofs that orders have been signed by makers.
    /// @return totalWethSpentAmount Total amount of WETH spent on the given orders.
    /// @return totalMakerAssetAcquiredAmount Total amount of maker asset acquired from the given orders.
    function _marketSellExactAmountNoThrow(
        LibOrder.Order[] memory orders,
        uint256 wethSellAmount,
        bytes[] memory signatures
    )
        internal
        returns (
            uint256 totalWethSpentAmount,
            uint256 totalMakerAssetAcquiredAmount
        )
    {
        uint256 totalProtocolFeePaid;

        for (uint256 i = 0; i != orders.length; i++) {
            // Preemptively skip to avoid division by zero in _marketSellSingleOrder
            if (orders[i].makerAssetAmount == 0 || orders[i].takerAssetAmount == 0) {
                continue;
            }

            // The remaining amount of WETH to sell
            uint256 remainingTakerAssetFillAmount = wethSellAmount
                .safeSub(totalWethSpentAmount);

            SellFillResults memory sellFillResults = _marketSellSingleOrder(
                orders[i],
                signatures[i],
                remainingTakerAssetFillAmount
            );

            totalWethSpentAmount = totalWethSpentAmount
                .safeAdd(sellFillResults.wethSpentAmount);
            totalMakerAssetAcquiredAmount = totalMakerAssetAcquiredAmount
                .safeAdd(sellFillResults.makerAssetAcquiredAmount);
            totalProtocolFeePaid = totalProtocolFeePaid.safeAdd(sellFillResults.protocolFeePaid);

            // Stop execution if the entire amount of WETH has been sold
            if (totalWethSpentAmount >= wethSellAmount) {
                break;
            }
        }
        totalWethSpentAmount = totalWethSpentAmount.safeAdd(totalProtocolFeePaid);
    }

    /// @dev Executes a single call of fillOrder according to the makerAssetBuyAmount and
    ///      the amount already bought.
    /// @param order A single order specification.
    /// @param signature Signature for the given order.
    /// @param remainingMakerAssetFillAmount Remaining amount of maker asset to buy.
    /// @return wethSpentAmount Amount of WETH spent on the given order.
    /// @return makerAssetAcquiredAmount Amount of maker asset acquired from the given order.
    function _marketBuySingleOrder(
        LibOrder.Order memory order,
        bytes memory signature,
        uint256 remainingMakerAssetFillAmount
    )
        internal
        returns (
            uint256 wethSpentAmount,
            uint256 makerAssetAcquiredAmount
        )
    {
        // No taker fee or WETH fee
        if (
            order.takerFee == 0 ||
            _areUnderlyingAssetsEqual(order.takerFeeAssetData, order.takerAssetData)
        ) {
            // Calculate the remaining amount of takerAsset to sell
            uint256 remainingTakerAssetFillAmount = LibMath.getPartialAmountCeil(
                order.takerAssetAmount,
                order.makerAssetAmount,
                remainingMakerAssetFillAmount
            );

            // Attempt to sell the remaining amount of takerAsset
            LibFillResults.FillResults memory singleFillResults = _fillOrderNoThrow(
                order,
                remainingTakerAssetFillAmount,
                signature
            );

            // WETH is also spent on the protocol and taker fees, so we add it here.
            wethSpentAmount = singleFillResults.takerAssetFilledAmount
                .safeAdd(singleFillResults.takerFeePaid)
                .safeAdd(singleFillResults.protocolFeePaid);

            makerAssetAcquiredAmount = singleFillResults.makerAssetFilledAmount;

        // Percentage fee
        } else if (_areUnderlyingAssetsEqual(order.takerFeeAssetData, order.makerAssetData)) {
            // Calculate the remaining amount of takerAsset to sell
            uint256 remainingTakerAssetFillAmount = LibMath.getPartialAmountCeil(
                order.takerAssetAmount,
                order.makerAssetAmount.safeSub(order.takerFee),
                remainingMakerAssetFillAmount
            );

            // Attempt to sell the remaining amount of takerAsset
            LibFillResults.FillResults memory singleFillResults = _fillOrderNoThrow(
                order,
                remainingTakerAssetFillAmount,
                signature
            );

            wethSpentAmount = singleFillResults.takerAssetFilledAmount
                .safeAdd(singleFillResults.protocolFeePaid);

            // Subtract fee from makerAssetFilledAmount for the net amount acquired.
            makerAssetAcquiredAmount = singleFillResults.makerAssetFilledAmount
                .safeSub(singleFillResults.takerFeePaid);

        // Unsupported fee
        } else {
            LibRichErrors.rrevert(LibForwarderRichErrors.UnsupportedFeeError(order.takerFeeAssetData));
        }

        return (wethSpentAmount, makerAssetAcquiredAmount);
    }

    /// @dev Synchronously executes multiple fill orders in a single transaction until total amount is acquired.
    ///      Note that the Forwarder may fill more than the makerAssetBuyAmount so that, after percentage fees
    ///      are paid, the net amount acquired after fees is equal to makerAssetBuyAmount (modulo rounding).
    ///      The asset being sold by taker must always be WETH.
    /// @param orders Array of order specifications.
    /// @param makerAssetBuyAmount Desired amount of makerAsset to fill.
    /// @param signatures Proofs that orders have been signed by makers.
    /// @return totalWethSpentAmount Total amount of WETH spent on the given orders.
    /// @return totalMakerAssetAcquiredAmount Total amount of maker asset acquired from the given orders.
    function _marketBuyFillOrKill(
        LibOrder.Order[] memory orders,
        uint256 makerAssetBuyAmount,
        bytes[] memory signatures
    )
        internal
        returns (
            uint256 totalWethSpentAmount,
            uint256 totalMakerAssetAcquiredAmount
        )
    {
        uint256 ordersLength = orders.length;
        for (uint256 i = 0; i != ordersLength; i++) {
            // Preemptively skip to avoid division by zero in _marketBuySingleOrder
            if (orders[i].makerAssetAmount == 0 || orders[i].takerAssetAmount == 0) {
                continue;
            }

            uint256 remainingMakerAssetFillAmount = makerAssetBuyAmount
                .safeSub(totalMakerAssetAcquiredAmount);

            // If the maker asset is ERC20Bridge, take a snapshot of the Forwarder contract's balance.
            bytes4 makerAssetProxyId = orders[i].makerAssetData.readBytes4(0);
            address tokenAddress;
            uint256 balanceBefore;
            if (makerAssetProxyId == ERC20_BRIDGE_PROXY_ID) {
                tokenAddress = orders[i].makerAssetData.readAddress(16);
                balanceBefore = IERC20Token(tokenAddress).balanceOf(address(this));
            }

            (
                uint256 wethSpentAmount,
                uint256 makerAssetAcquiredAmount
            ) = _marketBuySingleOrder(
                orders[i],
                signatures[i],
                remainingMakerAssetFillAmount
            );

            // Account for the ERC20Bridge transfering more of the maker asset than expected.
            if (makerAssetProxyId == ERC20_BRIDGE_PROXY_ID) {
                uint256 balanceAfter = IERC20Token(tokenAddress).balanceOf(address(this));
                makerAssetAcquiredAmount = LibSafeMath.max256(
                    balanceAfter.safeSub(balanceBefore),
                    makerAssetAcquiredAmount
                );
            }

            orders[i].makerAssetData.transferOut(makerAssetAcquiredAmount);

            totalWethSpentAmount = totalWethSpentAmount
                .safeAdd(wethSpentAmount);
            totalMakerAssetAcquiredAmount = totalMakerAssetAcquiredAmount
                .safeAdd(makerAssetAcquiredAmount);

            // Stop execution if the entire amount of makerAsset has been bought
            if (totalMakerAssetAcquiredAmount >= makerAssetBuyAmount) {
                break;
            }
        }

        if (totalMakerAssetAcquiredAmount < makerAssetBuyAmount) {
            LibRichErrors.rrevert(LibForwarderRichErrors.CompleteBuyFailedError(
                makerAssetBuyAmount,
                totalMakerAssetAcquiredAmount
            ));
        }
    }

    /// @dev Fills the input ExchangeV2 order. The `makerFeeAssetData` must be
    //       equal to EXCHANGE_V2_ORDER_ID (0x770501f8).
    ///      Returns false if the transaction would otherwise revert.
    /// @param order Order struct containing order specifications.
    /// @param takerAssetFillAmount Desired amount of takerAsset to sell.
    /// @param signature Proof that order has been created by maker.
    /// @return Amounts filled and fees paid by maker and taker.
    function _fillV2OrderNoThrow(
        LibOrder.Order memory order,
        uint256 takerAssetFillAmount,
        bytes memory signature
    )
        internal
        returns (LibFillResults.FillResults memory fillResults)
    {
        // Strip v3 specific fields from order
        IExchangeV2.Order memory v2Order = IExchangeV2.Order({
            makerAddress: order.makerAddress,
            takerAddress: order.takerAddress,
            feeRecipientAddress: order.feeRecipientAddress,
            senderAddress: order.senderAddress,
            makerAssetAmount: order.makerAssetAmount,
            takerAssetAmount: order.takerAssetAmount,
            // NOTE: We assume fees are 0 for all v2 orders. Orders with non-zero fees will fail to be filled.
            makerFee: 0,
            takerFee: 0,
            expirationTimeSeconds: order.expirationTimeSeconds,
            salt: order.salt,
            makerAssetData: order.makerAssetData,
            takerAssetData: order.takerAssetData
        });

        // ABI encode calldata for `fillOrder`
        bytes memory fillOrderCalldata = abi.encodeWithSelector(
            IExchangeV2(address(0)).fillOrder.selector,
            v2Order,
            takerAssetFillAmount,
            signature
        );

        address exchange = address(EXCHANGE_V2);
        (bool didSucceed, bytes memory returnData) = exchange.call(fillOrderCalldata);
        if (didSucceed) {
            assert(returnData.length == 128);
            // NOTE: makerFeePaid, takerFeePaid, and protocolFeePaid will always be 0 for v2 orders
            (fillResults.makerAssetFilledAmount, fillResults.takerAssetFilledAmount) = abi.decode(returnData, (uint256, uint256));
        }

        // fillResults values will be 0 by default if call was unsuccessful
        return fillResults;
    }

    /// @dev Fills the input ExchangeV3 order.
    ///      Returns false if the transaction would otherwise revert.
    /// @param order Order struct containing order specifications.
    /// @param takerAssetFillAmount Desired amount of takerAsset to sell.
    /// @param signature Proof that order has been created by maker.
    /// @return Amounts filled and fees paid by maker and taker.
    function _fillV3OrderNoThrow(
        LibOrder.Order memory order,
        uint256 takerAssetFillAmount,
        bytes memory signature
    )
        internal
        returns (LibFillResults.FillResults memory fillResults)
    {
        // ABI encode calldata for `fillOrder`
        bytes memory fillOrderCalldata = abi.encodeWithSelector(
            IExchange(address(0)).fillOrder.selector,
            order,
            takerAssetFillAmount,
            signature
        );

        address exchange = address(EXCHANGE);
        (bool didSucceed, bytes memory returnData) = exchange.call(fillOrderCalldata);
        if (didSucceed) {
            assert(returnData.length == 160);
            fillResults = abi.decode(returnData, (LibFillResults.FillResults));
        }

        // fillResults values will be 0 by default if call was unsuccessful
        return fillResults;
    }

    /// @dev Checks whether one asset is effectively equal to another asset.
    ///      This is the case if they have the same ERC20Proxy/ERC20BridgeProxy asset data, or if
    ///      one is the ERC20Bridge equivalent of the other.
    /// @param assetData1 Byte array encoded for the takerFee asset proxy.
    /// @param assetData2 Byte array encoded for the maker asset proxy.
    /// @return areEqual Whether or not the underlying assets are equal.
    function _areUnderlyingAssetsEqual(
        bytes memory assetData1,
        bytes memory assetData2
    )
        internal
        pure
        returns (bool)
    {
        bytes4 assetProxyId1 = assetData1.readBytes4(0);
        bytes4 assetProxyId2 = assetData2.readBytes4(0);
        bytes4 erc20ProxyId = IAssetData(address(0)).ERC20Token.selector;
        bytes4 erc20BridgeProxyId = IAssetData(address(0)).ERC20Bridge.selector;

        if (
            (assetProxyId1 == erc20ProxyId || assetProxyId1 == erc20BridgeProxyId) &&
            (assetProxyId2 == erc20ProxyId || assetProxyId2 == erc20BridgeProxyId)
        ) {
            // Compare the underlying token addresses.
            address token1 = assetData1.readAddress(16);
            address token2 = assetData2.readAddress(16);
            return (token1 == token2);
        } else {
            return assetData1.equals(assetData2);
        }
    }

    /// @dev Checks whether an order is a v2 order.
    /// @param order Order struct containing order specifications.
    /// @return True if the order's `makerFeeAssetData` is set to the v2 order id.
    function _isV2Order(LibOrder.Order memory order)
        internal
        pure
        returns (bool)
    {
        return order.makerFeeAssetData.length > 3 && order.makerFeeAssetData.readBytes4(0) == EXCHANGE_V2_ORDER_ID;
    }
}

/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract MixinReceiver {

    bytes4 constant public ERC1155_RECEIVED       = 0xf23a6e61;
    bytes4 constant public ERC1155_BATCH_RECEIVED = 0xbc197c81;

    /// @notice Handle the receipt of a single ERC1155 token type
    /// @dev The smart contract calls this function on the recipient
    /// after a `safeTransferFrom`. This function MAY throw to revert and reject the
    /// transfer. Return of other than the magic value MUST result in the
    ///transaction being reverted
    /// Note: the contract address is always the message sender
    /// @param operator  The address which called `safeTransferFrom` function
    /// @param from      The address which previously owned the token
    /// @param id        An array containing the ids of the token being transferred
    /// @param value     An array containing the amount of tokens being transferred
    /// @param data      Additional data with no specified format
    /// @return          `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    )
        external
        returns (bytes4)
    {
        return ERC1155_RECEIVED;
    }

    /// @notice Handle the receipt of multiple ERC1155 token types
    /// @dev The smart contract calls this function on the recipient
    /// after a `safeTransferFrom`. This function MAY throw to revert and reject the
    /// transfer. Return of other than the magic value MUST result in the
    /// transaction being reverted
    /// Note: the contract address is always the message sender
    /// @param operator  The address which called `safeTransferFrom` function
    /// @param from      The address which previously owned the token
    /// @param ids       An array containing ids of each token being transferred
    /// @param values    An array containing amounts of each token being transferred
    /// @param data      Additional data with no specified format
    /// @return           `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    )
        external
        returns (bytes4)
    {
        return ERC1155_BATCH_RECEIVED;
    }
}
/*

  Copyright 2019 ZeroEx Intl.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

*/

contract IForwarder {

    /// @dev Withdraws assets from this contract. The contract requires a ZRX balance in order to
    ///      function optimally, and this function allows the ZRX to be withdrawn by owner. It may also be
    ///      used to withdraw assets that were accidentally sent to this contract.
    /// @param assetData Byte array encoded for the respective asset proxy.
    /// @param amount Amount of ERC20 token to withdraw.
    function withdrawAsset(
        bytes calldata assetData,
        uint256 amount
    )
        external;

        /// @dev Approves the respective proxy for a given asset to transfer tokens on the Forwarder contract's behalf.
        ///      This is necessary because an order fee denominated in the maker asset (i.e. a percentage fee) is sent by the
        ///      Forwarder contract to the fee recipient.
        ///      This method needs to be called before forwarding orders of a maker asset that hasn't
        ///      previously been approved.
        /// @param assetData Byte array encoded for the respective asset proxy.
    function approveMakerAssetProxy(
        bytes calldata assetData
    )
        external;

    /// @dev Purchases as much of orders' makerAssets as possible by selling as much of the ETH value sent
    ///      as possible, accounting for order and forwarder fees.
    /// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
    /// @param signatures Proofs that orders have been created by makers.
    /// @param ethFeeAmounts Amounts of ETH, denominated in Wei, that are paid to corresponding feeRecipients.
    /// @param feeRecipients Addresses that will receive ETH when orders are filled.
    /// @return wethSpentAmount Amount of WETH spent on the given set of orders.
    /// @return makerAssetAcquiredAmount Amount of maker asset acquired from the given set of orders.
    function marketSellOrdersWithEth(
        LibOrder.Order[] memory orders,
        bytes[] memory signatures,
        uint256[] memory ethFeeAmounts,
        address payable[] memory feeRecipients
    )
        public
        payable
        returns (
            uint256 wethSpentAmount,
            uint256 makerAssetAcquiredAmount
        );

    /// @dev Attempt to buy makerAssetBuyAmount of makerAsset by selling ETH provided with transaction.
    ///      The Forwarder may *fill* more than makerAssetBuyAmount of the makerAsset so that it can
    ///      pay takerFees where takerFeeAssetData == makerAssetData (i.e. percentage fees).
    ///      Any ETH not spent will be refunded to sender.
    /// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
    /// @param makerAssetBuyAmount Desired amount of makerAsset to purchase.
    /// @param signatures Proofs that orders have been created by makers.
    /// @param ethFeeAmounts Amounts of ETH, denominated in Wei, that are paid to corresponding feeRecipients.
    /// @param feeRecipients Addresses that will receive ETH when orders are filled.
    /// @return wethSpentAmount Amount of WETH spent on the given set of orders.
    /// @return makerAssetAcquiredAmount Amount of maker asset acquired from the given set of orders.
    function marketBuyOrdersWithEth(
        LibOrder.Order[] memory orders,
        uint256 makerAssetBuyAmount,
        bytes[] memory signatures,
        uint256[] memory ethFeeAmounts,
        address payable[] memory feeRecipients
    )
        public
        payable
        returns (
            uint256 wethSpentAmount,
            uint256 makerAssetAcquiredAmount
        );
}

contract Forwarder is
    IForwarder,
    Ownable,
    MixinWethUtils,
    MixinExchangeWrapper,
    MixinReceiver
{
    using LibBytes for bytes;
    using LibAssetDataTransfer for bytes;
    using LibSafeMath for uint256;

    constructor (
        address _exchange,
        address _exchangeV2,
        address _weth
    )
        public
        Ownable()
        MixinWethUtils(
            _exchange,
            _weth
        )
        MixinExchangeWrapper(
            _exchange,
            _exchangeV2
        )
    {} // solhint-disable-line no-empty-blocks

    /// @dev Withdraws assets from this contract. It may be used by the owner to withdraw assets
    ///      that were accidentally sent to this contract.
    /// @param assetData Byte array encoded for the respective asset proxy.
    /// @param amount Amount of the asset to withdraw.
    function withdrawAsset(
        bytes calldata assetData,
        uint256 amount
    )
        external
        onlyOwner
    {
        assetData.transferOut(amount);
    }

    /// @dev Approves the respective proxy for a given asset to transfer tokens on the Forwarder contract's behalf.
    ///      This is necessary because an order fee denominated in the maker asset (i.e. a percentage fee) is sent by the
    ///      Forwarder contract to the fee recipient.
    ///      This method needs to be called before forwarding orders of a maker asset that hasn't
    ///      previously been approved.
    /// @param assetData Byte array encoded for the respective asset proxy.
    function approveMakerAssetProxy(bytes calldata assetData)
        external
    {
        bytes4 proxyId = assetData.readBytes4(0);
        bytes4 erc20ProxyId = IAssetData(address(0)).ERC20Token.selector;

        // For now we only care about ERC20, since percentage fees on ERC721 tokens are invalid.
        if (proxyId == erc20ProxyId) {
            address proxyAddress = EXCHANGE.getAssetProxy(erc20ProxyId);
            if (proxyAddress == address(0)) {
                LibRichErrors.rrevert(LibForwarderRichErrors.UnregisteredAssetProxyError());
            }
            address token = assetData.readAddress(16);
            LibERC20Token.approve(token, proxyAddress, MAX_UINT256);
        }
    }

    /// @dev Purchases as much of orders' makerAssets as possible by selling as much of the ETH value sent
    ///      as possible, accounting for order and forwarder fees.
    /// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
    /// @param signatures Proofs that orders have been created by makers.
    /// @param ethFeeAmounts Amounts of ETH, denominated in Wei, that are paid to corresponding feeRecipients.
    /// @param feeRecipients Addresses that will receive ETH when orders are filled.
    /// @return wethSpentAmount Amount of WETH spent on the given set of orders.
    /// @return makerAssetAcquiredAmount Amount of maker asset acquired from the given set of orders.
    function marketSellOrdersWithEth(
        LibOrder.Order[] memory orders,
        bytes[] memory signatures,
        uint256[] memory ethFeeAmounts,
        address payable[] memory feeRecipients
    )
        public
        payable
        returns (
            uint256 wethSpentAmount,
            uint256 makerAssetAcquiredAmount
        )
    {
        // Pay ETH affiliate fees to all feeRecipient addresses
        uint256 wethRemaining = _transferEthFeesAndWrapRemaining(
            ethFeeAmounts,
            feeRecipients
        );
        // Spends up to wethRemaining to fill orders, transfers purchased assets to msg.sender,
        // and pays WETH order fees.
        (
            wethSpentAmount,
            makerAssetAcquiredAmount
        ) = _marketSellNoThrow(
            orders,
            wethRemaining,
            signatures
        );

        // Ensure that no extra WETH owned by this contract has been spent.
        if (wethSpentAmount > wethRemaining) {
            LibRichErrors.rrevert(LibForwarderRichErrors.OverspentWethError(
                wethSpentAmount,
                msg.value
            ));
        }

        // Calculate amount of WETH that hasn't been spent.
        wethRemaining = wethRemaining.safeSub(wethSpentAmount);

        // Refund remaining ETH to msg.sender.
        _unwrapAndTransferEth(wethRemaining);
    }

    /// @dev Purchases as much of orders' makerAssets as possible by selling the specified amount of ETH
    ///      accounting for order and forwarder fees. This functions throws if ethSellAmount was not reached.
    /// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
    /// @param ethSellAmount Desired amount of ETH to sell.
    /// @param signatures Proofs that orders have been created by makers.
    /// @param ethFeeAmounts Amounts of ETH, denominated in Wei, that are paid to corresponding feeRecipients.
    /// @param feeRecipients Addresses that will receive ETH when orders are filled.
    /// @return wethSpentAmount Amount of WETH spent on the given set of orders.
    /// @return makerAssetAcquiredAmount Amount of maker asset acquired from the given set of orders.
    function marketSellAmountWithEth(
        LibOrder.Order[] memory orders,
        uint256 ethSellAmount,
        bytes[] memory signatures,
        uint256[] memory ethFeeAmounts,
        address payable[] memory feeRecipients
    )
        public
        payable
        returns (
            uint256 wethSpentAmount,
            uint256 makerAssetAcquiredAmount
        )
    {
        if (ethSellAmount > msg.value) {
            LibRichErrors.rrevert(LibForwarderRichErrors.CompleteSellFailedError(
                ethSellAmount,
                msg.value
            ));
        }
        // Pay ETH affiliate fees to all feeRecipient addresses
        uint256 wethRemaining = _transferEthFeesAndWrapRemaining(
            ethFeeAmounts,
            feeRecipients
        );
        // Need enough remaining to ensure we can sell ethSellAmount
        if (wethRemaining < ethSellAmount) {
            LibRichErrors.rrevert(LibForwarderRichErrors.OverspentWethError(
                wethRemaining,
                ethSellAmount
            ));
        }
        // Spends up to ethSellAmount to fill orders, transfers purchased assets to msg.sender,
        // and pays WETH order fees.
        (
            wethSpentAmount,
            makerAssetAcquiredAmount
        ) = _marketSellExactAmountNoThrow(
            orders,
            ethSellAmount,
            signatures
        );
        // Ensure we sold the specified amount (note: wethSpentAmount includes fees)
        if (wethSpentAmount < ethSellAmount) {
            LibRichErrors.rrevert(LibForwarderRichErrors.CompleteSellFailedError(
                ethSellAmount,
                wethSpentAmount
            ));
        }

        // Calculate amount of WETH that hasn't been spent.
        wethRemaining = wethRemaining.safeSub(wethSpentAmount);

        // Refund remaining ETH to msg.sender.
        _unwrapAndTransferEth(wethRemaining);
    }

    /// @dev Attempt to buy makerAssetBuyAmount of makerAsset by selling ETH provided with transaction.
    ///      The Forwarder may *fill* more than makerAssetBuyAmount of the makerAsset so that it can
    ///      pay takerFees where takerFeeAssetData == makerAssetData (i.e. percentage fees).
    ///      Any ETH not spent will be refunded to sender.
    /// @param orders Array of order specifications used containing desired makerAsset and WETH as takerAsset.
    /// @param makerAssetBuyAmount Desired amount of makerAsset to purchase.
    /// @param signatures Proofs that orders have been created by makers.
    /// @param ethFeeAmounts Amounts of ETH, denominated in Wei, that are paid to corresponding feeRecipients.
    /// @param feeRecipients Addresses that will receive ETH when orders are filled.
    /// @return wethSpentAmount Amount of WETH spent on the given set of orders.
    /// @return makerAssetAcquiredAmount Amount of maker asset acquired from the given set of orders.
    function marketBuyOrdersWithEth(
        LibOrder.Order[] memory orders,
        uint256 makerAssetBuyAmount,
        bytes[] memory signatures,
        uint256[] memory ethFeeAmounts,
        address payable[] memory feeRecipients
    )
        public
        payable
        returns (
            uint256 wethSpentAmount,
            uint256 makerAssetAcquiredAmount
        )
    {
        // Pay ETH affiliate fees to all feeRecipient addresses
        uint256 wethRemaining = _transferEthFeesAndWrapRemaining(
            ethFeeAmounts,
            feeRecipients
        );

        // Attempts to fill the desired amount of makerAsset and trasnfer purchased assets to msg.sender.
        (
            wethSpentAmount,
            makerAssetAcquiredAmount
        ) = _marketBuyFillOrKill(
            orders,
            makerAssetBuyAmount,
            signatures
        );

        // Ensure that no extra WETH owned by this contract has been spent.
        if (wethSpentAmount > wethRemaining) {
            LibRichErrors.rrevert(LibForwarderRichErrors.OverspentWethError(
                wethSpentAmount,
                msg.value
            ));
        }

        // Calculate amount of WETH that hasn't been spent.
        wethRemaining = wethRemaining.safeSub(wethSpentAmount);

        // Refund remaining ETH to msg.sender.
        _unwrapAndTransferEth(wethRemaining);
    }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_exchange","type":"address"},{"internalType":"address","name":"_exchangeV2","type":"address"},{"internalType":"address","name":"_weth","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"constant":true,"inputs":[],"name":"ERC1155_BATCH_RECEIVED","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ERC1155_RECEIVED","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"EXCHANGE_V2_ORDER_ID","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"assetData","type":"bytes"}],"name":"approveMakerAssetProxy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"components":[{"internalType":"address","name":"makerAddress","type":"address"},{"internalType":"address","name":"takerAddress","type":"address"},{"internalType":"address","name":"feeRecipientAddress","type":"address"},{"internalType":"address","name":"senderAddress","type":"address"},{"internalType":"uint256","name":"makerAssetAmount","type":"uint256"},{"internalType":"uint256","name":"takerAssetAmount","type":"uint256"},{"internalType":"uint256","name":"makerFee","type":"uint256"},{"internalType":"uint256","name":"takerFee","type":"uint256"},{"internalType":"uint256","name":"expirationTimeSeconds","type":"uint256"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"makerFeeAssetData","type":"bytes"},{"internalType":"bytes","name":"takerFeeAssetData","type":"bytes"}],"internalType":"struct LibOrder.Order[]","name":"orders","type":"tuple[]"},{"internalType":"uint256","name":"makerAssetBuyAmount","type":"uint256"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"},{"internalType":"uint256[]","name":"ethFeeAmounts","type":"uint256[]"},{"internalType":"address payable[]","name":"feeRecipients","type":"address[]"}],"name":"marketBuyOrdersWithEth","outputs":[{"internalType":"uint256","name":"wethSpentAmount","type":"uint256"},{"internalType":"uint256","name":"makerAssetAcquiredAmount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"components":[{"internalType":"address","name":"makerAddress","type":"address"},{"internalType":"address","name":"takerAddress","type":"address"},{"internalType":"address","name":"feeRecipientAddress","type":"address"},{"internalType":"address","name":"senderAddress","type":"address"},{"internalType":"uint256","name":"makerAssetAmount","type":"uint256"},{"internalType":"uint256","name":"takerAssetAmount","type":"uint256"},{"internalType":"uint256","name":"makerFee","type":"uint256"},{"internalType":"uint256","name":"takerFee","type":"uint256"},{"internalType":"uint256","name":"expirationTimeSeconds","type":"uint256"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"makerFeeAssetData","type":"bytes"},{"internalType":"bytes","name":"takerFeeAssetData","type":"bytes"}],"internalType":"struct LibOrder.Order[]","name":"orders","type":"tuple[]"},{"internalType":"uint256","name":"ethSellAmount","type":"uint256"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"},{"internalType":"uint256[]","name":"ethFeeAmounts","type":"uint256[]"},{"internalType":"address payable[]","name":"feeRecipients","type":"address[]"}],"name":"marketSellAmountWithEth","outputs":[{"internalType":"uint256","name":"wethSpentAmount","type":"uint256"},{"internalType":"uint256","name":"makerAssetAcquiredAmount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"components":[{"internalType":"address","name":"makerAddress","type":"address"},{"internalType":"address","name":"takerAddress","type":"address"},{"internalType":"address","name":"feeRecipientAddress","type":"address"},{"internalType":"address","name":"senderAddress","type":"address"},{"internalType":"uint256","name":"makerAssetAmount","type":"uint256"},{"internalType":"uint256","name":"takerAssetAmount","type":"uint256"},{"internalType":"uint256","name":"makerFee","type":"uint256"},{"internalType":"uint256","name":"takerFee","type":"uint256"},{"internalType":"uint256","name":"expirationTimeSeconds","type":"uint256"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"makerAssetData","type":"bytes"},{"internalType":"bytes","name":"takerAssetData","type":"bytes"},{"internalType":"bytes","name":"makerFeeAssetData","type":"bytes"},{"internalType":"bytes","name":"takerFeeAssetData","type":"bytes"}],"internalType":"struct LibOrder.Order[]","name":"orders","type":"tuple[]"},{"internalType":"bytes[]","name":"signatures","type":"bytes[]"},{"internalType":"uint256[]","name":"ethFeeAmounts","type":"uint256[]"},{"internalType":"address payable[]","name":"feeRecipients","type":"address[]"}],"name":"marketSellOrdersWithEth","outputs":[{"internalType":"uint256","name":"wethSpentAmount","type":"uint256"},{"internalType":"uint256","name":"makerAssetAcquiredAmount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"values","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"assetData","type":"bytes"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawAsset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]

60806040523480156200001157600080fd5b50604051620038503803806200385083398101604081905262000034916200048b565b60008054336001600160a01b031991821617909155600180549091166001600160a01b0383161790556040518390839082908490630f47261b60e41b906200008190839060240162000527565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217825251620000c191600291620003a0565b50604051630c0e082160e31b81526000906001600160a01b03841690636070410890620000fa90630f47261b60e41b906004016200055d565b60206040518083038186803b1580156200011357600080fd5b505afa15801562000128573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506200014e919081019062000462565b90506001600160a01b038116620001895762000189620001786200036b60201b620006621760201c565b6200039860201b6200027f1760201c565b60015460405163095ea7b360e01b81526001600160a01b039091169063095ea7b390620001bf9084906000199060040162000537565b602060405180830381600087803b158015620001da57600080fd5b505af1158015620001ef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250620002159190810190620004df565b506000836001600160a01b031663850a15016040518163ffffffff1660e01b815260040160206040518083038186803b1580156200025257600080fd5b505afa15801562000267573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506200028d919081019062000462565b90506001600160a01b038116156200032d5760015460405163095ea7b360e01b81526001600160a01b039091169063095ea7b390620002d59084906000199060040162000537565b602060405180830381600087803b158015620002f057600080fd5b505af115801562000305573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506200032b9190810190620004df565b505b5050600380546001600160a01b039586166001600160a01b031991821617909155600480549490951693169290921790925550620005bd9350505050565b6040805160048152602481019091526020810180516001600160e01b031663f3b96b8d60e01b1790525b90565b805160208201fd5b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10620003e357805160ff191683800117855562000413565b8280016001018555821562000413579182015b8281111562000413578251825591602001919060010190620003f6565b506200042192915062000425565b5090565b6200039591905b808211156200042157600081556001016200042c565b80516200044f8162000598565b92915050565b80516200044f81620005b2565b6000602082840312156200047557600080fd5b600062000483848462000442565b949350505050565b600080600060608486031215620004a157600080fd5b6000620004af868662000442565b9350506020620004c28682870162000442565b9250506040620004d58682870162000442565b9150509250925092565b600060208284031215620004f257600080fd5b600062000483848462000455565b6200050b816200056d565b82525050565b6200050b816200057f565b6200050b8162000395565b602081016200044f828462000500565b6040810162000547828562000500565b6200055660208301846200051c565b9392505050565b602081016200044f828462000511565b60006200044f826200058c565b151590565b6001600160e01b03191690565b6001600160a01b031690565b620005a3816200056d565b8114620005af57600080fd5b50565b620005a3816200057a565b61328380620005cd6000396000f3fe6080604052600436106100a75760003560e01c8063bc197c8111610064578063bc197c811461017e578063e0a5c949146101ab578063e196001b146101c0578063f23a6e61146101d5578063f2fde38b146101f5578063fc67bf1c14610215576100a7565b8063442026ed146100cc578063630f1e6c146100ec5780638da5cb5b1461010c578063907e5cc314610137578063939ce6ba146101585780639e8323151461016b575b6001546001600160a01b031633146100ca576100ca6100c53361022a565b61027f565b005b3480156100d857600080fd5b506100ca6100e7366004612b46565b610287565b3480156100f857600080fd5b506100ca610107366004612b87565b6103ef565b34801561011857600080fd5b50610121610445565b60405161012e9190612f8f565b60405180910390f35b61014a61014536600461295f565b610454565b60405161012e9291906130f4565b61014a610166366004612a0f565b6104af565b61014a610179366004612a0f565b610535565b34801561018a57600080fd5b5061019e610199366004612809565b61056b565b60405161012e919061305b565b3480156101b757600080fd5b5061019e61057f565b3480156101cc57600080fd5b5061019e61058a565b3480156101e157600080fd5b5061019e6101f03660046128d0565b610595565b34801561020157600080fd5b506100ca610210366004612727565b6105a7565b34801561022157600080fd5b5061019e610619565b60606308b1869860e01b826040516024016102459190612f8f565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290505b919050565b805160208201fd5b60006102d3600084848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929392505063ffffffff610624169050565b9050630f47261b60e41b6001600160e01b031982168114156103e957600354604051630c0e082160e31b81526000916001600160a01b03169063607041089061032090859060040161305b565b60206040518083038186803b15801561033857600080fd5b505afa15801561034c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506103709190810190612745565b90506001600160a01b03811661038b5761038b6100c5610662565b60006103d7601087878080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929392505063ffffffff61068e169050565b90506103e681836000196106c1565b50505b50505050565b6103f761071e565b6104408184848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929392505063ffffffff61074d169050565b505050565b6000546001600160a01b031681565b60008060006104638585610763565b9050610470878288610892565b90935091508083111561048a5761048a6100c58434610a8c565b61049a818463ffffffff610ae316565b90506104a581610b02565b5094509492505050565b600080348611156104c7576104c76100c58734610b97565b60006104d38585610763565b9050868110156104ea576104ea6100c58289610a8c565b6104f5888888610bb4565b90935091508683101561050f5761050f6100c58885610b97565b61051f818463ffffffff610ae316565b905061052a81610b02565b509550959350505050565b60008060006105448585610763565b9050610551888888610cd5565b90935091508083111561050f5761050f6100c58434610a8c565b63bc197c8160e01b98975050505050505050565b63f23a6e6160e01b81565b630ee0a03f60e31b81565b63f23a6e6160e01b9695505050505050565b6105af61071e565b6001600160a01b0381166105cd576105c86100c5610fb9565b610616565b600080546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35b50565b63bc197c8160e01b81565b60008160040183511015610645576106456100c56003855185600401610fd7565b5060208183018101519101906001600160e01b0319165b92915050565b6040805160048152602481019091526020810180516001600160e01b031663f3b96b8d60e01b17905290565b600081601401835110156106af576106af6100c56004855185601401610fd7565b5001601401516001600160a01b031690565b60405160609063095ea7b360e01b906106e09085908590602401613040565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506103e98482611032565b6000546001600160a01b0316331461074b5760005461074b906100c59033906001600160a01b03166110dd565b565b61075f8230338463ffffffff6110fa16565b5050565b8151815160009190811461077f5761077f6100c582855161120f565b34915060005b81811461082157600085828151811061079a57fe5b60200260200101519050808410156107b9576107b96100c5828661122c565b6107c9848263ffffffff610ae316565b93508482815181106107d757fe5b60200260200101516001600160a01b03166108fc829081150290604051600060405180830381858888f19350505050158015610817573d6000803e3d6000fd5b5050600101610785565b50600160009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0836040518263ffffffff1660e01b81526004016000604051808303818588803b15801561087257600080fd5b505af1158015610886573d6000803e3d6000fd5b50505050505092915050565b600080600061092d600360009054906101000a90046001600160a01b03166001600160a01b0316631ce4c78b6040518163ffffffff1660e01b815260040160206040518083038186803b1580156108e857600080fd5b505afa1580156108fc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506109209190810190612bf9565b3a9063ffffffff61124916565b905060005b86518114610a825786818151811061094657fe5b60200260200101516080015160001480610977575086818151811061096757fe5b602002602001015160a001516000145b1561098157610a7a565b6000610993878663ffffffff610ae316565b905060006109b38984815181106109a657fe5b602002602001015161127a565b6109bd57836109c0565b60005b9050808211156109e1576109da828263ffffffff610ae316565b91506109e8565b5050610a82565b6109f0612078565b610a218a85815181106109ff57fe5b6020026020010151898681518110610a1357fe5b6020026020010151856112be565b60408101518151919250610a4c91610a40908a9063ffffffff61158216565b9063ffffffff61158216565b9650610a6581602001518761158290919063ffffffff16565b9550888710610a7657505050610a82565b5050505b600101610932565b5050935093915050565b606063cdcbed5d60e01b8383604051602401610aa99291906130f4565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152905092915050565b600082821115610afc57610afc6100c56002858561159a565b50900390565b801561061657600154604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90610b389084906004016130e6565b600060405180830381600087803b158015610b5257600080fd5b505af1158015610b66573d6000803e3d6000fd5b505060405133925083156108fc02915083906000818181858888f1935050505015801561075f573d6000803e3d6000fd5b606063450a021960e01b8383604051602401610aa99291906130f4565b60008080805b86518114610cb957868181518110610bce57fe5b60200260200101516080015160001480610bff5750868181518110610bef57fe5b602002602001015160a001516000145b15610c0957610cb1565b6000610c1b878663ffffffff610ae316565b9050610c25612078565b610c56898481518110610c3457fe5b6020026020010151888581518110610c4857fe5b6020026020010151846112be565b8051909150610c6c90879063ffffffff61158216565b9550610c8581602001518661158290919063ffffffff16565b9450610c9e81604001518561158290919063ffffffff16565b9350878610610cae575050610cb9565b50505b600101610bba565b50610cca838263ffffffff61158216565b925050935093915050565b82516000908190815b818114610f9a57868181518110610cf157fe5b60200260200101516080015160001480610d225750868181518110610d1257fe5b602002602001015160a001516000145b15610d2c57610f92565b6000610d3e878563ffffffff610ae316565b90506000610d6e60008a8581518110610d5357fe5b6020026020010151610140015161062490919063ffffffff16565b90506000806001600160e01b0319831663dc1600f360e01b1415610e3a57610db860108c8781518110610d9d57fe5b6020026020010151610140015161068e90919063ffffffff16565b6040516370a0823160e01b81529092506001600160a01b038316906370a0823190610de7903090600401612f8f565b60206040518083038186803b158015610dff57600080fd5b505afa158015610e13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610e379190810190612bf9565b90505b600080610e6e8d8881518110610e4c57fe5b60200260200101518c8981518110610e6057fe5b6020026020010151886115b9565b90925090506001600160e01b0319851663dc1600f360e01b1415610f2a576040516370a0823160e01b81526000906001600160a01b038616906370a0823190610ebb903090600401612f8f565b60206040518083038186803b158015610ed357600080fd5b505afa158015610ee7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610f0b9190810190612bf9565b9050610f26610f20828663ffffffff610ae316565b836116f2565b9150505b610f55818e8981518110610f3a57fe5b6020026020010151610140015161074d90919063ffffffff16565b610f658a8363ffffffff61158216565b9950610f77898263ffffffff61158216565b98508b8910610f8b57505050505050610f9a565b5050505050505b600101610cde565b5084821015610fb057610fb06100c58684611709565b50935093915050565b604080518082019091526004815263734f6e1f60e11b602082015290565b6060632800659560e01b848484604051602401610ff693929190613095565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290505b9392505050565b60006060836001600160a01b03168360405161104e9190612f83565b6000604051808303816000865af19150503d806000811461108b576040519150601f19603f3d011682016040523d82523d6000602084013e611090565b606091505b509150915081156110d45780516110a857505061075f565b8051602014156110d45760006110bf826000611726565b905080600114156110d25750505061075f565b505b6103e98161027f565b6060631de45ad160e01b8383604051602401610aa9929190612f9d565b80611104576103e9565b6000611116858263ffffffff61062416565b90506001600160e01b03198116630f47261b60e41b148061114757506001600160e01b0319811663dc1600f360e01b145b156111635761115e8585858563ffffffff61173216565b611208565b6001600160e01b0319811663012b8bc960e11b141561118e5761115e8585858563ffffffff61176f16565b6001600160e01b0319811663a7cb5fb760e01b14156111b95761115e8585858563ffffffff61181816565b6001600160e01b031981166394cfcdd760e01b14156111e45761115e8585858563ffffffff61194816565b6001600160e01b0319811663619ce88560e11b14611208576112086100c5826119dc565b5050505050565b6060633ecb6ceb60e01b8383604051602401610aa99291906130f4565b606063ecf40fd960e01b8383604051602401610aa99291906130f4565b6000826112585750600061065c565b8282028284828161126557fe5b041461102b5761102b6100c56001868661159a565b600060038261018001515111801561065c5750610180820151630ee0a03f60e31b906112ad90600063ffffffff61062416565b6001600160e01b0319161492915050565b6112c6612078565b6101408401516000906112df908263ffffffff61062416565b90506000806001600160e01b0319831663dc1600f360e01b14156113965761014087015161131490601063ffffffff61068e16565b6040516370a0823160e01b81529092506001600160a01b038316906370a0823190611343903090600401612f8f565b60206040518083038186803b15801561135b57600080fd5b505afa15801561136f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506113939190810190612bf9565b90505b60e087015115806113b657506113b6876101a001518861014001516119f7565b15611404576113c3612099565b6113ce888789611af8565b6020810151865260808101516040870152606081015181519192506113f9919063ffffffff610ae316565b6020860152506114a0565b611418876101a001518861016001516119f7565b1561148f5760a087015160e08801516000916114459161143f90829063ffffffff61158216565b88611b33565b905061144f612099565b61145a89838a611af8565b90506114778160600151826020015161158290919063ffffffff16565b865280516020870152608001516040860152506114a0565b6114a06100c5886101a00151611b69565b6001600160e01b0319831663dc1600f360e01b141561155e576040516370a0823160e01b81526000906001600160a01b038416906370a08231906114e8903090600401612f8f565b60206040518083038186803b15801561150057600080fd5b505afa158015611514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506115389190810190612bf9565b905061155761154d828463ffffffff610ae316565b86602001516116f2565b6020860152505b60208401516101408801516115789163ffffffff61074d16565b5050509392505050565b60008282018381101561102b5761102b6100c5600086865b606063e946c1bb60e01b848484604051602401610ff69392919061307a565b6000808460e00151600014806115de57506115de856101a001518661016001516119f7565b156116405760006115f88660a00151876080015186611b33565b9050611602612099565b61160d878388611af8565b90506116328160800151610a408360600151846020015161158290919063ffffffff16565b905190935091506116ea9050565b611654856101a001518661014001516119f7565b156116d95760006116848660a0015161167e8860e001518960800151610ae390919063ffffffff16565b86611b33565b905061168e612099565b611699878388611af8565b90506116b68160800151826020015161158290919063ffffffff16565b606082015182519195506116d0919063ffffffff610ae316565b925050506116ea565b6116ea6100c5866101a00151611b69565b935093915050565b600081831015611702578161102b565b5090919050565b60606391353a0c60e01b8383604051602401610aa99291906130f4565b600061102b8383611b84565b600061174585601063ffffffff61068e16565b90506001600160a01b0384163014156117635761115e818484611bae565b61120881858585611bcd565b80600114611783576117836100c582611c2c565b600061179685601063ffffffff61068e16565b905060006117ab86602463ffffffff61172616565b6040516323b872dd60e01b81529091506001600160a01b038316906323b872dd906117de90889088908690600401613018565b600060405180830381600087803b1580156117f857600080fd5b505af115801561180c573d6000803e3d6000fd5b50505050505050505050565b60006060806060611836600489518a611c479092919063ffffffff16565b8060200190516118499190810190612763565b9350935093509350600082519050606081604051908082528060200260200182016040528015611883578160200160208202803883390190505b50905060005b8281146118d5576118b6888683815181106118a057fe5b602002602001015161124990919063ffffffff16565b8282815181106118c257fe5b6020908102919091010152600101611889565b50604051631759616b60e11b81526001600160a01b03871690632eb2c2d69061190a908c908c908a9087908a90600401612fb8565b600060405180830381600087803b15801561192457600080fd5b505af1158015611938573d6000803e3d6000fd5b5050505050505050505050505050565b6060806119626004875188611c479092919063ffffffff16565b8060200190516119759190810190612adf565b8051919350915060005b8181146119d2576119ca83828151811061199557fe5b602002602001015188886119c58886815181106119ae57fe5b60200260200101518a61124990919063ffffffff16565b6110fa565b60010161197f565b5050505050505050565b6060637996a27160e01b82604051602401610245919061305b565b600080611a0a848263ffffffff61062416565b90506000611a1e848263ffffffff61062416565b9050630f47261b60e41b63dc1600f360e01b6001600160e01b03198416821480611a5457506001600160e01b0319848116908216145b8015611a8257506001600160e01b03198381169083161480611a8257506001600160e01b0319838116908216145b15611ad3576000611a9a88601063ffffffff61068e16565b90506000611aaf88601063ffffffff61068e16565b9050806001600160a01b0316826001600160a01b031614965050505050505061065c565b611ae3878763ffffffff611cc716565b94505050505061065c565b5050505092915050565b611b00612099565b611b098461127a565b15611b2057611b19848484611cec565b905061102b565b611b2b848484611ea7565b949350505050565b6000611b2b83611b5d611b4d82600163ffffffff610ae316565b610a40888763ffffffff61124916565b9063ffffffff611fa316565b60606331360af160e01b826040516024016102459190613069565b60008160200183511015611ba557611ba56100c56005855185602001610fd7565b50016020015190565b60405160609063a9059cbb60e01b906106e09085908590602401613040565b6040516060906323b872dd60e01b90611bee90869086908690602401613018565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506112088582611032565b606063baffa47460e01b8260405160240161024591906130e6565b606081831115611c6057611c606100c560008585610fd7565b8351821115611c7957611c796100c56001848751610fd7565b8282036040519080825280601f01601f191660200182016040528015611ca6576020820181803883390190505b50905061102b611cb582611fcd565b84611cbf87611fcd565b018351611fd3565b60008151835114801561102b5750508051602091820120825192909101919091201490565b611cf4612099565b611cfc6120c8565b60405180610180016040528086600001516001600160a01b0316815260200186602001516001600160a01b0316815260200186604001516001600160a01b0316815260200186606001516001600160a01b03168152602001866080015181526020018660a00151815260200160008152602001600081526020018661010001518152602001866101200151815260200186610140015181526020018661016001518152509050606060006001600160a01b031663b4be83d5905060e01b828686604051602401611dce939291906130d5565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925260045491519092506001600160a01b03909116906000906060908390611e27908690612f83565b6000604051808303816000865af19150503d8060008114611e64576040519150601f19603f3d011682016040523d82523d6000602084013e611e69565b606091505b50915091508115611e9b578051608014611e7f57fe5b80806020019051611e939190810190612c17565b602088015286525b50505050509392505050565b611eaf612099565b604051606090634da26aab60e11b90611ed0908790879087906024016130a3565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925260035491519092506001600160a01b03909116906000906060908390611f29908690612f83565b6000604051808303816000865af19150503d8060008114611f66576040519150601f19603f3d011682016040523d82523d6000602084013e611f6b565b606091505b50915091508115611f9857805160a014611f8157fe5b80806020019051611f959190810190612bdb565b94505b505050509392505050565b600081611fb957611fb96100c56003858561159a565b6000828481611fc457fe5b04949350505050565b60200190565b6020811015611ffd576001816020036101000a038019835116818551168082178652505050610440565b8282141561200a57610440565b828211156120445760208103905080820181840181515b8285101561203c578451865260209586019590940193612021565b905250610440565b60208103905080820181840183515b8186121561206f5782518252601f199283019290910190612053565b85525050505050565b60405180606001604052806000815260200160008152602001600081525090565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b60405180610180016040528060006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160608152602001606081525090565b803561065c81613223565b805161065c81613223565b600082601f83011261217457600080fd5b813561218761218282613128565b613102565b915081818352602084019350602081019050838560208402820111156121ac57600080fd5b60005b83811015611aee57816121c2888261214d565b84525060209283019291909101906001016121af565b600082601f8301126121e957600080fd5b81516121f761218282613128565b81815260209384019390925082018360005b83811015611aee578151860161221f88826124a7565b8452506020928301929190910190600101612209565b600082601f83011261224657600080fd5b813561225461218282613128565b81815260209384019390925082018360005b83811015611aee578135860161227c8882612458565b8452506020928301929190910190600101612266565b600082601f8301126122a357600080fd5b81356122b161218282613128565b81815260209384019390925082018360005b83811015611aee57813586016122d98882612570565b84525060209283019291909101906001016122c3565b60008083601f84011261230157600080fd5b5081356001600160401b0381111561231857600080fd5b60208301915083602082028301111561233057600080fd5b9250929050565b600082601f83011261234857600080fd5b815161235661218282613128565b9150818183526020840193506020810190508385602084028201111561237b57600080fd5b60005b83811015611aee5781612391888261271c565b845250602092830192919091019060010161237e565b600082601f8301126123b857600080fd5b81356123c661218282613128565b915081818352602084019350602081019050838560208402820111156123eb57600080fd5b60005b83811015611aee57816124018882612711565b84525060209283019291909101906001016123ee565b60008083601f84011261242957600080fd5b5081356001600160401b0381111561244057600080fd5b60208301915083600182028301111561233057600080fd5b600082601f83011261246957600080fd5b813561247761218282613148565b9150808252602083016020830185838301111561249357600080fd5b61249e8382846131cd565b50505092915050565b600082601f8301126124b857600080fd5b81516124c661218282613148565b915080825260208301602083018583830111156124e257600080fd5b61249e8382846131d9565b600060a082840312156124ff57600080fd5b61250960a0613102565b90506000612517848461271c565b82525060206125288484830161271c565b602083015250604061253c8482850161271c565b60408301525060606125508482850161271c565b60608301525060806125648482850161271c565b60808301525092915050565b60006101c0828403121561258357600080fd5b61258e6101c0613102565b9050600061259c848461214d565b82525060206125ad8484830161214d565b60208301525060406125c18482850161214d565b60408301525060606125d58482850161214d565b60608301525060806125e984828501612711565b60808301525060a06125fd84828501612711565b60a08301525060c061261184828501612711565b60c08301525060e061262584828501612711565b60e08301525061010061263a84828501612711565b6101008301525061012061265084828501612711565b610120830152506101408201356001600160401b0381111561267157600080fd5b61267d84828501612458565b610140830152506101608201356001600160401b0381111561269e57600080fd5b6126aa84828501612458565b610160830152506101808201356001600160401b038111156126cb57600080fd5b6126d784828501612458565b610180830152506101a08201356001600160401b038111156126f857600080fd5b61270484828501612458565b6101a08301525092915050565b803561065c81613237565b805161065c81613237565b60006020828403121561273957600080fd5b6000611b2b848461214d565b60006020828403121561275757600080fd5b6000611b2b8484612158565b6000806000806080858703121561277957600080fd5b60006127858787612158565b94505060208501516001600160401b038111156127a157600080fd5b6127ad87828801612337565b93505060408501516001600160401b038111156127c957600080fd5b6127d587828801612337565b92505060608501516001600160401b038111156127f157600080fd5b6127fd878288016124a7565b91505092959194509250565b60008060008060008060008060a0898b03121561282557600080fd5b60006128318b8b61214d565b98505060206128428b828c0161214d565b97505060408901356001600160401b0381111561285e57600080fd5b61286a8b828c016122ef565b965096505060608901356001600160401b0381111561288857600080fd5b6128948b828c016122ef565b945094505060808901356001600160401b038111156128b257600080fd5b6128be8b828c01612417565b92509250509295985092959890939650565b60008060008060008060a087890312156128e957600080fd5b60006128f5898961214d565b965050602061290689828a0161214d565b955050604061291789828a01612711565b945050606061292889828a01612711565b93505060808701356001600160401b0381111561294457600080fd5b61295089828a01612417565b92509250509295509295509295565b6000806000806080858703121561297557600080fd5b84356001600160401b0381111561298b57600080fd5b61299787828801612292565b94505060208501356001600160401b038111156129b357600080fd5b6129bf87828801612235565b93505060408501356001600160401b038111156129db57600080fd5b6129e7878288016123a7565b92505060608501356001600160401b03811115612a0357600080fd5b6127fd87828801612163565b600080600080600060a08688031215612a2757600080fd5b85356001600160401b03811115612a3d57600080fd5b612a4988828901612292565b9550506020612a5a88828901612711565b94505060408601356001600160401b03811115612a7657600080fd5b612a8288828901612235565b93505060608601356001600160401b03811115612a9e57600080fd5b612aaa888289016123a7565b92505060808601356001600160401b03811115612ac657600080fd5b612ad288828901612163565b9150509295509295909350565b60008060408385031215612af257600080fd5b82516001600160401b03811115612b0857600080fd5b612b1485828601612337565b92505060208301516001600160401b03811115612b3057600080fd5b612b3c858286016121d8565b9150509250929050565b60008060208385031215612b5957600080fd5b82356001600160401b03811115612b6f57600080fd5b612b7b85828601612417565b92509250509250929050565b600080600060408486031215612b9c57600080fd5b83356001600160401b03811115612bb257600080fd5b612bbe86828701612417565b93509350506020612bd186828701612711565b9150509250925092565b600060a08284031215612bed57600080fd5b6000611b2b84846124ed565b600060208284031215612c0b57600080fd5b6000611b2b848461271c565b60008060408385031215612c2a57600080fd5b6000612c36858561271c565b9250506020612b3c8582860161271c565b6000612c538383612f7a565b505060200190565b612c648161317c565b82525050565b6000612c758261316f565b612c7f8185613173565b9350612c8a83611fcd565b8060005b83811015612cb8578151612ca28882612c47565b9750612cad83611fcd565b925050600101612c8e565b509495945050505050565b612c6481613187565b6000612cd78261316f565b612ce18185613173565b9350612cf18185602086016131d9565b612cfa81613205565b9093019392505050565b6000612d0f8261316f565b612d19818561027a565b9350612d298185602086016131d9565b9290920192915050565b612c64816131b7565b612c64816131c2565b80516000906101c0840190612d5a8582612c5b565b506020830151612d6d6020860182612c5b565b506040830151612d806040860182612c5b565b506060830151612d936060860182612c5b565b506080830151612da66080860182612f7a565b5060a0830151612db960a0860182612f7a565b5060c0830151612dcc60c0860182612f7a565b5060e0830151612ddf60e0860182612f7a565b50610100830151612df4610100860182612f7a565b50610120830151612e09610120860182612f7a565b50610140830151848203610140860152612e238282612ccc565b915050610160830151848203610160860152612e3f8282612ccc565b915050610180830151848203610180860152612e5b8282612ccc565b9150506101a08301518482036101a0860152612e778282612ccc565b95945050505050565b8051600090610180840190612e958582612c5b565b506020830151612ea86020860182612c5b565b506040830151612ebb6040860182612c5b565b506060830151612ece6060860182612c5b565b506080830151612ee16080860182612f7a565b5060a0830151612ef460a0860182612f7a565b5060c0830151612f0760c0860182612f7a565b5060e0830151612f1a60e0860182612f7a565b50610100830151612f2f610100860182612f7a565b50610120830151612f44610120860182612f7a565b50610140830151848203610140860152612f5e8282612ccc565b915050610160830151848203610160860152612e778282612ccc565b612c64816131b4565b600061102b8284612d04565b6020810161065c8284612c5b565b60408101612fab8285612c5b565b61102b6020830184612c5b565b60a08101612fc68288612c5b565b612fd36020830187612c5b565b8181036040830152612fe58186612c6a565b90508181036060830152612ff98185612c6a565b9050818103608083015261300d8184612ccc565b979650505050505050565b606081016130268286612c5b565b6130336020830185612c5b565b611b2b6040830184612f7a565b6040810161304e8285612c5b565b61102b6020830184612f7a565b6020810161065c8284612cc3565b6020808252810161102b8184612ccc565b606081016130888286612d33565b6130336020830185612f7a565b606081016130888286612d3c565b606080825281016130b48186612d45565b90506130c36020830185612f7a565b8181036040830152612e778184612ccc565b606080825281016130b48186612e80565b6020810161065c8284612f7a565b6040810161304e8285612f7a565b6040518181016001600160401b038111828210171561312057600080fd5b604052919050565b60006001600160401b0382111561313e57600080fd5b5060209081020190565b60006001600160401b0382111561315e57600080fd5b506020601f91909101601f19160190565b5190565b90815260200190565b600061065c826131a8565b6001600160e01b03191690565b8061027a8161320f565b8061027a81613219565b6001600160a01b031690565b90565b600061065c82613194565b600061065c8261319e565b82818337506000910152565b60005b838110156131f45781810151838201526020016131dc565b838111156103e95750506000910152565b601f01601f191690565b6004811061061657fe5b6008811061061657fe5b61322c8161317c565b811461061657600080fd5b61322c816131b456fea365627a7a723158205ba344f84431786b3add62b5df363dfefbf78656c0fb939708d0e1f4476aa9606c6578706572696d656e74616cf564736f6c6343000510004000000000000000000000000061935cbdd02287b511119ddb11aeb42f1593b7ef000000000000000000000000080bf510fcbf18b91105470639e9561022937712000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

Deployed Bytecode

0x6080604052600436106100a75760003560e01c8063bc197c8111610064578063bc197c811461017e578063e0a5c949146101ab578063e196001b146101c0578063f23a6e61146101d5578063f2fde38b146101f5578063fc67bf1c14610215576100a7565b8063442026ed146100cc578063630f1e6c146100ec5780638da5cb5b1461010c578063907e5cc314610137578063939ce6ba146101585780639e8323151461016b575b6001546001600160a01b031633146100ca576100ca6100c53361022a565b61027f565b005b3480156100d857600080fd5b506100ca6100e7366004612b46565b610287565b3480156100f857600080fd5b506100ca610107366004612b87565b6103ef565b34801561011857600080fd5b50610121610445565b60405161012e9190612f8f565b60405180910390f35b61014a61014536600461295f565b610454565b60405161012e9291906130f4565b61014a610166366004612a0f565b6104af565b61014a610179366004612a0f565b610535565b34801561018a57600080fd5b5061019e610199366004612809565b61056b565b60405161012e919061305b565b3480156101b757600080fd5b5061019e61057f565b3480156101cc57600080fd5b5061019e61058a565b3480156101e157600080fd5b5061019e6101f03660046128d0565b610595565b34801561020157600080fd5b506100ca610210366004612727565b6105a7565b34801561022157600080fd5b5061019e610619565b60606308b1869860e01b826040516024016102459190612f8f565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290505b919050565b805160208201fd5b60006102d3600084848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929392505063ffffffff610624169050565b9050630f47261b60e41b6001600160e01b031982168114156103e957600354604051630c0e082160e31b81526000916001600160a01b03169063607041089061032090859060040161305b565b60206040518083038186803b15801561033857600080fd5b505afa15801561034c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506103709190810190612745565b90506001600160a01b03811661038b5761038b6100c5610662565b60006103d7601087878080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929392505063ffffffff61068e169050565b90506103e681836000196106c1565b50505b50505050565b6103f761071e565b6104408184848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929392505063ffffffff61074d169050565b505050565b6000546001600160a01b031681565b60008060006104638585610763565b9050610470878288610892565b90935091508083111561048a5761048a6100c58434610a8c565b61049a818463ffffffff610ae316565b90506104a581610b02565b5094509492505050565b600080348611156104c7576104c76100c58734610b97565b60006104d38585610763565b9050868110156104ea576104ea6100c58289610a8c565b6104f5888888610bb4565b90935091508683101561050f5761050f6100c58885610b97565b61051f818463ffffffff610ae316565b905061052a81610b02565b509550959350505050565b60008060006105448585610763565b9050610551888888610cd5565b90935091508083111561050f5761050f6100c58434610a8c565b63bc197c8160e01b98975050505050505050565b63f23a6e6160e01b81565b630ee0a03f60e31b81565b63f23a6e6160e01b9695505050505050565b6105af61071e565b6001600160a01b0381166105cd576105c86100c5610fb9565b610616565b600080546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35b50565b63bc197c8160e01b81565b60008160040183511015610645576106456100c56003855185600401610fd7565b5060208183018101519101906001600160e01b0319165b92915050565b6040805160048152602481019091526020810180516001600160e01b031663f3b96b8d60e01b17905290565b600081601401835110156106af576106af6100c56004855185601401610fd7565b5001601401516001600160a01b031690565b60405160609063095ea7b360e01b906106e09085908590602401613040565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506103e98482611032565b6000546001600160a01b0316331461074b5760005461074b906100c59033906001600160a01b03166110dd565b565b61075f8230338463ffffffff6110fa16565b5050565b8151815160009190811461077f5761077f6100c582855161120f565b34915060005b81811461082157600085828151811061079a57fe5b60200260200101519050808410156107b9576107b96100c5828661122c565b6107c9848263ffffffff610ae316565b93508482815181106107d757fe5b60200260200101516001600160a01b03166108fc829081150290604051600060405180830381858888f19350505050158015610817573d6000803e3d6000fd5b5050600101610785565b50600160009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0836040518263ffffffff1660e01b81526004016000604051808303818588803b15801561087257600080fd5b505af1158015610886573d6000803e3d6000fd5b50505050505092915050565b600080600061092d600360009054906101000a90046001600160a01b03166001600160a01b0316631ce4c78b6040518163ffffffff1660e01b815260040160206040518083038186803b1580156108e857600080fd5b505afa1580156108fc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506109209190810190612bf9565b3a9063ffffffff61124916565b905060005b86518114610a825786818151811061094657fe5b60200260200101516080015160001480610977575086818151811061096757fe5b602002602001015160a001516000145b1561098157610a7a565b6000610993878663ffffffff610ae316565b905060006109b38984815181106109a657fe5b602002602001015161127a565b6109bd57836109c0565b60005b9050808211156109e1576109da828263ffffffff610ae316565b91506109e8565b5050610a82565b6109f0612078565b610a218a85815181106109ff57fe5b6020026020010151898681518110610a1357fe5b6020026020010151856112be565b60408101518151919250610a4c91610a40908a9063ffffffff61158216565b9063ffffffff61158216565b9650610a6581602001518761158290919063ffffffff16565b9550888710610a7657505050610a82565b5050505b600101610932565b5050935093915050565b606063cdcbed5d60e01b8383604051602401610aa99291906130f4565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152905092915050565b600082821115610afc57610afc6100c56002858561159a565b50900390565b801561061657600154604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90610b389084906004016130e6565b600060405180830381600087803b158015610b5257600080fd5b505af1158015610b66573d6000803e3d6000fd5b505060405133925083156108fc02915083906000818181858888f1935050505015801561075f573d6000803e3d6000fd5b606063450a021960e01b8383604051602401610aa99291906130f4565b60008080805b86518114610cb957868181518110610bce57fe5b60200260200101516080015160001480610bff5750868181518110610bef57fe5b602002602001015160a001516000145b15610c0957610cb1565b6000610c1b878663ffffffff610ae316565b9050610c25612078565b610c56898481518110610c3457fe5b6020026020010151888581518110610c4857fe5b6020026020010151846112be565b8051909150610c6c90879063ffffffff61158216565b9550610c8581602001518661158290919063ffffffff16565b9450610c9e81604001518561158290919063ffffffff16565b9350878610610cae575050610cb9565b50505b600101610bba565b50610cca838263ffffffff61158216565b925050935093915050565b82516000908190815b818114610f9a57868181518110610cf157fe5b60200260200101516080015160001480610d225750868181518110610d1257fe5b602002602001015160a001516000145b15610d2c57610f92565b6000610d3e878563ffffffff610ae316565b90506000610d6e60008a8581518110610d5357fe5b6020026020010151610140015161062490919063ffffffff16565b90506000806001600160e01b0319831663dc1600f360e01b1415610e3a57610db860108c8781518110610d9d57fe5b6020026020010151610140015161068e90919063ffffffff16565b6040516370a0823160e01b81529092506001600160a01b038316906370a0823190610de7903090600401612f8f565b60206040518083038186803b158015610dff57600080fd5b505afa158015610e13573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610e379190810190612bf9565b90505b600080610e6e8d8881518110610e4c57fe5b60200260200101518c8981518110610e6057fe5b6020026020010151886115b9565b90925090506001600160e01b0319851663dc1600f360e01b1415610f2a576040516370a0823160e01b81526000906001600160a01b038616906370a0823190610ebb903090600401612f8f565b60206040518083038186803b158015610ed357600080fd5b505afa158015610ee7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610f0b9190810190612bf9565b9050610f26610f20828663ffffffff610ae316565b836116f2565b9150505b610f55818e8981518110610f3a57fe5b6020026020010151610140015161074d90919063ffffffff16565b610f658a8363ffffffff61158216565b9950610f77898263ffffffff61158216565b98508b8910610f8b57505050505050610f9a565b5050505050505b600101610cde565b5084821015610fb057610fb06100c58684611709565b50935093915050565b604080518082019091526004815263734f6e1f60e11b602082015290565b6060632800659560e01b848484604051602401610ff693929190613095565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290505b9392505050565b60006060836001600160a01b03168360405161104e9190612f83565b6000604051808303816000865af19150503d806000811461108b576040519150601f19603f3d011682016040523d82523d6000602084013e611090565b606091505b509150915081156110d45780516110a857505061075f565b8051602014156110d45760006110bf826000611726565b905080600114156110d25750505061075f565b505b6103e98161027f565b6060631de45ad160e01b8383604051602401610aa9929190612f9d565b80611104576103e9565b6000611116858263ffffffff61062416565b90506001600160e01b03198116630f47261b60e41b148061114757506001600160e01b0319811663dc1600f360e01b145b156111635761115e8585858563ffffffff61173216565b611208565b6001600160e01b0319811663012b8bc960e11b141561118e5761115e8585858563ffffffff61176f16565b6001600160e01b0319811663a7cb5fb760e01b14156111b95761115e8585858563ffffffff61181816565b6001600160e01b031981166394cfcdd760e01b14156111e45761115e8585858563ffffffff61194816565b6001600160e01b0319811663619ce88560e11b14611208576112086100c5826119dc565b5050505050565b6060633ecb6ceb60e01b8383604051602401610aa99291906130f4565b606063ecf40fd960e01b8383604051602401610aa99291906130f4565b6000826112585750600061065c565b8282028284828161126557fe5b041461102b5761102b6100c56001868661159a565b600060038261018001515111801561065c5750610180820151630ee0a03f60e31b906112ad90600063ffffffff61062416565b6001600160e01b0319161492915050565b6112c6612078565b6101408401516000906112df908263ffffffff61062416565b90506000806001600160e01b0319831663dc1600f360e01b14156113965761014087015161131490601063ffffffff61068e16565b6040516370a0823160e01b81529092506001600160a01b038316906370a0823190611343903090600401612f8f565b60206040518083038186803b15801561135b57600080fd5b505afa15801561136f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506113939190810190612bf9565b90505b60e087015115806113b657506113b6876101a001518861014001516119f7565b15611404576113c3612099565b6113ce888789611af8565b6020810151865260808101516040870152606081015181519192506113f9919063ffffffff610ae316565b6020860152506114a0565b611418876101a001518861016001516119f7565b1561148f5760a087015160e08801516000916114459161143f90829063ffffffff61158216565b88611b33565b905061144f612099565b61145a89838a611af8565b90506114778160600151826020015161158290919063ffffffff16565b865280516020870152608001516040860152506114a0565b6114a06100c5886101a00151611b69565b6001600160e01b0319831663dc1600f360e01b141561155e576040516370a0823160e01b81526000906001600160a01b038416906370a08231906114e8903090600401612f8f565b60206040518083038186803b15801561150057600080fd5b505afa158015611514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506115389190810190612bf9565b905061155761154d828463ffffffff610ae316565b86602001516116f2565b6020860152505b60208401516101408801516115789163ffffffff61074d16565b5050509392505050565b60008282018381101561102b5761102b6100c5600086865b606063e946c1bb60e01b848484604051602401610ff69392919061307a565b6000808460e00151600014806115de57506115de856101a001518661016001516119f7565b156116405760006115f88660a00151876080015186611b33565b9050611602612099565b61160d878388611af8565b90506116328160800151610a408360600151846020015161158290919063ffffffff16565b905190935091506116ea9050565b611654856101a001518661014001516119f7565b156116d95760006116848660a0015161167e8860e001518960800151610ae390919063ffffffff16565b86611b33565b905061168e612099565b611699878388611af8565b90506116b68160800151826020015161158290919063ffffffff16565b606082015182519195506116d0919063ffffffff610ae316565b925050506116ea565b6116ea6100c5866101a00151611b69565b935093915050565b600081831015611702578161102b565b5090919050565b60606391353a0c60e01b8383604051602401610aa99291906130f4565b600061102b8383611b84565b600061174585601063ffffffff61068e16565b90506001600160a01b0384163014156117635761115e818484611bae565b61120881858585611bcd565b80600114611783576117836100c582611c2c565b600061179685601063ffffffff61068e16565b905060006117ab86602463ffffffff61172616565b6040516323b872dd60e01b81529091506001600160a01b038316906323b872dd906117de90889088908690600401613018565b600060405180830381600087803b1580156117f857600080fd5b505af115801561180c573d6000803e3d6000fd5b50505050505050505050565b60006060806060611836600489518a611c479092919063ffffffff16565b8060200190516118499190810190612763565b9350935093509350600082519050606081604051908082528060200260200182016040528015611883578160200160208202803883390190505b50905060005b8281146118d5576118b6888683815181106118a057fe5b602002602001015161124990919063ffffffff16565b8282815181106118c257fe5b6020908102919091010152600101611889565b50604051631759616b60e11b81526001600160a01b03871690632eb2c2d69061190a908c908c908a9087908a90600401612fb8565b600060405180830381600087803b15801561192457600080fd5b505af1158015611938573d6000803e3d6000fd5b5050505050505050505050505050565b6060806119626004875188611c479092919063ffffffff16565b8060200190516119759190810190612adf565b8051919350915060005b8181146119d2576119ca83828151811061199557fe5b602002602001015188886119c58886815181106119ae57fe5b60200260200101518a61124990919063ffffffff16565b6110fa565b60010161197f565b5050505050505050565b6060637996a27160e01b82604051602401610245919061305b565b600080611a0a848263ffffffff61062416565b90506000611a1e848263ffffffff61062416565b9050630f47261b60e41b63dc1600f360e01b6001600160e01b03198416821480611a5457506001600160e01b0319848116908216145b8015611a8257506001600160e01b03198381169083161480611a8257506001600160e01b0319838116908216145b15611ad3576000611a9a88601063ffffffff61068e16565b90506000611aaf88601063ffffffff61068e16565b9050806001600160a01b0316826001600160a01b031614965050505050505061065c565b611ae3878763ffffffff611cc716565b94505050505061065c565b5050505092915050565b611b00612099565b611b098461127a565b15611b2057611b19848484611cec565b905061102b565b611b2b848484611ea7565b949350505050565b6000611b2b83611b5d611b4d82600163ffffffff610ae316565b610a40888763ffffffff61124916565b9063ffffffff611fa316565b60606331360af160e01b826040516024016102459190613069565b60008160200183511015611ba557611ba56100c56005855185602001610fd7565b50016020015190565b60405160609063a9059cbb60e01b906106e09085908590602401613040565b6040516060906323b872dd60e01b90611bee90869086908690602401613018565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506112088582611032565b606063baffa47460e01b8260405160240161024591906130e6565b606081831115611c6057611c606100c560008585610fd7565b8351821115611c7957611c796100c56001848751610fd7565b8282036040519080825280601f01601f191660200182016040528015611ca6576020820181803883390190505b50905061102b611cb582611fcd565b84611cbf87611fcd565b018351611fd3565b60008151835114801561102b5750508051602091820120825192909101919091201490565b611cf4612099565b611cfc6120c8565b60405180610180016040528086600001516001600160a01b0316815260200186602001516001600160a01b0316815260200186604001516001600160a01b0316815260200186606001516001600160a01b03168152602001866080015181526020018660a00151815260200160008152602001600081526020018661010001518152602001866101200151815260200186610140015181526020018661016001518152509050606060006001600160a01b031663b4be83d5905060e01b828686604051602401611dce939291906130d5565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925260045491519092506001600160a01b03909116906000906060908390611e27908690612f83565b6000604051808303816000865af19150503d8060008114611e64576040519150601f19603f3d011682016040523d82523d6000602084013e611e69565b606091505b50915091508115611e9b578051608014611e7f57fe5b80806020019051611e939190810190612c17565b602088015286525b50505050509392505050565b611eaf612099565b604051606090634da26aab60e11b90611ed0908790879087906024016130a3565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925260035491519092506001600160a01b03909116906000906060908390611f29908690612f83565b6000604051808303816000865af19150503d8060008114611f66576040519150601f19603f3d011682016040523d82523d6000602084013e611f6b565b606091505b50915091508115611f9857805160a014611f8157fe5b80806020019051611f959190810190612bdb565b94505b505050509392505050565b600081611fb957611fb96100c56003858561159a565b6000828481611fc457fe5b04949350505050565b60200190565b6020811015611ffd576001816020036101000a038019835116818551168082178652505050610440565b8282141561200a57610440565b828211156120445760208103905080820181840181515b8285101561203c578451865260209586019590940193612021565b905250610440565b60208103905080820181840183515b8186121561206f5782518252601f199283019290910190612053565b85525050505050565b60405180606001604052806000815260200160008152602001600081525090565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b60405180610180016040528060006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160006001600160a01b0316815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160608152602001606081525090565b803561065c81613223565b805161065c81613223565b600082601f83011261217457600080fd5b813561218761218282613128565b613102565b915081818352602084019350602081019050838560208402820111156121ac57600080fd5b60005b83811015611aee57816121c2888261214d565b84525060209283019291909101906001016121af565b600082601f8301126121e957600080fd5b81516121f761218282613128565b81815260209384019390925082018360005b83811015611aee578151860161221f88826124a7565b8452506020928301929190910190600101612209565b600082601f83011261224657600080fd5b813561225461218282613128565b81815260209384019390925082018360005b83811015611aee578135860161227c8882612458565b8452506020928301929190910190600101612266565b600082601f8301126122a357600080fd5b81356122b161218282613128565b81815260209384019390925082018360005b83811015611aee57813586016122d98882612570565b84525060209283019291909101906001016122c3565b60008083601f84011261230157600080fd5b5081356001600160401b0381111561231857600080fd5b60208301915083602082028301111561233057600080fd5b9250929050565b600082601f83011261234857600080fd5b815161235661218282613128565b9150818183526020840193506020810190508385602084028201111561237b57600080fd5b60005b83811015611aee5781612391888261271c565b845250602092830192919091019060010161237e565b600082601f8301126123b857600080fd5b81356123c661218282613128565b915081818352602084019350602081019050838560208402820111156123eb57600080fd5b60005b83811015611aee57816124018882612711565b84525060209283019291909101906001016123ee565b60008083601f84011261242957600080fd5b5081356001600160401b0381111561244057600080fd5b60208301915083600182028301111561233057600080fd5b600082601f83011261246957600080fd5b813561247761218282613148565b9150808252602083016020830185838301111561249357600080fd5b61249e8382846131cd565b50505092915050565b600082601f8301126124b857600080fd5b81516124c661218282613148565b915080825260208301602083018583830111156124e257600080fd5b61249e8382846131d9565b600060a082840312156124ff57600080fd5b61250960a0613102565b90506000612517848461271c565b82525060206125288484830161271c565b602083015250604061253c8482850161271c565b60408301525060606125508482850161271c565b60608301525060806125648482850161271c565b60808301525092915050565b60006101c0828403121561258357600080fd5b61258e6101c0613102565b9050600061259c848461214d565b82525060206125ad8484830161214d565b60208301525060406125c18482850161214d565b60408301525060606125d58482850161214d565b60608301525060806125e984828501612711565b60808301525060a06125fd84828501612711565b60a08301525060c061261184828501612711565b60c08301525060e061262584828501612711565b60e08301525061010061263a84828501612711565b6101008301525061012061265084828501612711565b610120830152506101408201356001600160401b0381111561267157600080fd5b61267d84828501612458565b610140830152506101608201356001600160401b0381111561269e57600080fd5b6126aa84828501612458565b610160830152506101808201356001600160401b038111156126cb57600080fd5b6126d784828501612458565b610180830152506101a08201356001600160401b038111156126f857600080fd5b61270484828501612458565b6101a08301525092915050565b803561065c81613237565b805161065c81613237565b60006020828403121561273957600080fd5b6000611b2b848461214d565b60006020828403121561275757600080fd5b6000611b2b8484612158565b6000806000806080858703121561277957600080fd5b60006127858787612158565b94505060208501516001600160401b038111156127a157600080fd5b6127ad87828801612337565b93505060408501516001600160401b038111156127c957600080fd5b6127d587828801612337565b92505060608501516001600160401b038111156127f157600080fd5b6127fd878288016124a7565b91505092959194509250565b60008060008060008060008060a0898b03121561282557600080fd5b60006128318b8b61214d565b98505060206128428b828c0161214d565b97505060408901356001600160401b0381111561285e57600080fd5b61286a8b828c016122ef565b965096505060608901356001600160401b0381111561288857600080fd5b6128948b828c016122ef565b945094505060808901356001600160401b038111156128b257600080fd5b6128be8b828c01612417565b92509250509295985092959890939650565b60008060008060008060a087890312156128e957600080fd5b60006128f5898961214d565b965050602061290689828a0161214d565b955050604061291789828a01612711565b945050606061292889828a01612711565b93505060808701356001600160401b0381111561294457600080fd5b61295089828a01612417565b92509250509295509295509295565b6000806000806080858703121561297557600080fd5b84356001600160401b0381111561298b57600080fd5b61299787828801612292565b94505060208501356001600160401b038111156129b357600080fd5b6129bf87828801612235565b93505060408501356001600160401b038111156129db57600080fd5b6129e7878288016123a7565b92505060608501356001600160401b03811115612a0357600080fd5b6127fd87828801612163565b600080600080600060a08688031215612a2757600080fd5b85356001600160401b03811115612a3d57600080fd5b612a4988828901612292565b9550506020612a5a88828901612711565b94505060408601356001600160401b03811115612a7657600080fd5b612a8288828901612235565b93505060608601356001600160401b03811115612a9e57600080fd5b612aaa888289016123a7565b92505060808601356001600160401b03811115612ac657600080fd5b612ad288828901612163565b9150509295509295909350565b60008060408385031215612af257600080fd5b82516001600160401b03811115612b0857600080fd5b612b1485828601612337565b92505060208301516001600160401b03811115612b3057600080fd5b612b3c858286016121d8565b9150509250929050565b60008060208385031215612b5957600080fd5b82356001600160401b03811115612b6f57600080fd5b612b7b85828601612417565b92509250509250929050565b600080600060408486031215612b9c57600080fd5b83356001600160401b03811115612bb257600080fd5b612bbe86828701612417565b93509350506020612bd186828701612711565b9150509250925092565b600060a08284031215612bed57600080fd5b6000611b2b84846124ed565b600060208284031215612c0b57600080fd5b6000611b2b848461271c565b60008060408385031215612c2a57600080fd5b6000612c36858561271c565b9250506020612b3c8582860161271c565b6000612c538383612f7a565b505060200190565b612c648161317c565b82525050565b6000612c758261316f565b612c7f8185613173565b9350612c8a83611fcd565b8060005b83811015612cb8578151612ca28882612c47565b9750612cad83611fcd565b925050600101612c8e565b509495945050505050565b612c6481613187565b6000612cd78261316f565b612ce18185613173565b9350612cf18185602086016131d9565b612cfa81613205565b9093019392505050565b6000612d0f8261316f565b612d19818561027a565b9350612d298185602086016131d9565b9290920192915050565b612c64816131b7565b612c64816131c2565b80516000906101c0840190612d5a8582612c5b565b506020830151612d6d6020860182612c5b565b506040830151612d806040860182612c5b565b506060830151612d936060860182612c5b565b506080830151612da66080860182612f7a565b5060a0830151612db960a0860182612f7a565b5060c0830151612dcc60c0860182612f7a565b5060e0830151612ddf60e0860182612f7a565b50610100830151612df4610100860182612f7a565b50610120830151612e09610120860182612f7a565b50610140830151848203610140860152612e238282612ccc565b915050610160830151848203610160860152612e3f8282612ccc565b915050610180830151848203610180860152612e5b8282612ccc565b9150506101a08301518482036101a0860152612e778282612ccc565b95945050505050565b8051600090610180840190612e958582612c5b565b506020830151612ea86020860182612c5b565b506040830151612ebb6040860182612c5b565b506060830151612ece6060860182612c5b565b506080830151612ee16080860182612f7a565b5060a0830151612ef460a0860182612f7a565b5060c0830151612f0760c0860182612f7a565b5060e0830151612f1a60e0860182612f7a565b50610100830151612f2f610100860182612f7a565b50610120830151612f44610120860182612f7a565b50610140830151848203610140860152612f5e8282612ccc565b915050610160830151848203610160860152612e778282612ccc565b612c64816131b4565b600061102b8284612d04565b6020810161065c8284612c5b565b60408101612fab8285612c5b565b61102b6020830184612c5b565b60a08101612fc68288612c5b565b612fd36020830187612c5b565b8181036040830152612fe58186612c6a565b90508181036060830152612ff98185612c6a565b9050818103608083015261300d8184612ccc565b979650505050505050565b606081016130268286612c5b565b6130336020830185612c5b565b611b2b6040830184612f7a565b6040810161304e8285612c5b565b61102b6020830184612f7a565b6020810161065c8284612cc3565b6020808252810161102b8184612ccc565b606081016130888286612d33565b6130336020830185612f7a565b606081016130888286612d3c565b606080825281016130b48186612d45565b90506130c36020830185612f7a565b8181036040830152612e778184612ccc565b606080825281016130b48186612e80565b6020810161065c8284612f7a565b6040810161304e8285612f7a565b6040518181016001600160401b038111828210171561312057600080fd5b604052919050565b60006001600160401b0382111561313e57600080fd5b5060209081020190565b60006001600160401b0382111561315e57600080fd5b506020601f91909101601f19160190565b5190565b90815260200190565b600061065c826131a8565b6001600160e01b03191690565b8061027a8161320f565b8061027a81613219565b6001600160a01b031690565b90565b600061065c82613194565b600061065c8261319e565b82818337506000910152565b60005b838110156131f45781810151838201526020016131dc565b838111156103e95750506000910152565b601f01601f191690565b6004811061061657fe5b6008811061061657fe5b61322c8161317c565b811461061657600080fd5b61322c816131b456fea365627a7a723158205ba344f84431786b3add62b5df363dfefbf78656c0fb939708d0e1f4476aa9606c6578706572696d656e74616cf564736f6c63430005100040

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

00000000000000000000000061935cbdd02287b511119ddb11aeb42f1593b7ef000000000000000000000000080bf510fcbf18b91105470639e9561022937712000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

-----Decoded View---------------
Arg [0] : _exchange (address): 0x61935CbDd02287B511119DDb11Aeb42F1593b7Ef
Arg [1] : _exchangeV2 (address): 0x080bf510FCbF18b91105470639e9561022937712
Arg [2] : _weth (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 00000000000000000000000061935cbdd02287b511119ddb11aeb42f1593b7ef
Arg [1] : 000000000000000000000000080bf510fcbf18b91105470639e9561022937712
Arg [2] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2


Deployed Bytecode Sourcemap

187437:9770:0:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;142877:4;;-1:-1:-1;;;;;142877:4:0;142855:10;:27;142851:186;;142899:126;142921:103;142999:10;142921:59;:103::i;:::-;142899:21;:126::i;:::-;187437:9770;189029:722;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;189029:722:0;;;;;;;;:::i;188330:180::-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;188330:180:0;;;;;;;;:::i;148056:20::-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;148056:20:0;;;:::i;:::-;;;;;;;;;;;;;;;;190505:1417;;;;;;;;;:::i;:::-;;;;;;;;;192778:1973;;;;;;;;;:::i;195768:1436::-;;;;;;;;;:::i;182828:285::-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;182828:285:0;;;;;;;;:::i;:::-;;;;;;;;180646:58;;8:9:-1;5:2;;;30:1;27;20:12;5:2;180646:58:0;;;:::i;157300:56::-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;157300:56:0;;;:::i;181669:250::-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;181669:250:0;;;;;;;;:::i;148341:339::-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;-1:-1;148341:339:0;;;;;;;;:::i;180711:58::-;;8:9:-1;5:2;;;30:1;27;20:12;5:2;180711:58:0;;;:::i;140955:306::-;141090:12;140168:10;141164:50;;141229:13;141127:126;;;;;;;;;;;;;-1:-1:-1;;26:21;;;22:32;6:49;;141127:126:0;;;49:4:-1;25:18;;61:17;;-1:-1;;;;;182:15;-1:-1;;;;;;141127:126:0;;;179:29:-1;;;;160:49;;;141127:126:0;-1:-1:-1;140955:306:0;;;;:::o;17621:177::-;17769:9;17763:16;17756:4;17745:9;17741:20;17734:46;189029:722;189121:14;189138:23;189159:1;189138:9;;:20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;30:3:-1;22:6;14;1:33;99:1;81:16;;74:27;;;;-1:-1;189138:20:0;;:23;-1:-1:-1;;189138:23:0;:20;:23;;-1:-1:-1;189138:23:0:i;:::-;189121:40;-1:-1:-1;;;;;;;;;;189351:23:0;;;;189347:397;;;189414:8;;:36;;-1:-1:-1;;;189414:36:0;;189391:20;;-1:-1:-1;;;;;189414:8:0;;:22;;:36;;189437:12;;189414:36;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;189414:36:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;189414:36:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;189414:36:0;;;;;;;;;189391:59;-1:-1:-1;;;;;;189469:26:0;;189465:142;;189516:75;189538:52;:50;:52::i;189516:75::-;189621:13;189637:25;189659:2;189637:9;;:21;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;30:3:-1;22:6;14;1:33;99:1;81:16;;74:27;;;;-1:-1;189637:21:0;;:25;-1:-1:-1;;189637:25:0;:21;:25;;-1:-1:-1;189637:25:0:i;:::-;189621:41;;189677:55;189699:5;189706:12;-1:-1:-1;;189677:21:0;:55::i;:::-;189347:397;;;189029:722;;;;:::o;188330:180::-;148198:22;:20;:22::i;:::-;188473:29;188495:6;188473:9;;:21;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;30:3:-1;22:6;14;1:33;99:1;81:16;;74:27;;;;-1:-1;188473:21:0;;:29;-1:-1:-1;;188473:29:0;:21;:29;;-1:-1:-1;188473:29:0:i;:::-;188330:180;;;:::o;148056:20::-;;;-1:-1:-1;;;;;148056:20:0;;:::o;190505:1417::-;190777:23;190815:32;190940:21;190964:99;191011:13;191039;190964:32;:99::i;:::-;190940:123;;191292:103;191325:6;191346:13;191374:10;191292:18;:103::i;:::-;191209:186;;-1:-1:-1;191209:186:0;-1:-1:-1;191489:31:0;;;191485:205;;;191537:141;191559:118;191619:15;191653:9;191559:41;:118::i;191537:141::-;191779:38;:13;191801:15;191779:38;:21;:38;:::i;:::-;191763:54;;191878:36;191900:13;191878:21;:36::i;:::-;190505:1417;;;;;;;;:::o;192778:1973::-;193082:23;193120:32;193200:9;193184:13;:25;193180:202;;;193226:144;193248:121;193313:13;193345:9;193248:46;:121::i;193226:144::-;193457:21;193481:99;193528:13;193556;193481:32;:99::i;:::-;193457:123;;193681:13;193665;:29;193661:205;;;193711:143;193733:120;193793:13;193825;193733:41;:120::i;193711:143::-;194094:114;194138:6;194159:13;194187:10;194094:29;:114::i;:::-;194011:197;;-1:-1:-1;194011:197:0;-1:-1:-1;194309:31:0;;;194305:214;;;194357:150;194379:127;194444:13;194476:15;194379:46;:127::i;194357:150::-;194608:38;:13;194630:15;194608:38;:21;:38;:::i;:::-;194592:54;;194707:36;194729:13;194707:21;:36::i;:::-;192778:1973;;;;;;;;;:::o;195768:1436::-;196077:23;196115:32;196240:21;196264:99;196311:13;196339;196264:32;:99::i;:::-;196240:123;;196566:111;196601:6;196622:19;196656:10;196566:20;:111::i;:::-;196483:194;;-1:-1:-1;196483:194:0;-1:-1:-1;196771:31:0;;;196767:205;;;196819:141;196841:118;196901:15;196935:9;196841:41;:118::i;182828:285::-;-1:-1:-1;;;182828:285:0;;;;;;;;;;:::o;180646:58::-;-1:-1:-1;;;180646:58:0;:::o;157300:56::-;-1:-1:-1;;;157300:56:0;:::o;181669:250::-;-1:-1:-1;;;181669:250:0;;;;;;;;:::o;148341:339::-;148198:22;:20;:22::i;:::-;-1:-1:-1;;;;;148441:22:0;;148437:236;;148480:70;148502:47;:45;:47::i;148480:70::-;148437:236;;;148583:5;:16;;-1:-1:-1;;;;;;148583:16:0;-1:-1:-1;;;;;148583:16:0;;;;;;;148619:42;;148583:16;;148640:10;;148619:42;;148583:5;148619:42;148437:236;148341:339;:::o;180711:58::-;-1:-1:-1;;;180711:58:0;:::o;48631:898::-;48757:13;48803:5;48811:1;48803:9;48792:1;:8;:20;48788:296;;;48829:243;48851:220;48914:87;49020:1;:8;49047:5;49055:1;49047:9;48851:44;:220::i;48829:243::-;-1:-1:-1;49163:2:0;49264:13;;;;;49258:20;49154:11;;;-1:-1:-1;;;;;;49408:79:0;48631:898;;;;;:::o;150408:197::-;150534:63;;;22:32:-1;6:49;;150534:63:0;;;;;;49:4:-1;25:18;;61:17;;-1:-1;;;;;182:15;-1:-1;;;179:29;160:49;;150408:197:0;:::o;42396:1100::-;42523:14;42570:5;42578:2;42570:10;42559:1;:8;:21;42555:327;;;42597:273;42619:250;42682:89;42790:1;:8;42817:5;42825:2;42817:10;42619:44;:250::i;42597:273::-;-1:-1:-1;43395:13:0;43133:2;43395:13;43389:20;-1:-1:-1;;;;;43385:69:0;;42396:1100::o;53901:351::-;54061:125;;54037:21;;-1:-1:-1;;;54098:31:0;54061:125;;54144:7;;54166:9;;54061:125;;;;;;;;-1:-1:-1;;26:21;;;22:32;6:49;;54061:125:0;;;49:4:-1;25:18;;61:17;;-1:-1;;;;;182:15;-1:-1;;;;;;54061:125:0;;;179:29:-1;;;;160:49;;;54061:125:0;-1:-1:-1;54197:47:0;54228:5;54061:125;54197:30;:47::i;148688:265::-;148786:5;;-1:-1:-1;;;;;148786:5:0;148772:10;:19;148768:178;;148913:5;;148808:126;;148830:103;;148884:10;;-1:-1:-1;;;;;148913:5:0;148830:35;:103::i;148808:126::-;148688:265::o;77420:235::-;77540:107;:9;77585:4;77605:10;77630:6;77540:107;:22;:107;:::i;:::-;77420:235;;:::o;143414:1466::-;143645:20;;143750;;143589;;143645;143739:31;;143735:215;;143787:151;143809:128;143876:7;143902:13;:20;143809:48;:128::i;143787:151::-;144120:9;;-1:-1:-1;144147:9:0;144142:609;144167:7;144162:1;:12;144142:609;;144196:20;144219:13;144233:1;144219:16;;;;;;;;;;;;;;144196:39;;144327:12;144312;:27;144308:229;;;144360:161;144382:138;144454:12;144489;144382:49;:138::i;144360:161::-;144651:34;:12;144672;144651:34;:20;:34;:::i;:::-;144636:49;;144700:13;144714:1;144700:16;;;;;;;;;;;;;;-1:-1:-1;;;;;144700:25:0;:39;144726:12;144700:39;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;144176:3:0;;144142:609;;;;144806:4;;;;;;;;;-1:-1:-1;;;;;144806:4:0;-1:-1:-1;;;;;144806:12:0;;144825;144806:34;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;144806:34:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;;;;;143414:1466:0;;;;:::o;163455:2033::-;163650:28;163693:37;163758:19;163780:53;163800:8;;;;;;;;;-1:-1:-1;;;;;163800:8:0;-1:-1:-1;;;;;163800:30:0;;:32;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;163800:32:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;163800:32:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;163800:32:0;;;;;;;;;163780:11;;:53;:19;:53;:::i;:::-;163758:75;-1:-1:-1;163851:9:0;163846:1635;163871:6;:13;163866:1;:18;163846:1635;;163996:6;164003:1;163996:9;;;;;;;;;;;;;;:26;;;164026:1;163996:31;:66;;;;164031:6;164038:1;164031:9;;;;;;;;;;;;;;:26;;;164061:1;164031:31;163996:66;163992:115;;;164083:8;;163992:115;164176:37;164216:62;:14;164257:20;164216:62;:40;:62;:::i;:::-;164176:102;;164293:26;164322:21;164333:6;164340:1;164333:9;;;;;;;;;;;;;;164322:10;:21::i;:::-;:39;;164350:11;164322:39;;;164346:1;164322:39;164293:68;;164412:18;164380:29;:50;164376:395;;;164561:57;:29;164599:18;164561:57;:37;:57;:::i;:::-;164529:89;;164376:395;;;164750:5;;;;164376:395;164787:38;;:::i;:::-;164828:145;164869:6;164876:1;164869:9;;;;;;;;;;;;;;164897:10;164908:1;164897:13;;;;;;;;;;;;;;164929:29;164828:22;:145::i;:::-;165119:31;;;;165060;;164787:186;;-1:-1:-1;165013:138:0;;:79;;:20;;:79;:46;:79;:::i;:::-;:105;:138;:105;:138;:::i;:::-;164990:161;;165198:97;165254:15;:40;;;165198:29;:55;;:97;;;;:::i;:::-;165166:129;;165414:14;165390:20;:38;165386:84;;165449:5;;;;;165386:84;163846:1635;;;;163886:3;;163846:1635;;;;163455:2033;;;;;;;:::o;151661:309::-;151801:12;150345:10;151875:29;;151919:9;151943:8;151838:124;;;;;;;;;;;;;;-1:-1:-1;;26:21;;;22:32;6:49;;151838:124:0;;;49:4:-1;25:18;;61:17;;-1:-1;;;;;182:15;-1:-1;;;;;;151838:124:0;;;179:29:-1;;;;160:49;;;151838:124:0;-1:-1:-1;151661:309:0;;;;:::o;20103:377::-;20192:7;20225:1;20221;:5;20217:233;;;20243:195;20265:172;20323:59;20401:1;20421;20265:39;:172::i;20243:195::-;-1:-1:-1;20467:5:0;;;20103:377::o;145026:358::-;145176:18;;145172:205;;145247:4;;:29;;-1:-1:-1;;;145247:29:0;;-1:-1:-1;;;;;145247:4:0;;;;:13;;:29;;145261:14;;145247:29;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;145247:29:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;-1:-1;;145330:35:0;;:10;;-1:-1:-1;145330:35:0;;;;;-1:-1:-1;145350:14:0;;145330:35;;;;145350:14;145330:10;:35;;;;;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;150989:374:0;151161:12;150053:10;151235:35;;151285:23;151323:21;151198:157;;;;;;;;;;166038:1629;166244:28;;;;166393:1183;166418:6;:13;166413:1;:18;166393:1183;;166543:6;166550:1;166543:9;;;;;;;;;;;;;;:26;;;166573:1;166543:31;:66;;;;166578:6;166585:1;166578:9;;;;;;;;;;;;;;:26;;;166608:1;166578:31;166543:66;166539:115;;;166630:8;;166539:115;166723:37;166763:62;:14;166804:20;166763:62;:40;:62;:::i;:::-;166723:102;;166842:38;;:::i;:::-;166883:145;166924:6;166931:1;166924:9;;;;;;;;;;;;;;166952:10;166963:1;166952:13;;;;;;;;;;;;;;166984:29;166883:22;:145::i;:::-;167115:31;;166842:186;;-1:-1:-1;167068:79:0;;:20;;:79;:46;:79;:::i;:::-;167045:102;;167194:97;167250:15;:40;;;167194:29;:55;;:97;;;;:::i;:::-;167162:129;;167329:61;167358:15;:31;;;167329:20;:28;;:61;;;;:::i;:::-;167306:84;;167509:14;167485:20;:38;167481:84;;167544:5;;;;167481:84;166393:1183;;;166433:3;;166393:1183;;;-1:-1:-1;167609:50:0;:20;167638;167609:50;:28;:50;:::i;:::-;167586:73;;166038:1629;;;;;;;:::o;171701:2759::-;172034:13;;171903:28;;;;;172058:2130;172083:12;172078:1;:17;172058:2130;;172206:6;172213:1;172206:9;;;;;;;;;;;;;;:26;;;172236:1;172206:31;:66;;;;172241:6;172248:1;172241:9;;;;;;;;;;;;;;:26;;;172271:1;172241:31;172206:66;172202:115;;;172293:8;;172202:115;172333:37;172373:76;:19;172419:29;172373:76;:45;:76;:::i;:::-;172333:116;;172570:24;172597:38;172633:1;172597:6;172604:1;172597:9;;;;;;;;;;;;;;:24;;;:35;;:38;;;;:::i;:::-;172570:65;-1:-1:-1;172650:20:0;;-1:-1:-1;;;;;;172725:42:0;;-1:-1:-1;;;172725:42:0;172721:223;;;172803:40;172840:2;172803:6;172810:1;172803:9;;;;;;;;;;;;;;:24;;;:36;;:40;;;;:::i;:::-;172878:50;;-1:-1:-1;;;172878:50:0;;172788:55;;-1:-1:-1;;;;;;172878:35:0;;;;;:50;;172922:4;;172878:50;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;172878:50:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;172878:50:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;172878:50:0;;;;;;;;;172862:66;;172721:223;172979:23;173021:32;173071:144;173111:6;173118:1;173111:9;;;;;;;;;;;;;;173139:10;173150:1;173139:13;;;;;;;;;;;;;;173171:29;173071:21;:144::i;:::-;172960:255;;-1:-1:-1;172960:255:0;-1:-1:-1;;;;;;;173331:42:0;;-1:-1:-1;;;173331:42:0;173327:344;;;173417:50;;-1:-1:-1;;;173417:50:0;;173394:20;;-1:-1:-1;;;;;173417:35:0;;;;;:50;;173461:4;;173417:50;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;173417:50:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;173417:50:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;173417:50:0;;;;;;;;;173394:73;-1:-1:-1;173513:142:0;173554:35;173394:73;173575:13;173554:35;:20;:35;:::i;:::-;173612:24;173513:18;:142::i;:::-;173486:169;;173327:344;;173687:62;173724:24;173687:6;173694:1;173687:9;;;;;;;;;;;;;;:24;;;:36;;:62;;;;:::i;:::-;173789:63;:20;173836:15;173789:63;:46;:63;:::i;:::-;173766:86;-1:-1:-1;173899:81:0;:29;173955:24;173899:81;:55;:81;:::i;:::-;173867:113;;174116:19;174083:29;:52;174079:98;;174156:5;;;;;;;;174079:98;172058:2130;;;;;;;172097:3;;172058:2130;;;;174236:19;174204:29;:51;174200:253;;;174272:169;174294:146;174358:19;174396:29;174294:45;:146::i;174272:169::-;171701:2759;;;;;;;:::o;147762:165::-;147885:34;;;;;;;;;;;;-1:-1:-1;;;147885:34:0;;;;147762:165;:::o;31644:393::-;31839:12;31581:10;31913:37;;31965:9;31989:6;32010:8;31876:153;;;;;;;;;;;;;;;-1:-1:-1;;26:21;;;22:32;6:49;;31876:153:0;;;49:4:-1;25:18;;61:17;;-1:-1;;;;;182:15;-1:-1;;;;;;31876:153:0;;;179:29:-1;;;;160:49;;;31876:153:0;-1:-1:-1;31644:393:0;;;;;;:::o;58971:590::-;59109:15;59126:23;59153:6;-1:-1:-1;;;;;59153:11:0;59165:8;59153:21;;;;;;;;;;;;;;;;;;;;;;;14:1:-1;21;16:31;;;;75:4;69:11;64:16;;144:4;140:9;133:4;115:16;111:27;107:43;104:1;100:51;94:4;87:65;169:16;166:1;159:27;225:16;222:1;215:4;212:1;208:12;193:49;7:242;;16:31;36:4;31:9;;7:242;;59108:66:0;;;;59189:10;59185:325;;;59220:17;;59216:69;;59263:7;;;;59216:69;59303:10;:17;59324:2;59303:23;59299:200;;;59347:14;59364:35;59385:10;59397:1;59364:20;:35::i;:::-;59347:52;;59422:6;59432:1;59422:11;59418:66;;;59458:7;;;;;59418:66;59299:200;;59520:33;59542:10;59520:21;:33::i;147465:289::-;147595:12;147254:10;147669:25;;147709:6;147730:5;147632:114;;;;;;;;;;75363:1413;75532:11;75528:50;;75560:7;;75528:50;75590:14;75607:23;:9;75590:14;75607:23;:20;:23;:::i;:::-;75590:40;-1:-1:-1;;;;;;;75661:53:0;;-1:-1:-1;;;75661:53:0;;:124;;-1:-1:-1;;;;;;;75731:54:0;;-1:-1:-1;;;75731:54:0;75661:124;75643:1126;;;75812:112;:9;75859:4;75882:2;75903:6;75812:112;:28;:112;:::i;:::-;75643:1126;;;-1:-1:-1;;;;;;75946:54:0;;-1:-1:-1;;;75946:54:0;75942:827;;;76017:113;:9;76065:4;76088:2;76109:6;76017:113;:29;:113;:::i;75942:827::-;-1:-1:-1;;;;;;76152:56:0;;-1:-1:-1;;;76152:56:0;76148:621;;;76225:115;:9;76275:4;76298:2;76319:6;76225:115;:31;:115;:::i;76148:621::-;-1:-1:-1;;;;;;76362:53:0;;-1:-1:-1;;;76362:53:0;76358:411;;;76432:112;:9;76479:4;76502:2;76523:6;76432:112;:28;:112;:::i;76358:411::-;-1:-1:-1;;;;;;76566:53:0;;-1:-1:-1;;;76566:53:0;76562:207;;76636:121;76658:98;76734:7;76658:57;:98::i;76636:121::-;75363:1413;;;;;:::o;141269:355::-;141431:12;140334:10;141505:38;;141558:13;141586:19;141468:148;;;;;;;;;;140602:345;140759:12;139987:10;140833:39;;140887:14;140916:12;140796:143;;;;;;;;;;19225:465;19314:7;19343:6;19339:47;;-1:-1:-1;19373:1:0;19366:8;;19339:47;19408:5;;;19412:1;19408;:5;:1;19428:5;;;;;:10;19424:240;;19455:197;19477:174;19535:61;19615:1;19635;19477:39;:174::i;179774:235::-;179873:4;179935:1;179902:5;:23;;;:30;:34;:99;;;;-1:-1:-1;179940:23:0;;;;-1:-1:-1;;;179981:20:0;179940:37;;179975:1;179940:37;:34;:37;:::i;:::-;-1:-1:-1;;;;;;179940:61:0;;179895:106;179774:235;-1:-1:-1;;179774:235:0:o;159499:3448::-;159693:38;;:::i;:::-;159876:20;;;;159849:24;;159876:34;;159849:24;159876:34;:31;:34;:::i;:::-;159849:61;-1:-1:-1;159921:20:0;;-1:-1:-1;;;;;;159988:42:0;;-1:-1:-1;;;159988:42:0;159984:207;;;160062:20;;;;:36;;160095:2;160062:36;:32;:36;:::i;:::-;160129:50;;-1:-1:-1;;;160129:50:0;;160047:51;;-1:-1:-1;;;;;;160129:35:0;;;;;:50;;160173:4;;160129:50;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;160129:50:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;160129:50:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;160129:50:0;;;;;;;;;160113:66;;159984:207;160262:14;;;;:19;;:108;;;160298:72;160324:5;:23;;;160349:5;:20;;;160298:25;:72::i;:::-;160244:2121;;;160458:51;;:::i;:::-;160512:132;160548:5;160572:29;160620:9;160512:17;:132::i;:::-;160695:40;;;;160661:74;;160784:33;;;;160750:31;;;:67;161030:30;;;;160963:40;;160458:186;;-1:-1:-1;160963:98:0;;:40;:98;:66;:98;:::i;:::-;160920:40;;;:141;-1:-1:-1;160244:2121:0;;;161106:72;161132:5;:23;;;161157:5;:20;;;161106:25;:72::i;:::-;161102:1263;;;161455:22;;;;161527:14;;;;161377:28;;161408:197;;161496:46;;161455:22;;161496:46;:30;:46;:::i;:::-;161561:29;161408:28;:197::i;:::-;161377:228;;161622:51;;:::i;:::-;161676:123;161712:5;161736:20;161775:9;161676:17;:123::i;:::-;161622:177;;161922:98;161989:17;:30;;;161922:17;:40;;;:66;;:98;;;;:::i;:::-;161888:132;;162078:40;;162035;;;:83;162167:33;;;162133:31;;;:67;-1:-1:-1;161102:1263:0;;;162263:90;162285:67;162328:5;:23;;;162285:42;:67::i;162263:90::-;-1:-1:-1;;;;;;162472:42:0;;-1:-1:-1;;;162472:42:0;162468:352;;;162554:50;;-1:-1:-1;;;162554:50:0;;162531:20;;-1:-1:-1;;;;;162554:35:0;;;;;:50;;162598:4;;162554:50;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;162554:50:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;162554:50:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;162554:50:0;;;;;;;;;162531:73;-1:-1:-1;162662:146:0;162699:35;162531:73;162720:13;162699:35;:20;:35;:::i;:::-;162753:15;:40;;;162662:18;:146::i;:::-;162619:40;;;:189;-1:-1:-1;162468:352:0;162865:40;;;;162832:20;;;;:74;;;:32;:74;:::i;:::-;-1:-1:-1;;;159499:3448:0;;;;;:::o;20488:397::-;20577:7;20614:5;;;20634;;;20630:229;;;20656:191;20678:168;20736:55;20810:1;20830;18534:337;18694:12;17979:10;18768:28;;18811:9;18835:1;18851;18731:132;;;;;;;;;;;168171:2726;168378:23;168416:32;168531:5;:14;;;168549:1;168531:19;:108;;;;168567:72;168593:5;:23;;;168618:5;:20;;;168567:25;:72::i;:::-;168513:2314;;;168735:37;168775:173;168822:5;:22;;;168863:5;:22;;;168904:29;168775:28;:173::i;:::-;168735:213;;169032:51;;:::i;:::-;169086:132;169122:5;169146:29;169194:9;169086:17;:132::i;:::-;169032:186;;169339:159;169464:17;:33;;;169339:98;169406:17;:30;;;169339:17;:40;;;:66;;:98;;;;:::i;:159::-;169542:40;;169321:177;;-1:-1:-1;169542:40:0;-1:-1:-1;168513:2314:0;;-1:-1:-1;168513:2314:0;;169633:72;169659:5;:23;;;169684:5;:20;;;169633:25;:72::i;:::-;169629:1198;;;169791:37;169831:197;169878:5;:22;;;169919:46;169950:5;:14;;;169919:5;:22;;;:30;;:46;;;;:::i;:::-;169984:29;169831:28;:197::i;:::-;169791:237;;170112:51;;:::i;:::-;170166:132;170202:5;170226:29;170274:9;170166:17;:132::i;:::-;170112:186;;170333:101;170400:17;:33;;;170333:17;:40;;;:66;;:101;;;;:::i;:::-;170631:30;;;;170564:40;;170315:119;;-1:-1:-1;170564:98:0;;:40;:98;:66;:98;:::i;:::-;170537:125;;169629:1198;;;;;170725:90;170747:67;170790:5;:23;;;170747:42;:67::i;170725:90::-;168171:2726;;;;;;:::o;20893:142::-;20981:7;21018:1;21013;:6;;:14;;21026:1;21013:14;;;-1:-1:-1;21022:1:0;;21006:21;-1:-1:-1;20893:142:0:o;150613:368::-;150782:12;149892:10;150856:34;;150905:22;150942:20;150819:154;;;;;;;;;;47715:230;47842:14;47891:21;47903:1;47906:5;47891:11;:21::i;77995:587::-;78166:13;78182:25;:9;78204:2;78182:25;:21;:25;:::i;:::-;78166:41;-1:-1:-1;;;;;;78251:21:0;;78267:4;78251:21;78247:328;;;78289:107;78330:5;78354:2;78375:6;78289:22;:107::i;78247:328::-;78429:134;78474:5;78498:4;78521:2;78542:6;78429:26;:134::i;78908:627::-;79084:6;79094:1;79084:11;79080:167;;79112:123;79134:100;79213:6;79134:60;:100::i;79112:123::-;79288:13;79304:25;:9;79326:2;79304:25;:21;:25;:::i;:::-;79288:41;-1:-1:-1;79340:15:0;79358:25;:9;79380:2;79358:25;:21;:25;:::i;:::-;79426:101;;-1:-1:-1;;;79426:101:0;;79340:43;;-1:-1:-1;;;;;;79426:32:0;;;;;:101;;79473:4;;79492:2;;79340:43;;79426:101;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;79426:101:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;79426:101:0;;;;78908:627;;;;;;:::o;79863:1051::-;80109:13;80137:20;80172:23;80210:17;80266:36;80282:1;80285:9;:16;80266:9;:15;;:36;;;;;:::i;:::-;80241:125;;;;;;;;;;;;;;80094:272;;;;;;;;80446:14;80463:6;:13;80446:30;;80487:29;80533:6;80519:21;;;;;;;;;;;;;;;;;;;;;;29:2:-1;21:6;17:15;117:4;105:10;97:6;88:34;136:17;;-1:-1;80519:21:0;-1:-1:-1;80487:53:0;-1:-1:-1;80556:9:0;80551:108;80576:6;80571:1;:11;80551:108;;80622:25;80640:6;80622;80629:1;80622:9;;;;;;;;;;;;;;:17;;:25;;;;:::i;:::-;80604:12;80617:1;80604:15;;;;;;;;;;;;;;;;;:43;80584:3;;80551:108;;;-1:-1:-1;80758:148:0;;-1:-1:-1;;;80758:148:0;;-1:-1:-1;;;;;80758:37:0;;;;;:148;;80810:4;;80829:2;;80846:3;;80864:12;;80891:4;;80758:148;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;80758:148:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;80758:148:0;;;;79863:1051;;;;;;;;;;:::o;81250:726::-;81457:30;81489;81548:36;81564:1;81567:9;:16;81548:9;:15;;:36;;;;;:::i;:::-;81523:107;;;;;;;;;;;;;;81703:22;;81456:174;;-1:-1:-1;81456:174:0;-1:-1:-1;81677:23:0;81736:233;81761:15;81756:1;:20;81736:233;;81798:159;81829:15;81845:1;81829:18;;;;;;;;;;;;;;81866:4;81889:2;81910:32;81925:13;81939:1;81925:16;;;;;;;;;;;;;;81910:6;:14;;:32;;;;:::i;:::-;81798:12;:159::i;:::-;81778:3;;81736:233;;;;81250:726;;;;;;;:::o;74351:271::-;74469:12;74121:10;74543:38;;74596:7;74506:108;;;;;;;;;178617:944;178777:4;;178822:24;:10;178777:4;178822:24;:21;:24;:::i;:::-;178799:47;-1:-1:-1;178857:20:0;178880:24;:10;178857:20;178880:24;:21;:24;:::i;:::-;178857:47;-1:-1:-1;;;;;;;;;;;;;179093:29:0;;;;;:68;;-1:-1:-1;;;;;;;179126:35:0;;;;;;;179093:68;179092:157;;;;-1:-1:-1;;;;;;;179180:29:0;;;;;;;;:68;;-1:-1:-1;;;;;;;179213:35:0;;;;;;;179180:68;179074:480;;;179332:14;179349:26;:10;179372:2;179349:26;:22;:26;:::i;:::-;179332:43;-1:-1:-1;179390:14:0;179407:26;:10;179430:2;179407:26;:22;:26;:::i;:::-;179390:43;;179466:6;-1:-1:-1;;;;;179456:16:0;:6;-1:-1:-1;;;;;179456:16:0;;179448:25;;;;;;;;;;179074:480;179513:29;:10;179531;179513:29;:17;:29;:::i;:::-;179506:36;;;;;;;;179074:480;178617:944;;;;;;;;:::o;158447:561::-;158627:45;;:::i;:::-;158694:17;158705:5;158694:10;:17::i;:::-;158690:182;;;158735:125;158773:5;158797:20;158836:9;158735:19;:125::i;:::-;158728:132;;;;158690:182;158891:109;158925:5;158945:20;158980:9;158891:19;:109::i;:::-;158884:116;158447:561;-1:-1:-1;;;;158447:561:0:o;25155:562::-;25325:21;25570:106;25664:11;25570:71;25618:22;25664:11;25638:1;25618:22;:19;:22;:::i;:::-;25570:25;:9;25588:6;25570:25;:17;:25;:::i;:71::-;:93;:106;:93;:106;:::i;151371:282::-;151498:12;150195:10;151572:30;;151617:17;151535:110;;;;;;;;;45860:703;45987:14;46034:5;46042:2;46034:10;46023:1;:8;:21;46019:303;;;46061:249;46083:226;46146:92;46257:1;:8;46284:5;46292:2;46284:10;46083:44;:226::i;46061:249::-;-1:-1:-1;46507:13:0;46405:2;46507:13;46501:20;;45860:703::o;55328:337::-;55481:118;;55457:21;;-1:-1:-1;;;55518:32:0;55481:118;;55565:2;;55582:6;;55481:118;;;;56059:387;56239:141;;56215:21;;-1:-1:-1;;;56276:36:0;56239:141;;56327:4;;56346:2;;56363:6;;56239:141;;;;;;;;-1:-1:-1;;26:21;;;22:32;6:49;;56239:141:0;;;49:4:-1;25:18;;61:17;;-1:-1;;;;;182:15;-1:-1;;;;;;56239:141:0;;;179:29:-1;;;;160:49;;;56239:141:0;-1:-1:-1;56391:47:0;56422:5;56239:141;56391:30;:47::i;74630:278::-;74751:12;74288:10;74825:43;;74883:6;74788:112;;;;;;;;;37993:1135;38134:19;38318:2;38311:4;:9;38307:267;;;38337:225;38359:202;38422:80;38521:4;38544:2;38359:44;:202::i;38337:225::-;38593:1;:8;38588:2;:13;38584:277;;;38618:231;38640:208;38703:82;38804:2;38825:1;:8;38640:44;:208::i;38618:231::-;38956:4;38951:2;:9;38941:20;;;;;;;;;;;;;;;;;;;;;;;;;21:6:-1;;104:10;38941:20:0;87:34:-1;135:17;;-1:-1;38941:20:0;;38932:29;;38972:124;38994:23;:6;:21;:23::i;:::-;39053:4;39032:18;:1;:16;:18::i;:::-;:25;39072:6;:13;38972:7;:124::i;41761:415::-;41888:10;42122:3;:10;42108:3;:10;:24;:60;;;;-1:-1:-1;;42154:14:0;;;;;;;42136;;;;;;;;;;:32;;41761:415::o;174956:1873::-;175138:45;;:::i;:::-;175249:32;;:::i;:::-;175284:706;;;;;;;;175331:5;:18;;;-1:-1:-1;;;;;175284:706:0;;;;;175378:5;:18;;;-1:-1:-1;;;;;175284:706:0;;;;;175432:5;:25;;;-1:-1:-1;;;;;175284:706:0;;;;;175487:5;:19;;;-1:-1:-1;;;;;175284:706:0;;;;;175539:5;:22;;;175284:706;;;;175594:5;:22;;;175284:706;;;;175753:1;175284:706;;;;175779:1;175284:706;;;;175818:5;:27;;;175284:706;;;;175866:5;:10;;;175284:706;;;;175907:5;:20;;;175284:706;;;;175958:5;:20;;;175284:706;;;175249:741;;176051:30;176141:1;-1:-1:-1;;;;;176121:33:0;;:42;;;;176178:7;176200:20;176235:9;176084:171;;;;;;;;;;;;;;;-1:-1:-1;;26:21;;;22:32;6:49;;176084:171:0;;;49:4:-1;25:18;;61:17;;-1:-1;;;;;182:15;-1:-1;;;;;;176084:171:0;;;179:29:-1;;;;160:49;;;176295:11:0;;176363:32;;176084:171;;-1:-1:-1;;;;;;176295:11:0;;;;-1:-1:-1;;176336:23:0;;176295:11;;176363:32;;176084:171;;176363:32;;;;;;;;;;;;;;;;;;14:1:-1;21;16:31;;;;75:4;69:11;64:16;;144:4;140:9;133:4;115:16;111:27;107:43;104:1;100:51;94:4;87:65;169:16;166:1;159:27;225:16;222:1;215:4;212:1;208:12;193:49;7:242;;16:31;36:4;31:9;;7:242;;176318:77:0;;;;176410:10;176406:308;;;176444:10;:17;176465:3;176444:24;176437:32;;;;176671:10;176660:42;;;;;;;;;;;;;;176622:34;;;176585:117;;;176406:308;-1:-1:-1;;;;;174956:1873:0;;;;;:::o;177235:912::-;177417:45;;:::i;:::-;177561:167;;177528:30;;-1:-1:-1;;;177598:40:0;177561:167;;177653:5;;177673:20;;177708:9;;177561:167;;;;;;;;-1:-1:-1;;26:21;;;22:32;6:49;;177561:167:0;;;49:4:-1;25:18;;61:17;;-1:-1;;;;;182:15;-1:-1;;;;;;177561:167:0;;;179:29:-1;;;;160:49;;;177768:8:0;;177833:32;;177561:167;;-1:-1:-1;;;;;;177768:8:0;;;;-1:-1:-1;;177806:23:0;;177768:8;;177833:32;;177561:167;;177833:32;;;;;;;;;;;;;;;;;;14:1:-1;21;16:31;;;;75:4;69:11;64:16;;144:4;140:9;133:4;115:16;111:27;107:43;104:1;100:51;94:4;87:65;169:16;166:1;159:27;225:16;222:1;215:4;212:1;208:12;193:49;7:242;;16:31;36:4;31:9;;7:242;;177788:77:0;;;;177880:10;177876:156;;;177914:10;:17;177935:3;177914:24;177907:32;;;;177979:10;177968:52;;;;;;;;;;;;;;177954:66;;177876:156;-1:-1:-1;;;;177235:912:0;;;;;:::o;19698:397::-;19787:7;19816:6;19812:229;;19839:190;19861:167;19919:54;19992:1;20012;19861:39;:167::i;19839:190::-;20051:9;20067:1;20063;:5;;;;;;;19698:397;-1:-1:-1;;;;19698:397:0:o;32798:237::-;32983:2;32972:14;;32798:237::o;33280:4398::-;33438:2;33429:6;:11;33425:4246;;;33732:1;33722:6;33718:2;33714:15;33709:3;33705:25;33701:33;33784:4;33780:9;33771:6;33765:13;33761:29;33834:4;33827;33821:11;33817:22;33876:1;33873;33870:8;33864:4;33857:22;33670:224;;;;;;34001:4;33991:6;:14;33987:61;;;34026:7;;33987:61;34754:4;34745:6;:13;34741:2919;;;35086:2;35078:6;35074:15;35064:25;;35135:6;35127;35123:19;35186:6;35180:4;35176:17;35499:4;35493:11;35773:202;35791:4;35783:6;35780:16;35773:202;;;35840:13;;35827:27;;35902:2;35939:13;;;;35890:15;;;;35773:202;;;36047:18;;-1:-1:-1;34788:1296:0;;;36334:2;36326:6;36322:15;36312:25;;36383:6;36375;36371:19;36434:6;36428:4;36424:17;36750:6;36744:13;37339:195;37356:4;37350;37346:15;37339:195;;;37405:11;;37392:25;;-1:-1:-1;;37451:13:0;;;;37498;;;;37339:195;;;37607:19;;-1:-1:-1;;33280:4398:0;;;:::o;187437:9770::-;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;-1:-1:-1;;;;;187437:9770:0;;;;;;-1:-1:-1;;;;;187437:9770:0;;;;;;-1:-1:-1;;;;;187437:9770:0;;;;;;-1:-1:-1;;;;;187437:9770:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;5:130:-1:-;72:20;;97:33;72:20;97:33;;142:134;220:13;;238:33;220:13;238:33;;619:731;;744:3;737:4;729:6;725:17;721:27;711:2;;762:1;759;752:12;711:2;799:6;786:20;821:88;836:72;901:6;836:72;;;821:88;;;812:97;;926:5;951:6;944:5;937:21;981:4;973:6;969:17;959:27;;1003:4;998:3;994:14;987:21;;1056:6;1103:3;1095:4;1087:6;1083:17;1078:3;1074:27;1071:36;1068:2;;;1120:1;1117;1110:12;1068:2;1145:1;1130:214;1155:6;1152:1;1149:13;1130:214;;;1213:3;1235:45;1276:3;1264:10;1235:45;;;1223:58;;-1:-1;1304:4;1295:14;;;;1323;;;;;1177:1;1170:9;1130:214;;1374:693;;1503:3;1496:4;1488:6;1484:17;1480:27;1470:2;;1521:1;1518;1511:12;1470:2;1551:6;1545:13;1573:81;1588:65;1646:6;1588:65;;1573:81;1682:21;;;1726:4;1714:17;;;;1564:90;;-1:-1;1739:14;;1714:17;1834:1;1819:242;1844:6;1841:1;1838:13;1819:242;;;1920:3;1914:10;1906:6;1902:23;1944:53;1993:3;1981:10;1944:53;;;1932:66;;-1:-1;2021:4;2012:14;;;;2040;;;;;1866:1;1859:9;1819:242;;2091:693;;2213:3;2206:4;2198:6;2194:17;2190:27;2180:2;;2231:1;2228;2221:12;2180:2;2268:6;2255:20;2290:85;2305:69;2367:6;2305:69;;2290:85;2403:21;;;2447:4;2435:17;;;;2281:94;;-1:-1;2460:14;;2435:17;2555:1;2540:238;2565:6;2562:1;2559:13;2540:238;;;2648:3;2635:17;2627:6;2623:30;2672:42;2710:3;2698:10;2672:42;;;2660:55;;-1:-1;2738:4;2729:14;;;;2757;;;;;2587:1;2580:9;2540:238;;2824:732;;2959:3;2952:4;2944:6;2940:17;2936:27;2926:2;;2977:1;2974;2967:12;2926:2;3014:6;3001:20;3036:98;3051:82;3126:6;3051:82;;3036:98;3162:21;;;3206:4;3194:17;;;;3027:107;;-1:-1;3219:14;;3194:17;3314:1;3299:251;3324:6;3321:1;3318:13;3299:251;;;3407:3;3394:17;3386:6;3382:30;3431:55;3482:3;3470:10;3431:55;;;3419:68;;-1:-1;3510:4;3501:14;;;;3529;;;;;3346:1;3339:9;3299:251;;3582:352;;;3712:3;3705:4;3697:6;3693:17;3689:27;3679:2;;3730:1;3727;3720:12;3679:2;-1:-1;3750:20;;-1:-1;;;;;3779:30;;3776:2;;;3822:1;3819;3812:12;3776:2;3856:4;3848:6;3844:17;3832:29;;3907:3;3899:4;3891:6;3887:17;3877:8;3873:32;3870:41;3867:2;;;3924:1;3921;3914:12;3867:2;3672:262;;;;;;3960:714;;4084:3;4077:4;4069:6;4065:17;4061:27;4051:2;;4102:1;4099;4092:12;4051:2;4132:6;4126:13;4154:76;4169:60;4222:6;4169:60;;4154:76;4145:85;;4247:5;4272:6;4265:5;4258:21;4302:4;4294:6;4290:17;4280:27;;4324:4;4319:3;4315:14;4308:21;;4377:6;4424:3;4416:4;4408:6;4404:17;4399:3;4395:27;4392:36;4389:2;;;4441:1;4438;4431:12;4389:2;4466:1;4451:217;4476:6;4473:1;4470:13;4451:217;;;4534:3;4556:48;4600:3;4588:10;4556:48;;;4544:61;;-1:-1;4628:4;4619:14;;;;4647;;;;;4498:1;4491:9;4451:217;;4700:707;;4817:3;4810:4;4802:6;4798:17;4794:27;4784:2;;4835:1;4832;4825:12;4784:2;4872:6;4859:20;4894:80;4909:64;4966:6;4909:64;;4894:80;4885:89;;4991:5;5016:6;5009:5;5002:21;5046:4;5038:6;5034:17;5024:27;;5068:4;5063:3;5059:14;5052:21;;5121:6;5168:3;5160:4;5152:6;5148:17;5143:3;5139:27;5136:36;5133:2;;;5185:1;5182;5175:12;5133:2;5210:1;5195:206;5220:6;5217:1;5214:13;5195:206;;;5278:3;5300:37;5333:3;5321:10;5300:37;;;5288:50;;-1:-1;5361:4;5352:14;;;;5380;;;;;5242:1;5235:9;5195:206;;5429:336;;;5543:3;5536:4;5528:6;5524:17;5520:27;5510:2;;5561:1;5558;5551:12;5510:2;-1:-1;5581:20;;-1:-1;;;;;5610:30;;5607:2;;;5653:1;5650;5643:12;5607:2;5687:4;5679:6;5675:17;5663:29;;5738:3;5730:4;5722:6;5718:17;5708:8;5704:32;5701:41;5698:2;;;5755:1;5752;5745:12;5774:432;;5871:3;5864:4;5856:6;5852:17;5848:27;5838:2;;5889:1;5886;5879:12;5838:2;5926:6;5913:20;5948:60;5963:44;6000:6;5963:44;;5948:60;5939:69;;6028:6;6021:5;6014:21;6064:4;6056:6;6052:17;6097:4;6090:5;6086:16;6132:3;6123:6;6118:3;6114:16;6111:25;6108:2;;;6149:1;6146;6139:12;6108:2;6159:41;6193:6;6188:3;6183;6159:41;;;5831:375;;;;;;;;6215:434;;6323:3;6316:4;6308:6;6304:17;6300:27;6290:2;;6341:1;6338;6331:12;6290:2;6371:6;6365:13;6393:60;6408:44;6445:6;6408:44;;6393:60;6384:69;;6473:6;6466:5;6459:21;6509:4;6501:6;6497:17;6542:4;6535:5;6531:16;6577:3;6568:6;6563:3;6559:16;6556:25;6553:2;;;6594:1;6591;6584:12;6553:2;6604:39;6636:6;6631:3;6626;6604:39;;6697:1029;;6822:4;6810:9;6805:3;6801:19;6797:30;6794:2;;;6840:1;6837;6830:12;6794:2;6858:20;6873:4;6858:20;;;6849:29;-1:-1;6946:1;6978:60;7034:3;7014:9;6978:60;;;6953:86;;-1:-1;7118:2;7151:60;7207:3;7183:22;;;7151:60;;;7144:4;7137:5;7133:16;7126:86;7060:163;7281:2;7314:60;7370:3;7361:6;7350:9;7346:22;7314:60;;;7307:4;7300:5;7296:16;7289:86;7233:153;7444:2;7477:60;7533:3;7524:6;7513:9;7509:22;7477:60;;;7470:4;7463:5;7459:16;7452:86;7396:153;7610:3;7644:60;7700:3;7691:6;7680:9;7676:22;7644:60;;;7637:4;7630:5;7626:16;7619:86;7559:157;6788:938;;;;;7761:2713;;7868:6;7856:9;7851:3;7847:19;7843:32;7840:2;;;7888:1;7885;7878:12;7840:2;7906:22;7921:6;7906:22;;;7897:31;-1:-1;7986:1;8018:49;8063:3;8043:9;8018:49;;;7993:75;;-1:-1;8137:2;8170:49;8215:3;8191:22;;;8170:49;;;8163:4;8156:5;8152:16;8145:75;8089:142;8296:2;8329:49;8374:3;8365:6;8354:9;8350:22;8329:49;;;8322:4;8315:5;8311:16;8304:75;8241:149;8449:2;8482:49;8527:3;8518:6;8507:9;8503:22;8482:49;;;8475:4;8468:5;8464:16;8457:75;8400:143;8605:3;8639:49;8684:3;8675:6;8664:9;8660:22;8639:49;;;8632:4;8625:5;8621:16;8614:75;8553:147;8762:3;8796:49;8841:3;8832:6;8821:9;8817:22;8796:49;;;8789:4;8782:5;8778:16;8771:75;8710:147;8911:3;8945:49;8990:3;8981:6;8970:9;8966:22;8945:49;;;8938:4;8931:5;8927:16;8920:75;8867:139;9060:3;9094:49;9139:3;9130:6;9119:9;9115:22;9094:49;;;9087:4;9080:5;9076:16;9069:75;9016:139;9222:3;9258:49;9303:3;9294:6;9283:9;9279:22;9258:49;;;9249:6;9242:5;9238:18;9231:77;9165:154;9369:3;9405:49;9450:3;9441:6;9430:9;9426:22;9405:49;;;9396:6;9389:5;9385:18;9378:77;9329:137;9554:3;9543:9;9539:19;9526:33;-1:-1;;;;;9571:6;9568:30;9565:2;;;9611:1;9608;9601:12;9565:2;9648:54;9698:3;9689:6;9678:9;9674:22;9648:54;;;9639:6;9632:5;9628:18;9621:82;9476:238;9802:3;9791:9;9787:19;9774:33;-1:-1;;;;;9819:6;9816:30;9813:2;;;9859:1;9856;9849:12;9813:2;9896:54;9946:3;9937:6;9926:9;9922:22;9896:54;;;9887:6;9880:5;9876:18;9869:82;9724:238;10053:3;10042:9;10038:19;10025:33;-1:-1;;;;;10070:6;10067:30;10064:2;;;10110:1;10107;10100:12;10064:2;10147:54;10197:3;10188:6;10177:9;10173:22;10147:54;;;10138:6;10131:5;10127:18;10120:82;9972:241;10304:3;10293:9;10289:19;10276:33;-1:-1;;;;;10321:6;10318:30;10315:2;;;10361:1;10358;10351:12;10315:2;10398:54;10448:3;10439:6;10428:9;10424:22;10398:54;;;10389:6;10382:5;10378:18;10371:82;10223:241;7834:2640;;;;;10481:130;10548:20;;10573:33;10548:20;10573:33;;10618:134;10696:13;;10714:33;10696:13;10714:33;;10759:241;;10863:2;10851:9;10842:7;10838:23;10834:32;10831:2;;;10879:1;10876;10869:12;10831:2;10914:1;10931:53;10976:7;10956:9;10931:53;;11007:263;;11122:2;11110:9;11101:7;11097:23;11093:32;11090:2;;;11138:1;11135;11128:12;11090:2;11173:1;11190:64;11246:7;11226:9;11190:64;;11277:1019;;;;;11498:3;11486:9;11477:7;11473:23;11469:33;11466:2;;;11515:1;11512;11505:12;11466:2;11550:1;11567:72;11631:7;11611:9;11567:72;;;11557:82;;11529:116;11697:2;11686:9;11682:18;11676:25;-1:-1;;;;;11713:6;11710:30;11707:2;;;11753:1;11750;11743:12;11707:2;11773:85;11850:7;11841:6;11830:9;11826:22;11773:85;;;11763:95;;11655:209;11916:2;11905:9;11901:18;11895:25;-1:-1;;;;;11932:6;11929:30;11926:2;;;11972:1;11969;11962:12;11926:2;11992:85;12069:7;12060:6;12049:9;12045:22;11992:85;;;11982:95;;11874:209;12135:2;12124:9;12120:18;12114:25;-1:-1;;;;;12151:6;12148:30;12145:2;;;12191:1;12188;12181:12;12145:2;12211:69;12272:7;12263:6;12252:9;12248:22;12211:69;;;12201:79;;12093:193;11460:836;;;;;;;;12303:1179;;;;;;;;;12564:3;12552:9;12543:7;12539:23;12535:33;12532:2;;;12581:1;12578;12571:12;12532:2;12616:1;12633:53;12678:7;12658:9;12633:53;;;12623:63;;12595:97;12723:2;12741:53;12786:7;12777:6;12766:9;12762:22;12741:53;;;12731:63;;12702:98;12859:2;12848:9;12844:18;12831:32;-1:-1;;;;;12875:6;12872:30;12869:2;;;12915:1;12912;12905:12;12869:2;12943:80;13015:7;13006:6;12995:9;12991:22;12943:80;;;12933:90;;;;12810:219;13088:2;13077:9;13073:18;13060:32;-1:-1;;;;;13104:6;13101:30;13098:2;;;13144:1;13141;13134:12;13098:2;13172:80;13244:7;13235:6;13224:9;13220:22;13172:80;;;13162:90;;;;13039:219;13317:3;13306:9;13302:19;13289:33;-1:-1;;;;;13334:6;13331:30;13328:2;;;13374:1;13371;13364:12;13328:2;13402:64;13458:7;13449:6;13438:9;13434:22;13402:64;;;13392:74;;;;13268:204;12526:956;;;;;;;;;;;;13489:867;;;;;;;13680:3;13668:9;13659:7;13655:23;13651:33;13648:2;;;13697:1;13694;13687:12;13648:2;13732:1;13749:53;13794:7;13774:9;13749:53;;;13739:63;;13711:97;13839:2;13857:53;13902:7;13893:6;13882:9;13878:22;13857:53;;;13847:63;;13818:98;13947:2;13965:53;14010:7;14001:6;13990:9;13986:22;13965:53;;;13955:63;;13926:98;14055:2;14073:53;14118:7;14109:6;14098:9;14094:22;14073:53;;;14063:63;;14034:98;14191:3;14180:9;14176:19;14163:33;-1:-1;;;;;14208:6;14205:30;14202:2;;;14248:1;14245;14238:12;14202:2;14276:64;14332:7;14323:6;14312:9;14308:22;14276:64;;;14266:74;;;;14142:204;13642:714;;;;;;;;;14363:1223;;;;;14649:3;14637:9;14628:7;14624:23;14620:33;14617:2;;;14666:1;14663;14656:12;14617:2;14701:31;;-1:-1;;;;;14741:30;;14738:2;;;14784:1;14781;14774:12;14738:2;14804:96;14892:7;14883:6;14872:9;14868:22;14804:96;;;14794:106;;14680:226;14965:2;14954:9;14950:18;14937:32;-1:-1;;;;;14981:6;14978:30;14975:2;;;15021:1;15018;15011:12;14975:2;15041:83;15116:7;15107:6;15096:9;15092:22;15041:83;;;15031:93;;14916:214;15189:2;15178:9;15174:18;15161:32;-1:-1;;;;;15205:6;15202:30;15199:2;;;15245:1;15242;15235:12;15199:2;15265:78;15335:7;15326:6;15315:9;15311:22;15265:78;;;15255:88;;15140:209;15408:2;15397:9;15393:18;15380:32;-1:-1;;;;;15424:6;15421:30;15418:2;;;15464:1;15461;15454:12;15418:2;15484:86;15562:7;15553:6;15542:9;15538:22;15484:86;;15593:1349;;;;;;15896:3;15884:9;15875:7;15871:23;15867:33;15864:2;;;15913:1;15910;15903:12;15864:2;15948:31;;-1:-1;;;;;15988:30;;15985:2;;;16031:1;16028;16021:12;15985:2;16051:96;16139:7;16130:6;16119:9;16115:22;16051:96;;;16041:106;;15927:226;16184:2;16202:53;16247:7;16238:6;16227:9;16223:22;16202:53;;;16192:63;;16163:98;16320:2;16309:9;16305:18;16292:32;-1:-1;;;;;16336:6;16333:30;16330:2;;;16376:1;16373;16366:12;16330:2;16396:83;16471:7;16462:6;16451:9;16447:22;16396:83;;;16386:93;;16271:214;16544:2;16533:9;16529:18;16516:32;-1:-1;;;;;16560:6;16557:30;16554:2;;;16600:1;16597;16590:12;16554:2;16620:78;16690:7;16681:6;16670:9;16666:22;16620:78;;;16610:88;;16495:209;16763:3;16752:9;16748:19;16735:33;-1:-1;;;;;16780:6;16777:30;16774:2;;;16820:1;16817;16810:12;16774:2;16840:86;16918:7;16909:6;16898:9;16894:22;16840:86;;;16830:96;;16714:218;15858:1084;;;;;;;;;16949:651;;;17128:2;17116:9;17107:7;17103:23;17099:32;17096:2;;;17144:1;17141;17134:12;17096:2;17179:24;;-1:-1;;;;;17212:30;;17209:2;;;17255:1;17252;17245:12;17209:2;17275:85;17352:7;17343:6;17332:9;17328:22;17275:85;;;17265:95;;17158:208;17418:2;17407:9;17403:18;17397:25;-1:-1;;;;;17434:6;17431:30;17428:2;;;17474:1;17471;17464:12;17428:2;17494:90;17576:7;17567:6;17556:9;17552:22;17494:90;;;17484:100;;17376:214;17090:510;;;;;;17607:365;;;17730:2;17718:9;17709:7;17705:23;17701:32;17698:2;;;17746:1;17743;17736:12;17698:2;17781:31;;-1:-1;;;;;17821:30;;17818:2;;;17864:1;17861;17854:12;17818:2;17892:64;17948:7;17939:6;17928:9;17924:22;17892:64;;;17882:74;;;;17760:202;17692:280;;;;;;17979:490;;;;18119:2;18107:9;18098:7;18094:23;18090:32;18087:2;;;18135:1;18132;18125:12;18087:2;18170:31;;-1:-1;;;;;18210:30;;18207:2;;;18253:1;18250;18243:12;18207:2;18281:64;18337:7;18328:6;18317:9;18313:22;18281:64;;;18271:74;;;;18149:202;18382:2;18400:53;18445:7;18436:6;18425:9;18421:22;18400:53;;;18390:63;;18361:98;18081:388;;;;;;18476:314;;18616:3;18604:9;18595:7;18591:23;18587:33;18584:2;;;18633:1;18630;18623:12;18584:2;18668:1;18685:89;18766:7;18746:9;18685:89;;18797:263;;18912:2;18900:9;18891:7;18887:23;18883:32;18880:2;;;18928:1;18925;18918:12;18880:2;18963:1;18980:64;19036:7;19016:9;18980:64;;19067:399;;;19199:2;19187:9;19178:7;19174:23;19170:32;19167:2;;;19215:1;19212;19205:12;19167:2;19250:1;19267:64;19323:7;19303:9;19267:64;;;19257:74;;19229:108;19368:2;19386:64;19442:7;19433:6;19422:9;19418:22;19386:64;;19474:173;;19561:46;19603:3;19595:6;19561:46;;;-1:-1;;19636:4;19627:14;;19554:93;19655:103;19728:24;19746:5;19728:24;;;19723:3;19716:37;19710:48;;;19916:690;;20061:54;20109:5;20061:54;;;20128:86;20207:6;20202:3;20128:86;;;20121:93;;20235:56;20285:5;20235:56;;;20311:7;20339:1;20324:260;20349:6;20346:1;20343:13;20324:260;;;20416:6;20410:13;20437:63;20496:3;20481:13;20437:63;;;20430:70;;20517:60;20570:6;20517:60;;;20507:70;-1:-1;;20371:1;20364:9;20324:260;;;-1:-1;20597:3;;20040:566;-1:-1;;;;;20040:566;20614:110;20695:23;20712:5;20695:23;;20731:343;;20841:38;20873:5;20841:38;;;20891:70;20954:6;20949:3;20891:70;;;20884:77;;20966:52;21011:6;21006:3;20999:4;20992:5;20988:16;20966:52;;;21039:29;21061:6;21039:29;;;21030:39;;;;20821:253;-1:-1;;;20821:253;21081:356;;21209:38;21241:5;21209:38;;;21259:88;21340:6;21335:3;21259:88;;;21252:95;;21352:52;21397:6;21392:3;21385:4;21378:5;21374:16;21352:52;;;21416:16;;;;;21189:248;-1:-1;;21189:248;21766:160;21866:54;21914:5;21866:54;;21933:190;22048:69;22111:5;22048:69;;22183:2778;22404:23;;22183:2778;;22328:6;22319:16;;;22433:63;22323:3;22404:23;22433:63;;;22350:152;22583:4;22576:5;22572:16;22566:23;22595:63;22652:4;22647:3;22643:14;22629:12;22595:63;;;22512:152;22752:4;22745:5;22741:16;22735:23;22764:63;22821:4;22816:3;22812:14;22798:12;22764:63;;;22674:159;22915:4;22908:5;22904:16;22898:23;22927:63;22984:4;22979:3;22975:14;22961:12;22927:63;;;22843:153;23081:4;23074:5;23070:16;23064:23;23093:63;23150:4;23145:3;23141:14;23127:12;23093:63;;;23006:156;23247:4;23240:5;23236:16;23230:23;23259:63;23316:4;23311:3;23307:14;23293:12;23259:63;;;23172:156;23405:4;23398:5;23394:16;23388:23;23417:63;23474:4;23469:3;23465:14;23451:12;23417:63;;;23338:148;23563:4;23556:5;23552:16;23546:23;23575:63;23632:4;23627:3;23623:14;23609:12;23575:63;;;23496:148;23734:6;23727:5;23723:18;23717:25;23748:65;23805:6;23800:3;23796:16;23782:12;23748:65;;;23654:165;23892:6;23885:5;23881:18;23875:25;23906:65;23963:6;23958:3;23954:16;23940:12;23906:65;;;23829:148;24060:6;24053:5;24049:18;24043:25;24116:3;24110:4;24106:14;24097:6;24092:3;24088:16;24081:40;24136:67;24198:4;24184:12;24136:67;;;24128:75;;23987:228;24298:6;24291:5;24287:18;24281:25;24354:3;24348:4;24344:14;24335:6;24330:3;24326:16;24319:40;24374:67;24436:4;24422:12;24374:67;;;24366:75;;24225:228;24539:6;24532:5;24528:18;24522:25;24595:3;24589:4;24585:14;24576:6;24571:3;24567:16;24560:40;24615:67;24677:4;24663:12;24615:67;;;24607:75;;24463:231;24780:6;24773:5;24769:18;24763:25;24836:3;24830:4;24826:14;24817:6;24812:3;24808:16;24801:40;24856:67;24918:4;24904:12;24856:67;;;24848:75;22301:2660;-1:-1;;;;;22301:2660;25027:2298;25250:23;;25027:2298;;25174:6;25165:16;;;25279:63;25169:3;25250:23;25279:63;;;25196:152;25429:4;25422:5;25418:16;25412:23;25441:63;25498:4;25493:3;25489:14;25475:12;25441:63;;;25358:152;25598:4;25591:5;25587:16;25581:23;25610:63;25667:4;25662:3;25658:14;25644:12;25610:63;;;25520:159;25761:4;25754:5;25750:16;25744:23;25773:63;25830:4;25825:3;25821:14;25807:12;25773:63;;;25689:153;25927:4;25920:5;25916:16;25910:23;25939:63;25996:4;25991:3;25987:14;25973:12;25939:63;;;25852:156;26093:4;26086:5;26082:16;26076:23;26105:63;26162:4;26157:3;26153:14;26139:12;26105:63;;;26018:156;26251:4;26244:5;26240:16;26234:23;26263:63;26320:4;26315:3;26311:14;26297:12;26263:63;;;26184:148;26409:4;26402:5;26398:16;26392:23;26421:63;26478:4;26473:3;26469:14;26455:12;26421:63;;;26342:148;26580:6;26573:5;26569:18;26563:25;26594:65;26651:6;26646:3;26642:16;26628:12;26594:65;;;26500:165;26738:6;26731:5;26727:18;26721:25;26752:65;26809:6;26804:3;26800:16;26786:12;26752:65;;;26675:148;26906:6;26899:5;26895:18;26889:25;26962:3;26956:4;26952:14;26943:6;26938:3;26934:16;26927:40;26982:67;27044:4;27030:12;26982:67;;;26974:75;;26833:228;27144:6;27137:5;27133:18;27127:25;27200:3;27194:4;27190:14;27181:6;27176:3;27172:16;27165:40;27220:67;27282:4;27268:12;27220:67;;27332:103;27405:24;27423:5;27405:24;;27562:262;;27706:93;27795:3;27786:6;27706:93;;27831:213;27949:2;27934:18;;27963:71;27938:9;28007:6;27963:71;;28051:324;28197:2;28182:18;;28211:71;28186:9;28255:6;28211:71;;;28293:72;28361:2;28350:9;28346:18;28337:6;28293:72;;28382:1039;28730:3;28715:19;;28745:71;28719:9;28789:6;28745:71;;;28827:72;28895:2;28884:9;28880:18;28871:6;28827:72;;;28947:9;28941:4;28937:20;28932:2;28921:9;28917:18;28910:48;28972:108;29075:4;29066:6;28972:108;;;28964:116;;29128:9;29122:4;29118:20;29113:2;29102:9;29098:18;29091:48;29153:108;29256:4;29247:6;29153:108;;;29145:116;;29310:9;29304:4;29300:20;29294:3;29283:9;29279:19;29272:49;29335:76;29406:4;29397:6;29335:76;;;29327:84;28701:720;-1:-1;;;;;;;28701:720;29428:435;29602:2;29587:18;;29616:71;29591:9;29660:6;29616:71;;;29698:72;29766:2;29755:9;29751:18;29742:6;29698:72;;;29781;29849:2;29838:9;29834:18;29825:6;29781:72;;29870:324;30016:2;30001:18;;30030:71;30005:9;30074:6;30030:71;;;30112:72;30180:2;30169:9;30165:18;30156:6;30112:72;;30201:209;30317:2;30302:18;;30331:69;30306:9;30373:6;30331:69;;30417:297;30553:2;30567:47;;;30538:18;;30628:76;30538:18;30690:6;30628:76;;30721:469;30912:2;30897:18;;30926:88;30901:9;30987:6;30926:88;;;31025:72;31093:2;31082:9;31078:18;31069:6;31025:72;;31197:499;31403:2;31388:18;;31417:103;31392:9;31493:6;31417:103;;31703:655;31939:2;31953:47;;;31924:18;;32014:102;31924:18;32102:6;32014:102;;;32006:110;;32127:72;32195:2;32184:9;32180:18;32171:6;32127:72;;;32247:9;32241:4;32237:20;32232:2;32221:9;32217:18;32210:48;32272:76;32343:4;32334:6;32272:76;;32365:659;32603:2;32617:47;;;32588:18;;32678:104;32588:18;32768:6;32678:104;;33031:213;33149:2;33134:18;;33163:71;33138:9;33207:6;33163:71;;33251:324;33397:2;33382:18;;33411:71;33386:9;33455:6;33411:71;;33582:256;33644:2;33638:9;33670:17;;;-1:-1;;;;;33730:34;;33766:22;;;33727:62;33724:2;;;33802:1;33799;33792:12;33724:2;33818;33811:22;33622:216;;-1:-1;33622:216;33845:312;;-1:-1;;;;;34004:6;34001:30;33998:2;;;34044:1;34041;34034:12;33998:2;-1:-1;34079:4;34067:17;;;34132:15;;33935:222;35739:317;;-1:-1;;;;;35870:6;35867:30;35864:2;;;35910:1;35907;35900:12;35864:2;-1:-1;36041:4;35977;35954:17;;;;-1:-1;;35950:33;36031:15;;35801:255;36221:137;36324:12;;36295:63;36733:178;36851:19;;;36900:4;36891:14;;36844:67;37404:91;;37466:24;37484:5;37466:24;;37608:144;-1:-1;;;;;;37669:78;;37652:100;37759:144;37840:5;37846:52;37840:5;37846:52;;37910:174;38006:5;38012:67;38006:5;38012:67;;38091:121;-1:-1;;;;;38153:54;;38136:76;38219:72;38281:5;38264:27;38298:144;;38394:43;38431:5;38394:43;;38449:174;;38560:58;38612:5;38560:58;;38631:145;38712:6;38707:3;38702;38689:30;-1:-1;38768:1;38750:16;;38743:27;38682:94;38785:268;38850:1;38857:101;38871:6;38868:1;38865:13;38857:101;;;38938:11;;;38932:18;38919:11;;;38912:39;38893:2;38886:10;38857:101;;;38973:6;38970:1;38967:13;38964:2;;;-1:-1;;39038:1;39020:16;;39013:27;38834:219;39061:97;39149:2;39129:14;-1:-1;;39125:28;;39109:49;39166:110;39254:1;39247:5;39244:12;39234:2;;39260:9;39283:125;39386:1;39379:5;39376:12;39366:2;;39392:9;39415:117;39484:24;39502:5;39484:24;;;39477:5;39474:35;39464:2;;39523:1;39520;39513:12;39679:117;39748:24;39766:5;39748:24;

Swarm Source

bzzr://5ba344f84431786b3add62b5df363dfefbf78656c0fb939708d0e1f4476aa960

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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

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