solxtence / solana-swap

Package for performing token swaps ( Pump.fun, Moonshot, Raydium, Orca... ) - Jito integrated 🚀
https://docs.solxtence.com/swap
MIT License
38 stars 12 forks source link

Constantly getting 'transaction validity period exceeded' and other errors #10

Open xobosox opened 1 week ago

xobosox commented 1 week ago

Describe the bug I've tried implementing solana-swap into my code (I'm using vite server with electron front end). Initially, I was getting CORS errors from your https://swap.solxtence.com environment, so I've intercepted the requests so they go through a proxy handler, which works fine.

Now, I've tried through Quicknodes and Alchemy (I gave up on the public RPC, as it's immediately rate limited) and I'm getting the following errors about 95% of the time, with the occasional trades going through (my full logs for 1 tx is below - note that the failure often happens in under 1 sec, sorry I didn't add timestamps).

I've tried increasing the transaction validity period and number of retries, but it achieves nothing.

Describe the bug I've tried implementing solana-swap into my code (I'm using vite server with electron front end). Initially, I was getting CORS errors from your https://swap.solxtence.com environment, so I've intercepted the requests so they go through a proxy handler, which works fine.

Now, I've tried through Quicknodes and Alchemy (I gave up on the public RPC, as it's immediately rate limited) and I'm getting the following errors about 95% of the time, with the occasional trades going through (my full logs for 1 tx is below - note that the failure often happens in under 1 sec, sorry I didn't add timestamps).

I've tried increasing the transaction validity period and number of retries, but it achieves nothing. The relevant code is at the bottom of this issue.

