creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC1155/IERC1155.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC1155/IERC1155.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC1155 compliant contract, as defined in the\n * https://eips.ethereum.org/EIPS/eip-1155[EIP].\n *\n * _Available since v3.1._\n */\ninterface IERC1155 is IERC165 {\n    /**\n     * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.\n     */\n    event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);\n\n    /**\n     * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all\n     * transfers.\n     */\n    event TransferBatch(\n        address indexed operator,\n        address indexed from,\n        address indexed to,\n        uint256[] ids,\n        uint256[] values\n    );\n\n    /**\n     * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to\n     * `approved`.\n     */\n    event ApprovalForAll(address indexed account, address indexed operator, bool approved);\n\n    /**\n     * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.\n     *\n     * If an {URI} event was emitted for `id`, the standard\n     * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value\n     * returned by {IERC1155MetadataURI-uri}.\n     */\n    event URI(string value, uint256 indexed id);\n\n    /**\n     * @dev Returns the amount of tokens of token type `id` owned by `account`.\n     *\n     * Requirements:\n     *\n     * - `account` cannot be the zero address.\n     */\n    function balanceOf(address account, uint256 id) external view returns (uint256);\n\n    /**\n     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.\n     *\n     * Requirements:\n     *\n     * - `accounts` and `ids` must have the same length.\n     */\n    function balanceOfBatch(\n        address[] calldata accounts,\n        uint256[] calldata ids\n    ) external view returns (uint256[] memory);\n\n    /**\n     * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,\n     *\n     * Emits an {ApprovalForAll} event.\n     *\n     * Requirements:\n     *\n     * - `operator` cannot be the caller.\n     */\n    function setApprovalForAll(address operator, bool approved) external;\n\n    /**\n     * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.\n     *\n     * See {setApprovalForAll}.\n     */\n    function isApprovedForAll(address account, address operator) external view returns (bool);\n\n    /**\n     * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.\n     *\n     * Emits a {TransferSingle} event.\n     *\n     * Requirements:\n     *\n     * - `to` cannot be the zero address.\n     * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.\n     * - `from` must have a balance of tokens of type `id` of at least `amount`.\n     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the\n     * acceptance magic value.\n     */\n    function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) external;\n\n    /**\n     * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.\n     *\n     * Emits a {TransferBatch} event.\n     *\n     * Requirements:\n     *\n     * - `ids` and `amounts` must have the same length.\n     * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the\n     * acceptance magic value.\n     */\n    function safeBatchTransferFrom(\n        address from,\n        address to,\n        uint256[] calldata ids,\n        uint256[] calldata amounts,\n        bytes calldata data\n    ) external;\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/introspection/IERC165.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
      },
      "contracts/comics/ComicPurchase.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { IERC1155 } from \"@openzeppelin/contracts/token/ERC1155/IERC1155.sol\";\n\nimport { IComicPurchase } from \"./interfaces/IComicPurchase.sol\";\n\nimport { EchelonGateways } from \"../prime-token/EchelonGateways.sol\";\n\ncontract ComicPurchase is IComicPurchase, Ownable, EchelonGateways {\n    IERC20 public prime = IERC20(0xb23d80f5FefcDDaa212212F028021B41DEd428CF);\n\n    /// @notice Mapping of comic token id to comic supply\n    mapping(uint256 => uint256) public parallelComicsSupply;\n    /// @notice Mapping of comic token id to comics purchased\n    mapping(uint256 => uint256) public parallelComicsPurchased;\n\n    /// @notice Allowlist that bypasses the disabled variable\n    mapping(address => bool) public allowlist;\n    /// @notice Disabled state\n    bool public isDisabled = true;\n\n    /// @notice comic price\n    uint256 public comicPrice = 3 ether;\n\n    /// @notice Address to get the comics from\n    address public pullFromAddress = 0x716E6b6873038a8243F5EB44e2b09D85DEFf45Ec;\n    /// @notice Parallel Alpha contract\n    IERC1155 public parallelComic =\n        IERC1155(0x6A82872743217A0988E4d72975D74432CfDeF9D7);\n\n    /**\n     * @notice Function invoked by the prime token contract to handle totalCardCount increase and emit payment event\n     * @param _from The address of the original msg.sender\n     * @param _id An id passed by the caller to represent any arbitrary and potentially off-chain event id\n     * @param _primeValue The amount of prime that was sent from the prime token contract\n     * @param _data Catch-all param to allow the caller to pass additional data to the handler, includes the amount of cards they want to purchase\n     */\n    function handleInvokeEchelon(\n        address _from,\n        address,\n        address,\n        uint256 _id,\n        uint256,\n        uint256 _primeValue,\n        bytes memory _data\n    ) public payable {\n        if (msg.sender != address(prime)) {\n            revert InvalidCaller();\n        }\n\n        if (isDisabled && !allowlist[_from]) revert Disabled();\n\n        (uint256[] memory comicIds, uint256[] memory comicAmounts) = abi.decode(\n            _data,\n            (uint256[], uint256[])\n        );\n\n        uint256 totalPrice = 0;\n\n        for (uint256 i = 0; i < comicIds.length; i++) {\n            if (\n                parallelComicsPurchased[comicIds[i]] >=\n                parallelComicsSupply[comicIds[i]]\n            ) revert SoldOut(comicIds[i]);\n\n            parallelComicsPurchased[comicIds[i]] += comicAmounts[i];\n\n            totalPrice += comicPrice * comicAmounts[i];\n        }\n\n        if (totalPrice != _primeValue) revert InvalidPayment(_primeValue);\n\n        parallelComic.safeBatchTransferFrom(\n            pullFromAddress,\n            _from,\n            comicIds,\n            comicAmounts,\n            \"\"\n        );\n\n        emit ComicsPurchased(_from, comicIds, comicAmounts, _id);\n    }\n\n    /** @notice Set the prime token address\n     *  @param _prime prime token address\n     */\n    function setPrimeAddress(IERC20 _prime) external onlyOwner {\n        prime = _prime;\n        emit SetPrimeAddress(address(_prime));\n    }\n\n    /**\n     * @notice Sets the disabled state\n     * @dev Only callable by the owner\n     * @param _isDisabled The new disabled state\n     */\n    function setDisabled(bool _isDisabled) external onlyOwner {\n        isDisabled = _isDisabled;\n\n        emit IsDisabledSet(_isDisabled);\n    }\n\n    /**\n     * @notice Sets the parallel comic contract\n     * @dev Only callable by the owner\n     * @param _parallelComic The new parallel comic contract\n     */\n    function setParallelComic(IERC1155 _parallelComic) external onlyOwner {\n        parallelComic = IERC1155(_parallelComic);\n\n        emit ParallelComicSet(address(_parallelComic));\n    }\n\n    /**\n     * @notice Sets the pull from address\n     * @dev Only callable by the owner\n     * @param _pullFromAddress The new pull from address\n     */\n    function setPullFromAddress(address _pullFromAddress) external onlyOwner {\n        pullFromAddress = _pullFromAddress;\n\n        emit PullFromAddressSet(_pullFromAddress);\n    }\n\n    /**\n     * @notice Sets the comic price\n     * @dev Only callable by the owner\n     * @param _comicPrice The new comic price\n     */\n    function setComicPrice(uint256 _comicPrice) external onlyOwner {\n        comicPrice = _comicPrice;\n\n        emit ComicPriceSet(_comicPrice);\n    }\n\n    /**\n     * @notice Sets the comics\n     * @dev Only callable by the owner\n     * @param _comicIds The comic ids\n     * @param _comicSupplies The comic supplies\n     */\n    function setComics(\n        uint256[] calldata _comicIds,\n        uint256[] calldata _comicSupplies\n    ) external onlyOwner {\n        if (_comicIds.length != _comicSupplies.length) revert InvalidLength();\n\n        for (uint256 i = 0; i < _comicIds.length; i++) {\n            parallelComicsSupply[_comicIds[i]] = _comicSupplies[i];\n            parallelComicsPurchased[_comicIds[i]] = 0;\n        }\n\n        emit ComicsSet(_comicIds, _comicSupplies);\n    }\n\n    /**\n     * @notice Sets the allowlist\n     * @dev Only callable by the owner\n     * @param _allowlist The new allowlist\n     * @param _val The new value\n     */\n    function setAllowlist(\n        address[] calldata _allowlist,\n        bool _val\n    ) external onlyOwner {\n        for (uint256 i = 0; i < _allowlist.length; i++) {\n            allowlist[_allowlist[i]] = _val;\n        }\n\n        emit AllowlistSet(_allowlist, _val);\n    }\n}\n"
      },
      "contracts/comics/interfaces/IComicPurchase.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\ninterface IComicPurchase {\n    event ComicsPurchased(\n        address indexed buyer,\n        uint256[] comicIds,\n        uint256[] comicAmounts,\n        uint256 id\n    );\n    event SetPrimeAddress(address primeAddress);\n\n    event IsDisabledSet(bool isDisabled);\n\n    event ParallelComicSet(address parallelComic);\n\n    event PullFromAddressSet(address pullFromAddress);\n\n    event ComicPriceSet(uint256 comicPrice);\n\n    event ComicsSet(uint256[] comicIds, uint256[] comicAmounts);\n\n    event AllowlistSet(address[] allowlist, bool isAllowlisted);\n\n    error InvalidCaller();\n\n    error Disabled();\n\n    error InvalidPayment(uint256 value);\n\n    error SoldOut(uint256 comicId);\n\n    error InvalidLength();\n}\n"
      },
      "contracts/prime-token/EchelonGateways.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\ninterface EchelonGateways {\n    // Invoked by the Prime Token contract to handle arbitrary functionalities by the given gateway\n    function handleInvokeEchelon(\n        address from,\n        address ethDestination,\n        address primeDestination,\n        uint256 id,\n        uint256 ethValue,\n        uint256 primeValue,\n        bytes calldata data\n    ) external payable;\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "metadata": {
        "useLiteralContent": true
      },
      "libraries": {}
    }
  }}