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
  • 1. Initial Deposit and Leverage
  • 2. Leveraging an Existing Position
  • Important Considerations
Export as PDF
  1. Developer Docs
  2. Quick Start Guides
  3. Leverage

Leveraging

1. Initial Deposit and Leverage

The most common approach is to deposit and leverage in a single transaction. This is ideal for users who want to create a leveraged position from scratch.

Preparing for Leverage

Before leveraging, you need to:

  1. Understand your target position: Determine the collateral asset, borrow asset, and desired leverage ratio.

  2. Set an appropriate slippage tolerance: Typically 0.5-2% depending on asset volatility.

  3. Approve the necessary contracts: Your collateral token must approve the Position Management contract.

Here's how to prepare the deposit and leverage transaction:

// Approve the position management contract to spend your tokens if depositing and leveraging in one transaction
const underlyingContract = new ethers.Contract(
  underlyingAsset,
  UNDERLYING_ABI,
  signer
);
const depositAmount = ethers.utils.parseUnits('1000', 18); // Adjust amount and decimals
await underlyingContract.approve(POSITION_MANAGEMENT, depositAmount);

Constructing the LeverageStruct

The key to a successful leverage operation is properly constructing the LeverageStruct:

// Create the swap data structure
// This example uses 1inch swap data, but any DEX can be used
const swapData = {
  target: '0x1111111254EEB25477B68fb85Ed929f73A960582', // 1inch router
  inputToken: COLLATERAL_ASSET_UNDERLYING,
  outputToken: BORROWED_ASSET_ADDRESS,
  inputAmount: ethers.utils.parseUnits('500', 18), // Amount to borrow and swap
  call: '0x...', // Encoded swap call data from 1inch API
};

// Construct the leverage struct
const leverageData = {
  borrowToken: E_TOKEN,
  borrowAmount: ethers.utils.parseUnits('500', 18),
  positionToken: P_TOKEN,
  swapData: swapData,
  auxData: '0x' // Optional auxiliary data for specialized protocols
};

Executing the Leverage Operation

With the LeverageStruct prepared, execute the leverage operation:

// Set slippage tolerance (1%)
const slippage = ethers.utils.parseUnits('0.01', 18);

// Execute deposit and leverage in one transaction
const tx = await positionManagement.depositAndLeverage(
  depositAmount,
  leverageData,
  slippage,
  2000000
);

const receipt = await tx.wait();
console.log(`Leveraged position created! Tx hash: ${receipt.transactionHash}`);

2. Leveraging an Existing Position

If you already have collateral deposited, you can increase your leverage without an additional deposit:

const tx = await positionManagement.leverage(
  leverageData, // Same structure as above
  slippage,
  2000000
);

const receipt = await tx.wait();
console.log(`Position further leveraged! Tx hash: ${receipt.transactionHash}`);

Important Considerations

  1. Position Health and Risk Management:

    1. Monitor your position's health factor before and after leveraging.

    2. Consider the maximum leverage ratio allowed by the protocol.

    3. Be aware of liquidation risks when increasing leverage.

    4. Calculate the minimum collateral required to maintain a safe position.

  2. Swap Data Configuration:

    1. The swapData must accurately reflect the desired swap route.

    2. Ensure the inputAmount matches the borrowAmount in the leverage struct.

    3. Set appropriate slippage tolerance for the swap (typically 0.3-1% for stable pairs, 1-3% for volatile pairs).

  3. Amount Calculations:

    1. Ensure these amounts are properly calculated to achieve desired leverage ratio.

    2. Consider protocol fees when calculating amounts.

  4. Protocol-Specific Features:

    1. Some protocols may require additional data in the auxData field.

    2. Check protocol documentation for specific requirements.

PreviousLeverageNextDeleveraging

Last updated 9 days ago