raydium-io / raydium-sdk-V2-demo

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

Getting toBuffer error while createPoolV4 on Devnet. #45

Closed Sky1706 closed 3 months ago

Sky1706 commented 3 months ago

I am creating a Pool for sol/token and I am getting toBuffer while calling createPoolV4 I am using the createAmmPool.ts file code.

Market address: 9MH5JY7DFtm2mNKwjYkhbhJjGwHD9XSnebgiXC4vD9GY, base mint address: So11111111111111111111111111111111111111112 quote mint address: DxqA62o55zqMi4AvhWadhU9ppFBJxHPr9LsfpN4ZhwGi base amount: 1000000000 quote amount: 10000000000

Below is console of params of createPoolV4

{ programId: PublicKey [PublicKey(HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8)] { _bn: }, marketInfo: { market: PublicKey [PublicKey(9MH5JY7DFtm2mNKwjYkhbhJjGwHD9XSnebgiXC4vD9GY)] { _bn: <BN: 7c0f4966bbde86d8522edbacb3e9ff18f29d6d4db30f194ca21425e145da1a75> }, programId: PublicKey [PublicKey(EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj)] { _bn: } }, baseMintInfo: { mint: PublicKey [PublicKey(So11111111111111111111111111111111111111112)] { _bn: <BN: 69b8857feab8184fb687f634618c035dac439dc1aeb3b5598a0f00000000001> }, decimals: 9 }, quoteMintInfo: { mint: PublicKey [PublicKey(DxqA62o55zqMi4AvhWadhU9ppFBJxHPr9LsfpN4ZhwGi)] { _bn: }, decimals: 9 }, baseAmount: <BN: 3b9aca00>, quoteAmount: <BN: 174876e800>, startTime: <BN: 0>, ownerInfo: { useSOLBalance: true }, associatedOnly: false, feeDestinationId: PublicKey [PublicKey(3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR)] { _bn: <BN: 257e618f5c1001cad99db2910370745d3f740a1bdce5e2128a7ca7803d577af0> } }

cruzshia commented 3 months ago

please ensure your config.ts has set all info to devnet, I tried with provided market Id and wallet and it goes well. here is the code.

export const createAmmPool = async () => {
  const raydium = await initSdk()
  const marketId = new PublicKey(`9MH5JY7DFtm2mNKwjYkhbhJjGwHD9XSnebgiXC4vD9GY`)

  const marketBufferInfo = await raydium.connection.getAccountInfo(new PublicKey(marketId))
  const { baseMint, quoteMint } = MARKET_STATE_LAYOUT_V3.decode(marketBufferInfo!.data)

  const baseMintInfo = await raydium.token.getTokenInfo(baseMint)
  const quoteMintInfo = await raydium.token.getTokenInfo(quoteMint)

  const { execute, extInfo, transaction } = await raydium.liquidity.createPoolV4({
    programId: DEVNET_PROGRAM_ID.AmmV4, // devnet
    marketInfo: {
      marketId,
      programId: DEVNET_PROGRAM_ID.OPENBOOK_MARKET, // devent
    },
    baseMintInfo: {
      mint: baseMint,
      decimals: baseMintInfo.decimals, // if you know mint decimals here, can pass number directly
    },
    quoteMintInfo: {
      mint: quoteMint,
      decimals: quoteMintInfo.decimals, // if you know mint decimals here, can pass number directly
    },
    baseAmount: new BN(1000000000),
    quoteAmount: new BN(10000000000),
    startTime: new BN(0), // unit in seconds
    ownerInfo: {
      useSOLBalance: true,
    },
    associatedOnly: false,
    txVersion,
    feeDestinationId: DEVNET_PROGRAM_ID.FEE_DESTINATION_ID, // devnet
    // optional: set up priority fee here
    // computeBudgetConfig: {
    //   units: 600000,
    //   microLamports: 10000000,
    // },
  })
  printSimulate([transaction])

}

in config.ts

export const connection = new Connection(clusterApiUrl('devnet')) //<YOUR_RPC_URL>
export const txVersion = TxVersion.V0 // or TxVersion.LEGACY

let raydium: Raydium | undefined
export const initSdk = async (params?: { loadToken?: boolean }) => {
  if (raydium) return raydium
  raydium = await Raydium.load({
    // owner,
    owner: new PublicKey('4GMb3ucYaXLvySAFuMBjnBSh6KqKnFcaJqaHqWUFhThT'),
    connection,
    cluster: 'devnet',
    disableFeatureCheck: true,
    disableLoadToken: !params?.loadToken,
    blockhashCommitment: 'finalized',
  })
Sky1706 commented 3 months ago

Yes I checked everything initialized for Devnet.

    const raydium = await Raydium.load({
        // owner,
        owner: new PublicKey(
            '4GMb3ucYaXLvySAFuMBjnBSh6KqKnFcaJqaHqWUFhThT',
        ),
        connection,
        cluster: 'devnet',
        disableFeatureCheck: true,
        disableLoadToken: !true,
        blockhashCommitment: 'finalized',
    });

    And still facing same error.
cruzshia commented 3 months ago

could you try exactly the same code I provided to check it's work or not?

Sky1706 commented 3 months ago

yup, I found the problem I was passing the wrong argument in the createPoolV4 function instead of passing marketId I was passed market so that's why I am getting toBuffer error.

Now it's working thank you for your quick reply.