Skip to content

Commit

Permalink
Default value of 20 for min pub (#327)
Browse files Browse the repository at this point in the history
* Update contract and tests

* Add constant
  • Loading branch information
guibescos committed Dec 27, 2022
1 parent 265b262 commit c263c61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions program/rust/src/c_oracle_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pub const MAX_CI_DIVISOR: i64 = 3;
/// Bound on the range of the exponent in price accounts. This number is set such that the
/// PD-based EMA computation does not lose too much precision.
pub const MAX_NUM_DECIMALS: i32 = 8;
pub const PRICE_ACCOUNT_DEFAULT_MIN_PUB: u8 = 20;
6 changes: 5 additions & 1 deletion program/rust/src/processor/add_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use {
ProductAccount,
PythAccount,
},
c_oracle_header::PC_PTYPE_UNKNOWN,
c_oracle_header::{
PC_PTYPE_UNKNOWN,
PRICE_ACCOUNT_DEFAULT_MIN_PUB,
},
deserialize::{
load,
load_checked,
Expand Down Expand Up @@ -76,6 +79,7 @@ pub fn add_price(
price_data.price_type = cmd_args.price_type;
price_data.product_account = *product_account.key;
price_data.next_price_account = product_data.first_price_account;
price_data.min_pub_ = PRICE_ACCOUNT_DEFAULT_MIN_PUB;
product_data.first_price_account = *price_account.key;

Ok(())
Expand Down
7 changes: 6 additions & 1 deletion program/rust/src/tests/test_add_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use {
ProductAccount,
PythAccount,
},
c_oracle_header::PC_VERSION,
c_oracle_header::{
PC_VERSION,
PRICE_ACCOUNT_DEFAULT_MIN_PUB,
},
deserialize::load_checked,
error::OracleError,
instruction::{
Expand Down Expand Up @@ -82,6 +85,7 @@ fn test_add_price() {
let product_data = load_checked::<ProductAccount>(&product_account, PC_VERSION).unwrap();
assert_eq!(price_data.exponent, 1);
assert_eq!(price_data.price_type, 1);
assert_eq!(price_data.min_pub_, PRICE_ACCOUNT_DEFAULT_MIN_PUB);
assert!(price_data.product_account == *product_account.key);
assert!(price_data.next_price_account == Pubkey::default());
assert!(product_data.first_price_account == *price_account.key);
Expand All @@ -103,6 +107,7 @@ fn test_add_price() {
let product_data = load_checked::<ProductAccount>(&product_account, PC_VERSION).unwrap();
assert_eq!(price_data_2.exponent, 1);
assert_eq!(price_data_2.price_type, 1);
assert_eq!(price_data_2.min_pub_, PRICE_ACCOUNT_DEFAULT_MIN_PUB);
assert!(price_data_2.product_account == *product_account.key);
assert!(price_data_2.next_price_account == *price_account.key);
assert!(product_data.first_price_account == *price_account_2.key);
Expand Down

0 comments on commit c263c61

Please sign in to comment.