Skip to main content
added 1881 characters in body
Source Link

UPD: add code
This is swap function:

 async function execSwap(input) {
    const myPublicKey = myKeyPair.publicKey

    let targetPoolInfo;
    while (true) {
        await sleepTime(15000);
        try {
            targetPoolInfo = await formatAmmKeysById(input.targetPool);
            if (targetPoolInfo) {
                break; // If successful, exit the loop
            }
        } catch (error) {
            console.error('pool not found, retrying...');
            
        }
    }
    let poolKeys = jsonInfo2PoolKeys(targetPoolInfo);
  
    const minAmountOut = new TokenAmount(input.outputToken, 1);
    const walletTokenAccounts = await getWalletTokenAccount(connection, myPublicKey)
    console.log(myPublicKey)
    try {
        const instruction = await Liquidity.makeSwapInstructionSimple({
            connection,
            poolKeys,
            userKeys: {
                tokenAccounts: walletTokenAccounts,
                owner: myPublicKey
            },
            amountIn: input.inputTokenAmount,
            amountOut: minAmountOut,
            fixedSide: 'in',
            makeTxVersion,
    })
    } catch (error) {
        console.error(error);
    }

This is "main.js":

const inputToken = quoteToken; // WSOL
    const outputToken = baseToken; // custom token
    const inputTokenAmount = new TokenAmount(inputToken, 10**8);
    const slippage = new Percent(1, 100);
    const wallet = fromKeypair;
    console.log(wallet)
    const res = await execSwap({
          targetPool,
          inputTokenAmount,
          outputToken,
          slippage,
          wallet
      });

UPD: add code
This is swap function:

 async function execSwap(input) {
    const myPublicKey = myKeyPair.publicKey

    let targetPoolInfo;
    while (true) {
        await sleepTime(15000);
        try {
            targetPoolInfo = await formatAmmKeysById(input.targetPool);
            if (targetPoolInfo) {
                break; // If successful, exit the loop
            }
        } catch (error) {
            console.error('pool not found, retrying...');
            
        }
    }
    let poolKeys = jsonInfo2PoolKeys(targetPoolInfo);
  
    const minAmountOut = new TokenAmount(input.outputToken, 1);
    const walletTokenAccounts = await getWalletTokenAccount(connection, myPublicKey)
    console.log(myPublicKey)
    try {
        const instruction = await Liquidity.makeSwapInstructionSimple({
            connection,
            poolKeys,
            userKeys: {
                tokenAccounts: walletTokenAccounts,
                owner: myPublicKey
            },
            amountIn: input.inputTokenAmount,
            amountOut: minAmountOut,
            fixedSide: 'in',
            makeTxVersion,
    })
    } catch (error) {
        console.error(error);
    }

This is "main.js":

const inputToken = quoteToken; // WSOL
    const outputToken = baseToken; // custom token
    const inputTokenAmount = new TokenAmount(inputToken, 10**8);
    const slippage = new Percent(1, 100);
    const wallet = fromKeypair;
    console.log(wallet)
    const res = await execSwap({
          targetPool,
          inputTokenAmount,
          outputToken,
          slippage,
          wallet
      });
Source Link

pubkey.toBase58 is not a function

I'm trying to create swapAmm function on Raydium
I get targetPoolInfo by formatAmmKeysById() and get poolKeys by jsonInfo2PoolKeys()

But when I'm trying to run Liquidity.makeSwapInstructionSimple() always failes
With Error: pubkey.toBase58 is not a function I'm thinking that something wrong with poolkeys

Do you knok, how can I solve it?