Flash Actions

Step-by-step guide to building atomic strategies with Lotus flash loans and callbacks, including leveraged positions, refinancing, and collateral swaps.

Flash actions let you execute complex, atomic strategies in a single transaction using flash loans and optional callbacks.

Common use cases:

  • Lever up or down a position atomically.

  • Refinance between tranches or markets.

  • Collateral swaps and liquidation integrations.

How it works:

  • Flash loan transfers assets to your contract, calls your callback, then requires repayment by the end of the transaction.

  • Supply/repay/liquidate/collateral operations accept optional callback data. When configured, Lotus calls back into your contract so you can complete multi-step flows without intermediate state risk.

┌─────────────────────────────────────────────────────────────────────┐
│              Flash Loan and Callback Sequence                       │
└─────────────────────────────────────────────────────────────────────┘

  Caller Contract          Lotus Core           Caller Callback
  ───────────────          ──────────          ───────────────

       │                      │                       │
       │  flashLoan(...)      │                       │
       ├─────────────────────►│                       │
       │                      │                       │
       │                      │  Transfer assets      │
       │◄─────────────────────┤                       │
       │                      │                       │
       │                      │  onFlashLoan(...)     │
       │                      ├──────────────────────►│
       │                      │                       │
       │                      │              Execute custom logic:
       │                      │              - Swap assets
       │                      │              - Supply collateral
       │                      │              - Borrow from tranche
       │                      │              - Arbitrage
       │                      │                       │
       │                      │    Return control     │
       │                      │◄──────────────────────┤
       │                      │                       │
       │                      │  Verify repayment     │
       │  Repay exact amount  │  (no fee)             │
       ├─────────────────────►│                       │
       │                      │                       │
       │    Success ✓         │                       │
       │◄─────────────────────┤                       │
       │                      │                       │

Integration tips:

  • Ensure callback contracts are minimal and non-reentrant with clear allowlists.

  • Validate amounts and state before returning from callbacks.

  • Prefer known-good routers and auditors’ patterns for token transfers.

See also:

  • Learn → Advanced → Flash Loans and Callbacks for protocol-level behavior.

  • Reference → Contract Addresses for deployment targets.

Last updated