0

I'm trying to use pyth SDK make a program to fetch a price, then using a typescript client to pass the id of the price feed I want to the program. My rust lib.rs is essentially this:

pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8]
) -> ProgramResult {
    let account_iter = &mut accounts.iter();
    let price_account_info = next_account_info(account_iter)?;
    msg!("Account key: {}", price_account_info.key.to_string());
    let price_feed: PriceFeed = load_price_feed_from_account_info(&price_account_info).unwrap();
    Ok(())
}

of course I should then use the price feed to actually get the data, but I've limited my code unto the line where I believe the issue lie (and removed here the imports for readability). This has been build and deployed correctly on the devnet.

In typescript (also removing parts for readability) I do this:

const programKeypair = Keypair.fromSecretKey(programSecretKey);
const programPublicKey = programKeypair.publicKey;
const SOLUSDString = 'J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'; // SOL/USD price feed id
const SOLUSDpublicKey = new PublicKey(SOLUSDString);

const transaction = new Transaction();
transaction.add(
  new TransactionInstruction({
    keys: [{pubkey: SOLUSDpublicKey, isSigner: false, isWritable: false}],
    programId: programPublicKey
  }),
);

const payerKeypair = Keypair.fromSecretKey(payerSecretKey);
const connection = new Connection('https://api.devnet.solana.com', 'confirmed');

const txHash = await sendAndConfirmTransaction(
  connection,
  transaction,
  [payerKeypair],
);

I get the following error message:

'Program 4CkxyEHCCr4MTvfyWjc49CyK6mZnsz8FgTUHrJMk4AsA invoke [1]', 'Program log: Account key: J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix', "Program log: panicked at 'called Result::unwrap() on an Err value: InvalidAccountData', src/lib.rs:31:88", 'Program 4CkxyEHCCr4MTvfyWjc49CyK6mZnsz8FgTUHrJMk4AsA consumed 14281 of 200000 compute units', 'Program 4CkxyEHCCr4MTvfyWjc49CyK6mZnsz8FgTUHrJMk4AsA failed: SBF program panicked'

notice that lib.rs:31 is indeed the call to load_price_feed_from_account_info(). So, it seems to me that the price id enters my program but somehow the related price account isn't accepted by the function. I think it could be something I specified incorrectly in the "keys" argument of new TransactionInstruction. I've tried to set isWritable to true but the error persists.

Thank you for reading; hope someone can help me.

2
  • It's unfortunately not possible to tell just from this info. load_price_feed_from_account_info is having an issue deserializing the account you've provided, but the address appears correct on devnet. In that case, there might be a problem with load_price_feed_from_account_info
    – Jon C
    Commented Feb 26 at 20:34
  • thank you for your reply; I think indeed the problem is that I'm not serializing anything at all
    – NDXP
    Commented Feb 28 at 19:03

1 Answer 1

0

I made everything again using anchor and it worked. I believe the problem was the lack of serialization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.