Skip to content

Commit e798cb1

Browse files
authored
Merge pull request #6666 from BitGo/TMS-1338-customTx-support
feat: add customTx transactionType support for sol
2 parents b22bb38 + 00fe22f commit e798cb1

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

modules/sdk-coin-sol/src/lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export enum ValidInstructionTypesEnum {
4040
DepositSol = 'DepositSol',
4141
WithdrawStake = 'WithdrawStake',
4242
Approve = 'Approve',
43+
CustomInstruction = 'CustomInstruction',
4344
}
4445

4546
// Internal instructions types
@@ -87,6 +88,7 @@ export const VALID_SYSTEM_INSTRUCTION_TYPES: ValidInstructionTypes[] = [
8788
ValidInstructionTypesEnum.Approve,
8889
ValidInstructionTypesEnum.DepositSol,
8990
ValidInstructionTypesEnum.WithdrawStake,
91+
ValidInstructionTypesEnum.CustomInstruction,
9092
];
9193

9294
/** Const to check the order of the Wallet Init instructions when decode */

modules/sdk-coin-sol/src/lib/iface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ export type ValidInstructionTypes =
222222
| 'SetPriorityFee'
223223
| 'MintTo'
224224
| 'Burn'
225-
| 'Approve';
225+
| 'Approve'
226+
| 'CustomInstruction';
226227

227228
export type StakingAuthorizeParams = {
228229
stakingAddress: string;

modules/sdk-coin-sol/src/lib/transactionBuilderFactory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export class TransactionBuilderFactory extends BaseTransactionBuilderFactory {
5959
return this.getStakingDelegateBuilder(tx);
6060
case TransactionType.CloseAssociatedTokenAccount:
6161
return this.getCloseAtaInitializationBuilder(tx);
62+
case TransactionType.CustomTx:
63+
return this.getCustomInstructionBuilder(tx);
6264
default:
6365
throw new InvalidTransactionError('Invalid transaction');
6466
}

modules/sdk-coin-sol/src/lib/utils.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export function getTransactionType(transaction: SolTransaction): TransactionType
344344
} else if (matchTransactionTypeByInstructionsOrder(instructions, ataCloseInstructionIndexes)) {
345345
return TransactionType.CloseAssociatedTokenAccount;
346346
} else {
347-
throw new NotSupported('Invalid transaction, transaction not supported or invalid');
347+
return TransactionType.CustomTx;
348348
}
349349
}
350350

@@ -371,8 +371,8 @@ export function getInstructionType(instruction: TransactionInstruction): ValidIn
371371
instructionTypeMap.set(TokenInstruction.Approve, 'Approve');
372372
instructionTypeMap.set(TokenInstruction.TransferChecked, 'TokenTransfer');
373373
const validInstruction = instructionTypeMap.get(decodedInstruction.data.instruction);
374-
if (validInstruction === undefined) {
375-
throw new Error(`Unsupported token instruction type ${decodedInstruction.data.instruction}`);
374+
if (!validInstruction) {
375+
return 'CustomInstruction';
376376
}
377377
return validInstruction;
378378
case STAKE_POOL_PROGRAM_ID.toString():
@@ -397,9 +397,7 @@ export function getInstructionType(instruction: TransactionInstruction): ValidIn
397397
case COMPUTE_BUDGET:
398398
return 'SetPriorityFee';
399399
default:
400-
throw new NotSupported(
401-
'Invalid transaction, instruction program id not supported: ' + instruction.programId.toString()
402-
);
400+
return 'CustomInstruction';
403401
}
404402
}
405403

modules/sdk-coin-sol/test/unit/utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,14 @@ describe('SOL util library', function () {
235235
});
236236
Utils.getInstructionType(transferInstruction).should.equal('Transfer');
237237
});
238-
it('should fail for invalid type ', function () {
238+
it('should fallback to customInstruction for unsupported instructionType', function () {
239239
const voteAddress = 'Vote111111111111111111111111111111111111111';
240240
const invalidInstruction = new TransactionInstruction({
241241
keys: [],
242242
programId: new PublicKey(voteAddress),
243243
data: Buffer.from('random memo'),
244244
});
245-
should(() => Utils.getInstructionType(invalidInstruction)).throwError(
246-
'Invalid transaction, instruction program id not supported: ' + voteAddress
247-
);
245+
Utils.getInstructionType(invalidInstruction).should.equal('CustomInstruction');
248246
});
249247
});
250248

0 commit comments

Comments
 (0)