@@ -10,6 +10,7 @@ import {
1010 PriorityFeeCalculator ,
1111 TxParams ,
1212 PublicKey ,
13+ BlockhashSubscriber ,
1314} from '@drift-labs/sdk' ;
1415import { Mutex , tryAcquire , E_ALREADY_LOCKED } from 'async-mutex' ;
1516
@@ -27,7 +28,8 @@ import {
2728 View ,
2829} from '@opentelemetry/sdk-metrics-base' ;
2930import { RuntimeSpec , metricAttrFromUserAccount } from '../metrics' ;
30- import { getNodeToTriggerSignature } from '../utils' ;
31+ import { getNodeToTriggerSignature , getVersionedTransaction } from '../utils' ;
32+ import { AddressLookupTableAccount } from '@solana/web3.js' ;
3133
3234const TRIGGER_ORDER_COOLDOWN_MS = 10000 ; // time to wait between triggering an order
3335
@@ -52,6 +54,8 @@ export class TriggerBot implements Bot {
5254 private driftClient : DriftClient ;
5355 private slotSubscriber : SlotSubscriber ;
5456 private dlobSubscriber ?: DLOBSubscriber ;
57+ private blockhashSubscriber : BlockhashSubscriber ;
58+ private lookupTableAccount ?: AddressLookupTableAccount ;
5559 private triggeringNodes = new Map < string , number > ( ) ;
5660 private periodicTaskMutex = new Mutex ( ) ;
5761 private intervalIds : Array < NodeJS . Timer > = [ ] ;
@@ -77,6 +81,7 @@ export class TriggerBot implements Bot {
7781 constructor (
7882 driftClient : DriftClient ,
7983 slotSubscriber : SlotSubscriber ,
84+ blockhashSubscriber : BlockhashSubscriber ,
8085 userMap : UserMap ,
8186 runtimeSpec : RuntimeSpec ,
8287 config : BaseBotConfig
@@ -87,6 +92,7 @@ export class TriggerBot implements Bot {
8792 this . userMap = userMap ;
8893 this . runtimeSpec = runtimeSpec ;
8994 this . slotSubscriber = slotSubscriber ;
95+ this . blockhashSubscriber = blockhashSubscriber ;
9096
9197 this . metricsPort = config . metricsPort ;
9298 if ( this . metricsPort ) {
@@ -168,6 +174,9 @@ export class TriggerBot implements Bot {
168174 driftClient : this . driftClient ,
169175 } ) ;
170176 await this . dlobSubscriber . subscribe ( ) ;
177+
178+ this . lookupTableAccount =
179+ await this . driftClient . fetchMarketLookupTableAccount ( ) ;
171180 }
172181
173182 public async reset ( ) {
@@ -198,6 +207,20 @@ export class TriggerBot implements Bot {
198207 return healthy ;
199208 }
200209
210+ private async getBlockhashForTx ( ) : Promise < string > {
211+ const cachedBlockhash = this . blockhashSubscriber . getLatestBlockhash ( 10 ) ;
212+ if ( cachedBlockhash ) {
213+ return cachedBlockhash . blockhash as string ;
214+ }
215+
216+ const recentBlockhash =
217+ await this . driftClient . connection . getLatestBlockhash ( {
218+ commitment : 'confirmed' ,
219+ } ) ;
220+
221+ return recentBlockhash . blockhash ;
222+ }
223+
201224 private async tryTriggerForPerpMarket ( market : PerpMarketAccount ) {
202225 const marketIndex = market . marketIndex ;
203226
@@ -258,11 +281,11 @@ export class TriggerBot implements Bot {
258281
259282 ixs . push ( await this . driftClient . getRevertFillIx ( ) ) ;
260283
261- const tx = await this . driftClient . txSender . getVersionedTransaction (
284+ const tx = getVersionedTransaction (
285+ this . driftClient . wallet . publicKey ,
262286 ixs ,
263- [ ] ,
264- undefined ,
265- this . driftClient . opts
287+ [ this . lookupTableAccount ! ] ,
288+ await this . getBlockhashForTx ( )
266289 ) ;
267290
268291 this . driftClient
0 commit comments