Skip to content

Commit 6b66041

Browse files
committed
raydium: pull token balances from their api
1 parent 5910bf0 commit 6b66041

File tree

2 files changed

+49
-20
lines changed

2 files changed

+49
-20
lines changed

projects/raydium/api.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { getExports } = require('../helper/heroku-api')
22
const { sumTokens2 } = require('../helper/solana')
3+
const index = require('../index')
34

45
module.exports = {
56
timetravel: false,
@@ -12,6 +13,8 @@ module.exports.solana = {
1213
tvl: tvlWithCheck,
1314
}
1415

16+
module.exports.solana = index.solana
17+
1518
async function tvlWithCheck(api) {
1619
const balances = await tvl(api)
1720
api.addBalances(balances)

projects/raydium/index.js

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { PublicKey, } = require("@solana/web3.js");
44
const { TokenAmountLayout, KeyLayoutv4 } = require("../helper/utils/solana/layouts/raydium-layout");
55
const { transformDexBalances } = require("../helper/portedTokens");
66
const { sleep } = require("../helper/utils");
7+
const { get } = require("../helper/http");
78

89
const CLMM = 'CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK'
910
const AmmV4 = '675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8'
@@ -52,7 +53,7 @@ async function ammV4Tvl(api) {
5253
await sleep(20000)
5354
const allPoolKeyInfo = await connection.getProgramAccounts(new PublicKey(AmmV4), { filters: [{ dataSize: 752 }], dataSlice: { offset: 336, length: KeyLayoutv4.span } })
5455

55-
56+
5657
let i = 0
5758
let j = 0
5859
let data = []
@@ -120,26 +121,26 @@ async function ammV2V3() {
120121
async function combinedTvl(api) {
121122
try {
122123

123-
console.time('raydium: combinedTvl')
124+
console.time('raydium: combinedTvl')
124125

125-
console.time('raydium: tvlCLMM')
126-
const balancesCLMM = await tvlCLMM()
127-
api.addBalances(balancesCLMM)
128-
console.timeEnd('raydium: tvlCLMM')
126+
/* */ console.time('raydium: tvlCLMM')
127+
const balancesCLMM = await tvlCLMM()
128+
api.addBalances(balancesCLMM)
129+
console.timeEnd('raydium: tvlCLMM')
129130

130-
console.time('raydium: ammStableTvl')
131-
const balancesAmmStable = await ammStableTvl()
132-
api.addBalances(balancesAmmStable)
133-
console.timeEnd('raydium: ammStableTvl')
131+
console.time('raydium: ammStableTvl')
132+
const balancesAmmStable = await ammStableTvl()
133+
api.addBalances(balancesAmmStable)
134+
console.timeEnd('raydium: ammStableTvl')
134135

135-
console.time('raydium: ammV2V3')
136-
const balancesAmmV2V3 = await ammV2V3()
137-
api.addBalances(balancesAmmV2V3)
138-
console.timeEnd('raydium: ammV2V3')
136+
console.time('raydium: ammV2V3')
137+
const balancesAmmV2V3 = await ammV2V3()
138+
api.addBalances(balancesAmmV2V3)
139+
console.timeEnd('raydium: ammV2V3')
139140

140-
console.time('raydium: ammV4Tvl')
141-
await ammV4Tvl(api)
142-
console.timeEnd('raydium: ammV4Tvl')
141+
console.time('raydium: ammV4Tvl')
142+
// await ammV4Tvl(api)
143+
console.timeEnd('raydium: ammV4Tvl')
143144

144145
} catch (e) {
145146
console.error('raydium', e)
@@ -148,7 +149,10 @@ async function combinedTvl(api) {
148149

149150
console.timeEnd('raydium: combinedTvl')
150151
const tvl = await api.getUSDValue()
151-
if (tvl < 1.5e8) throw new Error('TVL is too low :' + tvl/1e6 + 'M')
152+
if (tvl < 1.5e8) throw new Error('TVL is too low :' + tvl / 1e6 + 'M')
153+
154+
api.removeTokenBalance('DS4QiZfkp39PsHXYCRV3NkyDUKV9SpTczp2qnAUg6Nt6') // ZMB
155+
api.removeTokenBalance('HDa3zJc12ahykSsBRvgiWzr6WLEByf36yzKKbVvy4gnF') // SOS
152156
return api.getBalances()
153157
}
154158

@@ -159,7 +163,29 @@ module.exports = {
159163
hallmarks: [[1667865600, "FTX collapse"]],
160164

161165
solana: {
162-
tvl: combinedTvl,
166+
// tvl: combinedTvl,
167+
tvl: tvlApi,
163168
staking: () => sumTokens2({ tokenAccounts: ['8tnpAECxAT9nHBqR1Ba494Ar5dQMPGhL31MmPJz1zZvY'] })
164169
},
165-
};
170+
};
171+
172+
async function tvlApi(api) {
173+
let hasMore = true
174+
let page = 1
175+
const pageSize = 1000
176+
do {
177+
const { data: { data } } = await get(`https://api-v3.raydium.io/pools/info/list?poolType=all&poolSortField=liquidity&sortType=desc&pageSize=${pageSize}&page=${page}`)
178+
const lastItem = data[data.length - 1]
179+
hasMore = data.length === pageSize && lastItem.tvl > 1000
180+
api.log('lastItem', lastItem.tvl, page)
181+
data.forEach(({ mintA, mintB, mintAmountA, mintAmountB, }) => {
182+
api.add(mintA.address, mintAmountA * (10 ** mintA.decimals))
183+
api.add(mintB.address, mintAmountB * (10 ** mintB.decimals))
184+
})
185+
page++
186+
} while (hasMore)
187+
188+
api.removeTokenBalance('DS4QiZfkp39PsHXYCRV3NkyDUKV9SpTczp2qnAUg6Nt6') // ZMB
189+
api.removeTokenBalance('HDa3zJc12ahykSsBRvgiWzr6WLEByf36yzKKbVvy4gnF') // SOS
190+
return api.getBalances()
191+
}

0 commit comments

Comments
 (0)