balancer_maths_rust/pools/weighted/
weighted_data.rs

1//! Weighted pool data structures
2
3use crate::common::types::BasePoolState;
4use alloy_primitives::U256;
5use serde::{Deserialize, Serialize};
6
7/// Weighted pool state (extends BasePoolState with weighted-specific fields)
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct WeightedState {
10    /// Base pool state
11    #[serde(flatten)]
12    pub base: BasePoolState,
13    /// Normalized weights (scaled 18)
14    pub weights: Vec<U256>,
15}
16
17impl WeightedState {
18    /// Create a new weighted pool state
19    pub fn new(base: BasePoolState, weights: Vec<U256>) -> Self {
20        Self { base, weights }
21    }
22
23    /// Get the base pool state
24    pub fn base(&self) -> &BasePoolState {
25        &self.base
26    }
27
28    /// Get the weights
29    pub fn weights(&self) -> &[U256] {
30        &self.weights
31    }
32}
33
34impl From<WeightedState> for BasePoolState {
35    fn from(weighted_state: WeightedState) -> Self {
36        weighted_state.base
37    }
38}
39
40impl AsRef<BasePoolState> for WeightedState {
41    fn as_ref(&self) -> &BasePoolState {
42        &self.base
43    }
44}
45
46impl From<WeightedState> for crate::common::types::PoolState {
47    fn from(state: WeightedState) -> Self {
48        crate::common::types::PoolState::Weighted(state)
49    }
50}