use crate::account::state::{Abstraction, PerpState, SpotState};
use crate::utils::Dec;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Dollars {
pub spot_total: Dec,
pub spot_available: Dec,
pub perp_withdrawable: Dec,
pub total: Dec,
pub available: Dec,
}
impl Dollars {
#[must_use]
pub fn new(abstraction: &Abstraction, spot: &SpotState, perp: &PerpState) -> Option<Dollars> {
let (spot_total, spot_available) = match spot.usdc() {
Some(usdc) => (usdc.total, usdc.available()?),
None => (Dec::ZERO, Dec::ZERO),
};
let perp_withdrawable = match abstraction.is_pooled() {
true => Dec::ZERO,
false => perp.withdrawable,
};
Some(Dollars {
spot_total,
spot_available,
perp_withdrawable,
total: spot_total.checked_add(perp_withdrawable)?,
available: spot_available.checked_add(perp_withdrawable)?,
})
}
}