@@ -11,7 +11,7 @@ import { CacheStorage } from '../../../../models/cache';
11
11
import { IBlock } from '../../../../types/Block' ;
12
12
import { CoinListingJSON } from '../../../../types/Coin' ;
13
13
import { IChainConfig , IProvider , ISVMNetworkConfig } from '../../../../types/Config' ;
14
- import { BroadcastTransactionParams , GetBalanceForAddressParams , GetBlockParams , GetCoinsForTxParams , GetEstimatePriorityFeeParams , GetWalletBalanceParams , IChainStateService , StreamAddressUtxosParams , StreamBlocksParams , StreamTransactionParams , StreamTransactionsParams , StreamWalletTransactionsParams , WalletBalanceType , GetBlockBeforeTimeParams } from '../../../../types/namespaces/ChainStateProvider' ;
14
+ import { BroadcastTransactionParams , GetBalanceForAddressParams , GetBlockBeforeTimeParams , GetBlockParams , GetCoinsForTxParams , GetEstimatePriorityFeeParams , GetWalletBalanceParams , IChainStateService , StreamAddressUtxosParams , StreamBlocksParams , StreamTransactionParams , StreamTransactionsParams , StreamWalletTransactionsParams , WalletBalanceType } from '../../../../types/namespaces/ChainStateProvider' ;
15
15
import { range } from '../../../../utils' ;
16
16
import { TransformWithEventPipe } from '../../../../utils/streamWithEventPipe' ;
17
17
import {
@@ -699,11 +699,16 @@ export class BaseSVMStateProvider extends InternalStateProvider implements IChai
699
699
async getSPLTokenInfo (
700
700
network : string ,
701
701
tokenAddress : string
702
- ) : Promise < { name : string ; symbol : string ; decimals : number } > {
703
- const { umi } = await this . getRpc ( network ) ;
702
+ ) : Promise < { name : string ; symbol : string ; decimals : number ; programType : string | undefined ; programAddress : string | undefined ; } > {
703
+ const TOKEN_PROGRAM_ADDRESS = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA' ;
704
+ const TOKEN_2022_ADDR = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb' ;
705
+ const { umi, connection } = await this . getRpc ( network ) ;
704
706
let decimals ;
707
+ let programType ;
708
+ let programAddress ;
705
709
let name = '' ;
706
710
let symbol = '' ;
711
+
707
712
try {
708
713
let error ;
709
714
let token ;
@@ -745,7 +750,28 @@ export class BaseSVMStateProvider extends InternalStateProvider implements IChai
745
750
} catch ( err ) {
746
751
logger . error ( 'Error getting SPL token info: %o' , err ) ;
747
752
}
748
- return { name, symbol, decimals } ;
753
+
754
+ try {
755
+ const result = await connection . getAccountInfo ( tokenAddress ) . send ( ) ;
756
+ const owner = result ?. value ?. owner ?. toString ?.( ) ;
757
+ if ( ! owner ) {
758
+ throw new Error ( `Mint account not found or unreadable: ${ tokenAddress } ` ) ;
759
+ }
760
+ if ( owner === TOKEN_PROGRAM_ADDRESS ) {
761
+ programType = 'token' ;
762
+ programAddress = TOKEN_PROGRAM_ADDRESS ;
763
+ } else if ( owner === TOKEN_2022_ADDR ) {
764
+ programType = 'token2022' ;
765
+ programAddress = TOKEN_2022_ADDR ;
766
+ }
767
+ if ( ! programAddress ) {
768
+ logger . warn ( `Unknown token program owner for ${ tokenAddress } : ${ owner } ` ) ;
769
+ }
770
+ } catch ( err ) {
771
+ logger . error ( 'Error getting SPL token program info: %o' , err ) ;
772
+ }
773
+
774
+ return { name, symbol, decimals, programType, programAddress } ;
749
775
}
750
776
751
777
async getLocalTip ( params : any ) : Promise < IBlock > {
0 commit comments