diff --git a/target_chains/solana/sdk/js/solana_utils/package.json b/target_chains/solana/sdk/js/solana_utils/package.json index 729ae32397..7e9dc50174 100644 --- a/target_chains/solana/sdk/js/solana_utils/package.json +++ b/target_chains/solana/sdk/js/solana_utils/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/solana-utils", - "version": "0.4.1", + "version": "0.4.2", "description": "Utility functions for Solana", "homepage": "https://pyth.network", "main": "lib/index.js", diff --git a/target_chains/solana/sdk/js/solana_utils/src/transaction.ts b/target_chains/solana/sdk/js/solana_utils/src/transaction.ts index b38f2d8e89..ba3340d7b8 100644 --- a/target_chains/solana/sdk/js/solana_utils/src/transaction.ts +++ b/target_chains/solana/sdk/js/solana_utils/src/transaction.ts @@ -259,11 +259,25 @@ export class TransactionBuilder { ); } + // 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 + const instructionsToSend: TransactionInstruction[] = []; + for (const instruction of instructionsWithComputeBudget) { + const sizeWithInstruction = getSizeOfTransaction( + [...instructionsToSend, instruction], + true, + this.addressLookupTable + ); + if (sizeWithInstruction > PACKET_DATA_SIZE) { + break; + } + instructionsToSend.push(instruction); + } + return { tx: new VersionedTransaction( new TransactionMessage({ recentBlockhash: blockhash, - instructions: instructionsWithComputeBudget, + instructions: instructionsToSend, payerKey: this.payer, }).compileToV0Message( this.addressLookupTable ? [this.addressLookupTable] : [] @@ -310,8 +324,21 @@ export class TransactionBuilder { ); } + // 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 + const instructionsToSend: TransactionInstruction[] = []; + for (const instruction of instructionsWithComputeBudget) { + const sizeWithInstruction = getSizeOfTransaction( + [...instructionsToSend, instruction], + false + ); + if (sizeWithInstruction > PACKET_DATA_SIZE) { + break; + } + instructionsToSend.push(instruction); + } + return { - tx: new Transaction().add(...instructionsWithComputeBudget), + tx: new Transaction().add(...instructionsToSend), signers: signers, }; }