我正在浏览AAVE v2闪存贷款文档,并尝试他们的闪存贷款锅炉板代码。我将编译器版本升级到了0.8.0。我收到以下错误消息
TypeError: Type contract ILendingPool is not implicitly convertible to expected type uint256.
--> contracts/MyFlashLoan.sol:36:46:
|
36 | IERC20(assets[i]).approve(address[LENDING_POOL], amountOwing);
| ^^^^^^^^^^^^
TypeError: Invalid type for argument in function call. Invalid implicit conversion from type(address[1] memory) to address requested.
--> contracts/MyFlashLoan.sol:36:38:
|
36 | IERC20(assets[i]).approve(address[LENDING_POOL], amountOwing);
| ^^^^^^^^^^^^^^^^^^^^^
Error HH600: Compilation failed
我试图编译的代码如下,
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import 'hardhat/console.sol';
import { FlashLoanReceiverBase } from './FlashLoanReceiverBase.sol';
import { ILendingPool } from './interfaces/ILendingPool.sol';
import { ILendingPoolAddressesProvider } from './interfaces/ILendingPoolAddressesProvider.sol';
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
contract MyFlashLoan is FlashLoanReceiverBase {
constructor(ILendingPoolAddressesProvider _addressProvider)
FlashLoanReceiverBase(_addressProvider) {}
function executeOperation(
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata premiums,
address initiator,
bytes calldata params
)
external
override
returns(bool)
{
// Flash Loan Code.
// Approve allowances for the lending pool to pull owed amounts
for( uint i = 0; i < assets.length;i++){
uint amountOwing = amounts[i].add(premiums[i]);
IERC20(assets[i]).approve(address[LENDING_POOL], amountOwing);
}
return true;
}
}
为什么我收到上述错误消息?我该如何纠正
您必须按以下方式键入强制转换以使其成为地址应付。
IERC20(assets[i]).approve(payable(address[LENDING_POOL]), amountOwing);
我认为,从0.8开始,您必须明确支付地址,因为您在进行转账之前明确批准了地址。