@iam4x/bsc-scan
Version:
An efficient BNB and token balance scanner
22 lines • 1.68 kB
JavaScript
import{decode}from"@findeth/abi";import{BATCH_SIZE,CONTRACT_ADDRESS}from"./constants";import{call}from"./providers";import{batch}from"./utils";/**
* Get a balance map from an array of addresses and an array of balances.
*
* @param {string[]} addresses
* @param {bigint[]} balances
* @return {BalanceMap}
*/export const toBalanceMap=(a,b)=>b.reduce((b,c,d)=>({...b,[a[d]]:c}),{});/**
* Get a nested balance map from an array of addresses, token addresses, and balances.
*
* @param {string[]} addresses
* @param {bigint[]} tokenAddresses
* @param {BalanceMap<BalanceMap>} balances
*/export const toNestedBalanceMap=(a,b,c)=>c.reduce((c,d,e)=>({...c,[a[e]]:toBalanceMap(b,d)}),{});/**
* Low level API function to send a contract call that returns a single uint256 array.
*
* @param {ProviderLike} provider
* @param {string[]} addresses
* @param {Function} encodeData
* @param {EthScanOptions} options
* @return {Promise<BalanceMap>}
*/export const callSingle=async(a,b,c,d)=>{var e,f;const g=null!==(e=null===d||void 0===d?void 0:d.contractAddress)&&void 0!==e?e:CONTRACT_ADDRESS,h=null!==(f=null===d||void 0===d?void 0:d.batchSize)&&void 0!==f?f:BATCH_SIZE,i=await batch(async b=>{const d=c(b);return decode(["uint256[]"],await call(a,g,d))[0]},h,b);return toBalanceMap(b,i)};export const callMultiple=async(a,b,c,d,e)=>{var f,g;const h=null!==(f=null===e||void 0===e?void 0:e.contractAddress)&&void 0!==f?f:CONTRACT_ADDRESS,i=null!==(g=null===e||void 0===e?void 0:e.batchSize)&&void 0!==g?g:BATCH_SIZE,j=await batch(async b=>{const e=d(b,c);return decode(["uint256[][]"],await call(a,h,e))[0]},i,b);return toNestedBalanceMap(b,c,j)};
//# sourceMappingURL=api.js.map