我遵循分步指南,因为只有主代码,所以我尝试使用以下导入
pragma solidity 0.6.12;
import { FlashLoanReceiverBase } from "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/FlashLoanReceiverBase.sol";
import { ILendingPool } from "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/ILendingPool.sol";
import { ILendingPoolAddressesProvider } from "https://github.com/aave/flashloan-box/blob/Remix/contracts/aave/ILendingPoolAddressesProvider.sol";
import { IERC20 } from "https://github.com/alcueca/ERC3156/blob/main/contracts/ERC20.sol";
/**
!!!
Never keep funds permanently on your FlashLoanReceiverBase contract as they could be
exposed to a 'griefing' attack, where the stored funds are used by an attacker.
!!!
*/
contract MyV2FlashLoan is FlashLoanReceiverBase {
/**
This function is called after your contract has received the flash loaned amount
*/
function executeOperation(
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata premiums,
address initiator,
bytes calldata params
)
external
override
returns (bool)
{
//
// This contract now has the funds requested.
// Your logic goes here.
//
// At the end of your logic above, this contract owes
// the flashloaned amounts + premiums.
// Therefore ensure your contract has enough to repay
// these amounts.
// Approve the LendingPool contract allowance to *pull* the owed amount
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;
}
}但是,当我试图编译(使用混合)时,会出现以下错误
not found https://github.com/OpenZeppelin/openzeppelincontracts/blob/master/contracts/token/ERC20/SafeERC20.sol发布于 2022-01-08 18:44:38
问题的要点是,您使用的Remixaave分行/闪贷箱回购似乎需要OpenZeppelin 3.x,但是正在导入最新版本。
OpenZeppelin v4.0.0中最重要的变化之一是contracts/目录的重组。特别是,SafeERC20.sol被移到utils/子目录。flashloan导入了一个尖端的OpenZeppelin版本,但仍然期望该文件位于旧路径下。如果您从导入访问URL,您可以看到此路径给您提供了一个HTTP404错误:https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/SafeERC20.sol。
当您只是在本地安装可以通过package.json控制版本的软件包时,这并不是一个问题。事实上,闪贷箱对OpenZeppelin 3.x有一个适当的依赖,所以您可以将它与Truffle一起使用,这似乎是自述的推荐方式。在Remix分支中,这不起作用。版本要求应该嵌入到导入中,而不是。这看起来像一个bug,我认为您应该使用在项目中报告。修复将涉及将FlashLoanReceiverBase.sol内部的导入替换为OpenZeppelin或NPM的导入@指定版本的语法的特定标记版本的URL。或者,该项目可以切换到OpenZeppelin 4.x,但它可能需要大量的工作。
修复必须由项目开发人员应用。同时,要使您的项目在Remix中工作,您必须克隆flashloan,或者将其合同直接添加到您自己的项目中,并在那里应用修复。就我个人而言,在这种情况下,我建议只使用一个框架,特别是如果这只是一个教程项目,而且您没有一个很大的代码库可供迁移。Remix的目的是让它非常快速和容易地开始开发,但在本地,您可以使用更强大的工具来进行依赖关系管理。如果您有一些特殊的需求,并且需要更多的控制,比如在这种情况下,框架通常是一个更好的选择。
https://ethereum.stackexchange.com/questions/118309
复制相似问题