[solana-receiver] Initialize receiver from CLI (#1191)

* Initialize

* Update address

* cleanup
This commit is contained in:
guibescos 2023-12-18 11:08:08 +07:00 committed by GitHub
parent 0a86414523
commit 4aa60453bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 3 deletions

View File

@ -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,
},
}

View File

@ -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(())
}

View File

@ -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 {