0

Please let me know how to fix this error or how to swap SPL token with code in Raydium.

  • This is my code. const poolInfo = await Liquidity.fetchInfo({ connection, poolKeys }); "Liquidity is Raydium sdk function. poolKeys is publicKey type."

  • This is error. tx failed => Error: simulate log not match keyword (argument="keyword"), value="GetPoolData"), code=INVALID_ARGUMENT, module=common/web3, version=1.1.0-beta.1) at W.makeError (logger.ts:216:1) at W.throwError (logger.ts:228:1) at W.throwArgumentError (logger.ts:232:1) at W.assertArgument (logger.ts:246:1) at Wt (web3.ts:252:1) at async qe.fetchMultipleInfo (liquidity.ts:1622:1) at async qe.fetchInfo (liquidity.ts:1566:1) at async calcAmountOut (raydium.js:45:1) at async tradeContext.js:191:1 : this is my own script.

Please help me.

1 Answer 1

0

It's likely your poolKeys parameter doesn't match the fetchInfo input.

You might want to check how you get your parameters.

Here's my approach for your reference.

const {
    Liquidity,
    Market,
    findProgramAddress,
    LIQUIDITY_STATE_LAYOUT_V4,
    MARKET_STATE_LAYOUT_V3,
    SPL_MINT_LAYOUT,
} = require('@raydium-io/raydium-sdk')

async function formatAmmKeysById(id) {
    const account = await connection.getAccountInfo(new PublicKey(id))

    if (account === null) throw Error(' get id info error ')
    const info = LIQUIDITY_STATE_LAYOUT_V4.decode(account.data)

    const marketId = info.marketId
    const marketAccount = await connection.getAccountInfo(marketId)
    if (marketAccount === null) throw Error(' get market info error')
    const marketInfo = MARKET_STATE_LAYOUT_V3.decode(marketAccount.data)

    const lpMint = info.lpMint
    const lpMintAccount = await connection.getAccountInfo(lpMint)
    if (lpMintAccount === null) throw Error(' get lp mint info error')
    const lpMintInfo = SPL_MINT_LAYOUT.decode(lpMintAccount.data)

    return {
        id,
        baseMint: info.baseMint.toString(),
        quoteMint: info.quoteMint.toString(),
        lpMint: info.lpMint.toString(),
        baseDecimals: info.baseDecimal.toNumber(),
        quoteDecimals: info.quoteDecimal.toNumber(),
        lpDecimals: lpMintInfo.decimals,
        version: 4,
        programId: account.owner.toString(),
        authority: Liquidity.getAssociatedAuthority({ programId: account.owner }).publicKey.toString(),
        openOrders: info.openOrders.toString(),
        targetOrders: info.targetOrders.toString(),
        baseVault: info.baseVault.toString(),
        quoteVault: info.quoteVault.toString(),
        withdrawQueue: info.withdrawQueue.toString(),
        lpVault: info.lpVault.toString(),
        marketVersion: 3,
        marketProgramId: info.marketProgramId.toString(),
        marketId: info.marketId.toString(),
        marketAuthority: Market.getAssociatedAuthority({ programId: info.marketProgramId, marketId: info.marketId }).publicKey.toString(),
        marketBaseVault: marketInfo.baseVault.toString(),
        marketQuoteVault: marketInfo.quoteVault.toString(),
        marketBids: marketInfo.bids.toString(),
        marketAsks: marketInfo.asks.toString(),
        marketEventQueue: marketInfo.eventQueue.toString(),
        lookupTableAccount: PublicKey.default.toString()
    }
}

const targetPoolInfo = await formatAmmKeysById("target_pool_address");
const poolKeys = jsonInfo2PoolKeys(targetPoolInfo)

you can also check this link for more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.