#DappCon22: Day 1 - Constructing Defi Automation - Behind The Scenes, Nikola Vuković
DappCon 2022 · September 2022 · 21:06
Nikola Vukovic, co-founder of DeFi Saver, gives a behind-the-scenes look at constructing DeFi automation on Day 1 of DappCon 2022. The talk covers the technical work of building tools that automatically manage collateral, leverage, and liquidation risk across DeFi lending positions. Nikola Vukovic draws on DeFi Saver's own automation infrastructure to walk through the tradeoffs involved in acting on users' behalf without custody of their funds.
Speakers
Topics
From DappCon 2022, hosted by Dappcon Berlin.
Transcript
so next up talk on defy automation from Nikola vukovic of D5 saver so please welcome Nicolette to the stage hi everyone thanks for coming to the talk thanks for sticking around I know it's uh past 4 pm already um so yeah the idea is actually uh I'm Nicola I'm from I come from the D5 saver team I lead the sort of user-facing Team on the whole app um so I wanted to give like a rough overview of what it was like here in the past couple of years basically building the whole automation feature system sort of thing
and so yeah uh back in 2018 I think it was like late 2018 like the team was on Thailand I was like a vacation um sort of thing um I just realized I don't have the like the clicker for the for the slides I don't know if that's like yeah so anyway uh uh I uh back in 2018 like the team was uh on Thailand on like a vacation sort of thing uh and you know it was it was a vacation you know everybody was like it was a 30 Thursday evening you know they were out in a bar um they started you know they were having beers and everything
and uh you know if you ever hang out with like the great thanks so much if you ever hung out with like any of the crypto Bros you know half of us have like a widget on our home screen like a coin gecko widget you know so you know they were having beers and somebody noticed on their phone like the price of it was going down um and Nana one of the guys at the time had like a CDP open so what that means uh if you haven't you know had a chance to like do something like with maker Tower or you know borrow one land using compound so basically and then I'd had some eat that he didn't want to sell he wanted to hold it for the long term but he needed cash for the the Thailand trip so basically he
supplied his eat as collateral and borrowed a bunch of diet you know like dye is a stable coin that's back to the dollar so far um and you know he used it to to pay for the chip so the idea was like he'd pay back the debt to eventually over time and you know he'd take out his he'd take back his Heat um so yeah that that's fine that works fine but like the thing with cdps is that your um collateral has to be like significantly larger than your depth so it was like at least at least 50 larger and you know cdps work until you know your collateral drastically loses its value like the the price of heat for example goes down or you know you create too much depth
so nanad one of the guys that had the CDP uh realized you know mid amid beer that he was about to get liquidated um so he ran back to the hotel you know he rised back and um he managed to save his position uh even though he didn't really have like uh um any you know extra extra collateral so long story short how he did it so let's imagine like he has a fourteen hundred uh dollars worth of collateral in eat and let's say he has eight hundred dollars worth of uh depth so this is a wrong number it says six cents let's say it was 800. so what Nana basically did um so initially he had like a ratio between the collateral and the depth
which was like around 1.75 so 175 percent and he took like a small chunk of his collateral uh he took it out he sold it for die and he like repaid his depth so he basically made the whole position um smaller uh but he actually increased the ratio between the collateral and the depth so he made his position safer you know he did sell a chunk of his eat but he he was safe from Liquidation from the liquidation penalty so that's like the the gist of it uh we call that action a repay some call it a a graceful unwinding or like a d-leverage uh that sort of thing so yeah uh Nana realized uh right then there was a it wasn't really easy to do
you know it had to it took like four transactions you know you had to do all these things so it's like um complicated it was hard to do was also not very safe because you needed to take out your collateral so that's the Inception of the original CBP saver idea so just like to have a dashboard where you can manage your basically loan um just do what Nana did in a safer easier and cheaper way that's that's like the the main idea and obviously with the end goal of preventing liquidation um so that was fine uh Nana could uh safest position and now everybody could do it as well but what about uh what if nobody noticed the price of it was going down what if Nana had to use his Ledger
instead of a metamask uh wallet and he didn't have it on him or you know what if he was just sleeping so it became very apparent that like you can't really manage this this type of thing manually uh or it doesn't make sense really so it makes much more sense to actually automate this so just like uh that was that was like really the the main idea of CDP server just to like to automate this process because it was pretty straightforward you know like just set up a trigger that like if the ratio drops below a certain threshold just repay your position back to like a safe ratio and uh obviously we implemented the the opposite thing as well so like if you're using your position for leveraging
um when the price goes up you you can actually set up a trigger to like buy more eat so like just increase your heat exposure and that was like the the main idea we had no idea what was actually going to work in production but like the only thing we knew off the bat was uh we had to make this completely trustless so we can't really you know because this is your this is the user's position it's not your someone else's money we didn't want to have any inherent risk you know when using automation so we didn't want to actually be able to do anything that would you know cause harm to the user or their position um so you know safety checks were enforced well actually initially the way it worked like you actually when you subscribe to the automation uh you just gave the automation system permission to
just do that one simple action which was like a replay and there was like also a a hard-coded check on the contract to actually see if the trigger conditions are met so if the ratio is actually low or like the ratio is above the threshold in the case of boost and obviously and also when the transaction was actually uh you know when the repay was actually done there was also a hard-coded uh check on the the contract that actually verified that the ratio actually went up so you know if something went wrong with the repay process you know if the wrong price was used or something like that or like a malicious uh attack or you know just a issue in our system happen like we the whole transaction would actually
revert back so it was like pretty safe on the on the contract side and we sort of created this back-end that did that we launched it we had no idea what to expect really in the you know in in real life you know circumstances and uh you know users actually liked it you know they got the idea right away it's something they needed you know there was a use case and uh you know they subscribed and you know a first first price crash came by and you know we were like glued to the screens we were like monitoring the system we had no idea what was going to happen actually and uh it seemed to work you know it repaid positions it did what it was supposed to do and uh however like every significant price Movement we we sort of
like so whenever like the price went up or down significantly we learned something new so it was like there was like a new Edge case that we had no idea before you know that actually could exist so like for example you know when the price is going up or down it's uh obviously that's when you know gas price spikes or like uh so like not only did you have to like so you know you repay one position but like if the gas spikes and you know that position gets stuck that transaction gets stuck in the replay transaction not only are you not gonna you know Replay that position because it should actually transaction is not going to get mined but you're actually like all the transactions after that one are also not going to get mined as well
because you know the nonce is a larger none so they're not gonna you know you have to like do this sequentially so you know we actually had to implement like uh uh system for resending uh transactions for like monitoring if the transactions were actually mined and then like also when you know when the price is moving significantly uh you're gonna get a lot of slippage hits so you know your exchange calls are going to fail um so you not only have to monitor if the transaction was mine you have to see if it actually reverted you know what happened in the transaction like did it repay to the to the adequate ratio doesn't need another repay so it's like you know every crash we learn something new and you know the system was sort of getting more stable over time
and uh so if you're in D5 you know throughout 20 2019 you know D5 summer and like early 2020 you might remember March 12th so this was like this was the first significant crash of the price uh where the ethereum blockchain actually had some significant usage you know the previous crashes there wasn't really D5 they weren't all these complex layered systems but like this was like March 12th you know thankfully it was day because you know if it was night I don't know what would happen like so we're like the price just started crashing and crashing and crashing and it just kept going it was like completely unprecedented like nobody knew what was going to happen in the whole D5 like
nobody knew if I was gonna remain stable you know if the liquidation processes are actually going to work um and you know we were just at the midst of it just trying to repay all these positions you know just trying to save the the users from Liquidation so it was like pretty crazy and uh you know we're like monitoring the system you know it's sending transactions and like all of a sudden all the transactions just start failing there's just like fail reverse revert after we have no idea why because it just happened all of a sudden like and it's like everything is impressed nobody knows like this is like a first time for so many things so we figured out like maybe 20 minutes later the people from from Khyber actually you know contacted us to let us
know what was going on because kyber was the the largest sort of liquidity provider um actually actually the centralized exchange at the time and they actually had a hard-coded uh gas price limit on their contract um if the price was like above I think it was like a hundred way I think I'm not sure like it might have been even 40 or something uh so if the price was like above let's say 100 gray they actually reverted the transaction right away because they just assumed something malicious was going on like why else would you need you know 100 gray for a transaction because it was just that level of unprecedented unprecedentedness at the time uh it was just like we were accustomed to you know transaction prices of like two or three
or five way like 20 way was high so yeah they raised the transaction the the gas limit and uh you know transactions started actually working and uh I guess you know it ended up fine like I don't think anybody got liquidated we actually got a bunch of these messages it was like very cool you know to see on Twitter on Reddit you know all these people like oh it worked and automation saved me it was like a cool thing so yeah it was like very fun um yeah so over you know over time we realized we could also automate some other things so you might remember the side to the immigration I think with late 2019 we also realized it was like a very tedious process because you couldn't migrate your position because
there wasn't enough liquidity it was a whole whole thing so so we just realized okay we can automate this as well and then like over time we also branched out from from being CDP saver to just like D5 saver uh we integrated compound and Navi which were like the the big protocols at the time uh obviously providing the same feature set such as you know boost and repay automation the whole thing but like um we sort of got this reputation that we were like an advanced toolkit for like Advanced D5 investors it was kind of hard to um well it was like this reputation were like sort of an advanced tool which
actually brought in even more advanced users and those users I mean that's that's a good it's a fun problem to have you know but like those users have all these crazy ideas of things they want to do accomplish and automate and the ideas make sense it's just very hard to you know it's like a very specific use case that's like relevant to them and you know like two percent of users so you know we integrated even more protocols over time and sort of grew organically but it was like very hard to figure out what we want to automate next because uh each new automation was like a specific specialized smart contract that had to be deployed the whole automation system had to be tailored towards that specific smart uh contract that actually executed
the the action so it was like very hard to scale and so we had this um system that was by now sort of stable tried and true um robust um you know throughout all these crashes it was like pretty trustless it was back completely by smart contract but it was very hard to expand you know it wasn't easy to to scale to like different strategies so we kind of realized we did a new system that kept all the the good parts of this one you know the robust robustness uh the robust you know infrastructure and the the trustlessness uh but just make it more generalized in general um so we sort of Started from the ground up uh from the smart contract level we
developed this smart contract architecture that was very modular it was made of these Atomic actions for all the D5 protocols at the time so for example you know make your supply compound borrow Ave flash loan you know sell on unit swap those were all like Atomic actions and uh the idea was to create this system so you can create like a what we call a recipe which is basically a list of all of all of those atomic actions composed together to create to execute this uh complex transaction that could interact with multiple protocols uh just just uh all this like uh all you know so we actually like uh as a proof
of concept we made it into a UI that was like basically a drag and drop UI and you could like you know drag and drop like a flashlight from Ave Supply to maker you know so you had this um the power of like the defy interoperability and like flash loans and all of these super abstract powerful things they were like previously mainly accessible to Smart contract developers now you had it in in a basically drag and drop interface so we I mean we launched it as like a standalone feature where you could like execute your recipe manually and like the users used it in all these unprecedented ways that we just didn't even think of it was like it was a very fun experience uh but yeah basically the the recipe system was like a proof of concept for
just overhauling overhauling our existing architecture into the recipe system so although all of those you know boost and repay specialized smart contracts were actually not being slowly transitioned to to the recipe system obviously the end goal being here to automate them so you know you have your recipe which is like for example a booster or a repay or you know closing your position or doing something special and then you have a trigger which is like we previously saw like for example when you're position ratio drops below a certain threshold you wanna that's where you wanna execute your recipe and that's sort of the combination of those two
things we call a strategy um so we had this system of recipes there was a way more flexible it allowed for so many things the you know previously were very hard to do and this we had the challenge of sort of keeping this uh flexible system as trustless as it was before so you know you had this recipe which was very dynamic um and you had to like enforce all of these checks you know that the real uh deemed necessary so we sort of followed the same Principle as earlier you know the system couldn't actually execute any recipe unless the
specific triggers were met all of these triggers were checked on the Chain the data sources were also on chain like you know chain link uh feeds uh and and like the actual recipe you know when the user subscribed all of these like uh arguments uh the parameters of the the actual recipe actions are hard-coded for the most part like the only part that's actually Dynamic is the well the parameters that need to be dynamic um like for example the repay amount which you know needs to be calculated by the uh the back end you know repay to a certain ratio but like all of the all the other things like for example your position ID your wallet address those are all hard coders you know the system
can't like you know withdraw uh funds and like send them to the to a different address or something like that um yeah so we launched that like last year and uh as a proof of concept we had this strategy there was a so again if you had like a make your dial position um you could actually set up a trigger that if you know if the price dropped and your ratio dropped you could actually use your uh savings account so if you had die in your uh in urine or convex or something like an M stable or something like that you could actually just use it to like pull it out of the savings fund and like repay back your debt to avoid liquidation which would which which is something like you would
use you would do by hand anyway so yeah the proof of concept strategy sort of launched it seemed to work like we had the robustness of the universe system and it definitely allowed us to iterate much more quickly you know so like just a couple weeks later we launched the the stop loss and like the take profit strategies which are like basically just a allow you to close your position when a certain price threshold is reached whether it's like a below a certain threshold or like when it reaches a profitable amount it allowed us to scale pretty quickly to to L2 support uh like we actually have Ave automation live on optimism and arbitrim uh through this system it was
like very sort of easy to do compared like to to the plane deploying the previous system another very fun thing that we actually did recently is like this very Dynamic strategy there was like uh it's called the trailing stop so if you're like a financial person you might know uh what are trading stop is but basically is it's like it allows you to like follow the price trend while it's going upward so you know while the while the trend is going while the price is going up uh nothing's gonna happen but if the price drops for like a specific uh percentage uh from its peak uh then that's where where your position will be closed you know you can see like the the closing price is actually going up you know with the actual market price
and you know when it finally drops like 20 that's where the position is closed so that that's like something that was like very hard to do earlier it was like very flexible to do in this new system and yeah obviously the end goal here being the to allow all these users to you know set up their own special triggers and like special recipes they're like custom for them and you know uh allow them to automate whatever they want so yeah that was a quick overview of the the past two or three years um feel free to shoot some questions feel free to get technical as well you know that's why I'm here for so thanks for listening
[Applause] cool any questions okay cool um thanks for listening again [Applause]