pDEX: The first privacy-protecting decentralized exchange

The first generation of exchanges includes centralized exchanges like Binance and Coinbase. The second generation of exchanges comprises of decentralized exchanges (DEX) like Bancor, Kyber, and Uniswap. pDEX is an upgraded DEX. Like decentralized exchanges, it is trustless. It also implements additional features such as privacy via zero-knowledge proofs, high throughput via sharding, and inter-blockchain trading via interoperable bridges.

DEX pDEX
Trustless YES YES
Privacy NO YES
High throughput NO YES
Low latency NO YES
Inter-blockchain NO YES

Trustless

pDEX is code (beaconpdeproducer.go, beaconpdeprocess.go) that is deployed to thousands of Nodes powering the Incognito network. It runs entirely on-chain and is completely decentralized.

The Automated Market Making mechanism of pDEX is somewhat different from typical exchanges. This post offers a high-level overview of the mechanism and argues for its major advantages. pDEX borrows heavily from Nick Johnson’s reddit post in 2016, Vitalik Buterin’s reddit post in 2016, Hayden Adam’s Uniswap implementation in 2018.

pDEX does not use an order book. Instead, it implements an Automated Market Making algorithm that enables instant matches, no matter how large the order or how small the liquidity pool is.

Trading on pDEX

The traditional order book is replaced by a bonding curve mechanism known as constant product. On a typical exchange such as Coinbase or Binance, market makers supply liquidity at various price points. pDEX takes everyone’s bids and asks, and pools them into two giant buckets. Market makers no longer specify prices at which they are willing to buy or sell; pDEX automatically creates markets based on an Automated Market Making algorithm.

Here is a simple example of how trading plays out on pDEX. Let’s say there is 100,000 pDAI and 10 pBTC currently in the pDAI/pBTC pool. The goal is to keep this product equal to 1,000,000 at any trading volume.

pDAI pool   : 100,000

pBTC pool   : 10

Constant    : 10 * 100,000 = 1,000,000

A buyer sends 10,000 pDAI to buy pBTC. A fee (in this example, 0.1% or 10 pDAI) is taken out for liquidity providers, and the remaining 9,990 is added to the pDAI pool. The constant product is divided by the new amount of pDAI in the liquidity pool to determine the new pBTC pool. The buyer receives the remaining pBTC.

Buyer sends : 10,000 pDAI

Fee         : 10,000 * 0.1% = 10 pDAI

pDAI pool   : 100,000 + 10,000 – 10 = 109,990

pBTC pool   : 1,000,000 / 109,990 = 9.091735

Buyer gets  : 10 – 9.091735 = 0.908254 pBTC

Note that:

  • The fee is added to the liquidity pool. The pDAI pool is now 109,990 + 10 = 110,000. Liquidity providers only collect fees when they exit the pool.
  • These fees mean that the Constant will increase slightly after each trade. In this example, it is now 110,000 * 9.091735 = 1,000,090.85
  • The price has now shifted. A buyer who makes a trade in the same direction will get a slightly worse pBTC/pDAI rate. A buyer who makes a trade in the opposite direction will get a slightly better pDAI/pBTC rate.

Becoming a liquidity provider and earning trading fees

Liquidity providers play an essential role. As the name suggests, they provide liquidity to various pools on pDEX and earn trading fees.

Let’s walk through it. In our example above, there is 100,000 pDAI and 10 pBTC in the pool. The ratio informs the price of the trading pair on pDEX: 100,000 pDAI / 10 pBTC = 10,000. If the price of BTC on another exchange (say, Binance) is not 10,000, there would be an arbitrage opportunity between pDEX and Binance.

Liquidity providers must therefore provide liquidity to both sides of the pair to ensure the ratio between pDAI and pBTC is maintained. For example, if Alice wants to supply 1 pBTC, she must also supply 10,000 pDAI.

pDEX records liquidity contribution by issuing shares representative of the liquidity provider’s ownership of the pool. In our example, Alice owns 9.09% of the pool. This represents her contribution as well as her earnings: 9.09% of the total trading fees made from that pool.

Alice supplies  : 10,000 pDAI and 1 pBTC

pDAI pool       : 100,000 + 10,000 = 110,000

pBTC pool       : 10 + 1 = 11

Alice owns      : 1 pBTC / 11 pBTC = 9.09% of the pool

Trading fees

Here’s how it works:

1. The users set their own trading fees.  

 2. Block producers sort orders by Trading FeeTrade Amount ratio, from highest to lowest, and process orders one by one.

3. The trading fees go directly to liquidity providers.

Unlike other exchanges which offer fixed trading fee structures, pDEX gives users complete control of their trading fees. It’s entirely market-driven. The higher you set your trading fees, the more likely your orders will be processed first at the prices you want.  The lower you set your trading fees, you’ll pay less but your orders is at risk of failing due to price movements.

Unlike other exchanges which take all of the trading fees, on pDEX, the entirety of trading fees go directly to the liquidity providers.

We think that it’s a fairer way to build a crypto exchange.

Inter-Blockchain Liquidity

pDEX leverages Incognito’s bridges to other blockchains like Ethereum and Bitcoin to enable inter-blockchain trading. So you can trade BTC and ERC20 tokens on pDEX – with complete privacy.

As of November 2019, the Incognito <> Ethereum Bridge is the only trustless bridge on the Mainnet. Other bridges will migrate to a trustless implementation in early 2020.

Bridges Current Implementation
Ethereum <> Incognito Trustless
Bitcoin <> Incognito Trusted (Going trustless Q1 2020)
Binance <> Incognito Trusted (Going trustless Q1 2020)
EOS <> Incognito Trusted (Going trustless Q2 2020)

Privacy

The solution for privacy is relatively simple. Within the Incognito Wallet, there is a unique address reserved for pDEX activities. Each user has a pDEX address. A user can transfer funds from any address to the pDEX address. All transfers are private by default on the Incognito network. No one can see the connection between the sending address and the pDEX address.

Once the pDEX address is funded, the user can freely trade without disclosing their identity.

High Throughput

pDEX leverages Incognito’s sharded architecture to deliver high throughput. The workload is shared among shards and trades are processed in parallel. Incognito’s throughput scales linearly by adding more shards, so it can grow to support large transaction volumes.

Low Latency

One of the benefits of Automated Market Making is instant matching. If you enter an order, it will match right away. The current block time of Incognito is 40s.

Once the block is produced on a shard, it is sent to the beacon chain, which takes another 40s. A trade will complete within 80s. Incognito plans to reduce the block time to 10s, once transaction size is further optimized.

Conclusion

Along with trustlessness, pDEX combines several advanced technologies like zero-knowledge proofs for privacy, sharding for high throughput, and interoperable bridges for inter-blockchain trading. We hope that pDEX will be a helpful product for the crypto community.

Users will be able to start trading on pDEX from 12 November 2019, and be able to participate as liquidity providers shortly after (date TBC).

We would love to hear your thoughts. Reach out to the tech team at t.me/incognitonode or send us an email at go@incognito.org.

 

Leave a Reply

Your email address will not be published. Required fields are marked *