Skip to content

Commit f770bd1

Browse files
fix(sdk-coin-sol): set priority fee in initBuilder
Ticket: COIN-2932
1 parent 6a8455b commit f770bd1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
7676
this.feePayer(txData.feePayer as string);
7777
this.nonce(txData.nonce, txData.durableNonce);
7878
this._instructionsData = instructionParamsFactory(tx.type, tx.solTransaction.instructions);
79+
// Parse priority fee instruction data
80+
const filteredPriorityFeeInstructionsData = txData.instructionsData.filter(
81+
(data) => data.type === InstructionBuilderTypes.SetPriorityFee
82+
);
7983

8084
for (const instruction of this._instructionsData) {
8185
if (instruction.type === InstructionBuilderTypes.Memo) {
@@ -87,6 +91,12 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
8791
const advanceNonceInstruction: Nonce = instruction;
8892
this.nonce(txData.nonce, advanceNonceInstruction.params);
8993
}
94+
95+
// If prio fee instruction exists, set the priority fee variable
96+
if (instruction.type === InstructionBuilderTypes.SetPriorityFee) {
97+
const priorityFeeInstructionsData = filteredPriorityFeeInstructionsData[0];
98+
this.setPriorityFee({ amount: Number(priorityFeeInstructionsData.params.fee) });
99+
}
90100
}
91101
}
92102

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as bs58 from 'bs58';
33

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

0 commit comments

Comments
 (0)