Skip to content

Commit

Permalink
dex: add checks to disable swaps and opening positions when the dex i…
Browse files Browse the repository at this point in the history
…s disabled
  • Loading branch information
aubrika committed Apr 16, 2024
1 parent ce5ba7e commit 63ae8ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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},
};

Expand All @@ -28,6 +28,14 @@ impl ActionHandler for PositionOpen {
}

async fn check_and_execute<S: StateWrite>(&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(())
}
Expand Down
10 changes: 9 additions & 1 deletion crates/core/component/dex/src/component/action_handler/swap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{ensure, Result};
use async_trait::async_trait;
use cnidarium::StateWrite;
use cnidarium_component::ActionHandler;
Expand Down Expand Up @@ -34,6 +34,14 @@ impl ActionHandler for Swap {
}

async fn check_and_execute<S: StateWrite>(&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;

Expand Down

0 comments on commit 63ae8ab

Please sign in to comment.