MATIC Price: $0.747724 (+9.33%)
Gas: 53 GWei
 

Overview

MATIC Balance

Polygon PoS Chain LogoPolygon PoS Chain LogoPolygon PoS Chain Logo0 MATIC

MATIC Value

$0.00

Token Holdings

Sponsored

Transaction Hash
Method
Block
From
To
Value
Register Token572037652024-05-21 1:01:1413 hrs ago1716253274IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0065227555.2733649
Register Token572006722024-05-20 23:03:4015 hrs ago1716246220IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0054248845.97007231
Register Token571996762024-05-20 22:25:5815 hrs ago1716243958IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0060260251.06927695
Register Token571957612024-05-20 20:00:4518 hrs ago1716235245IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.03853519326.54454318
Register Token571917982024-05-20 17:29:2420 hrs ago1716226164IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0058648349.69816176
Register Token571905902024-05-20 16:42:5121 hrs ago1716223371IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0057552248.76936537
Register Token571904242024-05-20 16:35:5521 hrs ago1716222955IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.005420745.93464606
Register Token571893122024-05-20 15:52:1322 hrs ago1716220333IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0059117950.10628756
Register Token571889482024-05-20 15:37:4222 hrs ago1716219462IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0076174264.54956308
Register Token571887112024-05-20 15:28:0422 hrs ago1716218884IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0106040889.85830884
Register Token571885922024-05-20 15:23:3822 hrs ago1716218618IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0102337686.7201888
Register Token571882882024-05-20 15:11:1622 hrs ago1716217876IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.007056859.79887398
Register Token571879892024-05-20 14:59:3423 hrs ago1716217174IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0062136852.65431458
Register Token571523182024-05-19 16:35:1645 hrs ago1716136516IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.005310445.0000001
Register Token571519832024-05-19 16:21:4845 hrs ago1716135708IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.005310445.00000009
Register Token571518752024-05-19 16:18:0045 hrs ago1716135480IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.005310445.0000005
Register Token571159672024-05-18 17:41:132 days ago1716054073IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.005365345.46988254
Register Token571159572024-05-18 17:40:492 days ago1716054049IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.005360145.42113903
Register Token570935052024-05-18 3:20:153 days ago1716002415IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0012377745.00000025
Register Token570935032024-05-18 3:20:093 days ago1716002409IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0053098645.00000025
Register Token570933762024-05-18 3:14:353 days ago1716002075IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0053098645.00000015
Register Token570932412024-05-18 3:09:473 days ago1716001787IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.005310445.00000017
Register Token570928322024-05-18 2:54:143 days ago1716000854IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0053098645.0000013
Register Token570863872024-05-17 22:41:133 days ago1715985673IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.005310445.00000006
Register Token570843362024-05-17 21:23:083 days ago1715980988IN
0x4bFb41d5...Bd8B8982E
0 MATIC0.0053093245.00000006
View all transactions

Parent Transaction Hash Block From To Value
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CTFExchange

Compiler Version
v0.8.15+commit.e14f2714

Optimization Enabled:
Yes with 1000000 runs

Other Settings:
default evmVersion
File 1 of 46 : CTFExchange.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

import { Auth } from "./mixins/Auth.sol";
import { Fees } from "./mixins/Fees.sol";
import { Assets } from "./mixins/Assets.sol";
import { Hashing } from "./mixins/Hashing.sol";
import { Trading } from "./mixins/Trading.sol";
import { Registry } from "./mixins/Registry.sol";
import { Pausable } from "./mixins/Pausable.sol";
import { Signatures } from "./mixins/Signatures.sol";
import { NonceManager } from "./mixins/NonceManager.sol";
import { AssetOperations } from "./mixins/AssetOperations.sol";

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

import { Order } from "./libraries/OrderStructs.sol";

/// @title CTF Exchange
/// @notice Implements logic for trading CTF assets
/// @author Polymarket
contract CTFExchange is
    BaseExchange,
    Auth,
    Assets,
    Fees,
    Pausable,
    AssetOperations,
    Hashing("Polymarket CTF Exchange", "1"),
    NonceManager,
    Registry,
    Signatures,
    Trading
{
    constructor(address _collateral, address _ctf, address _proxyFactory, address _safeFactory)
        Assets(_collateral, _ctf)
        Signatures(_proxyFactory, _safeFactory)
    { }

    /*//////////////////////////////////////////////////////////////
                        PAUSE
    //////////////////////////////////////////////////////////////*/

    /// @notice Pause trading on the Exchange
    function pauseTrading() external onlyAdmin {
        _pauseTrading();
    }

    /// @notice Unpause trading on the Exchange
    function unpauseTrading() external onlyAdmin {
        _unpauseTrading();
    }

    /*//////////////////////////////////////////////////////////////
                        TRADING
    //////////////////////////////////////////////////////////////*/

    /// @notice Fills an order
    /// @param order        - The order to be filled
    /// @param fillAmount   - The amount to be filled, always in terms of the maker amount
    function fillOrder(Order memory order, uint256 fillAmount) external nonReentrant onlyOperator notPaused {
        _fillOrder(order, fillAmount, msg.sender);
    }

    /// @notice Fills a set of orders
    /// @param orders       - The order to be filled
    /// @param fillAmounts  - The amounts to be filled, always in terms of the maker amount
    function fillOrders(Order[] memory orders, uint256[] memory fillAmounts)
        external
        nonReentrant
        onlyOperator
        notPaused
    {
        _fillOrders(orders, fillAmounts, msg.sender);
    }

    /// @notice Matches a taker order against a list of maker orders
    /// @param takerOrder       - The active order to be matched
    /// @param makerOrders      - The array of maker orders to be matched against the active order
    /// @param takerFillAmount  - The amount to fill on the taker order, always in terms of the maker amount
    /// @param makerFillAmounts - The array of amounts to fill on the maker orders, always in terms of the maker amount
    function matchOrders(
        Order memory takerOrder,
        Order[] memory makerOrders,
        uint256 takerFillAmount,
        uint256[] memory makerFillAmounts
    ) external nonReentrant onlyOperator notPaused {
        _matchOrders(takerOrder, makerOrders, takerFillAmount, makerFillAmounts);
    }

    /*//////////////////////////////////////////////////////////////
                        CONFIGURATION
    //////////////////////////////////////////////////////////////*/

    /// @notice Sets a new Proxy Wallet factory for the Exchange
    /// @param _newProxyFactory - The new Proxy Wallet factory
    function setProxyFactory(address _newProxyFactory) external onlyAdmin {
        _setProxyFactory(_newProxyFactory);
    }

    /// @notice Sets a new safe factory for the Exchange
    /// @param _newSafeFactory  - The new Safe wallet factory
    function setSafeFactory(address _newSafeFactory) external onlyAdmin {
        _setSafeFactory(_newSafeFactory);
    }

    /// @notice Registers a tokenId, its complement and its conditionId for trading on the Exchange
    /// @param token        - The tokenId being registered
    /// @param complement   - The complement of the tokenId
    /// @param conditionId  - The CTF conditionId
    function registerToken(uint256 token, uint256 complement, bytes32 conditionId) external onlyAdmin {
        _registerToken(token, complement, conditionId);
    }
}

File 1 of 46 : IERC1271.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC1271.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC1271 standard signature validation method for
 * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
 *
 * _Available since v4.1._
 */
interface IERC1271 {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     * @param hash      Hash of the data to be signed
     * @param signature Signature byte array associated with _data
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

File 1 of 46 : IERC1155.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

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

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

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

File 1 of 46 : ERC1155Holder.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/utils/ERC1155Holder.sol)

pragma solidity ^0.8.0;

import "./ERC1155Receiver.sol";

/**
 * Simple implementation of `ERC1155Receiver` that will allow a contract to hold ERC1155 tokens.
 *
 * IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
 * stuck.
 *
 * @dev _Available since v3.1._
 */
contract ERC1155Holder is ERC1155Receiver {
    function onERC1155Received(
        address,
        address,
        uint256,
        uint256,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC1155Received.selector;
    }

    function onERC1155BatchReceived(
        address,
        address,
        uint256[] memory,
        uint256[] memory,
        bytes memory
    ) public virtual override returns (bytes4) {
        return this.onERC1155BatchReceived.selector;
    }
}

File 1 of 46 : ERC1155Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol)

pragma solidity ^0.8.0;

import "../IERC1155Receiver.sol";
import "../../../utils/introspection/ERC165.sol";

/**
 * @dev _Available since v3.1._
 */
abstract contract ERC1155Receiver is ERC165, IERC1155Receiver {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
        return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
    }
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.0;

import "./math/Math.sol";

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

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

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

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

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

pragma solidity ^0.8.0;

import "../Strings.sol";

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

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

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

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

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

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

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

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

        return (signer, RecoverError.NoError);
    }

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

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

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

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

File 1 of 46 : EIP712.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./ECDSA.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 */
abstract contract EIP712 {
    /* solhint-disable var-name-mixedcase */
    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
    uint256 private immutable _CACHED_CHAIN_ID;
    address private immutable _CACHED_THIS;

    bytes32 private immutable _HASHED_NAME;
    bytes32 private immutable _HASHED_VERSION;
    bytes32 private immutable _TYPE_HASH;

    /* solhint-enable var-name-mixedcase */

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        bytes32 typeHash = keccak256(
            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
        );
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
        _CACHED_CHAIN_ID = block.chainid;
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
        _CACHED_THIS = address(this);
        _TYPE_HASH = typeHash;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
            return _CACHED_DOMAIN_SEPARATOR;
        } else {
            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
        }
    }

    function _buildDomainSeparator(
        bytes32 typeHash,
        bytes32 nameHash,
        bytes32 versionHash
    ) private view returns (bytes32) {
        return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
    }
}

File 1 of 46 : draft-EIP712.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// EIP-712 is Final as of 2022-08-11. This file is deprecated.

import "./EIP712.sol";

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

pragma solidity ^0.8.0;

import "./IERC165.sol";

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

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

pragma solidity ^0.8.0;

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

File 1 of 46 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
     * with further edits by Uniswap Labs also under MIT license.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator
    ) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod0 := mul(x, y)
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

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

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            require(denominator > prod1);

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

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

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

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
            // See https://cs.stackexchange.com/q/138556/92363.

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

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

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

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

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

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

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

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(
        uint256 x,
        uint256 y,
        uint256 denominator,
        Rounding rounding
    ) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10**64) {
                value /= 10**64;
                result += 64;
            }
            if (value >= 10**32) {
                value /= 10**32;
                result += 32;
            }
            if (value >= 10**16) {
                value /= 10**16;
                result += 16;
            }
            if (value >= 10**8) {
                value /= 10**8;
                result += 8;
            }
            if (value >= 10**4) {
                value /= 10**4;
                result += 4;
            }
            if (value >= 10**2) {
                value /= 10**2;
                result += 2;
            }
            if (value >= 10**1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0);
        }
    }
}

File 1 of 46 : ERC20.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event Transfer(address indexed from, address indexed to, uint256 amount);

    event Approval(address indexed owner, address indexed spender, uint256 amount);

    /*//////////////////////////////////////////////////////////////
                            METADATA STORAGE
    //////////////////////////////////////////////////////////////*/

    string public name;

    string public symbol;

    uint8 public immutable decimals;

    /*//////////////////////////////////////////////////////////////
                              ERC20 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;

    mapping(address => mapping(address => uint256)) public allowance;

    /*//////////////////////////////////////////////////////////////
                            EIP-2612 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 internal immutable INITIAL_CHAIN_ID;

    bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;

    mapping(address => uint256) public nonces;

    /*//////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;

        INITIAL_CHAIN_ID = block.chainid;
        INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
    }

    /*//////////////////////////////////////////////////////////////
                               ERC20 LOGIC
    //////////////////////////////////////////////////////////////*/

    function approve(address spender, uint256 amount) public virtual returns (bool) {
        allowance[msg.sender][spender] = amount;

        emit Approval(msg.sender, spender, amount);

        return true;
    }

    function transfer(address to, uint256 amount) public virtual returns (bool) {
        balanceOf[msg.sender] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(msg.sender, to, amount);

        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual returns (bool) {
        uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.

        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;

        balanceOf[from] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(from, to, amount);

        return true;
    }

    /*//////////////////////////////////////////////////////////////
                             EIP-2612 LOGIC
    //////////////////////////////////////////////////////////////*/

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        // Unchecked because the only math done is incrementing
        // the owner's nonce which cannot realistically overflow.
        unchecked {
            address recoveredAddress = ecrecover(
                keccak256(
                    abi.encodePacked(
                        "\x19\x01",
                        DOMAIN_SEPARATOR(),
                        keccak256(
                            abi.encode(
                                keccak256(
                                    "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
                                ),
                                owner,
                                spender,
                                value,
                                nonces[owner]++,
                                deadline
                            )
                        )
                    )
                ),
                v,
                r,
                s
            );

            require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }

    function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
        return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
    }

    function computeDomainSeparator() internal view virtual returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
                    keccak256(bytes(name)),
                    keccak256("1"),
                    block.chainid,
                    address(this)
                )
            );
    }

    /*//////////////////////////////////////////////////////////////
                        INTERNAL MINT/BURN LOGIC
    //////////////////////////////////////////////////////////////*/

    function _mint(address to, uint256 amount) internal virtual {
        totalSupply += amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(address(0), to, amount);
    }

    function _burn(address from, uint256 amount) internal virtual {
        balanceOf[from] -= amount;

        // Cannot underflow because a user's balance
        // will never be larger than the total supply.
        unchecked {
            totalSupply -= amount;
        }

        emit Transfer(from, address(0), amount);
    }
}

File 1 of 46 : SafeTransferLib.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

import {ERC20} from "../tokens/ERC20.sol";

/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
    /*//////////////////////////////////////////////////////////////
                             ETH OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferETH(address to, uint256 amount) internal {
        bool success;

        assembly {
            // Transfer the ETH and store if it succeeded or not.
            success := call(gas(), to, amount, 0, 0, 0, 0)
        }

        require(success, "ETH_TRANSFER_FAILED");
    }

    /*//////////////////////////////////////////////////////////////
                            ERC20 OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferFrom(
        ERC20 token,
        address from,
        address to,
        uint256 amount
    ) internal {
        bool success;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), from) // Append the "from" argument.
            mstore(add(freeMemoryPointer, 36), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
            )
        }

        require(success, "TRANSFER_FROM_FAILED");
    }

    function safeTransfer(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "TRANSFER_FAILED");
    }

    function safeApprove(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "APPROVE_FAILED");
    }
}

File 1 of 46 : ReentrancyGuard.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Forked from Solmate to handle clones.
/// @author Polymarket
/// @author Modified from Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
    uint256 private locked = 1;

    modifier nonReentrant() virtual {
        require(locked != 2, "REENTRANCY");

        locked = 2;

        _;

        locked = 1;
    }
}

File 1 of 46 : SafeTransferLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import {SafeTransferLib, ERC20} from "solmate/utils/SafeTransferLib.sol";

File 1 of 46 : BaseExchange.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { ERC1155Holder } from "openzeppelin-contracts/token/ERC1155/utils/ERC1155Holder.sol";
import { ReentrancyGuard } from "common/ReentrancyGuard.sol";

abstract contract BaseExchange is ERC1155Holder, ReentrancyGuard { }

File 2 of 46 : IAssetOperations.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

abstract contract IAssetOperations {
    function _getBalance(uint256 tokenId) internal virtual returns (uint256);

    function _transfer(address from, address to, uint256 id, uint256 value) internal virtual;

    function _mint(bytes32 conditionId, uint256 amount) internal virtual;

    function _merge(bytes32 conditionId, uint256 amount) internal virtual;
}

File 2 of 46 : IAssets.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

abstract contract IAssets {
    function getCollateral() public virtual returns (address);

    function getCtf() public virtual returns (address);
}

File 2 of 46 : IAuth.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

interface IAuthEE {
    error NotAdmin();
    error NotOperator();

    /// @notice Emitted when a new admin is added
    event NewAdmin(address indexed newAdminAddress, address indexed admin);

    /// @notice Emitted when a new operator is added
    event NewOperator(address indexed newOperatorAddress, address indexed admin);

    /// @notice Emitted when an admin is removed
    event RemovedAdmin(address indexed removedAdmin, address indexed admin);

    /// @notice Emitted when an operator is removed
    event RemovedOperator(address indexed removedOperator, address indexed admin);
}

interface IAuth is IAuthEE {
    function isAdmin(address) external view returns (bool);

    function isOperator(address) external view returns (bool);

    function addAdmin(address) external;

    function addOperator(address) external;

    function removeAdmin(address) external;

