Skip to main content

PositionManager

The PositionManager contract extends BasePositionManager with user-facing functionality for position management. It includes role-based access control for position execution and liquidation.

Contract Overview

The PositionManager handles:
  • Direct creation, modification, and liquidation of positions
  • Execution of orders from the OrderBook
  • Role-based access control for different operations
  • Integration with the OrderBook for limit orders
The PositionManager provides direct position execution functionality, as opposed to the queue-based approach of the PositionRouter.

Key Functions

Position Management

Increases a position with the specified parameters.
Increases a position using ETH as the input token.
Decreases a position with the specified parameters.
Decreases a position and receives ETH instead of WETH.

Liquidation

Liquidates a position if it meets the liquidation criteria.

Order Execution

Executes an increase order from the OrderBook.
Executes a decrease order from the OrderBook.

Access Control

The PositionManager implements several access control mechanisms:
Sets or removes an order keeper who can execute orders.
Sets or removes a liquidator who can liquidate positions.
Sets or removes a partner who can place orders for their users.
Sets the contract to legacy mode, which affects access control.

Validation

Sets whether increase orders should be validated before execution.
Returns whether increase orders should be validated.

Integration with OrderBook

The PositionManager is tightly integrated with the OrderBook contract:
Sets the OrderBook contract address.
Returns the OrderBook contract address.

Security Considerations

The PositionManager implements several security features:
  • Role-Based Access Control: Different roles for order execution and liquidation
  • Price Validation: Ensures that positions are executed at reasonable prices
  • Integration Validation: Validates interaction with other contracts
  • Error Handling: Comprehensive error handling for various failure scenarios
Only approved liquidators can liquidate positions when in private liquidation mode.

Example Usage

1

Increasing a Position

A trader wants to open a 5x long ETH position with 1 ETH as collateral.
2

Decreasing a Position

Later, the trader wants to close half of the position.
3

Executing an Order

An order keeper notices a pending increase order that meets its execution conditions.

Legacy Mode

The PositionManager includes a legacy mode feature:
In legacy mode, certain access control restrictions are relaxed, making the PositionManager backward compatible with earlier versions. This feature is typically used during protocol upgrades when necessary to maintain compatibility.