Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add approve DAI asset to Lending pool provider #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wwarodom
Copy link

@wwarodom wwarodom commented Mar 8, 2022

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

@kenny8333
Copy link

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);
^----^

@wwarodom
Copy link
Author

ERC20 is included in FlashLoanReceiverBase.sol.

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

function flashloan(address _asset) public onlyOwner

@kenny8333
Copy link

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);
}

}

@wwarodom
Copy link
Author

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

update dai transfered
@kenny8333
Copy link

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

@wwarodom
Copy link
Author

wwarodom commented Mar 19, 2022

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.

@kenny8333
Copy link

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

@faisalmotan
Copy link

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?

@kenny8333
Copy link

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

@faisalmotan
Copy link

faisalmotan commented Mar 21, 2022 via email

@faisalmotan
Copy link

faisalmotan commented Mar 21, 2022 via email

@Annnacri
Copy link

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 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants