Skip to content

Commit 4aa6045

Browse files
authored
[solana-receiver] Initialize receiver from CLI (#1191)
* Initialize * Update address * cleanup
1 parent 0a86414 commit 4aa6045

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

target_chains/solana/cli/src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ pub enum Action {
4444
about = "Initialize a wormhole receiver contract by sequentially replaying the guardian set updates"
4545
)]
4646
InitializeWormholeReceiver {},
47+
InitializePythReceiver {
48+
#[clap(short = 'f', long, help = "Fee in lmaports")]
49+
fee: u64,
50+
#[clap(short = 'e', long, parse(try_from_str = Pubkey::from_str), help = "Source emitter")]
51+
emitter: Pubkey,
52+
#[clap(short = 'c', long, help = "Source chain")]
53+
chain: u16,
54+
},
4755
}

target_chains/solana/cli/src/main.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![deny(warnings)]
22

3+
34
pub mod cli;
45
use {
56
anchor_client::anchor_lang::{
@@ -13,6 +14,7 @@ use {
1314
Action,
1415
Cli,
1516
},
17+
pyth_solana_receiver::state::config::DataSource,
1618
pythnet_sdk::wire::v1::{
1719
AccumulatorUpdateData,
1820
MerklePriceUpdate,
@@ -125,8 +127,40 @@ fn main() -> Result<()> {
125127
false,
126128
)?;
127129
}
128-
}
130+
Action::InitializePythReceiver {
131+
fee,
132+
emitter,
133+
chain,
134+
} => {
135+
let rpc_client = RpcClient::new(url);
136+
let payer =
137+
read_keypair_file(&*shellexpand::tilde(&keypair)).expect("Keypair not found");
129138

139+
let initialize_pyth_receiver_accounts =
140+
pyth_solana_receiver::accounts::Initialize::populate(&payer.pubkey())
141+
.to_account_metas(None);
142+
let initialize_pyth_receiver_instruction = Instruction {
143+
program_id: pyth_solana_receiver::ID,
144+
accounts: initialize_pyth_receiver_accounts,
145+
data: pyth_solana_receiver::instruction::Initialize {
146+
initial_config: pyth_solana_receiver::state::config::Config {
147+
governance_authority: payer.pubkey(),
148+
target_governance_authority: None,
149+
wormhole,
150+
valid_data_sources: vec![DataSource { chain, emitter }],
151+
single_update_fee_in_lamports: fee,
152+
},
153+
}
154+
.data(),
155+
};
156+
157+
process_transaction(
158+
&rpc_client,
159+
vec![initialize_pyth_receiver_instruction],
160+
&vec![&payer],
161+
)?;
162+
}
163+
}
130164
Ok(())
131165
}
132166

target_chains/solana/programs/pyth-solana-receiver/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use state::config::Config;
1+
use {
2+
anchor_lang::system_program,
3+
state::config::Config,
4+
};
25

36
pub mod error;
47
pub mod state;
@@ -26,7 +29,7 @@ use {
2629
},
2730
};
2831

29-
declare_id!("DvPfMBZJJwKgJsv2WJA8bFwUMn8nFd5Xpioc6foC3rse");
32+
declare_id!("rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ");
3033

3134
#[program]
3235
pub mod pyth_solana_receiver {
@@ -207,6 +210,16 @@ pub struct PostUpdates<'info> {
207210
pub posted_vaa: UncheckedAccount<'info>,
208211
}
209212

213+
impl crate::accounts::Initialize {
214+
pub fn populate(payer: &Pubkey) -> Self {
215+
let config = Pubkey::find_program_address(&[CONFIG_SEED.as_ref()], &crate::ID).0;
216+
crate::accounts::Initialize {
217+
payer: *payer,
218+
config,
219+
system_program: system_program::ID,
220+
}
221+
}
222+
}
210223

211224
impl crate::accounts::PostUpdates {
212225
pub fn populate(payer: &Pubkey, posted_vaa: &Pubkey) -> Self {

0 commit comments

Comments
 (0)