InternalCompilerError: Internal compiler error
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
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:
```Solidity
// SPDX-License-Identifier: MIT
pragma 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";
contract ArbitrageBot1 is Context, ReentrancyGuard {
using SafeMath for uint256;
ILendingPoolAddressesProvider provider;
ILendingPool lendingPool;
IUniswapV2Router02 uniswapRouter;
IUniswapV2Router02 sushiSwapRouter;
address private 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,
uint256 amountOutExpected,
uint256 amountOutExpected2,
address coin1,
address coin2
) external nonReentrant {
lendingPool.borrow(coin1, _amount, 1, 0, address(this));
address[] memory path2 = new address[](2);
path2[0] = coin1;
path2[1] = coin2;
sushiSwapRouter.swapExactTokensForTokens(
_amount,
amountOutExpected,
path2,
address(this),
block.timestamp
);
address[] memory path = new address[](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 interest
uint256 interest = _amount.mul(borrowRate).div(1e27);
// Calculate the total amount to repay
uint256 amountToRepay = _amount.add(interest);
// Approve the lending pool to transfer the repayment amount
IERC20(coin1).approve(address(lendingPool), amountToRepay);
// Repay the borrowed amount
lendingPool.repay(coin1, amountToRepay, 1, address(this));
}
function withdrawWETH(address outCoin) external OnlyOwner {
require(
IERC20(outCoin).balanceOf(address(this)) > 0,
"No funds to withdraw"
);
IERC20(outCoin).transfer(
owner,
IERC20(outCoin).balanceOf(address(this))
);
}}
```
And error:
```bash
$ 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
Contributor guide
Research direction
Reproduce the failure with `npx hardhat compile` using the supplied Solidity contract and environment details. Start at `libsolidity/codegen/CompilerUtils.cpp:1441`, then reduce the contract and imports to identify the smallest triggering case; done means a reproducible compiler issue or a confirmed fix with compilation succeeding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100