balancer_maths_rust/common/
pool_base.rs

1//! Pool base trait for all pool implementations
2
3use crate::common::errors::PoolError;
4use crate::common::types::*;
5use alloy_primitives::U256;
6
7/// Trait for pool implementations (matches TypeScript PoolBase interface and Python PoolBase abstract class)
8pub trait PoolBase {
9    /// Perform swap operation
10    fn on_swap(&self, swap_params: &SwapParams) -> Result<U256, PoolError>;
11
12    /// Compute invariant
13    fn compute_invariant(
14        &self,
15        balances_live_scaled_18: &[U256],
16        rounding: Rounding,
17    ) -> Result<U256, PoolError>;
18
19    /// Compute balance
20    fn compute_balance(
21        &self,
22        balances_live_scaled_18: &[U256],
23        token_in_index: usize,
24        invariant_ratio: &U256,
25    ) -> Result<U256, PoolError>;
26
27    /// Get maximum invariant ratio
28    fn get_maximum_invariant_ratio(&self) -> U256;
29
30    /// Get minimum invariant ratio
31    fn get_minimum_invariant_ratio(&self) -> U256;
32}