Skip to content

Commit 19a20ca

Browse files
added tvl adapter for dnax project (#17005)
1 parent c90b31a commit 19a20ca

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

projects/dnax/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { sumTokens2, nullAddress } = require('../helper/unwrapLPs')
2+
3+
const VAULT = '0xafc43faE32302D725fC4d448525c44c522a9a1B9'
4+
const NATIVE_PLACEHOLDER = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
5+
6+
const pairsAbi = 'function pairs() external view returns (address[2][])'
7+
8+
module.exports = {
9+
methodology: 'Reads the DNAX vault `pairs` list, then sums the balances of every listed token plus native BNB held by the vault.',
10+
bsc: {
11+
tvl: async (api) => {
12+
const pairs = await api.call({ target: VAULT, abi: pairsAbi })
13+
const tokenSet = new Set()
14+
15+
pairs.forEach(([token0, token1]) => {
16+
if (token0) tokenSet.add(formatToken(token0))
17+
if (token1) tokenSet.add(formatToken(token1))
18+
})
19+
20+
tokenSet.delete(undefined)
21+
22+
return sumTokens2({
23+
api,
24+
owner: VAULT,
25+
tokens: Array.from(tokenSet),
26+
permitFailure: true,
27+
})
28+
},
29+
},
30+
}
31+
32+
function formatToken(token) {
33+
const normalized = token.toLowerCase()
34+
if (normalized === NATIVE_PLACEHOLDER) return nullAddress
35+
if (normalized === '0x0000000000000000000000000000000000000000') return nullAddress
36+
return normalized
37+
}
38+

0 commit comments

Comments
 (0)