ts: if more ixs then more cu (#728)

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
microwavedcola1 2023-09-21 08:02:23 +02:00 committed by GitHub
parent f44b356826
commit f3431917b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -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'),

View File

@ -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,
];