raydium-io / raydium-sdk-V2

Open-source Typescript SDK for Raydium
GNU General Public License v3.0
79 stars 47 forks source link

Always getting insufficient balance no matter what I use as amountIn #12

Closed mcfriend99 closed 5 months ago

mcfriend99 commented 5 months ago

The issue is as it presents itself. I'm using the code as it is in the demo application with

const out = raydium.liquidity.computeAmountOut({
    poolInfo: {
      ...poolInfo,
      baseReserve: pool.baseReserve,
      quoteReserve: pool.quoteReserve,
      status: pool.status.toNumber(),
      version: 4,
    },
    amountIn: new BN(100000),
    mintIn: inputToken, // swap mintB -> mintA, use: poolInfo.mintB.address
    mintOut: outputToken, // swap mintB -> mintA, use: poolInfo.mintA.address
    slippage, // range: 1 ~ 0.0001, means 100% ~ 0.01%
  })

  const { transaction } = await raydium.liquidity.swap({
    poolInfo,
    amountIn: new BN(100000),
    amountOut: out.minAmountOut, // out.amountOut means amount 'without' slippage
    fixedSide: 'in',
    inputMint: inputToken, // swap mintB -> mintA, use: poolInfo.mintB.address
    associatedOnly: false,
    txVersion,
    // optional: set up priority fee here
    // computeBudgetConfig: {
    //   units: 600000,
    //   microLamports: 100000000,
    // },
  })

No matter what I set the amount in as I always get insufficient balance whether with transaction simulation enabled or not. Even when I set the amount to 0.0001 SOL (100000 lamports) and I have as much as 5 SOLs in my wallet balance, I still get insufficient funds error.

cruzshia commented 5 months ago

Make sure you pass correct input and outMint for compute and swap function, no issues was found.

mcfriend99 commented 5 months ago

I've debugged this severally, I've even hardcoded it based on the values returned from raydium.api.fetchPoolById and It's the same. I've set the values of input and output mint directly from what was returned by fetchPoolById.

Same behavior.

While I'm reporting this issue, more than 6 other members of my team are having the same issue with their own implementation too.

cruzshia commented 5 months ago

Please paste your full code here and what's the sdk version are you used?

mcfriend99 commented 5 months ago

You were right. The input and output mint were swapped by another library we all shared.