diff --git a/solana/jupiter-jito/index.ts b/solana/jupiter-jito/index.ts index 901df2d..5f344a8 100644 --- a/solana/jupiter-jito/index.ts +++ b/solana/jupiter-jito/index.ts @@ -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 @@ -54,6 +55,10 @@ class JitoSwapManager { this.connection = new Connection(CONFIG.JITO_ENDPOINT); } + private sleep(ms: number): Promise { + return new Promise(resolve => setTimeout(resolve, ms)); + } + async getSwapQuote(): Promise { const quote = await this.jupiterApi.quoteGet(QUOTE_REQUEST); if (!quote) throw new Error('No quote found'); @@ -115,6 +120,8 @@ class JitoSwapManager { } async pollBundleStatus(bundleId: string): Promise { + await this.sleep(CONFIG.DEFAULT_WAIT_BEFORE_POLL_MS); + const startTime = Date.now(); let lastStatus = ''; diff --git a/solana/web3.js-2.0/jito-bundles/lilJit.ts b/solana/web3.js-2.0/jito-bundles/lilJit.ts index 9b95f9f..29fb34f 100644 --- a/solana/web3.js-2.0/jito-bundles/lilJit.ts +++ b/solana/web3.js-2.0/jito-bundles/lilJit.ts @@ -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: { @@ -156,8 +159,11 @@ async function pollBundleStatus( rpc: Rpc, 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) { @@ -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));