import type { ParsedMessageAccount , TokenBalance } from '@solana/web3.js' ; export const getTokenBalance = ( accountKeys , tokenBalances , publicKey ) : TokenBalance | undefined => { if ( ! tokenBalances ) { return undefined ; } const accountIndex = accountKeys . findIndex ( ( accountKey ) => accountKey . pubkey . toBase58 ( ) === publicKey ) ; return tokenBalances . find ( ( tokenBalance ) => tokenBalance . accountIndex === accountIndex ) ; } ;