0

SIO2 is aave v2 foked version on Astar chain. I want to execute flash loan on it and have the following code:

function myFlashLoanCall() public returns (bool){
        address receiverAddress = address(this);

        address[] memory assets = new address[](2);
        assets[0] = address(0x7f27352D5F83Db87a5A3E00f4B07Cc2138D8ee52);
        assets[1] = address(0x3795C36e7D12A8c252A20C5a7B455f7c57b60283);

        uint256[] memory amounts = new uint256[](2);
        amounts[0] = 0 ether;
        amounts[1] = 0.0001 ether;

        // 0 = no debt, 1 = stable, 2 = variable
        uint256[] memory modes = new uint256[](2);
        modes[0] = 0;
        modes[1] = 0;

        address onBehalfOf = address(this);
        bytes memory params = "";
        uint16 referralCode = 0;

        LENDING_POOL.flashLoan(
            receiverAddress,
            assets,
            amounts,
            modes,
            onBehalfOf,
            params,
            referralCode
        );
        return true;
    }

Whenever I try to call the myFlashloan() I am always getting this error in truffle: revert SafeERC20: low-level call failed. Even I have used the debugging feature of Truffle but not able to solve the issue. May someone tell me what I am doing wrong? Here's my test case to call myFlashloan():

it("Calling myFlashLoanCall()",async ()=>{
        let reponse = await debug(myFlashLoanV2.myFlashLoanCall());
    })

Note: Truffle is not able to stop at debug() call even testing with test --debug in truffle console.

1 Answer 1

0

Since the loan is on behalf of the your smart contract it also should implement the IFlashLoanReceiver interface from the Aave docs.

My best guesstimation here is that the LENDING_POOL is trying to send the flasloan to your smart contract but since it is not implementing the IFlashLoanReceiver the call is failing.

You have to provide more details to your question because the error is happening in the LENDING_POOL.flashLoan(...) which execution is depending not only on the myFlashLoanCall() function but on the whole smart contract implementation.

Your Answer

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

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