Position Management
Overview
The Position Management system is a core component of Curvance's lending protocol, enabling advanced leverage and deleverage operations for user positions. It provides a structured way for users to manage complex DeFi positions across multiple asset types while maintaining protocol safety.
Architecture Design

Core Components
PositionManagementBase
The abstract base contract provides the core functionality for all position management implementations. It includes:
Common state variables and constants.
Core leverage/deleverage logic.
Safety checks and fee calculations.
Market status queries and calculations.
Standard integration points with other protocol components.
Specialized Implementations
Each implementation extends the base functionality to support specific asset types:
PositionManagementSimple: Basic implementation for standard tokens with simple swap requirements.
PositionManagementPendlePT: Specialized for Pendle Principal Tokens, handling their unique yield token mechanics.
PositionManagementPendleLP: Manages positions for Pendle liquidity provider tokens.
PositionManagementVelodrome: Handles Velodrome AMM-specific operations..
PositionManagementAerodrome: Extends Velodrome implementation for Aerodrome protocol
Key Data Structures
LeverageStruct
struct LeverageStruct {
IEToken borrowToken;
uint256 borrowAmount;
IPToken positionToken;
SwapperLib.Swap swapData;
bytes auxData;
}
Encapsulates all data needed for a leverage operation, including which token to borrow, how much to borrow, and which position token to leverage against.
DeleverageStruct
struct DeleverageStruct {
IPToken positionToken;
uint256 collateralShares;
IEToken borrowToken;
SwapperLib.Swap[] swapData;
uint256 repayAmount;
bytes auxData;
}
Contains data for deleverage operations, specifying which collateral to liquidate and how to route funds to repay debt.
Integration Points
The Position Management system interacts with multiple components of the Curvance ecosystem:
MarketManager: For checking account status, debt limits, and collateral values.
CentralRegistry: For protocol-wide configuration and permissions.
PTokens: Position tokens that serve as collateral.
ETokens: Debt tokens that users borrow from.
SwapperLib: For executing token swaps during leverage/deleverage operations.
External Protocols: Direct integrations with Pendle, Velodrome, and other DeFi protocols.
Security Features
The Position Management architecture implements several security features:
Slippage Protection: Ensures executed trades don't lose value beyond user-specified thresholds.
Sanity Checks: Validates all operations against user account status and market constraints.
Maximum Leverage Limits: Prevents users from taking on excessive risk.
Fee Calculations: Ensures protocol takes appropriate fees for providing leverage services.
Reentrancy Protection: Guards against reentrancy attacks during complex operations.
Protocol Interactions
During position management operations, the system follows these general steps:
Validation: Check that the requested operation is valid for the user's account.
Calculation: Determine limits, risks, and required amounts.
Execution: Perform necessary token transfers, borrows, or repayments.
Swapping: Convert between token types as needed using appropriate swap routes.
Position Update: Update the user's collateral and debt positions.
Fee Handling: Calculate and collect protocol fees.
This architecture enables Curvance to support complex leverage strategies across diverse asset types while maintaining protocol security and risk parameters.
Last updated