APE Price: $1.12 (-2.11%)

Contract

0x9A1D008994E8f69C66d99B743BDFc6990a7801aB

Overview

APE Balance

Apechain LogoApechain LogoApechain Logo0 APE

APE Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Latest 1 internal transaction

Parent Transaction Hash Block From To
46204852024-11-18 23:44:0715 hrs ago1731973447  Contract Creation0 APE

Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ModuleSweeps

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 40000 runs

Other Settings:
cancun EvmVersion, None license
File 1 of 29 : ModuleSweeps.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "./PaymentProcessorModuleAdvanced.sol";
import "@limitbreak/tm-core-lib/src/licenses/LicenseRef-PolyForm-Strict-1.0.0.sol";

/*
                                                     @@@@@@@@@@@@@@             
                                                    @@@@@@@@@@@@@@@@@@(         
                                                   @@@@@@@@@@@@@@@@@@@@@        
                                                  @@@@@@@@@@@@@@@@@@@@@@@@      
                                                           #@@@@@@@@@@@@@@      
                                                               @@@@@@@@@@@@     
                            @@@@@@@@@@@@@@*                    @@@@@@@@@@@@     
                           @@@@@@@@@@@@@@@     @               @@@@@@@@@@@@     
                          @@@@@@@@@@@@@@@     @                @@@@@@@@@@@      
                         @@@@@@@@@@@@@@@     @@               @@@@@@@@@@@@      
                        @@@@@@@@@@@@@@@     #@@             @@@@@@@@@@@@/       
                        @@@@@@@@@@@@@@.     @@@@@@@@@@@@@@@@@@@@@@@@@@@         
                       @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@            
                      @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@             
                     @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@           
                    @@@@@@@@@@@@@@@     @@@@@&%%%%%%%%&&@@@@@@@@@@@@@@          
                    @@@@@@@@@@@@@@      @@@@@               @@@@@@@@@@@         
                   @@@@@@@@@@@@@@@     @@@@@                 @@@@@@@@@@@        
                  @@@@@@@@@@@@@@@     @@@@@@                 @@@@@@@@@@@        
                 @@@@@@@@@@@@@@@     @@@@@@@                 @@@@@@@@@@@        
                @@@@@@@@@@@@@@@     @@@@@@@                 @@@@@@@@@@@&        
                @@@@@@@@@@@@@@     *@@@@@@@               (@@@@@@@@@@@@         
               @@@@@@@@@@@@@@@     @@@@@@@@             @@@@@@@@@@@@@@          
              @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@           
             @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@            
            @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@              
           .@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                 
           @@@@@@@@@@@@@@%     @@@@@@@@@@@@@@@@@@@@@@@@(                        
          @@@@@@@@@@@@@@@                                                       
         @@@@@@@@@@@@@@@                                                        
        @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                         
       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                          
       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&                                          
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                           
 
* @title ModuleSweeps
* @custom:version 3.0.0
* @author Limit Break, Inc.
*/ 

contract ModuleSweeps is PaymentProcessorModuleAdvanced {

    constructor(address configurationContract) PaymentProcessorModuleAdvanced(configurationContract){}

    /**
     * @notice Executes a sweep transaction for buying multiple items from the same collection.
     *
     * @dev    Throws when the sweep order protocol is ERC1155_PARTIAL_FILL (unsupported).
     * @dev    Throws when a maker's nonce has already been used or has been cancelled.
     * @dev    Throws when any order has expired.
     * @dev    Throws when any combined marketplace and royalty fee exceeds 100%.
     * @dev    Throws when the taker fee on top exceeds 100% of the combined item sale prices.
     * @dev    Throws when a maker's master nonce does not match the order details.
     * @dev    Throws when an order does not comply with the collection payment settings.
     * @dev    Throws when a maker's signature is invalid.
     * @dev    Throws when an order is a cosigned order and the cosignature is invalid.
     * @dev    Throws when the transaction originates from an untrusted channel if untrusted channels are blocked.
     * @dev    Throws when the taker does not have or did not send sufficient funds to complete the purchase.
     * @dev    Will NOT throw when a token fails to transfer but also will not disperse payments for failed items.
     * @dev    Any unused native token payment will be returned to the taker as wrapped native token.
     *
     * @dev    <h4>Postconditions:</h4>
     * @dev    1. Payment amounts and fees are sent to their respective recipients.
     * @dev    2. Purchased tokens are sent to the beneficiary.
     * @dev    3. Makers nonces are marked as used for ERC721_FILL_OR_KILL and ERC1155_FILL_OR_KILL orders.
     * @dev    4. Makers partially fillable order states are updated for ERC1155_PARTIAL_FILL orders.
     * @dev    5. `BuyListingERC721` events have been emitted for each ERC721 purchase.
     * @dev    6. `BuyListingERC1155` events have been emitted for each ERC1155 purchase.
     * @dev    7. A `NonceInvalidated` event has been emitted for each ERC721_FILL_OR_KILL or ERC1155_FILL_OR_KILL order.
     *
     * @param  feeOnTop         The additional fee to add on top of the orders, paid by taker.
     * @param  sweepOrder       The order information that is common to all items in the sweep.
     * @param  items            An array of items that contains the order information unique to each item.
     * @param  signedSellOrders An array of maker signatures authorizing the order execution.
     * @param  cosignatures     An array of additional cosignatures for cosigned orders, if applicable.
     */
    function sweepCollection(
        FeeOnTop calldata feeOnTop,
        SweepOrder calldata sweepOrder,
        SweepItem[] calldata items,
        SignatureECDSA[] calldata signedSellOrders,
        Cosignature[] calldata cosignatures
    ) public payable {
        uint256 appendedDataLength;
        unchecked {
            appendedDataLength = 
                msg.data.length - 
                BASE_MSG_LENGTH_SWEEP_COLLECTION - 
                (BASE_MSG_LENGTH_SWEEP_COLLECTION_PER_ITEM * items.length);
        }

        TradeContext memory context = TradeContext({
            channel: msg.sender,
            taker: _getTaker(appendedDataLength),
            disablePartialFill: false,
            orderDigest: bytes32(0),
            backfillNumerator: uint16(0),
            backfillReceiver: address(0),
            bountyNumerator: uint16(0),
            exclusiveMarketplace: address(0),
            useRoyaltyBackfillAsRoyaltySource: false,
            protocolFeeVersion: type(uint256).max,
            protocolFees: ProtocolFees({
                protocolFeeReceiver: address(0),
                minimumProtocolFeeBps: 0,
                marketplaceFeeProtocolTaxBps: 0,
                feeOnTopProtocolTaxBps: 0,
                versionExpiration: 0
            })
        });

        uint256 remainingNativeProceeds =_executeSweepOrder(
            context,
            msg.value,
            feeOnTop,
            sweepOrder,
            items,
            signedSellOrders,
            cosignatures
        );

        _refundUnspentNativeFunds(remainingNativeProceeds, context.taker);
    }

    /**
     * @notice Executes an advanced sweep transaction for buying multiple items from the same collection.
     *
     * @dev    Throws when the sweep order protocol is ERC1155_PARTIAL_FILL (unsupported).
     * @dev    Throws when a maker's nonce has already been used or has been cancelled.
     * @dev    Throws when any order has expired.
     * @dev    Throws when any combined marketplace and royalty fee exceeds 100%.
     * @dev    Throws when the taker fee on top exceeds 100% of the combined item sale prices.
     * @dev    Throws when a maker's master nonce does not match the order details.
     * @dev    Throws when an order does not comply with the collection payment settings.
     * @dev    Throws when a maker's signature is invalid.
     * @dev    Throws when an order is a cosigned order and the cosignature is invalid.
     * @dev    Throws when the transaction originates from an untrusted channel if untrusted channels are blocked.
     * @dev    Throws when the taker does not have or did not send sufficient funds to complete the purchase.
     * @dev    Throws when the provided bulk order merkle proof and order index are invalid.
     * @dev    Throws when the provided permit processor does not have approval to move the token or receives an invalid signature.
     * @dev    Will NOT throw when a token fails to transfer but also will not disperse payments for failed items.
     * @dev    Any unused native token payment will be returned to the taker as wrapped native token.
     *
     * @dev    <h4>Postconditions:</h4>
     * @dev    1. Payment amounts and fees are sent to their respective recipients.
     * @dev    2. Purchased tokens are sent to the beneficiary.
     * @dev    3. Makers nonces are marked as used for ERC721_FILL_OR_KILL and ERC1155_FILL_OR_KILL orders.
     * @dev    4. Makers partially fillable order states are updated for ERC1155_PARTIAL_FILL orders.
     * @dev    5. `BuyListingERC721` events have been emitted for each ERC721 purchase.
     * @dev    6. `BuyListingERC1155` events have been emitted for each ERC1155 purchase.
     * @dev    7. A `NonceInvalidated` event has been emitted for each ERC721_FILL_OR_KILL or ERC1155_FILL_OR_KILL order.
     *
     * @param  advancedSweep  The cosigner, maker, and taker signatures, order details and permit details.
     */
    function sweepCollectionAdvanced(
        AdvancedSweep calldata advancedSweep
    ) public payable {
        uint256 appendedDataLength;
        unchecked {
            appendedDataLength = 
                msg.data.length - 
                BASE_MSG_LENGTH_SWEEP_COLLECTION_ADVANCED - 
                (BASE_MSG_LENGTH_SWEEP_COLLECTION_ADVANCED_PER_ITEM * advancedSweep.items.length);

            for (uint256 i = 0; i < advancedSweep.items.length; ++i) {
                appendedDataLength -= PROOF_ELEMENT_SIZE * advancedSweep.items[i].bulkOrderProof.proof.length;
            }
        }

        TradeContext memory context = TradeContext({
            channel: msg.sender,
            taker: _getTaker(appendedDataLength),
            disablePartialFill: false,
            orderDigest: bytes32(0),
            backfillNumerator: uint16(0),
            backfillReceiver: address(0),
            bountyNumerator: uint16(0),
            exclusiveMarketplace: address(0),
            useRoyaltyBackfillAsRoyaltySource: false,
            protocolFeeVersion: type(uint256).max,
            protocolFees: ProtocolFees({
                protocolFeeReceiver: address(0),
                minimumProtocolFeeBps: 0,
                marketplaceFeeProtocolTaxBps: 0,
                feeOnTopProtocolTaxBps: 0,
                versionExpiration: 0
            })
        });

        uint256 remainingNativeProceeds =_executeSweepOrderAdvanced(
            context,
            msg.value,
            advancedSweep
        );

        _refundUnspentNativeFunds(remainingNativeProceeds, context.taker);
    }
}

File 2 of 29 : DataTypes.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @dev Storage data struct for stored approvals and order approvals
struct PackedApproval {
    // Only used for partial fill position 1155 transfers
    uint8 state;
    // Amount allowed
    uint200 amount;
    // Permission expiry
    uint48 expiration;
}

/// @dev Calldata data struct for order fill amounts
struct OrderFillAmounts {
    uint256 orderStartAmount;
    uint256 requestedFillAmount;
    uint256 minimumFillAmount;
}

File 3 of 29 : IPermitC.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import {OrderFillAmounts} from "../DataTypes.sol";

interface IPermitC {

    /**
     * =================================================
     * ==================== Events =====================
     * =================================================
     */

    /// @dev Emitted when an approval is stored
    event Approval(
        address indexed owner,
        address indexed token,
        address indexed operator,
        uint256 id,
        uint200 amount,
        uint48 expiration
    );

    /// @dev Emitted when a user increases their master nonce
    event Lockdown(address indexed owner);

    /// @dev Emitted when an order is opened
    event OrderOpened(
        bytes32 indexed orderId,
        address indexed owner,
        address indexed operator,
        uint256 fillableQuantity
    );

    /// @dev Emitted when an order has a fill
    event OrderFilled(
        bytes32 indexed orderId,
        address indexed owner,
        address indexed operator,
        uint256 amount
    );

    /// @dev Emitted when an order has been fully filled or cancelled
    event OrderClosed(
        bytes32 indexed orderId, 
        address indexed owner, 
        address indexed operator, 
        bool wasCancellation);

    /// @dev Emitted when an order has an amount restored due to a failed transfer
    event OrderRestored(
        bytes32 indexed orderId,
        address indexed owner,
        uint256 amountRestoredToOrder
    );

    /**
     * =================================================
     * ============== Approval Transfers ===============
     * =================================================
     */
    function approve(uint256 tokenType, address token, uint256 id, address operator, uint200 amount, uint48 expiration) external;

    function updateApprovalBySignature(
        uint256 tokenType,
        address token,
        uint256 id,
        uint256 nonce,
        uint200 amount,
        address operator,
        uint48 approvalExpiration,
        uint48 sigDeadline,
        address owner,
        bytes calldata signedPermit
    ) external;

    function allowance(
        address owner, 
        address operator, 
        uint256 tokenType,
        address token, 
        uint256 id
    ) external view returns (uint256 amount, uint256 expiration);

    /**
     * =================================================
     * ================ Signed Transfers ===============
     * =================================================
     */
    function registerAdditionalDataHash(string memory additionalDataTypeString) external;

    function permitTransferFromERC721(
        address token,
        uint256 id,
        uint256 nonce,
        uint256 expiration,
        address owner,
        address to,
        bytes calldata signedPermit
    ) external returns (bool isError);

    function permitTransferFromWithAdditionalDataERC721(
        address token,
        uint256 id,
        uint256 nonce,
        uint256 expiration,
        address owner,
        address to,
        bytes32 additionalData,
        bytes32 advancedPermitHash,
        bytes calldata signedPermit
    ) external returns (bool isError);

    function permitTransferFromERC1155(
        address token,
        uint256 id,
        uint256 nonce,
        uint256 permitAmount,
        uint256 expiration,
        address owner,
        address to,
        uint256 transferAmount,
        bytes calldata signedPermit
    ) external returns (bool isError);

    function permitTransferFromWithAdditionalDataERC1155(
        address token,
        uint256 id,
        uint256 nonce,
        uint256 permitAmount,
        uint256 expiration,
        address owner,
        address to,
        uint256 transferAmount,
        bytes32 additionalData,
        bytes32 advancedPermitHash,
        bytes calldata signedPermit
    ) external returns (bool isError);

    function permitTransferFromERC20(
        address token,
        uint256 nonce,
        uint256 permitAmount,
        uint256 expiration,
        address owner,
        address to,
        uint256 transferAmount,
        bytes calldata signedPermit
    ) external returns (bool isError);

    function permitTransferFromWithAdditionalDataERC20(
        address token,
        uint256 nonce,
        uint256 permitAmount,
        uint256 expiration,
        address owner,
        address to,
        uint256 transferAmount,
        bytes32 additionalData,
        bytes32 advancedPermitHash,
        bytes calldata signedPermit
    ) external returns (bool isError);

    function isRegisteredTransferAdditionalDataHash(bytes32 hash) external view returns (bool isRegistered);

    function isRegisteredOrderAdditionalDataHash(bytes32 hash) external view returns (bool isRegistered);

    /**
     * =================================================
     * =============== Order Transfers =================
     * =================================================
     */
    function fillPermittedOrderERC1155(
        bytes calldata signedPermit,
        OrderFillAmounts calldata orderFillAmounts,
        address token,
        uint256 id,
        address owner,
        address to,
        uint256 nonce,
        uint48 expiration,
        bytes32 orderId,
        bytes32 advancedPermitHash
    ) external returns (uint256 quantityFilled, bool isError);

    function fillPermittedOrderERC20(
        bytes calldata signedPermit,
        OrderFillAmounts calldata orderFillAmounts,
        address token,
        address owner,
        address to,
        uint256 nonce,
        uint48 expiration,
        bytes32 orderId,
        bytes32 advancedPermitHash
    ) external returns (uint256 quantityFilled, bool isError);

    function closePermittedOrder(
        address owner,
        address operator,
        uint256 tokenType,
        address token,
        uint256 id,
        bytes32 orderId
    ) external;

    function allowance(
        address owner, 
        address operator, 
        uint256 tokenType,
        address token, 
        uint256 id,
        bytes32 orderId
    ) external view returns (uint256 amount, uint256 expiration);


    /**
     * =================================================
     * ================ Nonce Management ===============
     * =================================================
     */
    function invalidateUnorderedNonce(uint256 nonce) external;

    function isValidUnorderedNonce(address owner, uint256 nonce) external view returns (bool isValid);

    function lockdown() external;

    function masterNonce(address owner) external view returns (uint256);

    /**
     * =================================================
     * ============== Transfer Functions ===============
     * =================================================
     */
    function transferFromERC721(
        address from,
        address to,
        address token,
        uint256 id
    ) external returns (bool isError);

    function transferFromERC1155(
        address from,
        address to,
        address token,
        uint256 id,
        uint256 amount
    ) external returns (bool isError);

    function transferFromERC20(
        address from,
        address to,
        address token,
        uint256 amount
    ) external returns (bool isError);

    /**
     * =================================================
     * ============ Signature Verification =============
     * =================================================
     */
    function domainSeparatorV4() external view returns (bytes32);
}

File 4 of 29 : TrustedForwarderERC2771Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (metatx/ERC2771Context.sol)
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/utils/Context.sol";
import "./interfaces/ITrustedForwarderFactory.sol";

/**
 * @title TrustedForwarderERC2771Context
 * @author Limit Break, Inc.
 * @notice Context variant that utilizes the TrustedForwarderFactory contract to determine if the sender is a trusted forwarder.
 */
abstract contract TrustedForwarderERC2771Context is Context {
    ITrustedForwarderFactory private immutable _factory;

    constructor(address factory) {
        _factory = ITrustedForwarderFactory(factory);
    }

    /**
     * @notice Returns true if the sender is a trusted forwarder, false otherwise.
     *
     * @dev    This function is required by ERC2771Context.
     *
     * @param forwarder The address to check.
     * @return True if the provided address is a trusted forwarder, false otherwise.
     */
    function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
        return _factory.isTrustedForwarder(forwarder);
    }

    function _msgSender() internal view virtual override returns (address sender) {
        if (_factory.isTrustedForwarder(msg.sender)) {
            if (msg.data.length >= 20) {
                // The assembly code is more direct than the Solidity version using `abi.decode`.
                /// @solidity memory-safe-assembly
                assembly {
                    sender := shr(96, calldataload(sub(calldatasize(), 20)))
                }
            } else {
                return super._msgSender();
            }
        } else {
            return super._msgSender();
        }
    }

    function _msgData() internal view virtual override returns (bytes calldata data) {
        if (_factory.isTrustedForwarder(msg.sender)) {
            assembly {
                let len := calldatasize()
                // Create a slice that defaults to the entire calldata
                data.offset := 0
                data.length := len
                // If the calldata is > 20 bytes, it contains the sender address at the end
                // and needs to be truncated
                if gt(len, 0x14) {
                    data.length := sub(len, 0x14)
                }
            }
        } else {
            return super._msgData();
        }
    }
}

File 5 of 29 : ITrustedForwarderFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

interface ITrustedForwarderFactory {
    error TrustedForwarderFactory__TrustedForwarderInitFailed(address admin, address appSigner);

    event TrustedForwarderCreated(address indexed trustedForwarder);

    function cloneTrustedForwarder(address admin, address appSigner, bytes32 salt)
        external
        returns (address trustedForwarder);
    function forwarders(address) external view returns (bool);
    function isTrustedForwarder(address sender) external view returns (bool);
    function trustedForwarderImplementation() external view returns (address);
}

File 6 of 29 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

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

pragma solidity ^0.8.0;

import "./math/Math.sol";
import "./math/SignedMath.sol";

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

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

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toString(int256 value) internal pure returns (string memory) {
        return string(abi.encodePacked(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) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

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

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

File 8 of 29 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

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

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

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

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

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

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

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

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

        return (signer, RecoverError.NoError);
    }

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

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

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

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, "\x19\x01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            data := keccak256(ptr, 0x42)
        }
    }

    /**
     * @dev Returns an Ethereum Signed Data with intended validator, created from a
     * `validator` and `data` according to the version 0 of EIP-191.
     *
     * See {recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x00", validator, data));
    }
}

File 9 of 29 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // 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.
            require(denominator > prod1, "Math: mulDiv overflow");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * @dev Return the log in base 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 + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 10 of 29 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.0;

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

File 11 of 29 : LicenseRef-PolyForm-Strict-1.0.0.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity ^0.8.0;

/*
# PolyForm Strict License 1.0.0

<https://polyformproject.org/licenses/strict/1.0.0>

## Acceptance

In order to get any license under these terms, you must agree
to them as both strict obligations and conditions to all
your licenses.

## Copyright License

The licensor grants you a copyright license for the software
to do everything you might do with the software that would
otherwise infringe the licensor's copyright in it for any
permitted purpose, other than distributing the software or
making changes or new works based on the software.

## Patent License

The licensor grants you a patent license for the software that
covers patent claims the licensor can license, or becomes able
to license, that you would infringe by using the software.

## Noncommercial Purposes

Any noncommercial purpose is a permitted purpose.

## Personal Uses

Personal use for research, experiment, and testing for
the benefit of public knowledge, personal study, private
entertainment, hobby projects, amateur pursuits, or religious
observance, without any anticipated commercial application,
is use for a permitted purpose.

## Noncommercial Organizations

Use by any charitable organization, educational institution,
public research organization, public safety or health
organization, environmental protection organization,
or government institution is use for a permitted purpose
regardless of the source of funding or obligations resulting
from the funding.

## Fair Use

You may have "fair use" rights for the software under the
law. These terms do not limit them.

## No Other Rights

These terms do not allow you to sublicense or transfer any of
your licenses to anyone else, or prevent the licensor from
granting licenses to anyone else.  These terms do not imply
any other licenses.

## Patent Defense

If you make any written claim that the software infringes or
contributes to infringement of any patent, your patent license
for the software granted under these terms ends immediately. If
your company makes such a claim, your patent license ends
immediately for work on behalf of your company.

## Violations

The first time you are notified in writing that you have
violated any of these terms, or done anything with the software
not covered by your licenses, your licenses can nonetheless
continue if you come into full compliance with these terms,
and take practical steps to correct past violations, within
32 days of receiving notice.  Otherwise, all your licenses
end immediately.

## No Liability

***As far as the law allows, the software comes as is, without
any warranty or condition, and the licensor will not be liable
to you for any damages arising out of these terms or the use
or nature of the software, under any kind of legal claim.***

## Definitions

The **licensor** is the individual or entity offering these
terms, and the **software** is the software the licensor makes
available under these terms.

**You** refers to the individual or entity agreeing to these
terms.

**Your company** is any legal entity, sole proprietorship,
or other kind of organization that you work for, plus all
organizations that have control over, are under the control of,
or are under common control with that organization.  **Control**
means ownership of substantially all the assets of an entity,
or the power to direct its management and policies by vote,
contract, or otherwise.  Control can be direct or indirect.

**Your licenses** are all the licenses granted to you for the
software under these terms.

**Use** means anything you do with the software requiring one
of your licenses.
*/

File 12 of 29 : IERC1155.sol
pragma solidity ^0.8.4;

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

/**
 * @dev Required interface of an ERC1155 compliant contract, as defined in the
 * https://eips.ethereum.org/EIPS/eip-1155[EIP].
 */
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;
}

File 13 of 29 : SafeERC20.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

library SafeERC20 {
    /**
     * @dev A gas efficient, and fallback-safe method to transfer ERC20 tokens owned by the contract.
     * 
     * @param tokenAddress  The address of the token to transfer.
     * @param to            The address to transfer tokens to.
     * @param amount        The amount of tokens to transfer.
     * 
     * @return isError      True if there was an error transferring, false if the call was successful.
     */
    function safeTransfer(
        address tokenAddress,
        address to,
        uint256 amount
    ) internal returns(bool isError) {
        assembly {
            function _callTransfer(_tokenAddress, _to, _amount) -> _isError {
                let ptr := mload(0x40)
                mstore(0x40, add(ptr, 0x60))
                mstore(ptr, 0xa9059cbb)
                mstore(add(0x20, ptr), _to)
                mstore(add(0x40, ptr), _amount)
                if call(gas(), _tokenAddress, 0, add(ptr, 0x1C), 0x44, 0x00, 0x00) {
                    if lt(returndatasize(), 0x20) {
                        _isError := iszero(extcodesize(_tokenAddress))
                        leave
                    }
                    returndatacopy(0x00, 0x00, 0x20)
                    _isError := iszero(mload(0x00))
                    leave
                }
                _isError := true
            }
            isError := _callTransfer(tokenAddress, to, amount)
        }
    }

    /**
     * @dev A gas efficient, and fallback-safe method to transfer ERC20 tokens owned by another address.
     * 
     * @param tokenAddress  The address of the token to transfer.
     * @param from          The address to transfer tokens from.
     * @param to            The address to transfer tokens to.
     * @param amount        The amount of tokens to transfer.
     * 
     * @return isError      True if there was an error transferring, false if the call was successful.
     */
    function safeTransferFrom(
        address tokenAddress,
        address from,
        address to,
        uint256 amount
    ) internal returns(bool isError) {
        assembly {
            function _callTransferFrom(_tokenAddress, _from, _to, _amount) -> _isError {
                let ptr := mload(0x40)
                mstore(0x40, add(ptr, 0x80))
                mstore(ptr, 0x23b872dd)
                mstore(add(0x20, ptr), _from)
                mstore(add(0x40, ptr), _to)
                mstore(add(0x60, ptr), _amount)
                if call(gas(), _tokenAddress, 0, add(ptr, 0x1C), 0x64, 0x00, 0x00) {
                    if lt(returndatasize(), 0x20) {
                        _isError := iszero(extcodesize(_tokenAddress))
                        leave
                    }
                    returndatacopy(0x00, 0x00, 0x20)
                    _isError := iszero(mload(0x00))
                    leave
                }
                _isError := true
            }
            isError := _callTransferFrom(tokenAddress, from, to, amount)
        }
    }

    /**
     * @dev A gas efficient, and fallback-safe method to set approval on ERC20 tokens.
     * 
     * @param tokenAddress  The address of the token to transfer.
     * @param spender       The address to allow to spend tokens.
     * @param allowance     The amount of tokens to allow `spender` to transfer.
     * 
     * @return isError      True if there was an error setting allowance, false if the call was successful.
     */
    function safeApprove(
        address tokenAddress,
        address spender,
        uint256 allowance
    ) internal returns(bool isError) {
        assembly {
            function _callApprove(_tokenAddress, _spender, _allowance) -> _isError {
                let ptr := mload(0x40)
                mstore(0x40, add(ptr, 0x60))
                mstore(ptr, 0x095ea7b3)
                mstore(add(0x20, ptr), _spender)
                mstore(add(0x40, ptr), _allowance)
                if call(gas(), _tokenAddress, 0, add(ptr, 0x1C), 0x44, 0x00, 0x00) {
                    if lt(returndatasize(), 0x20) {
                        _isError := iszero(extcodesize(_tokenAddress))
                        leave
                    }
                    returndatacopy(0x00, 0x00, 0x20)
                    _isError := iszero(mload(0x00))
                    leave
                }
                _isError := true
            }
            isError := _callApprove(tokenAddress, spender, allowance)
        }
    }

    /**
     * @dev A gas efficient, and fallback-safe method to set approval on ERC20 tokens.
     * @dev If the initial approve fails, it will retry setting the allowance to zero and then
     * @dev to the new allowance.
     * 
     * @param tokenAddress  The address of the token to transfer.
     * @param spender       The address to allow to spend tokens.
     * @param allowance     The amount of tokens to allow `spender` to transfer.
     * 
     * @return isError      True if there was an error setting allowance, false if the call was successful.
     */
    function safeApproveWithRetryAfterZero(
        address tokenAddress,
        address spender,
        uint256 allowance
    ) internal returns(bool isError) {
        assembly {
            function _callApprove(_ptr, _tokenAddress, _spender, _allowance) -> _isError {
                mstore(add(0x40, _ptr), _allowance)
                if call(gas(), _tokenAddress, 0, add(_ptr, 0x1C), 0x44, 0x00, 0x00) {
                    if lt(returndatasize(), 0x20) {
                        _isError := iszero(extcodesize(_tokenAddress))
                        leave
                    }
                    returndatacopy(0x00, 0x00, 0x20)
                    _isError := iszero(mload(0x00))
                    leave
                }
                _isError := true
            }

            let ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x60))
            mstore(ptr, 0x095ea7b3)
            mstore(add(0x20, ptr), spender)

            isError := _callApprove(ptr, tokenAddress, spender, allowance)
            if isError {
                pop(_callApprove(ptr, tokenAddress, spender, 0x00))
                isError := _callApprove(ptr, tokenAddress, spender, allowance)
            }
        }
    }
}

File 14 of 29 : IERC721.sol
pragma solidity ^0.8.4;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
     *   {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 15 of 29 : EfficientHash.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

/**
 * @title  EfficientHash
 * 
 * @author Limit Break
 * 
 * @notice Performs keccak256 hashing of value type parameters more efficiently than 
 * @notice high-level Solidity by utilizing scratch space for one or two values and
 * @notice efficient utilization of memory for parameter counts greater than two.
 * 
 * @notice Gas savings for EfficientHash compared to keccak256(abi.encode(...)):
 * @notice Parameter Count / Gas Savings (Shanghai) / Gas Savings (Cancun): 1 / 67 / 67
 * @notice Parameter Count / Gas Savings (Shanghai) / Gas Savings (Cancun): 5 / 66 / 66
 * @notice Parameter Count / Gas Savings (Shanghai) / Gas Savings (Cancun): 10 / 58 / 58
 * @notice Parameter Count / Gas Savings (Shanghai) / Gas Savings (Cancun): 15 / 1549 / 565
 * @notice Parameter Count / Gas Savings (Shanghai) / Gas Savings (Cancun): 20 / 3379 / 1027
 * @notice Parameter Count / Gas Savings (Shanghai) / Gas Savings (Cancun): 25 / 5807 / 1650
 * @notice Parameter Count / Gas Savings (Shanghai) / Gas Savings (Cancun): 50 / 23691 / 10107
 * @notice Parameter Count / Gas Savings (Shanghai) / Gas Savings (Cancun): 75 / 69164 / 41620
 * @notice Parameter Count / Gas Savings (Shanghai) / Gas Savings (Cancun): 99 / 172694 / 126646
 * 
 * @dev    Notes:
 * @dev    - `efficientHash` is overloaded for parameter counts between one and eight.
 * @dev    - Parameter counts between nine and sixteen require two functions to avoid
 * @dev        stack too deep errors. Each parameter count has a dedicated set of functions
 * @dev        (`efficientHashNineStep1`/`efficientHashNineStep2` ... `efficientHashSixteenStep1`/`efficientHashSixteenStep2`)
 * @dev        that must both be called to get the hash. 
 * @dev        `Step1` functions take eight parameters and return a memory pointer that is passed to `Step2`
 * @dev        `Step2` functions take the remaining parameters and return the hash of the values
 * @dev        Example: 
 * @dev              bytes32 hash = EfficientHash.efficientHashElevenStep2(
 * @dev                                   EfficientHash.efficientHashElevenStep1(
 * @dev                                       value1,
 * @dev                                       value2,
 * @dev                                       value3,
 * @dev                                       value4,
 * @dev                                       value5,
 * @dev                                       value6,
 * @dev                                       value7,
 * @dev                                       value8
 * @dev                                   ),
 * @dev                                   value9,
 * @dev                                   value10,
 * @dev                                   value11,
 * @dev                               );
 * @dev    - Parameter counts greater than sixteen must use the `Extension` functions.
 * @dev        Extension starts with `efficientHashExtensionStart` which takes the number
 * @dev        of parameters and the first eight parameters as an input and returns a
 * @dev        memory pointer that is passed to the `Continue` and `End` functions.
 * @dev        While the number of parameters remaining is greater than eight, call the
 * @dev        `efficientHashExtensionContinue` function with the pointer value and 
 * @dev        the next eight values.
 * @dev        When the number of parameters remaining is less than or equal to eight
 * @dev        call the `efficientHashExtensionEnd` function with the pointer value
 * @dev        and remaining values.
 * @dev        Example: 
 * @dev            bytes32 hash = EfficientHash.efficientHashExtensionEnd(
 * @dev                             EfficientHash.efficientHashExtensionContinue(
 * @dev                                 EfficientHash.efficientHashExtensionStart(
 * @dev                                     23,
 * @dev                                     value1,
 * @dev                                     value2,
 * @dev                                     value3,
 * @dev                                     value4,
 * @dev                                     value5,
 * @dev                                     value6,
 * @dev                                     value7,
 * @dev                                     value8
 * @dev                                 ), 
 * @dev                                 value9,
 * @dev                                 value10,
 * @dev                                 value11,
 * @dev                                 value12,
 * @dev                                 value13,
 * @dev                                 value14,
 * @dev                                 value15,
 * @dev                                 value16
 * @dev                             ),
 * @dev                             value17,
 * @dev                             value18,
 * @dev                             value19,
 * @dev                             value20,
 * @dev                             value21,
 * @dev                             value22,
 * @dev                             value23
 * @dev                         );
 */
library EfficientHash {
    
    /**
     * @notice Hashes one value type.
     * 
     * @param value The value to be hashed.
     * 
     * @return hash The hash of the value.
     */
    function efficientHash(bytes32 value) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(0x00, value)

            hash := keccak256(0x00, 0x20)
        }
    }
    
    /**
     * @notice Hashes two value types.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHash(bytes32 value1, bytes32 value2) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(0x00, value1)
            mstore(0x20, value2)
            
            hash := keccak256(0x00, 0x40)
        }
    }
    
    /**
     * @notice Hashes three value types.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHash(bytes32 value1, bytes32 value2, bytes32 value3) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x60))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            
            hash := keccak256(ptr, 0x60)
        }
    }
    
    /**
     * @notice Hashes four value types.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHash(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x80))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            
            hash := keccak256(ptr, 0x80)
        }
    }
    
    /**
     * @notice Hashes five value types.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHash(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            mstore(0x40, add(ptr, 0xA0))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            
            hash := keccak256(ptr, 0xA0)
        }
    }
    
    /**
     * @notice Hashes six value types.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHash(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            mstore(0x40, add(ptr, 0xC0))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            
            hash := keccak256(ptr, 0xC0)
        }
    }
    
    /**
     * @notice Hashes seven value types.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHash(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            mstore(0x40, add(ptr, 0xE0))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            
            hash := keccak256(ptr, 0xE0)
        }
    }
    
    /**
     * @notice Hashes eight value types.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHash(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x100))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            mstore(add(ptr, 0xE0), value8)
            
            hash := keccak256(ptr, 0x100)
        }
    }
    
    /**
     * @notice Step one of hashing nine values. Must be followed by `efficientHashNineStep2` to hash the values.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptr The memory pointer location for the values to hash.
     */
    function efficientHashNineStep1(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptr) {
        assembly ("memory-safe") {
            ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x120))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            mstore(add(ptr, 0xE0), value8)
        }
    }
    
    /**
     * @notice Step two of hashing nine values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value9  Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashNineStep2(
        uint256 ptr,
        bytes32 value9
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(add(ptr, 0x100), value9)

            hash := keccak256(ptr, 0x120)
        }
    }
    
    /**
     * @notice Step one of hashing ten values. Must be followed by `efficientHashTenStep2` to hash the values.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptr The memory pointer location for the values to hash.
     */
    function efficientHashTenStep1(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptr) {
        assembly ("memory-safe") {
            ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x140))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            mstore(add(ptr, 0xE0), value8)
        }
    }
    
    /**
     * @notice Step two of hashing ten values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value9  Value to be hashed.
     * @param value10 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashTenStep2(
        uint256 ptr,
        bytes32 value9, bytes32 value10
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(add(ptr, 0x100), value9)
            mstore(add(ptr, 0x120), value10)

            hash := keccak256(ptr, 0x140)
        }
    }
    
    /**
     * @notice Step one of hashing eleven values. Must be followed by `efficientHashElevenStep2` to hash the values.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptr The memory pointer location for the values to hash.
     */
    function efficientHashElevenStep1(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptr) {
        assembly ("memory-safe") {
            ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x160))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            mstore(add(ptr, 0xE0), value8)
        }
    }
    
    /**
     * @notice Step two of hashing eleven values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value9  Value to be hashed.
     * @param value10 Value to be hashed.
     * @param value11 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashElevenStep2(
        uint256 ptr,
        bytes32 value9, bytes32 value10, bytes32 value11
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(add(ptr, 0x100), value9)
            mstore(add(ptr, 0x120), value10)
            mstore(add(ptr, 0x140), value11)

            hash := keccak256(ptr, 0x160)
        }
    }
    
    /**
     * @notice Step one of hashing twelve values. Must be followed by `efficientHashTwelveStep2` to hash the values.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptr The memory pointer location for the values to hash.
     */
    function efficientHashTwelveStep1(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptr) {
        assembly ("memory-safe") {
            ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x180))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            mstore(add(ptr, 0xE0), value8)
        }
    }
    
    /**
     * @notice Step two of hashing twelve values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value9  Value to be hashed.
     * @param value10 Value to be hashed.
     * @param value11 Value to be hashed.
     * @param value12 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashTwelveStep2(
        uint256 ptr,
        bytes32 value9, bytes32 value10, bytes32 value11, bytes32 value12
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(add(ptr, 0x100), value9)
            mstore(add(ptr, 0x120), value10)
            mstore(add(ptr, 0x140), value11)
            mstore(add(ptr, 0x160), value12)

            hash := keccak256(ptr, 0x180)
        }
    }
    
    /**
     * @notice Step one of hashing thirteen values. Must be followed by `efficientHashThirteenStep2` to hash the values.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptr The memory pointer location for the values to hash.
     */
    function efficientHashThirteenStep1(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptr) {
        assembly ("memory-safe") {
            ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x1A0))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            mstore(add(ptr, 0xE0), value8)
        }
    }
    
    /**
     * @notice Step two of hashing thirteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value9  Value to be hashed.
     * @param value10 Value to be hashed.
     * @param value11 Value to be hashed.
     * @param value12 Value to be hashed.
     * @param value13 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashThirteenStep2(
        uint256 ptr,
        bytes32 value9, bytes32 value10, bytes32 value11, bytes32 value12,
        bytes32 value13
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(add(ptr, 0x100), value9)
            mstore(add(ptr, 0x120), value10)
            mstore(add(ptr, 0x140), value11)
            mstore(add(ptr, 0x160), value12)
            mstore(add(ptr, 0x180), value13)

            hash := keccak256(ptr, 0x1A0)
        }
    }
    
    /**
     * @notice Step one of hashing fourteen values. Must be followed by `efficientHashFourteenStep2` to hash the values.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptr The memory pointer location for the values to hash.
     */
    function efficientHashFourteenStep1(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptr) {
        assembly ("memory-safe") {
            ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x1C0))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            mstore(add(ptr, 0xE0), value8)
        }
    }
    
    /**
     * @notice Step two of hashing fourteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value9  Value to be hashed.
     * @param value10 Value to be hashed.
     * @param value11 Value to be hashed.
     * @param value12 Value to be hashed.
     * @param value13 Value to be hashed.
     * @param value14 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashFourteenStep2(
        uint256 ptr,
        bytes32 value9, bytes32 value10, bytes32 value11, bytes32 value12,
        bytes32 value13, bytes32 value14
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(add(ptr, 0x100), value9)
            mstore(add(ptr, 0x120), value10)
            mstore(add(ptr, 0x140), value11)
            mstore(add(ptr, 0x160), value12)
            mstore(add(ptr, 0x180), value13)
            mstore(add(ptr, 0x1A0), value14)

            hash := keccak256(ptr, 0x1C0)
        }
    }
    
    /**
     * @notice Step one of hashing fifteen values. Must be followed by `efficientHashFifteenStep2` to hash the values.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptr The memory pointer location for the values to hash.
     */
    function efficientHashFifteenStep1(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptr) {
        assembly ("memory-safe") {
            ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x1E0))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            mstore(add(ptr, 0xE0), value8)
        }
    }
    
    /**
     * @notice Step two of hashing fifteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value9  Value to be hashed.
     * @param value10 Value to be hashed.
     * @param value11 Value to be hashed.
     * @param value12 Value to be hashed.
     * @param value13 Value to be hashed.
     * @param value14 Value to be hashed.
     * @param value15 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashFifteenStep2(
        uint256 ptr,
        bytes32 value9, bytes32 value10, bytes32 value11, bytes32 value12,
        bytes32 value13, bytes32 value14, bytes32 value15
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(add(ptr, 0x100), value9)
            mstore(add(ptr, 0x120), value10)
            mstore(add(ptr, 0x140), value11)
            mstore(add(ptr, 0x160), value12)
            mstore(add(ptr, 0x180), value13)
            mstore(add(ptr, 0x1A0), value14)
            mstore(add(ptr, 0x1C0), value15)

            hash := keccak256(ptr, 0x1E0)
        }
    }
    
    /**
     * @notice Step one of hashing sixteen values. Must be followed by `efficientHashSixteenStep2` to hash the values.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptr The memory pointer location for the values to hash.
     */
    function efficientHashSixteenStep1(
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptr) {
        assembly ("memory-safe") {
            ptr := mload(0x40)
            mstore(0x40, add(ptr, 0x200))

            mstore(ptr, value1)
            mstore(add(ptr, 0x20), value2)
            mstore(add(ptr, 0x40), value3)
            mstore(add(ptr, 0x60), value4)
            mstore(add(ptr, 0x80), value5)
            mstore(add(ptr, 0xA0), value6)
            mstore(add(ptr, 0xC0), value7)
            mstore(add(ptr, 0xE0), value8)
        }
    }
    
    /**
     * @notice Step two of hashing sixteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value9  Value to be hashed.
     * @param value10 Value to be hashed.
     * @param value11 Value to be hashed.
     * @param value12 Value to be hashed.
     * @param value13 Value to be hashed.
     * @param value14 Value to be hashed.
     * @param value15 Value to be hashed.
     * @param value16 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashSixteenStep2(
        uint256 ptr,
        bytes32 value9, bytes32 value10, bytes32 value11, bytes32 value12,
        bytes32 value13, bytes32 value14, bytes32 value15, bytes32 value16
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            mstore(add(ptr, 0x100), value9)
            mstore(add(ptr, 0x120), value10)
            mstore(add(ptr, 0x140), value11)
            mstore(add(ptr, 0x160), value12)
            mstore(add(ptr, 0x180), value13)
            mstore(add(ptr, 0x1A0), value14)
            mstore(add(ptr, 0x1C0), value15)
            mstore(add(ptr, 0x1E0), value16)

            hash := keccak256(ptr, 0x200)
        }
    }
    
    /**
     * @notice Step one of hashing more than sixteen values.
     * @notice Must be followed by at least one call to 
     * @notice `efficientHashExtensionContinue` and completed with
     * @notice a call to `efficientHashExtensionEnd` with the remaining
     * @notice values.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptr The memory pointer location for the values to hash.
     */
    function efficientHashExtensionStart(
        uint256 numberOfValues,
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptr) {
        assembly ("memory-safe") {
            ptr := mload(0x40)
            mstore(0x40, add(add(ptr, 0x20), mul(numberOfValues, 0x20)))
            mstore(ptr, 0x100)
            
            mstore(add(ptr, 0x20), value1)
            mstore(add(ptr, 0x40), value2)
            mstore(add(ptr, 0x60), value3)
            mstore(add(ptr, 0x80), value4)
            mstore(add(ptr, 0xA0), value5)
            mstore(add(ptr, 0xC0), value6)
            mstore(add(ptr, 0xE0), value7)
            mstore(add(ptr, 0x100), value8)
        }
    }
    
    /**
     * @notice Second step of hashing more than sixteen values.
     * @notice Adds another eight values to the values to be hashed.
     * @notice May be called as many times as necessary until the values
     * @notice remaining to be added to the hash is less than or equal to
     * @notice eight.
     * 
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return ptrReturn The memory pointer location for the values to hash.
     */
    function efficientHashExtensionContinue(
        uint256 ptr,
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(uint256 ptrReturn) {
        assembly ("memory-safe") {
            ptrReturn := ptr
            let length := mload(ptrReturn)
            mstore(ptrReturn, add(length, 0x100))

            ptr := add(ptrReturn, length)
            
            mstore(add(ptr, 0x20), value1)
            mstore(add(ptr, 0x40), value2)
            mstore(add(ptr, 0x60), value3)
            mstore(add(ptr, 0x80), value4)
            mstore(add(ptr, 0xA0), value5)
            mstore(add(ptr, 0xC0), value6)
            mstore(add(ptr, 0xE0), value7)
            mstore(add(ptr, 0x100), value8)
        }
    }

    /**
     * @notice Final step of hashing more than sixteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value1 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashExtensionEnd(
        uint256 ptr,
        bytes32 value1
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptrStart := ptr
            let length := mload(ptrStart)

            ptr := add(ptrStart, length)
            
            mstore(add(ptr, 0x20), value1)

            hash := keccak256(add(ptrStart, 0x20), add(length, 0x20))
        }
    }

    /**
     * @notice Final step of hashing more than sixteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashExtensionEnd(
        uint256 ptr,
        bytes32 value1, bytes32 value2
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptrStart := ptr
            let length := mload(ptrStart)

            ptr := add(ptrStart, length)
            
            mstore(add(ptr, 0x20), value1)
            mstore(add(ptr, 0x40), value2)

            hash := keccak256(add(ptrStart, 0x20), add(length, 0x40))
        }
    }

    /**
     * @notice Final step of hashing more than sixteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashExtensionEnd(
        uint256 ptr,
        bytes32 value1, bytes32 value2, bytes32 value3
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptrStart := ptr
            let length := mload(ptrStart)

            ptr := add(ptrStart, length)
            
            mstore(add(ptr, 0x20), value1)
            mstore(add(ptr, 0x40), value2)
            mstore(add(ptr, 0x60), value3)

            hash := keccak256(add(ptrStart, 0x20), add(length, 0x60))
        }
    }

    /**
     * @notice Final step of hashing more than sixteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashExtensionEnd(
        uint256 ptr,
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptrStart := ptr
            let length := mload(ptrStart)

            ptr := add(ptrStart, length)
            
            mstore(add(ptr, 0x20), value1)
            mstore(add(ptr, 0x40), value2)
            mstore(add(ptr, 0x60), value3)
            mstore(add(ptr, 0x80), value4)

            hash := keccak256(add(ptrStart, 0x20), add(length, 0x80))
        }
    }

    /**
     * @notice Final step of hashing more than sixteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashExtensionEnd(
        uint256 ptr,
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptrStart := ptr
            let length := mload(ptrStart)

            ptr := add(ptrStart, length)
            
            mstore(add(ptr, 0x20), value1)
            mstore(add(ptr, 0x40), value2)
            mstore(add(ptr, 0x60), value3)
            mstore(add(ptr, 0x80), value4)
            mstore(add(ptr, 0xA0), value5)

            hash := keccak256(add(ptrStart, 0x20), add(length, 0xA0))
        }
    }

    /**
     * @notice Final step of hashing more than sixteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashExtensionEnd(
        uint256 ptr,
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptrStart := ptr
            let length := mload(ptrStart)

            ptr := add(ptrStart, length)
            
            mstore(add(ptr, 0x20), value1)
            mstore(add(ptr, 0x40), value2)
            mstore(add(ptr, 0x60), value3)
            mstore(add(ptr, 0x80), value4)
            mstore(add(ptr, 0xA0), value5)
            mstore(add(ptr, 0xC0), value6)

            hash := keccak256(add(ptrStart, 0x20), add(length, 0xC0))
        }
    }

    /**
     * @notice Final step of hashing more than sixteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashExtensionEnd(
        uint256 ptr,
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptrStart := ptr
            let length := mload(ptrStart)

            ptr := add(ptrStart, length)
            
            mstore(add(ptr, 0x20), value1)
            mstore(add(ptr, 0x40), value2)
            mstore(add(ptr, 0x60), value3)
            mstore(add(ptr, 0x80), value4)
            mstore(add(ptr, 0xA0), value5)
            mstore(add(ptr, 0xC0), value6)
            mstore(add(ptr, 0xE0), value7)

            hash := keccak256(add(ptrStart, 0x20), add(length, 0xE0))
        }
    }

    /**
     * @notice Final step of hashing more than sixteen values.
     * 
     * @param ptr    The memory pointer location for the values to hash.
     * @param value1 Value to be hashed.
     * @param value2 Value to be hashed.
     * @param value3 Value to be hashed.
     * @param value4 Value to be hashed.
     * @param value5 Value to be hashed.
     * @param value6 Value to be hashed.
     * @param value7 Value to be hashed.
     * @param value8 Value to be hashed.
     * 
     * @return hash The hash of the values.
     */
    function efficientHashExtensionEnd(
        uint256 ptr,
        bytes32 value1, bytes32 value2, bytes32 value3, bytes32 value4,
        bytes32 value5, bytes32 value6, bytes32 value7, bytes32 value8
    ) internal pure returns(bytes32 hash) {
        assembly ("memory-safe") {
            let ptrStart := ptr
            let length := mload(ptrStart)

            ptr := add(ptrStart, length)
            
            mstore(add(ptr, 0x20), value1)
            mstore(add(ptr, 0x40), value2)
            mstore(add(ptr, 0x60), value3)
            mstore(add(ptr, 0x80), value4)
            mstore(add(ptr, 0xA0), value5)
            mstore(add(ptr, 0xC0), value6)
            mstore(add(ptr, 0xE0), value7)
            mstore(add(ptr, 0x100), value8)

            hash := keccak256(add(ptrStart, 0x20), add(length, 0x100))
        }
    }
}

File 16 of 29 : IERC165.sol
pragma solidity ^0.8.4;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * 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[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 17 of 29 : EnumerableSet.sol
pragma solidity ^0.8.4;

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

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

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

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

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

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

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

                // Move the lastValue to the index where the value to delete is
                set._values[valueIndex] = lastValue;
                // Update the tracked position of the lastValue (that was just moved)
                set._positions[lastValue] = position;
            }

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

            // Delete the tracked position for the deleted slot
            delete set._positions[value];

            return true;
        } else {
            return false;
        }
    }

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

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

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

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

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

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

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

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

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

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

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

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

        return result;
    }
}

File 18 of 29 : Constants.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

bytes32 constant COSIGNATURE_HASH = keccak256("Cosignature(uint8 v,bytes32 r,bytes32 s,uint256 expiration,address taker)");
bytes32 constant COLLECTION_OFFER_APPROVAL_HASH = keccak256("CollectionOfferApproval(uint8 protocol,address cosigner,address buyer,address beneficiary,address marketplace,address fallbackRoyaltyRecipient,address paymentMethod,address tokenAddress,uint256 amount,uint256 itemPrice,uint256 expiration,uint256 marketplaceFeeNumerator,uint256 nonce,uint256 masterNonce)");
bytes32 constant ITEM_OFFER_APPROVAL_HASH = keccak256("ItemOfferApproval(uint8 protocol,address cosigner,address buyer,address beneficiary,address marketplace,address fallbackRoyaltyRecipient,address paymentMethod,address tokenAddress,uint256 tokenId,uint256 amount,uint256 itemPrice,uint256 expiration,uint256 marketplaceFeeNumerator,uint256 nonce,uint256 masterNonce)");
bytes32 constant TOKEN_SET_OFFER_APPROVAL_HASH = keccak256("TokenSetOfferApproval(uint8 protocol,address cosigner,address buyer,address beneficiary,address marketplace,address fallbackRoyaltyRecipient,address paymentMethod,address tokenAddress,uint256 amount,uint256 itemPrice,uint256 expiration,uint256 marketplaceFeeNumerator,uint256 nonce,uint256 masterNonce,bytes32 tokenSetMerkleRoot)");
bytes32 constant SALE_APPROVAL_HASH = keccak256("SaleApproval(uint8 protocol,address cosigner,address seller,address marketplace,address fallbackRoyaltyRecipient,address paymentMethod,address tokenAddress,uint256 tokenId,uint256 amount,uint256 itemPrice,uint256 expiration,uint256 marketplaceFeeNumerator,uint256 maxRoyaltyFeeNumerator,uint256 nonce,uint256 masterNonce,uint256 protocolFeeVersion)");
bytes32 constant PERMITTED_TRANSFER_SALE_APPROVAL = keccak256("PermitTransferFromWithAdditionalData(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 nonce,address operator,uint256 expiration,uint256 masterNonce,SaleApproval approval)SaleApproval(uint8 protocol,address cosigner,address seller,address marketplace,address fallbackRoyaltyRecipient,address paymentMethod,address tokenAddress,uint256 tokenId,uint256 amount,uint256 itemPrice,uint256 expiration,uint256 marketplaceFeeNumerator,uint256 maxRoyaltyFeeNumerator,uint256 nonce,uint256 masterNonce,uint256 protocolFeeVersion)");
bytes32 constant PERMITTED_ORDER_SALE_APPROVAL = keccak256("PermitOrderWithAdditionalData(uint256 tokenType,address token,uint256 id,uint256 amount,uint256 salt,address operator,uint256 expiration,uint256 masterNonce,SaleApproval approval)SaleApproval(uint8 protocol,address cosigner,address seller,address marketplace,address fallbackRoyaltyRecipient,address paymentMethod,address tokenAddress,uint256 tokenId,uint256 amount,uint256 itemPrice,uint256 expiration,uint256 marketplaceFeeNumerator,uint256 maxRoyaltyFeeNumerator,uint256 nonce,uint256 masterNonce,uint256 protocolFeeVersion)");

// The denominator used when calculating the marketplace fee.
// 0.5% fee numerator is 50, 1% fee numerator is 100, 10% fee numerator is 1,000 and so on.
uint256 constant FEE_DENOMINATOR = 100_00;

// Default Payment Method Whitelist Id
uint32 constant DEFAULT_PAYMENT_METHOD_WHITELIST_ID = 0;

// Convenience to avoid magic number in bitmask get/set logic.
uint256 constant ZERO = uint256(0);
uint256 constant ONE = uint256(1);

/**
 * @dev Defines condition to apply to order execution.
 */
// 0: ERC721 order that must execute in full or not at all.
uint256 constant ORDER_PROTOCOLS_ERC721_FILL_OR_KILL = 0;
// 1: ERC1155 order that must execute in full or not at all.
uint256 constant ORDER_PROTOCOLS_ERC1155_FILL_OR_KILL = 1;
// 2: ERC1155 order that may be partially executed.
uint256 constant ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL = 2;
// 3: Invalid order protocol for type check.
uint256 constant ORDER_PROTOCOLS_INVALID = 3;

/**
 * @dev Defines types of offers to be executed
 */
// 0: Offer for any item in a collection.
uint256 constant OFFER_TYPE_COLLECTION_OFFER = 0;
// 1: Offer for a specific item in a collection.
uint256 constant OFFER_TYPE_ITEM_OFFER = 1;
// 2: Offer for a set of tokens in a collection.
uint256 constant OFFER_TYPE_TOKEN_SET_OFFER = 2;

/// @dev The default protocol fee settings.
uint16 constant DEFAULT_PROTOCOL_FEE_MINIMUM_BPS = 25;
uint16 constant DEFAULT_PROTOCOL_FEE_MARKETPLACE_TAX_BPS = 15_00;
uint16 constant DEFAULT_PROTOCOL_FEE_FEE_ON_TOP_TAX_BPS = 25_00;

// The default admin role for NFT collections using Access Control.
bytes32 constant DEFAULT_ACCESS_CONTROL_ADMIN_ROLE = 0x00;

/// @dev The plain text message to sign for cosigner self-destruct signature verification
string constant COSIGNER_SELF_DESTRUCT_MESSAGE_TO_SIGN = "COSIGNER_SELF_DESTRUCT";

/**************************************************************/
/*                   PRECOMPUTED SELECTORS                    */
/**************************************************************/

bytes4 constant SELECTOR_DESTROY_COSIGNER = hex"aa04bf59";
bytes4 constant SELECTOR_REVOKE_MASTER_NONCE = hex"226d4adb";
bytes4 constant SELECTOR_REVOKE_SINGLE_NONCE = hex"b6d7dc33";
bytes4 constant SELECTOR_REVOKE_ORDER_DIGEST = hex"96ae0380";

bytes4 constant SELECTOR_BUY_LISTING = hex"27c46dc4";
bytes4 constant SELECTOR_ACCEPT_OFFER = hex"dbbb7e9d";
bytes4 constant SELECTOR_BULK_BUY_LISTINGS = hex"69bdcb08";
bytes4 constant SELECTOR_BULK_ACCEPT_OFFERS = hex"0aa91514";
bytes4 constant SELECTOR_SWEEP_COLLECTION = hex"6a89f68a";

bytes4 constant SELECTOR_BUY_LISTING_ADVANCED = hex"679d2803";
bytes4 constant SELECTOR_ACCEPT_OFFER_ADVANCED = hex"06814765";
bytes4 constant SELECTOR_BULK_BUY_LISTINGS_ADVANCED = hex"7497030d";
bytes4 constant SELECTOR_BULK_ACCEPT_OFFERS_ADVANCED = hex"088df090";
bytes4 constant SELECTOR_SWEEP_COLLECTION_ADVANCED = hex"b9d8d5a6";

/**************************************************************/
/*                   EXPECTED BASE msg.data LENGTHS           */
/**************************************************************/

uint256 constant PROOF_ELEMENT_SIZE = 32;

// | 4        | 544         | 96              | 192         | 64       | = 900 bytes
// | selector | saleDetails | sellerSignature | cosignature | feeOnTop |
uint256 constant BASE_MSG_LENGTH_BUY_LISTING = 900;

// | 4        | 32                     | 544         |  96             | 32 + (64 + (32 * proof.length)) | 192         | 64       | = 1028 bytes + (32 * proof.length)
// | selector | offerType              | saleDetails |  buyerSignature | tokenSetProof                   | cosignature | feeOnTop |
uint256 constant BASE_MSG_LENGTH_ACCEPT_OFFER = 1028;

// | 4        | 64              | 544 * length      | 64              | 96 * length      | 64              | 192 * length | 64              | 64 * length | = 260 bytes + (896 * saleDetailsArray.length)
// | selector | length + offset | saleDetailsArray  | length + offset | sellerSignatures | length + offset | cosignatures | length + offset | feesOnTop   |
uint256 constant BASE_MSG_LENGTH_BULK_BUY_LISTINGS = 260;
uint256 constant BASE_MSG_LENGTH_BULK_BUY_LISTINGS_PER_ITEM = 896;

// | 4        | 64               | 32 * length      | 32 * length            | 544 * length      | 96 * length  | 192 * length | 64               | 64               | 64 * length | 64               | 32 + (64 + (32 * proof.length)) | = 228 bytes + (1056 * saleDetailsArray.length) + (32 * proof.length [for each element])
// | selector | length + offsets | offsets          | offerType              | saleDetails       | signature    | cosignature  | length + offset  | length + offsets | feesOnTop   | length + offsets | tokenSetProof                   |
uint256 constant BASE_MSG_LENGTH_BULK_ACCEPT_OFFERS = 196;
uint256 constant BASE_MSG_LENGTH_BULK_ACCEPT_OFFERS_PER_ITEM = 1024;

// | 4        | 64       | 128        | 64              | 352 * length | 64              | 96 * length      | 64              | 192 * length | = 388 bytes + (640 * items.length)
// | selector | feeOnTop | sweepOrder | length + offset | items        | length + offset | signedSellOrders | length + offset | cosignatures |
uint256 constant BASE_MSG_LENGTH_SWEEP_COLLECTION = 388;
uint256 constant BASE_MSG_LENGTH_SWEEP_COLLECTION_PER_ITEM = 640;

// Advanced Trade Functions

// | 4        | 544         | 96        | 192         | 64       | 64            | 32 + (96 + (32 * proof.length)) | = 1092 bytes + (32 * proof.length)
// | selector | saleDetails | signature | cosignature | feeOnTop | permitContext | bulkOrderProof                  |
uint256 constant BASE_MSG_LENGTH_BUY_LISTING_ADVANCED = 1092;

// | 4        | 32                     | 544         |  96        | 192         | 64       | 64            | 32 + (96 + (32 * proof.length)) | 32 + (64 + (32 * proof.length)) | 96                    | = 1316 bytes + (32 * tokenSetProof.length) + (32 * bulkOrderProof.length)
// | selector | offerType              | saleDetails |  signature | cosignature | feeOnTop | permitContext | bulkOrderProof                  | tokenSetProof                   | sellerPermitSignature |
uint256 constant BASE_MSG_LENGTH_ACCEPT_OFFER_ADVANCED = 1316;

// | 4        | 64              | 544 * length      | 96 * length  | 192 * length | 64 * length   | 32 + (96 + (32 * proof.length)) | 64              | 64 * length | = 132 bytes + (1088 * advancedListingsArray.length) + (32 * bulkOrderProof.proof.length [for each element])
// | selector | length + offset | saleDetails       | signature    | cosignature  | permitContext | bulkOrderProof                  | length + offset | feeOnTop    |
uint256 constant BASE_MSG_LENGTH_BULK_BUY_LISTINGS_ADVANCED = 196;
uint256 constant BASE_MSG_LENGTH_BULK_BUY_LISTINGS_ADVANCED_PER_ITEM = 1088;

// | 4        | 64              | 32 * length            | 544 * length | 96 * length | 192 * length | 64 * length   | 96 * length           | 64              | 32 + (96 + (32 * proof.length)) | 64              | 64 * length | 64              | 32 + (64 + (32 * proof.length)) | = 260 bytes + (1312 * saleDetailsArray.length) + (32 * proof.length [for each element])
// | selector | length + offset | offerType              | saleDetails  | signature   | cosignatures | permitContext | sellerPermitSignature | length + offset | bulkOrderProof                  | length + offset | feeOnTop    | length + offset | tokenSetProof                   |
uint256 constant BASE_MSG_LENGTH_BULK_ACCEPT_OFFERS_ADVANCED = 260;
uint256 constant BASE_MSG_LENGTH_BULK_ACCEPT_OFFERS_ADVANCED_PER_ITEM = 1312;

// | 4        | 64       | 128        | 64              | 352 * length | 96 * length | 192 * length | 32 + (96 + (32 * proof.length)) | = 292 bytes + (864 * items.length) + (32 * bulkOrderProof.proof.length [for each element])
// | selector | feeOnTop | sweepOrder | length + offset | items        | signature   | cosignatures | bulkOrderProof                  |
uint256 constant BASE_MSG_LENGTH_SWEEP_COLLECTION_ADVANCED = 292;
uint256 constant BASE_MSG_LENGTH_SWEEP_COLLECTION_ADVANCED_PER_ITEM = 864;

/**************************************************************/
/*                           FLAGS                            */
/**************************************************************/

// Flags are used to efficiently store and retrieve boolean values in a single uint8.
// Each flag is a power of 2, so they can be combined using bitwise OR (|) and checked using bitwise AND (&).
// For example, to set the first and third flags, you would use: flags = FLAG1 | FLAG3;
// To check if the first flag is set, you would use: if (flags & FLAG1 != 0) { ... }
uint8 constant FLAG_IS_ROYALTY_BOUNTY_EXCLUSIVE = 1 << 0;
uint8 constant FLAG_BLOCK_TRADES_FROM_UNTRUSTED_CHANNELS = 1 << 1;
uint8 constant FLAG_USE_BACKFILL_AS_ROYALTY_SOURCE = 1 << 2;

/**************************************************************/
/*                   BULK ORDER TYPEHASHES                    */
/**************************************************************/

/// @dev Constant lookup tables for bulk order typehashes. The typehash offset is 32 * (height - 1) bytes.
bytes constant BULK_SALE_APPROVAL_TYPEHASHES_LOOKUP = 
    hex"8659f55d4c88f84030fe09241169834754ebf2e61099b616e530c6b65712c6445106f4043cda72e04ca2c760016628ea8d5667309323ba590682ea5254b4e82e71267a8f42e7ccde4ac75848a93b741df7a2f7a58e40274055f2fa51dbaa69ce6e90557aed2a349f8b6efb2b652c4025c56cfa82424c5cd0c6801cc234ebf519caf42fc49ad57705ea6be2ca9e1835c9ccddf7bc6fdea8f851917329b1d53a7f09b32b6b5ffee898d5fe18398652042cc8c46449329c5a1a79e425f4ede9bc2bc2362dea3338b88607906397acfdcc5651f19b40a038ee7c89dc4ab54c736cacf2bbc4f6d7ccfa2b8aab6505f0c8f2868c5a190c6c4cfce8c0de447804904df981f99e15003039550d3597e34e6426b1e230992a5a3727cb5e230754f18f3566012178d0a6b8f8748e48411572bdc391435539737aafc91fcba6f2c24ae156cf";

bytes constant BULK_COLLECTION_OFFER_APPROVAL_TYPEHASHES_LOOKUP = 
    hex"fb1dd652f3a5dcde3cb90b0cbb7ff0d33df15a48f216e6ac0e2306ff3538e33632fc12675167bd2e9c23f1a9b90ce9c0a14daa7e8b3fa5a01105804ad64aa49d22beb101a4a232e5b05a7b5f4727888724dd418194d6c5b1f1ba5ead4cbeed429ba46e6a390d8f8edfb6f752177c215b1cf8b6dcf1f5da395ead6c3e19755698ae93fe4a03206f6bb45035fab04a39964c83e7d265e93fc31521c86dd25a3be4ee3cb9e25b214af21b0d321776864470916324653397b355b267b2894a009a98516d5d5306f95a17cb6d0b84e71f78919a98ac5e3c723fc4b9b1a720193d590df5b1dcad1bd5c8161d6b904513bc658d4c9b8c288b2271e0f27d5938654e418663c21e3ce7e506548c01ef4e6a27a5805f9328e0da83e9a7c765dc28266a5aa19802b2e35d72255f2ae69bed829f0104723aa156059e02dfccfe781ffc955356";

bytes constant BULK_ITEM_OFFER_APPROVAL_TYPEHASHES_LOOKUP =
    hex"243dc86e63d73b10b2764253a38ab8763ded4ac63a632adef4019e482161964a2ed4880b2bfec74882da06ca9f461158c42fa73fa5974b5abec9fcde7cdd43ee8308607f65c90c023abf48563d2c8bd8c783d1db48ffd02ec324105d9f682f961f7a30dcec9205ff30a5290b3b756e1fd1a1585539bccbc817ab4e59d69a055ecfa8c0abdff5fb2704d1818f38dc974f5bdde6dfe1a4ddc3e22a1f3e593e98f324e3124a40922800d1eb1890240fc7d07f257a303bb383e8c0820e9910be1f97c72769ff919066b8d1f586bb8b7e720ad93f735ffa9570f9e9ef0e865d13251d89338818bfd140179260dbdc6d6bf38461d49661c166f2b76d3b56727acab7adf3e381ed4335a28fa612f4068c58de673cad05c8a7fbfb5c1fd557c2c5a2de9f84c94a0cfd84379f92ed5827593e2218a1dc1b975626bbe5c6948b9d2232f7d7";

bytes constant BULK_TOKEN_SET_OFFER_APPROVAL_TYPEHASHES_LOOKUP = 
    hex"0d0b16c0b281480a518e0ae1543bf94c612edc289e45edc04e8510dac617afa4337b9c051f65323200a3580d4917087d4d82e350fcc68b3397c654c9fc7872c38f8f306a409d08a43b82756f57beb839c3bf5bdd388ba0850d9d21f5c1d0c4dc9f510b8ccf7bbda5c9bd4333d7dcfc8e280aac9eaa9427dcd2f2ffca1fa7a8338599a8fc89aae892d7419812435866d931c9da91198b2f48d1d5318acb524461a0f24864e615845dfa14bee5d4fa28950fcdcf9d31893c68c26f4cfa13402a97621dd1d4cc7477f0587a16f5cd40ea8750209653e7275ccaea3b68623860181b51e570aee92287102d49a7493d337e8aa332c1bc639273de546b428973379fa9a9415346b8de2006517a8de68b2b4147a1d6fd91ce600f4040941627c1c8c3dfb75be8e10d720cf92518936f56974bdfa8e4a723902dd12e415ffba6eb6dde12";

/**************************************************************/
/*                           ROLES                            */
/**************************************************************/

bytes32 constant FEE_MANAGER = keccak256("FEE_MANAGER");

File 19 of 29 : DataTypes.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "@limitbreak/tm-core-lib/src/utils/structs/EnumerableSet.sol";

import { 
    OrderFillAmounts
} from "@limitbreak/permit-c/DataTypes.sol";

/**
 * @dev Used internally to indicate which side of the order the taker is on.
 */
enum Sides { 
    // 0: Taker is on buy side of order.
    Buy, 

    // 1: Taker is on sell side of order.
    Sell 
}

/**
 * @dev Defines the rules applied to a collection for payments.
 */
enum PaymentSettings { 
    // 0: Utilize Payment Processor default whitelist.
    DefaultPaymentMethodWhitelist,

    // 1: Allow any payment method.
    AllowAnyPaymentMethod,

    // 2: Use a custom payment method whitelist.
    CustomPaymentMethodWhitelist,

    // 3: Single payment method with floor and ceiling limits on collections only.
    PricingConstraintsCollectionOnly,

    // 4: Single payment method with floor and ceiling limits, allows both token and collection level constraints.
    PricingConstraints,

    // 5: Pauses trading for the collection.
    Paused
}

/**
 * @dev This struct is used internally for the deployment of the Payment Processor contract and 
 * @dev module deployments to define the default payment method whitelist.
 */
struct DefaultPaymentMethods {
    address defaultPaymentMethod1;
    address defaultPaymentMethod2;
    address defaultPaymentMethod3;
    address defaultPaymentMethod4;
}

/**
 * @dev This struct is used internally for the deployment of the Payment Processor contract and 
 * @dev module deployments to define the default trusted permit processors.
 */
struct TrustedPermitProcessors {
    address permitProcessor1;
    address permitProcessor2;
}

/**
 * @dev This struct is used internally for the deployment of the Payment Processor contract to define the
 * @dev module addresses to be used for the contract.
 */
struct PaymentProcessorModules {
    address moduleOnChainCancellation;
    address moduleBuyListings;
    address moduleAcceptOffers;
    address moduleSweeps;
}

/**
 * @dev This struct defines the payment settings parameters for a collection.
 *
 * @dev **paymentSettings**: The general rule definition for payment methods allowed.
 * @dev **paymentMethodWhitelistId**: The list id to be used when paymentSettings is set to CustomPaymentMethodWhitelist.
 * @dev **royaltyBackfillReceiver**: The backfilled royalty receiver for a collection.
 * @dev **royaltyBackfillNumerator**: The royalty fee to apply to the collection when ERC2981 is not supported.
 * @dev **royaltyBountyNumerator**: The percentage of royalties the creator will grant to a marketplace for order fulfillment.
 * @dev **isRoyaltyBountyExclusive**: If true, royalty bounties will only be paid if the order marketplace is the set exclusive marketplace.
 * @dev **blockTradesFromUntrustedChannels**: If true, trades that originate from untrusted channels will not be executed.
 */
struct CollectionPaymentSettings {
    bool initialized;
    PaymentSettings paymentSettings;
    uint32 paymentMethodWhitelistId;
    address royaltyBackfillReceiver;
    uint16 royaltyBackfillNumerator;
    uint16 royaltyBountyNumerator;
    uint8 flags;
}

/**
 * @dev The `v`, `r`, and `s` components of an ECDSA signature.  For more information
 *      [refer to this article](https://medium.com/mycrypto/the-magic-of-digital-signatures-on-ethereum-98fe184dc9c7).
 */
struct SignatureECDSA {
    uint256 v;
    bytes32 r;
    bytes32 s;
}

/**
 * @dev This struct defines order execution parameters.
 * 
 * @dev **protocol**: The order protocol to apply to the order.
 * @dev **maker**: The user that created and signed the order to be executed by a taker.
 * @dev **beneficiary**: The account that will receive the tokens.
 * @dev **marketplace**: The fee receiver of the marketplace that the order was created on.
 * @dev **fallbackRoyaltyRecipient**: The address that will receive royalties if ERC2981 
 * @dev is not supported by the collection and the creator has not defined backfilled royalties with Payment Processor.
 * @dev **paymentMethod**: The payment method for the order.
 * @dev **tokenAddress**: The address of the token collection the order is for.
 * @dev **tokenId**: The token id that the order is for.
 * @dev **amount**: The quantity of token the order is for.
 * @dev **itemPrice**: The price for the order in base units for the payment method.
 * @dev **nonce**: The maker's nonce for the order.
 * @dev **expiration**: The time, in seconds since the Unix epoch, that the order will expire.
 * @dev **marketplaceFeeNumerator**: The percentage fee that will be sent to the marketplace.
 * @dev **maxRoyaltyFeeNumerator**: The maximum royalty the maker is willing to accept. This will be used
 * @dev as the royalty amount when ERC2981 is not supported by the collection.
 * @dev **requestedFillAmount**: The amount of tokens for an ERC1155 partial fill order that the taker wants to fill.
 * @dev **minimumFillAmount**: The minimum amount of tokens for an ERC1155 partial fill order that the taker will accept.
 * @dev **protocolFeeVersion**: The protocol fee version to use when applying protocol fees.
 */
struct Order {
    uint256 protocol;
    address maker;
    address beneficiary;
    address marketplace;
    address fallbackRoyaltyRecipient;
    address paymentMethod;
    address tokenAddress;
    uint256 tokenId;
    uint256 amount;
    uint256 itemPrice;
    uint256 nonce;
    uint256 expiration;
    uint256 marketplaceFeeNumerator;
    uint256 maxRoyaltyFeeNumerator;
    uint256 requestedFillAmount;
    uint256 minimumFillAmount;
    uint256 protocolFeeVersion;
}

/**
 * @dev This struct defines the items required to execute an advanced order.
 *
 * @dev **saleDetails**: The order execution parameters.
 * @dev **signature**: The signature of the maker authorizing the order execution.
 * @dev **cosignature**: The cosignature of the maker authorizing the order execution.
 * @dev **permitContext**: Contains the address of the permit processor and the permit nonce to be used.
 */
struct AdvancedOrder {
    Order saleDetails;
    SignatureECDSA signature;
    Cosignature cosignature;
    PermitContext permitContext;
}

/**
 * @dev This struct defines the items required to execute an advanced bid order.
 * 
 * @dev **offerType**: The type of offer to execute.
 * @dev **advancedOrder**: The order execution parameters.
 * @dev **sellerPermitSignature**: The signature of the seller to be used for the permit.
 */
struct AdvancedBidOrder {
    uint256 offerType;
    AdvancedOrder advancedOrder;
    SignatureECDSA sellerPermitSignature;
}

/**
 * @dev This struct defines the items required to execute an advanced sweep order.
 *
 * @dev **feeOnTop**: The additional fee to be paid by the taker.
 * @dev **sweepOrder**: The order execution parameters.
 * @dev **items**: An array of items to be executed as part of the sweep order.
 */
struct AdvancedSweep {
    FeeOnTop feeOnTop;
    SweepOrder sweepOrder;
    AdvancedSweepItem[] items;
}

/**
 * @dev This struct is a wrapper for a sweep order item that includes the permit context, bulk order information, signature and cosignature.
 *
 * @dev **sweepItem**: The sweep order item to be executed.
 * @dev **signature**: The signature of the maker authorizing the order execution.
 * @dev **cosignature**: The cosignature of the maker authorizing the order execution.
 * @dev **permitContext**: Contains the address of the permit processor and the permit nonce to be used.
 * @dev **bulkOrderProof**: The proof data for the bulk order.
 */
struct AdvancedSweepItem {
    SweepItem sweepItem;
    SignatureECDSA signature;
    Cosignature cosignature;
    PermitContext permitContext;
    BulkOrderProof bulkOrderProof;
}

/**
 * @dev This struct defines the cosignature for verifying an order that is a cosigned order.
 *
 * @dev **signer**: The address that signed the cosigned order. This must match the cosigner that is part of the order signature.
 * @dev **taker**: The address of the order taker.
 * @dev **expiration**: The time, in seconds since the Unix epoch, that the cosignature will expire.
 * @dev The `v`, `r`, and `s` components of an ECDSA signature.  For more information
 *      [refer to this article](https://medium.com/mycrypto/the-magic-of-digital-signatures-on-ethereum-98fe184dc9c7).
 */
struct Cosignature {
    address signer;
    address taker;
    uint256 expiration;
    uint256 v;
    bytes32 r;
    bytes32 s;
}

/**
 * @dev This struct defines an additional fee on top of an order, paid by taker.
 *
 * @dev **recipient**: The recipient of the additional fee.
 * @dev **amount**: The amount of the additional fee, in base units of the payment token.
 */
struct FeeOnTop {
    address recipient;
    uint256 amount;
}

/**
 * @dev This struct defines the proof data for accepting an offer that is for a subset
 * @dev of items in a collection. The computed root hash from the proof must match the root
 * @dev hash that was signed by the order maker to recover the maker address.
 * 
 * @dev **proof**: The merkle proofs for the item being supplied to fulfill the offer order.
 */
struct TokenSetProof {
    bytes32[] proof;
}

/**
 * @dev This struct defines the proof data for a bulk order.
 * 
 * @dev **orderIndex**: The index of the order in the bulk order.
 * @dev **proof**: The merkle proofs for the order being supplied to fulfill the bulk order.
 */
struct BulkOrderProof {
    uint256 orderIndex;
    bytes32[] proof;
}

/**
 * @dev Current state of a partially fillable order.
 */
enum PartiallyFillableOrderState { 
    // 0: Order is open and may continue to be filled.
    Open, 

    // 1: Order has been completely filled.
    Filled, 

    // 2: Order has been cancelled.
    Cancelled
}

/**
 * @dev This struct defines the current status of a partially fillable order.
 * 
 * @dev **state**: The current state of the order as defined by the PartiallyFillableOrderState enum.
 * @dev **remainingFillableQuantity**: The remaining quantity that may be filled for the order.
 */
struct PartiallyFillableOrderStatus {
    PartiallyFillableOrderState state;
    uint248 remainingFillableQuantity;
}

/**
 * @dev This struct defines order information that is common to all items in a sweep order.
 * 
 * @dev **protocol**: The order protocol to apply to the order.
 * @dev **tokenAddress**: The address of the token collection the order is for.
 * @dev **paymentMethod**: The payment method for the order.
 * @dev **beneficiary**: The account that will receive the tokens.
 */
struct SweepOrder {
    uint256 protocol;
    address tokenAddress;
    address paymentMethod;
    address beneficiary;
}

/**
 * @dev This struct defines order information that is unique to each item of a sweep order.
 * @dev Combined with the SweepOrder header information to make an Order to execute.
 * 
 * @dev **maker**: The user that created and signed the order to be executed by a taker.
 * @dev **marketplace**: The marketplace that the order was created on.
 * @dev **fallbackRoyaltyRecipient**: The address that will receive royalties if ERC2981 
 * @dev is not supported by the collection and the creator has not defined royalties with Payment Processor.
 * @dev **tokenId**: The token id that the order is for.
 * @dev **amount**: The quantity of token the order is for.
 * @dev **itemPrice**: The price for the order in base units for the payment method.
 * @dev **nonce**: The maker's nonce for the order.
 * @dev **expiration**: The time, in seconds since the Unix epoch, that the order will expire.
 * @dev **marketplaceFeeNumerator**: The percentage fee that will be sent to the marketplace.
 * @dev **maxRoyaltyFeeNumerator**: The maximum royalty the maker is willing to accept. This will be used
 * @dev as the royalty amount when ERC2981 is not supported by the collection.
 * @dev **protocolFeeVersion**: The protocol fee version to use when applying protocol fees.
 */
struct SweepItem {
    address maker;
    address marketplace;
    address fallbackRoyaltyRecipient;
    uint256 tokenId;
    uint256 amount;
    uint256 itemPrice;
    uint256 nonce;
    uint256 expiration;
    uint256 marketplaceFeeNumerator;
    uint256 maxRoyaltyFeeNumerator;
    uint256 protocolFeeVersion;
}

/**
 * @dev This struct is used to define pricing constraints for a collection or individual token.
 *
 * @dev **isSet**: When true, this indicates that pricing constraints are set for the collection or token.
 * @dev **floorPrice**: The minimum price for a token or collection.  This is only enforced when 
 * @dev `enforcePricingConstraints` is `true`.
 * @dev **ceilingPrice**: The maximum price for a token or collection.  This is only enforced when
 * @dev `enforcePricingConstraints` is `true`.
 */
struct PricingBounds {
    bool initialized;
    bool isSet;
    uint120 floorPrice;
    uint120 ceilingPrice;
}

/**
 * @dev This struct defines the parameters for a bulk offer acceptance transaction.
 * 
 * 
 * @dev **offerType**: Offer type to execute.
 * @dev **saleDetails**: Order execution details.
 * @dev **signature**: Maker signature authorizing the order executions.
 * @dev **cosignature**: Additional cosignature for cosigned orders, as applicable.
 */
struct BulkAcceptOffersParams {
    uint256 offerType;
    Order saleDetails;
    SignatureECDSA signature;
    Cosignature cosignature;
}

/**
 * @dev This struct defines the parameters for a sweep execution transaction.
 *
 * @dev **fnPointers**: The function pointers to use for the sweep execution.
 * @dev **accumulator**: The accumulator to use for the sweep execution.
 * @dev **paymentCoin**: The payment token to use for the sweep execution.
 * @dev **paymentSettings**: The payment settings to use for the sweep execution.
 */
struct SweepExecutionParams {
    FulfillOrderFunctionPointers fnPointers;
    PayoutsAccumulator accumulator;
    address paymentCoin;
    PaymentSettings paymentSettings;
}

/** 
 * @dev This struct defines the parameters for the proceeds to be split between the seller, marketplace, and royalty recipient.
 *
 * @dev **royaltyRecipient**: The address of the royalty recipient.
 * @dev **royaltyProceeds**: The amount of proceeds to be sent to the royalty recipient.
 * @dev **marketplaceProceeds**: The amount of proceeds to be sent to the marketplace.
 * @dev **sellerProceeds**: The amount of proceeds to be sent to the seller.
 * @dev **infrastructureProceeds**: The amount of proceeds to be sent to the infrastructure recipient.
 */
struct SplitProceeds {
    address royaltyRecipient;
    uint256 royaltyProceeds;
    uint256 marketplaceProceeds;
    uint256 sellerProceeds;
    uint256 infrastructureProceeds;
}

/** 
 * @dev This struct defines the parameters to be used to accumulate payouts for an order.
 *
 * @dev **lastSeller**: The address of the last seller to receive proceeds.
 * @dev **lastMarketplace**: The address of the last marketplace to receive proceeds.
 * @dev **lastRoyaltyRecipient**: The address of the last royalty recipient to receive proceeds.
 * @dev **lastProtocolFeeRecipient**: The address of the last protocol fee recipient to receive proceeds.
 * @dev **accumulatedSellerProceeds**: The total amount of proceeds accumulated for the seller.
 * @dev **accumulatedMarketplaceProceeds**: The total amount of proceeds accumulated for the marketplace.
 * @dev **accumulatedRoyaltyProceeds**: The total amount of proceeds accumulated for the royalty recipient.
 * @dev **accumulatedInfrastructureProceeds**: The total amount of proceeds accumulated for the infrastructure recipient.
 */
struct PayoutsAccumulator {
    address lastSeller;
    address lastMarketplace;
    address lastRoyaltyRecipient;
    address lastProtocolFeeRecipient;
    uint256 accumulatedSellerProceeds;
    uint256 accumulatedMarketplaceProceeds;
    uint256 accumulatedRoyaltyProceeds;
    uint256 accumulatedInfrastructureProceeds;
}

/** 
 * @dev This struct defines the function pointers to be used for the fulfillment of an order.
 *
 * @dev **funcPayout**: The function pointer to use for the payout.
 * @dev **funcDispenseToken**: The function pointer to use for the token dispensation.
 * @dev **funcEmitOrderExecutionEvent**: The function pointer to use for emitting the order execution event.
 */
 struct FulfillOrderFunctionPointers {
    function(address,address,address,uint256) funcPayout;
    function(address,address,address,uint256,uint256) returns (bool) funcDispenseToken;
    function(TradeContext memory, Order memory) funcEmitOrderExecutionEvent;
 }

 /** 
 * @dev This struct defines the context to be used for a trade execution.
 *
 * @dev **channel**: The address of the channel to use for the trade.
 * @dev **taker**: The address of the taker for the trade.
 * @dev **disablePartialFill**: A flag to indicate if partial fills are disabled.
 * @dev **orderDigest**: The digest of the order to be executed.
 * @dev **backfillNumerator**: The numerator to use for the backfill.
 * @dev **backfillReceiver**: The address of the backfill receiver.
 * @dev **bountyNumerator**: The numerator to use for the bounty.
 * @dev **exclusiveMarketplace**: The address of the exclusive marketplace.
 * @dev **useRoyaltyBackfillAsRoyaltySource**: A flag to indicate if the royalty backfill should be used as the royalty source.
 * @dev **protocolFeeVersion**: The protocol fee version to use when applying protocol fees.
 * @dev **protocolFees**: Struct containing the loaded protocol fees for the current context.
 */
 struct TradeContext {
    address channel;
    address taker;
    bool disablePartialFill;
    bytes32 orderDigest;
    uint16 backfillNumerator;
    address backfillReceiver;
    uint16 bountyNumerator;
    address exclusiveMarketplace;
    bool useRoyaltyBackfillAsRoyaltySource;
    uint256 protocolFeeVersion;
    ProtocolFees protocolFees;
 }

/** 
 * @dev This struct defines the items required to handle a permitted order.
 *
 * @dev **permitProcessor**: The address of the permit processor to use for the order.
 * @dev **permitNonce**: The nonce to use for the permit.
 */
 struct PermitContext {
    address permitProcessor;
    uint256 permitNonce;
 }

/** 
 * @dev This struct defines the protocol fees to be applied to a trade based on the protocol fee version.
 *
 * @dev **protocolFeeReceiver**: The address to receive protocol fees.
 * @dev **minimumProtocolFeeBps**: The minimum fee in BPS that is applied to a trade.
 * @dev **marketplaceFeeProtocolTaxBps**: The fee in BPS that is applied to marketplace fees.
 * @dev **feeOnTopProtocolTaxBps**: The fee in BPS that is applied to a fee on top.
 * @dev **versionExpiration**: The timestamp when the protocol fee version expires.
 */
 struct ProtocolFees {
    address protocolFeeReceiver;
    uint16 minimumProtocolFeeBps;
    uint16 marketplaceFeeProtocolTaxBps;
    uint16 feeOnTopProtocolTaxBps;
    uint48 versionExpiration;
 }

/**
 * @dev This struct defines contract-level storage to be used across all Payment Processor modules.
 * @dev Follows the Diamond storage pattern.
 */
struct PaymentProcessorStorage {
    /**
     * @notice User-specific master nonce that allows buyers and sellers to efficiently cancel all listings or offers
     *         they made previously. The master nonce for a user only changes when they explicitly request to revoke all
     *         existing listings and offers.
     *
     * @dev    When prompting sellers to sign a listing or offer, marketplaces must query the current master nonce of
     *         the user and include it in the listing/offer signature data.
     */
    mapping(address => uint256) masterNonces;

    /**
     * @dev The mapping key is the user address.
     *
     * @dev The mapping value is another nested mapping of "slot" (key) to a bitmap (value) containing boolean flags
     *      indicating whether or not a nonce has been used or invalidated.
     *
     * @dev Marketplaces MUST track their own nonce by user, incrementing it for every signed listing or offer the user
     *      creates.  Listings and purchases may be executed out of order, and they may never be executed if orders
     *      are not matched prior to expriation.
     *
     * @dev The slot and the bit offset within the mapped value are computed as:
     *
     * @dev ```slot = nonce / 256;```
     * @dev ```offset = nonce % 256;```
     */
    mapping(address => mapping(uint256 => uint256)) invalidatedSignatures;
    
    /// @dev Mapping of token contract addresses to the collection payment settings.
    mapping (address => CollectionPaymentSettings) collectionPaymentSettings;

    /// @dev Mapping of payment method whitelist id to a defined list of allowed payment methods.
    mapping (uint32 => EnumerableSet.AddressSet) collectionPaymentMethodWhitelists;

    /// @dev Mapping of token contract addresses to the collection-level pricing boundaries (floor and ceiling price).
    mapping (address => PricingBounds) collectionPricingBounds;

    /// @dev Mapping of token contract addresses to the token-level pricing boundaries (floor and ceiling price).
    mapping (address => mapping (uint256 => PricingBounds)) tokenPricingBounds;

    /// @dev Mapping of token contract addresses to the defined pricing constaint payment method.
    mapping (address => address) collectionConstrainedPricingPaymentMethods;

    /// @dev Mapping of token contract addresses to the defined exclusive bounty receivers.
    mapping (address => address) collectionExclusiveBountyReceivers;

    /// @dev Mapping of maker addresses to a mapping of order digests to the status of the partially fillable order for that digest.
    mapping (address => mapping(bytes32 => PartiallyFillableOrderStatus)) partiallyFillableOrderStatuses;

    /// @dev Mapping of token contract addresses to the defined list of trusted channels for the token contract.
    mapping (address => EnumerableSet.AddressSet) collectionTrustedChannels;

    /// @dev A mapping of all co-signers that have self-destructed and can never be used as cosigners again.
    mapping (address => bool) destroyedCosigners;

    /// @dev An enumerable set of trusted permit processors that may be used.
    EnumerableSet.AddressSet trustedPermitProcessors;

    /// @dev Protocol Fee Current Version.
    uint256 currentProtocolFeeVersion;

    /// @dev Protocol Fee Version History.
    mapping (uint256 => ProtocolFees) protocolFeeVersions;
}

File 20 of 29 : Errors.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

/// @dev Thrown when an order is an ERC721 order and the amount is not one.
error PaymentProcessor__AmountForERC721SalesMustEqualOne();

/// @dev Thrown when an order is an ERC1155 order and the amount is zero.
error PaymentProcessor__AmountForERC1155SalesGreaterThanZero();

/// @dev Thrown when processing a permitted order and the order amount exceeds type(uint248).max
error PaymentProcessor__AmountExceedsMaximum();

/// @dev Thrown when appended data length is not zero or twenty bytes.
error PaymentProcessor__BadCalldataLength();

/// @dev Thrown when an offer is being accepted and the payment method is the chain native token.
error PaymentProcessor__BadPaymentMethod();

/**
 * @dev Thrown when a call is made to a function that must be called by the Collection Settings Registry 
 * @dev or by a self call from Payment Processor and the caller is not either of those addresses.
 */
error PaymentProcessor__CallerIsNotSettingsRegistryOrSelf();

/**
 * @dev Thrown when modifying collection payment settings, pricing bounds, or trusted channels on a collection
 * @dev that the caller is not the owner of or a member of the default admin role for.
 */
error PaymentProcessor__CallerMustHaveElevatedPermissionsForSpecifiedNFT();

/// @dev Thrown when the current block time is greater than the expiration time for the cosignature.
error PaymentProcessor__CosignatureHasExpired();

/// @dev Thrown when the cosigner has self destructed.
error PaymentProcessor__CosignerHasSelfDestructed();

/// @dev Thrown when a token failed to transfer to the beneficiary and partial fills are disabled.
error PaymentProcessor__DispensingTokenWasUnsuccessful();

/// @dev Thrown when a maker is a contract and the contract does not return the correct EIP1271 response to validate the signature.
error PaymentProcessor__EIP1271SignatureInvalid();

/// @dev Thrown when a native token transfer call fails to transfer the tokens.
error PaymentProcessor__FailedToTransferProceeds();

/// @dev Thrown when the additional fee on top exceeds the item price.
error PaymentProcessor__FeeOnTopCannotBeGreaterThanItemPrice();

/// @dev Thrown when the supplied root hash, token and proof do not match.
error PaymentProcessor__IncorrectTokenSetMerkleProof();

/// @dev Thrown when an input array has zero items in a location where it must have items.
error PaymentProcessor__InputArrayLengthCannotBeZero();

/// @dev Thrown when multiple input arrays have different lengths but are required to be the same length.
error PaymentProcessor__InputArrayLengthMismatch();

/// @dev Thrown when the height of the bulk order tree is either 0 or greater than 12.
error PaymentProcessor__InvalidBulkOrderHeight();

/// @dev Thrown when Payment Processor or a module is being deployed with invalid constructor arguments.
error PaymentProcessor__InvalidConstructorArguments();

/// @dev Thrown when an offer type parameter is not a valid offer type.
error PaymentProcessor__InvalidOfferType();

/// @dev Thrown when an order protocol parameter is not a valid order protocol type.
error PaymentProcessor__InvalidOrderProtocol();

/// @dev Thrown when a signature `v` value is greater than 255.
error PaymentProcessor__InvalidSignatureV();

/// @dev Thrown when the combined marketplace and royalty fees will exceed the item price.
error PaymentProcessor__MarketplaceAndRoyaltyFeesWillExceedSalePrice();

/// @dev Thrown when the version expiration grace period is exceeded.
error PaymentProcessor__MaxGracePeriodExceeded();

/// @dev Thrown when the recovered address from a cosignature does not match the order cosigner.
error PaymentProcessor__NotAuthorizedByCosigner();

/// @dev Thrown when the ERC2981 or backfilled royalties exceed the maximum fee specified by the order maker.
error PaymentProcessor__OnchainRoyaltiesExceedMaximumApprovedRoyaltyFee();

/// @dev Thrown when the current block timestamp is greater than the order expiration time.
error PaymentProcessor__OrderHasExpired();

/// @dev Thrown when attempting to fill a partially fillable order that has already been filled or cancelled.
error PaymentProcessor__OrderIsEitherCancelledOrFilled();

/// @dev Thrown when attempting to execute a sweep order for partially fillable orders.
error PaymentProcessor__OrderProtocolERC1155FillPartialUnsupportedInSweeps();

/// @dev Thrown when attempting to partially fill an order where the item price is not equally divisible by the amount of tokens.
error PaymentProcessor__PartialFillsNotSupportedForNonDivisibleItems();

/// @dev Thrown when attempting to execute an order with a payment method that is not allowed by the collection payment settings.
error PaymentProcessor__PaymentCoinIsNotAnApprovedPaymentMethod();

/// @dev Thrown when both a permit and a bulk order proof are submitted for an order, as these features are incompatible.
error PaymentProcessor__PermitsAreNotCompatibleWithBulkOrders();

/// @dev Thrown when attempting to use an untrusted permit processing system.
error PaymentProcessor__PermitProcessorNotTrusted();

/// @dev Thrown when the protocol fee is set to a value exceeding the maximum fee cap.
error PaymentProcessor__ProtocolFeeOrTaxExceedsCap();

/// @dev Thrown when the protocol fee version is expired.
error PaymentProcessor__ProtocolFeeVersionExpired();

/// @dev Thrown when distributing payments and fees in native token and the amount remaining is less than the amount to distribute.
error PaymentProcessor__RanOutOfNativeFunds();

/// @dev Thrown when a collection is set to pricing constraints and the item price exceeds the defined maximum price.
error PaymentProcessor__SalePriceAboveMaximumCeiling();

/// @dev Thrown when a collection is set to pricing constraints and the item price is below the defined minimum price.
error PaymentProcessor__SalePriceBelowMinimumFloor();

/// @dev Thrown when a maker's nonce has already been used for an executed order or cancelled by the maker.
error PaymentProcessor__SignatureAlreadyUsedOrRevoked();

/// @dev Thrown when a maker's nonce has not already been used for an executed order but an item with that nonce fails to fill.
error PaymentProcessor__SignatureNotUsedOrRevoked();

/**
 * @dev Thrown when a collection is set to block untrusted channels and the order execution originates from a channel 
 * @dev that is not in the collection's trusted channel list.
 */ 
error PaymentProcessor__TradeOriginatedFromUntrustedChannel();

/// @dev Thrown when a trading of a specific collection has been paused by the collection owner or admin.
error PaymentProcessor__TradingIsPausedForCollection();

/**
 * @dev Thrown when attempting to fill a partially fillable order and the amount available to fill 
 * @dev is less than the specified minimum to fill.
 */
error PaymentProcessor__UnableToFillMinimumRequestedQuantity();

/// @dev Thrown when the recovered signer for an order does not match the order maker.
error PaymentProcessor__UnauthorizedOrder();

/// @dev Thrown when the taker on a cosigned order does not match the taker on the cosignature.
error PaymentProcessor__UnauthorizedTaker();

/// @dev Thrown when the Payment Processor or a module is being deployed with uninitialized configuration values.
error PaymentProcessor__UninitializedConfiguration();

File 21 of 29 : IPaymentProcessorConfiguration.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "../DataTypes.sol";

/** 
* @title IPaymentProcessorConfiguration
* @custom:version 3.0.0
* @author Limit Break, Inc.
*/ 
interface IPaymentProcessorConfiguration {

    /**
     * @notice Returns the ERC2771 context setup params for payment processor modules.
     */
    function getPaymentProcessorModuleERC2771ContextParams() 
        external 
        view 
        returns (
            address /*trustedForwarderFactory*/
        );

    /**
     * @notice Returns the setup params for payment processor modules.
     */
    function getPaymentProcessorModuleDeploymentParams() 
        external 
        view 
        returns (
            address, /*deterministicPaymentProcessorAddress*/
            address, /*wrappedNativeCoin*/
            DefaultPaymentMethods memory /*defaultPaymentMethods*/,
            TrustedPermitProcessors memory /*trustedPermitProcessors*/,
            address /*collectionPaymentSettings*/,
            address /*infrastructureFeeReceiver*/
        );

    /**
     * @notice Returns the setup params for payment processor.
     */
    function getPaymentProcessorDeploymentParams()
        external
        view
        returns (
            address, /*defaultContractOwner*/
            PaymentProcessorModules memory /*paymentProcessorModules*/
        );
}

File 22 of 29 : IPaymentProcessorEvents.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "../DataTypes.sol";

/** 
* @title IPaymentProcessorEvents
* @custom:version 3.0.0
* @author Limit Break, Inc.
*/ 
interface IPaymentProcessorEvents {

    /// @notice Emitted when an ERC721 listing is purchased.
    event BuyListingERC721(
        address indexed buyer,
        address indexed seller,
        address indexed tokenAddress,
        address beneficiary,
        address paymentCoin,
        uint256 tokenId,
        uint256 salePrice);

    /// @notice Emitted when an ERC1155 listing is purchased.
    event BuyListingERC1155(
        address indexed buyer,
        address indexed seller,
        address indexed tokenAddress,
        address beneficiary,
        address paymentCoin,
        uint256 tokenId,
        uint256 amount,
        uint256 salePrice);

    /// @notice Emitted when an ERC721 offer is accepted.
    event AcceptOfferERC721(
        address indexed seller,
        address indexed buyer,
        address indexed tokenAddress,
        address beneficiary,
        address paymentCoin,
        uint256 tokenId,
        uint256 salePrice);

    /// @notice Emitted when an ERC1155 offer is accepted.
    event AcceptOfferERC1155(
        address indexed seller,
        address indexed buyer,
        address indexed tokenAddress,
        address beneficiary,
        address paymentCoin,
        uint256 tokenId,
        uint256 amount,
        uint256 salePrice);

    /// @notice Emitted when a cosigner destroys itself.
    event DestroyedCosigner(address indexed cosigner);

    /// @notice Emitted when a user revokes all of their existing listings or offers that share the master nonce.
    event MasterNonceInvalidated(address indexed account, uint256 nonce);

    /// @notice Emitted when a user revokes a single listing or offer nonce for a specific marketplace.
    event NonceInvalidated(
        uint256 indexed nonce, 
        address indexed account, 
        bool wasCancellation);

    /// @notice Emitted when a user fills a single listing or offer nonce but item fails to fill.
    event NonceRestored(
        uint256 indexed nonce, 
        address indexed account);

    /// @notice Emitted when a user revokes a single permitted listing nonce.
    event PermittedOrderNonceInvalidated(
        uint256 indexed permitNonce, 
        uint256 indexed orderNonce, 
        address indexed account, 
        bool wasCancellation);

    /// @notice Emitted when protocol fees are updated.
    event ProtocolFeesUpdated(
        address indexed newProtocolFeeRecipient,
        uint16 minimumProtocolFeeBps,
        uint16 marketplaceFeeProtocolTaxBps,
        uint16 feeOnTopProtocolTaxBps,
        uint48 gracePeriodExpiration);

    /// @notice Emitted the first time a partially fillable 1155 order has items filled on-chain.
    event OrderDigestOpened(
        bytes32 indexed orderDigest, 
        address indexed account, 
        uint256 orderStartAmount);

    /// @notice Emitted when a user fills items on a partially fillable 1155 listing.
    event OrderDigestItemsFilled(
        bytes32 indexed orderDigest, 
        address indexed account, 
        uint256 amountFilled);

    /// @notice Emitted when a user revokes a single partially fillable 1155 listing or offer for a specific marketplace.
    event OrderDigestInvalidated(
        bytes32 indexed orderDigest, 
        address indexed account, 
        bool wasCancellation);

    /// @notice Emitted when a user fills a partially fillable 1155 listing or offer but item fails to fill.
    event OrderDigestItemsRestored(
        bytes32 indexed orderDigest, 
        address indexed account, 
        uint256 amountRestoredToOrder);

    /// @notice Emitted when a coin is added to the approved coins mapping for a whitelist.
    event PaymentMethodAddedToWhitelist(
        uint32 indexed paymentMethodWhitelistId, 
        address indexed paymentMethod);

    /// @notice Emitted when a coin is removed from the approved coins mapping for a whitelist.
    event PaymentMethodRemovedFromWhitelist(
        uint32 indexed paymentMethodWhitelistId, 
        address indexed paymentMethod);

    /// @notice Emitted when a trusted channel is added for a collection
    event TrustedChannelAddedForCollection(
        address indexed tokenAddress, 
        address indexed channel);

    /// @notice Emitted when a trusted channel is removed for a collection.
    event TrustedChannelRemovedForCollection(
        address indexed tokenAddress, 
        address indexed channel);

    /// @notice Emitted when a permit processor is added to the trusted permit processor list.
    event TrustedPermitProcessorAdded(address indexed permitProcessor);

    /// @notice Emitted when a permit processor is removed from the trusted permit processor list.
    event TrustedPermitProcessorRemoved(address indexed permitProcessor);

    /// @notice Emitted whenever pricing bounds change at a collection level for price-constrained collections.
    event UpdatedCollectionLevelPricingBoundaries(
        address indexed tokenAddress, 
        uint256 floorPrice, 
        uint256 ceilingPrice);

    /// @notice Emitted when payment settings are updated for a collection.
    event UpdatedCollectionPaymentSettings(
        address indexed tokenAddress, 
        PaymentSettings paymentSettings, 
        uint32 indexed paymentMethodWhitelistId, 
        address indexed constrainedPricingPaymentMethod,
        uint16 royaltyBackfillNumerator,
        address royaltyBackfillReceiver,
        uint16 royaltyBountyNumerator,
        address exclusiveBountyReceiver,
        bool blockTradesFromUntrustedChannels,
        bool useRoyaltyBackfillAsRoyaltySource);

    /// @notice Emitted whenever pricing bounds change at a token level for price-constrained collections.
    event UpdatedTokenLevelPricingBoundaries(
        address indexed tokenAddress, 
        uint256 indexed tokenId, 
        uint256 floorPrice, 
        uint256 ceilingPrice);
}

File 23 of 29 : PaymentProcessorModule.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "../interfaces/IPaymentProcessorConfiguration.sol";
import "../interfaces/IPaymentProcessorEvents.sol";
import "../storage/PaymentProcessorStorageAccess.sol";
import "../settings-registry/IPaymentProcessorSettings.sol";
import "../Constants.sol";
import "../Errors.sol";

import "../settings-registry/ICollectionSettingsRegistry.sol";

import "@limitbreak/tm-core-lib/src/token/erc20/utils/SafeERC20.sol";
import "@limitbreak/tm-core-lib/src/utils/cryptography/EfficientHash.sol";
import "@limitbreak/tm-core-lib/src/token/erc721/IERC721.sol";
import "@limitbreak/tm-core-lib/src/token/erc1155/IERC1155.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

import {TrustedForwarderERC2771Context} from "@limitbreak/trusted-forwarder/TrustedForwarderERC2771Context.sol";

/*
                                                     @@@@@@@@@@@@@@             
                                                    @@@@@@@@@@@@@@@@@@(         
                                                   @@@@@@@@@@@@@@@@@@@@@        
                                                  @@@@@@@@@@@@@@@@@@@@@@@@      
                                                           #@@@@@@@@@@@@@@      
                                                               @@@@@@@@@@@@     
                            @@@@@@@@@@@@@@*                    @@@@@@@@@@@@     
                           @@@@@@@@@@@@@@@     @               @@@@@@@@@@@@     
                          @@@@@@@@@@@@@@@     @                @@@@@@@@@@@      
                         @@@@@@@@@@@@@@@     @@               @@@@@@@@@@@@      
                        @@@@@@@@@@@@@@@     #@@             @@@@@@@@@@@@/       
                        @@@@@@@@@@@@@@.     @@@@@@@@@@@@@@@@@@@@@@@@@@@         
                       @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@            
                      @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@             
                     @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@           
                    @@@@@@@@@@@@@@@     @@@@@&%%%%%%%%&&@@@@@@@@@@@@@@          
                    @@@@@@@@@@@@@@      @@@@@               @@@@@@@@@@@         
                   @@@@@@@@@@@@@@@     @@@@@                 @@@@@@@@@@@        
                  @@@@@@@@@@@@@@@     @@@@@@                 @@@@@@@@@@@        
                 @@@@@@@@@@@@@@@     @@@@@@@                 @@@@@@@@@@@        
                @@@@@@@@@@@@@@@     @@@@@@@                 @@@@@@@@@@@&        
                @@@@@@@@@@@@@@     *@@@@@@@               (@@@@@@@@@@@@         
               @@@@@@@@@@@@@@@     @@@@@@@@             @@@@@@@@@@@@@@          
              @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@           
             @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@            
            @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@              
           .@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                 
           @@@@@@@@@@@@@@%     @@@@@@@@@@@@@@@@@@@@@@@@(                        
          @@@@@@@@@@@@@@@                                                       
         @@@@@@@@@@@@@@@                                                        
        @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                         
       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                          
       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&                                          
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                           
 
* @title PaymentProcessorModule
* @custom:version 3.0.0
* @author Limit Break, Inc.
*/ 

abstract contract PaymentProcessorModule is 
    TrustedForwarderERC2771Context, 
    PaymentProcessorStorageAccess, 
    IPaymentProcessorEvents {

    using EnumerableSet for EnumerableSet.AddressSet;

    // Recommendations For Default Immutable Payment Methods Per Chain
    // Default Payment Method 1: Wrapped Native Coin
    // Default Payment Method 2: Wrapped ETH
    // Default Payment Method 3: USDC (Native)
    // Default Payment Method 4: USDC (Bridged)

    /// @dev The address of the ERC20 contract used for wrapped native token.
    address internal immutable _wrappedNativeCoinAddress;

    /// @dev The first default payment method defined at contract deployment. Immutable to save SLOAD cost.
    address internal immutable defaultPaymentMethod1;

    /// @dev The second default payment method defined at contract deployment. Immutable to save SLOAD cost.
    address internal immutable defaultPaymentMethod2;

    /// @dev The third default payment method defined at contract deployment. Immutable to save SLOAD cost.
    address internal immutable defaultPaymentMethod3;

    /// @dev The fourth default payment method defined at contract deployment. Immutable to save SLOAD cost.
    address internal immutable defaultPaymentMethod4;

    /// @dev The address of the collection settings registry contract.
    address internal immutable collectionSettingsRegistry;

    /// @dev The domain separator for EIP-712 signatures.
    bytes32 internal immutable _cachedDomainSeparator;

    address internal immutable _defaultInfrastructureFeeReceiver;

    constructor(address configurationContract)
    TrustedForwarderERC2771Context(
        IPaymentProcessorConfiguration(configurationContract).getPaymentProcessorModuleERC2771ContextParams()
    ) {
        (
            address paymentProcessorAddress_,
            address wrappedNativeCoinAddress_,
            DefaultPaymentMethods memory defaultPaymentMethods,,
            address collectionSettingsRegistry_,
            address infrastructureFeeReceiver_
        ) = IPaymentProcessorConfiguration(configurationContract).getPaymentProcessorModuleDeploymentParams();
        
        if (wrappedNativeCoinAddress_ == address(0) ||
            collectionSettingsRegistry_ == address(0)) {
            revert PaymentProcessor__InvalidConstructorArguments();
        }

        _wrappedNativeCoinAddress = wrappedNativeCoinAddress_;
        defaultPaymentMethod1 = defaultPaymentMethods.defaultPaymentMethod1;
        defaultPaymentMethod2 = defaultPaymentMethods.defaultPaymentMethod2;
        defaultPaymentMethod3 = defaultPaymentMethods.defaultPaymentMethod3;
        defaultPaymentMethod4 = defaultPaymentMethods.defaultPaymentMethod4;
        collectionSettingsRegistry = collectionSettingsRegistry_;

        _cachedDomainSeparator =
            keccak256(
                abi.encode(
                    keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), 
                    keccak256(bytes("PaymentProcessor")), 
                    keccak256(bytes("3.0.0")), 
                    block.chainid, 
                    paymentProcessorAddress_
                )
            );

        _defaultInfrastructureFeeReceiver = infrastructureFeeReceiver_;
    }

    /*************************************************************************/
    /*                        Default Payment Methods                        */
    /*************************************************************************/

    /**
     * @notice Returns true if `paymentMethod` is a default payment method.
     * 
     * @dev    This function will return true if the default payment method was added after contract deployment.
     *
     * @param paymentMethod The address of the payment method to check.
     */
    function _isDefaultPaymentMethod(address paymentMethod) internal returns (bool) {
        if (paymentMethod == address(0)) {
            return true;
        } else if (paymentMethod == _wrappedNativeCoinAddress) {
            return true;
        } else if (paymentMethod == defaultPaymentMethod1) {
            return true;
        } else if (paymentMethod == defaultPaymentMethod2) {
            return true;
        } else if (paymentMethod == defaultPaymentMethod3) {
            return true;
        } else if (paymentMethod == defaultPaymentMethod4) {
            return true;
        } else {
            // If it isn't one of the gas efficient immutable default payment methods,
            // it may have bee added to the fallback default payment method whitelist,
            // but there are SLOAD costs.

            return _isWhitelistedPaymentMethod(DEFAULT_PAYMENT_METHOD_WHITELIST_ID, paymentMethod);
        }
    }

    /**
     * @notice Returns true if `paymentMethod` is whitelisted for the provided `whitelistId`.
     *
     * @dev    This function will cache the payment method to the Payment Processor from the Collection Settings Registry
     * @dev    if it is not already cached.
     *
     * @param  whitelistId   The id of the whitelist to check.
     * @param  paymentMethod The address of the payment method to check.
     */
    function _isWhitelistedPaymentMethod(uint32 whitelistId, address paymentMethod) internal returns(bool) {
        if (appStorage().collectionPaymentMethodWhitelists[whitelistId].contains(paymentMethod)) {
            return true;
        }
        return IPaymentProcessorSettings(address(this)).checkWhitelistedPaymentMethod(whitelistId, paymentMethod);
    }

    /**
     * @notice Adds `paymentMethod` to the provided `whitelistId`.
     *
     * @param  ptrPaymentMethods The storage pointer to the payment method whitelist.
     * @param  whitelistId       The id of the whitelist to add the payment method to.
     * @param  paymentMethod     The address of the payment method to add.
     */
    function _addWhitelistedPaymentMethod(EnumerableSet.AddressSet storage ptrPaymentMethods, uint32 whitelistId, address paymentMethod) internal {
        if (ptrPaymentMethods.add(paymentMethod)) {
            emit PaymentMethodAddedToWhitelist(whitelistId, paymentMethod);
        }
    }

    /**
     * @notice Removes `paymentMethod` from the provided `whitelistId`.
     *
     * @param  ptrPaymentMethods The storage pointer to the payment method whitelist.
     * @param  whitelistId       The id of the whitelist to remove the payment method from.
     * @param  paymentMethod     The address of the payment method to remove.
     */
    function _removeWhitelistedPaymentMethod(EnumerableSet.AddressSet storage ptrPaymentMethods, uint32 whitelistId, address paymentMethod) internal {
        if (ptrPaymentMethods.remove(paymentMethod)) {
            emit PaymentMethodRemovedFromWhitelist(whitelistId, paymentMethod);
        }
    }

    /**
     * @notice Returns true if the provided `channel` is a trusted channel for the provided `tokenAddress`, false otherwise.
     *
     * @dev    This function will cache the channel to the Payment Processor from the Collection Settings Registry
     * @dev    if it is not already cached.
     *
     * @param  tokenAddress The address of the token collection.
     * @param  channel      The address of the channel to check.
     */
    function _isCollectionTrustedChannel(address tokenAddress, address channel) internal returns(bool) {
        if (appStorage().collectionTrustedChannels[tokenAddress].contains(channel)) {
            return true;
        }
        return IPaymentProcessorSettings(address(this)).checkCollectionTrustedChannels(tokenAddress, channel);
    }

    /**
     * @notice Adds `channel` to the trusted channels for the provided `tokenAddress`.
     *
     * @param  ptrTrustedChannels The storage pointer to the trusted channels set.
     * @param  tokenAddress       The address of the token collection.
     * @param  channel            The address of the channel to add.
     */
    function _addCollectionTrustedChannel(EnumerableSet.AddressSet storage ptrTrustedChannels, address tokenAddress, address channel) internal {
        if (ptrTrustedChannels.add(channel)) {
            emit TrustedChannelAddedForCollection(tokenAddress, channel);
        }
    }

    /**
     * @notice Removes `channel` from the trusted channels for the provided `tokenAddress`.
     *
     * @param  ptrTrustedChannels The storage pointer to the trusted channels set.
     * @param  tokenAddress       The address of the token collection.
     * @param  channel            The address of the channel to remove.
     */
    function _removeCollectionTrustedChannel(EnumerableSet.AddressSet storage ptrTrustedChannels, address tokenAddress, address channel) internal {
        if (ptrTrustedChannels.remove(channel)) {
            emit TrustedChannelRemovedForCollection(tokenAddress, channel);
        }
    }

    /**
     * @notice Adds `permitProcessor` to the trusted permit processors set.
     *
     * @param  permitProcessor The address of the permit processor to add.
     */
    function _addTrustedPermitProcessor(address permitProcessor) internal {
        if (appStorage().trustedPermitProcessors.add(permitProcessor)) {
            emit TrustedPermitProcessorAdded(permitProcessor);
        }
    }

    /**
     * @notice Removes `permitProcessor` from the trusted permit processors set.
     *
     * @param  permitProcessor The address of the permit processor to remove.
     */
    function _removeTrustedPermitProcessor(address permitProcessor) internal {
        if (appStorage().trustedPermitProcessors.remove(permitProcessor)) {
            emit TrustedPermitProcessorRemoved(permitProcessor);
        }
    }

    /**
     * @notice Returns an array of the default payment methods defined at contract deployment.
     * 
     * @dev    This array will **NOT** include default payment methods added after contract deployment.
     */
    function _getDefaultPaymentMethods() internal view returns (address[] memory) {
        address[] memory defaultPaymentMethods = new address[](6);
        defaultPaymentMethods[0] = address(0);
        defaultPaymentMethods[1] = _wrappedNativeCoinAddress;
        defaultPaymentMethods[2] = defaultPaymentMethod1;
        defaultPaymentMethods[3] = defaultPaymentMethod2;
        defaultPaymentMethods[4] = defaultPaymentMethod3;
        defaultPaymentMethods[5] = defaultPaymentMethod4;
        return defaultPaymentMethods;
    }

    /*************************************************************************/
    /*                            Order Execution                            */
    /*************************************************************************/

    /**
     * @notice Adjusts the item price and amount for per unit pricing.
     *
     * @dev    This function may be called multiple times during a bulk execution.
     * @dev    Throws when a partial fill order is not equally divisible by the number of items in the order.
     * 
     * @param quantityToFill The quantity of the item to fill.
     * @param saleDetails    The order execution details.
     */
    function _adjustForUnitPricing(uint256 quantityToFill, Order memory saleDetails) internal pure {
        if (quantityToFill != saleDetails.amount) {
            if (saleDetails.itemPrice % saleDetails.amount != 0) {
                revert PaymentProcessor__PartialFillsNotSupportedForNonDivisibleItems();
            }

            saleDetails.itemPrice = saleDetails.itemPrice / saleDetails.amount * quantityToFill;
            saleDetails.amount = quantityToFill;
        }
    }

    /**
     * @notice Validates the collection payment settings and fulfills an order.
     *
     * @dev    This function may be called multiple times during a bulk execution.
     * @dev    Throws when a partial fill order is not equally divisible by the number of items in the order.
     * @dev    Throws when a collection is set to block untrusted channels and the transaction originates 
     * @dev    from an untrusted channel.
     * @dev    Throws when the payment method is not an allowed payment method.
     * @dev    Throws when the sweep order is for ERC721 tokens and the amount is set to a value other than one.
     * @dev    Throws when the sweep order is for ERC1155 tokens and the amount is set to zero.
     * @dev    Throws when the marketplace fee and maximum royalty fee will exceed the sales price of an item.
     * @dev    Throws when the current block time is greater than the order expiration.
     * 
     *
     * @param  side                 The side of the order to fulfill.
     * @param  context              The current execution context to determine the taker.
     * @param  startingNativeFunds  The amount of native funds available at the beginning of the order execution.
     * @param  quantityToFill       The quantity of the item to fill.
     * @param  saleDetails          The order execution details.
     * @param  feeOnTop             The additional fee to add on top of the order, paid by taker.
     */
    function _validateAndFulfillOrder(
        Sides side,
        TradeContext memory context,
        uint256 startingNativeFunds,
        uint256 quantityToFill,
        Order memory saleDetails,
        FeeOnTop calldata feeOnTop
    ) internal returns (uint256 endingNativeFunds) {
        _adjustForUnitPricing(quantityToFill, saleDetails);

        _validateBasicOrderDetails(context, saleDetails);

        endingNativeFunds = _fulfillSingleOrderWithFeeOnTop(
            startingNativeFunds,
            context,
            side == Sides.Buy ? context.taker : saleDetails.maker,
            side == Sides.Buy ? saleDetails.maker : context.taker,
            saleDetails.paymentMethod,
            _getOrderFulfillmentFunctionPointers(side, saleDetails.paymentMethod, saleDetails.protocol),
            saleDetails,
            feeOnTop);
    }

    /**
     * @notice Checks order validation and fulfills a buy listing order.
     * 
     * @dev    This function may be called multiple times during a bulk execution.
     * @dev    Throws when a partial fill order is not equally divisible by the number of items in the order.
     * 
     * @param context             The current execution context to determine the taker.
     * @param startingNativeFunds The amount of native funds available at the beginning of the order execution.
     * @param saleDetails         The order execution details.
     * @param signedSellOrder     The maker's signature authorizing the order execution.
     * @param cosignature         The additional cosignature for a cosigned order, if applicable.
     * @param feeOnTop            The additional fee to add on top of the order, paid by taker.
     * 
     * @return endingNativeFunds  The amount of native funds available at the end of the order execution.
     */
    function _executeOrderBuySide(
        TradeContext memory context,
        uint256 startingNativeFunds,
        Order memory saleDetails,
        SignatureECDSA memory signedSellOrder,
        Cosignature memory cosignature,
        FeeOnTop calldata feeOnTop
    ) internal returns (uint256 endingNativeFunds) {
        saleDetails.itemPrice = uint240(saleDetails.itemPrice);

        uint256 quantityToFill = _verifySaleApproval(
            context, 
            saleDetails, 
            signedSellOrder, 
            cosignature);

        endingNativeFunds = 
            _validateAndFulfillOrder(
                Sides.Buy, 
                context, 
                startingNativeFunds, 
                quantityToFill, 
                saleDetails, 
                feeOnTop);
    }

    /**
     * @notice Checks order validation and fulfills an offer acceptance.
     * 
     * @dev    This function may be called multiple times during a bulk execution.
     * @dev    Throws when the payment method is the chain native token.
     * @dev    Throws when the supplied token for a token set offer cannot be validated with the root hash and proof.
     * @dev    Throws when a partial fill order is not equally divisible by the number of items in the order.
     * 
     * @param  context                The current execution context to determine the taker.
     * @param  offerType              The offer type to execute.
     * @param  saleDetails            The order execution details.
     * @param  signature              The maker's signature authorizing the order execution.
     * @param  tokenSetProof          The root hash and merkle proofs for an offer that is a subset of tokens in a collection.
     * @param  cosignature            The additional cosignature for a cosigned order, if applicable.
     * @param  feeOnTop               The additional fee to add on top of the order, paid by taker.
     */
    function _executeOrderSellSide(
        TradeContext memory context,
        uint256 offerType, 
        Order memory saleDetails,
        SignatureECDSA memory signature,
        TokenSetProof calldata tokenSetProof,
        Cosignature memory cosignature,
        FeeOnTop calldata feeOnTop
    ) internal {
        if (saleDetails.paymentMethod == address(0)) {
            revert PaymentProcessor__BadPaymentMethod();
        }
        saleDetails.itemPrice = uint240(saleDetails.itemPrice);

        uint256 quantityToFill = 
            _verifyBidOrderSignatures(
                offerType, 
                context, 
                saleDetails, 
                signature, 
                cosignature, 
                tokenSetProof
            );

        _validateAndFulfillOrder(
            Sides.Sell, 
            context, 
            0, 
            quantityToFill, 
            saleDetails, 
            feeOnTop);
    }

    /**
     * @notice Checks order validation and fulfills a sweep order.
     * 
     * @dev    Throws when the order protocol is for ERC1155 partial fills.
     * @dev    Throws when the `items`, `signedSellOrders` and `cosignatures` arrays have different lengths.
     * @dev    Throws when the `items` array length is zero.
     * 
     * @param context             The current execution context to determine the taker.
     * @param startingNativeFunds The amount of native funds available at the beginning of the order execution.
     * @param feeOnTop            The additional fee to add on top of the orders, paid by taker.
     * @param sweepOrder          The order information that is common to all items in the sweep.
     * @param items               An array of items that contains the order information unique to each item.
     * @param signedSellOrders    An array of maker signatures authorizing the order execution.
     * @param cosignatures        An array of additional cosignatures for cosigned orders, if applicable.
     * 
     * @return endingNativeFunds  The amount of native funds available at the end of the order execution.
     */
    function _executeSweepOrder(
        TradeContext memory context,
        uint256 startingNativeFunds,
        FeeOnTop calldata feeOnTop,
        SweepOrder calldata sweepOrder,
        SweepItem[] calldata items,
        SignatureECDSA[] calldata signedSellOrders,
        Cosignature[] calldata cosignatures
    ) internal returns (uint256 endingNativeFunds) {

        if (sweepOrder.protocol == ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL) {
            revert PaymentProcessor__OrderProtocolERC1155FillPartialUnsupportedInSweeps();
        }

        if (items.length != signedSellOrders.length) {
            revert PaymentProcessor__InputArrayLengthMismatch();
        }

        if (items.length != cosignatures.length) {
            revert PaymentProcessor__InputArrayLengthMismatch();
        }

        if (items.length == 0) {
            revert PaymentProcessor__InputArrayLengthCannotBeZero();
        }

        SweepExecutionParams memory params = _validateSweepOrderHeader(context, sweepOrder);

        endingNativeFunds = _validateAndFulfillSweepOrder(
            context,
            startingNativeFunds,
            feeOnTop,
            sweepOrder,
            items,
            signedSellOrders,
            cosignatures,
            params
        );
    }

    /*************************************************************************/
    /*                           Order Hashes                                */
    /*************************************************************************/

    /**
     * @notice Generates the order hash for a listing order.
     *
     * @param saleDetails      The order execution details.
     * @param signer           The address of the signer authorizing the order.
     * @param cosigner         The address of the cosigner authorizing the order.
     * @param makerMasterNonce The master nonce for the maker.
     */
    function _generateListingOrderHash(
        Order memory saleDetails,
        address signer,
        address cosigner,
        uint256 makerMasterNonce
    ) internal pure returns (bytes32 orderHash) {
        orderHash =
            EfficientHash.efficientHashExtensionEnd(
                EfficientHash.efficientHashExtensionContinue(
                    EfficientHash.efficientHashExtensionStart(
                        17,
                        SALE_APPROVAL_HASH,
                        bytes32(uint256(uint8(saleDetails.protocol))),
                        bytes32(uint256(uint160(cosigner))),
                        bytes32(uint256(uint160(signer))),
                        bytes32(uint256(uint160(saleDetails.marketplace))),
                        bytes32(uint256(uint160(saleDetails.fallbackRoyaltyRecipient))),
                        bytes32(uint256(uint160(saleDetails.paymentMethod))),
                        bytes32(uint256(uint160(saleDetails.tokenAddress)))
                    ),
                    bytes32(saleDetails.tokenId),
                    bytes32(saleDetails.amount),
                    bytes32(saleDetails.itemPrice),
                    bytes32(saleDetails.expiration),
                    bytes32(saleDetails.marketplaceFeeNumerator),
                    bytes32(saleDetails.maxRoyaltyFeeNumerator),
                    bytes32(saleDetails.nonce),
                    bytes32(makerMasterNonce)
                ),
                bytes32(saleDetails.protocolFeeVersion)
            );
    }

    /**
     * @notice Generates the order hash for a single item offer order.
     *
     * @param saleDetails      The order execution details.
     * @param signer           The address of the signer authorizing the order.
     * @param cosigner         The address of the cosigner authorizing the order.
     * @param makerMasterNonce The master nonce for the maker.
     */
    function _generateItemOfferOrderHash(
        Order memory saleDetails,
        address signer,
        address cosigner,
        uint256 makerMasterNonce
    ) internal pure returns (bytes32 orderHash) {
        orderHash = 
            EfficientHash.efficientHashSixteenStep2(
                EfficientHash.efficientHashSixteenStep1(
                    ITEM_OFFER_APPROVAL_HASH,
                    bytes32(uint256(uint8(saleDetails.protocol))),
                    bytes32(uint256(uint160(cosigner))),
                    bytes32(uint256(uint160(signer))),
                    bytes32(uint256(uint160(saleDetails.beneficiary))),
                    bytes32(uint256(uint160(saleDetails.marketplace))),
                    bytes32(uint256(uint160(saleDetails.fallbackRoyaltyRecipient))),
                    bytes32(uint256(uint160(saleDetails.paymentMethod)))
                ),
                bytes32(uint256(uint160(saleDetails.tokenAddress))),
                bytes32(saleDetails.tokenId),
                bytes32(saleDetails.amount),
                bytes32(saleDetails.itemPrice),
                bytes32(saleDetails.expiration),
                bytes32(saleDetails.marketplaceFeeNumerator),
                bytes32(saleDetails.nonce),
                bytes32(makerMasterNonce)
            );
    }

    /**
     * @notice Generates the order hash for a collection offer order.
     *
     * @param saleDetails      The order execution details.
     * @param signer           The address of the signer authorizing the order.
     * @param cosigner         The address of the cosigner authorizing the order.
     * @param makerMasterNonce The master nonce for the maker.
     */
    function _generateCollectionOfferOrderHash(
        Order memory saleDetails,
        address signer,
        address cosigner,
        uint256 makerMasterNonce
    ) internal pure returns (bytes32 orderHash) {
        orderHash = 
            EfficientHash.efficientHashFifteenStep2(
                EfficientHash.efficientHashFifteenStep1(
                    COLLECTION_OFFER_APPROVAL_HASH,
                    bytes32(uint256(uint8(saleDetails.protocol))),
                    bytes32(uint256(uint160(cosigner))),
                    bytes32(uint256(uint160(signer))),
                    bytes32(uint256(uint160(saleDetails.beneficiary))),
                    bytes32(uint256(uint160(saleDetails.marketplace))),
                    bytes32(uint256(uint160(saleDetails.fallbackRoyaltyRecipient))),
                    bytes32(uint256(uint160(saleDetails.paymentMethod)))
                ),
                bytes32(uint256(uint160(saleDetails.tokenAddress))),
                bytes32(saleDetails.amount),
                bytes32(saleDetails.itemPrice),
                bytes32(saleDetails.expiration),
                bytes32(saleDetails.marketplaceFeeNumerator),
                bytes32(saleDetails.nonce),
                bytes32(makerMasterNonce)
            );
    }

    /**
     * @notice Generates the order hash for a token set offer order.
     *
     * @param saleDetails      The order execution details.
     * @param signer           The address of the signer authorizing the order.
     * @param cosigner         The address of the cosigner authorizing the order.
     * @param makerMasterNonce The master nonce for the maker.
     * @param tokenSetProof    The token set proof for the order.
     */
    function _generateTokenSetOfferOrderHash(
        TokenSetProof calldata tokenSetProof,
        Order memory saleDetails,
        address signer,
        address cosigner,
        uint256 makerMasterNonce
    ) internal pure returns (bytes32 orderHash) {
        bytes32 tokenSetRootHash = _generateTokenSetRootHash(saleDetails.tokenAddress, saleDetails.tokenId, tokenSetProof.proof);

        orderHash = 
            EfficientHash.efficientHashSixteenStep2(
                EfficientHash.efficientHashSixteenStep1(
                    TOKEN_SET_OFFER_APPROVAL_HASH,
                    bytes32(uint256(uint8(saleDetails.protocol))),
                    bytes32(uint256(uint160(cosigner))),
                    bytes32(uint256(uint160(signer))),
                    bytes32(uint256(uint160(saleDetails.beneficiary))),
                    bytes32(uint256(uint160(saleDetails.marketplace))),
                    bytes32(uint256(uint160(saleDetails.fallbackRoyaltyRecipient))),
                    bytes32(uint256(uint160(saleDetails.paymentMethod)))
                ),
                bytes32(uint256(uint160(saleDetails.tokenAddress))),
                bytes32(saleDetails.amount),
                bytes32(saleDetails.itemPrice),
                bytes32(saleDetails.expiration),
                bytes32(saleDetails.marketplaceFeeNumerator),
                bytes32(saleDetails.nonce),
                bytes32(makerMasterNonce),
                tokenSetRootHash
            );
    }

    function _generateTokenSetRootHash(
        address tokenAddress,
        uint256 tokenId,
        bytes32[] calldata proof
    ) internal pure returns (bytes32 tokenSetRootHash) {
        tokenSetRootHash = EfficientHash.efficientHash(bytes32(uint256(uint160(tokenAddress))), bytes32(tokenId));
        bytes32 currentProof;
        for (uint256 i; i < proof.length; ++i) {
            currentProof = proof[i];
            if (currentProof < tokenSetRootHash) {
                tokenSetRootHash = EfficientHash.efficientHash(currentProof, tokenSetRootHash);
            } else {
                tokenSetRootHash = EfficientHash.efficientHash(tokenSetRootHash, currentProof);
            }
        }
    }

    /*************************************************************************/
    /*                           Order Validation                            */
    /*************************************************************************/

    /**
     * @notice Loads collection payment settings to validate a single item order.
     * 
     * @dev    This function may be called multiple times during a bulk execution.
     * @dev    Throws when a collection is set to block untrusted channels and the transaction originates 
     * @dev    from an untrusted channel.
     * @dev    Throws when the payment method is not an allowed payment method.
     * @dev    Throws when the sweep order is for ERC721 tokens and the amount is set to a value other than one.
     * @dev    Throws when the sweep order is for ERC1155 tokens and the amount is set to zero.
     * @dev    Throws when the marketplace fee and maximum royalty fee will exceed the sales price of an item.
     * @dev    Throws when the current block time is greater than the order expiration.
     * 
     * @param context     The current execution context to determine the taker.
     * @param saleDetails The order execution details.
     */
    function _validateBasicOrderDetails(
        TradeContext memory context,
        Order memory saleDetails
    ) internal {
        if (saleDetails.protocol == ORDER_PROTOCOLS_ERC721_FILL_OR_KILL) {
            if (saleDetails.amount != ONE) {
                revert PaymentProcessor__AmountForERC721SalesMustEqualOne();
            }
        } else if (saleDetails.protocol < ORDER_PROTOCOLS_INVALID) {
            if (saleDetails.amount == 0) {
                revert PaymentProcessor__AmountForERC1155SalesGreaterThanZero();
            }
        } else {
            revert PaymentProcessor__InvalidOrderProtocol();
        }

        if (block.timestamp > saleDetails.expiration) {
            revert PaymentProcessor__OrderHasExpired();
        }

        if (saleDetails.marketplaceFeeNumerator + saleDetails.maxRoyaltyFeeNumerator > FEE_DENOMINATOR) {
            revert PaymentProcessor__MarketplaceAndRoyaltyFeesWillExceedSalePrice();
        }

        CollectionPaymentSettings storage paymentSettingsForCollection = 
            appStorage().collectionPaymentSettings[saleDetails.tokenAddress];

        if (!paymentSettingsForCollection.initialized) {
            IPaymentProcessorSettings(address(this)).checkSyncCollectionSettings(saleDetails.tokenAddress);
        }

        PaymentSettings paymentSettings = paymentSettingsForCollection.paymentSettings;
        context.backfillReceiver = paymentSettingsForCollection.royaltyBackfillReceiver;
        context.backfillNumerator = paymentSettingsForCollection.royaltyBackfillNumerator;
        context.bountyNumerator = paymentSettingsForCollection.royaltyBountyNumerator;

        uint8 flags = paymentSettingsForCollection.flags;

        if (_isFlagSet(flags, FLAG_BLOCK_TRADES_FROM_UNTRUSTED_CHANNELS)) {
            if (!_isCollectionTrustedChannel(saleDetails.tokenAddress, context.channel)) {
                revert PaymentProcessor__TradeOriginatedFromUntrustedChannel();
            }
        }

        context.useRoyaltyBackfillAsRoyaltySource = _isFlagSet(flags, FLAG_USE_BACKFILL_AS_ROYALTY_SOURCE);

        context.exclusiveMarketplace = 
            _isFlagSet(flags, FLAG_IS_ROYALTY_BOUNTY_EXCLUSIVE) ?
                appStorage().collectionExclusiveBountyReceivers[saleDetails.tokenAddress] : address(0);
        
        if (paymentSettings == PaymentSettings.DefaultPaymentMethodWhitelist) {
            if (!_isDefaultPaymentMethod(saleDetails.paymentMethod)) {
                revert PaymentProcessor__PaymentCoinIsNotAnApprovedPaymentMethod();
            }
        } else if (paymentSettings == PaymentSettings.CustomPaymentMethodWhitelist) {
            if (!_isWhitelistedPaymentMethod(paymentSettingsForCollection.paymentMethodWhitelistId, saleDetails.paymentMethod)) {
                revert PaymentProcessor__PaymentCoinIsNotAnApprovedPaymentMethod();
            }
        } else if (paymentSettings == PaymentSettings.PricingConstraints || paymentSettings == PaymentSettings.PricingConstraintsCollectionOnly) {
            if (appStorage().collectionConstrainedPricingPaymentMethods[saleDetails.tokenAddress] != saleDetails.paymentMethod) {
                revert PaymentProcessor__PaymentCoinIsNotAnApprovedPaymentMethod();
            }

            _validateSalePriceInRange(
                paymentSettings,
                saleDetails.tokenAddress, 
                saleDetails.tokenId, 
                saleDetails.amount, 
                saleDetails.itemPrice);
        } else if (paymentSettings == PaymentSettings.Paused) {
            revert PaymentProcessor__TradingIsPausedForCollection();
        }

        if (block.timestamp > context.protocolFees.versionExpiration) {
            revert PaymentProcessor__ProtocolFeeVersionExpired();
        }

        if (context.protocolFees.minimumProtocolFeeBps > FEE_DENOMINATOR) {
            revert PaymentProcessor__ProtocolFeeOrTaxExceedsCap();
        }
    }

    /**
     * @notice Validates the sweep order header and returns the sweep execution parameters.
     *
     * @dev    This function may be called multiple times during a bulk execution.
     * @dev    Throws when a collection is set to block untrusted channels and the transaction originates
     * @dev    from an untrusted channel.
     * @dev    Throws when the payment method is not an allowed payment method.
     * @dev    Throws when trading is paused for the collection.
     * 
     * @param context    The current execution context to determine the taker.
     * @param sweepOrder The order information that is common to all items in the sweep.
     */
    function _validateSweepOrderHeader(
        TradeContext memory context,
        SweepOrder memory sweepOrder
    ) internal returns (
        SweepExecutionParams memory params
    ) {
        CollectionPaymentSettings storage paymentSettingsForCollection = 
            appStorage().collectionPaymentSettings[sweepOrder.tokenAddress];

        if (!paymentSettingsForCollection.initialized) {
            IPaymentProcessorSettings(address(this)).checkSyncCollectionSettings(sweepOrder.tokenAddress);
        }

        PaymentSettings paymentSettings = paymentSettingsForCollection.paymentSettings;
        context.backfillReceiver = paymentSettingsForCollection.royaltyBackfillReceiver;
        context.backfillNumerator = paymentSettingsForCollection.royaltyBackfillNumerator;
        context.bountyNumerator = paymentSettingsForCollection.royaltyBountyNumerator;

        uint8 flags = paymentSettingsForCollection.flags;

        if (_isFlagSet(flags, FLAG_BLOCK_TRADES_FROM_UNTRUSTED_CHANNELS)) {
            if (!_isCollectionTrustedChannel(sweepOrder.tokenAddress, context.channel)) {
                revert PaymentProcessor__TradeOriginatedFromUntrustedChannel();
            }
        }
        
        context.useRoyaltyBackfillAsRoyaltySource = _isFlagSet(flags, FLAG_USE_BACKFILL_AS_ROYALTY_SOURCE);

        context.exclusiveMarketplace = 
            _isFlagSet(flags, FLAG_IS_ROYALTY_BOUNTY_EXCLUSIVE) ?
                appStorage().collectionExclusiveBountyReceivers[sweepOrder.tokenAddress] : address(0);

        if (paymentSettings == PaymentSettings.DefaultPaymentMethodWhitelist) {
            if (!_isDefaultPaymentMethod(sweepOrder.paymentMethod)) {
                revert PaymentProcessor__PaymentCoinIsNotAnApprovedPaymentMethod();
            }
        } else if (paymentSettings == PaymentSettings.CustomPaymentMethodWhitelist) {
            if (!_isWhitelistedPaymentMethod(paymentSettingsForCollection.paymentMethodWhitelistId, sweepOrder.paymentMethod)) {
                revert PaymentProcessor__PaymentCoinIsNotAnApprovedPaymentMethod();
            }
        } else if (paymentSettings == PaymentSettings.PricingConstraints || paymentSettings == PaymentSettings.PricingConstraintsCollectionOnly) {
            if (appStorage().collectionConstrainedPricingPaymentMethods[sweepOrder.tokenAddress] != sweepOrder.paymentMethod) {
                revert PaymentProcessor__PaymentCoinIsNotAnApprovedPaymentMethod();
            }
            params.paymentSettings = paymentSettings;
        } else if (paymentSettings == PaymentSettings.Paused) {
            revert PaymentProcessor__TradingIsPausedForCollection();
        }

        params.fnPointers = _getOrderFulfillmentFunctionPointers(Sides.Buy, sweepOrder.paymentMethod, sweepOrder.protocol);
        params.paymentCoin = sweepOrder.paymentMethod;
    }

    /**
     * @notice Validates the sales price for a token is within the bounds set.
     * 
     * @dev    Throws when the unit price is above the ceiling bound.
     * @dev    Throws when the unit price is below the floor bound.
     * 
     * @param tokenAddress The contract address for the token.
     * @param tokenId      The token id.
     * @param amount       The quantity of the token being transacted.
     * @param salePrice    The total price for the token quantity.
     */
    function _validateSalePriceInRange(
        PaymentSettings paymentSettings,
        address tokenAddress, 
        uint256 tokenId, 
        uint256 amount, 
        uint256 salePrice
    ) internal {
        (uint256 floorPrice, uint256 ceilingPrice) = _getFloorAndCeilingPrices(paymentSettings, tokenAddress, tokenId);

        unchecked {
            uint256 unitPrice = salePrice / amount;

            if (unitPrice > ceilingPrice) {
                revert PaymentProcessor__SalePriceAboveMaximumCeiling();
            }

            if (unitPrice < floorPrice) {
                revert PaymentProcessor__SalePriceBelowMinimumFloor();
            }
        }
    }

    /**
     * @notice Returns the floor and ceiling price for a token for collections set to use pricing constraints.
     * 
     * @dev    Returns token pricing bounds if token bounds are set. 
     * @dev    If token bounds are not set then returns collection pricing bounds if they are set.
     * @dev    If collection bounds are not set, returns zero floor bound and uint256 max ceiling bound.
     * 
     * @param tokenAddress The contract address for the token.
     * @param tokenId      The token id.
     */
    function _getFloorAndCeilingPrices(
        PaymentSettings paymentSettings,
        address tokenAddress, 
        uint256 tokenId
    ) internal returns (uint256, uint256) {
        if (paymentSettings == PaymentSettings.PricingConstraints) {
            PricingBounds storage tokenLevelPricingBounds = appStorage().tokenPricingBounds[tokenAddress][tokenId];
            if (!tokenLevelPricingBounds.initialized) {
                return IPaymentProcessorSettings(address(this)).checkSyncTokenPricingBounds(tokenAddress, tokenId);
            }
            if (tokenLevelPricingBounds.isSet) {
                return (tokenLevelPricingBounds.floorPrice, tokenLevelPricingBounds.ceilingPrice);
            }
        }
        
        PricingBounds memory collectionLevelPricingBounds = appStorage().collectionPricingBounds[tokenAddress];
        if (collectionLevelPricingBounds.isSet) {
            return (collectionLevelPricingBounds.floorPrice, collectionLevelPricingBounds.ceilingPrice);
        }

        return (0, type(uint256).max);
    }

    /*************************************************************************/
    /*                           Order Fulfillment                           */
    /*************************************************************************/

    /**
     * @notice Dispenses tokens and proceeds for a single order.
     * 
     * @dev    This function may be called multiple times during a bulk execution.
     * @dev    Throws when a token false to dispense AND partial fills are disabled.
     * @dev    Throws when the taker did not supply enough native funds.
     * @dev    Throws when the fee on top amount is greater than the item price.
     * 
     * @param startingNativeFunds      The amount of native funds remaining at the beginning of the function call.
     * @param context                  The current execution context to determine the taker.
     * @param purchaser                The user that is buying the token.
     * @param seller                   The user that is selling the token.
     * @param paymentCoin              The ERC20 token used for payment, will be zero values for chain native token.
     * @param fnPointers               Struct containing the function pointers for dispensing tokens, sending payments
     *                                 and emitting events.
     * @param saleDetails              The order execution details.
     * @param feeOnTop                 The additional fee on top of the item sales price to be paid by the taker.
     *
     * @return endingNativeFunds       The amount of native funds remaining at the end of the function call.
     */
    function _fulfillSingleOrderWithFeeOnTop(
        uint256 startingNativeFunds,
        TradeContext memory context,
        address purchaser,
        address seller,
        address paymentCoin,
        FulfillOrderFunctionPointers memory fnPointers,
        Order memory saleDetails,
        FeeOnTop calldata feeOnTop
    ) internal returns (uint256 endingNativeFunds) {
        endingNativeFunds = startingNativeFunds;

        if (!fnPointers.funcDispenseToken(
                seller, 
                saleDetails.beneficiary, 
                saleDetails.tokenAddress, 
                saleDetails.tokenId, 
                saleDetails.amount)) {
            if (context.disablePartialFill) {
                revert PaymentProcessor__DispensingTokenWasUnsuccessful();
            } 
            else {
                // Nonce or some amount of fillable quantity was burned during order validation, but the item failed to 
                // fill.  Since partial fills are allowed, restore the nonce because we can't make assumptions about the
                // reason the fill failed. Order books should re-simulate there order for removal from order book if it 
                // failed because a fill is impossible.
                if (saleDetails.protocol == ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL) {
                    _restoreFillableItems(saleDetails.maker, context.orderDigest, saleDetails.amount);
                } else {
                    _restoreNonce(saleDetails.maker, saleDetails.nonce);
                }
            }
        } else {
            SplitProceeds memory proceeds =
                _computePaymentSplits(
                    context,
                    saleDetails.itemPrice,
                    saleDetails.tokenAddress,
                    saleDetails.tokenId,
                    saleDetails.marketplace,
                    saleDetails.marketplaceFeeNumerator,
                    saleDetails.maxRoyaltyFeeNumerator,
                    saleDetails.fallbackRoyaltyRecipient
                );

            uint256 feeOnTopAmount;
            if (feeOnTop.recipient != address(0)) {
                feeOnTopAmount = feeOnTop.amount;
                
                if (feeOnTopAmount > saleDetails.itemPrice) {
                    revert PaymentProcessor__FeeOnTopCannotBeGreaterThanItemPrice();
                }
            }

            if (saleDetails.paymentMethod == address(0)) {
                unchecked {
                    uint256 nativeProceedsToSpend = saleDetails.itemPrice + feeOnTopAmount;
                    if (endingNativeFunds < nativeProceedsToSpend) {
                        revert PaymentProcessor__RanOutOfNativeFunds();
                    }

                    endingNativeFunds -= nativeProceedsToSpend;
                }
            }

            if (feeOnTopAmount > 0) {
                unchecked {
                    uint256 feeOnTopAmountInfrastructure = feeOnTopAmount * context.protocolFees.feeOnTopProtocolTaxBps / FEE_DENOMINATOR;
                    fnPointers.funcPayout(feeOnTop.recipient, context.taker, paymentCoin, feeOnTopAmount - feeOnTopAmountInfrastructure);
                    
                    if (purchaser == context.taker) {
                        proceeds.infrastructureProceeds += feeOnTopAmountInfrastructure;
                    } else {
                        if (feeOnTopAmountInfrastructure > 0) {
                            fnPointers.funcPayout(context.protocolFees.protocolFeeReceiver, context.taker, paymentCoin, feeOnTopAmountInfrastructure);
                        }
                    }
                }
            }

            if (proceeds.infrastructureProceeds > 0) {
                fnPointers.funcPayout(context.protocolFees.protocolFeeReceiver, purchaser, paymentCoin, proceeds.infrastructureProceeds);
            }

            if (proceeds.royaltyProceeds > 0) {
                fnPointers.funcPayout(proceeds.royaltyRecipient, purchaser, paymentCoin, proceeds.royaltyProceeds);
            }

            if (proceeds.marketplaceProceeds > 0) {
                fnPointers.funcPayout(saleDetails.marketplace, purchaser, paymentCoin, proceeds.marketplaceProceeds);
            }

            if (proceeds.sellerProceeds > 0) {
                fnPointers.funcPayout(seller, purchaser, paymentCoin, proceeds.sellerProceeds);
            }

            fnPointers.funcEmitOrderExecutionEvent(context, saleDetails);
        }
    }

    /**
     * @notice Validates a sweep order and fulfills the order.
     *
     * @dev    Throws when the order protocol is for ERC721 and the amount is not set to one.
     * @dev    Throws when the order protocol is for ERC1155 and the amount is set to zero.
     * @dev    Throws when an invalid order protocol is detected.
     * @dev    Throws when the marketplace fee and maximum royalty fee will exceed the sales price of an item.
     * @dev    Throws when the sale price is outside the pricing constraints.
     * @dev    Throws when the current block time is greater than the order expiration.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker signature is invalid.
     * @dev    Throws when the maker's order nonce has already been used or was cancelled.
     * @dev    Throws when a partially fillable order has already been filled, cancelled or 
     * @dev    cannot be filled with the minimum fillable amount.
     * @dev    Throws when the taker did not supply enough native funds.
     *
     * @param context             The current execution context to determine the taker.
     * @param startingNativeFunds The amount of native funds available at the beginning of the order execution.
     * @param feeOnTop            The additional fee to add on top of the orders, paid by taker.
     * @param sweepOrder          The order information that is common to all items in the sweep.
     * @param items               An array of items that contains the order information unique to each item.
     * @param signedSellOrders    An array of maker signatures authorizing the order execution.
     * @param cosignatures        An array of additional cosignatures for cosigned orders, if applicable.
     * @param params              The sweep execution parameters.
     */
    function _validateAndFulfillSweepOrder(
        TradeContext memory context,
        uint256 startingNativeFunds,
        FeeOnTop calldata feeOnTop,
        SweepOrder calldata sweepOrder,
        SweepItem[] calldata items,
        SignatureECDSA[] memory signedSellOrders,
        Cosignature[] memory cosignatures,
        SweepExecutionParams memory params
    ) internal returns (uint256 endingNativeFunds) {
        endingNativeFunds = startingNativeFunds;

        uint256 sumListingPrices;
        uint256 dispensedPaymentValue;

        for(uint256 itemIndex;itemIndex < items.length;) {
            SweepItem calldata sweepItem = items[itemIndex];
            Order memory saleDetails = Order({
                protocol: sweepOrder.protocol,
                maker: sweepItem.maker,
                beneficiary: sweepOrder.beneficiary,
                marketplace: sweepItem.marketplace,
                fallbackRoyaltyRecipient: sweepItem.fallbackRoyaltyRecipient,
                paymentMethod: sweepOrder.paymentMethod,
                tokenAddress: sweepOrder.tokenAddress,
                tokenId: sweepItem.tokenId,
                amount: sweepItem.amount,
                itemPrice: uint240(sweepItem.itemPrice),
                nonce: sweepItem.nonce,
                expiration: sweepItem.expiration,
                marketplaceFeeNumerator: sweepItem.marketplaceFeeNumerator,
                maxRoyaltyFeeNumerator: sweepItem.maxRoyaltyFeeNumerator,
                requestedFillAmount: sweepItem.amount,
                minimumFillAmount: sweepItem.amount,
                protocolFeeVersion: sweepItem.protocolFeeVersion
            });

            if (context.protocolFeeVersion != saleDetails.protocolFeeVersion) {
                context.protocolFeeVersion = saleDetails.protocolFeeVersion;
                context.protocolFees = appStorage().protocolFeeVersions[saleDetails.protocolFeeVersion];
            }

            sumListingPrices += saleDetails.itemPrice;

            if (saleDetails.protocol == ORDER_PROTOCOLS_ERC721_FILL_OR_KILL) {
                if (saleDetails.amount != ONE) {
                    revert PaymentProcessor__AmountForERC721SalesMustEqualOne();
                }
            } else if (saleDetails.protocol == ORDER_PROTOCOLS_ERC1155_FILL_OR_KILL) {
                if (saleDetails.amount == 0) {
                    revert PaymentProcessor__AmountForERC1155SalesGreaterThanZero();
                }
            } else {
                revert PaymentProcessor__InvalidOrderProtocol();
            }

            if (saleDetails.marketplaceFeeNumerator + saleDetails.maxRoyaltyFeeNumerator > FEE_DENOMINATOR) {
                revert PaymentProcessor__MarketplaceAndRoyaltyFeesWillExceedSalePrice();
            }

            if (params.paymentSettings == PaymentSettings.PricingConstraints || params.paymentSettings == PaymentSettings.PricingConstraintsCollectionOnly) {
                _validateSalePriceInRange(
                    params.paymentSettings,
                    saleDetails.tokenAddress, 
                    saleDetails.tokenId, 
                    saleDetails.amount, 
                    saleDetails.itemPrice);
            }

            if (block.timestamp > saleDetails.expiration) {
                    revert PaymentProcessor__OrderHasExpired();
            }

            if (block.timestamp > context.protocolFees.versionExpiration) {
                revert PaymentProcessor__ProtocolFeeVersionExpired();
            }

            if (context.protocolFees.minimumProtocolFeeBps > FEE_DENOMINATOR) {
                revert PaymentProcessor__ProtocolFeeOrTaxExceedsCap();
            }

            _verifySaleApproval(
                context,
                saleDetails,
                signedSellOrders[itemIndex],
                cosignatures[itemIndex]
            );

            (endingNativeFunds, dispensedPaymentValue) = _dispenseAndPayoutSweepItem(
                context,
                saleDetails, 
                params,
                endingNativeFunds,
                dispensedPaymentValue
            );

            unchecked {
                ++itemIndex;
            }
        }

        if (feeOnTop.amount > sumListingPrices) {
            revert PaymentProcessor__FeeOnTopCannotBeGreaterThanItemPrice();
        }

        endingNativeFunds = _finalizePaymentAccumulatorDisbursement(
            context,
            params,
            feeOnTop,
            dispensedPaymentValue,
            sumListingPrices,
            endingNativeFunds
        );
    }

    /**
     * @notice Finalizes the payment accumulator disbursement for a sweep order.
     * 
     * @dev    Throws if the taker did not supply enough native funds.
     *
     * @param context                The current execution context to determine the taker.
     * @param params                 The sweep execution parameters.
     * @param feeOnTop               The additional fee to add on top of the orders, paid by taker.
     * @param dispensedPaymentValue  The total value of dispensed payments.
     * @param sumListingPrices       The total value of all listings.
     * @param startingNativeFunds    The amount of native funds available at the beginning of the order execution.
     */
    function _finalizePaymentAccumulatorDisbursement(
        TradeContext memory context,
        SweepExecutionParams memory params,
        FeeOnTop calldata feeOnTop,
        uint256 dispensedPaymentValue,
        uint256 sumListingPrices,
        uint256 startingNativeFunds
    ) internal returns (uint256 endingNativeFunds) {
        endingNativeFunds = startingNativeFunds;

        if (feeOnTop.recipient != address(0)) {
            if (feeOnTop.amount > 0) {
                uint256 feeOnTopAmountApp;
                uint256 feeOnTopAmount = feeOnTop.amount * dispensedPaymentValue / sumListingPrices;
                uint256 feeOnTopAmountInfrastructure = feeOnTopAmount * context.protocolFees.feeOnTopProtocolTaxBps / FEE_DENOMINATOR;
                unchecked {
                    feeOnTopAmountApp = feeOnTopAmount - feeOnTopAmountInfrastructure;
                }
                
                if (address(params.paymentCoin) == address(0)) {
                    if (endingNativeFunds < feeOnTopAmount) {
                        revert PaymentProcessor__RanOutOfNativeFunds();
                    }
    
                    unchecked {
                        endingNativeFunds -= feeOnTopAmount;
                    }
                }

                params.fnPointers.funcPayout(
                    feeOnTop.recipient, 
                    context.taker, 
                    params.paymentCoin, 
                    feeOnTopAmountApp
                );

                unchecked {
                    params.accumulator.accumulatedInfrastructureProceeds += feeOnTopAmountInfrastructure;
                }
            }
        }

        if(params.accumulator.accumulatedInfrastructureProceeds > 0) {
            params.fnPointers.funcPayout(
                context.protocolFees.protocolFeeReceiver,
                context.taker, 
                params.paymentCoin, 
                params.accumulator.accumulatedInfrastructureProceeds
            );
        }

        if(params.accumulator.accumulatedRoyaltyProceeds > 0) {
            params.fnPointers.funcPayout(
                params.accumulator.lastRoyaltyRecipient, 
                context.taker, 
                params.paymentCoin, 
                params.accumulator.accumulatedRoyaltyProceeds
            );
        }

        if(params.accumulator.accumulatedMarketplaceProceeds > 0) {
            params.fnPointers.funcPayout(
                params.accumulator.lastMarketplace, 
                context.taker, 
                params.paymentCoin, 
                params.accumulator.accumulatedMarketplaceProceeds
            );
        }

        if(params.accumulator.accumulatedSellerProceeds > 0) {
            params.fnPointers.funcPayout(
                params.accumulator.lastSeller, 
                context.taker, 
                params.paymentCoin, 
                params.accumulator.accumulatedSellerProceeds
            );
        }
    }

    /**
     * @notice Dispenses tokens and proceeds for a single sweep item.
     *
     * @dev    Throws when the taker did not supply enough native funds.
     * @dev    If the token transfer fails, the nonce is restored.
     *
     * @param context              The current execution context to determine the taker.
     * @param saleDetails          The order execution details.
     * @param params               The sweep execution parameters.
     * @param startingNativeFunds  The amount of native funds available at the beginning of the order execution.
     */
    function _dispenseAndPayoutSweepItem(
        TradeContext memory context,
        Order memory saleDetails,
        SweepExecutionParams memory params,
        uint256 startingNativeFunds,
        uint256 startingDispensedPaymentValue
    ) internal returns(
        uint256 endingNativeFunds,
        uint256 endingDispensedPaymentValue
    ) {
        endingNativeFunds = startingNativeFunds;
        endingDispensedPaymentValue = startingDispensedPaymentValue;

        if (params.fnPointers.funcDispenseToken(
                saleDetails.maker, 
                saleDetails.beneficiary, 
                saleDetails.tokenAddress, 
                saleDetails.tokenId, 
                saleDetails.amount)) {
            SplitProceeds memory proceeds =
                _computePaymentSplits(
                    context,
                    saleDetails.itemPrice,
                    saleDetails.tokenAddress,
                    saleDetails.tokenId,
                    saleDetails.marketplace,
                    saleDetails.marketplaceFeeNumerator,
                    saleDetails.maxRoyaltyFeeNumerator,
                    saleDetails.fallbackRoyaltyRecipient
                );

            unchecked {
                endingDispensedPaymentValue += saleDetails.itemPrice;
            }

            if (saleDetails.paymentMethod == address(0)) {
                if (endingNativeFunds < saleDetails.itemPrice) {
                    revert PaymentProcessor__RanOutOfNativeFunds();
                }

                unchecked {
                    endingNativeFunds -= saleDetails.itemPrice;
                }
            }

            if (proceeds.royaltyRecipient != params.accumulator.lastRoyaltyRecipient) {
                if(params.accumulator.accumulatedRoyaltyProceeds > 0) {
                    params.fnPointers.funcPayout(params.accumulator.lastRoyaltyRecipient, context.taker, params.paymentCoin, params.accumulator.accumulatedRoyaltyProceeds);
                }

                params.accumulator.lastRoyaltyRecipient = proceeds.royaltyRecipient;
                params.accumulator.accumulatedRoyaltyProceeds = 0;
            }

            if (saleDetails.marketplace != params.accumulator.lastMarketplace) {
                if(params.accumulator.accumulatedMarketplaceProceeds > 0) {
                    params.fnPointers.funcPayout(params.accumulator.lastMarketplace, context.taker, params.paymentCoin, params.accumulator.accumulatedMarketplaceProceeds);
                }

                params.accumulator.lastMarketplace = saleDetails.marketplace;
                params.accumulator.accumulatedMarketplaceProceeds = 0;
            }

            if (saleDetails.maker != params.accumulator.lastSeller) {
                if(params.accumulator.accumulatedSellerProceeds > 0) {
                    params.fnPointers.funcPayout(params.accumulator.lastSeller, context.taker, params.paymentCoin, params.accumulator.accumulatedSellerProceeds);
                }

                params.accumulator.lastSeller = saleDetails.maker;
                params.accumulator.accumulatedSellerProceeds = 0;
            }

            if (context.protocolFees.protocolFeeReceiver != params.accumulator.lastProtocolFeeRecipient) {
                if (params.accumulator.accumulatedInfrastructureProceeds > 0) {
                    params.fnPointers.funcPayout(params.accumulator.lastProtocolFeeRecipient, context.taker, params.paymentCoin, params.accumulator.accumulatedInfrastructureProceeds);
                }

                params.accumulator.lastProtocolFeeRecipient = context.protocolFees.protocolFeeReceiver;
                params.accumulator.accumulatedInfrastructureProceeds = 0;
            }

            unchecked {
                params.accumulator.accumulatedRoyaltyProceeds += proceeds.royaltyProceeds;
                params.accumulator.accumulatedMarketplaceProceeds += proceeds.marketplaceProceeds;
                params.accumulator.accumulatedSellerProceeds += proceeds.sellerProceeds;
                params.accumulator.accumulatedInfrastructureProceeds += proceeds.infrastructureProceeds;
            }

            params.fnPointers.funcEmitOrderExecutionEvent(context, saleDetails);
        } else {
            if (saleDetails.protocol != ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL) {
                _restoreNonce(saleDetails.maker, saleDetails.nonce);
            }
        }
    }

    /**
     * @notice Calculates the payment splits between seller, creator and marketplace based
     * @notice on on-chain royalty information or backfilled royalty information if on-chain
     * @notice data is unavailable.
     * 
     * @dev    Throws when ERC2981 on-chain royalties are set to an amount greater than the 
     * @dev    maker signed maximum.
     * 
     * @param salePrice                The sale price for the token being sold.
     * @param tokenAddress             The contract address for the token being sold.
     * @param tokenId                  The token id for the token being sold.
     * @param marketplaceFeeRecipient  The address that will receive the marketplace fee. 
     *                                 If zero, no marketplace fee will be applied.
     * @param marketplaceFeeNumerator  The fee numerator for calculating marketplace fees.
     * @param maxRoyaltyFeeNumerator  The maximum royalty fee authorized by the order maker.
     * @param fallbackRoyaltyRecipient The address that will receive royalties if not defined onchain.
     * @param context                  The royalty backfill and bounty information set onchain by the creator.
     *
     * @return proceeds A struct containing the split of payment and receiving addresses for the
     *                  seller, creator and marketplace.
     */
    function _computePaymentSplits(
        TradeContext memory context,
        uint256 salePrice,
        address tokenAddress,
        uint256 tokenId,
        address marketplaceFeeRecipient,
        uint256 marketplaceFeeNumerator,
        uint256 maxRoyaltyFeeNumerator,
        address fallbackRoyaltyRecipient
    ) internal view returns (SplitProceeds memory proceeds) {

        proceeds.sellerProceeds = salePrice;

        bool useBackfill = context.useRoyaltyBackfillAsRoyaltySource;

        address royaltyReceiver;
        uint256 royaltyAmount;
        if(!useBackfill) {
            (
                royaltyReceiver, 
                royaltyAmount, 
                useBackfill
            ) = _safeRoyaltyInfo(tokenAddress, tokenId, salePrice);

            if (royaltyAmount == 0) {
                useBackfill = true;
            }
        }
        unchecked {
            if (useBackfill) {
                // If the token doesn't implement the royaltyInfo function or creator has set
                // the use backfill royalty flag, then check if there are backfilled royalties.
                if (context.backfillReceiver != address(0)) {
                    if (context.backfillNumerator > maxRoyaltyFeeNumerator) {
                        revert PaymentProcessor__OnchainRoyaltiesExceedMaximumApprovedRoyaltyFee();
                    }
        
                    proceeds.royaltyRecipient = context.backfillReceiver;
                    proceeds.royaltyProceeds = 
                        (salePrice * context.backfillNumerator) / FEE_DENOMINATOR;
        
                    proceeds.sellerProceeds -= proceeds.royaltyProceeds;
                } else if (fallbackRoyaltyRecipient != address(0)) {
                    proceeds.royaltyRecipient = fallbackRoyaltyRecipient;
                    proceeds.royaltyProceeds = (salePrice * maxRoyaltyFeeNumerator) / FEE_DENOMINATOR;
        
                    proceeds.sellerProceeds -= proceeds.royaltyProceeds;
                }
            } else {
                if (royaltyReceiver == address(0)) {
                    royaltyAmount = 0;
                }
        
                if (royaltyAmount > 0) {
                    if (royaltyAmount > (salePrice * maxRoyaltyFeeNumerator) / FEE_DENOMINATOR) {
                        revert PaymentProcessor__OnchainRoyaltiesExceedMaximumApprovedRoyaltyFee();
                    }
        
                    proceeds.royaltyRecipient = royaltyReceiver;
                    proceeds.royaltyProceeds = royaltyAmount;
        
                    proceeds.sellerProceeds -= royaltyAmount;
                }
            }

            if (marketplaceFeeRecipient != address(0)) {
                proceeds.marketplaceProceeds = (salePrice * marketplaceFeeNumerator) / FEE_DENOMINATOR;
                proceeds.sellerProceeds -= proceeds.marketplaceProceeds;

                if (context.bountyNumerator > 0) {
                    if (context.exclusiveMarketplace == address(0) || 
                        context.exclusiveMarketplace == marketplaceFeeRecipient) {
                        uint256 royaltyBountyProceeds = 
                            proceeds.royaltyProceeds * context.bountyNumerator / FEE_DENOMINATOR;
                    
                        if (royaltyBountyProceeds > 0) {
                            proceeds.royaltyProceeds -= royaltyBountyProceeds;
                            proceeds.marketplaceProceeds += royaltyBountyProceeds;
                        }
                    }
                }

                proceeds.infrastructureProceeds = 
                    proceeds.marketplaceProceeds * context.protocolFees.marketplaceFeeProtocolTaxBps / FEE_DENOMINATOR;
                proceeds.marketplaceProceeds -= proceeds.infrastructureProceeds;
            }

            uint256 minInfrastructureFee = (salePrice * context.protocolFees.minimumProtocolFeeBps) / FEE_DENOMINATOR;
            if (proceeds.infrastructureProceeds < minInfrastructureFee) {
                uint256 shortfall = minInfrastructureFee - proceeds.infrastructureProceeds;
                if (shortfall > proceeds.sellerProceeds) {
                    proceeds.infrastructureProceeds += proceeds.sellerProceeds;
                    proceeds.sellerProceeds = 0;
                } else {
                    proceeds.sellerProceeds -= shortfall;
                    proceeds.infrastructureProceeds = minInfrastructureFee;
                }
            }
        }
    }

    /**
     * @notice Transfers chain native token to `to`.
     * 
     * @dev    Throws when the native token transfer call reverts.
     *
     * @param to                   The address that will receive chain native tokens.
     * @param proceeds             The amount of chain native token value to transfer.
     */
    function _pushProceeds(address to, uint256 proceeds) internal {
        bool success;

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

        if (!success) {
            revert PaymentProcessor__FailedToTransferProceeds();
        }
    }

    /**
     * @notice Refunds the taker any unspent native funds.
     * 
     * @param remainingNativeFunds The amount of native funds that were not spent.
     * @param taker                The address that will receive the unspent native funds.
     */
    function _refundUnspentNativeFunds(uint256 remainingNativeFunds, address taker) internal {
        if (remainingNativeFunds > 0) {
            _pushProceeds(taker, remainingNativeFunds);
        }
    }

    /**
     * @notice Transfers chain native token to `payee`.
     * 
     * @dev    Throws when the native token transfer call reverts.
     *
     * @param payee     The address that will receive chain native tokens.
     * @param proceeds  The amount of chain native token value to transfer.
     */
    function _payoutNativeCurrency(
        address payee, 
        address /*payer*/, 
        address /*paymentCoin*/, 
        uint256 proceeds) internal {
        _pushProceeds(payee, proceeds);
    }

    /**
     * @notice Transfers ERC20 tokens to from `payer` to `payee`.
     * 
     * @dev    Throws when the ERC20 transfer call reverts.
     *
     * @param payee The address that will receive ERC20 tokens.
     * @param payer The address the ERC20 tokens will be sent from.
     * @param paymentCoin The ERC20 token being transferred.
     * @param proceeds The amount of token value to transfer.
     */
    function _payoutCoinCurrency(
        address payee, 
        address payer, 
        address paymentCoin, 
        uint256 proceeds) internal {
        if (SafeERC20.safeTransferFrom(paymentCoin, payer, payee, proceeds)) {
            revert PaymentProcessor__FailedToTransferProceeds();
        }
    }

    /**
     * @notice Calls the token contract to transfer an ERC721 token from the seller to the buyer.
     * 
     * @dev    This will **NOT** throw if the transfer fails. It will instead return false
     * @dev    so that the calling function can handle the failed transfer.
     * @dev    Returns true if the transfer does not revert.
     * 
     * @param from         The seller of the token.
     * @param to           The beneficiary of the order execution.
     * @param tokenAddress The contract address for the token being transferred.
     * @param tokenId      The token id for the order.
     */
    function _dispenseERC721Token(
        address from, 
        address to, 
        address tokenAddress, 
        uint256 tokenId, 
        uint256 /*amount*/) internal returns (bool) {
        try IERC721(tokenAddress).transferFrom(from, to, tokenId) {
            return true;
        } catch {
            return false;
        }
    }

    /**
     * @notice Calls the token contract to transfer an ERC1155 token from the seller to the buyer.
     * 
     * @dev    This will **NOT** throw if the transfer fails. It will instead return false
     * @dev    so that the calling function can handle the failed transfer.
     * @dev    Returns true if the transfer does not revert.
     * 
     * @param from         The seller of the token.
     * @param to           The beneficiary of the order execution.
     * @param tokenAddress The contract address for the token being transferred.
     * @param tokenId      The token id for the order.
     * @param amount       The quantity of the token to transfer.
     */
    function _dispenseERC1155Token(
        address from, 
        address to, 
        address tokenAddress, 
        uint256 tokenId, 
        uint256 amount) internal returns (bool) {
        try IERC1155(tokenAddress).safeTransferFrom(from, to, tokenId, amount, "") {
            return true;
        } catch {
            return false;
        }
    }

    /**
     * @notice Emits a a BuyListingERC721 event.
     * 
     * @param context The current execution context to determine the taker.
     * @param saleDetails The order execution details.
     */
    function _emitBuyListingERC721Event(TradeContext memory context, Order memory saleDetails) internal {
        emit BuyListingERC721(
                context.taker,
                saleDetails.maker,
                saleDetails.tokenAddress,
                saleDetails.beneficiary,
                saleDetails.paymentMethod,
                saleDetails.tokenId,
                saleDetails.itemPrice);
    }

    /**
     * @notice Emits a BuyListingERC1155 event.
     * 
     * @param context The current execution context to determine the taker.
     * @param saleDetails The order execution details.
     */
    function _emitBuyListingERC1155Event(TradeContext memory context, Order memory saleDetails) internal {
        emit BuyListingERC1155(
                context.taker,
                saleDetails.maker,
                saleDetails.tokenAddress,
                saleDetails.beneficiary,
                saleDetails.paymentMethod,
                saleDetails.tokenId,
                saleDetails.amount,
                saleDetails.itemPrice);
    }

    /**
     * @notice Emits an AcceptOfferERC721 event.
     * 
     * @param context The current execution context to determine the taker.
     * @param saleDetails The order execution details.
     */
    function _emitAcceptOfferERC721Event(TradeContext memory context, Order memory saleDetails) internal {
        emit AcceptOfferERC721(
                context.taker,
                saleDetails.maker,
                saleDetails.tokenAddress,
                saleDetails.beneficiary,
                saleDetails.paymentMethod,
                saleDetails.tokenId,
                saleDetails.itemPrice);
    }

    /**
     * @notice Emits an AcceptOfferERC1155 event.
     * 
     * @param context The current execution context to determine the taker.
     * @param saleDetails The order execution details.
     */
    function _emitAcceptOfferERC1155Event(TradeContext memory context, Order memory saleDetails) internal {
        emit AcceptOfferERC1155(
                context.taker,
                saleDetails.maker,
                saleDetails.tokenAddress,
                saleDetails.beneficiary,
                saleDetails.paymentMethod,
                saleDetails.tokenId,
                saleDetails.amount,
                saleDetails.itemPrice);
    }

    /**
     * @notice Returns the appropriate function pointers for payouts, dispensing tokens and event emissions.
     *
     * @param side The taker's side of the order.
     * @param paymentMethod The payment method for the order. If address zero, the chain native token.
     * @param orderProtocol The type of token and fill method for the order.
     */
    function _getOrderFulfillmentFunctionPointers(
        Sides side,
        address paymentMethod,
        uint256 orderProtocol
    ) internal pure returns (FulfillOrderFunctionPointers memory orderFulfillmentFunctionPointers) {
        orderFulfillmentFunctionPointers = FulfillOrderFunctionPointers({
            funcPayout: paymentMethod == address(0) ? _payoutNativeCurrency : _payoutCoinCurrency,
            funcDispenseToken: orderProtocol == ORDER_PROTOCOLS_ERC721_FILL_OR_KILL ? _dispenseERC721Token : _dispenseERC1155Token,
            funcEmitOrderExecutionEvent: orderProtocol == ORDER_PROTOCOLS_ERC721_FILL_OR_KILL ? 
                (side == Sides.Buy ? _emitBuyListingERC721Event : _emitAcceptOfferERC721Event) : 
                (side == Sides.Buy ?_emitBuyListingERC1155Event : _emitAcceptOfferERC1155Event)
        });
    }

    /*************************************************************************/
    /*                        Signature Verification                         */
    /*************************************************************************/

    /**
     * @notice Updates the remaining fillable amount and order status for partially fillable orders.
     * @notice Performs checks for minimum fillable amount and order status.
     *
     * @dev    Throws when the remaining fillable amount is less than the minimum fillable amount requested.
     * @dev    Throws when the order status is not open.
     *
     * @param account             The maker account for the order.
     * @param orderDigest         The hash digest of the order execution details.
     * @param orderStartAmount    The original amount for the partially fillable order.
     * @param requestedFillAmount The amount the taker is requesting to fill.
     * @param minimumFillAmount   The minimum amount the taker is willing to fill.
     *
     * @return quantityToFill     Lesser of remainingFillableAmount and requestedFillAmount.
     */
    function _checkAndUpdateRemainingFillableItems(
        address account,
        bytes32 orderDigest, 
        uint256 orderStartAmount,
        uint256 requestedFillAmount,
        uint256 minimumFillAmount
    ) internal returns (uint256 quantityToFill) {
        if(orderStartAmount > type(uint248).max) {
            revert PaymentProcessor__AmountExceedsMaximum();
        }

        quantityToFill = requestedFillAmount;
        PartiallyFillableOrderStatus storage partialFillStatus = 
            appStorage().partiallyFillableOrderStatuses[account][orderDigest];
    
        if (partialFillStatus.state == PartiallyFillableOrderState.Open) {
            if (partialFillStatus.remainingFillableQuantity == 0) {
                partialFillStatus.remainingFillableQuantity = uint248(orderStartAmount);
                emit OrderDigestOpened(orderDigest, account, orderStartAmount);
            }

            if (quantityToFill > partialFillStatus.remainingFillableQuantity) {
                quantityToFill = partialFillStatus.remainingFillableQuantity;
            }

            if (quantityToFill < minimumFillAmount) {
                revert PaymentProcessor__UnableToFillMinimumRequestedQuantity();
            }

            unchecked {
                partialFillStatus.remainingFillableQuantity -= uint248(quantityToFill);
                emit OrderDigestItemsFilled(orderDigest, account, quantityToFill);
            }

            if (partialFillStatus.remainingFillableQuantity == 0) {
                partialFillStatus.state = PartiallyFillableOrderState.Filled;
                emit OrderDigestInvalidated(orderDigest, account, false);
            }
        } else {
            revert PaymentProcessor__OrderIsEitherCancelledOrFilled();
        }
    }

    /**
     * @notice Restored items to a partially fillable order when the items failed to dispense in a bulk order fill.
     *
     * @param account             The maker account for the order.
     * @param orderDigest         The hash digest of the order execution details.
     * @param unfilledAmount      The amount that was subtracted from the order that needs to be added back.
     *
     */
    function _restoreFillableItems(address account, bytes32 orderDigest, uint256 unfilledAmount) internal {
        if (unfilledAmount > 0) {
            PartiallyFillableOrderStatus storage partialFillStatus = 
                appStorage().partiallyFillableOrderStatuses[account][orderDigest];

            unchecked {
                partialFillStatus.remainingFillableQuantity += uint248(unfilledAmount);
            }

            partialFillStatus.state = PartiallyFillableOrderState.Open;

            emit OrderDigestItemsRestored(orderDigest, account, unfilledAmount);
        }
    }

    /**
     * @notice Invalidates a maker's nonce and emits a NonceInvalidated event.
     * 
     * @dev    Throws when the nonce has already been invalidated.
     * 
     * @param account         The maker account to invalidate `nonce` of.
     * @param nonce           The nonce to invalidate.
     * @param wasCancellation If true, the invalidation is the maker cancelling the nonce. 
     *                        If false, from the nonce being used to execute an order.
     */
    function _checkAndInvalidateNonce(
        address account, 
        uint256 nonce, 
        bool wasCancellation) internal returns (uint256) {

        // The following code is equivalent to, but saves 115 gas units:
        // 
        // mapping(uint256 => uint256) storage ptrInvalidatedSignatureBitmap = 
        //     appStorage().invalidatedSignatures[account];

        // unchecked {
        //     uint256 slot = nonce / 256;
        //     uint256 offset = nonce % 256;
        //     uint256 slotValue = ptrInvalidatedSignatureBitmap[slot];
        // 
        //     if (((slotValue >> offset) & ONE) == ONE) {
        //         revert PaymentProcessor__SignatureAlreadyUsedOrRevoked();
        //     }
        // 
        //     ptrInvalidatedSignatureBitmap[slot] = (slotValue | ONE << offset);
        // }

        unchecked {
            if (uint256(appStorage().invalidatedSignatures[account][uint248(nonce >> 8)] ^= (ONE << uint8(nonce))) & 
                (ONE << uint8(nonce)) == ZERO) {
                revert PaymentProcessor__SignatureAlreadyUsedOrRevoked();
            }
        }

        emit NonceInvalidated(nonce, account, wasCancellation);

        return appStorage().masterNonces[account];
    }

    /**
     * @notice After a maker's nonce is invalidated, should the order item fail to transfer
     *         we need to restore the nonce so order cannot be griefed.  Emits a NonceRestored event.
     * 
     * @dev    Throws when the nonce has already been invalidated.
     * 
     * @param account         The maker account to restore `nonce` of.
     * @param nonce           The nonce to restore.
     */
    function _restoreNonce(address account, uint256 nonce) internal {
        unchecked {
            if (uint256(appStorage().invalidatedSignatures[account][uint248(nonce >> 8)] ^= (ONE << uint8(nonce))) & 
                (ONE << uint8(nonce)) != ZERO) {
                revert PaymentProcessor__SignatureNotUsedOrRevoked();
            }
        }

        emit NonceRestored(nonce, account);
    }

    /**
     * @notice Updates the state of a maker's order to cancelled and remaining fillable quantity to zero.
     *
     * @dev    Throws when the current order state is not open.
     *
     * @param account     The maker account to invalid the order for.
     * @param orderDigest The hash digest of the order to invalidate.
     */
    function _revokeOrderDigest(address account, bytes32 orderDigest) internal {
        PartiallyFillableOrderStatus storage partialFillStatus = 
            appStorage().partiallyFillableOrderStatuses[account][orderDigest];
    
        if (partialFillStatus.state == PartiallyFillableOrderState.Open) {
            partialFillStatus.state = PartiallyFillableOrderState.Cancelled;
            partialFillStatus.remainingFillableQuantity = 0;
            emit OrderDigestInvalidated(orderDigest, account, true);
        } else {
            revert PaymentProcessor__OrderIsEitherCancelledOrFilled();
        }
    }

    /**
     * @notice Invalidates a maker's nonce and emits a NonceInvalidated event.
     *
     * @dev    Skips nonce invalidation for partial fillable orders.
     * @dev    Throws when the nonce has already been invalidated.
     *
     * @param saleDetails The order execution details.
     */
    function _checkAndInvalidateNonceForFillOrKillOrders(
        Order memory saleDetails
    ) internal returns (uint256 masterNonce) {
        masterNonce = 
            saleDetails.protocol == ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL ? 
                appStorage().masterNonces[saleDetails.maker] :
                _checkAndInvalidateNonce(saleDetails.maker, saleDetails.nonce, false);
    }

    /**
     * Verifies offer is approved by the maker.
     *
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker signature is invalid.
     * @dev    Throws when the maker's order nonce has already been used or was cancelled.
     * @dev    Throws when a partially fillable order has already been filled, cancelled or 
     * @dev    cannot be filled with the minimum fillable amount.
     * 
     * @param offerType               The type of offer to execute.
     * @param context                 The current execution context to determine the taker.
     * @param saleDetails             The order execution details.
     * @param signature               The order maker's signature.
     * @param cosignature             The cosignature from the order cosigner, if applicable.
     * @param tokenSetProof           The token set proof that contains the root hash for the merkle
     *                                tree of allowed tokens for accepting the maker's offer.
     */
    function _verifyBidOrderSignatures(
        uint256 offerType,
        TradeContext memory context,
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature,
        TokenSetProof calldata tokenSetProof
    ) internal returns (uint256 quantityToFill) {
        if (offerType == OFFER_TYPE_COLLECTION_OFFER) {
            quantityToFill = _verifyCollectionOffer(
                context, 
                saleDetails, 
                signature, 
                cosignature);
        } else if (offerType == OFFER_TYPE_ITEM_OFFER) {
            quantityToFill = _verifyItemOffer(
                context,
                saleDetails, 
                signature, 
                cosignature);
        } else if (offerType == OFFER_TYPE_TOKEN_SET_OFFER) {
            quantityToFill = _verifyTokenSetOffer(
                context, 
                saleDetails, 
                signature, 
                cosignature,
                tokenSetProof);
        } else {
            revert PaymentProcessor__InvalidOfferType();
        }
    }

    /**
     * @notice Verifies a token offer is approved by the maker.
     *
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker signature is invalid.
     * @dev    Throws when the maker's order nonce has already been used or was cancelled.
     * @dev    Throws when a partially fillable order has already been filled, cancelled or 
     * @dev    cannot be filled with the minimum fillable amount.
     *
     * @param context       The current execution context to determine the taker.
     * @param saleDetails   The order execution details.
     * @param signature     The order maker's signature.
     * @param cosignature   The cosignature from the order cosigner, if applicable.
     * 
     * @return quantityToFill The amount of the token that will be filled for this order.
     */
    function _verifyItemOffer(
        TradeContext memory context, 
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature
    ) internal returns (uint256 quantityToFill) {
        quantityToFill = _verifyOrderSignatures(
            context, 
            saleDetails, 
            signature, 
            cosignature, 
            _generateItemOfferOrderHash(
                saleDetails,
                saleDetails.maker,
                cosignature.signer,
                _checkAndInvalidateNonceForFillOrKillOrders(saleDetails)
            )
        );
    }

    /**
     * @notice Verifies a collection offer is approved by the maker.
     *
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker signature is invalid.
     * @dev    Throws when the maker's order nonce has already been used or was cancelled.
     * @dev    Throws when a partially fillable order has already been filled, cancelled or 
     * @dev    cannot be filled with the minimum fillable amount.
     *
     * @param context       The current execution context to determine the taker.
     * @param saleDetails   The order execution details.
     * @param signature     The order maker's signature.
     * @param cosignature   The cosignature from the order cosigner, if applicable.
     * 
     * @return quantityToFill The amount of the token that will be filled for this order.
     */
    function _verifyCollectionOffer(
        TradeContext memory context, 
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature
    ) internal returns (uint256 quantityToFill) {
        quantityToFill = _verifyOrderSignatures(
            context, 
            saleDetails, 
            signature, 
            cosignature, 
            _generateCollectionOfferOrderHash(
                saleDetails,
                saleDetails.maker,
                cosignature.signer,
                _checkAndInvalidateNonceForFillOrKillOrders(saleDetails)
            )
        );
    }

    /**
     * @notice Verifies a token set offer is approved by the maker.
     *
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker signature is invalid.
     * @dev    Throws when the maker's order nonce has already been used or was cancelled.
     * @dev    Throws when a partially fillable order has already been filled, cancelled or 
     * @dev    cannot be filled with the minimum fillable amount.
     *
     * @param context       The current execution context to determine the taker.
     * @param saleDetails   The order execution details.
     * @param signature     The order maker's signature.
     * @param tokenSetProof The token set proof that contains the root hash for the merkle  
     *                      tree of allowed tokens for accepting the maker's offer.
     * @param cosignature   The cosignature from the order cosigner, if applicable.
     * 
     * @return quantityToFill The amount of the token that will be filled for this order.
     */
    function _verifyTokenSetOffer(
        TradeContext memory context, 
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature,
        TokenSetProof calldata tokenSetProof
    ) internal returns (uint256 quantityToFill) {
        bytes32 orderHash = 
            _generateTokenSetOfferOrderHash(
                tokenSetProof,
                saleDetails,
                saleDetails.maker,
                cosignature.signer,
                _checkAndInvalidateNonceForFillOrKillOrders(saleDetails)
            );

        quantityToFill = _verifyOrderSignatures(
            context, 
            saleDetails, 
            signature, 
            cosignature, 
            orderHash
        );
    }

    /**
     * @notice Verifies a listing is approved by the maker.
     *
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker signature is invalid.
     * @dev    Throws when the maker's order nonce has already been used or was cancelled.
     * @dev    Throws when a partially fillable order has already been filled, cancelled or 
     * @dev    cannot be filled with the minimum fillable amount.
     *
     * @param context     The current execution context to determine the taker.
     * @param saleDetails The order execution details.
     * @param signature   The order maker's signature.
     * @param cosignature The cosignature from the order cosigner, if applicable.
     * 
     * @return quantityToFill The amount of the token that will be filled for this order.
     */
    function _verifySaleApproval(
        TradeContext memory context, 
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature
    ) internal returns (uint256 quantityToFill) {
        quantityToFill = _verifyOrderSignatures(
            context, 
            saleDetails, 
            signature, 
            cosignature, 
            _generateListingOrderHash(
                saleDetails,
                saleDetails.maker,
                cosignature.signer,
                _checkAndInvalidateNonceForFillOrKillOrders(saleDetails)
            )
        );
    }

    /**
     * @notice Verifies a listing is approved by the maker.
     *
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker signature is invalid.
     * @dev    Throws when the maker's order nonce has already been used or was cancelled.
     * @dev    Throws when a partially fillable order has already been filled, cancelled or
     * @dev    cannot be filled with the minimum fillable amount.
     *
     * @param context     The current execution context to determine the taker.
     * @param saleDetails The order execution details.
     * @param signature   The order maker's signature.
     * @param cosignature The cosignature from the order cosigner, if applicable.
     * @param orderHash   The hash digest of the order execution details.
     */
    function _verifyOrderSignatures(
        TradeContext memory context,
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature,
        bytes32 orderHash
    ) internal returns (uint256 quantityToFill) {
        if (cosignature.signer != address(0)) {
            _verifyCosignature(context, signature, cosignature);
        }

         bytes32 orderDigest = _hashTypedDataV4(_cachedDomainSeparator, orderHash);

        _verifyMakerSignature(saleDetails.maker, signature, orderDigest);

        if (saleDetails.protocol == ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL) {
            quantityToFill = _checkAndUpdateRemainingFillableItems(
                saleDetails.maker, 
                orderHash, 
                saleDetails.amount, 
                saleDetails.requestedFillAmount,
                saleDetails.minimumFillAmount);
            context.orderDigest = orderHash;
        } else {
            quantityToFill = saleDetails.amount;
        }
    }

    /**
     * @notice Reverts a transaction when the recovered signer is not the order maker.
     *
     * @dev Throws when the recovered signer for the `signature` and `digest` does not match the order maker AND
     * @dev - The maker address does not have deployed code, OR 
     * @dev - The maker contract does not return the correct ERC1271 value to validate the signature.
     *
     * @param maker The adress for the order maker.
     * @param signature The order maker's signature.
     * @param digest The hash digest of the order.
     */
    function _verifyMakerSignature(address maker, SignatureECDSA memory signature, bytes32 digest ) internal view {
        (bool isError, address signer) = _tryEcdsaRecover(digest, signature.v, signature.r, signature.s);
        if (maker != signer || isError) {
            if (maker.code.length > 0) {
                _verifyEIP1271Signature(maker, digest, signature);
            } else {
                revert PaymentProcessor__UnauthorizedOrder();
            }
        }
    }

    /**
     * @notice Reverts the transaction when a supplied cosignature is not valid.
     *
     * @dev    Throws when the current block timestamp is greater than the cosignature expiration.
     * @dev    Throws when the order taker does not match the cosignature taker.
     * @dev    Throws when the cosigner has self-destructed their account.
     * @dev    Throws when the recovered address for the cosignature does not match the cosigner address.
     * 
     * @param context     The current execution context to determine the order taker.
     * @param signature   The order maker's signature.
     * @param cosignature The cosignature from the order cosigner.
     */
    function _verifyCosignature(
        TradeContext memory context, 
        SignatureECDSA memory signature, 
        Cosignature memory cosignature
    ) internal view {
        if (block.timestamp > cosignature.expiration) {
            revert PaymentProcessor__CosignatureHasExpired();
        }

        if (context.taker != cosignature.taker) {
            revert PaymentProcessor__UnauthorizedTaker();
        }

        if (appStorage().destroyedCosigners[cosignature.signer]) {
            revert PaymentProcessor__CosignerHasSelfDestructed();
        }

        if (cosignature.signer != _ecdsaRecover(
            _hashTypedDataV4(
                _cachedDomainSeparator, 
                EfficientHash.efficientHash(
                    COSIGNATURE_HASH,
                    bytes32(signature.v),
                    signature.r,
                    signature.s,
                    bytes32(cosignature.expiration),
                    bytes32(uint256(uint160(cosignature.taker)))
                )
            ), 
            cosignature.v, 
            cosignature.r, 
            cosignature.s)) {
            revert PaymentProcessor__NotAuthorizedByCosigner();
        }
    }

    /**
     * @notice Reverts the transaction if the contract at `signer` does not return the ERC1271
     * @notice isValidSignature selector when called with `hash`.
     * 
     * @dev    Throws when attempting to verify a signature from an address that has deployed
     * @dev    contract code using ERC1271 and the contract does not return the isValidSignature
     * @dev    function selector as its return value.
     *
     * @param signer The signer address for a maker order that has deployed contract code.
     * @param hash The ERC712 hash value of the order.
     * @param signature The signature for the order hash.
     */
    function _verifyEIP1271Signature(
        address signer, 
        bytes32 hash, 
        SignatureECDSA memory signature
    ) internal view {
        if (!_safeIsValidSignature(signer, hash, signature.v, signature.r, signature.s)) {
            revert PaymentProcessor__EIP1271SignatureInvalid();
        }
    }

    /**
     * @notice A gas efficient, and fallback-safe way to call the isValidSignature function for EIP-1271.
     *
     * @param signer     The EIP-1271 signer to call to check for a valid signature.
     * @param hash       The hash digest to verify with the EIP-1271 signer.
     * @param v         The `v` value of the signature
     * @param r         The `r` value of the signature
     * @param s         The `s` value of the signature
     * 
     * @return isValid   True if the EIP-1271 signer returns the EIP-1271 magic value.
     */
    function _safeIsValidSignature(
        address signer,
        bytes32 hash,
        uint256 v,
        bytes32 r,
        bytes32 s
    ) private view returns(bool isValid) {
        if (v > type(uint8).max) {
            revert PaymentProcessor__InvalidSignatureV();
        }

        assembly {
            function _callIsValidSignature(_signer, _hash, _r, _s, _v) -> _isValid {
                let ptr := mload(0x40)
                // store isValidSignature(bytes32,bytes) selector
                mstore(ptr, hex"1626ba7e")
                // store bytes32 hash value in abi encoded location
                mstore(add(ptr, 0x04), _hash)
                // store abi encoded location of the bytes signature data
                mstore(add(ptr, 0x24), 0x40)
                // store bytes signature length
                mstore(add(ptr, 0x44), 0x41)
                // store the signature `_r`, `_v` and `_s` in memory
                // `_v` is stored before `_s` to avoid shifting
                mstore(add(ptr, 0x64), _r)
                mstore(add(ptr, 0x85), _v)
                mstore(add(ptr, 0x84), _s)
                // update free memory pointer, 0xC4 is the length of calldata
                mstore(0x40, add(ptr, 0xC4))

                // static call _signer with abi encoded data
                // skip return data check if call failed or return data size is not at least 32 bytes
                if and(iszero(lt(returndatasize(), 0x20)), staticcall(gas(), _signer, ptr, 0xC4, 0x00, 0x20)) {
                    // check if return data is equal to isValidSignature magic value
                    _isValid := eq(mload(0x00), hex"1626ba7e")
                    leave
                }
            }
            isValid := _callIsValidSignature(signer, hash, r, s, v)
        }
    }

    /**
     * @notice Recovers the signer address from a hash and signature.
     * 
     * @dev Throws when `v` is greater than `type(uint8).max`.
     * @dev Throws when the recovered address is zero.
     *
     * @param digest The hash digest that was signed.
     * @param v The v-value of the signature.
     * @param r The r-value of the signature.
     * @param s The s-value of the signature.
     *
     * @return signer The recovered signer address from the signature.
     */
    function _ecdsaRecover(
        bytes32 digest, 
        uint256 v, 
        bytes32 r, 
        bytes32 s
    ) internal pure returns (address signer) {
        bool isError;
        (isError, signer) = _tryEcdsaRecover(digest, v, r, s);
        if(isError) {
            revert PaymentProcessor__UnauthorizedOrder();
        }
    }

    /**
     * @notice Recovers the signer address from a hash and signature.
     * 
     * @dev     Does **NOT** revert if invalid input values are provided or `signer` is recovered as address(0)
     * @dev     Returns an `isError` value in those conditions that is handled upstream
     *
     * @param digest The hash digest that was signed.
     * @param v The v-value of the signature.
     * @param r The r-value of the signature.
     * @param s The s-value of the signature.
     *
     * @return isError  True if the ECDSA function is provided invalid inputs
     * @return signer   The recovered signer address from the signature.
     */
    function _tryEcdsaRecover(
        bytes32 digest, 
        uint256 v, 
        bytes32 r, 
        bytes32 s
    ) internal pure returns (bool isError, address signer) {
        if (v > type(uint8).max) {
            return (true, address(0));
        }

        signer = ecrecover(digest, uint8(v), r, s);
        isError = (signer == address(0));
    }

    /**
     * @notice Returns the EIP-712 hash digest for `domainSeparator` and `structHash`.
     * 
     * @param domainSeparator The domain separator for the EIP-712 hash.
     * @param structHash The hash of the EIP-712 struct.
     */
    function _hashTypedDataV4(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return ECDSA.toTypedDataHash(domainSeparator, structHash);
    }

    /*************************************************************************/
    /*                             Miscellaneous                             */
    /*************************************************************************/

    /**
     * @notice Pulls settings from the CollectionSettingsRegistry contract and updates the
     * @notice applicable cached collection settings in the PaymentProcessor contract.
     * 
     * @param tokenAddress The contract address for the token to update settings for.
     */
    function _syncCollectionSettings(address tokenAddress) internal {
        bytes32[] memory noExtensions;

        (
            CollectionRegistryPaymentSettings memory collectionCoreSettings,
            RegistryPricingBounds memory collectionPricingBounds,
            address constrainedPricingPaymentMethod,
            address exclusiveBountyReceiver,,
        ) = ICollectionSettingsRegistry(collectionSettingsRegistry).getCollectionSettings(tokenAddress, noExtensions, noExtensions);

        uint8 flags = uint8(collectionCoreSettings.extraData);

        appStorage().collectionPaymentSettings[tokenAddress] = CollectionPaymentSettings({
            initialized: true,
            paymentSettings: PaymentSettings(collectionCoreSettings.paymentSettingsType),
            paymentMethodWhitelistId: collectionCoreSettings.paymentMethodWhitelistId,
            royaltyBackfillReceiver: collectionCoreSettings.royaltyBackfillReceiver,
            royaltyBackfillNumerator: collectionCoreSettings.royaltyBackfillNumerator,
            royaltyBountyNumerator: collectionCoreSettings.royaltyBountyNumerator,
            flags: flags
        });

        if (PaymentSettings(collectionCoreSettings.paymentSettingsType) == PaymentSettings.PricingConstraints ||
            PaymentSettings(collectionCoreSettings.paymentSettingsType) == PaymentSettings.PricingConstraintsCollectionOnly) {
            appStorage().collectionConstrainedPricingPaymentMethods[tokenAddress] = constrainedPricingPaymentMethod;
            PricingBounds memory currentPricingBounds = appStorage().collectionPricingBounds[tokenAddress];
            
            if(!(currentPricingBounds.isSet == collectionPricingBounds.isSet &&
                currentPricingBounds.floorPrice == collectionPricingBounds.floorPrice &&
                currentPricingBounds.ceilingPrice == collectionPricingBounds.ceilingPrice)
            ) {
                appStorage().collectionPricingBounds[tokenAddress] = PricingBounds({
                    initialized: true,
                    isSet: collectionPricingBounds.isSet,
                    floorPrice: collectionPricingBounds.floorPrice,
                    ceilingPrice: collectionPricingBounds.ceilingPrice
                });

                emit UpdatedCollectionLevelPricingBoundaries(
                    tokenAddress, 
                    collectionPricingBounds.floorPrice, 
                    collectionPricingBounds.ceilingPrice);
            }
        }

        if (_isFlagSet(flags, FLAG_IS_ROYALTY_BOUNTY_EXCLUSIVE)) {
            appStorage().collectionExclusiveBountyReceivers[tokenAddress] = exclusiveBountyReceiver;
        }

        emit UpdatedCollectionPaymentSettings(
            tokenAddress, 
            PaymentSettings(collectionCoreSettings.paymentSettingsType), 
            collectionCoreSettings.paymentMethodWhitelistId,
            constrainedPricingPaymentMethod,
            collectionCoreSettings.royaltyBackfillNumerator,
            collectionCoreSettings.royaltyBackfillReceiver,
            collectionCoreSettings.royaltyBountyNumerator,
            exclusiveBountyReceiver,
            _isFlagSet(flags, FLAG_BLOCK_TRADES_FROM_UNTRUSTED_CHANNELS),
            _isFlagSet(flags, FLAG_USE_BACKFILL_AS_ROYALTY_SOURCE));
    }

    /**
     * @notice Reverts the transaction if the caller is not the CollectionSettingsRegistry or the contract itself.
     */
    function _requireCallerIsCollectionSettingsRegistryOrSelf() internal view {
        if(!(msg.sender == collectionSettingsRegistry || msg.sender == address(this))) {
            revert PaymentProcessor__CallerIsNotSettingsRegistryOrSelf();
        }
    }

    /**
     * @notice Returns true if the `flagValue` has the `flag` set, false otherwise.
     *
     * @dev    This function uses the bitwise AND operator to check if the `flag` is set in `flagValue`.
     *
     * @param flagValue  The value to check for the presence of the `flag`.
     * @param flag       The flag to check for in the `flagValue`.
     */
    function _isFlagSet(uint8 flagValue, uint8 flag) internal pure returns (bool flagSet) {
        flagSet = (flagValue & flag) != 0;
    }

    /**
     * @notice Sets the `flag` in `flagValue` to `flagSet` and returns the updated value.
     * 
     * @dev    This function uses the bitwise OR and AND operators to set or unset the `flag` in `flagValue`.
     *
     * @param flagValue The value to set the `flag` in.
     * @param flag      The flag to set in the `flagValue`.
     * @param flagSet   True to set the `flag`, false to unset the `flag`.
     */
    function _setFlag(uint8 flagValue, uint8 flag, bool flagSet) internal pure returns (uint8) {
        if(flagSet) {
            return (flagValue | flag);
        } else {
            unchecked {
                return (flagValue & (255 - flag));
            }
        }
    }

    /**
     * @notice A gas efficient, and fallback-safe way to call the royaltyInfo function on a token contract.
     *
     * @dev    This will get the royaltyInfo if it exists - and when the function is unimplemented, the
     * @dev    presence of a fallback function will not result in halted execution.
     * 
     * @param  tokenAddress The contract address of the token to check for royalties.
     * @param  tokenId      The token ID to check for royalties.
     * @param  salePrice    The sale price of the token.
     */
    function _safeRoyaltyInfo(
        address tokenAddress, 
        uint256 tokenId, 
        uint256 salePrice
    ) internal view returns(address receiver, uint256 royaltyAmount, bool isError) {
        assembly {
            function _callRoyaltyInfo(_tokenAddress, _tokenId, _salePrice) -> _receiver, _royaltyAmount, _isError {
                let ptr := mload(0x40)
                mstore(0x40, add(ptr, 0x60))
                mstore(ptr, 0x2a55205a)
                mstore(add(0x20, ptr), _tokenId)
                mstore(add(0x40, ptr), _salePrice)
                if and(iszero(lt(returndatasize(), 0x40)), staticcall(gas(), _tokenAddress, add(ptr, 0x1C), 0x44, 0x00, 0x40)) {
                    _receiver := mload(0x00)
                    _royaltyAmount := mload(0x20)
                    leave
                }
                _isError := true
            }
            receiver, royaltyAmount, isError := _callRoyaltyInfo(tokenAddress, tokenId, salePrice)
        }
    }

    /**
     * @notice A gas efficient, and fallback-safe way to call the owner function on a token contract.
     *
     * @dev    This will get the owner if it exists - and when the function is unimplemented, the
     * @dev    presence of a fallback function will not result in halted execution.
     *
     * @param tokenAddress The contract address of the token to check for the owner.
     */
    function _safeOwner(
        address tokenAddress
    ) internal view returns(address owner, bool isError) {
        assembly {
            function _callOwner(_tokenAddress) -> _owner, _isError {
                mstore(0x00, 0x8da5cb5b)
                if and(iszero(lt(returndatasize(), 0x20)), staticcall(gas(), _tokenAddress, 0x1C, 0x04, 0x00, 0x20)) {
                    _owner := mload(0x00)
                    leave
                }
                _isError := true
            }
            owner, isError := _callOwner(tokenAddress)
        }
    }
    
    /**
     * @notice A gas efficient, and fallback-safe way to call the hasRole function on a token contract.
     *
     * @dev    This will check if the account `hasRole` if `hasRole` exists - and when the function is unimplemented, the
     * @dev    presence of a fallback function will not result in halted execution.
     *
     * @param tokenAddress The contract address of the token to check for the role.
     * @param role         The role to check for.
     * @param account      The account to check for the role.
     */
    function _safeHasRole(
        address tokenAddress,
        bytes32 role,
        address account
    ) internal view returns(bool hasRole, bool isError) {
        assembly {
            function _callHasRole(_tokenAddress, _role, _account) -> _hasRole, _isError {
                let ptr := mload(0x40)
                mstore(0x40, add(ptr, 0x60))
                mstore(ptr, 0x91d14854)
                mstore(add(0x20, ptr), _role)
                mstore(add(0x40, ptr), _account)
                if and(iszero(lt(returndatasize(), 0x20)), staticcall(gas(), _tokenAddress, add(ptr, 0x1C), 0x44, 0x00, 0x20)) {
                    _hasRole := mload(0x00)
                    leave
                }
                _isError := true
            }
            hasRole, isError := _callHasRole(tokenAddress, role, account)
        }
    }

    
    /**
     * @notice Returns the taker for a transaction with trusted forwarder context if appended data length is 20 bytes.
     *
     * @dev    Throws when appended data length is not zero or 20 bytes.
     * 
     * @param appendedDataLength  The length of extra calldata sent with a transaction.
     * 
     * @return taker  The address of the taker for the transaction.
     */
    function _getTaker(
        uint256 appendedDataLength
    ) internal view returns(address taker) {
        taker = msg.sender;
        if (appendedDataLength > 0) {
            if (appendedDataLength != 20) revert PaymentProcessor__BadCalldataLength();
            taker = _msgSender();
        }
    }
}

File 24 of 29 : PaymentProcessorModuleAdvanced.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "./PaymentProcessorModulePermits.sol";

/*
                                                     @@@@@@@@@@@@@@             
                                                    @@@@@@@@@@@@@@@@@@(         
                                                   @@@@@@@@@@@@@@@@@@@@@        
                                                  @@@@@@@@@@@@@@@@@@@@@@@@      
                                                           #@@@@@@@@@@@@@@      
                                                               @@@@@@@@@@@@     
                            @@@@@@@@@@@@@@*                    @@@@@@@@@@@@     
                           @@@@@@@@@@@@@@@     @               @@@@@@@@@@@@     
                          @@@@@@@@@@@@@@@     @                @@@@@@@@@@@      
                         @@@@@@@@@@@@@@@     @@               @@@@@@@@@@@@      
                        @@@@@@@@@@@@@@@     #@@             @@@@@@@@@@@@/       
                        @@@@@@@@@@@@@@.     @@@@@@@@@@@@@@@@@@@@@@@@@@@         
                       @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@            
                      @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@             
                     @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@           
                    @@@@@@@@@@@@@@@     @@@@@&%%%%%%%%&&@@@@@@@@@@@@@@          
                    @@@@@@@@@@@@@@      @@@@@               @@@@@@@@@@@         
                   @@@@@@@@@@@@@@@     @@@@@                 @@@@@@@@@@@        
                  @@@@@@@@@@@@@@@     @@@@@@                 @@@@@@@@@@@        
                 @@@@@@@@@@@@@@@     @@@@@@@                 @@@@@@@@@@@        
                @@@@@@@@@@@@@@@     @@@@@@@                 @@@@@@@@@@@&        
                @@@@@@@@@@@@@@     *@@@@@@@               (@@@@@@@@@@@@         
               @@@@@@@@@@@@@@@     @@@@@@@@             @@@@@@@@@@@@@@          
              @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@           
             @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@            
            @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@              
           .@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                 
           @@@@@@@@@@@@@@%     @@@@@@@@@@@@@@@@@@@@@@@@(                        
          @@@@@@@@@@@@@@@                                                       
         @@@@@@@@@@@@@@@                                                        
        @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                         
       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                          
       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&                                          
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                           
 
* @title PaymentProcessorModuleAdvanced
* @custom:version 3.0.0
* @author Limit Break, Inc.
*/ 

abstract contract PaymentProcessorModuleAdvanced is PaymentProcessorModulePermits {
    using EnumerableSet for EnumerableSet.AddressSet;

    constructor(address configurationContract) PaymentProcessorModulePermits(configurationContract) {}

    /*************************************************************************/
    /*                            Order Execution                            */
    /*************************************************************************/

    /**
     * @notice Executes an advanced buy side order. An advanced order includes an optional permit context and optional bulk order proof.
     *
     * @dev    Throws when the permit processor is not trusted.
     * @dev    Throws when the permit processor is provided and the maker created the order by signing a merkle tree root.
     *
     * @param tradeContext         The execution context of the trade.
     * @param startingNativeFunds  The starting native funds.
     * @param advancedListing      Order details including the permit context, signatures and sale details.
     * @param bulkOrderProof       Optional bulk order proof.
     * @param feeOnTop             The additional fee to add on top of the orders, paid by taker.
     */
    function _executeOrderBuySideAdvanced(
        TradeContext memory tradeContext,
        uint256 startingNativeFunds,
        AdvancedOrder memory advancedListing,
        BulkOrderProof calldata bulkOrderProof,
        FeeOnTop calldata feeOnTop
    ) internal returns (uint256 endingNativeFunds) {
        if (advancedListing.permitContext.permitProcessor == address(0)) {
            if (bulkOrderProof.proof.length == 0) {
                endingNativeFunds = _executeOrderBuySide(
                    tradeContext,
                    startingNativeFunds,
                    advancedListing.saleDetails,
                    advancedListing.signature,
                    advancedListing.cosignature,
                    feeOnTop);
            } else {
                endingNativeFunds = _executeOrderBuySideBulk(
                    tradeContext,
                    startingNativeFunds,
                    advancedListing,
                    bulkOrderProof,
                    feeOnTop);
            }
        } else {
            if (bulkOrderProof.proof.length == 0) {
                if (!_isTrustedPermitProcessor(advancedListing.permitContext.permitProcessor)) {
                    revert PaymentProcessor__PermitProcessorNotTrusted();
                }
                advancedListing.saleDetails.itemPrice = uint240(advancedListing.saleDetails.itemPrice);
    
                endingNativeFunds = _validateAndFulfillSinglePermittedOrder(
                    startingNativeFunds,
                    Sides.Buy,
                    advancedListing,
                    tradeContext,
                    feeOnTop);
            } else {
                revert PaymentProcessor__PermitsAreNotCompatibleWithBulkOrders();
            }
        }
    }

    /**
     * @notice Verifies the proof and signature of an order that was generated by a signed merkle tree root
     * @notice and executes the order.
     *
     * @dev    Throws when the order type is ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL and the remaining fillable 
     * @dev    amount is less than the minimum fillable amount requested.
     * @dev    Throws when the order status is not open.
     * @dev    Throws when the nonce has already been invalidated.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker's signature is invalid.
     *
     * @param tradeContext         The execution context of the trade.
     * @param startingNativeFunds  The starting native funds.
     * @param advancedListing      Order details including the permit context, signatures and sale details.
     * @param bulkOrderProof       The bulk order proof and order index.
     * @param feeOnTop             The additional fee to add on top of the orders, paid by taker. 
     */
    function _executeOrderBuySideBulk(
        TradeContext memory tradeContext,
        uint256 startingNativeFunds,
        AdvancedOrder memory advancedListing,
        BulkOrderProof calldata bulkOrderProof,
        FeeOnTop calldata feeOnTop
    ) internal returns (uint256 endingNativeFunds) {
        Order memory saleDetails = advancedListing.saleDetails;
        saleDetails.itemPrice = uint240(saleDetails.itemPrice);

        uint256 quantityToFill = _verifyBulkSaleApprovalProofAndSignedTree(
                tradeContext,
                saleDetails,
                advancedListing.signature,
                advancedListing.cosignature,
                bulkOrderProof);

        endingNativeFunds = 
            _validateAndFulfillOrder(
                Sides.Buy, 
                tradeContext, 
                startingNativeFunds, 
                quantityToFill, 
                saleDetails, 
                feeOnTop);
    }

    /**
     * @notice Executes an advanced sell side order. An advanced order includes an optional permit context and optional bulk order proof.
     *
     * @dev    Throws when the permit processor is provided and is not trusted.
     * @dev    Throws when the permit processor is provided and the maker created the order by signing a merkle tree root.
     * @dev    Throws when the permit processor is set and the order is paid with the native token.
     * 
     * @param tradeContext         The execution context of the trade.
     * @param advancedBid          Order details including the permit context, signatures and sale details.
     * @param bulkOrderProof       Optional bulk order proof.
     * @param feeOnTop             The additional fee to add on top of the orders, paid by taker.
     */
    function _executeOrderSellSideAdvanced(
        TradeContext memory tradeContext,
        AdvancedBidOrder memory advancedBid,
        BulkOrderProof calldata bulkOrderProof,
        FeeOnTop calldata feeOnTop,
        TokenSetProof calldata tokenSetProof
    ) internal {
        if (advancedBid.advancedOrder.permitContext.permitProcessor == address(0)) {
            if (bulkOrderProof.proof.length == 0) { 
                _executeOrderSellSide(
                    tradeContext,
                    advancedBid.offerType,
                    advancedBid.advancedOrder.saleDetails,
                    advancedBid.advancedOrder.signature,
                    tokenSetProof,
                    advancedBid.advancedOrder.cosignature,
                    feeOnTop);
            } else {
                _executeOrderSellSideBulk(
                    tradeContext,
                    advancedBid,
                    bulkOrderProof,
                    feeOnTop,
                    tokenSetProof);
            }
        } else {
            if (bulkOrderProof.proof.length == 0) { 
                if (!_isTrustedPermitProcessor(advancedBid.advancedOrder.permitContext.permitProcessor)) {
                    revert PaymentProcessor__PermitProcessorNotTrusted();
                }
        
                if (advancedBid.advancedOrder.saleDetails.paymentMethod == address(0)) {
                    revert PaymentProcessor__BadPaymentMethod();
                }
                advancedBid.advancedOrder.saleDetails.itemPrice = uint240(advancedBid.advancedOrder.saleDetails.itemPrice);

                uint256 quantityToFill = 
                    _verifyBidOrderSignatures(
                        advancedBid.offerType, 
                        tradeContext, 
                        advancedBid.advancedOrder.saleDetails, 
                        advancedBid.advancedOrder.signature, 
                        advancedBid.advancedOrder.cosignature, 
                        tokenSetProof);

                _adjustForUnitPricing(quantityToFill, advancedBid.advancedOrder.saleDetails);
        
                advancedBid.advancedOrder.signature = advancedBid.sellerPermitSignature;
        
                _validateAndFulfillSinglePermittedOrder(0, Sides.Sell, advancedBid.advancedOrder, tradeContext, feeOnTop);
            } else {
                revert PaymentProcessor__PermitsAreNotCompatibleWithBulkOrders();
            }
        }
    }

    /**
     * @notice Verifies the proof and signature of an order that was generated by a signed merkle tree root
     * @notice and executes the order.
     *
     * @dev    Throws when the payment method is the native token.
     * @dev    Throws when the token set proof is provided and is invalid.
     * @dev    Throws when the nonce has already been invalidated.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker's signature is invalid.
     * @dev    Throws when the order status is not open.
     * @dev    Throws when the order type is ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL and the remaining fillable
     * @dev    amount is less than the minimum fillable amount requested.
     * 
     * @param tradeContext         The execution context of the trade.
     * @param advancedBid          Order details including the permit context, signatures and sale details.
     * @param bulkOrderProof       The bulk order proof and order index.
     * @param feeOnTop             The additional fee to add on top of the orders, paid by taker.
     * @param tokenSetProof        The token set proof that contains the root hash for the merkle
     *                             tree of allowed tokens for accepting the maker's offer.
     */
    function _executeOrderSellSideBulk(
        TradeContext memory tradeContext,
        AdvancedBidOrder memory advancedBid,
        BulkOrderProof calldata bulkOrderProof,
        FeeOnTop calldata feeOnTop,
        TokenSetProof calldata tokenSetProof
    ) internal {
        Order memory saleDetails = advancedBid.advancedOrder.saleDetails;
        saleDetails.itemPrice = uint240(saleDetails.itemPrice);

        if (saleDetails.paymentMethod == address(0)) {
            revert PaymentProcessor__BadPaymentMethod();
        }

        uint256 quantityToFill;

        uint256 offerType = advancedBid.offerType;
        if (offerType == OFFER_TYPE_COLLECTION_OFFER) {
            quantityToFill = _verifyBulkCollectionOfferApprovalProofAndSignedTree(
                tradeContext, 
                saleDetails, 
                advancedBid.advancedOrder.signature, 
                advancedBid.advancedOrder.cosignature,
                bulkOrderProof);
        } else if (offerType == OFFER_TYPE_ITEM_OFFER) {
            quantityToFill = _verifyBulkItemOfferApprovalProofAndSignedTree(
                tradeContext,
                saleDetails, 
                advancedBid.advancedOrder.signature, 
                advancedBid.advancedOrder.cosignature,
                bulkOrderProof);
        } else if (offerType == OFFER_TYPE_TOKEN_SET_OFFER) {
            quantityToFill = _verifyBulkTokenSetOfferApprovalProofAndSignedTree(
                tradeContext, 
                saleDetails, 
                advancedBid.advancedOrder.signature, 
                tokenSetProof, 
                advancedBid.advancedOrder.cosignature,
                bulkOrderProof);
        } else {
            revert PaymentProcessor__InvalidOfferType();
        }

        _validateAndFulfillOrder(
            Sides.Sell, 
            tradeContext, 
            0, 
            quantityToFill, 
            saleDetails, 
            feeOnTop);
    }

    /**
     * @notice Executes a sweep order. A sweep order is a collection of items that are purchased in a single transaction.
     * 
     * @dev    Throws when the sweep order protocol is ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL.
     * @dev    Throws when the sweep order items array is empty.
     * @dev    Throws when a collection is set to block untrusted channels and the transaction originates
     * @dev    from an untrusted channel.
     * @dev    Throws when the payment method is not an allowed payment method.
     * @dev    Throws when trading is paused for the collection.
     * @dev    Throws when any protocol is ORDER_PROTOCOLS_ERC721_FILL_OR_KILL and the amount is not 1.
     * @dev    Throws when any protocol is ORDER_PROTOCOLS_ERC1155_FILL_OR_KILL and the amount is 0.
     * @dev    Throws when any protocol is not ORDER_PROTOCOLS_ERC721_FILL_OR_KILL or ORDER_PROTOCOLS_ERC1155_FILL_OR_KILL.
     * @dev    Throws when the sum of the marketplace fee and the max royalty fee exceeds the fee denominator.
     * @dev    Throws when the sale price is not within the allowed price range.
     * @dev    Throws when the order has expired.
     * @dev    Throws when the fee on top is greater than the sum of the listing prices.
     * @dev    Throws when the payment method is not an allowed payment method.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker signature is invalid.
     * @dev    Throws when the maker's order nonce has already been used or was cancelled.
     * @dev    Throws when a partially fillable order has already been filled, cancelled or 
     * @dev    cannot be filled with the minimum fillable amount.
     *
     * @param tradeContext         The execution context of the trade.
     * @param startingNativeFunds  The starting native funds.
     * @param advancedSweep        Order details including the permit context, signatures and sweep details.
     */
    function _executeSweepOrderAdvanced(
        TradeContext memory tradeContext,
        uint256 startingNativeFunds,
        AdvancedSweep calldata advancedSweep
    ) internal returns (uint256 endingNativeFunds) {
        if (advancedSweep.sweepOrder.protocol == ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL) {
            revert PaymentProcessor__OrderProtocolERC1155FillPartialUnsupportedInSweeps();
        }

        if (advancedSweep.items.length == 0) {
            revert PaymentProcessor__InputArrayLengthCannotBeZero();
        }

        SweepExecutionParams memory params = _validateSweepOrderHeader(tradeContext, advancedSweep.sweepOrder);

        endingNativeFunds = _validateAndFulfillSweepOrderAdvanced(
            startingNativeFunds,
            advancedSweep,
            tradeContext,
            params
        );
    }

    /**
     * @notice Validates and fulfills a sweep order.
     *
     * @dev    Throws when any protocol is ORDER_PROTOCOLS_ERC721_FILL_OR_KILL and the amount is not 1.
     * @dev    Throws when any protocol is ORDER_PROTOCOLS_ERC1155_FILL_OR_KILL and the amount is 0.
     * @dev    Throws when any protocol is not ORDER_PROTOCOLS_ERC721_FILL_OR_KILL or ORDER_PROTOCOLS_ERC1155_FILL_OR_KILL.
     * @dev    Throws when the sum of the marketplace fee and the max royalty fee exceeds the fee denominator.
     * @dev    Throws when the sale price is not within the allowed price range.
     * @dev    Throws when the order has expired.
     * @dev    Throws when the fee on top is greater than the sum of the listing prices.
     * @dev    Throws when the payment method is not an allowed payment method.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the maker signature is invalid.
     * @dev    Throws when the maker's order nonce has already been used or was cancelled.
     * @dev    Throws when a partially fillable order has already been filled, cancelled or 
     * @dev    cannot be filled with the minimum fillable amount.
     * 
     * @param startingNativeFunds  The starting native funds.
     * @param advancedSweep        Order details including the permit context, signatures and sweep details.
     * @param context              The current exectuion context.
     * @param params               The sweep execution parameters.
     */
    function _validateAndFulfillSweepOrderAdvanced(
        uint256 startingNativeFunds,
        AdvancedSweep calldata advancedSweep,
        TradeContext memory context,
        SweepExecutionParams memory params
    ) internal returns (uint256 endingNativeFunds) {
        endingNativeFunds = startingNativeFunds;

        uint256 sumListingPrices;
        uint256 dispensedPaymentValue; 

        SweepOrder calldata sweepOrder = advancedSweep.sweepOrder;
        AdvancedSweepItem[] calldata items = advancedSweep.items;

        for(uint256 itemIndex;itemIndex < items.length;) {
            AdvancedSweepItem calldata advancedSweepItem = items[itemIndex];
            SweepItem calldata sweepItem = advancedSweepItem.sweepItem;
            AdvancedOrder memory advancedOrder;

            advancedOrder.permitContext = advancedSweepItem.permitContext;
            advancedOrder.signature = advancedSweepItem.signature;
            advancedOrder.cosignature = advancedSweepItem.cosignature;
            advancedOrder.saleDetails = Order({
                protocol: sweepOrder.protocol,
                maker: sweepItem.maker,
                beneficiary: sweepOrder.beneficiary,
                marketplace: sweepItem.marketplace,
                fallbackRoyaltyRecipient: sweepItem.fallbackRoyaltyRecipient,
                paymentMethod: sweepOrder.paymentMethod,
                tokenAddress: sweepOrder.tokenAddress,
                tokenId: sweepItem.tokenId,
                amount: sweepItem.amount,
                itemPrice: uint240(sweepItem.itemPrice),
                nonce: sweepItem.nonce,
                expiration: sweepItem.expiration,
                marketplaceFeeNumerator: sweepItem.marketplaceFeeNumerator,
                maxRoyaltyFeeNumerator: sweepItem.maxRoyaltyFeeNumerator,
                requestedFillAmount: sweepItem.amount,
                minimumFillAmount: sweepItem.amount,
                protocolFeeVersion: sweepItem.protocolFeeVersion
            });

            Order memory saleDetails = advancedOrder.saleDetails;

            if (context.protocolFeeVersion != saleDetails.protocolFeeVersion) {
                context.protocolFeeVersion = saleDetails.protocolFeeVersion;
                context.protocolFees = appStorage().protocolFeeVersions[saleDetails.protocolFeeVersion];
            }

            sumListingPrices += saleDetails.itemPrice;

            if (saleDetails.protocol == ORDER_PROTOCOLS_ERC721_FILL_OR_KILL) {
                if (saleDetails.amount != ONE) {
                    revert PaymentProcessor__AmountForERC721SalesMustEqualOne();
                }
            } else if (saleDetails.protocol == ORDER_PROTOCOLS_ERC1155_FILL_OR_KILL) {
                if (saleDetails.amount == 0) {
                    revert PaymentProcessor__AmountForERC1155SalesGreaterThanZero();
                }
            } else {
                revert PaymentProcessor__InvalidOrderProtocol();
            }

            if (saleDetails.marketplaceFeeNumerator + saleDetails.maxRoyaltyFeeNumerator > FEE_DENOMINATOR) {
                revert PaymentProcessor__MarketplaceAndRoyaltyFeesWillExceedSalePrice();
            }

            if (params.paymentSettings == PaymentSettings.PricingConstraints || params.paymentSettings == PaymentSettings.PricingConstraintsCollectionOnly) {
                _validateSalePriceInRange(
                    params.paymentSettings,
                    saleDetails.tokenAddress, 
                    saleDetails.tokenId, 
                    saleDetails.amount, 
                    saleDetails.itemPrice);
            }

            if (block.timestamp > saleDetails.expiration) {
                    revert PaymentProcessor__OrderHasExpired();
            }

            if (block.timestamp > context.protocolFees.versionExpiration) {
                revert PaymentProcessor__ProtocolFeeVersionExpired();
            }

            if (context.protocolFees.minimumProtocolFeeBps > FEE_DENOMINATOR) {
                revert PaymentProcessor__ProtocolFeeOrTaxExceedsCap();
            }

            if (advancedOrder.permitContext.permitProcessor == address(0)) {
                if (advancedSweepItem.bulkOrderProof.proof.length == 0) {
                    _verifySaleApproval(
                        context,
                        saleDetails,
                        advancedOrder.signature,
                        advancedOrder.cosignature
                    );
                } else {
                    _verifyBulkSaleApprovalProofAndSignedTree(
                        context,
                        saleDetails,
                        advancedOrder.signature,
                        advancedOrder.cosignature,
                        advancedSweepItem.bulkOrderProof
                    );
                }
            }

            (endingNativeFunds, dispensedPaymentValue) = _dispenseAndPayoutSweepItemAdvanced(
                advancedOrder, 
                context,
                params,
                endingNativeFunds,
                dispensedPaymentValue
            );

            unchecked {
                ++itemIndex;
            }
        }

        if (advancedSweep.feeOnTop.amount > sumListingPrices) {
            revert PaymentProcessor__FeeOnTopCannotBeGreaterThanItemPrice();
        }

        endingNativeFunds = _finalizePaymentAccumulatorDisbursement(
            context,
            params,
            advancedSweep.feeOnTop,
            dispensedPaymentValue,
            sumListingPrices,
            endingNativeFunds
        );
    }

    /**
     * @notice Disburses the accumulated proceeds to the respective recipients.
     *
     * @dev    Throws when the provided permit processor is not trusted.
     * @dev    Throws when the order has run out of native funds.
     */
    function _dispenseAndPayoutSweepItemAdvanced(
        AdvancedOrder memory advancedOrder,
        TradeContext memory context,
        SweepExecutionParams memory params,
        uint256 startingNativeFunds,
        uint256 startingDispensedPaymentValue
    ) internal returns(
        uint256 endingNativeFunds,
        uint256 endingDispensedPaymentValue
    ) {
        endingNativeFunds = startingNativeFunds;
        endingDispensedPaymentValue = startingDispensedPaymentValue;

        Order memory saleDetails = advancedOrder.saleDetails;
        bool failedToDispense;

        if (advancedOrder.permitContext.permitProcessor == address(0)) {
            failedToDispense = !params.fnPointers.funcDispenseToken(
                saleDetails.maker, 
                saleDetails.beneficiary, 
                saleDetails.tokenAddress, 
                saleDetails.tokenId, 
                saleDetails.amount);

            if(failedToDispense) {
                if (saleDetails.protocol != ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL) {
                    _restoreNonce(saleDetails.maker, saleDetails.nonce);
                }
            }
        } else {
            if (!_isTrustedPermitProcessor(advancedOrder.permitContext.permitProcessor)) {
                revert PaymentProcessor__PermitProcessorNotTrusted();
            }

            uint256 quantityToFill;
            (quantityToFill, failedToDispense) = 
                _verifyPermittedSaleApprovalAndDispense(true, saleDetails.maker, advancedOrder, context);

            _adjustForUnitPricing(quantityToFill, saleDetails);
        }

        if (!failedToDispense) {
            SplitProceeds memory proceeds =
                _computePaymentSplits(
                    context,
                    saleDetails.itemPrice,
                    saleDetails.tokenAddress,
                    saleDetails.tokenId,
                    saleDetails.marketplace,
                    saleDetails.marketplaceFeeNumerator,
                    saleDetails.maxRoyaltyFeeNumerator,
                    saleDetails.fallbackRoyaltyRecipient
                );

            unchecked {
                endingDispensedPaymentValue += saleDetails.itemPrice;
            }

            if (saleDetails.paymentMethod == address(0)) {
                if (endingNativeFunds < saleDetails.itemPrice) {
                    revert PaymentProcessor__RanOutOfNativeFunds();
                }

                unchecked {
                    endingNativeFunds -= saleDetails.itemPrice;
                }
            }

            if (proceeds.royaltyRecipient != params.accumulator.lastRoyaltyRecipient) {
                if(params.accumulator.accumulatedRoyaltyProceeds > 0) {
                    params.fnPointers.funcPayout(params.accumulator.lastRoyaltyRecipient, context.taker, params.paymentCoin, params.accumulator.accumulatedRoyaltyProceeds);
                }

                params.accumulator.lastRoyaltyRecipient = proceeds.royaltyRecipient;
                params.accumulator.accumulatedRoyaltyProceeds = 0;
            }

            if (saleDetails.marketplace != params.accumulator.lastMarketplace) {
                if(params.accumulator.accumulatedMarketplaceProceeds > 0) {
                    params.fnPointers.funcPayout(params.accumulator.lastMarketplace, context.taker, params.paymentCoin, params.accumulator.accumulatedMarketplaceProceeds);
                }

                params.accumulator.lastMarketplace = saleDetails.marketplace;
                params.accumulator.accumulatedMarketplaceProceeds = 0;
            }

            if (saleDetails.maker != params.accumulator.lastSeller) {
                if(params.accumulator.accumulatedSellerProceeds > 0) {
                    params.fnPointers.funcPayout(params.accumulator.lastSeller, context.taker, params.paymentCoin, params.accumulator.accumulatedSellerProceeds);
                }

                params.accumulator.lastSeller = saleDetails.maker;
                params.accumulator.accumulatedSellerProceeds = 0;
            }

            if (context.protocolFees.protocolFeeReceiver != params.accumulator.lastProtocolFeeRecipient) {
                if (params.accumulator.accumulatedInfrastructureProceeds > 0) {
                    params.fnPointers.funcPayout(params.accumulator.lastProtocolFeeRecipient, context.taker, params.paymentCoin, params.accumulator.accumulatedInfrastructureProceeds);
                }

                params.accumulator.lastProtocolFeeRecipient = context.protocolFees.protocolFeeReceiver;
                params.accumulator.accumulatedInfrastructureProceeds = 0;
            }

            unchecked {
                params.accumulator.accumulatedRoyaltyProceeds += proceeds.royaltyProceeds;
                params.accumulator.accumulatedMarketplaceProceeds += proceeds.marketplaceProceeds;
                params.accumulator.accumulatedSellerProceeds += proceeds.sellerProceeds;
                params.accumulator.accumulatedInfrastructureProceeds += proceeds.infrastructureProceeds;
            }

            params.fnPointers.funcEmitOrderExecutionEvent(context, saleDetails);
        }

    }

    /**
     * @notice Verifies the proof and signature of an order that was generated by a signed merkle tree root.
     *
     * @dev    Throws when the maker's signature is invalid.
     * @dev    Throws when the order status is not open.
     * @dev    Throws when the nonce has already been invalidated.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the order type is ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL and the remaining fillable
     * @dev    amount is less than the minimum fillable amount requested.
     *
     * @param  context                            The execution context of the trade.
     * @param  saleDetails                        The details of the sale.
     * @param  signature                          The maker's signature authorizing the order execution.
     * @param  cosignature                        The additional cosignature for a cosigned order, if applicable.
     * @param  bulkOrderProof                     The bulk order proof and order index.
     * @param  orderHash                          The digest generated from the order details.
     * @param  _getBulkOrderTypehashByTreeHeight  The function to get the bulk order typehash by tree height.
     */
    function _verifyBulkOrderSignatures(
        TradeContext memory context,
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature,
        BulkOrderProof calldata bulkOrderProof,
        bytes32 orderHash,
        function(uint256) internal pure returns(bytes32) _getBulkOrderTypehashByTreeHeight
    ) internal returns (uint256 quantityToFill) {
        uint256 orderIndex = bulkOrderProof.orderIndex;
        bytes32 bulkOrderRootHash = orderHash;
        bytes32[] calldata proof = bulkOrderProof.proof;
        for (uint256 i; i < proof.length;) {
            if (orderIndex & 1 == 0) {
                bulkOrderRootHash = EfficientHash.efficientHash(bulkOrderRootHash, proof[i]);
            } else {
                bulkOrderRootHash = EfficientHash.efficientHash(proof[i], bulkOrderRootHash);
            }
            orderIndex >>= 1;
            unchecked {
                ++i;
            }
        }

        if (cosignature.signer != address(0)) {
            _verifyCosignature(context, signature, cosignature);
        }

        _verifyMakerSignature(
            saleDetails.maker, 
            signature, 
            _hashTypedDataV4(
                _cachedDomainSeparator, 
                EfficientHash.efficientHash(
                    _getBulkOrderTypehashByTreeHeight(bulkOrderProof.proof.length),
                    bulkOrderRootHash
                )
            )
        );

        if (saleDetails.protocol == ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL) {
            quantityToFill = _checkAndUpdateRemainingFillableItems(
                saleDetails.maker, 
                orderHash, 
                saleDetails.amount, 
                saleDetails.requestedFillAmount,
                saleDetails.minimumFillAmount);
            context.orderDigest = orderHash;
        } else {
            quantityToFill = saleDetails.amount;
        }
    }

    /**
     * @notice Generate the order digest and verify the bulk order proof and signatures for an item.
     *
     * @dev    Throws when the maker's signature is invalid.
     * @dev    Throws when the order status is not open.
     * @dev    Throws when the nonce has already been invalidated.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the order type is ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL and the remaining fillable
     * @dev    amount is less than the minimum fillable amount requested.
     *
     * @param  tradeContext     The execution context of the trade.
     * @param  saleDetails      The details of the sale.
     * @param  signature        The maker's signature authorizing the order execution.
     * @param  cosignature      The additional cosignature for a cosigned order, if applicable.
     * @param  bulkOrderProof   The bulk order proof and order index.
     */
    function _verifyBulkItemOfferApprovalProofAndSignedTree(
        TradeContext memory tradeContext,
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature,
        BulkOrderProof calldata bulkOrderProof
    ) internal returns (uint256 quantityToFill) {
        bytes32 orderHash = 
            _generateItemOfferOrderHash(
                saleDetails, 
                saleDetails.maker, 
                cosignature.signer, 
                _checkAndInvalidateNonceForFillOrKillOrders(saleDetails)
            );

        quantityToFill = _verifyBulkOrderSignatures(
            tradeContext, 
            saleDetails, 
            signature, 
            cosignature, 
            bulkOrderProof, 
            orderHash,
            _getBulkItemOfferApprovalTypehash
        );
    }

    /**
     * @notice Generate the order digest and verify the bulk order proof and signatures for a collection.
     *
     * @dev    Throws when the maker's signature is invalid.
     * @dev    Throws when the order status is not open.
     * @dev    Throws when the nonce has already been invalidated.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the order type is ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL and the remaining fillable
     * @dev    amount is less than the minimum fillable amount requested.
     *
     * @param  tradeContext     The execution context of the trade.
     * @param  saleDetails      The details of the sale.
     * @param  signature        The maker's signature authorizing the order execution.
     * @param  cosignature      The additional cosignature for a cosigned order, if applicable.
     * @param  bulkOrderProof   The bulk order proof and order index.
     */
    function _verifyBulkCollectionOfferApprovalProofAndSignedTree(
        TradeContext memory tradeContext,
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature,
        BulkOrderProof calldata bulkOrderProof
    ) internal returns (uint256 quantityToFill) {
        bytes32 orderHash = 
            _generateCollectionOfferOrderHash(
                saleDetails, 
                saleDetails.maker, 
                cosignature.signer, 
                _checkAndInvalidateNonceForFillOrKillOrders(saleDetails)
            );

        quantityToFill = _verifyBulkOrderSignatures(
            tradeContext, 
            saleDetails, 
            signature, 
            cosignature, 
            bulkOrderProof, 
            orderHash,
            _getBulkCollectionOfferApprovalTypehash
        );
    }

    /**
     * @notice Generate the order digest and verify the bulk order proof and signatures for a token set order.
     *
     * @dev    Throws when the maker's signature is invalid.
     * @dev    Throws when the order status is not open.
     * @dev    Throws when the nonce has already been invalidated.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the order type is ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL and the remaining fillable
     * @dev    amount is less than the minimum fillable amount requested.
     *
     * @param  tradeContext     The execution context of the trade.
     * @param  saleDetails      The details of the sale.
     * @param  signature        The maker's signature authorizing the order execution.
     * @param  tokenSetProof    The merkle proofs for an offer that is a subset of tokens in a collection.
     * @param  cosignature      The additional cosignature for a cosigned order, if applicable.
     * @param  bulkOrderProof   The bulk order proof and order index.
     */
    function _verifyBulkTokenSetOfferApprovalProofAndSignedTree(
        TradeContext memory tradeContext,
        Order memory saleDetails,
        SignatureECDSA memory signature,
        TokenSetProof calldata tokenSetProof,
        Cosignature memory cosignature,
        BulkOrderProof calldata bulkOrderProof
    ) internal returns (uint256 quantityToFill) {
        bytes32 orderHash = 
            _generateTokenSetOfferOrderHash(
                tokenSetProof,
                saleDetails, 
                saleDetails.maker, 
                cosignature.signer, 
                _checkAndInvalidateNonceForFillOrKillOrders(saleDetails)
            );

        quantityToFill = _verifyBulkOrderSignatures(
            tradeContext, 
            saleDetails, 
            signature, 
            cosignature, 
            bulkOrderProof, 
            orderHash,
            _getBulkTokenSetOfferApprovalTypehash
        );
    }

    /**
     * @notice Generate the order digest and verify the bulk order proof and signatures for a sale approval.
     *
     * @dev    Throws when the maker's signature is invalid.
     * @dev    Throws when the order status is not open.
     * @dev    Throws when the nonce has already been invalidated.
     * @dev    Throws when a cosignature is required and the cosignature is invalid.
     * @dev    Throws when the order type is ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL and the remaining fillable
     * @dev    amount is less than the minimum fillable amount requested.
     *
     * @param  tradeContext     The execution context of the trade.
     * @param  saleDetails      The details of the sale.
     * @param  signature        The maker's signature authorizing the order execution.
     * @param  cosignature      The additional cosignature for a cosigned order, if applicable.
     * @param  bulkOrderProof   The bulk order proof and order index.
     */
    function _verifyBulkSaleApprovalProofAndSignedTree(
        TradeContext memory tradeContext,
        Order memory saleDetails,
        SignatureECDSA memory signature,
        Cosignature memory cosignature,
        BulkOrderProof calldata bulkOrderProof
    ) internal returns (uint256 quantityToFill) {
        bytes32 orderHash = 
            _generateListingOrderHash(
                saleDetails, 
                saleDetails.maker, 
                cosignature.signer, 
                _checkAndInvalidateNonceForFillOrKillOrders(saleDetails)
            );

        quantityToFill = _verifyBulkOrderSignatures(
            tradeContext, 
            saleDetails, 
            signature, 
            cosignature, 
            bulkOrderProof, 
            orderHash,
            _getBulkSaleApprovalTypehash
        );
    }

    /**
     * @notice Helper function which returns the bulk sale approval typehash for a provided height.
     *
     * @param height  The height of the typehash.
     */
    function _getBulkSaleApprovalTypehash(uint256 height) internal pure returns(bytes32 hash) {
        if(height > 10 || height == 0) {
            revert PaymentProcessor__InvalidBulkOrderHeight();
        }
        bytes memory memTypehashes = BULK_SALE_APPROVAL_TYPEHASHES_LOOKUP;
        assembly {
            hash := mload(add(memTypehashes, shl(5, height)))
        }
    }

    /**
     * @notice Helper function which returns the bulk collection offer approval typehash for a provided height.
     *
     * @param height  The height of the typehash.
     */
    function _getBulkCollectionOfferApprovalTypehash(uint256 height) internal pure returns(bytes32 hash) {
        if(height > 10 || height == 0) {
            revert PaymentProcessor__InvalidBulkOrderHeight();
        }
        bytes memory memTypehashes = BULK_COLLECTION_OFFER_APPROVAL_TYPEHASHES_LOOKUP;
        assembly {
            hash := mload(add(memTypehashes, shl(5, height)))
        }
    }

    /**
     * @notice Helper function which returns the bulk item offer approval typehash for a provided height.
     *
     * @param height  The height of the typehash.
     */
    function _getBulkItemOfferApprovalTypehash(uint256 height) internal pure returns(bytes32 hash) {
        if(height > 10 || height == 0) {
            revert PaymentProcessor__InvalidBulkOrderHeight();
        }
        bytes memory memTypehashes = BULK_ITEM_OFFER_APPROVAL_TYPEHASHES_LOOKUP;
        assembly {
            hash := mload(add(memTypehashes, shl(5, height)))
        }
    }

    /**
     * @notice Helper function which returns the bulk token set offer approval typehash for a provided height.
     *
     * @param height  The height of the typehash.
     */
    function _getBulkTokenSetOfferApprovalTypehash(uint256 height) internal pure returns(bytes32 hash) {
        if(height > 10 || height == 0) {
            revert PaymentProcessor__InvalidBulkOrderHeight();
        }
        bytes memory memTypehashes = BULK_TOKEN_SET_OFFER_APPROVAL_TYPEHASHES_LOOKUP;
        assembly {
            hash := mload(add(memTypehashes, shl(5, height)))
        }
    }
}

File 25 of 29 : PaymentProcessorModulePermits.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "./PaymentProcessorModule.sol";

import {
    IPermitC 
} from "@limitbreak/permit-c/interfaces/IPermitC.sol";

/*
                                                     @@@@@@@@@@@@@@             
                                                    @@@@@@@@@@@@@@@@@@(         
                                                   @@@@@@@@@@@@@@@@@@@@@        
                                                  @@@@@@@@@@@@@@@@@@@@@@@@      
                                                           #@@@@@@@@@@@@@@      
                                                               @@@@@@@@@@@@     
                            @@@@@@@@@@@@@@*                    @@@@@@@@@@@@     
                           @@@@@@@@@@@@@@@     @               @@@@@@@@@@@@     
                          @@@@@@@@@@@@@@@     @                @@@@@@@@@@@      
                         @@@@@@@@@@@@@@@     @@               @@@@@@@@@@@@      
                        @@@@@@@@@@@@@@@     #@@             @@@@@@@@@@@@/       
                        @@@@@@@@@@@@@@.     @@@@@@@@@@@@@@@@@@@@@@@@@@@         
                       @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@            
                      @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@             
                     @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@           
                    @@@@@@@@@@@@@@@     @@@@@&%%%%%%%%&&@@@@@@@@@@@@@@          
                    @@@@@@@@@@@@@@      @@@@@               @@@@@@@@@@@         
                   @@@@@@@@@@@@@@@     @@@@@                 @@@@@@@@@@@        
                  @@@@@@@@@@@@@@@     @@@@@@                 @@@@@@@@@@@        
                 @@@@@@@@@@@@@@@     @@@@@@@                 @@@@@@@@@@@        
                @@@@@@@@@@@@@@@     @@@@@@@                 @@@@@@@@@@@&        
                @@@@@@@@@@@@@@     *@@@@@@@               (@@@@@@@@@@@@         
               @@@@@@@@@@@@@@@     @@@@@@@@             @@@@@@@@@@@@@@          
              @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@           
             @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@            
            @@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@              
           .@@@@@@@@@@@@@@     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                 
           @@@@@@@@@@@@@@%     @@@@@@@@@@@@@@@@@@@@@@@@(                        
          @@@@@@@@@@@@@@@                                                       
         @@@@@@@@@@@@@@@                                                        
        @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                         
       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                          
       @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&                                          
      @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                                           
 
* @title PaymentProcessorModulePermits
* @custom:version 3.0.0
* @author Limit Break, Inc.
*/ 

abstract contract PaymentProcessorModulePermits is PaymentProcessorModule {
    using EnumerableSet for EnumerableSet.AddressSet;

    address private immutable permitProcessor1;
    address private immutable permitProcessor2;

    constructor(address configurationContract) PaymentProcessorModule(configurationContract) {
        (,,,TrustedPermitProcessors memory trustedPermitProcessors,,
        ) = IPaymentProcessorConfiguration(configurationContract).getPaymentProcessorModuleDeploymentParams();
        
        permitProcessor1 = trustedPermitProcessors.permitProcessor1;
        permitProcessor2 = trustedPermitProcessors.permitProcessor2;
    }

    /*************************************************************************/
    /*                        Default Permit Processors                      */
    /*************************************************************************/

    /**
     * @notice Returns true if `permitProcessor` is a trusted permit processor.
     * 
     * @dev    This function will also return true if the permit processor was added after contract deployment.
     */
    function _isTrustedPermitProcessor(address permitProcessor) internal returns (bool) {
        if (permitProcessor == permitProcessor1 || 
            permitProcessor == permitProcessor2) {
            return true;
        }
        if (appStorage().trustedPermitProcessors.contains(permitProcessor)) {
            return true;
        }
        return IPaymentProcessorSettings(address(this)).checkTrustedPermitProcessors(permitProcessor);
    }

    /**
     * @notice Returns an array of the default payment methods defined at contract deployment.
     * 
     * @dev    This array will **NOT** include default payment methods added after contract deployment.
     */
    function _getTrustedPermitProcessors() internal view returns (address[] memory trustedPermitProcessors) {
        trustedPermitProcessors = new address[](2);
        trustedPermitProcessors[0] = permitProcessor1;
        trustedPermitProcessors[1] = permitProcessor2;
    }

    /*************************************************************************/
    /*                           Order Fulfillment                           */
    /*************************************************************************/

    /**
     * @notice Validates and fulfills a single permitted order.
     * 
     * @dev    Throws if the order is buy side, requires a cosignature, and the cosignature is invalid.
     * @dev    Throws if the permit nonce is invalid.
     * @dev    Throws if the permit signature is invalid.
     *
     * @param startingNativeFunds The starting native funds.
     * @param side                The side of the order.
     * @param matchedOrder        The order to fulfill.
     * @param tradeContext        The execution context of the trade.
     * @param feeOnTop            The additional fee to add on top of the order, paid by taker.
     */
    function _validateAndFulfillSinglePermittedOrder(
        uint256 startingNativeFunds,
        Sides side,
        AdvancedOrder memory matchedOrder,
        TradeContext memory tradeContext,
        FeeOnTop calldata feeOnTop
    ) internal returns (uint256 endingNativeFunds) {
        endingNativeFunds = startingNativeFunds;

        Order memory saleDetails = matchedOrder.saleDetails;

        address purchaser = tradeContext.taker;
        address seller = matchedOrder.saleDetails.maker;
        bool isBuySide = side == Sides.Buy;

        if (!isBuySide) {
            purchaser = matchedOrder.saleDetails.maker;
            seller = tradeContext.taker;
        }

        (uint256 quantityToFill, bool failedToDispense) = 
            _verifyPermittedSaleApprovalAndDispense(isBuySide, seller, matchedOrder, tradeContext);
        
        _adjustForUnitPricing(quantityToFill, saleDetails);

        _validateBasicOrderDetails(tradeContext, saleDetails);

        if (failedToDispense) {
            if (tradeContext.disablePartialFill) {
                revert PaymentProcessor__DispensingTokenWasUnsuccessful();
            }
        } else {
            SplitProceeds memory proceeds =
                _computePaymentSplits(
                    tradeContext,
                    saleDetails.itemPrice,
                    saleDetails.tokenAddress,
                    saleDetails.tokenId,
                    saleDetails.marketplace,
                    saleDetails.marketplaceFeeNumerator,
                    saleDetails.maxRoyaltyFeeNumerator,
                    saleDetails.fallbackRoyaltyRecipient
                );

            uint256 feeOnTopAmount;
            if (feeOnTop.recipient != address(0)) {
                feeOnTopAmount = feeOnTop.amount;

                if (feeOnTopAmount > saleDetails.itemPrice) {
                    revert PaymentProcessor__FeeOnTopCannotBeGreaterThanItemPrice();
                }
            }

            if (saleDetails.paymentMethod == address(0)) {
                unchecked {
                    uint256 nativeProceedsToSpend = saleDetails.itemPrice + feeOnTopAmount;
                    if (endingNativeFunds < nativeProceedsToSpend) {
                        revert PaymentProcessor__RanOutOfNativeFunds();
                    }

                    endingNativeFunds -= nativeProceedsToSpend;
                }
            }

            FulfillOrderFunctionPointers memory fnPointers = 
                _getOrderFulfillmentFunctionPointers(side, saleDetails.paymentMethod, saleDetails.protocol);

            if (feeOnTopAmount > 0) {
                unchecked {
                    uint256 feeOnTopAmountInfrastructure = feeOnTopAmount * tradeContext.protocolFees.feeOnTopProtocolTaxBps / FEE_DENOMINATOR;
                    fnPointers.funcPayout(feeOnTop.recipient, tradeContext.taker, saleDetails.paymentMethod, feeOnTopAmount - feeOnTopAmountInfrastructure);

                    if (purchaser == tradeContext.taker) {
                        proceeds.infrastructureProceeds += feeOnTopAmountInfrastructure;
                    } else {
                        if (feeOnTopAmountInfrastructure > 0) {
                            fnPointers.funcPayout(tradeContext.protocolFees.protocolFeeReceiver, tradeContext.taker, saleDetails.paymentMethod, feeOnTopAmountInfrastructure);
                        }
                    }
                }
            }

            if (proceeds.infrastructureProceeds > 0) {
                fnPointers.funcPayout(tradeContext.protocolFees.protocolFeeReceiver, purchaser, saleDetails.paymentMethod, proceeds.infrastructureProceeds);
            }

            if (proceeds.royaltyProceeds > 0) {
                fnPointers.funcPayout(proceeds.royaltyRecipient, purchaser, saleDetails.paymentMethod, proceeds.royaltyProceeds);
            }

            if (proceeds.marketplaceProceeds > 0) {
                fnPointers.funcPayout(saleDetails.marketplace, purchaser, saleDetails.paymentMethod, proceeds.marketplaceProceeds);
            }

            if (proceeds.sellerProceeds > 0) {
                fnPointers.funcPayout(seller, purchaser, saleDetails.paymentMethod, proceeds.sellerProceeds);
            }

            fnPointers.funcEmitOrderExecutionEvent(tradeContext, saleDetails);
        }
    }

    /*************************************************************************/
    /*                        Signature Verification                         */
    /*************************************************************************/

    /**
     * @notice Performs initial verification of a permit signature and processes it via the permit processor.
     *
     * @dev    Throws if the order is buy side, requires a cosignature, and the cosignature is invalid.
     * @dev    Throws if the permit nonce is invalid.
     * @dev    Throws if the permit signature is invalid.
     *
     * @param isBuySide       True if the order is buy side, false otherwise.
     * @param seller          The seller of the order.
     * @param matchedOrder    The order to verify.
     * @param tradeContext    The trade context.
     */
    function _verifyPermittedSaleApprovalAndDispense(
        bool isBuySide,
        address seller,
        AdvancedOrder memory matchedOrder,
        TradeContext memory tradeContext
    ) internal returns (uint256 quantityToFill, bool isError) {
        Order memory saleDetails = matchedOrder.saleDetails;

        bytes32 orderDigest = _generateListingOrderHash(
            matchedOrder.saleDetails,
            seller,
            isBuySide ? matchedOrder.cosignature.signer : address(0),
            appStorage().masterNonces[seller]
        );

        if (isBuySide) {
            if (matchedOrder.cosignature.signer != address(0)) {
                _verifyCosignature(
                    tradeContext, 
                    matchedOrder.signature, 
                    matchedOrder.cosignature);
            }
        }

        if (saleDetails.protocol == ORDER_PROTOCOLS_ERC1155_FILL_PARTIAL) {
            if (isBuySide) {
                (quantityToFill, isError) = _fillPermittedOrderERC1155(seller, orderDigest, matchedOrder);
            } else {
                isError = _permitTransferFromWithAdditionalDataERC1155(seller, orderDigest, matchedOrder);
                quantityToFill = saleDetails.amount;
            }
        } else {
            quantityToFill = saleDetails.amount;

            if (saleDetails.protocol == ORDER_PROTOCOLS_ERC721_FILL_OR_KILL) {
                isError = _permitTransferFromWithAdditionalDataERC721(seller, orderDigest, matchedOrder);
            } else {
                isError = _permitTransferFromWithAdditionalDataERC1155(seller, orderDigest, matchedOrder);
            }
        }
    }

    /**
     * @notice Processes a permit signature for an ERC1155 order.
     *
     * @dev    Throws if the permit nonce is invalid.
     * @dev    Throws if the permit signature is invalid.
     * @dev    Throws if the amount remaining is less than the minimum fill amount.
     * @dev    Throws if the quantity to fill exceeds uint248 max.
     *
     * @param seller          The seller of the order.
     * @param orderDigest     The order digest.
     * @param matchedOrder    The order to verify.
     */
    function _fillPermittedOrderERC1155(
        address seller,
        bytes32 orderDigest,
        AdvancedOrder memory matchedOrder
    ) internal returns (uint256 quantityToFill, bool isError) {
        Order memory saleDetails = matchedOrder.saleDetails;

        (
            quantityToFill, 
            isError
        ) = IPermitC(matchedOrder.permitContext.permitProcessor).fillPermittedOrderERC1155(
            _repackSignature(matchedOrder.signature),
            OrderFillAmounts({
                orderStartAmount: saleDetails.amount,
                requestedFillAmount: saleDetails.requestedFillAmount,
                minimumFillAmount: saleDetails.minimumFillAmount
            }),
            saleDetails.tokenAddress,
            saleDetails.tokenId,
            seller,
            saleDetails.beneficiary,
            matchedOrder.permitContext.permitNonce,
            uint48(saleDetails.expiration),
            orderDigest,
            PERMITTED_ORDER_SALE_APPROVAL
        );

        if(quantityToFill > type(uint248).max) {
            revert PaymentProcessor__AmountExceedsMaximum();
        }
    }

    /**
     * @notice Processes a permit signature with additional data for an ERC1155 order.
     * 
     * @dev    Throws if the permit nonce is invalid.
     * @dev    Throws if the permit signature is invalid.
     *
     * @param seller          The seller of the order.
     * @param orderDigest     The order digest.
     * @param matchedOrder    The order to verify.
     */
    function _permitTransferFromWithAdditionalDataERC1155(
        address seller,
        bytes32 orderDigest,
        AdvancedOrder memory matchedOrder
    ) internal returns (bool isError) {
        Order memory saleDetails = matchedOrder.saleDetails;

        isError = IPermitC(matchedOrder.permitContext.permitProcessor).permitTransferFromWithAdditionalDataERC1155(
            saleDetails.tokenAddress,
            saleDetails.tokenId,
            matchedOrder.permitContext.permitNonce,
            saleDetails.amount,
            saleDetails.expiration,
            seller,
            saleDetails.beneficiary,
            saleDetails.amount,
            orderDigest,
            PERMITTED_TRANSFER_SALE_APPROVAL,
            _repackSignature(matchedOrder.signature)
        );

        if (!isError) {
            emit PermittedOrderNonceInvalidated(
                matchedOrder.permitContext.permitNonce,
                saleDetails.nonce,
                seller,
                false
            );
        }
    }

    /**
     * @notice Processes a permit signature with additional data for an ERC721 order.
     * 
     * @dev    Throws if the permit nonce is invalid.
     * @dev    Throws if the permit signature is invalid.
     * 
     * @param seller          The seller of the order.
     * @param orderDigest     The order digest.
     * @param matchedOrder    The order to verify.
     */
    function _permitTransferFromWithAdditionalDataERC721(
        address seller,
        bytes32 orderDigest,
        AdvancedOrder memory matchedOrder
    ) internal returns (bool isError) {
        Order memory saleDetails = matchedOrder.saleDetails;

        isError = IPermitC(matchedOrder.permitContext.permitProcessor).permitTransferFromWithAdditionalDataERC721(
            saleDetails.tokenAddress,
            saleDetails.tokenId,
            matchedOrder.permitContext.permitNonce,
            saleDetails.expiration,
            seller,
            saleDetails.beneficiary,
            orderDigest,
            PERMITTED_TRANSFER_SALE_APPROVAL,
            _repackSignature(matchedOrder.signature)
        );

        if (!isError) {
            emit PermittedOrderNonceInvalidated(
                matchedOrder.permitContext.permitNonce,
                saleDetails.nonce,
                seller,
                false
            );
        }
    }

    /**
     * @notice Concatenates the r, s, and v values of a signature into a single bytes array.
     *
     * @param signature The signature to repack.
     */
    function _repackSignature(SignatureECDSA memory signature) internal pure returns (bytes memory) {
        if(signature.v > type(uint8).max) {
            revert PaymentProcessor__InvalidSignatureV();
        }
        return abi.encodePacked(signature.r, signature.s, uint8(signature.v));
    }
}

File 26 of 29 : ICollectionSettingsRegistry.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "./IPaymentProcessorSettings.sol";
import "./SettingsDataTypes.sol";

/** 
* @title ICollectionSettingsRegistry
* @custom:version 3.0.0
* @author Limit Break, Inc.
*/ 
interface ICollectionSettingsRegistry {

    /// @notice Emitted when a new payment method whitelist is created.
    event CreatedPaymentMethodWhitelist(
        uint32 indexed paymentMethodWhitelistId, 
        address indexed whitelistOwner,
        string whitelistName);

    /// @notice Emitted when a coin is added to the approved coins mapping for a whitelist.
    event PaymentMethodAddedToWhitelist(
        uint32 indexed paymentMethodWhitelistId, 
        address indexed paymentMethod);

    /// @notice Emitted when a coin is removed from the approved coins mapping for a whitelist.
    event PaymentMethodRemovedFromWhitelist(
        uint32 indexed paymentMethodWhitelistId, 
        address indexed paymentMethod);

    /// @notice Emitted when a permit processor is added to the trusted permit processor list.
    event TrustedPermitProcessorAdded(address indexed permitProcessor);

    /// @notice Emitted when a permit processor is removed from the trusted permit processor list.
    event TrustedPermitProcessorRemoved(address indexed permitProcessor);

    /// @notice Emitted when payment settings are updated for a collection.
    event UpdatedCollectionPaymentSettings(
        address indexed tokenAddress,
        CollectionPaymentSettingsParams params
    );

    /// @notice Emitted whenever pricing bounds change at a token level for price-constrained collections.
    event UpdatedTokenLevelPricingBoundaries(
        address indexed tokenAddress, 
        uint256 indexed tokenId, 
        uint256 floorPrice, 
        uint256 ceilingPrice);

    /// @notice Emitted when a trusted channel is removed for a collection.
    event TrustedChannelRemovedForCollection(
        address indexed tokenAddress, 
        address indexed channel);

    /// @notice Emitted when a trusted channel is added for a collection.
    event TrustedChannelAddedForCollection(
        address indexed tokenAddress, 
        address indexed channel);

    /// @notice Emitted when a payment method whitelist is reassigned to a new owner.
    event ReassignedPaymentMethodWhitelistOwnership(uint32 indexed id, address indexed newOwner);

    function isCollectionSettingsInitialized(address tokenAddress) external view returns (bool);

    function getCollectionSettings(
        address tokenAddress,
        bytes32[] calldata dataExtensions,
        bytes32[] calldata wordExtensions
    ) external view returns (
        CollectionRegistryPaymentSettings memory collectionCoreSettings,
        RegistryPricingBounds memory collectionPricingBounds,
        address constrainedPricingPaymentMethod,
        address exclusiveBountyReceiver,
        bytes[] memory data, 
        bytes32[] memory words
    );

    function getCollectionSettingsExtendedData(
        address tokenAddress, 
        bytes32[] calldata extensions
    ) external view returns (bytes[] memory data);

    function getCollectionSettingsExtendedWords(
        address tokenAddress, 
        bytes32[] calldata extensions
    ) external view returns (bytes32[] memory words);

    function isWhitelistedPaymentMethod(
        uint32 whitelistId,
        address paymentMethod
    ) external view returns (bool paymentMethodWhitelisted);

    function isTrustedChannelForCollection(
        address tokenAddress,
        address channel
    ) external view returns (bool channelIsTrusted);

    function isTrustedPermitProcessor(
        address permitProcessor
    ) external view returns (bool isTrusted);

    function getTokenBoundPricing(
        address tokenAddress,
        uint256 tokenId
    ) external view returns (RegistryPricingBounds memory);
}

File 27 of 29 : IPaymentProcessorSettings.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "./SettingsDataTypes.sol";

/** 
* @title IPaymentProcessorSettings
* @custom:version 3.0.0
* @author Limit Break, Inc.
*/ 
interface IPaymentProcessorSettings {
    function registrySyncSettings(address tokenAddress) external;

    function registryUpdateWhitelistPaymentMethods(
        uint32 paymentMethodWhitelistId,
        address[] calldata paymentMethods,
        bool paymentMethodsAdded
    ) external;

    function registryUpdateTrustedChannels(
        address tokenAddress,
        address[] calldata channelsToUpdate,
        bool channelsAdded
    ) external;

    function registryUpdateTokenPricingBounds(
        address tokenAddress, 
        uint256[] calldata tokenIds, 
        RegistryPricingBounds[] calldata pricingBounds
    ) external;

    function registryUpdateTrustedPermitProcessors(
        address[] calldata permitProcessors,
        bool permitProcessorsAdded
    ) external;

    function checkSyncCollectionSettings(
        address tokenAddress
    ) external;

    function checkSyncTokenPricingBounds(
        address tokenAddress,
        uint256 tokenId
    ) external returns (uint256, uint256);
    
    function checkWhitelistedPaymentMethod(
        uint32 whitelistId,
        address paymentMethod
    ) external returns (bool isWhitelisted);
    
    function checkCollectionTrustedChannels(
        address tokenAddress,
        address channel
    ) external returns (bool isAllowed);
    
    function checkTrustedPermitProcessors(
        address permitProcessor
    ) external returns (bool isTrusted);
}

File 28 of 29 : SettingsDataTypes.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;


/**
 * @dev This struct defines the payment settings for a collection.
 * 
 * @dev **initialized**: True if the payment settings have been initialized, false otherwise.
 * @dev **paymentSettingsType**: The type of payment settings for the collection.
 * @dev **paymentMethodWhitelistId**: The ID of the payment method whitelist to use for the collection.
 * @dev **royaltyBackfillReceiver**: The address to use as the royalty backfill receiver.
 * @dev **royaltyBackfillNumerator**: The numerator to use for the royalty backfill.
 * @dev **royaltyBountyNumerator**: The numerator to use for the royalty bounty.
 * @dev **extraData**: Extra data for the payment settings.
 */
struct CollectionRegistryPaymentSettings {
    bool initialized;
    uint8 paymentSettingsType;
    uint32 paymentMethodWhitelistId;
    address royaltyBackfillReceiver;
    uint16 royaltyBackfillNumerator;
    uint16 royaltyBountyNumerator;
    uint16 extraData;
}

/**
 * @dev This struct defines the parameters for collection payment settings.
 *
 * @dev **paymentSettings**: The payment settings for the collection.
 * @dev **paymentMethodWhitelistId**: The ID of the payment method whitelist to use for the collection.
 * @dev **constrainedPricingPaymentMethod**: The payment method to use for constrained pricing.
 * @dev **royaltyBackfillNumerator**: The numerator to use for the royalty backfill.
 * @dev **royaltyBackfillReceiver**: The address to use as the royalty backfill receiver.
 * @dev **royaltyBountyNumerator**: The numerator to use for the royalty bounty.
 * @dev **exclusiveBountyReceiver**: The address to use as the exclusive bounty receiver.
 * @dev **extraData**: Extra data for the payment settings.
 * @dev **collectionMinimumFloorPrice**: The minimum floor price for the collection.
 * @dev **collectionMaximumCeilingPrice**: The maximum ceiling price for the collection.
 * @dev **flags**: The flags for the payment settings.
 */
struct CollectionPaymentSettingsParams {
    uint8 paymentSettings;
    uint32 paymentMethodWhitelistId;
    address constrainedPricingPaymentMethod;
    uint16 royaltyBackfillNumerator;
    address royaltyBackfillReceiver;
    uint16 royaltyBountyNumerator;
    address exclusiveBountyReceiver;
    uint16 extraData;
    uint120 collectionMinimumFloorPrice;
    uint120 collectionMaximumCeilingPrice;
}

/**
 * @dev This struct defines the pricing bounds for a registry.
 *
 * @dev **isSet**: True if the pricing bounds are set, false otherwise.
 * @dev **floorPrice**: The floor price for the registry.
 * @dev **ceilingPrice**: The ceiling price for the registry.
 */
struct RegistryPricingBounds {
    bool isSet;
    uint120 floorPrice;
    uint120 ceilingPrice;
}

File 29 of 29 : PaymentProcessorStorageAccess.sol
//SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
pragma solidity 0.8.24;

import "../DataTypes.sol";

/** 
* @title PaymentProcessorStorageAccess
* @custom:version 3.0.0
* @author Limit Break, Inc.
*/ 
contract PaymentProcessorStorageAccess {

    /// @dev The base storage slot for Payment Processor contract storage items.
    bytes32 constant DIAMOND_STORAGE_PAYMENT_PROCESSOR = 
        0x0000000000000000000000000000000000000000000000000000000000009A1D;

    /**
     * @dev Returns a storage object that follows the Diamond standard storage pattern for
     * @dev contract storage across multiple module contracts.
     */
    function appStorage() internal pure returns (PaymentProcessorStorage storage diamondStorage) {
        bytes32 slot = DIAMOND_STORAGE_PAYMENT_PROCESSOR;
        assembly {
            diamondStorage.slot := slot
        }
    }
}

Settings
{
  "remappings": [
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "@rari-capital/solmate/=lib/solmate/",
    "murky/=lib/murky/src/",
    "@limitbreak/trusted-forwarder/=lib/TrustedForwarder/src/",
    "@limitbreak/permit-c/=lib/PermitC/src/",
    "@limitbreak/tm-core-lib/=lib/tm-core-lib/",
    "@limitbreak/wrapped-native/=lib/wrapped-native/src/",
    "@limitbreak/tm-role-server/=lib/tm-role-server/src/",
    "PermitC/=lib/PermitC/",
    "TrustedForwarder/=lib/TrustedForwarder/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-metering/=lib/PermitC/lib/forge-gas-metering/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "solady/=lib/PermitC/lib/forge-gas-metering/lib/solady/",
    "solmate/=lib/solmate/src/",
    "tm-core-lib/=lib/tm-core-lib/src/",
    "tm-role-server/=lib/tm-role-server/src/",
    "wrapped-native/=lib/wrapped-native/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 40000
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  },
  "evmVersion": "cancun",
  "viaIR": false,
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"configurationContract","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"PaymentProcessor__AmountExceedsMaximum","type":"error"},{"inputs":[],"name":"PaymentProcessor__AmountForERC1155SalesGreaterThanZero","type":"error"},{"inputs":[],"name":"PaymentProcessor__AmountForERC721SalesMustEqualOne","type":"error"},{"inputs":[],"name":"PaymentProcessor__BadCalldataLength","type":"error"},{"inputs":[],"name":"PaymentProcessor__CosignatureHasExpired","type":"error"},{"inputs":[],"name":"PaymentProcessor__CosignerHasSelfDestructed","type":"error"},{"inputs":[],"name":"PaymentProcessor__EIP1271SignatureInvalid","type":"error"},{"inputs":[],"name":"PaymentProcessor__FailedToTransferProceeds","type":"error"},{"inputs":[],"name":"PaymentProcessor__FeeOnTopCannotBeGreaterThanItemPrice","type":"error"},{"inputs":[],"name":"PaymentProcessor__InputArrayLengthCannotBeZero","type":"error"},{"inputs":[],"name":"PaymentProcessor__InputArrayLengthMismatch","type":"error"},{"inputs":[],"name":"PaymentProcessor__InvalidBulkOrderHeight","type":"error"},{"inputs":[],"name":"PaymentProcessor__InvalidConstructorArguments","type":"error"},{"inputs":[],"name":"PaymentProcessor__InvalidOrderProtocol","type":"error"},{"inputs":[],"name":"PaymentProcessor__InvalidSignatureV","type":"error"},{"inputs":[],"name":"PaymentProcessor__MarketplaceAndRoyaltyFeesWillExceedSalePrice","type":"error"},{"inputs":[],"name":"PaymentProcessor__NotAuthorizedByCosigner","type":"error"},{"inputs":[],"name":"PaymentProcessor__OnchainRoyaltiesExceedMaximumApprovedRoyaltyFee","type":"error"},{"inputs":[],"name":"PaymentProcessor__OrderHasExpired","type":"error"},{"inputs":[],"name":"PaymentProcessor__OrderIsEitherCancelledOrFilled","type":"error"},{"inputs":[],"name":"PaymentProcessor__OrderProtocolERC1155FillPartialUnsupportedInSweeps","type":"error"},{"inputs":[],"name":"PaymentProcessor__PartialFillsNotSupportedForNonDivisibleItems","type":"error"},{"inputs":[],"name":"PaymentProcessor__PaymentCoinIsNotAnApprovedPaymentMethod","type":"error"},{"inputs":[],"name":"PaymentProcessor__PermitProcessorNotTrusted","type":"error"},{"inputs":[],"name":"PaymentProcessor__ProtocolFeeOrTaxExceedsCap","type":"error"},{"inputs":[],"name":"PaymentProcessor__ProtocolFeeVersionExpired","type":"error"},{"inputs":[],"name":"PaymentProcessor__RanOutOfNativeFunds","type":"error"},{"inputs":[],"name":"PaymentProcessor__SalePriceAboveMaximumCeiling","type":"error"},{"inputs":[],"name":"PaymentProcessor__SalePriceBelowMinimumFloor","type":"error"},{"inputs":[],"name":"PaymentProcessor__SignatureAlreadyUsedOrRevoked","type":"error"},{"inputs":[],"name":"PaymentProcessor__SignatureNotUsedOrRevoked","type":"error"},{"inputs":[],"name":"PaymentProcessor__TradeOriginatedFromUntrustedChannel","type":"error"},{"inputs":[],"name":"PaymentProcessor__TradingIsPausedForCollection","type":"error"},{"inputs":[],"name":"PaymentProcessor__UnableToFillMinimumRequestedQuantity","type":"error"},{"inputs":[],"name":"PaymentProcessor__UnauthorizedOrder","type":"error"},{"inputs":[],"name":"PaymentProcessor__UnauthorizedTaker","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"address","name":"beneficiary","type":"address"},{"indexed":false,"internalType":"address","name":"paymentCoin","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"AcceptOfferERC1155","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"address","name":"beneficiary","type":"address"},{"indexed":false,"internalType":"address","name":"paymentCoin","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"AcceptOfferERC721","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"address","name":"beneficiary","type":"address"},{"indexed":false,"internalType":"address","name":"paymentCoin","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"BuyListingERC1155","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"address","name":"beneficiary","type":"address"},{"indexed":false,"internalType":"address","name":"paymentCoin","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"salePrice","type":"uint256"}],"name":"BuyListingERC721","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"cosigner","type":"address"}],"name":"DestroyedCosigner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"MasterNonceInvalidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"wasCancellation","type":"bool"}],"name":"NonceInvalidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":true,"internalType":"address","name":"account","type":"address"}],"name":"NonceRestored","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderDigest","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"wasCancellation","type":"bool"}],"name":"OrderDigestInvalidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderDigest","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountFilled","type":"uint256"}],"name":"OrderDigestItemsFilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderDigest","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountRestoredToOrder","type":"uint256"}],"name":"OrderDigestItemsRestored","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderDigest","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"orderStartAmount","type":"uint256"}],"name":"OrderDigestOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"paymentMethodWhitelistId","type":"uint32"},{"indexed":true,"internalType":"address","name":"paymentMethod","type":"address"}],"name":"PaymentMethodAddedToWhitelist","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"paymentMethodWhitelistId","type":"uint32"},{"indexed":true,"internalType":"address","name":"paymentMethod","type":"address"}],"name":"PaymentMethodRemovedFromWhitelist","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"permitNonce","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"orderNonce","type":"uint256"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"wasCancellation","type":"bool"}],"name":"PermittedOrderNonceInvalidated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newProtocolFeeRecipient","type":"address"},{"indexed":false,"internalType":"uint16","name":"minimumProtocolFeeBps","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"marketplaceFeeProtocolTaxBps","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"feeOnTopProtocolTaxBps","type":"uint16"},{"indexed":false,"internalType":"uint48","name":"gracePeriodExpiration","type":"uint48"}],"name":"ProtocolFeesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":true,"internalType":"address","name":"channel","type":"address"}],"name":"TrustedChannelAddedForCollection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":true,"internalType":"address","name":"channel","type":"address"}],"name":"TrustedChannelRemovedForCollection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"permitProcessor","type":"address"}],"name":"TrustedPermitProcessorAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"permitProcessor","type":"address"}],"name":"TrustedPermitProcessorRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"floorPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ceilingPrice","type":"uint256"}],"name":"UpdatedCollectionLevelPricingBoundaries","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":false,"internalType":"enum PaymentSettings","name":"paymentSettings","type":"uint8"},{"indexed":true,"internalType":"uint32","name":"paymentMethodWhitelistId","type":"uint32"},{"indexed":true,"internalType":"address","name":"constrainedPricingPaymentMethod","type":"address"},{"indexed":false,"internalType":"uint16","name":"royaltyBackfillNumerator","type":"uint16"},{"indexed":false,"internalType":"address","name":"royaltyBackfillReceiver","type":"address"},{"indexed":false,"internalType":"uint16","name":"royaltyBountyNumerator","type":"uint16"},{"indexed":false,"internalType":"address","name":"exclusiveBountyReceiver","type":"address"},{"indexed":false,"internalType":"bool","name":"blockTradesFromUntrustedChannels","type":"bool"},{"indexed":false,"internalType":"bool","name":"useRoyaltyBackfillAsRoyaltySource","type":"bool"}],"name":"UpdatedCollectionPaymentSettings","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"floorPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"ceilingPrice","type":"uint256"}],"name":"UpdatedTokenLevelPricingBoundaries","type":"event"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct FeeOnTop","name":"feeOnTop","type":"tuple"},{"components":[{"internalType":"uint256","name":"protocol","type":"uint256"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"paymentMethod","type":"address"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct SweepOrder","name":"sweepOrder","type":"tuple"},{"components":[{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"marketplace","type":"address"},{"internalType":"address","name":"fallbackRoyaltyRecipient","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"itemPrice","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"marketplaceFeeNumerator","type":"uint256"},{"internalType":"uint256","name":"maxRoyaltyFeeNumerator","type":"uint256"},{"internalType":"uint256","name":"protocolFeeVersion","type":"uint256"}],"internalType":"struct SweepItem[]","name":"items","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"v","type":"uint256"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct SignatureECDSA[]","name":"signedSellOrders","type":"tuple[]"},{"components":[{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"v","type":"uint256"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct Cosignature[]","name":"cosignatures","type":"tuple[]"}],"name":"sweepCollection","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"internalType":"struct FeeOnTop","name":"feeOnTop","type":"tuple"},{"components":[{"internalType":"uint256","name":"protocol","type":"uint256"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"paymentMethod","type":"address"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct SweepOrder","name":"sweepOrder","type":"tuple"},{"components":[{"components":[{"internalType":"address","name":"maker","type":"address"},{"internalType":"address","name":"marketplace","type":"address"},{"internalType":"address","name":"fallbackRoyaltyRecipient","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"itemPrice","type":"uint256"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"marketplaceFeeNumerator","type":"uint256"},{"internalType":"uint256","name":"maxRoyaltyFeeNumerator","type":"uint256"},{"internalType":"uint256","name":"protocolFeeVersion","type":"uint256"}],"internalType":"struct SweepItem","name":"sweepItem","type":"tuple"},{"components":[{"internalType":"uint256","name":"v","type":"uint256"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct SignatureECDSA","name":"signature","type":"tuple"},{"components":[{"internalType":"address","name":"signer","type":"address"},{"internalType":"address","name":"taker","type":"address"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"uint256","name":"v","type":"uint256"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"internalType":"struct Cosignature","name":"cosignature","type":"tuple"},{"components":[{"internalType":"address","name":"permitProcessor","type":"address"},{"internalType":"uint256","name":"permitNonce","type":"uint256"}],"internalType":"struct PermitContext","name":"permitContext","type":"tuple"},{"components":[{"internalType":"uint256","name":"orderIndex","type":"uint256"},{"internalType":"bytes32[]","name":"proof","type":"bytes32[]"}],"internalType":"struct BulkOrderProof","name":"bulkOrderProof","type":"tuple"}],"internalType":"struct AdvancedSweepItem[]","name":"items","type":"tuple[]"}],"internalType":"struct AdvancedSweep","name":"advancedSweep","type":"tuple"}],"name":"sweepCollectionAdvanced","outputs":[],"stateMutability":"payable","type":"function"}]

6101e060405234801562000011575f80fd5b5060405162005c3838038062005c3883398101604081905262000034916200035f565b808080806001600160a01b031663ed7e776c6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000074573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200009a91906200035f565b806001600160a01b03166080816001600160a01b031681525050505f805f805f856001600160a01b0316638e71e7196040518163ffffffff1660e01b815260040161014060405180830381865afa158015620000f8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200011e9190620003ef565b95509550509450945094505f6001600160a01b0316846001600160a01b031614806200015157506001600160a01b038216155b15620001705760405163049b2c3f60e31b815260040160405180910390fd5b6001600160a01b0380851660a0528351811660c052602080850151821660e05260408086015183166101005260608601518316610120529184166101405281518083018352601081526f2830bcb6b2b73a283937b1b2b9b9b7b960811b908201528151808301835260058152640332e302e360dc1b90820152905162000287917f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f917fdab569368da3525b394950b18252b2a008851cf1162b59295579c87c37790526917fd7a1ce683065975771bedf401ecab037f4f4c62cc51fefdc8b39dd246ff0343a9146918b91019485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b60408051601f198184030181528282528051602090910120610160526001600160a01b0392831661018052638e71e71960e01b8252515f97509188169550638e71e7199450600480820194506101409350908290030181865afa158015620002f1573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620003179190620003ef565b505080516001600160a01b039081166101a052602090910151166101c05250620004f395505050505050565b80516001600160a01b03811681146200035a575f80fd5b919050565b5f6020828403121562000370575f80fd5b6200037b8262000343565b9392505050565b5f6040828403121562000393575f80fd5b604080519081016001600160401b0381118282101715620003c257634e487b7160e01b5f52604160045260245ffd5b604052905080620003d38362000343565b8152620003e36020840162000343565b60208201525092915050565b5f805f805f8086880361014081121562000407575f80fd5b620004128862000343565b9650620004226020890162000343565b95506080603f198201121562000436575f80fd5b50604051608081016001600160401b03811182821017156200046657634e487b7160e01b5f52604160045260245ffd5b8060405250620004796040890162000343565b8152620004896060890162000343565b60208201526200049c6080890162000343565b6040820152620004af60a0890162000343565b60608201529350620004c58860c0890162000382565b9250620004d6610100880162000343565b9150620004e7610120880162000343565b90509295509295509295565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516156bd6200057b5f395f61395a01525f61390501525f50505f81816132050152818161383b0152613eda01525f50505f611b8501525f611b2a01525f611acf01525f611a7401525f611a1901525f818160d9015261075301526156bd5ff3fe608060405260043610610033575f3560e01c8063572b6c05146100375780636a89f68a1461006a578063b9d8d5a61461007f575b5f80fd5b348015610042575f80fd5b50610056610051366004614cbb565b610092565b604051901515815260200160405180910390f35b61007d610078366004614d9f565b61014a565b005b61007d61008d366004614e82565b610264565b6040517f572b6c0500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82811660048301525f917f00000000000000000000000000000000000000000000000000000000000000009091169063572b6c0590602401602060405180830381865afa158015610120573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101449190614ec8565b92915050565b604080516101608101909152338152610280860236037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7c01905f906020810161019284610409565b73ffffffffffffffffffffffffffffffffffffffff1681525f602080830182905260408084018390526060808501849052608080860185905260a080870186905260c0870186905260e087018690527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61010088015283519081018452858152938401859052918301849052820183905281018290526101209092019190915290915061024782348d8d8d8d8d8d8d8d610457565b905061025781836020015161063c565b5050505050505050505050565b5f61027260c0830183614ee1565b6103600236037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedc0191505f90505b6102ad60c0840184614ee1565b9050811015610312576102c360c0840184614ee1565b828181106102d3576102d3614f45565b90506020028101906102e59190614f72565b6102f4906102c0810190614fae565b610302906020810190614ee1565b60200290920391506001016102a0565b505f6040518061016001604052803373ffffffffffffffffffffffffffffffffffffffff16815260200161034584610409565b73ffffffffffffffffffffffffffffffffffffffff1681525f602080830182905260408084018390526060808501849052608080860185905260a080870186905260c0870186905260e087018690527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101008801528351908101845285815293840185905291830184905282018390528101829052610120909201919091529091506103f3823486610650565b905061040381836020015161063c565b50505050565b338115610452578160141461044a576040517f06dbb06700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610144610723565b919050565b5f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8835016104b2576040517f4746e96900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8584146104eb576040517fb62503e300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b858214610524576040517fb62503e300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f86900361055e576040517fdb560cb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6105778c610572368c90038c018c614fe0565b61080e565b905061062c8c8c8c8c8c8c8c8c808060200260200160405190810160405280939291908181526020015f905b828210156105cf576105c060608302860136819003810190615079565b815260200190600101906105a3565b50505050508b8b808060200260200160405190810160405280939291908181526020015f905b828210156106215761061260c083028601368190038101906150f8565b815260200190600101906105f5565b505050505089610c21565b9c9b505050505050505050505050565b811561064c5761064c818361124b565b5050565b5f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6040830135016106ae576040517f4746e96900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106bb60c0830183614ee1565b90505f036106f5576040517fdb560cb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61070c8561057236869003860160408701614fe0565b905061071a84848784611292565b95945050505050565b6040517f572b6c050000000000000000000000000000000000000000000000000000000081523360048201525f907f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff169063572b6c0590602401602060405180830381865afa1580156107ad573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107d19190614ec8565b15610809576014361061080957507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec36013560601c90565b503390565b610816614a75565b60208281015173ffffffffffffffffffffffffffffffffffffffff165f908152619a1f90915260409020805460ff166108ca5760208301516040517fc1f8dd0c00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091166004820152309063c1f8dd0c906024015f604051808303815f87803b1580156108b3575f80fd5b505af11580156108c5573d5f803e3d5ffd5b505050505b805473ffffffffffffffffffffffffffffffffffffffff660100000000000082041660a086015261ffff7a0100000000000000000000000000000000000000000000000000008204811660808701527c010000000000000000000000000000000000000000000000000000000082041660c086015260ff61010082048116917e0100000000000000000000000000000000000000000000000000000000000090041661097c81600260ff911616151590565b156109c8576109928560200151875f015161191a565b6109c8576040517f292d235200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600481161515610100870152600181166109e2575f610a12565b60208581015173ffffffffffffffffffffffffffffffffffffffff9081165f908152619a24909252604090912054165b73ffffffffffffffffffffffffffffffffffffffff1660e08701525f826005811115610a4057610a406151a1565b03610a8d57610a5285604001516119f3565b610a88576040517fab9c00de00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610be2565b6002826005811115610aa157610aa16151a1565b03610ac35782546040860151610a529162010000900463ffffffff1690611be4565b6004826005811115610ad757610ad76151a1565b1480610af457506003826005811115610af257610af26151a1565b145b15610b975760408581015160208088015173ffffffffffffffffffffffffffffffffffffffff9081165f908152619a23909252929020548216911614610b66576040517fab9c00de00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608401826005811115610b7c57610b7c6151a1565b90816005811115610b8f57610b8f6151a1565b905250610be2565b6005826005811115610bab57610bab6151a1565b03610be2576040517fba78259100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610bf45f8660400151875f0151611c74565b845250505060409182015173ffffffffffffffffffffffffffffffffffffffff1691810191909152919050565b875f80805b878110156111fe5736898983818110610c4157610c41614f45565b9050610160020190505f6040518061022001604052808d5f01358152602001835f016020810190610c729190614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020018d6060016020810190610ca09190614cbb565b73ffffffffffffffffffffffffffffffffffffffff168152602001836020016020810190610cce9190614cbb565b73ffffffffffffffffffffffffffffffffffffffff168152602001610cf96060850160408601614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020018d6040016020810190610d279190614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020018d6020016020810190610d559190614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200183606001358152602001836080013581526020018360a001357dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681526020018360c0013581526020018360e00135815260200183610100013581526020018361012001358152602001836080013581526020018360800135815260200183610140013581525090508061020001518f610120015114610f29578061020001518f610120018181525050610e21619a1d90565b600e015f82610200015181526020019081526020015f206040518060a00160405290815f82015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020015f820160149054906101000a900461ffff1661ffff1661ffff1681526020015f820160169054906101000a900461ffff1661ffff1661ffff1681526020015f820160189054906101000a900461ffff1661ffff1661ffff1681526020015f8201601a9054906101000a900465ffffffffffff1665ffffffffffff1665ffffffffffff16815250508f61014001819052505b610120810151610f3990866151fb565b8151909550610f8657600181610100015114610f81576040517fdb3ca79a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61101e565b80517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01610fec578061010001515f03610f81576040517f26db27f100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fa799542700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612710816101a0015182610180015161103791906151fb565b111561106f576040517fca9d1e5400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600487606001516005811115611087576110876151a1565b14806110a857506003876060015160058111156110a6576110a66151a1565b145b156110d0576110d087606001518260c001518360e00151846101000151856101200151611d65565b80610160015142111561110f576040517fac492cc000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8e61014001516080015165ffffffffffff1642111561115a576040517f1463d5d500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6127108f61014001516020015161ffff1611156111a3576040517febaa3f7900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6111e18f828b86815181106111ba576111ba614f45565b60200260200101518b87815181106111d4576111d4614f45565b6020026020010151611e07565b506111ef8f82898988611e2f565b90965093505050600101610c26565b50818a60200135111561123d576040517f1d6203f500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61062c8c858c848688612251565b5f805f805f85875af190508061128d576040517f6c998d3e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050565b835f806040860136826112a860c08a018a614ee1565b915091505f5b818110156118bf57368383838181106112c9576112c9614f45565b90506020028101906112db9190614f72565b9050806112e6614b00565b6112f9368490038401610280850161520e565b60608201526113113684900384016101608501615079565b60208201526113293684900384016101c085016150f8565b604080830191909152805161022081019091528735815260208082019061135290850185614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200161137d60808a0160608b01614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020018360200160208101906113ab9190614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020016113d66060850160408601614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200161140160608a0160408b01614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200188602001602081019061142f9190614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200183606001358152602001836080013581526020018360a001357dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681526020018360c0013581526020018360e001358152602001836101000135815260200183610120013581526020018360800135815260200183608001358152602001836101400135815250815f01819052505f815f015190508061020001518d6101200151146115d057610200810180516101208f0152515f908152619a2b6020908152604091829020825160a081018452905473ffffffffffffffffffffffffffffffffffffffff8116825274010000000000000000000000000000000000000000810461ffff9081169383019390935276010000000000000000000000000000000000000000000081048316938201939093527801000000000000000000000000000000000000000000000000830490911660608201527a01000000000000000000000000000000000000000000000000000090910465ffffffffffff1660808201526101408e01525b6101208101516115e0908b6151fb565b8151909a5061162d57600181610100015114611628576040517fdb3ca79a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611693565b80517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01610fec578061010001515f03611628576040517f26db27f100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612710816101a001518261018001516116ac91906151fb565b11156116e4576040517fca9d1e5400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60048c6060015160058111156116fc576116fc6151a1565b148061171d575060038c60600151600581111561171b5761171b6151a1565b145b15611745576117458c606001518260c001518360e00151846101000151856101200151611d65565b806101600151421115611784576040517fac492cc000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8c61014001516080015165ffffffffffff164211156117cf576040517f1463d5d500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6127108d61014001516020015161ffff161115611818576040517febaa3f7900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608201515173ffffffffffffffffffffffffffffffffffffffff1661189d576118466102c0850185614fae565b611854906020810190614ee1565b90505f03611876576118708d8284602001518560400151611e07565b5061189d565b61189b8d828460200151856040015188806102c001906118969190614fae565b61245c565b505b6118aa828e8e8e8d612492565b909b50985050600190930192506112ae915050565b5060208901358510156118fe576040517f1d6203f500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61190c88888b87898b612251565b9a9950505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff82165f908152619a26602052604081206119499083612947565b1561195657506001610144565b6040517f7a3f5d8c00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8085166004830152831660248201523090637a3f5d8c906044015b6020604051808303815f875af11580156119c8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119ec9190614ec8565b9392505050565b5f73ffffffffffffffffffffffffffffffffffffffff8216611a1757506001919050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611a7257506001919050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611acd57506001919050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611b2857506001919050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611b8357506001919050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611bde57506001919050565b6101445f835b63ffffffff8281165f908152619a20602052604081209091611c099190849061294716565b15611c1657506001610144565b6040517feb5e068d00000000000000000000000000000000000000000000000000000000815263ffffffff8416600482015273ffffffffffffffffffffffffffffffffffffffff83166024820152309063eb5e068d906044016119ac565b611c9b6040518060600160405280614c8e8152602001614c8e8152602001614c8e81525090565b60408051606081019091528073ffffffffffffffffffffffffffffffffffffffff851615611ccb57612975611ccf565b6129b85b67ffffffffffffffff1681526020018315611cec576129c2611cf0565b612a785b67ffffffffffffffff1681526020018315611d2d575f866001811115611d1857611d186151a1565b14611d2557612ade611d51565b612bc1611d51565b5f866001811115611d4057611d406151a1565b14611d4d57612c98611d51565b612d605b67ffffffffffffffff169052949350505050565b5f80611d72878787612e28565b915091505f848481611d8657611d86615288565b04905081811115611dc3576040517f9837ddd700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82811015611dfd576040517f9318944000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050505050505050565b5f61071a85858585611e2a898a60200151895f0151611e258d613047565b613099565b6131d5565b5f80839150829050611e64866020015187604001518860c001518960e001518a61010001518a5f01516020015163ffffffff16565b1561222b575f611e99888861012001518960c001518a60e001518b606001518c61018001518d6101a001518e608001516132a4565b61012088015160a089015193019290915073ffffffffffffffffffffffffffffffffffffffff16611f0e57866101200151831015611f03576040517f70d5b32e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b866101200151830392505b85602001516040015173ffffffffffffffffffffffffffffffffffffffff16815f015173ffffffffffffffffffffffffffffffffffffffff1614611fba57602086015160c0015115611f8857611f8886602001516040015189602001518860400151896020015160c001518a5f01515f015163ffffffff16565b805160208701805173ffffffffffffffffffffffffffffffffffffffff909216604090920191909152515f60c0909101525b85602001516020015173ffffffffffffffffffffffffffffffffffffffff16876060015173ffffffffffffffffffffffffffffffffffffffff161461206a57602086015160a00151156120355761203586602001516020015189602001518860400151896020015160a001518a5f01515f015163ffffffff16565b60608701516020808801805173ffffffffffffffffffffffffffffffffffffffff9093169290910191909152515f60a0909101525b85602001515f015173ffffffffffffffffffffffffffffffffffffffff16876020015173ffffffffffffffffffffffffffffffffffffffff161461210e57602086015160800151156120df576020808701518051918a015160408901516080909201518951516120df9493919063ffffffff16565b602080880151908701805173ffffffffffffffffffffffffffffffffffffffff909216909152515f6080909101525b85602001516060015173ffffffffffffffffffffffffffffffffffffffff168861014001515f015173ffffffffffffffffffffffffffffffffffffffff16146121c557602086015160e001511561218d5761218d86602001516060015189602001518860400151896020015160e001518a5f01515f015163ffffffff16565b6101408801515160208701805173ffffffffffffffffffffffffffffffffffffffff909216606090920191909152515f60e091909101525b602080820151908701805160c0018051909201909152604080830151825160a001805190910190526060830151825160809081018051909201909152830151915160e001805190920190915286510151612225908990899063ffffffff16565b50612247565b8551600214612247576122478660200151876101400151613639565b9550959350505050565b805f6122606020870187614cbb565b73ffffffffffffffffffffffffffffffffffffffff161461236957602085013515612369575f80846122968760208a01356152b5565b6122a091906152cc565b90505f6127108a61014001516060015161ffff16836122bf91906152b5565b6122c991906152cc565b60408a0151818403945090915073ffffffffffffffffffffffffffffffffffffffff16612330578184101561232a576040517f70d5b32e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81840393505b61235761234060208a018a614cbb565b60208c015160408c01518c5151879063ffffffff16565b602089015160e0018051909101905250505b602086015160e00151156123a3576101408701515160208089015160408901519189015160e001518951516123a39493919063ffffffff16565b602086015160c00151156123df576123df86602001516040015188602001518860400151896020015160c001518a5f01515f015163ffffffff16565b602086015160a001511561241b5761241b86602001516020015188602001518860400151896020015160a001518a5f01515f015163ffffffff16565b602086015160800151156124525760208087015180519189015160408901516080909201518951516124529493919063ffffffff16565b9695505050505050565b5f80612474868760200151865f0151611e258a613047565b90506124878787878787866136fb61376d565b979650505050505050565b8451606086015151839183915f9073ffffffffffffffffffffffffffffffffffffffff16612511576124e7826020015183604001518460c001518560e001518661010001518c5f01516020015163ffffffff16565b159050801561250c57815160021461250c5761250c8260200151836101400151613639565b612578565b60608901515161252090613902565b612556576040517f14db8bdb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f612568600184602001518c8c613a37565b925090506125768184613b53565b505b8061293b575f6125ad898461012001518560c001518660e001518760600151886101800151896101a001518a608001516132a4565b61012084015160a085015195019490915073ffffffffffffffffffffffffffffffffffffffff1661262257826101200151851015612617576040517f70d5b32e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b826101200151850394505b87602001516040015173ffffffffffffffffffffffffffffffffffffffff16815f015173ffffffffffffffffffffffffffffffffffffffff16146126ce57602088015160c001511561269c5761269c8860200151604001518a602001518a604001518b6020015160c001518c5f01515f015163ffffffff16565b805160208901805173ffffffffffffffffffffffffffffffffffffffff909216604090920191909152515f60c0909101525b87602001516020015173ffffffffffffffffffffffffffffffffffffffff16836060015173ffffffffffffffffffffffffffffffffffffffff161461277e57602088015160a0015115612749576127498860200151602001518a602001518a604001518b6020015160a001518c5f01515f015163ffffffff16565b60608301516020808a01805173ffffffffffffffffffffffffffffffffffffffff9093169290910191909152515f60a0909101525b87602001515f015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff161461282257602088015160800151156127f3576020808901518051918b015160408b01516080909201518b51516127f39493919063ffffffff16565b602080840151908901805173ffffffffffffffffffffffffffffffffffffffff909216909152515f6080909101525b87602001516060015173ffffffffffffffffffffffffffffffffffffffff168961014001515f015173ffffffffffffffffffffffffffffffffffffffff16146128d957602088015160e00151156128a1576128a18860200151606001518a602001518a604001518b6020015160e001518c5f01515f015163ffffffff16565b6101408901515160208901805173ffffffffffffffffffffffffffffffffffffffff909216606090920191909152515f60e091909101525b602080820151908901805160c0018051909201909152604080830151825160a001805190910190526060830151825160809081018051909201909152830151915160e001805190920190915288510151612939908a90859063ffffffff16565b505b50509550959350505050565b73ffffffffffffffffffffffffffffffffffffffff81165f90815260018301602052604081205415156119ec565b61298182848684613bda565b15610403576040517f6c998d3e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610403848261124b565b6040517ff242432a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86811660048301528581166024830152604482018490526064820183905260a060848301525f60a48301819052919085169063f242432a9060c4015b5f604051808303815f87803b158015612a50575f80fd5b505af1925050508015612a61575060015b612a6c57505f61071a565b50600195945050505050565b6040517f23b872dd00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86811660048301528581166024830152604482018490525f91908516906323b872dd90606401612a39565b8060c0015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff167f6f4c56c4b9a9d2479f963d802b19d17b02293ce1225461ac0cb846c482ee3c3e84604001518560a001518660e00151876101000151886101200151604051612bb595949392919073ffffffffffffffffffffffffffffffffffffffff958616815293909416602084015260408301919091526060820152608081019190915260a00190565b60405180910390a45050565b8060c0015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff167f1217006325a98bdcc6afc9c44965bb66ac7460a44dc57c2ac47622561d25c45a84604001518560a001518660e00151876101000151886101200151604051612bb595949392919073ffffffffffffffffffffffffffffffffffffffff958616815293909416602084015260408301919091526060820152608081019190915260a00190565b8060c0015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff167f8b87c0b049fe52718fe6ff466b514c5a93c405fb0de8fbd761a23483f9f9e19884604001518560a001518660e00151876101200151604051612bb5949392919073ffffffffffffffffffffffffffffffffffffffff94851681529290931660208301526040820152606081019190915260800190565b8060c0015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff167fffb29e9cf48456d56b6d414855b66a7ec060ce2054dcb124a1876310e1b7355c84604001518560a001518660e00151876101200151604051612bb5949392919073ffffffffffffffffffffffffffffffffffffffff94851681529290931660208301526040820152606081019190915260800190565b5f806004856005811115612e3e57612e3e6151a1565b03612f635773ffffffffffffffffffffffffffffffffffffffff84165f908152619a22602090815260408083208684529091529020805460ff16612f19576040517f7a67b4a000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86166004820152602481018590523090637a67b4a09060440160408051808303815f875af1158015612eeb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f0f91906152df565b925092505061303f565b8054610100900460ff1615612f6157546effffffffffffffffffffffffffffff620100008204811693507101000000000000000000000000000000000090910416905061303f565b505b73ffffffffffffffffffffffffffffffffffffffff84165f908152619a2160209081526040918290208251608081018452905460ff80821615158352610100820416158015938301939093526effffffffffffffffffffffffffffff62010000820481169483019490945271010000000000000000000000000000000000900490921660608301526130175760408101516060909101516effffffffffffffffffffffffffffff918216935016905061303f565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92509250505b935093915050565b80515f9060021461306b5761306682602001518361014001515f613c51565b610144565b619a1d60209283015173ffffffffffffffffffffffffffffffffffffffff165f908152925250604090205490565b835160608086015160808088015160a0808a015160c0808c015160408051610240810182526101008082527f36e5aab0dde52c07206863cf8fe7b4b1a25be63a3ae5286f8fe80d159c154c4f602083015260ff909b169181019190915273ffffffffffffffffffffffffffffffffffffffff8c8116998201999099528c8916968101969096529587169285019290925291851690830152831660e08201529116918101919091525f9061071a906131ba9060e08801516101008901516101208a01516101608b01516101808c01516101a08d01516101408e01518b88516101008082018b526020918b019182019990995260408101979097526060870195909552608086019390935260a085019190915260c084015260e083015291015290565b61020087015181516020818401810192909252810191012090565b81515f9073ffffffffffffffffffffffffffffffffffffffff16156131ff576131ff868585613d4a565b5f61322a7f000000000000000000000000000000000000000000000000000000000000000084613f7a565b905061323b86602001518683613fb9565b85517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0161329157613283866020015184886101000151896101c001518a6101e00151614079565b60608801849052915061329a565b85610100015191505b5095945050505050565b6132e76040518060a001604052805f73ffffffffffffffffffffffffffffffffffffffff1681526020015f81526020015f81526020015f81526020015f81525090565b606081018890526101008901515f808261331a576133068a8a8d6143c2565b945090925090505f81900361331a57600192505b821561340d5760a08c015173ffffffffffffffffffffffffffffffffffffffff16156133c857858c6080015161ffff161115613382576040517f1bdbc8f400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60a08c015173ffffffffffffffffffffffffffffffffffffffff16845260808c01516127109061ffff168c025b046020850181905260608501805191909103905261349d565b73ffffffffffffffffffffffffffffffffffffffff8516156134085773ffffffffffffffffffffffffffffffffffffffff851684526127108b87026133af565b61349d565b73ffffffffffffffffffffffffffffffffffffffff821661342b57505f5b801561349d576127108b870204811115613471576040517f1bdbc8f400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff821684526020840181905260608401805182900390525b73ffffffffffffffffffffffffffffffffffffffff8816156135b6576127108b8802046040850181905260608501805191909103905260c08c015161ffff161561357d5760e08c015173ffffffffffffffffffffffffffffffffffffffff16158061353757508773ffffffffffffffffffffffffffffffffffffffff168c60e0015173ffffffffffffffffffffffffffffffffffffffff16145b1561357d575f6127108d60c0015161ffff168660200151028161355c5761355c615288565b049050801561357b576020850180518290039052604085018051820190525b505b6127108c61014001516040015161ffff16856040015102816135a1576135a1615288565b04608085018190526040850180519190910390525b5f6127108d61014001516020015161ffff168d02816135d7576135d7615288565b04905080856080015110156136295760808501516060860151908203908111156136145760608601805160808801805190910190525f9052613627565b6060860180518290039052608086018290525b505b5050505098975050505050505050565b73ffffffffffffffffffffffffffffffffffffffff82165f908152619a1e60209081526040808320600885901c845290915290208054600160ff84161b9081189182905516156136b5576040517fee8e6a3a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60405173ffffffffffffffffffffffffffffffffffffffff83169082907f86983746fe0ad3ad6fceb2a9aa2d498430d4343ec3c8fead646124f0615f4ba6905f90a35050565b5f600a821180613709575081155b15613740576040517ffde01ad000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6040518061016001604052806101408152602001615548610140913960059390931b9092015192915050565b5f83358336836137806020890189614ee1565b915091505f5b8181101561380457846001165f036137ca576137c3848484848181106137ae576137ae614f45565b905060200201355f9182526020526040902090565b93506137f8565b6137f58383838181106137df576137df614f45565b90506020020135855f9182526020526040902090565b93505b600194851c9401613786565b50885173ffffffffffffffffffffffffffffffffffffffff161561382d5761382d8c8b8b613d4a565b6138948b602001518b61388f7f000000000000000000000000000000000000000000000000000000000000000061388a61387b8e80602001906138709190614ee1565b90508d63ffffffff16565b895f9182526020526040902090565b613f7a565b613fb9565b8a517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016138ea576138dc8b60200151888d61010001518e6101c001518f6101e00151614079565b60608d0188905294506138f3565b8a610100015194505b50505050979650505050505050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806139a857507f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b156139b557506001919050565b6139c1619a2883612947565b156139ce57506001919050565b6040517fa15c173d00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83166004820152309063a15c173d906024016020604051808303815f875af1158015610120573d5f803e3d5ffd5b81515f90819081613a8082888a613a4e575f613a55565b6040890151515b73ffffffffffffffffffffffffffffffffffffffff8b165f908152619a1d6020526040902054613099565b90508715613abc5760408601515173ffffffffffffffffffffffffffffffffffffffff1615613abc57613abc8587602001518860400151613d4a565b81517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01613b19578715613aff57613af5878288614439565b9094509250613b48565b613b0a8782886145a8565b92508161010001519350613b48565b6101008201518251909450613b3a57613b33878288614704565b9250613b48565b613b458782886145a8565b92505b505094509492505050565b806101000151821461064c57806101000151816101200151613b759190615301565b15613bac576040517ffe41cfc900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81816101000151826101200151613bc391906152cc565b613bcd91906152b5565b6101208201526101000152565b5f613c45565b5f604051608081016040526323b872dd81528381602001528481604001528581606001525f806064601c84015f875af115613c375760203d1015613c28575050803b15613c3d565b60205f803e50505f5115613c3d565b50600190505b949350505050565b61071a82848688613be0565b73ffffffffffffffffffffffffffffffffffffffff83165f908152619a1e60209081526040808320600886901c845290915281208054600160ff86161b9081189182905516613ccc576040517f548db54000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8373ffffffffffffffffffffffffffffffffffffffff16837ff3003920635c7d35c4f314eaeeed4b4c653ccb36608a86d57df761d460eab09d84604051613d17911515815260200190565b60405180910390a350505073ffffffffffffffffffffffffffffffffffffffff165f908152619a1d602052604090205490565b8060400151421115613d88576040517f39db6a8400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff1614613df5576040517f53b220dd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b805173ffffffffffffffffffffffffffffffffffffffff165f908152619a27602052604090205460ff1615613e56576040517fb5095d2d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81516020808401516040808601518582015186850151835160c080820186527f347b7818601b168f6faadc037723496e9130b057c1ffef2ec4128311e19142f2825296810197909752928601939093526060850152608084019190915273ffffffffffffffffffffffffffffffffffffffff1660a08301529020613f1390613eff907f000000000000000000000000000000000000000000000000000000000000000090613f7a565b826060015183608001518460a001516147a1565b73ffffffffffffffffffffffffffffffffffffffff16815f015173ffffffffffffffffffffffffffffffffffffffff161461128d576040517fdb2d3d4e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f190100000000000000000000000000000000000000000000000000000000000081526002810183905260228101829052604290205f906119ec565b5f80613fd283855f0151866020015187604001516147f4565b915091508073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614158061400e5750815b156140725773ffffffffffffffffffffffffffffffffffffffff85163b156140405761403b8584866148a9565b614072565b6040517f33e929a000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050505050565b5f7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8411156140d3576040517f9e0e41d300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5073ffffffffffffffffffffffffffffffffffffffff85165f908152619a25602090815260408083208784529091528120805484929060ff16600281111561411d5761411d6151a1565b0361439057805461010090047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff165f036141cc57805460ff166101007effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff87160217815560405185815273ffffffffffffffffffffffffffffffffffffffff88169087907f0363038f06c44447365467317554445fad3b007628b98200e08224f1aecb1c579060200160405180910390a35b805461010090047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1682111561422657805461010090047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1691505b82821015614260576040517fa10cbd9500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61010080830482168590039091160260ff90911617815560405182815273ffffffffffffffffffffffffffffffffffffffff88169087907f0f72b72442c719b271089c5e7774fb382e47457791f8dc3b147e72c9c685df999060200160405180910390a3805461010090047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff165f0361438b5780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011781556040515f815273ffffffffffffffffffffffffffffffffffffffff88169087907fc63c82396a1b7865295ff481988a98493c2c3cc29066c229b8001c6f5dd647a99060200160405180910390a35b61329a565b6040517fab2ccbf500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f805f61441f565b5f805f60405160608101604052632a55205a815285816020015286816040015260405f6044601c8401885afa60403d10151615614410575f519350602051925050614416565b50600190505b93509350939050565b61442a8486886143ca565b92509250925093509350939050565b5f805f835f0151905083606001515f015173ffffffffffffffffffffffffffffffffffffffff16633779e6fd61447286602001516148f7565b60405180606001604052808561010001518152602001856101c001518152602001856101e001518152508460c001518560e001518b87604001518b60600151602001518961016001518e7f06ad108efb587ddea4f632c87662b13c59dbba674c2ea7289b2fb10575a49d796040518b63ffffffff1660e01b81526004016145029a99989796959493929190615375565b60408051808303815f875af115801561451d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906145419190615410565b90935091507effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83111561459f576040517f9e0e41d300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50935093915050565b5f80825f0151905082606001515f015173ffffffffffffffffffffffffffffffffffffffff16630f59197d8260c001518360e001518660600151602001518561010001518661016001518b88604001518961010001518d7fb1cb65a3e643070d9d33047fdfd384badc7cd70b2415e548b37db5a10c70871661462d8f602001516148f7565b6040518c63ffffffff1660e01b81526004016146539b9a9998979695949392919061543a565b6020604051808303815f875af115801561466f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906146939190614ec8565b9150816146fc578473ffffffffffffffffffffffffffffffffffffffff168161014001518460600151602001517f68db558b3492d318070ad648fde8dab15f9d5cff3058c951bf13070512b4064b5f6040516146f3911515815260200190565b60405180910390a45b509392505050565b5f80825f0151905082606001515f015173ffffffffffffffffffffffffffffffffffffffff1663b3992ab18260c001518360e001518660600151602001518561016001518a87604001518b7fb1cb65a3e643070d9d33047fdfd384badc7cd70b2415e548b37db5a10c70871661477d8d602001516148f7565b6040518a63ffffffff1660e01b8152600401614653999897969594939291906154ba565b5f806147af868686866147f4565b9250905080156147eb576040517f33e929a000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50949350505050565b5f8060ff85111561480a5750600190505f6148a0565b604080515f81526020810180835288905260ff871691810191909152606081018590526080810184905260019060a0016020604051602081039080840390855afa15801561485a573d5f803e3d5ffd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015173ffffffffffffffffffffffffffffffffffffffff81161593509150505b94509492505050565b6148c18383835f015184602001518560400151614994565b61128d576040517ff83b002000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b805160609060ff1015614936576040517fe19a3e7b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208281015160408085015185518251948501939093529083015260f81b7fff000000000000000000000000000000000000000000000000000000000000001660608201526061016040516020818303038152906040529050919050565b5f60ff8411156149d0576040517fe19a3e7b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b614a68565b5f6040517f1626ba7e000000000000000000000000000000000000000000000000000000008152836004820152604060248201526041604482015284606482015286608582015285608482015260c4810160405260205f60c483865afa60203d1015161561329a5750505f517f1626ba7e000000000000000000000000000000000000000000000000000000001461071a565b612452848385888a6149d5565b6040518060800160405280614aa76040518060600160405280614c8e8152602001614c8e8152602001614c8e81525090565b815260408051610100810182525f8082526020828101829052928201819052606082018190526080820181905260a0820181905260c0820181905260e082015291019081525f602082018190526040909101905b905290565b6040518060800160405280614c056040518061022001604052805f81526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b8152604080516060810182525f80825260208281018290529282015291019081526040805160c0810182525f8082526020828101829052928201819052606082018190526080820181905260a08201529101908152602001614afb60405180604001604052805f73ffffffffffffffffffffffffffffffffffffffff1681526020015f81525090565b614c9661551a565b565b803573ffffffffffffffffffffffffffffffffffffffff81168114610452575f80fd5b5f60208284031215614ccb575f80fd5b6119ec82614c98565b5f8083601f840112614ce4575f80fd5b50813567ffffffffffffffff811115614cfb575f80fd5b60208301915083602061016083028501011115614d16575f80fd5b9250929050565b5f8083601f840112614d2d575f80fd5b50813567ffffffffffffffff811115614d44575f80fd5b602083019150836020606083028501011115614d16575f80fd5b5f8083601f840112614d6e575f80fd5b50813567ffffffffffffffff811115614d85575f80fd5b60208301915083602060c083028501011115614d16575f80fd5b5f805f805f805f80888a03610120811215614db8575f80fd5b6040811215614dc5575f80fd5b89985060807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc082011215614df7575f80fd5b5060408901965060c089013567ffffffffffffffff80821115614e18575f80fd5b614e248c838d01614cd4565b909850965060e08b0135915080821115614e3c575f80fd5b614e488c838d01614d1d565b90965094506101008b0135915080821115614e61575f80fd5b50614e6e8b828c01614d5e565b999c989b5096995094979396929594505050565b5f60208284031215614e92575f80fd5b813567ffffffffffffffff811115614ea8575f80fd5b820160e081850312156119ec575f80fd5b80518015158114610452575f80fd5b5f60208284031215614ed8575f80fd5b6119ec82614eb9565b5f8083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112614f14575f80fd5b83018035915067ffffffffffffffff821115614f2e575f80fd5b6020019150600581901b3603821315614d16575f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f82357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd21833603018112614fa4575f80fd5b9190910192915050565b5f82357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112614fa4575f80fd5b5f60808284031215614ff0575f80fd5b6040516080810181811067ffffffffffffffff82111715615038577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040528235815261504b60208401614c98565b602082015261505c60408401614c98565b604082015261506d60608401614c98565b60608201529392505050565b5f60608284031215615089575f80fd5b6040516060810181811067ffffffffffffffff821117156150d1577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b80604052508235815260208301356020820152604083013560408201528091505092915050565b5f60c08284031215615108575f80fd5b60405160c0810181811067ffffffffffffffff82111715615150577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60405261515c83614c98565b815261516a60208401614c98565b602082015260408301356040820152606083013560608201526080830135608082015260a083013560a08201528091505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b80820180821115610144576101446151ce565b5f6040828403121561521e575f80fd5b6040516040810181811067ffffffffffffffff82111715615266577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60405261527283614c98565b8152602083013560208201528091505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b8082028115828204841417610144576101446151ce565b5f826152da576152da615288565b500490565b5f80604083850312156152f0575f80fd5b505080516020909101519092909150565b5f8261530f5761530f615288565b500690565b5f81518084525f5b818110156153385760208185018101518683018201520161531c565b505f6020828601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011685010191505092915050565b5f6101808083526153888184018e615314565b9150508a51602083015260208b0151604083015260408b0151606083015273ffffffffffffffffffffffffffffffffffffffff808b1660808401528960a084015280891660c084015280881660e084015250856101008301526153f661012083018665ffffffffffff169052565b610140820193909352610160015298975050505050505050565b5f8060408385031215615421575f80fd5b8251915061543160208401614eb9565b90509250929050565b5f61016073ffffffffffffffffffffffffffffffffffffffff808f1684528d60208501528c60408501528b60608501528a6080850152808a1660a085015280891660c0850152508660e08401528561010084015284610120840152806101408401526154a881840185615314565b9e9d5050505050505050505050505050565b5f61012073ffffffffffffffffffffffffffffffffffffffff808d1684528b60208501528a6040850152896060850152808916608085015280881660a0850152508560c08401528460e08401528061010084015261062c81840185615314565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52605160045260245ffdfe8659f55d4c88f84030fe09241169834754ebf2e61099b616e530c6b65712c6445106f4043cda72e04ca2c760016628ea8d5667309323ba590682ea5254b4e82e71267a8f42e7ccde4ac75848a93b741df7a2f7a58e40274055f2fa51dbaa69ce6e90557aed2a349f8b6efb2b652c4025c56cfa82424c5cd0c6801cc234ebf519caf42fc49ad57705ea6be2ca9e1835c9ccddf7bc6fdea8f851917329b1d53a7f09b32b6b5ffee898d5fe18398652042cc8c46449329c5a1a79e425f4ede9bc2bc2362dea3338b88607906397acfdcc5651f19b40a038ee7c89dc4ab54c736cacf2bbc4f6d7ccfa2b8aab6505f0c8f2868c5a190c6c4cfce8c0de447804904df981f99e15003039550d3597e34e6426b1e230992a5a3727cb5e230754f18f3566012178d0a6b8f8748e48411572bdc391435539737aafc91fcba6f2c24ae156cfa2646970667358221220b41171987035fca55c2f91a0a85580c40eb56064037cbddbd0e69d0f09bacb7f64736f6c634300081800330000000000000000000000009a1d00773287950891b8a48be6f21e951eff91b3

Deployed Bytecode

0x608060405260043610610033575f3560e01c8063572b6c05146100375780636a89f68a1461006a578063b9d8d5a61461007f575b5f80fd5b348015610042575f80fd5b50610056610051366004614cbb565b610092565b604051901515815260200160405180910390f35b61007d610078366004614d9f565b61014a565b005b61007d61008d366004614e82565b610264565b6040517f572b6c0500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82811660048301525f917f000000000000000000000000ff0000b6c4352714cce809000d0cd30a0e0c8dce9091169063572b6c0590602401602060405180830381865afa158015610120573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101449190614ec8565b92915050565b604080516101608101909152338152610280860236037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe7c01905f906020810161019284610409565b73ffffffffffffffffffffffffffffffffffffffff1681525f602080830182905260408084018390526060808501849052608080860185905260a080870186905260c0870186905260e087018690527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61010088015283519081018452858152938401859052918301849052820183905281018290526101209092019190915290915061024782348d8d8d8d8d8d8d8d610457565b905061025781836020015161063c565b5050505050505050505050565b5f61027260c0830183614ee1565b6103600236037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedc0191505f90505b6102ad60c0840184614ee1565b9050811015610312576102c360c0840184614ee1565b828181106102d3576102d3614f45565b90506020028101906102e59190614f72565b6102f4906102c0810190614fae565b610302906020810190614ee1565b60200290920391506001016102a0565b505f6040518061016001604052803373ffffffffffffffffffffffffffffffffffffffff16815260200161034584610409565b73ffffffffffffffffffffffffffffffffffffffff1681525f602080830182905260408084018390526060808501849052608080860185905260a080870186905260c0870186905260e087018690527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6101008801528351908101845285815293840185905291830184905282018390528101829052610120909201919091529091506103f3823486610650565b905061040381836020015161063c565b50505050565b338115610452578160141461044a576040517f06dbb06700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610144610723565b919050565b5f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe8835016104b2576040517f4746e96900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8584146104eb576040517fb62503e300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b858214610524576040517fb62503e300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f86900361055e576040517fdb560cb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6105778c610572368c90038c018c614fe0565b61080e565b905061062c8c8c8c8c8c8c8c8c808060200260200160405190810160405280939291908181526020015f905b828210156105cf576105c060608302860136819003810190615079565b815260200190600101906105a3565b50505050508b8b808060200260200160405190810160405280939291908181526020015f905b828210156106215761061260c083028601368190038101906150f8565b815260200190600101906105f5565b505050505089610c21565b9c9b505050505050505050505050565b811561064c5761064c818361124b565b5050565b5f7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe6040830135016106ae576040517f4746e96900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6106bb60c0830183614ee1565b90505f036106f5576040517fdb560cb500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f61070c8561057236869003860160408701614fe0565b905061071a84848784611292565b95945050505050565b6040517f572b6c050000000000000000000000000000000000000000000000000000000081523360048201525f907f000000000000000000000000ff0000b6c4352714cce809000d0cd30a0e0c8dce73ffffffffffffffffffffffffffffffffffffffff169063572b6c0590602401602060405180830381865afa1580156107ad573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107d19190614ec8565b15610809576014361061080957507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec36013560601c90565b503390565b610816614a75565b60208281015173ffffffffffffffffffffffffffffffffffffffff165f908152619a1f90915260409020805460ff166108ca5760208301516040517fc1f8dd0c00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091166004820152309063c1f8dd0c906024015f604051808303815f87803b1580156108b3575f80fd5b505af11580156108c5573d5f803e3d5ffd5b505050505b805473ffffffffffffffffffffffffffffffffffffffff660100000000000082041660a086015261ffff7a0100000000000000000000000000000000000000000000000000008204811660808701527c010000000000000000000000000000000000000000000000000000000082041660c086015260ff61010082048116917e0100000000000000000000000000000000000000000000000000000000000090041661097c81600260ff911616151590565b156109c8576109928560200151875f015161191a565b6109c8576040517f292d235200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600481161515610100870152600181166109e2575f610a12565b60208581015173ffffffffffffffffffffffffffffffffffffffff9081165f908152619a24909252604090912054165b73ffffffffffffffffffffffffffffffffffffffff1660e08701525f826005811115610a4057610a406151a1565b03610a8d57610a5285604001516119f3565b610a88576040517fab9c00de00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610be2565b6002826005811115610aa157610aa16151a1565b03610ac35782546040860151610a529162010000900463ffffffff1690611be4565b6004826005811115610ad757610ad76151a1565b1480610af457506003826005811115610af257610af26151a1565b145b15610b975760408581015160208088015173ffffffffffffffffffffffffffffffffffffffff9081165f908152619a23909252929020548216911614610b66576040517fab9c00de00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608401826005811115610b7c57610b7c6151a1565b90816005811115610b8f57610b8f6151a1565b905250610be2565b6005826005811115610bab57610bab6151a1565b03610be2576040517fba78259100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610bf45f8660400151875f0151611c74565b845250505060409182015173ffffffffffffffffffffffffffffffffffffffff1691810191909152919050565b875f80805b878110156111fe5736898983818110610c4157610c41614f45565b9050610160020190505f6040518061022001604052808d5f01358152602001835f016020810190610c729190614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020018d6060016020810190610ca09190614cbb565b73ffffffffffffffffffffffffffffffffffffffff168152602001836020016020810190610cce9190614cbb565b73ffffffffffffffffffffffffffffffffffffffff168152602001610cf96060850160408601614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020018d6040016020810190610d279190614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020018d6020016020810190610d559190614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200183606001358152602001836080013581526020018360a001357dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681526020018360c0013581526020018360e00135815260200183610100013581526020018361012001358152602001836080013581526020018360800135815260200183610140013581525090508061020001518f610120015114610f29578061020001518f610120018181525050610e21619a1d90565b600e015f82610200015181526020019081526020015f206040518060a00160405290815f82015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020015f820160149054906101000a900461ffff1661ffff1661ffff1681526020015f820160169054906101000a900461ffff1661ffff1661ffff1681526020015f820160189054906101000a900461ffff1661ffff1661ffff1681526020015f8201601a9054906101000a900465ffffffffffff1665ffffffffffff1665ffffffffffff16815250508f61014001819052505b610120810151610f3990866151fb565b8151909550610f8657600181610100015114610f81576040517fdb3ca79a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61101e565b80517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01610fec578061010001515f03610f81576040517f26db27f100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fa799542700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612710816101a0015182610180015161103791906151fb565b111561106f576040517fca9d1e5400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600487606001516005811115611087576110876151a1565b14806110a857506003876060015160058111156110a6576110a66151a1565b145b156110d0576110d087606001518260c001518360e00151846101000151856101200151611d65565b80610160015142111561110f576040517fac492cc000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8e61014001516080015165ffffffffffff1642111561115a576040517f1463d5d500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6127108f61014001516020015161ffff1611156111a3576040517febaa3f7900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6111e18f828b86815181106111ba576111ba614f45565b60200260200101518b87815181106111d4576111d4614f45565b6020026020010151611e07565b506111ef8f82898988611e2f565b90965093505050600101610c26565b50818a60200135111561123d576040517f1d6203f500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61062c8c858c848688612251565b5f805f805f85875af190508061128d576040517f6c998d3e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050565b835f806040860136826112a860c08a018a614ee1565b915091505f5b818110156118bf57368383838181106112c9576112c9614f45565b90506020028101906112db9190614f72565b9050806112e6614b00565b6112f9368490038401610280850161520e565b60608201526113113684900384016101608501615079565b60208201526113293684900384016101c085016150f8565b604080830191909152805161022081019091528735815260208082019061135290850185614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200161137d60808a0160608b01614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020018360200160208101906113ab9190614cbb565b73ffffffffffffffffffffffffffffffffffffffff1681526020016113d66060850160408601614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200161140160608a0160408b01614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200188602001602081019061142f9190614cbb565b73ffffffffffffffffffffffffffffffffffffffff16815260200183606001358152602001836080013581526020018360a001357dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681526020018360c0013581526020018360e001358152602001836101000135815260200183610120013581526020018360800135815260200183608001358152602001836101400135815250815f01819052505f815f015190508061020001518d6101200151146115d057610200810180516101208f0152515f908152619a2b6020908152604091829020825160a081018452905473ffffffffffffffffffffffffffffffffffffffff8116825274010000000000000000000000000000000000000000810461ffff9081169383019390935276010000000000000000000000000000000000000000000081048316938201939093527801000000000000000000000000000000000000000000000000830490911660608201527a01000000000000000000000000000000000000000000000000000090910465ffffffffffff1660808201526101408e01525b6101208101516115e0908b6151fb565b8151909a5061162d57600181610100015114611628576040517fdb3ca79a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611693565b80517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01610fec578061010001515f03611628576040517f26db27f100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612710816101a001518261018001516116ac91906151fb565b11156116e4576040517fca9d1e5400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60048c6060015160058111156116fc576116fc6151a1565b148061171d575060038c60600151600581111561171b5761171b6151a1565b145b15611745576117458c606001518260c001518360e00151846101000151856101200151611d65565b806101600151421115611784576040517fac492cc000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8c61014001516080015165ffffffffffff164211156117cf576040517f1463d5d500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6127108d61014001516020015161ffff161115611818576040517febaa3f7900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608201515173ffffffffffffffffffffffffffffffffffffffff1661189d576118466102c0850185614fae565b611854906020810190614ee1565b90505f03611876576118708d8284602001518560400151611e07565b5061189d565b61189b8d828460200151856040015188806102c001906118969190614fae565b61245c565b505b6118aa828e8e8e8d612492565b909b50985050600190930192506112ae915050565b5060208901358510156118fe576040517f1d6203f500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61190c88888b87898b612251565b9a9950505050505050505050565b73ffffffffffffffffffffffffffffffffffffffff82165f908152619a26602052604081206119499083612947565b1561195657506001610144565b6040517f7a3f5d8c00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8085166004830152831660248201523090637a3f5d8c906044015b6020604051808303815f875af11580156119c8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119ec9190614ec8565b9392505050565b5f73ffffffffffffffffffffffffffffffffffffffff8216611a1757506001919050565b7f0000000000000000000000006000030000842044000077551d00cfc6b400590073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611a7257506001919050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611acd57506001919050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611b2857506001919050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611b8357506001919050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611bde57506001919050565b6101445f835b63ffffffff8281165f908152619a20602052604081209091611c099190849061294716565b15611c1657506001610144565b6040517feb5e068d00000000000000000000000000000000000000000000000000000000815263ffffffff8416600482015273ffffffffffffffffffffffffffffffffffffffff83166024820152309063eb5e068d906044016119ac565b611c9b6040518060600160405280614c8e8152602001614c8e8152602001614c8e81525090565b60408051606081019091528073ffffffffffffffffffffffffffffffffffffffff851615611ccb57612975611ccf565b6129b85b67ffffffffffffffff1681526020018315611cec576129c2611cf0565b612a785b67ffffffffffffffff1681526020018315611d2d575f866001811115611d1857611d186151a1565b14611d2557612ade611d51565b612bc1611d51565b5f866001811115611d4057611d406151a1565b14611d4d57612c98611d51565b612d605b67ffffffffffffffff169052949350505050565b5f80611d72878787612e28565b915091505f848481611d8657611d86615288565b04905081811115611dc3576040517f9837ddd700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b82811015611dfd576040517f9318944000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050505050505050565b5f61071a85858585611e2a898a60200151895f0151611e258d613047565b613099565b6131d5565b5f80839150829050611e64866020015187604001518860c001518960e001518a61010001518a5f01516020015163ffffffff16565b1561222b575f611e99888861012001518960c001518a60e001518b606001518c61018001518d6101a001518e608001516132a4565b61012088015160a089015193019290915073ffffffffffffffffffffffffffffffffffffffff16611f0e57866101200151831015611f03576040517f70d5b32e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b866101200151830392505b85602001516040015173ffffffffffffffffffffffffffffffffffffffff16815f015173ffffffffffffffffffffffffffffffffffffffff1614611fba57602086015160c0015115611f8857611f8886602001516040015189602001518860400151896020015160c001518a5f01515f015163ffffffff16565b805160208701805173ffffffffffffffffffffffffffffffffffffffff909216604090920191909152515f60c0909101525b85602001516020015173ffffffffffffffffffffffffffffffffffffffff16876060015173ffffffffffffffffffffffffffffffffffffffff161461206a57602086015160a00151156120355761203586602001516020015189602001518860400151896020015160a001518a5f01515f015163ffffffff16565b60608701516020808801805173ffffffffffffffffffffffffffffffffffffffff9093169290910191909152515f60a0909101525b85602001515f015173ffffffffffffffffffffffffffffffffffffffff16876020015173ffffffffffffffffffffffffffffffffffffffff161461210e57602086015160800151156120df576020808701518051918a015160408901516080909201518951516120df9493919063ffffffff16565b602080880151908701805173ffffffffffffffffffffffffffffffffffffffff909216909152515f6080909101525b85602001516060015173ffffffffffffffffffffffffffffffffffffffff168861014001515f015173ffffffffffffffffffffffffffffffffffffffff16146121c557602086015160e001511561218d5761218d86602001516060015189602001518860400151896020015160e001518a5f01515f015163ffffffff16565b6101408801515160208701805173ffffffffffffffffffffffffffffffffffffffff909216606090920191909152515f60e091909101525b602080820151908701805160c0018051909201909152604080830151825160a001805190910190526060830151825160809081018051909201909152830151915160e001805190920190915286510151612225908990899063ffffffff16565b50612247565b8551600214612247576122478660200151876101400151613639565b9550959350505050565b805f6122606020870187614cbb565b73ffffffffffffffffffffffffffffffffffffffff161461236957602085013515612369575f80846122968760208a01356152b5565b6122a091906152cc565b90505f6127108a61014001516060015161ffff16836122bf91906152b5565b6122c991906152cc565b60408a0151818403945090915073ffffffffffffffffffffffffffffffffffffffff16612330578184101561232a576040517f70d5b32e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81840393505b61235761234060208a018a614cbb565b60208c015160408c01518c5151879063ffffffff16565b602089015160e0018051909101905250505b602086015160e00151156123a3576101408701515160208089015160408901519189015160e001518951516123a39493919063ffffffff16565b602086015160c00151156123df576123df86602001516040015188602001518860400151896020015160c001518a5f01515f015163ffffffff16565b602086015160a001511561241b5761241b86602001516020015188602001518860400151896020015160a001518a5f01515f015163ffffffff16565b602086015160800151156124525760208087015180519189015160408901516080909201518951516124529493919063ffffffff16565b9695505050505050565b5f80612474868760200151865f0151611e258a613047565b90506124878787878787866136fb61376d565b979650505050505050565b8451606086015151839183915f9073ffffffffffffffffffffffffffffffffffffffff16612511576124e7826020015183604001518460c001518560e001518661010001518c5f01516020015163ffffffff16565b159050801561250c57815160021461250c5761250c8260200151836101400151613639565b612578565b60608901515161252090613902565b612556576040517f14db8bdb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f612568600184602001518c8c613a37565b925090506125768184613b53565b505b8061293b575f6125ad898461012001518560c001518660e001518760600151886101800151896101a001518a608001516132a4565b61012084015160a085015195019490915073ffffffffffffffffffffffffffffffffffffffff1661262257826101200151851015612617576040517f70d5b32e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b826101200151850394505b87602001516040015173ffffffffffffffffffffffffffffffffffffffff16815f015173ffffffffffffffffffffffffffffffffffffffff16146126ce57602088015160c001511561269c5761269c8860200151604001518a602001518a604001518b6020015160c001518c5f01515f015163ffffffff16565b805160208901805173ffffffffffffffffffffffffffffffffffffffff909216604090920191909152515f60c0909101525b87602001516020015173ffffffffffffffffffffffffffffffffffffffff16836060015173ffffffffffffffffffffffffffffffffffffffff161461277e57602088015160a0015115612749576127498860200151602001518a602001518a604001518b6020015160a001518c5f01515f015163ffffffff16565b60608301516020808a01805173ffffffffffffffffffffffffffffffffffffffff9093169290910191909152515f60a0909101525b87602001515f015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff161461282257602088015160800151156127f3576020808901518051918b015160408b01516080909201518b51516127f39493919063ffffffff16565b602080840151908901805173ffffffffffffffffffffffffffffffffffffffff909216909152515f6080909101525b87602001516060015173ffffffffffffffffffffffffffffffffffffffff168961014001515f015173ffffffffffffffffffffffffffffffffffffffff16146128d957602088015160e00151156128a1576128a18860200151606001518a602001518a604001518b6020015160e001518c5f01515f015163ffffffff16565b6101408901515160208901805173ffffffffffffffffffffffffffffffffffffffff909216606090920191909152515f60e091909101525b602080820151908901805160c0018051909201909152604080830151825160a001805190910190526060830151825160809081018051909201909152830151915160e001805190920190915288510151612939908a90859063ffffffff16565b505b50509550959350505050565b73ffffffffffffffffffffffffffffffffffffffff81165f90815260018301602052604081205415156119ec565b61298182848684613bda565b15610403576040517f6c998d3e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610403848261124b565b6040517ff242432a00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86811660048301528581166024830152604482018490526064820183905260a060848301525f60a48301819052919085169063f242432a9060c4015b5f604051808303815f87803b158015612a50575f80fd5b505af1925050508015612a61575060015b612a6c57505f61071a565b50600195945050505050565b6040517f23b872dd00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86811660048301528581166024830152604482018490525f91908516906323b872dd90606401612a39565b8060c0015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff167f6f4c56c4b9a9d2479f963d802b19d17b02293ce1225461ac0cb846c482ee3c3e84604001518560a001518660e00151876101000151886101200151604051612bb595949392919073ffffffffffffffffffffffffffffffffffffffff958616815293909416602084015260408301919091526060820152608081019190915260a00190565b60405180910390a45050565b8060c0015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff167f1217006325a98bdcc6afc9c44965bb66ac7460a44dc57c2ac47622561d25c45a84604001518560a001518660e00151876101000151886101200151604051612bb595949392919073ffffffffffffffffffffffffffffffffffffffff958616815293909416602084015260408301919091526060820152608081019190915260a00190565b8060c0015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff167f8b87c0b049fe52718fe6ff466b514c5a93c405fb0de8fbd761a23483f9f9e19884604001518560a001518660e00151876101200151604051612bb5949392919073ffffffffffffffffffffffffffffffffffffffff94851681529290931660208301526040820152606081019190915260800190565b8060c0015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff167fffb29e9cf48456d56b6d414855b66a7ec060ce2054dcb124a1876310e1b7355c84604001518560a001518660e00151876101200151604051612bb5949392919073ffffffffffffffffffffffffffffffffffffffff94851681529290931660208301526040820152606081019190915260800190565b5f806004856005811115612e3e57612e3e6151a1565b03612f635773ffffffffffffffffffffffffffffffffffffffff84165f908152619a22602090815260408083208684529091529020805460ff16612f19576040517f7a67b4a000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86166004820152602481018590523090637a67b4a09060440160408051808303815f875af1158015612eeb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f0f91906152df565b925092505061303f565b8054610100900460ff1615612f6157546effffffffffffffffffffffffffffff620100008204811693507101000000000000000000000000000000000090910416905061303f565b505b73ffffffffffffffffffffffffffffffffffffffff84165f908152619a2160209081526040918290208251608081018452905460ff80821615158352610100820416158015938301939093526effffffffffffffffffffffffffffff62010000820481169483019490945271010000000000000000000000000000000000900490921660608301526130175760408101516060909101516effffffffffffffffffffffffffffff918216935016905061303f565b5f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff92509250505b935093915050565b80515f9060021461306b5761306682602001518361014001515f613c51565b610144565b619a1d60209283015173ffffffffffffffffffffffffffffffffffffffff165f908152925250604090205490565b835160608086015160808088015160a0808a015160c0808c015160408051610240810182526101008082527f36e5aab0dde52c07206863cf8fe7b4b1a25be63a3ae5286f8fe80d159c154c4f602083015260ff909b169181019190915273ffffffffffffffffffffffffffffffffffffffff8c8116998201999099528c8916968101969096529587169285019290925291851690830152831660e08201529116918101919091525f9061071a906131ba9060e08801516101008901516101208a01516101608b01516101808c01516101a08d01516101408e01518b88516101008082018b526020918b019182019990995260408101979097526060870195909552608086019390935260a085019190915260c084015260e083015291015290565b61020087015181516020818401810192909252810191012090565b81515f9073ffffffffffffffffffffffffffffffffffffffff16156131ff576131ff868585613d4a565b5f61322a7f308ffbd37fdea620a0ae29a038519a27ab4ab6334e7bcd22e619feeb7893735d84613f7a565b905061323b86602001518683613fb9565b85517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0161329157613283866020015184886101000151896101c001518a6101e00151614079565b60608801849052915061329a565b85610100015191505b5095945050505050565b6132e76040518060a001604052805f73ffffffffffffffffffffffffffffffffffffffff1681526020015f81526020015f81526020015f81526020015f81525090565b606081018890526101008901515f808261331a576133068a8a8d6143c2565b945090925090505f81900361331a57600192505b821561340d5760a08c015173ffffffffffffffffffffffffffffffffffffffff16156133c857858c6080015161ffff161115613382576040517f1bdbc8f400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60a08c015173ffffffffffffffffffffffffffffffffffffffff16845260808c01516127109061ffff168c025b046020850181905260608501805191909103905261349d565b73ffffffffffffffffffffffffffffffffffffffff8516156134085773ffffffffffffffffffffffffffffffffffffffff851684526127108b87026133af565b61349d565b73ffffffffffffffffffffffffffffffffffffffff821661342b57505f5b801561349d576127108b870204811115613471576040517f1bdbc8f400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff821684526020840181905260608401805182900390525b73ffffffffffffffffffffffffffffffffffffffff8816156135b6576127108b8802046040850181905260608501805191909103905260c08c015161ffff161561357d5760e08c015173ffffffffffffffffffffffffffffffffffffffff16158061353757508773ffffffffffffffffffffffffffffffffffffffff168c60e0015173ffffffffffffffffffffffffffffffffffffffff16145b1561357d575f6127108d60c0015161ffff168660200151028161355c5761355c615288565b049050801561357b576020850180518290039052604085018051820190525b505b6127108c61014001516040015161ffff16856040015102816135a1576135a1615288565b04608085018190526040850180519190910390525b5f6127108d61014001516020015161ffff168d02816135d7576135d7615288565b04905080856080015110156136295760808501516060860151908203908111156136145760608601805160808801805190910190525f9052613627565b6060860180518290039052608086018290525b505b5050505098975050505050505050565b73ffffffffffffffffffffffffffffffffffffffff82165f908152619a1e60209081526040808320600885901c845290915290208054600160ff84161b9081189182905516156136b5576040517fee8e6a3a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60405173ffffffffffffffffffffffffffffffffffffffff83169082907f86983746fe0ad3ad6fceb2a9aa2d498430d4343ec3c8fead646124f0615f4ba6905f90a35050565b5f600a821180613709575081155b15613740576040517ffde01ad000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6040518061016001604052806101408152602001615548610140913960059390931b9092015192915050565b5f83358336836137806020890189614ee1565b915091505f5b8181101561380457846001165f036137ca576137c3848484848181106137ae576137ae614f45565b905060200201355f9182526020526040902090565b93506137f8565b6137f58383838181106137df576137df614f45565b90506020020135855f9182526020526040902090565b93505b600194851c9401613786565b50885173ffffffffffffffffffffffffffffffffffffffff161561382d5761382d8c8b8b613d4a565b6138948b602001518b61388f7f308ffbd37fdea620a0ae29a038519a27ab4ab6334e7bcd22e619feeb7893735d61388a61387b8e80602001906138709190614ee1565b90508d63ffffffff16565b895f9182526020526040902090565b613f7a565b613fb9565b8a517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016138ea576138dc8b60200151888d61010001518e6101c001518f6101e00151614079565b60608d0188905294506138f3565b8a610100015194505b50505050979650505050505050565b5f7f000000000000000000000000721c002b0059009a671d00ad1700c9748146cd1b73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806139a857507f000000000000000000000000721c0078c2328597ca70f5451fff5a7b38d4e94773ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b156139b557506001919050565b6139c1619a2883612947565b156139ce57506001919050565b6040517fa15c173d00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83166004820152309063a15c173d906024016020604051808303815f875af1158015610120573d5f803e3d5ffd5b81515f90819081613a8082888a613a4e575f613a55565b6040890151515b73ffffffffffffffffffffffffffffffffffffffff8b165f908152619a1d6020526040902054613099565b90508715613abc5760408601515173ffffffffffffffffffffffffffffffffffffffff1615613abc57613abc8587602001518860400151613d4a565b81517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01613b19578715613aff57613af5878288614439565b9094509250613b48565b613b0a8782886145a8565b92508161010001519350613b48565b6101008201518251909450613b3a57613b33878288614704565b9250613b48565b613b458782886145a8565b92505b505094509492505050565b806101000151821461064c57806101000151816101200151613b759190615301565b15613bac576040517ffe41cfc900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81816101000151826101200151613bc391906152cc565b613bcd91906152b5565b6101208201526101000152565b5f613c45565b5f604051608081016040526323b872dd81528381602001528481604001528581606001525f806064601c84015f875af115613c375760203d1015613c28575050803b15613c3d565b60205f803e50505f5115613c3d565b50600190505b949350505050565b61071a82848688613be0565b73ffffffffffffffffffffffffffffffffffffffff83165f908152619a1e60209081526040808320600886901c845290915281208054600160ff86161b9081189182905516613ccc576040517f548db54000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8373ffffffffffffffffffffffffffffffffffffffff16837ff3003920635c7d35c4f314eaeeed4b4c653ccb36608a86d57df761d460eab09d84604051613d17911515815260200190565b60405180910390a350505073ffffffffffffffffffffffffffffffffffffffff165f908152619a1d602052604090205490565b8060400151421115613d88576040517f39db6a8400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b806020015173ffffffffffffffffffffffffffffffffffffffff16836020015173ffffffffffffffffffffffffffffffffffffffff1614613df5576040517f53b220dd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b805173ffffffffffffffffffffffffffffffffffffffff165f908152619a27602052604090205460ff1615613e56576040517fb5095d2d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81516020808401516040808601518582015186850151835160c080820186527f347b7818601b168f6faadc037723496e9130b057c1ffef2ec4128311e19142f2825296810197909752928601939093526060850152608084019190915273ffffffffffffffffffffffffffffffffffffffff1660a08301529020613f1390613eff907f308ffbd37fdea620a0ae29a038519a27ab4ab6334e7bcd22e619feeb7893735d90613f7a565b826060015183608001518460a001516147a1565b73ffffffffffffffffffffffffffffffffffffffff16815f015173ffffffffffffffffffffffffffffffffffffffff161461128d576040517fdb2d3d4e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f190100000000000000000000000000000000000000000000000000000000000081526002810183905260228101829052604290205f906119ec565b5f80613fd283855f0151866020015187604001516147f4565b915091508073ffffffffffffffffffffffffffffffffffffffff168573ffffffffffffffffffffffffffffffffffffffff1614158061400e5750815b156140725773ffffffffffffffffffffffffffffffffffffffff85163b156140405761403b8584866148a9565b614072565b6040517f33e929a000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050505050565b5f7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8411156140d3576040517f9e0e41d300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5073ffffffffffffffffffffffffffffffffffffffff85165f908152619a25602090815260408083208784529091528120805484929060ff16600281111561411d5761411d6151a1565b0361439057805461010090047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff165f036141cc57805460ff166101007effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff87160217815560405185815273ffffffffffffffffffffffffffffffffffffffff88169087907f0363038f06c44447365467317554445fad3b007628b98200e08224f1aecb1c579060200160405180910390a35b805461010090047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1682111561422657805461010090047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1691505b82821015614260576040517fa10cbd9500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80547effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff61010080830482168590039091160260ff90911617815560405182815273ffffffffffffffffffffffffffffffffffffffff88169087907f0f72b72442c719b271089c5e7774fb382e47457791f8dc3b147e72c9c685df999060200160405180910390a3805461010090047effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff165f0361438b5780547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011781556040515f815273ffffffffffffffffffffffffffffffffffffffff88169087907fc63c82396a1b7865295ff481988a98493c2c3cc29066c229b8001c6f5dd647a99060200160405180910390a35b61329a565b6040517fab2ccbf500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f805f61441f565b5f805f60405160608101604052632a55205a815285816020015286816040015260405f6044601c8401885afa60403d10151615614410575f519350602051925050614416565b50600190505b93509350939050565b61442a8486886143ca565b92509250925093509350939050565b5f805f835f0151905083606001515f015173ffffffffffffffffffffffffffffffffffffffff16633779e6fd61447286602001516148f7565b60405180606001604052808561010001518152602001856101c001518152602001856101e001518152508460c001518560e001518b87604001518b60600151602001518961016001518e7f06ad108efb587ddea4f632c87662b13c59dbba674c2ea7289b2fb10575a49d796040518b63ffffffff1660e01b81526004016145029a99989796959493929190615375565b60408051808303815f875af115801561451d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906145419190615410565b90935091507effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83111561459f576040517f9e0e41d300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50935093915050565b5f80825f0151905082606001515f015173ffffffffffffffffffffffffffffffffffffffff16630f59197d8260c001518360e001518660600151602001518561010001518661016001518b88604001518961010001518d7fb1cb65a3e643070d9d33047fdfd384badc7cd70b2415e548b37db5a10c70871661462d8f602001516148f7565b6040518c63ffffffff1660e01b81526004016146539b9a9998979695949392919061543a565b6020604051808303815f875af115801561466f573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906146939190614ec8565b9150816146fc578473ffffffffffffffffffffffffffffffffffffffff168161014001518460600151602001517f68db558b3492d318070ad648fde8dab15f9d5cff3058c951bf13070512b4064b5f6040516146f3911515815260200190565b60405180910390a45b509392505050565b5f80825f0151905082606001515f015173ffffffffffffffffffffffffffffffffffffffff1663b3992ab18260c001518360e001518660600151602001518561016001518a87604001518b7fb1cb65a3e643070d9d33047fdfd384badc7cd70b2415e548b37db5a10c70871661477d8d602001516148f7565b6040518a63ffffffff1660e01b8152600401614653999897969594939291906154ba565b5f806147af868686866147f4565b9250905080156147eb576040517f33e929a000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50949350505050565b5f8060ff85111561480a5750600190505f6148a0565b604080515f81526020810180835288905260ff871691810191909152606081018590526080810184905260019060a0016020604051602081039080840390855afa15801561485a573d5f803e3d5ffd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015173ffffffffffffffffffffffffffffffffffffffff81161593509150505b94509492505050565b6148c18383835f015184602001518560400151614994565b61128d576040517ff83b002000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b805160609060ff1015614936576040517fe19a3e7b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208281015160408085015185518251948501939093529083015260f81b7fff000000000000000000000000000000000000000000000000000000000000001660608201526061016040516020818303038152906040529050919050565b5f60ff8411156149d0576040517fe19a3e7b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b614a68565b5f6040517f1626ba7e000000000000000000000000000000000000000000000000000000008152836004820152604060248201526041604482015284606482015286608582015285608482015260c4810160405260205f60c483865afa60203d1015161561329a5750505f517f1626ba7e000000000000000000000000000000000000000000000000000000001461071a565b612452848385888a6149d5565b6040518060800160405280614aa76040518060600160405280614c8e8152602001614c8e8152602001614c8e81525090565b815260408051610100810182525f8082526020828101829052928201819052606082018190526080820181905260a0820181905260c0820181905260e082015291019081525f602082018190526040909101905b905290565b6040518060800160405280614c056040518061022001604052805f81526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f73ffffffffffffffffffffffffffffffffffffffff1681526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b8152604080516060810182525f80825260208281018290529282015291019081526040805160c0810182525f8082526020828101829052928201819052606082018190526080820181905260a08201529101908152602001614afb60405180604001604052805f73ffffffffffffffffffffffffffffffffffffffff1681526020015f81525090565b614c9661551a565b565b803573ffffffffffffffffffffffffffffffffffffffff81168114610452575f80fd5b5f60208284031215614ccb575f80fd5b6119ec82614c98565b5f8083601f840112614ce4575f80fd5b50813567ffffffffffffffff811115614cfb575f80fd5b60208301915083602061016083028501011115614d16575f80fd5b9250929050565b5f8083601f840112614d2d575f80fd5b50813567ffffffffffffffff811115614d44575f80fd5b602083019150836020606083028501011115614d16575f80fd5b5f8083601f840112614d6e575f80fd5b50813567ffffffffffffffff811115614d85575f80fd5b60208301915083602060c083028501011115614d16575f80fd5b5f805f805f805f80888a03610120811215614db8575f80fd5b6040811215614dc5575f80fd5b89985060807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc082011215614df7575f80fd5b5060408901965060c089013567ffffffffffffffff80821115614e18575f80fd5b614e248c838d01614cd4565b909850965060e08b0135915080821115614e3c575f80fd5b614e488c838d01614d1d565b90965094506101008b0135915080821115614e61575f80fd5b50614e6e8b828c01614d5e565b999c989b5096995094979396929594505050565b5f60208284031215614e92575f80fd5b813567ffffffffffffffff811115614ea8575f80fd5b820160e081850312156119ec575f80fd5b80518015158114610452575f80fd5b5f60208284031215614ed8575f80fd5b6119ec82614eb9565b5f8083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1843603018112614f14575f80fd5b83018035915067ffffffffffffffff821115614f2e575f80fd5b6020019150600581901b3603821315614d16575f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f82357ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd21833603018112614fa4575f80fd5b9190910192915050565b5f82357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc1833603018112614fa4575f80fd5b5f60808284031215614ff0575f80fd5b6040516080810181811067ffffffffffffffff82111715615038577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040528235815261504b60208401614c98565b602082015261505c60408401614c98565b604082015261506d60608401614c98565b60608201529392505050565b5f60608284031215615089575f80fd5b6040516060810181811067ffffffffffffffff821117156150d1577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b80604052508235815260208301356020820152604083013560408201528091505092915050565b5f60c08284031215615108575f80fd5b60405160c0810181811067ffffffffffffffff82111715615150577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60405261515c83614c98565b815261516a60208401614c98565b602082015260408301356040820152606083013560608201526080830135608082015260a083013560a08201528091505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b80820180821115610144576101446151ce565b5f6040828403121561521e575f80fd5b6040516040810181811067ffffffffffffffff82111715615266577f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b60405261527283614c98565b8152602083013560208201528091505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b8082028115828204841417610144576101446151ce565b5f826152da576152da615288565b500490565b5f80604083850312156152f0575f80fd5b505080516020909101519092909150565b5f8261530f5761530f615288565b500690565b5f81518084525f5b818110156153385760208185018101518683018201520161531c565b505f6020828601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011685010191505092915050565b5f6101808083526153888184018e615314565b9150508a51602083015260208b0151604083015260408b0151606083015273ffffffffffffffffffffffffffffffffffffffff808b1660808401528960a084015280891660c084015280881660e084015250856101008301526153f661012083018665ffffffffffff169052565b610140820193909352610160015298975050505050505050565b5f8060408385031215615421575f80fd5b8251915061543160208401614eb9565b90509250929050565b5f61016073ffffffffffffffffffffffffffffffffffffffff808f1684528d60208501528c60408501528b60608501528a6080850152808a1660a085015280891660c0850152508660e08401528561010084015284610120840152806101408401526154a881840185615314565b9e9d5050505050505050505050505050565b5f61012073ffffffffffffffffffffffffffffffffffffffff808d1684528b60208501528a6040850152896060850152808916608085015280881660a0850152508560c08401528460e08401528061010084015261062c81840185615314565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52605160045260245ffdfe8659f55d4c88f84030fe09241169834754ebf2e61099b616e530c6b65712c6445106f4043cda72e04ca2c760016628ea8d5667309323ba590682ea5254b4e82e71267a8f42e7ccde4ac75848a93b741df7a2f7a58e40274055f2fa51dbaa69ce6e90557aed2a349f8b6efb2b652c4025c56cfa82424c5cd0c6801cc234ebf519caf42fc49ad57705ea6be2ca9e1835c9ccddf7bc6fdea8f851917329b1d53a7f09b32b6b5ffee898d5fe18398652042cc8c46449329c5a1a79e425f4ede9bc2bc2362dea3338b88607906397acfdcc5651f19b40a038ee7c89dc4ab54c736cacf2bbc4f6d7ccfa2b8aab6505f0c8f2868c5a190c6c4cfce8c0de447804904df981f99e15003039550d3597e34e6426b1e230992a5a3727cb5e230754f18f3566012178d0a6b8f8748e48411572bdc391435539737aafc91fcba6f2c24ae156cfa2646970667358221220b41171987035fca55c2f91a0a85580c40eb56064037cbddbd0e69d0f09bacb7f64736f6c63430008180033

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

0000000000000000000000009a1d00773287950891b8a48be6f21e951eff91b3

-----Decoded View---------------
Arg [0] : configurationContract (address): 0x9A1D00773287950891B8A48Be6f21e951EFF91b3

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000009a1d00773287950891b8a48be6f21e951eff91b3


Deployed Bytecode Sourcemap

3055:8229:21:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;969:144:2;;;;;;;;;;-1:-1:-1;969:144:2;;;;;:::i;:::-;;:::i;:::-;;;571:14:29;;564:22;546:41;;534:2;519:18;969:144:2;;;;;;;5718:1614:21;;;;;;:::i;:::-;;:::i;:::-;;9680:1602;;;;;;:::i;:::-;;:::i;969:144:2:-;1068:38;;;;;:27;3941:55:29;;;1068:38:2;;;3923:74:29;1045:4:2;;1068:8;:27;;;;;;3896:18:29;;1068:38:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;1061:45;969:144;-1:-1:-1;;969:144:2:o;5718:1614:21:-;6277:735;;;;;;;;;6313:10;6277:735;;8224:3:16;6169:56:21;;6081:8;:145;:67;:145;;5983:26;;6277:735;;;6344:29;6081:145;6344:9;:29::i;:::-;6277:735;;;;6407:5;6277:735;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6707:17;6277:735;;;;6752:249;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6277:735;;;;;;;;6247:765;;-1:-1:-1;7056:193:21;6247:765;7109:9;7132:8;7154:10;7178:5;;7197:16;;7227:12;;7056:18;:193::i;:::-;7023:226;;7260:65;7286:23;7311:7;:13;;;7260:25;:65::i;:::-;5973:1359;;;5718:1614;;;;;;;;:::o;9680:1602::-;9790:26;10038:19;;;;:13;:19;:::i;:::-;11008:3:16;9985:79:21;9888:8;:177;:76;:177;;-1:-1:-1;9888:8:21;;-1:-1:-1;10080:183:21;10104:19;;;;:13;:19;:::i;:::-;:26;;10100:1;:30;10080:183;;;10198:19;;;;:13;:19;:::i;:::-;10218:1;10198:22;;;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;:37;;;;;;;:::i;:::-;:43;;;;;;;:::i;:::-;6046:2:16;10177:71:21;10155:93;;;;-1:-1:-1;10132:3:21;;10080:183;;;;10283:27;10313:735;;;;;;;;10349:10;10313:735;;;;;;10380:29;10390:18;10380:9;:29::i;:::-;10313:735;;;;10443:5;10313:735;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;10743:17;10313:735;;;;10788:249;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;10313:735;;;;;;;;10283:765;;-1:-1:-1;11092:107:21;10283:765;11153:9;11176:13;11092:26;:107::i;:::-;11059:140;;11210:65;11236:23;11261:7;:13;;;11210:25;:65::i;:::-;9780:1502;;;9680:1602;:::o;115193:303:22:-;115309:10;115333:22;;115329:161;;115375:18;115397:2;115375:24;115371:74;;115408:37;;;;;;;;;;;;;;115371:74;115467:12;:10;:12::i;115329:161::-;115193:303;;;:::o;22640:1276::-;22975:25;23017:59;:19;;:59;23013:167;;23099:70;;;;;;;;;;;;;;23013:167;23194:39;;;23190:121;;23256:44;;;;;;;;;;;;;;23190:121;23325:35;;;23321:117;;23383:44;;;;;;;;;;;;;;23321:117;23468:1;23452:17;;;23448:103;;23492:48;;;;;;;;;;;;;;23448:103;23561:34;23598:46;23624:7;23598:46;;;;;;;23633:10;23598:46;:::i;:::-;:25;:46::i;:::-;23561:83;;23675:234;23718:7;23739:19;23772:8;23794:10;23818:5;;23837:16;;23675:234;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;23867:12;;23675:234;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;23893:6;23675:29;:234::i;:::-;23655:254;22640:1276;-1:-1:-1;;;;;;;;;;;;22640:1276:22:o;71425:202::-;71528:24;;71524:97;;71568:42;71582:5;71589:20;71568:13;:42::i;:::-;71425:202;;:::o;16499:833:23:-;16684:25;16725:73;:24;;;:33;:73;16721:181;;16821:70;;;;;;;;;;;;;;16721:181;16916:19;;;;:13;:19;:::i;:::-;:26;;16946:1;16916:31;16912:117;;16970:48;;;;;;;;;;;;;;16912:117;17039:34;17076:65;17102:12;17076:65;;;;;;;17116:24;;;17076:65;:::i;:::-;17039:102;;17172:153;17223:19;17256:13;17283:12;17309:6;17172:37;:153::i;:::-;17152:173;16499:833;-1:-1:-1;;;;;16499:833:23:o;1119:596:2:-;1211:39;;;;;1239:10;1211:39;;;3923:74:29;1181:14:2;;1211:8;:27;;;;;3896:18:29;;1211:39:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;1207:502;;;1289:2;1270:8;:21;1266:377;;-1:-1:-1;1522:23:2;1526:14;1522:23;1509:37;1505:2;1501:46;1119:596;:::o;1266:377::-;-1:-1:-1;734:10:4;;1119:596:2:o;37861:2842:22:-;38004:34;;:::i;:::-;38172:23;;;;;38133:63;;38055:62;38133:63;;;:38;:63;;;;;;38212:40;;;;38207:165;;38337:23;;;;38268:93;;;;;3953:42:29;3941:55;;;38268:93:22;;;3923:74:29;38302:4:22;;38268:68;;3896:18:29;;38268:93:22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;38207:165;38416:44;;38497:52;;;;;38470:24;;;:79;38587:53;;;;;;38559:25;;;:81;38676:51;;;;38650:23;;;:77;38416:44;;;;;;;38752:34;;;;38801:60;38752:34;11696:6:16;110189:23:22;110190:16;;110189:23;;;;110083:136;38801:60;38797:261;;;38882:69;38910:10;:23;;;38935:7;:15;;;38882:27;:69::i;:::-;38877:171;;38978:55;;;;;;;;;;;;;;38877:171;11757:6:16;110190:16:22;;110189:23;;39076:41;;;:98;11629:6:16;110190:16:22;;39229:155;;39382:1;39229:155;;;39347:23;;;;;39299:72;;;;;;;;:47;:72;;;;;;;;;39229:155;39185:199;;:28;;;:199;39418:45;39399:15;:64;;;;;;;;:::i;:::-;;39395:1122;;39484:49;39508:10;:24;;;39484:23;:49::i;:::-;39479:155;;39560:59;;;;;;;;;;;;;;39479:155;39395:1122;;;39673:44;39654:15;:63;;;;;;;;:::i;:::-;;39650:867;;39766:53;;39821:24;;;;39738:108;;39766:53;;;;;;39738:27;:108::i;39650:867::-;39986:34;39967:15;:53;;;;;;;;:::i;:::-;;:124;;;-1:-1:-1;40043:48:22;40024:15;:67;;;;;;;;:::i;:::-;;39967:124;39963:554;;;40195:24;;;;;40167:23;;;;;40111:108;:80;;;;;;;:55;:80;;;;;;;;;:108;;;40107:213;;40246:59;;;;;;;;;;;;;;40107:213;40333:22;;;40358:15;40333:40;;;;;;;;:::i;:::-;;;;;;;;;;;:::i;:::-;;;-1:-1:-1;39963:554:22;;;40413:22;40394:15;:41;;;;;;;;:::i;:::-;;40390:127;;40458:48;;;;;;;;;;;;;;40390:127;40547:94;40584:9;40595:10;:24;;;40621:10;:19;;;40547:36;:94::i;:::-;40527:114;;-1:-1:-1;;;40672:24:22;;;;;40651:45;;:18;;;:45;;;;40527:6;37861:2842;-1:-1:-1;37861:2842:22:o;51396:4574::-;51839:19;51782:25;;;51943:3644;51965:24;;;51943:3644;;;52006:28;52037:5;;52043:9;52037:16;;;;;;;:::i;:::-;;;;;;52006:47;;52067:24;52094:960;;;;;;;;52128:10;:19;;;52094:960;;;;52172:9;:15;;;;;;;;;;:::i;:::-;52094:960;;;;;;52218:10;:22;;;;;;;;;;:::i;:::-;52094:960;;;;;;52271:9;:21;;;;;;;;;;:::i;:::-;52094:960;;;;;;52336:34;;;;;;;;:::i;:::-;52094:960;;;;;;52403:10;:24;;;;;;;;;;:::i;:::-;52094:960;;;;;;52459:10;:23;;;;;;;;;;:::i;:::-;52094:960;;;;;;52509:9;:17;;;52094:960;;;;52552:9;:16;;;52094:960;;;;52605:9;:19;;;52094:960;;;;;;52650:9;:15;;;52094:960;;;;52695:9;:20;;;52094:960;;;;52758:9;:33;;;52094:960;;;;52833:9;:32;;;52094:960;;;;52904:9;:16;;;52094:960;;;;52957:9;:16;;;52094:960;;;;53011:9;:28;;;52094:960;;;52067:987;;53103:11;:30;;;53073:7;:26;;;:60;53069:263;;53182:11;:30;;;53153:7;:26;;:59;;;;;53253:12;402:66:28;;645:227;53253:12:22;:32;;:64;53286:11;:30;;;53253:64;;;;;;;;;;;53230:87;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:7;:20;;:87;;;;53069:263;53366:21;;;;53346:41;;;;:::i;:::-;53406:20;;53346:41;;-1:-1:-1;53402:551:22;;3364:1:16;53489:11:22;:18;;;:25;53485:131;;53545:52;;;;;;;;;;;;;;53485:131;53402:551;;;53640:20;;:60;;53636:317;;53724:11;:18;;;53746:1;53724:23;53720:133;;53778:56;;;;;;;;;;;;;;53636:317;53898:40;;;;;;;;;;;;;;53636:317;3128:6:16;54009:11:22;:34;;;53971:11;:35;;;:72;;;;:::i;:::-;:90;53967:200;;;54088:64;;;;;;;;;;;;;;53967:200;54211:34;54185:6;:22;;;:60;;;;;;;;:::i;:::-;;:138;;;-1:-1:-1;54275:48:22;54249:6;:22;;;:74;;;;;;;;:::i;:::-;;54185:138;54181:420;;;54343:243;54390:6;:22;;;54434:11;:24;;;54481:11;:19;;;54523:11;:18;;;54564:11;:21;;;54343:25;:243::i;:::-;54637:11;:22;;;54619:15;:40;54615:125;;;54690:35;;;;;;;;;;;;;;54615:125;54776:7;:20;;;:38;;;54758:56;;:15;:56;54754:147;;;54841:45;;;;;;;;;;;;;;54754:147;3128:6:16;54919:7:22;:20;;;:42;;;:60;;;54915:152;;;55006:46;;;;;;;;;;;;;;54915:152;55081:173;55118:7;55143:11;55172:16;55189:9;55172:27;;;;;;;;:::i;:::-;;;;;;;55217:12;55230:9;55217:23;;;;;;;;:::i;:::-;;;;;;;55081:19;:173::i;:::-;;55314:194;55359:7;55384:11;55414:6;55438:17;55473:21;55314:27;:194::i;:::-;55269:239;;-1:-1:-1;55269:239:22;-1:-1:-1;;;55551:11:22;;51943:3644;;;;55619:16;55601:8;:15;;;:34;55597:128;;;55658:56;;;;;;;;;;;;;;55597:128;55755:208;55808:7;55829:6;55849:8;55871:21;55906:16;55936:17;55755:39;:208::i;70814:348::-;70886:12;71044:1;71041;71038;71035;71025:8;71021:2;71014:5;71009:37;70998:48;;71071:7;71066:90;;71101:44;;;;;;;;;;;;;;71066:90;70876:286;70814:348;;:::o;18860:5581:23:-;19152:19;19095:25;;19290:24;;;19257:30;19095:25;19361:19;;;;19290:13;19361:19;:::i;:::-;19324:56;;;;19395:17;19391:4639;19413:24;;;19391:4639;;;19454:44;19501:5;;19507:9;19501:16;;;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;19454:63;-1:-1:-1;19454:63:23;19603:34;;:::i;:::-;19652:61;;;;;;;19682:31;;;19652:61;:::i;:::-;:27;;;:61;19727:53;;;;;;;19753:27;;;19727:53;:::i;:::-;:23;;;:53;19794:57;;;;;;;19822:29;;;19794:57;:::i;:::-;:25;;;;:57;;;;19893:960;;;;;;;;19927:19;;19893:960;;;;;;;19971:15;;;;:9;:15;:::i;:::-;19893:960;;;;;;20017:22;;;;;;;;:::i;:::-;19893:960;;;;;;20070:9;:21;;;;;;;;;;:::i;:::-;19893:960;;;;;;20135:34;;;;;;;;:::i;:::-;19893:960;;;;;;20202:24;;;;;;;;:::i;:::-;19893:960;;;;;;20258:10;:23;;;;;;;;;;:::i;:::-;19893:960;;;;;;20308:9;:17;;;19893:960;;;;20351:9;:16;;;19893:960;;;;20404:9;:19;;;19893:960;;;;;;20449:9;:15;;;19893:960;;;;20494:9;:20;;;19893:960;;;;20557:9;:33;;;19893:960;;;;20632:9;:32;;;19893:960;;;;20703:9;:16;;;19893:960;;;;20756:9;:16;;;19893:960;;;;20810:9;:28;;;19893:960;;;19865:13;:25;;:988;;;;20868:24;20895:13;:25;;;20868:52;;20969:11;:30;;;20939:7;:26;;;:60;20935:263;;21048:30;;;;;21019:26;;;:59;21152:30;21119:64;;;;:32;:64;;;;;;;;;21096:87;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:20;;;:87;20935:263;21232:21;;;;21212:41;;;;:::i;:::-;21272:20;;21212:41;;-1:-1:-1;21268:551:23;;3364:1:16;21355:11:23;:18;;;:25;21351:131;;21411:52;;;;;;;;;;;;;;21351:131;21268:551;;;21506:20;;:60;;21502:317;;21590:11;:18;;;21612:1;21590:23;21586:133;;21644:56;;;;;;;;;;;;;;21502:317;3128:6:16;21875:11:23;:34;;;21837:11;:35;;;:72;;;;:::i;:::-;:90;21833:200;;;21954:64;;;;;;;;;;;;;;21833:200;22077:34;22051:6;:22;;;:60;;;;;;;;:::i;:::-;;:138;;;-1:-1:-1;22141:48:23;22115:6;:22;;;:74;;;;;;;;:::i;:::-;;22051:138;22047:420;;;22209:243;22256:6;:22;;;22300:11;:24;;;22347:11;:19;;;22389:11;:18;;;22430:11;:21;;;22209:25;:243::i;:::-;22503:11;:22;;;22485:15;:40;22481:125;;;22556:35;;;;;;;;;;;;;;22481:125;22642:7;:20;;;:38;;;22624:56;;:15;:56;22620:147;;;22707:45;;;;;;;;;;;;;;22620:147;3128:6:16;22785:7:23;:20;;;:42;;;:60;;;22781:152;;;22872:46;;;;;;;;;;;;;;22781:152;22951:27;;;;:43;:57;;22947:741;;23032:32;;;;:17;:32;:::i;:::-;:38;;;;;;;:::i;:::-;:45;;23081:1;23032:50;23028:646;;23106:211;23151:7;23184:11;23221:13;:23;;;23270:13;:25;;;23106:19;:211::i;:::-;;23028:646;;;23364:291;23431:7;23464:11;23501:13;:23;;;23550:13;:25;;;23601:17;:32;;;;;;;;:::i;:::-;23364:41;:291::i;:::-;;23028:646;23747:204;23800:13;23832:7;23857:6;23881:17;23916:21;23747:35;:204::i;:::-;23702:249;;-1:-1:-1;23702:249:23;-1:-1:-1;;23994:11:23;;;;;-1:-1:-1;19391:4639:23;;-1:-1:-1;;19391:4639:23;;-1:-1:-1;24044:29:23;;;;:48;-1:-1:-1;24040:142:23;;;24115:56;;;;;;;;;;;;;;24040:142;24212:222;24265:7;24286:6;24306:13;24342:21;24377:16;24407:17;24212:39;:222::i;:::-;24192:242;18860:5581;-1:-1:-1;;;;;;;;;;18860:5581:23:o;11012:338:22:-;11125:52;;;11105:4;11125:52;;;:38;:52;;;;;:70;;11187:7;11125:61;:70::i;:::-;11121:112;;;-1:-1:-1;11218:4:22;11211:11;;11121:112;11249:94;;;;;10491:42:29;10560:15;;;11249:94:22;;;10542:34:29;10612:15;;10592:18;;;10585:43;11283:4:22;;11249:71;;10454:18:29;;11249:94:22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;11242:101;11012:338;-1:-1:-1;;;11012:338:22:o;7553:933::-;7627:4;7647:27;;;7643:837;;-1:-1:-1;7697:4:22;;7553:933;-1:-1:-1;7553:933:22:o;7643:837::-;7739:25;7722:42;;:13;:42;;;7718:762;;-1:-1:-1;7787:4:22;;7553:933;-1:-1:-1;7553:933:22:o;7718:762::-;7829:21;7812:38;;:13;:38;;;7808:672;;-1:-1:-1;7873:4:22;;7553:933;-1:-1:-1;7553:933:22:o;7808:672::-;7915:21;7898:38;;:13;:38;;;7894:586;;-1:-1:-1;7959:4:22;;7553:933;-1:-1:-1;7553:933:22:o;7894:586::-;8001:21;7984:38;;:13;:38;;;7980:500;;-1:-1:-1;8045:4:22;;7553:933;-1:-1:-1;7553:933:22:o;7980:500::-;8087:21;8070:38;;:13;:38;;;8066:414;;-1:-1:-1;8131:4:22;;7553:933;-1:-1:-1;7553:933:22:o;8066:414::-;8390:79;3230:1:16;8455:13:22;8918:359;9035:59;;;;9015:4;9035:59;;;:46;:59;;;;;9015:4;;9035:83;;:59;9104:13;;9035:68;:83;:::i;:::-;9031:125;;;-1:-1:-1;9141:4:22;9134:11;;9031:125;9172:98;;;;;10841:10:29;10829:23;;9172:98:22;;;10811:42:29;10901;10889:55;;10869:18;;;10862:83;9206:4:22;;9172:70;;10784:18:29;;9172:98:22;10639:312:29;77771:842:22;77928:68;-1:-1:-1;;;;;;;;;;;;;;;;;;;;;;;;77928:68:22;78043:563;;;;;;;;;;78098:27;;;;:73;;78152:19;78098:73;;;78128:21;78098:73;78043:563;;;;;;78204:52;;:99;;78282:21;78204:99;;;78259:20;78204:99;78043:563;;;;;;78346:52;;:249;;78525:9;78517:4;:17;;;;;;;;:::i;:::-;;:77;;78566:28;78346:249;;78517:77;78536:27;78346:249;;;78427:9;78419:4;:17;;;;;;;;:::i;:::-;;:76;;78468:27;78419:76;;;78439:26;78419:76;78043:563;;;;78008:598;77771:842;-1:-1:-1;;;;77771:842:22:o;41200:670::-;41411:18;41431:20;41455:65;41481:15;41498:12;41512:7;41455:25;:65::i;:::-;41410:110;;;;41555:17;41587:6;41575:9;:18;;;;;:::i;:::-;;41555:38;;41624:12;41612:9;:24;41608:118;;;41663:48;;;;;;;;;;;;;;41608:118;41756:10;41744:9;:22;41740:114;;;41793:46;;;;;;;;;;;;;;41740:114;41531:333;41400:470;;41200:670;;;;;:::o;94532:621::-;94738:22;94789:357;94825:7;94847:11;94873:9;94897:11;94923:213;94966:11;94995;:17;;;95030:11;:18;;;95066:56;95110:11;95066:43;:56::i;:::-;94923:25;:213::i;:::-;94789:22;:357::i;60206:4418::-;60474:25;60509:35;60581:19;60561:39;;60640:29;60610:59;;60684:231;60737:11;:17;;;60773:11;:23;;;60815:11;:24;;;60858:11;:19;;;60896:11;:18;;;60684:6;:17;;;:35;;;:231;;:::i;:::-;60680:3938;;;60931:29;60979:414;61022:7;61051:11;:21;;;61094:11;:24;;;61140:11;:19;;;61181:11;:23;;;61226:11;:35;;;61283:11;:34;;;61339:11;:36;;;60979:21;:414::i;:::-;61467:21;;;;61521:25;;;;61436:52;;;60931:462;;-1:-1:-1;61521:39:22;;61517:322;;61604:11;:21;;;61584:17;:41;61580:134;;;61656:39;;;;;;;;;;;;;;61580:134;61785:11;:21;;;61764:42;;;;61517:322;61886:6;:18;;;:39;;;61857:68;;:8;:25;;;:68;;;61853:505;;61948:18;;;;:45;;;:49;61945:246;;62021:151;62050:6;:18;;;:39;;;62091:7;:13;;;62106:6;:18;;;62126:6;:18;;;:45;;;62021:6;:17;;;:28;;;:151;;:::i;:::-;62251:25;;62209:18;;;;;:67;;;;:39;;;;:67;;;;62294:18;62251:25;62294:45;;;;:49;61853:505;62403:6;:18;;;:34;;;62376:61;;:11;:23;;;:61;;;62372:498;;62460:18;;;;:49;;;:53;62457:249;;62537:150;62566:6;:18;;;:34;;;62602:7;:13;;;62617:6;:18;;;62637:6;:18;;;:49;;;62537:6;:17;;;:28;;;:150;;:::i;:::-;62761:23;;;;62724:18;;;;;;:60;;;;:34;;;;:60;;;;62802:18;-1:-1:-1;62802:49:22;;;;:53;62372:498;62909:6;:18;;;:29;;;62888:50;;:11;:17;;;:50;;;62884:456;;62961:18;;;;:44;;;:48;62958:234;;63062:18;;;;;:29;;63093:13;;;;63108:18;;;;63128:44;;;;;63033:17;;:28;:140;;63062:29;63108:18;63128:44;63033:140;;:::i;:::-;63242:17;;;;;63210:18;;;;;:49;;;;;;;63277:18;63210:29;63277:44;;;;:48;62884:456;63402:6;:18;;;:43;;;63358:87;;:7;:20;;;:40;;;:87;;;63354:569;;63469:18;;;;:52;;;:56;63465:265;;63549:162;63578:6;:18;;;:43;;;63623:7;:13;;;63638:6;:18;;;63658:6;:18;;;:52;;;63549:6;:17;;;:28;;;:162;;:::i;:::-;63794:20;;;;:40;63748:18;;;;;:86;;;;:43;;;;:86;;;;63852:18;63794:40;-1:-1:-1;63852:52:22;;;;:56;63354:569;64014:24;;;;;63965:18;;;;;:45;;:73;;;;;;;;64109:28;;;;;64056:18;;:49;;:81;;;;;;;64203:23;;;;64155:18;;:44;;;;:71;;;;;;;;64300:31;;;64244:18;;:52;;:87;;;;;;;;64360:17;;:45;;:67;;64406:7;;64415:11;;64360:67;;:::i;:::-;60917:3521;60680:3938;;;64462:20;;3778:1:16;64462:60:22;64458:150;;64542:51;64556:11;:17;;;64575:11;:17;;;64542:13;:51::i;:::-;60206:4418;;;;;;;;:::o;56680:2947::-;57037:19;56980:25;57071:18;;;;:8;:18;:::i;:::-;:32;;;57067:1265;;57123:15;;;;:19;57119:1203;;57162:25;;57272:16;57230:39;57248:21;57230:15;;;;:39;:::i;:::-;:58;;;;:::i;:::-;57205:83;;57306:36;3128:6:16;57362:7:22;:20;;;:43;;;57345:60;;:14;:60;;;;:::i;:::-;:78;;;;:::i;:::-;57603:18;;;;57493:45;;;;-1:-1:-1;57306:117:22;;-1:-1:-1;57595:41:22;;57591:342;;57684:14;57664:17;:34;57660:135;;;57733:39;;;;;;;;;;;;;;57660:135;57878:14;57857:35;;;;57591:342;57951:203;58001:18;;;;:8;:18;:::i;:::-;58042:13;;;;58078:18;;;;57951:17;;:28;58119:17;;57951:203;;:::i;:::-;58205:18;;;;:52;;:84;;;;;;;-1:-1:-1;;57119:1203:22;58345:18;;;;:52;;;:56;58342:325;;58463:20;;;;:40;58521:13;;;;;58553:18;;;;58590;;;;:52;;;58417:17;;:28;:239;;58463:40;58553:18;58590:52;58417:239;;:::i;:::-;58680:18;;;;:45;;;:49;58677:311;;58745:232;58791:6;:18;;;:39;;;58849:7;:13;;;58881:6;:18;;;58918:6;:18;;;:45;;;58745:6;:17;;;:28;;;:232;;:::i;:::-;59001:18;;;;:49;;;:53;58998:314;;59070:231;59116:6;:18;;;:34;;;59169:7;:13;;;59201:6;:18;;;59238:6;:18;;;:49;;;59070:6;:17;;;:28;;;:231;;:::i;:::-;59325:18;;;;:44;;;:48;59322:299;;59435:18;;;;;:29;;59483:13;;;;59515:18;;;;59552:44;;;;;59389:17;;:28;:221;;59435:29;59515:18;59552:44;59389:221;;:::i;:::-;56680:2947;;;;;;;;:::o;39692:831:23:-;39972:22;40006:17;40039:216;40082:11;40112;:17;;;40148:11;:18;;;40185:56;40229:11;40185:43;:56::i;40039:216::-;40006:249;;40283:233;40323:12;40350:11;40376:9;40400:11;40426:14;40455:9;40478:28;40283:26;:233::i;:::-;40266:250;39692:831;-1:-1:-1;;;;;;;39692:831:23:o;24689:5161::-;25208:25;;25279:27;;;;:43;25082:19;;25141:29;;24975:25;;25279:57;;25275:1014;;25372:231;25425:11;:17;;;25461:11;:23;;;25503:11;:24;;;25546:11;:19;;;25584:11;:18;;;25372:6;:17;;;:35;;;:231;;:::i;:::-;25371:232;25352:251;;25621:16;25618:211;;;25661:20;;3778:1:16;25661:60:23;25657:158;;25745:51;25759:11;:17;;;25778:11;:17;;;25745:13;:51::i;:::-;25275:1014;;;25890:27;;;;:43;25864:70;;:25;:70::i;:::-;25859:162;;25961:45;;;;;;;;;;;;;;25859:162;26035:22;26125:88;26165:4;26171:11;:17;;;26190:13;26205:7;26125:39;:88::i;:::-;26071:142;-1:-1:-1;26071:142:23;-1:-1:-1;26228:50:23;26071:142;26266:11;26228:21;:50::i;:::-;25845:444;25275:1014;26304:16;26299:3544;;26336:29;26384:414;26427:7;26456:11;:21;;;26499:11;:24;;;26545:11;:19;;;26586:11;:23;;;26631:11;:35;;;26688:11;:34;;;26744:11;:36;;;26384:21;:414::i;:::-;26872:21;;;;26926:25;;;;26841:52;;;26336:462;;-1:-1:-1;26926:39:23;;26922:322;;27009:11;:21;;;26989:17;:41;26985:134;;;27061:39;;;;;;;;;;;;;;26985:134;27190:11;:21;;;27169:42;;;;26922:322;27291:6;:18;;;:39;;;27262:68;;:8;:25;;;:68;;;27258:505;;27353:18;;;;:45;;;:49;27350:246;;27426:151;27455:6;:18;;;:39;;;27496:7;:13;;;27511:6;:18;;;27531:6;:18;;;:45;;;27426:6;:17;;;:28;;;:151;;:::i;:::-;27656:25;;27614:18;;;;;:67;;;;:39;;;;:67;;;;27699:18;27656:25;27699:45;;;;:49;27258:505;27808:6;:18;;;:34;;;27781:61;;:11;:23;;;:61;;;27777:498;;27865:18;;;;:49;;;:53;27862:249;;27942:150;27971:6;:18;;;:34;;;28007:7;:13;;;28022:6;:18;;;28042:6;:18;;;:49;;;27942:6;:17;;;:28;;;:150;;:::i;:::-;28166:23;;;;28129:18;;;;;;:60;;;;:34;;;;:60;;;;28207:18;-1:-1:-1;28207:49:23;;;;:53;27777:498;28314:6;:18;;;:29;;;28293:50;;:11;:17;;;:50;;;28289:456;;28366:18;;;;:44;;;:48;28363:234;;28467:18;;;;;:29;;28498:13;;;;28513:18;;;;28533:44;;;;;28438:17;;:28;:140;;28467:29;28513:18;28533:44;28438:140;;:::i;:::-;28647:17;;;;;28615:18;;;;;:49;;;;;;;28682:18;28615:29;28682:44;;;;:48;28289:456;28807:6;:18;;;:43;;;28763:87;;:7;:20;;;:40;;;:87;;;28759:569;;28874:18;;;;:52;;;:56;28870:265;;28954:162;28983:6;:18;;;:43;;;29028:7;:13;;;29043:6;:18;;;29063:6;:18;;;:52;;;28954:6;:17;;;:28;;;:162;;:::i;:::-;29199:20;;;;:40;29153:18;;;;;:86;;;;:43;;;;:86;;;;29257:18;29199:40;-1:-1:-1;29257:52:23;;;;:56;28759:569;29419:24;;;;;29370:18;;;;;:45;;:73;;;;;;;;29514:28;;;;;29461:18;;:49;;:81;;;;;;;29608:23;;;;29560:18;;:44;;;;:71;;;;;;;;29705:31;;;29649:18;;:52;;:87;;;;;;;;29765:17;;:45;;:67;;29811:7;;29820:11;;29765:67;;:::i;:::-;26322:3521;26299:3544;25052:4798;;24689:5161;;;;;;;;:::o;8665:165:15:-;8798:23;;;8745:4;4154:21;;;:14;;;:21;;;;;;:26;;8768:55;4058:129;72556:304:22;72713:63;72740:11;72753:5;72760;72767:8;72713:26;:63::i;:::-;72709:145;;;72799:44;;;;;;;;;;;;;;71938:200;72101:30;72115:5;72122:8;72101:13;:30::i;74503:352::-;74698:70;;;;;:39;11817:15:29;;;74698:70:22;;;11799:34:29;11869:15;;;11849:18;;;11842:43;11901:18;;;11894:34;;;11944:18;;;11937:34;;;12008:3;11987:19;;;11980:32;74678:4:22;12028:19:29;;;12021:30;;;74678:4:22;74698:39;;;;;;12068:19:29;;74698:70:22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;74694:155;;-1:-1:-1;74833:5:22;74826:12;;74694:155;-1:-1:-1;74790:4:22;74503:352;;;;;;;:::o;73479:338::-;73677:53;;;;;:34;12379:15:29;;;73677:53:22;;;12361:34:29;12431:15;;;12411:18;;;12404:43;12463:18;;;12456:34;;;73657:4:22;;73677:34;;;;;;12273:18:29;;73677:53:22;12098:398:29;76956:447:22;77175:11;:24;;;77073:323;;77140:11;:17;;;77073:323;;77109:7;:13;;;77073:323;;;77217:11;:23;;;77258:11;:25;;;77301:11;:19;;;77338:11;:18;;;77374:11;:21;;;77073:323;;;;;;;;;12770:42:29;12839:15;;;12821:34;;12891:15;;;;12886:2;12871:18;;12864:43;12938:2;12923:18;;12916:34;;;;12981:2;12966:18;;12959:34;13024:3;13009:19;;13002:35;;;;12747:3;12732:19;;12501:542;77073:323:22;;;;;;;;76956:447;;:::o;75681:445::-;75898:11;:24;;;75797:322;;75863:11;:17;;;75797:322;;75832:7;:13;;;75797:322;;;75940:11;:23;;;75981:11;:25;;;76024:11;:19;;;76061:11;:18;;;76097:11;:21;;;75797:322;;;;;;;;;12770:42:29;12839:15;;;12821:34;;12891:15;;;;12886:2;12871:18;;12864:43;12938:2;12923:18;;12916:34;;;;12981:2;12966:18;;12959:34;13024:3;13009:19;;13002:35;;;;12747:3;12732:19;;12501:542;76336:409:22;76553:11;:24;;;76452:286;;76518:11;:17;;;76452:286;;76487:7;:13;;;76452:286;;;76595:11;:23;;;76636:11;:25;;;76679:11;:19;;;76716:11;:21;;;76452:286;;;;;;;;13289:42:29;13358:15;;;13340:34;;13410:15;;;;13405:2;13390:18;;13383:43;13457:2;13442:18;;13435:34;13500:2;13485:18;;13478:34;;;;13266:3;13251:19;;13048:470;75065:407:22;75280:11;:24;;;75180:285;;75245:11;:17;;;75180:285;;75214:7;:13;;;75180:285;;;75322:11;:23;;;75363:11;:25;;;75406:11;:19;;;75443:11;:21;;;75180:285;;;;;;;;13289:42:29;13358:15;;;13340:34;;13410:15;;;;13405:2;13390:18;;13383:43;13457:2;13442:18;;13435:34;13500:2;13485:18;;13478:34;;;;13266:3;13251:19;;13048:470;42397:1050:22;42553:7;;42604:34;42585:15;:53;;;;;;;;:::i;:::-;;42581:534;;42702:45;;;42654;42702;;;:31;:45;;;;;;;;:54;;;;;;;;42775:35;;;;42770:173;;42837:91;;;;;13727:42:29;13715:55;;42837:91:22;;;13697:74:29;13787:18;;;13780:34;;;42871:4:22;;42837:68;;13670:18:29;;42837:91:22;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;42830:98;;;;;;;42770:173;42960:29;;;;;;;42956:149;;;43017:34;;;;;;;;-1:-1:-1;43053:36:22;;;;;;-1:-1:-1;43009:81:22;;42956:149;42640:475;42581:534;43185:50;;;43133:49;43185:50;;;:36;:50;;;;;;;;;43133:102;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;43245:156;;43307:39;;;;43348:41;;;;;43299:91;;;;;-1:-1:-1;43299:91:22;;-1:-1:-1;43299:91:22;;43245:156;43419:1;43422:17;43411:29;;;;;42397:1050;;;;;;;:::o;86313:388::-;86482:20;;86424:19;;3778:1:16;86482:60:22;:212;;86625:69;86650:11;:17;;;86669:11;:17;;;86688:5;86625:24;:69::i;:::-;86482:212;;;402:66:28;86588:17:22;;;;;86562:44;;:25;:44;;;;;-1:-1:-1;86562:44:22;;;;;86313:388::o;24532:1530::-;25051:20;;25244:23;;;;;25320:36;;;;;25409:25;;;;;25487:24;;;;;29506:4:13;29500:11;;29537:46;;;29524:60;;29609:5;29597:18;;;1382:361:16;29577:4:13;29541:14;;29641:30;25037:36:22;;;;29691:14:13;;;29684:30;;;;25108:26:22;;;;29734:14:13;;;29727:30;;;;25169:24:22;;;29777:14:13;;;29770:30;;;;25228:41:22;;;29820:14:13;;;29813:30;;;;25304:54:22;;;29863:14:13;;;29856:30;25393:43:22;;29915:4:13;29906:14;;29899:30;25471:42:22;;29949:15:13;;;29942:31;;;;24714:17:22;;24767:1288;;24824:1160;;25566:19;;;;25616:18;;;;25665:21;;;;25717:22;;;;25770:35;;;;25836:34;;;;25901:17;;;;25949:16;31082::13;;31141:5;31129:18;;;31111:37;;31233:4;31169:22;;;31224:14;;;31217:30;;;;31276:4;31267:14;;31260:30;;;;31319:4;31310:14;;31303:30;;;;31362:4;31353:14;;31346:30;;;;31405:4;31396:14;;31389:30;;;;31448:4;31439:14;;31432:30;31491:4;31482:14;;31475:30;31525:15;;31518:31;31052:3;30738:827;24824:1160:22;26010:30;;;;32041:15:13;;32140:4;32077:21;;;32131:14;;32124:30;;;;32207:17;;32186:19;;32176:49;;31824:417;95988:1013:22;96261:18;;96223:22;;96261:32;;;96257:114;;96309:51;96328:7;96337:9;96348:11;96309:18;:51::i;:::-;96382:19;96404:51;96421:22;96445:9;96404:16;:51::i;:::-;96382:73;;96466:64;96488:11;:17;;;96507:9;96518:11;96466:21;:64::i;:::-;96545:20;;:60;;96541:454;;96638:235;96693:11;:17;;;96729:9;96757:11;:18;;;96794:11;:31;;;96843:11;:29;;;96638:37;:235::i;:::-;96887:19;;;:31;;;96621:252;-1:-1:-1;96541:454:22;;;96966:11;:18;;;96949:35;;96541:454;96247:754;95988:1013;;;;;;;:::o;65990:4494::-;66333:29;-1:-1:-1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;66333:29:22;66375:23;;;:35;;;66440:41;;;;66421:16;;66440:41;66556:293;;66699:50;66716:12;66730:7;66739:9;66699:16;:50::i;:::-;66587:162;-1:-1:-1;66587:162:22;;-1:-1:-1;66587:162:22;-1:-1:-1;66785:1:22;66768:18;;;66764:75;;66820:4;66806:18;;66764:75;66886:11;66882:1752;;;67111:24;;;;:38;;;67107:887;;67205:22;67177:7;:25;;;:50;;;67173:179;;;67262:67;;;;;;;;;;;;;;67173:179;67410:24;;;;67382:52;;;;67521:25;;;;3128:6:16;;67509:37:22;;;;67508:57;;67456:24;;;:109;;;67596:23;;;:51;;;;;;;;66882:1752;;67107:887;67676:38;;;;67672:322;;67738:52;;;;;3128:6:16;67840:34:22;;;67839:54;;67672:322;66882:1752;;;68036:29;;;68032:93;;-1:-1:-1;68105:1:22;68032:93;68155:17;;68151:469;;3128:6:16;68217:34:22;;;68216:54;68200:13;:70;68196:199;;;68305:67;;;;;;;;;;;;;;68196:199;68425:43;;;;;68490:24;;;:40;;;68561:23;;;:40;;;;;;;68151:469;68652:37;;;;68648:1155;;3128:6:16;68741:35:22;;;68740:55;68709:28;;;:86;;;68813:23;;;:55;;;;;;;;68891:23;;;;:27;;;68887:649;;68946:28;;;;:42;;;;:126;;;69049:23;69017:55;;:7;:28;;;:55;;;68946:126;68942:576;;;69100:29;3128:6:16;69188:7:22;:23;;;69161:50;;:8;:24;;;:50;:68;;;;;:::i;:::-;;;-1:-1:-1;69280:25:22;;69276:220;;69337:24;;;:49;;;;;;;69416:28;;;:53;;;;;;69276:220;69074:444;68942:576;3128:6:16;69640:7:22;:20;;;:49;;;69609:80;;:8;:28;;;:80;:98;;;;;:::i;:::-;;69554:31;;;:153;;;69725:28;;;:63;;;;;;;;68648:1155;69817:28;3128:6:16;69861:7:22;:20;;;:42;;;69849:54;;:9;:54;69848:74;;;;;:::i;:::-;;69817:105;;69974:20;69940:8;:31;;;:54;69936:532;;;70057:31;;;;70122:23;;;;70034:54;;;;70110:35;;70106:348;;;70204:23;;;;;70169:31;;;:58;;;;;;;-1:-1:-1;70249:27:22;;70106:348;;;70323:23;;;:36;;;;;;;70381:31;;;:54;;;70106:348;69996:472;69936:532;66858:3620;66364:4120;;;65990:4494;;;;;;;;;;:::o;84652:397::-;84762:43;;;3329:1:16;84762:43:22;;;:34;:43;;;;;;;;84823:1;84814:10;;;84762:64;;;;;;;:89;;3364:1:16;84873:19:22;;;;84762:89;;;;;;;84754:139;:147;84750:238;;84928:45;;;;;;;;;;;;;;84750:238;85013:29;;;;;;85027:5;;85013:29;;;;;84652:397;;:::o;40702:377:23:-;40778:12;40814:2;40805:6;:11;:26;;;-1:-1:-1;40820:11:23;;40805:26;40802:105;;;40854:42;;;;;;;;;;;;;;40802:105;40916:26;40945:36;;;;;;;;;;;;;;;;;41051:1;41047:14;;;;41028:34;;;41022:41;;40702:377;-1:-1:-1;;40702:377:23:o;31121:1933::-;31500:22;31555:25;;31618:9;31637:24;31500:22;31664:20;;;;31555:14;31664:20;:::i;:::-;31637:47;;;;31699:9;31694:397;31710:16;;;31694:397;;;31747:10;31760:1;31747:14;31765:1;31747:19;31743:249;;31806:56;31834:17;31853:5;;31859:1;31853:8;;;;;;;:::i;:::-;;;;;;;5809:12:13;5872:20;;;5912:4;5905:20;5975:4;5959:21;;;5732:264;31806:56:23;31786:76;;31743:249;;;31921:56;31949:5;;31955:1;31949:8;;;;;;;:::i;:::-;;;;;;;31959:17;5809:12:13;5872:20;;;5912:4;5905:20;5975:4;5959:21;;;5732:264;31921:56:23;31901:76;;31743:249;32020:1;32005:16;;;;32063:3;31694:397;;;-1:-1:-1;32105:18:23;;:32;;;32101:114;;32153:51;32172:7;32181:9;32192:11;32153:18;:51::i;:::-;32225:358;32260:11;:17;;;32292:9;32316:257;32350:22;32391:168;32440:62;32474:14;:20;;;;;;;;:::i;:::-;:27;;32440:33;:62;;:::i;:::-;32524:17;5809:12:13;5872:20;;;5912:4;5905:20;5975:4;5959:21;;;5732:264;32391:168:23;32316:16;:257::i;:::-;32225:21;:358::i;:::-;32598:20;;:60;;32594:454;;32691:235;32746:11;:17;;;32782:9;32810:11;:18;;;32847:11;:31;;;32896:11;:29;;;32691:37;:235::i;:::-;32940:19;;;:31;;;32674:252;-1:-1:-1;32594:454:23;;;33019:11;:18;;;33002:35;;32594:454;31524:1530;;;;31121:1933;;;;;;;;;:::o;4177:445:24:-;4255:4;4294:16;4275:35;;:15;:35;;;:87;;;;4346:16;4327:35;;:15;:35;;;4275:87;4271:129;;;-1:-1:-1;4385:4:24;;4177:445;-1:-1:-1;4177:445:24:o;4271:129::-;4413:62;:36;4459:15;4413:45;:62::i;:::-;4409:104;;;-1:-1:-1;4498:4:24;;4177:445;-1:-1:-1;4177:445:24:o;4409:104::-;4529:86;;;;;3953:42:29;3941:55;;4529:86:24;;;3923:74:29;4563:4:24;;4529:69;;3896:18:29;;4529:86:24;;;;;;;;;;;;;;;;;;;;;;;11179:1645;11460:24;;11385:22;;;;;11517:210;11460:24;11594:6;11614:9;:56;;11668:1;11614:56;;;11626:24;;;;:31;11614:56;11684:33;;;:25;:33;;;402:66:28;11684:33:24;;;;;;11517:25;:210::i;:::-;11495:232;;11742:9;11738:268;;;11771:24;;;;:31;:45;;;11767:229;;11836:145;11876:12;11911;:22;;;11956:12;:24;;;11836:18;:145::i;:::-;12020:20;;:60;;12016:802;;12100:9;12096:318;;;12157:61;12184:6;12192:11;12205:12;12157:26;:61::i;:::-;12129:89;;-1:-1:-1;12129:89:24;-1:-1:-1;12016:802:24;;12096:318;12267:79;12312:6;12320:11;12333:12;12267:44;:79::i;:::-;12257:89;;12381:11;:18;;;12364:35;;12016:802;;;12461:18;;;;12498:20;;12461:18;;-1:-1:-1;12494:314:24;;12587:78;12631:6;12639:11;12652:12;12587:43;:78::i;:::-;12577:88;;12494:314;;;12714:79;12759:6;12767:11;12780:12;12714:44;:79::i;:::-;12704:89;;12494:314;11423:1401;;11179:1645;;;;;;;:::o;14843:481:22:-;14970:11;:18;;;14952:14;:36;14948:370;;15032:11;:18;;;15008:11;:21;;;:42;;;;:::i;:::-;:47;15004:157;;15082:64;;;;;;;;;;;;;;15004:157;15244:14;15223:11;:18;;;15199:11;:21;;;:42;;;;:::i;:::-;:59;;;;:::i;:::-;15175:21;;;:83;15272:18;;:35;14843:481::o;1992:1075:11:-;2137:12;2184:794;;;2250:8;2294:4;2288:11;2338:4;2333:3;2329:14;2323:4;2316:28;2373:10;2368:3;2361:23;2424:5;2418:3;2412:4;2408:14;2401:29;2470:3;2464;2458:4;2454:14;2447:27;2514:7;2508:3;2502:4;2498:14;2491:31;2600:4;2594;2588;2581;2576:3;2572:14;2569:1;2554:13;2547:5;2542:63;2539:392;;;2652:4;2634:16;2631:26;2628:154;;;-1:-1:-1;;2703:26:11;;2696:34;2755:5;;2628:154;2830:4;2824;2818;2803:32;-1:-1:-1;;2881:4:11;2875:11;2868:19;2908:5;;2539:392;;2960:4;2948:16;;2184:794;;;;;;;:::o;:::-;3002:49;3044:6;3040:2;3034:4;3020:12;3002:49;:::i;82996:1234:22:-;83867:43;;;83129:7;83867:43;;;:34;:43;;;;;;;;83928:1;83919:10;;;83867:64;;;;;;;:89;;3364:1:16;83978:19:22;;;;83867:89;;;;;;;83859:139;83855:242;;84033:49;;;;;;;;;;;;;;83855:242;84146:7;84122:49;;84139:5;84122:49;84155:15;84122:49;;;;571:14:29;564:22;546:41;;534:2;519:18;;406:187;84122:49:22;;;;;;;;-1:-1:-1;;;84189:34:22;;:25;:34;;;402:66:28;84189:34:22;;;;;;;82996:1234::o;98727:1190::-;98927:11;:22;;;98909:15;:40;98905:119;;;98972:41;;;;;;;;;;;;;;98905:119;99055:11;:17;;;99038:34;;:7;:13;;;:34;;;99034:109;;99095:37;;;;;;;;;;;;;;99034:109;99189:18;;99157:51;;;;;;:31;:51;;;;;;;;99153:134;;;99231:45;;;;;;;;;;;;;;99153:134;99520:11;;99554;;;;;99587;;;;;99628:22;;;;99697:17;;;;8912:11:13;;8958:4;8949:14;;;8936:28;;121:86:16;8978:19:13;;9017:14;;;9010:30;;;;9060:14;;;9053:30;;;;9112:4;9103:14;;9096:30;9155:4;9146:14;;9139:30;;;;99681:35:22;;9198:4:13;9189:14;;9182:30;9246:20;;99323:511:22;;99350:399;;99384:22;;32316:16:23;:257::i;99350:399:22:-;99764:11;:13;;;99792:11;:13;;;99820:11;:13;;;99323;:511::i;:::-;99301:533;;:11;:18;;;:533;;;99297:614;;99857:43;;;;;;;;;;;;;;105332:177;8536:4:6;8530:11;8566:10;8554:23;;8606:4;8597:14;;8590:39;;;8658:4;8649:14;;8642:34;;;8712:4;8697:20;;105426:7:22;;105452:50;8336:397:6;97560:480:22;97681:12;97695:14;97713:63;97730:6;97738:9;:11;;;97751:9;:11;;;97764:9;:11;;;97713:16;:63::i;:::-;97680:96;;;;97799:6;97790:15;;:5;:15;;;;:26;;;;97809:7;97790:26;97786:248;;;97836:17;;;;:21;97832:192;;97877:49;97901:5;97908:6;97916:9;97877:23;:49::i;:::-;97832:192;;;97972:37;;;;;;;;;;;;;;97832:192;97670:370;;97560:480;;;:::o;79732:1774::-;79964:22;80020:17;80001:36;;79998:113;;;80060:40;;;;;;;;;;;;;;79998:113;-1:-1:-1;80237:52:22;;;80167:54;80237:52;;;:43;:52;;;;;;;;:65;;;;;;;;80321:23;;80138:19;;80167:54;80321:23;;:59;;;;;;;;:::i;:::-;;80317:1183;;80400:43;;;;;;;;:48;80396:238;;80468:71;;;;;;;;;;;;80562:57;;14338:25:29;;;80562:57:22;;;;80580:11;;80562:57;;14326:2:29;14311:18;80562:57:22;;;;;;;80396:238;80669:43;;;;;;;80652:60;;80648:159;;;80749:43;;;;;;;;-1:-1:-1;80648:159:22;80842:17;80825:14;:34;80821:136;;;80886:56;;;;;;;;;;;;;;80821:136;80999:70;;;;;;;;;;;;;;;;;;;;;;;81092:60;;14338:25:29;;;81092:60:22;;;;81115:11;;81092:60;;14326:2:29;14311:18;81092:60:22;;;;;;;81185:43;;;;;;;;:48;81181:221;;81253:60;;;;81279:34;81253:60;;;81336:51;;-1:-1:-1;546:41:29;;81336:51:22;;;;81359:11;;81336:51;;534:2:29;519:18;81336:51:22;;;;;;;81181:221;80317:1183;;;81439:50;;;;;;;;;;;;;;111463:983;111601:16;111619:21;111642:12;111689:642;;;111755:9;111766:14;111782:8;111826:4;111820:11;111870:4;111865:3;111861:14;111855:4;111848:28;111905:10;111900:3;111893:23;111956:8;111950:3;111944:4;111940:14;111933:32;112005:10;111999:3;111993:4;111989:14;111982:34;112137:4;112131;112125;112118;112113:3;112109:14;112094:13;112087:5;112076:66;112068:4;112050:16;112047:26;112040:34;112036:107;112033:251;;;112185:4;112179:11;112166:24;;112235:4;112229:11;112211:29;;112261:5;;;112033:251;;112313:4;112301:16;;111689:642;;;;;;;;:::o;:::-;112380:50;112420:9;112411:7;112397:12;112380:50;:::i;:::-;112344:86;;;;;;111463:983;;;;;;;:::o;13343:1127:24:-;13499:22;13523:12;13547:24;13574:12;:24;;;13547:51;;13681:12;:26;;;:42;;;13672:78;;;13764:40;13781:12;:22;;;13764:16;:40::i;:::-;13818:222;;;;;;;;13871:11;:18;;;13818:222;;;;13928:11;:31;;;13818:222;;;;13996:11;:29;;;13818:222;;;14054:11;:24;;;14092:11;:19;;;14125:6;14145:11;:23;;;14182:12;:26;;;:38;;;14241:11;:22;;;14278:11;2396:540:16;13672:670:24;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;13609:733;;-1:-1:-1;13609:733:24;-1:-1:-1;14373:17:24;14356:34;;14353:111;;;14413:40;;;;;;;;;;;;;;14353:111;13537:933;13343:1127;;;;;;:::o;14860:1024::-;15034:12;15058:24;15085:12;:24;;;15058:51;;15139:12;:26;;;:42;;;15130:96;;;15240:11;:24;;;15278:11;:19;;;15311:12;:26;;;:38;;;15363:11;:18;;;15395:11;:22;;;15431:6;15451:11;:23;;;15488:11;:18;;;15520:11;1797:548:16;15591:40:24;15608:12;:22;;;15591:16;:40::i;:::-;15130:511;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;15120:521;;15657:7;15652:226;;15824:6;15685:182;;15789:11;:17;;;15733:12;:26;;;:38;;;15685:182;15848:5;15685:182;;;;571:14:29;564:22;546:41;;534:2;519:18;;406:187;15685:182:24;;;;;;;;15652:226;15048:836;14860:1024;;;;;:::o;16274:958::-;16447:12;16471:24;16498:12;:24;;;16471:51;;16552:12;:26;;;:42;;;16543:95;;;16652:11;:24;;;16690:11;:19;;;16723:12;:26;;;:38;;;16775:11;:22;;;16811:6;16831:11;:23;;;16868:11;1797:548:16;16939:40:24;16956:12;:22;;;16939:16;:40::i;:::-;16543:446;;;;;;;;;;;;;;;;;;;;;;;:::i;103739:334:22:-;103875:14;103901:12;103943:33;103960:6;103968:1;103971;103974;103943:16;:33::i;:::-;103923:53;-1:-1:-1;103923:53:22;-1:-1:-1;103986:81:22;;;;104019:37;;;;;;;;;;;;;;103986:81;103891:182;103739:334;;;;;;:::o;104730:355::-;104869:12;;104917:15;104913:19;;104909:75;;;-1:-1:-1;104956:4:22;;-1:-1:-1;104970:1:22;104948:25;;104909:75;105003:33;;;;;;;;;;;;18591:25:29;;;18664:4;18652:17;;18632:18;;;18625:45;;;;18686:18;;;18679:34;;;18729:18;;;18722:34;;;105003:33:22;;18563:19:29;;105003:33:22;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;105003:33:22;;;;;105057:20;;;;;-1:-1:-1;105003:33:22;-1:-1:-1;;104730:355:22;;;;;;;;:::o;100564:314::-;100721:74;100743:6;100751:4;100757:9;:11;;;100770:9;:11;;;100783:9;:11;;;100721:21;:74::i;:::-;100716:156;;100818:43;;;;;;;;;;;;;;17403:294:24;17512:11;;17485:12;;17526:15;-1:-1:-1;17509:103:24;;;17564:37;;;;;;;;;;;;;;17509:103;17645:11;;;;;17658;;;;;17677;;17628:62;;;;;18948:19:29;;;;18983:12;;;18976:28;19042:3;19038:16;19056:66;19034:89;19020:12;;;19013:111;19140:12;;17628:62:24;;;;;;;;;;;;17621:69;;17403:294;;;:::o;101435:1809:22:-;101596:12;101628:15;101624:19;;101620:94;;;101666:37;;;;;;;;;;;;;;101620:94;101747:1413;;;101809:8;101853:4;101847:11;101953:13;101948:3;101941:26;102075:5;102068:4;102063:3;102059:14;102052:29;102195:4;102188;102183:3;102179:14;102172:28;102288:4;102281;102276:3;102272:14;102265:28;102466:2;102459:4;102454:3;102450:14;102443:26;102509:2;102502:4;102497:3;102493:14;102486:26;102552:2;102545:4;102540:3;102536:14;102529:26;102672:4;102667:3;102663:14;102657:4;102650:28;102946:4;102940;102934;102929:3;102920:7;102913:5;102902:49;102894:4;102876:16;102873:26;102866:34;102862:90;102859:287;;;-1:-1:-1;;103081:4:22;103075:11;103088:13;103072:30;103123:5;;101747:1413;103184:44;103226:1;103223;103220;103214:4;103206:6;103184:44;:::i;-1:-1:-1:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:::o;14:196:29:-;82:20;;142:42;131:54;;121:65;;111:93;;200:1;197;190:12;215:186;274:6;327:2;315:9;306:7;302:23;298:32;295:52;;;343:1;340;333:12;295:52;366:29;385:9;366:29;:::i;598:390::-;679:8;689:6;743:3;736:4;728:6;724:17;720:27;710:55;;761:1;758;751:12;710:55;-1:-1:-1;784:20:29;;827:18;816:30;;813:50;;;859:1;856;849:12;813:50;896:4;888:6;884:17;872:29;;961:3;954:4;944:6;936;932:19;924:6;920:32;916:43;913:52;910:72;;;978:1;975;968:12;910:72;598:390;;;;;:::o;993:393::-;1079:8;1089:6;1143:3;1136:4;1128:6;1124:17;1120:27;1110:55;;1161:1;1158;1151:12;1110:55;-1:-1:-1;1184:20:29;;1227:18;1216:30;;1213:50;;;1259:1;1256;1249:12;1213:50;1296:4;1288:6;1284:17;1272:29;;1359:3;1352:4;1344;1336:6;1332:17;1324:6;1320:30;1316:41;1313:50;1310:70;;;1376:1;1373;1366:12;1391:390;1474:8;1484:6;1538:3;1531:4;1523:6;1519:17;1515:27;1505:55;;1556:1;1553;1546:12;1505:55;-1:-1:-1;1579:20:29;;1622:18;1611:30;;1608:50;;;1654:1;1651;1644:12;1608:50;1691:4;1683:6;1679:17;1667:29;;1754:3;1747:4;1739;1731:6;1727:17;1719:6;1715:30;1711:41;1708:50;1705:70;;;1771:1;1768;1761:12;1786:1588;2114:6;2122;2130;2138;2146;2154;2162;2170;2214:9;2205:7;2201:23;2244:3;2240:2;2236:12;2233:32;;;2261:1;2258;2251:12;2233:32;2285:2;2281;2277:11;2274:31;;;2301:1;2298;2291:12;2274:31;2324:9;2314:19;;2426:3;2357:66;2353:2;2349:75;2345:85;2342:105;;;2443:1;2440;2433:12;2342:105;;2481:2;2470:9;2466:18;2456:28;;2535:3;2524:9;2520:19;2507:33;2559:18;2600:2;2592:6;2589:14;2586:34;;;2616:1;2613;2606:12;2586:34;2655:88;2735:7;2726:6;2715:9;2711:22;2655:88;:::i;:::-;2762:8;;-1:-1:-1;2629:114:29;-1:-1:-1;2850:3:29;2835:19;;2822:33;;-1:-1:-1;2867:16:29;;;2864:36;;;2896:1;2893;2886:12;2864:36;2935:95;3022:7;3011:8;3000:9;2996:24;2935:95;:::i;:::-;3049:8;;-1:-1:-1;2909:121:29;-1:-1:-1;3137:3:29;3122:19;;3109:33;;-1:-1:-1;3154:16:29;;;3151:36;;;3183:1;3180;3173:12;3151:36;;3222:92;3306:7;3295:8;3284:9;3280:24;3222:92;:::i;:::-;1786:1588;;;;-1:-1:-1;1786:1588:29;;-1:-1:-1;1786:1588:29;;;;;;3333:8;-1:-1:-1;;;1786:1588:29:o;3379:393::-;3471:6;3524:2;3512:9;3503:7;3499:23;3495:32;3492:52;;;3540:1;3537;3530:12;3492:52;3580:9;3567:23;3613:18;3605:6;3602:30;3599:50;;;3645:1;3642;3635:12;3599:50;3668:22;;3724:3;3706:16;;;3702:26;3699:46;;;3741:1;3738;3731:12;4008:164;4084:13;;4133;;4126:21;4116:32;;4106:60;;4162:1;4159;4152:12;4177:202;4244:6;4297:2;4285:9;4276:7;4272:23;4268:32;4265:52;;;4313:1;4310;4303:12;4265:52;4336:37;4363:9;4336:37;:::i;4384:641::-;4514:4;4520:6;4580:11;4567:25;4670:66;4659:8;4643:14;4639:29;4635:102;4615:18;4611:127;4601:155;;4752:1;4749;4742:12;4601:155;4779:33;;4831:20;;;-1:-1:-1;4874:18:29;4863:30;;4860:50;;;4906:1;4903;4896:12;4860:50;4939:4;4927:17;;-1:-1:-1;4990:1:29;4986:14;;;4970;4966:35;4956:46;;4953:66;;;5015:1;5012;5005:12;5030:184;5082:77;5079:1;5072:88;5179:4;5176:1;5169:15;5203:4;5200:1;5193:15;5219:393;5322:4;5380:11;5367:25;5470:66;5459:8;5443:14;5439:29;5435:102;5415:18;5411:127;5401:155;;5552:1;5549;5542:12;5401:155;5573:33;;;;;5219:393;-1:-1:-1;;5219:393:29:o;5617:390::-;5717:4;5775:11;5762:25;5865:66;5854:8;5838:14;5834:29;5830:102;5810:18;5806:127;5796:155;;5947:1;5944;5937:12;6621:813;6708:6;6761:3;6749:9;6740:7;6736:23;6732:33;6729:53;;;6778:1;6775;6768:12;6729:53;6811:2;6805:9;6853:3;6845:6;6841:16;6923:6;6911:10;6908:22;6887:18;6875:10;6872:34;6869:62;6866:242;;;6964:77;6961:1;6954:88;7065:4;7062:1;7055:15;7093:4;7090:1;7083:15;6866:242;7124:2;7117:22;7163:23;;7148:39;;7220:38;7254:2;7239:18;;7220:38;:::i;:::-;7215:2;7207:6;7203:15;7196:63;7292:38;7326:2;7315:9;7311:18;7292:38;:::i;:::-;7287:2;7279:6;7275:15;7268:63;7364:38;7398:2;7387:9;7383:18;7364:38;:::i;:::-;7359:2;7347:15;;7340:63;7351:6;6621:813;-1:-1:-1;;;6621:813:29:o;7439:731::-;7530:6;7583:2;7571:9;7562:7;7558:23;7554:32;7551:52;;;7599:1;7596;7589:12;7551:52;7632:2;7626:9;7674:2;7666:6;7662:15;7743:6;7731:10;7728:22;7707:18;7695:10;7692:34;7689:62;7686:242;;;7784:77;7781:1;7774:88;7885:4;7882:1;7875:15;7913:4;7910:1;7903:15;7686:242;7948:10;7944:2;7937:22;;7996:9;7983:23;7975:6;7968:39;8068:2;8057:9;8053:18;8040:32;8035:2;8027:6;8023:15;8016:57;8134:2;8123:9;8119:18;8106:32;8101:2;8093:6;8089:15;8082:57;8158:6;8148:16;;;7439:731;;;;:::o;8175:944::-;8263:6;8316:3;8304:9;8295:7;8291:23;8287:33;8284:53;;;8333:1;8330;8323:12;8284:53;8366:2;8360:9;8408:3;8400:6;8396:16;8478:6;8466:10;8463:22;8442:18;8430:10;8427:34;8424:62;8421:242;;;8519:77;8516:1;8509:88;8620:4;8617:1;8610:15;8648:4;8645:1;8638:15;8421:242;8679:2;8672:22;8718:29;8737:9;8718:29;:::i;:::-;8710:6;8703:45;8781:38;8815:2;8804:9;8800:18;8781:38;:::i;:::-;8776:2;8768:6;8764:15;8757:63;8881:2;8870:9;8866:18;8853:32;8848:2;8840:6;8836:15;8829:57;8947:2;8936:9;8932:18;8919:32;8914:2;8906:6;8902:15;8895:57;9014:3;9003:9;8999:19;8986:33;8980:3;8972:6;8968:16;8961:59;9082:3;9071:9;9067:19;9054:33;9048:3;9040:6;9036:16;9029:59;9107:6;9097:16;;;8175:944;;;;:::o;9124:184::-;9176:77;9173:1;9166:88;9273:4;9270:1;9263:15;9297:4;9294:1;9287:15;9313:184;9365:77;9362:1;9355:88;9462:4;9459:1;9452:15;9486:4;9483:1;9476:15;9502:125;9567:9;;;9588:10;;;9585:36;;;9601:18;;:::i;9632:670::-;9722:6;9775:2;9763:9;9754:7;9750:23;9746:32;9743:52;;;9791:1;9788;9781:12;9743:52;9824:2;9818:9;9866:2;9858:6;9854:15;9935:6;9923:10;9920:22;9899:18;9887:10;9884:34;9881:62;9878:242;;;9976:77;9973:1;9966:88;10077:4;10074:1;10067:15;10105:4;10102:1;10095:15;9878:242;10136:2;10129:22;10175:29;10194:9;10175:29;:::i;:::-;10167:6;10160:45;10266:2;10255:9;10251:18;10238:32;10233:2;10225:6;10221:15;10214:57;10290:6;10280:16;;;9632:670;;;;:::o;10956:184::-;11008:77;11005:1;10998:88;11105:4;11102:1;11095:15;11129:4;11126:1;11119:15;11145:168;11218:9;;;11249;;11266:15;;;11260:22;;11246:37;11236:71;;11287:18;;:::i;11318:120::-;11358:1;11384;11374:35;;11389:18;;:::i;:::-;-1:-1:-1;11423:9:29;;11318:120::o;13825:245::-;13904:6;13912;13965:2;13953:9;13944:7;13940:23;13936:32;13933:52;;;13981:1;13978;13971:12;13933:52;-1:-1:-1;;14004:16:29;;14060:2;14045:18;;;14039:25;14004:16;;14039:25;;-1:-1:-1;13825:245:29:o;14075:112::-;14107:1;14133;14123:35;;14138:18;;:::i;:::-;-1:-1:-1;14172:9:29;;14075:112::o;14374:481::-;14415:3;14453:5;14447:12;14480:6;14475:3;14468:19;14505:1;14515:162;14529:6;14526:1;14523:13;14515:162;;;14591:4;14647:13;;;14643:22;;14637:29;14619:11;;;14615:20;;14608:59;14544:12;14515:162;;;14519:3;14722:1;14715:4;14706:6;14701:3;14697:16;14693:27;14686:38;14844:4;14774:66;14769:2;14761:6;14757:15;14753:88;14748:3;14744:98;14740:109;14733:116;;;14374:481;;;;:::o;14963:1172::-;15387:4;15416:3;15446:2;15435:9;15428:21;15466:44;15506:2;15495:9;15491:18;15483:6;15466:44;:::i;:::-;15458:52;;;15552:6;15546:13;15541:2;15530:9;15526:18;15519:41;15614:2;15606:6;15602:15;15596:22;15591:2;15580:9;15576:18;15569:50;15673:2;15665:6;15661:15;15655:22;15650:2;15639:9;15635:18;15628:50;15697:42;15788:2;15780:6;15776:15;15770:3;15759:9;15755:19;15748:44;15829:6;15823:3;15812:9;15808:19;15801:35;15885:2;15877:6;15873:15;15867:3;15856:9;15852:19;15845:44;15938:2;15930:6;15926:15;15920:3;15909:9;15905:19;15898:44;;15979:6;15973:3;15962:9;15958:19;15951:35;15995:46;16036:3;16025:9;16021:19;16013:6;14936:14;14925:26;14913:39;;14860:98;15995:46;16072:3;16057:19;;16050:35;;;;16116:3;16101:19;16094:35;14963:1172;;-1:-1:-1;;;;;;;;14963:1172:29:o;16140:263::-;16216:6;16224;16277:2;16265:9;16256:7;16252:23;16248:32;16245:52;;;16293:1;16290;16283:12;16245:52;16322:9;16316:16;16306:26;;16351:46;16393:2;16382:9;16378:18;16351:46;:::i;:::-;16341:56;;16140:263;;;;;:::o;16408:1046::-;16799:4;16828:3;16850:42;16931:2;16923:6;16919:15;16908:9;16901:34;16971:6;16966:2;16955:9;16951:18;16944:34;17014:6;17009:2;16998:9;16994:18;16987:34;17057:6;17052:2;17041:9;17037:18;17030:34;17101:6;17095:3;17084:9;17080:19;17073:35;17157:2;17149:6;17145:15;17139:3;17128:9;17124:19;17117:44;17210:2;17202:6;17198:15;17192:3;17181:9;17177:19;17170:44;;17251:6;17245:3;17234:9;17230:19;17223:35;17295:6;17289:3;17278:9;17274:19;17267:35;17339:6;17333:3;17322:9;17318:19;17311:35;17383:2;17377:3;17366:9;17362:19;17355:31;17403:45;17444:2;17433:9;17429:18;17420:7;17403:45;:::i;:::-;17395:53;16408:1046;-1:-1:-1;;;;;;;;;;;;;;16408:1046:29:o;17459:900::-;17793:4;17822:3;17844:42;17925:2;17917:6;17913:15;17902:9;17895:34;17965:6;17960:2;17949:9;17945:18;17938:34;18008:6;18003:2;17992:9;17988:18;17981:34;18051:6;18046:2;18035:9;18031:18;18024:34;18107:2;18099:6;18095:15;18089:3;18078:9;18074:19;18067:44;18160:2;18152:6;18148:15;18142:3;18131:9;18127:19;18120:44;;18201:6;18195:3;18184:9;18180:19;18173:35;18245:6;18239:3;18228:9;18224:19;18217:35;18289:2;18283:3;18272:9;18268:19;18261:31;18309:44;18349:2;18338:9;18334:18;18326:6;18309:44;:::i;19163:184::-;19215:77;19212:1;19205:88;19312:4;19309:1;19302:15;19336:4;19333:1;19326:15

Swarm Source

ipfs://b41171987035fca55c2f91a0a85580c40eb56064037cbddbd0e69d0f09bacb7f

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

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