raydium-sdk-swap-example-typescript icon indicating copy to clipboard operation
raydium-sdk-swap-example-typescript copied to clipboard

Loaded pool keys

Open 0NighTWizard0 opened this issue 11 months ago • 24 comments

hello. I don't know why it gives me this error when I exceute the swap. this error related to the pool and it's like the code can't read the pool list.

Loaded pool keys C:\raydium-sdk-swap-example-typescript\src\RaydiumSwap.ts:59 const poolData = this.allPoolKeysJson.find( ^ TypeError: Cannot read properties of undefined (reading 'find') at RaydiumSwap.findPoolInfoForTokens (C:\raydium-sdk-swap-example-typescript\src\RaydiumSwap.ts:59:43) at C:\raydium-sdk-swap-example-typescript\src\index.ts:30:32 at Generator.next () at fulfilled (C:\raydium-sdk-swap-example-typescript\src\index.ts:5:58) at processTicksAndRejections (node:internal/process/task_queues:95:5) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

0NighTWizard0 avatar Mar 19 '24 01:03 0NighTWizard0

i met same error const directionIn = poolKeys.quoteMint.toString() == toToken ^ TypeError: Cannot read properties of null (reading 'quoteMint')

1500256797 avatar Mar 19 '24 06:03 1500256797

I have been noticing this error with new coins. Are you trying to swap newly created coins?

soos3d avatar Mar 19 '24 13:03 soos3d

its BOME token (ukHH6c7mMyiWCf1b9pnWe25TSpkDDt3H5pQZgZ74J82) it came about 6 days ago.

0NighTWizard0 avatar Mar 21 '24 01:03 0NighTWizard0

just tried it now and the simulation worked fine!

Raydium swap initialized
Swapping 0.01 of So11111111111111111111111111111111111111112 for ukHH6c7mMyiWCf1b9pnWe25TSpkDDt3H5pQZgZ74J82...
Loaded pool keys
Found pool info
{
  minAmountOut: TokenAmount {
    numerator: <BN: 7c19b44>,
    denominator: <BN: f4240>,
    currency: Token {
      decimals: 6,
      symbol: 'UNKNOWN',
      name: 'UNKNOWN',
      programId: [PublicKey [PublicKey(TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA)]],
      mint: [PublicKey [PublicKey(ukHH6c7mMyiWCf1b9pnWe25TSpkDDt3H5pQZgZ74J82)]]
    },
    token: Token {
      decimals: 6,
      symbol: 'UNKNOWN',
      name: 'UNKNOWN',
      programId: [PublicKey [PublicKey(TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA)]],
      mint: [PublicKey [PublicKey(ukHH6c7mMyiWCf1b9pnWe25TSpkDDt3H5pQZgZ74J82)]]
    }
  },
  amountIn: TokenAmount {
    numerator: <BN: 989680>,
    denominator: <BN: 3b9aca00>,
    currency: Token {
      decimals: 9,
      symbol: 'UNKNOWN',
      name: 'UNKNOWN',
      programId: [PublicKey [PublicKey(TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA)]],
      mint: [PublicKey [PublicKey(So11111111111111111111111111111111111111112)]]
    },
    token: Token {
      decimals: 9,
      symbol: 'UNKNOWN',
      name: 'UNKNOWN',
      programId: [PublicKey [PublicKey(TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA)]],
      mint: [PublicKey [PublicKey(So11111111111111111111111111111111111111112)]]
    }
  }
}
{
  context: { apiVersion: '1.17.25', slot: 255567497 },
  value: {
    accounts: null,
    err: null,
    logs: [
      'Program ComputeBudget111111111111111111111111111111 invoke [1]',
      'Program ComputeBudget111111111111111111111111111111 success',
      'Program 11111111111111111111111111111111 invoke [1]',
      'Program 11111111111111111111111111111111 success',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
      'Program log: Instruction: InitializeAccount',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3443 of 999700 compute units',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
      'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]',
      'Program log: Create',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
      'Program log: Instruction: GetAccountDataSize',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1569 of 986390 compute units',
      'Program return: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA pQAAAAAAAAA=',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
      'Program 11111111111111111111111111111111 invoke [2]',
      'Program 11111111111111111111111111111111 success',
      'Program log: Initialize the associated token account',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
      'Program log: Instruction: InitializeImmutableOwner',
      'Program log: Please upgrade to SPL Token 2022 for immutable owner support',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1405 of 979803 compute units',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
      'Program log: Instruction: InitializeAccount3',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4188 of 975921 compute units',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
      'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 24807 of 996257 compute units',
      'Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success',
      'Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [1]',
      'Program log: ray_log: A4CWmAAAAAAARJvBBwAAAAABAAAAAAAAAICWmAAAAAAAeylzdg8AAACMAmQgAQAAAAjjJAgAAAAA',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
      'Program log: Instruction: Transfer',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4736 of 953333 compute units',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]',
      'Program log: Instruction: Transfer',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4645 of 945616 compute units',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success',
      'Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 31282 of 971450 compute units',
      'Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 success',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]',
      'Program log: Instruction: CloseAccount',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2915 of 940168 compute units',
      'Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success'
    ],
    returnData: null,
    unitsConsumed: 62747
  }
}
✨  Done in 21.39s.

