creation_sourcecode: {{
    "language": "Solidity",
    "settings": {
      "viaIR": false,
      "optimizer": {
        "runs": 999999,
        "enabled": true
      },
      "metadata": {
        "useLiteralContent": false,
        "bytecodeHash": "ipfs"
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "evmVersion": "london",
      "libraries": {},
      "remappings": [
        "subapi/=lib/subapi/",
        "ORMP/=lib/ORMP/",
        "@darwinia-msgport/=lib/darwinia-msgport/",
        "@openzeppelin/contracts@4.9.2/=lib/openzeppelin-contracts/contracts/",
        "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
        "@safe-smart-account/=lib/subapi/lib/safe-smart-account/contracts/",
        "@sphinx-labs/contracts/=lib/sphinx/packages/contracts/contracts/foundry/",
        "forge-std/=lib/forge-std/src/",
        "solmate/=lib/darwinia-msgport/lib/solmate/src/",
        "create3-deploy/=lib/create3-deploy/"
      ]
    },
    "sources": {
      "lib/ORMP/src/Common.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\n/// @dev The block of control information and data for comminicate\n/// between user applications. Messages are the exchange medium\n/// used by channels to send and receive data through cross-chain networks.\n/// A message is sent from a source chain to a destination chain.\n/// @param index The leaf index lives in channel's incremental mekle tree.\n/// @param fromChainId The message source chain id.\n/// @param from User application contract address which send the message.\n/// @param toChainId The message destination chain id.\n/// @param to User application contract address which receive the message.\n/// @param gasLimit Gas limit for destination UA used.\n/// @param encoded The calldata which encoded by ABI Encoding.\nstruct Message {\n    address channel;\n    uint256 index;\n    uint256 fromChainId;\n    address from;\n    uint256 toChainId;\n    address to;\n    uint256 gasLimit;\n    bytes encoded; /*(abi.encodePacked(SELECTOR, PARAMS))*/\n}\n\n/// @dev Hash of the message.\nfunction hash(Message memory message) pure returns (bytes32) {\n    return keccak256(abi.encode(message));\n}\n"
      },
      "lib/ORMP/src/Verifier.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport \"./interfaces/IVerifier.sol\";\n\nabstract contract Verifier is IVerifier {\n    /// @notice Fetch message hash.\n    /// @param chainId The source chain id.\n    /// @param channel The message channel.\n    /// @param msgIndex The Message index.\n    /// @return Message hash in source chain.\n    function hashOf(uint256 chainId, address channel, uint256 msgIndex) public view virtual returns (bytes32);\n\n    /// @inheritdoc IVerifier\n    function verifyMessageProof(Message calldata message, bytes calldata) external view returns (bool) {\n        // check oracle's message hash equal relayer's message hash\n        return hashOf(message.fromChainId, message.channel, message.index) == hash(message);\n    }\n}\n"
      },
      "lib/ORMP/src/eco/Oracle.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport \"../Verifier.sol\";\nimport \"../interfaces/IORMP.sol\";\n\ncontract Oracle is Verifier {\n    event SetFee(uint256 indexed chainId, uint256 fee);\n    event SetApproved(address operator, bool approve);\n    event Withdrawal(address indexed to, uint256 amt);\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    address public immutable PROTOCOL;\n\n    address public owner;\n    // chainId => price\n    mapping(uint256 => uint256) public feeOf;\n    // operator => isApproved\n    mapping(address => bool) public approvedOf;\n\n    modifier onlyOwner() {\n        require(msg.sender == owner, \"!owner\");\n        _;\n    }\n\n    modifier onlyApproved() {\n        require(isApproved(msg.sender), \"!approve\");\n        _;\n    }\n\n    constructor(address dao, address ormp) {\n        PROTOCOL = ormp;\n        owner = dao;\n    }\n\n    receive() external payable {}\n\n    function version() public pure returns (string memory) {\n        return \"2.0.0\";\n    }\n\n    /// @dev Only could be called by owner.\n    /// @param chainId The source chain id.\n    /// @param channel The message channel.\n    /// @param msgIndex The source chain message index.\n    /// @param msgHash The source chain message hash corresponding to the channel.\n    function importMessageHash(uint256 chainId, address channel, uint256 msgIndex, bytes32 msgHash)\n        external\n        onlyOwner\n    {\n        IORMP(PROTOCOL).importHash(chainId, channel, msgIndex, msgHash);\n    }\n\n    function hashOf(uint256 chainId, address channel, uint256 msgIndex) public view override returns (bytes32) {\n        return IORMP(PROTOCOL).hashLookup(address(this), keccak256(abi.encode(chainId, channel, msgIndex)));\n    }\n\n    function changeOwner(address newOwner) external onlyOwner {\n        address oldOwner = owner;\n        owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n\n    function setApproved(address operator, bool approve) external onlyOwner {\n        approvedOf[operator] = approve;\n        emit SetApproved(operator, approve);\n    }\n\n    function isApproved(address operator) public view returns (bool) {\n        return approvedOf[operator];\n    }\n\n    function withdraw(address to, uint256 amount) external onlyApproved {\n        (bool success,) = to.call{value: amount}(\"\");\n        require(success, \"!withdraw\");\n        emit Withdrawal(to, amount);\n    }\n\n    function setFee(uint256 chainId, uint256 fee_) external onlyApproved {\n        feeOf[chainId] = fee_;\n        emit SetFee(chainId, fee_);\n    }\n\n    function fee(uint256 toChainId, address /*ua*/ ) public view returns (uint256) {\n        uint256 f = feeOf[toChainId];\n        require(f != 0, \"!fee\");\n        return f;\n    }\n}\n"
      },
      "lib/ORMP/src/interfaces/IORMP.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport \"../Common.sol\";\n\ninterface IORMP {\n    /// @dev Send a cross-chain message over the endpoint.\n    /// @notice follow https://eips.ethereum.org/EIPS/eip-5750\n    /// @param toChainId The Message destination chain id.\n    /// @param to User application contract address which receive the message.\n    /// @param gasLimit Gas limit for destination user application used.\n    /// @param encoded The calldata which encoded by ABI Encoding.\n    /// @param refund Return extra fee to refund address.\n    /// @return Return the hash of the message as message id.\n    /// @param params General extensibility for relayer to custom functionality.\n    function send(\n        uint256 toChainId,\n        address to,\n        uint256 gasLimit,\n        bytes calldata encoded,\n        address refund,\n        bytes calldata params\n    ) external payable returns (bytes32);\n\n    /// @notice Get a quote in source native gas, for the amount that send() requires to pay for message delivery.\n    /// @param toChainId The Message destination chain id.\n    //  @param ua User application contract address which send the message.\n    /// @param gasLimit Gas limit for destination user application used.\n    /// @param encoded The calldata which encoded by ABI Encoding.\n    /// @param params General extensibility for relayer to custom functionality.\n    function fee(uint256 toChainId, address ua, uint256 gasLimit, bytes calldata encoded, bytes calldata params)\n        external\n        view\n        returns (uint256);\n\n    /// @dev Recv verified message and dispatch to destination user application address.\n    /// @param message Verified receive message info.\n    /// @param proof Message proof of this message.\n    /// @return dispatchResult Result of the message dispatch.\n    function recv(Message calldata message, bytes calldata proof) external payable returns (bool dispatchResult);\n\n    /// @dev Fetch user application config.\n    /// @notice If user application has not configured, then the default config is used.\n    /// @param ua User application contract address.\n    function getAppConfig(address ua) external view returns (address oracle, address relayer);\n\n    /// @notice Set user application config.\n    /// @param oracle Oracle which user application choose.\n    /// @param relayer Relayer which user application choose.\n    function setAppConfig(address oracle, address relayer) external;\n\n    function defaultUC() external view returns (address oracle, address relayer);\n\n    /// @dev Check the msg if it is dispatched.\n    /// @param msgHash Hash of the checked message.\n    /// @return Return the dispatched result of the checked message.\n    function dones(bytes32 msgHash) external view returns (bool);\n\n    /// @dev Import hash by any oracle address.\n    /// @notice Hash is an abstract of the proof system, it can be a block hash or a message root hash,\n    ///  \t\tspecifically provided by oracles.\n    /// @param chainId The source chain id.\n    /// @param channel The message channel.\n    /// @param msgIndex The source chain message index.\n    /// @param hash_ The hash to import.\n    function importHash(uint256 chainId, address channel, uint256 msgIndex, bytes32 hash_) external;\n\n    /// @dev Fetch hash.\n    /// @param oracle The oracle address.\n    /// @param lookupKey The key for loop up hash.\n    /// @return Return the hash imported by the oracle.\n    function hashLookup(address oracle, bytes32 lookupKey) external view returns (bytes32);\n}\n"
      },
      "lib/ORMP/src/interfaces/IVerifier.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport \"../Common.sol\";\n\ninterface IVerifier {\n    /// @notice Verify message proof\n    /// @dev Message proof provided by relayer. Oracle should provide message root of\n    ///      source chain, and verify the merkle proof of the message hash.\n    /// @param message The message info.\n    /// @param proof Proof of the message\n    /// @return Result of the message verify.\n    function verifyMessageProof(Message calldata message, bytes calldata proof) external view returns (bool);\n}\n"
      }
    }
  }}