Skip to content

Commit 84d89dd

Browse files
authored
add description of DEX (#53)
* wip: fill in dex description more images TK * flesh out further details of DEX * move up liquidity provisioning in sidebar * few text tweaks to dex section * dex: few small additions * update figures, move LP section into DEX subheading
1 parent 689a334 commit 84d89dd

10 files changed

+96
-15
lines changed

pages/_meta.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,11 @@
4545
"breadcrumb": false
4646
}
4747
},
48-
"lp": {
49-
"title": "Providing Liquidity",
50-
"theme": {
51-
"breadcrumb": false
52-
}
53-
},
5448
"dev": "Development",
5549
"resources": {
5650
"title": "Resources",
5751
"theme": {
5852
"breadcrumb": false
5953
}
6054
}
61-
}
55+
}

pages/dex.mdx

+79
Original file line numberDiff line numberDiff line change
@@ -1 +1,80 @@
11
# The Penumbra DEX
2+
3+
Penumbra's decentralized exchange (DEX) is a state of the art DEX engine, enabling private, high-performance trading of any IBC asset. Using Penumbra's DEX, users can swap between assets *without* leaving Penumbra's shielded pool.
4+
5+
## What makes the Penumbra DEX unique?
6+
7+
The Penumbra DEX features a batched swap/intent system and enables fine-grained control over liquidity positions for liquidity providers (LPs). In this section, we'll dive into some of the key features of the Penumbra DEX.
8+
9+
### Batch Execution
10+
11+
The incoming order flow of swap intents are batched together by trading pair and executed at the end of each block. The batching of swap intents means that in Penumbra, there is no intra-block ordering of swap intents that can be manipulated by traders. Trades get executed approximately every 5 seconds - Penumbra's block time.
12+
13+
<picture>
14+
<img src="./images/dex-batch-execution.png" />
15+
</picture>
16+
17+
Each block, the Penumbra protocol:
18+
19+
1. Receives swap inputs from users submitting Penumbra `Swap` transactions. These swap intents describe the desired input and output assets, as well as the amount of the input asset the user would like to swap. The `Swap` transaction essentially burns the input funds, which are in the Penumbra shielded pool.
20+
2. Batches, or sums, together all the swap intents for each trading pair. The result is a single batch. For example, if Alice, Bob, and Charlie each submit a swap intent to swap 1, 2, and 3 ETH respectively - each into UM - the batch swap will consist of 6 ETH to swap into UM.
21+
3. Executes the batch swap against Penumbra's DEX engine (described in more detail below). This is done on a per-trading pair basis. The batch swap can succeed or fail, for example the batch swap can fail if there is insufficient liquidity to fill the batch. The batch swap result gets written to the public chain state.
22+
23+
Finally, in subsequent blocks, users can mint the outputs of the batch swap directly into the Penumbra shielded pool. This is done via a `SwapClaim` transaction, which takes the batch swap result, and mints that user's swap output funds directly into Penumbra's shielded pool. The minted output funds for a specific user will be their pro-rata contribution to the batch swap, or it can be the original swap inputs if the batch swap failed.
24+
25+
For example, in the output above where Charlie submitted an intent to swap 3 ETH into UM, and he contributed half of the batch swap input funds in that block and trading pair:
26+
* if the batch swap succeeds, the `SwapClaim` transaction will mint half of the batch swap output funds to Charlie.
27+
* if the batch swap fails, the `SwapClaim` transaction will mint 3 ETH to Charlie.
28+
29+
One important feature of the `SwapClaim` transaction is that it can be *automatically* performed by wallets, since:
30+
* the fees are pre-paid in the original `Swap` transaction
31+
* the `SwapClaim` is pre-authorized by the `Swap` transaction, so does not require any additional signatures from the user
32+
33+
The phased two-block execution of the `Swap` and `SwapClaim` transactions is illustrated below:
34+
35+
<picture>
36+
<img src="./images/dex-swap-claim.png" />
37+
</picture>
38+
39+
### Concentrated Liquidity Positions
40+
41+
*Market makers* are users who provide liquidity by agreeing to buy and sell a specific trading pair at a price they specify. They do this by creating a *liquidity position* in Penumbra.
42+
43+
Penumbra's DEX supports concentrated [liquidity positions](/dex/lp). Each liquidity position in Penumbra is essentially a constant-sum individual [Automated Market Maker (AMM)](https://www.gemini.com/cryptopedia/amm-what-are-automated-market-makers#section-automated-market-maker-variations). Fees are set on a per-position basis, instead of fee tiers. This enables market forces to set fees.
44+
45+
By creating an arbitrary number of these concentrated liquidity positions, market makers can approximate any trading function:
46+
47+
<picture>
48+
<img src="./images/dex-concentrated-liquidity.png" />
49+
</picture>
50+
51+
This enables fine-grained control over liquidity provisioning. Active market makers can adjust prices as often as once per block.
52+
53+
The positions themselves are public, but anonymous. For further details on liquidity positions, see the [Providing Liquidity](/dex/lp) page.
54+
55+
### DEX Execution and Optimal Routing
56+
57+
Penumbra's DEX automatically finds the *best* trading path across all available liquidity. You can consider each liquidity position as a road connecting two assets, at a specified price. The DEX engine acts like a smart GPS, finding the best route to trade your input asset into your output asset. Sometimes the best route might be direct, but often it will involve multiple liquidity positions to get you the best price. This is all done transparently to the user.
58+
59+
We call the collection of all liquidity positions the *liquidity graph*, as it can be thought of as a graph of nodes and edges, and the Penumbra DEX engine traverses the graph to find the best path for your trade.
60+
61+
<picture>
62+
<img src="./images/dex-optimal-routing.png" />
63+
</picture>
64+
65+
Each block, the DEX engine executes in four steps:
66+
67+
1. Add newly opened liquidity positions to the liquidity graph.
68+
2. Execute batched trades for each trading pair. This is done by searching the liquidity graph for the mathematically optimal trading path across the available liquidity, and then executing the batch of swap intents for that trading pair.
69+
3. Perform optimal arbitrage to ensure prices are consistent between liquidity pools.
70+
4. Remove closed liquidity positions from the liquidity graph.
71+
72+
This optimal execution means that the DEX provides the best prices for swaps, routing your trade through the most efficient path, including splitting swaps across multiple pools.
73+
74+
### Privacy
75+
76+
Privacy is at the core of Penumbra, including its DEX.
77+
78+
Swap intents are submitted anonymously, and the claimed swap output values are never revealed to the network - they are minted completely privately, directly into Penumbra's shielded pool.
79+
80+
Market makers provide liquidity by creating anonymous concentrated liquidity positions. These positions disclose only the amount of liquidity and the trading function, without linking to any identity. This enables truly *private* trading, preventing others from copying your proprietary trading strategies.

