Struct Oracle

Source
pub struct Oracle<'a> {
    pub config: Map<'static, &'a AssetEntry, UncheckedPriceSource>,
    /* private fields */
}
Expand description

Struct for calculating asset prices/values for a smart contract.

Fields§

§config: Map<'static, &'a AssetEntry, UncheckedPriceSource>

map of human-readable asset names to their human-readable price source

Implementations§

Source§

impl<'a> Oracle<'a>

Source

pub const fn new() -> Self

Source

pub fn update_assets( &self, deps: DepsMut<'_>, ans: &AnsHost, to_add: Vec<(AssetEntry, UncheckedPriceSource)>, to_remove: Vec<AssetEntry>, ) -> AbstractResult<()>

Updates the assets in the Oracle. First adds the provided assets to the oracle, then removes the provided assets from the oracle.

Source

pub fn asset_value( &self, deps: Deps<'_>, asset: Asset, ) -> AbstractResult<Uint128>

Calculates the value of a single asset by recursive conversion to underlying asset(s). Does not make use of the cache to prevent querying the same price source multiple times.

Source

pub fn account_value( &mut self, deps: Deps<'_>, account: &Addr, ) -> AbstractResult<AccountValue>

Calculates the total value of an account’s assets by efficiently querying the configured price sources

§Resolve the total value of an account given a base asset.

This process goes as follows

  1. Get the assets for the highest, not visited, complexity.
  2. For each asset query it’s balance, get the conversion ratios associated with that asset and load its cached values.
  3. Using the conversion ratio convert the balance and cached values and save the resulting values in the cache for that lower complexity asset.
  4. Repeat until the base asset is reached. (complexity = 0)
Source

pub fn validate(&self, deps: Deps<'_>) -> AbstractResult<()>

Checks that the oracle is configured correctly.

Source

pub fn paged_asset_info( &self, deps: Deps<'_>, last_asset: Option<AssetInfo>, limit: Option<u8>, ) -> AbstractResult<Vec<(AssetInfo, (PriceSource, Complexity))>>

Page over the oracle assets

Source

pub fn paged_asset_config( &self, deps: Deps<'_>, last_asset: Option<AssetEntry>, limit: Option<u8>, ) -> AbstractResult<Vec<(AssetEntry, UncheckedPriceSource)>>

Page over the oracle’s asset configuration

Source

pub fn asset_config( &self, deps: Deps<'_>, asset: &AssetEntry, ) -> AbstractResult<UncheckedPriceSource>

get the configuration of an asset

Source

pub fn base_asset(&self, deps: Deps<'_>) -> AbstractResult<AssetInfo>

Auto Trait Implementations§

§

impl<'a> Freeze for Oracle<'a>

§

impl<'a> RefUnwindSafe for Oracle<'a>

§

impl<'a> Send for Oracle<'a>

§

impl<'a> Sync for Oracle<'a>

§

impl<'a> Unpin for Oracle<'a>

§

impl<'a> UnwindSafe for Oracle<'a>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts 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
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.