File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ const CONFIG = {
26
26
WALLET_SECRET : process . env . WALLET_SECRET ?. split ( ',' ) . map ( Number ) || [ ] ,
27
27
JITO_TIP_AMOUNT : 0.0005 * LAMPORTS_PER_SOL , // 500,000 lamports
28
28
POLL_TIMEOUT_MS : 30000 ,
29
- POLL_INTERVAL_MS : 3000
29
+ POLL_INTERVAL_MS : 3000 ,
30
+ DEFAULT_WAIT_BEFORE_POLL_MS : 5000
30
31
} ;
31
32
32
33
// Quote request configuration
@@ -54,6 +55,10 @@ class JitoSwapManager {
54
55
this . connection = new Connection ( CONFIG . JITO_ENDPOINT ) ;
55
56
}
56
57
58
+ private sleep ( ms : number ) : Promise < void > {
59
+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
60
+ }
61
+
57
62
async getSwapQuote ( ) : Promise < QuoteResponse > {
58
63
const quote = await this . jupiterApi . quoteGet ( QUOTE_REQUEST ) ;
59
64
if ( ! quote ) throw new Error ( 'No quote found' ) ;
@@ -115,6 +120,8 @@ class JitoSwapManager {
115
120
}
116
121
117
122
async pollBundleStatus ( bundleId : string ) : Promise < boolean > {
123
+ await this . sleep ( CONFIG . DEFAULT_WAIT_BEFORE_POLL_MS ) ;
124
+
118
125
const startTime = Date . now ( ) ;
119
126
let lastStatus = '' ;
120
127
Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ const SIMULATE_ONLY = true;
30
30
const ENDPOINT = 'https://example.quiknode.pro/123456/' ; // 👈 Replace with your own endpoint
31
31
const POLL_INTERVAL_MS = 3000 ;
32
32
const POLL_TIMEOUT_MS = 30000 ;
33
+ const DEFAULT_WAIT_BEFORE_POLL_MS = 5000 ;
34
+
35
+ const sleep = ( ms : number ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
33
36
34
37
type JitoBundleSimulationResponse = {
35
38
context : {
@@ -156,8 +159,11 @@ async function pollBundleStatus(
156
159
rpc : Rpc < LilJitAddon > ,
157
160
bundleId : string ,
158
161
timeoutMs = 30000 ,
159
- pollIntervalMs = 3000
162
+ pollIntervalMs = 3000 ,
163
+ waitBeforePollMs = DEFAULT_WAIT_BEFORE_POLL_MS
160
164
) {
165
+ await sleep ( waitBeforePollMs ) ;
166
+
161
167
const startTime = Date . now ( ) ;
162
168
let lastStatus = '' ;
163
169
while ( Date . now ( ) - startTime < timeoutMs ) {
@@ -174,8 +180,7 @@ async function pollBundleStatus(
174
180
}
175
181
176
182
if ( status === 'Failed' ) {
177
- console . log ( `Bundle ${ status . toLowerCase ( ) } . Exiting...` ) ;
178
- throw new Error ( `Bundle failed with status: ${ status } ` ) ;
183
+ throw new Error ( `Bundle ${ status . toLowerCase ( ) } failed with status: ${ status } ` ) ;
179
184
}
180
185
181
186
await new Promise ( resolve => setTimeout ( resolve , pollIntervalMs ) ) ;
You can’t perform that action at this time.
0 commit comments