@@ -19,8 +19,9 @@ import {
19
19
} from '@wormhole-foundation/sdk-connect' ;
20
20
import { SolanaChain } from './chain.js' ;
21
21
22
- import { TOKEN_PROGRAM_ID } from '@solana/spl-token' ;
22
+ import { TOKEN_PROGRAM_ID , TOKEN_2022_PROGRAM_ID } from '@solana/spl-token' ;
23
23
import type {
24
+ AccountInfo ,
24
25
Commitment ,
25
26
ConnectionConfig ,
26
27
ParsedAccountData ,
@@ -150,19 +151,24 @@ export class SolanaPlatform<N extends Network>
150
151
native = BigInt ( await rpc . getBalance ( new PublicKey ( walletAddress ) ) ) ;
151
152
}
152
153
153
- const splParsedTokenAccounts = await rpc . getParsedTokenAccountsByOwner (
154
- new PublicKey ( walletAddress ) ,
155
- {
156
- programId : new PublicKey ( TOKEN_PROGRAM_ID ) ,
157
- } ,
158
- ) ;
154
+ const splParsedTokenAccounts = ( await Promise . all (
155
+ [ TOKEN_PROGRAM_ID , TOKEN_2022_PROGRAM_ID ]
156
+ . map ( pid => new PublicKey ( pid ) )
157
+ . map ( programId => rpc . getParsedTokenAccountsByOwner ( new PublicKey ( walletAddress ) , { programId } )
158
+ ) ) ) . reduce < {
159
+ pubkey : PublicKey ;
160
+ account : AccountInfo < ParsedAccountData > ;
161
+ } [ ]
162
+ > ( ( acc , val ) => {
163
+ return acc . concat ( val . value ) ;
164
+ } , [ ] ) ;
159
165
160
166
const balancesArr = tokens . map ( ( token ) => {
161
167
if ( isNative ( token ) ) {
162
168
return { [ 'native' ] : native } ;
163
169
}
164
170
const addrString = new SolanaAddress ( token ) . toString ( ) ;
165
- const amount = splParsedTokenAccounts . value . find (
171
+ const amount = splParsedTokenAccounts . find (
166
172
( v ) => v ?. account . data . parsed ?. info ?. mint === token ,
167
173
) ?. account . data . parsed ?. info ?. tokenAmount ?. amount ;
168
174
if ( ! amount ) return { [ addrString ] : null } ;
0 commit comments