ETHLondonUK: Code your first flash loan with Aave fam, with Emilio Frangella & Ernesto Boado
ETHGlobal·Fri, Oct 9, 2020, 12:00 AM
Speakers
Transcript
hello guys well first of all to get a bit of because I don't know how is the the audience here you say who knows what up it does more or less or has an approximate a video ok not so many ok basically a ABI is a money market where like the centralized protocol where people can borrow and and deposit different assets and so if you deposit you do at interest you got deal for your your assets and if you borrow you need to pay my interest for for those depositors no today in the in the course will be about one of the main features we have in the protocol one of the most like new features and innovations and I is the the flash loans who who heard about the flash loans here lately in last week's almost more than even now because is quite normal actually and yeah so the flash loans has a lot of you know is are based on the atomicity of the you know blockchain of the transactions in the human blockchain that when you execute when you when you execute the sub transactions inside a one function call if everything passes everything passes if something fails in the middle a everything everything get Roberta this is quite interesting because you can make multiple jumps and and go from one platform to the other in the case of flash loads with with fans with ETH with I or whatever other currency and then validate at the end if if the final status is consistent and if it's not consistent you just repaired everything and you have like really powerful features because of this atomicity in the thing the big innovation of the flash looms and what it makes it really powerful is the actually the combination with a money market like ours in a way because you have basically you have a a big amount because chunk of funds store there that are not borrowed by the by borrowers from the depositors and one way of using them is like flash loan for one transaction so anybody even if they don't have any capital they can just flash long at the beginning of the transaction they do whatever operations in the in defeating other a few applications that are available and then the only condition is that they need to return the funds at the end of the of the transaction so yeah that is the flash loans and they are really well known as a lot of you know last two weeks because there was a quite big attack attack or like not only attack for me was kind of a genius movement the principle based on the composability of off with you and they did like strategy and I mean 14 seconds of a block basically they got 350 K or something like that in dollars so that made like everything in this world when there is a big attack and so that it gets a lot of money it goes mainstream know so yeah we introduced the feature will release the protocol like almost week to months ago and this was one of the main features we were releasing but nobody was using at at the beginning and now is growing because actually has a lot of potential so today is mainly to give a quick technical introduction of how is the flash loaning our protocol and how anybody can implement something using them so yeah here there are some some links that we can share at the end of the of the presentation but basically we created a repo the first one if you want to take a picture or whatever but I will open now with kind of a template of how to implement the flash loans and from from Ali so the idea is that we created like a mock exchange that we I will we will show Amelie which also means that we created a mock exchange that the received funds from flash long and then then it returns and you need to return the funds and it returns with a small fee that is like a mock but is just to show they how to do it not and yet the there is more information but then we will go click first of all I will try to show you the code in the protocol itself of how exactly the flash loan works for us I know how to yeah basically this this contact is our our rep one is the landing pool and it's like the entry point contract of a or four yeah yeah yeah how is the brightness and the soup there is a weird keyboard is my fault sorry yeah and let me go to a particular place however we are not gonna go show so much in detail about the code itself is uh more about the okay yeah so basically this is the function in this content you have like the deposit function the borrow function the the fashion to to swap between the different types of of interest that you can use to borrow and another function is the flash no no so a basically what what in the receives is that you you receive an address of the receiver that is this mark on that where the fans are on the flash fans are gonna be sent so it's like the borrower of the flash long then the reserve is is the asset that you are borrowing flash born like ETS died the amount screen and then the the params is is if you want to send any data to that contract that is receiving the funds to do whatever you need so a yeah basically we it does multiple validations that the liquidity available is enough to to borrow and that kind of stuff and it calculates a fee this is important in our protocol we took the decision that the flash loans have a fee but this fee is a deposit or jail like it's a fee that it goes get redirected to the depositors the biggest part of it this the the rationale of this is that at the end of the day the these are fans of depositors so and somebody's using those funds even if this is like during one transaction and and there is almost no risk I mean it's debatable if it there is risk or not but it's practically zero we still think that the depositors should be rewarded because of it because at the end is usage of capital right really quickly usage of capital but quick used to so yeah after the validation there is this calculation of the fee and this is kind of the tricky part that is the core is the contra that they store the funds and it transfers to the to the receiver the one after that the only thing that it does is like it checks the liquidity because this executed after this execute operation the funds should be returned by this by the other contract and it just checks that the liquidity after doing the flash loan return is consistent like the funds return are the same that you borrow plus the the corresponding fee so this is the implementation is quite quite simple some omit of evans and yeah yeah the potato on the state of flash long is basically that putting the in the date and the in the state of the in different contexts so basically what we have today here maybe okay yeah in the other website we have for the the documentation for developers we also have this flash one receiver base and basically this is like an example of the Contra that should receive the funds when you make a want to make the flash loan so dick yeah the main faction is this execute operation if you remember in the in the previous landing pod there was a core dot dot execute operation that was after transferring the funds to this contract so this content will receive the funds after that the other flash long function calls this execute operation and this execute operation is where the developer needs to code the particular logic so it receives the also the reserved amount the fee the fee that was pre calculated before and here is where for example the parameters are quite useful because then you can do whatever you want with with your data and you know and at the end is just to the amount you just ask the fee the new fee and in track it transfer a bag that is this is a function we inherit from the from the other base it just transferred the funds back to the plus the fee to the to the lending pool so that is that is the model a this flash loan function is if because this example is designed to be that the other flash known function in the landing pool is called from here so you use the same contra to first called the flash long and then improve the landing pool calls this execute operation that returns back to the lending pool and fish and profit and yeah another thing that we did and that they may Amelie will will show working is this flag flashes change that is just a mock contra that the only thing is that the it receives it will be the the logic in the middle of the execute operation will and you see yeah the thing it will call this is the function that will call Isis change is simply that it will receive the funds it transferred from the funds to here and then okay for the B so specifically it's possible to use the fans that are depositing in the protocol to perform arbitrage between the centralized exchanges right or liquidation in different money market protocols like ours for example it's possible to use the flash loans and the funds that are deposited in our protocol to execute liquidations on compound or dydx for example right this exchange kind of discount was very small content that we brought kind of simulates this specific use case so you can I can show actually in the readme I'm sorry if we are compressing the information so much we thought of this like at least a couple of hours workshop but they're going to be half an hour so we need to be quick so the idea is that we are we are giving you here is we develop it and deploy it this very very easy and kind of funny flash exchange because the thing is that you can invoke it using flash loans right and what this exchange does is we if you send to this exchange funds it will return back the same funds that you sent plus a certain yield for you right so there is actually no exchange we charge the contract with like 0.5 ETH and we will put maybe like 10 or 20 die in it and then you can invoke the the exchange in both ropes and and may not and you send you send an amount to this exchange it will send back the amount that you sent plus very small percentage in this case is 18 basis point 9 basis points will be needed to refund the the pool for the flash lon the other 9 basis points is your yield okay so the this exchange can be called in the same way in the way that Ernesto explained before for to follow the best tradition with flash loans these flash exchange is fully exploitable so you can have there is an exploit that we put in in it and if you find a way to exploit in one single transaction you can actually keep all the funds because we don't care so that could be like an interest sex exercise you can use flash won't completely drain this this exchange this very small exchange one thing that I want to say is that to use the exchange you will need to be white listed otherwise someone else will dry drained all the funds so we will provide like I can show you my telegram ID or you can join our discord channel and if you buy a few bills like a test flesh wound we will add you to the exchange to be able to actually execute the function so and can you actually idea was to make life yeah yeah there are here the of the logic in the music that calls this is change and the funds will be returned there with an extra and then return back to blank watching and Julie's a bad one okay so these three are our telegram handles and also there is our discourse channel that way now I don't have the link honestly but still you can enter the discourse channel or contact are soon on telegram we will be available for further explanation of the examples and how to use them and eventually if you build something to use the flash exchanges that we deposited we will just add you to the white list of the of the contracts you can you can actually invoke the the function okay but about the the flash ones the thing is that may be interesting for you is that we have a when we implemented the flash loans we kind of predict that this could lead to big problems and big advantage but potentially be problems and even inside our our protocol no so like like I told you that we have this landing pool contract that has all the functions of the protocol so one of the biggest not boondi that brunner abilities but more complex reasoning to to know if there were vulnerable to store not it was like having a with known with possible Renton see some funds from some functions from the flash law because some of them are really really clear that are a big problem like the repayment of a loan that is also in this landing pool but at that point what we decide for example and is quite interesting is that we put the Renton C word on everything like and because of the flash loans mainly because we said okay this is really difficult to predict how it's gonna be the result and for example the well you know that this car came bcx the the first one was a small bag but also a manipulation of price and the second was with the flash law like the first one was not was with a flash norm of another platform but the second one was with the flash loan because of also some manipulation of price plus r/n transy and afghanistan so the thing is that and that what what it looks that is gonna bold and that is this is gonna affect the here in the bellum and the phi and everything is that from now on anybody that wants to build something related with with funds that we need to think a lot in flash loans style because it opens another different type of but more needed to execute this is so much that probably will never be with flash one this becomes a much higher risk scenario compared to before because right now what do you need to perform such an attack is only acknowledged you don't need the money anymore you just need the knowledge and this can actually makes the acquisition the whole ecosystem stronger at the end of the day because it forces like everybody to think the security more deeply more thoroughly and not overlooked cases that maybe before were overlooked and for example the attacks on fulcrum we're executing only because the some design decisions overlooked some possible risks right and those risk were to be using and from our experience for example like that like I told before is like we released the protocol and it had already the flash loom the other platform that has available the flash loom had also the flash long at that point but people was a bit interested but not so so much at the moment of after just after the the BCL attack it was in our like our disk or our telegram everything people just asking how can I do fly zones because they notice that is so powerful that you only need knowledge and like combined the puzzle of the puzzle of the of different pieces of the fight to to get life 350k like the and the first attacker deep that nobody knows if it was the same as they are the second but yeah it it brings they will bring a lot of headaches for for developers but at the same time at least in our case we really believe that this is going to be quite big and that the use cases actually are to steal to discover because the attack was one and and the arbitrage that was more or less than the attack is is the one more direct but there are some others that are also really powerful like for example the playing with with the bolts in a maker in and I it's an application that one of our members of the community build a tool for that to make collateral swapping in dye using the flash loom and and we are developing also some some other stuff margin actually trading platform using using flash loans that allows you to to expositions long position or multiple actually configuration on different like landing protocols using watch laws there are like MSO saying there is there are people developing collateral applications with contracts and applications that allow you to change your collateral different landing protocols like makeup for example there is the David one of the first smart quarter that allows you using flash loon to move like seriously your depth position from ETH for Adorama to basic adventure talkin Kuato and so on something for example that will come soon from our side most probably is that a lot of platforms have like like hours that we have over collateralization on the lawns but something that people actually that just arrives to these kind of model says sometimes okay but in mind that they liking maker I think it's 150 the over collateralization so I have the collateral but I get liquidated with 150 why what happens if I already used the funds but I have my collateral but I don't have the the medium of his change the principle to return I would like to actually swap my collateral and and repay the loan with my collateral because I prefer to to lose this portion in the collateral but not lose the bonus that in comes with the liquidation so problem that that for example is gonna probably change the rules of the game because playing with with this kind of liquidation bond which is not gonna be so so easy because one way of doing is like do flash loan from some other place you repay you take the collateral you swap the collateral and and and you return back to the flash loan so you didn't lose anything at that point you only lose the industry pitch of office change yeah yeah no no no this is completely like an example like that the hackers can use like to to hub just a reference of how it works you can try and Rob then you can try in local in with ganache it's a bit more difficult because you will need the protocol to be deploy tools but yeah it's just a demonstration example would be a bar because for example you need to capture a spread for one two different decentralized exchange now let's say Khyber in unit 1 okay so to capture a spread unit funds you buy for example a th on Kaiba you gonna only swap where the price is different you sell the DTH there and you profit right so this way is a typical example fraction instead of using your own funds if you don't have the dam or you are not exposed on the glass you go our DTH serve them on khyber buy back from units what kept the profit you get the difference we have the problem right of course demoing that in a workshop is complicated because you need the actual opportunity of capturing the spread right so to simplify this we just built the flash flash exchange that kind of simulates but is not understated the most important part for people that want to experiment with the flash loans is this one this example because if you take this contract and and of course liming the imports and everything that is basically the addresses of the two interact with the protocol and you replace in the middle they with the new your thing here with your logic it will just simply work so that is the thing yeah it will be like this flash law calls the landing pool yeah interface is up okay in this fashion you would already have defense from the pool right whatever amount you you decide you at this point you have them here imagine with the sample that I said here you would call unit swap sell on one buying the other or the opposite and take the profit yeah and of course I mean all the reserves like they and the famous attack was wrong with with with CDH but the flash loan is not limited to ETH I mean you can borrow any of the 16 16 16 they are su and are like yeah yeah yeah yeah whatever it's like not in one call you can the end a DC that is the consequence of their entrance award that for that you will need to fly slow and then interact with the protocol to flash long another one so that is not allowed because of actually that is for example one of the limitation that we will probably remove at some point because we know more or less sure that the interacting from one currency with flash loan and with the other in a different in some specific conditions is not problematic or should not be problematic we still are evaluating that and so that could be interesting to to actually flash loan one a flash law and order and combine everything to do some crazy stuff in the middle yeah but right now they needs to be live you can do flash looms with all the cars if there is liquidity but it needs to be in separate steps not in the center and such if not the rentals award will not Allah thanks guys [Applause]
Automatic transcript — names and jargon may be misspelled.
