Skip to content

feat: add customTx transactionType support for sol #6666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/sdk-coin-sol/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export enum ValidInstructionTypesEnum {
DepositSol = 'DepositSol',
WithdrawStake = 'WithdrawStake',
Approve = 'Approve',
CustomInstruction = 'CustomInstruction',
}

// Internal instructions types
Expand Down Expand Up @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion modules/sdk-coin-sol/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ export type ValidInstructionTypes =
| 'SetPriorityFee'
| 'MintTo'
| 'Burn'
| 'Approve';
| 'Approve'
| 'CustomInstruction';

export type StakingAuthorizeParams = {
stakingAddress: string;
Expand Down
2 changes: 2 additions & 0 deletions modules/sdk-coin-sol/src/lib/transactionBuilderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
10 changes: 4 additions & 6 deletions modules/sdk-coin-sol/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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():
Expand All @@ -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';
}
}

Expand Down
6 changes: 2 additions & 4 deletions modules/sdk-coin-sol/test/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down
Loading