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>
impl<'a> Oracle<'a>
pub const fn new() -> Self
Sourcepub fn update_assets(
&self,
deps: DepsMut<'_>,
ans: &AnsHost,
to_add: Vec<(AssetEntry, UncheckedPriceSource)>,
to_remove: Vec<AssetEntry>,
) -> AbstractResult<()>
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.
Sourcepub fn asset_value(
&self,
deps: Deps<'_>,
asset: Asset,
) -> AbstractResult<Uint128>
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.
Sourcepub fn account_value(
&mut self,
deps: Deps<'_>,
account: &Addr,
) -> AbstractResult<AccountValue>
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
- Get the assets for the highest, not visited, complexity.
- For each asset query it’s balance, get the conversion ratios associated with that asset and load its cached values.
- Using the conversion ratio convert the balance and cached values and save the resulting values in the cache for that lower complexity asset.
- Repeat until the base asset is reached. (complexity = 0)
Sourcepub fn validate(&self, deps: Deps<'_>) -> AbstractResult<()>
pub fn validate(&self, deps: Deps<'_>) -> AbstractResult<()>
Checks that the oracle is configured correctly.
Sourcepub fn paged_asset_info(
&self,
deps: Deps<'_>,
last_asset: Option<AssetInfo>,
limit: Option<u8>,
) -> AbstractResult<Vec<(AssetInfo, (PriceSource, Complexity))>>
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
Sourcepub fn paged_asset_config(
&self,
deps: Deps<'_>,
last_asset: Option<AssetEntry>,
limit: Option<u8>,
) -> AbstractResult<Vec<(AssetEntry, UncheckedPriceSource)>>
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
Sourcepub fn asset_config(
&self,
deps: Deps<'_>,
asset: &AssetEntry,
) -> AbstractResult<UncheckedPriceSource>
pub fn asset_config( &self, deps: Deps<'_>, asset: &AssetEntry, ) -> AbstractResult<UncheckedPriceSource>
get the configuration of an asset
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> 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
Mutably borrows from an owned value. Read more