    function removeOperator(address) external;

    function renounceAdminRole() external;

    function renounceOperatorRole() external;
}

File 2 of 46 : IConditionalTokens.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol";

/// @title IConditionalTokens
/// @notice Interface for the Gnosis ConditionalTokensFramework: https://github.com/gnosis/conditional-tokens-contracts/blob/master/contracts/ConditionalTokens.sol
interface IConditionalTokens {
    function payoutNumerators(bytes32 conditionId, uint256 index) external view returns (uint256);

    function payoutDenominator(bytes32 conditionId) external view returns (uint256);

    /// @dev This function prepares a condition by initializing a payout vector associated with the condition.
    /// @param oracle The account assigned to report the result for the prepared condition.
    /// @param questionId An identifier for the question to be answered by the oracle.
    /// @param outcomeSlotCount The number of outcome slots which should be used for this condition. Must not exceed 256.
    function prepareCondition(address oracle, bytes32 questionId, uint256 outcomeSlotCount) external;

    /// @dev Called by the oracle for reporting results of conditions. Will set the payout vector for the condition with the ID ``keccak256(abi.encodePacked(oracle, questionId, outcomeSlotCount))``, where oracle is the message sender, questionId is one of the parameters of this function, and outcomeSlotCount is the length of the payouts parameter, which contains the payoutNumerators for each outcome slot of the condition.
    /// @param questionId The question ID the oracle is answering for
    /// @param payouts The oracle's answer
    function reportPayouts(bytes32 questionId, uint256[] calldata payouts) external;

    /// @dev This function splits a position. If splitting from the collateral, this contract will attempt to transfer `amount` collateral from the message sender to itself. Otherwise, this contract will burn `amount` stake held by the message sender in the position being split worth of EIP 1155 tokens. Regardless, if successful, `amount` stake will be minted in the split target positions. If any of the transfers, mints, or burns fail, the transaction will revert. The transaction will also revert if the given partition is trivial, invalid, or refers to more slots than the condition is prepared with.
    /// @param collateralToken The address of the positions' backing collateral token.
    /// @param parentCollectionId The ID of the outcome collections common to the position being split and the split target positions. May be null, in which only the collateral is shared.
    /// @param conditionId The ID of the condition to split on.
    /// @param partition An array of disjoint index sets representing a nontrivial partition of the outcome slots of the given condition. E.g. A|B and C but not A|B and B|C (is not disjoint). Each element's a number which, together with the condition, represents the outcome collection. E.g. 0b110 is A|B, 0b010 is B, etc.
    /// @param amount The amount of collateral or stake to split.
    function splitPosition(
        IERC20 collateralToken,
        bytes32 parentCollectionId,
        bytes32 conditionId,
        uint256[] calldata partition,
        uint256 amount
    ) external;

    /// @dev This function merges CTF tokens into the underlying collateral.
    /// @param collateralToken The address of the positions' backing collateral token.
    /// @param parentCollectionId The ID of the outcome collections common to the position being split and the split target positions. May be null, in which only the collateral is shared.
    /// @param conditionId The ID of the condition to split on.
    /// @param partition An array of disjoint index sets representing a nontrivial partition of the outcome slots of the given condition. E.g. A|B and C but not A|B and B|C (is not disjoint). Each element's a number which, together with the condition, represents the outcome collection. E.g. 0b110 is A|B, 0b010 is B, etc.
    /// @param amount The amount of collateral or stake to split.
    function mergePositions(
        IERC20 collateralToken,
        bytes32 parentCollectionId,
        bytes32 conditionId,
        uint256[] calldata partition,
        uint256 amount
    ) external;

    /// @dev This function redeems a CTF ERC1155 token for the underlying collateral
    /// @param collateralToken The address of the positions' backing collateral token.
    /// @param parentCollectionId The ID of the outcome collections common to the position
    /// @param conditionId The ID of the condition to split on.
    /// @param indexSets Index sets of the outcome collection to combine with the parent outcome collection
    function redeemPositions(
        IERC20 collateralToken,
        bytes32 parentCollectionId,
        bytes32 conditionId,
        uint256[] calldata indexSets
    ) external;

    /// @dev Gets the outcome slot count of a condition.
    /// @param conditionId ID of the condition.
    /// @return Number of outcome slots associated with a condition, or zero if condition has not been prepared yet.
    function getOutcomeSlotCount(bytes32 conditionId) external view returns (uint256);

    /// @dev Constructs a condition ID from an oracle, a question ID, and the outcome slot count for the question.
    /// @param oracle The account assigned to report the result for the prepared condition.
    /// @param questionId An identifier for the question to be answered by the oracle.
    /// @param outcomeSlotCount The number of outcome slots which should be used for this condition. Must not exceed 256.
    function getConditionId(address oracle, bytes32 questionId, uint256 outcomeSlotCount)
        external
        pure
        returns (bytes32);

    /// @dev Constructs an outcome collection ID from a parent collection and an outcome collection.
    /// @param parentCollectionId Collection ID of the parent outcome collection, or bytes32(0) if there's no parent.
    /// @param conditionId Condition ID of the outcome collection to combine with the parent outcome collection.
    /// @param indexSet Index set of the outcome collection to combine with the parent outcome collection.
    function getCollectionId(bytes32 parentCollectionId, bytes32 conditionId, uint256 indexSet)
        external
        view
        returns (bytes32);

    /// @dev Constructs a position ID from a collateral token and an outcome collection. These IDs are used as the ERC-1155 ID for this contract.
    /// @param collateralToken Collateral token which backs the position.
    /// @param collectionId ID of the outcome collection associated with this position.
    function getPositionId(IERC20 collateralToken, bytes32 collectionId) external pure returns (uint256);
}

File 2 of 46 : IFees.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

interface IFeesEE {
    error FeeTooHigh();

    /// @notice Emitted when a fee is charged
    event FeeCharged(address indexed receiver, uint256 tokenId, uint256 amount);
}

abstract contract IFees is IFeesEE {
    function getMaxFeeRate() public pure virtual returns (uint256);
}

File 2 of 46 : IHashing.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { Order } from "../libraries/OrderStructs.sol";

abstract contract IHashing {
    function hashOrder(Order memory order) public view virtual returns (bytes32);
}

File 2 of 46 : INonceManager.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

abstract contract INonceManager {
    function incrementNonce() external virtual;

    function isValidNonce(address user, uint256 userNonce) public view virtual returns (bool);
}

File 2 of 46 : IPausable.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

interface IPausableEE {
    error Paused();

    event TradingPaused(address indexed pauser);

    event TradingUnpaused(address indexed pauser);
}

abstract contract IPausable is IPausableEE {
    function _pauseTrading() internal virtual;

    function _unpauseTrading() internal virtual;
}

File 2 of 46 : IRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

interface IRegistryEE {
    error InvalidComplement();
    error InvalidTokenId();
    error AlreadyRegistered();

    /// @notice Emitted when a token is registered
    event TokenRegistered(uint256 indexed token0, uint256 indexed token1, bytes32 indexed conditionId);
}

abstract contract IRegistry is IRegistryEE {
    function getConditionId(uint256 tokenId) public view virtual returns (bytes32);

    function getComplement(uint256 tokenId) public view virtual returns (uint256);

    function validateTokenId(uint256 tokenId) public view virtual;

    function validateComplement(uint256 token0, uint256 token1) public view virtual;
}

File 2 of 46 : ISignatures.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { Order } from "../libraries/OrderStructs.sol";

interface ISignaturesEE {
    error InvalidSignature();
}

abstract contract ISignatures is ISignaturesEE {
    function validateOrderSignature(bytes32 orderHash, Order memory order) public view virtual;
}

File 2 of 46 : ITrading.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { OrderStatus, Order } from "../libraries/OrderStructs.sol";

interface ITradingEE {
    error NotOwner();
    error NotTaker();
    error OrderFilledOrCancelled();
    error OrderExpired();
    error InvalidNonce();
    error MakingGtRemaining();
    error NotCrossing();
    error TooLittleTokensReceived();
    error MismatchedTokenIds();

    /// @notice Emitted when an order is cancelled
    event OrderCancelled(bytes32 indexed orderHash);

    /// @notice Emitted when an order is filled
    event OrderFilled(
        bytes32 indexed orderHash,
        address indexed maker,
        address indexed taker,
        uint256 makerAssetId,
        uint256 takerAssetId,
        uint256 makerAmountFilled,
        uint256 takerAmountFilled,
        uint256 fee
    );

    /// @notice Emitted when a set of orders is matched
    event OrdersMatched(
        bytes32 indexed takerOrderHash,
        address indexed takerOrderMaker,
        uint256 makerAssetId,
        uint256 takerAssetId,
        uint256 makerAmountFilled,
        uint256 takerAmountFilled
    );
}

interface ITrading is ITradingEE { }

File 2 of 46 : CalculatorHelper.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { Order, Side } from "../libraries/OrderStructs.sol";

library CalculatorHelper {
    uint256 internal constant ONE = 10 ** 18;

    uint256 internal constant BPS_DIVISOR = 10_000;

    function calculateTakingAmount(uint256 makingAmount, uint256 makerAmount, uint256 takerAmount)
        internal
        pure
        returns (uint256)
    {
        if (makerAmount == 0) return 0;
        return makingAmount * takerAmount / makerAmount;
    }

    /// @notice Calculates the fee for an order
    /// @dev Fees are calculated based on amount of outcome tokens and the order's feeRate
    /// @param feeRateBps       - Fee rate, in basis points
    /// @param outcomeTokens    - The number of outcome tokens
    /// @param makerAmount      - The maker amount of the order
    /// @param takerAmount      - The taker amount of the order
    /// @param side             - The side of the order
    function calculateFee(
        uint256 feeRateBps,
        uint256 outcomeTokens,
        uint256 makerAmount,
        uint256 takerAmount,
        Side side
    ) internal pure returns (uint256 fee) {
        if (feeRateBps > 0) {
            uint256 price = _calculatePrice(makerAmount, takerAmount, side);
            if (price > 0 && price <= ONE) {
                if (side == Side.BUY) {
                    // Fee charged on Token Proceeds:
                    // baseRate * min(price, 1-price) * (outcomeTokens/price)
                    fee = (feeRateBps * min(price, ONE - price) * outcomeTokens) / (price * BPS_DIVISOR);
                } else {
                    // Fee charged on Collateral proceeds:
                    // baseRate * min(price, 1-price) * outcomeTokens
                    fee = feeRateBps * min(price, ONE - price) * outcomeTokens / (BPS_DIVISOR * ONE);
                }
            }
        }
    }

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

    function calculatePrice(Order memory order) internal pure returns (uint256) {
        return _calculatePrice(order.makerAmount, order.takerAmount, order.side);
    }

    function _calculatePrice(uint256 makerAmount, uint256 takerAmount, Side side) internal pure returns (uint256) {
        if (side == Side.BUY) return takerAmount != 0 ? makerAmount * ONE / takerAmount : 0;
        return makerAmount != 0 ? takerAmount * ONE / makerAmount : 0;
    }

    function isCrossing(Order memory a, Order memory b) internal pure returns (bool) {
        if (a.takerAmount == 0 || b.takerAmount == 0) return true;

        return _isCrossing(calculatePrice(a), calculatePrice(b), a.side, b.side);
    }

    function _isCrossing(uint256 priceA, uint256 priceB, Side sideA, Side sideB) internal pure returns (bool) {
        if (sideA == Side.BUY) {
            if (sideB == Side.BUY) {
                // if a and b are bids
                return priceA + priceB >= ONE;
            }
            // if a is bid and b is ask
            return priceA >= priceB;
        }
        if (sideB == Side.BUY) {
            // if a is ask and b is bid
            return priceB >= priceA;
        }
        // if a and b are asks
        return priceA + priceB <= ONE;
    }
}

File 2 of 46 : OrderStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

bytes32 constant ORDER_TYPEHASH = keccak256(
    "Order(uint256 salt,address maker,address signer,address taker,uint256 tokenId,uint256 makerAmount,uint256 takerAmount,uint256 expiration,uint256 nonce,uint256 feeRateBps,uint8 side,uint8 signatureType)"
);

struct Order {
    /// @notice Unique salt to ensure entropy
    uint256 salt;
    /// @notice Maker of the order, i.e the source of funds for the order
    address maker;
    /// @notice Signer of the order
    address signer;
    /// @notice Address of the order taker. The zero address is used to indicate a public order
    address taker;
    /// @notice Token Id of the CTF ERC1155 asset to be bought or sold
    /// If BUY, this is the tokenId of the asset to be bought, i.e the makerAssetId
    /// If SELL, this is the tokenId of the asset to be sold, i.e the takerAssetId
    uint256 tokenId;
    /// @notice Maker amount, i.e the maximum amount of tokens to be sold
    uint256 makerAmount;
    /// @notice Taker amount, i.e the minimum amount of tokens to be received
    uint256 takerAmount;
    /// @notice Timestamp after which the order is expired
    uint256 expiration;
    /// @notice Nonce used for onchain cancellations
    uint256 nonce;
    /// @notice Fee rate, in basis points, charged to the order maker, charged on proceeds
    uint256 feeRateBps;
    /// @notice The side of the order: BUY or SELL
    Side side;
    /// @notice Signature type used by the Order: EOA, POLY_PROXY or POLY_GNOSIS_SAFE
    SignatureType signatureType;
    /// @notice The order signature
    bytes signature;
}

enum SignatureType
// 0: ECDSA EIP712 signatures signed by EOAs
{
    EOA,
    // 1: EIP712 signatures signed by EOAs that own Polymarket Proxy wallets
    POLY_PROXY,
    // 2: EIP712 signatures signed by EOAs that own Polymarket Gnosis safes
    POLY_GNOSIS_SAFE
}

enum Side
// 0: buy
{
    BUY,
    // 1: sell
    SELL
}

enum MatchType
// 0: buy vs sell
{
    COMPLEMENTARY,
    // 1: both buys
    MINT,
    // 2: both sells
    MERGE
}

struct OrderStatus {
    bool isFilledOrCancelled;
    uint256 remaining;
}

File 2 of 46 : PolyProxyLib.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

/// @notice Helper library to compute polymarket proxy wallet addresses
library PolyProxyLib {
    /// @notice Gets the polymarket proxy address for a signer
    /// @param signer - Address of the signer
    function getProxyWalletAddress(address signer, address implementation, address deployer)
        internal
        pure
        returns (address proxyWallet)
    {
        return _computeCreate2Address(deployer, implementation, keccak256(abi.encodePacked(signer)));
    }

    function _computeCreate2Address(address from, address target, bytes32 salt) internal pure returns (address) {
        bytes32 bytecodeHash = keccak256(_computeCreationCode(from, target));
        bytes32 _data = keccak256(abi.encodePacked(bytes1(0xff), from, salt, bytecodeHash));
        return address(uint160(uint256(_data)));
    }

    function _computeCreationCode(address deployer, address target) internal pure returns (bytes memory clone) {
        bytes memory consData = abi.encodeWithSignature("cloneConstructor(bytes)", new bytes(0));
        bytes memory buffer = new bytes(99);
        assembly {
            mstore(add(buffer, 0x20), 0x3d3d606380380380913d393d73bebebebebebebebebebebebebebebebebebebe)
            mstore(add(buffer, 0x2d), mul(deployer, 0x01000000000000000000000000))
            mstore(add(buffer, 0x41), 0x5af4602a57600080fd5b602d8060366000396000f3363d3d373d3d3d363d73be)
            mstore(add(buffer, 0x60), mul(target, 0x01000000000000000000000000))
            mstore(add(buffer, 116), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)
        }
        // clone = bytes.concat(buffer, consData);
        clone = abi.encodePacked(buffer, consData);
        return clone;
    }
}

File 2 of 46 : PolySafeLib.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

