瀏覽代碼

Add ERC-7786 interface (#5737)

Hadrien Croubois 3 月之前
父節點
當前提交
fd9bbaec30
共有 3 個文件被更改,包括 72 次插入0 次删除
  1. 5 0
      .changeset/wild-baths-buy.md
  2. 3 0
      contracts/interfaces/README.adoc
  3. 64 0
      contracts/interfaces/draft-IERC7786.sol

+ 5 - 0
.changeset/wild-baths-buy.md

@@ -0,0 +1,5 @@
+---
+'openzeppelin-solidity': minor
+---
+
+`IERC7786`: Add the (draft) interface for ERC-7786 "Cross-Chain Messaging Gateway"

+ 3 - 0
contracts/interfaces/README.adoc

@@ -45,6 +45,7 @@ are useful to interact with third party contracts that implement them.
 - {IERC6909Metadata}
 - {IERC6909TokenSupply}
 - {IERC7674}
+- {IERC7786}
 - {IERC7802}
 
 == Detailed ABI
@@ -99,4 +100,6 @@ are useful to interact with third party contracts that implement them.
 
 {{IERC7674}}
 
+{{IERC7786}}
+
 {{IERC7802}}

+ 64 - 0
contracts/interfaces/draft-IERC7786.sol

@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: MIT
+
+pragma solidity >=0.8.4;
+
+/**
+ * @dev Interface for ERC-7786 source gateways.
+ *
+ * See ERC-7786 for more details
+ */
+interface IERC7786GatewaySource {
+    /**
+     * @dev Event emitted when a message is created. If `outboxId` is zero, no further processing is necessary. If
+     * `outboxId` is not zero, then further (gateway specific, and non-standardized) action is required.
+     */
+    event MessageSent(
+        bytes32 indexed sendId,
+        bytes sender, // Binary Interoperable Address
+        bytes receiver, // Binary Interoperable Address
+        bytes payload,
+        uint256 value,
+        bytes[] attributes
+    );
+
+    /// @dev This error is thrown when a message creation fails because of an unsupported attribute being specified.
+    error UnsupportedAttribute(bytes4 selector);
+
+    /// @dev Getter to check whether an attribute is supported or not.
+    function supportsAttribute(bytes4 selector) external view returns (bool);
+
+    /**
+     * @dev Endpoint for creating a new message. If the message requires further (gateway specific) processing before
+     * it can be sent to the destination chain, then a non-zero `outboxId` must be returned. Otherwise, the
+     * message MUST be sent and this function must return 0.
+     *
+     * * MUST emit a {MessageSent} event.
+     *
+     * If any of the `attributes` is not supported, this function SHOULD revert with an {UnsupportedAttribute} error.
+     * Other errors SHOULD revert with errors not specified in ERC-7786.
+     */
+    function sendMessage(
+        bytes calldata recipient, // Binary Interoperable Address
+        bytes calldata payload,
+        bytes[] calldata attributes
+    ) external payable returns (bytes32 sendId);
+}
+
+/**
+ * @dev Interface for the ERC-7786 client contract (receiver).
+ *
+ * See ERC-7786 for more details
+ */
+interface IERC7786Receiver {
+    /**
+     * @dev Endpoint for receiving cross-chain message.
+     *
+     * This function may be called directly by the gateway.
+     */
+    function executeMessage(
+        bytes32 receiveId,
+        bytes calldata sender, // Binary Interoperable Address
+        bytes calldata payload,
+        bytes[] calldata attributes
+    ) external payable returns (bytes4);
+}