mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-01-12 08:34:23 +08:00
update backpack
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
const sdk = require('@defillama/sdk')
|
||||
const { sumTokensExport } = require('../helper/sumTokens')
|
||||
const ADDRESSES = require('../helper/coreAssets.json')
|
||||
const { defaultTokens } = require('../helper/cex')
|
||||
const { getConfig } = require('../helper/cache.js')
|
||||
const { getStakedSol } = require('../helper/solana')
|
||||
|
||||
const API_URL = 'https://api.backpack.exchange/api/v1/wallets'
|
||||
|
||||
@@ -66,31 +64,18 @@ CHAINS.forEach((chain) => {
|
||||
}
|
||||
|
||||
const options = { ...entry, owners, tokens, chain, blacklistedTokens }
|
||||
if (chain === 'solana' || chain === 'eclipse') options.solOwners = owners
|
||||
if (chain === 'ton') options.onlyWhitelistedTokens = true
|
||||
if (chain === 'aptos' && Array.isArray(fungibleAssets)) options.fungibleAssets = fungibleAssets
|
||||
|
||||
if (chain === 'solana') {
|
||||
const balances = await sumTokensExport(options)()
|
||||
|
||||
if (Array.isArray(owners) && owners.length) {
|
||||
const uniqOwners = [...new Set(owners)]
|
||||
const BATCH = 50
|
||||
let totalStaked = 0
|
||||
for (let i = 0; i < uniqOwners.length; i += BATCH) {
|
||||
const chunk = uniqOwners.slice(i, i + BATCH)
|
||||
const parts = await Promise.all(chunk.map(addr => getStakedSol(addr)))
|
||||
totalStaked += parts.reduce((a, b) => a + b, 0)
|
||||
}
|
||||
sdk.util.sumSingleBalance(balances, `solana:${ADDRESSES.solana.SOL}`, totalStaked)
|
||||
}
|
||||
|
||||
return balances
|
||||
switch (chain) {
|
||||
case 'solana': options.includeStakedSol = true
|
||||
case 'eclipse': options.solOwners = owners; break
|
||||
case 'ton': options.onlyWhitelistedTokens = true; break
|
||||
case 'aptos':
|
||||
if (Array.isArray(fungibleAssets)) options.fungibleAssets = fungibleAssets
|
||||
break
|
||||
}
|
||||
|
||||
return sumTokensExport(options)()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = exportObj
|
||||
module.exports = exportObj
|
||||
|
||||
@@ -203,6 +203,7 @@ async function sumTokens2({
|
||||
blacklistedTokens = [],
|
||||
allowError = false,
|
||||
computeTokenAccount = false,
|
||||
includeStakedSol = false,
|
||||
chain = 'solana',
|
||||
}) {
|
||||
|
||||
@@ -212,6 +213,16 @@ async function sumTokens2({
|
||||
else balances = {}
|
||||
}
|
||||
|
||||
if (includeStakedSol) {
|
||||
let stakeOwners = solOwners.length ? solOwners : owners.length ? owners : owner ? [owner] : []
|
||||
stakeOwners = getUniqueAddresses(stakeOwners, chain)
|
||||
for (const so of stakeOwners) {
|
||||
const staked = await getStakedSol(so)
|
||||
await sleep(2000)
|
||||
sdk.util.sumSingleBalance(balances, `solana:${ADDRESSES.solana.SOL}`, staked)
|
||||
}
|
||||
}
|
||||
|
||||
const endpoint = getEndpoint(chain)
|
||||
blacklistedTokens.push(...blacklistedTokens_default)
|
||||
if (!tokensAndOwners.length) {
|
||||
|
||||
Reference in New Issue
Block a user