penumbra_sdk_dex/component/action_handler/position/close.rs
1use anyhow::Result;
2use async_trait::async_trait;
3use cnidarium::StateWrite;
4use cnidarium_component::ActionHandler;
5// use penumbra_sdk_proto::{DomainType as _, StateWriteProto as _};
6
7use crate::{component::PositionManager, lp::action::PositionClose};
8
9#[async_trait]
10/// Debits an opened position NFT and credits a closed position NFT.
11impl ActionHandler for PositionClose {
12 type CheckStatelessContext = ();
13 async fn check_stateless(&self, _context: ()) -> Result<()> {
14 // Nothing to do: the only validation is of the state change,
15 // and that's done by the value balance mechanism.
16 Ok(())
17 }
18
19 async fn check_and_execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
20 // We don't want to actually close the position here, because otherwise
21 // the economic effects could depend on intra-block ordering, and we'd
22 // lose the ability to do block-scoped JIT liquidity, where a single
23 // transaction opens and closes a position, keeping liquidity live only
24 // during that block's batch swap execution.
25 state.queue_close_position(self.position_id).await?;
26
27 Ok(())
28 }
29}