raydium-io / raydium-sdk-V2

Open-source Typescript SDK for Raydium
GNU General Public License v3.0
59 stars 44 forks source link

Always faild while fetching all pool basic info #26

Closed liuyuekeng closed 3 months ago

liuyuekeng commented 3 months ago

Hello I am encountering failures when running the routeSwap script in theraydium-sdk-V2-demo project. I have tried using both OneKey's RPC and Alchemy's RPC, and errors are thrown during the fetchRoutePoolBasicInfo process. Below is the error message.

using onekey

raydium-sdk-V2-demo % yarn dev src/trade/routeSwap.ts
yarn run v1.22.19
$ ts-node src/trade/routeSwap.ts
connect to rpc https://node.onekey.so/sol in mainnet
reading cache pool data
cannot read cache pool data
fetching all pool basic info, this might take a while (more than 30 seconds)..
TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11730:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ClientBrowser.callServer (/Users/odd-tangerine/kekkai/raydium-sdk-V2-demo/node_modules/@solana/web3.js/src/connection.ts:1674:17) {
  cause: ConnectTimeoutError: Connect Timeout Error
      at onConnectTimeout (node:internal/deps/undici/undici:6869:28)
      at node:internal/deps/undici/undici:6825:50
      at Immediate._onImmediate (node:internal/deps/undici/undici:6857:13)
      at processImmediate (node:internal/timers:476:21) {
    code: 'UND_ERR_CONNECT_TIMEOUT'
  }
}
error Command failed with exit code 1.

using alchemy

raydium-sdk-V2-demo % yarn dev src/trade/routeSwap.ts
yarn run v1.22.19
$ ts-node src/trade/routeSwap.ts
connect to rpc https://solana-mainnet.g.alchemy.com/v2/******************************** in mainnet
reading cache pool data
cannot read cache pool data
fetching all pool basic info, this might take a while (more than 30 seconds)..
/Users/odd-tangerine/kekkai/raydium-sdk-V2-demo/node_modules/@solana/web3.js/src/connection.ts:1698
        callback(new Error(`${res.status} ${res.statusText}: ${text}`));
                 ^
Error: 500 Internal Server Error: {"jsonrpc":"2.0","id":"d3ae1bf5-2d1c-45ef-b4e9-af993099cc63","error":{"code":-32603,"message":"Internal server error"}}
    at ClientBrowser.callServer (/Users/odd-tangerine/kekkai/raydium-sdk-V2-demo/node_modules/@solana/web3.js/src/connection.ts:1698:18)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
error Command failed with exit code 1.

According to the issue at https://github.com/raydium-io/raydium-sdk-V2/issues/9, I have checked the network status and can confirm that I can access api-v3.raydium.io without any issues.

raydium-sdk-V2-demo % curl "https://api-v3.raydium.io/pools/info/ids?ids=CnoKYnj3GNdTxQfKKBxmq33rJMShyt3eC1zWGgfptzkT"
{"id":"ce373fcf-3cc7-43c1-affb-cc04513cbfa8","success":true,"data":[{"type":"Standard","programId":"CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C","id":"CnoKYnj3GNdTxQfKKBxmq33rJMShyt3eC1zWGgfptzkT","mintA":{"chainId":101,"address":"So11111111111111111111111111111111111111112","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","logoURI":"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png","symbol":"WSOL","name":"Wrapped SOL","decimals":9,"tags":[],"extensions":{}},"mintB":{"chainId":101,"address":"AK2Vf9cCx2TkRBf51B4oUwtr8Fp926PQeBjPkZcCCeMK","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","logoURI":"https://img-v1.raydium.io/icon/AK2Vf9cCx2TkRBf51B4oUwtr8Fp926PQeBjPkZcCCeMK.png","symbol":"CR7","name":"CRISTIENO RONELDO","decimals":6,"tags":[],"extensions":{}},"config":{"id":"D4FPEruKEHrG5TenZ2mpDGEfu1iUvTiqBxvpU8HLBvC2","index":0,"protocolFeeRate":120000,"tradeFeeRate":2500,"fundFeeRate":40000,"createPoolFee":"150000000"},"price":25726539.08212697,"mintAmountA":0.029587796,"mintAmountB":761191.590148,"feeRate":0.0025,"openTime":"1718554400","tvl":5.77,"day":{"volume":0,"volumeQuote":0,"volumeFee":0,"apr":0,"feeApr":0,"priceMin":0,"priceMax":0,"rewardApr":[]},"week":{"volume":0,"volumeQuote":0,"volumeFee":0,"apr":0,"feeApr":0,"priceMin":0,"priceMax":0,"rewardApr":[]},"month":{"volume":0,"volumeQuote":0,"volumeFee":0,"apr":0,"feeApr":0,"priceMin":0,"priceMax":0,"rewardApr":[]},"pooltype":[],"rewardDefaultInfos":[],"farmUpcomingCount":0,"farmOngoingCount":0,"farmFinishedCount":0,"lpMint":{"chainId":101,"address":"FghsDrnbXNjFzwF2x96tJ4jNJ3vLvpsAwPxnLqGajbUZ","programId":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","logoURI":"","symbol":"","name":"","decimals":9,"tags":[],"extensions":{}},"lpPrice":57654343.46546721,"lpAmount":1e-7}]}

How should I resolve this issue?

cruzshia commented 3 months ago

raydium.tradeV2.fetchRoutePoolBasicInfo doesn't call raydium's api, it calls rpc to fetch huge pool data from rpc directly, according to your error message and some tests from our side, we can confirm that it's your rpc's error, please ensure your rpcs have enough network capacity to fetch more than 20k pools data. which CONNECT_TIMEOUT and Internal server error were both thrown from rpc nodes. also reminds that this issue is related to demo reop, you can open issues there.