Skip to content

feat(lazer): update solana example #38

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

Merged
merged 1 commit into from
Dec 11, 2024
Merged

Conversation

Riateche
Copy link
Contributor

The example contract now calls the Pyth Lazer contract using the CPI.

Copy link
Contributor

@darunrs darunrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truth be told, I'm not really familiar with what is going on here. Mainly, I see we working with new accounts. Is this related to the addition of fees to verification?

@@ -49,6 +52,14 @@ fn main() -> anyhow::Result<()> {
let signature = client.send_and_confirm_transaction(&tx)?;
println!("OK {signature:?}");
} else if cmd == "update" {
let state_data = client.get_account_data(&data_pda_key)?;
let state = from_bytes::<State>(&state_data);
println!("state: {state:?}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kinds of things are in state that we would want to print it out? I wonder if we can migrate to using tracing crate for logging to change visibility of some of these print statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can look at the state to figure out which price feed this contract instance wants to receive and what is the timestamp of the latest applied update (the contract will only allow updates with a greater timestamp).

I think println is fine for an example. I'd like it to be as easy to understand as possible, and tracing/log can be confusing if unfamiliar.

Comment on lines +173 to +177
let _pyth_program_account = &accounts[2];
let pyth_storage_account = &accounts[3];
let pyth_treasury_account = &accounts[4];
let system_program_account = &accounts[5];
let instructions_sysvar_account = &accounts[6];
Copy link
Contributor

@darunrs darunrs Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do all these accounts do? Are they actually different accounts entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Program accounts are required to allow the contract to call them. This contract calls the pyth contract (_pyth_program_account ) which calls the system program (system_program_account) to make the fee transfer. pyth_storage_account and pyth_treasury_account are accounts that have to be accessed by the pyth contract. instructions_sysvar_account is a special account that allows programs to inspect other instructions within the current transaction, which is needed to validate the signature.

Copy link
Contributor

@ali-behjati ali-behjati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@Riateche Riateche merged commit 08f56e0 into main Dec 11, 2024
4 checks passed
@Riateche Riateche deleted the lazer-update-solana-example branch December 11, 2024 11:18
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

Successfully merging this pull request may close these issues.

3 participants