ETH Price: $2,865.71 (-2.57%)

Contract

0x6a3796C21e733a3016Bc0bA41edF763016247e72
 

Overview

ETH Balance

0 ETH

ETH Value

$0.00

Token Holdings

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Cancel Orders108467522024-11-01 23:21:59450 days ago1730503319IN
0x6a3796C2...016247e72
0 ETH0.000000880.00192863
Cancel Orders108422372024-11-01 20:51:29450 days ago1730494289IN
0x6a3796C2...016247e72
0 ETH0.000001250.00148937
Cancel Orders108352302024-11-01 16:57:55450 days ago1730480275IN
0x6a3796C2...016247e72
0 ETH0.00000080.00213207
Cancel Orders108342622024-11-01 16:25:39450 days ago1730478339IN
0x6a3796C2...016247e72
0 ETH0.000001270.00196642
Cancel Orders108339462024-11-01 16:15:07450 days ago1730477707IN
0x6a3796C2...016247e72
0 ETH0.000001250.00171338
Cancel Orders108333752024-11-01 15:56:05450 days ago1730476565IN
0x6a3796C2...016247e72
0 ETH0.000002590.00202782
Cancel Orders108317752024-11-01 15:02:45450 days ago1730473365IN
0x6a3796C2...016247e72
0 ETH0.000001850.00169272
Cancel Orders108315462024-11-01 14:55:07450 days ago1730472907IN
0x6a3796C2...016247e72
0 ETH0.000001850.00178265
Cancel Orders108302762024-11-01 14:12:47450 days ago1730470367IN
0x6a3796C2...016247e72
0 ETH0.000001540.00171328
Cancel Orders108083512024-11-01 2:01:57451 days ago1730426517IN
0x6a3796C2...016247e72
0 ETH0.000001760.00277138
Cancel Orders108015152024-10-31 22:14:05451 days ago1730412845IN
0x6a3796C2...016247e72
0 ETH0.000000620.00238088
Cancel Orders108012312024-10-31 22:04:37451 days ago1730412277IN
0x6a3796C2...016247e72
0 ETH0.000000620.0023522
Cancel Orders108011042024-10-31 22:00:23451 days ago1730412023IN
0x6a3796C2...016247e72
0 ETH0.00000070.00229783
Cancel Orders107995652024-10-31 21:09:05451 days ago1730408945IN
0x6a3796C2...016247e72
0 ETH0.000000750.00167115
Cancel Orders107980972024-10-31 20:20:09451 days ago1730406009IN
0x6a3796C2...016247e72
0 ETH0.000006010.00184401
Cancel Orders107930972024-10-31 17:33:29451 days ago1730396009IN
0x6a3796C2...016247e72
0 ETH0.000000280.00327338
Cancel Orders107890362024-10-31 15:18:07451 days ago1730387887IN
0x6a3796C2...016247e72
0 ETH0.000002070.00151809
Cancel Orders107876452024-10-31 14:31:45451 days ago1730385105IN
0x6a3796C2...016247e72
0 ETH0.000009540.00155178
Cancel Orders107575952024-10-30 21:50:05452 days ago1730325005IN
0x6a3796C2...016247e72
0 ETH0.000001040.00289276
Cancel Orders107555852024-10-30 20:43:05452 days ago1730320985IN
0x6a3796C2...016247e72
0 ETH0.000001230.00486894
Cancel Orders107553802024-10-30 20:36:15452 days ago1730320575IN
0x6a3796C2...016247e72
0 ETH0.000001180.00487657
Cancel Orders107545452024-10-30 20:08:25452 days ago1730318905IN
0x6a3796C2...016247e72
0 ETH0.000000640.00449747
Cancel Orders107530622024-10-30 19:18:59452 days ago1730315939IN
0x6a3796C2...016247e72
0 ETH0.000000450.00382923
Cancel Orders107502752024-10-30 17:46:05452 days ago1730310365IN
0x6a3796C2...016247e72
0 ETH0.000000810.00507787
Cancel Orders107488912024-10-30 16:59:57452 days ago1730307597IN
0x6a3796C2...016247e72
0 ETH0.000001260.00219879
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
BlastNegRiskCtfExchange

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 57 : BlastNegRiskCtfExchange.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {BlastNativeYield} from "../Blast/BlastNativeYield.sol";

import {NegRiskCtfExchange} from "./NegRiskCtfExchange.sol";
import {IConditionalTokens} from "../UMA/interfaces/IConditionalTokens.sol";

contract BlastNegRiskCtfExchange is NegRiskCtfExchange, BlastNativeYield {
    constructor(
        address _collateral,
        address _ctf,
        address _negRiskAdapter,
        address _proxyFactory,
        address _safeFactory,
        address _addressFinder
    )
        NegRiskCtfExchange(_collateral, _ctf, _negRiskAdapter, _proxyFactory, _safeFactory)
        BlastNativeYield(_addressFinder)
    {}
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1271.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC1271 standard signature validation method for
 * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
 */
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 3 of 57 : IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)

pragma solidity ^0.8.20;

interface IERC5267 {
    /**
     * @dev MAY be emitted to signal that the domain could have changed.
     */
    event EIP712DomainChanged();

    /**
     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
     * signature.
     */
    function eip712Domain()
        external
        view
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        );
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 */
interface IERC1155 is IERC165 {
    /**
     * @dev Emitted when `value` amount of tokens of 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 value 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 a `value` amount of tokens of type `id` from `from` to `to`.
     *
     * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
     * to an untrusted contract, when invoking {onERC1155Received} on the receiver.
     * Ensure to follow the checks-effects-interactions pattern and consider employing
     * reentrancy guards when interacting with untrusted contracts.
     *
     * 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 `value` 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 value, bytes calldata data) external;

    /**
     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
     *
     * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
     * to an untrusted contract, when invoking {onERC1155BatchReceived} on the receiver.
     * Ensure to follow the checks-effects-interactions pattern and consider employing
     * reentrancy guards when interacting with untrusted contracts.
     *
     * Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments.
     *
     * Requirements:
     *
     * - `ids` and `values` 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 values,
        bytes calldata data
    ) external;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)

pragma solidity ^0.8.20;

import {IERC165} from "../../utils/introspection/IERC165.sol";

/**
 * @dev Interface that must be implemented by smart contracts in order to receive
 * ERC-1155 token transfers.
 */
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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/utils/ERC1155Holder.sol)

pragma solidity ^0.8.20;

import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol";
import {IERC1155Receiver} from "../IERC1155Receiver.sol";

/**
 * @dev Simple implementation of `IERC1155Receiver` 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.
 */
abstract contract ERC1155Holder 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);
    }

    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;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.20;

/**
 * @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
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
     * return address(0) without also returning an error description. Errors are documented using an enum (error type)
     * and a bytes32 providing additional information about the error.
     *
     * If no error is returned, then the address can be used for verification purposes.
     *
     * The `ecrecover` EVM precompile 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 {MessageHashUtils-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]
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
        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, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile 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 {MessageHashUtils-toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        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]
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            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.
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError, bytes32) {
        // 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, s);
        }

        // 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, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @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, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
     */
    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.20;

import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
 * encoding is very generic and therefore its 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 order to
 * produce the hash of their typed data 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].
 *
 * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
 * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
 * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
 *
 * @custom:oz-upgrades-unsafe-allow state-variable-immutable
 */
abstract contract EIP712 is IERC5267 {
    using ShortStrings for *;

    bytes32 private constant TYPE_HASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

    // 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 _cachedDomainSeparator;
    uint256 private immutable _cachedChainId;
    address private immutable _cachedThis;

    bytes32 private immutable _hashedName;
    bytes32 private immutable _hashedVersion;

    ShortString private immutable _name;
    ShortString private immutable _version;
    string private _nameFallback;
    string private _versionFallback;

    /**
     * @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) {
        _name = name.toShortStringWithFallback(_nameFallback);
        _version = version.toShortStringWithFallback(_versionFallback);
        _hashedName = keccak256(bytes(name));
        _hashedVersion = keccak256(bytes(version));

        _cachedChainId = block.chainid;
        _cachedDomainSeparator = _buildDomainSeparator();
        _cachedThis = address(this);
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
            return _cachedDomainSeparator;
        } else {
            return _buildDomainSeparator();
        }
    }

    function _buildDomainSeparator() private view returns (bytes32) {
        return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, 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 MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
    }

    /**
     * @dev See {IERC-5267}.
     */
    function eip712Domain()
        public
        view
        virtual
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        )
    {
        return (
            hex"0f", // 01111
            _EIP712Name(),
            _EIP712Version(),
            block.chainid,
            address(this),
            bytes32(0),
            new uint256[](0)
        );
    }

    /**
     * @dev The name parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _name which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Name() internal view returns (string memory) {
        return _name.toStringWithFallback(_nameFallback);
    }

    /**
     * @dev The version parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _version which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Version() internal view returns (string memory) {
        return _version.toStringWithFallback(_versionFallback);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
 *
 * The library provides methods for generating a hash of a message that conforms to the
 * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
 * specifications.
 */
library MessageHashUtils {
    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing a bytes32 `messageHash` with
     * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
     * keccak256, although any bytes32 value can be safely used because the final digest will
     * be re-hashed.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
            mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
            digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
        }
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing an arbitrary `message` with
     * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
        return
            keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x00` (data with intended validator).
     *
     * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
     * `validator` address. Then hashing the result.
     *
     * See {ECDSA-recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(hex"19_00", validator, data));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
     *
     * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
     * `\x19\x01` and hashing the result. It corresponds to the hash signed by the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
     *
     * See {ECDSA-recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, hex"19_01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            digest := keccak256(ptr, 0x42)
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/SignatureChecker.sol)

pragma solidity ^0.8.20;

import {ECDSA} from "./ECDSA.sol";
import {IERC1271} from "../../interfaces/IERC1271.sol";

/**
 * @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA
 * signatures from externally owned accounts (EOAs) as well as ERC1271 signatures from smart contract wallets like
 * Argent and Safe Wallet (previously Gnosis Safe).
 */
library SignatureChecker {
    /**
     * @dev Checks if a signature is valid for a given signer and data hash. If the signer is a smart contract, the
     * signature is validated against that smart contract using ERC1271, otherwise it's validated using `ECDSA.recover`.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
        (address recovered, ECDSA.RecoverError error, ) = ECDSA.tryRecover(hash, signature);
        return
            (error == ECDSA.RecoverError.NoError && recovered == signer) ||
            isValidERC1271SignatureNow(signer, hash, signature);
    }

    /**
     * @dev Checks if a signature is valid for a given signer and data hash. The signature is validated
     * against the signer smart contract using ERC1271.
     *
     * NOTE: Unlike ECDSA signatures, contract signatures are revocable, and the outcome of this function can thus
     * change through time. It could return true at block N and false at block N+1 (or the opposite).
     */
    function isValidERC1271SignatureNow(
        address signer,
        bytes32 hash,
        bytes memory signature
    ) internal view returns (bool) {
        (bool success, bytes memory result) = signer.staticcall(
            abi.encodeCall(IERC1271.isValidSignature, (hash, signature))
        );
        return (success &&
            result.length >= 32 &&
            abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)

pragma solidity ^0.8.20;

import {IERC165} from "./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);
 * }
 * ```
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

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

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

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

    /**
     * @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 towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (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 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

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

            ///////////////////////////////////////////////
            // 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.

            uint256 twos = denominator & (0 - denominator);
            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 (unsignedRoundsUp(rounding) && 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
     * towards zero.
     *
     * 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 + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * 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 + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * 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 + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * 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 256, 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 + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

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

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)

pragma solidity ^0.8.20;

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

// | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |
// | length  | 0x                                                              BB |
type ShortString is bytes32;

/**
 * @dev This library provides functions to convert short memory strings
 * into a `ShortString` type that can be used as an immutable variable.
 *
 * Strings of arbitrary length can be optimized using this library if
 * they are short enough (up to 31 bytes) by packing them with their
 * length (1 byte) in a single EVM word (32 bytes). Additionally, a
 * fallback mechanism can be used for every other case.
 *
 * Usage example:
 *
 * ```solidity
 * contract Named {
 *     using ShortStrings for *;
 *
 *     ShortString private immutable _name;
 *     string private _nameFallback;
 *
 *     constructor(string memory contractName) {
 *         _name = contractName.toShortStringWithFallback(_nameFallback);
 *     }
 *
 *     function name() external view returns (string memory) {
 *         return _name.toStringWithFallback(_nameFallback);
 *     }
 * }
 * ```
 */
