Skip to content

Commit a53dc56

Browse files
✨ feat: add interest protocol sui stable swap (DefiLlama#14280)
1 parent 1ecb3b7 commit a53dc56

File tree

1 file changed

+42
-0
lines changed
  • projects/interest-protocol-stable-swap

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const sui = require("../helper/chain/sui")
2+
3+
const PACKAGE_ID = '0x50052aca3d7b971bd9824e1bb151748d03870adfe3ba06dce384d2a77297c719';
4+
5+
const POW_9 = 1_000_000_000n;
6+
7+
function normalizeAddress(
8+
value,
9+
forceAdd0x = true,
10+
) {
11+
let address = value.toLowerCase();
12+
if (!forceAdd0x && address.startsWith('0x')) {
13+
address = address.slice(2);
14+
}
15+
return `0x${address.padStart(32 * 2, '0')}`;
16+
}
17+
18+
const tvl = async (api) => {
19+
const newPoolEvents = await sui.queryEvents({
20+
eventType: `${PACKAGE_ID}::event_wrapper::InterestStableSwapEvent<${PACKAGE_ID}::events::NewPool>`
21+
});
22+
23+
const statesIds = newPoolEvents.map(
24+
(event) => event.pos0.state
25+
);
26+
27+
const states = await sui.getObjects(statesIds);
28+
29+
states.forEach((state) => {
30+
state.fields.coins.forEach((typeName, index) => {
31+
const [package, module, otw] = typeName.fields.name.split('::')
32+
api.add(`${normalizeAddress(package)}::${module}::${otw}`, BigInt(state.fields.balances[index]) / POW_9);
33+
});
34+
});
35+
}
36+
37+
module.exports = {
38+
timetravel: false,
39+
sui: {
40+
tvl,
41+
},
42+
}

0 commit comments

Comments
 (0)