@@ -10,16 +10,12 @@ use bytemuck::{
1010use solana_program:: account_info:: AccountInfo ;
1111use solana_program:: clock:: Clock ;
1212use solana_program:: entrypoint:: ProgramResult ;
13- use solana_program:: program:: invoke;
1413use solana_program:: program_error:: ProgramError ;
1514use solana_program:: program_memory:: {
1615 sol_memcpy,
1716 sol_memset,
1817} ;
1918use solana_program:: pubkey:: Pubkey ;
20- use solana_program:: rent:: Rent ;
21- use solana_program:: system_instruction:: transfer;
22- use solana_program:: system_program:: check_id;
2319use solana_program:: sysvar:: Sysvar ;
2420
2521use crate :: c_oracle_header:: {
@@ -44,16 +40,13 @@ use crate::c_oracle_header::{
4440 PC_PROD_ACC_SIZE ,
4541 PC_PTYPE_UNKNOWN ,
4642 PC_STATUS_UNKNOWN ,
47- PC_VERSION ,
4843} ;
4944use crate :: deserialize:: {
5045 initialize_pyth_account_checked, /* TODO: This has a confusingly similar name to a Solana
5146 * sdk function */
5247 load,
53- load_account_as_mut,
5448 load_checked,
5549} ;
56- use crate :: time_machine_types:: PriceAccountWrapper ;
5750use crate :: utils:: {
5851 check_exponent_range,
5952 check_valid_fresh_account,
@@ -69,11 +62,6 @@ use crate::utils::{
6962 read_pc_str_t,
7063 try_convert,
7164} ;
72- use crate :: OracleError ;
73-
74- const PRICE_T_SIZE : usize = size_of :: < pc_price_t > ( ) ;
75- const PRICE_ACCOUNT_SIZE : usize = size_of :: < PriceAccountWrapper > ( ) ;
76-
7765
7866#[ cfg( target_arch = "bpf" ) ]
7967#[ link( name = "cpyth-bpf" ) ]
@@ -87,79 +75,6 @@ extern "C" {
8775 pub fn c_upd_aggregate ( _input : * mut u8 , clock_slot : u64 , clock_timestamp : i64 ) -> bool ;
8876}
8977
90- fn send_lamports < ' a > (
91- from : & AccountInfo < ' a > ,
92- to : & AccountInfo < ' a > ,
93- system_program : & AccountInfo < ' a > ,
94- amount : u64 ,
95- ) -> Result < ( ) , ProgramError > {
96- let transfer_instruction = transfer ( from. key , to. key , amount) ;
97- invoke (
98- & transfer_instruction,
99- & [ from. clone ( ) , to. clone ( ) , system_program. clone ( ) ] ,
100- ) ?;
101- Ok ( ( ) )
102- }
103-
104- /// resizes a price account so that it fits the Time Machine
105- /// key[0] funding account [signer writable]
106- /// key[1] price account [Signer writable]
107- /// key[2] system program [readable]
108- pub fn resize_price_account (
109- program_id : & Pubkey ,
110- accounts : & [ AccountInfo ] ,
111- _instruction_data : & [ u8 ] ,
112- ) -> ProgramResult {
113- let [ funding_account_info, price_account_info, system_program] = match accounts {
114- [ x, y, z] => Ok ( [ x, y, z] ) ,
115- _ => Err ( ProgramError :: InvalidArgument ) ,
116- } ?;
117-
118- check_valid_funding_account ( funding_account_info) ?;
119- check_valid_signable_account ( program_id, price_account_info, size_of :: < pc_price_t > ( ) ) ?;
120- pyth_assert (
121- check_id ( system_program. key ) ,
122- OracleError :: InvalidSystemAccount . into ( ) ,
123- ) ?;
124- //throw an error if not a price account
125- //need to makre sure it goes out of scope immediatly to avoid mutable borrow errors
126- {
127- load_checked :: < pc_price_t > ( price_account_info, PC_VERSION ) ?;
128- }
129- let account_len = price_account_info. try_data_len ( ) ?;
130- match account_len {
131- PRICE_T_SIZE => {
132- //ensure account is still rent exempt after resizing
133- let rent: Rent = Default :: default ( ) ;
134- let lamports_needed: u64 = rent
135- . minimum_balance ( size_of :: < PriceAccountWrapper > ( ) )
136- . saturating_sub ( price_account_info. lamports ( ) ) ;
137- if lamports_needed > 0 {
138- send_lamports (
139- funding_account_info,
140- price_account_info,
141- system_program,
142- lamports_needed,
143- ) ?;
144- }
145- //resize
146- //we do not need to zero initialize since this is the first time this memory
147- //is allocated
148- price_account_info. realloc ( size_of :: < PriceAccountWrapper > ( ) , false ) ?;
149- //The load below would fail if the account was not a price account, reverting the whole
150- // transaction
151- let mut price_account =
152- load_checked :: < PriceAccountWrapper > ( price_account_info, PC_VERSION ) ?;
153- //Initialize Time Machine
154- price_account. initialize_time_machine ( ) ?;
155- Ok ( ( ) )
156- }
157- PRICE_ACCOUNT_SIZE => Ok ( ( ) ) ,
158- _ => Err ( ProgramError :: InvalidArgument ) ,
159- }
160- }
161-
162-
16378/// initialize the first mapping account in a new linked-list of mapping accounts
16479/// accounts[0] funding account [signer writable]
16580/// accounts[1] new mapping account [signer writable]
@@ -272,23 +187,16 @@ pub fn upd_price(
272187 }
273188
274189 // Try to update the aggregate
275- let mut aggregate_updated = false ;
276190 if clock. slot > latest_aggregate_price. pub_slot_ {
277191 unsafe {
278- aggregate_updated = c_upd_aggregate (
192+ let _aggregate_updated = c_upd_aggregate (
279193 price_account. try_borrow_mut_data ( ) ?. as_mut_ptr ( ) ,
280194 clock. slot ,
281195 clock. unix_timestamp ,
282196 ) ;
283197 }
284198 }
285199
286- let account_len = price_account. try_data_len ( ) ?;
287- if aggregate_updated && account_len == PRICE_ACCOUNT_SIZE {
288- let mut price_account = load_account_as_mut :: < PriceAccountWrapper > ( price_account) ?;
289- price_account. add_price_to_time_machine ( ) ?;
290- }
291-
292200 // Try to update the publisher's price
293201 if is_component_update ( cmd_args) ? {
294202 let mut status: u32 = cmd_args. status_ ;
@@ -463,7 +371,7 @@ pub fn init_price(
463371 0 ,
464372 size_of :: < pc_price_info_t > ( ) ,
465373 ) ;
466- for i in 0 ..( price_data. comp_ . len ( ) as usize ) {
374+ for i in 0 ..price_data. comp_ . len ( ) {
467375 sol_memset (
468376 bytes_of_mut ( & mut price_data. comp_ [ i] . agg_ ) ,
469377 0 ,
0 commit comments