Skip to content

Commit ed13665

Browse files
committed
Merge branch 'master' into mainnet-beta
2 parents 76e35c6 + 7595752 commit ed13665

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

src/bots/common/jetTxSender.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
ConfirmOptions,
3-
Connection,
4-
SendTransactionError,
5-
} from '@solana/web3.js';
1+
import { ConfirmOptions, Connection } from '@solana/web3.js';
62
import { logger } from '../../logger';
73
import { WhileValidTxSender } from '@drift-labs/sdk';
84

src/bots/common/timedLookup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function timedCacheableLookup(
2121
// Use cacheable lookup instead of direct dns.lookup
2222
//@ts-ignore
2323
cacheable.lookup(hostname, options, (err, address, family) => {
24-
console.log(`Cached Lookup: ${hostname}: ${hrtimeMs() - start}ms`);
24+
console.debug(`Cached Lookup: ${hostname}: ${hrtimeMs() - start}ms`);
2525
callback(err, address, family);
2626
});
2727
}

src/bots/makerBidAskTwapCrank.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
isOneOfVariant,
1414
getVariant,
1515
PerpMarkets,
16+
BlockhashSubscriber,
1617
} from '@drift-labs/sdk';
1718
import { Mutex } from 'async-mutex';
1819

@@ -51,6 +52,8 @@ const MAX_PRIORITY_FEE = process.env.MAX_PRIORITY_FEE
5152
? parseInt(process.env.MAX_PRIORITY_FEE) || 500_000
5253
: 500_000;
5354

55+
const CACHED_BLOCKHASH_OFFSET = 5;
56+
5457
const SLOT_STALENESS_THRESHOLD_RESTART = process.env
5558
.SLOT_STALENESS_THRESHOLD_RESTART
5659
? parseInt(process.env.SLOT_STALENESS_THRESHOLD_RESTART) || 300
@@ -209,6 +212,7 @@ export class MakerBidAskTwapCrank implements Bot {
209212
private pythPullOracleClient: PythPullClient;
210213
private pythHealthy: boolean = true;
211214
private lookupTableAccounts: AddressLookupTableAccount[];
215+
private blockhashSubscriber: BlockhashSubscriber;
212216

213217
private bundleSender?: BundleSender;
214218
private crankIntervalToMarketIndicies?: { [key: number]: number[] };
@@ -220,6 +224,7 @@ export class MakerBidAskTwapCrank implements Bot {
220224
config: MakerBidAskTwapCrankConfig,
221225
globalConfig: GlobalConfig,
222226
runOnce: boolean,
227+
blockhashSubscriber: BlockhashSubscriber,
223228
pythPriceSubscriber?: PythPriceFeedSubscriber,
224229
lookupTableAccounts: AddressLookupTableAccount[] = [],
225230
bundleSender?: BundleSender
@@ -236,6 +241,7 @@ export class MakerBidAskTwapCrank implements Bot {
236241
this.pythPullOracleClient = new PythPullClient(this.driftClient.connection);
237242
this.bundleSender = bundleSender;
238243
this.crankIntervalToMarketIndicies = config.crankIntervalToMarketIndicies;
244+
this.blockhashSubscriber = blockhashSubscriber;
239245

240246
// Pyth lazer: remember to remove devnet guard
241247
if (!this.globalConfig.lazerEndpoints || !this.globalConfig.lazerToken) {
@@ -428,8 +434,7 @@ export class MakerBidAskTwapCrank implements Bot {
428434
ixs: TransactionInstruction[],
429435
doSimulation = true
430436
): Promise<VersionedTransaction | undefined> {
431-
const recentBlockhash =
432-
await this.driftClient.connection.getLatestBlockhash('confirmed');
437+
const recentBlockhash = await this.getBlockhashForTx();
433438

434439
let simResult: SimulateAndGetTxWithCUsResponse | undefined;
435440
try {
@@ -441,7 +446,7 @@ export class MakerBidAskTwapCrank implements Bot {
441446
cuLimitMultiplier: CU_EST_MULTIPLIER,
442447
minCuLimit: TWAP_CRANK_MIN_CU,
443448
doSimulation,
444-
recentBlockhash: recentBlockhash.blockhash,
449+
recentBlockhash,
445450
});
446451
} catch (error) {
447452
logger.error(`[${this.name}] simulating tx: ${error}`);
@@ -469,6 +474,21 @@ export class MakerBidAskTwapCrank implements Bot {
469474
}
470475
}
471476

477+
private async getBlockhashForTx(): Promise<string> {
478+
const cachedBlockhash = this.blockhashSubscriber.getLatestBlockhash(
479+
CACHED_BLOCKHASH_OFFSET
480+
);
481+
if (cachedBlockhash) {
482+
return cachedBlockhash.blockhash as string;
483+
}
484+
485+
const recentBlockhash =
486+
await this.driftClient.connection.getLatestBlockhash({
487+
commitment: 'confirmed',
488+
});
489+
return recentBlockhash.blockhash;
490+
}
491+
472492
private async getPythIxsFromTwapCrankInfo(
473493
crankMarketIndex: number,
474494
precedingIxs: TransactionInstruction[] = []

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ const runBot = async () => {
902902

903903
if (configHasBot(config, 'markTwapCrank')) {
904904
needPythPriceSubscriber = true;
905+
needBlockhashSubscriber = true;
905906
needCheckDriftUser = true;
906907
needUserMapSubscribe = true;
907908
needDriftStateWatcher = true;
@@ -914,6 +915,7 @@ const runBot = async () => {
914915
config.botConfigs!.markTwapCrank!,
915916
config.global,
916917
config.global.runOnce ?? false,
918+
blockhashSubscriber,
917919
pythPriceSubscriber,
918920
[],
919921
bundleSender

0 commit comments

Comments
 (0)