Skip to content

Commit

Permalink
fix(sdk-coin-sol): set priority fee in initBuilder
Browse files Browse the repository at this point in the history
Ticket: COIN-2932
  • Loading branch information
Vijay-Jagannathan committed Jan 31, 2025
1 parent 6a8455b commit b273119
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 9 additions & 0 deletions modules/sdk-coin-sol/src/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
this.feePayer(txData.feePayer as string);
this.nonce(txData.nonce, txData.durableNonce);
this._instructionsData = instructionParamsFactory(tx.type, tx.solTransaction.instructions);
// Set priority fee if it exists
const filteredPriorityFeeInstructionsData = txData.instructionsData.filter(
(data) => data.type === InstructionBuilderTypes.SetPriorityFee
);

if (filteredPriorityFeeInstructionsData.length > 0) {
const priorityFeeInstructionsData = filteredPriorityFeeInstructionsData[0];
this._priorityFee = Number(priorityFeeInstructionsData.params.fee);
}

for (const instruction of this._instructionsData) {
if (instruction.type === InstructionBuilderTypes.Memo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as bs58 from 'bs58';

import { getBuilderFactory } from '../getBuilderFactory';
import { KeyPair, TokenTransferBuilder } from '../../../src';
import { Eddsa, FeeOptions, TransactionType } from '@bitgo/sdk-core';
import { Eddsa, TransactionType } from '@bitgo/sdk-core';
import * as testData from '../../resources/sol';
import BigNumber from 'bignumber.js';
import { Ed25519Bip32HdTree } from '@bitgo/sdk-lib-mpc';
Expand Down Expand Up @@ -164,10 +164,9 @@ describe('Sol Transaction Builder', async () => {
testData.TOKEN_TRANSFER_SIGNED_TX_WITH_MEMO_AND_DURABLE_NONCE
) as TokenTransferBuilder;
const prioFeeMicroLamports = '10000000';
const priorityFee: FeeOptions = {
amount: prioFeeMicroLamports,
};
txBuilder.setPriorityFee(priorityFee);
// We don't have to manually set the priority fee here as the raw txn already has the priority fee instruction;
// therefore once initBuilder is called (it's called within fromImplementation), it will set the txBuilder's priorityFee field
// which will then be used in txBuilder.build() by tokenTransferBuilder to add the set compute fee instruction
const builtTx = await txBuilder.build();
should.equal(builtTx.type, TransactionType.Send);
should.equal(
Expand Down

0 comments on commit b273119

Please sign in to comment.