1

I'm trying to implement a flash loan using aave-v3 flash loan contracts. and when testing using hardhat I get this error:

Error:

Transaction reverted: function returned an unexpected amount of data
    at FlashLoan.constructor (contracts/utils/FlashLoanSimpleReceiverBase.sol:22)
    at EthModule._estimateGasAction (flashLoan/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:425:7)
    at HardhatNetworkProvider.request (flashLoan/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:118:18)
    at EthersProviderWrapper.send (flashLoan/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

& this is my implementation

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10;

import "./utils/IERC20.sol";
import "./utils/FlashLoanSimpleReceiverBase.sol";

contract FlashLoan is FlashLoanSimpleReceiverBase {
address payable owner;
address assetAddress;

error NotOwner();
error NotEnoughFunds();

constructor (address _poolAddress) FlashLoanSimpleReceiverBase(IPoolAddressesProvider(_poolAddress)) {
    owner = payable(msg.sender);
}

function executeOperation(
    address asset,
    uint256 amount,
    uint256 premium,
    address initiator,
    bytes calldata params
) external returns (bool) {
    IERC20 token = IERC20(asset);
    uint256 debt = amount + premium;
    if (token.balanceOf(address(this)) < debt) revert NotEnoughFunds();
    token.approve(address(POOL), debt);
    return true;
}

function flashloan(address _assetAddress, uint256 amount) external {
    if (msg.sender != owner) revert NotOwner();
    assetAddress = _assetAddress;
    address recieverAddress = address(this);
    bytes memory params = '';
    uint16 referralCode = 0;

    POOL.flashLoanSimple(recieverAddress, assetAddress, amount, params, referralCode);
}

function withdraw() external {
    if (msg.sender != owner) revert NotOwner();
    IERC20 token = IERC20(assetAddress);
    token.transfer(owner, token.balanceOf(address(this)));
}
}

1 Answer 1

0

I just copied your code and found the pool that normal was supposed to take the asset from is empty. What provider did you use? Was it: PoolAddressesProvider-Aave

Well idk if this is also your issue but when trying to use it on kovan i found out that the pool is empty, but when trying on rinksebey it works fine and the pool isnt empty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.