/// @title PolySafeLib
/// @notice Helper library to compute Polymarket gnosis safe addresses
library PolySafeLib {
    bytes private constant proxyCreationCode =
        hex"608060405234801561001057600080fd5b5060405161017138038061017183398101604081905261002f916100b9565b6001600160a01b0381166100945760405162461bcd60e51b815260206004820152602260248201527f496e76616c69642073696e676c65746f6e20616464726573732070726f766964604482015261195960f21b606482015260840160405180910390fd5b600080546001600160a01b0319166001600160a01b03929092169190911790556100e7565b6000602082840312156100ca578081fd5b81516001600160a01b03811681146100e0578182fd5b9392505050565b607c806100f56000396000f3fe6080604052600080546001600160a01b0316813563530ca43760e11b1415602857808252602082f35b3682833781823684845af490503d82833e806041573d82fd5b503d81f3fea264697066735822122015938e3bf2c49f5df5c1b7f9569fa85cc5d6f3074bb258a2dc0c7e299bc9e33664736f6c63430008040033";

    /// @notice Gets the Polymarket Gnosis safe address for a signer
    /// @param signer   - Address of the signer
    /// @param deployer - Address of the deployer contract
    function getSafeAddress(address signer, address implementation, address deployer)
        internal
        pure
        returns (address safe)
    {
        bytes32 bytecodeHash = keccak256(getContractBytecode(implementation));
        bytes32 salt = keccak256(abi.encode(signer));
        safe = _computeCreate2Address(deployer, bytecodeHash, salt);
    }

    function getContractBytecode(address masterCopy) internal pure returns (bytes memory) {
        return abi.encodePacked(proxyCreationCode, abi.encode(masterCopy));
    }

    function _computeCreate2Address(address deployer, bytes32 bytecodeHash, bytes32 salt)
        internal
        pure
        returns (address)
    {
        bytes32 _data = keccak256(abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash));
        return address(uint160(uint256(_data)));
    }
}

File 2 of 46 : TransferHelper.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

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

import { SafeTransferLib, ERC20 } from "common/libraries/SafeTransferLib.sol";

/// @title TransferHelper
/// @notice Helper method to transfer tokens
library TransferHelper {
    /// @notice Transfers tokens from msg.sender to a recipient
    /// @param token    - The contract address of the token which will be transferred
    /// @param to       - The recipient of the transfer
    /// @param amount   - The amount to be transferred
    function _transferERC20(address token, address to, uint256 amount) internal {
        SafeTransferLib.safeTransfer(ERC20(token), to, amount);
    }

    /// @notice Transfers tokens from the targeted address to the given destination
    /// @param token    - The contract address of the token to be transferred
    /// @param from     - The originating address from which the tokens will be transferred
    /// @param to       - The destination address of the transfer
    /// @param amount   - The amount to be transferred
    function _transferFromERC20(address token, address from, address to, uint256 amount) internal {
        SafeTransferLib.safeTransferFrom(ERC20(token), from, to, amount);
    }

    /// @notice Transfer an ERC1155 token
    /// @param token    - The contract address of the token to be transferred
    /// @param from     - The originating address from which the tokens will be transferred
    /// @param to       - The destination address of the transfer
    /// @param id       - The tokenId of the token to be transferred
    /// @param amount   - The amount to be transferred
    function _transferFromERC1155(address token, address from, address to, uint256 id, uint256 amount) internal {
        IERC1155(token).safeTransferFrom(from, to, id, amount, "");
    }

    /// @notice Transfers a set of ERC1155 tokens
    /// @param token    - The contract address of the token to be transferred
    /// @param from     - The originating address from which the tokens will be transferred
    /// @param to       - The destination address of the transfer
    /// @param ids      - The tokenId of the token to be transferred
    /// @param amounts  - The amount to be transferred
    function _batchTransferFromERC1155(
        address token,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts
    ) internal {
        IERC1155(token).safeBatchTransferFrom(from, to, ids, amounts, "");
    }
}

File 2 of 46 : AssetOperations.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import { IERC1155 } from "openzeppelin-contracts/token/ERC1155/IERC1155.sol";

import { IAssets } from "../interfaces/IAssets.sol";
import { IAssetOperations } from "../interfaces/IAssetOperations.sol";
import { IConditionalTokens } from "../interfaces/IConditionalTokens.sol";

import { TransferHelper } from "../libraries/TransferHelper.sol";

/// @title Asset Operations
/// @notice Operations on the CTF and Collateral assets
abstract contract AssetOperations is IAssetOperations, IAssets {
    bytes32 public constant parentCollectionId = bytes32(0);

    function _getBalance(uint256 tokenId) internal override returns (uint256) {
        if (tokenId == 0) return IERC20(getCollateral()).balanceOf(address(this));
        return IERC1155(getCtf()).balanceOf(address(this), tokenId);
    }

    function _transfer(address from, address to, uint256 id, uint256 value) internal override {
        if (id == 0) return _transferCollateral(from, to, value);
        return _transferCTF(from, to, id, value);
    }

    function _transferCollateral(address from, address to, uint256 value) internal {
        address token = getCollateral();
        if (from == address(this)) TransferHelper._transferERC20(token, to, value);
        else TransferHelper._transferFromERC20(token, from, to, value);
    }

    function _transferCTF(address from, address to, uint256 id, uint256 value) internal {
        TransferHelper._transferFromERC1155(getCtf(), from, to, id, value);
    }

    function _mint(bytes32 conditionId, uint256 amount) internal override {
        uint256[] memory partition = new uint256[](2);
        partition[0] = 1;
        partition[1] = 2;
        IConditionalTokens(getCtf()).splitPosition(
            IERC20(getCollateral()), parentCollectionId, conditionId, partition, amount
        );
    }

    function _merge(bytes32 conditionId, uint256 amount) internal override {
        uint256[] memory partition = new uint256[](2);
        partition[0] = 1;
        partition[1] = 2;

        IConditionalTokens(getCtf()).mergePositions(
            IERC20(getCollateral()), parentCollectionId, conditionId, partition, amount
        );
    }
}

File 2 of 46 : Assets.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol";

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

abstract contract Assets is IAssets {
    address internal immutable collateral;
    address internal immutable ctf;

    constructor(address _collateral, address _ctf) {
        collateral = _collateral;
        ctf = _ctf;
        IERC20(collateral).approve(ctf, type(uint256).max);
    }

    function getCollateral() public view override returns (address) {
        return collateral;
    }

    function getCtf() public view override returns (address) {
        return ctf;
    }
}

File 2 of 46 : Auth.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

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

/// @title Auth
/// @notice Provides admin and operator roles and access control modifiers
abstract contract Auth is IAuth {
    /// @dev The set of addresses authorized as Admins
    mapping(address => uint256) public admins;

    /// @dev The set of addresses authorized as Operators
    mapping(address => uint256) public operators;

    modifier onlyAdmin() {
        if (admins[msg.sender] != 1) revert NotAdmin();
        _;
    }

    modifier onlyOperator() {
        if (operators[msg.sender] != 1) revert NotOperator();
        _;
    }

    constructor() {
        admins[msg.sender] = 1;
        operators[msg.sender] = 1;
    }

    function isAdmin(address usr) external view returns (bool) {
        return admins[usr] == 1;
    }

    function isOperator(address usr) external view returns (bool) {
        return operators[usr] == 1;
    }

    /// @notice Adds a new admin
    /// Can only be called by a current admin
    /// @param admin_ - The new admin
    function addAdmin(address admin_) external onlyAdmin {
        admins[admin_] = 1;
        emit NewAdmin(admin_, msg.sender);
    }

    /// @notice Adds a new operator
    /// Can only be called by a current admin
    /// @param operator_ - The new operator
    function addOperator(address operator_) external onlyAdmin {
        operators[operator_] = 1;
        emit NewOperator(operator_, msg.sender);
    }

    /// @notice Removes an existing Admin
    /// Can only be called by a current admin
    /// @param admin - The admin to be removed
    function removeAdmin(address admin) external onlyAdmin {
        admins[admin] = 0;
        emit RemovedAdmin(admin, msg.sender);
    }

    /// @notice Removes an existing operator
    /// Can only be called by a current admin
    /// @param operator - The operator to be removed
    function removeOperator(address operator) external onlyAdmin {
        operators[operator] = 0;
        emit RemovedOperator(operator, msg.sender);
    }

    /// @notice Removes the admin role for the caller
    /// Can only be called by an existing admin
    function renounceAdminRole() external onlyAdmin {
        admins[msg.sender] = 0;
        emit RemovedAdmin(msg.sender, msg.sender);
    }

    /// @notice Removes the operator role for the caller
    /// Can only be called by an exiting operator
    function renounceOperatorRole() external onlyOperator {
        operators[msg.sender] = 0;
        emit RemovedOperator(msg.sender, msg.sender);
    }
}

File 2 of 46 : Fees.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

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

abstract contract Fees is IFees {
    /// @notice Maximum fee rate that can be signed into an Order
    uint256 internal constant MAX_FEE_RATE_BIPS = 1000; // 1000 bips or 10%

    /// @notice Returns the maximum fee rate for an order
    function getMaxFeeRate() public pure override returns (uint256) {
        return MAX_FEE_RATE_BIPS;
    }
}

File 2 of 46 : Hashing.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { EIP712 } from "openzeppelin-contracts/utils/cryptography/draft-EIP712.sol";

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

import { Order, ORDER_TYPEHASH } from "../libraries/OrderStructs.sol";

abstract contract Hashing is EIP712, IHashing {
    bytes32 public immutable domainSeparator;

    constructor(string memory name, string memory version) EIP712(name, version) {
        domainSeparator = _domainSeparatorV4();
    }

    /// @notice Computes the hash for an order
    /// @param order - The order to be hashed
    function hashOrder(Order memory order) public view override returns (bytes32) {
        return _hashTypedDataV4(
            keccak256(
                abi.encode(
                    ORDER_TYPEHASH,
                    order.salt,
                    order.maker,
                    order.signer,
                    order.taker,
                    order.tokenId,
                    order.makerAmount,
                    order.takerAmount,
                    order.expiration,
                    order.nonce,
                    order.feeRateBps,
                    order.side,
                    order.signatureType
                )
            )
        );
    }
}

File 2 of 46 : NonceManager.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

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

abstract contract NonceManager is INonceManager {
    mapping(address => uint256) public nonces;

    function incrementNonce() external override {
        updateNonce(1);
    }

    function updateNonce(uint256 val) internal {
        nonces[ msg.sender] = nonces[ msg.sender] + val;
    }

    function isValidNonce(address usr, uint256 nonce) public view override returns (bool) {
        return nonces[ usr] == nonce;
    }
}

File 2 of 46 : Pausable.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

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

abstract contract Pausable is IPausable {
    bool public paused = false;

    modifier notPaused() {
        if (paused) revert Paused();
        _;
    }

    function _pauseTrading() internal override {
        paused = true;
        emit TradingPaused(msg.sender);
    }

    function _unpauseTrading() internal override {
        paused = false;
        emit TradingUnpaused(msg.sender);
    }
}

File 2 of 46 : PolyFactoryHelper.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { PolySafeLib } from "../libraries/PolySafeLib.sol";
import { PolyProxyLib } from "../libraries/PolyProxyLib.sol";

interface IPolyProxyFactory {
    function getImplementation() external view returns (address);
}

interface IPolySafeFactory {
    function masterCopy() external view returns (address);
}

abstract contract PolyFactoryHelper {
    /// @notice The Polymarket Proxy Wallet Factory Contract
    address public proxyFactory;
    /// @notice The Polymarket Gnosis Safe Factory Contract
    address public safeFactory;

    event ProxyFactoryUpdated(address indexed oldProxyFactory, address indexed newProxyFactory);

    event SafeFactoryUpdated(address indexed oldSafeFactory, address indexed newSafeFactory);

    constructor(address _proxyFactory, address _safeFactory) {
        proxyFactory = _proxyFactory;
        safeFactory = _safeFactory;
    }

    /// @notice Gets the Proxy factory address
    function getProxyFactory() public view returns (address) {
        return proxyFactory;
    }

    /// @notice Gets the Safe factory address
    function getSafeFactory() public view returns (address) {
        return safeFactory;
    }

    /// @notice Gets the Polymarket Proxy factory implementation address
    function getPolyProxyFactoryImplementation() public view returns (address) {
        return IPolyProxyFactory(proxyFactory).getImplementation();
    }

    /// @notice Gets the Safe factory implementation address
    function getSafeFactoryImplementation() public view returns (address) {
        return IPolySafeFactory(safeFactory).masterCopy();
    }

    /// @notice Gets the Polymarket proxy wallet address for an address
    /// @param _addr    - The address that owns the proxy wallet
    function getPolyProxyWalletAddress(address _addr) public view returns (address) {
        return PolyProxyLib.getProxyWalletAddress(_addr, getPolyProxyFactoryImplementation(), proxyFactory);
    }

    /// @notice Gets the Polymarket Gnosis Safe address for an address
    /// @param _addr    - The address that owns the proxy wallet
    function getSafeAddress(address _addr) public view returns (address) {
        return PolySafeLib.getSafeAddress(_addr, getSafeFactoryImplementation(), safeFactory);
    }

    function _setProxyFactory(address _proxyFactory) internal {
        emit ProxyFactoryUpdated(proxyFactory, _proxyFactory);
        proxyFactory = _proxyFactory;
    }

    function _setSafeFactory(address _safeFactory) internal {
        emit SafeFactoryUpdated(safeFactory, _safeFactory);
        safeFactory = _safeFactory;
    }
}

File 2 of 46 : Registry.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

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

struct OutcomeToken {
    uint256 complement;
    bytes32 conditionId;
}

/// @title Registry
abstract contract Registry is IRegistry {
    mapping(uint256 => OutcomeToken) public registry;

    /// @notice Gets the conditionId from a tokenId
    /// @param token    - The token
    function getConditionId(uint256 token) public view override returns (bytes32) {
        return registry[ token].conditionId;
    }

    /// @notice Gets the complement of a tokenId
    /// @param token    - The token
    function getComplement(uint256 token) public view override returns (uint256) {
        validateTokenId(token);
        return registry[ token].complement;
    }

    /// @notice Validates the complement of a tokenId
    /// @param token        - The tokenId
    /// @param complement   - The complement to be validated
    function validateComplement(uint256 token, uint256 complement) public view override {
        if (getComplement(token) != complement) revert InvalidComplement();
    }
    /// @notice Validates that a tokenId is registered
    /// @param tokenId - The tokenId

    function validateTokenId(uint256 tokenId) public view override {
        if (registry[ tokenId].complement == 0) revert InvalidTokenId();
    }

    function _registerToken(uint256 token0, uint256 token1, bytes32 conditionId) internal {
        if (token0 == token1 || (token0 == 0 || token1 == 0)) revert InvalidTokenId();
        if (registry[ token0].complement != 0 || registry[ token1].complement != 0) revert AlreadyRegistered();

        registry[ token0] = OutcomeToken({complement: token1, conditionId: conditionId});

        registry[ token1] = OutcomeToken({complement: token0, conditionId: conditionId});

        emit TokenRegistered(token0, token1, conditionId);
        emit TokenRegistered(token1, token0, conditionId);
    }
}

File 2 of 46 : Signatures.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;

import { IERC1271 } from "openzeppelin-contracts/interfaces/IERC1271.sol";
import { ECDSA } from "openzeppelin-contracts/utils/cryptography/ECDSA.sol";

import { SignatureType, Order } from "../libraries/OrderStructs.sol";

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

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

