From f3431917b8029f860851b1e16a4f61057df3f7a1 Mon Sep 17 00:00:00 2001 From: microwavedcola1 <89031858+microwavedcola1@users.noreply.github.com> Date: Thu, 21 Sep 2023 08:02:23 +0200 Subject: [PATCH] ts: if more ixs then more cu (#728) Signed-off-by: microwavedcola1 --- ts/client/src/constants/index.ts | 4 ++++ ts/client/src/utils/rpc.ts | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ts/client/src/constants/index.ts b/ts/client/src/constants/index.ts index 11e4ec270..830ef3349 100644 --- a/ts/client/src/constants/index.ts +++ b/ts/client/src/constants/index.ts @@ -11,6 +11,10 @@ export const RUST_I64_MIN = (): BN => { return new BN('-9223372036854775807'); }; +export const COMPUTE_BUDGET_PROGRAM_ID = new PublicKey( + 'ComputeBudget111111111111111111111111111111', +); + export const OPENBOOK_PROGRAM_ID = { devnet: new PublicKey('EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj'), 'mainnet-beta': new PublicKey('srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX'), diff --git a/ts/client/src/utils/rpc.ts b/ts/client/src/utils/rpc.ts index a2d042e8c..e94ea343e 100644 --- a/ts/client/src/utils/rpc.ts +++ b/ts/client/src/utils/rpc.ts @@ -5,7 +5,6 @@ import { AddressLookupTableAccount, ComputeBudgetProgram, MessageV0, - PublicKey, Signer, TransactionConfirmationStatus, TransactionError, @@ -13,6 +12,7 @@ import { TransactionSignature, VersionedTransaction, } from '@solana/web3.js'; +import { COMPUTE_BUDGET_PROGRAM_ID } from '../constants'; export interface MangoSignatureStatus { slot: number; @@ -45,15 +45,18 @@ export async function sendTransaction( // https://github.com/solana-labs/solana-web3.js/blob/master/packages/library-legacy/src/programs/compute-budget.ts#L202 const computeUnitLimitIxFound = ixs.some( (ix) => - ix.programId.equals( - new PublicKey('ComputeBudget111111111111111111111111111111'), - ) && u8().decode(ix.data.subarray(0, 1)) == 2, + ix.programId.equals(COMPUTE_BUDGET_PROGRAM_ID) && + u8().decode(ix.data.subarray(0, 1)) == 2, ); if (!computeUnitLimitIxFound) { + const totalUserIntendedIxs = ixs.filter( + (ix) => !ix.programId.equals(COMPUTE_BUDGET_PROGRAM_ID), + ).length; + const requestCu = Math.min(totalUserIntendedIxs * 250_000, 1_600_000); ixs = [ ComputeBudgetProgram.setComputeUnitLimit({ - units: 250_000, + units: requestCu, }), ...ixs, ];