balancer_maths_rust/hooks/
types.rs1use 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#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13#[serde(untagged)]
14pub enum HookState {
15 Akron(AkronHookState),
17 DirectionalFee(DirectionalFeeHookState),
19 ExitFee(ExitFeeHookState),
21 StableSurge(StableSurgeHookState),
23}
24
25impl HookState {
26 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#[derive(Debug, Clone)]
45pub struct AfterSwapParams {
46 pub kind: SwapKind,
47 pub token_in: String, pub token_out: String, 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#[derive(Debug, Clone)]
59pub struct DynamicSwapFeeResult {
60 pub success: bool,
61 pub dynamic_swap_fee: BigInt,
62}
63
64#[derive(Debug, Clone)]
66pub struct BeforeSwapResult {
67 pub success: bool,
68 pub hook_adjusted_balances_scaled_18: Vec<BigInt>,
69}
70
71#[derive(Debug, Clone)]
73pub struct AfterSwapResult {
74 pub success: bool,
75 pub hook_adjusted_amount_calculated_raw: BigInt,
76}
77
78#[derive(Debug, Clone)]
80pub struct BeforeAddLiquidityResult {
81 pub success: bool,
82 pub hook_adjusted_balances_scaled_18: Vec<BigInt>,
83}
84
85#[derive(Debug, Clone)]
87pub struct AfterAddLiquidityResult {
88 pub success: bool,
89 pub hook_adjusted_amounts_in_raw: Vec<BigInt>,
90}
91
92#[derive(Debug, Clone)]
94pub struct BeforeRemoveLiquidityResult {
95 pub success: bool,
96 pub hook_adjusted_balances_scaled_18: Vec<BigInt>,
97}
98
99#[derive(Debug, Clone)]
101pub struct AfterRemoveLiquidityResult {
102 pub success: bool,
103 pub hook_adjusted_amounts_out_raw: Vec<BigInt>,
104}