/// @title Signatures
/// @notice Maintains logic that defines the various signature types and validates them
abstract contract Signatures is ISignatures, PolyFactoryHelper {
    constructor(address _proxyFactory, address _safeFactory) PolyFactoryHelper(_proxyFactory, _safeFactory) { }

    /// @notice Validates the signature of an order
    /// @param orderHash - The hash of the order
    /// @param order     - The order
    function validateOrderSignature(bytes32 orderHash, Order memory order) public view override {
        if (!isValidSignature(order.signer, order.maker, orderHash, order.signature, order.signatureType)) {
            revert InvalidSignature();
        }
    }

    /// @notice Verifies a signature for signed Order structs
    /// @param signer           - Address of the signer
    /// @param associated       - Address associated with the signer.
    ///                           For signature type EOA, this MUST be the same as the signer address.
    ///                           For signature types POLY_PROXY and POLY_GNOSIS_SAFE, this is the address of the proxy or the safe
    /// @param structHash       - The hash of the struct being verified
    /// @param signature        - The signature to be verified
    /// @param signatureType    - The signature type to be verified
    function isValidSignature(
        address signer,
        address associated,
        bytes32 structHash,
        bytes memory signature,
        SignatureType signatureType
    ) internal view returns (bool) {
        if (signatureType == SignatureType.EOA) {
            return verifyEOASignature(signer, associated, structHash, signature);
        } else if (signatureType == SignatureType.POLY_GNOSIS_SAFE) {
            return verifyPolySafeSignature(signer, associated, structHash, signature);
        } else {
            // POLY_PROXY
            return verifyPolyProxySignature(signer, associated, structHash, signature);
        }
    }

    /// @notice Verifies an EOA ECDSA signature
    /// Verifies that:
    /// 1) the signature is valid
    /// 2) the signer and maker are the same
    /// @param signer      - The address of the signer
    /// @param maker       - The address of the maker
    /// @param structHash  - The hash of the struct being verified
    /// @param signature   - The signature to be verified
    function verifyEOASignature(address signer, address maker, bytes32 structHash, bytes memory signature)
        internal
        pure
        returns (bool)
    {
        return (signer == maker) && verifyECDSASignature(signer, structHash, signature);
    }

    /// @notice Verifies an ECDSA signature
    /// @dev Reverts if the signature length is invalid or the recovered signer is the zero address
    /// @param signer      - Address of the signer
    /// @param structHash  - The hash of the struct being verified
    /// @param signature   - The signature to be verified
    function verifyECDSASignature(address signer, bytes32 structHash, bytes memory signature)
        internal
        pure
        returns (bool)
    {
        return ECDSA.recover(structHash, signature) == signer;
    }

    /// @notice Verifies a signature signed by a Polymarket proxy wallet
    // Verifies that:
    // 1) the ECDSA signature is valid
    // 2) the Proxy wallet is owned by the signer
    /// @param signer       - Address of the signer
    /// @param proxyWallet  - Address of the poly proxy wallet
    /// @param structHash   - Hash of the struct being verified
    /// @param signature    - Signature to be verified
    function verifyPolyProxySignature(address signer, address proxyWallet, bytes32 structHash, bytes memory signature)
        internal
        view
        returns (bool)
    {
        return verifyECDSASignature(signer, structHash, signature) && getPolyProxyWalletAddress(signer) == proxyWallet;
    }

    /// @notice Verifies a signature signed by a Polymarket Gnosis safe
    // Verifies that:
    // 1) the ECDSA signature is valid
    // 2) the Safe is owned by the signer
    /// @param signer      - Address of the signer
    /// @param safeAddress - Address of the safe
    /// @param hash        - Hash of the struct being verified
    /// @param signature   - Signature to be verified
    function verifyPolySafeSignature(address signer, address safeAddress, bytes32 hash, bytes memory signature)
        internal
        view
        returns (bool)
    {
        return verifyECDSASignature(signer, hash, signature) && getSafeAddress(signer) == safeAddress;
    }
}

File 2 of 46 : Trading.sol
// SPDX-License-Identifier: MIT
pragma solidity <0.9.0;

import { IFees } from "../interfaces/IFees.sol";
import { IHashing } from "../interfaces/IHashing.sol";
import { ITrading } from "../interfaces/ITrading.sol";
import { IRegistry } from "../interfaces/IRegistry.sol";
import { ISignatures } from "../interfaces/ISignatures.sol";
import { INonceManager } from "../interfaces/INonceManager.sol";
import { IAssetOperations } from "../interfaces/IAssetOperations.sol";

import { CalculatorHelper } from "../libraries/CalculatorHelper.sol";
import { Order, Side, MatchType, OrderStatus } from "../libraries/OrderStructs.sol";

/// @title Trading
/// @notice Implements logic for trading CTF assets
abstract contract Trading is IFees, ITrading, IHashing, IRegistry, ISignatures, INonceManager, IAssetOperations {
    /// @notice Mapping of orders to their current status
    mapping(bytes32 => OrderStatus) public orderStatus;

    /// @notice Gets the status of an order
    /// @param orderHash    - The hash of the order
    function getOrderStatus(bytes32 orderHash) public view returns (OrderStatus memory) {
        return orderStatus[ orderHash];
    }

    /// @notice Validates an order
    /// @notice order - The order to be validated
    function validateOrder(Order memory order) public view {
        bytes32 orderHash = hashOrder(order);
        _validateOrder(orderHash, order);
    }

    /// @notice Cancels an order
    /// An order can only be cancelled by its maker, the address which holds funds for the order
    /// @notice order - The order to be cancelled
    function cancelOrder(Order memory order) external {
        _cancelOrder(order);
    }

    /// @notice Cancels a set of orders
    /// @notice orders - The set of orders to be cancelled
    function cancelOrders(Order[] memory orders) external {
        uint256 length = orders.length;
        uint256 i = 0;
        for (; i < length;) {
            _cancelOrder(orders[ i]);
            unchecked {
                ++i;
            }
        }
    }

    function _cancelOrder(Order memory order) internal {
        if (order.maker != msg.sender) revert NotOwner();

        bytes32 orderHash = hashOrder(order);
        OrderStatus storage status = orderStatus[orderHash];
        if (status.isFilledOrCancelled) revert OrderFilledOrCancelled();

        status.isFilledOrCancelled = true;
        emit OrderCancelled(orderHash);
    }

    function _validateOrder(bytes32 orderHash, Order memory order) internal view {
        // Validate order expiration
        if (order.expiration > 0 && order.expiration < block.timestamp) revert OrderExpired();

        // Validate signature
        validateOrderSignature(orderHash, order);

        // Validate fee
        if (order.feeRateBps > getMaxFeeRate()) revert FeeTooHigh();

        // Validate the token to be traded
        validateTokenId(order.tokenId);

        // Validate that the order can be filled
        if (orderStatus[orderHash].isFilledOrCancelled) revert OrderFilledOrCancelled();

        // Validate nonce
        if (!isValidNonce(order.maker, order.nonce)) revert InvalidNonce();
    }

    /// @notice Fills an order against the caller
    /// @param order        - The order to be filled
    /// @param fillAmount   - The amount to be filled, always in terms of the maker amount
    /// @param to           - The address to receive assets from filling the order
    function _fillOrder(Order memory order, uint256 fillAmount, address to) internal {
        uint256 making = fillAmount;
        (uint256 taking, bytes32 orderHash) = _performOrderChecks(order, making);

        uint256 fee = CalculatorHelper.calculateFee(
            order.feeRateBps, order.side == Side.BUY ? taking : making, order.makerAmount, order.takerAmount, order.side
        );

        (uint256 makerAssetId, uint256 takerAssetId) = _deriveAssetIds(order);

        // Transfer order proceeds minus fees from msg.sender to order maker
        _transfer(msg.sender, order.maker, takerAssetId, taking - fee);

        // Transfer makingAmount from order maker to `to`
        _transfer(order.maker, to, makerAssetId, making);

        // NOTE: Fees are "collected" by the Operator implicitly,
        // since the fee is deducted from the assets paid by the Operator

        emit OrderFilled(orderHash, order.maker, msg.sender, makerAssetId, takerAssetId, making, taking, fee);
    }

    /// @notice Fills a set of orders against the caller
    /// @param orders       - The order to be filled
    /// @param fillAmounts  - The amounts to be filled, always in terms of the maker amount
    /// @param to           - The address to receive assets from filling the order
    function _fillOrders(Order[] memory orders, uint256[] memory fillAmounts, address to) internal {
        uint256 length = orders.length;
        uint256 i = 0;
        for (; i < length;) {
            _fillOrder(orders[i], fillAmounts[i], to);
            unchecked {
                ++i;
            }
        }
    }

    /// @notice Matches orders against each other
    /// Matches a taker order against a list of maker orders
    /// @param takerOrder       - The active order to be matched
    /// @param makerOrders      - The array of passive orders to be matched against the active order
    /// @param takerFillAmount  - The amount to fill on the taker order, in terms of the maker amount
    /// @param makerFillAmounts - The array of amounts to fill on the maker orders, in terms of the maker amount
    function _matchOrders(
        Order memory takerOrder,
        Order[] memory makerOrders,
        uint256 takerFillAmount,
        uint256[] memory makerFillAmounts
    ) internal {
        uint256 making = takerFillAmount;

        (uint256 taking, bytes32 orderHash) = _performOrderChecks(takerOrder, making);
        (uint256 makerAssetId, uint256 takerAssetId) = _deriveAssetIds(takerOrder);

        // Transfer takerOrder making amount from taker order to the Exchange
        _transfer(takerOrder.maker, address(this), makerAssetId, making);

        // Fill the maker orders
        _fillMakerOrders(takerOrder, makerOrders, makerFillAmounts);

        taking = _updateTakingWithSurplus(taking, takerAssetId);
        uint256 fee = CalculatorHelper.calculateFee(
            takerOrder.feeRateBps, takerOrder.side == Side.BUY ? taking : making, making, taking, takerOrder.side
        );

        // Execute transfers

        // Transfer order proceeds post fees from the Exchange to the taker order maker
        _transfer(address(this), takerOrder.maker, takerAssetId, taking - fee);

        // Charge the fee to taker order maker, explicitly transferring the fee from the Exchange to the Operator
        _chargeFee(address(this), msg.sender, takerAssetId, fee);

        // Refund any leftover tokens pulled from the taker to the taker order
        uint256 refund = _getBalance(makerAssetId);
        if (refund > 0) _transfer(address(this), takerOrder.maker, makerAssetId, refund);

        emit OrderFilled(
            orderHash, takerOrder.maker, address(this), makerAssetId, takerAssetId, making, taking, fee
        );

        emit OrdersMatched(orderHash, takerOrder.maker, makerAssetId, takerAssetId, making, taking);

        
    }

    function _fillMakerOrders(Order memory takerOrder, Order[] memory makerOrders, uint256[] memory makerFillAmounts)
        internal
    {
        uint256 length = makerOrders.length;
        uint256 i = 0;
        for (; i < length;) {
            _fillMakerOrder(takerOrder, makerOrders[i], makerFillAmounts[i]);
            unchecked {
                ++i;
            }
        }
    }

    /// @notice Fills a Maker order
    /// @param takerOrder   - The taker order
    /// @param makerOrder   - The maker order
    /// @param fillAmount   - The fill amount
    function _fillMakerOrder(Order memory takerOrder, Order memory makerOrder, uint256 fillAmount) internal {
        MatchType matchType = _deriveMatchType(takerOrder, makerOrder);

        // Ensure taker order and maker order match
        _validateTakerAndMaker(takerOrder, makerOrder, matchType);

        uint256 making = fillAmount;
        (uint256 taking, bytes32 orderHash) = _performOrderChecks(makerOrder, making);
        uint256 fee = CalculatorHelper.calculateFee(
            makerOrder.feeRateBps,
            makerOrder.side == Side.BUY ? taking : making,
            makerOrder.makerAmount,
            makerOrder.takerAmount,
            makerOrder.side
        );
        (uint256 makerAssetId, uint256 takerAssetId) = _deriveAssetIds(makerOrder);

        _fillFacingExchange(making, taking, makerOrder.maker, makerAssetId, takerAssetId, matchType, fee);

        emit OrderFilled(
            orderHash, makerOrder.maker, takerOrder.maker, makerAssetId, takerAssetId, making, taking, fee
        );
    }

    /// @notice Performs common order computations and validation
    /// 1) Validates the order taker
    /// 2) Computes the order hash
    /// 3) Validates the order
    /// 4) Computes taking amount
    /// 5) Updates the order status in storage
    /// @param order    - The order being prepared
    /// @param making   - The amount of the order being filled, in terms of maker amount
    function _performOrderChecks(Order memory order, uint256 making)
        internal
        returns (uint256 takingAmount, bytes32 orderHash)
    {
        _validateTaker(order.taker);

        orderHash = hashOrder(order);

        // Validate order
        _validateOrder(orderHash, order);

        // Calculate taking amount
        takingAmount = CalculatorHelper.calculateTakingAmount(making, order.makerAmount, order.takerAmount);

        // Update the order status in storage
        _updateOrderStatus(orderHash, order, making);
    }

    /// @notice Fills a maker order using the Exchange as the counterparty
    /// @param makingAmount - Amount to be filled in terms of maker amount
    /// @param takingAmount - Amount to be filled in terms of taker amount
    /// @param maker        - The order maker
    /// @param makerAssetId - The Token Id of the Asset to be sold
    /// @param takerAssetId - The Token Id of the Asset to be received
    /// @param matchType    - The match type
    /// @param fee          - The fee charged to the Order maker
    function _fillFacingExchange(
        uint256 makingAmount,
        uint256 takingAmount,
        address maker,
        uint256 makerAssetId,
        uint256 takerAssetId,
        MatchType matchType,
        uint256 fee
    ) internal {
        // Transfer makingAmount tokens from order maker to Exchange
        _transfer(maker, address(this), makerAssetId, makingAmount);

        // Executes a match call based on match type
        _executeMatchCall(makingAmount, takingAmount, makerAssetId, takerAssetId, matchType);

        // Ensure match action generated enough tokens to fill the order
        if (_getBalance(takerAssetId) < takingAmount) revert TooLittleTokensReceived();

        // Transfer order proceeds minus fees from the Exchange to the order maker
        _transfer(address(this), maker, takerAssetId, takingAmount - fee);

        // Transfer fees from Exchange to the Operator
        _chargeFee(address(this), msg.sender, takerAssetId, fee);
    }

    function _deriveMatchType(Order memory takerOrder, Order memory makerOrder) internal pure returns (MatchType) {
        if (takerOrder.side == Side.BUY && makerOrder.side == Side.BUY) return MatchType.MINT;
        if (takerOrder.side == Side.SELL && makerOrder.side == Side.SELL) return MatchType.MERGE;
        return MatchType.COMPLEMENTARY;
    }

    function _deriveAssetIds(Order memory order) internal pure returns (uint256 makerAssetId, uint256 takerAssetId) {
        if (order.side == Side.BUY) return (0, order.tokenId);
        return (order.tokenId, 0);
    }

    /// @notice Executes a CTF call to match orders by minting new Outcome tokens
    /// or merging Outcome tokens into collateral.
    /// @param makingAmount - Amount to be filled in terms of maker amount
    /// @param takingAmount - Amount to be filled in terms of taker amount
    /// @param makerAssetId - The Token Id of the Asset to be sold
    /// @param takerAssetId - The Token Id of the Asset to be received
    /// @param matchType    - The match type
    function _executeMatchCall(
        uint256 makingAmount,
        uint256 takingAmount,
        uint256 makerAssetId,
        uint256 takerAssetId,
        MatchType matchType
    ) internal {
        if (matchType == MatchType.COMPLEMENTARY) {
            // Indicates a buy vs sell order
            // no match action needed
            return;
        }
        if (matchType == MatchType.MINT) {
            // Indicates matching 2 buy orders
            // Mint new Outcome tokens using Exchange collateral balance and fill buys
            return _mint(getConditionId(takerAssetId), takingAmount);
        }
        if (matchType == MatchType.MERGE) {
            // Indicates matching 2 sell orders
            // Merge the Exchange Outcome token balance into collateral and fill sells
            return _merge(getConditionId(makerAssetId), makingAmount);
        }
    }

    /// @notice Ensures the taker and maker orders can be matched against each other
    /// @param takerOrder   - The taker order
    /// @param makerOrder   - The maker order
    function _validateTakerAndMaker(Order memory takerOrder, Order memory makerOrder, MatchType matchType)
        internal
        view
    {
        if (!CalculatorHelper.isCrossing(takerOrder, makerOrder)) revert NotCrossing();

        // Ensure orders match
        if (matchType == MatchType.COMPLEMENTARY) {
            if (takerOrder.tokenId != makerOrder.tokenId) revert MismatchedTokenIds();
        } else {
            // both bids or both asks
            validateComplement(takerOrder.tokenId, makerOrder.tokenId);
        }
    }

    function _validateTaker(address taker) internal view {
        if (taker != address(0) && taker != msg.sender) revert NotTaker();
    }

    function _chargeFee(address payer, address receiver, uint256 tokenId, uint256 fee) internal {
        // Charge fee to the payer if any
        if (fee > 0) {
            _transfer(payer, receiver, tokenId, fee);
            emit FeeCharged(receiver, tokenId, fee);
        }
    }

    function _updateOrderStatus(bytes32 orderHash, Order memory order, uint256 makingAmount)
        internal
        returns (uint256 remaining)
    {
        OrderStatus storage status = orderStatus[orderHash];
        // Fetch remaining amount from storage
        remaining = status.remaining;

        // Update remaining if the order is new/has not been filled
        remaining = remaining == 0 ? order.makerAmount : remaining;

        // Throw if the makingAmount(amount to be filled) is greater than the amount available
        if (makingAmount > remaining) revert MakingGtRemaining();

        // Update remaining using the makingAmount
        remaining = remaining - makingAmount;

        // If order is completely filled, update isFilledOrCancelled in storage
        if (remaining == 0) status.isFilledOrCancelled = true;

        // Update remaining in storage
        status.remaining = remaining;
    }

    function _updateTakingWithSurplus(uint256 minimumAmount, uint256 tokenId) internal returns (uint256) {
        uint256 actualAmount = _getBalance(tokenId);
        if (actualAmount < minimumAmount) revert TooLittleTokensReceived();
        return actualAmount;
    }
}

