Skip to content

Commit 4dce370

Browse files
committed
Add draft Torus CAD
1 parent 130804c commit 4dce370

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Convex Architecture Documents (CADs) are defined for standards relating to the C
4343
| [CAD027](cad/027_log) | Event Logging | Draft | mikera
4444
| [CAD028](cad/028_dlfs) | Data Lattice File System | Draft | mikera
4545
| [CAD029](cad/029_fungible) | Fungible Token Standard | Draft | mikera
46+
| [CAD030](cad/030_torus) | Torus DEX | Draft | mikera
4647

4748
## Convex Project Repositories
4849

cad/030_torus/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Torus DEX
2+
3+
Torus is a decentralised exchange (DEX) built on Convex. It is an open source actor that operates by facilitating smart contract interactions between:
4+
- Liquidity providers, who earn commission on trades
5+
- Traders who wish to swap fungible tokens
6+
7+
## Specification
8+
9+
### Torus actor
10+
11+
The Torus actor is the actor that manages all Torus DEX markets and provides user functionality.
12+
13+
Use of the library is typically achieved by importing the Torus actor as a library:
14+
15+
```clojure
16+
(import exchange.torus :as torus)
17+
```
18+
19+
### Markets
20+
21+
Torus maintains a market for each fungible token that users wish to exchange.
22+
23+
Markets are created on demand when the first user requests creation:
24+
25+
```clojure
26+
(torus/create-market token-id)
27+
=> #678
28+
```
29+
30+
A new market is a deployed actor that implements the Torus market SPI. Initially the market will have zero liquidity (this may be added by liquidity providers later).
31+
32+
If a second user requests creation of a market after it is already created, the original market is returned and no new market is deployed.
33+
34+
Subsequently, the address of a market can be accessed with the `get-market` function:
35+
36+
```clojure
37+
(torus/get-market token-id)
38+
=> #678
39+
```
40+
41+
If no market exists for a fungible asset, `get-market` returns `nil`.
42+
43+
### Convex Coin Liquidity
44+
45+
Each active Torus market MUST contain Convex Coins in the liquidity pool, of equal value to the CAD29 fungible token being traded.
46+
47+
We use Convex Coins as the common pairing for each fungible token because:
48+
- This enables swaps between any two CAD29 tokens with just two swaps, avoiding the need to create a market for every possible fungible token pair.
49+
- Convex Coins generally make sense to hold as an asset for ecosystem participants
50+
- It provides an additional opportunity to earn a return on Convex Coins
51+
52+
### Adding and withdrawing liquidity
53+
54+
A prospective liquidity provide MAY add liquidity to a market at any time with the `torus/add-liquidity` function.
55+
56+
```clojure
57+
;; Add initial liquidity with Convex quantity
58+
;; This is necessary for the initial liquidity provided
59+
(torus/add-liquidity token-id token-quantity convex-quantity)
60+
61+
;; Add liquidity with token quantity only
62+
;; (will infer Convex quantity from current price)
63+
(torus/add-liquidity token-id token-quantity)
64+
```
65+
66+
If successful, `add-liquidity` will return with a integer equal to the number of liquidity shares gained by the liquidity provider.
67+
68+
The attempt to add liquidity will fail if the user has insufficient Convex coins or tokens to provide the liquidity.
69+
70+
If the market does not already exist, one will be created as if `create-market` was used.
71+
72+
73+
74+
### TODO more specification
75+
76+
77+

0 commit comments

Comments
 (0)