Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parsePriceData not properly parsing account data #79

Open
danielkboyer opened this issue Jul 31, 2024 · 2 comments
Open

parsePriceData not properly parsing account data #79

danielkboyer opened this issue Jul 31, 2024 · 2 comments

Comments

@danielkboyer
Copy link

Code in question

  const pricePublicKey = new PublicKey(oracle.priceAddress);
    const result = await connection.getAccountInfo(pricePublicKey);
    if (result !== null) {
      let { price, previousPrice } = parsePriceData(result.data);
      priceData = price || previousPrice;
          }

Error

Error: The value of "offset is out of range. It must be >= 0 and <= 126. Received 176
    at ERR_OUT_OF_RANGE (c:\Users\dedaq\Documents\SolendLiquidator\dans-liquidator\src\libs\pyth.ts:287:3)
    at boundsError (c:\Users\dedaq\Documents\SolendLiquidator\dans-liquidator\src\libs\pyth.ts:283:9)
    at readBigUInt64LE (c:\Users\dedaq\Documents\SolendLiquidator\dans-liquidator\src\libs\pyth.ts:247:5)
    at parsePriceData (c:\Users\dedaq\Documents\SolendLiquidator\dans-liquidator\src\libs\pyth.ts:162:24)
    at getTokenOracleData (c:\Users\dedaq\Documents\SolendLiquidator\dans-liquidator\src\libs\pyth.ts:56:38)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at getTokensOracleData (c:\Users\dedaq\Documents\SolendLiquidator\dans-liquidator\src\libs\pyth.ts:104:16)
    at runLiquidator (c:\Users\dedaq\Documents\SolendLiquidator\dans-liquidator\src\liquidate.ts:49:28)

Node.js v20.10.0

I'm not sure why it's not able to parse the oracles data anymore.

@danielkboyer
Copy link
Author

Solution

const pythSolanaReceiver = new PythSolanaReceiver({
    connection,
    wallet: new NodeWallet(RAND_KEYPAIR),
  });
 const priceAccount =
        await pythSolanaReceiver.fetchPriceUpdateAccount(pricePublicKey);

if (priceAccount !== null) {
  priceData = priceAccount.priceMessage.price;
}
      ```

@uno-Maas
Copy link

I'm starting to study programming on Solana and in your solution to the "parsePriceData" error, can you indicate where we should get or import "PythSolanaReceiver", "NodeWallet" and "RAND_KEYPAIR" from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants