Skip to content

Commit 7a141bf

Browse files
committed
Torus CAD updates
1 parent 5705146 commit 7a141bf

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

cad/030_torus/README.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Torus is a decentralised exchange (DEX) built on Convex. It is an open source ac
88

99
### Torus actor
1010

11-
The Torus actor is the actor that manages all Torus DEX markets and provides user functionality.
11+
The Torus actor manages all Torus DEX markets and provides user functionality.
1212

13-
Use of the library is typically achieved by importing the Torus actor as a library:
13+
Users typically import the Torus actor as a library to make Torus functions available in their environment:
1414

1515
```clojure
1616
(import exchange.torus :as torus)
@@ -40,13 +40,59 @@ Subsequently, the address of a market can be accessed with the `get-market` func
4040

4141
If no market exists for a fungible asset, `get-market` returns `nil`.
4242

43-
### Convex Coin Liquidity
43+
### Trades
4444

45-
Each active Torus market MUST contain Convex Coins in the liquidity pool, of equal value to the CAD29 fungible token being traded.
45+
Any user may trade on a Torus market.
46+
47+
```clojure
48+
;; Assume a CAD token identified by TOKEN
49+
50+
;; Buy a 100 token quantity of a token
51+
(torus/buy-tokens TOKEN 100)
52+
53+
;; Sell 100 tokens
54+
(torus/sell-tokens TOKEN 100)
55+
56+
;; Buy 1000 CVX using the token
57+
(torus/buy-cvx TOKEN 1000)
58+
59+
;; Sell 1000 CVX, receiving the token
60+
(torus/sell-cvx TOKEN 1000)
61+
```
62+
63+
It is also possible to do swaps between any two tokens. These are atomic swaps that execute a Torus trade on both underlying markets.
64+
65+
```clojure
66+
;; Assume we have a second token named USD
67+
68+
;; Buy 200 TOKEN using USD
69+
(torus/buy TOKEN 200 USD)
70+
71+
;; Sell 300 TOKEN and receive USD
72+
(torus/sell TOKEN 300 USD)
73+
74+
```
75+
76+
Trades will fail if any of the following are true:
77+
- An attempt is made to buy or sell a negative quantity
78+
- The liquidity pool has insufficient liquidity to complete the trade
79+
- The user has insufficient funds (CVX or token) to complete the trade
80+
81+
### Liquidity Pool
82+
83+
Each Torus market holds a liquidity pool of two assets:
84+
- Convex Coins
85+
- The CAD29 fungible token that the market represents
86+
87+
Each active Torus market MUST have a positive Convex Coins in the liquidity pool.
88+
89+
Each active Torus market MUST own a positive balance of the CAD29 fungible token being traded.
90+
91+
The Torus market assumes the two asset quantities have equal value.
4692

4793
We use Convex Coins as the common pairing for each fungible token because:
4894
- 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
95+
- Convex Coins generally make sense to hold as a common asset for ecosystem participants
5096
- It provides an additional opportunity to earn a return on Convex Coins
5197

5298
### Adding and withdrawing liquidity
@@ -63,15 +109,21 @@ A prospective liquidity provide MAY add liquidity to a market at any time with t
63109
(torus/add-liquidity token-id token-quantity)
64110
```
65111

66-
If successful, `add-liquidity` will return with a integer equal to the number of liquidity shares gained by the liquidity provider.
112+
If successful, `add-liquidity` will return an integer equal to the number of liquidity shares gained by the liquidity provider.
67113

68114
The attempt to add liquidity will fail if the user has insufficient Convex coins or tokens to provide the liquidity.
69115

70116
If the market does not already exist, one will be created as if `create-market` was used.
71117

72118

73119

74-
### TODO more specification
120+
### Torus Market SPI
121+
122+
The Torus market SPI is usually not directly accessed by users: Torus functionality should be accessed by the `exchange.torus` library.
123+
124+
A Torus market MUST implement a CAD29 fungible token SPI so that its liquidity share function as a fungible token.
125+
126+
The Torus market SPI MAY change due to updates of Torus
75127

76128

77129

0 commit comments

Comments
 (0)