Aave-FlashLoan-using-solidity icon indicating copy to clipboard operation
Aave-FlashLoan-using-solidity copied to clipboard

Add approve DAI asset to Lending pool provider

Open wwarodom opened this issue 2 years ago • 12 comments

I faced this errors due to no approval for a lending pool.

"Fail with error 'SafeMath: subtraction overflow' " Ref: https://kovan.etherscan.io/tx/0x25169bbad32aa94a14242b47c4e951cdac37dca7cedb6ca6c2cbdd377099fef3

AAVE state that: Also note that since the owed amounts will be pulled from your contract, your contract must give allowance to the Pool to pull those funds to pay back the flash loan amount + premiums.

Ref: https://docs.aave.com/developers/guides/flash-loans#overview

After applied "approve", I can successfully run flashloan.

https://kovan.etherscan.io/tx/0x34a5c5f7e64747fdcb1b029ce4e36f901361ef4ebb5736acd31adba3112b8424

wwarodom avatar Mar 08 '22 02:03 wwarodom

Hi Wwarodom, any idea how to resolve this issue-

    ERC20 dai = ERC20(_asset);
    dai.approve(addressesProvider.getLendingPool(), 900000000000000000000000 );

Upon executing the flashloan, I got this this error as shown below, contracts/flashloan.sol:48:27: DeclarationError: Undeclared identifier. Did you mean "assert"? ERC20 dai = ERC20(_asset); ^----^

kenny8333 avatar Mar 18 '22 02:03 kenny8333

ERC20 is included in FlashLoanReceiverBase.sol.

"_asset" is the local variable which is declared here:

function flashloan(address _asset) public onlyOwner

wwarodom avatar Mar 18 '22 03:03 wwarodom

Thanks Wwarodom for the prompt reply. Yes, I have all these in the contract, yet upon executing I still received this error message. Am I missing out anything? or would you mind vetting the contract and advise me accordingly. Appreciate your assistance. I am still kinda newbie to all these.

contracts/flashloan.sol:48:27: DeclarationError: Undeclared identifier. Did you mean "assert"? ERC20 dai = ERC20(_asset); ^----^

//Use the lisence here: MIT & Apachai standart //@dev/Developer = Pavan Ananth Sharma //@.NET/Network = Kovan Test Network pragma solidity ^0.6.6; import "./FlashLoanReceiverBase.sol"; import "./ILendingPoolAddressesProvider.sol"; import "./ILendingPool.sol";

contract FlashloanV1 is FlashLoanReceiverBaseV1 {

string _Real_Owner = "kenny wong" ;

function Owner_Of_This_Contract() public view returns(string memory){
    return _Real_Owner;
}

constructor(address _addressProvider) FlashLoanReceiverBaseV1(_addressProvider) public{}

/** Flash loan 1000000000000000000 wei (1 ether) worth of _asset */ function flashloan(address _asset) public onlyOwner { bytes memory data = ""; uint amount = 1 ether; //this is the loan amount which will be seen or converted to DAI which means if you enter in 100 here you will be taking a loan of 100 DAI and so on. //basically we can say that this ebtered amount is converted to wei which is a small decimal of ETH and then it is placed in to the mem pool for the mining of the DAI

    ILendingPoolV1 lendingPool = ILendingPoolV1(addressesProvider.getLendingPool());
    lendingPool.flashLoan(address(this), _asset, amount, data);
}

/**

This function is called after your contract has received the flash loaned amount */ function executeOperation( address _reserve, uint256 _amount, uint256 _fee, bytes calldata _params ) external override { require(_amount <= getBalanceInternal(address(this), _reserve), "Invalid balance, was the flashLoan successful?"); // // Your logic goes here. // !! Ensure that this contract has enough of _reserve funds to payback the _fee !! // ERC20 dai = ERC20 (_asset); dai.approve(addressesProvider.getLendingPool(), 900000000000000000000000 );

    uint totalDebt = _amount.add(_fee);
    transferFundsBackToPoolInternal(_reserve, totalDebt);
}

}

kenny8333 avatar Mar 18 '22 10:03 kenny8333

Opp, you have to move

ERC20 dai = ERC20 (_asset);
dai.approve(addressesProvider.getLendingPool(), 900000000000000000000000 );

to flashloan() function

you can check my project with hardhat project here: https://github.com/wwarodom/flashloan_aave

wwarodom avatar Mar 18 '22 12:03 wwarodom

Thanks! I will do test run later. By the way can it be done on Ropsten Testnet? or it has to be Kovan?

kenny8333 avatar Mar 18 '22 13:03 kenny8333

I haven't tested it yet. If AAVE deploys LPs on Ropsten, it can work. However, it depends on LP deploying address, liquidity pool, DAI faucet, DAI address etc. I suggested trying on Kovan first to get shit done.

wwarodom avatar Mar 19 '22 02:03 wwarodom

Noted. In addition, may I check with you, do you develop any code for flash loan arbitrage bot?

kenny8333 avatar Mar 19 '22 04:03 kenny8333

Noted. In addition, may I check with you, do you develop any code for flash loan arbitrage bot?

same i needed for arbitrage functionality is there anyone know?

faisalmotan avatar Mar 20 '22 20:03 faisalmotan

You may want to check this out and let me know if it works for you - https://github.com/ChengGong0602/flashloan-arbitrage-bot/blob/main/FlashArbitrageTrader.sol

kenny8333 avatar Mar 21 '22 00:03 kenny8333

can you guide me it is working on test network can you give me demo please?

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon Virus-free. www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Mon, Mar 21, 2022 at 5:16 AM kenny8333 @.***> wrote:

You may want to check this out and let me know if it works for you - https://github.com/ChengGong0602/flashloan-arbitrage-bot/blob/main/FlashArbitrageTrader.sol

— Reply to this email directly, view it on GitHub https://github.com/PavanAnanthSharma/Aave-FlashLoan-using-solidity/pull/3#issuecomment-1073381595, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIY6KUVINANUEA5HYYFZHRLVA65WZANCNFSM5QFBTXYA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.*** .com>

faisalmotan avatar Mar 21 '22 17:03 faisalmotan

not found https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/math/SafeMath.sol

it is giving the error

On Mon, Mar 21, 2022 at 10:01 PM Faisal Motan @.***> wrote:

can you guide me it is working on test network can you give me demo please?

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon Virus-free. www.avast.com https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link <#m_-3843936947816147814_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Mon, Mar 21, 2022 at 5:16 AM kenny8333 @.***> wrote:

You may want to check this out and let me know if it works for you - https://github.com/ChengGong0602/flashloan-arbitrage-bot/blob/main/FlashArbitrageTrader.sol

— Reply to this email directly, view it on GitHub https://github.com/PavanAnanthSharma/Aave-FlashLoan-using-solidity/pull/3#issuecomment-1073381595, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIY6KUVINANUEA5HYYFZHRLVA65WZANCNFSM5QFBTXYA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: <PavanAnanthSharma/Aave-FlashLoan-using-solidity/pull/3/c1073381595@ github.com>

faisalmotan avatar Mar 21 '22 17:03 faisalmotan

oi , dá para fazer a estratégia em outra network diferente da Kovan test net ? No meu caso seria em avax . Penso que me fiz entender com a minha pergunta 😂

Annnacri avatar Jul 15 '22 21:07 Annnacri