Struct kujira_std::NormalizedPrice
source · pub struct NormalizedPrice(/* private fields */);Expand description
NormalizedPrice should be used in all operations involving
calculating the value of coins given the oracle price.
When comparing values of non-standard denominations, failing
to normalize the price can cause unexpected and incorrect results.
Standard denominations have 6 decimal places, so we use that as the reference point.
Implementations§
source§impl NormalizedPrice
impl NormalizedPrice
sourcepub fn unsafe_unchecked(price: Decimal) -> Self
pub fn unsafe_unchecked(price: Decimal) -> Self
This is unsafe because it does not check that the price is normalized to the reference decimal places. Most likely during testing.
pub fn from_raw(price: Decimal, decimals: u8) -> Self
pub fn from_delta(price: Decimal, delta: i16) -> Self
pub fn from_oracle<T: Into<String>>( querier: &KujiraQuerier<'_>, denom: T, decimals: u8 ) -> StdResult<Self>
pub fn inner(&self) -> Decimal
Methods from Deref<Target = Decimal>§
pub const DECIMAL_PLACES: u32 = 18u32
pub const MAX: Decimal = _
pub const MIN: Decimal = _
pub fn is_zero(&self) -> bool
sourcepub fn atomics(&self) -> Uint128
pub fn atomics(&self) -> Uint128
A decimal is an integer of atomic units plus a number that specifies the position of the decimal dot. So any decimal can be expressed as two numbers.
§Examples
// Value with whole and fractional part
let a = Decimal::from_str("1.234").unwrap();
assert_eq!(a.decimal_places(), 18);
assert_eq!(a.atomics(), Uint128::new(1234000000000000000));
// Smallest possible value
let b = Decimal::from_str("0.000000000000000001").unwrap();
assert_eq!(b.decimal_places(), 18);
assert_eq!(b.atomics(), Uint128::new(1));sourcepub fn decimal_places(&self) -> u32
pub fn decimal_places(&self) -> u32
The number of decimal places. This is a constant value for now but this could potentially change as the type evolves.
See also Decimal::atomics().
sourcepub fn checked_ceil(&self) -> Result<Decimal, RoundUpOverflowError>
pub fn checked_ceil(&self) -> Result<Decimal, RoundUpOverflowError>
Rounds value up after decimal places. Returns OverflowError on overflow.
Trait Implementations§
source§impl Clone for NormalizedPrice
impl Clone for NormalizedPrice
source§fn clone(&self) -> NormalizedPrice
fn clone(&self) -> NormalizedPrice
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for NormalizedPrice
impl Debug for NormalizedPrice
source§impl Deref for NormalizedPrice
impl Deref for NormalizedPrice
source§impl<'de> Deserialize<'de> for NormalizedPrice
impl<'de> Deserialize<'de> for NormalizedPrice
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Div<NormalizedPrice> for Uint128
impl Div<NormalizedPrice> for Uint128
source§impl Div<Uint128> for NormalizedPrice
impl Div<Uint128> for NormalizedPrice
source§impl Div for NormalizedPrice
impl Div for NormalizedPrice
§type Output = NormalizedPrice
type Output = NormalizedPrice
/ operator.source§impl DivAssign for NormalizedPrice
impl DivAssign for NormalizedPrice
source§fn div_assign(&mut self, rhs: NormalizedPrice)
fn div_assign(&mut self, rhs: NormalizedPrice)
/= operation. Read moresource§impl From<NormalizedPrice> for Decimal
impl From<NormalizedPrice> for Decimal
source§fn from(price: NormalizedPrice) -> Self
fn from(price: NormalizedPrice) -> Self
source§impl JsonSchema for NormalizedPrice
impl JsonSchema for NormalizedPrice
source§fn schema_name() -> String
fn schema_name() -> String
source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref keyword. Read moresource§impl Mul<NormalizedPrice> for Uint128
impl Mul<NormalizedPrice> for Uint128
source§impl Mul<Uint128> for NormalizedPrice
impl Mul<Uint128> for NormalizedPrice
source§impl Mul for NormalizedPrice
impl Mul for NormalizedPrice
§type Output = NormalizedPrice
type Output = NormalizedPrice
* operator.source§impl MulAssign<NormalizedPrice> for Uint128
impl MulAssign<NormalizedPrice> for Uint128
source§fn mul_assign(&mut self, rhs: NormalizedPrice)
fn mul_assign(&mut self, rhs: NormalizedPrice)
*= operation. Read moresource§impl MulAssign for NormalizedPrice
impl MulAssign for NormalizedPrice
source§fn mul_assign(&mut self, rhs: NormalizedPrice)
fn mul_assign(&mut self, rhs: NormalizedPrice)
*= operation. Read moresource§impl Ord for NormalizedPrice
impl Ord for NormalizedPrice
source§fn cmp(&self, other: &NormalizedPrice) -> Ordering
fn cmp(&self, other: &NormalizedPrice) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for NormalizedPrice
impl PartialEq for NormalizedPrice
source§fn eq(&self, other: &NormalizedPrice) -> bool
fn eq(&self, other: &NormalizedPrice) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd for NormalizedPrice
impl PartialOrd for NormalizedPrice
source§fn partial_cmp(&self, other: &NormalizedPrice) -> Option<Ordering>
fn partial_cmp(&self, other: &NormalizedPrice) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl Serialize for NormalizedPrice
impl Serialize for NormalizedPrice
impl Copy for NormalizedPrice
impl Eq for NormalizedPrice
impl StructuralPartialEq for NormalizedPrice
Auto Trait Implementations§
impl RefUnwindSafe for NormalizedPrice
impl Send for NormalizedPrice
impl Sync for NormalizedPrice
impl Unpin for NormalizedPrice
impl UnwindSafe for NormalizedPrice
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more