Skip to content

Commit 047b443

Browse files
committed
update backpack
1 parent f3e74f8 commit 047b443

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

projects/backpack/index.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
const sdk = require('@defillama/sdk')
21
const { sumTokensExport } = require('../helper/sumTokens')
32
const ADDRESSES = require('../helper/coreAssets.json')
43
const { defaultTokens } = require('../helper/cex')
54
const { getConfig } = require('../helper/cache.js')
6-
const { getStakedSol } = require('../helper/solana')
75

86
const API_URL = 'https://api.backpack.exchange/api/v1/wallets'
97

@@ -66,31 +64,18 @@ CHAINS.forEach((chain) => {
6664
}
6765

6866
const options = { ...entry, owners, tokens, chain, blacklistedTokens }
69-
if (chain === 'solana' || chain === 'eclipse') options.solOwners = owners
70-
if (chain === 'ton') options.onlyWhitelistedTokens = true
71-
if (chain === 'aptos' && Array.isArray(fungibleAssets)) options.fungibleAssets = fungibleAssets
7267

73-
if (chain === 'solana') {
74-
const balances = await sumTokensExport(options)()
75-
76-
if (Array.isArray(owners) && owners.length) {
77-
const uniqOwners = [...new Set(owners)]
78-
const BATCH = 50
79-
let totalStaked = 0
80-
for (let i = 0; i < uniqOwners.length; i += BATCH) {
81-
const chunk = uniqOwners.slice(i, i + BATCH)
82-
const parts = await Promise.all(chunk.map(addr => getStakedSol(addr)))
83-
totalStaked += parts.reduce((a, b) => a + b, 0)
84-
}
85-
sdk.util.sumSingleBalance(balances, `solana:${ADDRESSES.solana.SOL}`, totalStaked)
86-
}
87-
88-
return balances
68+
switch (chain) {
69+
case 'solana': options.includeStakedSol = true
70+
case 'eclipse': options.solOwners = owners; break
71+
case 'ton': options.onlyWhitelistedTokens = true; break
72+
case 'aptos':
73+
if (Array.isArray(fungibleAssets)) options.fungibleAssets = fungibleAssets
74+
break
8975
}
90-
9176
return sumTokensExport(options)()
9277
}
9378
}
9479
})
9580

96-
module.exports = exportObj
81+
module.exports = exportObj

projects/helper/solana.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ async function sumTokens2({
203203
blacklistedTokens = [],
204204
allowError = false,
205205
computeTokenAccount = false,
206+
includeStakedSol = false,
206207
chain = 'solana',
207208
}) {
208209

@@ -212,6 +213,16 @@ async function sumTokens2({
212213
else balances = {}
213214
}
214215

216+
if (includeStakedSol) {
217+
let stakeOwners = solOwners.length ? solOwners : owners.length ? owners : owner ? [owner] : []
218+
stakeOwners = getUniqueAddresses(stakeOwners, chain)
219+
for (const so of stakeOwners) {
220+
const staked = await getStakedSol(so)
221+
await sleep(2000)
222+
sdk.util.sumSingleBalance(balances, `solana:${ADDRESSES.solana.SOL}`, staked)
223+
}
224+
}
225+
215226
const endpoint = getEndpoint(chain)
216227
blacklistedTokens.push(...blacklistedTokens_default)
217228
if (!tokensAndOwners.length) {

0 commit comments

Comments
 (0)