Leverage
Leveraging in Curvance allows users to amplify their position by borrowing assets against their collateral and reinvesting them. This creates a more capital-efficient position with greater exposure to underlying assets. Curvance's leveraging system is built on its powerful Position Management framework, which simplifies complex DeFi operations into single, atomic transactions. This eliminates the manual loop of borrowing, swapping, and depositing that would otherwise be required to build leveraged positions.
View functions inside ProtocolReader provide handy data needed to calculate proper swap and leverage amounts.
Core Structures for Leveraging
To understand leveraging in Curvance, you need to be familiar with two key data structures that control the leverage and deleverage operations:
LeverageAction
struct LeverageAction {
IBorrowableCToken borrowToken; // The cToken you want to borrow from.
uint256 borrowAssets; // Amount of underlying tokens to borrow.
ICToken cToken; // cToken that will receive the swapped assets.
SwapperLib.Swap swapData; // Instructions for swapping borrowed tokens.
bytes auxData; // Optional protocol-specific data.
}DeleverageAction
struct DeleverageAction {
ICToken cToken; // The cToken you're unwinding
uint256 collateralAmount; // Amount of cTokens to redeem
IBorrowableCToken borrowToken; // The cToken debt to repay
SwapperLib.Swap[] swapData; // Array of swaps to execute
uint256 repayAmount; // Amount of debt to repay
bytes auxData; // Optional protocol-specific data
}SwapperLib.Swap
Both structures use the SwapperLib.Swap structure to handle token swaps:
Important Note: LeverageStruct takes a single Swap while DeleverageStruct takes an array of Swap operations, allowing for multi-hop swaps when deleveraging.
Pre, Post, and Auxiliary Swap Operations
Pre-Swap when Leveraging
When leveraging, a swap is executed to obtain the collateral asset using the borrowed asset. You must provide the appropriate calldata hex string in the Swap.call struct member. Additionally, ensure the swap's receiver is set to the corresponding PositionManager contract.
Post-Swap when Deleveraging
During deleveraging, a swap is performed to exchange the collateral asset for the borrowed asset. You need to supply the correct calldata hex string in the Swap.call struct member. Also, make sure the swap's receiver is configured as the relevant PositionManager contract.
Auxiliary Swap for Complex Assets
When leveraging or deleveraging exotic assets, you may need to include auxiliary data to initiate the position. For instance, to enter a Pendle PT position, you must provide swap data to exchange the borrowed asset for Pendle PT via Pendle’s internal exchange.
Below is a code snippet demonstrating how to prepare this data:
Setting Up Your Environment
Before interacting with Curvance, set up your development environment:
Monitoring Position Health
Maintaining a healthy leverage ratio is crucial to avoid liquidation. Regularly check your position's health by using getPositionHealth() in the ProtocolReader contract. The function returns the healthiness of an account's position.
Last updated