Skip to content

Commit 3cb45ec

Browse files
authored
fix:solana utils single tx (#1743)
* add fix * bump * improve comment
1 parent 2c2bfe3 commit 3cb45ec

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Diff for: target_chains/solana/sdk/js/solana_utils/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/solana-utils",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "Utility functions for Solana",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

Diff for: target_chains/solana/sdk/js/solana_utils/src/transaction.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,25 @@ export class TransactionBuilder {
259259
);
260260
}
261261

262+
// This handles an edge case where a single instruction is too big and therefore needs to be by itself without any compute budget instructions or jito tips
263+
const instructionsToSend: TransactionInstruction[] = [];
264+
for (const instruction of instructionsWithComputeBudget) {
265+
const sizeWithInstruction = getSizeOfTransaction(
266+
[...instructionsToSend, instruction],
267+
true,
268+
this.addressLookupTable
269+
);
270+
if (sizeWithInstruction > PACKET_DATA_SIZE) {
271+
break;
272+
}
273+
instructionsToSend.push(instruction);
274+
}
275+
262276
return {
263277
tx: new VersionedTransaction(
264278
new TransactionMessage({
265279
recentBlockhash: blockhash,
266-
instructions: instructionsWithComputeBudget,
280+
instructions: instructionsToSend,
267281
payerKey: this.payer,
268282
}).compileToV0Message(
269283
this.addressLookupTable ? [this.addressLookupTable] : []
@@ -310,8 +324,21 @@ export class TransactionBuilder {
310324
);
311325
}
312326

327+
// This handles an edge case where a single instruction is too big and therefore needs to be by itself without any compute budget instructions or jito tips
328+
const instructionsToSend: TransactionInstruction[] = [];
329+
for (const instruction of instructionsWithComputeBudget) {
330+
const sizeWithInstruction = getSizeOfTransaction(
331+
[...instructionsToSend, instruction],
332+
false
333+
);
334+
if (sizeWithInstruction > PACKET_DATA_SIZE) {
335+
break;
336+
}
337+
instructionsToSend.push(instruction);
338+
}
339+
313340
return {
314-
tx: new Transaction().add(...instructionsWithComputeBudget),
341+
tx: new Transaction().add(...instructionsToSend),
315342
signers: signers,
316343
};
317344
}

0 commit comments

Comments
 (0)