pages/dex/_meta.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"lp": {
3+
"title": "Providing Liquidity",
4+
"theme": {
5+
"breadcrumb": false
6+
}
7+
}
8+
}

pages/lp.mdx pages/dex/lp.mdx

File renamed without changes.

pages/index.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { Bleed } from 'nextra-theme-docs'
22

33
# Welcome to Penumbra
44

5-
Penumbra is a fully private, cross-chain proof-of-stake network and
6-
decentralized exchange for the Cosmos and beyond. Penumbra brings privacy to
7-
IBC, allowing anyone to shield any IBC asset just by transferring it into
5+
Penumbra is a fully private, cross-chain proof-of-stake L1 blockchain and
6+
decentralized exchange for the Cosmos ecosystem and beyond. Penumbra brings privacy to
7+
[IBC](https://ibcprotocol.dev/), allowing anyone to shield any IBC asset just by transferring it into
88
Penumbra's interchain shielded pool. Within Penumbra, users can transact,
99
stake, swap, or marketmake without broadcasting their personal information to
1010
the world. Unlike a transparent chain, where all information is public,
11-
Penumbra is end-to-end encrypted.
11+
Penumbra is end-to-end encrypted, and transactions are shielded by default.
1212

1313
<picture>
1414
<img src="./images/interchain-shielded-pool.jpg" />

pages/interchain-privacy.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ across chains.
1212
### Deposit
1313

1414
To deposit tokens into Penumbra's shielded pool, users initiate an ordinary IBC
15-
transfer from any connected chain, with a Penumbra address as the receiver.
15+
transfer from any connected chain, with a Penumbra address as the receiver.
1616

1717
### Transact Privately
1818

@@ -42,8 +42,8 @@ Here's what you need to know:
4242

4343
Penumbra transactions are end-to-end encrypted, visible only to the sender and
4444
receiver (and anyone they choose to disclose to), but not to the public. Instead of executing transactions on-chain, user data like an account balance is
45-
updated locally, then submitted to the chain encrypted, with client-side ZK
46-
proving to ensure the encrypted updates are correct.
45+
updated locally, then submitted to the chain encrypted, with client-side zero-knowledge (ZK)
46+
proving to ensure the encrypted updates are correct.
4747

4848
But this means there's no RPC that can tell you what your balance is, as that
4949
information is visible only to you. So Penumbra is designed to enable
@@ -56,7 +56,7 @@ ultralight node.
5656

5757
### Wallets, Accounts, Addresses
5858

59-
On a transparent chain, each signing key controls one account with one address.
59+
On a transparent chain, each signing key typically controls one account with one address.
6060
This means that giving out an address doesn't just let someone send you funds.
6161
It also means giving them the ability to view all of your token balances and all
6262
of your past and future transaction history.

public/images/dex-batch-execution.png

270 KB
Loading
57.7 KB
Loading

public/images/dex-optimal-routing.png

265 KB
Loading

public/images/dex-swap-claim.png

191 KB
Loading

0 commit comments

Comments
 (0)