Flash Actions
Step-by-step guide to building atomic strategies with Lotus flash loans and callbacks, including leveraged positions, refinancing, and collateral swaps.
Minimal Flash Loan Callback
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ILotusFlashLoanCallback} from "lotus/src/interfaces/ILotusCallbacks.sol";
import {ILotus} from "lotus/src/interfaces/ILotus.sol";
import {IERC20} from "openzeppelin/token/ERC20/IERC20.sol";
contract FlashArbitrage is ILotusFlashLoanCallback {
ILotus public immutable lotus;
constructor(address _lotus) {
lotus = ILotus(_lotus);
}
function execute(address token, uint256 amount) external {
bytes memory data = abi.encode(token, msg.sender);
lotus.flashLoan(token, amount, data);
}
function onLotusFlashLoan(uint256 assets, bytes calldata data) external {
require(msg.sender == address(lotus), "unauthorized");
(address token, address initiator) = abi.decode(data, (address, address));
// --- Custom logic here ---
// Swap, arbitrage, or compose other operations.
// The full `assets` amount must be repayable by the end.
// Approve Lotus to reclaim the tokens (no fee).
IERC20(token).approve(address(lotus), assets);
}
}Element
Description
See Also
Last updated

