|
| 1 | +/* |
| 2 | + * Obyte City — A community engagement space for Obyte |
| 3 | + * A community engagement space where Obyte community members establish closer |
| 4 | + * connections with each other and receive rewards after becoming neighbors in the City |
| 5 | + * @see https://city.obyte.org |
| 6 | + */ |
| 7 | +const { |
| 8 | + getBalances, |
| 9 | + fetchOswapExchangeRates, |
| 10 | + fetchOswapAssets, |
| 11 | + getDecimalsByAsset, |
| 12 | +} = require('../helper/chain/obyte') |
| 13 | + |
| 14 | +const CITY_AA_ADDRESS = 'CITYC3WWO5DD2UM6HQR3H333RRTD253Q' |
| 15 | + |
| 16 | +async function totalTvl() { |
| 17 | + const [assetMetadata, exchangeRates, balances] = await Promise.all([ |
| 18 | + fetchOswapAssets(), |
| 19 | + fetchOswapExchangeRates(), |
| 20 | + getBalances([CITY_AA_ADDRESS]).then((balances) => balances[CITY_AA_ADDRESS]) |
| 21 | + ]); |
| 22 | + |
| 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 | + }); |
| 35 | + |
| 36 | + await Promise.all(decimalGetters); |
| 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 } |
| 51 | +} |
| 52 | + |
| 53 | +module.exports = { |
| 54 | + timetravel: false, |
| 55 | + misrepresentedTokens: true, |
| 56 | + methodology: |
| 57 | + "The TVL is the total USD-value of funds locked in the agent of the CITY platform", |
| 58 | + obyte: { |
| 59 | + tvl: () => ({}), |
| 60 | + staking: totalTvl, |
| 61 | + } |
| 62 | +} |
0 commit comments