Skip to main content

BasePositionManager

The BasePositionManager is an abstract contract that serves as the foundation for position management in the Satoshi Perps protocol. It provides core functionality for increasing and decreasing positions with safety checks and fee management.

Contract Overview

The BasePositionManager handles:
  • Basic position management operations
  • Validation of position parameters
  • Fee collection for position adjustments
  • Integration with the ShortsTracker for short position monitoring
  • Global position size limits
The BasePositionManager is designed to be extended by specialized position manager contracts.

Key Functions

Core Position Functions

Internal function to increase a position with validation.
Internal function to decrease a position with validation.

Position Validation

Validates that a position does not exceed the global size limit for a token.

Fee Management

Collects fees for position adjustments based on the deposit fee rate and whether a fee should be deducted.
Transfers ETH to a receiver with a gas limit. If the transfer fails due to gas limitations, it will fall back to sending WETH instead.

Token Swapping

Executes a token swap through the Router.

Integration Points

The BasePositionManager integrates with several core contracts:
  • Vault: For position storage and management
  • Router: For plugin authorization and token swaps
  • ShortsTracker: For tracking global short positions
  • ReferralStorage: For handling affiliate referrals

Global Size Limits

The BasePositionManager implements limits on the maximum global position size:
Sets the maximum global long and short sizes for a list of tokens.
Returns the maximum global long size for a token.
Returns the maximum global short size for a token.

Fee Configuration

Sets the deposit fee basis points.
Returns the current deposit fee basis points.

Security Considerations

The BasePositionManager includes several security features:
  • Access Control: Only authorized plugins can execute position changes
  • Position Validation: Ensures positions do not exceed global limits
  • Fee Handling: Properly accounts for fees in position calculations
  • Error Handling: Includes proper error messages for various failure cases
As a base contract, BasePositionManager is not meant to be used directly by users, but rather extended by more specialized position managers.

Inheritance and Extension

The BasePositionManager is designed to be inherited by concrete implementations like PositionManager. When extending BasePositionManager, implementers should:
  1. Implement user-facing methods for position management
  2. Add appropriate access controls
  3. Implement any additional specialized functionality
Example extension pattern: