Skip to content

Commit e4fa501

Browse files
committed
chore: add minimum compute price to constants
1 parent 67fa821 commit e4fa501

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/constants/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ export const DEFAULT_OPTIONS = {
3333
export const JUP_API = "https://quote-api.jup.ag/v6";
3434
export const JUP_REFERRAL_ADDRESS =
3535
"REFER4ZgmyYx9c6He5XfaTMiGfdLwRnkV4RPp9t9iF3";
36+
37+
/**
38+
* Minimum compute price required to carry out complex transactions on the Drift protocol
39+
*/
40+
export const MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS =
41+
0.000003 * 1000000 * 1000000;

src/tools/drift/drift.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { PublicKey } from "@solana/web3.js";
3535
import { Transaction } from "@solana/web3.js";
3636
import { ComputeBudgetProgram } from "@solana/web3.js";
3737
import type { RawL2Output } from "./types";
38+
import { MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS } from "../../constants";
3839

3940
export async function initClients(
4041
agent: SolanaAgentKit,
@@ -68,7 +69,7 @@ export async function initClients(
6869
activeSubAccountId: params?.activeSubAccountId,
6970
subAccountIds: params?.subAccountIds,
7071
txParams: {
71-
computeUnitsPrice: 0.000001 * 1000000 * 1000000,
72+
computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS,
7273
},
7374
txSender: new FastSingleTxSender({
7475
connection: agent.connection,
@@ -212,7 +213,7 @@ export async function depositToDriftUserAccount(
212213

213214
const tx = new Transaction().add(...depInstruction).add(
214215
ComputeBudgetProgram.setComputeUnitPrice({
215-
microLamports: 0.000001 * 1000000 * 1000000,
216+
microLamports: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS,
216217
}),
217218
);
218219
tx.recentBlockhash = latestBlockhash.blockhash;
@@ -277,7 +278,7 @@ export async function withdrawFromDriftUserAccount(
277278

278279
const tx = new Transaction().add(...withdrawInstruction).add(
279280
ComputeBudgetProgram.setComputeUnitPrice({
280-
microLamports: 0.000003 * 1000000 * 1000000,
281+
microLamports: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS,
281282
}),
282283
);
283284
tx.recentBlockhash = latestBlockhash.blockhash;
@@ -384,7 +385,7 @@ export async function driftPerpTrade(
384385
marketIndex: market.marketIndex,
385386
}),
386387
{
387-
computeUnitsPrice: 0.000001 * 1000000 * 1000000,
388+
computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS,
388389
},
389390
);
390391
}
@@ -552,7 +553,7 @@ export async function stakeToDriftInsuranceFund(
552553
),
553554
initializeStakeAccount: shouldCreateAccount,
554555
txParams: {
555-
computeUnitsPrice: 0.000002 * 1000000 * 1000000,
556+
computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS,
556557
},
557558
});
558559

@@ -592,7 +593,7 @@ export async function requestUnstakeFromDriftInsuranceFund(
592593
const signature = await driftClient.requestRemoveInsuranceFundStake(
593594
token.marketIndex,
594595
numberToSafeBN(amount, token.precision),
595-
{ computeUnitsPrice: 0.000002 * 1000000 * 1000000 },
596+
{ computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS },
596597
);
597598

598599
await cleanUp();
@@ -630,7 +631,7 @@ export async function unstakeFromDriftInsuranceFund(
630631
token.marketIndex,
631632
getAssociatedTokenAddressSync(token.mint, agent.wallet.publicKey),
632633
{
633-
computeUnitsPrice: 0.000002 * 1000000 * 1000000,
634+
computeUnitsPrice: MINIMUM_COMPUTE_PRICE_FOR_COMPLEX_ACTIONS,
634635
},
635636
);
636637

0 commit comments

Comments
 (0)