So I wan’t to write an arbitrage contract but I can’t seem to figure out what this Logic part is of it. I would love to learn this part of solidity but I don’t know what to search for, if that makes any sense.
So here’s a arbitrage contract with a clear view of the part I want to learn.
pragma solidity ^0.5.0;
pragma experimental ABIEncoderV2;
import "@studydefi/money-legos/dydx/contracts/DydxFlashloanBase.sol";
import "@studydefi/money-legos/dydx/contracts/ICallee.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract DydxFlashloaner is ICallee, DydxFlashloanBase {
struct MyCustomData {
address token;
uint256 repayAmount;
}
// This is the function that will be called postLoan
// i.e. Encode the logic to handle your flashloaned funds here
function callFunction(
address sender,
Account.Info memory account,
bytes memory data
) public {
MyCustomData memory mcd = abi.decode(data, (MyCustomData));
uint256 balOfLoanedToken = IERC20(mcd.token).balanceOf(address(this));
require(
balOfLoanedToken >= mcd.repayAmount,
"Not enough funds to repay dydx loan!"
);
function arbitrageSwap(uint256 deadline, uint256 amountOutMinUniswap) external payable {
uint256 amountOutMinBancor = 1;
uint256 amountOutMinSushiSwap = 1;
}
// TODO: Encode your logic here
// E.g. arbitrage, liquidate accounts, etc
revert("Hello, you haven't encoded your logic");
}
function initiateFlashLoan(address _solo, address _token, uint256 _amount)
external
{
ISoloMargin solo = ISoloMargin(_solo);
// Get marketId from token address
uint256 marketId = _getMarketIdFromTokenAddress(_solo, _token);
// Calculate repay amount (_amount + (2 wei))
// Approve transfer from
uint256 repayAmount = _getRepaymentAmountInternal(_amount);
IERC20(_token).approve(_solo, repayAmount);
// 1. Withdraw $
// 2. Call callFunction(...)
// 3. Deposit back $
Actions.ActionArgs[] memory operations = new Actions.ActionArgs[](3);
operations[0] = _getWithdrawAction(marketId, _amount);
operations[1] = _getCallAction(
// Encode MyCustomData for callFunction
abi.encode(MyCustomData({token: _token, repayAmount: repayAmount}))
);
operations[2] = _getDepositAction(marketId, repayAmount);
Account.Info[] memory accountInfos = new Account.Info[](1);
accountInfos[0] = _getAccountInfo();
solo.operate(accountInfos, operations);
}
}
So these are the parts i’m talking about…
// i.e. Encode the logic to handle your flashloaned funds here
// TODO: Encode your logic here
I understand that I need to write logic there, but what is logic? If someone has a link for a whitepaper I can read would be amazing, a code example would be great too maybe that would help me understand what to search for.
Thanks already!