diff --git a/tee-worker/litentry/core/data-providers/src/moralis.rs b/tee-worker/litentry/core/data-providers/src/moralis.rs index 199654952c..0a7f85c9a4 100644 --- a/tee-worker/litentry/core/data-providers/src/moralis.rs +++ b/tee-worker/litentry/core/data-providers/src/moralis.rs @@ -275,9 +275,10 @@ pub trait BalanceApiList { ) -> Result, Error>; // https://docs.moralis.io/web3-data-api/evm/reference/wallet-api/get-token-balances-by-wallet - fn get_evm_tokens_balance_by_wallet( + fn get_evm_token_balance_by_wallet( &mut self, address: String, + token_address: String, network: &Web3Network, fast_fail: bool, ) -> Result, Error>; @@ -338,15 +339,19 @@ impl BalanceApiList for MoralisClient { } } - fn get_evm_tokens_balance_by_wallet( + fn get_evm_token_balance_by_wallet( &mut self, address: String, + token_address: String, network: &Web3Network, fast_fail: bool, ) -> Result, Error> { - debug!("get_evm_tokens_balance_by_wallet, address: {}", address); + debug!("get_evm_token_balance_by_wallet, address: {}", address); - let query = Some(vec![("chain".to_string(), web3_network_to_chain(network))]); + let query = Some(vec![ + ("chain".to_string(), web3_network_to_chain(network)), + ("token_addresses[0]".to_string(), token_address), + ]); let params = MoralisRequest { path: format!("{}/erc20", address), query }; match self.get::>( @@ -355,11 +360,11 @@ impl BalanceApiList for MoralisClient { fast_fail, ) { Ok(resp) => { - debug!("get_evm_tokens_balance_by_wallet, response: {:?}", resp); + debug!("get_evm_token_balance_by_wallet, response: {:?}", resp); Ok(resp) }, Err(e) => { - debug!("get_evm_tokens_balance_by_wallet, error: {:?}", e); + debug!("get_evm_token_balance_by_wallet, error: {:?}", e); Err(e) }, } diff --git a/tee-worker/litentry/core/service/src/web3_token/token_balance/common.rs b/tee-worker/litentry/core/service/src/web3_token/token_balance/common.rs index bf170dc5c2..4e80a5d893 100644 --- a/tee-worker/litentry/core/service/src/web3_token/token_balance/common.rs +++ b/tee-worker/litentry/core/service/src/web3_token/token_balance/common.rs @@ -97,13 +97,17 @@ pub fn get_balance( let decimals = token_type.get_decimals(network); let mut client = MoralisClient::new(data_provider_config); - let result = - client.get_evm_tokens_balance_by_wallet(address.1.clone(), &network, false); + let result = client.get_evm_token_balance_by_wallet( + address.1.clone(), + token_address.into(), + &network, + false, + ); match result { Ok(items) => - match items.iter().find(|&item| item.token_address == token_address) { - Some(item) => match item.balance.parse::() { + if !items.is_empty() { + match items[0].balance.parse::() { Ok(balance) => { total_balance += calculate_balance_with_decimals(balance, decimals); @@ -111,11 +115,15 @@ pub fn get_balance( Ok(LoopControls::Continue) }, Err(err) => { - error!("Failed to parse {} to f64: {}", item.balance, err); + error!( + "Failed to parse {} to f64: {}", + items[0].balance, err + ); Err(Error::ParseError) }, - }, - None => Ok(LoopControls::Continue), + } + } else { + Ok(LoopControls::Continue) }, Err(err) => Err(err.into_error_detail()), }