From 8cbdc807584d2c88186d7f43664183738dc86ef6 Mon Sep 17 00:00:00 2001 From: Anthony Laibe <491074+alaibe@users.noreply.github.com> Date: Fri, 15 Dec 2023 09:19:40 +0100 Subject: [PATCH] feat: expose token balance API --- services/wallet/api.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/services/wallet/api.go b/services/wallet/api.go index 3724ed20c..1fe7109e3 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -65,6 +65,17 @@ func (api *API) GetWalletToken(ctx context.Context, addresses []common.Address) return api.reader.GetWalletToken(ctx, addresses) } +// GetBalancesByChain return a map with key as chain id and value as map of account address and map of token address and balance +// [chainID][account][token]balance +func (api *API) GetBalancesByChain(ctx context.Context, chainIDs []uint64, addresses, tokens []common.Address) (map[uint64]map[common.Address]map[common.Address]*hexutil.Big, error) { + clients, err := api.s.rpcClient.EthClients(chainIDs) + if err != nil { + return nil, err + } + + return api.s.tokenManager.GetBalancesByChain(ctx, clients, addresses, tokens) +} + func (api *API) GetCachedWalletTokensWithoutMarketData(ctx context.Context) (map[common.Address][]Token, error) { return api.reader.GetCachedWalletTokensWithoutMarketData() }