|
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, fixed::FIXED_PRECISION, price::Price, quantity::Quantity}; |
19 | 22 |
|
20 | 23 | /// Represents different types of Automated Market Makers (AMMs) in DeFi protocols.
|
21 | 24 | #[derive(Debug, Clone)]
|
@@ -105,3 +108,46 @@ impl Display for Dex {
|
105 | 108 | write!(f, "Dex(chain={}, name={})", self.chain, self.name)
|
106 | 109 | }
|
107 | 110 | }
|
| 111 | + |
| 112 | +impl From<Pool> for CurrencyPair { |
| 113 | + fn from(p: Pool) -> Self { |
| 114 | + let symbol = Symbol::from(format!("{}/{}", p.token0.symbol, p.token1.symbol)); |
| 115 | + let id = InstrumentId::new(symbol, Venue::from(p.dex.id())); |
| 116 | + |
| 117 | + let size_precision = p.token0.decimals.min(FIXED_PRECISION); |
| 118 | + let price_precision = p.token1.decimals.min(FIXED_PRECISION); |
| 119 | + |
| 120 | + let price_increment = Price::new(10f64.powi(-(price_precision as i32)), price_precision); |
| 121 | + let size_increment = Quantity::new(10f64.powi(-(size_precision as i32)), size_precision); |
| 122 | + |
| 123 | + CurrencyPair::new( |
| 124 | + id, |
| 125 | + symbol, |
| 126 | + Currency::from(p.token0.symbol.as_str()), |
| 127 | + Currency::from(p.token1.symbol.as_str()), |
| 128 | + price_precision, |
| 129 | + size_precision, |
| 130 | + price_increment, |
| 131 | + size_increment, |
| 132 | + None, |
| 133 | + None, |
| 134 | + None, |
| 135 | + None, |
| 136 | + None, |
| 137 | + None, |
| 138 | + None, |
| 139 | + None, |
| 140 | + None, |
| 141 | + None, |
| 142 | + None, |
| 143 | + 0.into(), |
| 144 | + 0.into(), |
| 145 | + ) |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +impl From<Pool> for InstrumentAny { |
| 150 | + fn from(p: Pool) -> Self { |
| 151 | + CurrencyPair::from(p).into_any() |
| 152 | + } |
| 153 | +} |
0 commit comments