Closed BobosanCrypto closed 4 months ago
please provide your code, error logs don't have enough information.
export const swap = async () => { const raydium = await initSdk() const poolId = '2QdhepnKRTLjjSqPL1PtKNwqrUkoLee5Gqs8bvZhRdMv' const inputAmount = new BN(100) // RAY-USDC pool // note: api doesn't support get devnet pool info const data = await raydium.api.fetchPoolById({ ids: poolId }) const poolInfo = data[0] as ApiV3PoolInfoConcentratedItem
const clmmPoolInfo = await PoolUtils.fetchComputeClmmInfo({ connection: raydium.connection, poolInfo, })
const tickCache = await PoolUtils.fetchMultiplePoolTickArrays({ connection: raydium.connection, poolKeys: [clmmPoolInfo], })
const { minAmountOut, remainingAccounts } = await PoolUtils.computeAmountOutFormat({ poolInfo: clmmPoolInfo, tickArrayCache: tickCache[poolId], amountIn: inputAmount, tokenOut: poolInfo.mintB, slippage: 0.1, epochInfo: await raydium.fetchEpochInfo(), })
const { execute } = await raydium.clmm.swap({ poolInfo, inputMint: poolInfo.mintA.address, amountIn: inputAmount, amountOutMin: minAmountOut.amount.raw, ownerInfo: {}, remainingAccounts, txVersion, })
const { txId } = await execute() console.log('swapped in clmm pool:', { txId })
}
swap()
pull latest code and run yarn install update sdk.
OK, I'll try, thanks
clmm is ok, how to combine clmm and cpmm transactions, Transaction too large?
I don't recommend combine them in to 1 tx cuz there might have unexpected issues(e.g. tx too large, duplicate create token acc..etc), if you still want to do that, sdk tx related functions return transaction and builder which contains all tx data, you can combine/reorganize them by yourself.
const { execute, transaction, builder } = await raydium.clmm.swap({
poolInfo,
inputMint: poolInfo.mintA.address,
amountIn: inputAmount,
amountOutMin: minAmountOut.amount.raw,
observationId: clmmPoolInfo.observationId,
ownerInfo: {},
remainingAccounts,
txVersion,
})
builder.allInstructions
builder.AllTxData
https://solscan.io/tx/2guKCu3NXBghEfyPHy67CLwp1obZfYoMkuBLUb9PsWxjYVYPCV5ae4PitJzc4zi3a9KT5tfrKy2HP9vQHud12r7Z amm and clmm can be combined, if cpmm data is too large. I try to deploy it but it always fails, why? I want to make arbitration
different type of pool definitely has different contract and instructions, and tx has size limits, so you can't just combine them, you should check is over limit or not. reference: https://solana.com/docs/core/transactions#transaction-size.
logs: [ 'Program CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK invoke [1]', 'Program log: Instruction: SwapV2', 'Program log: AnchorError caused by account: observation_state. Error Code: AccountOwnedByWrongProgram. Error Number: 3007. Error Message: The given account is owned by a different program than expected.', 'Program log: Left:', 'Program log: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', 'Program log: Right:', 'Program log: CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK', 'Program CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK consumed 12976 of 200000 compute units', 'Program CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK failed: custom program error: 0xbbf' ]