部署交易合约 (Deploy an exchange contract)
dex 合约是指打算利用 Sei 的 dex 模块中的功能的 CosmWasm 合约 A dex contract refers to a CosmWasm contract that intends to make use of functionalities from Sei's dex module
合约开发 (Contract Development)
To leverage the highly efficient dex
module of Sei, a dex-registered (see later section of this page) CosmWasm contract has to implement the following four SudoMsg
interfaces:
为了利用 Sei 的高效 dex 模块,dex 注册(参见本页后面部分)的 CosmWasm 合约必须实现以下四个 SudoMsg 接口:
SudoMsg::BulkOrderPlacements
This endpoint receives orders placed in the current block on Sei dex and needs to respond with any order id that is not intended to go through by the contract.
该端点接收放在 Sei dex 上当前区块中的订单,并且需要使用任何不经由合约的订单 ID 进行响应。
SudoMsg::BulkOrderCancellation
This endpoint receives orders cancelled in the current block on Sei dex.
该端点接收在 Sei dex 上当前区块中取消的订单。
SudoMsg::Settlement
This endpoint receives orders settled in the current block on Sei dex and dex doesn't need response from this endpoint.
该端点接收在 Sei dex 上当前区块结算的订单,而 dex 不需要来自该端点的响应。
SudoMsg::NewBlock
This endpoint receives the latest epoch at the beginning of each block.
该端点在每个块的开头接收最新的纪元(数据)。
SudoMsg::FinalizeBlock
This endpoint receives the order placement results for orders sent by this contract only. Also note that this endpoint is not needed if the contract is not registered as NeedHook in the dex module.
该端点仅接收此合约发送的订单之下单结果。另请注意,如果合约未在 dex 模块中注册为 NeedHook ,则不需要此端点。
Data type definitions (official Sei libraries for these types coming soon):
数据类型定义(这些类型的官方库即将推出):
Response objects like BulkOrderPlacementsResponse
need to be first serialized as JSON strings, and then encoded with base64:
类似 BulkOrderPlacementsResponse
这样的响应对象,需要先序列化为 JSON 字符串,然后用 base64 编码:
There is no requirement on execute
and query
endpoints. That being said, it's encouraged to minimize the usage of execute
and build the bulk of your exchange logic into the aforementioned sudo
endpoints, for performance reasons.
对执行和查询端点没有要求。话虽如此,出于性能原因,鼓励尽量减少执行并将大部分交换/交易所逻辑构建到上述 sudo 端点中。
构建/上传/实例化合约 (Build/Upload/Instantiate Contract)
The same as deploying a generic CosmWasm contract.
与部署 通用 CosmWasm 合约 相同。
向 DEX 模块注册合约 (Register Contract with DEX Module)
In order to leverage dex
module's functionalities, you need to register your contract with dex
. To do so, send a register-contract
transaction to the dex
module. Template of the command is:
为了利用 dex 模块的功能,您需要使用 dex 注册您的合约。为此,向 dex 模块发送一个 register-contract
交易。该命令的模板是:
Example: 举例:
Note the two boolean variables represents:
请注意,两个布尔变量表示:
NeedHook
NeedOrderMatching
Sei Cosmwasm
Sei cosmwasm crate provides Sei specific bindings for cosmwasm contract to be able to interact with the Sei blockchain by exposing custom messages, queries, and structs that correspond to custom module functionality in the Sei chain. Contracts can import the latest version of the crate and directly interact with a vary of sei modules.
Sei cosmwasm 库为 cosmwasm 合约提供 Sei 的特定绑定,以使其可以通过以下方式与Sei区块链交互:公开在Sei区块链上与自定义模块、查询和结构对应的自定义消息。合约可以导入最新版本的库并直接与各种 sei 模块交互。
最后更新于