// File: @openzeppelin/contracts-upgradeable/finance/PaymentSplitterUpgradeable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (finance/PaymentSplitter.sol)

pragma solidity ^0.8.0;

import "../token/ERC20/utils/SafeERC20Upgradeable.sol";
import "../utils/AddressUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @title PaymentSplitter
 * @dev This contract allows to split Ether payments among a group of accounts. The sender does not need to be aware
 * that the Ether will be split in this way, since it is handled transparently by the contract.
 *
 * The split can be in equal parts or in any other arbitrary proportion. The way this is specified is by assigning each
 * account to a number of shares. Of all the Ether that this contract receives, each account will then be able to claim
 * an amount proportional to the percentage of total shares they were assigned.
 *
 * `PaymentSplitter` follows a _pull payment_ model. This means that payments are not automatically forwarded to the
 * accounts but kept in this contract, and the actual transfer is triggered as a separate step by calling the {release}
 * function.
 *
 * NOTE: This contract assumes that ERC20 tokens will behave similarly to native tokens (Ether). Rebasing tokens, and
 * tokens that apply fees during transfers, are likely to not be supported as expected. If in doubt, we encourage you
 * to run tests before sending real value to this contract.
 */
contract PaymentSplitterUpgradeable is Initializable, ContextUpgradeable {
    event PayeeAdded(address account, uint256 shares);
    event PaymentReleased(address to, uint256 amount);
    event ERC20PaymentReleased(IERC20Upgradeable indexed token, address to, uint256 amount);
    event PaymentReceived(address from, uint256 amount);

    uint256 private _totalShares;
    uint256 private _totalReleased;

    mapping(address => uint256) private _shares;
    mapping(address => uint256) private _released;
    address[] private _payees;

    mapping(IERC20Upgradeable => uint256) private _erc20TotalReleased;
    mapping(IERC20Upgradeable => mapping(address => uint256)) private _erc20Released;

    /**
     * @dev Creates an instance of `PaymentSplitter` where each account in `payees` is assigned the number of shares at
     * the matching position in the `shares` array.
     *
     * All addresses in `payees` must be non-zero. Both arrays must have the same non-zero length, and there must be no
     * duplicates in `payees`.
     */
    function __PaymentSplitter_init(address[] memory payees, uint256[] memory shares_) internal onlyInitializing {
        __PaymentSplitter_init_unchained(payees, shares_);
    }

    function __PaymentSplitter_init_unchained(address[] memory payees, uint256[] memory shares_) internal onlyInitializing {
        require(payees.length == shares_.length, "PaymentSplitter: payees and shares length mismatch");
        require(payees.length > 0, "PaymentSplitter: no payees");

        for (uint256 i = 0; i < payees.length; i++) {
            _addPayee(payees[i], shares_[i]);
        }
    }

    /**
     * @dev The Ether received will be logged with {PaymentReceived} events. Note that these events are not fully
     * reliable: it's possible for a contract to receive Ether without triggering this function. This only affects the
     * reliability of the events, and not the actual splitting of Ether.
     *
     * To learn more about this see the Solidity documentation for
     * https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function[fallback
     * functions].
     */
    receive() external payable virtual {
        emit PaymentReceived(_msgSender(), msg.value);
    }

    /**
     * @dev Getter for the total shares held by payees.
     */
    function totalShares() public view returns (uint256) {
        return _totalShares;
    }

    /**
     * @dev Getter for the total amount of Ether already released.
     */
    function totalReleased() public view returns (uint256) {
        return _totalReleased;
    }

    /**
     * @dev Getter for the total amount of `token` already released. `token` should be the address of an IERC20
     * contract.
     */
    function totalReleased(IERC20Upgradeable token) public view returns (uint256) {
        return _erc20TotalReleased[token];
    }

    /**
     * @dev Getter for the amount of shares held by an account.
     */
    function shares(address account) public view returns (uint256) {
        return _shares[account];
    }

    /**
     * @dev Getter for the amount of Ether already released to a payee.
     */
    function released(address account) public view returns (uint256) {
        return _released[account];
    }

    /**
     * @dev Getter for the amount of `token` tokens already released to a payee. `token` should be the address of an
     * IERC20 contract.
     */
    function released(IERC20Upgradeable token, address account) public view returns (uint256) {
        return _erc20Released[token][account];
    }

    /**
     * @dev Getter for the address of the payee number `index`.
     */
    function payee(uint256 index) public view returns (address) {
        return _payees[index];
    }

    /**
     * @dev Triggers a transfer to `account` of the amount of Ether they are owed, according to their percentage of the
     * total shares and their previous withdrawals.
     */
    function release(address payable account) public virtual {
        require(_shares[account] > 0, "PaymentSplitter: account has no shares");

        uint256 totalReceived = address(this).balance + totalReleased();
        uint256 payment = _pendingPayment(account, totalReceived, released(account));

        require(payment != 0, "PaymentSplitter: account is not due payment");

        _released[account] += payment;
        _totalReleased += payment;

        AddressUpgradeable.sendValue(account, payment);
        emit PaymentReleased(account, payment);
    }

    /**
     * @dev Triggers a transfer to `account` of the amount of `token` tokens they are owed, according to their
     * percentage of the total shares and their previous withdrawals. `token` must be the address of an IERC20
     * contract.
     */
    function release(IERC20Upgradeable token, address account) public virtual {
        require(_shares[account] > 0, "PaymentSplitter: account has no shares");

        uint256 totalReceived = token.balanceOf(address(this)) + totalReleased(token);
        uint256 payment = _pendingPayment(account, totalReceived, released(token, account));

        require(payment != 0, "PaymentSplitter: account is not due payment");

        _erc20Released[token][account] += payment;
        _erc20TotalReleased[token] += payment;

        SafeERC20Upgradeable.safeTransfer(token, account, payment);
        emit ERC20PaymentReleased(token, account, payment);
    }

    /**
     * @dev internal logic for computing the pending payment of an `account` given the token historical balances and
     * already released amounts.
     */
    function _pendingPayment(
        address account,
        uint256 totalReceived,
        uint256 alreadyReleased
    ) private view returns (uint256) {
        return (totalReceived * _shares[account]) / _totalShares - alreadyReleased;
    }

    /**
     * @dev Add a new payee to the contract.
     * @param account The address of the payee to add.
     * @param shares_ The number of shares owned by the payee.
     */
    function _addPayee(address account, uint256 shares_) private {
        require(account != address(0), "PaymentSplitter: account is the zero address");
        require(shares_ > 0, "PaymentSplitter: shares are 0");
        require(_shares[account] == 0, "PaymentSplitter: account already has shares");

        _payees.push(account);
        _shares[account] = shares_;
        _totalShares = _totalShares + shares_;
        emit PayeeAdded(account, shares_);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[43] private __gap;
}

// File: @openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.0;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To initialize the implementation contract, you can either invoke the
 * initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() initializer {}
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     */
    bool private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Modifier to protect an initializer function from being invoked twice.
     */
    modifier initializer() {
        // If the contract is initializing we ignore whether _initialized is set in order to support multiple
        // inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
        // contract may have been reentered.
        require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");

        bool isTopLevelCall = !_initializing;
        if (isTopLevelCall) {
            _initializing = true;
            _initialized = true;
        }

        _;

        if (isTopLevelCall) {
            _initializing = false;
        }
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} modifier, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    function _isConstructor() private view returns (bool) {
        return !AddressUpgradeable.isContract(address(this));
    }
}

// File: @openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

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

// File: @openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol



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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

// File: @openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20Upgradeable.sol";
import "../../../utils/AddressUpgradeable.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20Upgradeable {
    using AddressUpgradeable for address;

    function safeTransfer(
        IERC20Upgradeable token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20Upgradeable token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20Upgradeable token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

// File: @openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

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

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721Upgradeable is IERC165Upgradeable {
    /**
     * @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`, 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 be 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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * 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 Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @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 caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

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

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

// File: @openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

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

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

// File: @openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

// File: @openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol



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

pragma solidity ^0.8.0;

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

// File: @openzeppelin/contracts-upgradeable/utils/structs/BitMapsUpgradeable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/structs/BitMaps.sol)
pragma solidity ^0.8.0;

/**
 * @dev Library for managing uint256 to bool mapping in a compact and efficient way, providing the keys are sequential.
 * Largelly inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor].
 */
library BitMapsUpgradeable {
    struct BitMap {
        mapping(uint256 => uint256) _data;
    }

    /**
     * @dev Returns whether the bit at `index` is set.
     */
    function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
        uint256 bucket = index >> 8;
        uint256 mask = 1 << (index & 0xff);
        return bitmap._data[bucket] & mask != 0;
    }

    /**
     * @dev Sets the bit at `index` to the boolean `value`.
     */
    function setTo(
        BitMap storage bitmap,
        uint256 index,
        bool value
    ) internal {
        if (value) {
            set(bitmap, index);
        } else {
            unset(bitmap, index);
        }
    }

    /**
     * @dev Sets the bit at `index`.
     */
    function set(BitMap storage bitmap, uint256 index) internal {
        uint256 bucket = index >> 8;
        uint256 mask = 1 << (index & 0xff);
        bitmap._data[bucket] |= mask;
    }

    /**
     * @dev Unsets the bit at `index`.
     */
    function unset(BitMap storage bitmap, uint256 index) internal {
        uint256 bucket = index >> 8;
        uint256 mask = 1 << (index & 0xff);
        bitmap._data[bucket] &= ~mask;
    }
}

// File: @openzeppelin/contracts/access/Ownable.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// File: @openzeppelin/contracts/proxy/Clones.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (proxy/Clones.sol)

pragma solidity ^0.8.0;

/**
 * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for
 * deploying minimal proxy contracts, also known as "clones".
 *
 * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
 * > a minimal bytecode implementation that delegates all calls to a known, fixed address.
 *
 * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
 * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
 * deterministic method.
 *
 * _Available since v3.4._
 */
library Clones {
    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create opcode, which should never revert.
     */
    function clone(address implementation) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create(0, 0x09, 0x37)
        }
        require(instance != address(0), "ERC1167: create failed");
    }

    /**
     * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.
     *
     * This function uses the create2 opcode and a `salt` to deterministically deploy
     * the clone. Using the same `implementation` and `salt` multiple time will revert, since
     * the clones cannot be deployed twice at the same address.
     */
    function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
            // of the `implementation` address with the bytecode before the address.
            mstore(0x00, or(shr(0xe8, shl(0x60, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
            // Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
            mstore(0x20, or(shl(0x78, implementation), 0x5af43d82803e903d91602b57fd5bf3))
            instance := create2(0, 0x09, 0x37, salt)
        }
        require(instance != address(0), "ERC1167: create2 failed");
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(
        address implementation,
        bytes32 salt,
        address deployer
    ) internal pure returns (address predicted) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(add(ptr, 0x38), deployer)
            mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
            mstore(add(ptr, 0x14), implementation)
            mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
            mstore(add(ptr, 0x58), salt)
            mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
            predicted := keccak256(add(ptr, 0x43), 0x55)
        }
    }

    /**
     * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
     */
    function predictDeterministicAddress(address implementation, bytes32 salt)
        internal
        view
        returns (address predicted)
    {
        return predictDeterministicAddress(implementation, salt, address(this));
    }
}

// File: @openzeppelin/contracts/utils/Address.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

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

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

// File: @openzeppelin/contracts/utils/Context.sol



// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (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;
    }
}

// File: contracts/aspen/api/agreement/IAgreement.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

interface ICedarAgreementV0 {
    // Accept legal terms associated with transfer of this NFT
    function acceptTerms() external;

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

    function termsActivated() external view returns (bool);

    function setTermsStatus(bool _status) external;

    function getAgreementStatus(address _address) external view returns (bool sig);

    function storeTermsAccepted(address _acceptor, bytes calldata _signature) external;
}

interface ICedarAgreementV1 {
    // Accept legal terms associated with transfer of this NFT
    event TermsActivationStatusUpdated(bool isActivated);
    event TermsUpdated(string termsURI, uint8 termsVersion);
    event TermsAccepted(string termsURI, uint8 termsVersion, address indexed acceptor);

    function acceptTerms() external;

    function acceptTerms(address _acceptor) external;

    function setTermsActivation(bool _active) external;

    function setTermsURI(string calldata _termsURI) external;

    function getTermsDetails()
        external
        view
        returns (
            string memory termsURI,
            uint8 termsVersion,
            bool termsActivated
        );

    function hasAcceptedTerms(address _address) external view returns (bool hasAccepted);

    //    function hasAcceptedTerms(address _address, uint8 _termsVersion) external view returns (bool hasAccepted);
}