Settings
{
  "remappings": [
    "common/=src/common/",
    "creator/=src/creator/",
    "dev/=src/dev/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "exchange/=src/exchange/",
    "forge-std/=lib/forge-std/src/",
    "gov/=src/gov/",
    "mocks/=src/dev/mocks/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "pool/=src/dev/uniswap/",
    "ptoken/=src/ptoken/",
    "solmate/=lib/solmate/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 1000000
  },
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_collateral","type":"address"},{"internalType":"address","name":"_ctf","type":"address"},{"internalType":"address","name":"_proxyFactory","type":"address"},{"internalType":"address","name":"_safeFactory","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyRegistered","type":"error"},{"inputs":[],"name":"FeeTooHigh","type":"error"},{"inputs":[],"name":"InvalidComplement","type":"error"},{"inputs":[],"name":"InvalidNonce","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidTokenId","type":"error"},{"inputs":[],"name":"MakingGtRemaining","type":"error"},{"inputs":[],"name":"MismatchedTokenIds","type":"error"},{"inputs":[],"name":"NotAdmin","type":"error"},{"inputs":[],"name":"NotCrossing","type":"error"},{"inputs":[],"name":"NotOperator","type":"error"},{"inputs":[],"name":"NotOwner","type":"error"},{"inputs":[],"name":"NotTaker","type":"error"},{"inputs":[],"name":"OrderExpired","type":"error"},{"inputs":[],"name":"OrderFilledOrCancelled","type":"error"},{"inputs":[],"name":"Paused","type":"error"},{"inputs":[],"name":"TooLittleTokensReceived","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FeeCharged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newAdminAddress","type":"address"},{"indexed":true,"internalType":"address","name":"admin","type":"address"}],"name":"NewAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newOperatorAddress","type":"address"},{"indexed":true,"internalType":"address","name":"admin","type":"address"}],"name":"NewOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"OrderCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"maker","type":"address"},{"indexed":true,"internalType":"address","name":"taker","type":"address"},{"indexed":false,"internalType":"uint256","name":"makerAssetId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"takerAssetId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"makerAmountFilled","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"takerAmountFilled","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"OrderFilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"takerOrderHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"takerOrderMaker","type":"address"},{"indexed":false,"internalType":"uint256","name":"makerAssetId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"takerAssetId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"makerAmountFilled","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"takerAmountFilled","type":"uint256"}],"name":"OrdersMatched","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldProxyFactory","type":"address"},{"indexed":true,"internalType":"address","name":"newProxyFactory","type":"address"}],"name":"ProxyFactoryUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"removedAdmin","type":"address"},{"indexed":true,"internalType":"address","name":"admin","type":"address"}],"name":"RemovedAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"removedOperator","type":"address"},{"indexed":true,"internalType":"address","name":"admin","type":"address"}],"name":"RemovedOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldSafeFactory","type":"address"},{"indexed":true,"internalType":"address","name":"newSafeFactory","type":"address"}],"name":"SafeFactoryUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"token0","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"token1","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"conditionId","type":"bytes32"}],"name":"TokenRegistered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pauser","type":"address"}],"name":"TradingPaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pauser","type":"address"}],"name":"TradingUnpaused","type":"event"},{"inputs":[{"internalType":"address","name":"admin_","type":"address"}],"name":"addAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator_","type":"address"}],"name":"addOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"admins","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"makerAmount","type":"uint256"},{"internalType":"uint256","name":"takerAmount","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"feeRateBps","type":"uint256"},{"internalType":"enum Side","name":"side","type":"uint8"},{"internalType":"enum SignatureType","name":"signatureType","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"}],"name":"cancelOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"makerAmount","type":"uint256"},{"internalType":"uint256","name":"takerAmount","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"feeRateBps","type":"uint256"},{"internalType":"enum Side","name":"side","type":"uint8"},{"internalType":"enum SignatureType","name":"signatureType","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Order[]","name":"orders","type":"tuple[]"}],"name":"cancelOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"domainSeparator","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"makerAmount","type":"uint256"},{"internalType":"uint256","name":"takerAmount","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"feeRateBps","type":"uint256"},{"internalType":"enum Side","name":"side","type":"uint8"},{"internalType":"enum SignatureType","name":"signatureType","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"uint256","name":"fillAmount","type":"uint256"}],"name":"fillOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"makerAmount","type":"uint256"},{"internalType":"uint256","name":"takerAmount","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"feeRateBps","type":"uint256"},{"internalType":"enum Side","name":"side","type":"uint8"},{"internalType":"enum SignatureType","name":"signatureType","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Order[]","name":"orders","type":"tuple[]"},{"internalType":"uint256[]","name":"fillAmounts","type":"uint256[]"}],"name":"fillOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getCollateral","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"token","type":"uint256"}],"name":"getComplement","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"token","type":"uint256"}],"name":"getConditionId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCtf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxFeeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"getOrderStatus","outputs":[{"components":[{"internalType":"bool","name":"isFilledOrCancelled","type":"bool"},{"internalType":"uint256","name":"remaining","type":"uint256"}],"internalType":"struct OrderStatus","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPolyProxyFactoryImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_addr","type":"address"}],"name":"getPolyProxyWalletAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProxyFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_addr","type":"address"}],"name":"getSafeAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSafeFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSafeFactoryImplementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"makerAmount","type":"uint256"},{"internalType":"uint256","name":"takerAmount","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"feeRateBps","type":"uint256"},{"internalType":"enum Side","name":"side","type":"uint8"},{"internalType":"enum SignatureType","name":"signatureType","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"}],"name":"hashOrder","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"incrementNonce","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"isAdmin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"isValidNonce","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"makerAmount","type":"uint256"},{"internalType":"uint256","name":"takerAmount","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"feeRateBps","type":"uint256"},{"internalType":"enum Side","name":"side","type":"uint8"},{"internalType":"enum SignatureType","name":"signatureType","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Order","name":"takerOrder","type":"tuple"},{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"makerAmount","type":"uint256"},{"internalType":"uint256","name":"takerAmount","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"feeRateBps","type":"uint256"},{"internalType":"enum Side","name":"side","type":"uint8"},{"internalType":"enum SignatureType","name":"signatureType","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Order[]","name":"makerOrders","type":"tuple[]"},{"internalType":"uint256","name":"takerFillAmount","type":"uint256"},{"internalType":"uint256[]","name":"makerFillAmounts","type":"uint256[]"}],"name":"matchOrders","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"operators","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"orderStatus","outputs":[{"internalType":"bool","name":"isFilledOrCancelled","type":"bool"},{"internalType":"uint256","name":"remaining","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"parentCollectionId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pauseTrading","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxyFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"token","type":"uint256"},{"internalType":"uint256","name":"complement","type":"uint256"},{"internalType":"bytes32","name":"conditionId","type":"bytes32"}],"name":"registerToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"registry","outputs":[{"internalType":"uint256","name":"complement","type":"uint256"},{"internalType":"bytes32","name":"conditionId","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"admin","type":"address"}],"name":"removeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"}],"name":"removeOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceAdminRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOperatorRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"safeFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newProxyFactory","type":"address"}],"name":"setProxyFactory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newSafeFactory","type":"address"}],"name":"setSafeFactory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpauseTrading","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"token","type":"uint256"},{"internalType":"uint256","name":"complement","type":"uint256"}],"name":"validateComplement","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"makerAmount","type":"uint256"},{"internalType":"uint256","name":"takerAmount","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"feeRateBps","type":"uint256"},{"internalType":"enum Side","name":"side","type":"uint8"},{"internalType":"enum SignatureType","name":"signatureType","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"}],"name":"validateOrder","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"makerAmount","type":"uint256"},{"internalType":"uint256","name":"takerAmount","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"feeRateBps","type":"uint256"},{"internalType":"enum Side","name":"side","type":"uint8"},{"internalType":"enum SignatureType","name":"signatureType","type":"uint8"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct Order","name":"order","type":"tuple"}],"name":"validateOrderSignature","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"validateTokenId","outputs":[],"stateMutability":"view","type":"function"}]

