raydium-io / raydium-sdk-V2-demo

Open-source Typescript SDK demos
48 stars 31 forks source link

RPC_ERROR: Transaction Simulation Failure in swap Function #32

Closed bl4ckh401 closed 4 months ago

bl4ckh401 commented 4 months ago

I'm encountering an issue while trying to execute a swap using the Raydium SDK. The transaction simulation fails with the following error:

Fetching multiple info... Error in swapOnlyAmmV2: Error: failed to simulate for instructions, RPC_ERROR, {"message":"rpc simulateTransaction error"} at di.logWithError (C:\Users\Admin\Desktop\SMEV\node_modules\@raydium-io\raydium-sdk-v2\src\common\logger.ts:45:11) at cs (C:\Users\Admin\Desktop\SMEV\node_modules\@raydium-io\raydium-sdk-v2\src\common\txTool\txUtils.ts:116:14) at processTicksAndRejections (node:internal/process/task_queues:95:5) at ef (C:\Users\Admin\Desktop\SMEV\node_modules\@raydium-io\raydium-sdk-v2\src\raydium\liquidity\utils.ts:157:16) at swapOnlyAmmV2 (C:\Users\Admin\Desktop\SMEV\src\controller\tradeToken.ts:60:15) at fetchRaydiumMints (C:\Users\Admin\Desktop\SMEV\src\controller\lpTracker.ts:139:26) at C:\Users\Admin\Desktop\SMEV\src\main.ts:32:40

My code and specifically where I experience the error:

`try { console.log("Initializing Raydium SDK..."); const amountIn = 100; const raydium = await initSdk(); if (!raydium) throw new Error("Failed to initialize Raydium SDK");

const poolId = input.targetPool;
console.log("Target Pool ID:", poolId);

if (!poolId || typeof poolId !== 'string' || poolId.length !== 44) {
  throw new Error("Invalid pool ID");
}

console.log("Fetching pool keys...");
const poolKeys = await raydium.liquidity.getAmmPoolKeys(poolId);
if (!poolKeys) throw new Error("Pool keys are null or undefined");
console.log("Pool Keys:", poolKeys);

console.log("Fetching multiple info...");
let res = await fetchMultipleInfo({
  connection: raydium.connection,
  poolKeysList: [poolKeys],
  config: undefined,
});
console.log("Fetched Multiple Info:", res);`

Steps to Reproduce

Behaviour The transaction simulation fails with the error: "RPC_ERROR, {"message":"rpc simulateTransaction error"}".

Additional Information The pool ID fetches successfully but when I try to fetch the poolInfo and Data parameters they are null.

` console.log("Fetching pool by ID..."); const data = await raydium.api.fetchPoolById({ ids: poolId }); console.log("Fetched Pool Data:", data);

 if (!data || data.length === 0) {
   throw new Error(`No pool data found for pool ID: ${poolId}`);
 }

const poolInfo = data[0] as ApiV3PoolInfoStandardItem; if (!poolInfo) throw new Error("Pool information is null or undefined"); console.log("Fetched Pool Info:", poolInfo);`

Doing this, I get both Data and poolInfo are null but poolKeys always returns the correvt things

The issue seems to occur during the transaction simulation step. Could you please help me understand what might be causing this issue and how to resolve it?

Thank you for your assistance!

cruzshia commented 4 months ago

duplicated issue https://github.com/raydium-io/raydium-sdk-V2-demo/issues/33, let's discuss in there.