Repository: nautechsystems/nautilus_trader
File: crates/model/src/defi/dex.rs (Rust)

Code before:

    /// Returns a unique identifier for this DEX, combining chain and name.
    ///
    /// Format: "{chain_id}:{name_snake_case}"
    pub fn id(&self) -> String {
        format!(
            "{}:{}",
            self.chain.name,
            self.name.to_lowercase().replace(" ", "_")
        )
    }
}

impl Display for Dex {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "Dex(chain={}, name={})", self.chain, self.name)
    }
}

impl From<Pool> for CurrencyPair {
    fn from(p: Pool) -> Self {
        let symbol = Symbol::from(format!("{}/{}", p.token0.symbol, p.token1.symbol));
        let id = InstrumentId::new(symbol, Venue::from("DEFI"));

        let size_precision = p.token0.decimals;
        let price_precision = p.token0.decimals.saturating_add(p.token1.decimals);

        let price_increment = Price::new(10f64.powi(-(price_precision as i32)), price_precision);
        let size_increment = Quantity::new(10f64.powi(-(size_precision as i32)), size_precision);

        CurrencyPair::new(
            id,
            symbol,
            Currency::from(p.token0.symbol.as_str()),
            Currency::from(p.token1.symbol.as_str()),
            price_precision,
            size_precision,
            price_increment,
            size_increment,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            0.into(),

Review comment (suggestion):
This should probably be the `min(token1.decimals, FIXED_PRECISION)` (because we're currently limited to 16 rather than the full 18 which much of DeFi will need).

Code after:

    /// Returns a unique identifier for this DEX, combining chain and name.
    ///
    /// Format: "{chain_id}:{name_snake_case}"
    pub fn id(&self) -> String {
        format!(
            "{}:{}",
            self.chain.name,
            self.name.to_lowercase().replace(" ", "_")
        )
    }
}

impl Display for Dex {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "Dex(chain={}, name={})", self.chain, self.name)
    }
}

impl From<Pool> for CurrencyPair {
    fn from(p: Pool) -> Self {
        let symbol = Symbol::from(format!("{}/{}", p.token0.symbol, p.token1.symbol));
        let id = InstrumentId::new(symbol, Venue::from(p.dex.id()));

        let size_precision = p.token0.decimals.min(FIXED_PRECISION);
        let price_precision = p.token1.decimals.min(FIXED_PRECISION);

        let price_increment = Price::new(10f64.powi(-(price_precision as i32)), price_precision);
        let size_increment = Quantity::new(10f64.powi(-(size_precision as i32)), size_precision);

        CurrencyPair::new(
            id,
            symbol,
            Currency::from(p.token0.symbol.as_str()),
            Currency::from(p.token1.symbol.as_str()),
            price_precision,
            size_precision,
            price_increment,
            size_increment,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            0.into(),