interface IPublicAgreementV0 {
    function acceptTerms() external;

    function getTermsDetails()
        external
        view
        returns (
            string memory termsURI,
            uint8 termsVersion,
            bool termsActivated
        );

    function hasAcceptedTerms(address _address) external view returns (bool hasAccepted);

    function hasAcceptedTerms(address _address, uint8 _termsVersion) external view returns (bool hasAccepted);
}

interface IPublicAgreementV1 is IPublicAgreementV0 {
    /// @dev Emitted when the terms are accepted.
    event TermsAccepted(string termsURI, uint8 termsVersion, address indexed acceptor);
}

interface IRestrictedAgreementV0 {
    function acceptTerms(address _acceptor) external;

    function setTermsActivation(bool _active) external;

    function setTermsURI(string calldata _termsURI) external;
}

interface IRestrictedAgreementV1 is IRestrictedAgreementV0 {
    /// @dev Emitted when the terms are accepted by an issuer.
    event TermsAcceptedForAddress(string termsURI, uint8 termsVersion, address indexed acceptor, address caller);
    /// @dev Emitted when the terms are activated/deactivated.
    event TermsActivationStatusUpdated(bool isActivated);
    /// @dev Emitted when the terms URI is updated.
    event TermsUpdated(string termsURI, uint8 termsVersion);
}

interface IDelegatedAgreementV0 {
    /// @dev Emitted when the terms are accepted using singature of acceptor.
    event TermsWithSignatureAccepted(string termsURI, uint8 termsVersion, address indexed acceptor, bytes signature);

    function acceptTerms(address _acceptor, bytes calldata _signature) external;

    function batchAcceptTerms(address[] calldata _acceptors) external;
}

// File: contracts/aspen/api/baseURI/IUpdateBaseURI.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

interface ICedarUpdateBaseURIV0 {
    /// @dev Emitted when base URI is updated.
    event BaseURIUpdated(uint256 baseURIIndex, string baseURI);

    /**
     *  @notice Lets a minter (account with `MINTER_ROLE`) update base URI
     */
    function updateBaseURI(uint256 baseURIIndex, string calldata _baseURIForTokens) external;

    /**
     *  @dev Gets the base URI indices
     */
    function getBaseURIIndices() external view returns (uint256[] memory);
}

interface IPublicUpdateBaseURIV0 {
    /**
     *  @dev Gets the base URI indices
     */
    function getBaseURIIndices() external view returns (uint256[] memory);
}

interface IDelegatedUpdateBaseURIV0 {
    /**
     *  @dev Gets the base URI indices
     */
    function getBaseURIIndices() external view returns (uint256[] memory);
}

interface IRestrictedUpdateBaseURIV0 {
    /**
     *  @notice Lets a minter (account with `MINTER_ROLE`) update base URI
     */
    function updateBaseURI(uint256 baseURIIndex, string calldata _baseURIForTokens) external;
}

interface IRestrictedUpdateBaseURIV1 is IRestrictedUpdateBaseURIV0 {
    /// @dev Emitted when base URI is updated.
    event BaseURIUpdated(uint256 baseURIIndex, string baseURI);
}

// File: contracts/aspen/api/config/IGlobalConfig.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

import "../config/IPlatformFeeConfig.sol";
import "../config/IOperatorFilterersConfig.sol";

interface IGlobalConfigV0 is IOperatorFiltererConfigV0, IPlatformFeeConfigV0 {

}
// File: contracts/aspen/api/config/IOperatorFilterersConfig.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

import "./types/OperatorFiltererDataTypes.sol";

interface IOperatorFiltererConfigV0 {
    event OperatorFiltererAdded(
        bytes32 operatorFiltererId,
        string name,
        address defaultSubscription,
        address operatorFilterRegistry
    );

    function getOperatorFiltererOrDie(bytes32 _operatorFiltererId)
        external
        view
        returns (IOperatorFiltererDataTypesV0.OperatorFilterer memory);

    function getOperatorFilterer(bytes32 _operatorFiltererId)
        external
        view
        returns (IOperatorFiltererDataTypesV0.OperatorFilterer memory);

    function getOperatorFiltererIds() external view returns (bytes32[] memory operatorFiltererIds);

    function addOperatorFilterer(IOperatorFiltererDataTypesV0.OperatorFilterer memory _newOperatorFilterer) external;
}

// File: contracts/aspen/api/config/IPlatformFeeConfig.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface IPlatformFeeConfigV0 {
    event PlatformFeesUpdated(address platformFeeReceiver, uint16 platformFeeBPS);

    function getPlatformFees() external view returns (address platformFeeReceiver, uint16 platformFeeBPS);

    function setPlatformFees(address _newPlatformFeeReceiver, uint16 _newPlatformFeeBPS) external;
}

// File: contracts/aspen/api/config/types/OperatorFiltererDataTypes.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface IOperatorFiltererDataTypesV0 {
    struct OperatorFilterer {
        bytes32 operatorFiltererId;
        string name;
        address defaultSubscription;
        address operatorFilterRegistry;
    }
}

// File: contracts/aspen/api/deploy/IAspenDeployer.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

import "../impl/IAspenERC721Drop.sol";
import "../impl/IAspenERC1155Drop.sol";
import "../impl/IAspenPaymentSplitter.sol";
import "./types/DropFactoryDataTypes.sol";

// Events deployed by AspenDeployer directly (not by factories)
interface IAspenDeployerOwnEventsV1 {
    event AspenInterfaceDeployed(
        address indexed contractAddress,
        uint256 indexed majorVersion,
        uint256 indexed minorVersion,
        uint256 patchVersion,
        string implementationInterfaceId
    );
}

// Update this interface by bumping the version then updating in-place.
// Previous versions will be immortalised in manifest but do not need to be kept around to clutter
// solidity code
interface IAspenDeployerV2 is IAspenDeployerOwnEventsV1, IAspenVersionedV2 {
    function deployAspenERC1155Drop(
        IDropFactoryDataTypesV0.TokenDetails memory _tokenDetails,
        IDropFactoryDataTypesV0.FeeDetails memory _feeDetails,
        bytes32 _operatorFiltererType
    ) external payable returns (IAspenERC1155DropV2);

    function deployAspenERC721Drop(
        IDropFactoryDataTypesV0.TokenDetails memory _tokenDetails,
        IDropFactoryDataTypesV0.FeeDetails memory _feeDetails,
        bytes32 _operatorFiltererType
    ) external payable returns (IAspenERC721DropV2);

    function deployAspenPaymentSplitter(address[] memory payees, uint256[] memory shares)
        external
        returns (IAspenPaymentSplitterV1);

    function getDeploymentFeeDetails() external view returns (uint256 _deploymentFee, address _feeReceiver);

    /// Versions
    function aspenERC721DropVersion()
        external
        view
        returns (
            uint256 major,
            uint256 minor,
            uint256 patch
        );

    function aspenERC1155DropVersion()
        external
        view
        returns (
            uint256 major,
            uint256 minor,
            uint256 patch
        );

    function aspenPaymentSplitterVersion()
        external
        view
        returns (
            uint256 major,
            uint256 minor,
            uint256 patch
        );

    /// Features

    function aspenERC721DropFeatures() external view returns (string[] memory features);

    function aspenERC1155DropFeatures() external view returns (string[] memory features);

    function aspenPaymentSplitterFeatures() external view returns (string[] memory features);

    /// Interface Ids

    function aspenERC721DropInterfaceId() external view returns (string memory interfaceId);

    function aspenERC1155DropInterfaceId() external view returns (string memory interfaceId);

    function aspenPaymentSplitterInterfaceId() external view returns (string memory interfaceId);
}

interface ICedarFactoryEventsV0 {
    // Primarily for the benefit of Etherscan verification
    event AspenImplementationDeployed(
        address indexed implementationAddress,
        uint256 indexed majorVersion,
        uint256 indexed minorVersion,
        uint256 patchVersion,
        string contractName
    );
}

interface IAspenFactoryEventsV0 {
    // Primarily for the benefit of Etherscan verification
    event AspenImplementationDeployed(
        address indexed implementationAddress,
        uint256 indexed majorVersion,
        uint256 indexed minorVersion,
        uint256 patchVersion,
        string contractName
    );
}

/// Factory specific events (emitted by factories, but included in ICedarDeployer interfaces because they can be
/// expected to be emitted on transactions that call the deploy functions

interface IAspenERC721PremintFactoryEventsV1 is IAspenFactoryEventsV0 {
    event AspenERC721PremintDeployment(
        address indexed contractAddress,
        uint256 indexed majorVersion,
        uint256 indexed minorVersion,
        uint256 patchVersion,
        address adminAddress,
        string name,
        string symbol,
        uint256 maxLimit,
        string userAgreement,
        string baseURI
    );
}

interface IAspenERC721DropFactoryEventsV0 is IAspenFactoryEventsV0 {
    event AspenERC721DropV2Deployment(
        address indexed contractAddress,
        uint256 indexed majorVersion,
        uint256 indexed minorVersion,
        uint256 patchVersion
    );
}

interface IAspenERC1155DropFactoryEventsV0 is IAspenFactoryEventsV0 {
    event AspenERC1155DropV2Deployment(
        address indexed contractAddress,
        uint256 indexed majorVersion,
        uint256 indexed minorVersion,
        uint256 patchVersion
    );
}

interface IAspenPaymentSplitterEventsV0 is IAspenFactoryEventsV0 {
    event AspenPaymentSplitterDeployment(
        address indexed contractAddress,
        uint256 indexed majorVersion,
        uint256 indexed minorVersion,
        uint256 patchVersion,
        address[] payees,
        uint256[] shares
    );
}

interface IDropFactoryEventsV0 is IAspenFactoryEventsV0 {
    /// @dev Unified interface for drop contract deployment through the factory contracts
    ///     Emitted when the `deploy()` from Factory contracts is called
    event DropContractDeployment(
        address indexed contractAddress,
        uint256 indexed majorVersion,
        uint256 indexed minorVersion,
        uint256 patchVersion,
        address adminAddress,
        string name,
        string symbol,
        address saleRecipient,
        address defaultRoyaltyRecipient,
        uint128 defaultRoyaltyBps,
        string userAgreement,
        uint128 platformFeeBps,
        address platformFeeRecipient
    );
}

interface IDropFactoryEventsV1 is IAspenFactoryEventsV0 {
    /// @dev Unified interface for drop contract deployment through the factory contracts
    ///     Emitted when the `deploy()` from Factory contracts is called
    event DropContractDeployment(
        address indexed contractAddress,
        uint256 indexed majorVersion,
        uint256 indexed minorVersion,
        uint256 patchVersion,
        address adminAddress,
        string name,
        string symbol,
        bytes32 operatorFiltererId
    );
}

// File: contracts/aspen/api/deploy/types/DropFactoryDataTypes.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

import "../../config/types/OperatorFiltererDataTypes.sol";
import "../../config/IGlobalConfig.sol";

interface IDropFactoryDataTypesV0 {
    struct DropConfig {
        address dropDelegateLogic;
        IGlobalConfigV0 aspenConfig;
        TokenDetails tokenDetails;
        FeeDetails feeDetails;
        IOperatorFiltererDataTypesV0.OperatorFilterer operatorFilterer;
    }

    struct TokenDetails {
        address defaultAdmin;
        string name;
        string symbol;
        string contractURI;
        address[] trustedForwarders;
        string userAgreement;
    }

    struct FeeDetails {
        address saleRecipient;
        address royaltyRecipient;
        uint128 royaltyBps;
    }
}

// File: contracts/aspen/api/errors/ISplitPaymentErrors.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface ISplitPaymentErrorsV0 {
    error PayeeSharesArrayMismatch(uint256 payeesLength, uint256 sharesLength);
    error PayeeAlreadyExists(address payee);
    error InvalidTotalShares(uint256 totalShares);
}

// File: contracts/aspen/api/IAspenFeatures.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

import "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol";

interface ICedarFeaturesV0 is IERC165Upgradeable {
    // Marker interface to make an ERC165 clash less likely
    function isICedarFeaturesV0() external pure returns (bool);

    // List of features that contract supports and may be passed to featureVersion
    function supportedFeatures() external pure returns (string[] memory features);
}

interface IAspenFeaturesV0 is IERC165Upgradeable {
    // Marker interface to make an ERC165 clash less likely
    function isIAspenFeaturesV0() external pure returns (bool);

    // List of features that contract supports and may be passed to featureVersion
    function supportedFeatures() external pure returns (string[] memory features);
}

// File: contracts/aspen/api/IAspenVersioned.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

import "@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol";

