balancer_maths_rust/pools/weighted/
weighted_data.rs1use crate::common::types::BasePoolState;
4use alloy_primitives::U256;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct WeightedState {
10 #[serde(flatten)]
12 pub base: BasePoolState,
13 pub weights: Vec<U256>,
15}
16
17impl WeightedState {
18 pub fn new(base: BasePoolState, weights: Vec<U256>) -> Self {
20 Self { base, weights }
21 }
22
23 pub fn base(&self) -> &BasePoolState {
25 &self.base
26 }
27
28 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}