diff --git a/platforms/solana/src/platform.ts b/platforms/solana/src/platform.ts index f2bcfaf5f..5f133e71a 100644 --- a/platforms/solana/src/platform.ts +++ b/platforms/solana/src/platform.ts @@ -21,6 +21,7 @@ import { SolanaChain } from './chain.js'; import { TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'; import type { + AccountInfo, Commitment, ConnectionConfig, ParsedAccountData, @@ -150,30 +151,24 @@ export class SolanaPlatform native = BigInt(await rpc.getBalance(new PublicKey(walletAddress))); } - const splParsedTokenAccounts = await rpc.getParsedTokenAccountsByOwner( - new PublicKey(walletAddress), - { - programId: new PublicKey(TOKEN_PROGRAM_ID), - }, - ); - - // Fetch 2022 tokens - const splParsedToken2022Accounts = await rpc.getParsedTokenAccountsByOwner( - new PublicKey(walletAddress), - { - programId: new PublicKey(TOKEN_2022_PROGRAM_ID), - }, - ); + const splParsedTokenAccounts = (await Promise.all( + [TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID] + .map(pid => new PublicKey(pid)) + .map(programId => rpc.getParsedTokenAccountsByOwner(new PublicKey(walletAddress), { programId }) + ))).reduce<{ + pubkey: PublicKey; + account: AccountInfo; + }[] + >((acc, val) => { + return acc.concat(val.value); + }, []); - // Merge the two token account lists - splParsedTokenAccounts.value.push(...splParsedToken2022Accounts.value); - const balancesArr = tokens.map((token) => { if (isNative(token)) { return { ['native']: native }; } const addrString = new SolanaAddress(token).toString(); - const amount = splParsedTokenAccounts.value.find( + const amount = splParsedTokenAccounts.find( (v) => v?.account.data.parsed?.info?.mint === token, )?.account.data.parsed?.info?.tokenAmount?.amount; if (!amount) return { [addrString]: null };