soos3d avatar Mar 21 '24 15:03 soos3d

i met same error const directionIn = poolKeys.quoteMint.toString() == toToken ^ TypeError: Cannot read properties of null (reading 'quoteMint')

@soos3d Thanks for your help on this. Its clear the community will use it to trade the latest meme craze of the hour so the acceptance tests should be tight to that use case.

I was able to swap with your default example tokens with no issues using my mainnet Chainstack RPC.

However I am seeing the same issue as others after changing the 'tokenBAddress' address. Did you change anything to get it to work? Here is an example with the Raydium token RAY

image

youngclaude avatar Mar 22 '24 00:03 youngclaude

I have been noticing this error with new coins. Are you trying to swap newly created coins?

This is nice tool. Thanks! I'm trying this with newly created coins and I see the same error. Is this because it attempts to read the price of the token? Why not provide an option for the user to specify?

mulerm avatar Mar 22 '24 01:03 mulerm

I have the same problem, it would be interesting to have a solution for swapping new tokens too

peonante avatar Mar 27 '24 01:03 peonante

i met same error const directionIn = poolKeys.quoteMint.toString() == toToken ^ TypeError: Cannot read properties of null (reading 'quoteMint')

@soos3d Thanks for your help on this. Its clear the community will use it to trade the latest meme craze of the hour so the acceptance tests should be tight to that use case.

I was able to swap with your default example tokens with no issues using my mainnet Chainstack RPC.

However I am seeing the same issue as others after changing the 'tokenBAddress' address. Did you change anything to get it to work? Here is an example with the Raydium token RAY

image

Hi @youngclaude , quoteMint should be an issue with the slippage. You can edit it from here: slippage line

soos3d avatar Mar 27 '24 14:03 soos3d

I'm working on adding retries to re-fetch the pools when they fail. might not fix the issue at 100%, but it should help.

soos3d avatar Mar 27 '24 14:03 soos3d

i met same error const directionIn = poolKeys.quoteMint.toString() == toToken ^ TypeError: Cannot read properties of null (reading 'quoteMint')

@soos3d Thanks for your help on this. Its clear the community will use it to trade the latest meme craze of the hour so the acceptance tests should be tight to that use case. I was able to swap with your default example tokens with no issues using my mainnet Chainstack RPC. However I am seeing the same issue as others after changing the 'tokenBAddress' address. Did you change anything to get it to work? Here is an example with the Raydium token RAY image

Hi @youngclaude , quoteMint should be an issue with the slippage. You can edit it from here: slippage line

I tried changing the slippage but nothing changes, the error persists.

I believe the problem is due to the fact that new pairs are not immediately updated in the .. mainnet.json link

peonante avatar Mar 27 '24 14:03 peonante

Yes, I think that too. Adding retry logic to fetch the pairs should make it better. I'll work on it as soon as I have some time!

soos3d avatar Mar 28 '24 13:03 soos3d

must there be something already existing that does this job? I can't find any other repositories or code anywhere that solves this, yet there are swaps and bots that do it

peonante avatar Mar 28 '24 14:03 peonante

Hey folks :wave: I have same issue. I'm trying to get pool information from here https://api.raydium.io/v2/sdk/liquidity/mainnet.json and seems Raydium is updating file not so frequently and one can't get latest deployed pool information from there. Do you know any alternative services that provide that?

kiknaio avatar Mar 29 '24 14:03 kiknaio

Guys thanks a lot for your helps. Is there any way to test it first on devnet ?

Why my change "https://api.raydium.io/v2/sdk/liquidity/devnet.json" not works ? @soos3d could you please let me know how can i make the code compatible for Devnet ?

Doing test by Devnet is important really.

anisurrahman072 avatar Apr 01 '24 11:04 anisurrahman072

I swapped the token A (HUMP). to token B (SOL) the terminal show no error and generate the transaction URL but TX-URL_SOLSCAN nothing is there

