Skip to content

Commit c75e783

Browse files
authored
makerBidAskTwapCrank: skip simulation if updating switchboard oracle (#328)
1 parent 02ddddb commit c75e783

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/bots/makerBidAskTwapCrank.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ export class MakerBidAskTwapCrank implements Bot {
365365

366366
private async buildTransaction(
367367
marketIndex: number,
368-
ixs: TransactionInstruction[]
368+
ixs: TransactionInstruction[],
369+
doSimulation = true
369370
): Promise<VersionedTransaction | undefined> {
370371
const recentBlockhash =
371372
await this.driftClient.connection.getLatestBlockhash('confirmed');
@@ -377,7 +378,7 @@ export class MakerBidAskTwapCrank implements Bot {
377378
lookupTableAccounts: this.lookupTableAccounts,
378379
cuLimitMultiplier: CU_EST_MULTIPLIER,
379380
minCuLimit: TWAP_CRANK_MIN_CU,
380-
doSimulation: true,
381+
doSimulation,
381382
recentBlockhash: recentBlockhash.blockhash,
382383
});
383384
logger.info(
@@ -476,9 +477,15 @@ export class MakerBidAskTwapCrank implements Bot {
476477
let txsToBundle: VersionedTransaction[] = [];
477478

478479
for (const mi of crankMarkets) {
480+
const usingSwitchboardOnDemand = isVariant(
481+
this.driftClient.getPerpMarketAccount(mi)!.amm.oracleSource,
482+
'switchboardOnDemand'
483+
);
479484
const ixs = [
480485
ComputeBudgetProgram.setComputeUnitLimit({
481-
units: 1_400_000, // will be overwritten by simulateAndGetTxWithCUs
486+
units: usingSwitchboardOnDemand
487+
? 350_000 // switchboard simulation is unreliable, use hardcoded CU limit
488+
: 1_400_000, // will be overwritten by simulateAndGetTxWithCUs
482489
}),
483490
];
484491

@@ -547,12 +554,7 @@ export class MakerBidAskTwapCrank implements Bot {
547554
const pythIxs = await this.getPythIxsFromTwapCrankInfo(mi);
548555
ixs.push(...pythIxs);
549556
pythIxsPushed = true;
550-
} else if (
551-
isVariant(
552-
this.driftClient.getPerpMarketAccount(mi)!.amm.oracleSource,
553-
'switchboardOnDemand'
554-
)
555-
) {
557+
} else if (usingSwitchboardOnDemand) {
556558
const switchboardIx =
557559
await this.driftClient.getPostSwitchboardOnDemandUpdateAtomicIx(
558560
this.driftClient.getPerpMarketAccount(mi)!.amm.oracle,
@@ -596,7 +598,11 @@ export class MakerBidAskTwapCrank implements Bot {
596598
if (isFirstTxInBundle) {
597599
ixs.push(this.bundleSender!.getTipIx());
598600
}
599-
const txToSend = await this.buildTransaction(mi, ixs);
601+
const txToSend = await this.buildTransaction(
602+
mi,
603+
ixs,
604+
!usingSwitchboardOnDemand
605+
);
600606
if (txToSend) {
601607
// @ts-ignore;
602608
txToSend.sign(jitoSigners);
@@ -605,7 +611,11 @@ export class MakerBidAskTwapCrank implements Bot {
605611
logger.error(`[${this.name}] failed to build tx for market: ${mi}`);
606612
}
607613
} else {
608-
const txToSend = await this.buildTransaction(mi, ixs);
614+
const txToSend = await this.buildTransaction(
615+
mi,
616+
ixs,
617+
!usingSwitchboardOnDemand
618+
);
609619
if (txToSend) {
610620
await this.sendSingleTx(mi, txToSend);
611621
} else {

0 commit comments

Comments
 (0)