[1] App is ready (development mode), creating window... [1] 🚀 Main Process - Creating Swap Instance [1] 📤 Main Process - Sending Parameters: { [1] fromToken: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', [1] toToken: 'So11111111111111111111111111111111111111112', [1] amount: '0.001855', [1] slippage: '10', [1] payer: '2Gzowy5XXXXXXXXXXXXXXXXXXXXXXXXXXF4yc5eiS', [1] priorityFee: '0.000005' [1] } [1] Main Process - Swap Instructions Response: { [1] transaction: { [1] serializedTx: 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAJFhL0w7BDYIMQHRLbbW5GZeoxJ4WcA0P0mPQP1ATnAKcnARX7nnlZQ80spdGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXAMAEgMDAAABCQP6wt3yuHWL6y30z++iI0E5aJoGTrSYBxeHrIel0nK/ygUlJiQoIAQIJwMKjwkZrZfCaH4+0XJNd/NAimkyUMOB1O2AA0PO4uVSc+4EBgACAQEI5YlWlsHAFlbW6zDz4QPic9SwZTv85I0/Jvapyl6UQdYEpKGjogFI', [1] txType: 'v0', [1] executionTime: 0.21717580300010741 [1] }, [1] swapDetails: { [1] inputAmount: 0.001855, [1] outputAmount: 0.000009433, [1] minimumOutputAmount: 0.00000849, [1] priceData: { spotPrice: null, effectivePrice: null, priceImpactPercentage: 0 }, [1] feeInfo: { swapFee: 4999, platformFeeAmount: 0, platformFeeFormatted: 0 } [1] }, [1] tokenInfo: { [1] sourceToken: { [1] address: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', [1] decimalPlaces: 6 [1] }, [1] destinationToken: { [1] address: 'So11111111111111111111111111111111111111112', [1] decimalPlaces: 9 [1] } [1] } [1] } [1] Main Process - Performing Swap { [1] sendConfig: { skipPreflight: true }, [1] maxConfirmationAttempts: 30, [1] confirmationTimeout: 500, [1] commitmentLevel: 'processed' [1] } [1] Swap execution failed: TxError: Transaction validity period exceeded [1] at handleTransaction (file:/solana-trading-bot-2/node_modules/@solxtence/solana-swap/dist/index.mjs:80:15) [1] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [1] at async SolanaSwap.performSwap (file:/solana-trading-bot-2/node_modules/@solxtence/solana-swap/dist/index.mjs:269:18) [1] at async file:/solana-trading-bot-2/dist-electron/main.js:183:22 [1] at async WebContents. (node:electron/js2c/browser_init:2:77963) { [1] txSignature: '4K7bRU2PGiANDPRnNdZYByp1AgHx3mZkpV8VDqkhecNTXJibiV9wzT4oUCJ4oMXET7QBrzFGe1zcvcvt5KiMoedY' [1] } [1] Error occurred in handler for 'executeSwap': TxError: Transaction validity period exceeded [1] at handleTransaction (file:/solana-trading-bot-2/node_modules/@solxtence/solana-swap/dist/index.mjs:80:15) [1] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [1] at async SolanaSwap.performSwap (file:/solana-trading-bot-2/node_modules/@solxtence/solana-swap/dist/index.mjs:269:18) [1] at async file:/solana-trading-bot-2/dist-electron/main.js:183:22 [1] at async WebContents. (node:electron/js2c/browser_init:2:77963) { [1] txSignature: '4K7bRU2PGiANDPRnNdZYByp1AgHx3mZkpV8VDqkhecNTXJibiV9wzT4oUCJ4oMXET7QBrzFGe1zcvcvt5KiMoedY' [1] } [1] 🚀 Main Process - Creating Swap Instance [1] 📤 Main Process - Sending Parameters: { [1] fromToken: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', [1] toToken: 'So11111111111111111111111111111111111111112', [1] amount: '0.001279', [1] slippage: '10', [1] payer: '2Gzowy5wXXXXXXXXXXXXXXXXXXXXXXXXXyc5eiS', [1] priorityFee: '0.000005' [1] } [1] Main Process - Swap Instructions Response: { [1] transaction: { [1] serializedTx: 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQAJExL0w7BDYIMQHRLbbW5GZeoxJ4WcA0P0mPQP1ATnAKcnARX7nlZQ80spdGTgR2Zt4U/sjdP/Sm9PJGGeHaT4yRcHEMdccZ2b8CDW74gwrZ3JIEhvUdrBVV3iYvbH0EdlgT2p2MNIbr+pnXCufG7twpVVvwnRvvJ5RR2s4LfpR3VcQNjoiZzUUIFMPJNTH3afrItrF7rCGlj2fp5onO3JwnhB07OoUaAklpzAghgXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX4OISMVIiAiHB4FCCMoHyIQDg4lIhsdDC7BIJszQdacgQIDAAAALwAAZAABLmQBAiZkAgP/BAAAAAAAAIkZAAAAAAAA6AMADgMCAAABCQP6Z328ouKWIM+ib18PCVu8vt43I0X8FaeNatFdN8oZzAQFAAQJBwETCAIRAwePCRmtl8Jofj7Rck1380CKaTJQw4HU7YADQ87i5VJz7gQGAAIBAiYIHjk+jLBCg/Y9z+omNuhunPRKhIL0Gl6PcZ/IOPE6i8YGACceISYkAA==', [1] txType: 'v0', [1] executionTime: 3.9025248319999957 [1] }, [1] swapDetails: { [1] inputAmount: 0.001279, [1] outputAmount: 0.000006537, [1] minimumOutputAmount: 0.000005884, [1] priceData: { spotPrice: null, effectivePrice: null, priceImpactPercentage: 0 }, [1] feeInfo: { swapFee: 4999, platformFeeAmount: 0, platformFeeFormatted: 0 } [1] }, [1] tokenInfo: { [1] sourceToken: { [1] address: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', [1] decimalPlaces: 6 [1] }, [1] destinationToken: { [1] address: 'So11111111111111111111111111111111111111112', [1] decimalPlaces: 9 [1] } [1] } [1] } [1] Main Process - Performing Swap { [1] sendConfig: { skipPreflight: true }, [1] maxConfirmationAttempts: 20, [1] confirmationTimeout: 10000, [1] commitmentLevel: 'processed' [1] } [1] Swap execution failed: TxError: Transaction validity period exceeded [1] at handleTransaction (file:/solana-trading-bot-2/node_modules/@solxtence/solana-swap/dist/index.mjs:80:15) [1] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [1] at async SolanaSwap.performSwap (file:/solana-trading-bot-2/node_modules/@solxtence/solana-swap/dist/index.mjs:269:18) [1] at async file:/solana-trading-bot-2/dist-electron/main.js:183:22 [1] at async WebContents. (node:electron/js2c/browser_init:2:77963) { [1] txSignature: '4rF51B9ycVEKFqxDyN6oJKnMTfFuySQmcnuHqbQ9CFo82z1nzNagTGxaxxXgX54iG657KaeyYcCW2rX8DcARYf9e' [1] } [1] Error occurred in handler for 'executeSwap': TxError: Transaction validity period exceeded [1] at handleTransaction (file:/solana-trading-bot-2/node_modules/@solxtence/solana-swap/dist/index.mjs:80:15) [1] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [1] at async SolanaSwap.performSwap (file:/solana-trading-bot-2/node_modules/@solxtence/solana-swap/dist/index.mjs:269:18) [1] at async file:/solana-trading-bot-2/dist-electron/main.js:183:22 [1] at async WebContents. (node:electron/js2c/browser_init:2:77963) { [1] txSignature: '4rF51B9ycVEKFqxDyN6oJKnMTfFuySQmcnuHqbQ9CFo82z1nzNagTGxaxxXgX54iG657KaeyYcCW2rX8DcARYf9e'

CODE: `ipcMain.handle('executeSwap', async (_, params) => { try { // First get swap instructions const { fromToken, toToken, amount, slippage, payerPrivateKey, priorityFee } = params; const keypair = Keypair.fromSecretKey(bs58.decode(payerPrivateKey));

console.log('🚀 Main Process - Creating Swap Instance');
solanaSwapInstance = createPatchedSolanaSwap(keypair, 'https://solana-mainnet.g.alchemy.com/v2/XXXXXXXXXXXXXXXXXXXXXXXXX');

console.log('📤 Main Process - Sending Parameters:', {
  fromToken,
  toToken,
  amount: amount.toString(),
  slippage: slippage.toString(),
  payer: keypair.publicKey.toBase58(),
  priorityFee: priorityFee.toString()
});

const swapInstructions = await solanaSwapInstance.getSwapInstructions(
  fromToken,
  toToken,
  amount,
  slippage,
  keypair.publicKey.toBase58(),
  priorityFee
);

console.log('Main Process - Swap Instructions Response:', swapInstructions);

// Type check the response if ('error' in swapInstructions) { throw new Error(Failed to get swap instructions: ${swapInstructions.error}); }

console.log('Main Process - Performing Swap', {
  sendConfig: { skipPreflight: true },
  maxConfirmationAttempts: 20,
  confirmationTimeout: 10000,
  commitmentLevel: "processed"
});
// Then perform the swap
const txid = await solanaSwapInstance.performSwap(swapInstructions, {
  sendConfig: { skipPreflight: true },
  maxConfirmationAttempts: 20,
  confirmationTimeout: 10000,
  commitmentLevel: "processed"
});

console.log("It's done!", txid);
console.log("✅ TX Hash:", txid);
console.log("🔍 TX on Solscan:", `https://solscan.io/tx/${txid}`);

return txid;

} catch (error) { console.error('Swap execution failed:', error); throw error; } });`

solxtence commented 1 week ago

Hey there,

Sorry for the delay! Based on the payload you've provided, the priority fee is very low ([1] priorityFee: '0.000005'), use a minimum of 0.002 priority fee for your transactions to go through otherwise they will fail.