Skip to main content

plasma_amm_state/
lib.rs

1use errors::PlasmaStateError;
2
3pub mod amm;
4pub mod errors;
5pub mod fixed;
6pub mod lp;
7
8pub type SlotWindow = u64;
9
10/// Private trait for safely downcasting between types
11pub(crate) trait Downcast<To> {
12    fn downcast(&self) -> Result<To, PlasmaStateError>;
13}
14
15impl Downcast<u64> for u128 {
16    fn downcast(&self) -> Result<u64, PlasmaStateError> {
17        if *self > u64::MAX as u128 {
18            Err(PlasmaStateError::Overflow)
19        } else {
20            Ok(*self as u64)
21        }
22    }
23}
24
25/// Private trait for upcasting a larger integer type
26pub(crate) trait Upcast<To> {
27    fn upcast(&self) -> To;
28}
29
30impl Upcast<u128> for u64 {
31    fn upcast(&self) -> u128 {
32        *self as u128
33    }
34}
35
36impl Upcast<u128> for u32 {
37    fn upcast(&self) -> u128 {
38        *self as u128
39    }
40}