decred.org/dcrdex@v1.0.5/spec/README.mediawiki (about) 1 =Decred DEX Specification= 2 3 __TOC__ 4 5 ==Introduction== 6 7 Decred DEX is a decentralized, non-custodial, trustless, and intermediary-free 8 cryptocurrency exchange platform. Decred DEX aims to solve a number of issues 9 with existing systems of exchange. 10 11 Currently, the majority of cryptocurrency trading is performed via centralized, 12 custodial exchanges. 13 These exchanges have filled an important role in the blockchain ecosystem, but 14 are in many ways antithetical to the spirit of blockchain. 15 Blockchain is decentralized, trustless, and enables self-custody, but when a 16 user must send their coin to a third party in order to trade, all of those 17 benefits are lost. 18 19 Several projects have attempted to address this misalignment by 20 replacing the exchange with a blockchain or a token, and they have met with 21 varying degrees of success. 22 While they remove the trusted third party (TTP), they insert their own products 23 as a means to capture trading fees, which replaces the TTP friction with a 24 new platform friction. 25 26 A more robust solution is based on [https://github.com/decred/atomicswap atomic swap technology] 27 [[references.mediawiki|<nowiki>[2]</nowiki>]], 28 which enables trustless exchange directly between wallets. 29 Until recently, few blockchains supported atomic swaps, but the past few years 30 have seen widespread adoption, and such an exchange is now possible. 31 32 Decred DEX is the first exchange built on atomic swaps that doesn't collect 33 trading fees. The primary service offered by DEX is to match traders through a 34 familiar interface based on markets and orders. Decred DEX's novel matching 35 algorithm disincintevizes manipulative, abusive trading practices commonly seen 36 on centralized exchanges. The epoch-based match cycle is difficult to game by 37 the client, while for the server, cryptographic order commitments make 38 censorship and unfair matching difficult. 39 40 While trades are fully trustless, steps are taken to discourage malicious 41 clients from hindering normal trade activity. 42 All clients must lock coins in bonds to trade. 43 Registered clients are then bound to the 44 [[community.mediawiki|rules of community conduct]], violation of which typically 45 results in loss of trading privileges. 46 47 In the interest of maintaining active, open-source, community-driven 48 development, this specification document describes the protocols necessary for 49 implementation of both DEX clients and DEX servers. 50 51 ==Contents== 52 53 The remaining content details the Decred DEX protocol. 54 It is intended as a first resource when implementing servers and clients. 55 Continuing client-server interoperability will likely depend on subtle aspects 56 of the specification laid out in this document. 57 58 '''<nowiki>[1]</nowiki> [[comm.mediawiki|Communication Protocols]]''' describes the 59 messaging protocols and communication layer technologies that are to be used 60 for the DEX API. 61 62 * [[comm.mediawiki#websockets|WebSockets]] 63 * [[comm.mediawiki/#encoding|Data Encodings]] 64 ** [[comm.mediawiki/#timestamps|Timestamps]] 65 ** [[comm.mediawiki/#rate-encoding|Rate Encoding]] 66 ** [[comm.mediawiki/#coin-id|Coin ID]] 67 * [[comm.mediawiki/#message-protocol|Message Protocol]] 68 * [[comm.mediawiki/#session-authentication|Session Authentication]] 69 * [[comm.mediawiki/#http|HTTP]] 70 71 '''<nowiki>[2]</nowiki> [[fundamentals.mediawiki|Distributed Exchange Design Fundamentals]]''' 72 describes the notable design aspects that facilitate an exchange service with 73 the features described above. 74 75 * [[fundamentals.mediawiki/#exchange-variables|Exchange Variables]] 76 ** [[fundamentals.mediawiki/#global-variables|Global Variables]] 77 ** [[fundamentals.mediawiki/#asset-variables|Asset Variables]] 78 ** [[fundamentals.mediawiki/#market-variables|Market Variables]] 79 ** [[fundamentals.mediawiki/#configuration-data-request|Configuration Data Request]] 80 * [[fundamentals.mediawiki/#fees|Fees]] 81 * [[fundamentals.mediawiki/#transaction-fees|Transaction Fees]] 82 * [[fundamentals.mediawiki/#epochbased-order-matching|Epoch-based Order Matching]] 83 ** [[fundamentals.mediawiki/#epoch-time|Epoch Time]] 84 ** [[fundamentals.mediawiki/#pseudorandom-order-matching|Pseudorandom Order Matching]] 85 * [[fundamentals.mediawiki/#identities-based-on-public-key-infrastructure-pki-key-pairs|Identification]] 86 * [[fundamentals.mediawiki/#blockchain-interaction|Blockchain Interaction]] 87 * [[fundamentals.mediawiki/#adding-new-assets|Adding New Assets]] 88 * [[fundamentals.mediawiki/#api-version|API Version]] 89 ** [[fundamentals.mediawiki/#v0|v0]] 90 91 '''<nowiki>[3]</nowiki> [[admin.mediawiki|Distributed Exchange Administration]]''' describes 92 the tasks required to administer the exchange. 93 94 * [[admin.mediawiki/#exchange-variables|Exchange Variables]] 95 * [[admin.mediawiki/#per-asset-variables|Per-asset Variables]] 96 * [[admin.mediawiki/#administration-api|Administration API]] 97 98 '''<nowiki>[4]</nowiki> [[accounts.mediawiki|Client Accounts]]''' details account creation. 99 100 * [[accounts.mediawiki/#step-1-registration|Registration]] 101 * [[accounts.mediawiki/#step-2-fee-notification|Fee Notification]] 102 103 '''<nowiki>[5]</nowiki> [[orders.mediawiki|Client Order Management]]''' details the different 104 order types and the client/server workflows required to synchronize the order 105 book and place orders. 106 107 * [[orders.mediawiki/#connection-persistence|Connection Persistence]] 108 * [[orders.mediawiki/#order-book-subscriptions|Order Book Subscriptions]] 109 * [[orders.mediawiki/#order-preparation|Order Preparation]] 110 ** [[orders.mediawiki/#calculating-transaction-fees|Calculating Transaction Fees]] 111 ** [[orders.mediawiki/#coin-preparation|Coin Preparation]] 112 ** [[orders.mediawiki/#order-commitment|Order Commitment]] 113 ** [[orders.mediawiki/#order-signing|Order Signing]] 114 ** [[orders.mediawiki/#order-id|Order ID]] 115 * [[orders.mediawiki/#order-types|Order Types]] 116 ** [[orders.mediawiki/#limit-order|Limit Order]] 117 ** [[orders.mediawiki/#market-order|Market Order]] 118 *** [[orders.mediawiki/#market-buy-orders|Market Buy Orders]] 119 ** [[orders.mediawiki/#cancel-order|Cancel Order]] 120 * [[orders.mediawiki/#preimage-reveal|Preimage Handling]] 121 * [[orders.mediawiki/#match-negotiation|Match Negotiation]] 122 * [[orders.mediawiki/#match-revocation|Match Revocation]] 123 * [[orders.mediawiki/#trade-suspension|Trade Suspension]] 124 125 '''<nowiki>[6]</nowiki> [[api.mediawiki| Data API]]''' defines http and WebSocket APIs to browse 126 trade history. 127 128 '''<nowiki>[7]</nowiki> [[atomic.mediawiki|Atomic Settlement]]''' walks through the settlement 129 process with a couple of examples to provide a high-level overview. 130 131 * [[atomic.mediawiki/#case-a-perfect-match|Perfect Match]] 132 * [[atomic.mediawiki/#case-b-multi-taker-with-partial-fill|Multi-Taker with Partial Fill]] 133 134 '''<nowiki>[8]</nowiki> [[community.mediawiki|Community Conduct]]''' describes the system of rules 135 to which clients interacting with the DEX must adhere. 136 137 * [[community.mediawiki/#rules-of-community-conduct|Rules of Community Conduct]] 138 ** [[community.mediawiki/#rule-1-clients-must-respond-to-all-preimage-requests|Preimage Response]] 139 ** [[community.mediawiki/#rule-2-every-match-must-be-fully-settled|Fully Settle]] 140 ** [[community.mediawiki/#rule-3-an-accounts-cancellation-rate-must-not-exceed-the-threshold|Cancellation Rate Threshold]] 141 ** [[community.mediawiki/#rule-4-transaction-outputs-must-be-properly-sized|Transaction Output Size]] 142 * [[community.mediawiki/#penalties|Penalties]] 143 ** [[community.mediawiki/#penalization-notification|Penalization Notification]] 144 *** [[community.mediawiki/#penalty-object|Penalty Object]] 145 146 '''<nowiki>[9]</nowiki> [[references.mediawiki|References]]''' lists references used in the development 147 of the specification.