From 4aa60453bd5a7a28ac4c52aa54d35e396e01bcb5 Mon Sep 17 00:00:00 2001 From: guibescos <59208140+guibescos@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:08:08 +0700 Subject: [PATCH] [solana-receiver] Initialize receiver from CLI (#1191) * Initialize * Update address * cleanup --- target_chains/solana/cli/src/cli.rs | 8 +++++ target_chains/solana/cli/src/main.rs | 36 ++++++++++++++++++- .../programs/pyth-solana-receiver/src/lib.rs | 17 +++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/target_chains/solana/cli/src/cli.rs b/target_chains/solana/cli/src/cli.rs index 5f44c02d..2b2230f3 100644 --- a/target_chains/solana/cli/src/cli.rs +++ b/target_chains/solana/cli/src/cli.rs @@ -44,4 +44,12 @@ pub enum Action { about = "Initialize a wormhole receiver contract by sequentially replaying the guardian set updates" )] InitializeWormholeReceiver {}, + InitializePythReceiver { + #[clap(short = 'f', long, help = "Fee in lmaports")] + fee: u64, + #[clap(short = 'e', long, parse(try_from_str = Pubkey::from_str), help = "Source emitter")] + emitter: Pubkey, + #[clap(short = 'c', long, help = "Source chain")] + chain: u16, + }, } diff --git a/target_chains/solana/cli/src/main.rs b/target_chains/solana/cli/src/main.rs index 4d264972..d92806f9 100644 --- a/target_chains/solana/cli/src/main.rs +++ b/target_chains/solana/cli/src/main.rs @@ -1,5 +1,6 @@ #![deny(warnings)] + pub mod cli; use { anchor_client::anchor_lang::{ @@ -13,6 +14,7 @@ use { Action, Cli, }, + pyth_solana_receiver::state::config::DataSource, pythnet_sdk::wire::v1::{ AccumulatorUpdateData, MerklePriceUpdate, @@ -125,8 +127,40 @@ fn main() -> Result<()> { false, )?; } - } + Action::InitializePythReceiver { + fee, + emitter, + chain, + } => { + let rpc_client = RpcClient::new(url); + let payer = + read_keypair_file(&*shellexpand::tilde(&keypair)).expect("Keypair not found"); + let initialize_pyth_receiver_accounts = + pyth_solana_receiver::accounts::Initialize::populate(&payer.pubkey()) + .to_account_metas(None); + let initialize_pyth_receiver_instruction = Instruction { + program_id: pyth_solana_receiver::ID, + accounts: initialize_pyth_receiver_accounts, + data: pyth_solana_receiver::instruction::Initialize { + initial_config: pyth_solana_receiver::state::config::Config { + governance_authority: payer.pubkey(), + target_governance_authority: None, + wormhole, + valid_data_sources: vec![DataSource { chain, emitter }], + single_update_fee_in_lamports: fee, + }, + } + .data(), + }; + + process_transaction( + &rpc_client, + vec![initialize_pyth_receiver_instruction], + &vec![&payer], + )?; + } + } Ok(()) } diff --git a/target_chains/solana/programs/pyth-solana-receiver/src/lib.rs b/target_chains/solana/programs/pyth-solana-receiver/src/lib.rs index d0428a13..5f03664b 100644 --- a/target_chains/solana/programs/pyth-solana-receiver/src/lib.rs +++ b/target_chains/solana/programs/pyth-solana-receiver/src/lib.rs @@ -1,4 +1,7 @@ -use state::config::Config; +use { + anchor_lang::system_program, + state::config::Config, +}; pub mod error; pub mod state; @@ -26,7 +29,7 @@ use { }, }; -declare_id!("DvPfMBZJJwKgJsv2WJA8bFwUMn8nFd5Xpioc6foC3rse"); +declare_id!("rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ"); #[program] pub mod pyth_solana_receiver { @@ -207,6 +210,16 @@ pub struct PostUpdates<'info> { pub posted_vaa: UncheckedAccount<'info>, } +impl crate::accounts::Initialize { + pub fn populate(payer: &Pubkey) -> Self { + let config = Pubkey::find_program_address(&[CONFIG_SEED.as_ref()], &crate::ID).0; + crate::accounts::Initialize { + payer: *payer, + config, + system_program: system_program::ID, + } + } +} impl crate::accounts::PostUpdates { pub fn populate(payer: &Pubkey, posted_vaa: &Pubkey) -> Self {