Canonical patterns for composing Lotus actions including leveraged loops, tranche refinancing, collateral swaps, and liquidation bot recipes with code examples.
This page outlines canonical flows using Lotus building blocks. Use them as starting points and adapt to your needs.
Leveraged Loop with Flash Actions
A leveraged loop increases position size atomically without interim risk by borrowing via a flash loan and immediately collateralizing the proceeds.
Notes: check free supply constraints; accrue interest for accuracy if needed.
Collateral Swap with Bounds
A collateral swap replaces the collateral asset backing a position while maintaining loan health throughout the transaction.
Steps: flashLoan → repay → withdraw old collateral → swap → supply new collateral → borrow → repay flash.
Notes: enforce swap slippage limits; recheck health after each leg.
Security Tips
Keep callbacks minimal and non‑reentrant; whitelist tokens and markets.
Validate amounts, health, and free supply before finalizing.
Prefer pull patterns and safe transfer libraries.
Liquidation Bot
A liquidation bot monitors borrower positions and executes profitable liquidations when positions become unhealthy.
Steps: index borrowers → compute health per tranche → encode lmData with BaseLiquidationParams → call liquidate → optionally use flash-funded callback.
Notes: see Liquidation Bot for a complete implementation with code.