Defi Llama

Levana is currently indexed on DefiLlama for both TVL and Volume. These are completely separate repositories with different considerations.

TVL

TVL is calculated as the wallet balance of a market contract, and the only funds that market contracts allow depositing are collateral tokens.

Therefore, the process for calculating TVL is ultimately:

  1. For each market, get the balance in collateral
  2. Convert from collateral to USD
  3. Sum it all up

This needs to be done from the DefiLlama tool and Perps tool, then the final values can be compared.

If there is a significant discrepency between DefiLlama and Perps, then the next step is debugging, which requires reporting the specific per-market logs to a developer.

Running the Levana TVL calculation tool

in the levana-perps repo:

cargo run --bin perps-deploy util tvl-report ~/Downloads/tvl-report.csv

(of course, you may want a different file output than "~/Downloads/tvl-report.csv", adjust accordingly)

This will write a CSV log of each market's TVL as both collateral and USD

Running the DefiLlama TVL calculation tool

The DefiLlama tool is meant to be used by their indexer and does not support inherent debugging.

Therefore, we maintain a debug branch of our fork

After cloning that, run the test tool just like in the main README:

node test.js projects/levana/index.js

In addition to the usual DefiLlama info, this will log out additional debug data, including the collateral balance per market and USD balance per market. The collateral balance will not have decimal places, as they are in the raw wallet units.

The action item is typically to compare this output to the Perps tool, and note any major differences.

Here's an example comparing the two for ETH_USD on SEI:

alt text

vs.

alt text

(it would be nice to update these logs to also write to a CSV, to make some comparisons easier. As of this writing, that remains to be done).

There will likely be some difference, due to the inherent difference between Pyth prices and DefiLlama prices (in fact, for Pyth alone, there is a significant difference between the regular price and the ema/averaged price).

The following is optional and not typically required for support engineer reports

In case there seems to be some massive difference in USD price, the DefiLlama USD price can be queried directly.

In order to construct the url, the denom must be taken from the "market to denom" mapping, and then appended with the chain name and separated by commas.

For example, if SEI_USD has the denom of "usei" and ETH_USD has the denom of "factory:sei189adguawugk3e55zn63z8r9ll29xrjwca636ra7v7gxuzn98sxyqwzt47l:4tLQqCLaoKKfNFuPjA9o39YbKUwhR1F8N29Tz3hEbfP2"

then the USD price query on DefiLlama becomes:

https://coins2.llama.fi/prices/current/sei:usei,sei:factory:sei189adguawugk3e55zn63z8r9ll29xrjwca636ra7v7gxuzn98sxyqwzt47l:4tLQqCLaoKKfNFuPjA9o39YbKUwhR1F8N29Tz3hEbfP2

Volume

The approach for Volume is theoretically similar to that of TVL, however in this case there is no native chain querying - both the Perps frontend and the DefiLlama tooling hit the same indexer endpoint.

That said, the DefiLlama tool doesn't necessarily use "now" for the timestamp, and it also doesn't log each output per-market.

Therefore, we maintain a debug branch of our fork

After cloning that, run the test tool just like in the main README:

yarn run test dexs levana

(note - you may need to use npm instead and edit the test command in package.json... this change is not checked into the repo, however)

This will log out the per-market volume and total market volume, alongside the final DefiLlama summary.

The action item is typically to compare this output to the Perps frontend, and note any major differences.

Here's an example comparing the total volumes for all markets on SEI:

alt text

vs.

alt text

and another example comparing just the ETH_USD markets on SEI:

alt text

vs.

alt text