raydium-io / raydium-sdk-V2-demo

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

Not able to create cpmm pool sdk v2 #78

Open Nayyaroddeen opened 6 days ago

Nayyaroddeen commented 6 days ago

export const createPool = async () => { try { const raydium = await initSdk({ loadToken: true })

// Check token list here: https://api-v3.raydium.io/mint/list
// RAY
const mintA = await raydium.token.getTokenInfo('DkuWZzwDLCGTi7KWoLbEND1A2GUrXNTQEqq1AKq2Dunp')
// USDC
const mintB = await raydium.token.getTokenInfo('FVPnpBh3X6YdAHeJ9de92BQBRcACk3iaPcMKv21Ei7ZU')
console.log(mintA, mintB)

const feeConfigs = await raydium.api.getCpmmConfigs()

if (raydium.cluster === 'devnet') {
  feeConfigs.forEach((config) => {
    config.id = getCpmmPdaAmmConfigId(DEVNET_PROGRAM_ID.CREATE_CPMM_POOL_PROGRAM, config.index).publicKey.toBase58()
  })
}

const { execute, extInfo } = await raydium.cpmm.createPool({
  programId: DEVNET_PROGRAM_ID.CREATE_CPMM_POOL_PROGRAM,
  poolFeeAccount: DEVNET_PROGRAM_ID.CREATE_CPMM_POOL_PROGRAM,
  mintA,
  mintB,
  mintAAmount: new BN(1),
  mintBAmount: new BN(1),
  startTime: new BN(0),
  feeConfig: feeConfigs[0],
  associatedOnly: false,
  ownerInfo: {
    useSOLBalance: true,
  },
  txVersion,
})
console.log("here")

const { txId } = await execute({ sendAndConfirm: true })
console.log(txId,"here")
console.log('Pool created', {
  txId,
  poolKeys: Object.keys(extInfo.address).reduce(
    (acc, cur) => ({
      ...acc,
      [cur]: extInfo.address[cur as keyof typeof extInfo.address].toString(),
    }),
    {}
  ),
})

} catch (error) { console.log(error) console.dir(error, { depth: null }); // Set depth to null for full depth inspection

}  

}

/* Uncomment the code below to execute / createPool() .then(() => console.log('Pool creation process complete.')) .catch((error) => console.error('Unhandled error:', error))

It's print object object but not creating a pool, pls help me understand this

Screenshot 2024-09-11 at 11 51 23 AM
cruzshia commented 5 days ago

raydium api doesn't support get devent mint info via raydium.token.getTokenInfo(mint address) please setup them manually like this

{
      address: '4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R',
      programId: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
      decimals: 6,
    } 

also you can paste simulate tx string here https://explorer.solana.com/tx/inspector?cluster=devnet to check what's going on and ensure you config a devent rpc url and cluster in config.ts