Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: REST api exposing DEX and lending TVLs #1596

Closed
bvotteler opened this issue Oct 30, 2023 · 0 comments · Fixed by #1605
Closed

Feat: REST api exposing DEX and lending TVLs #1596

bvotteler opened this issue Oct 30, 2023 · 0 comments · Fixed by #1605
Assignees
Labels
enhancement New feature or request prio:high

Comments

@bvotteler
Copy link
Contributor

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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request prio:high
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant