@@ -11,7 +11,7 @@ import { CacheStorage } from '../../../../models/cache';
1111import { IBlock } from '../../../../types/Block' ;
1212import { CoinListingJSON } from '../../../../types/Coin' ;
1313import { 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' ;
1515import { range } from '../../../../utils' ;
1616import { TransformWithEventPipe } from '../../../../utils/streamWithEventPipe' ;
1717import {
@@ -699,11 +699,16 @@ export class BaseSVMStateProvider extends InternalStateProvider implements IChai
699699 async getSPLTokenInfo (
700700 network : string ,
701701 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 ) ;
704706 let decimals ;
707+ let programType ;
708+ let programAddress ;
705709 let name = '' ;
706710 let symbol = '' ;
711+
707712 try {
708713 let error ;
709714 let token ;
@@ -745,7 +750,28 @@ export class BaseSVMStateProvider extends InternalStateProvider implements IChai
745750 } catch ( err ) {
746751 logger . error ( 'Error getting SPL token info: %o' , err ) ;
747752 }
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 } ;
749775 }
750776
751777 async getLocalTip ( params : any ) : Promise < IBlock > {
0 commit comments