Example Implementation
Here's a basic example of a flash loan receiver for arbitrage:
contract ArbitrageFlashLoanReceiver is IFlashLoanReceiver {
address public immutable fiveProtocol;
constructor(address _fiveProtocol) {
fiveProtocol = _fiveProtocol;
}
function executeOperation(
address[] calldata tokens,
uint256[] calldata amounts,
uint256[] calldata fees,
address initiator,
bytes calldata params
) external override returns (bool) {
// Ensure caller is the Five Protocol
require(msg.sender == fiveProtocol, "Unauthorized");
require(initiator == address(this), "Unauthorized initiator");
// Perform arbitrage operations here
// ...
// Approve repayment of flash loan + fee
for (uint i = 0; i < tokens.length; i++) {
uint amountOwed = amounts[i] + fees[i];
IERC20(tokens[i]).approve(fiveProtocol, amountOwed);
}
return true;
}
function executeArbitrage(
address[] calldata tokens,
uint256[] calldata amounts
) external {
// Call flash loan
IFiveProtocol(fiveProtocol).flashLoan(
address(this),
tokens,
amounts,
bytes("")
);
}
}
Introduction
Last updated