ShortsTracker
The ShortsTracker contract is a specialized component of the Satoshi Perps protocol that tracks global short positions. It maintains an accurate record of short position sizes and average prices, which is essential for funding rate calculations and protocol health monitoring.Contract Overview
The ShortsTracker handles:- Tracking global short position sizes for each token
- Calculating average entry prices for short positions
- Providing data for funding rate calculations
- Ensuring accurate short interest accounting
The ShortsTracker complements the Vault’s native tracking of long positions by providing specialized tracking for short positions across the protocol.
Key Functions
Position Tracking
State Access
Administration
Global Short Tracking Mechanism
The ShortsTracker integrates with the Vault to access and track two key pieces of data for each token:- Global Short Size: The total USD value of all short positions (stored in the Vault)
- Global Short Average Price: The average entry price of all short positions (stored in the Vault)
1
Position Increase
When a short position is increased, the tracker:
- Calculates the new global size by adding the position size delta
- Updates the average price based on the weighted average of existing positions and the new position
2
Position Decrease
When a short position is decreased, the tracker:
- Reduces the global size by the position size delta
- Maintains the average price (since decreasing positions doesn’t change the average entry price)
Integration with Vault and Other Contracts
The ShortsTracker integrates with several core contracts:- Vault: The Vault reads the global short data for funding rate calculations
- PositionManager and PositionRouter: These contracts notify the ShortsTracker when short positions change
- BasePositionManager: Acts as a handler to update the global short data
Security Considerations
The ShortsTracker implements several security features:- Access Control: Only authorized handlers can update the global short data
- Data Validation: Validates that size deltas and prices are reasonable
- Global State Management: Provides a centralized source of truth for short position data
Accurate short position tracking is critical for proper funding rate calculations. Inaccuracies could lead to incorrect funding payments between longs and shorts.
Example Usage
Data Migration and Readiness
The ShortsTracker includes features for data migration and readiness:Benefits of Dedicated Short Tracking
Having a dedicated ShortsTracker contract provides several benefits:- Specialized Logic: Optimized for tracking short positions specifically
- Gas Efficiency: Reduces gas costs by separating short tracking from the main Vault
- Easier Upgrades: Can be upgraded independently of the core Vault contract
- Better Reporting: Provides clear data points for protocol monitoring and analytics