wp-solana-pool-traits 0.1.1

Traits and utilities for Solana liquidity pool operations: PoolViewer, PoolInfuser, PositionViewer
Documentation
use anyhow::Result;
use rust_decimal::Decimal;

use crate::types::Currency;

/// Base trait for pool operations that provides common price and tick/bin
/// conversion methods
///
/// This trait provides a unified interface for converting between prices and
/// tick/bin indices across different pool protocols (Whirlpool, Raydium CLMM,
/// Meteora DLMM, etc.).
///
/// For protocols that use ticks (Whirlpool, Raydium CLMM), the methods convert
/// between price and tick index. For protocols that use bins (Meteora DLMM),
/// the methods convert between price and bin ID.
pub trait PoolBase: Send + Sync {
    /// Get currency A
    fn currency_a(&self) -> Currency;

    /// Get currency B
    fn currency_b(&self) -> Currency;

    /// Get tick spacing
    fn tick_spacing(&self) -> u16;

    /// Convert a price to a tick/bin index
    ///
    /// # Arguments
    ///
    /// * `price` - The price to convert (token A per token B)
    ///
    /// # Returns
    ///
    /// The tick index (for Whirlpool/Raydium CLMM) or bin ID (for Meteora DLMM)
    fn price_to_tick_index(&self, price: Decimal, tick_spacing: u16) -> Result<i32>;

    /// Convert a tick/bin index to a price
    ///
    /// # Arguments
    ///
    /// * `tick_index` - The tick index (for Whirlpool/Raydium CLMM) or bin ID
    ///   (for Meteora DLMM)
    ///
    /// # Returns
    ///
    /// The price (token A per token B) as Decimal
    fn tick_index_to_price(&self, tick_index: i32, tick_spacing: u16) -> Result<Decimal>;
}