import { MVM_RPC_URL } from '../../utils/mvm.js'; import type { Token, TokenAmount } from '../../types/token.js'; import { SuiClient } from '@mysten/sui/client'; const suiClient = new SuiClient({ url: MVM_RPC_URL, }); export const getMVMBalance = async ( walletAddress: string, tokens: Token[], ): Promise => { if (tokens.length === 0) { return []; } const tokenBalances: TokenAmount[] = []; const data = await suiClient.getAllBalances({ owner: walletAddress }); tokens.forEach((token) => { const balance = data.find( (item) => item.coinType === token.address, )?.totalBalance; if (balance) { tokenBalances.push({ ...token, amount: BigInt(balance || 0), }); } else { tokenBalances.push({ ...token, amount: BigInt(0), }); } }); return tokenBalances; };