pub struct NormalizedPrice(_);
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

source

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.

source

pub fn from_raw(price: Decimal, decimals: u8) -> Self

source

pub fn from_delta(price: Decimal, delta: i16) -> Self

source

pub fn from_oracle<T: Into<String>>( querier: &KujiraQuerier<'_>, denom: T, decimals: u8 ) -> StdResult<Self>

source

pub fn inner(&self) -> Decimal

Methods from Deref<Target = Decimal>§

source

pub const DECIMAL_PLACES: u32 = 18u32

source

pub const MAX: Decimal = Self(Uint128::MAX)

source

pub const MIN: Decimal = Self(Uint128::MIN)

source

pub fn is_zero(&self) -> bool

source

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));
source

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().

source

pub fn floor(&self) -> Decimal

Rounds value down after decimal places.

source

pub fn ceil(&self) -> Decimal

Rounds value up after decimal places. Panics on overflow.

source

pub fn checked_ceil(&self) -> Result<Decimal, RoundUpOverflowError>

Rounds value up after decimal places. Returns OverflowError on overflow.

source

pub fn sqrt(&self) -> Decimal

Returns the approximate square root as a Decimal.

This should not overflow or panic.

Trait Implementations§

source§

impl Clone for NormalizedPrice

source§

fn clone(&self) -> NormalizedPrice

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for NormalizedPrice

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for NormalizedPrice

§

type Target = Decimal

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'de> Deserialize<'de> for NormalizedPrice

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Div<NormalizedPrice> for NormalizedPrice

§

type Output = NormalizedPrice

The resulting type after applying the / operator.
source§

fn div(self, rhs: NormalizedPrice) -> Self::Output

Performs the / operation. Read more
source§

impl Div<NormalizedPrice> for Uint128

§

type Output = Option<Uint128>

The resulting type after applying the / operator.
source§

fn div(self, rhs: NormalizedPrice) -> Self::Output

Performs the / operation. Read more
source§

impl Div<Uint128> for NormalizedPrice

§

type Output = Option<Uint128>

The resulting type after applying the / operator.
source§

fn div(self, rhs: Uint128) -> Self::Output

Performs the / operation. Read more
source§

impl DivAssign<NormalizedPrice> for NormalizedPrice

source§

fn div_assign(&mut self, rhs: NormalizedPrice)

Performs the /= operation. Read more
source§

impl From<NormalizedPrice> for Decimal

source§

fn from(price: NormalizedPrice) -> Self

Converts to this type from the input type.
source§

impl JsonSchema for NormalizedPrice

source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
source§

fn json_schema(gen: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
source§

impl Mul<NormalizedPrice> for NormalizedPrice

§

type Output = NormalizedPrice

The resulting type after applying the * operator.
source§

fn mul(self, rhs: NormalizedPrice) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<NormalizedPrice> for Uint128

§

type Output = Uint128

The resulting type after applying the * operator.
source§

fn mul(self, rhs: NormalizedPrice) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Uint128> for NormalizedPrice

§

type Output = Uint128

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Uint128) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign<NormalizedPrice> for NormalizedPrice

source§

fn mul_assign(&mut self, rhs: NormalizedPrice)

Performs the *= operation. Read more
source§

impl MulAssign<NormalizedPrice> for Uint128

source§

fn mul_assign(&mut self, rhs: NormalizedPrice)

Performs the *= operation. Read more
source§

impl Ord for NormalizedPrice

source§

fn cmp(&self, other: &NormalizedPrice) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<NormalizedPrice> for NormalizedPrice

source§

fn eq(&self, other: &NormalizedPrice) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<NormalizedPrice> for NormalizedPrice

source§

fn partial_cmp(&self, other: &NormalizedPrice) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for NormalizedPrice

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for NormalizedPrice

source§

impl Eq for NormalizedPrice

source§

impl StructuralEq for NormalizedPrice

source§

impl StructuralPartialEq for NormalizedPrice

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

§

impl<T, Rhs, Output> ScalarMul<Rhs, Output> for Twhere T: Mul<Rhs, Output = Output> + MulAssign<Rhs>,