我的合同:
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import './interfaces/MyILendingPool.sol';
import './interfaces/MyIERC20.sol';
contract FlashLoaner {
struct MyCustomData {
address token;
uint256 repayAmount;
}
// **** storage variables from the proxy ****
address public logicContract;
address public deployer;
uint public borrowed;
// ********
function execute(address _weth, address _contract, uint256 _borrowed) external {
MyILendingPool lendingPoolAAVE = MyILendingPool(0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9);
MyIERC20 weth = MyIERC20(_weth);
address usdc = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
uint aaveUSDCloan = 1000000 * 10 ** 18;
weth.approve(address(lendingPoolAAVE), _borrowed);
lendingPoolAAVE.deposit(_weth, _borrowed, _contract, 0);
lendingPoolAAVE.borrow(usdc, aaveUSDCloan, 2, 0, _contract); //---> issue
}
}接口连接良好,我成功地使用deposit()存储了一些抵押品(6400ETH)。
当我使用MyILendingPool从-and查询时,注释掉了borrow()-:
function getUserAccountData(address user)
external
view
returns (
uint256 totalCollateralETH,
uint256 totalDebtETH,
uint256 availableBorrowsETH,
uint256 currentLiquidationThreshold,
uint256 ltv,
uint256 healthFactor
);...I得到所有正确的值,availableBorrowsETH值约为1500万美元(折算)。
我得到的错误是:
Error: VM Exception while processing transaction: reverted with reason string 'Delegate Call failed'
...since --这是来自代理的逻辑契约,但我不认为问题在代理上,因为当我注释掉borrow()并从贷款池查询时,一切都运行顺利。
谢谢你的帮助!
以防万一,MyILendingPool:
// // SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
interface MyILendingPool {
function deposit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
function borrow(
address asset,
uint256 amount,
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) external;
function getUserAccountData(address user)
external
view
returns (
uint256 totalCollateralETH,
uint256 totalDebtETH,
uint256 availableBorrowsETH,
uint256 currentLiquidationThreshold,
uint256 ltv,
uint256 healthFactor
);
}发布于 2021-06-29 15:44:43
AAVE,v2,USDC和USDT令牌使用的是6个小数,而不是18个。我猜你想借的是一万亿美元,而不仅仅是一百万美元。
这一行:
aaveUSDCloan = 1000000 * 10 ** 18;
可能应该是:
aaveUSDCloan = 1000000 * 10 ** 6;
关于不同的atokens使用的小数的文档在这里:https://docs.aave.com/developers/deployed-contracts/deployed-contracts
https://ethereum.stackexchange.com/questions/102667
复制相似问题