Skip to content

Commit

Permalink
makerBidAskTwapCrank: skip simulation if updating switchboard oracle (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan authored Dec 23, 2024
1 parent 02ddddb commit c75e783
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/bots/makerBidAskTwapCrank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ export class MakerBidAskTwapCrank implements Bot {

private async buildTransaction(
marketIndex: number,
ixs: TransactionInstruction[]
ixs: TransactionInstruction[],
doSimulation = true
): Promise<VersionedTransaction | undefined> {
const recentBlockhash =
await this.driftClient.connection.getLatestBlockhash('confirmed');
Expand All @@ -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(
Expand Down Expand Up @@ -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
}),
];

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit c75e783

Please sign in to comment.