library ShortStrings {
    // Used as an identifier for strings longer than 31 bytes.
    bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;

    error StringTooLong(string str);
    error InvalidShortString();

    /**
     * @dev Encode a string of at most 31 chars into a `ShortString`.
     *
     * This will trigger a `StringTooLong` error is the input string is too long.
     */
    function toShortString(string memory str) internal pure returns (ShortString) {
        bytes memory bstr = bytes(str);
        if (bstr.length > 31) {
            revert StringTooLong(str);
        }
        return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
    }

    /**
     * @dev Decode a `ShortString` back to a "normal" string.
     */
    function toString(ShortString sstr) internal pure returns (string memory) {
        uint256 len = byteLength(sstr);
        // using `new string(len)` would work locally but is not memory safe.
        string memory str = new string(32);
        /// @solidity memory-safe-assembly
        assembly {
            mstore(str, len)
            mstore(add(str, 0x20), sstr)
        }
        return str;
    }

    /**
     * @dev Return the length of a `ShortString`.
     */
    function byteLength(ShortString sstr) internal pure returns (uint256) {
        uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
        if (result > 31) {
            revert InvalidShortString();
        }
        return result;
    }

    /**
     * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
     */
    function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
        if (bytes(value).length < 32) {
            return toShortString(value);
        } else {
            StorageSlot.getStringSlot(store).value = value;
            return ShortString.wrap(FALLBACK_SENTINEL);
        }
    }

    /**
     * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     */
    function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return toString(value);
        } else {
            return store;
        }
    }

    /**
     * @dev Return the length of a string that was encoded to `ShortString` or written to storage using
     * {setWithFallback}.
     *
     * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
     * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
     */
    function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return byteLength(value);
        } else {
            return bytes(store).length;
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)

pragma solidity ^0.8.20;

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

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

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @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), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

    /**
     * @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) {
        uint256 localValue = value;
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = HEX_DIGITS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        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);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 19 of 57 : BlastNativeYield.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {IBlast, YieldMode, GasMode} from "./interfaces/IBlast.sol";
import {IAddressFinder} from "./interfaces/IAddressFinder.sol";
import {BlastPoints} from "./BlastPoints.sol";

/**
 * @title BlastNativeYield
 * @notice This contract is a base contract for inheriting functions to claim native yield and for those that wish to receive Blast points
 */
contract BlastNativeYield is BlastPoints {
    /**
     * @param addressFinder Blast address finder
     */
    constructor(address addressFinder) BlastPoints(addressFinder) {
        address blast = IAddressFinder(addressFinder).getImplementationAddress("Blast");
        address governor = IAddressFinder(addressFinder).getImplementationAddress("Governor");
        IBlast(blast).configure(YieldMode.CLAIMABLE, GasMode.CLAIMABLE, governor);
    }
}

File 20 of 57 : BlastPoints.sol
// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

import {IBlastPoints} from "./interfaces/IBlastPoints.sol";
import {IAddressFinder} from "./interfaces/IAddressFinder.sol";

/**
 * @title BlastPoints
 * @notice This contract is a base for future contracts that wish to be recipients of Blast points to inherit from
 */
contract BlastPoints {
    /**
     * @param addressFinder Blast address finder
     */
    constructor(address addressFinder) {
        address blastPoints = IAddressFinder(addressFinder).getImplementationAddress("BlastPoints");
        address blastPointsOperator = IAddressFinder(addressFinder).getImplementationAddress("BlastPointsOperator");
        IBlastPoints(blastPoints).configurePointsOperator(blastPointsOperator);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/**
 * @title Provides addresses of the live contracts implementing certain interfaces.
 * @dev Examples are the Oracle or Store interfaces.
 * @notice This is a straight fork of UMA's Finder contract and we are using it for non-contracts as well.
 */
interface IAddressFinder {
    /**
     * @notice Updates the address of the contract that implements `interfaceName`.
     * @param interfaceName bytes32 encoding of the interface name that is either changed or registered.
     * @param implementationAddress address of the deployed contract that implements the interface.
     */
    function changeImplementationAddress(bytes32 interfaceName, address implementationAddress) external;

    /**
     * @notice Gets the address of the contract that implements the given `interfaceName`.
     * @param interfaceName queried interface.
     * @return implementationAddress address of the deployed contract that implements the interface.
     */
    function getImplementationAddress(bytes32 interfaceName) external view returns (address);
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

enum YieldMode {
    AUTOMATIC,
    VOID,
    CLAIMABLE
}

enum GasMode {
    VOID,
    CLAIMABLE
}

interface IBlast {
    // configure
    function configureContract(address contractAddress, YieldMode _yield, GasMode gasMode, address governor) external;

    function configure(YieldMode _yield, GasMode gasMode, address governor) external;

    // base configuration options
    function configureClaimableYield() external;

    function configureClaimableYieldOnBehalf(address contractAddress) external;

    function configureAutomaticYield() external;

    function configureAutomaticYieldOnBehalf(address contractAddress) external;

    function configureVoidYield() external;

    function configureVoidYieldOnBehalf(address contractAddress) external;

    function configureClaimableGas() external;

    function configureClaimableGasOnBehalf(address contractAddress) external;

    function configureVoidGas() external;

    function configureVoidGasOnBehalf(address contractAddress) external;

    function configureGovernor(address _governor) external;

    function configureGovernorOnBehalf(address _newGovernor, address contractAddress) external;

    // claim yield
    function claimYield(address contractAddress, address recipientOfYield, uint256 amount) external returns (uint256);

    function claimAllYield(address contractAddress, address recipientOfYield) external returns (uint256);

    // claim gas
    function claimAllGas(address contractAddress, address recipientOfGas) external returns (uint256);

    function claimGasAtMinClaimRate(
        address contractAddress,
        address recipientOfGas,
        uint256 minClaimRateBips
    ) external returns (uint256);

    function claimMaxGas(address contractAddress, address recipientOfGas) external returns (uint256);

    function claimGas(
        address contractAddress,
        address recipientOfGas,
        uint256 gasToClaim,
        uint256 gasSecondsToConsume
    ) external returns (uint256);

    // read functions
    function readClaimableYield(address contractAddress) external view returns (uint256);

    function readYieldConfiguration(address contractAddress) external view returns (uint8);

    function readGasParams(
        address contractAddress
    ) external view returns (uint256 etherSeconds, uint256 etherBalance, uint256 lastUpdated, GasMode);
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

interface IBlastPoints {
    function configurePointsOperator(address operator) external;
}

File 24 of 57 : BaseExchange.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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

abstract contract BaseExchange is ERC1155Holder, ReentrancyGuard {}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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
contract CTFExchange is
    BaseExchange,
    Auth,
    Assets,
    Fees,
    Pausable,
    AssetOperations,
    Hashing("predict.fun 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);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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

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

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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 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(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);
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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 31 of 57 : IHashing.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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

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

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

abstract contract INonceManager {
    event NonceIncremented(address indexed user, uint256 newNonce);

    function incrementNonce() external virtual;

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

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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 {}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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 38 of 57 : OrderStructs.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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;
}

/// @notice: Although signature type 0 says EOA, we have modified the code slightly to enable EIP-1271 for smart contract wallets.
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;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/// @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;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/// @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)));
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import {SafeTransferLib, ERC20} from "solmate/src/utils/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, "");
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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
        );
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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 45 of 57 : Fees.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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 46 of 57 : Hashing.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {EIP712} from "@openzeppelin/contracts/utils/cryptography/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
                    )
                )
            );
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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 {
        uint256 newNonce = nonces[msg.sender] + val;
        nonces[msg.sender] = newNonce;
        emit NonceIncremented(msg.sender, newNonce);
    }

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

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.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 view 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 view returns (bool) {
        return SignatureChecker.isValidSignatureNow(signer, structHash, signature);
    }

    /// @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;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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;
    }
}

File 53 of 57 : ReentrancyGuard.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.24;

/// @notice Forked from Solmate to handle clones.
/// @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 54 of 57 : NegRiskCtfExchange.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {CTFExchange} from "../Exchange/CTFExchange.sol";
import {IConditionalTokens} from "../UMA/interfaces/IConditionalTokens.sol";

/// @title NegRiskCtfExchange
/// @notice A slightly modified version of CTFExchange
/// @notice with added approvals for the NegRiskAdapter
contract NegRiskCtfExchange is CTFExchange {
    constructor(
        address _collateral,
        address _ctf,
        address _negRiskAdapter,
        address _proxyFactory,
        address _safeFactory
    ) CTFExchange(_collateral, _negRiskAdapter, _proxyFactory, _safeFactory) {
        IConditionalTokens(_ctf).setApprovalForAll(_negRiskAdapter, true);
        IConditionalTokens(_ctf).setApprovalForAll(address(this), true);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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

interface IConditionalTokens is IERC1155 {
    /// Mapping key is an condition ID. Value represents numerators of the payout vector associated with the condition. This array is initialized with a length equal to the outcome slot count. E.g. Condition with 3 outcomes [A, B, C] and two of those correct [0.5, 0.5, 0]. In Ethereum there are no decimal values, so here, 0.5 is represented by fractions like 1/2 == 0.5. That's why we need numerator and denominator values. Payout numerators are also used as a check of initialization. If the numerators array is empty (has length zero), the condition was not created/prepared. See getOutcomeSlotCount.
    function payoutNumerators(bytes32) external returns (uint256[] memory);

    /// Denominator is also used for checking if the condition has been resolved. If the denominator is non-zero, then the condition has been resolved.
    function payoutDenominator(bytes32) external returns (uint256);

    /// @dev This function prepares a condition by initializing a payout vector associated with the 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(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;

    function mergePositions(
        IERC20 collateralToken,
        bytes32 parentCollectionId,
        bytes32 conditionId,
        uint256[] calldata partition,
        uint256 amount
    ) external;

    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);
}

// 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);
    }
}

