|
7 | 7 | const { |
8 | 8 | getBalances, |
9 | 9 | fetchOswapExchangeRates, |
10 | | - fetchOswapAssets, |
11 | 10 | getDecimalsByAsset, |
| 11 | + executeGetter, |
| 12 | + getAaStateVars, |
12 | 13 | } = require('../helper/chain/obyte') |
13 | 14 |
|
14 | 15 | const CITY_AA_ADDRESS = 'CITYC3WWO5DD2UM6HQR3H333RRTD253Q' |
| 16 | +const GBYTE_DECIMALS = 9; |
15 | 17 |
|
16 | 18 | async function totalTvl() { |
17 | | - const [assetMetadata, exchangeRates, balances] = await Promise.all([ |
18 | | - fetchOswapAssets(), |
| 19 | + return { tether: 0 } |
| 20 | +} |
| 21 | + |
| 22 | +async function totalStaking() { |
| 23 | + const [ |
| 24 | + depositedSupply, |
| 25 | + exchangeRates, |
| 26 | + constants |
| 27 | + ] = await Promise.all([ |
| 28 | + executeGetter(CITY_AA_ADDRESS, 'get_deposited_supply', []), |
19 | 29 | fetchOswapExchangeRates(), |
20 | | - getBalances([CITY_AA_ADDRESS]).then((balances) => balances[CITY_AA_ADDRESS]) |
| 30 | + getAaStateVars(CITY_AA_ADDRESS, 'constants').then(vars => vars?.constants) |
21 | 31 | ]); |
22 | 32 |
|
23 | | - const assetDecimals = {}; |
24 | | - const decimalGetters = []; |
25 | | - |
26 | | - Object.keys(balances).forEach((asset) => { |
27 | | - const decimals = assetMetadata[asset]?.decimals; |
28 | | - |
29 | | - if (decimals !== undefined) { |
30 | | - assetDecimals[asset] = decimals; |
31 | | - } else { |
32 | | - decimalGetters.push(getDecimalsByAsset(asset).then((decimals) => assetDecimals[asset] = decimals)) |
33 | | - } |
34 | | - }); |
| 33 | + const decimals = await getDecimalsByAsset(constants.asset); |
35 | 34 |
|
36 | | - await Promise.all(decimalGetters); |
| 35 | + const price = exchangeRates[`${constants.asset}_USD`]; |
| 36 | + const staked = price * (depositedSupply / 10 ** decimals); |
37 | 37 |
|
38 | | - let tvl = 0; |
39 | | - |
40 | | - Object.entries(balances).forEach(async ([asset, { stable: balance = 0 }]) => { |
41 | | - const assetKey = (asset === "base") ? "GBYTE" : asset; |
42 | | - const usdRate = exchangeRates[`${assetKey}_USD`] ?? 0; |
43 | | - const decimals = assetDecimals[asset]; |
44 | | - |
45 | | - if (decimals !== undefined) { |
46 | | - tvl += (balance / 10 ** decimals) * usdRate; |
47 | | - } |
48 | | - }); |
49 | | - |
50 | | - return { tether: tvl } |
| 38 | + return { tether: staked } |
51 | 39 | } |
52 | 40 |
|
| 41 | + |
53 | 42 | module.exports = { |
54 | 43 | timetravel: false, |
55 | 44 | misrepresentedTokens: true, |
56 | 45 | methodology: |
57 | | - "The TVL is the total USD-value of funds locked in the agent of the CITY platform", |
| 46 | + "The TVL is the total USD-value of GBYTE funds locked in the agent of the CITY platform. Staking represents the USD-value of deposited CITY tokens.", |
58 | 47 | obyte: { |
59 | | - tvl: () => ({}), |
60 | | - staking: totalTvl, |
| 48 | + tvl: totalTvl, |
| 49 | + staking: totalStaking, |
61 | 50 | } |
62 | 51 | } |
0 commit comments