Krshivam25 avatar Apr 05 '24 08:04 Krshivam25

Guys thanks a lot for your helps. Is there any way to test it first on devnet ?

Why my change "https://api.raydium.io/v2/sdk/liquidity/devnet.json" not works ? @soos3d could you please let me know how can i make the code compatible for Devnet ?

Doing test by Devnet is important really.

Let me look into that!

soos3d avatar Apr 05 '24 12:04 soos3d

I swapped the token A (HUMP). to token B (SOL) the terminal show no error and generate the transaction URL but TX-URL_SOLSCAN nothing is there

yeah this happens when the chain is really congested; the transactions are simply dropped. Unfortunately, there is not too much we can do at the moment besides increasing priority fees and sens transactions continuously until one goes through🥲

soos3d avatar Apr 05 '24 12:04 soos3d

@soos3d adding to this code need lot of more improvement as even the user dont have the SOL balance on wallet the transaction getting executed and there is no check for this. which is wrong.

Krshivam25 avatar Apr 05 '24 12:04 Krshivam25

even the user dont have the SOL balance on wallet the transaction getting executed and there is no check for this

true, this can be a good feature to add; feel free to contribute and open a PR if you want to implement it!

soos3d avatar Apr 05 '24 12:04 soos3d

even the user dont have the SOL balance on wallet the transaction getting executed and there is no check for this

true, this can be a good feature to add; feel free to contribute and open a PR if you want to implement it!

Sure, I am working on it , will update it here soon : )

Krshivam25 avatar Apr 05 '24 12:04 Krshivam25

hello. I don't know why it gives me this error when I exceute the swap. this error related to the pool and it's like the code can't read the pool list.

Loaded pool keys C:\raydium-sdk-swap-example-typescript\src\RaydiumSwap.ts:59 const poolData = this.allPoolKeysJson.find( ^ TypeError: Cannot read properties of undefined (reading 'find') at RaydiumSwap.findPoolInfoForTokens (C:\raydium-sdk-swap-example-typescript\src\RaydiumSwap.ts:59:43) at C:\raydium-sdk-swap-example-typescript\src\index.ts:30:32 at Generator.next () at fulfilled (C:\raydium-sdk-swap-example-typescript\src\index.ts:5:58) at processTicksAndRejections (node:internal/process/task_queues:95:5) error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

here I am facing other error

throw new Error('Non-base' + BASE + ' character')
      ^

Error: Non-base58 character

AMIYA8597 avatar Apr 16 '24 07:04 AMIYA8597

Guys thanks a lot for your helps. Is there any way to test it first on devnet ? Why my change "https://api.raydium.io/v2/sdk/liquidity/devnet.json" not works ? @soos3d could you please let me know how can i make the code compatible for Devnet ? Doing test by Devnet is important really.

Let me look into that!

i have this issue to, is it becasue raydium does not provide the poolkeys?

brianyeap avatar Apr 18 '24 07:04 brianyeap

The TypeError: Cannot read properties of null (reading 'quoteMint' appears if the app can't load any pools keys for your tokens pairs(for example pair: SOL and USDC).

So you can write instead of

 const poolInfo = raydiumSwap.findPoolInfoForTokens(swapConfig.tokenAAddress, swapConfig.tokenBAddress);
 console.log('Found pool info');

this:

  const poolInfo = raydiumSwap.findPoolInfoForTokens(swapConfig.tokenAAddress, swapConfig.tokenBAddress);
    if (!poolInfo) {
      console.error('Pool not found');
      return 'Pool not found';
    }
  

alexandr-kazakov avatar Apr 26 '24 14:04 alexandr-kazakov

I'm searching myself ho to make swap for newly created coins. Current this repo solution doesn't work for this. I implemented this https://solana.stackexchange.com/a/10020/2840 by LIQUIDITY_STATE_LAYOUT_V4 solution too and it doesn't help. I'm thinking about yellowstone-grpc solution now.

Any ideas?

alexandr-kazakov avatar Apr 26 '24 14:04 alexandr-kazakov

Hey folks 👋 I have same issue. I'm trying to get pool information from here https://api.raydium.io/v2/sdk/liquidity/mainnet.json and seems Raydium is updating file not so frequently and one can't get latest deployed pool information from there. Do you know any alternative services that provide that?

have you solved it?

brooke007 avatar Jun 28 '24 07:06 brooke007

@brooke007 I solved it https://github.com/alexandr-kazakov/solana-crendel-bot In my bot pools data is not get from mainnet.json. From the first second of pool creation you will know about it.

alexandr-kazakov avatar Jun 29 '24 08:06 alexandr-kazakov