// 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;

        /// @solidity memory-safe-assembly
        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;

        /// @solidity memory-safe-assembly
        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), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
            mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
            mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.

            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;

        /// @solidity memory-safe-assembly
        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), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.

            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;

        /// @solidity memory-safe-assembly
        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), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.

            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");
    }
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"_collateral","type":"address"},{"internalType":"address","name":"_ctf","type":"address"},{"internalType":"address","name":"_negRiskAdapter","type":"address"},{"internalType":"address","name":"_proxyFactory","type":"address"},{"internalType":"address","name":"_safeFactory","type":"address"},{"internalType":"address","name":"_addressFinder","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":"InvalidShortString","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":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"inputs":[],"name":"TooLittleTokensReceived","type":"error"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"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":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"newNonce","type":"uint256"}],"name":"NonceIncremented","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":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","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"},{"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"}]

6101c08060405234620006915760009060c0816200407c8038038091620000278285620006dc565b83398101031262000625576200003d8162000700565b916200004c6020830162000700565b6200005a6040840162000700565b620000686060850162000700565b916200008560a06200007d6080880162000700565b960162000700565b92604051956200009587620006c0565b601887528560208089017f707265646963742e66756e204354462045786368616e676500000000000000008152604051620000d081620006c0565b6001815282810191603160f81b83526001855533855260018452600160408620556002845260016040862055620001078c6200074f565b9b6101209c8d52620001198362000929565b6101405251902060e052519020996101009a8b524660a0526200013b62000af4565b6080523060c05261016081905261018087905260405163095ea7b360e01b81526001600160a01b038089166004830152600019602483015290938492604492849291165af1801562000686576200063f575b5060ff1960055416600555620001a262000715565b6101a052600880546001600160a01b03199081166001600160a01b0394851617909155600980549091169183169190911790551690813b15620005485760405163a22cb46560e01b8082526001600160a01b03909216600482015260016024820152848160448183875af18015620005c05762000629575b50813b15620005485783916044839260405194859384928352306004840152600160248401525af1801562000500579083916200060d575b50506040516302abf57960e61b8082526a426c617374506f696e747360a81b60048301526001600160a01b03929092169190602081602481865afa90811562000555578491620005cb575b50604051908282527f426c617374506f696e74734f70657261746f72000000000000000000000000006004830152602082602481875afa918215620005c05785926200057c575b506001600160a01b031690813b1562000578576040516336b91f2b60e01b81526001600160a01b0390911660048201529084908290602490829084905af18015620005555790849162000560575b50506040519080825264109b185cdd60da1b6004830152602082602481865afa918215620005555784926200050b575b5060209060246040518095819382526723b7bb32b93737b960c11b60048301525afa91821562000500578392620004bc575b506001600160a01b031690813b15620004b85760405163c8992e6160e01b815260026004820152600160248201526001600160a01b0390911660448201529082908290606490829084905af18015620004ad5762000492575b50506040519061351b928362000b6184396080518361265f015260a0518361271a015260c05183612629015260e051836126ae015251826126d401525181610f0701526101405181610f330152610160518181816108ca0152818161284801528181612c9c015281816132a001526134ab01526101805181818161063201528181612c1b01528181612d320152818161325b015261346501526101a051816117530152f35b6200049e829162000696565b620004aa5780620003ed565b80fd5b6040513d84823e3d90fd5b8280fd5b9091506020813d602011620004f7575b81620004db60209383620006dc565b81010312620004b857620004ef9062000700565b903862000394565b3d9150620004cc565b6040513d85823e3d90fd5b9091506020813d6020116200054c575b816200052a60209383620006dc565b8101031262000548576200054060209162000700565b919062000362565b8380fd5b3d91506200051b565b6040513d86823e3d90fd5b6200056b9062000696565b620004b857823862000332565b8480fd5b9091506020813d602011620005b7575b816200059b60209383620006dc565b810103126200057857620005af9062000700565b9038620002e4565b3d91506200058c565b6040513d87823e3d90fd5b90506020813d60201162000604575b81620005e960209383620006dc565b810103126200054857620005fd9062000700565b386200029d565b3d9150620005da565b620006189062000696565b6200062557813862000252565b5080fd5b620006379094919462000696565b92386200021a565b6020813d6020116200067d575b816200065b60209383620006dc565b81010312620006795751801515036200067557386200018d565b8580fd5b8680fd5b3d91506200064c565b6040513d89823e3d90fd5b600080fd5b6001600160401b038111620006aa57604052565b634e487b7160e01b600052604160045260246000fd5b604081019081106001600160401b03821117620006aa57604052565b601f909101601f19168101906001600160401b03821190821017620006aa57604052565b51906001600160a01b03821682036200069157565b60c0516001600160a01b031630148062000743575b15620007365760805190565b6200074062000af4565b90565b5060a05146146200072a565b80516020919082811015620007ee575090601f8251116200078d57808251920151908083106200077e57501790565b82600019910360031b1b161790565b90604051809263305a27a960e01b82528060048301528251908160248401526000935b828510620007d4575050604492506000838284010152601f80199101168101030190fd5b8481018201518686016044015293810193859350620007b0565b6001600160401b038111620006aa576003928354926001938481811c911680156200091e575b838210146200090857601f8111620008cf575b5081601f84116001146200086657509282939183926000946200085a575b50501b9160001990841b1c191617905560ff90565b01519250388062000845565b919083601f1981168760005284600020946000905b88838310620008b457505050106200089b575b505050811b01905560ff90565b015160001983861b60f8161c191690553880806200088e565b8587015188559096019594850194879350908101906200087b565b8560005284601f84600020920160051c820191601f860160051c015b828110620008fb57505062000827565b60008155018590620008eb565b634e487b7160e01b600052602260045260246000fd5b90607f169062000814565b80516020919082811015620009b9575090601f8251116200095857808251920151908083106200077e57501790565b90604051809263305a27a960e01b82528060048301528251908160248401526000935b8285106200099f575050604492506000838284010152601f80199101168101030190fd5b84810182015186860160440152938101938593506200097b565b6001600160401b038111620006aa576004928354926001938481811c9116801562000ae9575b8382101462000ad457601f811162000a9b575b5081601f841160011462000a32575092829391839260009462000a26575b50501b916000199060031b1c191617905560ff90565b01519250388062000a10565b919083601f1981168760005284600020946000905b8883831062000a80575050501062000a6657505050811b01905560ff90565b015160001960f88460031b161c191690553880806200088e565b85870151885590960195948501948793509081019062000a47565b8560005284601f84600020920160051c820191601f860160051c015b82811062000ac7575050620009f2565b6000815501859062000ab7565b602286634e487b7160e01b6000525260246000fd5b90607f1690620009df565b60e051610100516040519060208201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8452604083015260608201524660808201523060a082015260a0815260c0810181811060018060401b03821117620006aa576040525190209056fe6080604052600436101561001257600080fd5b60003560e01c806301ffc9a71461033d5780630647ee201461033857806306b9d691146103335780631031e36e1461032e578063131e7e1c146102c057806313e7c9d8146103295780631785f53c1461032457806324d7806c1461031f5780632dff692d1461031a57806334600901146103155780633b521d78146103105780633d6d35981461030b578063429b62e51461030657806344bea37e146103015780634544f055146102fc578063456068d2146102f757806346423aa7146102f25780634a2a11f5146102ed5780635893253c146102e85780635c1548fb146102e35780635c975abb146102de578063627cdcb9146102d9578063654f0ce4146102d457806368c7450f146102cf5780636d70f7ae146102ca57806370480275146102c557806375d7370a146102c05780637ecebe00146102bb57806383b8a5ae146102b657806384b0196e146102b15780639870d7fe146102ac578063a10f3dce146102a7578063a287bdf1146102a2578063a6dfcf861461029d578063ac8a584a14610298578063b28c51c01461028e578063bc197c8114610293578063c10f1a751461028e578063d798eff614610289578063d7fb272f14610284578063d82da8381461027f578063e03ac3d01461027a578063e2eec40514610275578063e50e4f9714610270578063e60f0c051461026b578063edef7d8e14610266578063f23a6e6114610261578063f698da251461025c578063fa950b4814610257578063fbddd751146102525763fe729aaf1461024d57600080fd5b61184c565b6117d0565b611776565b61173b565b6116e2565b6116bb565b61143e565b611426565b6113eb565b6113d0565b6113b1565b611382565b6112ad565b611102565b6111a2565b61108d565b611077565b611050565b61102a565b610fb4565b610eee565b610e15565b610dd8565b6104a9565b610d63565b610d23565b610be0565b610bc1565b61091c565b6108f9565b6108b4565b61087f565b610862565b6107fd565b6107a5565b610729565b61070d565b6106d0565b610661565b61061c565b6105fe565b6105c4565b610584565b61050f565b6104d2565b610439565b61040c565b6103b6565b346103935760203660031901126103935760043563ffffffff60e01b811680910361039357602090630271189760e51b8114908115610382575b506040519015158152f35b6301ffc9a760e01b14905038610377565b600080fd5b6001600160a01b0381160361039357565b35906103b482610398565b565b346103935760403660031901126103935760206103f76004356103d881610398565b6001600160a01b03166000908152600660205260409020546024351490565b6040519015158152f35b600091031261039357565b346103935760003660031901126103935760206104276118e9565b6040516001600160a01b039091168152f35b34610393576000806003193601126104a6573381526001602052600160408220540361049457600160ff196005541617600555337f203c4bd3e526634f661575359ff30de3b0edaba6c2cb1eac60f730b6d2d9d5368280a280f35b604051637bfa4b9f60e01b8152600490fd5b80fd5b34610393576000366003190112610393576009546040516001600160a01b039091168152602090f35b34610393576020366003190112610393576004356104ef81610398565b60018060a01b031660005260026020526020604060002054604051908152f35b346103935760203660031901126103935760043561052c81610398565b60009033825260016020526001604083205403610494576001600160a01b031680825260016020526040822082905533907f787a2e12f4a55b658b8f573c32432ee11a5e8b51677d1e1e937aaf6a0bb5776e8380a380f35b34610393576020366003190112610393576004356105a181610398565b60018060a01b031660005260016020526020600160406000205414604051908152f35b3461039357602036600319011261039357600435600052600a602052604080600020600160ff825416910154825191151582526020820152f35b346103935760203660031901126103935761061a60043561194f565b005b34610393576000366003190112610393576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610393576000806003193601126104a657338152600260205260016040822054036106be57338152600260205280604081205533337ff7262ed0443cc211121ceb1a80d69004f319245615a7488f951f1437fd91642c8380a380f35b604051631f0853c160e21b8152600490fd5b34610393576020366003190112610393576004356106ed81610398565b60018060a01b031660005260016020526020604060002054604051908152f35b3461039357600036600319011261039357602060405160008152f35b346103935760203660031901126103935760043561074681610398565b60009033825260016020526001604083205403610494576009546001600160a01b0391821691829082167f9726d7faf7429d6b059560dc858ed769377ccdf8b7541eabe12b22548719831f8580a36001600160a01b0319161760095580f35b34610393576000806003193601126104a657338152600160205260016040822054036104945760ff1960055416600555337fa1e8a54850dbd7f520bcc09f47bff152294b77b2081da545a7adf531b7ea283b8280a280f35b34610393576020366003190112610393576000602060405161081e8161099e565b8281520152600435600052600a602052604080600020815161083f8161099e565b6020600160ff845416151593848452015491019081528251918252516020820152f35b346103935760003660031901126103935760206040516103e88152f35b346103935760203660031901126103935760043560005260076020526040806000206001815491015482519182526020820152f35b34610393576000366003190112610393576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461039357600036600319011261039357602060ff600554166040519015158152f35b34610393576000806003193601126104a65733815260066020526040812054600181018091116109835733825260066020528060408320556040519081527fa82a649bbd060c9099cd7b7326e2b0dc9e9af0836480e0f849dc9eaa79710b3b60203392a280f35b612086565b634e487b7160e01b600052604160045260246000fd5b604081019081106001600160401b038211176109b957604052565b610988565b6001600160401b0381116109b957604052565b6101a081019081106001600160401b038211176109b957604052565b60c081019081106001600160401b038211176109b957604052565b90601f801991011681019081106001600160401b038211176109b957604052565b604051906103b4826109d1565b604051906103b48261099e565b3590600282101561039357565b3590600382101561039357565b6001600160401b0381116109b957601f01601f191660200190565b81601f8201121561039357803590610a8f82610a5d565b92610a9d6040519485610a08565b8284526020838301011161039357816000926020809301838601378301015290565b91906101a08382031261039357610ad4610a29565b9280358452610ae5602082016103a9565b6020850152610af6604082016103a9565b6040850152610b07606082016103a9565b60608501526080810135608085015260a081013560a085015260c081013560c085015260e081013560e085015261010080820135908501526101208082013590850152610140610b58818301610a43565b90850152610160610b6a818301610a50565b9085015261018091828201356001600160401b03811161039357610b8e9201610a78565b90830152565b602060031982011261039357600435906001600160401b03821161039357610bbe91600401610abf565b90565b346103935761061a610bd236610b94565b610bdb81611e13565b61209c565b3461039357606036600319011261039357600435602435906044359060009233845260016020526001604085205403610494578082148015610d13575b610d0157610c35826000526007602052604060002090565b5415801590610ce4575b610cd257610c7c610c4e610a36565b828152846020820152610c6b846000526007602052604060002090565b906020600191805184550151910155565b610ca4610c87610a36565b838152846020820152610c6b836000526007602052604060002090565b7fbc9a2432e8aeb48327246cddd6e872ef452812b4243c04e6bfb786a2cd8faf0d838284838880a48480a480f35b604051630ea075bf60e21b8152600490fd5b50610cf9816000526007602052604060002090565b541515610c3f565b6040516307ed98ed60e31b8152600490fd5b50811580610c1d57508015610c1d565b3461039357602036600319011261039357600435610d4081610398565b60018060a01b031660005260026020526020600160406000205414604051908152f35b3461039357602036600319011261039357600435610d8081610398565b60009033825260016020526001604083205403610494576001600160a01b031680825260016020819052604083205533907ff9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dc8380a380f35b3461039357602036600319011261039357600435610df581610398565b60018060a01b031660005260066020526020604060002054604051908152f35b34610393576000806003193601126104a6573381526001602052600160408220540361049457338152600160205280604081205533337f787a2e12f4a55b658b8f573c32432ee11a5e8b51677d1e1e937aaf6a0bb5776e8380a380f35b60005b838110610e855750506000910152565b8181015183820152602001610e75565b90602091610eae81518092818552858086019101610e72565b601f01601f1916010190565b90815180825260208080930193019160005b828110610eda575050505090565b835185529381019392810192600101610ecc565b3461039357600036600319011261039357610f81610f2b7f00000000000000000000000000000000000000000000000000000000000000006123dd565b610fb0610f577f00000000000000000000000000000000000000000000000000000000000000006124e2565b610f8f610f62611964565b91604051958695600f60f81b875260e0602088015260e0870190610e95565b908582036040870152610e95565b90466060850152306080850152600060a085015283820360c0850152610eba565b0390f35b3461039357602036600319011261039357600435610fd181610398565b60009033825260016020526001604083205403610494576001600160a01b03168082526002602052604082206001905533907ff1e04d73c4304b5ff164f9d10c7473e2a1593b740674a6107975e2a7001c1e5c8380a380f35b346103935760203660031901126103935760206110486004356119b8565b604051908152f35b3461039357602036600319011261039357602061042760043561107281610398565b6119d2565b346103935761061a61108836610b94565b612177565b34610393576020366003190112610393576004356110aa81610398565b60009033825260016020526001604083205403610494576001600160a01b031680825260026020526040822082905533907ff7262ed0443cc211121ceb1a80d69004f319245615a7488f951f1437fd91642c8380a380f35b34610393576000366003190112610393576008546040516001600160a01b039091168152602090f35b6001600160401b0381116109b95760051b60200190565b9080601f8301121561039357602090823561115c8161112b565b9361116a6040519586610a08565b81855260208086019260051b82010192831161039357602001905b828210611193575050505090565b81358152908301908301611185565b346103935760a0366003190112610393576111be600435610398565b6111c9602435610398565b6001600160401b03604435818111610393576111e9903690600401611142565b5060643581811161039357611202903690600401611142565b506084359081116103935761121b903690600401610a78565b5060405163bc197c8160e01b8152602090f35b81601f82011215610393578035916020916112488461112b565b936112566040519586610a08565b808552838086019160051b8301019280841161039357848301915b8483106112815750505050505090565b82356001600160401b0381116103935786916112a284848094890101610abf565b815201920191611271565b34610393576040366003190112610393576001600160401b03600435818111610393576112de90369060040161122e565b90602435908111610393576112f7903690600401611142565b600091611308600284541415611c5b565b60028355338352600260205260019160016040852054036106be5760ff6005541661137057815191845b83811061134757856113446001600055565b80f35b8061136a611356879385612072565b5133906113638488612072565b51906122d9565b01611332565b6040516313d0ff5960e31b8152600490fd5b346103935760203660031901126103935760043560005260076020526020600160406000200154604051908152f35b346103935760403660031901126103935761061a602435600435611c94565b34610393576000366003190112610393576020610427611cb6565b34610393576040366003190112610393576024356001600160401b0381116103935761141e61061a913690600401610abf565b600435611d13565b3461039357602061104861143936610b94565b611e13565b346103935760803660031901126103935760046001600160401b0381358181116103935761146f9036908401610abf565b9060243581811161039357611487903690850161122e565b9160443591606435908111610393576114a39036908601611142565b6000936114b4600286541415611c5b565b60028555338552600260205260016040862054036116aa5760ff6005541661169957839495506114e48484612740565b9490926114f08561280d565b60208701805191969295909387926001600160a01b031686883061151393612834565b61151d9189612908565b61152691612a56565b91829161012087015196610140019085825161154181611d61565b61154a81611d61565b7f63bf4d16b7fa898ef4c4b2b6d90fd201e9c56313b65638af6088d149d2ce956c99611667976116439661163796611593946116925782905b519361158e85611d61565b612aaf565b82516115b4906001600160a01b03168a6115ad848a6122cc565b9130612834565b6115c0818a3330612b7e565b6115c982612beb565b80611674575b50825160408051938452602084018b905283018d905260608301879052608083019190915230916001600160a01b03909116908b907fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69060a090a4516001600160a01b031690565b6001600160a01b031690565b96604051948594859094939260609260808301968352602083015260408201520152565b0390a36113446001600055565b835161168c919084906001600160a01b031630612834565b386115cf565b8190611583565b6040516313d0ff5960e31b81528690fd5b604051631f0853c160e21b81528690fd5b346103935760203660031901126103935760206104276004356116dd81610398565b611ebe565b346103935760a0366003190112610393576116fe600435610398565b611709602435610398565b6084356001600160401b03811161039357611728903690600401610a78565b5060405163f23a6e6160e01b8152602090f35b346103935760003660031901126103935760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b34610393576020366003190112610393576004356001600160401b038111610393576117a690369060040161122e565b805160005b8181106117b457005b806117ca6117c460019386612072565b51612177565b016117ab565b34610393576020366003190112610393576004356117ed81610398565b60009033825260016020526001604083205403610494576008546001600160a01b0391821691829082167f3053c6252a932554235c173caffc1913604dba3a41cee89516f631c4a1a50a378580a36001600160a01b0319161760085580f35b34610393576040366003190112610393576004356001600160401b0381116103935761187c903690600401610abf565b60009061188d600283541415611c5b565b60028255338252600260205260016040832054036106be5760ff60055416611370576118be903390602435906122d9565b6113446001600055565b908160209103126103935751610bbe81610398565b6040513d6000823e3d90fd5b60085460405163557887a160e11b815290602090829060049082906001600160a01b03165afa90811561194a57600091611921575090565b610bbe915060203d602011611943575b61193b8183610a08565b8101906118c8565b503d611931565b6118dd565b600052600760205260406000205415610d0157565b604051602081018181106001600160401b038211176109b95760405260008152906000368137565b60405190606082018281106001600160401b038211176109b95760405260028252604082602036910137565b6119c18161194f565b600052600760205260406000205490565b610bbe90611be56119e1611cb6565b9160018060a01b036009541692611c13611c1f60405192611a01846109d1565b61017184527f608060405234801561001057600080fd5b50604051610171380380610171833960208501527f8101604081905261002f916100b9565b6001600160a01b03811661009457604060408501527f5162461bcd60e51b815260206004820152602260248201527f496e76616c696460608501527f2073696e676c65746f6e20616464726573732070726f7669646044820152611960808501527f5960f21b606482015260840160405180910390fd5b600080546001600160a01b60a08501527f0319166001600160a01b03929092169190911790556100e7565b60006020828460c08501527f0312156100ca578081fd5b81516001600160a01b03811681146100e0578182fd60e08501527f5b9392505050565b607c806100f56000396000f3fe60806040526000805460016101008501527f600160a01b0316813563530ca43760e11b1415602857808252602082f35b36826101208501527f833781823684845af490503d82833e806041573d82fd5b503d81f3fea26469706101408501527f66735822122015938e3bf2c49f5df5c1b7f9569fa85cc5d6f3074bb258a2dc0c610160850152707e299bc9e33664736f6c6343000804003360781b61018085015260405195869160208301919091602081019260018060a01b03169052565b0394611bf9601f1996878101835282610a08565b604051928391611c0d6020840180976125b3565b906125b3565b03858101835282610a08565b519020604080516001600160a01b03909316602084019081529193919291611c5291839081015b03908101835282610a08565b519020916125ca565b15611c6257565b60405162461bcd60e51b815260206004820152600a6024820152695245454e5452414e435960b01b6044820152606490fd5b611c9d906119b8565b03611ca457565b60405163337c310560e11b8152600490fd5b60095460405163530ca43760e11b815290602090829060049082906001600160a01b03165afa90811561194a57600091611921575090565b634e487b7160e01b600052602160045260246000fd5b60031115611d0e57565b611cee565b611d489160018060a01b0391826040830151169260208301511661016061018084015193015193611d4385611d04565b6121ee565b15611d4f57565b604051638baa579f60e01b8152600490fd5b60021115611d0e57565b90611d7582611d04565b52565b9a98969492918b929d9c9a989694919d6101a084019e7fa852566c4e14d00869b6db0220888a9090a13eccdaea03713ff0a3d27bf9767c85526020850152600160a01b60019003938480931690604001521660608c01521660808a015260a089015260c088015260e08701526101008601526101208501526101408401526002811015611d0e576101608301526103b4916101800190611d6b565b805160208201519091906001600160a01b031660408201519092906001600160a01b031660608301519091906001600160a01b03169260808101519060a081015160c082015160e0830151610100840151916101208501519361014086015195611e7c87611d61565b610160015196611e8b88611d04565b6040519a8b9a60208c019d611ea09b8f611d78565b03601f1981018252611eb29082610a08565b519020610bbe90612290565b611637610bbe91611ecd6118e9565b9061203860085492604051611c46602091828101906bffffffffffffffffffffffff19809760601b16825260148152611f058161099e565b51902094611fe2611fee611f3d611f1a611964565b6040516352e831dd60e01b88820152602481018890529182916044830190610e95565b0396611f51601f1998898101845283610a08565b611f59612e30565b947f3d3d606380380380913d393d73bebebebebebebebebebebebebebebebebebebe888701528b60601b16602d8601527f5af4602a57600080fd5b602d8060366000396000f3363d3d373d3d3d363d73be604186015260601b60608501526e5af43d82803e903d91602b57fd5bf360881b6074850152604051928391611c0d88840180976125b3565b03868101835282610a08565b5190206040516001600160f81b031993810193845260609790971b6bffffffffffffffffffffffff1916600184015260158301959095526035820194909452939283906055860190565b5190206001600160a01b031690565b634e487b7160e01b600052603260045260246000fd5b80516001101561206d5760400190565b612047565b805182101561206d5760209160051b010190565b634e487b7160e01b600052601160045260246000fd5b60e0820151801515908161216d575b5061215b576120ba8282611d13565b6103e861012083015111612149576120ec6120f3916120dc608085015161194f565b600052600a602052604060002090565b5460ff1690565b61213757602081810151610100909201516001600160a01b039092166000908152600690915260409020540361212557565b604051633ab3447f60e11b8152600490fd5b604051633d9c5bb760e11b8152600490fd5b60405163cd4e616760e01b8152600490fd5b6040516362b439dd60e11b8152600490fd5b90504211386120ab565b60208101516001600160a01b031633036121dc5761219490611e13565b80600052600a6020526040600020805460ff81166121375760ff191660011790557f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d600080a2565b6040516330cd747160e01b8152600490fd5b936121f881611d04565b8061222b57506001600160a01b038481169116149283612219575b50505090565b6122239350612e5b565b388080612213565b8061223a600292959395611d04565b03612270576122499184612e5b565b918261225457505090565b61225f9192506119d2565b6001600160a01b0390811691161490565b61227a9184612e5b565b918261228557505090565b61225f919250611ebe565b60429061229b612626565b906040519161190160f01b8352600283015260228201522090565b90670de0b6b3a764000091820391821161098357565b9190820391821161098357565b916122e48284612740565b91909260206123286101208701516101408801805161230281611d61565b61230b81611d61565b6123d757875b60a08a01519060c08b015192519361158e85611d61565b6123318761280d565b929097019060018060a01b0380835116928289039089821161098357612396878c7fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69a6123866123a3968b6123d29b33612834565b84516001600160a01b0316612834565b516001600160a01b031690565b1696604051948594339a869192608093969594919660a084019784526020840152604083015260608201520152565b0390a4565b84612311565b60ff81146123ee57610bbe90612cd0565b5060405160006003549060018260011c92600181169182156124d8575b6020916020861084146124c4578587528694936020860193929181156124a55750600114612443575b505050610bbe92500382610a08565b92509361247260036000527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b90565b946000935b82851061248f57505050610bbe935001388080612434565b8654858501529586019587955093810193612477565b92505050610bbe9491925060ff19168252151560051b01388080612434565b634e487b7160e01b85526022600452602485fd5b93607f169361240b565b60ff81146124f357610bbe90612cd0565b5060405160006004549060018260011c92600181169182156125a9575b6020916020861084146124c4578587528694936020860193929181156124a5575060011461254757505050610bbe92500382610a08565b92509361257660046000527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b90565b946000935b82851061259357505050610bbe935001388080612434565b865485850152958601958795509381019361257b565b93607f1693612510565b906125c660209282815194859201610e72565b0190565b6040516001600160f81b03196020820190815260609290921b6bffffffffffffffffffffffff191660218201526035810193909352605580840192909252908252612616607583610a08565b905190206001600160a01b031690565b307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03161480612717575b15612681577f000000000000000000000000000000000000000000000000000000000000000090565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f000000000000000000000000000000000000000000000000000000000000000060408201527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a082015260a08152612711816109ed565b51902090565b507f00000000000000000000000000000000000000000000000000000000000000004614612658565b60608101519092906001600160a01b03168015159081612802575b506127f05761276983611e13565b91612774848461209c565b61278a60a085019460c086519101519083612d06565b9383600052600a60205260406000206001810191825480156000146127e8575051925b8381116127d6578084039380851161098357146127c8575055565b805460ff1916600117905555565b604051637166356b60e11b8152600490fd5b9050926127ad565b604051635211a07960e01b8152600490fd5b90503314153861275b565b610140810151906002821015611d0e576080911561282d57015190600090565b0151600091565b9291908115612846576103b493612d26565b7f0000000000000000000000000000000000000000000000000000000000000000939091506001600160a01b03908116903082036128895750506103b492612f5a565b806020956000958693606496604051966323b872dd60e01b885260048801521660248601526044850152165af13d15601f3d11600160005114161716156128cc57565b60405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606490fd5b9080519260009160005b85811061292157505050505050565b80856123966129d07fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f6612a0061295960019789612072565b51612a47612967888c612072565b51918c612a0f612977838b612fda565b9261298384828d613072565b61298d8682612740565b999093610120830151906101408401908151906129a982611d61565b6129b282611d61565b50612a5057855b60a08501519060c086015192519361158e85611d61565b9687946129dc8361280d565b99819d91928b6020809701948c8a6129fa885160018060a01b031690565b916130d6565b9a01516001600160a01b031690565b938b8060a01b039586604051978897169b1699869192608093969594919660a084019784526020840152604083015260608201520152565b0390a401612912565b886129b9565b90612a6090612beb565b908110612a6a5790565b6040516301be9b0160e71b8152600490fd5b8181029291811591840414171561098357565b8115612a99570490565b634e487b7160e01b600052601260045260246000fd5b9194939260009583612ac3575b5050505050565b612ace918591612db4565b91821593841580612b6c575b15612abc57909192939495506002811015611d0e57612b3e5790612b13612b1892612b0d612b07866122b6565b86612e1e565b90612a7c565b612a7c565b9161271080830292830414171561098357612b3291612a8f565b905b3880808080612abc565b69021e19e0c9bab24000009350612b1390612b0d84612b5f612b65966122b6565b90612e1e565b0490612b34565b50670de0b6b3a7640000841115612ada565b9092919282612b8e575b50505050565b82612bbe7facffcc86834d0f1a64b0d5a675798deed6ff0bcfc2231edd3480e7288dba7ff4948684604096612834565b825194855260208501526001600160a01b031692a238808080612b88565b90816020910312610393575190565b8015612c7857604051627eeac760e11b815230600482015260248101919091526020816044816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa90811561194a57600091612c4f575090565b610bbe915060203d602011612c71575b612c698183610a08565b810190612bdc565b503d612c5f565b506040516370a0823160e01b81523060048201526020816024816001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000165afa90811561194a57600091612c4f575090565b60ff811690601f8211612cf45760405191612cea8361099e565b8252602082015290565b604051632cd44ac360e21b8152600490fd5b8115612d1e57610bbe92612d1991612a7c565b612a8f565b505050600090565b90926001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811693909290843b156103935760009460c493869286604051998a988997637921219560e11b89521660048801521660248601526044850152606484015260a060848401528160a48401525af1801561194a57612dab5750565b6103b4906109be565b90916002811015611d0e5715612df4578015612ded57670de0b6b3a76400009182810292818404149015171561098357610bbe91612a8f565b5050600090565b908015612ded57670de0b6b3a76400009182810292818404149015171561098357610bbe91612a8f565b9080821015612e2b575090565b905090565b6040519060a082018281106001600160401b038211176109b957604052606382526080366020840137565b612e658383613122565b506004819592951015611d0e57159384612f44575b508315612e875750505090565b6000929350908291604051612ece81612ec06020820194630b135d3f60e11b998a87526024840152604060448401526064830190610e95565b03601f198101835282610a08565b51915afa903d15612f3d573d612ee381610a5d565b90612ef16040519283610a08565b81523d6000602083013e5b82612f2f575b82612f12575b5050388080612213565b612f2791925060208082518301019101612bdc565b143880612f08565b915060208251101591612f02565b6060612efc565b6001600160a01b03838116911614935038612e7a565b60405163a9059cbb60e01b81526001600160a01b03928316600482015260248101939093526020926000926044928491165af13d15601f3d1160016000511416171615612fa357565b60405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606490fd5b61014080910180516002811015611d0e57612ff481611d61565b1580613055575b61304d576001905161300c81611d61565b61301581611d61565b14918261302d575b505061302857600090565b600290565b60019250015161303c81611d61565b61304581611d61565b14388061301d565b505050600190565b508183015161306381611d61565b61306c81611d61565b15612ffb565b909161307e838361315e565b156130c45761308c81611d04565b6130b257608080910151910151036130a057565b60405163a0b9446560e01b8152600490fd5b6080908101519101516103b491611c94565b604051633fcd37a360e11b8152600490fd5b6130f39293828692989793986130ee8184308a612834565b6131bc565b836130fd83612beb565b10612a6a57828403938411610983576103b4938261311b9230612834565b3330612b7e565b81519190604183036131535761314c92506020820151906060604084015193015160001a906132f1565b9192909190565b505060009160029190565b60c08101511580156131b0575b6131a95761317881613375565b9161318281613375565b9161014080910151916002831015611d0e570151916002831015611d0e57610bbe93613399565b5050600190565b5060c08201511561316b565b929391936131c983611d04565b8215612abc576131d883611d04565b60018314613217575050806131ee600292611d04565b146131f7575050565b60016132106103b4936000526007602052604060002090565b0154613438565b925092505060009081526007602052600160408220015461323661198c565b9081511561206d576001602083015260026132508361205d565b526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081169190823b156132ed5784906132c9604051978896879586946372ce427560e01b86527f00000000000000000000000000000000000000000000000000000000000000001660048601613402565b03925af1801561194a576132da5750565b806132e76103b4926109be565b80610401565b8480fd5b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841161336957926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa1561194a5780516001600160a01b0381161561336057918190565b50809160019190565b50505060009160039190565b60a08101519061014060c0820151910151906002821015611d0e57610bbe92612db4565b9290916002811015611d0e57156133d4576133b381611d61565b156133cf57810180911161098357670de0b6b3a7640000101590565b101590565b6133e081939293611d61565b156133ea57101590565b90810180911161098357670de0b6b3a7640000111590565b9493926080926134339260018060a01b0316875260006020880152604087015260a0606087015260a0860190610eba565b930152565b61344061198c565b80511561206d576001602082015260026134598261205d565b526001600160a01b03917f0000000000000000000000000000000000000000000000000000000000000000831690813b1561039357600080946134d460405197889687958694639e7212ad60e01b86527f00000000000000000000000000000000000000000000000000000000000000001660048601613402565b03925af1801561194a57612dab575056fea26469706673582212202fe0f19b0d8cdb77684686fb18937c237ee22dc9b974daee8b32171fd58cc67964736f6c6343000818003300000000000000000000000043000000000000000000000000000000000000030000000000000000000000008f9c9f888a4268ab0e2dda03a291769479bac285000000000000000000000000c55687812285d05b74815ee2716d046faf61b00300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c31bb90ee75706911faf6b831699026e5eb6f24a

