canic_core/spec/ic/
xrc.rs1use crate::spec::prelude::*;
2
3#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
9pub enum AssetClass {
10 Cryptocurrency,
11 FiatCurrency,
12}
13
14#[derive(CandidType, Clone, Debug, Deserialize)]
20pub struct Asset {
21 pub symbol: String,
22 pub class: AssetClass,
23}
24
25#[derive(CandidType, Clone, Debug, Deserialize)]
31pub struct GetExchangeRateRequest {
32 pub base_asset: Asset,
33 pub quote_asset: Asset,
34 pub timestamp: Option<u64>,
35}
36
37#[derive(CandidType, Clone, Debug, Deserialize)]
43pub struct ExchangeRateMetadata {
44 pub decimals: u32,
45 pub base_asset_num_queried_sources: u32,
46 pub base_asset_num_received_rates: u32,
47 pub quote_asset_num_queried_sources: u32,
48 pub quote_asset_num_received_rates: u32,
49 pub standard_deviation: u64,
50 pub forex_timestamp: Option<u64>,
51}
52
53#[derive(CandidType, Clone, Debug, Deserialize)]
59pub struct ExchangeRate {
60 pub rate: u64,
61 pub metadata: ExchangeRateMetadata,
62}
63
64#[derive(CandidType, Clone, Debug, Deserialize)]
70pub enum ExchangeRateError {
71 AnonymousPrincipalNotAllowed,
72 CryptoQuoteAssetNotFound,
73 FailedToAcceptCycles,
74 ForexBaseAssetNotFound,
75 CryptoBaseAssetNotFound,
76 StablecoinRateTooFewRates,
77 ForexAssetsNotFound,
78 InconsistentRatesReceived,
79 RateLimited,
80 StablecoinRateZeroRate,
81 Other(String),
82 NotEnoughCycles,
83 ForexInvalidTimestamp,
84 NotEnoughRates,
85 ForexQuoteAssetNotFound,
86 StablecoinRateNotFound,
87}
88
89#[derive(CandidType, Clone, Debug, Deserialize)]
95pub enum GetExchangeRateResult {
96 Ok(ExchangeRate),
97 Err(ExchangeRateError),
98}