Skip to content

Commit 8983b25

Browse files
authored
fix: tvl and staking (#17173)
1 parent 6a1f8a8 commit 8983b25

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

projects/obyte-city/index.js

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,45 @@
77
const {
88
getBalances,
99
fetchOswapExchangeRates,
10-
fetchOswapAssets,
1110
getDecimalsByAsset,
11+
executeGetter,
12+
getAaStateVars,
1213
} = require('../helper/chain/obyte')
1314

1415
const CITY_AA_ADDRESS = 'CITYC3WWO5DD2UM6HQR3H333RRTD253Q'
16+
const GBYTE_DECIMALS = 9;
1517

1618
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', []),
1929
fetchOswapExchangeRates(),
20-
getBalances([CITY_AA_ADDRESS]).then((balances) => balances[CITY_AA_ADDRESS])
30+
getAaStateVars(CITY_AA_ADDRESS, 'constants').then(vars => vars?.constants)
2131
]);
2232

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);
3534

36-
await Promise.all(decimalGetters);
35+
const price = exchangeRates[`${constants.asset}_USD`];
36+
const staked = price * (depositedSupply / 10 ** decimals);
3737

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 }
5139
}
5240

41+
5342
module.exports = {
5443
timetravel: false,
5544
misrepresentedTokens: true,
5645
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.",
5847
obyte: {
59-
tvl: () => ({}),
60-
staking: totalTvl,
48+
tvl: totalTvl,
49+
staking: totalStaking,
6150
}
6251
}

0 commit comments

Comments
 (0)