recover() function for retrieving tokens accidentally sent to the proxy or accumulated as rewards.
FlashLeverageRouter is a convenience contract for users who don’t already hold the collateral token. It lets you swap from a base token (like USDC) into the collateral and leverage in a single transaction.
Key functions on FlashLeverage
leverage() opens a new position. Anyone can call this on behalf of another user. It transfers in collateral, creates a UserProxy, flash-loans the borrow amount, swaps to collateral, supplies everything to Morpho, and borrows to repay the flash loan.
deleverage() closes a position. Only the position owner can call it. Flash-loans to repay debt, withdraws collateral, swaps back to loan token, takes fees from profit, returns the rest.
increaseLeverage() adds more leverage to an existing position. Position owner only. Flash-loans additional funds and adds them to the collateral.
supplyCollateral() adds collateral to reduce LTV. Anyone can call this for any position. The deposited value gets tracked for accurate fee calculation on close.
repay() pays down debt on a position. Anyone can call this. Supports repay-by-amount and repay-by-shares.
borrow() extracts loan tokens from a position. Position owner only, and only works for non-correlated pairs. This is blocked for correlated pairs because it would mess up the yield accounting used for fee calculation.
enableManualMode() is owner-only. Activates manual mode on a UserProxy so the position owner can interact with Morpho directly for emergency unwinding.