The Decred Decentralized Exchange (DEX) is a system that enables trustless exchange of different types of blockchain assets via a familiar market-based API. DEX is a non-custodial solution for cross-chain exchange based on atomic swap technology. DEX matches trading parties and facilitates price discovery and the communication of swap details.
Matching is performed through a familiar exchange interface, with market and limit orders and an order book. Settlement occurs on-chain. DEX's epoch-based matching algorithm and rules of community conduct ensure that the order book action you see is real and not an army of bots.
Trades are performed directly between users through on-chain contracts with no actual reliance on DEX, though swap details must be reported both as a courtesy and to prove compliance with trading rules. Trades are settled with pure 4-transaction atomic swaps and nothing else. Because DEX collects no trading fees, there's no intermediary token and no fee transactions.
Although trading fees are not collected, DEX does require a one-time registration fee to be paid on-chain. Atomic swap technology secures all trades, but client software must still adhere to a set of policies to ensure orderly settlement of matches. The maximum penalty imposable by DEX is loss of trading privileges and forfeiture of registration fee.
- Market API
- Client Applications and the Core Package
- Using Decred DEX
- Server Installation
- Client Installation
- Contribute
DEX services are offered via the Market API. The DEX specification details the messaging and trading protocols required to use the Market API.
In order to be accessible to the widest range of applications and languages, the Market API is accessed using JSON messages over WebSockets. A basic client application can be implemented in most popular programming languages with little more than the standard library.
The initial DEX release also includes the client Core module, written in Go. Core offers an intuitive programmer interface, with methods for creating wallets, registering DEX accounts, viewing markets, and performing trades.
dcrdex has two applications built with Core.
The browser-based GUI (a.k.a. "the app") offers a familiar exchange experience in your browser. The app is really just a one-client web server that you run and connect to on the same machine. The market view allows you to see the market's order book in sorted lists or as a depth chart. You can place your order and monitor it's status in the same market view. The GUI application is managed by the dexc utility in client/cmd/dexc.
The dexcctl utility enables trading via CLI. Commands are parsed and issued to Core for execution. dexcctl also requires dexc.
The Decred DEX is in early stages of development, and should not be used to conduct trades on mainnet. For those who would like to contribute, or just poke around and offer feedback, there are a number of ways to do that.
- Run dcrdex and dexc on simnet. Recommended for development.
- Run dexc on testnet. Recommended for poking around.
- Run the test app server. Useful for GUI development, or just to try everything out without needing to create wallets or connect to a dcrdex server.
- Linux or MacOS
- Go >= 1.13
- PostgreSQL 11+, tuned and running.
In a PostgreSQL psql
terminal, run
CREATE USER dcrdex WITH PASSWORD 'dexpass';
CREATE DATABASE dcrdex_testnet OWNER dcrdex;
The master public key is used for collecting registration fees. Using dcrctl and dcrwallet, create a new account.
dcrctl --wallet --testnet createnewaccount fees
Get the master public key for the account.
dcrctl --wallet --testnet getmasterpubkey fees
Master public keys are network-specific, so make sure to specify the network
to both dcrwallet
and dcrctl
, if not using mainnet.
Place the pubkey string into a new DEX configuration file.
~/.dcrdex/dcrdex.conf
# Testnet extended pubkey
regfeexpub=tpubVWHTkHRefqHptAnBdNcDJ...
# PostgreSQL Credentials
pgpass=dexpass
~/.dcrdex/ is the default app data directory location used by the
DEX server, but can be customized with the --appdata
command-line argument.
As of writing, only dcrd
, bitcoind
, and litecoind
are supported. The
txindex
configuration option must be set. Be sure to specify the correct
network if not using mainnet.
A sample is given at sample-markets.json. See the Per-asset Variables section of the specification for more information on individual options.
From a command prompt, navigate to server/cmd/dcrdex. Build the executable
by running go build
. The generated executable will be named dcrdex. Run
./dcrdex --help
to see configuration options that can be set either as a
command line argument or in the dcrdex.conf file. The
Exchange Variables section of the specification has
additional information on a few key options.
Run the server.
./dcrdex --testnet
from server/cmd/dcrdex.
The client is in early development, and is not fully functional. Instructions are listed for development purposes.
- Go >= 1.13
- Node 12+ is used to bundle resources for the browser interface.
Build the web assets from client/webserver/site/.
npm install
npm run build
Build and run the client from client/cmd/dexc.
go build
./dexc --testnet
Connect to the client from your browser at localhost:5758
.
Looking to contribute? We need your help to make DEX #1.
Nearly all development is done in Go and JavaScript. Work is coordinated through the repo issues, so that's the best place to start. Before beginning work, chat with us in the DEX Development room. The pace of development is pretty fast right now, so you'll be expected to keep your pull requests moving through the review process.
Check out these wiki pages for more information.
The DEX specification was drafted following stakeholder approval of the specification proposal.
The source code for the DEX server and client are being developed according to the specification. This undertaking was approved via a second DEX development proposal.