Skip to content

Commit e57d8ce

Browse files
gguuttssg1nt0ki
andauthored
Add STAB Protocol adapter (DefiLlama#12218)
Co-authored-by: g1nt0ki <[email protected]>
1 parent 92dc1ca commit e57d8ce

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

projects/stab-protocol/index.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const ADDRESSES = require('../helper/coreAssets.json')
2+
3+
const { queryAddresses, sumTokens } = require('../helper/chain/radixdlt');
4+
5+
const STAB_COMPONENT = "component_rdx1cq70cjajtvllgk9z9wm9l8v6w8hsgtlw530cdgpraxprn4yevg89kf";
6+
const STAB_XRD_POOL_XRD_VAULT = "internal_vault_rdx1trk04c3sxffatj5h78w3266c8q07cvjlgq0zx44sask8wsam4q8rup";
7+
const ORACLE_COMPONENT = "component_rdx1cq7zsdqfh0mcwnutrevkz6wtml0vnav5fcmtf7rksmhk48urkyjg9c";
8+
9+
async function tvl(api) {
10+
//get the token amounts of collaterals used in the STAB Protocol
11+
const stabComponentTokens = await sumTokens({ owners: [STAB_COMPONENT], api })
12+
const xrdAmount = stabComponentTokens['radixdlt:resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd']
13+
const lsuLpAmount = stabComponentTokens['radixdlt:resource_rdx1thksg5ng70g9mmy9ne7wz0sc7auzrrwy7fmgcxzel2gvp8pj0xxfmf']
14+
15+
//calculate value of LSULP against XRD to get accurate price data
16+
const [{ details: { state } }] = await queryAddresses({ addresses: [ORACLE_COMPONENT] } )
17+
const xrdPrice = state.fields[0].elements[0].fields[1].value
18+
const lsuLpPrice = state.fields[0].elements[1].fields[1].value
19+
const lsuLpMultiplier = lsuLpPrice / xrdPrice
20+
21+
//add XRD and LSULP values to tvl
22+
api.add('resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd', xrdAmount + lsuLpAmount * lsuLpMultiplier)
23+
24+
//get the amount of XRD in the protocol native STAB/XRD pool (with 50/50 weights)
25+
const stabXrdPoolXrdVault = await queryAddresses({ addresses: [STAB_XRD_POOL_XRD_VAULT] });
26+
const xrdAmountPool = stabXrdPoolXrdVault[0].details.balance.amount;
27+
28+
//add only XRD value of pool to tvl (STAB value is excluded as backing of STAB tokens are already included in tvl)
29+
api.add('resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd', xrdAmountPool)
30+
}
31+
32+
module.exports = {
33+
methodology: 'Calculates TVL using the amount of collateral locked to borrow STAB using CDPs, and amount of STAB and XRD locked in the protocol-native STAB/XRD pool.',
34+
radixdlt: { tvl },
35+
misrepresentedTokens: true,
36+
timetravel: false,
37+
};

0 commit comments

Comments
 (0)