@@ -13,8 +13,9 @@ import {
1313 AddressLookupTableAccount ,
1414 ComputeBudgetProgram ,
1515 PublicKey ,
16+ TransactionInstruction ,
1617} from '@solana/web3.js' ;
17- import { getVersionedTransaction , sleepMs } from '../utils' ;
18+ import { chunks , getVersionedTransaction , shuffle , sleepMs } from '../utils' ;
1819import { Agent , setGlobalDispatcher } from 'undici' ;
1920
2021setGlobalDispatcher (
@@ -24,7 +25,7 @@ setGlobalDispatcher(
2425) ;
2526
2627// ref: https://solscan.io/tx/Z5X334CFBmzbzxXHgfa49UVbMdLZf7nJdDCekjaZYinpykVqgTm47VZphazocMjYe1XJtEyeiL6QgrmvLeMesMA
27- const MIN_CU_LIMIT = 350_000 ;
28+ const MIN_CU_LIMIT = 700_000 ;
2829
2930export class SwitchboardCrankerBot implements Bot {
3031 public name : string ;
@@ -106,11 +107,12 @@ export class SwitchboardCrankerBot implements Bot {
106107 }
107108
108109 async runCrankLoop ( ) {
109- for ( const alias in this . crankConfigs . pullFeedConfigs ) {
110+ const pullFeedAliases = chunks (
111+ shuffle ( Object . keys ( this . crankConfigs . pullFeedConfigs ) ) ,
112+ 2
113+ ) ;
114+ for ( const aliasChunk of pullFeedAliases ) {
110115 try {
111- const pubkey = new PublicKey (
112- this . crankConfigs . pullFeedConfigs [ alias ] . pubkey
113- ) ;
114116 const ixs = [
115117 ComputeBudgetProgram . setComputeUnitLimit ( {
116118 units : MIN_CU_LIMIT ,
@@ -122,23 +124,17 @@ export class SwitchboardCrankerBot implements Bot {
122124 } else {
123125 const priorityFees =
124126 this . priorityFeeSubscriber ?. getHeliusPriorityFeeLevel ( ) || 0 ;
125- logger . info ( `Priority fee for ${ alias } : ${ priorityFees } ` ) ;
126127 ixs . push (
127128 ComputeBudgetProgram . setComputeUnitPrice ( {
128129 microLamports : Math . floor ( priorityFees ) ,
129130 } )
130131 ) ;
131132 }
132- const pullIx =
133- await this . driftClient . getPostSwitchboardOnDemandUpdateAtomicIx (
134- pubkey ,
135- this . slothashSubscriber . currentSlothash
136- ) ;
137- if ( ! pullIx ) {
138- logger . error ( `No pullIx for ${ alias } ` ) ;
139- continue ;
140- }
141- ixs . push ( pullIx ) ;
133+
134+ const pullIxs = (
135+ await Promise . all ( aliasChunk . map ( ( alias ) => this . getPullIx ( alias ) ) )
136+ ) . filter ( ( ix ) => ix !== undefined ) as TransactionInstruction [ ] ;
137+ ixs . push ( ...pullIxs ) ;
142138
143139 const tx = getVersionedTransaction (
144140 this . driftClient . wallet . publicKey ,
@@ -163,19 +159,35 @@ export class SwitchboardCrankerBot implements Bot {
163159 . sendTransaction ( tx )
164160 . then ( ( txSigAndSlot : TxSigAndSlot ) => {
165161 logger . info (
166- `Posted update sb atomic tx for ${ alias } : ${ txSigAndSlot . txSig } `
162+ `Posted update sb atomic tx for ${ aliasChunk } : ${ txSigAndSlot . txSig } `
167163 ) ;
168164 } )
169165 . catch ( ( e ) => {
170166 console . log ( e ) ;
171167 } ) ;
172168 }
173169 } catch ( e ) {
174- logger . error ( `Error processing alias ${ alias } : ${ e } ` ) ;
170+ logger . error ( `Error processing alias ${ aliasChunk } : ${ e } ` ) ;
175171 }
176172 }
177173 }
178174
175+ async getPullIx ( alias : string ) : Promise < TransactionInstruction | undefined > {
176+ const pubkey = new PublicKey (
177+ this . crankConfigs . pullFeedConfigs [ alias ] . pubkey
178+ ) ;
179+ const pullIx =
180+ await this . driftClient . getPostSwitchboardOnDemandUpdateAtomicIx (
181+ pubkey ,
182+ this . slothashSubscriber . currentSlothash
183+ ) ;
184+ if ( ! pullIx ) {
185+ logger . error ( `No pullIx for ${ alias } ` ) ;
186+ return ;
187+ }
188+ return pullIx ;
189+ }
190+
179191 async healthCheck ( ) : Promise < boolean > {
180192 return true ;
181193 }
0 commit comments