10.基于谓词的订单簿 (Predicate-based order book)
Spark version of using predicates to orchestrate a swap without any smart contracts.
Spark版本使用谓词来协调交换/交易,没有任何智能合约。
In Sway, predicates are essentially programs that evaluate to either true or false, without having any side effects. They are used to specify conditions or requirements that need to be met in order for a certain action to be executed.
在Sway中,谓词本质上是在没有任何副作用的情况下评估为真或假(布尔值)的程序。它们被用来指明需要满足的条件或要求,进而执行某个动作。
In the context of the Sway blockchain, a predicate is a script that specifies the rules for a transaction to be valid. When a predicate is included in a transaction, it is executed on the blockchain to determine if the transaction meets the specified conditions. Predicates can be used for a wide range of purposes, including smart contract conditions, multisignature requirements, and more.
在Sway区块链的背景下,谓词是一个脚本,它规定了有效交易的规则。当交易中包含一个谓词时,它在区块链上被执行,确定交易是否符合指明的条件。谓词用途广泛,包括智能合约条件、多签要求等等。
Predicates are associated with a predicate address, which is generated from the compiled byte code and is similar to a P2SH address used in Bitcoin. This address can own assets, and users can send assets to it just like any other address. However, to spend the assets associated with the predicate address, the user must provide the original byte code of the predicate along with the predicate data. If the predicate is validated successfully, the assets can then be transferred to the desired destination.
谓词与一个谓词地址相关联,该地址由编译的字节码生成,类似于比特币中使用的P2SH地址。这个地址可以拥有资产,用户可以像其他地址一样向其发送资产。然而,要花费与谓词地址相关的资产,用户必须提供谓词的原始字节码以及谓词数据。如果该谓词被成功验证,资产就可以被转移到指明的目的地。
谓词如何与限价单配合使用?(How do predicates work with limit orders?)
Predicates are not deployed to the chain as smart contracts. Instead, they are represented by a hash that locks some coins. If a user can provide the bytecode that generates that hash and makes the predicate evaluate to true, then they can spend the locked coins. This means that when creating a limit order using predicates, the user just needs to send coins to the code hash. When executing the order, the transaction only needs to make the predicate return true. The predicate's role is to ensure that the taker sends enough coins to the maker, allowing them to spend the predicate as they wish. With this innovative approach, Sway has introduced a new level of flexibility and efficiency to the world of decentralized finance.
谓词不是作为智能合约部署到链上。相反,是由锁定一些代币的哈希值来表示。如果用户能够提供生成该哈希值的字节码,并使谓词评估为真,那么他们就可以花费被锁定的代币。这意味着,当使用谓词创建一个限价单时,用户只需要将代币发送到代码哈希。当执行订单时,交易只需要让谓词返回真。谓词的作用是确吃单方向挂单方发送足够的代币,使他们能够按照自己的意愿消费谓词。通过这种创新的方法,Sway为去中心化的金融世界引入了新的灵活性和效率水平。
这种DEX架构与其他架构相比有何独特之处?(What makes this DEX architecture unique compared to others?)
There have been two primary DEX architecture strategies implemented so far: the uniswap style automated market maker (AMM) that can function entirely within smart contracts, and the off-chain order book with on-chain settlement used by platforms like DYDX, 0x, and OpenSea. Both have downsides, such as reduced capital efficiency in the case of the AMM, and centralized components and potential regulation in the case of off-chain order books.
到目前为止,已经有两个主要的DEX架构策略得到了实施:可以完全在智能合约内运作的,uniswap风格的自动做市商(AMM),以及DYDX、0x和OpenSea等平台所使用的链外订单簿与链上结算。两者都有缺点,比如在AMM的情况下,资本效率降低,而在链外订单簿的情况下,择优中心化组件和潜在监管等问题。
Fuel Labs has introduced a new architecture that uses predicates to enable a fully on-chain order book. Since creating an order is simply a transfer, there is no costly state writing problem. As long as there is a data availability layer that allows the public to observe the orders, they can be fully verified on-chain by checking the predicate balance. The predicate order book offers the capital efficiency advantages of a centralized limit order book without sacrificing decentralization.
Fuel Labs推出了一个新的架构,使用谓词来实现完全的链上订单簿。由于创建一个订单只是一个转移,所以不存在昂贵的状态写入问题。只需一个可供公众观察订单的数据可用性层,就可以通过检查谓词的余额,在链上进行完全验证。谓此订单簿提供了中心化限价订单簿的资本效率优势,而不牺牲去中心化。
模块 (Modules)
Predicate orders builder service 谓词订单建立者服务
Create order script 创建订单脚本
Order template predicate 订单模板谓词
Matcher engine 匹配器引擎
Frontend 前端
对谓词进行SPARK订单本操作的算法 (Algorithm for SPARK orderbook operation on predicates)
This scheme contains a description of the operation of 2 test cases:
Case #1: p2p fulfilling of order Alice wants to exchange 1000 USDC for 200 UNI Bob wants to exchange 200 UNI for 1000 USDC
Case #2: partial p2p fulfilling of order Alice wants to exchange 1000 USDC for 200 UNI Bob wants to exchange 100 UNI for 500 USDC Chad wants to exchange 100 UNI for 500 USDC 🚧 In the near future, there will be another scheme for the operation of the matching engine.
这个方案包含对2个测试案例的操作描述:
案例#1:订单的p2p执行 Alice想用1000 USDC换200 UNI Bob想用200 UNI换1000 USDC
案例#2:订单的部分p2p执行 Alice想用1000 USDC换200 UNI Bob想用100 UNI换500 USDC Chad想用100 UNI换500 USDC 🚧 在不久的将来,将有另一种方案用于匹配引擎的操作
Last updated