penumbra_dex/component/action_handler/position/
open.rsuse anyhow::{ensure, Result};
use async_trait::async_trait;
use cnidarium::StateWrite;
use cnidarium_component::ActionHandler;
use crate::{
component::{PositionManager, StateReadExt},
lp::{action::PositionOpen, position},
};
#[async_trait]
impl ActionHandler for PositionOpen {
type CheckStatelessContext = ();
async fn check_stateless(&self, _context: ()) -> Result<()> {
self.position.check_stateless()?;
if self.position.state != position::State::Opened {
anyhow::bail!("attempted to open a position with a state besides `Opened`");
}
Ok(())
}
async fn check_and_execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
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(())
}
}