-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* orai: add amm-v3 info * orai: calculate tvl dex v3 from on-chain data instead of from indexer * orai: disabled no-constant-condition for while true * code refactor --------- Co-authored-by: trungbach <[email protected]>
- Loading branch information
Showing
2 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const { sumTokens, sumCW20Tokens, queryContract } = require('../helper/chain/cosmos') | ||
const { getUniqueAddresses } = require('../helper/utils') | ||
|
||
const AMM_V3_CONTRACT = "orai10s0c75gw5y5eftms5ncfknw6lzmx0dyhedn75uz793m8zwz4g8zq4d9x9a" | ||
|
||
const isNativeToken = denom => !denom.startsWith("orai1") | ||
|
||
async function tvl(api) { | ||
const CHUNK_SIZE = 100 | ||
const pools = [] | ||
let hasMore = true | ||
|
||
while (hasMore) { | ||
const startAfter = pools.length == 0 ? undefined : pools[pools.length - 1].pool_key | ||
const res = await queryContract({ | ||
chain: api.chain, | ||
contract: AMM_V3_CONTRACT, | ||
data: { pools: { limit: CHUNK_SIZE, startAfter } } | ||
}) | ||
|
||
pools.push(...res) | ||
hasMore = res.length === CHUNK_SIZE | ||
} | ||
|
||
let cw20Tokens = pools.map(pool => [pool.pool_key.token_x, pool.pool_key.token_y]).flat().filter(token => !isNativeToken(token)) | ||
cw20Tokens = getUniqueAddresses(cw20Tokens, true) | ||
|
||
await sumTokens({ owner: AMM_V3_CONTRACT, api, }) | ||
return sumCW20Tokens({ api, tokens: cw20Tokens, owner: AMM_V3_CONTRACT }) | ||
} | ||
|
||
module.exports = { | ||
timetravel: false, | ||
methodology: "Liquidity on pool V3", | ||
orai: { tvl } | ||
} |