interface ICedarMinorVersionedV0 {
    function minorVersion() external view returns (uint256 minor, uint256 patch);
}

interface ICedarImplementationVersionedV0 {
    /// @dev Concrete implementation semantic version - provided for completeness but not designed to be the point of dispatch
    function implementationVersion()
        external
        view
        returns (
            uint256 major,
            uint256 minor,
            uint256 patch
        );
}

interface ICedarImplementationVersionedV1 is ICedarImplementationVersionedV0 {
    /// @dev returns the name of the implementation interface such as IAspenERC721DropV3
    /// allows us to reliably emit the correct events
    function implementationInterfaceName() external view returns (string memory interfaceName);
}

interface ICedarImplementationVersionedV2 is ICedarImplementationVersionedV0 {
    /// @dev returns the name of the implementation interface such as impl/IAspenERC721Drop.sol:IAspenERC721DropV3
    function implementationInterfaceId() external view returns (string memory interfaceId);
}

interface ICedarVersionedV0 is ICedarImplementationVersionedV0, ICedarMinorVersionedV0, IERC165Upgradeable {}

interface ICedarVersionedV1 is ICedarImplementationVersionedV1, ICedarMinorVersionedV0, IERC165Upgradeable {}

interface ICedarVersionedV2 is ICedarImplementationVersionedV2, ICedarMinorVersionedV0, IERC165Upgradeable {}

interface IAspenVersionedV2 is IERC165Upgradeable {
    function minorVersion() external view returns (uint256 minor, uint256 patch);

    /// @dev Concrete implementation semantic version - provided for completeness but not designed to be the point of dispatch
    function implementationVersion()
        external
        view
        returns (
            uint256 major,
            uint256 minor,
            uint256 patch
        );

    /// @dev returns the name of the implementation interface such as impl/IAspenERC721Drop.sol:IAspenERC721DropV3
    function implementationInterfaceId() external view returns (string memory interfaceId);
}

// File: contracts/aspen/api/impl/IAspenERC1155Drop.sol



// SPDX-License-Identifier: Apache 2.0

pragma solidity ^0.8;

import "../IAspenFeatures.sol";
import "../IMulticallable.sol";
import "../IAspenVersioned.sol";
import "../issuance/ICedarSFTIssuance.sol";
import "../issuance/ISFTLimitSupply.sol";
import "../issuance/ISFTSupply.sol";
import "../issuance/ISFTClaimCount.sol";
import "../baseURI/IUpdateBaseURI.sol";
import "../standard/IERC1155.sol";
import "../standard/IERC2981.sol";
import "../standard/IERC4906.sol";
import "../royalties/IRoyalty.sol";
import "../metadata/ISFTMetadata.sol";
import "../metadata/IContractMetadata.sol";
import "../agreement/IAgreement.sol";
import "../primarysale/IPrimarySale.sol";
import "../lazymint/ILazyMint.sol";
import "../pausable/IPausable.sol";
import "../ownable/IOwnable.sol";
import "../royalties/IPlatformFee.sol";

interface IAspenERC1155DropV2 is
    IAspenFeaturesV0,
    IAspenVersionedV2,
    IMulticallableV0,
    // NOTE: keep this standard interfaces around to generate supportsInterface
    IERC1155V3,
    IERC2981V0,
    IRestrictedERC4906V0,
    // NOTE: keep this standard interfaces around to generate supportsInterface ˆˆ
    // Supply
    IPublicSFTSupplyV0,
    IDelegatedSFTSupplyV0,
    IRestrictedSFTLimitSupplyV1,
    // Issuance
    IPublicSFTIssuanceV4,
    IDelegatedSFTIssuanceV0,
    IRestrictedSFTIssuanceV4,
    // Royalties
    IPublicRoyaltyV0,
    IRestrictedRoyaltyV1,
    // BaseUri
    IDelegatedUpdateBaseURIV0,
    IRestrictedUpdateBaseURIV1,
    // Metadata
    IPublicMetadataV0,
    IRestrictedMetadataV2,
    IAspenSFTMetadataV1,
    // Ownable
    IPublicOwnableV0,
    IRestrictedOwnableV0,
    // Pausable
    IDelegatedPausableV0,
    IRestrictedPausableV1,
    // Agreement
    IPublicAgreementV1,
    IDelegatedAgreementV0,
    IRestrictedAgreementV1,
    // Primary Sale
    IPublicPrimarySaleV1,
    IRestrictedPrimarySaleV2,
    IRestrictedSFTPrimarySaleV0,
    // Operator Filterer
    IRestrictedOperatorFiltererV0,
    IPublicOperatorFilterToggleV0,
    IRestrictedOperatorFilterToggleV0,
    // Delegated only
    IDelegatedPlatformFeeV0,
    // Restricted Only
    IRestrictedLazyMintV1,
    IRestrictedSFTClaimCountV0
{}

// File: contracts/aspen/api/impl/IAspenERC721Drop.sol



// SPDX-License-Identifier: Apache 2.0

pragma solidity ^0.8;

import "../IAspenFeatures.sol";
import "../IMulticallable.sol";
import "../IAspenVersioned.sol";
import "../issuance/ICedarNFTIssuance.sol";
import "../issuance/INFTLimitSupply.sol";
import "../agreement/IAgreement.sol";
import "../issuance/INFTSupply.sol";
import "../issuance/INFTClaimCount.sol";
import "../lazymint/ILazyMint.sol";
import "../standard/IERC721.sol";
import "../standard/IERC4906.sol";
import "../standard/IERC2981.sol";
import "../royalties/IRoyalty.sol";
import "../baseURI/IUpdateBaseURI.sol";
import "../metadata/INFTMetadata.sol";
import "../metadata/IContractMetadata.sol";
import "../primarysale/IPrimarySale.sol";
import "../pausable/IPausable.sol";
import "../ownable/IOwnable.sol";
import "../royalties/IPlatformFee.sol";

// Each AspenERC721 contract should implement a maximal version of the interfaces it supports and should itself carry
// the version major version suffix, in this case CedarERC721V0

interface IAspenERC721DropV2 is
    IAspenFeaturesV0,
    IAspenVersionedV2,
    IMulticallableV0,
    // NOTE: keep this standard interfaces around to generate supportsInterface
    IERC721V3,
    IERC2981V0,
    IRestrictedERC4906V0,
    // NOTE: keep this standard interfaces around to generate supportsInterface ˆˆ
    // Supply
    INFTSupplyV1,
    IRestrictedNFTLimitSupplyV1,
    // Issuance
    IPublicNFTIssuanceV4,
    IDelegatedNFTIssuanceV0,
    IRestrictedNFTIssuanceV4,
    // Roylaties
    IPublicRoyaltyV0,
    IRestrictedRoyaltyV1,
    // BaseUri
    IPublicUpdateBaseURIV0,
    IRestrictedUpdateBaseURIV1,
    // Metadata
    IPublicMetadataV0,
    IAspenNFTMetadataV1,
    IRestrictedMetadataV2,
    // Ownable
    IPublicOwnableV0,
    IRestrictedOwnableV0,
    // Pausable
    IPublicPausableV0,
    IRestrictedPausableV1,
    // Agreement
    IPublicAgreementV1,
    IDelegatedAgreementV0,
    IRestrictedAgreementV1,
    // Primary Sale
    IPublicPrimarySaleV1,
    IRestrictedPrimarySaleV2,
    // Oprator Filterers
    IRestrictedOperatorFiltererV0,
    IPublicOperatorFilterToggleV0,
    IRestrictedOperatorFilterToggleV0,
    // Delegated only
    IDelegatedPlatformFeeV0,
    // Restricted only
    IRestrictedLazyMintV1,
    IRestrictedNFTClaimCountV0
{

}

// File: contracts/aspen/api/impl/IAspenPaymentSplitter.sol



// SPDX-License-Identifier: Apache 2.0

pragma solidity ^0.8;

import "../IAspenFeatures.sol";
import "../IAspenVersioned.sol";
import "../IMulticallable.sol";
import "../splitpayment/ISplitPayment.sol";

interface IAspenPaymentSplitterV1 is IAspenFeaturesV0, IAspenVersionedV2, IMulticallableV0, IAspenSplitPaymentV1 {}

// File: contracts/aspen/api/IMulticallable.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

// See https://docs.openzeppelin.com/contracts/4.x/utilities#multicall
interface IMulticallableV0 {
    function multicall(bytes[] calldata data) external returns (bytes[] memory results);
}

// File: contracts/aspen/api/issuance/ICedarNFTIssuance.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

import "./IDropClaimCondition.sol";

/**
 *  Cedar's 'Drop' contracts are distribution mechanisms for tokens. The
 *  `DropERC721` contract is a distribution mechanism for ERC721 tokens.
 *
 *  A minter wallet (i.e. holder of `MINTER_ROLE`) can (lazy)mint 'n' tokens
 *  at once by providing a single base URI for all tokens being lazy minted.
 *  The URI for each of the 'n' tokens lazy minted is the provided base URI +
 *  `{tokenId}` of the respective token. (e.g. "ipsf://Qmece.../1").
 *
 *  A contract admin (i.e. holder of `DEFAULT_ADMIN_ROLE`) can create claim conditions
 *  with non-overlapping time windows, and accounts can claim the tokens according to
 *  restrictions defined in the claim condition that is active at the time of the transaction.
 */

interface ICedarNFTIssuanceV0 is IDropClaimConditionV0 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        address indexed claimer,
        address indexed receiver,
        uint256 startTokenId,
        uint256 quantityClaimed
    );

    /// @dev Emitted when new claim conditions are set.
    event ClaimConditionsUpdated(ClaimCondition[] claimConditions);

    /**
     *  @notice Lets a contract admin (account with `DEFAULT_ADMIN_ROLE`) set claim conditions.
     *
     *  @param phases                Claim conditions in ascending order by `startTimestamp`.
     *  @param resetClaimEligibility Whether to reset `limitLastClaimTimestamp` and
     *                               `limitMerkleProofClaim` values when setting new
     *                               claim conditions.
     */
    function setClaimConditions(ClaimCondition[] calldata phases, bool resetClaimEligibility) external;

    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;
}

interface ICedarNFTIssuanceV1 is ICedarNFTIssuanceV0 {
    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions()
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 remainingSupply
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface ICedarNFTIssuanceV2 is ICedarNFTIssuanceV1 {
    event TokensIssued(
        uint256 indexed startTokenId,
        address indexed issuer,
        address indexed receiver,
        uint256 quantity
    );

    event TokenIssued(uint256 indexed tokenId, address indexed issuer, address indexed receiver, string tokenURI);

    event TokenURIUpdated(uint256 indexed tokenId, address indexed updater, string tokenURI);

    /// @dev Issue quantity tokens directly to receiver, only callable by ISSUER_ROLE. Emits TokensIssued event.
    function issue(address receiver, uint256 quantity) external;

    /// @dev Issue a single token directly to receiver with a custom tokenURI, only callable by ISSUER_ROLE.
    /// Emits TokenIssued event.
    function issueWithTokenURI(address receiver, string calldata tokenURI) external;

    /// @dev Sets the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits TokenURIUpdated event.
    function setTokenURI(uint256 tokenId, string memory _tokenURI) external;
}

interface ICedarNFTIssuanceV3 is ICedarNFTIssuanceV0 {
    event TokensIssued(
        uint256 indexed startTokenId,
        address indexed issuer,
        address indexed receiver,
        uint256 quantity
    );

    event TokenIssued(uint256 indexed tokenId, address indexed issuer, address indexed receiver, string tokenURI);

    event TokenURIUpdated(uint256 indexed tokenId, address indexed updater, string tokenURI);

    /// @dev Issue quantity tokens directly to receiver, only callable by ISSUER_ROLE. Emits TokensIssued event.
    function issue(address receiver, uint256 quantity) external;

    /// @dev Issue a single token directly to receiver with a custom tokenURI, only callable by ISSUER_ROLE.
    /// Emits TokenIssued event.
    function issueWithTokenURI(address receiver, string calldata tokenURI) external;

