Recipes

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.

  • Steps: flashLoan loan token → supply collateral → borrow → repay flash → optional rebalance.

  • Notes: cap leverage; set slippage and price bounds; validate post‑state.

Refinance Across Tranches

Refinancing moves debt from a junior tranche to a more senior tranche in a single transaction, lowering the borrow rate without closing the position.

  • Steps: flashLoan → repay junior → borrow senior → repay flash.

  • 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.

See also:

Last updated