diff --git a/crates/brk_computer/src/states/cohorts/address.rs b/crates/brk_computer/src/states/cohorts/address.rs index fd1a2f3fb..41e5a3749 100644 --- a/crates/brk_computer/src/states/cohorts/address.rs +++ b/crates/brk_computer/src/states/cohorts/address.rs @@ -98,14 +98,20 @@ impl AddressCohortState { pub fn add(&mut self, addressdata: &AddressData) { self.address_count += 1; - self.inner - .increment_(&addressdata.into(), addressdata.realized_cap); + self.inner.increment_( + &addressdata.into(), + addressdata.realized_cap, + addressdata.realized_price(), + ); } pub fn subtract(&mut self, addressdata: &AddressData) { self.address_count = self.address_count.checked_sub(1).unwrap(); - self.inner - .decrement_(&addressdata.into(), addressdata.realized_cap); + self.inner.decrement_( + &addressdata.into(), + addressdata.realized_cap, + addressdata.realized_price(), + ); } pub fn commit(&mut self, height: Height) -> Result<()> { diff --git a/crates/brk_computer/src/states/cohorts/common.rs b/crates/brk_computer/src/states/cohorts/common.rs index 7d2fe4cca..ec63241d6 100644 --- a/crates/brk_computer/src/states/cohorts/common.rs +++ b/crates/brk_computer/src/states/cohorts/common.rs @@ -1,6 +1,6 @@ use std::{cmp::Ordering, path::Path}; -use brk_core::{Bitcoin, CheckedSub, Dollars, Height, Result, Sats}; +use brk_core::{CheckedSub, Dollars, Height, Result, Sats}; use crate::{PriceToAmount, RealizedState, SupplyState, UnrealizedState}; @@ -61,16 +61,18 @@ impl CohortState { } } - pub fn increment_(&mut self, supply_state: &SupplyState, realized_cap: Dollars) { + pub fn increment_( + &mut self, + supply_state: &SupplyState, + realized_cap: Dollars, + realized_price: Dollars, + ) { self.supply += supply_state; if supply_state.value > Sats::ZERO { if let Some(realized) = self.realized.as_mut() { realized.increment_(realized_cap); - self.price_to_amount.increment( - realized_cap / Bitcoin::from(supply_state.value), - supply_state, - ); + self.price_to_amount.increment(realized_price, supply_state); } } } @@ -87,16 +89,18 @@ impl CohortState { } } - pub fn decrement_(&mut self, supply_state: &SupplyState, realized_cap: Dollars) { + pub fn decrement_( + &mut self, + supply_state: &SupplyState, + realized_cap: Dollars, + realized_price: Dollars, + ) { self.supply -= supply_state; if supply_state.value > Sats::ZERO { if let Some(realized) = self.realized.as_mut() { realized.decrement_(realized_cap); - self.price_to_amount.decrement( - (realized_cap / Bitcoin::from(supply_state.value)).round_nearest_cent(), - supply_state, - ); + self.price_to_amount.decrement(realized_price, supply_state); } } } diff --git a/crates/brk_computer/src/vecs/stateful/mod.rs b/crates/brk_computer/src/vecs/stateful/mod.rs index 612308d09..894aae99f 100644 --- a/crates/brk_computer/src/vecs/stateful/mod.rs +++ b/crates/brk_computer/src/vecs/stateful/mod.rs @@ -38,7 +38,7 @@ pub use addresstype_to_typeindex_vec::*; use r#trait::CohortVecs; pub use withaddressdatasource::WithAddressDataSource; -const VERSION: Version = Version::new(9); +const VERSION: Version = Version::new(11); #[derive(Clone)] pub struct Vecs { diff --git a/crates/brk_core/src/structs/sats.rs b/crates/brk_core/src/structs/sats.rs index 7fd1f0afc..724c55324 100644 --- a/crates/brk_core/src/structs/sats.rs +++ b/crates/brk_core/src/structs/sats.rs @@ -95,6 +95,10 @@ impl CheckedSub for Sats { impl SubAssign for Sats { fn sub_assign(&mut self, rhs: Self) { *self = self.checked_sub(rhs).unwrap(); + // .unwrap_or_else(|| { + // dbg!((*self, rhs)); + // unreachable!(); + // }); } }