canic_core/cdk/spec/standards/
xrc.rs1use crate::cdk::spec::prelude::*;
8
9#[derive(CandidType, Clone, Copy, Debug, Deserialize, Eq, PartialEq)]
15pub enum AssetClass {
16 Cryptocurrency,
17 FiatCurrency,
18}
19
20#[derive(CandidType, Clone, Debug, Deserialize)]
26pub struct Asset {
27 pub symbol: String,
28 pub class: AssetClass,
29}
30
31#[derive(CandidType, Clone, Debug, Deserialize)]
37pub struct GetExchangeRateRequest {
38 pub base_asset: Asset,
39 pub quote_asset: Asset,
40 pub timestamp: Option<u64>,
41}
42
43#[derive(CandidType, Clone, Debug, Deserialize)]
49pub struct ExchangeRateMetadata {
50 pub decimals: u32,
51 pub base_asset_num_queried_sources: u32,
52 pub base_asset_num_received_rates: u32,
53 pub quote_asset_num_queried_sources: u32,
54 pub quote_asset_num_received_rates: u32,
55 pub standard_deviation: u64,
56 pub forex_timestamp: Option<u64>,
57}
58
59#[derive(CandidType, Clone, Debug, Deserialize)]
65pub struct ExchangeRate {
66 pub rate: u64,
67 pub metadata: ExchangeRateMetadata,
68}
69
70#[derive(CandidType, Clone, Debug, Deserialize)]
76pub enum ExchangeRateError {
77 AnonymousPrincipalNotAllowed,
78 CryptoQuoteAssetNotFound,
79 FailedToAcceptCycles,
80 ForexBaseAssetNotFound,
81 CryptoBaseAssetNotFound,
82 StablecoinRateTooFewRates,
83 ForexAssetsNotFound,
84 InconsistentRatesReceived,
85 RateLimited,
86 StablecoinRateZeroRate,
87 Other(String),
88 NotEnoughCycles,
89 ForexInvalidTimestamp,
90 NotEnoughRates,
91 ForexQuoteAssetNotFound,
92 StablecoinRateNotFound,
93}
94
95#[derive(CandidType, Clone, Debug, Deserialize)]
101pub enum GetExchangeRateResult {
102 Ok(ExchangeRate),
103 Err(ExchangeRateError),
104}