mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-27 16:19:59 -07:00
general: snapshot
This commit is contained in:
@@ -2,14 +2,14 @@ use allocative::Allocative;
|
||||
|
||||
use crate::{
|
||||
states::{DurableStates, OneShotStates, PriceToValue, UnrealizedState},
|
||||
structs::{LiquiditySplitResult, Price, SplitByLiquidity, WAmount},
|
||||
structs::{Amount, LiquiditySplitResult, Price, SplitByLiquidity},
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Allocative)]
|
||||
pub struct AddressCohortDurableStates {
|
||||
pub address_count: usize,
|
||||
pub split_durable_states: SplitByLiquidity<DurableStates>,
|
||||
pub price_to_split_amount: PriceToValue<SplitByLiquidity<WAmount>>,
|
||||
pub price_to_split_amount: PriceToValue<SplitByLiquidity<Amount>>,
|
||||
}
|
||||
|
||||
const ONE_THIRD: f64 = 1.0 / 3.0;
|
||||
@@ -19,7 +19,7 @@ impl AddressCohortDurableStates {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn increment(
|
||||
&mut self,
|
||||
amount: WAmount,
|
||||
amount: Amount,
|
||||
utxo_count: usize,
|
||||
realized_cap: Price,
|
||||
mean_price_paid: Price,
|
||||
@@ -44,7 +44,7 @@ impl AddressCohortDurableStates {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn decrement(
|
||||
&mut self,
|
||||
amount: WAmount,
|
||||
amount: Amount,
|
||||
utxo_count: usize,
|
||||
realized_cap: Price,
|
||||
mean_price_paid: Price,
|
||||
@@ -69,7 +69,7 @@ impl AddressCohortDurableStates {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn _crement(
|
||||
&mut self,
|
||||
amount: WAmount,
|
||||
amount: Amount,
|
||||
utxo_count: usize,
|
||||
realized_cap: Price,
|
||||
mean_price_paid: Price,
|
||||
@@ -98,7 +98,7 @@ impl AddressCohortDurableStates {
|
||||
|
||||
let illiquid_amount = split_sat_amount_result.illiquid.trunc();
|
||||
let illiquid_amount_rest = split_sat_amount_result.illiquid - illiquid_amount;
|
||||
let mut illiquid_amount = WAmount::from_sat(illiquid_amount as u64);
|
||||
let mut illiquid_amount = Amount::from_sat(illiquid_amount as u64);
|
||||
let mut illiquid_utxo_count = split_utxo_count_result.illiquid.trunc() as usize;
|
||||
let illiquid_utxo_count_rest = split_utxo_count_result.illiquid.fract();
|
||||
let mut illiquid_realized_cap =
|
||||
@@ -107,7 +107,7 @@ impl AddressCohortDurableStates {
|
||||
|
||||
let liquid_amount = split_sat_amount_result.liquid.trunc();
|
||||
let liquid_amount_rest = split_sat_amount_result.liquid - liquid_amount;
|
||||
let mut liquid_amount = WAmount::from_sat(liquid_amount as u64);
|
||||
let mut liquid_amount = Amount::from_sat(liquid_amount as u64);
|
||||
let mut liquid_utxo_count = split_utxo_count_result.liquid.trunc() as usize;
|
||||
let liquid_utxo_count_rest = split_utxo_count_result.liquid.fract();
|
||||
let mut liquid_realized_cap =
|
||||
@@ -120,7 +120,7 @@ impl AddressCohortDurableStates {
|
||||
realized_cap - illiquid_realized_cap - liquid_realized_cap;
|
||||
|
||||
let amount_diff = amount - illiquid_amount - liquid_amount - highly_liquid_amount;
|
||||
if amount_diff > WAmount::ZERO {
|
||||
if amount_diff > Amount::ZERO {
|
||||
if illiquid_amount_rest >= ONE_THIRD && illiquid_amount_rest > liquid_amount_rest {
|
||||
illiquid_amount += amount_diff;
|
||||
} else if illiquid_amount_rest >= ONE_THIRD {
|
||||
@@ -337,7 +337,7 @@ impl AddressCohortDurableStates {
|
||||
);
|
||||
}
|
||||
|
||||
if split_amount.illiquid > WAmount::ZERO {
|
||||
if split_amount.illiquid > Amount::ZERO {
|
||||
one_shot_states_ref.illiquid.price_paid_state.iterate(
|
||||
price_paid,
|
||||
split_amount.illiquid,
|
||||
@@ -359,7 +359,7 @@ impl AddressCohortDurableStates {
|
||||
}
|
||||
}
|
||||
|
||||
if split_amount.liquid > WAmount::ZERO {
|
||||
if split_amount.liquid > Amount::ZERO {
|
||||
one_shot_states_ref.liquid.price_paid_state.iterate(
|
||||
price_paid,
|
||||
split_amount.liquid,
|
||||
@@ -381,7 +381,7 @@ impl AddressCohortDurableStates {
|
||||
}
|
||||
}
|
||||
|
||||
if split_amount.highly_liquid > WAmount::ZERO {
|
||||
if split_amount.highly_liquid > Amount::ZERO {
|
||||
one_shot_states_ref.highly_liquid.price_paid_state.iterate(
|
||||
price_paid,
|
||||
split_amount.highly_liquid,
|
||||
|
||||
@@ -2,7 +2,7 @@ use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use crate::{
|
||||
states::InputState,
|
||||
structs::{AddressRealizedData, LiquidityClassification, SplitByLiquidity, WAmount},
|
||||
structs::{AddressRealizedData, Amount, LiquidityClassification, SplitByLiquidity},
|
||||
};
|
||||
|
||||
use super::SplitByAddressCohort;
|
||||
@@ -27,17 +27,17 @@ impl AddressCohortsInputStates {
|
||||
|
||||
state.illiquid.iterate(
|
||||
split_count.illiquid,
|
||||
WAmount::from_sat(split_volume.illiquid.round() as u64),
|
||||
Amount::from_sat(split_volume.illiquid.round() as u64),
|
||||
);
|
||||
|
||||
state.liquid.iterate(
|
||||
split_count.liquid,
|
||||
WAmount::from_sat(split_volume.liquid.round() as u64),
|
||||
Amount::from_sat(split_volume.liquid.round() as u64),
|
||||
);
|
||||
|
||||
state.highly_liquid.iterate(
|
||||
split_count.highly_liquid,
|
||||
WAmount::from_sat(split_volume.highly_liquid.round() as u64),
|
||||
Amount::from_sat(split_volume.highly_liquid.round() as u64),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -2,7 +2,7 @@ use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use crate::{
|
||||
states::OutputState,
|
||||
structs::{AddressRealizedData, LiquidityClassification, SplitByLiquidity, WAmount},
|
||||
structs::{AddressRealizedData, Amount, LiquidityClassification, SplitByLiquidity},
|
||||
};
|
||||
|
||||
use super::SplitByAddressCohort;
|
||||
@@ -27,17 +27,17 @@ impl AddressCohortsOutputStates {
|
||||
|
||||
state.illiquid.iterate(
|
||||
split_count.illiquid,
|
||||
WAmount::from_sat(split_volume.illiquid.round() as u64),
|
||||
Amount::from_sat(split_volume.illiquid.round() as u64),
|
||||
);
|
||||
|
||||
state.liquid.iterate(
|
||||
split_count.liquid,
|
||||
WAmount::from_sat(split_volume.liquid.round() as u64),
|
||||
Amount::from_sat(split_volume.liquid.round() as u64),
|
||||
);
|
||||
|
||||
state.highly_liquid.iterate(
|
||||
split_count.highly_liquid,
|
||||
WAmount::from_sat(split_volume.highly_liquid.round() as u64),
|
||||
Amount::from_sat(split_volume.highly_liquid.round() as u64),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use allocative::Allocative;
|
||||
use color_eyre::eyre::eyre;
|
||||
|
||||
use crate::structs::{Price, WAmount};
|
||||
use crate::structs::{Amount, Price};
|
||||
|
||||
use super::{CapitalizationState, SupplyState, UTXOState};
|
||||
|
||||
@@ -15,11 +15,11 @@ pub struct DurableStates {
|
||||
impl DurableStates {
|
||||
pub fn increment(
|
||||
&mut self,
|
||||
amount: WAmount,
|
||||
amount: Amount,
|
||||
utxo_count: usize,
|
||||
realized_cap: Price,
|
||||
) -> color_eyre::Result<()> {
|
||||
if amount == WAmount::ZERO {
|
||||
if amount == Amount::ZERO {
|
||||
if utxo_count != 0 {
|
||||
dbg!(amount, utxo_count);
|
||||
return Err(eyre!("Shouldn't be possible"));
|
||||
@@ -35,11 +35,11 @@ impl DurableStates {
|
||||
|
||||
pub fn decrement(
|
||||
&mut self,
|
||||
amount: WAmount,
|
||||
amount: Amount,
|
||||
utxo_count: usize,
|
||||
realized_cap: Price,
|
||||
) -> color_eyre::Result<()> {
|
||||
if amount == WAmount::ZERO {
|
||||
if amount == Amount::ZERO {
|
||||
if utxo_count != 0 {
|
||||
dbg!(amount, utxo_count);
|
||||
unreachable!("Shouldn't be possible")
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use crate::structs::WAmount;
|
||||
use crate::structs::Amount;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct InputState {
|
||||
pub count: f64,
|
||||
pub volume: WAmount,
|
||||
pub volume: Amount,
|
||||
}
|
||||
|
||||
impl InputState {
|
||||
pub fn iterate(&mut self, count: f64, volume: WAmount) {
|
||||
pub fn iterate(&mut self, count: f64, volume: Amount) {
|
||||
self.count += count;
|
||||
self.volume += volume;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use crate::structs::WAmount;
|
||||
use crate::structs::Amount;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct OutputState {
|
||||
pub count: f64,
|
||||
pub volume: WAmount,
|
||||
pub volume: Amount,
|
||||
}
|
||||
|
||||
impl OutputState {
|
||||
pub fn iterate(&mut self, count: f64, volume: WAmount) {
|
||||
pub fn iterate(&mut self, count: f64, volume: Amount) {
|
||||
self.count += count;
|
||||
self.volume += volume;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::structs::{Price, WAmount};
|
||||
use crate::structs::{Amount, Price};
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct PricePaidState {
|
||||
@@ -22,11 +22,11 @@ pub struct PricePaidState {
|
||||
pub pp_90p: Option<Price>,
|
||||
pub pp_95p: Option<Price>,
|
||||
|
||||
pub processed_amount: WAmount,
|
||||
pub processed_amount: Amount,
|
||||
}
|
||||
|
||||
impl PricePaidState {
|
||||
pub fn iterate(&mut self, price: Price, amount: WAmount, total_supply: WAmount) {
|
||||
pub fn iterate(&mut self, price: Price, amount: Amount, total_supply: Amount) {
|
||||
let PricePaidState {
|
||||
processed_amount,
|
||||
pp_05p,
|
||||
|
||||
@@ -8,7 +8,7 @@ use allocative::Allocative;
|
||||
use color_eyre::eyre::eyre;
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
|
||||
use crate::structs::{Price, SplitByLiquidity, WAmount};
|
||||
use crate::structs::{Amount, Price, SplitByLiquidity};
|
||||
|
||||
#[derive(Deref, DerefMut, Default, Debug, Allocative)]
|
||||
pub struct PriceToValue<T>(BTreeMap<u32, T>);
|
||||
@@ -82,13 +82,13 @@ pub trait CanSubtract {
|
||||
fn can_subtract(&self, other: &Self) -> bool;
|
||||
}
|
||||
|
||||
impl CanSubtract for WAmount {
|
||||
impl CanSubtract for Amount {
|
||||
fn can_subtract(&self, other: &Self) -> bool {
|
||||
self >= other
|
||||
}
|
||||
}
|
||||
|
||||
impl CanSubtract for SplitByLiquidity<WAmount> {
|
||||
impl CanSubtract for SplitByLiquidity<Amount> {
|
||||
fn can_subtract(&self, other: &Self) -> bool {
|
||||
self.all >= other.all
|
||||
&& self.illiquid >= other.illiquid
|
||||
@@ -101,23 +101,23 @@ pub trait IsZero {
|
||||
fn is_zero(&self) -> color_eyre::Result<bool>;
|
||||
}
|
||||
|
||||
impl IsZero for WAmount {
|
||||
impl IsZero for Amount {
|
||||
fn is_zero(&self) -> color_eyre::Result<bool> {
|
||||
Ok(*self == WAmount::ZERO)
|
||||
Ok(*self == Amount::ZERO)
|
||||
}
|
||||
}
|
||||
|
||||
impl IsZero for SplitByLiquidity<WAmount> {
|
||||
impl IsZero for SplitByLiquidity<Amount> {
|
||||
fn is_zero(&self) -> color_eyre::Result<bool> {
|
||||
if self.all == WAmount::ZERO
|
||||
&& (self.illiquid != WAmount::ZERO
|
||||
|| self.liquid != WAmount::ZERO
|
||||
|| self.highly_liquid != WAmount::ZERO)
|
||||
if self.all == Amount::ZERO
|
||||
&& (self.illiquid != Amount::ZERO
|
||||
|| self.liquid != Amount::ZERO
|
||||
|| self.highly_liquid != Amount::ZERO)
|
||||
{
|
||||
dbg!(&self);
|
||||
Err(eyre!("Bad split"))
|
||||
} else {
|
||||
Ok(self.all == WAmount::ZERO)
|
||||
Ok(self.all == Amount::ZERO)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
use allocative::Allocative;
|
||||
use color_eyre::eyre::eyre;
|
||||
|
||||
use crate::structs::WAmount;
|
||||
use crate::structs::Amount;
|
||||
|
||||
#[derive(Debug, Default, Allocative)]
|
||||
pub struct SupplyState {
|
||||
pub supply: WAmount,
|
||||
pub supply: Amount,
|
||||
}
|
||||
|
||||
impl SupplyState {
|
||||
pub fn increment(&mut self, amount: WAmount) {
|
||||
pub fn increment(&mut self, amount: Amount) {
|
||||
self.supply += amount;
|
||||
}
|
||||
|
||||
pub fn decrement(&mut self, amount: WAmount) -> color_eyre::Result<()> {
|
||||
pub fn decrement(&mut self, amount: Amount) -> color_eyre::Result<()> {
|
||||
if self.supply < amount {
|
||||
dbg!(self.supply, amount);
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
use std::{cmp::Ordering, ops::Add};
|
||||
|
||||
use crate::structs::{Price, WAmount};
|
||||
use crate::structs::{Amount, Price};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct UnrealizedState {
|
||||
pub supply_in_profit: WAmount,
|
||||
pub supply_in_profit: Amount,
|
||||
pub unrealized_profit: Price,
|
||||
pub unrealized_loss: Price,
|
||||
}
|
||||
|
||||
impl UnrealizedState {
|
||||
#[inline]
|
||||
pub fn iterate(&mut self, price_then: Price, price_now: Price, amount: WAmount) {
|
||||
pub fn iterate(&mut self, price_then: Price, price_now: Price, amount: Amount) {
|
||||
match price_then.cmp(&price_now) {
|
||||
Ordering::Less => {
|
||||
self.unrealized_profit += (price_now - price_then) * amount;
|
||||
|
||||
@@ -2,19 +2,19 @@ use allocative::Allocative;
|
||||
|
||||
use crate::{
|
||||
states::{DurableStates, OneShotStates, PriceToValue, UnrealizedState},
|
||||
structs::{Price, WAmount},
|
||||
structs::{Amount, Price},
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, Allocative)]
|
||||
pub struct UTXOCohortDurableStates {
|
||||
pub durable_states: DurableStates,
|
||||
pub price_to_amount: PriceToValue<WAmount>,
|
||||
pub price_to_amount: PriceToValue<Amount>,
|
||||
}
|
||||
|
||||
impl UTXOCohortDurableStates {
|
||||
pub fn increment(
|
||||
&mut self,
|
||||
amount: WAmount,
|
||||
amount: Amount,
|
||||
utxo_count: usize,
|
||||
price: Price,
|
||||
) -> color_eyre::Result<()> {
|
||||
@@ -23,7 +23,7 @@ impl UTXOCohortDurableStates {
|
||||
|
||||
pub fn decrement(
|
||||
&mut self,
|
||||
amount: WAmount,
|
||||
amount: Amount,
|
||||
utxo_count: usize,
|
||||
price: Price,
|
||||
) -> color_eyre::Result<()> {
|
||||
@@ -32,7 +32,7 @@ impl UTXOCohortDurableStates {
|
||||
|
||||
pub fn _crement(
|
||||
&mut self,
|
||||
amount: WAmount,
|
||||
amount: Amount,
|
||||
utxo_count: usize,
|
||||
price: Price,
|
||||
increment: bool,
|
||||
|
||||
@@ -5,9 +5,9 @@ use rayon::prelude::*;
|
||||
|
||||
use crate::{
|
||||
states::DateDataVec,
|
||||
structs::{BlockData, Price, SentData, WAmount},
|
||||
structs::{Amount, BlockData, Price, SentData},
|
||||
utils::difference_in_days_between_timestamps,
|
||||
WNaiveDate,
|
||||
Date,
|
||||
};
|
||||
|
||||
use super::{SplitByUTXOCohort, UTXOCohortDurableStates, UTXOCohortsOneShotStates};
|
||||
@@ -33,7 +33,7 @@ impl UTXOCohortsDurableStates {
|
||||
let utxo_count = block_data.utxos as usize;
|
||||
|
||||
// No need to either insert or remove if 0
|
||||
if amount == WAmount::ZERO {
|
||||
if amount == Amount::ZERO {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,12 +65,12 @@ impl UTXOCohortsDurableStates {
|
||||
let price = block_data.price;
|
||||
|
||||
// No need to either insert or remove if 0
|
||||
if amount == WAmount::ZERO {
|
||||
if amount == Amount::ZERO {
|
||||
return;
|
||||
}
|
||||
|
||||
if block_data.height == last_block_data.height {
|
||||
let year = WNaiveDate::from_timestamp(block_data.timestamp).year() as u32;
|
||||
let year = Date::from_timestamp(block_data.timestamp).year() as u32;
|
||||
|
||||
self.initial_filtered_apply(&0, &year, |state| {
|
||||
state.increment(amount, utxo_count, price).unwrap();
|
||||
@@ -118,7 +118,7 @@ impl UTXOCohortsDurableStates {
|
||||
let utxo_count = sent_data.count as usize;
|
||||
|
||||
// No need to either insert or remove if 0
|
||||
if amount == WAmount::ZERO {
|
||||
if amount == Amount::ZERO {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ impl UTXOCohortsDurableStates {
|
||||
previous_last_block_data.timestamp,
|
||||
);
|
||||
|
||||
let year = WNaiveDate::from_timestamp(block_data.timestamp).year() as u32;
|
||||
let year = Date::from_timestamp(block_data.timestamp).year() as u32;
|
||||
|
||||
self.initial_filtered_apply(&days_old, &year, |state| {
|
||||
state
|
||||
|
||||
Reference in New Issue
Block a user