You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi i creating arbitrage bot using Solidity in Hardhat and i created smart contract which take aave flashloan make 2 swaps and repay flashloan itself and i got error when i tried to compile smart contract
Solidity version ^0.6.12
Hardhat version ^2.19.4
Operating System Windows 11
Code:
// SPDX-License-Identifier: MITpragma solidity^0.6.12;
import"@aave/protocol-v2/contracts/interfaces/ILendingPool.sol";
import"@aave/protocol-v2/contracts/interfaces/ILendingPoolAddressesProvider.sol";
import"@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import"@openzeppelin/contracts/math/SafeMath.sol";
import"@openzeppelin/contracts/token/ERC20/IERC20.sol";
import"@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import"@openzeppelin/contracts/utils/Context.sol";
contractArbitrageBot1isContext, ReentrancyGuard {
using SafeMathforuint256;
ILendingPoolAddressesProvider provider;
ILendingPool lendingPool;
IUniswapV2Router02 uniswapRouter;
IUniswapV2Router02 sushiSwapRouter;
addressprivate owner;
constructor(
address_provider,
address_uniswapRouter,
address_sushiSwapRouter
) public {
provider =ILendingPoolAddressesProvider(_provider);
lendingPool =ILendingPool(provider.getLendingPool());
uniswapRouter =IUniswapV2Router02(_uniswapRouter);
sushiSwapRouter =IUniswapV2Router02(_sushiSwapRouter);
owner =msg.sender;
}
modifier OnlyOwner() {
require(msg.sender== owner);
_;
}
function borrowAndSwap(
uint256_amount,
uint256amountOutExpected,
uint256amountOutExpected2,
addresscoin1,
addresscoin2
) external nonReentrant {
lendingPool.borrow(coin1, _amount, 1, 0, address(this));
address[] memory path2 =newaddress[](2);
path2[0] = coin1;
path2[1] = coin2;
sushiSwapRouter.swapExactTokensForTokens(
_amount,
amountOutExpected,
path2,
address(this),
block.timestamp
);
address[] memory path =newaddress[](2);
path[0] = coin2;
path[1] = coin1;
uniswapRouter.swapExactTokensForTokens(
IERC20(coin2).balanceOf(address(this)),
amountOutExpected2,
path,
address(this),
block.timestamp
);
// Get the borrow rate
DataTypes.ReserveData memory reserveData = lendingPool.getReserveData(
coin1
);
uint256 borrowRate = reserveData.currentVariableBorrowRate;
// Calculate the amount of interestuint256 interest = _amount.mul(borrowRate).div(1e27);
// Calculate the total amount to repayuint256 amountToRepay = _amount.add(interest);
// Approve the lending pool to transfer the repayment amountIERC20(coin1).approve(address(lendingPool), amountToRepay);
// Repay the borrowed amount
lendingPool.repay(coin1, amountToRepay, 1, address(this));
}
function withdrawWETH(addressoutCoin) external OnlyOwner {
require(
IERC20(outCoin).balanceOf(address(this)) >0,
"No funds to withdraw"
);
IERC20(outCoin).transfer(
owner,
IERC20(outCoin).balanceOf(address(this))
);
}}
And error:
$ npx hardhat compile
InternalCompilerError: Internal compiler error (C:\projects\solidity\libsolidity\codegen\CompilerUtils.cpp:1441)
Error HH600: Compilation failed
For more info go to https://hardhat.org/HH600 or run Hardhat with --show-stack-traces
The text was updated successfully, but these errors were encountered:
We always consider an internal compiler error (ICE) to be a bug (usually a low priority one), so thanks for the report. @Xardesso can you please post the exact version of the compiler you were using? ^0.6.12 just means higher than 0.6.12, so I assume you weren't using 0.6.x, since those are fairly old.
Looks like it might have already been reported in #12114 but that issue was closed by the user because they found a workaround. The ICE might still be there though - we should try to reproduce on 0.8.23 (but with abicoder v1 since it's no longer the default).
Hi i creating arbitrage bot using Solidity in Hardhat and i created smart contract which take aave flashloan make 2 swaps and repay flashloan itself and i got error when i tried to compile smart contract
Code:
And error:
The text was updated successfully, but these errors were encountered: