use crate::spec::prelude::*;
#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
pub enum AssetClass {
Cryptocurrency,
FiatCurrency,
}
#[derive(CandidType, Clone, Debug, Deserialize)]
pub struct Asset {
pub symbol: String,
pub class: AssetClass,
}
#[derive(CandidType, Clone, Debug, Deserialize)]
pub struct GetExchangeRateRequest {
pub base_asset: Asset,
pub quote_asset: Asset,
pub timestamp: Option<u64>,
}
#[derive(CandidType, Clone, Debug, Deserialize)]
pub struct ExchangeRateMetadata {
pub decimals: u32,
pub base_asset_num_queried_sources: u32,
pub base_asset_num_received_rates: u32,
pub quote_asset_num_queried_sources: u32,
pub quote_asset_num_received_rates: u32,
pub standard_deviation: u64,
pub forex_timestamp: Option<u64>,
}
#[derive(CandidType, Clone, Debug, Deserialize)]
pub struct ExchangeRate {
pub rate: u64,
pub metadata: ExchangeRateMetadata,
}
#[derive(CandidType, Clone, Debug, Deserialize)]
pub enum ExchangeRateError {
AnonymousPrincipalNotAllowed,
CryptoQuoteAssetNotFound,
FailedToAcceptCycles,
ForexBaseAssetNotFound,
CryptoBaseAssetNotFound,
StablecoinRateTooFewRates,
ForexAssetsNotFound,
InconsistentRatesReceived,
RateLimited,
StablecoinRateZeroRate,
Other(String),
NotEnoughCycles,
ForexInvalidTimestamp,
NotEnoughRates,
ForexQuoteAssetNotFound,
StablecoinRateNotFound,
}
#[derive(CandidType, Clone, Debug, Deserialize)]
pub enum GetExchangeRateResult {
Ok(ExchangeRate),
Err(ExchangeRateError),
}