diff --git a/modules/sdk-coin-sol/src/lib/constants.ts b/modules/sdk-coin-sol/src/lib/constants.ts index 69848ae7ca..d13b8ab955 100644 --- a/modules/sdk-coin-sol/src/lib/constants.ts +++ b/modules/sdk-coin-sol/src/lib/constants.ts @@ -40,6 +40,7 @@ export enum ValidInstructionTypesEnum { DepositSol = 'DepositSol', WithdrawStake = 'WithdrawStake', Approve = 'Approve', + CustomInstruction = 'CustomInstruction', } // Internal instructions types @@ -87,6 +88,7 @@ export const VALID_SYSTEM_INSTRUCTION_TYPES: ValidInstructionTypes[] = [ ValidInstructionTypesEnum.Approve, ValidInstructionTypesEnum.DepositSol, ValidInstructionTypesEnum.WithdrawStake, + ValidInstructionTypesEnum.CustomInstruction, ]; /** Const to check the order of the Wallet Init instructions when decode */ diff --git a/modules/sdk-coin-sol/src/lib/iface.ts b/modules/sdk-coin-sol/src/lib/iface.ts index 36eaf81497..7d554a0d35 100644 --- a/modules/sdk-coin-sol/src/lib/iface.ts +++ b/modules/sdk-coin-sol/src/lib/iface.ts @@ -222,7 +222,8 @@ export type ValidInstructionTypes = | 'SetPriorityFee' | 'MintTo' | 'Burn' - | 'Approve'; + | 'Approve' + | 'CustomInstruction'; export type StakingAuthorizeParams = { stakingAddress: string; diff --git a/modules/sdk-coin-sol/src/lib/transactionBuilderFactory.ts b/modules/sdk-coin-sol/src/lib/transactionBuilderFactory.ts index 25dc9311ca..ee7260cebc 100644 --- a/modules/sdk-coin-sol/src/lib/transactionBuilderFactory.ts +++ b/modules/sdk-coin-sol/src/lib/transactionBuilderFactory.ts @@ -59,6 +59,8 @@ export class TransactionBuilderFactory extends BaseTransactionBuilderFactory { return this.getStakingDelegateBuilder(tx); case TransactionType.CloseAssociatedTokenAccount: return this.getCloseAtaInitializationBuilder(tx); + case TransactionType.CustomTx: + return this.getCustomInstructionBuilder(tx); default: throw new InvalidTransactionError('Invalid transaction'); } diff --git a/modules/sdk-coin-sol/src/lib/utils.ts b/modules/sdk-coin-sol/src/lib/utils.ts index 5857130574..644607bb98 100644 --- a/modules/sdk-coin-sol/src/lib/utils.ts +++ b/modules/sdk-coin-sol/src/lib/utils.ts @@ -344,7 +344,7 @@ export function getTransactionType(transaction: SolTransaction): TransactionType } else if (matchTransactionTypeByInstructionsOrder(instructions, ataCloseInstructionIndexes)) { return TransactionType.CloseAssociatedTokenAccount; } else { - throw new NotSupported('Invalid transaction, transaction not supported or invalid'); + return TransactionType.CustomTx; } } @@ -371,8 +371,8 @@ export function getInstructionType(instruction: TransactionInstruction): ValidIn instructionTypeMap.set(TokenInstruction.Approve, 'Approve'); instructionTypeMap.set(TokenInstruction.TransferChecked, 'TokenTransfer'); const validInstruction = instructionTypeMap.get(decodedInstruction.data.instruction); - if (validInstruction === undefined) { - throw new Error(`Unsupported token instruction type ${decodedInstruction.data.instruction}`); + if (!validInstruction) { + return 'CustomInstruction'; } return validInstruction; case STAKE_POOL_PROGRAM_ID.toString(): @@ -397,9 +397,7 @@ export function getInstructionType(instruction: TransactionInstruction): ValidIn case COMPUTE_BUDGET: return 'SetPriorityFee'; default: - throw new NotSupported( - 'Invalid transaction, instruction program id not supported: ' + instruction.programId.toString() - ); + return 'CustomInstruction'; } } diff --git a/modules/sdk-coin-sol/test/unit/utils.ts b/modules/sdk-coin-sol/test/unit/utils.ts index 141076551b..e93e540321 100644 --- a/modules/sdk-coin-sol/test/unit/utils.ts +++ b/modules/sdk-coin-sol/test/unit/utils.ts @@ -235,16 +235,14 @@ describe('SOL util library', function () { }); Utils.getInstructionType(transferInstruction).should.equal('Transfer'); }); - it('should fail for invalid type ', function () { + it('should fallback to customInstruction for unsupported instructionType', function () { const voteAddress = 'Vote111111111111111111111111111111111111111'; const invalidInstruction = new TransactionInstruction({ keys: [], programId: new PublicKey(voteAddress), data: Buffer.from('random memo'), }); - should(() => Utils.getInstructionType(invalidInstruction)).throwError( - 'Invalid transaction, instruction program id not supported: ' + voteAddress - ); + Utils.getInstructionType(invalidInstruction).should.equal('CustomInstruction'); }); });