|
1 | 1 | #![deny(warnings)]
|
2 | 2 |
|
3 |
| - |
4 | 3 | pub mod cli;
|
| 4 | + |
| 5 | + |
5 | 6 | use {
|
6 | 7 | anchor_client::anchor_lang::{
|
7 | 8 | InstructionData,
|
|
14 | 15 | Action,
|
15 | 16 | Cli,
|
16 | 17 | },
|
17 |
| - pyth_solana_receiver::state::config::DataSource, |
| 18 | + pyth_solana_receiver::{ |
| 19 | + state::config::DataSource, |
| 20 | + PostUpdatesAtomicParams, |
| 21 | + }, |
18 | 22 | pythnet_sdk::wire::v1::{
|
19 | 23 | AccumulatorUpdateData,
|
20 | 24 | MerklePriceUpdate,
|
@@ -102,6 +106,25 @@ fn main() -> Result<()> {
|
102 | 106 | &merkle_price_updates[0],
|
103 | 107 | )?;
|
104 | 108 | }
|
| 109 | + Action::PostPriceUpdateAtomic { |
| 110 | + payload, |
| 111 | + n_signatures, |
| 112 | + } => { |
| 113 | + let rpc_client = RpcClient::new(url); |
| 114 | + let payer = |
| 115 | + read_keypair_file(&*shellexpand::tilde(&keypair)).expect("Keypair not found"); |
| 116 | + |
| 117 | + let (vaa, merkle_price_updates) = deserialize_accumulator_update_data(&payload)?; |
| 118 | + |
| 119 | + process_post_price_update_atomic( |
| 120 | + &rpc_client, |
| 121 | + &vaa, |
| 122 | + n_signatures, |
| 123 | + &wormhole, |
| 124 | + &payer, |
| 125 | + &merkle_price_updates[0], |
| 126 | + )?; |
| 127 | + } |
105 | 128 |
|
106 | 129 | Action::InitializeWormholeReceiver {} => {
|
107 | 130 | let rpc_client = RpcClient::new(url);
|
@@ -140,6 +163,7 @@ fn main() -> Result<()> {
|
140 | 163 | false,
|
141 | 164 | )?;
|
142 | 165 | }
|
| 166 | + |
143 | 167 | Action::InitializePythReceiver {
|
144 | 168 | fee,
|
145 | 169 | emitter,
|
@@ -221,6 +245,55 @@ pub fn process_upgrade_guardian_set(
|
221 | 245 | Ok(())
|
222 | 246 | }
|
223 | 247 |
|
| 248 | +pub fn process_post_price_update_atomic( |
| 249 | + rpc_client: &RpcClient, |
| 250 | + vaa: &[u8], |
| 251 | + n_signatures: usize, |
| 252 | + wormhole: &Pubkey, |
| 253 | + payer: &Keypair, |
| 254 | + merkle_price_update: &MerklePriceUpdate, |
| 255 | +) -> Result<Pubkey> { |
| 256 | + let price_update_keypair = Keypair::new(); |
| 257 | + |
| 258 | + let (mut header, body): (Header, Body<&RawMessage>) = serde_wormhole::from_slice(vaa).unwrap(); |
| 259 | + trim_signatures(&mut header, n_signatures); |
| 260 | + |
| 261 | + let request_compute_units_instruction: Instruction = |
| 262 | + ComputeBudgetInstruction::set_compute_unit_limit(400_000); |
| 263 | + |
| 264 | + |
| 265 | + let post_update_accounts = pyth_solana_receiver::accounts::PostUpdatesAtomic::populate( |
| 266 | + payer.pubkey(), |
| 267 | + price_update_keypair.pubkey(), |
| 268 | + *wormhole, |
| 269 | + header.guardian_set_index, |
| 270 | + ) |
| 271 | + .to_account_metas(None); |
| 272 | + |
| 273 | + let post_update_instruction = Instruction { |
| 274 | + program_id: pyth_solana_receiver::id(), |
| 275 | + accounts: post_update_accounts, |
| 276 | + data: pyth_solana_receiver::instruction::PostUpdatesAtomic { |
| 277 | + params: PostUpdatesAtomicParams { |
| 278 | + merkle_price_update: merkle_price_update.clone(), |
| 279 | + vaa: serde_wormhole::to_vec(&(header, body)).unwrap(), |
| 280 | + }, |
| 281 | + } |
| 282 | + .data(), |
| 283 | + }; |
| 284 | + |
| 285 | + process_transaction( |
| 286 | + rpc_client, |
| 287 | + vec![request_compute_units_instruction, post_update_instruction], |
| 288 | + &vec![payer, &price_update_keypair], |
| 289 | + )?; |
| 290 | + Ok(price_update_keypair.pubkey()) |
| 291 | +} |
| 292 | + |
| 293 | +fn trim_signatures(header: &mut Header, n_signatures: usize) { |
| 294 | + header.signatures = header.signatures[..(n_signatures)].to_vec(); |
| 295 | +} |
| 296 | + |
224 | 297 | fn deserialize_guardian_set(buf: &mut &[u8], legacy_guardian_set: bool) -> Result<GuardianSet> {
|
225 | 298 | if !legacy_guardian_set {
|
226 | 299 | // Skip anchor discriminator
|
|
0 commit comments