Core Contract Architecture
Our current system consists of two primary smart contracts working in tandem: FlashLeverageCore The core engine that powers our leveraged yield strategies:- Flash Loan Orchestration: Executes complex multi-step leverage operations in a single transaction
- Dynamic Loan Calculation: Automatically calculates optimal loan amounts based on collateral value and LTV ratios
- Risk Management: Implements liquidation buffer (
i_liquidationBuffer) and slippage protection (i_slippageBuffer) to protect positions - Position State Management: Tracks collateral amounts and borrowed shares for each user proxy through isolated
CoreLeveragePositionstructs - Oracle Integration: Uses Morpho’s
IOraclefor real-time price feeds and accurate position valuation
leverage()- Creates/modifies leveraged positions via flashloan mechanicsunleverage()- Closes positions and returns profits to userscalcLeverageFlashLoan()- Determines optimal borrowing amounts based on desired LTVgetMaxLtv()- Returns safe LTV ratios with built-in liquidation protection
- Automatic Token Swapping: Integrates with Pendle router for seamless token-to-PT conversions
- Position Registry: Maintains complete user position history with
LeveragePositionstructs - Yield Fee Management: Collects 10% performance fee on profits through treasury system
- Gas Efficiency: Combines multiple operations into single transactions
swapAndLeverage()- One-click leveraging with automatic token conversionleverage()- Direct leveraging with prepared collateralunleverage()- Position closure with profit distributiongetUserLeveragePositions()- Complete position portfolio querying