penumbra_dex::component

Trait PositionManager

Source
pub trait PositionManager: StateWrite + PositionRead {
    // Provided methods
    fn close_position_by_id<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        id: &'life1 Id,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: Send + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn queue_close_position(&mut self, id: Id) { ... }
    fn close_queued_positions<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: Send + 'async_trait,
             'life0: 'async_trait { ... }
    fn open_position<'life0, 'async_trait>(
        &'life0 mut self,
        position: Position,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: Send + 'async_trait,
             'life0: 'async_trait { ... }
    fn position_execution<'life0, 'async_trait>(
        &'life0 mut self,
        new_state: Position,
        context: DirectedTradingPair,
    ) -> Pin<Box<dyn Future<Output = Result<Position>> + Send + 'async_trait>>
       where Self: Send + 'async_trait,
             'life0: 'async_trait { ... }
    fn withdraw_position<'life0, 'async_trait>(
        &'life0 mut self,
        position_id: Id,
        sequence: u64,
    ) -> Pin<Box<dyn Future<Output = Result<Balance>> + Send + 'async_trait>>
       where Self: Send + 'async_trait,
             'life0: 'async_trait { ... }
}
Available on crate feature component only.
Expand description

Manages liquidity positions within the chain state.

Provided Methods§

Source

fn close_position_by_id<'life0, 'life1, 'async_trait>( &'life0 mut self, id: &'life1 Id, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Close a position by id, removing it from the state.

If the position is already closed, this is a no-op.

§Errors

Returns an error if the position does not exist.

Source

fn queue_close_position(&mut self, id: Id)

Queues a position to be closed at the end of the block, after batch execution.

Source

fn close_queued_positions<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Send + 'async_trait, 'life0: 'async_trait,

Close all positions that have been queued for closure.

Source

fn open_position<'life0, 'async_trait>( &'life0 mut self, position: Position, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Send + 'async_trait, 'life0: 'async_trait,

Opens a new position, updating all necessary indexes and checking for its nonexistence prior to being opened.

§Errors

This method returns an error if the position is malformed e.g. it is set to a state other than Opened or, it specifies a position identifier already used by another position.

An error can also occur if a DEX engine invariant is breached e.g. overflowing the position counter (u16::MAX) or, overflowing the value circuit breaker (u128::MAX)

In any of those cases, we do not want to allow a new position to be opened.

Source

fn position_execution<'life0, 'async_trait>( &'life0 mut self, new_state: Position, context: DirectedTradingPair, ) -> Pin<Box<dyn Future<Output = Result<Position>> + Send + 'async_trait>>
where Self: Send + 'async_trait, 'life0: 'async_trait,

Record execution against an opened position.

IMPORTANT: This method can mutate its input state.

We return the position that was ultimately written to the state, it could differ from the initial input e.g. if the position is auto-closing.

§Context parameter

The context parameter records the global context of the path in which the position execution happened. This may be completely different than the trading pair of the position itself, and is used to link the micro-scale execution (processed by this method) with the macro-scale context (a swap or arbitrage).

§Auto-closing positions

Some positions are close_on_fill i.e. they are programmed to close after execution exhausts either side of their reserves. This method returns the position that was written to the chain state, making it possible for callers to inspect any change that has occured during execution handling.

Source

fn withdraw_position<'life0, 'async_trait>( &'life0 mut self, position_id: Id, sequence: u64, ) -> Pin<Box<dyn Future<Output = Result<Balance>> + Send + 'async_trait>>
where Self: Send + 'async_trait, 'life0: 'async_trait,

Withdraw from a closed position, incrementing its sequence number.

Updates the position’s reserves and rewards to zero and returns the withdrawn balance.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: StateWrite + ?Sized + Chandelier> PositionManager for T