@phiresky/eth-scan
Version:
An efficient Ether and token balance scanner
35 lines • 2.58 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.getTokensBalance=exports.getTokensBalances=exports.getTokenBalances=exports.getEtherBalances=void 0;var _abi=require("@findeth/abi"),_api=require("./api"),_constants=require("./constants"),_utils=require("./utils");/**
* Get the Ether balances for the addresses specified.
*
* @param {ProviderLike} provider
* @param {string[]} addresses
* @param {EthScanOptions} options
* @return {Promise<BalanceMap>}
*/const getEtherBalances=async(a,b,c)=>{const d=await(0,_api.callSingle)(a,b,[],[],a=>(0,_utils.withId)(_constants.ETHER_BALANCES_ID,(0,_abi.encode)(_constants.ETHER_BALANCES_TYPE,[a])),()=>"",c);return(0,_api.toBalanceMap)(b,d)};/**
* Get the ERC-20 token balances of the token with the address `tokenAddress` for the addresses
* specified.
*
* @param {ProviderLike} provider
* @param {string[]} addresses
* @param {string} tokenAddress
* @param {EthScanOptions} options
* @return {Promise<BalanceMap>}
*/exports.getEtherBalances=getEtherBalances;const getTokenBalances=async(a,b,c,d)=>{const e=await(0,_api.callSingle)(a,b,b,c,a=>(0,_utils.withId)(_constants.TOKEN_BALANCES_ID,(0,_abi.encode)(_constants.TOKEN_BALANCES_TYPE,[a,c])),a=>(0,_utils.withId)(_constants.BALANCE_OF_ID,(0,_abi.encode)(_constants.BALANCE_OF_TYPE,[a])),d);return(0,_api.toBalanceMap)(b,e)};/**
* Get the ERC-20 token balances for multiple contracts, for multiple addresses.
*
* @param {ProviderLike} provider
* @param {string[]} addresses
* @param {string[]} tokenAddresses
* @param {EthScanOptions} options
* @return {Promise<BalanceMap<BalanceMap>>}
*/exports.getTokenBalances=getTokenBalances;const getTokensBalances=async(a,b,c,d)=>{const e=await Promise.all(b.map(async b=>Object.values(await getTokensBalance(a,b,c,d))));return(0,_api.toNestedBalanceMap)(b,c,e)};/**
* Get the ERC-20 token balance of the tokens with the addresses `tokenAddresses` for the single
* address specified.
*
* @param {ProviderLike} provider
* @param {string} address
* @param {string[]} tokenAddresses
* @param {EthScanOptions} options
* @return {Promise<BalanceMap>}
*/exports.getTokensBalances=getTokensBalances;const getTokensBalance=async(a,b,c,d)=>{const e=await(0,_api.callSingle)(a,c,b,c,a=>(0,_utils.withId)(_constants.TOKENS_BALANCE_ID,(0,_abi.encode)(_constants.TOKENS_BALANCE_TYPE,[b,a])),()=>(0,_utils.withId)(_constants.BALANCE_OF_ID,(0,_abi.encode)(_constants.BALANCE_OF_TYPE,[b])),d);return(0,_api.toBalanceMap)(c,e)};exports.getTokensBalance=getTokensBalance;
//# sourceMappingURL=eth-scan.js.map