balancer_maths_rust/hooks/
types.rs

1//! Hook types and state definitions
2
3use super::akron::AkronHookState;
4use super::directional_fee::DirectionalFeeHookState;
5use super::exit_fee::ExitFeeHookState;
6use super::stable_surge::StableSurgeHookState;
7use crate::common::types::{HookStateBase, SwapKind};
8use num_bigint::BigInt;
9use serde::{Deserialize, Serialize};
10
11/// Hook state - can be any specific hook type
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13#[serde(untagged)]
14pub enum HookState {
15    /// Akron hook state
16    Akron(AkronHookState),
17    /// Directional fee hook state
18    DirectionalFee(DirectionalFeeHookState),
19    /// Exit fee hook state
20    ExitFee(ExitFeeHookState),
21    /// Stable surge hook state
22    StableSurge(StableSurgeHookState),
23}
24
25impl HookState {
26    /// Get the hook type
27    pub fn hook_type(&self) -> &str {
28        match self {
29            HookState::Akron(state) => state.hook_type(),
30            HookState::DirectionalFee(state) => state.hook_type(),
31            HookState::ExitFee(state) => state.hook_type(),
32            HookState::StableSurge(state) => state.hook_type(),
33        }
34    }
35}
36
37impl HookStateBase for HookState {
38    fn hook_type(&self) -> &str {
39        self.hook_type()
40    }
41}
42
43/// Parameters for after swap hook
44#[derive(Debug, Clone)]
45pub struct AfterSwapParams {
46    pub kind: SwapKind,
47    pub token_in: String,  // IERC20 address
48    pub token_out: String, // IERC20 address
49    pub amount_in_scaled_18: BigInt,
50    pub amount_out_scaled_18: BigInt,
51    pub token_in_balance_scaled_18: BigInt,
52    pub token_out_balance_scaled_18: BigInt,
53    pub amount_calculated_scaled_18: BigInt,
54    pub amount_calculated_raw: BigInt,
55}
56
57/// Result of dynamic swap fee computation
58#[derive(Debug, Clone)]
59pub struct DynamicSwapFeeResult {
60    pub success: bool,
61    pub dynamic_swap_fee: BigInt,
62}
63
64/// Result of before swap hook
65#[derive(Debug, Clone)]
66pub struct BeforeSwapResult {
67    pub success: bool,
68    pub hook_adjusted_balances_scaled_18: Vec<BigInt>,
69}
70
71/// Result of after swap hook
72#[derive(Debug, Clone)]
73pub struct AfterSwapResult {
74    pub success: bool,
75    pub hook_adjusted_amount_calculated_raw: BigInt,
76}
77
78/// Result of before add liquidity hook
79#[derive(Debug, Clone)]
80pub struct BeforeAddLiquidityResult {
81    pub success: bool,
82    pub hook_adjusted_balances_scaled_18: Vec<BigInt>,
83}
84
85/// Result of after add liquidity hook
86#[derive(Debug, Clone)]
87pub struct AfterAddLiquidityResult {
88    pub success: bool,
89    pub hook_adjusted_amounts_in_raw: Vec<BigInt>,
90}
91
92/// Result of before remove liquidity hook
93#[derive(Debug, Clone)]
94pub struct BeforeRemoveLiquidityResult {
95    pub success: bool,
96    pub hook_adjusted_balances_scaled_18: Vec<BigInt>,
97}
98
99/// Result of after remove liquidity hook
100#[derive(Debug, Clone)]
101pub struct AfterRemoveLiquidityResult {
102    pub success: bool,
103    pub hook_adjusted_amounts_out_raw: Vec<BigInt>,
104}