    /// @dev Sets the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits TokenURIUpdated event.
    function setTokenURI(uint256 tokenId, string memory _tokenURI) external;

    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions()
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 remainingSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface ICedarNFTIssuanceV4 is ICedarNFTIssuanceV0 {
    event TokensIssued(
        uint256 indexed startTokenId,
        address indexed issuer,
        address indexed receiver,
        uint256 quantity
    );

    event TokenIssued(uint256 indexed tokenId, address indexed issuer, address indexed receiver, string tokenURI);

    event TokenURIUpdated(uint256 indexed tokenId, address indexed updater, string tokenURI);

    /// @dev Issue quantity tokens directly to receiver, only callable by ISSUER_ROLE. Emits TokensIssued event.
    function issue(address receiver, uint256 quantity) external;

    /// @dev Issue a single token directly to receiver with a custom tokenURI, only callable by ISSUER_ROLE.
    /// Emits TokenIssued event.
    function issueWithTokenURI(address receiver, string calldata tokenURI) external;

    /// @dev Sets the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits TokenURIUpdated event.
    function setTokenURI(uint256 tokenId, string memory _tokenURI) external;

    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions()
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 tokenSupply,
            uint256 maxTotalSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface IPublicNFTIssuanceV0 is IDropClaimConditionV0 {
    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;

    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions()
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            // FIXME[Silas]: maxTotalSupply and tokenSupply are the _opposite_ was here than in ICedarSFTIssuance.
            //   I think it is more logical to have maxTokenSupply *last* but I am changing here to account for the fact
            //   that the actual implementation had these two swapped!
            // Update: Fixed on CedarV10
            uint256 maxTotalSupply,
            uint256 tokenSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface IPublicNFTIssuanceV1 is IPublicNFTIssuanceV0 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        address indexed claimer,
        address indexed receiver,
        uint256 startTokenId,
        uint256 quantityClaimed
    );
}

interface IPublicNFTIssuanceV2 is IDropClaimConditionV1 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        address indexed claimer,
        address indexed receiver,
        uint256 startTokenId,
        uint256 quantityClaimed,
        bytes32 phaseId
    );

    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;

    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions()
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 tokenSupply,
            uint256 maxTotalSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Returns the claim condition at the given uid.
    function getClaimConditionById(uint256 _conditionId) external view returns (ClaimCondition memory condition);

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface IPublicNFTIssuanceV3 is IDropClaimConditionV1 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        address indexed claimer,
        address indexed receiver,
        uint256 startTokenId,
        uint256 quantityClaimed,
        bytes32 phaseId
    );

    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;

    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions()
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 tokenSupply,
            uint256 maxTotalSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Returns the claim condition at the given uid.
    function getClaimConditionById(uint256 _conditionId) external view returns (ClaimCondition memory condition);

    /// @dev Returns an array with all the claim conditions.
    function getClaimConditions() external view returns (ClaimCondition[] memory conditions);

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria
    ///     including verification proofs.
    function verifyClaim(
        address _receiver,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bytes32[] calldata _proofs,
        uint256 _proofMaxQuantityPerTransaction
    ) external view;
}

interface IPublicNFTIssuanceV4 is IDropClaimConditionV1 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        address indexed claimer,
        address indexed receiver,
        uint256 startTokenId,
        uint256 quantityClaimed,
        bytes32 phaseId
    );

    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;
}

interface IDelegatedNFTIssuanceV0 is IDropClaimConditionV1 {
    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(address _claimer)
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 tokenSupply,
            uint256 maxTotalSupply,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp,
            bool isClaimPaused
        );

    /// @dev Returns an array with all the claim conditions.
    function getClaimConditions() external view returns (ClaimCondition[] memory conditions);

    /// @dev Returns basic info for claim data
    function getClaimData()
        external
        view
        returns (
            uint256 nextTokenIdToMint,
            uint256 maxTotalSupply,
            uint256 maxWalletClaimCount
        );

    /// @dev Returns the claim condition at the given uid.
    function getClaimConditionById(uint256 _conditionId) external view returns (ClaimCondition memory condition);

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria
    ///     including verification proofs.
    function verifyClaim(
        address _receiver,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bytes32[] calldata _proofs,
        uint256 _proofMaxQuantityPerTransaction
    ) external view;
}

interface IRestrictedNFTIssuanceV0 is IDropClaimConditionV0 {
    /**
     *  @notice Lets a contract admin (account with `DEFAULT_ADMIN_ROLE`) set claim conditions.
     *
     *  @param phases                Claim conditions in ascending order by `startTimestamp`.
     *  @param resetClaimEligibility Whether to reset `limitLastClaimTimestamp` and
     *                               `limitMerkleProofClaim` values when setting new
     *                               claim conditions.
     */
    function setClaimConditions(ClaimCondition[] calldata phases, bool resetClaimEligibility) external;

    /// @dev Issue quantity tokens directly to receiver, only callable by ISSUER_ROLE. Emits TokensIssued event.
    function issue(address receiver, uint256 quantity) external;

    /// @dev Issue a single token directly to receiver with a custom tokenURI, only callable by ISSUER_ROLE.
    /// Emits TokenIssued event.
    function issueWithTokenURI(address receiver, string calldata tokenURI) external;

    /// @dev Sets the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits TokenURIUpdated event.
    function setTokenURI(uint256 tokenId, string memory _tokenURI) external;
}

interface IRestrictedNFTIssuanceV1 is IRestrictedNFTIssuanceV0 {
    /// @dev Emitted when new claim conditions are set.
    event ClaimConditionsUpdated(IDropClaimConditionV0.ClaimCondition[] claimConditions);
    /// @dev Emitted when new token is issued by ISSUER.
    event TokensIssued(
        uint256 indexed startTokenId,
        address indexed issuer,
        address indexed receiver,
        uint256 quantity
    );
    /// @dev Emitted when tokens are issued.
    event TokenIssued(uint256 indexed tokenId, address indexed issuer, address indexed receiver, string tokenURI);
    /// @dev Emitted when token URI is updated.
    event TokenURIUpdated(uint256 indexed tokenId, address indexed updater, string tokenURI);
}

interface IRestrictedNFTIssuanceV2 is IDropClaimConditionV1 {
    /// @dev Emitted when new claim conditions are set.
    event ClaimConditionsUpdated(IDropClaimConditionV1.ClaimCondition[] claimConditions);
    /// @dev Emitted when new token is issued by ISSUER.
    event TokensIssued(
        uint256 indexed startTokenId,
        address indexed issuer,
        address indexed receiver,
        uint256 quantity
    );
    /// @dev Emitted when tokens are issued.
    event TokenIssued(uint256 indexed tokenId, address indexed issuer, address indexed receiver, string tokenURI);
    /// @dev Emitted when token URI is updated.
    event TokenURIUpdated(uint256 indexed tokenId, address indexed updater, string tokenURI);

    /**
     *  @notice Lets a contract admin (account with `DEFAULT_ADMIN_ROLE`) set claim conditions.
     *
     *  @param phases                Claim conditions in ascending order by `startTimestamp`.
     *  @param resetClaimEligibility Whether to reset `limitLastClaimTimestamp` and
     *                               `limitMerkleProofClaim` values when setting new
     *                               claim conditions.
     */
    function setClaimConditions(ClaimCondition[] calldata phases, bool resetClaimEligibility) external;

    /// @dev Issue quantity tokens directly to receiver, only callable by ISSUER_ROLE. Emits TokensIssued event.
    function issue(address receiver, uint256 quantity) external;

    /// @dev Issue a single token directly to receiver with a custom tokenURI, only callable by ISSUER_ROLE.
    /// Emits TokenIssued event.
    function issueWithTokenURI(address receiver, string calldata tokenURI) external;

    /// @dev Sets the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits "TokenURIUpdated" event.
    function setTokenURI(uint256 tokenId, string memory _tokenURI) external;
}

interface IRestrictedNFTIssuanceV3 is IRestrictedNFTIssuanceV2 {
    /// @dev Sets and Freezes the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits a "TokenURIUpdated" and a "PermanentURI" event.
    function setPermantentTokenURI(uint256 tokenId, string memory _tokenURI) external;

    /// @dev Event emitted when permanent token uri is set
    event PermanentURI(string _value, uint256 indexed _id);
}

interface IRestrictedNFTIssuanceV4 is IRestrictedNFTIssuanceV3 {
    /// @dev Issue quantity tokens directly to receiver, only callable by ISSUER_ROLE. Emits TokensIssued event.
    ///     It verifies the issue in a similar way as claim() and record the claimed tokens
    /// Emits TokenIssued event.
    function issueWithinPhase(address receiver, uint256 quantity) external;

    /// @dev Issue a single token directly to receiver with a custom tokenURI, only callable by ISSUER_ROLE.
    ///     It verifies the issue in a similar way as claim() and record the claimed tokens
    /// Emits TokenIssued event.
    function issueWithinPhaseWithTokenURI(address receiver, string calldata tokenURI) external;
}

// File: contracts/aspen/api/issuance/ICedarSFTIssuance.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

import "./IDropClaimCondition.sol";

/**
 *  Cedar's 'Drop' contracts are distribution mechanisms for tokens. The
 *  `DropERC721` contract is a distribution mechanism for ERC721 tokens.
 *
 *  A minter wallet (i.e. holder of `MINTER_ROLE`) can (lazy)mint 'n' tokens
 *  at once by providing a single base URI for all tokens being lazy minted.
 *  The URI for each of the 'n' tokens lazy minted is the provided base URI +
 *  `{tokenId}` of the respective token. (e.g. "ipsf://Qmece.../1").
 *
 *  A contract admin (i.e. holder of `DEFAULT_ADMIN_ROLE`) can create claim conditions
 *  with non-overlapping time windows, and accounts can claim the tokens according to
 *  restrictions defined in the claim condition that is active at the time of the transaction.
 */

interface ICedarSFTIssuanceV0 is IDropClaimConditionV0 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        uint256 indexed tokenId,
        address indexed claimer,
        address receiver,
        uint256 quantityClaimed
    );

    /// @dev Emitted when tokens are issued.
    event TokensIssued(uint256 indexed tokenId, address indexed claimer, address receiver, uint256 quantityClaimed);

    /// @dev Emitted when new claim conditions are set for a token.
    event ClaimConditionsUpdated(uint256 indexed tokenId, ClaimCondition[] claimConditions);

    /**
     *  @notice Lets a contract admin (account with `DEFAULT_ADMIN_ROLE`) set claim conditions.
     *
     *  @param tokenId               The token ID for which to set mint conditions.
     *  @param phases                Claim conditions in ascending order by `startTimestamp`.
     *  @param resetClaimEligibility Whether to reset `limitLastClaimTimestamp` and
     *                               `limitMerkleProofClaim` values when setting new
     *                               claim conditions.
     */
    function setClaimConditions(
        uint256 tokenId,
        ClaimCondition[] calldata phases,
        bool resetClaimEligibility
    ) external;

    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param tokenId                       The unique ID of the token to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 tokenId,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;

    /**
     *  @notice Lets an account with ISSUER_ROLE issue NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param tokenId                       The unique ID of the token to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     */
    function issue(
        address receiver,
        uint256 tokenId,
        uint256 quantity
    ) external;
}

