diff --git a/src/bots/makerBidAskTwapCrank.ts b/src/bots/makerBidAskTwapCrank.ts index 82a153f1..d97d957e 100644 --- a/src/bots/makerBidAskTwapCrank.ts +++ b/src/bots/makerBidAskTwapCrank.ts @@ -365,7 +365,8 @@ export class MakerBidAskTwapCrank implements Bot { private async buildTransaction( marketIndex: number, - ixs: TransactionInstruction[] + ixs: TransactionInstruction[], + doSimulation = true ): Promise { const recentBlockhash = await this.driftClient.connection.getLatestBlockhash('confirmed'); @@ -377,7 +378,7 @@ export class MakerBidAskTwapCrank implements Bot { lookupTableAccounts: this.lookupTableAccounts, cuLimitMultiplier: CU_EST_MULTIPLIER, minCuLimit: TWAP_CRANK_MIN_CU, - doSimulation: true, + doSimulation, recentBlockhash: recentBlockhash.blockhash, }); logger.info( @@ -476,9 +477,15 @@ export class MakerBidAskTwapCrank implements Bot { let txsToBundle: VersionedTransaction[] = []; for (const mi of crankMarkets) { + const usingSwitchboardOnDemand = isVariant( + this.driftClient.getPerpMarketAccount(mi)!.amm.oracleSource, + 'switchboardOnDemand' + ); const ixs = [ ComputeBudgetProgram.setComputeUnitLimit({ - units: 1_400_000, // will be overwritten by simulateAndGetTxWithCUs + units: usingSwitchboardOnDemand + ? 350_000 // switchboard simulation is unreliable, use hardcoded CU limit + : 1_400_000, // will be overwritten by simulateAndGetTxWithCUs }), ]; @@ -547,12 +554,7 @@ export class MakerBidAskTwapCrank implements Bot { const pythIxs = await this.getPythIxsFromTwapCrankInfo(mi); ixs.push(...pythIxs); pythIxsPushed = true; - } else if ( - isVariant( - this.driftClient.getPerpMarketAccount(mi)!.amm.oracleSource, - 'switchboardOnDemand' - ) - ) { + } else if (usingSwitchboardOnDemand) { const switchboardIx = await this.driftClient.getPostSwitchboardOnDemandUpdateAtomicIx( this.driftClient.getPerpMarketAccount(mi)!.amm.oracle, @@ -596,7 +598,11 @@ export class MakerBidAskTwapCrank implements Bot { if (isFirstTxInBundle) { ixs.push(this.bundleSender!.getTipIx()); } - const txToSend = await this.buildTransaction(mi, ixs); + const txToSend = await this.buildTransaction( + mi, + ixs, + !usingSwitchboardOnDemand + ); if (txToSend) { // @ts-ignore; txToSend.sign(jitoSigners); @@ -605,7 +611,11 @@ export class MakerBidAskTwapCrank implements Bot { logger.error(`[${this.name}] failed to build tx for market: ${mi}`); } } else { - const txToSend = await this.buildTransaction(mi, ixs); + const txToSend = await this.buildTransaction( + mi, + ixs, + !usingSwitchboardOnDemand + ); if (txToSend) { await this.sendSingleTx(mi, txToSend); } else {