Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
TransactionBuilder should include computeBudgetLimit for fixed budget…
Browse files Browse the repository at this point in the history
… option (#97)
  • Loading branch information
zach225 authored Dec 10, 2024
1 parent e938793 commit 340564e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/common-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orca-so/common-sdk",
"version": "0.6.4",
"version": "0.6.5",
"description": "Common Typescript components across Orca",
"repository": "https://github.com/orca-so/orca-sdks",
"author": "Orca Foundation",
Expand Down
29 changes: 22 additions & 7 deletions packages/common-sdk/src/web3/transactions/transactions-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,12 @@ export class TransactionBuilder {
ComputeBudgetProgram.setComputeUnitLimit({
units: computeLimit,
}),
ComputeBudgetProgram.setComputeUnitPrice({
microLamports,
}),
];
if (microLamports > 0) {
prependInstructions.push(ComputeBudgetProgram.setComputeUnitPrice({
microLamports,
}));
}
if (computeBudgetOption.jitoTipLamports && computeBudgetOption.jitoTipLamports > 0) {
prependInstructions.push(
SystemProgram.transfer({
Expand Down Expand Up @@ -397,18 +399,19 @@ export class TransactionBuilder {
recentBlockhash = await this.connection.getLatestBlockhash(blockhashCommitment);
}
let finalComputeBudgetOption = computeBudgetOption ?? { type: "none" };
if (finalComputeBudgetOption.type === "auto") {
const margin = finalComputeBudgetOption.computeLimitMargin ?? 0.1;
const lookupTableAccounts =

const lookupTableAccounts =
finalOptions.maxSupportedTransactionVersion === "legacy"
? undefined
: finalOptions.lookupTableAccounts;

if (finalComputeBudgetOption.type === "auto") {
const computeBudgetLimit = await estimateComputeBudgetLimit(
this.connection,
this.instructions,
lookupTableAccounts,
this.wallet.publicKey,
margin,
finalComputeBudgetOption.computeLimitMargin ?? 0.1,
);
const percentile =
finalComputeBudgetOption.computePricePercentile ?? DEFAULT_PRIORITY_FEE_PERCENTILE;
Expand All @@ -433,6 +436,18 @@ export class TransactionBuilder {
computeBudgetLimit,
jitoTipLamports: finalComputeBudgetOption.jitoTipLamports,
};
} else if (finalComputeBudgetOption.type === "fixed" && finalComputeBudgetOption.computeBudgetLimit === undefined) {
const computeBudgetLimit = await estimateComputeBudgetLimit(
this.connection,
this.instructions,
lookupTableAccounts,
this.wallet.publicKey,
0.1,
);
finalComputeBudgetOption = {
...finalComputeBudgetOption,
computeBudgetLimit,
};
}
return this.buildSync({
...finalOptions,
Expand Down

0 comments on commit 340564e

Please sign in to comment.