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
  • Architecture Design
  • Core Components
  • Key Data Structures
  • Integration Points
  • Security Features
  • Protocol Interactions
Export as PDF
  1. Developer Docs

Position Management

PreviousUniversal BalanceNextLeverage

Last updated 15 days ago

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.