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
Source§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(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§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
Source§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§impl PartialOrd for NormalizedPrice
impl PartialOrd for NormalizedPrice
Source§impl Serialize for NormalizedPrice
impl Serialize for NormalizedPrice
impl Copy for NormalizedPrice
impl Eq for NormalizedPrice
impl StructuralPartialEq for NormalizedPrice
Auto Trait Implementations§
impl Freeze for NormalizedPrice
impl RefUnwindSafe for NormalizedPrice
impl Send for NormalizedPrice
impl Sync for NormalizedPrice
impl Unpin for NormalizedPrice
impl UnwindSafe for NormalizedPrice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more