|
16 | 16 | use std::{borrow::Cow, fmt::Display, sync::Arc};
|
17 | 17 |
|
18 | 18 | use crate::defi::{amm::Pool, chain::Chain};
|
| 19 | +use crate::identifiers::{InstrumentId, Symbol, Venue}; |
| 20 | +use crate::instruments::{Instrument, any::InstrumentAny, currency_pair::CurrencyPair}; |
| 21 | +use crate::types::{currency::Currency, price::Price, quantity::Quantity}; |
19 | 22 |
|
20 | 23 | /// Represents different types of Automated Market Makers (AMMs) in DeFi protocols.
|
21 | 24 | #[derive(Debug, Clone)]
|
@@ -96,3 +99,46 @@ impl Display for Dex {
|
96 | 99 | write!(f, "Dex(chain={}, name={})", self.chain, self.name)
|
97 | 100 | }
|
98 | 101 | }
|
| 102 | + |
| 103 | +impl From<Pool> for CurrencyPair { |
| 104 | + fn from(p: Pool) -> Self { |
| 105 | + let symbol = Symbol::from(format!("{}/{}", p.token0.symbol, p.token1.symbol)); |
| 106 | + let id = InstrumentId::new(symbol, Venue::from("DEFI")); |
| 107 | + |
| 108 | + let size_precision = p.token0.decimals; |
| 109 | + let price_precision = p.token0.decimals.saturating_add(p.token1.decimals); |
| 110 | + |
| 111 | + let price_increment = Price::new(10f64.powi(-(price_precision as i32)), price_precision); |
| 112 | + let size_increment = Quantity::new(10f64.powi(-(size_precision as i32)), size_precision); |
| 113 | + |
| 114 | + CurrencyPair::new( |
| 115 | + id, |
| 116 | + symbol, |
| 117 | + Currency::from(p.token0.symbol.as_str()), |
| 118 | + Currency::from(p.token1.symbol.as_str()), |
| 119 | + price_precision, |
| 120 | + size_precision, |
| 121 | + price_increment, |
| 122 | + size_increment, |
| 123 | + None, |
| 124 | + None, |
| 125 | + None, |
| 126 | + None, |
| 127 | + None, |
| 128 | + None, |
| 129 | + None, |
| 130 | + None, |
| 131 | + None, |
| 132 | + None, |
| 133 | + None, |
| 134 | + 0.into(), |
| 135 | + 0.into(), |
| 136 | + ) |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +impl From<Pool> for InstrumentAny { |
| 141 | + fn from(p: Pool) -> Self { |
| 142 | + CurrencyPair::from(p).into_any() |
| 143 | + } |
| 144 | +} |
0 commit comments