|
@@ -26,6 +26,11 @@ export const DEFAULT_COMPUTE_BUDGET_UNITS = 200000;
|
|
|
export const PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET =
|
|
export const PACKET_DATA_SIZE_WITH_ROOM_FOR_COMPUTE_BUDGET =
|
|
|
PACKET_DATA_SIZE - 52;
|
|
PACKET_DATA_SIZE - 52;
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * The maximum number of transactions in a Jito bundle.
|
|
|
|
|
+ */
|
|
|
|
|
+export const JITO_BUNDLE_SIZE = 5;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* An instruction with some extra information that will be used to build transactions.
|
|
* An instruction with some extra information that will be used to build transactions.
|
|
|
*/
|
|
*/
|
|
@@ -46,7 +51,6 @@ export type PriorityFeeConfig = {
|
|
|
computeUnitPriceMicroLamports?: number;
|
|
computeUnitPriceMicroLamports?: number;
|
|
|
tightComputeBudget?: boolean;
|
|
tightComputeBudget?: boolean;
|
|
|
jitoTipLamports?: number;
|
|
jitoTipLamports?: number;
|
|
|
- jitoBundleSize?: number;
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -188,7 +192,11 @@ export class TransactionBuilder {
|
|
|
this.transactionInstructions.length - 1
|
|
this.transactionInstructions.length - 1
|
|
|
].instructions,
|
|
].instructions,
|
|
|
instruction,
|
|
instruction,
|
|
|
- buildJitoTipInstruction(this.payer, 1),
|
|
|
|
|
|
|
+ this.transactionInstructions.length % JITO_BUNDLE_SIZE === 0 // This transaction may be the first of a Jito bundle, so we leave room for a Jito tip transfer.
|
|
|
|
|
+ ? buildJitoTipInstruction(this.payer, 1)
|
|
|
|
|
+ : ComputeBudgetProgram.setComputeUnitPrice({
|
|
|
|
|
+ microLamports: 1,
|
|
|
|
|
+ }),
|
|
|
ComputeBudgetProgram.setComputeUnitLimit({ units: 1 }),
|
|
ComputeBudgetProgram.setComputeUnitLimit({ units: 1 }),
|
|
|
],
|
|
],
|
|
|
true,
|
|
true,
|
|
@@ -232,9 +240,6 @@ export class TransactionBuilder {
|
|
|
await this.connection.getLatestBlockhash({ commitment: "confirmed" })
|
|
await this.connection.getLatestBlockhash({ commitment: "confirmed" })
|
|
|
).blockhash;
|
|
).blockhash;
|
|
|
|
|
|
|
|
- const jitoBundleSize =
|
|
|
|
|
- args.jitoBundleSize || this.transactionInstructions.length;
|
|
|
|
|
-
|
|
|
|
|
return this.transactionInstructions.map(
|
|
return this.transactionInstructions.map(
|
|
|
({ instructions, signers, computeUnits }, index) => {
|
|
({ instructions, signers, computeUnits }, index) => {
|
|
|
const instructionsWithComputeBudget: TransactionInstruction[] = [
|
|
const instructionsWithComputeBudget: TransactionInstruction[] = [
|
|
@@ -255,7 +260,7 @@ export class TransactionBuilder {
|
|
|
}),
|
|
}),
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
- if (args.jitoTipLamports && index % jitoBundleSize === 0) {
|
|
|
|
|
|
|
+ if (args.jitoTipLamports && index % JITO_BUNDLE_SIZE === 0) {
|
|
|
instructionsWithComputeBudget.push(
|
|
instructionsWithComputeBudget.push(
|
|
|
buildJitoTipInstruction(this.payer, args.jitoTipLamports),
|
|
buildJitoTipInstruction(this.payer, args.jitoTipLamports),
|
|
|
);
|
|
);
|
|
@@ -297,9 +302,6 @@ export class TransactionBuilder {
|
|
|
buildLegacyTransactions(
|
|
buildLegacyTransactions(
|
|
|
args: PriorityFeeConfig,
|
|
args: PriorityFeeConfig,
|
|
|
): { tx: Transaction; signers: Signer[] }[] {
|
|
): { tx: Transaction; signers: Signer[] }[] {
|
|
|
- const jitoBundleSize =
|
|
|
|
|
- args.jitoBundleSize || this.transactionInstructions.length;
|
|
|
|
|
-
|
|
|
|
|
return this.transactionInstructions.map(
|
|
return this.transactionInstructions.map(
|
|
|
({ instructions, signers, computeUnits }, index) => {
|
|
({ instructions, signers, computeUnits }, index) => {
|
|
|
const instructionsWithComputeBudget: TransactionInstruction[] = [
|
|
const instructionsWithComputeBudget: TransactionInstruction[] = [
|
|
@@ -320,7 +322,7 @@ export class TransactionBuilder {
|
|
|
}),
|
|
}),
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
- if (args.jitoTipLamports && index % jitoBundleSize === 0) {
|
|
|
|
|
|
|
+ if (args.jitoTipLamports && index % JITO_BUNDLE_SIZE === 0) {
|
|
|
instructionsWithComputeBudget.push(
|
|
instructionsWithComputeBudget.push(
|
|
|
buildJitoTipInstruction(this.payer, args.jitoTipLamports),
|
|
buildJitoTipInstruction(this.payer, args.jitoTipLamports),
|
|
|
);
|
|
);
|