Skip to content

Commit ecf3479

Browse files
authored
chore(solana): use instruction builders (#1415)
1 parent 5afb187 commit ecf3479

File tree

1 file changed

+16
-50
lines changed
  • target_chains/solana/cli/src

1 file changed

+16
-50
lines changed

target_chains/solana/cli/src/main.rs

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ use {
1515
Action,
1616
Cli,
1717
},
18-
pyth_solana_receiver::{
19-
sdk::{
20-
deserialize_accumulator_update_data,
21-
get_treasury_address,
22-
DEFAULT_TREASURY_ID,
23-
},
24-
PostUpdateAtomicParams,
25-
PostUpdateParams,
18+
pyth_solana_receiver::sdk::{
19+
deserialize_accumulator_update_data,
20+
get_treasury_address,
21+
DEFAULT_TREASURY_ID,
2622
},
2723
pyth_solana_receiver_sdk::config::DataSource,
2824
pythnet_sdk::wire::v1::MerklePriceUpdate,
@@ -177,24 +173,18 @@ fn main() -> Result<()> {
177173
let payer =
178174
read_keypair_file(&*shellexpand::tilde(&keypair)).expect("Keypair not found");
179175

180-
let initialize_pyth_receiver_accounts =
181-
pyth_solana_receiver::accounts::Initialize::populate(&payer.pubkey())
182-
.to_account_metas(None);
183-
let initialize_pyth_receiver_instruction = Instruction {
184-
program_id: pyth_solana_receiver::ID,
185-
accounts: initialize_pyth_receiver_accounts,
186-
data: pyth_solana_receiver::instruction::Initialize {
187-
initial_config: pyth_solana_receiver_sdk::config::Config {
176+
let initialize_pyth_receiver_instruction =
177+
pyth_solana_receiver::instruction::Initialize::populate(
178+
&payer.pubkey(),
179+
pyth_solana_receiver_sdk::config::Config {
188180
governance_authority: payer.pubkey(),
189181
target_governance_authority: None,
190182
wormhole,
191183
valid_data_sources: vec![DataSource { chain, emitter }],
192184
single_update_fee_in_lamports: fee,
193185
minimum_signatures: 5,
194186
},
195-
}
196-
.data(),
197-
};
187+
);
198188

199189
// We need to send some rent to the treasury account, otherwise it won't be able to accept incoming transfers
200190
let pay_treasury_rent = system_instruction::transfer(
@@ -262,29 +252,16 @@ pub fn process_post_price_update_atomic(
262252
let request_compute_units_instruction: Instruction =
263253
ComputeBudgetInstruction::set_compute_unit_limit(400_000);
264254

265-
266-
let post_update_accounts = pyth_solana_receiver::accounts::PostUpdateAtomic::populate(
255+
let post_update_instruction = pyth_solana_receiver::instruction::PostUpdateAtomic::populate(
267256
payer.pubkey(),
268257
payer.pubkey(),
269258
price_update_keypair.pubkey(),
270259
*wormhole,
271260
header.guardian_set_index,
261+
serde_wormhole::to_vec(&(header, body)).unwrap(),
262+
merkle_price_update.clone(),
272263
DEFAULT_TREASURY_ID,
273-
)
274-
.to_account_metas(None);
275-
276-
let post_update_instruction = Instruction {
277-
program_id: pyth_solana_receiver::id(),
278-
accounts: post_update_accounts,
279-
data: pyth_solana_receiver::instruction::PostUpdateAtomic {
280-
params: PostUpdateAtomicParams {
281-
merkle_price_update: merkle_price_update.clone(),
282-
vaa: serde_wormhole::to_vec(&(header, body)).unwrap(),
283-
treasury_id: DEFAULT_TREASURY_ID,
284-
},
285-
}
286-
.data(),
287-
};
264+
);
288265

289266
process_transaction(
290267
rpc_client,
@@ -472,24 +449,13 @@ pub fn process_write_encoded_vaa_and_post_price_update(
472449

473450
let price_update_keypair = Keypair::new();
474451

475-
let post_update_accounts = pyth_solana_receiver::accounts::PostUpdate::populate(
452+
let post_update_instructions = pyth_solana_receiver::instruction::PostUpdate::populate(
476453
payer.pubkey(),
477454
payer.pubkey(),
478455
encoded_vaa_keypair.pubkey(),
479456
price_update_keypair.pubkey(),
480-
)
481-
.to_account_metas(None);
482-
let post_update_instructions = Instruction {
483-
program_id: pyth_solana_receiver::id(),
484-
accounts: post_update_accounts,
485-
data: pyth_solana_receiver::instruction::PostUpdate {
486-
params: PostUpdateParams {
487-
merkle_price_update: merkle_price_update.clone(),
488-
treasury_id: DEFAULT_TREASURY_ID,
489-
},
490-
}
491-
.data(),
492-
};
457+
merkle_price_update.clone(),
458+
);
493459

494460
// 2nd transaction
495461
process_transaction(

0 commit comments

Comments
 (0)