Skip to content

Commit c0176aa

Browse files
deep-pathg1nt0ki
andauthored
remove anchor for add solana tvl (DefiLlama#12053)
Co-authored-by: g1nt0ki <[email protected]>
1 parent 91696d3 commit c0176aa

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

projects/deltatrade.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
const ADDRESSES = require('./helper/coreAssets.json')
2-
const { sumTokens } = require('./helper/chain/near');
2+
const { sumTokens } = require('./helper/chain/near')
3+
const { getConfig } = require('./helper/cache')
4+
const { get } = require('./helper/http')
5+
6+
const { PublicKey } = require('@solana/web3.js');
7+
const { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, } = require("@solana/spl-token");
8+
const { sumTokens2 } = require('./helper/solana')
9+
10+
const state = new PublicKey('FRcbUFpGHQppvXAyJrNYLKME1BQfowh4xKZB2vt9j6yn');
11+
const programId = new PublicKey('CNLGhYQgNwjyDfHZTEjHfk1MPkqwP96qZahWN82UfcLM');
312

413
const GRID_CONTRACT_ID = 'grid.deltatrade.near';
514
const DCA_CONTRACT_ID = 'dca.deltatrade.near';
@@ -23,4 +32,37 @@ module.exports = {
2332
near: {
2433
tvl: () => sumTokens({ tokens, owners: [GRID_CONTRACT_ID, DCA_CONTRACT_ID] }),
2534
},
35+
solana: {
36+
tvl: solanaTvl,
37+
}
38+
}
39+
40+
async function getTokens() {
41+
return getConfig('deltatrade/sol-pairs', undefined, {
42+
fetcher: async () => {
43+
const { data } = await get('https://solapi.deltatrade.ai/api/bot/grid/pairs');
44+
const tokenSet = new Set()
45+
data.forEach(pair => {
46+
tokenSet.add(pair.base_token.code)
47+
tokenSet.add(pair.quote_token.code)
48+
})
49+
const arry = Array.from(tokenSet)
50+
arry.sort()
51+
return arry
52+
}
53+
})
54+
}
55+
56+
function getGlobalBalanceUser(token) {
57+
const [globalBalPda] = PublicKey.findProgramAddressSync([Buffer.from("global_balance_user"), state.toBuffer(), new PublicKey(token).toBuffer()], programId);
58+
59+
// const globalBalTokenAccount = await Token.getAssociatedTokenAddress(ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, new PublicKey(token), new PublicKey(globalBalPda.toString()), true);
60+
const [tokenAccount] = PublicKey.findProgramAddressSync([new PublicKey(globalBalPda.toString()), TOKEN_PROGRAM_ID, new PublicKey(token)].map(i => i.toBuffer()), ASSOCIATED_TOKEN_PROGRAM_ID)
61+
return tokenAccount.toString();
62+
}
63+
64+
async function solanaTvl() {
65+
const tokens = await getTokens();
66+
const tokenAccounts = tokens.map(getGlobalBalanceUser)
67+
return sumTokens2({ tokenAccounts })
2668
}

projects/helper/chain/near.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function transformAddress(addr) {
1313
}
1414

1515
const endpoint = "https://rpc.mainnet.near.org"
16+
// const endpoint = "https://near.lava.build"
1617

1718
const tokenMapping = {
1819
'wrap.near': { name: 'near', decimals: 24, },

0 commit comments

Comments
 (0)