You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 4-portfolio-management-yield-farming/indexer/README.md
+37-17Lines changed: 37 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Indexer
2
2
3
-
Indexer allows anyone to easily create their own index fund, utilizing resources created on the Radix network. Once a index fund is created, anyone can invest in the fund. Each time someone deposits XRD into the newly created index fund, the XRD is equally split across each token making up the index fund and the depositor receives Indexer Tokens. The Indexer Token is similar to an LP token and keep track of % ownership of the index fund.
3
+
Indexer allows anyone to easily create their own index fund, utilizing resources created on the Radix network. Once a index fund is created, anyone can invest in the fund. Each time someone deposits XRD into the newly created index fund, the XRD is equally split across each token making up the index fund and the depositor receives Indexer Tokens. The Indexer Token is similar to an LP token and keeps track of % ownership of the index fund.
4
4
5
5
## Features
6
6
@@ -10,15 +10,15 @@ Indexer allows anyone to easily create their own index fund, utilizing resources
10
10
11
11
## Design Details
12
12
13
-
A index fund may be created by choosing individual resources to make up the index fund. The XRD token will need to be apart of the index fund. The individual tokens that make up the index fund are stored in vaults. When users deposit XRD into the index fund, the XRD is split evenly across each token making up the index fund. The protocol automatically take the XRD and swaps them to each resource that make up the index fund.
13
+
A index fund may be created by choosing individual resources to make up the index fund. The XRD token will need to be apart of the index fund. The individual tokens that make up the index fund are stored in vaults. When users deposit XRD into the index fund, the XRD is split evenly across each token making up the index fund. The protocol automatically takes the XRD and swaps them into each resource that makes up the index fund.
14
14
15
-
Users will receive Indexer Tokens, which keeps track of % ownership of the index fund. The protocol mints and burns Indexer Tokens when users deposit or redeem their Indexer Tokens. The amount of Indexer Tokens that are minted are based on the amount of XRD divided across the number of index pools. For example, say you invest 1000 XRD into a index fund consisting of 10 tokens. Each token index would receive 100 XRD worth of tokens. 100 Indexer tokens would be minted. 100 XRD tokens will be swapped for each resource that makes up the index fund and deposited in their vaults.
15
+
Users will receive Indexer Tokens, which keeps track of % ownership of the index fund. The protocol mints and burns Indexer Tokens when users deposit or redeem their Indexer Tokens. The amount of Indexer Tokens that are minted are based on the amount of XRD divided across the number of index pools. For example, say you invest 1000 XRD into a index fund consisting of 10 tokens. Each token index would receive 100 XRD worth of tokens. 100 Indexer Tokens would be minted. 100 XRD tokens will be swapped for each resource that makes up the index fund and deposited in their vaults.
16
16
17
-
When users redeem their Indexer Tokens, an equal number of XRD worth of tokens will be taken from each index pool. Continuing with the same example above, the user presents 100 Indexer Tokens for redemption. 100 XRD worth of tokens will be taken from each index pool swapped for XRD and returned to the user. The user will receive their portion of fees generated from arbitrage and flash loans.
17
+
When users redeem their Indexer Tokens, an equal number of XRD worth of tokens will be taken from each index pool. Continuing with the same example above, the user presents 100 Indexer Tokens for redemption. 100 XRD worth of tokens will be taken from each index pool swapped to XRD and returned to the user. The user will receive their portion of fees generated from arbitrage and flash loans.
18
18
19
19
## Getting Started
20
20
21
-
1. Lets start off by creating 4 new accounts so we can test our index fund.
21
+
1. Lets start off by creating 4 new accounts so we can test the Indexer Protocal.
4. We can now publish the Indexer package and also instantiate a new Indexer, Ociswap, and Oracle component by running the following commands:
69
-
We are saving the component addresses for each bluprints and the Indexer Token resource address to variables.
68
+
4. We can now publish the Indexer package and also instantiate a new Indexer, Ociswap, RaDEX, Oracle1, and Oracle2 component by running the following commands:
69
+
We are exporting the component addresses for each blueprint and the Indexer Token resource address to variables.
@@ -155,7 +155,7 @@ resim call-method $RADEX_COMPONENT add_liquidity 1000000,$QUANT
155
155
resim call-method $RADEX_COMPONENT add_liquidity 50000,$XRD
156
156
```
157
157
158
-
7. Lets set some price for the Oracle component. Note the prices for Oracle2 are set slightly lower.
158
+
7. Lets set some price for the Oracle component. Note the prices for Oracle2 are set slightly lower. We will use this to demonstrate an arbitrage trade.
159
159
160
160
```sh
161
161
resim call-method $ORACLE1_COMPONENT set_price $BITCOIN 21300
@@ -181,8 +181,7 @@ resim call-method $ORACLE2_COMPONENT set_price $QUANT 100
181
181
resim call-method $ORACLE2_COMPONENT set_price $XRD .6
182
182
```
183
183
184
-
8. Now we need to add the Ociswap and Oracle component address to the Indexer component and add the Oracle
185
-
component address to the Ociswap component.
184
+
8. Now we need to add the Ociswap, RaDEX, Oracle1, and Oracle2 component address to the Indexer component, add the Oracle1 component address to the Ociswap component, and Oracle2 component address to the RaDEX component.
186
185
187
186
```sh
188
187
resim call-method $INDEXER_COMPONENT oci_address $OCI_COMPONENT
@@ -193,7 +192,7 @@ resim call-method $OCI_COMPONENT oracle1_address $ORACLE1_COMPONENT
193
192
resim call-method $RADEX_COMPONENT oracle2_address $ORACLE2_COMPONENT
194
193
```
195
194
196
-
9. Now we can finally create our custom index fund. We will add 10 tokens to out index fund.
195
+
9. Now we can finally create our custom index fund. We will add 10 tokens to our index fund.
197
196
198
197
```sh
199
198
resim call-method $INDEXER_COMPONENT create_index_pool $BITCOIN
@@ -225,7 +224,7 @@ resim call-method $INDEXER_COMPONENT deposit 30000,$XRD
225
224
resim call-method $INDEXER_COMPONENT show_index_pool
226
225
```
227
226
228
-
12. Lets generate some yield using the index pool tokens and performing arbitrage on tokens trading at a discount on Radex. We will sell the tokens on Ociswap and buy them back cheaper on Radex.
227
+
12. Lets generate some yield using the index pool tokens and performing arbitrage trades with tokens trading at a discount on RaDEX. We will sell the tokens on Ociswap and buy them back cheaper on RaDEX.
229
228
230
229
```sh
231
230
resim call-method $INDEXER_COMPONENT arb_oci_radex $LITECOIN
@@ -253,11 +252,32 @@ resim set-default-account $ACC_ADDRESS2 $PRIV_KEY2
253
252
resim call-method $INDEXER_COMPONENT withdraw 1000,$INDEXER_TOKEN
254
253
```
255
254
256
-
15. Lets check the account balance of accounts 2, 3, and 4. Each account balance starts with 1 million XRD. Anything in addition to this amount represents the fees accrued. The fees accrued are proportional to the initial amount deposited by accounts 2, 3, and 4. Account 4 fees accrued should be equal to the sum of account 2 and 3 accrued, Account 3 fees accrued should be double that of Account 2.
255
+
15. Lets check the account balance of accounts 2, 3, and 4. Each account balance starts with 1 million XRD. Anything in addition to this amount represents the fees accrued. The fees accrued are proportional to the initial amount deposited by accounts 2, 3, and 4. Account 4 accrued fees should be equal to the sum of account 2 and 3 accrued fees. Account 3 accrued fees should be double that of Account 2.
257
256
258
257
```sh
259
258
resim show $ACC_ADDRESS2
260
259
resim show $ACC_ADDRESS3
261
260
resim show $ACC_ADDRESS4
262
261
```
263
262
263
+
16. Useful methods...
264
+
265
+
16.1 Show token balances in index pools
266
+
267
+
```sh
268
+
resim call-method $INDEXER_COMPONENT show_index_pool
269
+
```
270
+
271
+
16.2 Show token balance in Ociswap liquidity pools
272
+
273
+
```sh
274
+
resim call-method $OCI_COMPONENT show_liquidity_pool
275
+
```
276
+
277
+
16.3 Show token balanace in RaDEX liquidity pools
278
+
279
+
```sh
280
+
resim call-method $RADEX_COMPONENT show_liquidity_pool
0 commit comments