diff --git a/crates/core/component/dex/src/component/action_handler/position/open.rs b/crates/core/component/dex/src/component/action_handler/position/open.rs index 4f2445292b..c591e35a58 100644 --- a/crates/core/component/dex/src/component/action_handler/position/open.rs +++ b/crates/core/component/dex/src/component/action_handler/position/open.rs @@ -1,10 +1,10 @@ -use anyhow::Result; +use anyhow::{ensure, Result}; use async_trait::async_trait; use cnidarium::StateWrite; use cnidarium_component::ActionHandler; use crate::{ - component::PositionManager, + component::{PositionManager, StateReadExt}, lp::{action::PositionOpen, position}, }; @@ -28,6 +28,14 @@ impl ActionHandler for PositionOpen { } async fn check_and_execute(&self, mut state: S) -> Result<()> { + // Only open the position if the dex is enabled in the dex params. + let dex_params = state.get_dex_params().await?; + + ensure!( + dex_params.is_enabled, + "Dex MUST be enabled to open positions." + ); + state.open_position(self.position.clone()).await?; Ok(()) } diff --git a/crates/core/component/dex/src/component/action_handler/swap.rs b/crates/core/component/dex/src/component/action_handler/swap.rs index b735a3b295..74848317fc 100644 --- a/crates/core/component/dex/src/component/action_handler/swap.rs +++ b/crates/core/component/dex/src/component/action_handler/swap.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +use anyhow::{ensure, Result}; use async_trait::async_trait; use cnidarium::StateWrite; use cnidarium_component::ActionHandler; @@ -34,6 +34,14 @@ impl ActionHandler for Swap { } async fn check_and_execute(&self, mut state: S) -> Result<()> { + // Only execute the swap if the dex is enabled in the dex params. + let dex_params = state.get_dex_params().await?; + + ensure!( + dex_params.is_enabled, + "Dex MUST be enabled to process swap actions." + ); + let swap_start = std::time::Instant::now(); let swap = self;