Flash Loan Arbitrage | Aave Flash Loan Tutorial
Vložit
- čas přidán 1. 10. 2022
- Create an Aave Flash Loan arbitrage smart contract from scratch in this comprehensive flash loan tutorial. In this step-by-step DeFi tutorial we use the Aave v3 protocol to build a flash loan receiver smart contract. We'll then use a mock DEX contract to simulate a flash loan arbitrage.
Project repo:
github.com/jspruance/aave-fla...
Aave v3 Flash Loan documentation:
docs.aave.com/developers/guid...
docs.aave.com/developers/depl...
DAI-TestnetMintableERC20-Aave token (Goerli):
0xDF1742fE5b0bFc12331D8EAec6b478DfDbD31464
USDC-TestnetMintableERC20-Aave token(Goerli):
0xA2025B15a1757311bfD68cb14eaeFCc237AF5b43
AAVE PoolAddressProvider (Goerli):
0x5E52dEc931FFb32f609681B8438A51c675cc232d
Get Goerli test Eth here:
faucets.chain.link/
Get test ERC20 tokens here:
staging.aave.com/faucet/?mark...
Remix imports:
import {FlashLoanSimpleReceiverBase} from "github.com/aave/aave-v3-core/...";
import {IPoolAddressesProvider} from "github.com/aave/aave-v3-core/...";
import {IERC20} from "github.com/aave/aave-v3-core/...";
Dex.sol deployed (Goerli):
0xD6e8c479B6B62d8Ce985C0f686D39e96af9424df
Add liquidity:
USDC 1500
DAI 1500
Approve:
USDC 1000000000
DAI 1200000000000000000000
Request Loan - USDC (6 decimal):
0xA2025B15a1757311bfD68cb14eaeFCc237AF5b43,1000000000 // 1,000 USDC
0xA2025B15a1757311bfD68cb14eaeFCc237AF5b43,1000000 // 1 USDC - Věda a technologie
I've been trying to find a tutorial this robust for about 2 years. Thank you!
has this method worked for you
hands down, the best ever flash loan arbitrage tutorial. thank you for detailed explanation.
I am halfway at watching the video, and I just want to thank you a lot for this tutorial. This is the best flashloan tutorial on youtube that I watched until now.
Thanks my friend - I appreciate that! : )
why do i get error when i import files he says import from dpendencies? i copied the green and pink lines in git hub?
@@BlockExplorerMedia can this be done in polygon chain?
@@saheb1009 why are you scared of fees. Haha okay yeah it could work I guess just change the variables that represent matic from eth also router address.
Bro please don't stop making content. Your tutorials are some of the most easily digestible Solidity Tutorials online hands down. Even when I run into issue it's easy to fix because the foundation of how you deliver the information is solid. I'm not a complete novice when it comes to solidity but I'm also not an expert. My point is these are good for people of all levels even those who want to understand the code just so they now a little about how smart contracts work. Please don't stop making these videos they're awesome. If you're not gonna do this here on youtube at least start a Udemy class or something. Key point being your work is needed in this space. Thank' You.
I really appreciate the kind words. I've had a bit of a lull but new video dropping tomorrow. Thanks for your support!
Yeah, this dude, absolutely, rocks.
@@BlockExplorerMedia brother can you mentor me I signed up to your Patreon and saw it had no videos 😂
But this video is gold literally
So with all the praise of this video. I'm assuming there was success in one of you creating flash loans?
Clear and amazing. Better than any related videos which gonna charge lots of $
yup the first tutorial to actually work!!! Damn you're good
Just realized this video is also form the same creator as the website I was just reading an article on 30 min ago.. so dope that you have channel too and not just a bullshit one so you can say you do. This video is very well put together and you speak clearly and slowly it’s almost soothing haha 😂. Please keep up the content these kinds of quality videos will be helping people for years to come I’m subbing after the comment and clicking the bell haha
Thanks, I appreciate your kind words. Which website was that? I don't have one : ) I should have a new video dropping in the next day or so - thanks!
Great video, concise and exactly what you need to get started!
why do i get error when i import files he says import from dpendencies? i copied the green and pink lines in git hub?
Gosh you guys have the best tutorials 💯 seriously been so helpful
This is a really great tutorial, I am looking forward to your new content on this channel. Thanks
the only tutorials where my adhd doesnt take over lolz,thank you
still works the code?
thank you for your efforts in this video, know it really takes a lot of effort to make things end-to-end. Nice work!
Thanks bro, best flashloan tutorial I have ever watched
This is my favorite video of yours so far. Thanks!
Just out of curiosity...If I were to run the V2 on mainnet, with my own USDC/DAI would it return similar profits? aka, press button=make me rich? Lol
Thanks appreciate it!!
Well the 'make me rich' part all comes down to what arbitrage opportunity you've found. In my example it's a little contrived, of course, but I've heard that people have made some serious bacon from flash loans. The potential is definitely there!
Wow.. You've nailed it. Thanks for sharing this educ. video.
This is much appreciated! Thank you 👍👍
why do i get error when i import files he says import from dependencies? i copied the green and pink lines in git hub? and
Reply
THIS IS GREAT . .please make more tutorial on Defi ..
This is brilliant, thank you
Excellent video!
Outstanding video💥🔥⚡⚡🔥💥
Thank you it worked, take care!
Thank you for the excellent tutorial. Does the test wallet require any funds prior to execution of the script?
AWESOME!!!
Great video, thanks one million. Going to try it and add another comment. Peace out fam
Amazing video
Great tutorial, now i was wondering if you can make it with DODO or DYDX
Best explanation ever on executing a flashloan in CZcams by the way Did you recieved usdc in metamask wallet end of it ??? Please reply I'm eagerly waiting for you reply 😊
great stuff
thanks for this dude
No problemo!
very good!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
thanks bro full value
This was a brilliant tutorial explaining from scratch how use flash loans. Can u make video on flashbots and reentrancy hacks too
lmao
Can you execute an operation with a CEX like Binance using an API once you have taken a flash loan or are we just limited to DEXs
Thank you so much for creating and sharing this amazing tutorial video!
Quick question...
Do you have a video or could you create video which shows how to create this development setup for people who never coded anything before but still want to follow this tutorial step by step? I myself am not a developer and I know such a video would be really helpful for me.
imo you really have to learn at least some basic solidity and study how transactions happen under the hood (what you're interacting with in order to do this) to fully understand and get the maximum benefit from using stuff like this.
I can help with that.
As someone who doesn't know anything about programming this looks titanically impossible, well this is going to be a long ride
id like to get something straight , do we have to deposit the 1500 USDC and 1500 DAI ($3000) from our own personal metamask wallet ? Or these funds comes from the test tokens faucet?
Is it possible to configure for mainnet? I'm trying to implement flashloan and abitration in V2, but it's returning zero in getBalance and zero after executing the executeOperation() function
I love this video
I have a question, did u take arbitrary dexRate? If yes then is it possible to set arbitrary dexRate in mainnet ???
Shouldnt we need to use some thing like chainlink to get pricefeeds to calculate DexA rate and DexB rate
sir can't we perform arbitrage on test net directly without using the dex contract??
token's address faucet different with token's address borrow and repay such as DAI or USDC, how can I fix it?
Thanks lot
What is the initial amount should have in wallet to do this complete project
Thanks mate its easy to understand and good intro to flash loan arb, Can we automate this, so that whenever it finds a difference in price it will execute...
yes we can
how did you get used on goerli? I can't find a goerli faucet for usdc
Are there any good videos on how to code this kind of thing? I haven't coded in almost 30yrs.
Super nice tutorial! Very pleasant. I have 2 questions:
1. For Add liquidity, I see 1,500 USDC while the Flashloan is 1,000 USDC. Is adding 1,000 as liquidity possible? What upper security margin should we consider in percentage?
2. For Approve, i see 1,200 DAI (1200000000000000000000) while USDC is 1,000. Why 1200 DAI?
Hi. Is it possible to fund the contract with less than 1500? If so, what is the minimum?
How profit did you get? there are still some opportunities on Market Now?
Do i need to write that smart contract to do flash loan arbitrage on Aave?
What a great tutorial. I am totally newbie on this but your step-by-step guide helped a lot. But I did receive this message "'insufficient funds for intrinsic transaction cost'", and I am wondering, what's the minimum ETH I should deposit? I just created a totally new wallet in Metamask, but not sure how much ETH should I transfer or depo, just for this tutorial purpose.
Just found out that we actually need some faucet goerliETH for the transaction fee to deploy the fast loan contract. I thought we just need the faucet USDC only for testing. Thanks again for the tutorial
@@Fansuri85 yes you always need native coin for the gas fee
@@Fansuri85have you been successful using this method?
Can I use this for the balancer protocol ? Please I will appreciate your help on this
Can I use the bsc network?
Hi
One question pls; if I want to deploy the dex contract on the mainnet, would it cost me the 1500 USDC and 1500 DAI as it's done in the video using the test tokens? If no, how much minimum would it reasonably cost?
Hi how do i populate the infura goreli endpoint
hello, i tried this on my vscode but am having issues deploying it
hi, please can you code for arbitrage only without the flashloan?
This tutorial was really helpful! The only issue I had was that the USDC I obtained using Aave's faucet had a different contract address. Is there a way I can supply the DEX with the USDC using the address that Aave expects? I apologize for my poor English. :(
cc :waiting for the reply too... thanks in advance .
for more context:
## DAI-TestnetMintableERC20-Aave token (Goerli):
your video Aave's faucet addressess - 0xDF1742fE5b0bFc12331D8EAec6b478DfDbD31464
~
the new Aave's faucet contract addresses - ` 0x75Ab5AB1Eef154C0352Fc31D2428Cef80C7F8B33 `
## USDC-TestnetMintableERC20-Aave token(Goerli):
your video Aave's faucet addresses - 0xA2025B15a1757311bfD68cb14eaeFCc237AF5b43
~
the new Aave's faucet contract addresses -` 0x9FD21bE27A2B059a288229361E2fA632D8D2d074 `
Did u get help?
Use v3 of the USDC faucet token, I was using v2 and it was giving me gas failure errors
Did you tried using on Mainet and did it worked ??
My friend, thank you very much for this tutorial)) I have one small problem which I can not deal with. In 12:03 you had a problem in second line, but after 2 seconds (on the next shot) this problem doesn't exist. Please tell me what have you done with it ? I will really appreciate it if you help me.
Did you get the help?
Undeclared identifier line 39 column 5. Pool variable is undeclared. How do I fix?
Thanks for the video, you will forever remain the best, I appreciate, please i have a small issue when i run the code that will deploy the contract, i always get an error saying “flashLoan.deployed is not a function
Please help me on how to solve the issue, thanks so much
I get the same issue on deployment: "flashLoan.deployed is not a function" - any ideas what is causing that 'revert'?
Goerli testnet is deprecated. Is there a dex.sol anybody has for Sepoli with liquidity?
thanks for the video. Quick question. What vscode extension do you use / settings for solidity highlighting. Thanks
I'm using the Solidity VC plugin by Juan Blanco which is great (using that specifically in this video). I have also used the Hardhat Solidity plugin. Prettier for formatting - you have to enable 'format on save' in VC settings and also ensure a formatter is set for Solidity.
@@BlockExplorerMedia thanks bro, big help
Great tutorial! One question though: why can't we use the 1000 USDC borrowed from Aave for the DEX transcations but have to deposit another 1000 USDC for liquidity? The borrowing and arbitraging actions seem to be two separate transcations in the example?
The inital deposit is the collateral fees. In case you can't afford to pay back the amount borrowed. Nothing is free
But your supposed to be able to borrow without collateral! This is how flash loans are spoken about 🤣
I made an cross exchange arbitrage bot with flash loan. What no one tells you, is that miners who land the block have control over the transactions that will go on the block. So they can manipulate who will take the arbitrage oportunities.
any tips to start creating a cross exchange arbitrage bot with flashloans?
@@JS-jq8pu there's no shortcuts, you can look for degenbot to have some idea if you understand python. the concept is basically keep track of current reservers of a pair and calculate the future by filtering pending transactions on the blockchain> You will also need code in solidity, there's no way to run (but is not as hard as it looks, honestly is the easiest part). I have nothing linked with degenbot, it's just the only arbitrage real content i ever saw in the internet, and i still not use it, i made all my stuff. It's a lot of work (for real, there's no limit to upgrade), as more exchanges you implement more opportunities and also more profitable each opportunity will be, so it's kinda exponential. I don't know what more i can tell you, ask me a more specific question if u want. Currently im making just few dollars a day, probably an average of 5-6. But is increasing as i upgrade my code. January was few cents a day
Will this work on Polygon network?
Sorry, minute 9'42 when clicked on botton C on the botton 2 windows were opened on the top. I didnt understand how those were opened
Hi, thanks for the great tutorial... When I tried deploying to the TESTNET I received this error...
´Deploying contract...
Deployment error: Error: cannot estimate gas; transaction may fail or may require manual gas limit ´
Do you know why??? Thanks 🙏
sir, can you make eth frontrunning smart contract?
dont get the sol to compile in remix. those imports are not working it seems 3 parse errors
Infinite money glitch. Jk, loved the tutorial!
I'm still looking for that glitch ; ) thanks!
Hello, thanks for tutorial. im getting the following error: "NotImplementedError: Method 'HardhatEthersProvider.resolveName' is not implemented" when i try to deployFlashloan.js (following minute 27:40 from video. Anyone know what is the problem?
i cant inherit from FlashLoanSimpleReceiverBase .. it even didnt show on emmet
hi block explorer can i use it on mainnet
Great video, can i also use a bigger Flash loan of like 100k or 1mil and make more profit?
Hey bro, did you use this on the mainnet and if yes, did you get some profits?
@Block Explorer I am completely happy with the clear explanation given in the video. But I have a question, The amount you have deposited for liquidity 1500 USDC and 1500 DAI, do we need to deposit from our end?. I am from India and I feel the amount is more expensive to deposit. Please help me with the query.
bro thats testnet dai and usdc, doesnt cost u anything
.
@@antonstauer6421 but what about when we want to deploy it on the mainnet, would it cost the same 1,500 for USDC and DAI? And if no, how much minimum would it reasonably cost to deploy it?
Very helpful video, thank you bro. Just a noob question though. The 10% discount for the DAI, I assume it depends on the price of DAI right? I mean we can't enforce the 10% discount on DAI, it just depends on what the DAI's price at the time we want to arbritage them? So the 10% is purely for tutorial purposes not the real situation? Thank you again for the great video.
Yes, the 10% is just for tutorial purposes so I can have a controlled way to demonstrate how an arbitrage would work. In the wild, you'd have to find a real arbitrage opportunity by comparing token values across different DeFi protocols or DEXes.
@@BlockExplorerMedia Got it. Thank you.
This is fucking amazing
can i use python instead of js? or it will be slow
bro can i excecute on this in mainnet and earn money bro will it work now
Is this a testnet transaction or mainnet
Hi can we deploy mev on unisawap borrowed eth from ave
Why was it so fast at taking a loan then buying dai and then selling it for usdc? Usually currency rates do not move that quickly... Can you show a real example with some real money and real dex?
this is awesome. I now understand so much better. I have software that finds trades where i can arb them so this is awesome to learn as i want to also do myself if possible. Do you do any courses?
your software fins arb opportunities on DEX liquidity pools or exchange platforms ?
@@D.H_music69 it searches a couple of Dex exchanges and does the whole smart contract on polygon. But I want to learn myself and learn how to fish so to speak
@@D.H_music69 I replied but did it disappear????
@@D.H_music69 the software searches Dexs. Only a few at present more to add. But the beauty of it is that it does everything in the one block. Gets loan executes trade. Pays back loan and profit is distributed into MM. I just want to learn to do it myself. 🙏🙏
I am getting an error saying invalid project id when trying to run the code. Anyone have any solutions ?
I have a question. I notice at the beginning when you ran the aave packages with the dotenv package, the env package populated. When I ran the aave packages with the dotenv package, it didn't populate. Anyone know why that is?
.env files are private files that hold secret information so they don’t get committed to repos. I checked the GitHub project and there is a .env.example so you could just clone the repo and rename the .env.example file to just .env
I'm trying this on June 2024 but it does not compile, giving errors about abstract contract, I tried to fix but then got other errors and didn't want to mess up the code.
great tutorial would be nice tho if we could get a mainnet tutorial on the arbitrage
Yeah I want the same
yes its available
@@CyberDTech where pls?
Hey, can this be done in BSC?
Awesome video. It’s just when I type npx hardhat , I see a message in red: the term ‘npx’ Is not recognized
you need to install it
5:53 How come you’re not getting errors when trying to install Hardhat?
Hi, great video. I want to ask is there a way to code a flashloan to take arbitrage from example binance to kucoin or is there a different name that I'm not familiar with for this example
Yes there is. You have to grab the Binance contracts and look for their liquidity pool factory. Import the factory's interface as well as the liquidity pool's. Repeat for kukoin. On the backend you'll need to subscribe to both of their apis and query quotes for certain pairs. I recommend monitoring stable coins to make your like easier. If you use polygon, I highly recommend to use dydx or equalizer flashloans as they charge 0% fees will make million dollar trades viable. Anyways good luck
yes there is.
@@CyberDTech hey bro can I ask a question? The Dex smart contract he used for the Arbitrage, to deploy it on the mainnet what minimum amounts of USDC and DAI is reasonably needed to deploy it?
Hi Bro, very nice. How and where can I find this kind of flashloan opportunity ? Is there somthing like a market place ? Thnx.
The basic idea is to compare token prices at different DeFi protocols until you find a discrepancy where you can make a profit. This is called 'arbitrage' and AMMs depend on this kind of behavior in order to keep their token pairs in sync with the outside market.
I have no idea why but the usdc doesn’t go to the Aave contract address, even though it does go to USDC contract address and it doesn’t let me take the flash loan
Use v3 of the USDC faucet token, I was using v2 and it was giving me gas failure errors
I really wish I knew what all of this was. OR how to implement it. This needs to brew in my head like a pot of kimchi.
start from the basics.
how much did you make in one month ?
I want this real bad . Sri if you have a tutorial on that subject please, send me the purchase link
Is that solidity codes?
If I need to pay gas fees to get money from the faucet it defeats the purpose of using the faucet the gas fees are too high