本文档介绍了OpenZeppelin社区合约中定义的一系列标准化接口,主要用于与实现了这些接口的第三方合约进行交互。其中包括跨链消息传递(IERC7786GatewaySource、IERC7786Receiver)、跨链铸造和销毁代币(IERC7802)、批量执行(IERC7821)以及强制转移和冻结代币(IERC7943)等功能的接口定义。
建议在 https://docs.openzeppelin.com/contracts/api/interfaces 查看此文档 |
这些接口以 .sol
文件的形式提供。它们可用于与实现这些接口的第三方合约进行交互。
{IERC7913SignatureVerifier}
IERC7786GatewaySource
import "@openzeppelin/community-contracts/interfaces/IERC7786.sol";
ERC-7786 源网关的接口。
有关更多详细信息,请参见 ERC-7786
函数
supportsAttribute(selector)
sendMessage(recipient, payload, attributes)
事件
MessageSent(sendId, sender, receiver, payload, value, attributes)
错误
UnsupportedAttribute(selector)
supportsAttribute(bytes4 selector) → bool
external用于检查是否支持属性的 Getter。
sendMessage(bytes recipient, bytes payload, bytes[] attributes) → bytes32 sendId
external用于创建新消息的端点。如果消息在可以发送到目标链之前需要进一步的(网关特定的)处理,则必须返回一个非零的 outboxId
。否则,必须发送消息,并且此函数必须返回 0。
MessageSent
事件。如果任何 attributes
不受支持,则此函数应通过 UnsupportedAttribute
错误回退。
其他错误应通过 ERC-7786 中未指定的错误回退。
MessageSent(bytes32 indexed sendId, bytes sender, bytes receiver, bytes payload, uint256 value, bytes[] attributes)
event创建消息时发出的事件。如果 outboxId
为零,则无需进一步处理。如果 outboxId
不为零,则需要进一步的(网关特定的和非标准化的)操作。
UnsupportedAttribute(bytes4 selector)
error当由于指定了不受支持的属性而导致消息创建失败时,将引发此错误。
IERC7786Receiver
import "@openzeppelin/community-contracts/interfaces/IERC7786.sol";
ERC-7786 客户端合约(接收者)的接口。
有关更多详细信息,请参见 ERC-7786
函数
executeMessage(receiveId, sender, payload, attributes)
executeMessage(bytes32 receiveId, bytes sender, bytes payload, bytes[] attributes) → bytes4
external用于接收跨链消息的端点。
此函数可以直接由网关调用。
IERC7802
import "@openzeppelin/community-contracts/interfaces/IERC7802.sol";
函数
crosschainMint(_to, _amount)
crosschainBurn(_from, _amount)
IERC165
supportsInterface(interfaceId)
事件
CrosschainMint(to, amount, sender)
CrosschainBurn(from, amount, sender)
crosschainMint(address _to, uint256 _amount)
externalcrosschainBurn(address _from, uint256 _amount)
externalCrosschainMint(address indexed to, uint256 amount, address indexed sender)
eventCrosschainBurn(address indexed from, uint256 amount, address indexed sender)
eventIERC7821
import "@openzeppelin/community-contracts/interfaces/IERC7821.sol";
最小批量执行器的接口。
函数
execute(mode, executionData)
supportsExecutionMode(mode)
execute(bytes32 mode, bytes executionData)
external在 executionData
中执行调用。
如果任何调用失败,则恢复并冒泡错误。
executionData
编码:
如果 opData
为空,则 executionData
仅为 abi.encode(calls)
。
否则,executionData
为 abi.encode(calls, opData)
。
参见: https://learnblockchain.cn/docs/eips/EIPS/eip-7579
支持的模式:
bytes32(0x01000000000000000000…)
:不支持可选的 opData
。
bytes32(0x01000000000078210001…)
:支持可选的 opData
。
授权检查:
如果 opData
为空,则实现应要求 msg.sender == address(this)
。
如果 opData
不为空,则实现应使用 opData
中编码的签名来确定调用者是否可以执行执行。
opData
可用于存储用于身份验证、付费方数据、gas 限制等的其他数据。
supportsExecutionMode(bytes32 mode) → bool
external提供此功能是为了让前端检测支持。 仅对以下项返回 true:
bytes32(0x01000000000000000000…)
:不支持可选的 opData
。
bytes32(0x01000000000078210001…)
:支持可选的 opData
。
IERC7943
import "@openzeppelin/community-contracts/interfaces/IERC7943.sol";
函数
forceTransfer(from, to, tokenId, amount)
setFrozen(user, tokenId, amount)
getFrozen(user, tokenId)
isTransferAllowed(from, to, tokenId, amount)
isUserAllowed(user)
IERC165
supportsInterface(interfaceId)
事件
ForcedTransfer(from, to, tokenId, amount)
Frozen(user, tokenId, amount)
错误
ERC7943NotAllowedUser(account)
ERC7943NotAllowedTransfer(from, to, tokenId, amount)
ERC7943InsufficientUnfrozenBalance(user, tokenId, amount, unfrozen)
forceTransfer(address from, address to, uint256 tokenId, uint256 amount)
external需要特定授权。用于法规遵从性或恢复场景。
setFrozen(address user, uint256 tokenId, uint256 amount)
external需要特定授权。用户无法转移冻结的 token。
getFrozen(address user, uint256 tokenId) → uint256 amount
externalisTransferAllowed(address from, address to, uint256 tokenId, uint256 amount) → bool allowed
external这可能涉及诸如允许列表、阻止列表、转移限制和其他策略定义的限制之类的检查。
isUserAllowed(address user) → bool allowed
external这通常用于允许列表/KYC/KYB/AML 检查。
ForcedTransfer(address indexed from, address indexed to, uint256 tokenId, uint256 amount)
eventFrozen(address indexed user, uint256 indexed tokenId, uint256 amount)
eventERC7943NotAllowedUser(address account)
errorERC7943NotAllowedTransfer(address from, address to, uint256 tokenId, uint256 amount)
errorERC7943InsufficientUnfrozenBalance(address user, uint256 tokenId, uint256 amount, uint256 unfrozen)
error
- 原文链接: docs.openzeppelin.com/co...
- 登链社区 AI 助手,为大家转译优秀英文文章,如有翻译不通的地方,还请包涵~
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!