interface ICedarSFTIssuanceV1 is ICedarSFTIssuanceV0 {
    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions(uint256 _tokenId)
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 remainingSupply
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(uint256 _tokenId, address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _tokenId,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface ICedarSFTIssuanceV2 is ICedarSFTIssuanceV0 {
    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions(uint256 _tokenId)
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 remainingSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(uint256 _tokenId, address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _tokenId,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface ICedarSFTIssuanceV3 is ICedarSFTIssuanceV0 {
    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions(uint256 _tokenId)
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 tokenSupply,
            uint256 maxTotalSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(uint256 _tokenId, address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _tokenId,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface IPublicSFTIssuanceV0 is IDropClaimConditionV0 {
    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param tokenId                       The unique ID of the token to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 tokenId,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;

    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions(uint256 _tokenId)
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 tokenSupply,
            uint256 maxTotalSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(uint256 _tokenId, address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _tokenId,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface IPublicSFTIssuanceV1 is IPublicSFTIssuanceV0 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        uint256 indexed tokenId,
        address indexed claimer,
        address receiver,
        uint256 quantityClaimed
    );
}

interface IPublicSFTIssuanceV2 is IDropClaimConditionV1 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        uint256 indexed tokenId,
        address indexed claimer,
        address receiver,
        uint256 quantityClaimed,
        bytes32 phaseId
    );

    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param tokenId                       The unique ID of the token to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 tokenId,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;

    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions(uint256 _tokenId)
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 tokenSupply,
            uint256 maxTotalSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(uint256 _tokenId, address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Returns the claim condition at the given uid.
    function getClaimConditionById(uint256 _tokenId, uint256 _conditionId)
        external
        view
        returns (ClaimCondition memory condition);

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria.
    function verifyClaim(
        uint256 _conditionId,
        address _claimer,
        uint256 _tokenId,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bool verifyMaxQuantityPerTransaction
    ) external view;
}

interface IPublicSFTIssuanceV3 is IDropClaimConditionV1 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        uint256 indexed tokenId,
        address indexed claimer,
        address receiver,
        uint256 quantityClaimed,
        bytes32 phaseId
    );

    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param tokenId                       The unique ID of the token to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 tokenId,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;

    /// @dev Expose the current active claim condition including claim limits
    function getActiveClaimConditions(uint256 _tokenId)
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 tokenSupply,
            uint256 maxTotalSupply,
            bool isClaimPaused
        );

    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(uint256 _tokenId, address _claimer)
        external
        view
        returns (
            uint256 conditionId,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp
        );

    /// @dev Returns the claim condition at the given uid.
    function getClaimConditionById(uint256 _tokenId, uint256 _conditionId)
        external
        view
        returns (ClaimCondition memory condition);

    /// @dev Returns an array with all the claim conditions for a specific token.
    function getClaimConditions(uint256 _tokenId) external view returns (ClaimCondition[] memory conditions);

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria
    ///     including verification proofs.
    function verifyClaim(
        address _receiver,
        uint256 _tokenId,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bytes32[] calldata _proofs,
        uint256 _proofMaxQuantityPerTransaction
    ) external view;
}

interface IPublicSFTIssuanceV4 is IDropClaimConditionV1 {
    /// @dev Emitted when tokens are claimed.
    event TokensClaimed(
        uint256 indexed claimConditionIndex,
        address indexed claimer,
        address indexed receiver,
        uint256 tokenId,
        uint256 quantityClaimed,
        bytes32 phaseId
    );

    /**
     *  @notice Lets an account claim a given quantity of NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param tokenId                       The unique ID of the token to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     *  @param currency                       The currency in which to pay for the claim.
     *  @param pricePerToken                  The price per token to pay for the claim.
     *  @param proofs                         The proof of the claimer's inclusion in the merkle root allowlist
     *                                        of the claim conditions that apply.
     *  @param proofMaxQuantityPerTransaction (Optional) The maximum number of NFTs an address included in an
     *                                        allowlist can claim.
     */
    function claim(
        address receiver,
        uint256 tokenId,
        uint256 quantity,
        address currency,
        uint256 pricePerToken,
        bytes32[] calldata proofs,
        uint256 proofMaxQuantityPerTransaction
    ) external payable;
}

interface IDelegatedSFTIssuanceV0 is IDropClaimConditionV1 {
    /// @dev Expose the user specific limits related to the current active claim condition
    function getUserClaimConditions(uint256 _tokenId, address _claimer)
        external
        view
        returns (
            ClaimCondition memory condition,
            uint256 conditionId,
            uint256 walletMaxClaimCount,
            uint256 tokenSupply,
            uint256 maxTotalSupply,
            uint256 walletClaimedCount,
            uint256 walletClaimedCountInPhase,
            uint256 lastClaimTimestamp,
            uint256 nextValidClaimTimestamp,
            bool isClaimPaused
        );

    /// @dev Returns an array with all the claim conditions for a specific token.
    function getClaimConditions(uint256 _tokenId) external view returns (ClaimCondition[] memory conditions);

    /// @dev Returns basic info for claim data
    function getClaimData(uint256 _tokenId)
        external
        view
        returns (
            uint256 nextTokenIdToMint,
            uint256 maxTotalSupply,
            uint256 maxWalletClaimCount
        );

    /// @dev Returns the claim condition at the given uid.
    function getClaimConditionById(uint256 _tokenId, uint256 _conditionId)
        external
        view
        returns (ClaimCondition memory conditions);

    /// @dev Checks a request to claim NFTs against the active claim condition's criteria
    ///     including verification proofs.
    function verifyClaim(
        address _receiver,
        uint256 _tokenId,
        uint256 _quantity,
        address _currency,
        uint256 _pricePerToken,
        bytes32[] calldata _proofs,
        uint256 _proofMaxQuantityPerTransaction
    ) external view;
}

interface IRestrictedSFTIssuanceV0 is IDropClaimConditionV0 {
    /**
     *  @notice Lets a contract admin (account with `DEFAULT_ADMIN_ROLE`) set claim conditions.
     *
     *  @param tokenId               The token ID for which to set mint conditions.
     *  @param phases                Claim conditions in ascending order by `startTimestamp`.
     *  @param resetClaimEligibility Whether to reset `limitLastClaimTimestamp` and
     *                               `limitMerkleProofClaim` values when setting new
     *                               claim conditions.
     */
    function setClaimConditions(
        uint256 tokenId,
        ClaimCondition[] calldata phases,
        bool resetClaimEligibility
    ) external;

    /**
     *  @notice Lets an account with ISSUER_ROLE issue NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param tokenId                       The unique ID of the token to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     */
    function issue(
        address receiver,
        uint256 tokenId,
        uint256 quantity
    ) external;
}

interface IRestrictedSFTIssuanceV1 is IRestrictedSFTIssuanceV0 {
    /// @dev Emitted when tokens are issued.
    event TokensIssued(uint256 indexed tokenId, address indexed claimer, address receiver, uint256 quantityClaimed);

    /// @dev Emitted when new claim conditions are set for a token.
    event ClaimConditionsUpdated(uint256 indexed tokenId, ClaimCondition[] claimConditions);
}

interface IRestrictedSFTIssuanceV2 is IDropClaimConditionV1 {
    /// @dev Emitted when tokens are issued.
    event TokensIssued(uint256 indexed tokenId, address indexed claimer, address receiver, uint256 quantityClaimed);

    /// @dev Emitted when new claim conditions are set for a token.
    event ClaimConditionsUpdated(uint256 indexed tokenId, ClaimCondition[] claimConditions);

    /**
     *  @notice Lets a contract admin (account with `DEFAULT_ADMIN_ROLE`) set claim conditions.
     *
     *  @param tokenId               The token ID for which to set mint conditions.
     *  @param phases                Claim conditions in ascending order by `startTimestamp`.
     *  @param resetClaimEligibility Whether to reset `limitLastClaimTimestamp` and
     *                               `limitMerkleProofClaim` values when setting new
     *                               claim conditions.
     */
    function setClaimConditions(
        uint256 tokenId,
        ClaimCondition[] calldata phases,
        bool resetClaimEligibility
    ) external;

    /**
     *  @notice Lets an account with ISSUER_ROLE issue NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param tokenId                       The unique ID of the token to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     */
    function issue(
        address receiver,
        uint256 tokenId,
        uint256 quantity
    ) external;
}

interface IRestrictedSFTIssuanceV3 is IRestrictedSFTIssuanceV2 {
    /// @dev Sets and Freezes the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits a "TokenURIUpdated" and a "PermanentURI" event.
    function setPermantentTokenURI(uint256 tokenId, string memory _tokenURI) external;

    /// @dev Event emitted when permanent token uri is set
    event PermanentURI(string _value, uint256 indexed _id);

    /// @dev Sets the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits TokenURIUpdated event.
    function setTokenURI(uint256 tokenId, string memory _tokenURI) external;

    /// @dev Event emitted when a token uri is update
    event TokenURIUpdated(uint256 indexed tokenId, address indexed updater, string tokenURI);
}

interface IRestrictedSFTIssuanceV4 is IDropClaimConditionV1 {
    /// @dev Emitted when tokens are issued.
    event TokensIssued(
        uint256 indexed tokenId,
        address indexed issuer,
        address indexed receiver,
        uint256 quantityClaimed
    );

    /// @dev Emitted when new claim conditions are set for a token.
    event ClaimConditionsUpdated(uint256 indexed tokenId, ClaimCondition[] claimConditions);

    /**
     *  @notice Lets a contract admin (account with `DEFAULT_ADMIN_ROLE`) set claim conditions.
     *
     *  @param tokenId               The token ID for which to set mint conditions.
     *  @param phases                Claim conditions in ascending order by `startTimestamp`.
     *  @param resetClaimEligibility Whether to reset `limitLastClaimTimestamp` and
     *                               `limitMerkleProofClaim` values when setting new
     *                               claim conditions.
     */
    function setClaimConditions(
        uint256 tokenId,
        ClaimCondition[] calldata phases,
        bool resetClaimEligibility
    ) external;

    /**
     *  @notice Lets an account with ISSUER_ROLE issue NFTs.
     *
     *  @param receiver                       The receiver of the NFTs to claim.
     *  @param tokenId                       The unique ID of the token to claim.
     *  @param quantity                       The quantity of NFTs to claim.
     */
    function issue(
        address receiver,
        uint256 tokenId,
        uint256 quantity
    ) external;

    /// @dev Issue quantity tokens directly to receiver, only callable by ISSUER_ROLE. Emits TokensIssued event.
    ///     It verifies the issue in a similar way as claim() and record the claimed tokens
    /// @param receiver     The receiver of the NFTs to claim.
    /// @param tokenId      The unique ID of the token to claim.
    /// @param quantity     The quantity of NFTs to claim.
    /// Emits TokenIssued event.
    function issueWithinPhase(
        address receiver,
        uint256 tokenId,
        uint256 quantity
    ) external;

    /// @dev Sets and Freezes the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits a "TokenURIUpdated" and a "PermanentURI" event.
    function setPermantentTokenURI(uint256 tokenId, string memory _tokenURI) external;

    /// @dev Event emitted when permanent token uri is set
    event PermanentURI(string _value, uint256 indexed _id);

    /// @dev Sets the tokenURI of a specific token which overrides the one that would otherwise
    /// be generated from the baseURI. This function keeps tracks of whether the tokenURI or baseURI is fresher for a
    /// particular token. Emits TokenURIUpdated event.
    function setTokenURI(uint256 tokenId, string memory _tokenURI) external;

    /// @dev Event emitted when a token uri is update
    event TokenURIUpdated(uint256 indexed tokenId, address indexed updater, string tokenURI);
}

// File: contracts/aspen/api/issuance/IDropClaimCondition.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

import "@openzeppelin/contracts-upgradeable/utils/structs/BitMapsUpgradeable.sol";

/**
 *  Cedar's 'Drop' contracts are distribution mechanisms for tokens.
 *
 *  A contract admin (i.e. a holder of `DEFAULT_ADMIN_ROLE`) can set a series of claim conditions,
 *  ordered by their respective `startTimestamp`. A claim condition defines criteria under which
 *  accounts can mint tokens. Claim conditions can be overwritten or added to by the contract admin.
 *  At any moment, there is only one active claim condition.
 */

interface IDropClaimConditionV0 {
    /**
     *  @notice The criteria that make up a claim condition.
     *
     *  @param startTimestamp                 The unix timestamp after which the claim condition applies.
     *                                        The same claim condition applies until the `startTimestamp`
     *                                        of the next claim condition.
     *
     *  @param maxClaimableSupply             The maximum total number of tokens that can be claimed under
     *                                        the claim condition.
     *
     *  @param supplyClaimed                  At any given point, the number of tokens that have been claimed
     *                                        under the claim condition.
     *
     *  @param quantityLimitPerTransaction    The maximum number of tokens that can be claimed in a single
     *                                        transaction.
     *
     *  @param waitTimeInSecondsBetweenClaims The least number of seconds an account must wait after claiming
     *                                        tokens, to be able to claim tokens again.
     *
     *  @param merkleRoot                     The allowlist of addresses that can claim tokens under the claim
     *                                        condition.
     *
     *  @param pricePerToken                  The price required to pay per token claimed.
     *
     *  @param currency                       The currency in which the `pricePerToken` must be paid.
     */
    struct ClaimCondition {
        uint256 startTimestamp;
        uint256 maxClaimableSupply;
        uint256 supplyClaimed;
        uint256 quantityLimitPerTransaction;
        uint256 waitTimeInSecondsBetweenClaims;
        bytes32 merkleRoot;
        uint256 pricePerToken;
        address currency;
    }

    /**
     *  @notice The set of all claim conditions, at any given moment.
     *  Claim Phase ID = [currentStartId, currentStartId + length - 1];
     *
     *  @param currentStartId           The uid for the first claim condition amongst the current set of
     *                                  claim conditions. The uid for each next claim condition is one
     *                                  more than the previous claim condition's uid.
     *
     *  @param count                    The total number of phases / claim conditions in the list
     *                                  of claim conditions.
     *
     *  @param phases                   The claim conditions at a given uid. Claim conditions
     *                                  are ordered in an ascending order by their `startTimestamp`.
     *
     *  @param claimDetails             Map from an account and uid for a claim condition, to the claim
     *                                  records an account has done.
     *
     */
    struct ClaimConditionList {
        uint256 currentStartId;
        uint256 count;
        mapping(uint256 => ClaimCondition) phases;
        mapping(uint256 => mapping(address => ClaimDetails)) userClaims;
    }

    /**
     *  @notice Claim detail for a user claim.
     *
     *  @param lastClaimTimestamp    The timestamp at which the last token was claimed.
     *
     *  @param claimedBalance        The number of tokens claimed.
     *
     */
    struct ClaimDetails {
        uint256 lastClaimTimestamp;
        uint256 claimedBalance;
    }
}

interface IDropClaimConditionV1 {
    /**
     *  @notice The criteria that make up a claim condition.
     *
     *  @param startTimestamp                 The unix timestamp after which the claim condition applies.
     *                                        The same claim condition applies until the `startTimestamp`
     *                                        of the next claim condition.
     *
     *  @param maxClaimableSupply             The maximum total number of tokens that can be claimed under
     *                                        the claim condition.
     *
     *  @param supplyClaimed                  At any given point, the number of tokens that have been claimed
     *                                        under the claim condition.
     *
     *  @param quantityLimitPerTransaction    The maximum number of tokens that can be claimed in a single
     *                                        transaction.
     *
     *  @param waitTimeInSecondsBetweenClaims The least number of seconds an account must wait after claiming
     *                                        tokens, to be able to claim tokens again.
     *
     *  @param merkleRoot                     The allowlist of addresses that can claim tokens under the claim
     *                                        condition.
     *
     *  @param pricePerToken                  The price required to pay per token claimed.
     *
     *  @param currency                       The currency in which the `pricePerToken` must be paid.
     */
    struct ClaimCondition {
        uint256 startTimestamp;
        uint256 maxClaimableSupply;
        uint256 supplyClaimed;
        uint256 quantityLimitPerTransaction;
        uint256 waitTimeInSecondsBetweenClaims;
        bytes32 merkleRoot;
        uint256 pricePerToken;
        address currency;
        bytes32 phaseId;
    }

    /**
     *  @notice The set of all claim conditions, at any given moment.
     *  Claim Phase ID = [currentStartId, currentStartId + length - 1];
     *
     *  @param currentStartId           The uid for the first claim condition amongst the current set of
     *                                  claim conditions. The uid for each next claim condition is one
     *                                  more than the previous claim condition's uid.
     *
     *  @param count                    The total number of phases / claim conditions in the list
     *                                  of claim conditions.
     *
     *  @param phases                   The claim conditions at a given uid. Claim conditions
     *                                  are ordered in an ascending order by their `startTimestamp`.
     *
     *  @param claimDetails             Map from an account and uid for a claim condition, to the claim
     *                                  records an account has done.
     *
     */
    struct ClaimConditionList {
        uint256 currentStartId;
        uint256 count;
        mapping(uint256 => ClaimCondition) phases;
        mapping(uint256 => mapping(address => ClaimDetails)) userClaims;
    }

    /**
     *  @notice Claim detail for a user claim.
     *
     *  @param lastClaimTimestamp    The timestamp at which the last token was claimed.
     *
     *  @param claimedBalance        The number of tokens claimed.
     *
     */
    struct ClaimDetails {
        uint256 lastClaimTimestamp;
        uint256 claimedBalance;
    }
}

// File: contracts/aspen/api/issuance/INFTClaimCount.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface IRestrictedNFTClaimCountV0 {
    /// @dev Emitted when the wallet claim count for an address is updated.
    event WalletClaimCountUpdated(address indexed wallet, uint256 count);
    /// @dev Emitted when the global max wallet claim count is updated.
    event MaxWalletClaimCountUpdated(uint256 count);

    /// @dev Lets a contract admin set a claim count for a wallet.
    function setWalletClaimCount(address _claimer, uint256 _count) external;

    /// @dev Lets a contract admin set a maximum number of NFTs that can be claimed by any wallet.
    function setMaxWalletClaimCount(uint256 _count) external;
}

// File: contracts/aspen/api/issuance/INFTLimitSupply.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface IRestrictedNFTLimitSupplyV0 {
    function setMaxTotalSupply(uint256 _maxTotalSupply) external;
}

