Skip to content

Commit

Permalink
add: jito polling delay
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
amilz committed Jan 10, 2025
1 parent b9c66a5 commit 515066f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 8 additions & 1 deletion solana/jupiter-jito/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const CONFIG = {
WALLET_SECRET: process.env.WALLET_SECRET?.split(',').map(Number) || [],
JITO_TIP_AMOUNT: 0.0005 * LAMPORTS_PER_SOL, // 500,000 lamports
POLL_TIMEOUT_MS: 30000,
POLL_INTERVAL_MS: 3000
POLL_INTERVAL_MS: 3000,
DEFAULT_WAIT_BEFORE_POLL_MS: 5000
};

// Quote request configuration
Expand Down Expand Up @@ -54,6 +55,10 @@ class JitoSwapManager {
this.connection = new Connection(CONFIG.JITO_ENDPOINT);
}

private sleep(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}

async getSwapQuote(): Promise<QuoteResponse> {
const quote = await this.jupiterApi.quoteGet(QUOTE_REQUEST);
if (!quote) throw new Error('No quote found');
Expand Down Expand Up @@ -115,6 +120,8 @@ class JitoSwapManager {
}

async pollBundleStatus(bundleId: string): Promise<boolean> {
await this.sleep(CONFIG.DEFAULT_WAIT_BEFORE_POLL_MS);

const startTime = Date.now();
let lastStatus = '';

Expand Down
11 changes: 8 additions & 3 deletions solana/web3.js-2.0/jito-bundles/lilJit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const SIMULATE_ONLY = true;
const ENDPOINT = 'https://example.quiknode.pro/123456/'; // 👈 Replace with your own endpoint
const POLL_INTERVAL_MS = 3000;
const POLL_TIMEOUT_MS = 30000;
const DEFAULT_WAIT_BEFORE_POLL_MS = 5000;

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

type JitoBundleSimulationResponse = {
context: {
Expand Down Expand Up @@ -156,8 +159,11 @@ async function pollBundleStatus(
rpc: Rpc<LilJitAddon>,
bundleId: string,
timeoutMs = 30000,
pollIntervalMs = 3000
pollIntervalMs = 3000,
waitBeforePollMs = DEFAULT_WAIT_BEFORE_POLL_MS
) {
await sleep(waitBeforePollMs);

const startTime = Date.now();
let lastStatus = '';
while (Date.now() - startTime < timeoutMs) {
Expand All @@ -174,8 +180,7 @@ async function pollBundleStatus(
}

if (status === 'Failed') {
console.log(`Bundle ${status.toLowerCase()}. Exiting...`);
throw new Error(`Bundle failed with status: ${status}`);
throw new Error(`Bundle ${status.toLowerCase()} failed with status: ${status}`);
}

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

0 comments on commit 515066f

Please sign in to comment.