Deployed Bytecode

0x6080604052600436101561001257600080fd5b60003560e01c806301ffc9a71461033d5780630647ee201461033857806306b9d691146103335780631031e36e1461032e578063131e7e1c146102c057806313e7c9d8146103295780631785f53c1461032457806324d7806c1461031f5780632dff692d1461031a57806334600901146103155780633b521d78146103105780633d6d35981461030b578063429b62e51461030657806344bea37e146103015780634544f055146102fc578063456068d2146102f757806346423aa7146102f25780634a2a11f5146102ed5780635893253c146102e85780635c1548fb146102e35780635c975abb146102de578063627cdcb9146102d9578063654f0ce4146102d457806368c7450f146102cf5780636d70f7ae146102ca57806370480275146102c557806375d7370a146102c05780637ecebe00146102bb57806383b8a5ae146102b657806384b0196e146102b15780639870d7fe146102ac578063a10f3dce146102a7578063a287bdf1146102a2578063a6dfcf861461029d578063ac8a584a14610298578063b28c51c01461028e578063bc197c8114610293578063c10f1a751461028e578063d798eff614610289578063d7fb272f14610284578063d82da8381461027f578063e03ac3d01461027a578063e2eec40514610275578063e50e4f9714610270578063e60f0c051461026b578063edef7d8e14610266578063f23a6e6114610261578063f698da251461025c578063fa950b4814610257578063fbddd751146102525763fe729aaf1461024d57600080fd5b61184c565b6117d0565b611776565b61173b565b6116e2565b6116bb565b61143e565b611426565b6113eb565b6113d0565b6113b1565b611382565b6112ad565b611102565b6111a2565b61108d565b611077565b611050565b61102a565b610fb4565b610eee565b610e15565b610dd8565b6104a9565b610d63565b610d23565b610be0565b610bc1565b61091c565b6108f9565b6108b4565b61087f565b610862565b6107fd565b6107a5565b610729565b61070d565b6106d0565b610661565b61061c565b6105fe565b6105c4565b610584565b61050f565b6104d2565b610439565b61040c565b6103b6565b346103935760203660031901126103935760043563ffffffff60e01b811680910361039357602090630271189760e51b8114908115610382575b506040519015158152f35b6301ffc9a760e01b14905038610377565b600080fd5b6001600160a01b0381160361039357565b35906103b482610398565b565b346103935760403660031901126103935760206103f76004356103d881610398565b6001600160a01b03166000908152600660205260409020546024351490565b6040519015158152f35b600091031261039357565b346103935760003660031901126103935760206104276118e9565b6040516001600160a01b039091168152f35b34610393576000806003193601126104a6573381526001602052600160408220540361049457600160ff196005541617600555337f203c4bd3e526634f661575359ff30de3b0edaba6c2cb1eac60f730b6d2d9d5368280a280f35b604051637bfa4b9f60e01b8152600490fd5b80fd5b34610393576000366003190112610393576009546040516001600160a01b039091168152602090f35b34610393576020366003190112610393576004356104ef81610398565b60018060a01b031660005260026020526020604060002054604051908152f35b346103935760203660031901126103935760043561052c81610398565b60009033825260016020526001604083205403610494576001600160a01b031680825260016020526040822082905533907f787a2e12f4a55b658b8f573c32432ee11a5e8b51677d1e1e937aaf6a0bb5776e8380a380f35b34610393576020366003190112610393576004356105a181610398565b60018060a01b031660005260016020526020600160406000205414604051908152f35b3461039357602036600319011261039357600435600052600a602052604080600020600160ff825416910154825191151582526020820152f35b346103935760203660031901126103935761061a60043561194f565b005b34610393576000366003190112610393576040517f000000000000000000000000c55687812285d05b74815ee2716d046faf61b0036001600160a01b03168152602090f35b34610393576000806003193601126104a657338152600260205260016040822054036106be57338152600260205280604081205533337ff7262ed0443cc211121ceb1a80d69004f319245615a7488f951f1437fd91642c8380a380f35b604051631f0853c160e21b8152600490fd5b34610393576020366003190112610393576004356106ed81610398565b60018060a01b031660005260016020526020604060002054604051908152f35b3461039357600036600319011261039357602060405160008152f35b346103935760203660031901126103935760043561074681610398565b60009033825260016020526001604083205403610494576009546001600160a01b0391821691829082167f9726d7faf7429d6b059560dc858ed769377ccdf8b7541eabe12b22548719831f8580a36001600160a01b0319161760095580f35b34610393576000806003193601126104a657338152600160205260016040822054036104945760ff1960055416600555337fa1e8a54850dbd7f520bcc09f47bff152294b77b2081da545a7adf531b7ea283b8280a280f35b34610393576020366003190112610393576000602060405161081e8161099e565b8281520152600435600052600a602052604080600020815161083f8161099e565b6020600160ff845416151593848452015491019081528251918252516020820152f35b346103935760003660031901126103935760206040516103e88152f35b346103935760203660031901126103935760043560005260076020526040806000206001815491015482519182526020820152f35b34610393576000366003190112610393576040517f00000000000000000000000043000000000000000000000000000000000000036001600160a01b03168152602090f35b3461039357600036600319011261039357602060ff600554166040519015158152f35b34610393576000806003193601126104a65733815260066020526040812054600181018091116109835733825260066020528060408320556040519081527fa82a649bbd060c9099cd7b7326e2b0dc9e9af0836480e0f849dc9eaa79710b3b60203392a280f35b612086565b634e487b7160e01b600052604160045260246000fd5b604081019081106001600160401b038211176109b957604052565b610988565b6001600160401b0381116109b957604052565b6101a081019081106001600160401b038211176109b957604052565b60c081019081106001600160401b038211176109b957604052565b90601f801991011681019081106001600160401b038211176109b957604052565b604051906103b4826109d1565b604051906103b48261099e565b3590600282101561039357565b3590600382101561039357565b6001600160401b0381116109b957601f01601f191660200190565b81601f8201121561039357803590610a8f82610a5d565b92610a9d6040519485610a08565b8284526020838301011161039357816000926020809301838601378301015290565b91906101a08382031261039357610ad4610a29565b9280358452610ae5602082016103a9565b6020850152610af6604082016103a9565b6040850152610b07606082016103a9565b60608501526080810135608085015260a081013560a085015260c081013560c085015260e081013560e085015261010080820135908501526101208082013590850152610140610b58818301610a43565b90850152610160610b6a818301610a50565b9085015261018091828201356001600160401b03811161039357610b8e9201610a78565b90830152565b602060031982011261039357600435906001600160401b03821161039357610bbe91600401610abf565b90565b346103935761061a610bd236610b94565b610bdb81611e13565b61209c565b3461039357606036600319011261039357600435602435906044359060009233845260016020526001604085205403610494578082148015610d13575b610d0157610c35826000526007602052604060002090565b5415801590610ce4575b610cd257610c7c610c4e610a36565b828152846020820152610c6b846000526007602052604060002090565b906020600191805184550151910155565b610ca4610c87610a36565b838152846020820152610c6b836000526007602052604060002090565b7fbc9a2432e8aeb48327246cddd6e872ef452812b4243c04e6bfb786a2cd8faf0d838284838880a48480a480f35b604051630ea075bf60e21b8152600490fd5b50610cf9816000526007602052604060002090565b541515610c3f565b6040516307ed98ed60e31b8152600490fd5b50811580610c1d57508015610c1d565b3461039357602036600319011261039357600435610d4081610398565b60018060a01b031660005260026020526020600160406000205414604051908152f35b3461039357602036600319011261039357600435610d8081610398565b60009033825260016020526001604083205403610494576001600160a01b031680825260016020819052604083205533907ff9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dc8380a380f35b3461039357602036600319011261039357600435610df581610398565b60018060a01b031660005260066020526020604060002054604051908152f35b34610393576000806003193601126104a6573381526001602052600160408220540361049457338152600160205280604081205533337f787a2e12f4a55b658b8f573c32432ee11a5e8b51677d1e1e937aaf6a0bb5776e8380a380f35b60005b838110610e855750506000910152565b8181015183820152602001610e75565b90602091610eae81518092818552858086019101610e72565b601f01601f1916010190565b90815180825260208080930193019160005b828110610eda575050505090565b835185529381019392810192600101610ecc565b3461039357600036600319011261039357610f81610f2b7f707265646963742e66756e204354462045786368616e676500000000000000186123dd565b610fb0610f577f31000000000000000000000000000000000000000000000000000000000000016124e2565b610f8f610f62611964565b91604051958695600f60f81b875260e0602088015260e0870190610e95565b908582036040870152610e95565b90466060850152306080850152600060a085015283820360c0850152610eba565b0390f35b3461039357602036600319011261039357600435610fd181610398565b60009033825260016020526001604083205403610494576001600160a01b03168082526002602052604082206001905533907ff1e04d73c4304b5ff164f9d10c7473e2a1593b740674a6107975e2a7001c1e5c8380a380f35b346103935760203660031901126103935760206110486004356119b8565b604051908152f35b3461039357602036600319011261039357602061042760043561107281610398565b6119d2565b346103935761061a61108836610b94565b612177565b34610393576020366003190112610393576004356110aa81610398565b60009033825260016020526001604083205403610494576001600160a01b031680825260026020526040822082905533907ff7262ed0443cc211121ceb1a80d69004f319245615a7488f951f1437fd91642c8380a380f35b34610393576000366003190112610393576008546040516001600160a01b039091168152602090f35b6001600160401b0381116109b95760051b60200190565b9080601f8301121561039357602090823561115c8161112b565b9361116a6040519586610a08565b81855260208086019260051b82010192831161039357602001905b828210611193575050505090565b81358152908301908301611185565b346103935760a0366003190112610393576111be600435610398565b6111c9602435610398565b6001600160401b03604435818111610393576111e9903690600401611142565b5060643581811161039357611202903690600401611142565b506084359081116103935761121b903690600401610a78565b5060405163bc197c8160e01b8152602090f35b81601f82011215610393578035916020916112488461112b565b936112566040519586610a08565b808552838086019160051b8301019280841161039357848301915b8483106112815750505050505090565b82356001600160401b0381116103935786916112a284848094890101610abf565b815201920191611271565b34610393576040366003190112610393576001600160401b03600435818111610393576112de90369060040161122e565b90602435908111610393576112f7903690600401611142565b600091611308600284541415611c5b565b60028355338352600260205260019160016040852054036106be5760ff6005541661137057815191845b83811061134757856113446001600055565b80f35b8061136a611356879385612072565b5133906113638488612072565b51906122d9565b01611332565b6040516313d0ff5960e31b8152600490fd5b346103935760203660031901126103935760043560005260076020526020600160406000200154604051908152f35b346103935760403660031901126103935761061a602435600435611c94565b34610393576000366003190112610393576020610427611cb6565b34610393576040366003190112610393576024356001600160401b0381116103935761141e61061a913690600401610abf565b600435611d13565b3461039357602061104861143936610b94565b611e13565b346103935760803660031901126103935760046001600160401b0381358181116103935761146f9036908401610abf565b9060243581811161039357611487903690850161122e565b9160443591606435908111610393576114a39036908601611142565b6000936114b4600286541415611c5b565b60028555338552600260205260016040862054036116aa5760ff6005541661169957839495506114e48484612740565b9490926114f08561280d565b60208701805191969295909387926001600160a01b031686883061151393612834565b61151d9189612908565b61152691612a56565b91829161012087015196610140019085825161154181611d61565b61154a81611d61565b7f63bf4d16b7fa898ef4c4b2b6d90fd201e9c56313b65638af6088d149d2ce956c99611667976116439661163796611593946116925782905b519361158e85611d61565b612aaf565b82516115b4906001600160a01b03168a6115ad848a6122cc565b9130612834565b6115c0818a3330612b7e565b6115c982612beb565b80611674575b50825160408051938452602084018b905283018d905260608301879052608083019190915230916001600160a01b03909116908b907fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69060a090a4516001600160a01b031690565b6001600160a01b031690565b96604051948594859094939260609260808301968352602083015260408201520152565b0390a36113446001600055565b835161168c919084906001600160a01b031630612834565b386115cf565b8190611583565b6040516313d0ff5960e31b81528690fd5b604051631f0853c160e21b81528690fd5b346103935760203660031901126103935760206104276004356116dd81610398565b611ebe565b346103935760a0366003190112610393576116fe600435610398565b611709602435610398565b6084356001600160401b03811161039357611728903690600401610a78565b5060405163f23a6e6160e01b8152602090f35b346103935760003660031901126103935760206040517f335a6853ac8d3191bea95614eeafa3c9b1f2a72993ca26873a2b2d84c57187fa8152f35b34610393576020366003190112610393576004356001600160401b038111610393576117a690369060040161122e565b805160005b8181106117b457005b806117ca6117c460019386612072565b51612177565b016117ab565b34610393576020366003190112610393576004356117ed81610398565b60009033825260016020526001604083205403610494576008546001600160a01b0391821691829082167f3053c6252a932554235c173caffc1913604dba3a41cee89516f631c4a1a50a378580a36001600160a01b0319161760085580f35b34610393576040366003190112610393576004356001600160401b0381116103935761187c903690600401610abf565b60009061188d600283541415611c5b565b60028255338252600260205260016040832054036106be5760ff60055416611370576118be903390602435906122d9565b6113446001600055565b908160209103126103935751610bbe81610398565b6040513d6000823e3d90fd5b60085460405163557887a160e11b815290602090829060049082906001600160a01b03165afa90811561194a57600091611921575090565b610bbe915060203d602011611943575b61193b8183610a08565b8101906118c8565b503d611931565b6118dd565b600052600760205260406000205415610d0157565b604051602081018181106001600160401b038211176109b95760405260008152906000368137565b60405190606082018281106001600160401b038211176109b95760405260028252604082602036910137565b6119c18161194f565b600052600760205260406000205490565b610bbe90611be56119e1611cb6565b9160018060a01b036009541692611c13611c1f60405192611a01846109d1565b61017184527f608060405234801561001057600080fd5b50604051610171380380610171833960208501527f8101604081905261002f916100b9565b6001600160a01b03811661009457604060408501527f5162461bcd60e51b815260206004820152602260248201527f496e76616c696460608501527f2073696e676c65746f6e20616464726573732070726f7669646044820152611960808501527f5960f21b606482015260840160405180910390fd5b600080546001600160a01b60a08501527f0319166001600160a01b03929092169190911790556100e7565b60006020828460c08501527f0312156100ca578081fd5b81516001600160a01b03811681146100e0578182fd60e08501527f5b9392505050565b607c806100f56000396000f3fe60806040526000805460016101008501527f600160a01b0316813563530ca43760e11b1415602857808252602082f35b36826101208501527f833781823684845af490503d82833e806041573d82fd5b503d81f3fea26469706101408501527f66735822122015938e3bf2c49f5df5c1b7f9569fa85cc5d6f3074bb258a2dc0c610160850152707e299bc9e33664736f6c6343000804003360781b61018085015260405195869160208301919091602081019260018060a01b03169052565b0394611bf9601f1996878101835282610a08565b604051928391611c0d6020840180976125b3565b906125b3565b03858101835282610a08565b519020604080516001600160a01b03909316602084019081529193919291611c5291839081015b03908101835282610a08565b519020916125ca565b15611c6257565b60405162461bcd60e51b815260206004820152600a6024820152695245454e5452414e435960b01b6044820152606490fd5b611c9d906119b8565b03611ca457565b60405163337c310560e11b8152600490fd5b60095460405163530ca43760e11b815290602090829060049082906001600160a01b03165afa90811561194a57600091611921575090565b634e487b7160e01b600052602160045260246000fd5b60031115611d0e57565b611cee565b611d489160018060a01b0391826040830151169260208301511661016061018084015193015193611d4385611d04565b6121ee565b15611d4f57565b604051638baa579f60e01b8152600490fd5b60021115611d0e57565b90611d7582611d04565b52565b9a98969492918b929d9c9a989694919d6101a084019e7fa852566c4e14d00869b6db0220888a9090a13eccdaea03713ff0a3d27bf9767c85526020850152600160a01b60019003938480931690604001521660608c01521660808a015260a089015260c088015260e08701526101008601526101208501526101408401526002811015611d0e576101608301526103b4916101800190611d6b565b805160208201519091906001600160a01b031660408201519092906001600160a01b031660608301519091906001600160a01b03169260808101519060a081015160c082015160e0830151610100840151916101208501519361014086015195611e7c87611d61565b610160015196611e8b88611d04565b6040519a8b9a60208c019d611ea09b8f611d78565b03601f1981018252611eb29082610a08565b519020610bbe90612290565b611637610bbe91611ecd6118e9565b9061203860085492604051611c46602091828101906bffffffffffffffffffffffff19809760601b16825260148152611f058161099e565b51902094611fe2611fee611f3d611f1a611964565b6040516352e831dd60e01b88820152602481018890529182916044830190610e95565b0396611f51601f1998898101845283610a08565b611f59612e30565b947f3d3d606380380380913d393d73bebebebebebebebebebebebebebebebebebebe888701528b60601b16602d8601527f5af4602a57600080fd5b602d8060366000396000f3363d3d373d3d3d363d73be604186015260601b60608501526e5af43d82803e903d91602b57fd5bf360881b6074850152604051928391611c0d88840180976125b3565b03868101835282610a08565b5190206040516001600160f81b031993810193845260609790971b6bffffffffffffffffffffffff1916600184015260158301959095526035820194909452939283906055860190565b5190206001600160a01b031690565b634e487b7160e01b600052603260045260246000fd5b80516001101561206d5760400190565b612047565b805182101561206d5760209160051b010190565b634e487b7160e01b600052601160045260246000fd5b60e0820151801515908161216d575b5061215b576120ba8282611d13565b6103e861012083015111612149576120ec6120f3916120dc608085015161194f565b600052600a602052604060002090565b5460ff1690565b61213757602081810151610100909201516001600160a01b039092166000908152600690915260409020540361212557565b604051633ab3447f60e11b8152600490fd5b604051633d9c5bb760e11b8152600490fd5b60405163cd4e616760e01b8152600490fd5b6040516362b439dd60e11b8152600490fd5b90504211386120ab565b60208101516001600160a01b031633036121dc5761219490611e13565b80600052600a6020526040600020805460ff81166121375760ff191660011790557f5152abf959f6564662358c2e52b702259b78bac5ee7842a0f01937e670efcc7d600080a2565b6040516330cd747160e01b8152600490fd5b936121f881611d04565b8061222b57506001600160a01b038481169116149283612219575b50505090565b6122239350612e5b565b388080612213565b8061223a600292959395611d04565b03612270576122499184612e5b565b918261225457505090565b61225f9192506119d2565b6001600160a01b0390811691161490565b61227a9184612e5b565b918261228557505090565b61225f919250611ebe565b60429061229b612626565b906040519161190160f01b8352600283015260228201522090565b90670de0b6b3a764000091820391821161098357565b9190820391821161098357565b916122e48284612740565b91909260206123286101208701516101408801805161230281611d61565b61230b81611d61565b6123d757875b60a08a01519060c08b015192519361158e85611d61565b6123318761280d565b929097019060018060a01b0380835116928289039089821161098357612396878c7fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f69a6123866123a3968b6123d29b33612834565b84516001600160a01b0316612834565b516001600160a01b031690565b1696604051948594339a869192608093969594919660a084019784526020840152604083015260608201520152565b0390a4565b84612311565b60ff81146123ee57610bbe90612cd0565b5060405160006003549060018260011c92600181169182156124d8575b6020916020861084146124c4578587528694936020860193929181156124a55750600114612443575b505050610bbe92500382610a08565b92509361247260036000527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b90565b946000935b82851061248f57505050610bbe935001388080612434565b8654858501529586019587955093810193612477565b92505050610bbe9491925060ff19168252151560051b01388080612434565b634e487b7160e01b85526022600452602485fd5b93607f169361240b565b60ff81146124f357610bbe90612cd0565b5060405160006004549060018260011c92600181169182156125a9575b6020916020861084146124c4578587528694936020860193929181156124a5575060011461254757505050610bbe92500382610a08565b92509361257660046000527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b90565b946000935b82851061259357505050610bbe935001388080612434565b865485850152958601958795509381019361257b565b93607f1693612510565b906125c660209282815194859201610e72565b0190565b6040516001600160f81b03196020820190815260609290921b6bffffffffffffffffffffffff191660218201526035810193909352605580840192909252908252612616607583610a08565b905190206001600160a01b031690565b307f0000000000000000000000006a3796c21e733a3016bc0ba41edf763016247e726001600160a01b03161480612717575b15612681577f335a6853ac8d3191bea95614eeafa3c9b1f2a72993ca26873a2b2d84c57187fa90565b60405160208101907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82527f824eadb8873175abfbfdc1e76458964b2a39b5184e5ec9292fcff01abb3a7bcb60408201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260a08152612711816109ed565b51902090565b507f0000000000000000000000000000000000000000000000000000000000013e314614612658565b60608101519092906001600160a01b03168015159081612802575b506127f05761276983611e13565b91612774848461209c565b61278a60a085019460c086519101519083612d06565b9383600052600a60205260406000206001810191825480156000146127e8575051925b8381116127d6578084039380851161098357146127c8575055565b805460ff1916600117905555565b604051637166356b60e11b8152600490fd5b9050926127ad565b604051635211a07960e01b8152600490fd5b90503314153861275b565b610140810151906002821015611d0e576080911561282d57015190600090565b0151600091565b9291908115612846576103b493612d26565b7f0000000000000000000000004300000000000000000000000000000000000003939091506001600160a01b03908116903082036128895750506103b492612f5a565b806020956000958693606496604051966323b872dd60e01b885260048801521660248601526044850152165af13d15601f3d11600160005114161716156128cc57565b60405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606490fd5b9080519260009160005b85811061292157505050505050565b80856123966129d07fd0a08e8c493f9c94f29311604c9de1b4e8c8d4c06bd0c789af57f2d65bfec0f6612a0061295960019789612072565b51612a47612967888c612072565b51918c612a0f612977838b612fda565b9261298384828d613072565b61298d8682612740565b999093610120830151906101408401908151906129a982611d61565b6129b282611d61565b50612a5057855b60a08501519060c086015192519361158e85611d61565b9687946129dc8361280d565b99819d91928b6020809701948c8a6129fa885160018060a01b031690565b916130d6565b9a01516001600160a01b031690565b938b8060a01b039586604051978897169b1699869192608093969594919660a084019784526020840152604083015260608201520152565b0390a401612912565b886129b9565b90612a6090612beb565b908110612a6a5790565b6040516301be9b0160e71b8152600490fd5b8181029291811591840414171561098357565b8115612a99570490565b634e487b7160e01b600052601260045260246000fd5b9194939260009583612ac3575b5050505050565b612ace918591612db4565b91821593841580612b6c575b15612abc57909192939495506002811015611d0e57612b3e5790612b13612b1892612b0d612b07866122b6565b86612e1e565b90612a7c565b612a7c565b9161271080830292830414171561098357612b3291612a8f565b905b3880808080612abc565b69021e19e0c9bab24000009350612b1390612b0d84612b5f612b65966122b6565b90612e1e565b0490612b34565b50670de0b6b3a7640000841115612ada565b9092919282612b8e575b50505050565b82612bbe7facffcc86834d0f1a64b0d5a675798deed6ff0bcfc2231edd3480e7288dba7ff4948684604096612834565b825194855260208501526001600160a01b031692a238808080612b88565b90816020910312610393575190565b8015612c7857604051627eeac760e11b815230600482015260248101919091526020816044816001600160a01b037f000000000000000000000000c55687812285d05b74815ee2716d046faf61b003165afa90811561194a57600091612c4f575090565b610bbe915060203d602011612c71575b612c698183610a08565b810190612bdc565b503d612c5f565b506040516370a0823160e01b81523060048201526020816024816001600160a01b037f0000000000000000000000004300000000000000000000000000000000000003165afa90811561194a57600091612c4f575090565b60ff811690601f8211612cf45760405191612cea8361099e565b8252602082015290565b604051632cd44ac360e21b8152600490fd5b8115612d1e57610bbe92612d1991612a7c565b612a8f565b505050600090565b90926001600160a01b037f000000000000000000000000c55687812285d05b74815ee2716d046faf61b003811693909290843b156103935760009460c493869286604051998a988997637921219560e11b89521660048801521660248601526044850152606484015260a060848401528160a48401525af1801561194a57612dab5750565b6103b4906109be565b90916002811015611d0e5715612df4578015612ded57670de0b6b3a76400009182810292818404149015171561098357610bbe91612a8f565b5050600090565b908015612ded57670de0b6b3a76400009182810292818404149015171561098357610bbe91612a8f565b9080821015612e2b575090565b905090565b6040519060a082018281106001600160401b038211176109b957604052606382526080366020840137565b612e658383613122565b506004819592951015611d0e57159384612f44575b508315612e875750505090565b6000929350908291604051612ece81612ec06020820194630b135d3f60e11b998a87526024840152604060448401526064830190610e95565b03601f198101835282610a08565b51915afa903d15612f3d573d612ee381610a5d565b90612ef16040519283610a08565b81523d6000602083013e5b82612f2f575b82612f12575b5050388080612213565b612f2791925060208082518301019101612bdc565b143880612f08565b915060208251101591612f02565b6060612efc565b6001600160a01b03838116911614935038612e7a565b60405163a9059cbb60e01b81526001600160a01b03928316600482015260248101939093526020926000926044928491165af13d15601f3d1160016000511416171615612fa357565b60405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606490fd5b61014080910180516002811015611d0e57612ff481611d61565b1580613055575b61304d576001905161300c81611d61565b61301581611d61565b14918261302d575b505061302857600090565b600290565b60019250015161303c81611d61565b61304581611d61565b14388061301d565b505050600190565b508183015161306381611d61565b61306c81611d61565b15612ffb565b909161307e838361315e565b156130c45761308c81611d04565b6130b257608080910151910151036130a057565b60405163a0b9446560e01b8152600490fd5b6080908101519101516103b491611c94565b604051633fcd37a360e11b8152600490fd5b6130f39293828692989793986130ee8184308a612834565b6131bc565b836130fd83612beb565b10612a6a57828403938411610983576103b4938261311b9230612834565b3330612b7e565b81519190604183036131535761314c92506020820151906060604084015193015160001a906132f1565b9192909190565b505060009160029190565b60c08101511580156131b0575b6131a95761317881613375565b9161318281613375565b9161014080910151916002831015611d0e570151916002831015611d0e57610bbe93613399565b5050600190565b5060c08201511561316b565b929391936131c983611d04565b8215612abc576131d883611d04565b60018314613217575050806131ee600292611d04565b146131f7575050565b60016132106103b4936000526007602052604060002090565b0154613438565b925092505060009081526007602052600160408220015461323661198c565b9081511561206d576001602083015260026132508361205d565b526001600160a01b037f000000000000000000000000c55687812285d05b74815ee2716d046faf61b00381169190823b156132ed5784906132c9604051978896879586946372ce427560e01b86527f00000000000000000000000043000000000000000000000000000000000000031660048601613402565b03925af1801561194a576132da5750565b806132e76103b4926109be565b80610401565b8480fd5b91907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0841161336957926020929160ff608095604051948552168484015260408301526060820152600092839182805260015afa1561194a5780516001600160a01b0381161561336057918190565b50809160019190565b50505060009160039190565b60a08101519061014060c0820151910151906002821015611d0e57610bbe92612db4565b9290916002811015611d0e57156133d4576133b381611d61565b156133cf57810180911161098357670de0b6b3a7640000101590565b101590565b6133e081939293611d61565b156133ea57101590565b90810180911161098357670de0b6b3a7640000111590565b9493926080926134339260018060a01b0316875260006020880152604087015260a0606087015260a0860190610eba565b930152565b61344061198c565b80511561206d576001602082015260026134598261205d565b526001600160a01b03917f000000000000000000000000c55687812285d05b74815ee2716d046faf61b003831690813b1561039357600080946134d460405197889687958694639e7212ad60e01b86527f00000000000000000000000043000000000000000000000000000000000000031660048601613402565b03925af1801561194a57612dab575056fea26469706673582212202fe0f19b0d8cdb77684686fb18937c237ee22dc9b974daee8b32171fd58cc67964736f6c63430008180033

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

