@@ -53,21 +53,22 @@ export function instructionParamsFactory(
53
53
type : TransactionType ,
54
54
instructions : TransactionInstruction [ ] ,
55
55
coinName ?: string ,
56
- instructionMetadata ?: InstructionParams [ ]
56
+ instructionMetadata ?: InstructionParams [ ] ,
57
+ _useTokenAddressTokenName ?: boolean
57
58
) : InstructionParams [ ] {
58
59
switch ( type ) {
59
60
case TransactionType . WalletInitialization :
60
61
return parseWalletInitInstructions ( instructions ) ;
61
62
case TransactionType . Send :
62
- return parseSendInstructions ( instructions , instructionMetadata ) ;
63
+ return parseSendInstructions ( instructions , instructionMetadata , _useTokenAddressTokenName ) ;
63
64
case TransactionType . StakingActivate :
64
65
return parseStakingActivateInstructions ( instructions ) ;
65
66
case TransactionType . StakingDeactivate :
66
67
return parseStakingDeactivateInstructions ( instructions , coinName ) ;
67
68
case TransactionType . StakingWithdraw :
68
69
return parseStakingWithdrawInstructions ( instructions ) ;
69
70
case TransactionType . AssociatedTokenAccountInitialization :
70
- return parseAtaInitInstructions ( instructions , instructionMetadata ) ;
71
+ return parseAtaInitInstructions ( instructions , instructionMetadata , _useTokenAddressTokenName ) ;
71
72
case TransactionType . CloseAssociatedTokenAccount :
72
73
return parseAtaCloseInstructions ( instructions ) ;
73
74
case TransactionType . StakingAuthorize :
@@ -122,7 +123,8 @@ function parseWalletInitInstructions(instructions: TransactionInstruction[]): Ar
122
123
*/
123
124
function parseSendInstructions (
124
125
instructions : TransactionInstruction [ ] ,
125
- instructionMetadata ?: InstructionParams [ ]
126
+ instructionMetadata ?: InstructionParams [ ] ,
127
+ _useTokenAddressTokenName ?: boolean
126
128
) : Array < Nonce | Memo | Transfer | TokenTransfer | AtaInit | AtaClose | SetPriorityFee > {
127
129
const instructionData : Array < Nonce | Memo | Transfer | TokenTransfer | AtaInit | AtaClose | SetPriorityFee > = [ ] ;
128
130
for ( const instruction of instructions ) {
@@ -162,7 +164,12 @@ function parseSendInstructions(
162
164
} else {
163
165
tokenTransferInstruction = decodeTransferCheckedInstruction ( instruction , TOKEN_2022_PROGRAM_ID ) ;
164
166
}
165
- const tokenName = findTokenName ( tokenTransferInstruction . keys . mint . pubkey . toString ( ) , instructionMetadata ) ;
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
+ }
166
173
const tokenTransfer : TokenTransfer = {
167
174
type : InstructionBuilderTypes . TokenTransfer ,
168
175
params : {
@@ -171,13 +178,20 @@ function parseSendInstructions(
171
178
amount : tokenTransferInstruction . data . amount . toString ( ) ,
172
179
tokenName,
173
180
sourceAddress : tokenTransferInstruction . keys . source . pubkey . toString ( ) ,
181
+ tokenAddress : tokenAddress ,
182
+ programId : programIDForTokenTransfer ,
183
+ decimalPlaces : tokenTransferInstruction . data . decimals ,
174
184
} ,
175
185
} ;
176
186
instructionData . push ( tokenTransfer ) ;
177
187
break ;
178
188
case ValidInstructionTypesEnum . InitializeAssociatedTokenAccount :
179
189
const mintAddress = instruction . keys [ ataInitInstructionKeysIndexes . MintAddress ] . pubkey . toString ( ) ;
180
- const mintTokenName = findTokenName ( mintAddress , instructionMetadata ) ;
190
+ const mintTokenName = findTokenName ( mintAddress , instructionMetadata , _useTokenAddressTokenName ) ;
191
+ let programID : string | undefined ;
192
+ if ( instruction . programId ) {
193
+ programID = instruction . programId . toString ( ) ;
194
+ }
181
195
182
196
const ataInit : AtaInit = {
183
197
type : InstructionBuilderTypes . CreateAssociatedTokenAccount ,
@@ -187,6 +201,7 @@ function parseSendInstructions(
187
201
ownerAddress : instruction . keys [ ataInitInstructionKeysIndexes . OwnerAddress ] . pubkey . toString ( ) ,
188
202
payerAddress : instruction . keys [ ataInitInstructionKeysIndexes . PayerAddress ] . pubkey . toString ( ) ,
189
203
tokenName : mintTokenName ,
204
+ programId : programID ,
190
205
} ,
191
206
} ;
192
207
instructionData . push ( ataInit ) ;
@@ -656,7 +671,8 @@ const closeAtaInstructionKeysIndexes = {
656
671
*/
657
672
function parseAtaInitInstructions (
658
673
instructions : TransactionInstruction [ ] ,
659
- instructionMetadata ?: InstructionParams [ ]
674
+ instructionMetadata ?: InstructionParams [ ] ,
675
+ _useTokenAddressTokenName ?: boolean
660
676
) : Array < AtaInit | Memo | Nonce > {
661
677
const instructionData : Array < AtaInit | Memo | Nonce > = [ ] ;
662
678
let memo : Memo | undefined ;
@@ -680,8 +696,11 @@ function parseAtaInitInstructions(
680
696
break ;
681
697
case ValidInstructionTypesEnum . InitializeAssociatedTokenAccount :
682
698
const mintAddress = instruction . keys [ ataInitInstructionKeysIndexes . MintAddress ] . pubkey . toString ( ) ;
683
- const tokenName = findTokenName ( mintAddress , instructionMetadata ) ;
684
-
699
+ const tokenName = findTokenName ( mintAddress , instructionMetadata , _useTokenAddressTokenName ) ;
700
+ let programID : string | undefined ;
701
+ if ( instruction . programId ) {
702
+ programID = instruction . programId . toString ( ) ;
703
+ }
685
704
const ataInit : AtaInit = {
686
705
type : InstructionBuilderTypes . CreateAssociatedTokenAccount ,
687
706
params : {
@@ -690,6 +709,7 @@ function parseAtaInitInstructions(
690
709
ownerAddress : instruction . keys [ ataInitInstructionKeysIndexes . OwnerAddress ] . pubkey . toString ( ) ,
691
710
payerAddress : instruction . keys [ ataInitInstructionKeysIndexes . PayerAddress ] . pubkey . toString ( ) ,
692
711
tokenName,
712
+ programId : programID ,
693
713
} ,
694
714
} ;
695
715
instructionData . push ( ataInit ) ;
@@ -836,7 +856,11 @@ function parseStakingAuthorizeRawInstructions(instructions: TransactionInstructi
836
856
return instructionData ;
837
857
}
838
858
839
- function findTokenName ( mintAddress : string , instructionMetadata ?: InstructionParams [ ] ) : string {
859
+ function findTokenName (
860
+ mintAddress : string ,
861
+ instructionMetadata ?: InstructionParams [ ] ,
862
+ _useTokenAddressTokenName ?: boolean
863
+ ) : string {
840
864
let token : string | undefined ;
841
865
842
866
coins . forEach ( ( value , key ) => {
@@ -860,6 +884,11 @@ function findTokenName(mintAddress: string, instructionMetadata?: InstructionPar
860
884
}
861
885
} ) ;
862
886
}
887
+
888
+ if ( ! token && _useTokenAddressTokenName ) {
889
+ token = mintAddress ;
890
+ }
891
+
863
892
assert ( token ) ;
864
893
865
894
return token ;
0 commit comments