pragma solidity 0.6.6; pragma experimental ABIEncoderV2; import "https://github.com/sushiswap/sushiswap/blob/master/contracts/uniswapv2/interfaces/IUniswapV2Router02.sol"; import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/FlashLoanReceiverBase.sol"; import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/ILendingPoolAddressesProvider.sol"; import "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/ILendingPool.sol"; struct Swap { address pool; address tokenIn; address tokenOut; uint swapAmount; // tokenInAmount / tokenOutAmount uint limitReturnAmount; // minAmountOut / maxAmountIn uint maxPrice; } interface IBalancerProxy { function smartSwapExactIn(TokenInterface tokenIn, TokenInterface tokenOut, uint totalAmountIn, uint minTotalAmountOut, uint nPools) external payable returns (uint totalAmountOut); function viewSplitExactIn(address tokenIn, address tokenOut, uint swapAmount, uint nPools) external returns (Swap[] memory swaps, uint totalOutput); function batchSwapExactIn( Swap[] calldata swaps, TokenInterface tokenIn, TokenInterface tokenOut, uint totalAmountIn, uint minTotalAmountOut ) external payable returns (uint totalAmountOut); } contract SimpleStore { function swap(uint firstLeg, uint secondLeg, uint amount, address tokenIn, address tokenOut) public payable { IERC20 ERC20TokenIn = IERC20(tokenIn); IERC20 ERC20TokenOut = IERC20(tokenOut); TokenInterface TIERC20TokenIn = TokenInterface(tokenIn); TokenInterface TIERC20TokenOut = TokenInterface(tokenOut); Swap[] memory swaps; //(Swap[] memory _swaps, _myBalamountOut) = BalancerProxy.viewSplitExactIn(tokenIn, tokenOut, amount, 10); (swaps ,myBalamountOut) = BalancerProxy.viewSplitExactIn(tokenIn, tokenOut, amount, 10); //TIERC20TokenIn.approve(address(BalancerProxy), amount); //balancerPayable.transfer(amount); _wrapEth(amount); WETH.approve(address(BalancerProxy), amount); //totalAmountOut = BalancerProxy.batchSwapExactIn{value: amount}(swaps, ERC20TokenIn, ERC20TokenOut, amount, myBalamountOut); totalAmountOut = BalancerProxy.smartSwapExactIn(TIERC20TokenIn, TIERC20TokenOut, amount, myBalamountOut, 10); } }
0.6.6