creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)\n\npragma solidity ^0.8.20;\n\nimport {Context} from \"../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 * The initial owner is set to the address provided by the deployer. This can\n * 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    /**\n     * @dev The caller account is not authorized to perform an operation.\n     */\n    error OwnableUnauthorizedAccount(address account);\n\n    /**\n     * @dev The owner is not a valid owner account. (eg. `address(0)`)\n     */\n    error OwnableInvalidOwner(address owner);\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.\n     */\n    constructor(address initialOwner) {\n        if (initialOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\n        _transferOwnership(initialOwner);\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        if (owner() != _msgSender()) {\n            revert OwnableUnauthorizedAccount(_msgSender());\n        }\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        if (newOwner == address(0)) {\n            revert OwnableInvalidOwner(address(0));\n        }\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/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)\n\npragma solidity ^0.8.20;\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"
      },
      "@openzeppelin/contracts/utils/ReentrancyGuard.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n    // Booleans are more expensive than uint256 or any type that takes up a full\n    // word because each write operation emits an extra SLOAD to first read the\n    // slot's contents, replace the bits taken up by the boolean, and then write\n    // back. This is the compiler's defense against contract upgrades and\n    // pointer aliasing, and it cannot be disabled.\n\n    // The values being non-zero value makes deployment a bit more expensive,\n    // but in exchange the refund on every call to nonReentrant will be lower in\n    // amount. Since refunds are capped to a percentage of the total\n    // transaction's gas, it is best to keep them low in cases like this one, to\n    // increase the likelihood of the full refund coming into effect.\n    uint256 private constant NOT_ENTERED = 1;\n    uint256 private constant ENTERED = 2;\n\n    uint256 private _status;\n\n    /**\n     * @dev Unauthorized reentrant call.\n     */\n    error ReentrancyGuardReentrantCall();\n\n    constructor() {\n        _status = NOT_ENTERED;\n    }\n\n    /**\n     * @dev Prevents a contract from calling itself, directly or indirectly.\n     * Calling a `nonReentrant` function from another `nonReentrant`\n     * function is not supported. It is possible to prevent this from happening\n     * by making the `nonReentrant` function external, and making it call a\n     * `private` function that does the actual work.\n     */\n    modifier nonReentrant() {\n        _nonReentrantBefore();\n        _;\n        _nonReentrantAfter();\n    }\n\n    function _nonReentrantBefore() private {\n        // On the first call to nonReentrant, _status will be NOT_ENTERED\n        if (_status == ENTERED) {\n            revert ReentrancyGuardReentrantCall();\n        }\n\n        // Any calls to nonReentrant after this point will fail\n        _status = ENTERED;\n    }\n\n    function _nonReentrantAfter() private {\n        // By storing the original value once again, a refund is triggered (see\n        // https://eips.ethereum.org/EIPS/eip-2200)\n        _status = NOT_ENTERED;\n    }\n\n    /**\n     * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n     * `nonReentrant` function in the call stack.\n     */\n    function _reentrancyGuardEntered() internal view returns (bool) {\n        return _status == ENTERED;\n    }\n}\n"
      },
      "contracts/EndpointV1.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.20;\n\nimport {Ownable} from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport {ReentrancyGuard} from \"@openzeppelin/contracts/utils/ReentrancyGuard.sol\";\n\ncontract EndpointV1 is Ownable, ReentrancyGuard {\n    uint public index;\n\n    uint32 private _lastSrcChain;\n    address private _lastSrcCaller;\n\n    address public relayerFeesRecipient;\n\n    mapping(address => bool) public relayers;\n    mapping(uint => MsgReceiveParameter) public failedMsgs;\n    mapping(uint => bool) public processed; // keep track of processed messages\n\n    struct MsgSendParameter {\n        uint32 dstChain;\n        address dstAddress;\n        bytes payload;\n    }\n\n    struct MsgReceiveParameter {\n        uint srcMsgId;\n        uint32 srcChain;\n        address srcCaller;\n        address dstAddress;\n        bytes payload;\n    }\n\n    event MessageSent(\n        uint indexed _msgId,\n        uint32 _dstChain,\n        address indexed _srcCaller,\n        address indexed _dstAddress,\n        uint _fees,\n        bytes _payload\n    );\n\n    event MessageReceived(\n        uint indexed _msgId,\n        uint32 _srcChain,\n        address indexed _srcCaller,\n        address indexed _dstAddress,\n        bytes _payload\n    );\n    event MessageReceivedFailed(uint indexed _msgId);\n\n    constructor(address _relayer) Ownable(msg.sender) {\n        relayerFeesRecipient = msg.sender;\n        relayers[_relayer] = true;\n    }\n\n    modifier onlyRelayers() {\n        require(relayers[msg.sender], \"Not relayer.\");\n        _;\n    }\n\n    function msgReceive(\n        MsgReceiveParameter calldata _params\n    ) external nonReentrant onlyRelayers {\n        (_lastSrcChain, _lastSrcCaller) = (_params.srcChain, _params.srcCaller);\n\n        (bool success, ) = _params.dstAddress.call(_params.payload);\n\n        if (success) {\n            emit MessageReceived(\n                _params.srcMsgId,\n                _params.srcChain,\n                _params.srcCaller,\n                _params.dstAddress,\n                _params.payload\n            );\n            processed[_params.srcMsgId] = true;\n\n            return;\n        }\n\n        failedMsgs[_params.srcMsgId] = _params;\n\n        emit MessageReceivedFailed(_params.srcMsgId);\n    }\n\n    function msgReceiveRetry(uint _msgId) external nonReentrant {\n        MsgReceiveParameter memory params = failedMsgs[_msgId];\n        (bool success, ) = params.dstAddress.call(params.payload);\n\n        if (success) {\n            emit MessageReceived(\n                _msgId,\n                params.srcChain,\n                params.srcCaller,\n                params.dstAddress,\n                params.payload\n            );\n            processed[params.srcMsgId] = true;\n\n            delete failedMsgs[_msgId];\n        }\n    }\n\n    function msgSend(\n        MsgSendParameter calldata _params\n    ) external payable nonReentrant {\n        _forwardFees(relayerFeesRecipient);\n\n        emit MessageSent(\n            index,\n            _params.dstChain,\n            msg.sender,\n            _params.dstAddress,\n            msg.value,\n            _params.payload\n        );\n\n        index++;\n    }\n\n    function getMsgDeliveryParams() external view returns (uint32, address) {\n        return (_lastSrcChain, _lastSrcCaller);\n    }\n\n    function updateFeesRecipient(address _recipient) external onlyOwner {\n        require(_recipient != address(0), \"Invalid recipient.\");\n        relayerFeesRecipient = _recipient;\n    }\n\n    function updateRelayers(\n        address _address,\n        bool _isRelayer\n    ) external onlyOwner {\n        relayers[_address] = _isRelayer;\n    }\n\n    function collectFees() external {\n        require(\n            msg.sender == relayerFeesRecipient || msg.sender == owner(),\n            \"Only authorized addresses.\"\n        );\n        _forwardFees(msg.sender);\n    }\n\n    function _forwardFees(address _recipient) internal {\n        (bool success, ) = payable(_recipient).call{\n            value: address(this).balance\n        }(\"\");\n        require(success);\n    }\n\n    receive() external payable {}\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "evmVersion": "paris",
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}