Skip to content

Commit

Permalink
feat: enable accumulator_v2 on price creation (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
Riateche authored Aug 30, 2024
1 parent 256b575 commit e1457a8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
5 changes: 5 additions & 0 deletions program/rust/src/processor/add_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
crate::{
accounts::{
PriceAccount,
PriceAccountFlags,
ProductAccount,
PythAccount,
},
Expand Down Expand Up @@ -83,6 +84,10 @@ pub fn add_price(
price_data.next_price_account = product_data.first_price_account;
price_data.min_pub_ = PRICE_ACCOUNT_DEFAULT_MIN_PUB;
price_data.feed_index = reserve_new_price_feed_index(permissions_account)?;
price_data
.flags
.insert(PriceAccountFlags::ACCUMULATOR_V2 | PriceAccountFlags::MESSAGE_BUFFER_CLEARED);

product_data.first_price_account = *price_account.key;

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions program/rust/src/tests/test_full_publisher_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ async fn test_full_publisher_set() -> Result<(), Box<dyn std::error::Error>> {
.await
.unwrap();

assert_eq!(price_data.agg_.price_, 110);
assert_eq!(price_data.agg_.conf_, 20);
assert_eq!(price_data.agg_.price_, 0);
assert_eq!(price_data.agg_.conf_, 0);
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions program/rust/src/tests/test_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ async fn test_publish() {
assert_eq!(price_data.comp_[0].latest_.conf_, 0);
assert_eq!(price_data.comp_[0].latest_.status_, PC_STATUS_UNKNOWN);

assert_eq!(price_data.comp_[0].agg_.price_, 150);
assert_eq!(price_data.comp_[0].agg_.conf_, 7);
assert_eq!(price_data.comp_[0].agg_.status_, PC_STATUS_TRADING);
assert_eq!(price_data.comp_[0].agg_.price_, 0);
assert_eq!(price_data.comp_[0].agg_.conf_, 0);
assert_eq!(price_data.comp_[0].agg_.status_, PC_STATUS_UNKNOWN);
}
}
11 changes: 4 additions & 7 deletions program/rust/src/tests/test_publish_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn test_publish_batch() {
.get_account_data_as::<PriceAccount>(*price)
.await
.unwrap();
let quote = quotes.get(key).unwrap();
let _quote = quotes.get(key).unwrap();
let new_quote = new_quotes.get(key).unwrap();

assert_eq!(price_data.comp_[0].latest_.price_, new_quote.price);
Expand All @@ -125,11 +125,8 @@ async fn test_publish_batch() {
)
.unwrap()
);
assert_eq!(price_data.comp_[0].agg_.price_, quote.price);
assert_eq!(price_data.comp_[0].agg_.conf_, quote.confidence);
assert_eq!(
price_data.comp_[0].agg_.status_,
get_status_for_conf_price_ratio(quote.price, quote.confidence, quote.status).unwrap()
);
assert_eq!(price_data.comp_[0].agg_.price_, 0);
assert_eq!(price_data.comp_[0].agg_.conf_, 0);
assert_eq!(price_data.comp_[0].agg_.status_, PC_STATUS_UNKNOWN);
}
}

0 comments on commit e1457a8

Please sign in to comment.