From e4fa501c52456885087d448e530c31f3d6131ecf Mon Sep 17 00:00:00 2001 From: michaelessiet Date: Fri, 17 Jan 2025 17:23:15 +0100 Subject: [PATCH] chore: add minimum compute price to constants --- src/constants/index.ts | 6 ++++++ src/tools/drift/drift.ts | 15 ++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/constants/index.ts b/src/constants/index.ts index 69965bf..5e261b4 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -33,3 +33,9 @@ export const DEFAULT_OPTIONS = { export const JUP_API = "https://quote-api.jup.ag/v6"; export const JUP_REFERRAL_ADDRESS = "REFER4ZgmyYx9c6He5XfaTMiGfdLwRnkV4RPp9t9iF3"; + +/** + * Minimum compute price required to carry out complex transactions on the Drift protocol + */ +export const MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS = + 0.000003 * 1000000 * 1000000; diff --git a/src/tools/drift/drift.ts b/src/tools/drift/drift.ts index 9f8f88d..6c6ec1b 100644 --- a/src/tools/drift/drift.ts +++ b/src/tools/drift/drift.ts @@ -35,6 +35,7 @@ import { PublicKey } from "@solana/web3.js"; import { Transaction } from "@solana/web3.js"; import { ComputeBudgetProgram } from "@solana/web3.js"; import type { RawL2Output } from "./types"; +import { MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS } from "../../constants"; export async function initClients( agent: SolanaAgentKit, @@ -68,7 +69,7 @@ export async function initClients( activeSubAccountId: params?.activeSubAccountId, subAccountIds: params?.subAccountIds, txParams: { - computeUnitsPrice: 0.000001 * 1000000 * 1000000, + computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS, }, txSender: new FastSingleTxSender({ connection: agent.connection, @@ -212,7 +213,7 @@ export async function depositToDriftUserAccount( const tx = new Transaction().add(...depInstruction).add( ComputeBudgetProgram.setComputeUnitPrice({ - microLamports: 0.000001 * 1000000 * 1000000, + microLamports: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS, }), ); tx.recentBlockhash = latestBlockhash.blockhash; @@ -277,7 +278,7 @@ export async function withdrawFromDriftUserAccount( const tx = new Transaction().add(...withdrawInstruction).add( ComputeBudgetProgram.setComputeUnitPrice({ - microLamports: 0.000003 * 1000000 * 1000000, + microLamports: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS, }), ); tx.recentBlockhash = latestBlockhash.blockhash; @@ -384,7 +385,7 @@ export async function driftPerpTrade( marketIndex: market.marketIndex, }), { - computeUnitsPrice: 0.000001 * 1000000 * 1000000, + computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS, }, ); } @@ -552,7 +553,7 @@ export async function stakeToDriftInsuranceFund( ), initializeStakeAccount: shouldCreateAccount, txParams: { - computeUnitsPrice: 0.000002 * 1000000 * 1000000, + computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS, }, }); @@ -592,7 +593,7 @@ export async function requestUnstakeFromDriftInsuranceFund( const signature = await driftClient.requestRemoveInsuranceFundStake( token.marketIndex, numberToSafeBN(amount, token.precision), - { computeUnitsPrice: 0.000002 * 1000000 * 1000000 }, + { computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS }, ); await cleanUp(); @@ -630,7 +631,7 @@ export async function unstakeFromDriftInsuranceFund( token.marketIndex, getAssociatedTokenAddressSync(token.mint, agent.wallet.publicKey), { - computeUnitsPrice: 0.000002 * 1000000 * 1000000, + computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS, }, );