From e57d8cefff92346c8d766cdb481f8239f06ace3c Mon Sep 17 00:00:00 2001 From: Octopus <156575930+gguuttss@users.noreply.github.com> Date: Sat, 9 Nov 2024 12:59:29 +0100 Subject: [PATCH] Add STAB Protocol adapter (#12218) Co-authored-by: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> --- projects/stab-protocol/index.js | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 projects/stab-protocol/index.js diff --git a/projects/stab-protocol/index.js b/projects/stab-protocol/index.js new file mode 100644 index 0000000000..20e6b505c0 --- /dev/null +++ b/projects/stab-protocol/index.js @@ -0,0 +1,37 @@ +const ADDRESSES = require('../helper/coreAssets.json') + +const { queryAddresses, sumTokens } = require('../helper/chain/radixdlt'); + +const STAB_COMPONENT = "component_rdx1cq70cjajtvllgk9z9wm9l8v6w8hsgtlw530cdgpraxprn4yevg89kf"; +const STAB_XRD_POOL_XRD_VAULT = "internal_vault_rdx1trk04c3sxffatj5h78w3266c8q07cvjlgq0zx44sask8wsam4q8rup"; +const ORACLE_COMPONENT = "component_rdx1cq7zsdqfh0mcwnutrevkz6wtml0vnav5fcmtf7rksmhk48urkyjg9c"; + +async function tvl(api) { + //get the token amounts of collaterals used in the STAB Protocol + const stabComponentTokens = await sumTokens({ owners: [STAB_COMPONENT], api }) + const xrdAmount = stabComponentTokens['radixdlt:resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd'] + const lsuLpAmount = stabComponentTokens['radixdlt:resource_rdx1thksg5ng70g9mmy9ne7wz0sc7auzrrwy7fmgcxzel2gvp8pj0xxfmf'] + + //calculate value of LSULP against XRD to get accurate price data + const [{ details: { state } }] = await queryAddresses({ addresses: [ORACLE_COMPONENT] } ) + const xrdPrice = state.fields[0].elements[0].fields[1].value + const lsuLpPrice = state.fields[0].elements[1].fields[1].value + const lsuLpMultiplier = lsuLpPrice / xrdPrice + + //add XRD and LSULP values to tvl + api.add('resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd', xrdAmount + lsuLpAmount * lsuLpMultiplier) + + //get the amount of XRD in the protocol native STAB/XRD pool (with 50/50 weights) + const stabXrdPoolXrdVault = await queryAddresses({ addresses: [STAB_XRD_POOL_XRD_VAULT] }); + const xrdAmountPool = stabXrdPoolXrdVault[0].details.balance.amount; + + //add only XRD value of pool to tvl (STAB value is excluded as backing of STAB tokens are already included in tvl) + api.add('resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd', xrdAmountPool) +} + +module.exports = { + 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.', + radixdlt: { tvl }, + misrepresentedTokens: true, + timetravel: false, +};