11import {
22 DecodedTransferCheckedInstruction ,
33 decodeTransferCheckedInstruction ,
4+ DecodedBurnInstruction ,
5+ decodeBurnInstruction ,
6+ DecodedMintToInstruction ,
7+ decodeMintToInstruction ,
48 TOKEN_2022_PROGRAM_ID ,
59} from '@solana/spl-token' ;
610import {
@@ -27,8 +31,10 @@ import { InstructionBuilderTypes, ValidInstructionTypesEnum, walletInitInstructi
2731import {
2832 AtaClose ,
2933 AtaInit ,
34+ Burn ,
3035 InstructionParams ,
3136 Memo ,
37+ MintTo ,
3238 Nonce ,
3339 StakingActivate ,
3440 StakingAuthorize ,
@@ -125,8 +131,10 @@ function parseSendInstructions(
125131 instructions : TransactionInstruction [ ] ,
126132 instructionMetadata ?: InstructionParams [ ] ,
127133 _useTokenAddressTokenName ?: boolean
128- ) : Array < Nonce | Memo | Transfer | TokenTransfer | AtaInit | AtaClose | SetPriorityFee > {
129- const instructionData : Array < Nonce | Memo | Transfer | TokenTransfer | AtaInit | AtaClose | SetPriorityFee > = [ ] ;
134+ ) : Array < Nonce | Memo | Transfer | TokenTransfer | AtaInit | AtaClose | SetPriorityFee | MintTo | Burn > {
135+ const instructionData : Array <
136+ Nonce | Memo | Transfer | TokenTransfer | AtaInit | AtaClose | SetPriorityFee | MintTo | Burn
137+ > = [ ] ;
130138 for ( const instruction of instructions ) {
131139 const type = getInstructionType ( instruction ) ;
132140 switch ( type ) {
@@ -232,6 +240,60 @@ function parseSendInstructions(
232240 } ;
233241 instructionData . push ( setPriorityFee ) ;
234242 break ;
243+ case ValidInstructionTypesEnum . MintTo :
244+ let mintToInstruction : DecodedMintToInstruction ;
245+ if ( instruction . programId . toString ( ) !== TOKEN_2022_PROGRAM_ID . toString ( ) ) {
246+ mintToInstruction = decodeMintToInstruction ( instruction ) ;
247+ } else {
248+ mintToInstruction = decodeMintToInstruction ( instruction , TOKEN_2022_PROGRAM_ID ) ;
249+ }
250+ const mintAddressForMint = mintToInstruction . keys . mint . pubkey . toString ( ) ;
251+ const tokenNameForMint = findTokenName ( mintAddressForMint , instructionMetadata , _useTokenAddressTokenName ) ;
252+ let programIDForMint : string | undefined ;
253+ if ( instruction . programId ) {
254+ programIDForMint = instruction . programId . toString ( ) ;
255+ }
256+ const mintTo : MintTo = {
257+ type : InstructionBuilderTypes . MintTo ,
258+ params : {
259+ mintAddress : mintAddressForMint ,
260+ destinationAddress : mintToInstruction . keys . destination . pubkey . toString ( ) ,
261+ authorityAddress : mintToInstruction . keys . authority . pubkey . toString ( ) ,
262+ amount : mintToInstruction . data . amount . toString ( ) ,
263+ tokenName : tokenNameForMint ,
264+ decimalPlaces : undefined ,
265+ programId : programIDForMint ,
266+ } ,
267+ } ;
268+ instructionData . push ( mintTo ) ;
269+ break ;
270+ case ValidInstructionTypesEnum . Burn :
271+ let burnInstruction : DecodedBurnInstruction ;
272+ if ( instruction . programId . toString ( ) !== TOKEN_2022_PROGRAM_ID . toString ( ) ) {
273+ burnInstruction = decodeBurnInstruction ( instruction ) ;
274+ } else {
275+ burnInstruction = decodeBurnInstruction ( instruction , TOKEN_2022_PROGRAM_ID ) ;
276+ }
277+ const mintAddressForBurn = burnInstruction . keys . mint . pubkey . toString ( ) ;
278+ const tokenNameForBurn = findTokenName ( mintAddressForBurn , instructionMetadata , _useTokenAddressTokenName ) ;
279+ let programIDForBurn : string | undefined ;
280+ if ( instruction . programId ) {
281+ programIDForBurn = instruction . programId . toString ( ) ;
282+ }
283+ const burn : Burn = {
284+ type : InstructionBuilderTypes . Burn ,
285+ params : {
286+ mintAddress : mintAddressForBurn ,
287+ accountAddress : burnInstruction . keys . account . pubkey . toString ( ) ,
288+ authorityAddress : burnInstruction . keys . owner . pubkey . toString ( ) ,
289+ amount : burnInstruction . data . amount . toString ( ) ,
290+ tokenName : tokenNameForBurn ,
291+ decimalPlaces : undefined ,
292+ programId : programIDForBurn ,
293+ } ,
294+ } ;
295+ instructionData . push ( burn ) ;
296+ break ;
235297 default :
236298 throw new NotSupported (
237299 'Invalid transaction, instruction type not supported: ' + getInstructionType ( instruction )
0 commit comments