Deleveraging
Understanding Deleveraging
Preparing for Deleveraging
Constructing the DeleverageAction struct
// Define how much collateral to withdraw
const collateralAmount = ethers.utils.parseUnits('300', 18);
const repayAmount = ethers.utils.parseUnits('200', 18); // Amount of debt to repay
// Create swap data to convert collateral to borrow asset
// Note: This is an array of swaps, allowing for multi-hop routes
const swapData = [{
target: '0x1111111254EEB25477B68fb85Ed929f73A960582', // 1inch router
inputToken: underlyingAsset,
outputToken: borrowUnderlying,
inputAmount: ethers.utils.parseUnits('250', 18), // Amount needed to convert to repay debt
call: '0x...', // Encoded swap call data
}];
// Construct deleverage struct
const deleverageAction = {
cToken: COLLATERAL_CTOKEN,
collateralAssets: collateralAmount,
borrowedToken: BORROWED_CTOKEN,
swapData: swapData,
repayAmount: repayAmount,
auxData: '0x' // Optional for specialized protocols
};Executing the Deleverage Operation
Important Considerations
Last updated
Was this helpful?