Is your feature request related to a problem? Please describe.
We want to provide DEX and lending TVL values to DfiLlama who, in turn, need a REST api to query.
Describe the solution you'd like
We want to utilize the existing api structure the UI provides to expose TVL information (sourced by querying the lib) for external providers such as DefiLlama, Coingecko, etc.
Describe alternatives you've considered
We have considered adding tracking on squid. The downsides of that approach are:
1) duplication of logic already present in the lib/UI, and
2) we would still need a REST api wrapper somewhere for queries from external parties (they do not always support making graphql queries from their adapters).
Peter provided a feasible approach on Discord when explaining how TVL is calculated on the UI:
Actually, what we do to calculate total liquidity of DEX is:
1st fetch all liquidity pools from chain using lib amm.getLiquidityPools, this returns array of LiquidityPool objects, each of these contains pooledCurrencies field that contains amount of assets that are supplied in the pool. Then using these amounts and prices fetched on the UI side we use this simple reducer to get total amount in USD: https://github.com/interlay/interbtc-ui/blob/master/src/utils/helpers/pool.ts#L8
Now for the lending, I don't see any TVL displayed in the UI, but the similar approach as for the DEX can be applied:
1st fetch all loan assets (markets) from chain using lib loans.getLoanAssets, this returns map of (ticker => LoanAsset), where LoanAsset contains property totalLiquidity. Now applying the same approach as for the AMM and picking up the totalLiquidity, it's easy to get total lending liquidity value in USD.
Is your feature request related to a problem? Please describe. We want to provide DEX and lending TVL values to DfiLlama who, in turn, need a REST api to query.
Describe the solution you'd like We want to utilize the existing
api
structure the UI provides to expose TVL information (sourced by querying the lib) for external providers such as DefiLlama, Coingecko, etc.Describe alternatives you've considered We have considered adding tracking on squid. The downsides of that approach are: 1) duplication of logic already present in the lib/UI, and 2) we would still need a REST api wrapper somewhere for queries from external parties (they do not always support making graphql queries from their adapters).
Additional context Related issues:
Peter provided a feasible approach on Discord when explaining how TVL is calculated on the UI: