1use crate::model::withdrawal::WithdrawalPriority;
7use pretty_simple_display::{DebugPretty, DisplaySimple};
8use serde::{Deserialize, Serialize};
9use serde_with::skip_serializing_none;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13#[serde(rename_all = "UPPERCASE")]
14pub enum Currency {
15 Btc,
17 Eth,
19 Usdc,
21 Usdt,
23 Eurr,
25}
26
27impl std::fmt::Display for Currency {
28 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
29 match self {
30 Currency::Btc => write!(f, "BTC"),
31 Currency::Eth => write!(f, "ETH"),
32 Currency::Usdc => write!(f, "USDC"),
33 Currency::Usdt => write!(f, "USDT"),
34 Currency::Eurr => write!(f, "EURR"),
35 }
36 }
37}
38
39#[skip_serializing_none]
41#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
42pub struct CurrencyStruct {
43 pub currency: String,
45 pub currency_long: String,
47 pub decimals: Option<u32>,
49 pub fee_precision: Option<u32>,
51 pub min_confirmations: u32,
53 pub min_withdrawal_fee: f64,
55 pub withdrawal_fee: f64,
57 pub withdrawal_priorities: Vec<WithdrawalPriority>,
59 pub apr: Option<f64>,
61 pub coin_type: Option<String>,
63 pub network_fee: Option<f64>,
65 pub network_currency: Option<String>,
67 pub in_cross_collateral_pool: Option<bool>,
69}
70
71#[skip_serializing_none]
73#[derive(DebugPretty, DisplaySimple, Clone, PartialEq, Serialize, Deserialize)]
74pub struct CurrencyInfo {
75 pub coin_type: String,
77 pub currency: String,
79 pub currency_long: String,
81 pub fee_precision: i32,
83 pub min_confirmations: i32,
85 pub min_withdrawal_fee: f64,
87 pub withdrawal_fee: f64,
89 pub withdrawal_priorities: Vec<WithdrawalPriority>,
91 pub disabled: Option<bool>,
93 pub min_deposit_amount: Option<f64>,
95 pub max_withdrawal_amount: Option<f64>,
97}
98
99impl CurrencyInfo {
100 pub fn new(
102 coin_type: String,
103 currency: String,
104 currency_long: String,
105 fee_precision: i32,
106 min_confirmations: i32,
107 min_withdrawal_fee: f64,
108 withdrawal_fee: f64,
109 ) -> Self {
110 Self {
111 coin_type,
112 currency,
113 currency_long,
114 fee_precision,
115 min_confirmations,
116 min_withdrawal_fee,
117 withdrawal_fee,
118 withdrawal_priorities: Vec::new(),
119 disabled: None,
120 min_deposit_amount: None,
121 max_withdrawal_amount: None,
122 }
123 }
124
125 pub fn add_priority(&mut self, priority: WithdrawalPriority) {
127 self.withdrawal_priorities.push(priority);
128 }
129
130 pub fn with_disabled(mut self, disabled: bool) -> Self {
132 self.disabled = Some(disabled);
133 self
134 }
135
136 pub fn with_deposit_limit(mut self, min_amount: f64) -> Self {
138 self.min_deposit_amount = Some(min_amount);
139 self
140 }
141
142 pub fn with_withdrawal_limit(mut self, max_amount: f64) -> Self {
144 self.max_withdrawal_amount = Some(max_amount);
145 self
146 }
147
148 pub fn is_enabled(&self) -> bool {
150 !self.disabled.unwrap_or(false)
151 }
152
153 pub fn get_priority(&self, name: &str) -> Option<&WithdrawalPriority> {
155 self.withdrawal_priorities.iter().find(|p| p.name == name)
156 }
157
158 pub fn highest_priority(&self) -> Option<&WithdrawalPriority> {
160 self.withdrawal_priorities
161 .iter()
162 .max_by(|a, b| a.value.partial_cmp(&b.value).unwrap())
163 }
164
165 pub fn lowest_priority(&self) -> Option<&WithdrawalPriority> {
167 self.withdrawal_priorities
168 .iter()
169 .min_by(|a, b| a.value.partial_cmp(&b.value).unwrap())
170 }
171}
172
173#[derive(DebugPretty, DisplaySimple, Clone, PartialEq, Serialize, Deserialize)]
175pub struct CurrencyInfoCollection {
176 pub currencies: Vec<CurrencyInfo>,
178}
179
180impl CurrencyInfoCollection {
181 pub fn new() -> Self {
183 Self {
184 currencies: Vec::new(),
185 }
186 }
187
188 pub fn add(&mut self, info: CurrencyInfo) {
190 self.currencies.push(info);
191 }
192
193 pub fn get(&self, currency: String) -> Option<&CurrencyInfo> {
195 self.currencies.iter().find(|c| c.currency == currency)
196 }
197
198 pub fn enabled(&self) -> Vec<&CurrencyInfo> {
200 self.currencies.iter().filter(|c| c.is_enabled()).collect()
201 }
202
203 pub fn with_withdrawal(&self) -> Vec<&CurrencyInfo> {
205 self.currencies
206 .iter()
207 .filter(|c| !c.withdrawal_priorities.is_empty())
208 .collect()
209 }
210}
211
212impl Default for CurrencyInfoCollection {
213 fn default() -> Self {
214 Self::new()
215 }
216}
217
218#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
220pub struct CurrencyExpirations {
221 pub future: Option<Vec<String>>,
223 pub option: Option<Vec<String>>,
225}