Deleverage / Fold
Last updated
Last updated
Curvance's position management system offers sophisticated leveraging and deleveraging capabilities across various asset types and DeFi protocols. This document explains the process of unwinding (deleveraging) a position.
The deleveraging system consists of several interconnected components:
Position Management Base: Core contract defining the leverage/deleverage interface
Protocol-Specific Implementations: Extensions for specific DeFi protocols (Pendle, Velodrome, etc.)
Market Manager: Tracks account positions and validates liquidity status
EToken and PToken Contracts: Manage borrowing and collateral positions
The position unwinding flow follows these key steps:
Initiation: User calls deleverage()
with parameters defining:
Position Token Withdrawal:
The system calls withdrawByPositionManagement()
on the position token
This withdraws the specified collateral amount and triggers callback for specialized handling
Collateral Conversion:
If collateral and debt tokens differ, swapping occurs
Protocol-specific implementations define unique swapping logic
Different adapters handle various protocols (Pendle, Velodrome, Simple swaps)
Debt Repayment:
The converted collateral is used to repay the user's debt
The system calls repay()
on the borrow token
Asset Return:
Any remaining collateral underlying is transferred back to user
Any swap dust from intermediate tokens is also returned
When unwinding a leveraged position, the account's state transitions through:
The system validates that:
Position is valid for deleveraging
Repayment amount is within bounds
Final position remains solvent
User has permission to execute the operation
Curvance supports several protocol-specific position management implementations:
PositionManagementSimple: Basic token swap deleveraging
PositionManagementVelodrome: For Velodrome/Aerodrome LP positions
PositionManagementPendlePT: For Pendle Principal Tokens
PositionManagementPendleLP: For Pendle LP token positions
Each implementation provides specialized logic for handling the unique characteristics of its respective protocol when exiting positions.
Position unwinding operations can be initiated by:
The position owner directly
A delegated address with approved permissions
The liquidation system (for under-collateralized positions)
To prevent excessive slippage during the unwinding process:
Users specify acceptable slippage parameters
The system performs pre and post execution checks
Transactions revert if slippage exceeds user-defined limits
A typical deleveraging flow:
User has a leveraged ETH position against USDC debt
User calls deleverage to unwind part of this position
System withdraws ETH collateral from PToken vault
ETH is swapped to USDC according to swap parameters
USDC debt is repaid to the EToken contract
Any remaining ETH and swap dust is returned to the user
Token approvals are cleaned up
This mechanism allows for precise management of leveraged positions while minimizing execution risk.
Description: Deleverages an existing Curvance position to decrease both collateral and debt. Includes slippage protection through the checkSlippage
modifier.
Contract: PositionManagement
Function signature:
DeleverageStruct
deleverageData
Structure containing deleverage operation details including position token, collateral amount, borrow token, swap data, repay amount, and auxiliary data
uint256
slippage
Slippage accepted by the user for the deleverage action, in WAD (1e18)
Description: Deleverages an existing Curvance position on behalf of another account via delegation. Includes slippage protection through the checkSlippage
modifier. Requires delegation approval from the account being deleveraged for.
Contract: PositionManagement
Function signature:
DeleverageStruct
deleverageData
Structure containing deleverage operation details including position token, collateral amount, borrow token, swap data, repay amount, and auxiliary data
address
account
The account to deleverage an active Curvance position for
uint256
slippage
Slippage accepted by the user for the deleverage action, in WAD (1e18)