@@ -52,23 +52,21 @@ import { getInstructionType } from './utils';
5252export function instructionParamsFactory (
5353 type : TransactionType ,
5454 instructions : TransactionInstruction [ ] ,
55- coinName ?: string ,
56- instructionMetadata ?: InstructionParams [ ] ,
57- _useTokenAddressTokenName ?: boolean
55+ coinName ?: string
5856) : InstructionParams [ ] {
5957 switch ( type ) {
6058 case TransactionType . WalletInitialization :
6159 return parseWalletInitInstructions ( instructions ) ;
6260 case TransactionType . Send :
63- return parseSendInstructions ( instructions , instructionMetadata , _useTokenAddressTokenName ) ;
61+ return parseSendInstructions ( instructions ) ;
6462 case TransactionType . StakingActivate :
6563 return parseStakingActivateInstructions ( instructions ) ;
6664 case TransactionType . StakingDeactivate :
6765 return parseStakingDeactivateInstructions ( instructions , coinName ) ;
6866 case TransactionType . StakingWithdraw :
6967 return parseStakingWithdrawInstructions ( instructions ) ;
7068 case TransactionType . AssociatedTokenAccountInitialization :
71- return parseAtaInitInstructions ( instructions , instructionMetadata , _useTokenAddressTokenName ) ;
69+ return parseAtaInitInstructions ( instructions ) ;
7270 case TransactionType . CloseAssociatedTokenAccount :
7371 return parseAtaCloseInstructions ( instructions ) ;
7472 case TransactionType . StakingAuthorize :
@@ -122,9 +120,7 @@ function parseWalletInitInstructions(instructions: TransactionInstruction[]): Ar
122120 * @returns {InstructionParams[] } An array containing instruction params for Send tx
123121 */
124122function parseSendInstructions (
125- instructions : TransactionInstruction [ ] ,
126- instructionMetadata ?: InstructionParams [ ] ,
127- _useTokenAddressTokenName ?: boolean
123+ instructions : TransactionInstruction [ ]
128124) : Array < Nonce | Memo | Transfer | TokenTransfer | AtaInit | AtaClose | SetPriorityFee > {
129125 const instructionData : Array < Nonce | Memo | Transfer | TokenTransfer | AtaInit | AtaClose | SetPriorityFee > = [ ] ;
130126 for ( const instruction of instructions ) {
@@ -164,12 +160,7 @@ function parseSendInstructions(
164160 } else {
165161 tokenTransferInstruction = decodeTransferCheckedInstruction ( instruction , TOKEN_2022_PROGRAM_ID ) ;
166162 }
167- const tokenAddress = tokenTransferInstruction . keys . mint . pubkey . toString ( ) ;
168- const tokenName = findTokenName ( tokenAddress , instructionMetadata , _useTokenAddressTokenName ) ;
169- let programIDForTokenTransfer : string | undefined ;
170- if ( instruction . programId ) {
171- programIDForTokenTransfer = instruction . programId . toString ( ) ;
172- }
163+ const tokenName = findTokenName ( tokenTransferInstruction . keys . mint . pubkey . toString ( ) ) ;
173164 const tokenTransfer : TokenTransfer = {
174165 type : InstructionBuilderTypes . TokenTransfer ,
175166 params : {
@@ -178,20 +169,13 @@ function parseSendInstructions(
178169 amount : tokenTransferInstruction . data . amount . toString ( ) ,
179170 tokenName,
180171 sourceAddress : tokenTransferInstruction . keys . source . pubkey . toString ( ) ,
181- tokenAddress : tokenAddress ,
182- programId : programIDForTokenTransfer ,
183- decimalPlaces : tokenTransferInstruction . data . decimals ,
184172 } ,
185173 } ;
186174 instructionData . push ( tokenTransfer ) ;
187175 break ;
188176 case ValidInstructionTypesEnum . InitializeAssociatedTokenAccount :
189177 const mintAddress = instruction . keys [ ataInitInstructionKeysIndexes . MintAddress ] . pubkey . toString ( ) ;
190- const mintTokenName = findTokenName ( mintAddress , instructionMetadata , _useTokenAddressTokenName ) ;
191- let programID : string | undefined ;
192- if ( instruction . programId ) {
193- programID = instruction . programId . toString ( ) ;
194- }
178+ const mintTokenName = findTokenName ( mintAddress ) ;
195179
196180 const ataInit : AtaInit = {
197181 type : InstructionBuilderTypes . CreateAssociatedTokenAccount ,
@@ -201,7 +185,6 @@ function parseSendInstructions(
201185 ownerAddress : instruction . keys [ ataInitInstructionKeysIndexes . OwnerAddress ] . pubkey . toString ( ) ,
202186 payerAddress : instruction . keys [ ataInitInstructionKeysIndexes . PayerAddress ] . pubkey . toString ( ) ,
203187 tokenName : mintTokenName ,
204- programId : programID ,
205188 } ,
206189 } ;
207190 instructionData . push ( ataInit ) ;
@@ -669,11 +652,7 @@ const closeAtaInstructionKeysIndexes = {
669652 * @param {TransactionInstruction[] } instructions - an array of supported Solana instructions
670653 * @returns {InstructionParams[] } An array containing instruction params for Send tx
671654 */
672- function parseAtaInitInstructions (
673- instructions : TransactionInstruction [ ] ,
674- instructionMetadata ?: InstructionParams [ ] ,
675- _useTokenAddressTokenName ?: boolean
676- ) : Array < AtaInit | Memo | Nonce > {
655+ function parseAtaInitInstructions ( instructions : TransactionInstruction [ ] ) : Array < AtaInit | Memo | Nonce > {
677656 const instructionData : Array < AtaInit | Memo | Nonce > = [ ] ;
678657 let memo : Memo | undefined ;
679658
@@ -696,11 +675,8 @@ function parseAtaInitInstructions(
696675 break ;
697676 case ValidInstructionTypesEnum . InitializeAssociatedTokenAccount :
698677 const mintAddress = instruction . keys [ ataInitInstructionKeysIndexes . MintAddress ] . pubkey . toString ( ) ;
699- const tokenName = findTokenName ( mintAddress , instructionMetadata , _useTokenAddressTokenName ) ;
700- let programID : string | undefined ;
701- if ( instruction . programId ) {
702- programID = instruction . programId . toString ( ) ;
703- }
678+ const tokenName = findTokenName ( mintAddress ) ;
679+
704680 const ataInit : AtaInit = {
705681 type : InstructionBuilderTypes . CreateAssociatedTokenAccount ,
706682 params : {
@@ -709,7 +685,6 @@ function parseAtaInitInstructions(
709685 ownerAddress : instruction . keys [ ataInitInstructionKeysIndexes . OwnerAddress ] . pubkey . toString ( ) ,
710686 payerAddress : instruction . keys [ ataInitInstructionKeysIndexes . PayerAddress ] . pubkey . toString ( ) ,
711687 tokenName,
712- programId : programID ,
713688 } ,
714689 } ;
715690 instructionData . push ( ataInit ) ;
@@ -856,11 +831,7 @@ function parseStakingAuthorizeRawInstructions(instructions: TransactionInstructi
856831 return instructionData ;
857832}
858833
859- function findTokenName (
860- mintAddress : string ,
861- instructionMetadata ?: InstructionParams [ ] ,
862- _useTokenAddressTokenName ?: boolean
863- ) : string {
834+ function findTokenName ( mintAddress : string ) : string {
864835 let token : string | undefined ;
865836
866837 coins . forEach ( ( value , key ) => {
@@ -869,26 +840,6 @@ function findTokenName(
869840 }
870841 } ) ;
871842
872- if ( ! token && instructionMetadata ) {
873- instructionMetadata . forEach ( ( instruction ) => {
874- if (
875- instruction . type === InstructionBuilderTypes . CreateAssociatedTokenAccount &&
876- instruction . params . mintAddress === mintAddress
877- ) {
878- token = instruction . params . tokenName ;
879- } else if (
880- instruction . type === InstructionBuilderTypes . TokenTransfer &&
881- instruction . params . tokenAddress === mintAddress
882- ) {
883- token = instruction . params . tokenName ;
884- }
885- } ) ;
886- }
887-
888- if ( ! token && _useTokenAddressTokenName ) {
889- token = mintAddress ;
890- }
891-
892843 assert ( token ) ;
893844
894845 return token ;
0 commit comments