55 BlockhashSubscriber ,
66 DriftClient ,
77 PriorityFeeSubscriber ,
8+ SlothashSubscriber ,
89 TxSigAndSlot ,
910} from '@drift-labs/sdk' ;
10- import { SwitchboardOnDemandClient } from '@drift-labs/sdk' ;
1111import { BundleSender } from '../bundleSender' ;
1212import {
1313 AddressLookupTableAccount ,
@@ -28,11 +28,10 @@ const SIM_CU_ESTIMATE_MULTIPLIER = 1.5;
2828export class SwitchboardCrankerBot implements Bot {
2929 public name : string ;
3030 public dryRun : boolean ;
31- private intervalMs : number ;
32- private oracleClient : SwitchboardOnDemandClient ;
33- public defaultIntervalMs = 30_000 ;
31+ public defaultIntervalMs : number ;
3432
3533 private blockhashSubscriber : BlockhashSubscriber ;
34+ private slothashSubscriber : SlothashSubscriber ;
3635
3736 constructor (
3837 private globalConfig : GlobalConfig ,
@@ -44,13 +43,16 @@ export class SwitchboardCrankerBot implements Bot {
4443 ) {
4544 this . name = crankConfigs . botId ;
4645 this . dryRun = crankConfigs . dryRun ;
47- this . intervalMs = crankConfigs . intervalMs ;
46+ this . defaultIntervalMs = crankConfigs . intervalMs || 10_000 ;
4847 this . blockhashSubscriber = new BlockhashSubscriber ( {
4948 connection : driftClient . connection ,
5049 } ) ;
5150
52- this . oracleClient = new SwitchboardOnDemandClient (
53- this . driftClient . connection
51+ this . slothashSubscriber = new SlothashSubscriber (
52+ this . driftClient . connection ,
53+ {
54+ commitment : 'processed' ,
55+ }
5456 ) ;
5557 }
5658
@@ -60,6 +62,7 @@ export class SwitchboardCrankerBot implements Bot {
6062 this . lookupTableAccounts . push (
6163 await this . driftClient . fetchMarketLookupTableAccount ( )
6264 ) ;
65+ await this . slothashSubscriber . subscribe ( ) ;
6366 }
6467
6568 async reset ( ) : Promise < void > {
@@ -68,7 +71,7 @@ export class SwitchboardCrankerBot implements Bot {
6871 await this . driftClient . unsubscribe ( ) ;
6972 }
7073
71- async startIntervalLoop ( intervalMs = this . intervalMs ) : Promise < void > {
74+ async startIntervalLoop ( intervalMs = this . defaultIntervalMs ) : Promise < void > {
7275 logger . info ( `Starting ${ this . name } bot with interval ${ intervalMs } ms` ) ;
7376 await sleepMs ( 5000 ) ;
7477 await this . runCrankLoop ( ) ;
@@ -117,7 +120,8 @@ export class SwitchboardCrankerBot implements Bot {
117120 }
118121 const pullIx =
119122 await this . driftClient . getPostSwitchboardOnDemandUpdateAtomicIx (
120- pubkey
123+ pubkey ,
124+ this . slothashSubscriber . currentSlothash
121125 ) ;
122126 if ( ! pullIx ) {
123127 logger . error ( `No pullIx for ${ alias } ` ) ;
0 commit comments