raydium-io / raydium-sdk-V2-demo

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

clmm swap always says insufficient funds #37

Closed NotArchon closed 3 months ago

NotArchon commented 3 months ago

Anyone else have this issue?

MINT IN : So11111111111111111111111111111111111111112 AMOUNT IN : 100 MINT OUT : AujTJJ7aMS8LDo3bFzoyXDwT3jBALUbu4VZhzZdTZLmG AMOUNT OUT : 83106

Slightly modified code, but I can create an amm swap using 100 sol as input without issues:

    if (!isValidClmm(poolInfo.programId)) throw new Error('target pool is not CLMM pool')

    const clmmPoolInfo = await PoolUtils.fetchComputeClmmInfo({
      connection: raydium.connection,
      poolInfo,
    })

    const tickCache = await PoolUtils.fetchMultiplePoolTickArrays({
      connection: raydium.connection,
      poolKeys: [clmmPoolInfo],
    })

    const amountIn = new BN(process.env.AMOUNT_IN as string)

    const computedOut = PoolUtils.computeAmountOutFormat({
      poolInfo: clmmPoolInfo,
      tickArrayCache: tickCache[poolInfo.id],
      amountIn: amountIn,
      tokenOut: mintOut,
      slippage: process.env.SLIPPAGE_PERCENT
        ? Number(process.env.SLIPPAGE_PERCENT) / 100.0 // range: 1 ~ 0.0001, means 100% ~ 0.01%
        : 0,
      epochInfo: await raydium.fetchEpochInfo(),
    })
    const remainingAccounts = computedOut.remainingAccounts

    console.log("MINT IN : " + mintIn.address)
    console.log("AMOUNT IN : " + amountIn)
    console.log("MINT OUT : " + mintOut.address)
    console.log("AMOUNT OUT : " + computedOut.minAmountOut.amount.raw)

    const txData = await raydium.clmm.swap({
      poolInfo,
      inputMint: mintIn.address,
      amountIn: amountIn,
      amountOutMin: computedOut.minAmountOut.amount.raw,
      observationId: clmmPoolInfo.observationId,
      ownerInfo: {},
      //associatedOnly: false,
      remainingAccounts,
      txVersion,
    })
cruzshia commented 3 months ago

updated. pull latest code and run yarn to install latest sdk

NotArchon commented 3 months ago
image

This change?

Edit: I see the latest commit.