Skip to content
Open
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
9 changes: 9 additions & 0 deletions modules/sdk-coin-sol/src/lib/ataInitializationBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ export class AtaInitializationBuilder extends TransactionBuilder {
}

this._instructionsData = [];
if (this._priorityFee && this._priorityFee !== Number(0)) {
this._instructionsData.push({
type: InstructionBuilderTypes.SetPriorityFee,
params: {
fee: this._priorityFee,
},
});
}

await Promise.all(
this._tokenAssociateRecipients.map(async (recipient) => {
let tokenAddress: string;
Expand Down
11 changes: 10 additions & 1 deletion modules/sdk-coin-sol/src/lib/stakingActivateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ export class StakingActivateBuilder extends TransactionBuilder {
extraParams: this._extraParams,
},
};
this._instructionsData = [stakingAccountData];
this._instructionsData =
this._priorityFee && this._priorityFee !== Number(0)
? [
{
type: InstructionBuilderTypes.SetPriorityFee,
params: { fee: this._priorityFee },
},
stakingAccountData,
]
: [stakingAccountData];

return await super.buildImplementation();
}
Expand Down
7 changes: 7 additions & 0 deletions modules/sdk-coin-sol/src/lib/stakingDeactivateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ export class StakingDeactivateBuilder extends TransactionBuilder {
this._instructionsData.push(stakingDeactivateData);
}

if (this._priorityFee && this._priorityFee !== Number(0)) {
this._instructionsData.unshift({
type: InstructionBuilderTypes.SetPriorityFee,
params: { fee: this._priorityFee },
});
}

return await super.buildImplementation();
}
}
6 changes: 6 additions & 0 deletions modules/sdk-coin-sol/src/lib/stakingDelegateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export class StakingDelegateBuilder extends TransactionBuilder {
};
this._instructionsData = [stakingAccountData];
}
if (this._priorityFee && this._priorityFee !== Number(0)) {
this._instructionsData.unshift({
type: InstructionBuilderTypes.SetPriorityFee,
params: { fee: this._priorityFee },
});
}
return await super.buildImplementation();
}
}
11 changes: 10 additions & 1 deletion modules/sdk-coin-sol/src/lib/stakingWithdrawBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ export class StakingWithdrawBuilder extends TransactionBuilder {
amount: this._amount,
},
};
this._instructionsData = [stakingWithdrawData];
this._instructionsData =
this._priorityFee && this._priorityFee !== Number(0)
? [
{
type: InstructionBuilderTypes.SetPriorityFee,
params: { fee: this._priorityFee },
},
stakingWithdrawData,
]
: [stakingWithdrawData];

return await super.buildImplementation();
}
Expand Down
13 changes: 12 additions & 1 deletion modules/sdk-coin-sol/src/lib/transferBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,18 @@ export class TransferBuilder extends TransactionBuilder {
},
};
});
this._instructionsData = transferData;
// Prepend the priority fee instruction (CHALO-485) so native SOL transfers can be
// prioritized during network congestion. Omitted when no priority fee is set (0).
this._instructionsData =
this._priorityFee && this._priorityFee !== Number(0)
? [
{
type: InstructionBuilderTypes.SetPriorityFee,
params: { fee: this._priorityFee },
},
...transferData,
]
: transferData;

return await super.buildImplementation();
}
Expand Down
6 changes: 1 addition & 5 deletions modules/sdk-coin-sol/src/lib/transferBuilderV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,9 @@ export class TransferBuilderV2 extends TransactionBuilder {
: [];

let addPriorityFeeInstruction: SetPriorityFee;
// If there are createAtaInstructions, then token is involved and we need to add a priority fee instruction
if (!this._priorityFee || this._priorityFee === Number(0)) {
this._instructionsData = [...createAtaInstructions, ...thawInstructions, ...sendInstructions];
} else if (
createAtaInstructions.length !== 0 ||
sendInstructions.some((instruction) => instruction.type === InstructionBuilderTypes.TokenTransfer)
) {
} else {
addPriorityFeeInstruction = {
type: InstructionBuilderTypes.SetPriorityFee,
params: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getBuilderFactory } from '../getBuilderFactory';
import { KeyPair, Utils } from '../../../src';
import { TransactionType } from '@bitgo/sdk-core';
import should from 'should';
import * as testData from '../../resources/sol';

Expand Down Expand Up @@ -231,6 +232,24 @@ describe('Sol Transfer Builder', () => {
should.equal(Utils.isValidRawTransaction(rawTx), true);
should.equal(rawTx, testData.MULTI_TRANSFER_SIGNED);
});

it('build a signed transfer with priority fee', async () => {
const txBuilder = transferBuilder();
txBuilder.sender(authAccount.pub);
txBuilder.send({ address: nonceAccount.pub, amount });
txBuilder.setPriorityFee({ amount: 50000 });
txBuilder.sign({ key: authAccount.prv });
const tx = await txBuilder.build();
tx.type.should.equal(TransactionType.Send);
const rawTx = tx.toBroadcastFormat();
should.equal(Utils.isValidRawTransaction(rawTx), true);
const onChainInstructions = (tx as any).solTransaction.instructions;
onChainInstructions
.some(
(ix: any) => ix.programId.toString() === 'ComputeBudget111111111111111111111111111111' && ix.data.length > 0
)
.should.equal(true);
});
});
describe('Fail', () => {
it('for invalid sender', () => {
Expand Down
Loading