Skip to content

Commit 515066f

Browse files
committed
add: jito polling delay
some users have latency between sending a bundle and polling seeing the bundle. add an optional delay for users to way before beginning polling project impacted: - [jupiter jito](solana/jupiter-jito/index.ts) - [jito sw3js2](solana/web3.js-2.0/jito-bundles/lilJit.ts)
1 parent b9c66a5 commit 515066f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

solana/jupiter-jito/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const CONFIG = {
2626
WALLET_SECRET: process.env.WALLET_SECRET?.split(',').map(Number) || [],
2727
JITO_TIP_AMOUNT: 0.0005 * LAMPORTS_PER_SOL, // 500,000 lamports
2828
POLL_TIMEOUT_MS: 30000,
29-
POLL_INTERVAL_MS: 3000
29+
POLL_INTERVAL_MS: 3000,
30+
DEFAULT_WAIT_BEFORE_POLL_MS: 5000
3031
};
3132

3233
// Quote request configuration
@@ -54,6 +55,10 @@ class JitoSwapManager {
5455
this.connection = new Connection(CONFIG.JITO_ENDPOINT);
5556
}
5657

58+
private sleep(ms: number): Promise<void> {
59+
return new Promise(resolve => setTimeout(resolve, ms));
60+
}
61+
5762
async getSwapQuote(): Promise<QuoteResponse> {
5863
const quote = await this.jupiterApi.quoteGet(QUOTE_REQUEST);
5964
if (!quote) throw new Error('No quote found');
@@ -115,6 +120,8 @@ class JitoSwapManager {
115120
}
116121

117122
async pollBundleStatus(bundleId: string): Promise<boolean> {
123+
await this.sleep(CONFIG.DEFAULT_WAIT_BEFORE_POLL_MS);
124+
118125
const startTime = Date.now();
119126
let lastStatus = '';
120127

solana/web3.js-2.0/jito-bundles/lilJit.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ const SIMULATE_ONLY = true;
3030
const ENDPOINT = 'https://example.quiknode.pro/123456/'; // 👈 Replace with your own endpoint
3131
const POLL_INTERVAL_MS = 3000;
3232
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));
3336

3437
type JitoBundleSimulationResponse = {
3538
context: {
@@ -156,8 +159,11 @@ async function pollBundleStatus(
156159
rpc: Rpc<LilJitAddon>,
157160
bundleId: string,
158161
timeoutMs = 30000,
159-
pollIntervalMs = 3000
162+
pollIntervalMs = 3000,
163+
waitBeforePollMs = DEFAULT_WAIT_BEFORE_POLL_MS
160164
) {
165+
await sleep(waitBeforePollMs);
166+
161167
const startTime = Date.now();
162168
let lastStatus = '';
163169
while (Date.now() - startTime < timeoutMs) {
@@ -174,8 +180,7 @@ async function pollBundleStatus(
174180
}
175181

176182
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}`);
179184
}
180185

181186
await new Promise(resolve => setTimeout(resolve, pollIntervalMs));

0 commit comments

Comments
 (0)