raydium-io / raydium-sdk

An SDK for building applications on top of Raydium.
https://sdk.raydium.io
GNU General Public License v3.0
308 stars 125 forks source link

Fetch Info simulation error #68

Open vlcr777888 opened 3 months ago

vlcr777888 commented 3 months ago

Hello, I found the problem while calling Liquidity.fetchInfo() from liquidity.ts static async fetchInfo({ connection, poolKeys }: LiquidityFetchInfoParams) {

sometimes it gives an error reason: 'failed to simulate for instructions'

sometimes its works correctly (from 100 calls it work only aprx for 60)

how to figure out what the reason? tried with different rpc public and paid ones, problem remains

also found some folks at Raydium discord with the same problem

vlcr777888 commented 3 months ago

People who have the same problem 1 2 3 4 5

Giopi commented 3 months ago

same error

nuhfurkan commented 2 months ago

Is there any solution found yet?

mdatsev commented 2 months ago

I have the same problem. It's hard to reproduce and when it happens the sdk hides the details of why it failed. I opened another issue #77

alexrepetskyi commented 2 months ago

I have same issue. I tried to do a call just for the 1 pool.

WhoIsMars commented 2 months ago

same error

roshaans commented 1 month ago

same

easoninus commented 1 month ago

Same error on localhost by clone program from devnet to local.

solana-test-validator -r \
--ledger ~/.anchor/test-ledger \
--url devnet \
--clone-upgradeable-program HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8 \
--clone-upgradeable-program EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj \
--clone 3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR \
--clone 8QN9yfKqWDoKjvZmqFsgCzAqwZBQuzVVnC388dN5RCPo \
--clone RaydiumSimuLateTransaction11111111111111111

Got an error Program HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8 failed: instruction modified data of a read-only account by calling Liquidity.fetchInfo functions. But it seems working fine on devnet

mcfriend99 commented 3 weeks ago

Anybody find a solution so far??

roshaans commented 3 weeks ago

Yes. In my case, I just needed to call the Raydium FetchInfo API to fetch the updated reserves. I simply wrote a method to do this for me.

const reserves = await this.calculateReserves(poolKeys) as LiquidityPoolInfo

  private async calculateReserves(poolKeys: LiquidityPoolKeysV4) {
    try {
      const baseAmount = await this.getTokenAmount(poolKeys.baseVault);
      const quoteAmount = await this.getTokenAmount(poolKeys.quoteVault);

      logger.info("base vault", poolKeys.baseVault)
      logger.info("quote vault", poolKeys.quoteVault)
      logger.info("base decimals", poolKeys.baseDecimals)
      logger.info("quote decimals", poolKeys.quoteDecimals)
      const baseReserve = baseAmount.div(new BN(10).pow(new BN(poolKeys.baseDecimals)));
      const quoteReserve = quoteAmount.div(new BN(10).pow(new BN(poolKeys.quoteDecimals)));

      console.log('Base Reserve:', baseReserve.toString());
      console.log('Quote Reserve:', quoteReserve.toString());

      return { baseReserve, quoteReserve };
    } catch (error) {
      console.error('Failed to calculate reserves:', error);
      throw error;
    }
  }