没有合适的资源?快使用搜索试试~ 我知道了~
首页0x交易所协议技术白皮书
0x交易所协议技术白皮书
需积分: 0 197 浏览量
更新于2023-05-27
评论 3
收藏 312KB PDF 举报
目前最实用的分布式交易所协议技术白皮书,未来所有分布式交易所可能都会基于这个协议设计
资源详情
资源评论
资源推荐

0x: An open protocol for decentralized exchange on
the Ethereum blockchain
Will Warren, Amir Bandeali
0xProject.com
February 21, 2017
Abstract
We describe a protocol that facilitates low friction peer-to-peer exchange of ERC20 tokens on the
Ethereum blockchain. The protocol is intended to serve as an open standard and common building
block, driving interoperability among decentralized applications (dApps) that incorporate exchange
functionality. Trades are executed by a system of Ethereum smart contracts that are publicly acces-
sible, free to use and that any dApp can hook into. DApps built on top of the protocol can access
public liquidity pools or create their own liquidity pool and charge transaction fees on the resulting
volume. The protocol is unopinionated: it does not impose costs on its users or arbitrarily extract
value from one group of users to benefit another. Decentralized governance is used to continuously
and securely integrate updates into the base protocol without disrupting dApps or end users.
1

Contents
1 Introduction 3
2 Existing Work 4
3 Specification 5
3.1 Message Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.1 Point-to-point Orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.2 Broadcast Orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Smart Contract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.1 Signature Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.2 Fills & Partial Fills . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.3 Expiration Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2.4 Cancelling Orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4 Protocol Token 11
4.1 Decentralized Governance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.1.1 Continuous Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.1.2 Token Registry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
5 Summary 13
6 Acknowledgements 14
7 Appendix 15
7.1 ERC20 Token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7.2 Contract ABI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7.3 Ethereum Name Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2

1 Introduction
Blockchains have been revolutionary by allowing anyone to own and transfer assets across an open finan-
cial network without the need for a trusted third party. Now that there are hundreds [1] of blockchain-
based assets, and more being added every month, the need to exchange these assets is compounding.
With the advent of smart contracts, it is possible for two or more parties to exchange blockchain assets
without the need for a trusted third party.
Decentralized exchange is an important progression from the ecosystem of centralized exchanges for a
few key reasons: decentralized exchanges can provide stronger security guarantees to end users since
there is no longer a central party which can be hacked, run away with customer funds or be subjected to
government regulations. Hacks of Mt. Gox, Shapeshift and Bitfinex [2, 3] have demonstrated that these
types of systemic risks are palpable. Decentralized exchange will eliminate these risks by allowing users
to transact trustlessly - without a middleman - and by placing the burden of security onto individual
users rather than onto a single custodian.
In the two years that have passed since the Ethereum blockchain’s genesis block, numerous decentralized
applications (dApps) have created Ethereum smart contracts for peer-to-peer exchange. Rapid iteration
and a lack of best practices have left the blockchain scattered with proprietary and application-specific
implementations. As a result, end users are exposed to numerous smart contracts of varying quality and
security, with unique configuration processes and learning curves, all of which implement the same func-
tionality. This approach imposes unecessary costs on the network by fragmenting end users according
to the particular dApp each user happens to be using, destroying valuable network effects around liquidity.
0x is an open protocol for decentralized exchange on the Ethereum blockchain. It is intended to serve
as a basic building block that may be combined with other protocols to drive increasingly sophisticated
dApps [4]. 0x uses a publicly accessible system of smart contracts that can act as shared infrastructure
for a variety of dApps, as shown in Figure 1. In the long run, open technical standards tend to win
over closed ones, and as more assets are being tokenized on the blockchain each month, we will see more
dApps that require the use of these different tokens. As a result, an open standard for exchange is critical
to supporting this open economy.
Shared
Exchange
Protocol
End Users
dApp A
Shared
Liquidity
Pool(s)
dApp B
dApp N
Ethereum Blockchain
Figure 1: Open protocols should be application-agnostic. Decoupling the protocol layer from the appli-
cation layer provides mutual benefits for dApp developers and end users alike.
3

2 Existing Work
Decentralized exchanges implemented with Ethereum smart contracts have failed to generate significant
volume due to inefficiencies in their design that impose high friction costs on market makers. In particu-
lar, these implementations place their order books
1
on the blockchain [5–8], requiring market makers to
spend gas each time they post, modify or cancel an order. While the cost of a single transaction is small,
frequently modifying orders in response to evolving market conditions is prohibitively expensive. In addi-
tion to imposing high costs on market makers, maintaining an on-chain order book results in transactions
that consume network bandwidth and bloat the blockchain without necessarily resulting in value transfer.
Automated market maker (AMM) smart contracts are proposed [9,10] as an alternative to the on-chain
order book. The AMM smart contract replaces the order book with a price-adjustment model in which
an asset’s spot price deterministically responds to market forces and market participants on either side of
the market trade with the AMM rather than with each other. Benefits of the AMM include availability
(it is always available to act as a counterparty, though the spot price it offers may be worse than what
one could get from a more traditional exchange) and ease-of-integration with external smart contracts
that need to execute market orders. The deterministic nature of price-adjustment models make them
insensitive to market liquidity, meaning that trades cause prices to move the same amount in both thick
and thin markets [11]. In other words, AMMs impose artificial constraints on the supply curve. If the
price-adjustment model is too sensitive, even small trades will produce large fluctuations in the spot
price. If the price-adjustment model is not sensitive enough, the AMMs bankroll will quickly be depleted
by arbitrageurs.
State channels are proposed as a means of scaling the Ethereum blockchain and reducing costs for a
variety of applications - including exchange [12] - by moving transactions off of the blockchain [13, 14].
Participants in a state channel pass cryptographically signed messages back and forth, accumulating
intermediate state changes without publishing them to the canonical chain until the channel is closed.
State channels are ideal for “bar tab” applications where numerous intermediate state changes may be
accumulated off-chain before being settled by a single on-chain transaction (i.e. day trading, poker,
turn-based games). If one of the channel participants leaves the channel or attempts to cheat, there is a
challenge period during which the other participant may publish the most recent message they received
from the offender. It follows that channel participants must always be online to challenge a dishon-
est counterparty and the participants are therefore vulnerable to DDOS attacks. While state channels
drastically reduce the number of on-chain transactions for specific use cases, the numerous on-chain
transactions and security deposit required to open and safely close a state channel make them inefficient
for one-time transactions.
A hybrid implementation, which we refer to as “off-chain order relay with on-chain settlement,” com-
bines the efficiency of state channels with the near instant settlement of on-chain order books. In this
approach, cryptographically signed orders are broadcast off of the blockchain; an interested counterparty
may inject one or more of these orders into a smart contract to execute trades trustlessly, directly on the
blockchain [15, 16]. Friction costs are minimized for market makers because they can signal intent off-
chain and transactions only occur when value is being transferred. We extend this approach by allowing
anyone to act as the exchange and by making the protocol application-agnostic.
1
An order book is used to publicly record the interest of buyers and sellers in a particular financial instrument. Each entry
includes a reference to the interested party, the number of shares and the price that the buyer or seller are bidding/asking
for the particular security.
4
剩余15页未读,继续阅读



















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0