-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathtest_upd_price.rs
559 lines (514 loc) · 21.8 KB
/
test_upd_price.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
use {
crate::{
accounts::{
PriceAccount,
PythAccount,
},
c_oracle_header::{
PC_STATUS_IGNORED,
PC_STATUS_TRADING,
PC_STATUS_UNKNOWN,
PC_VERSION,
},
deserialize::{
load_checked,
load_mut,
},
instruction::{
OracleCommand,
UpdPriceArgs,
},
processor::process_instruction,
tests::test_utils::{
update_clock_slot,
update_clock_timestamp,
AccountSetup,
},
},
solana_program::{
program_error::ProgramError,
pubkey::Pubkey,
},
solana_sdk::account_info::AccountInfo,
std::mem::size_of,
};
#[test]
fn test_upd_price() {
let mut instruction_data = [0u8; size_of::<UpdPriceArgs>()];
populate_instruction(&mut instruction_data, 42, 2, 1);
let program_id = Pubkey::new_unique();
let mut funding_setup = AccountSetup::new_funding();
let funding_account = funding_setup.as_account_info();
let mut price_setup = AccountSetup::new::<PriceAccount>(&program_id);
let mut price_account = price_setup.as_account_info();
price_account.is_signer = false;
PriceAccount::initialize(&price_account, PC_VERSION).unwrap();
{
let mut price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
price_data.num_ = 1;
price_data.comp_[0].pub_ = *funding_account.key;
}
let mut clock_setup = AccountSetup::new_clock();
let mut clock_account = clock_setup.as_account_info();
clock_account.is_signer = false;
clock_account.is_writable = false;
update_clock_slot(&mut clock_account, 1);
update_clock_timestamp(&mut clock_account, 1);
assert!(process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 42);
assert_eq!(price_data.comp_[0].latest_.conf_, 2);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 1);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 0);
assert_eq!(price_data.last_slot_, 1);
assert_eq!(price_data.agg_.pub_slot_, 1);
assert_eq!(price_data.agg_.price_, 42);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 0);
assert_eq!(price_data.prev_price_, 0);
assert_eq!(price_data.prev_conf_, 0);
assert_eq!(price_data.prev_timestamp_, 0);
assert_eq!(price_data.price_cumulative.price, 42);
assert_eq!(price_data.price_cumulative.conf, 2);
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
// add some prices for current slot - get rejected
populate_instruction(&mut instruction_data, 43, 2, 1);
assert_eq!(
process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
),
Err(ProgramError::InvalidArgument)
);
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 42);
assert_eq!(price_data.comp_[0].latest_.conf_, 2);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 1);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 0);
assert_eq!(price_data.last_slot_, 1);
assert_eq!(price_data.agg_.pub_slot_, 1);
assert_eq!(price_data.agg_.price_, 42);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 0);
assert_eq!(price_data.prev_price_, 0);
assert_eq!(price_data.prev_conf_, 0);
assert_eq!(price_data.prev_timestamp_, 0);
assert_eq!(price_data.price_cumulative.price, 42);
assert_eq!(price_data.price_cumulative.conf, 2);
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
// update new price in new slot, aggregate should be updated and prev values should be updated
populate_instruction(&mut instruction_data, 81, 2, 2);
update_clock_slot(&mut clock_account, 3);
assert!(process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 81);
assert_eq!(price_data.comp_[0].latest_.conf_, 2);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 2);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 1);
assert_eq!(price_data.last_slot_, 3);
assert_eq!(price_data.agg_.pub_slot_, 3);
assert_eq!(price_data.agg_.price_, 81);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 1);
assert_eq!(price_data.prev_price_, 42);
assert_eq!(price_data.prev_conf_, 2);
assert_eq!(price_data.prev_timestamp_, 1);
assert_eq!(price_data.price_cumulative.price, 42 + 2 * 81);
assert_eq!(price_data.price_cumulative.conf, 3 * 2);
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
// next price doesn't change but slot and timestamp does
populate_instruction(&mut instruction_data, 81, 2, 3);
update_clock_slot(&mut clock_account, 4);
update_clock_timestamp(&mut clock_account, 4);
assert!(process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 81);
assert_eq!(price_data.comp_[0].latest_.conf_, 2);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 3);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 3);
assert_eq!(price_data.last_slot_, 4);
assert_eq!(price_data.agg_.pub_slot_, 4);
assert_eq!(price_data.agg_.price_, 81);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 3);
assert_eq!(price_data.prev_price_, 81);
assert_eq!(price_data.prev_conf_, 2);
assert_eq!(price_data.timestamp_, 4); // We only check for timestamp_ here because test_upd_price doesn't directly update timestamp_, this is updated through c_upd_aggregate which is tested in test_upd_aggregate, but we assert here to show that in subsequent asserts for prev_timestamp_ the value should be updated to this value
assert_eq!(price_data.prev_timestamp_, 1);
assert_eq!(price_data.price_cumulative.price, 42 + 3 * 81);
assert_eq!(price_data.price_cumulative.conf, 4 * 2);
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
// next price doesn't change and neither does aggregate but slot does
populate_instruction(&mut instruction_data, 81, 2, 4);
update_clock_slot(&mut clock_account, 5);
assert!(process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 81);
assert_eq!(price_data.comp_[0].latest_.conf_, 2);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 4);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 4);
assert_eq!(price_data.last_slot_, 5);
assert_eq!(price_data.agg_.pub_slot_, 5);
assert_eq!(price_data.agg_.price_, 81);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 4);
assert_eq!(price_data.prev_price_, 81);
assert_eq!(price_data.prev_conf_, 2);
assert_eq!(price_data.prev_timestamp_, 4);
assert_eq!(price_data.price_cumulative.price, 42 + 81 * 4);
assert_eq!(price_data.price_cumulative.conf, 5 * 2);
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
// try to publish back-in-time
populate_instruction(&mut instruction_data, 81, 2, 1);
update_clock_slot(&mut clock_account, 5);
assert_eq!(
process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
),
Err(ProgramError::InvalidArgument)
);
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 81);
assert_eq!(price_data.comp_[0].latest_.conf_, 2);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 4);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 4);
assert_eq!(price_data.last_slot_, 5);
assert_eq!(price_data.agg_.pub_slot_, 5);
assert_eq!(price_data.agg_.price_, 81);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 4);
assert_eq!(price_data.prev_price_, 81);
assert_eq!(price_data.prev_conf_, 2);
assert_eq!(price_data.prev_timestamp_, 4);
assert_eq!(price_data.price_cumulative.price, 42 + 81 * 4);
assert_eq!(price_data.price_cumulative.conf, 5 * 2);
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
populate_instruction(&mut instruction_data, 50, 20, 5);
update_clock_slot(&mut clock_account, 6);
// Publishing a wide CI results in a status of unknown.
// check that someone doesn't accidentally break the test.
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
}
assert!(process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 50);
assert_eq!(price_data.comp_[0].latest_.conf_, 20);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 5);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_IGNORED);
assert_eq!(price_data.valid_slot_, 5);
assert_eq!(price_data.last_slot_, 5);
assert_eq!(price_data.agg_.pub_slot_, 6);
assert_eq!(price_data.agg_.price_, 81);
assert_eq!(price_data.agg_.status_, PC_STATUS_UNKNOWN);
assert_eq!(price_data.prev_slot_, 5);
assert_eq!(price_data.prev_price_, 81);
assert_eq!(price_data.prev_conf_, 2);
assert_eq!(price_data.prev_timestamp_, 4);
assert_eq!(price_data.price_cumulative.price, 42 + 81 * 4);
assert_eq!(price_data.price_cumulative.conf, 2 * 5);
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
// Negative prices are accepted
populate_instruction(&mut instruction_data, -100, 1, 7);
update_clock_slot(&mut clock_account, 8);
assert!(process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, -100);
assert_eq!(price_data.comp_[0].latest_.conf_, 1);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 7);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 6);
assert_eq!(price_data.last_slot_, 8);
assert_eq!(price_data.agg_.pub_slot_, 8);
assert_eq!(price_data.agg_.price_, -100);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 5);
assert_eq!(price_data.prev_price_, 81);
assert_eq!(price_data.prev_conf_, 2);
assert_eq!(price_data.prev_timestamp_, 4);
assert_eq!(price_data.price_cumulative.price, 42 + 81 * 4 - 100 * 3);
assert_eq!(price_data.price_cumulative.conf, 2 * 5 + 3); // 2 * 5 + 1 * 3
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
// add new test for multiple publishers and ensure that agg price is not updated multiple times when program upgrade happens in the same slot after the first update
let mut funding_setup_two = AccountSetup::new_funding();
let funding_account_two = funding_setup_two.as_account_info();
add_publisher(&mut price_account, funding_account_two.key);
populate_instruction(&mut instruction_data, 10, 1, 10);
update_clock_slot(&mut clock_account, 10);
assert!(process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 10);
assert_eq!(price_data.comp_[0].latest_.conf_, 1);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 10);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 8);
assert_eq!(price_data.last_slot_, 10);
assert_eq!(price_data.agg_.pub_slot_, 10);
assert_eq!(price_data.agg_.price_, 10);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 8);
assert_eq!(price_data.prev_price_, -100);
assert_eq!(price_data.prev_conf_, 1);
assert_eq!(price_data.prev_timestamp_, 4);
assert_eq!(price_data.twap_.numer_, 1677311098);
assert_eq!(price_data.twap_.denom_, 1279419481);
assert_eq!(
price_data.price_cumulative.price,
42 + 81 * 4 - 100 * 3 + 10 * 2
);
assert_eq!(price_data.price_cumulative.conf, 2 * 5 + 5); // 2 * 5 + 1 * 5
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
// reset twap_.denom_ to 0 to simulate program upgrade in the same slot and make sure agg_.price_ is not updated again
{
let mut price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
price_data.prev_twap_.denom_ = 0;
}
populate_instruction(&mut instruction_data, 20, 1, 10);
assert!(process_instruction(
&program_id,
&[
funding_account_two.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[1].latest_.price_, 20);
assert_eq!(price_data.comp_[1].latest_.conf_, 1);
assert_eq!(price_data.comp_[1].latest_.pub_slot_, 10);
assert_eq!(price_data.comp_[1].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 8);
assert_eq!(price_data.last_slot_, 10);
assert_eq!(price_data.agg_.pub_slot_, 10);
assert_eq!(price_data.agg_.price_, 10);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 8);
assert_eq!(price_data.prev_price_, -100);
assert_eq!(price_data.prev_conf_, 1);
assert_eq!(price_data.prev_timestamp_, 4);
assert_eq!(price_data.twap_.numer_, 1677311098); // twap_.numer_ should not be updated
assert_eq!(price_data.twap_.denom_, 1279419481); // twap_.denom_ should not be updated
// price_cumulative should not be updated
assert_eq!(
price_data.price_cumulative.price,
42 + 81 * 4 - 100 * 3 + 10 * 2
);
assert_eq!(price_data.price_cumulative.conf, 2 * 5 + 5);
assert_eq!(price_data.price_cumulative.num_down_slots, 0);
}
remove_publisher(&mut price_account);
// Big gap
populate_instruction(&mut instruction_data, 60, 4, 50);
update_clock_slot(&mut clock_account, 50);
assert!(process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 60);
assert_eq!(price_data.comp_[0].latest_.conf_, 4);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 50);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 10);
assert_eq!(price_data.agg_.pub_slot_, 50);
assert_eq!(price_data.agg_.price_, 60);
assert_eq!(price_data.agg_.conf_, 4);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(
price_data.price_cumulative.price,
42 + 81 * 4 - 100 * 3 + 10 * 2 + 60 * 40
);
assert_eq!(price_data.price_cumulative.conf, 2 * 5 + 5 + 40 * 4);
assert_eq!(price_data.price_cumulative.num_down_slots, 15);
}
// add new test for multiple publishers and ensure that price_cumulative is updated correctly
add_publisher(&mut price_account, funding_account_two.key);
populate_instruction(&mut instruction_data, 10, 1, 100);
update_clock_slot(&mut clock_account, 100);
assert!(process_instruction(
&program_id,
&[
funding_account.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
populate_instruction(&mut instruction_data, 20, 2, 100);
assert!(process_instruction(
&program_id,
&[
funding_account_two.clone(),
price_account.clone(),
clock_account.clone()
],
&instruction_data
)
.is_ok());
{
let price_data = load_checked::<PriceAccount>(&price_account, PC_VERSION).unwrap();
assert_eq!(price_data.comp_[0].latest_.price_, 10);
assert_eq!(price_data.comp_[0].latest_.conf_, 1);
assert_eq!(price_data.comp_[0].latest_.pub_slot_, 100);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.comp_[1].latest_.price_, 20);
assert_eq!(price_data.comp_[1].latest_.conf_, 2);
assert_eq!(price_data.comp_[1].latest_.pub_slot_, 100);
assert_eq!(price_data.comp_[1].latest_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.valid_slot_, 100);
assert_eq!(price_data.agg_.pub_slot_, 100);
assert_eq!(price_data.agg_.price_, 14);
assert_eq!(price_data.agg_.conf_, 6);
assert_eq!(price_data.agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.prev_slot_, 50);
assert_eq!(price_data.prev_price_, 60);
assert_eq!(price_data.prev_conf_, 4);
assert_eq!(
price_data.prev_price_cumulative.price,
42 + 81 * 4 - 100 * 3 + 10 * 2 + 60 * 40
);
assert_eq!(price_data.prev_price_cumulative.conf, 2 * 5 + 5 + 40 * 4);
assert_eq!(price_data.prev_price_cumulative.num_down_slots, 15);
assert_eq!(
price_data.price_cumulative.price,
42 + 81 * 4 - 100 * 3 + 10 * 2 + 60 * 40 + 14 * 50
); // (42 + 81 * 4 - 100 * 3 + 10 * 2 + 60 * 40 + 55) is the price cumulative from the previous test and 14 * 49 (slot_gap) is the price cumulative from this test
assert_eq!(
price_data.price_cumulative.conf,
2 * 5 + 5 + 40 * 4 + 6 * 50
);
assert_eq!(price_data.price_cumulative.num_down_slots, 40); // prev num_down_slots was 15 and since pub slot is 100 and last pub slot was 50, slot_gap is 50 and default latency is 25, so num_down_slots = 50 - 25 = 25, so total num_down_slots = 15 + 25 = 40
}
}
// Create an upd_price instruction with the provided parameters
fn populate_instruction(instruction_data: &mut [u8], price: i64, conf: u64, pub_slot: u64) {
let mut cmd = load_mut::<UpdPriceArgs>(instruction_data).unwrap();
cmd.header = OracleCommand::UpdPrice.into();
cmd.status = PC_STATUS_TRADING;
cmd.price = price;
cmd.confidence = conf;
cmd.publishing_slot = pub_slot;
cmd.unused_ = 0;
}
fn add_publisher(price_account: &mut AccountInfo, publisher_key: &Pubkey) {
let mut price_data = load_checked::<PriceAccount>(price_account, PC_VERSION).unwrap();
let index = price_data.num_ as usize;
price_data.comp_[index].pub_ = *publisher_key;
price_data.num_ += 1;
}
fn remove_publisher(price_account: &mut AccountInfo) {
let mut price_data = load_checked::<PriceAccount>(price_account, PC_VERSION).unwrap();
if price_data.num_ > 0 {
price_data.num_ -= 1;
}
}