[solana-receiver] Initialize receiver from CLI (#1191)
* Initialize * Update address * cleanup
This commit is contained in:
parent
0a86414523
commit
4aa60453bd
|
@ -44,4 +44,12 @@ pub enum Action {
|
||||||
about = "Initialize a wormhole receiver contract by sequentially replaying the guardian set updates"
|
about = "Initialize a wormhole receiver contract by sequentially replaying the guardian set updates"
|
||||||
)]
|
)]
|
||||||
InitializeWormholeReceiver {},
|
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,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
|
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
use {
|
use {
|
||||||
anchor_client::anchor_lang::{
|
anchor_client::anchor_lang::{
|
||||||
|
@ -13,6 +14,7 @@ use {
|
||||||
Action,
|
Action,
|
||||||
Cli,
|
Cli,
|
||||||
},
|
},
|
||||||
|
pyth_solana_receiver::state::config::DataSource,
|
||||||
pythnet_sdk::wire::v1::{
|
pythnet_sdk::wire::v1::{
|
||||||
AccumulatorUpdateData,
|
AccumulatorUpdateData,
|
||||||
MerklePriceUpdate,
|
MerklePriceUpdate,
|
||||||
|
@ -125,8 +127,40 @@ fn main() -> Result<()> {
|
||||||
false,
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
use state::config::Config;
|
use {
|
||||||
|
anchor_lang::system_program,
|
||||||
|
state::config::Config,
|
||||||
|
};
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
@ -26,7 +29,7 @@ use {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
declare_id!("DvPfMBZJJwKgJsv2WJA8bFwUMn8nFd5Xpioc6foC3rse");
|
declare_id!("rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ");
|
||||||
|
|
||||||
#[program]
|
#[program]
|
||||||
pub mod pyth_solana_receiver {
|
pub mod pyth_solana_receiver {
|
||||||
|
@ -207,6 +210,16 @@ pub struct PostUpdates<'info> {
|
||||||
pub posted_vaa: UncheckedAccount<'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 {
|
impl crate::accounts::PostUpdates {
|
||||||
pub fn populate(payer: &Pubkey, posted_vaa: &Pubkey) -> Self {
|
pub fn populate(payer: &Pubkey, posted_vaa: &Pubkey) -> Self {
|
||||||
|
|
Loading…
Reference in New Issue