raydium-io / raydium-sdk-V2-demo

Open-source Typescript SDK demos
45 stars 25 forks source link

Phantom wallet sign tx error when creates AMM pool #31

Closed talent-dev610 closed 3 months ago

talent-dev610 commented 3 months ago

I'm facing this error when I'm creating AMM pool by using raydium sdk v2. Actually sdk V2 is very convenient than v1. But there is no problem when I sign tx through my private key. I only get this error when I sign tx by usiing phantom wallet. this is my code part.

const { execute, extInfo, builder } = await raydium.liquidity.createPoolV4({.....})

const instructions: TransactionInstruction[] = builder.allInstructions; instructions.forEach(async (instruction) => { transaction.add(instruction); }) console.log("🚀 ~ createAmmPool ~ instructions:", instructions) try { const signature = await sendTransaction(transaction, connection); console.log("🚀 ~ createAmmPool ~ signature:", signature) } catch (error) { console.error('Transaction signing failed', error); }

cruzshia commented 3 months ago

please check how sdk txtool build transactions, and raydium.liquidity.createPoolV4() also return transaction, you can compare what's the different. https://github.com/raydium-io/raydium-sdk-V2/blob/master/src/common/txTool/txTool.ts#L228 https://github.com/raydium-io/raydium-sdk-V2/blob/master/src/common/txTool/txTool.ts#L405

talent-dev610 commented 3 months ago

By using signAllTransactions parameters, I could sign transaction by using Phantom wallet so when execute() function is called, phantom wallet appeared. But same error occured . Transaction failed.

const createAmmPool = async (id: any) => { const raydium = await initSdk() const marketId = new PublicKey(id)

// if you are confirmed your market info, don't have to get market info from rpc below
const marketBufferInfo = await raydium.connection.getAccountInfo(new PublicKey(marketId))
const { baseMint, quoteMint } = MARKET_STATE_LAYOUT_V3.decode(marketBufferInfo!.data)

// check mint info here: https://api-v3.raydium.io/mint/list
// or get mint info by api: await raydium.token.getTokenInfo('mint address')

const baseMintInfo = await raydium.token.getTokenInfo(baseMint)
console.log("🚀 ~ createAmmPool ~ baseMintInfo:", baseMintInfo)
const quoteMintInfo = await raydium.token.getTokenInfo(quoteMint)
console.log("🚀 ~ createAmmPool ~ quoteMintInfo:", quoteMintInfo)

// Create pool instructions
// This is a placeholder code. Replace it with actual instructions required for Raydium pool creation

const { execute, extInfo, builder } = await raydium.liquidity.createPoolV4({
  // programId: AMM_V4, // devnet: DEVNET_PROGRAM_ID.AmmV4      
  programId: DEVNET_PROGRAM_ID.AmmV4,
  marketInfo: {
    marketId,
    // programId: OPEN_BOOK_PROGRAM, // devnet: DEVNET_PROGRAM_ID.OPENBOOK_MARKET
    programId: DEVNET_PROGRAM_ID.OPENBOOK_MARKET
  },
  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(10000),
  quoteAmount: new BN(0.1),
  startTime: new BN(0),
  ownerInfo: {
    useSOLBalance: true,
  },
  associatedOnly: false,
  txVersion,
  // feeDestinationId: FEE_DESTINATION_ID, // devnet: DEVNET_PROGRAM_ID.FEE_DESTINATION_ID
  feeDestinationId: DEVNET_PROGRAM_ID.FEE_DESTINATION_ID
  // optional: set up priority fee here
  // computeBudgetConfig: {
  //   units: 600000,
  //   microLamports: 10000000,
  // },
})

const { txId } = await execute()
console.log("🚀 ~ createAmmPool ~ txId:", txId)

}

cruzshia commented 3 months ago

could you provide your market id? is it in devent? also did you switch phantom wallet to devent mode?

talent-dev610 commented 3 months ago

yes, I already switched into devnet mode 3636rwvFB2T4cETX9WjW7P2ibZjodRfVY8uJX628npKu This is market Id for solana devnet. I think create marketid works well on devnet. Just got failed on create AMM pool function on devnet

cruzshia commented 3 months ago

run this code block will show tx in base64 format, paste this base64 to here

import { printSimulate } from '@raydium-io/raydium-sdk-v2'

const { transaction } = await raydium.liquidity.createPoolV4({xxx})
printSimulate([transaction])
talent-dev610 commented 3 months ago

"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQALFtYVLDskhsEATkalZWDmlhBq11qNY364lAZ11IsEb1ylwWHEi3oQmt00G/FiL+XNs2osu62fn3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EPFQwQCw4CEQMEEg0FBgcTCBQVAAkBChoB/AAAAAAAAAAAAAAAAAAAAAAQJwAAAAAAAAwDAQAAAQkA"

cruzshia commented 3 months ago

check simulate result here

initial liquidity for createPool must greater than 0, and you pass new BN(0.1) to quoteAmount is invalid. also noticed that your second mint in market has decimals = 9 but fixed supply is 10**5, if change quoteAmount to greater integer(>= 1) still not working, you can try create a new devnet spl with more than 10**(spl decimals) and try create market/pool again

 baseAmount: new BN(10000),
 quoteAmount: new BN(0.1),
image
talent-dev610 commented 3 months ago