interface IRestrictedNFTLimitSupplyV1 is IRestrictedNFTLimitSupplyV0 {
    /// @dev Emitted when the global max supply of tokens is updated.
    event MaxTotalSupplyUpdated(uint256 maxTotalSupply);
}

// File: contracts/aspen/api/issuance/INFTSupply.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

interface INFTSupplyV0 {
    /**
     * @dev Total amount of tokens minted.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Indicates whether any token exist with a given id, or not.
     */
    function exists(uint256 id) external view returns (bool);
}

interface INFTSupplyV1 is INFTSupplyV0 {
    /// @dev Offset for token IDs.
    function getSmallestTokenId() external view returns (uint8);
}

interface IDelegatedNFTSupplyV0 {
    /// @dev Offset for token IDs.
    function getSmallestTokenId() external view returns (uint8);
}

// File: contracts/aspen/api/issuance/ISFTClaimCount.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface IRestrictedSFTClaimCountV0 {
    /// @dev Emitted when the wallet claim count for a given tokenId and address is updated.
    event WalletClaimCountUpdated(uint256 tokenId, address indexed wallet, uint256 count);
    /// @dev Emitted when the max wallet claim count for a given tokenId is updated.
    event MaxWalletClaimCountUpdated(uint256 tokenId, uint256 count);

    /// @dev Lets a contract admin set a claim count for a wallet.
    function setWalletClaimCount(
        uint256 _tokenId,
        address _claimer,
        uint256 _count
    ) external;

    /// @dev Lets a contract admin set a maximum number of NFTs of a tokenId that can be claimed by any wallet.
    function setMaxWalletClaimCount(uint256 _tokenId, uint256 _count) external;
}

// File: contracts/aspen/api/issuance/ISFTLimitSupply.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface IRestrictedSFTLimitSupplyV0 {
    function setMaxTotalSupply(uint256 _tokenId, uint256 _maxTotalSupply) external;
}

interface IRestrictedSFTLimitSupplyV1 is IRestrictedSFTLimitSupplyV0 {
    /// @dev Emitted when the global max supply of tokens is updated.
    event MaxTotalSupplyUpdated(uint256 tokenId, uint256 maxTotalSupply);
}

// File: contracts/aspen/api/issuance/ISFTSupply.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

interface ISFTSupplyV0 {
    /**
     * @dev Total amount of tokens in with a given id.
     */
    function totalSupply(uint256 id) external view returns (uint256);

    /**
     * @dev Indicates whether any token exist with a given id, or not.
     */
    function exists(uint256 id) external view returns (bool);

    /**
     * @dev Amount of unique tokens minted.
     */
    function getLargestTokenId() external view returns (uint256);
}

interface ISFTSupplyV1 is ISFTSupplyV0 {
    /// @dev Offset for token IDs.
    function getSmallestTokenId() external view returns (uint8);
}

interface IPublicSFTSupplyV0 {
    /**
     * @dev Total amount of tokens in with a given id.
     */
    function totalSupply(uint256 id) external view returns (uint256);

    /**
     * @dev Indicates whether any token exist with a given id, or not.
     */
    function exists(uint256 id) external view returns (bool);
}

interface IDelegatedSFTSupplyV0 {
    /**
     * @dev Amount of unique tokens minted.
     */
    function getLargestTokenId() external view returns (uint256);

    /// @dev Offset for token IDs.
    function getSmallestTokenId() external view returns (uint8);
}

// File: contracts/aspen/api/lazymint/ILazyMint.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8.4;

interface ICedarLazyMintV0 {
    /// @dev Emitted when tokens are lazy minted.
    event TokensLazyMinted(uint256 startTokenId, uint256 endTokenId, string baseURI);

    /**
     *  @notice Lets an account with `MINTER_ROLE` lazy mint 'n' NFTs.
     *          The URIs for each token is the provided `_baseURIForTokens` + `{tokenId}`.
     *
     *  @param amount           The amount of NFTs to lazy mint.
     *  @param baseURIForTokens The URI for the NFTs to lazy mint. If lazy minting
     *                           'delayed-reveal' NFTs, the is a URI for NFTs in the
     *                           un-revealed state.
     */
    function lazyMint(uint256 amount, string calldata baseURIForTokens) external;
}

interface IRestrictedLazyMintV0 {
    /**
     *  @notice Lets an account with `MINTER_ROLE` lazy mint 'n' NFTs.
     *          The URIs for each token is the provided `_baseURIForTokens` + `{tokenId}`.
     *
     *  @param amount           The amount of NFTs to lazy mint.
     *  @param baseURIForTokens The URI for the NFTs to lazy mint. If lazy minting
     *                           'delayed-reveal' NFTs, the is a URI for NFTs in the
     *                           un-revealed state.
     */
    function lazyMint(uint256 amount, string calldata baseURIForTokens) external;
}

interface IRestrictedLazyMintV1 is IRestrictedLazyMintV0 {
    /// @dev Emitted when tokens are lazy minted.
    event TokensLazyMinted(uint256 startTokenId, uint256 endTokenId, string baseURI);
}

// File: contracts/aspen/api/metadata/IContractMetadata.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface ICedarMetadataV1 {
    /// @dev Contract level metadata.
    function contractURI() external view returns (string memory);

    /// @dev Lets a contract admin set the URI for contract-level metadata.
    function setContractURI(string calldata _uri) external;

    /// @dev Emitted when contractURI is updated
    event ContractURIUpdated(address indexed updater, string uri);
}

interface IPublicMetadataV0 {
    /// @dev Contract level metadata.
    function contractURI() external view returns (string memory);
}

interface IRestrictedMetadataV0 {
    /// @dev Lets a contract admin set the URI for contract-level metadata.
    function setContractURI(string calldata _uri) external;
}

interface IRestrictedMetadataV1 is IRestrictedMetadataV0 {
    /// @dev Emitted when contractURI is updated
    event ContractURIUpdated(address indexed updater, string uri);
}

interface IRestrictedMetadataV2 is IRestrictedMetadataV1 {
    /// @dev Lets a contract admin set the token name and symbol
    function setTokenNameAndSymbol(string calldata _name, string calldata _symbol) external;

    /// @dev Emitted when token name and symbol are updated
    event TokenNameAndSymbolUpdated(address indexed updater, string name, string symbol);
}

// File: contracts/aspen/api/metadata/INFTMetadata.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface ICedarNFTMetadataV1 {
    /// @dev Returns the URI for a given tokenId.
    function tokenURI(uint256 _tokenId) external view returns (string memory);
}

interface IAspenNFTMetadataV1 {
    /// @dev Returns the URI for a given tokenId.
    function tokenURI(uint256 _tokenId) external view returns (string memory);
}

// File: contracts/aspen/api/metadata/ISFTMetadata.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface ICedarSFTMetadataV1 {
    /// @dev Returns the URI for a given tokenId.
    function uri(uint256 _tokenId) external view returns (string memory);
}

interface IAspenSFTMetadataV1 {
    /// @dev Returns the URI for a given tokenId.
    function uri(uint256 _tokenId) external view returns (string memory);
}

// File: contracts/aspen/api/ownable/IOwnable.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface IOwnableV0 {
    /// @dev Returns the owner of the contract.
    function owner() external view returns (address);

    /// @dev Lets a module admin set a new owner for the contract. The new owner must be a module admin.
    function setOwner(address _newOwner) external;

    /// @dev Emitted when a new Owner is set.
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
}

interface IOwnableEventV0 {
    /// @dev Emitted when a new Owner is set.
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
}

interface IPublicOwnableV0 is IOwnableEventV0 {
    /// @dev Returns the owner of the contract.
    function owner() external view returns (address);
}

interface IRestrictedOwnableV0 is IOwnableEventV0 {
    /// @dev Lets a module admin set a new owner for the contract. The new owner must be a module admin.
    function setOwner(address _newOwner) external;
}

// File: contracts/aspen/api/pausable/IPausable.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

interface ICedarPausableV0 {
    /// @dev Pause claim functionality.
    function pauseClaims() external;

    /// @dev Un-pause claim functionality.
    function unpauseClaims() external;

    /// @dev Event emitted when claim functionality is paused/un-paused.
    event ClaimPauseStatusUpdated(bool pauseStatus);
}

interface ICedarPausableV1 {
    /// @dev Pause / Un-pause claim functionality.
    function setClaimPauseStatus(bool _pause) external;

    /// @dev Event emitted when claim functionality is paused/un-paused.
    event ClaimPauseStatusUpdated(bool pauseStatus);
}

interface IRestrictedPausableV0 {
    /// @dev Pause / Un-pause claim functionality.
    function setClaimPauseStatus(bool _pause) external;
}

interface IRestrictedPausableV1 is IRestrictedPausableV0 {
    /// @dev Event emitted when claim functionality is paused/un-paused.
    event ClaimPauseStatusUpdated(bool pauseStatus);
}

