Skip to main content
The protocol is split into several contracts with clean separation of responsibilities. FlashLeverage is the main contract that users interact with. It handles the full position lifecycle - opening, adjusting, and closing positions. It also manages fees, LTV validation, UserProxy creation, and market configuration. It inherits from MarketPositionManager, SwapManager, ReentrancyGuard, and Ownable2Step. MarketPositionManager is an abstract base that handles all the Morpho protocol interactions. Flash loan callbacks, supplying collateral, borrowing, repaying, withdrawing - all the low-level Morpho plumbing lives here. It also stores market parameters and provides view functions for querying positions and share values. SwapManager manages token swaps through whitelisted external routers. It doesn’t have its own AMM logic. Instead, it delegates swaps to aggregators like KyberSwap, ODOS, or Pendle Router using encoded calldata. Before executing any swap, it checks the router is approved and verifies the output meets the minTokenOut slippage threshold. UserProxy is a minimal clone contract deployed per position using EIP-1167. Each one holds a user’s Morpho position (collateral + debt) in isolation. Normally only FlashLeverage can call it, but if Manual Mode is activated, the position owner can call it directly. There’s also a 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.

Constants

The liquidation buffer is 2.5% (hardcoded, immutable). This gets subtracted from the Morpho market’s liquidation LTV to set the max LTV the protocol allows. So if a market liquidates at 90% LTV, the protocol caps you at 87.5%. Max yield fee is 10%. Max deposit fee is 1%. Both are adjustable by the owner within those caps.