Curvance
  • Protocol Overview
    • Click Less, Earn More
    • Protocol Architecture
    • Asset Types
    • Liquidity Markets
      • Borrowing
      • Liquidations
      • Interest Rates
      • Oracles
      • Collateral Caps
      • Bad Debt Socialization
    • Application Specific Sequencing
    • New Age Liquidity Mining
      • Protocols
    • How Are New Assets Integrated
    • Plugin System
    • Universal Account Balance
    • Token Approval Management
    • Lending Risks
  • Security
    • Security and Audits
  • Miscellaneous
    • RPCs and Testnet Stability
    • Glossary
    • TL;DR
      • Customer Types and Benefits
    • Brand Assets
    • Weblinks
    • Disclaimer
    • Frequently Asked Questions
  • Developer Docs
    • Overview
    • Quick Start Guides
      • Atlas Fastlane Auctions (coming soon)
      • Plugin Integration
        • List of Delegable Actions
      • Loans & Collateral
        • Lend Assets
        • Deposit into pTokens
        • Withdraw Loans
        • Withdraw pTokens
      • Borrowing & Repayment
        • Borrow
        • Repaying Debt
      • Leverage
        • Leveraging
        • Deleveraging
    • Lending Protocol
      • Market Manager
      • Position Tokens (pToken)
      • Earn Tokens (eTokens)
      • Dynamic Interest Rate Model
      • Universal Balance
    • Position Management
      • Leverage
      • Deleverage / Fold
    • Dynamic Liquidation Engine (DLE)
      • Orderflow Auction System
      • Bad Debt Socialization
    • Plugin & Delegation System
      • Transfer Lock Mechanism
      • Delegable Actions
    • Cross-Chain Functionality
      • Messaging Hub
      • Fee Manager
      • Reward Manager
    • Auxiliary Functionality
Powered by GitBook
On this page
  • Overview
  • Key Components
  • Deleverage Process Flow
  • State Transitions
  • Protocol-Specific Implementations
  • Access Control and Delegation
  • Slippage Protection
  • Example Flow
  • User Interaction Functions
Export as PDF
  1. Developer Docs
  2. Position Management

Deleverage / Fold

PreviousLeverageNextDynamic Liquidation Engine (DLE)

Last updated 4 days ago

Overview

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.

Key Components

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.

Deleverage Process Flow

The position unwinding flow follows these key steps:

Data Flow

  1. Initiation: User calls deleverage() with parameters defining:

  2. Position Token Withdrawal:

    1. The system calls withdrawByPositionManagement() on the position token.

    2. This withdraws the specified collateral amount and triggers callback for specialized handling.

  3. Collateral Conversion:

    1. If collateral and debt tokens differ, swapping occurs.

    2. Protocol-specific implementations define unique swapping logic.

    3. Different adapters handle various protocols (Pendle, Velodrome, Simple swaps).

  4. Debt Repayment:

    1. The converted collateral is used to repay the user's debt.

    2. The system calls repay() on the borrow token.

  5. Asset Return:

    1. Any remaining collateral underlying is transferred back to user.

    2. Any swap dust from intermediate tokens is also returned.

State Transitions

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.

Protocol-Specific Implementations

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.

Access Control and Delegation

Position unwinding operations can be initiated by:

  • The position owner directly.

  • A delegated address with approved permissions.

  • The liquidation system (for under-collateralized positions).

Slippage Protection

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.

Example Flow

A typical deleveraging flow:

  1. User has a leveraged ETH position against USDC debt.

  2. User calls deleverage to unwind part of this position.

  3. System withdraws ETH collateral from PToken vault.

  4. ETH is swapped to USDC according to swap parameters.

  5. USDC debt is repaid to the EToken contract.

  6. Any remaining ETH and swap dust is returned to the user.

  7. Token approvals are cleaned up.

This mechanism allows for precise management of leveraged positions while minimizing execution risk.

User Interaction Functions

deleverage()

Description: Deleverages an existing Curvance position to decrease both collateral and debt. Includes slippage protection through the checkSlippage modifier.

Contract: PositionManagement

Function signature:

function deleverage(
    DeleverageStruct calldata deleverageData,
    uint256 slippage
) external checkSlippage(msg.sender, slippage) nonReentrant
Type
Name
Description

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).

Events:

// In EToken.sol
event Repay(address payer, address account, uint256 amount);
event Transfer(address indexed from, address indexed to, uint256 value);
// In MarketManager.sol
event CollateralRemoved(address account, address pToken, uint256 amount);
// Only emitted if the positionis being completely closed
event TokenPositionClosed(address mToken, address account);

deleverageFor()

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:

function deleverageFor(
    DeleverageStruct calldata deleverageData,
    address account,
    uint256 slippage
) external checkSlippage(account, slippage) nonReentrant
Type
Name
Description

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).

Events:

// In EToken.sol
event Repay(address payer, address account, uint256 amount);
event Transfer(address indexed from, address indexed to, uint256 value);
// In MarketManager.sol
event CollateralRemoved(address account, address pToken, uint256 amount);
// Only emitted if the positionis being completely closed
event TokenPositionClosed(address mToken, address account);