Skip to content

Commit 5ea290e

Browse files
authored
update Rain TVL (DefiLlama#9712)
* Updated the IDL and added another way to get the collateralized amounts and currency. * Hello! I Updated the IDL and added another way to get the collateralized amounts and currency * fixed Marketplace type missing * Added missing fields * fix missing bs58 * last fix hopefully
1 parent 3fcdd06 commit 5ea290e

File tree

2 files changed

+225
-19
lines changed

2 files changed

+225
-19
lines changed

projects/rain/idl.js

Lines changed: 206 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,140 @@ module.exports = {
55
"instructions": [],
66
"accounts": [
77
{
8-
"name": "assetManager",
8+
"name": "loan",
99
"type": {
1010
"kind": "struct",
1111
"fields": [
1212
{
13-
"name": "currencyIn",
13+
"name": "kind",
14+
"type": {
15+
"defined": "LoanKind"
16+
}
17+
},
18+
{
19+
"name": "status",
20+
"type": {
21+
"defined": "LoanStatus"
22+
}
23+
},
24+
{
25+
"name": "borrower",
1426
"type": "publicKey"
1527
},
1628
{
17-
"name": "currencyOut",
29+
"name": "lender",
1830
"type": "publicKey"
1931
},
2032
{
21-
"name": "pythInFeed",
33+
"name": "pool",
2234
"type": "publicKey"
2335
},
2436
{
25-
"name": "pythOutFeed",
37+
"name": "mint",
2638
"type": "publicKey"
2739
},
2840
{
29-
"name": "totalAmountTokenized",
41+
"name": "currency",
42+
"type": "publicKey"
43+
},
44+
{
45+
"name": "isCustom",
46+
"type": "bool"
47+
},
48+
{
49+
"name": "isFrozen",
50+
"type": "bool"
51+
},
52+
{
53+
"name": "price",
3054
"type": "u64"
3155
},
3256
{
33-
"name": "currentAmountTokenized",
57+
"name": "interest",
3458
"type": "u64"
3559
},
60+
{
61+
"name": "amount",
62+
"type": "u64"
63+
},
64+
{
65+
"name": "duration",
66+
"type": "u64"
67+
},
68+
{
69+
"name": "collection",
70+
"type": "u32"
71+
},
72+
{
73+
"name": "liquidation",
74+
"type": "u16"
75+
},
76+
{
77+
"name": "marketplace",
78+
"type": {
79+
"defined": "Marketplace"
80+
}
81+
},
82+
{
83+
"name": "sale",
84+
"type": {
85+
"defined": "Sale"
86+
}
87+
},
3688
{
3789
"name": "createdAt",
3890
"type": "u64"
3991
},
4092
{
41-
"name": "updatedAt",
93+
"name": "expiredAt",
94+
"type": "u64"
95+
},
96+
{
97+
"name": "repaidAt",
98+
"type": "u64"
99+
},
100+
{
101+
"name": "soldAt",
102+
"type": "u64"
103+
},
104+
{
105+
"name": "liquidatedAt",
106+
"type": "u64"
107+
},
108+
{
109+
"name": "listing",
110+
"type": {
111+
"defined": "Listing"
112+
}
113+
},
114+
{
115+
"name": "isCompressedLoan",
116+
"type": "bool"
117+
},
118+
{
119+
"name": "isDefi",
120+
"type": "bool"
121+
},
122+
{
123+
"name": "collateralAmount",
42124
"type": "u64"
43125
},
126+
{
127+
"name": "collateralDecimals",
128+
"type": "u8"
129+
},
44130
{
45131
"name": "padding",
46132
"type": {
47133
"array": [
48134
"u64",
49-
31
135+
5
50136
]
51137
}
52138
},
53139
{
54-
"name": "totalAmountLiquidated",
55-
"type": "u64"
140+
"name": "padding1",
141+
"type": "u32"
56142
}
57143
]
58144
}
@@ -213,6 +299,40 @@ module.exports = {
213299
},
214300
],
215301
"types": [
302+
{
303+
"name": "LoanKind",
304+
"type": {
305+
"kind": "enum",
306+
"variants": [
307+
{
308+
"name": "Loan"
309+
},
310+
{
311+
"name": "Mortgage"
312+
}
313+
]
314+
}
315+
},
316+
{
317+
"name": "LoanStatus",
318+
"type": {
319+
"kind": "enum",
320+
"variants": [
321+
{
322+
"name": "Ongoing"
323+
},
324+
{
325+
"name": "Repaid"
326+
},
327+
{
328+
"name": "Liquidated"
329+
},
330+
{
331+
"name": "Sold"
332+
}
333+
]
334+
}
335+
},
216336
{
217337
"name": "Curve",
218338
"type": {
@@ -350,7 +470,80 @@ module.exports = {
350470
]
351471
}
352472
},
473+
{
474+
"name": "Marketplace",
475+
"type": {
476+
"kind": "enum",
477+
"variants": [
478+
{
479+
"name": "None"
480+
},
481+
{
482+
"name": "Auctionhouse"
483+
},
484+
{
485+
"name": "Solanart"
486+
},
487+
{
488+
"name": "Hyperspace"
489+
},
490+
{
491+
"name": "Yaww"
492+
},
493+
{
494+
"name": "Hadeswap"
495+
},
496+
{
497+
"name": "Rain"
498+
},
499+
{
500+
"name": "TensorswapOrder"
501+
},
502+
{
503+
"name": "TensorswapListing"
504+
},
505+
{
506+
"name": "MagicEden"
507+
}
508+
]
509+
}
510+
},
511+
{
512+
"name": "Sale",
513+
"type": {
514+
"kind": "struct",
515+
"fields": [
516+
{
517+
"name": "isForSale",
518+
"type": "bool"
519+
},
520+
{
521+
"name": "salePrice",
522+
"type": "u64"
523+
},
524+
{
525+
"name": "currency",
526+
"type": "publicKey"
527+
}
528+
]
529+
}
530+
},
531+
{
532+
"name": "Listing",
533+
"type": {
534+
"kind": "struct",
535+
"fields": [
536+
{
537+
"name": "isListed",
538+
"type": "bool"
539+
},
540+
{
541+
"name": "price",
542+
"type": "u64"
543+
}
544+
]
545+
}
546+
}
353547
],
354548
"errors": []
355-
}
356-
549+
}

projects/rain/index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
const { Program } = require("@project-serum/anchor");
2+
const bs58 = require('bs58');
23
const { getProvider } = require("../helper/solana");
34
const idl = require('./idl')
45

56
async function tvl(api) {
67
const provider = getProvider()
7-
const rainProgram = new Program(idl, 'RainEraPU5yDoJmTrHdYynK9739GkEfDsE4ffqce2BR', provider)
8-
const tokenizerProgram = new Program(idl, 'RtokEFPPbXqDrzAHJHt16fwN6hZmepfPpSvW7y47g5r', provider)
8+
const program = new Program(idl, 'RainEraPU5yDoJmTrHdYynK9739GkEfDsE4ffqce2BR', provider)
99

10-
const pools = await rainProgram.account.pool.all()
11-
const assetManagers = await tokenizerProgram.account.assetManager.all()
10+
const pools = await program.account.pool.all()
11+
const loans = await program.account.loan.all([
12+
{
13+
memcmp: {
14+
offset: 294 + 8,
15+
bytes: bs58.encode(Buffer.from([1])), // tokens loans only
16+
},
17+
},
18+
{
19+
memcmp: {
20+
offset: 8 + 1,
21+
bytes: bs58.encode(Buffer.from([0])), // active loans only
22+
},
23+
},
24+
])
1225

13-
for (const assetManager of assetManagers) {
14-
api.add(assetManager.account.currencyIn.toString(), assetManager.account.currentAmountTokenized)
26+
for (const loan of loans) {
27+
api.add(loan.account.mint.toString(), loan.account.collateralAmount)
1528
}
1629

1730
for (const pool of pools)

0 commit comments

Comments
 (0)