00000000000000000000000043000000000000000000000000000000000000030000000000000000000000008f9c9f888a4268ab0e2dda03a291769479bac285000000000000000000000000c55687812285d05b74815ee2716d046faf61b00300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c31bb90ee75706911faf6b831699026e5eb6f24a

-----Decoded View---------------
Arg [0] : _collateral (address): 0x4300000000000000000000000000000000000003
Arg [1] : _ctf (address): 0x8F9C9f888A4268Ab0E2DDa03A291769479bAc285
Arg [2] : _negRiskAdapter (address): 0xc55687812285D05b74815EE2716D046fAF61B003
Arg [3] : _proxyFactory (address): 0x0000000000000000000000000000000000000000
Arg [4] : _safeFactory (address): 0x0000000000000000000000000000000000000000
Arg [5] : _addressFinder (address): 0xc31BB90Ee75706911faf6b831699026e5eB6f24a

-----Encoded View---------------
6 Constructor Arguments found :
Arg [0] : 0000000000000000000000004300000000000000000000000000000000000003
Arg [1] : 0000000000000000000000008f9c9f888a4268ab0e2dda03a291769479bac285
Arg [2] : 000000000000000000000000c55687812285d05b74815ee2716d046faf61b003
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [5] : 000000000000000000000000c31bb90ee75706911faf6b831699026e5eb6f24a


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
Loading...
Loading
[ 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.