@@ -8,9 +8,9 @@ Torus is a decentralised exchange (DEX) built on Convex. It is an open source ac
8
8
9
9
### Torus actor
10
10
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.
12
12
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 :
14
14
15
15
``` clojure
16
16
(import exchange.torus :as torus)
@@ -40,13 +40,59 @@ Subsequently, the address of a market can be accessed with the `get-market` func
40
40
41
41
If no market exists for a fungible asset, ` get-market ` returns ` nil ` .
42
42
43
- ### Convex Coin Liquidity
43
+ ### Trades
44
44
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.
46
92
47
93
We use Convex Coins as the common pairing for each fungible token because:
48
94
- 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
50
96
- It provides an additional opportunity to earn a return on Convex Coins
51
97
52
98
### Adding and withdrawing liquidity
@@ -63,15 +109,21 @@ A prospective liquidity provide MAY add liquidity to a market at any time with t
63
109
(torus/add-liquidity token-id token-quantity)
64
110
```
65
111
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.
67
113
68
114
The attempt to add liquidity will fail if the user has insufficient Convex coins or tokens to provide the liquidity.
69
115
70
116
If the market does not already exist, one will be created as if ` create-market ` was used.
71
117
72
118
73
119
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
75
127
76
128
77
129
0 commit comments