pub trait ProvideAssetPrice {
type AssetId;
type Price: FixedPointNumber;
// Required method
fn get_price(asset_id: Self::AssetId) -> Option<Self::Price>;
// Provided methods
fn calculate_decimals_aware_price(
original_price: Self::Price,
usd_decimals: u8,
asset_decimals: u8,
) -> Option<Self::Price> { ... }
fn convert_back_to_normal_price(
decimals_aware_price: Self::Price,
usd_decimals: u8,
asset_decimals: u8,
) -> Option<Self::Price> { ... }
fn get_decimals_aware_price(
asset_id: Self::AssetId,
usd_decimals: u8,
asset_decimals: u8,
) -> Option<Self::Price> { ... }
}Required Associated Types§
type AssetId
type Price: FixedPointNumber
Required Methods§
Provided Methods§
Sourcefn calculate_decimals_aware_price(
original_price: Self::Price,
usd_decimals: u8,
asset_decimals: u8,
) -> Option<Self::Price>
fn calculate_decimals_aware_price( original_price: Self::Price, usd_decimals: u8, asset_decimals: u8, ) -> Option<Self::Price>
Prices define the relationship between USD/Asset. When to and from that asset, we need to be aware that they might
have different decimals. This function calculates the relationship having in mind the decimals. For example:
if the price is 2.5, our underlying USD unit has 6 decimals, and the asset has 8 decimals, the price will be
calculated like so: (2.5USD * 10^6) / (1 * 10^8) = 0.025. And so if we want to convert 20 of the asset to USD,
we would do 0.025(USD/Asset)FixedPointNumber * 20_000_000_00(Asset)u128 = 50_000_000 which is 50 USD with 6 decimals
fn convert_back_to_normal_price( decimals_aware_price: Self::Price, usd_decimals: u8, asset_decimals: u8, ) -> Option<Self::Price>
fn get_decimals_aware_price( asset_id: Self::AssetId, usd_decimals: u8, asset_decimals: u8, ) -> Option<Self::Price>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.