interface IPublicPausableV0 {
    /// @dev returns the pause status of the drop contract.
    function getClaimPauseStatus() external view returns (bool pauseStatus);
}

interface IDelegatedPausableV0 {
    /// @dev returns the pause status of the drop contract.
    function getClaimPauseStatus() external view returns (bool pauseStatus);
}

// File: contracts/aspen/api/primarysale/IPrimarySale.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

interface IPrimarySaleV0 {
    /// @dev The address that receives all primary sales value.
    function primarySaleRecipient() external view returns (address);

    /// @dev Lets a module admin set the default recipient of all primary sales.
    function setPrimarySaleRecipient(address _saleRecipient) external;

    /// @dev Emitted when a new sale recipient is set.
    event PrimarySaleRecipientUpdated(address indexed recipient);
}

interface IPrimarySaleV1 {
    /// @dev The address that receives all primary sales value.
    function primarySaleRecipient() external view returns (address);

    /// @dev Lets a module admin set the default recipient of all primary sales.
    function setPrimarySaleRecipient(address _saleRecipient) external;

    /// @dev Emitted when a new sale recipient is set.
    event PrimarySaleRecipientUpdated(address indexed recipient, bool frogs);
}

interface IPublicPrimarySaleV1 {
    /// @dev The address that receives all primary sales value.
    function primarySaleRecipient() external view returns (address);
}

interface IRestrictedPrimarySaleV1 {
    /// @dev Lets a module admin set the default recipient of all primary sales.
    function setPrimarySaleRecipient(address _saleRecipient) external;
}

interface IRestrictedPrimarySaleV2 is IRestrictedPrimarySaleV1 {
    /// @dev Emitted when a new sale recipient is set.
    event PrimarySaleRecipientUpdated(address indexed recipient);
}

// NOTE: The below feature only exists on ERC1155 atm, therefore new interface that handles only that
interface IRestrictedSFTPrimarySaleV0 {
    /// @dev Lets a contract admin set the recipient for all primary sales.
    function setSaleRecipientForToken(uint256 _tokenId, address _saleRecipient) external;

    /// @dev Emitted when the sale recipient for a particular tokenId is updated.
    event SaleRecipientForTokenUpdated(uint256 indexed tokenId, address saleRecipient);
}

// File: contracts/aspen/api/royalties/IPlatformFee.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

// NOTE: Deprecated from v2 onwards
interface IPublicPlatformFeeV0 {
    /// @dev Returns the platform fee bps and recipient.
    function getPlatformFeeInfo() external view returns (address, uint16);
}

interface IDelegatedPlatformFeeV0 {
    /// @dev Returns the platform fee bps and recipient.
    function getPlatformFeeInfo() external view returns (address platformFeeRecipient, uint16 platformFeeBps);
}

interface IRestrictedPlatformFeeV0 {
    /// @dev Emitted when fee on primary sales is updated.
    event PlatformFeeInfoUpdated(address platformFeeRecipient, uint256 platformFeeBps);

    /// @dev Lets a module admin update the fees on primary sales.
    function setPlatformFeeInfo(address _platformFeeRecipient, uint256 _platformFeeBps) external;
}

// File: contracts/aspen/api/royalties/IRoyalty.sol



// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8;

import "../standard/IERC2981.sol";

interface IRoyaltyV0 is IERC2981V0 {
    struct RoyaltyInfo {
        address recipient;
        uint256 bps;
    }

    /// @dev Returns the royalty recipient and fee bps.
    function getDefaultRoyaltyInfo() external view returns (address, uint16);

    /// @dev Lets a module admin update the royalty bps and recipient.
    function setDefaultRoyaltyInfo(address _royaltyRecipient, uint256 _royaltyBps) external;

    /// @dev Lets a module admin set the royalty recipient for a particular token Id.
    function setRoyaltyInfoForToken(
        uint256 tokenId,
        address recipient,
        uint256 bps
    ) external;

    /// @dev Returns the royalty recipient for a particular token Id.
    function getRoyaltyInfoForToken(uint256 tokenId) external view returns (address, uint16);

    /// @dev Emitted when royalty info is updated.
    event DefaultRoyalty(address newRoyaltyRecipient, uint256 newRoyaltyBps);

    /// @dev Emitted when royalty recipient for tokenId is set
    event RoyaltyForToken(uint256 indexed tokenId, address royaltyRecipient, uint256 royaltyBps);
}

interface IPublicRoyaltyV0 is IERC2981V0 {
    struct RoyaltyInfo {
        address recipient;
        uint256 bps;
    }

    /// @dev Returns the royalty recipient and fee bps.
    function getDefaultRoyaltyInfo() external view returns (address, uint16);

    /// @dev Returns the royalty recipient for a particular token Id.
    function getRoyaltyInfoForToken(uint256 tokenId) external view returns (address, uint16);
}

interface IRestrictedRoyaltyV0 {
    /// @dev Lets a module admin update the royalty bps and recipient.
    function setDefaultRoyaltyInfo(address _royaltyRecipient, uint256 _royaltyBps) external;

    /// @dev Lets a module admin set the royalty recipient for a particular token Id.
    function setRoyaltyInfoForToken(
        uint256 tokenId,
        address recipient,
        uint256 bps
    ) external;
}

interface IRestrictedRoyaltyV1 is IRestrictedRoyaltyV0 {
    /// @dev Emitted when royalty info is updated.
    event DefaultRoyalty(address newRoyaltyRecipient, uint256 newRoyaltyBps);
    /// @dev Emitted when royalty recipient for tokenId is set
    event RoyaltyForToken(uint256 indexed tokenId, address royaltyRecipient, uint256 royaltyBps);
}

interface IRestrictedRoyaltyV2 is IRestrictedRoyaltyV1 {
    /// @dev Emitted when the operator filter is updated.
    event OperatorFilterStatusUpdated(bool enabled);

    /// @dev allows an admin to enable / disable the operator filterer.
    function setOperatorFiltererStatus(bool _enabled) external;
}

interface IPublicOperatorFilterToggleV0 {
    function operatorRestriction() external view returns (bool);
}

interface IRestrictedOperatorFilterToggleV0 {
    event OperatorRestriction(bool _restriction);

    function setOperatorRestriction(bool _restriction) external;
}

interface IRestrictedOperatorFiltererV0 {
    event OperatorFiltererUpdated(bytes32 _operatorFiltererId);

    function setOperatorFilterer(bytes32 _operatorFiltererId) external;
}

// File: contracts/aspen/api/splitpayment/ISplitPayment.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";

interface ICedarSplitPaymentV0 {
    function getTotalReleased() external view returns (uint256);

    function getTotalReleased(IERC20Upgradeable token) external view returns (uint256);

    function getReleased(address account) external view returns (uint256);

    function getReleased(IERC20Upgradeable token, address account) external view returns (uint256);

    function releasePayment(address payable account) external;

    function releasePayment(IERC20Upgradeable token, address account) external;
}

interface IAspenSplitPaymentV1 is ICedarSplitPaymentV0 {
    function getPendingPayment(address account) external view returns (uint256);

    function getPendingPayment(IERC20Upgradeable token, address account) external view returns (uint256);
}

// File: contracts/aspen/api/standard/IERC1155.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

import "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.sol";

interface IERC1155V0 is IERC1155Upgradeable {}

interface IERC1155V1 is IERC1155Upgradeable {
    function burn(
        address account,
        uint256 id,
        uint256 value
    ) external;

    function burnBatch(
        address account,
        uint256[] memory ids,
        uint256[] memory values
    ) external;
}

interface IERC1155V2 is IERC1155V1 {
    function name() external returns (string memory);

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

interface IERC1155V3 is IERC1155V1 {
    function name() external view returns (string memory);

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

interface IERC1155SupplyV0 is IERC1155V0 {
    /**
     * @dev Total amount of tokens in with a given id.
     */
    function totalSupply(uint256 id) external view returns (uint256);

    /**
     * @dev Indicates whether any token exist with a given id, or not.
     */
    function exists(uint256 id) external view returns (bool);
}

interface IERC1155SupplyV1 is IERC1155SupplyV0 {
    /**
     * @dev Amount of unique tokens minted.
     */
    function getLargestTokenId() external view returns (uint256);
}

interface IERC1155SupplyV2 is IERC1155V1 {
    /**
     * @dev Total amount of tokens in with a given id.
     */
    function totalSupply(uint256 id) external view returns (uint256);

    /**
     * @dev Indicates whether any token exist with a given id, or not.
     */
    function exists(uint256 id) external view returns (bool);

    /**
     * @dev Amount of unique tokens minted.
     */
    function getLargestTokenId() external view returns (uint256);
}

// File: contracts/aspen/api/standard/IERC2981.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

interface IERC2981V0 {
    /**
     * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of
     * exchange. The royalty amount is denominated and should be payed in that same unit of exchange.
     */
    function royaltyInfo(uint256 tokenId, uint256 salePrice)
        external
        view
        returns (address receiver, uint256 royaltyAmount);
}

// File: contracts/aspen/api/standard/IERC4906.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

// Note: So that it can be included in Delegated logic contract
interface IRestrictedERC4906V0 {
    /// @dev This event emits when the metadata of a token is changed.
    /// So that the third-party platforms such as NFT market could
    /// timely update the images and related attributes of the NFT.
    event MetadataUpdate(uint256 _tokenId);

