def get_multieth_balance( self, accounts: List[ChecksumEthAddress], call_order: Optional[Sequence[NodeName]] = None, ) -> Dict[ChecksumEthAddress, FVal]: """Returns a dict with keys being accounts and balances in ETH May raise: - RemoteError if an external service such as Etherscan is queried and there is a problem with its query. """ balances: Dict[ChecksumEthAddress, FVal] = {} log.debug( 'Querying ethereum chain for ETH balance', eth_addresses=accounts, ) result = ETH_SCAN.call( ethereum=self, method_name='etherBalances', arguments=[accounts], call_order=call_order if call_order is not None else self.default_call_order(), ) balances = {} for idx, account in enumerate(accounts): balances[account] = from_wei(result[idx]) return balances
def _get_multitoken_account_balance( self, tokens: List[CustomEthereumTokenWithIdentifier], account: ChecksumEthAddress, call_order: Optional[Sequence[NodeName]], ) -> Dict[str, FVal]: """Queries balances of multiple tokens for an account Return a dictionary with keys being tokens and value a dictionary of account to balances May raise: - RemoteError if an external service such as Etherscan is queried and there is a problem with its query. - BadFunctionCallOutput if a local node is used and the contract for the token has no code. That means the chain is not synced """ log.debug( 'Querying ethereum chain for multi token account balances', eth_address=account, tokens_num=len(tokens), ) balances: Dict[str, FVal] = {} result = ETH_SCAN.call( ethereum=self.ethereum, method_name='tokensBalance', arguments=[account, [x.address for x in tokens]], call_order=call_order, ) for tk_idx, token in enumerate(tokens): token_amount = result[tk_idx] if token_amount != 0: balances[token.identifier] = token_normalized_value( token_amount, token) return balances
def _get_multitoken_multiaccount_balance( self, tokens: List[EthTokenInfo], accounts: List[ChecksumEthAddress], ) -> Dict[str, Dict[ChecksumEthAddress, FVal]]: """Queries a list of accounts for balances of multiple tokens Return a dictionary with keys being tokens and value a dictionary of account to balances May raise: - RemoteError if an external service such as Etherscan is queried and there is a problem with its query. - BadFunctionCallOutput if a local node is used and the contract for the token has no code. That means the chain is not synced """ log.debug( 'Querying ethereum chain for multi token multi account balances', eth_addresses=accounts, tokens_num=len(tokens), ) balances: Dict[str, Dict[ChecksumEthAddress, FVal]] = defaultdict(dict) result = ETH_SCAN.call( ethereum=self.ethereum, method_name='tokensBalances', arguments=[accounts, [x.address for x in tokens]], ) for acc_idx, account in enumerate(accounts): for tk_idx, token in enumerate(tokens): token_amount = result[acc_idx][tk_idx] if token_amount != 0: balances[ token.identifier][account] = token_normalized_value( token_amount=token_amount, token=token, ) return balances