6101a060405260016000556003805460ff191690553480156200002157600080fd5b506040516200473f3803806200473f8339810160408190526200004491620002d6565b604080518082018252601781527f506f6c796d61726b6574204354462045786368616e67650000000000000000006020808301918252835180850185526001808252603160f81b82840190815233600090815282855287812083905560028552879020919091558451909320815190932060e08490526101008190524660a081815287517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f818701819052818a0188905260608201859052608082019390935230818301528851808203909201825260c0019097528651969093019590952087958795879587959194938d938d9387938793909291906080523060c05261012052505050506001600160a01b0382811661014081905290821661016081905260405163095ea7b360e01b81526004810191909152600019602482015263095ea7b3906044016020604051808303816000875af1158015620001a9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001cf919062000333565b50620001dd91505062000265565b610180525050600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055506200035e945050505050565b6040805160208101859052908101839052606081018290524660808201523060a082015260009060c0016040516020818303038152906040528051906020012090509392505050565b600060c0516001600160a01b0316306001600160a01b03161480156200028c575060a05146145b1562000299575060805190565b620002b46101205160e051610100516200021c60201b60201c565b905090565b80516001600160a01b0381168114620002d157600080fd5b919050565b60008060008060808587031215620002ed57600080fd5b620002f885620002b9565b93506200030860208601620002b9565b92506200031860408601620002b9565b91506200032860608601620002b9565b905092959194509250565b6000602082840312156200034657600080fd5b815180151581146200035757600080fd5b9392505050565b60805160a05160c05160e05161010051610120516101405161016051610180516143386200040760003960006108970152600081816104c801528181612698015281816129450152818161355201526136820152600081816105eb015281816125e3015281816128ed0152818161358e01526136be01526000612258015260006122a701526000612282015260006121db015260006122050152600061222f01526143386000f3fe608060405234801561001057600080fd5b50600436106103365760003560e01c806370480275116101b2578063d798eff6116100f9578063e60f0c05116100a2578063f698da251161007c578063f698da2514610892578063fa950b48146108b9578063fbddd751146108cc578063fe729aaf146108df57600080fd5b8063e60f0c0514610834578063edef7d8e14610847578063f23a6e611461085a57600080fd5b8063e03ac3d0116100d3578063e03ac3d014610806578063e2eec4051461080e578063e50e4f971461082157600080fd5b8063d798eff6146107bd578063d7fb272f146107d0578063d82da838146107f357600080fd5b8063a287bdf11161015b578063b28c51c011610135578063b28c51c01461073b578063bc197c8114610759578063c10f1a751461079d57600080fd5b8063a287bdf114610702578063a6dfcf8614610715578063ac8a584a1461072857600080fd5b806383b8a5ae1161018c57806383b8a5ae146106d45780639870d7fe146106dc578063a10f3dce146106ef57600080fd5b8063704802751461068357806375d7370a146106965780637ecebe00146106b457600080fd5b8063429b62e5116102815780635893253c1161022a578063627cdcb911610204578063627cdcb91461061c578063654f0ce41461062457806368c7450f146106375780636d70f7ae1461064a57600080fd5b80635893253c146105ad5780635c1548fb146105e95780635c975abb1461060f57600080fd5b8063456068d21161025b578063456068d21461052f57806346423aa7146105375780634a2a11f5146105a557600080fd5b8063429b62e5146104f457806344bea37e146105145780634544f0551461051c57600080fd5b80631785f53c116102e357806334600901116102bd57806334600901146104b35780633b521d78146104c65780633d6d3598146104ec57600080fd5b80631785f53c1461042257806324d7806c146104355780632dff692d1461046f57600080fd5b80631031e36e116103145780631031e36e146103ca578063131e7e1c146103d457806313e7c9d8146103f457600080fd5b806301ffc9a71461033b5780630647ee201461036357806306b9d6911461039d575b600080fd5b61034e6103493660046136e2565b6108f2565b60405190151581526020015b60405180910390f35b61034e610371366004613756565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152600460205260409020541490565b6103a561098b565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161035a565b6103d2610a24565b005b6007546103a59073ffffffffffffffffffffffffffffffffffffffff1681565b610414610402366004613782565b60026020526000908152604090205481565b60405190815260200161035a565b6103d2610430366004613782565b610a78565b61034e610443366004613782565b73ffffffffffffffffffffffffffffffffffffffff166000908152600160208190526040909120541490565b61049c61047d36600461379f565b6008602052600090815260409020805460019091015460ff9091169082565b60408051921515835260208301919091520161035a565b6103d26104c136600461379f565b610b15565b7f00000000000000000000000000000000000000000000000000000000000000006103a5565b6103d2610b5f565b610414610502366004613782565b60016020526000908152604090205481565b610414600081565b6103d261052a366004613782565b610be3565b6103d2610c36565b61058861054536600461379f565b6040805180820190915260008082526020820152506000908152600860209081526040918290208251808401909352805460ff1615158352600101549082015290565b60408051825115158152602092830151928101929092520161035a565b6103e8610414565b6105d46105bb36600461379f565b6005602052600090815260409020805460019091015482565b6040805192835260208301919091520161035a565b7f00000000000000000000000000000000000000000000000000000000000000006103a5565b60035461034e9060ff1681565b6103d2610c88565b6103d26106323660046139f8565b610c92565b6103d2610645366004613a2d565b610cad565b61034e610658366004613782565b73ffffffffffffffffffffffffffffffffffffffff1660009081526002602052604090205460011490565b6103d2610691366004613782565b610d07565b60075473ffffffffffffffffffffffffffffffffffffffff166103a5565b6104146106c2366004613782565b60046020526000908152604090205481565b6103d2610da7565b6103d26106ea366004613782565b610e2c565b6104146106fd36600461379f565b610eca565b6103a5610710366004613782565b610ee8565b6103d26107233660046139f8565b610f14565b6103d2610736366004613782565b610f1d565b60065473ffffffffffffffffffffffffffffffffffffffff166103a5565b61076c610767366004613ae8565b610fba565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200161035a565b6006546103a59073ffffffffffffffffffffffffffffffffffffffff1681565b6103d26107cb366004613c16565b610fe5565b6104146107de36600461379f565b60009081526005602052604090206001015490565b6103d2610801366004613c7a565b6110f5565b6103a5611136565b6103d261081c366004613c9c565b6111a6565b61041461082f3660046139f8565b6111fb565b6103d2610842366004613cd9565b611298565b6103a5610855366004613782565b6113a6565b61076c610868366004613d6b565b7ff23a6e610000000000000000000000000000000000000000000000000000000095945050505050565b6104147f000000000000000000000000000000000000000000000000000000000000000081565b6103d26108c7366004613dd4565b6113d2565b6103d26108da366004613782565b611409565b6103d26108ed366004613e09565b61145c565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f4e2312e000000000000000000000000000000000000000000000000000000000148061098557507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b600654604080517faaf10f42000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff169163aaf10f429160048083019260209291908290030181865afa1580156109fb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a1f9190613e4e565b905090565b3360009081526001602081905260409091205414610a6e576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a7661155e565b565b3360009081526001602081905260409091205414610ac2576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020526040808220829055513392917f787a2e12f4a55b658b8f573c32432ee11a5e8b51677d1e1e937aaf6a0bb5776e91a350565b6000818152600560205260408120549003610b5c576040517f3f6cc76800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b33600090815260026020526040902054600114610ba8576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b336000818152600260205260408082208290555182917ff7262ed0443cc211121ceb1a80d69004f319245615a7488f951f1437fd91642c91a3565b3360009081526001602081905260409091205414610c2d576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610b5c816115b6565b3360009081526001602081905260409091205414610c80576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a76611644565b610a766001611699565b6000610c9d826111fb565b9050610ca981836116c7565b5050565b3360009081526001602081905260409091205414610cf7576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d02838383611826565b505050565b3360009081526001602081905260409091205414610d51576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020819052604080832091909155513392917ff9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dc91a350565b3360009081526001602081905260409091205414610df1576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b336000818152600160205260408082208290555182917f787a2e12f4a55b658b8f573c32432ee11a5e8b51677d1e1e937aaf6a0bb5776e91a3565b3360009081526001602081905260409091205414610e76576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff811660008181526002602052604080822060019055513392917ff1e04d73c4304b5ff164f9d10c7473e2a1593b740674a6107975e2a7001c1e5c91a350565b6000610ed582610b15565b5060009081526005602052604090205490565b600061098582610ef6611136565b60075473ffffffffffffffffffffffffffffffffffffffff16611982565b610b5c81611a80565b3360009081526001602081905260409091205414610f67576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116600081815260026020526040808220829055513392917ff7262ed0443cc211121ceb1a80d69004f319245615a7488f951f1437fd91642c91a350565b7fbc197c81000000000000000000000000000000000000000000000000000000005b95945050505050565b600054600203611056576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f5245454e5452414e43590000000000000000000000000000000000000000000060448201526064015b60405180910390fd5b6002600081815533815260209190915260409020546001146110a4576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60035460ff16156110e1576040517f9e87fac800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6110ec828233611b85565b50506001600055565b806110ff83610eca565b14610ca9576040517f66f8620a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600754604080517fa619486e000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff169163a619486e9160048083019260209291908290030181865afa1580156109fb573d6000803e3d6000fd5b6111c58160400151826020015184846101800151856101600151611bde565b610ca9576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006109857fa852566c4e14d00869b6db0220888a9090a13eccdaea03713ff0a3d27bf9767c836000015184602001518560400151866060015187608001518860a001518960c001518a60e001518b61010001518c61012001518d61014001518e610160015160405160200161127d9d9c9b9a99989796959493929190613eae565b60405160208183030381529060405280519060200120611c3c565b600054600203611304576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f5245454e5452414e435900000000000000000000000000000000000000000000604482015260640161104d565b600260008181553381526020919091526040902054600114611352576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60035460ff161561138f576040517f9e87fac800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61139b84848484611ca5565b505060016000555050565b6000610985826113b461098b565b60065473ffffffffffffffffffffffffffffffffffffffff16611e5c565b805160005b81811015610d02576114018382815181106113f4576113f4613f4c565b6020026020010151611a80565b6001016113d7565b3360009081526001602081905260409091205414611453576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610b5c81611ebe565b6000546002036114c8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f5245454e5452414e435900000000000000000000000000000000000000000000604482015260640161104d565b600260008181553381526020919091526040902054600114611516576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60035460ff1615611553576040517f9e87fac800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6110ec828233611f4c565b600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905560405133907f203c4bd3e526634f661575359ff30de3b0edaba6c2cb1eac60f730b6d2d9d53690600090a2565b60075460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f9726d7faf7429d6b059560dc858ed769377ccdf8b7541eabe12b22548719831f90600090a3600780547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905560405133907fa1e8a54850dbd7f520bcc09f47bff152294b77b2081da545a7adf531b7ea283b90600090a2565b336000908152600460205260409020546116b4908290613faa565b3360009081526004602052604090205550565b60008160e001511180156116de5750428160e00151105b15611715576040517fc56873ba00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61171f82826111a6565b6103e88161012001511115611760576040517fcd4e616700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61176d8160800151610b15565b60008281526008602052604090205460ff16156117b6576040517f7b38b76e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6117f0816020015182610100015173ffffffffffffffffffffffffffffffffffffffff919091166000908152600460205260409020541490565b610ca9576040517f756688fe00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8183148061183a575082158061183a575081155b15611871576040517f3f6cc76800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008381526005602052604090205415158061189a575060008281526005602052604090205415155b156118d1576040517f3a81d6fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805180820182528381526020808201848152600087815260058084528582209451855591516001948501558451808601865288815280840187815288835292909352848120925183559051919092015590518291849186917fbc9a2432e8aeb48327246cddd6e872ef452812b4243c04e6bfb786a2cd8faf0d91a48083837fbc9a2432e8aeb48327246cddd6e872ef452812b4243c04e6bfb786a2cd8faf0d60405160405180910390a4505050565b60008061198e8461205a565b8051906020012090506000856040516020016119c6919073ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b604080518083037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001815282825280516020918201207fff000000000000000000000000000000000000000000000000000000000000008285015260609790971b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000166021840152603583019690965260558083019490945280518083039094018452607590910190525080519201919091209392505050565b602081015173ffffffffffffffffffffffffffffffffffffffff163314611ad3576040517f30cd747100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000611ade826111fb565b600081815260086020526040902080549192509060ff1615611b2c576040517f7b38b76e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117815560405182907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a2505050565b825160005b81811015611bd757611bcf858281518110611ba757611ba7613f4c565b6020026020010151858381518110611bc157611bc1613f4c565b602002602001015185611f4c565b600101611b8a565b5050505050565b600080826002811115611bf357611bf3613e6b565b03611c0b57611c04868686866120eb565b9050610fdc565b6002826002811115611c1f57611c1f613e6b565b03611c3057611c0486868686612139565b611c048686868661218d565b6000610985611c496121c1565b836040517f19010000000000000000000000000000000000000000000000000000000000006020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b81600080611cb387846122f5565b91509150600080611cc389612342565b91509150611cd78960200151308488612379565b611ce28989886123a3565b611cec84826123f5565b6101208a0151909450600090611d2e90828c61014001516001811115611d1457611d14613e6b565b14611d1f5787611d21565b865b88888e610140015161243d565b9050611d4b308b60200151848489611d469190613fc2565b612379565b611d573033848461252d565b6000611d6284612596565b90508015611d7a57611d7a308c602001518684612379565b60208b8101516040805187815292830186905282018990526060820188905260808201849052309173ffffffffffffffffffffffffffffffffffffffff9091169087907fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69060a00160405180910390a46020808c01516040805187815292830186905282018990526060820188905273ffffffffffffffffffffffffffffffffffffffff169086907f63bf4d16b7fa898ef4c4b2b6d90fd201e9c56313b65638af6088d149d2ce956c9060800160405180910390a35050505050505050505050565b6040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606085901b166020820152600090611eb49083908590603401604051602081830303815290604052805190602001206126c6565b90505b9392505050565b60065460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f3053c6252a932554235c173caffc1913604dba3a41cee89516f631c4a1a50a3790600090a3600680547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b81600080611f5a86846122f5565b6101208801519193509150600090611fa790825b8961014001516001811115611f8557611f85613e6b565b14611f905785611f92565b845b8960a001518a60c001518b610140015161243d565b9050600080611fb589612342565b91509150611fcf338a60200151838689611d469190613fc2565b611fdf8960200151888489612379565b6020898101516040805185815292830184905282018890526060820187905260808201859052339173ffffffffffffffffffffffffffffffffffffffff9091169086907fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69060a00160405180910390a4505050505050505050565b6060604051806101a00160405280610171815260200161419261017191396040805173ffffffffffffffffffffffffffffffffffffffff8516602082015201604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290526120d59291602001614005565b6040516020818303038152906040529050919050565b60008373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614801561212e575061212e858484612763565b90505b949350505050565b6000612146858484612763565b801561212e57508373ffffffffffffffffffffffffffffffffffffffff1661216d86610ee8565b73ffffffffffffffffffffffffffffffffffffffff161495945050505050565b600061219a858484612763565b801561212e57508373ffffffffffffffffffffffffffffffffffffffff1661216d866113a6565b60003073ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614801561222757507f000000000000000000000000000000000000000000000000000000000000000046145b1561225157507f000000000000000000000000000000000000000000000000000000000000000090565b50604080517f00000000000000000000000000000000000000000000000000000000000000006020808301919091527f0000000000000000000000000000000000000000000000000000000000000000828401527f000000000000000000000000000000000000000000000000000000000000000060608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b60008061230584606001516127a5565b61230e846111fb565b905061231a81856116c7565b61232d838560a001518660c00151612817565b915061233a81858561283e565b509250929050565b60008080836101400151600181111561235d5761235d613e6b565b0361236d57505060800151600091565b50506080015190600090565b816000036123915761238c8484836128eb565b61239d565b61239d84848484612940565b50505050565b815160005b81811015611bd7576123ed858583815181106123c6576123c6613f4c565b60200260200101518584815181106123e0576123e0613f4c565b602002602001015161296d565b6001016123a8565b60008061240183612596565b905083811015611eb7576040517fdf4d808000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008515610fdc576000612452858585612a52565b905060008111801561246c5750670de0b6b3a76400008111155b1561252357600083600181111561248557612485613e6b565b036124d75761249661271082614034565b866124b2836124ad81670de0b6b3a7640000613fc2565b612ac1565b6124bc908a614034565b6124c69190614034565b6124d09190614071565b9150612523565b6124eb670de0b6b3a7640000612710614034565b86612502836124ad81670de0b6b3a7640000613fc2565b61250c908a614034565b6125169190614034565b6125209190614071565b91505b5095945050505050565b801561239d5761253f84848484612379565b604080518381526020810183905273ffffffffffffffffffffffffffffffffffffffff8516917facffcc86834d0f1a64b0d5a675798deed6ff0bcfc2231edd3480e7288dba7ff4910160405180910390a250505050565b60008160000361264f576040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016906370a08231906024015b602060405180830381865afa15801561262b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061098591906140ac565b6040517efdd58e0000000000000000000000000000000000000000000000000000000081523060048201526024810183905273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169062fdd58e9060440161260e565b6000806126d38585612ad7565b8051602091820120604080517fff000000000000000000000000000000000000000000000000000000000000008185015260609890981b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000166021890152603588019590955260558088019190915284518088039091018152607590960190935250508251920191909120919050565b60008373ffffffffffffffffffffffffffffffffffffffff166127868484612c5a565b73ffffffffffffffffffffffffffffffffffffffff1614949350505050565b73ffffffffffffffffffffffffffffffffffffffff8116158015906127e0575073ffffffffffffffffffffffffffffffffffffffff81163314155b15610b5c576040517f5211a07900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008260000361282957506000611eb7565b826128348386614034565b611eb49190614071565b6000838152600860205260409020600181015490811561285e5781612864565b8360a001515b9150818311156128a0576040517fe2cc6ad600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6128aa8383613fc2565b9150816000036128de5780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011781555b6001018190559392505050565b7f00000000000000000000000000000000000000000000000000000000000000003073ffffffffffffffffffffffffffffffffffffffff8516036129345761238c818484612c7e565b61239d81858585612c89565b61239d7f000000000000000000000000000000000000000000000000000000000000000085858585612c95565b60006129798484612d41565b9050612986848483612ddd565b8160008061299486846122f5565b61012088015191935091506000906129ac9082611f6e565b90506000806129ba89612342565b915091506129d186868b6020015185858c89612e89565b6020808b01518a820151604080518681529384018590528301899052606083018890526080830186905273ffffffffffffffffffffffffffffffffffffffff9182169291169086907fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69060a00160405180910390a450505050505050505050565b600080826001811115612a6757612a67613e6b565b03612a9f5782600003612a7b576000612a98565b82612a8e670de0b6b3a764000086614034565b612a989190614071565b9050611eb7565b83600003612aae576000611eb4565b83612834670de0b6b3a764000085614034565b6000818310612ad05781611eb7565b5090919050565b6040805160008082526020820190925260609190612af890604481016140c5565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152918152602080830180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f52e831dd000000000000000000000000000000000000000000000000000000001790528151606380825260a082019093529293506000929190820181803683370190505090507f3d3d606380380380913d393d73bebebebebebebebebebebebebebebebebebebe60208201526c010000000000000000000000008502602d8201527f5af4602a57600080fd5b602d8060366000396000f3363d3d373d3d3d363d73be60418201526c01000000000000000000000000840260608201527f5af43d82803e903d91602b57fd5bf3000000000000000000000000000000000060748201528082604051602001612c41929190614005565b6040516020818303038152906040529250505092915050565b6000806000612c698585612f09565b91509150612c7681612f4e565b509392505050565b610d02838383613101565b61239d848484846131ba565b6040517ff242432a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528481166024830152604482018490526064820183905260a06084830152600060a483015286169063f242432a9060c401600060405180830381600087803b158015612d2257600080fd5b505af1158015612d36573d6000803e3d6000fd5b505050505050505050565b6000808361014001516001811115612d5b57612d5b613e6b565b148015612d7e575060008261014001516001811115612d7c57612d7c613e6b565b145b15612d8b57506001610985565b60018361014001516001811115612da457612da4613e6b565b148015612dc7575060018261014001516001811115612dc557612dc5613e6b565b145b15612dd457506002610985565b50600092915050565b612de78383613279565b612e1d576040517f7f9a6f4600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000816002811115612e3157612e31613e6b565b03612e77578160800151836080015114610d02576040517fa0b9446500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d02836080015183608001516110f5565b612e958530868a612379565b612ea287878686866132c3565b85612eac84612596565b1015612ee4576040517fdf4d808000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612ef4308685611d46858b613fc2565b612f003033858461252d565b50505050505050565b6000808251604103612f3f5760208301516040840151606085015160001a612f338782858561334b565b94509450505050612f47565b506000905060025b9250929050565b6000816004811115612f6257612f62613e6b565b03612f6a5750565b6001816004811115612f7e57612f7e613e6b565b03612fe5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015260640161104d565b6002816004811115612ff957612ff9613e6b565b03613060576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161104d565b600381600481111561307457613074613e6b565b03610b5c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f7565000000000000000000000000000000000000000000000000000000000000606482015260840161104d565b60006040517fa9059cbb000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d116001600051141617169150508061239d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f5452414e534645525f4641494c45440000000000000000000000000000000000604482015260640161104d565b60006040517f23b872dd0000000000000000000000000000000000000000000000000000000081528460048201528360248201528260448201526020600060648360008a5af13d15601f3d1160016000511416171691505080611bd7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5452414e534645525f46524f4d5f4641494c4544000000000000000000000000604482015260640161104d565b60008260c0015160001480613290575060c0820151155b1561329d57506001610985565b611eb76132a98461343a565b6132b28461343a565b856101400151856101400151613454565b60008160028111156132d7576132d7613e6b565b14611bd75760018160028111156132f0576132f0613e6b565b036133165760008281526005602052604090206001015461331190856134ee565b611bd7565b600281600281111561332a5761332a613e6b565b03611bd757600083815260056020526040902060010154613311908661361e565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156133825750600090506003613431565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156133d6573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811661342a57600060019250925050613431565b9150600090505b94509492505050565b60006109858260a001518360c00151846101400151612a52565b60008083600181111561346957613469613e6b565b036134ad57600082600181111561348257613482613e6b565b036134a357670de0b6b3a764000061349a8587613faa565b10159050612131565b5082841015612131565b60008260018111156134c1576134c1613e6b565b036134d0575083831015612131565b670de0b6b3a76400006134e38587613faa565b111595945050505050565b60408051600280825260608201835260009260208301908036833701905050905060018160008151811061352457613524613f4c565b60200260200101818152505060028160018151811061354557613545613f4c565b60209081029190910101527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff166372ce42757f00000000000000000000000000000000000000000000000000000000000000005b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526135f09190600090889087908990600401614116565b600060405180830381600087803b15801561360a57600080fd5b505af1158015612f00573d6000803e3d6000fd5b60408051600280825260608201835260009260208301908036833701905050905060018160008151811061365457613654613f4c565b60200260200101818152505060028160018151811061367557613675613f4c565b60209081029190910101527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16639e7212ad7f00000000000000000000000000000000000000000000000000000000000000006135ae565b6000602082840312156136f457600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114611eb757600080fd5b73ffffffffffffffffffffffffffffffffffffffff81168114610b5c57600080fd5b803561375181613724565b919050565b6000806040838503121561376957600080fd5b823561377481613724565b946020939093013593505050565b60006020828403121561379457600080fd5b8135611eb781613724565b6000602082840312156137b157600080fd5b5035919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040516101a0810167ffffffffffffffff8111828210171561380b5761380b6137b8565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715613858576138586137b8565b604052919050565b80356002811061375157600080fd5b80356003811061375157600080fd5b600082601f83011261388f57600080fd5b813567ffffffffffffffff8111156138a9576138a96137b8565b6138da60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601613811565b8181528460208386010111156138ef57600080fd5b816020850160208301376000918101602001919091529392505050565b60006101a0828403121561391f57600080fd5b6139276137e7565b90508135815261393960208301613746565b602082015261394a60408301613746565b604082015261395b60608301613746565b60608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e08201526101008083013581830152506101208083013581830152506101406139ae818401613860565b908201526101606139c083820161386f565b908201526101808281013567ffffffffffffffff8111156139e057600080fd5b6139ec8582860161387e565b82840152505092915050565b600060208284031215613a0a57600080fd5b813567ffffffffffffffff811115613a2157600080fd5b6121318482850161390c565b600080600060608486031215613a4257600080fd5b505081359360208301359350604090920135919050565b600067ffffffffffffffff821115613a7357613a736137b8565b5060051b60200190565b600082601f830112613a8e57600080fd5b81356020613aa3613a9e83613a59565b613811565b82815260059290921b84018101918181019086841115613ac257600080fd5b8286015b84811015613add5780358352918301918301613ac6565b509695505050505050565b600080600080600060a08688031215613b0057600080fd5b8535613b0b81613724565b94506020860135613b1b81613724565b9350604086013567ffffffffffffffff80821115613b3857600080fd5b613b4489838a01613a7d565b94506060880135915080821115613b5a57600080fd5b613b6689838a01613a7d565b93506080880135915080821115613b7c57600080fd5b50613b898882890161387e565b9150509295509295909350565b600082601f830112613ba757600080fd5b81356020613bb7613a9e83613a59565b82815260059290921b84018101918181019086841115613bd657600080fd5b8286015b84811015613add57803567ffffffffffffffff811115613bfa5760008081fd5b613c088986838b010161390c565b845250918301918301613bda565b60008060408385031215613c2957600080fd5b823567ffffffffffffffff80821115613c4157600080fd5b613c4d86838701613b96565b93506020850135915080821115613c6357600080fd5b50613c7085828601613a7d565b9150509250929050565b60008060408385031215613c8d57600080fd5b50508035926020909101359150565b60008060408385031215613caf57600080fd5b82359150602083013567ffffffffffffffff811115613ccd57600080fd5b613c708582860161390c565b60008060008060808587031215613cef57600080fd5b843567ffffffffffffffff80821115613d0757600080fd5b613d138883890161390c565b95506020870135915080821115613d2957600080fd5b613d3588838901613b96565b9450604087013593506060870135915080821115613d5257600080fd5b50613d5f87828801613a7d565b91505092959194509250565b600080600080600060a08688031215613d8357600080fd5b8535613d8e81613724565b94506020860135613d9e81613724565b93506040860135925060608601359150608086013567ffffffffffffffff811115613dc857600080fd5b613b898882890161387e565b600060208284031215613de657600080fd5b813567ffffffffffffffff811115613dfd57600080fd5b61213184828501613b96565b60008060408385031215613e1c57600080fd5b823567ffffffffffffffff811115613e3357600080fd5b613e3f8582860161390c565b95602094909401359450505050565b600060208284031215613e6057600080fd5b8151611eb781613724565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60038110613eaa57613eaa613e6b565b9052565b60006101a0820190508e82528d602083015273ffffffffffffffffffffffffffffffffffffffff808e166040840152808d166060840152808c166080840152508960a08301528860c08301528760e083015286610100830152856101208301528461014083015260028410613f2557613f25613e6b565b83610160830152613f3a610180830184613e9a565b9e9d5050505050505050505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008219821115613fbd57613fbd613f7b565b500190565b600082821015613fd457613fd4613f7b565b500390565b60005b83811015613ff4578181015183820152602001613fdc565b8381111561239d5750506000910152565b60008351614017818460208801613fd9565b83519083019061402b818360208801613fd9565b01949350505050565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561406c5761406c613f7b565b500290565b6000826140a7577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b6000602082840312156140be57600080fd5b5051919050565b60208152600082518060208401526140e4816040850160208701613fd9565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b600060a0820173ffffffffffffffffffffffffffffffffffffffff881683526020878185015286604085015260a0606085015281865180845260c086019150828801935060005b818110156141795784518352938301939183019160010161415d565b5050809350505050826080830152969550505050505056fe608060405234801561001057600080fd5b5060405161017138038061017183398101604081905261002f916100b9565b6001600160a01b0381166100945760405162461bcd60e51b815260206004820152602260248201527f496e76616c69642073696e676c65746f6e20616464726573732070726f766964604482015261195960f21b606482015260840160405180910390fd5b600080546001600160a01b0319166001600160a01b03929092169190911790556100e7565b6000602082840312156100ca578081fd5b81516001600160a01b03811681146100e0578182fd5b9392505050565b607c806100f56000396000f3fe6080604052600080546001600160a01b0316813563530ca43760e11b1415602857808252602082f35b3682833781823684845af490503d82833e806041573d82fd5b503d81f3fea264697066735822122015938e3bf2c49f5df5c1b7f9569fa85cc5d6f3074bb258a2dc0c7e299bc9e33664736f6c63430008040033a264697066735822122056df26e165b5957191bd0ff149c07ae13f5a6b4252973fb3c07a4653cce0f3b164736f6c634300080f00330000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa841740000000000000000000000004d97dcd97ec945f40cf65f87097ace5ea0476045000000000000000000000000ab45c5a4b0c941a2f231c04c3f49182e1a254052000000000000000000000000aacfeea03eb1561c4e67d661e40682bd20e3541b

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106103365760003560e01c806370480275116101b2578063d798eff6116100f9578063e60f0c05116100a2578063f698da251161007c578063f698da2514610892578063fa950b48146108b9578063fbddd751146108cc578063fe729aaf146108df57600080fd5b8063e60f0c0514610834578063edef7d8e14610847578063f23a6e611461085a57600080fd5b8063e03ac3d0116100d3578063e03ac3d014610806578063e2eec4051461080e578063e50e4f971461082157600080fd5b8063d798eff6146107bd578063d7fb272f146107d0578063d82da838146107f357600080fd5b8063a287bdf11161015b578063b28c51c011610135578063b28c51c01461073b578063bc197c8114610759578063c10f1a751461079d57600080fd5b8063a287bdf114610702578063a6dfcf8614610715578063ac8a584a1461072857600080fd5b806383b8a5ae1161018c57806383b8a5ae146106d45780639870d7fe146106dc578063a10f3dce146106ef57600080fd5b8063704802751461068357806375d7370a146106965780637ecebe00146106b457600080fd5b8063429b62e5116102815780635893253c1161022a578063627cdcb911610204578063627cdcb91461061c578063654f0ce41461062457806368c7450f146106375780636d70f7ae1461064a57600080fd5b80635893253c146105ad5780635c1548fb146105e95780635c975abb1461060f57600080fd5b8063456068d21161025b578063456068d21461052f57806346423aa7146105375780634a2a11f5146105a557600080fd5b8063429b62e5146104f457806344bea37e146105145780634544f0551461051c57600080fd5b80631785f53c116102e357806334600901116102bd57806334600901146104b35780633b521d78146104c65780633d6d3598146104ec57600080fd5b80631785f53c1461042257806324d7806c146104355780632dff692d1461046f57600080fd5b80631031e36e116103145780631031e36e146103ca578063131e7e1c146103d457806313e7c9d8146103f457600080fd5b806301ffc9a71461033b5780630647ee201461036357806306b9d6911461039d575b600080fd5b61034e6103493660046136e2565b6108f2565b60405190151581526020015b60405180910390f35b61034e610371366004613756565b73ffffffffffffffffffffffffffffffffffffffff919091166000908152600460205260409020541490565b6103a561098b565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161035a565b6103d2610a24565b005b6007546103a59073ffffffffffffffffffffffffffffffffffffffff1681565b610414610402366004613782565b60026020526000908152604090205481565b60405190815260200161035a565b6103d2610430366004613782565b610a78565b61034e610443366004613782565b73ffffffffffffffffffffffffffffffffffffffff166000908152600160208190526040909120541490565b61049c61047d36600461379f565b6008602052600090815260409020805460019091015460ff9091169082565b60408051921515835260208301919091520161035a565b6103d26104c136600461379f565b610b15565b7f0000000000000000000000004d97dcd97ec945f40cf65f87097ace5ea04760456103a5565b6103d2610b5f565b610414610502366004613782565b60016020526000908152604090205481565b610414600081565b6103d261052a366004613782565b610be3565b6103d2610c36565b61058861054536600461379f565b6040805180820190915260008082526020820152506000908152600860209081526040918290208251808401909352805460ff1615158352600101549082015290565b60408051825115158152602092830151928101929092520161035a565b6103e8610414565b6105d46105bb36600461379f565b6005602052600090815260409020805460019091015482565b6040805192835260208301919091520161035a565b7f0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa841746103a5565b60035461034e9060ff1681565b6103d2610c88565b6103d26106323660046139f8565b610c92565b6103d2610645366004613a2d565b610cad565b61034e610658366004613782565b73ffffffffffffffffffffffffffffffffffffffff1660009081526002602052604090205460011490565b6103d2610691366004613782565b610d07565b60075473ffffffffffffffffffffffffffffffffffffffff166103a5565b6104146106c2366004613782565b60046020526000908152604090205481565b6103d2610da7565b6103d26106ea366004613782565b610e2c565b6104146106fd36600461379f565b610eca565b6103a5610710366004613782565b610ee8565b6103d26107233660046139f8565b610f14565b6103d2610736366004613782565b610f1d565b60065473ffffffffffffffffffffffffffffffffffffffff166103a5565b61076c610767366004613ae8565b610fba565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200161035a565b6006546103a59073ffffffffffffffffffffffffffffffffffffffff1681565b6103d26107cb366004613c16565b610fe5565b6104146107de36600461379f565b60009081526005602052604090206001015490565b6103d2610801366004613c7a565b6110f5565b6103a5611136565b6103d261081c366004613c9c565b6111a6565b61041461082f3660046139f8565b6111fb565b6103d2610842366004613cd9565b611298565b6103a5610855366004613782565b6113a6565b61076c610868366004613d6b565b7ff23a6e610000000000000000000000000000000000000000000000000000000095945050505050565b6104147f1a573e3617c78403b5b4b892827992f027b03d4eaf570048b8ee8cdd84d151be81565b6103d26108c7366004613dd4565b6113d2565b6103d26108da366004613782565b611409565b6103d26108ed366004613e09565b61145c565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f4e2312e000000000000000000000000000000000000000000000000000000000148061098557507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b600654604080517faaf10f42000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff169163aaf10f429160048083019260209291908290030181865afa1580156109fb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a1f9190613e4e565b905090565b3360009081526001602081905260409091205414610a6e576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a7661155e565b565b3360009081526001602081905260409091205414610ac2576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020526040808220829055513392917f787a2e12f4a55b658b8f573c32432ee11a5e8b51677d1e1e937aaf6a0bb5776e91a350565b6000818152600560205260408120549003610b5c576040517f3f6cc76800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b33600090815260026020526040902054600114610ba8576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b336000818152600260205260408082208290555182917ff7262ed0443cc211121ceb1a80d69004f319245615a7488f951f1437fd91642c91a3565b3360009081526001602081905260409091205414610c2d576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610b5c816115b6565b3360009081526001602081905260409091205414610c80576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a76611644565b610a766001611699565b6000610c9d826111fb565b9050610ca981836116c7565b5050565b3360009081526001602081905260409091205414610cf7576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d02838383611826565b505050565b3360009081526001602081905260409091205414610d51576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116600081815260016020819052604080832091909155513392917ff9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dc91a350565b3360009081526001602081905260409091205414610df1576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b336000818152600160205260408082208290555182917f787a2e12f4a55b658b8f573c32432ee11a5e8b51677d1e1e937aaf6a0bb5776e91a3565b3360009081526001602081905260409091205414610e76576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff811660008181526002602052604080822060019055513392917ff1e04d73c4304b5ff164f9d10c7473e2a1593b740674a6107975e2a7001c1e5c91a350565b6000610ed582610b15565b5060009081526005602052604090205490565b600061098582610ef6611136565b60075473ffffffffffffffffffffffffffffffffffffffff16611982565b610b5c81611a80565b3360009081526001602081905260409091205414610f67576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116600081815260026020526040808220829055513392917ff7262ed0443cc211121ceb1a80d69004f319245615a7488f951f1437fd91642c91a350565b7fbc197c81000000000000000000000000000000000000000000000000000000005b95945050505050565b600054600203611056576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f5245454e5452414e43590000000000000000000000000000000000000000000060448201526064015b60405180910390fd5b6002600081815533815260209190915260409020546001146110a4576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60035460ff16156110e1576040517f9e87fac800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6110ec828233611b85565b50506001600055565b806110ff83610eca565b14610ca9576040517f66f8620a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600754604080517fa619486e000000000000000000000000000000000000000000000000000000008152905160009273ffffffffffffffffffffffffffffffffffffffff169163a619486e9160048083019260209291908290030181865afa1580156109fb573d6000803e3d6000fd5b6111c58160400151826020015184846101800151856101600151611bde565b610ca9576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006109857fa852566c4e14d00869b6db0220888a9090a13eccdaea03713ff0a3d27bf9767c836000015184602001518560400151866060015187608001518860a001518960c001518a60e001518b61010001518c61012001518d61014001518e610160015160405160200161127d9d9c9b9a99989796959493929190613eae565b60405160208183030381529060405280519060200120611c3c565b600054600203611304576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f5245454e5452414e435900000000000000000000000000000000000000000000604482015260640161104d565b600260008181553381526020919091526040902054600114611352576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60035460ff161561138f576040517f9e87fac800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61139b84848484611ca5565b505060016000555050565b6000610985826113b461098b565b60065473ffffffffffffffffffffffffffffffffffffffff16611e5c565b805160005b81811015610d02576114018382815181106113f4576113f4613f4c565b6020026020010151611a80565b6001016113d7565b3360009081526001602081905260409091205414611453576040517f7bfa4b9f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610b5c81611ebe565b6000546002036114c8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600a60248201527f5245454e5452414e435900000000000000000000000000000000000000000000604482015260640161104d565b600260008181553381526020919091526040902054600114611516576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60035460ff1615611553576040517f9e87fac800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6110ec828233611f4c565b600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905560405133907f203c4bd3e526634f661575359ff30de3b0edaba6c2cb1eac60f730b6d2d9d53690600090a2565b60075460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f9726d7faf7429d6b059560dc858ed769377ccdf8b7541eabe12b22548719831f90600090a3600780547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b600380547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905560405133907fa1e8a54850dbd7f520bcc09f47bff152294b77b2081da545a7adf531b7ea283b90600090a2565b336000908152600460205260409020546116b4908290613faa565b3360009081526004602052604090205550565b60008160e001511180156116de5750428160e00151105b15611715576040517fc56873ba00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61171f82826111a6565b6103e88161012001511115611760576040517fcd4e616700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61176d8160800151610b15565b60008281526008602052604090205460ff16156117b6576040517f7b38b76e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6117f0816020015182610100015173ffffffffffffffffffffffffffffffffffffffff919091166000908152600460205260409020541490565b610ca9576040517f756688fe00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8183148061183a575082158061183a575081155b15611871576040517f3f6cc76800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008381526005602052604090205415158061189a575060008281526005602052604090205415155b156118d1576040517f3a81d6fc00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805180820182528381526020808201848152600087815260058084528582209451855591516001948501558451808601865288815280840187815288835292909352848120925183559051919092015590518291849186917fbc9a2432e8aeb48327246cddd6e872ef452812b4243c04e6bfb786a2cd8faf0d91a48083837fbc9a2432e8aeb48327246cddd6e872ef452812b4243c04e6bfb786a2cd8faf0d60405160405180910390a4505050565b60008061198e8461205a565b8051906020012090506000856040516020016119c6919073ffffffffffffffffffffffffffffffffffffffff91909116815260200190565b604080518083037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe001815282825280516020918201207fff000000000000000000000000000000000000000000000000000000000000008285015260609790971b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000166021840152603583019690965260558083019490945280518083039094018452607590910190525080519201919091209392505050565b602081015173ffffffffffffffffffffffffffffffffffffffff163314611ad3576040517f30cd747100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000611ade826111fb565b600081815260086020526040902080549192509060ff1615611b2c576040517f7b38b76e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117815560405182907f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d90600090a2505050565b825160005b81811015611bd757611bcf858281518110611ba757611ba7613f4c565b6020026020010151858381518110611bc157611bc1613f4c565b602002602001015185611f4c565b600101611b8a565b5050505050565b600080826002811115611bf357611bf3613e6b565b03611c0b57611c04868686866120eb565b9050610fdc565b6002826002811115611c1f57611c1f613e6b565b03611c3057611c0486868686612139565b611c048686868661218d565b6000610985611c496121c1565b836040517f19010000000000000000000000000000000000000000000000000000000000006020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b81600080611cb387846122f5565b91509150600080611cc389612342565b91509150611cd78960200151308488612379565b611ce28989886123a3565b611cec84826123f5565b6101208a0151909450600090611d2e90828c61014001516001811115611d1457611d14613e6b565b14611d1f5787611d21565b865b88888e610140015161243d565b9050611d4b308b60200151848489611d469190613fc2565b612379565b611d573033848461252d565b6000611d6284612596565b90508015611d7a57611d7a308c602001518684612379565b60208b8101516040805187815292830186905282018990526060820188905260808201849052309173ffffffffffffffffffffffffffffffffffffffff9091169087907fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69060a00160405180910390a46020808c01516040805187815292830186905282018990526060820188905273ffffffffffffffffffffffffffffffffffffffff169086907f63bf4d16b7fa898ef4c4b2b6d90fd201e9c56313b65638af6088d149d2ce956c9060800160405180910390a35050505050505050505050565b6040517fffffffffffffffffffffffffffffffffffffffff000000000000000000000000606085901b166020820152600090611eb49083908590603401604051602081830303815290604052805190602001206126c6565b90505b9392505050565b60065460405173ffffffffffffffffffffffffffffffffffffffff8084169216907f3053c6252a932554235c173caffc1913604dba3a41cee89516f631c4a1a50a3790600090a3600680547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b81600080611f5a86846122f5565b6101208801519193509150600090611fa790825b8961014001516001811115611f8557611f85613e6b565b14611f905785611f92565b845b8960a001518a60c001518b610140015161243d565b9050600080611fb589612342565b91509150611fcf338a60200151838689611d469190613fc2565b611fdf8960200151888489612379565b6020898101516040805185815292830184905282018890526060820187905260808201859052339173ffffffffffffffffffffffffffffffffffffffff9091169086907fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69060a00160405180910390a4505050505050505050565b6060604051806101a00160405280610171815260200161419261017191396040805173ffffffffffffffffffffffffffffffffffffffff8516602082015201604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290526120d59291602001614005565b6040516020818303038152906040529050919050565b60008373ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614801561212e575061212e858484612763565b90505b949350505050565b6000612146858484612763565b801561212e57508373ffffffffffffffffffffffffffffffffffffffff1661216d86610ee8565b73ffffffffffffffffffffffffffffffffffffffff161495945050505050565b600061219a858484612763565b801561212e57508373ffffffffffffffffffffffffffffffffffffffff1661216d866113a6565b60003073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004bfb41d5b3570defd03c39a9a4d8de6bd8b8982e1614801561222757507f000000000000000000000000000000000000000000000000000000000000008946145b1561225157507f1a573e3617c78403b5b4b892827992f027b03d4eaf570048b8ee8cdd84d151be90565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527ff30041e9aac4c4d3a1481d2941dfb0a844a72040e9bbc79a810d1ec5b5d6c7af828401527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b60008061230584606001516127a5565b61230e846111fb565b905061231a81856116c7565b61232d838560a001518660c00151612817565b915061233a81858561283e565b509250929050565b60008080836101400151600181111561235d5761235d613e6b565b0361236d57505060800151600091565b50506080015190600090565b816000036123915761238c8484836128eb565b61239d565b61239d84848484612940565b50505050565b815160005b81811015611bd7576123ed858583815181106123c6576123c6613f4c565b60200260200101518584815181106123e0576123e0613f4c565b602002602001015161296d565b6001016123a8565b60008061240183612596565b905083811015611eb7576040517fdf4d808000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008515610fdc576000612452858585612a52565b905060008111801561246c5750670de0b6b3a76400008111155b1561252357600083600181111561248557612485613e6b565b036124d75761249661271082614034565b866124b2836124ad81670de0b6b3a7640000613fc2565b612ac1565b6124bc908a614034565b6124c69190614034565b6124d09190614071565b9150612523565b6124eb670de0b6b3a7640000612710614034565b86612502836124ad81670de0b6b3a7640000613fc2565b61250c908a614034565b6125169190614034565b6125209190614071565b91505b5095945050505050565b801561239d5761253f84848484612379565b604080518381526020810183905273ffffffffffffffffffffffffffffffffffffffff8516917facffcc86834d0f1a64b0d5a675798deed6ff0bcfc2231edd3480e7288dba7ff4910160405180910390a250505050565b60008160000361264f576040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa8417416906370a08231906024015b602060405180830381865afa15801561262b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061098591906140ac565b6040517efdd58e0000000000000000000000000000000000000000000000000000000081523060048201526024810183905273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004d97dcd97ec945f40cf65f87097ace5ea0476045169062fdd58e9060440161260e565b6000806126d38585612ad7565b8051602091820120604080517fff000000000000000000000000000000000000000000000000000000000000008185015260609890981b7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000166021890152603588019590955260558088019190915284518088039091018152607590960190935250508251920191909120919050565b60008373ffffffffffffffffffffffffffffffffffffffff166127868484612c5a565b73ffffffffffffffffffffffffffffffffffffffff1614949350505050565b73ffffffffffffffffffffffffffffffffffffffff8116158015906127e0575073ffffffffffffffffffffffffffffffffffffffff81163314155b15610b5c576040517f5211a07900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008260000361282957506000611eb7565b826128348386614034565b611eb49190614071565b6000838152600860205260409020600181015490811561285e5781612864565b8360a001515b9150818311156128a0576040517fe2cc6ad600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6128aa8383613fc2565b9150816000036128de5780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011781555b6001018190559392505050565b7f0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa841743073ffffffffffffffffffffffffffffffffffffffff8516036129345761238c818484612c7e565b61239d81858585612c89565b61239d7f0000000000000000000000004d97dcd97ec945f40cf65f87097ace5ea047604585858585612c95565b60006129798484612d41565b9050612986848483612ddd565b8160008061299486846122f5565b61012088015191935091506000906129ac9082611f6e565b90506000806129ba89612342565b915091506129d186868b6020015185858c89612e89565b6020808b01518a820151604080518681529384018590528301899052606083018890526080830186905273ffffffffffffffffffffffffffffffffffffffff9182169291169086907fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69060a00160405180910390a450505050505050505050565b600080826001811115612a6757612a67613e6b565b03612a9f5782600003612a7b576000612a98565b82612a8e670de0b6b3a764000086614034565b612a989190614071565b9050611eb7565b83600003612aae576000611eb4565b83612834670de0b6b3a764000085614034565b6000818310612ad05781611eb7565b5090919050565b6040805160008082526020820190925260609190612af890604481016140c5565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152918152602080830180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f52e831dd000000000000000000000000000000000000000000000000000000001790528151606380825260a082019093529293506000929190820181803683370190505090507f3d3d606380380380913d393d73bebebebebebebebebebebebebebebebebebebe60208201526c010000000000000000000000008502602d8201527f5af4602a57600080fd5b602d8060366000396000f3363d3d373d3d3d363d73be60418201526c01000000000000000000000000840260608201527f5af43d82803e903d91602b57fd5bf3000000000000000000000000000000000060748201528082604051602001612c41929190614005565b6040516020818303038152906040529250505092915050565b6000806000612c698585612f09565b91509150612c7681612f4e565b509392505050565b610d02838383613101565b61239d848484846131ba565b6040517ff242432a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff85811660048301528481166024830152604482018490526064820183905260a06084830152600060a483015286169063f242432a9060c401600060405180830381600087803b158015612d2257600080fd5b505af1158015612d36573d6000803e3d6000fd5b505050505050505050565b6000808361014001516001811115612d5b57612d5b613e6b565b148015612d7e575060008261014001516001811115612d7c57612d7c613e6b565b145b15612d8b57506001610985565b60018361014001516001811115612da457612da4613e6b565b148015612dc7575060018261014001516001811115612dc557612dc5613e6b565b145b15612dd457506002610985565b50600092915050565b612de78383613279565b612e1d576040517f7f9a6f4600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000816002811115612e3157612e31613e6b565b03612e77578160800151836080015114610d02576040517fa0b9446500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610d02836080015183608001516110f5565b612e958530868a612379565b612ea287878686866132c3565b85612eac84612596565b1015612ee4576040517fdf4d808000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612ef4308685611d46858b613fc2565b612f003033858461252d565b50505050505050565b6000808251604103612f3f5760208301516040840151606085015160001a612f338782858561334b565b94509450505050612f47565b506000905060025b9250929050565b6000816004811115612f6257612f62613e6b565b03612f6a5750565b6001816004811115612f7e57612f7e613e6b565b03612fe5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601860248201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604482015260640161104d565b6002816004811115612ff957612ff9613e6b565b03613060576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161104d565b600381600481111561307457613074613e6b565b03610b5c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f7565000000000000000000000000000000000000000000000000000000000000606482015260840161104d565b60006040517fa9059cbb000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d116001600051141617169150508061239d576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f5452414e534645525f4641494c45440000000000000000000000000000000000604482015260640161104d565b60006040517f23b872dd0000000000000000000000000000000000000000000000000000000081528460048201528360248201528260448201526020600060648360008a5af13d15601f3d1160016000511416171691505080611bd7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5452414e534645525f46524f4d5f4641494c4544000000000000000000000000604482015260640161104d565b60008260c0015160001480613290575060c0820151155b1561329d57506001610985565b611eb76132a98461343a565b6132b28461343a565b856101400151856101400151613454565b60008160028111156132d7576132d7613e6b565b14611bd75760018160028111156132f0576132f0613e6b565b036133165760008281526005602052604090206001015461331190856134ee565b611bd7565b600281600281111561332a5761332a613e6b565b03611bd757600083815260056020526040902060010154613311908661361e565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156133825750600090506003613431565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156133d6573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811661342a57600060019250925050613431565b9150600090505b94509492505050565b60006109858260a001518360c00151846101400151612a52565b60008083600181111561346957613469613e6b565b036134ad57600082600181111561348257613482613e6b565b036134a357670de0b6b3a764000061349a8587613faa565b10159050612131565b5082841015612131565b60008260018111156134c1576134c1613e6b565b036134d0575083831015612131565b670de0b6b3a76400006134e38587613faa565b111595945050505050565b60408051600280825260608201835260009260208301908036833701905050905060018160008151811061352457613524613f4c565b60200260200101818152505060028160018151811061354557613545613f4c565b60209081029190910101527f0000000000000000000000004d97dcd97ec945f40cf65f87097ace5ea047604573ffffffffffffffffffffffffffffffffffffffff166372ce42757f0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa841745b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526135f09190600090889087908990600401614116565b600060405180830381600087803b15801561360a57600080fd5b505af1158015612f00573d6000803e3d6000fd5b60408051600280825260608201835260009260208301908036833701905050905060018160008151811061365457613654613f4c565b60200260200101818152505060028160018151811061367557613675613f4c565b60209081029190910101527f0000000000000000000000004d97dcd97ec945f40cf65f87097ace5ea047604573ffffffffffffffffffffffffffffffffffffffff16639e7212ad7f0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa841746135ae565b6000602082840312156136f457600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114611eb757600080fd5b73ffffffffffffffffffffffffffffffffffffffff81168114610b5c57600080fd5b803561375181613724565b919050565b6000806040838503121561376957600080fd5b823561377481613724565b946020939093013593505050565b60006020828403121561379457600080fd5b8135611eb781613724565b6000602082840312156137b157600080fd5b5035919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040516101a0810167ffffffffffffffff8111828210171561380b5761380b6137b8565b60405290565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016810167ffffffffffffffff81118282101715613858576138586137b8565b604052919050565b80356002811061375157600080fd5b80356003811061375157600080fd5b600082601f83011261388f57600080fd5b813567ffffffffffffffff8111156138a9576138a96137b8565b6138da60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f84011601613811565b8181528460208386010111156138ef57600080fd5b816020850160208301376000918101602001919091529392505050565b60006101a0828403121561391f57600080fd5b6139276137e7565b90508135815261393960208301613746565b602082015261394a60408301613746565b604082015261395b60608301613746565b60608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e08201526101008083013581830152506101208083013581830152506101406139ae818401613860565b908201526101606139c083820161386f565b908201526101808281013567ffffffffffffffff8111156139e057600080fd5b6139ec8582860161387e565b82840152505092915050565b600060208284031215613a0a57600080fd5b813567ffffffffffffffff811115613a2157600080fd5b6121318482850161390c565b600080600060608486031215613a4257600080fd5b505081359360208301359350604090920135919050565b600067ffffffffffffffff821115613a7357613a736137b8565b5060051b60200190565b600082601f830112613a8e57600080fd5b81356020613aa3613a9e83613a59565b613811565b82815260059290921b84018101918181019086841115613ac257600080fd5b8286015b84811015613add5780358352918301918301613ac6565b509695505050505050565b600080600080600060a08688031215613b0057600080fd5b8535613b0b81613724565b94506020860135613b1b81613724565b9350604086013567ffffffffffffffff80821115613b3857600080fd5b613b4489838a01613a7d565b94506060880135915080821115613b5a57600080fd5b613b6689838a01613a7d565b93506080880135915080821115613b7c57600080fd5b50613b898882890161387e565b9150509295509295909350565b600082601f830112613ba757600080fd5b81356020613bb7613a9e83613a59565b82815260059290921b84018101918181019086841115613bd657600080fd5b8286015b84811015613add57803567ffffffffffffffff811115613bfa5760008081fd5b613c088986838b010161390c565b845250918301918301613bda565b60008060408385031215613c2957600080fd5b823567ffffffffffffffff80821115613c4157600080fd5b613c4d86838701613b96565b93506020850135915080821115613c6357600080fd5b50613c7085828601613a7d565b9150509250929050565b60008060408385031215613c8d57600080fd5b50508035926020909101359150565b60008060408385031215613caf57600080fd5b82359150602083013567ffffffffffffffff811115613ccd57600080fd5b613c708582860161390c565b60008060008060808587031215613cef57600080fd5b843567ffffffffffffffff80821115613d0757600080fd5b613d138883890161390c565b95506020870135915080821115613d2957600080fd5b613d3588838901613b96565b9450604087013593506060870135915080821115613d5257600080fd5b50613d5f87828801613a7d565b91505092959194509250565b600080600080600060a08688031215613d8357600080fd5b8535613d8e81613724565b94506020860135613d9e81613724565b93506040860135925060608601359150608086013567ffffffffffffffff811115613dc857600080fd5b613b898882890161387e565b600060208284031215613de657600080fd5b813567ffffffffffffffff811115613dfd57600080fd5b61213184828501613b96565b60008060408385031215613e1c57600080fd5b823567ffffffffffffffff811115613e3357600080fd5b613e3f8582860161390c565b95602094909401359450505050565b600060208284031215613e6057600080fd5b8151611eb781613724565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60038110613eaa57613eaa613e6b565b9052565b60006101a0820190508e82528d602083015273ffffffffffffffffffffffffffffffffffffffff808e166040840152808d166060840152808c166080840152508960a08301528860c08301528760e083015286610100830152856101208301528461014083015260028410613f2557613f25613e6b565b83610160830152613f3a610180830184613e9a565b9e9d5050505050505050505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008219821115613fbd57613fbd613f7b565b500190565b600082821015613fd457613fd4613f7b565b500390565b60005b83811015613ff4578181015183820152602001613fdc565b8381111561239d5750506000910152565b60008351614017818460208801613fd9565b83519083019061402b818360208801613fd9565b01949350505050565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048311821515161561406c5761406c613f7b565b500290565b6000826140a7577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b6000602082840312156140be57600080fd5b5051919050565b60208152600082518060208401526140e4816040850160208701613fd9565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b600060a0820173ffffffffffffffffffffffffffffffffffffffff881683526020878185015286604085015260a0606085015281865180845260c086019150828801935060005b818110156141795784518352938301939183019160010161415d565b5050809350505050826080830152969550505050505056fe608060405234801561001057600080fd5b5060405161017138038061017183398101604081905261002f916100b9565b6001600160a01b0381166100945760405162461bcd60e51b815260206004820152602260248201527f496e76616c69642073696e676c65746f6e20616464726573732070726f766964604482015261195960f21b606482015260840160405180910390fd5b600080546001600160a01b0319166001600160a01b03929092169190911790556100e7565b6000602082840312156100ca578081fd5b81516001600160a01b03811681146100e0578182fd5b9392505050565b607c806100f56000396000f3fe6080604052600080546001600160a01b0316813563530ca43760e11b1415602857808252602082f35b3682833781823684845af490503d82833e806041573d82fd5b503d81f3fea264697066735822122015938e3bf2c49f5df5c1b7f9569fa85cc5d6f3074bb258a2dc0c7e299bc9e33664736f6c63430008040033a264697066735822122056df26e165b5957191bd0ff149c07ae13f5a6b4252973fb3c07a4653cce0f3b164736f6c634300080f0033

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

0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa841740000000000000000000000004d97dcd97ec945f40cf65f87097ace5ea0476045000000000000000000000000ab45c5a4b0c941a2f231c04c3f49182e1a254052000000000000000000000000aacfeea03eb1561c4e67d661e40682bd20e3541b

-----Decoded View---------------
Arg [0] : _collateral (address): 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174
Arg [1] : _ctf (address): 0x4D97DCd97eC945f40cF65F87097ACe5EA0476045
Arg [2] : _proxyFactory (address): 0xaB45c5A4B0c941a2F231C04C3f49182e1A254052
Arg [3] : _safeFactory (address): 0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 0000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174
Arg [1] : 0000000000000000000000004d97dcd97ec945f40cf65f87097ace5ea0476045
Arg [2] : 000000000000000000000000ab45c5a4b0c941a2f231c04c3f49182e1a254052
Arg [3] : 000000000000000000000000aacfeea03eb1561c4e67d661e40682bd20e3541b


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ 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.