@@ -10,16 +10,12 @@ use bytemuck::{
10
10
use solana_program:: account_info:: AccountInfo ;
11
11
use solana_program:: clock:: Clock ;
12
12
use solana_program:: entrypoint:: ProgramResult ;
13
- use solana_program:: program:: invoke;
14
13
use solana_program:: program_error:: ProgramError ;
15
14
use solana_program:: program_memory:: {
16
15
sol_memcpy,
17
16
sol_memset,
18
17
} ;
19
18
use 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;
23
19
use solana_program:: sysvar:: Sysvar ;
24
20
25
21
use crate :: c_oracle_header:: {
@@ -44,16 +40,13 @@ use crate::c_oracle_header::{
44
40
PC_PROD_ACC_SIZE ,
45
41
PC_PTYPE_UNKNOWN ,
46
42
PC_STATUS_UNKNOWN ,
47
- PC_VERSION ,
48
43
} ;
49
44
use crate :: deserialize:: {
50
45
initialize_pyth_account_checked, /* TODO: This has a confusingly similar name to a Solana
51
46
* sdk function */
52
47
load,
53
- load_account_as_mut,
54
48
load_checked,
55
49
} ;
56
- use crate :: time_machine_types:: PriceAccountWrapper ;
57
50
use crate :: utils:: {
58
51
check_exponent_range,
59
52
check_valid_fresh_account,
@@ -69,11 +62,6 @@ use crate::utils::{
69
62
read_pc_str_t,
70
63
try_convert,
71
64
} ;
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
-
77
65
78
66
#[ cfg( target_arch = "bpf" ) ]
79
67
#[ link( name = "cpyth-bpf" ) ]
@@ -87,79 +75,6 @@ extern "C" {
87
75
pub fn c_upd_aggregate ( _input : * mut u8 , clock_slot : u64 , clock_timestamp : i64 ) -> bool ;
88
76
}
89
77
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
-
163
78
/// initialize the first mapping account in a new linked-list of mapping accounts
164
79
/// accounts[0] funding account [signer writable]
165
80
/// accounts[1] new mapping account [signer writable]
@@ -272,23 +187,16 @@ pub fn upd_price(
272
187
}
273
188
274
189
// Try to update the aggregate
275
- let mut aggregate_updated = false ;
276
190
if clock. slot > latest_aggregate_price. pub_slot_ {
277
191
unsafe {
278
- aggregate_updated = c_upd_aggregate (
192
+ let _aggregate_updated = c_upd_aggregate (
279
193
price_account. try_borrow_mut_data ( ) ?. as_mut_ptr ( ) ,
280
194
clock. slot ,
281
195
clock. unix_timestamp ,
282
196
) ;
283
197
}
284
198
}
285
199
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
-
292
200
// Try to update the publisher's price
293
201
if is_component_update ( cmd_args) ? {
294
202
let mut status: u32 = cmd_args. status_ ;
@@ -463,7 +371,7 @@ pub fn init_price(
463
371
0 ,
464
372
size_of :: < pc_price_info_t > ( ) ,
465
373
) ;
466
- for i in 0 ..( price_data. comp_ . len ( ) as usize ) {
374
+ for i in 0 ..price_data. comp_ . len ( ) {
467
375
sol_memset (
468
376
bytes_of_mut ( & mut price_data. comp_ [ i] . agg_ ) ,
469
377
0 ,
0 commit comments