"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQALFtYVLDskhsEATkalZWDmlhBq11qNY364lAZ11IsEb1ylojZDzRgQ5nWIWydsLJ7xvRvVUqL6cSWoqMNRNxmoLphnuEkMK346jg2bK7DEW1QFck7LK5p6Bnn3p9yQOr0+aIK77oOGPtIbu255azo//nMZaf24cIdG9NO4JiQrMMQP1//5n7WF0reLW5K2AAIMVcJNb0kelVbgZzZ9F8c4mjZbrFdvCzJa+3yMA/ycTNZzWDEkbSJIWTM+eUHKejx+U/YdksEALbhknkxBcGbRA1K7HXLFla3BOtSKsfS46wzA2lxz52F5N68TViLYVUimzuswG1tqUXbbwSKm3EKEMGAlfmGPXBABytmdspEDcHRdP3QKG9zl4hKKfKeAPVd68CNJV3pfrJsM3tQd2WGGgd+lkAO//w7EuRgq0EMa4tAUOd5s8RWcHQenXRyz0AH2+WU9aFaeeHG1DbMyc7ubRQUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpBpuIV/6rgYT7aH9jRhjANdrEOdwa6ztVmKDwAAAAAAEGp9UXGSxcUSGMyUw9SvF/WNruCJuh/UTj29mKAAAAAPVoKwb8y9umtA0jShSx996di14R5FpyvKqSYj8+Z3objJclj04kifG7PRApFI4NgwtaE5na/xCEBI572Nvp+Fm7HPCjKxncvtY5by6WcW0F9RHewB0PZf11ht1kRKpNj82iaWnF835vih7BXFgBSunoStE0s1FJ6m4Ns9oNKy7Cbf4WPUsPNsn6+Yv59ZOc5qy/EPSN8y/0rNX75XdiHVbNDrwdm/rd1skt4FKR1S97OZKYlNAN73RBtoNNsze+RLtk2ZbJBEcbYnmlQHrXLLkwWqF2Dp4bHXdLWwUGagfw7L36RtIPOCwflRzLso5ReZa+9RrliRufFKy2mLsS4nsECwIAAXwDAAAA1hUsOySGwQBORqVlYOaWEGrXWo1jfriUBnXUiwRvXKUgAAAAAAAAAEUxTkpudjVheW5DeW14VTFBM3g2clZycU1zYW5ZMzlR8R0fAAAAAAClAAAAAAAAAAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpDAQBDQAOAQEPFQwQCw4CEQMEEg0FBgcTCBQVAAkBChoB/AAAAAAAAAAAAQAAAAAAAAAQJwAAAAAAAAwDAQAAAQkA"

talent-dev610 commented 3 months ago

I'm silll get this error, what wrong with me?

cruzshia commented 3 months ago

wrong fee payer, please check

image
talent-dev610 commented 3 months ago

it is my wallet address. I'm not sure what's wrong. Fee payer is not my wallet address?

cruzshia commented 3 months ago

baseAmount or quoteAmount are too less, input more, also you can paste base64 string here ( https://explorer.solana.com/tx/inspector?cluster=devnet) and click simulate to check what's going on.

image
talent-dev610 commented 3 months ago

"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAQALFtYVLDskhsEATkalZWDmlhBq11qNY364lAZ11IsEb1yloJvnBG88S4StvzEuPUww9k52dPm6QraxuQsPH8B+8jLG/RMYpCVUUF+6SPEoB5WneXpcDGlS0Wnv7wa5tJORMjCmdK4Iuzc5W3qorzJzSC8MhbjHPawjNb4ZNodf97jaac2PrMkMhNRnuD4V+nrxCsk9CYvKv7co3pHv8VpEa429lNPZu6Zhk4ud5v1Zw7Zw//IObD2e933tzYmZPaXUFTd7Y3jALLTlOLkxNzowenvSq5uFwSh696C7v5o8LY99JpFZ0a4tucumO/594s+MAqf7TcAAN5uA23Qd1b5ZVIUlfmGPXBABytmdspEDcHRdP3QKG9zl4hKKfKeAPVd68BZy9BV0/IielCulaGhWkd/8/k1AfgtcM500/qDUarNux3g1yyFlchAHOp6Ok6nWrlYSuvCcmiLozB5GgEbX5DMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpBpuIV/6rgYT7aH9jRhjANdrEOdwa6ztVmKDwAAAAAAEGp9UXGSxcUSGMyUw9SvF/WNruCJuh/UTj29mKAAAAAPVoKwb8y9umtA0jShSx996di14R5FpyvKqSYj8+Z3objJclj04kifG7PRApFI4NgwtaE5na/xCEBI572Nvp+Fm7HPCjKxncvtY5by6WcW0F9RHewB0PZf11ht1kRKpNj0EuEtZjWYV4GGn6hHrVOlNaAN9n4BnUg9SnUaB4pZHqbf4WPUsPNsn6+Yv59ZOc5qy/EPSN8y/0rNX75XdiHVbNDrwdm/rd1skt4FKR1S97OZKYlNAN73RBtoNNsze+RNPnMbtu1P8mdfofDmQeLl6TUeSpz+jr7HXactZkDbftMR3qqxVbJAcVSyAdPqB301S5jKe+PJvrYUYGWvBwKtEECwIAAXwDAAAA1hUsOySGwQBORqVlYOaWEGrXWo1jfriUBnXUiwRvXKUgAAAAAAAAAEJ6d1F3N0pudWdNNW9GUHc1OGtRd0xaa2F0RjlkaGJSBB4fAAAAAAClAAAAAAAAAAbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpDAQBDQAOAQEPFQwQCw4CEQMEEg0FBgcTCBQVAAkBChoB/AAAAAAAAAAAFAAAAAAAAAAAwusLAAAAAAwDAQAAAQkA" How much base and quote do I need? baseAmount: new BN(200000000), quoteAmount: new BN(20), This is also small?

cruzshia commented 3 months ago

Yes, please check my prev comment and simulate by yourself

cruzshia commented 3 months ago

Due to no issues found in sdk side, I'll close issue, and do your own test in further development.