Multicall
Batch transaction with InfinitCore's multicall.
// Example multicall function
function executeMulticall(uint256 posId, address lendingPoolA, uint256 borrowAAmount, address lendingPoolB, uint256 lendingBAmount) external returns (bytes[] memory results) {
// 0. .. perform necessary actions for example pulling tokens from the caller ..
// 1. build multicall bytes data
// Example: 1) borrow tokenA, 2) lend tokenB, 3) collateralize the deposited tokenB
bytes[] memory calls = new bytes[](3);
// build data for step 1)
calls[0] = abi.encodeWithSelector(IInfinitCore.borrow.selector, lendingPoolA, borrowAAmount, posId, address(this));
// build data for step 2) β mint directly to position manager
IERC20(ILendingPool(lendingPoolB).underlyingToken()).safeTransfer(lendingPoolB, lendingBAmount); // transfer underlying token to lending pool directly for mint
calls[1] = abi.encodeWithSelector(IInfinitCore.mintTo.selector, lendingPoolB, POS_MANAGER);
// build data for step 3)
calls[2] = abi.encodeWithSelector(IInfinitCore.collateralize.selector, posId, lendingPoolB);
results = IInfinitCore(INFINIT_CORE).multicall(calls);
}Last updated