Trait penumbra_dex::component::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 add_recently_accessed_asset(
        &mut self,
        asset_id: Id,
        fixed_candidates: Arc<Vec<Id>>
    ) { ... }
    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 add_recently_accessed_asset( &mut self, asset_id: Id, fixed_candidates: Arc<Vec<Id>> )

Adds an asset ID to the list of recently accessed assets, making it a candidate for the current block’s arbitrage routing.

This ensures that assets associated with recently active positions will be eligible for arbitrage if mispriced positions are 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.

Object Safety§

This trait is not object safe.

Implementors§