    /// @dev This event emits when the metadata of a range of tokens is changed.
    /// So that the third-party platforms such as NFT market could
    /// timely update the images and related attributes of the NFTs.
    event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
}

// File: contracts/aspen/api/standard/IERC721.sol



// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

import "@openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";

interface IERC721V0 is IERC721Upgradeable {}

interface IERC721V1 is IERC721Upgradeable {
    function burn(uint256 tokenId) external;
}

interface IERC721V2 is IERC721V1 {
    function name() external returns (string memory);

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

interface IERC721V3 is IERC721V1 {
    function name() external view returns (string memory);

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

// File: contracts/aspen/generated/impl/BaseAspenPaymentSplitterV1.sol



// SPDX-License-Identifier: Apache-2.0

// Generated by impl.ts. Will be overwritten.
// Filename: './BaseAspenPaymentSplitterV1.sol'

pragma solidity ^0.8.4;

import "../../api/impl/IAspenPaymentSplitter.sol";
import "../../api/IAspenFeatures.sol";
import "../../api/IAspenVersioned.sol";
import "../../api/IMulticallable.sol";
import "../../api/splitpayment/ISplitPayment.sol";

/// Inherit from this base to implement introspection
abstract contract BaseAspenPaymentSplitterV1 is IAspenFeaturesV0, IAspenVersionedV2, IMulticallableV0, IAspenSplitPaymentV1 {
    function supportedFeatures() override public pure returns (string[] memory features) {
        features = new string[](4);
        features[0] = "IAspenFeatures.sol:IAspenFeaturesV0";
        features[1] = "IAspenVersioned.sol:IAspenVersionedV2";
        features[2] = "IMulticallable.sol:IMulticallableV0";
        features[3] = "splitpayment/ISplitPayment.sol:IAspenSplitPaymentV1";
    }

    /// This needs to be public to be callable from initialize via delegatecall
    function minorVersion() virtual override public pure returns (uint256 minor, uint256 patch);

    function implementationVersion() override public pure returns (uint256 major, uint256 minor, uint256 patch) {
        (minor, patch) = minorVersion();
        major = 1;
    }

    function implementationInterfaceId() virtual override public pure returns (string memory interfaceId) {
        interfaceId = "impl/IAspenPaymentSplitter.sol:IAspenPaymentSplitterV1";
    }

    function supportsInterface(bytes4 interfaceID) virtual override public view returns (bool) {
        return (interfaceID != 0x0) && ((interfaceID != 0xffffffff) && ((interfaceID == 0x01ffc9a7) || ((interfaceID == type(IAspenFeaturesV0).interfaceId) || ((interfaceID == type(IAspenVersionedV2).interfaceId) || ((interfaceID == type(IMulticallableV0).interfaceId) || ((interfaceID == type(IAspenSplitPaymentV1).interfaceId) || (interfaceID == type(IAspenPaymentSplitterV1).interfaceId)))))));
    }

    function isIAspenFeaturesV0() override public pure returns (bool) {
        return true;
    }
}

// File: contracts/aspen/paymentSplit/AspenPaymentSplitter.sol



// SPDX-License-Identifier: Apache-2.0

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                                           //
//                      _'                    AAA                                                                                            //
//                    !jz_                   A:::A                                                                                           //
//                 ;Lzzzz-                  A:::::A                                                                                          //
//              '1zzzzxzz'                 A:::::::A                                                                                         //
//            !xzzzzzzi~                  A:::::::::A             ssssssssss   ppppp   ppppppppp       eeeeeeeeeeee    nnnn  nnnnnnnn        //
//         ;izzzzzzj^`                   A:::::A:::::A          ss::::::::::s  p::::ppp:::::::::p    ee::::::::::::ee  n:::nn::::::::nn      //
//              `;^.`````               A:::::A A:::::A       ss:::::::::::::s p:::::::::::::::::p  e::::::eeeee:::::een::::::::::::::nn     //
//              -;;;;;;;-              A:::::A   A:::::A      s::::::ssss:::::spp::::::ppppp::::::pe::::::e     e:::::enn:::::::::::::::n    //
//           .;;;;;;;_                A:::::A     A:::::A      s:::::s  ssssss  p:::::p     p:::::pe:::::::eeeee::::::e  n:::::nnnn:::::n    //
//         ;;;;;;;;`                 A:::::AAAAAAAAA:::::A       s::::::s       p:::::p     p:::::pe:::::::::::::::::e   n::::n    n::::n    //
//      _;;;;;;;'                   A:::::::::::::::::::::A         s::::::s    p:::::p     p:::::pe::::::eeeeeeeeeee    n::::n    n::::n    //
//            ;{jjjjjjjjj          A:::::AAAAAAAAAAAAA:::::A  ssssss   s:::::s  p:::::p    p::::::pe:::::::e             n::::n    n::::n    //
//         `+IIIVVVVVVVVI`        A:::::A             A:::::A s:::::ssss::::::s p:::::ppppp:::::::pe::::::::e            n::::n    n::::n    //
//       ^sIVVVVVVVVVVVVI`       A:::::A               A:::::As::::::::::::::s  p::::::::::::::::p  e::::::::eeeeeeee    n::::n    n::::n    //
//    ~xIIIVVVVVVVVVVVVVI`      A:::::A                 A:::::As:::::::::::ss   p::::::::::::::pp    ee:::::::::::::e    n::::n    n::::n    //
//  -~~~;;;;;;;;;;;;;;;;;      AAAAAAA                   AAAAAAAsssssssssss     p::::::pppppppp        eeeeeeeeeeeeee    nnnnnn    nnnnnn    //
//                                                                              p:::::p                                                      //
//                                                                              p:::::p                                                      //
//                                                                             p:::::::p                                                     //
//                                                                             p:::::::p                                                     //
//                                                                             p:::::::p                                                     //
//                                                                             ppppppppp                                                     //
//                                                                                                                                           //
//  Website: https://aspenft.io/                                                                                                             //
//  Twitter: https://twitter.com/aspenft                                                                                                     //
//                                                                                                                                           //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

pragma solidity ^0.8;

//  ==========  External imports    ==========
import "@openzeppelin/contracts-upgradeable/finance/PaymentSplitterUpgradeable.sol";
import "@openzeppelin/contracts/utils/Address.sol";

import "../generated/impl/BaseAspenPaymentSplitterV1.sol";
import "../api/errors/ISplitPaymentErrors.sol";

contract AspenPaymentSplitter is PaymentSplitterUpgradeable, BaseAspenPaymentSplitterV1 {
    mapping(address => bool) private payeeExists;

    function initialize(address[] memory _payees, uint256[] memory _shares) external initializer {
        if (_payees.length != _shares.length)
            revert ISplitPaymentErrorsV0.PayeeSharesArrayMismatch(_payees.length, _shares.length);
        uint256 totalShares = 0;
        for (uint256 i = 0; i < _shares.length; i++) {
            totalShares = totalShares + _shares[i];

            if (payeeExists[_payees[i]] == true) revert ISplitPaymentErrorsV0.PayeeAlreadyExists(_payees[i]);
            payeeExists[_payees[i]] = true;
        }

        if (totalShares != 10000) revert ISplitPaymentErrorsV0.InvalidTotalShares(totalShares);

        __PaymentSplitter_init(_payees, _shares);
    }

    /// ==================================
    /// ========== Relase logic ==========
    /// ==================================
    /// @dev Triggers a transfer to `account` of the amount of Ether they are owed, according to their percentage of the
    ///     total shares and their previous withdrawals.
    /// @param account - The address of the payee to release funds to.
    function releasePayment(address payable account) external override {
        release(account);
    }

    /// @dev Triggers a transfer to `account` of the amount of `token` tokens they are owed, according to their
    ///     percentage of the total shares and their previous withdrawals. `token` must be the address of an IERC20
    ///     contract.
    /// @param token - the address of an IERC20 contract.
    /// @param account - The address of the payee to release funds to.
    function releasePayment(IERC20Upgradeable token, address account) external override {
        release(token, account);
    }

    /// ======================================
    /// ========== Getter functions ==========
    /// ======================================
    /// @dev Getter for the total amount of Ether already released.
    function getTotalReleased() external view override returns (uint256) {
        return totalReleased();
    }

    /// @dev Getter for the total amount of `token` already released.
    /// @param token - the address of an IERC20 contract.
    function getTotalReleased(IERC20Upgradeable token) external view override returns (uint256) {
        return totalReleased(token);
    }

    /// @dev Getter for the amount of Ether already released to a payee.
    /// @param account - The address of the payee to check the funds that can be released to.
    function getReleased(address account) external view override returns (uint256) {
        return released(account);
    }

    /// @dev Getter for the total amount of `token` already released.
    /// @param token - the address of an IERC20 contract.
    /// @param account - The address of the payee to check the funds that can be released to.
    function getReleased(IERC20Upgradeable token, address account) external view override returns (uint256) {
        return released(token, account);
    }

    /// @dev Getter for the total amount of Ether that can be released for an account.
    /// @param account - The address of the payee to check the funds that can be released to.
    function getPendingPayment(address account) external view override returns (uint256) {
        if (shares(account) == 0) return 0;
        uint256 totalReceived = address(this).balance + totalReleased();

        return _getPendingPayment(account, totalReceived, released(account));
    }

    /// @dev Getter for the total amount of `token` that can be released for an account.
    /// @param token - the address of an IERC20 contract.
    /// @param account - The address of the payee to check the funds that can be released to.
    function getPendingPayment(IERC20Upgradeable token, address account) external view override returns (uint256) {
        if (shares(account) == 0) return 0;
        uint256 totalReceived = token.balanceOf(address(this)) + totalReleased(token);

        return _getPendingPayment(account, totalReceived, released(token, account));
    }

    /// @dev internal logic for computing the pending payment of an `account` given the token historical balances and
    ///     already released amounts.
    ///     private logic taken from _pendingPayment() function from openzeppelin/contracts-upgradeable/finance/PaymentSplitterUpgradeable.sol
    function _getPendingPayment(
        address account,
        uint256 totalReceived,
        uint256 alreadyReleased
    ) internal view returns (uint256) {
        return (totalReceived * shares(account)) / totalShares() - alreadyReleased;
    }

    /// ======================================
    /// =========== Miscellaneous ============
    /// ======================================
    /// @dev Provides a function to batch together multiple calls in a single external call.
    function multicall(bytes[] calldata data) external virtual override returns (bytes[] memory results) {
        results = new bytes[](data.length);
        for (uint256 i = 0; i < data.length; i++) {
            results[i] = Address.functionDelegateCall(address(this), data[i]);
        }
        return results;
    }

    /// @dev Concrete implementation semantic version -
    ///         provided for completeness but not designed to be the point of dispatch
    function minorVersion() public pure override returns (uint256 minor, uint256 patch) {
        minor = 0;
        patch = 0;
    }
}

// File: contracts/aspen/paymentSplit/AspenPaymentSplitterFactory.sol



// SPDX-License-Identifier: Apache 2.0

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                                           //
//                      _'                    AAA                                                                                            //
//                    !jz_                   A:::A                                                                                           //
//                 ;Lzzzz-                  A:::::A                                                                                          //
//              '1zzzzxzz'                 A:::::::A                                                                                         //
//            !xzzzzzzi~                  A:::::::::A             ssssssssss   ppppp   ppppppppp       eeeeeeeeeeee    nnnn  nnnnnnnn        //
//         ;izzzzzzj^`                   A:::::A:::::A          ss::::::::::s  p::::ppp:::::::::p    ee::::::::::::ee  n:::nn::::::::nn      //
//              `;^.`````               A:::::A A:::::A       ss:::::::::::::s p:::::::::::::::::p  e::::::eeeee:::::een::::::::::::::nn     //
//              -;;;;;;;-              A:::::A   A:::::A      s::::::ssss:::::spp::::::ppppp::::::pe::::::e     e:::::enn:::::::::::::::n    //
//           .;;;;;;;_                A:::::A     A:::::A      s:::::s  ssssss  p:::::p     p:::::pe:::::::eeeee::::::e  n:::::nnnn:::::n    //
//         ;;;;;;;;`                 A:::::AAAAAAAAA:::::A       s::::::s       p:::::p     p:::::pe:::::::::::::::::e   n::::n    n::::n    //
//      _;;;;;;;'                   A:::::::::::::::::::::A         s::::::s    p:::::p     p:::::pe::::::eeeeeeeeeee    n::::n    n::::n    //
//            ;{jjjjjjjjj          A:::::AAAAAAAAAAAAA:::::A  ssssss   s:::::s  p:::::p    p::::::pe:::::::e             n::::n    n::::n    //
//         `+IIIVVVVVVVVI`        A:::::A             A:::::A s:::::ssss::::::s p:::::ppppp:::::::pe::::::::e            n::::n    n::::n    //
//       ^sIVVVVVVVVVVVVI`       A:::::A               A:::::As::::::::::::::s  p::::::::::::::::p  e::::::::eeeeeeee    n::::n    n::::n    //
//    ~xIIIVVVVVVVVVVVVVI`      A:::::A                 A:::::As:::::::::::ss   p::::::::::::::pp    ee:::::::::::::e    n::::n    n::::n    //
//  -~~~;;;;;;;;;;;;;;;;;      AAAAAAA                   AAAAAAAsssssssssss     p::::::pppppppp        eeeeeeeeeeeeee    nnnnnn    nnnnnn    //
//                                                                              p:::::p                                                      //
//                                                                              p:::::p                                                      //
//                                                                             p:::::::p                                                     //
//                                                                             p:::::::p                                                     //
//                                                                             p:::::::p                                                     //
//                                                                             ppppppppp                                                     //
//                                                                                                                                           //
//  Website: https://aspenft.io/                                                                                                             //
//  Twitter: https://twitter.com/aspenft                                                                                                     //
//                                                                                                                                           //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

pragma solidity ^0.8;

import "@openzeppelin/contracts/proxy/Clones.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./AspenPaymentSplitter.sol";
import "../api/deploy/IAspenDeployer.sol";

contract AspenPaymentSplitterFactory is Ownable, IAspenPaymentSplitterEventsV0, ICedarImplementationVersionedV0 {
    AspenPaymentSplitter public implementation;

    struct EventParams {
        address contractAddress;
        uint256 majorVersion;
        uint256 minorVersion;
        uint256 patchVersion;
        address[] payees;
        uint256[] shares;
    }

    constructor() {
        // Deploy the implementation contract and set implementationAddress
        implementation = new AspenPaymentSplitter();
        address[] memory recipients = new address[](1);
        recipients[0] = msg.sender;
        uint256[] memory shares = new uint256[](1);
        shares[0] = 10000;

        implementation.initialize(recipients, shares);

        (uint256 major, uint256 minor, uint256 patch) = implementation.implementationVersion();
        emit AspenImplementationDeployed(address(implementation), major, minor, patch, "AspenPaymentSplitter");
    }

    function emitEvent(EventParams memory params) private {
        emit AspenPaymentSplitterDeployment(
            params.contractAddress,
            params.majorVersion,
            params.minorVersion,
            params.patchVersion,
            params.payees,
            params.shares
        );
    }

    function deploy(address[] memory payees, uint256[] memory shares_)
        external
        onlyOwner
        returns (AspenPaymentSplitter)
    {
        // newClone = PaymentSplitter(Clones.clone(address((implementation)));
        AspenPaymentSplitter newClone = new AspenPaymentSplitter();
        newClone.initialize(payees, shares_);

        (uint256 major, uint256 minor, uint256 patch) = newClone.implementationVersion();

        EventParams memory params;
        params.contractAddress = address(newClone);
        params.majorVersion = major;
        params.minorVersion = minor;
        params.patchVersion = patch;
        params.payees = payees;
        params.shares = shares_;

        emitEvent(params);
        return newClone;
    }

    function implementationVersion()
        external
        view
        override
        returns (
            uint256 major,
            uint256 minor,
            uint256 patch
        )
    {
        return implementation.implementationVersion();
    }
}