New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Gelato Job Scheduling to Automate Your Smart Contracts Hilmar Maximillian Orth

Ethereum DenverSun, Oct 9, 2022, 12:00 AM

Transcript

cool quite the full room in here thanks a lot guys for coming let me just put my timer here so i don't speak too long there's a lot of stuff we want to cover here all right cool so yeah thanks a lot guys for for coming to today's talk my name is silma i'm one of the the founders of uh gelato and today i want to talk to you about smart contract automation how to automate certain transactions that you want to send to ethereum or any other evm based compatible networks and if you want to maybe automate certain functionalities within your applications that you might be building over the week to come and yeah how you could use something like gelato to do that and how smart contract automation works and what automation means and why you need something like gelato actually to facilitate it on your behalf so as an example smart contract right here what what we what we have is you don't need to kind of like dig into the code here but what you can imagine this to be is just like a smart contract where you just deposit some funds let's say some 1000 ucc let's have you let's say you have five children and you want to send them their lunch money every day at like uh lunch time so they don't get everything at once they don't go out and spend it on candy and stuff they only get like every day ten dollars to buy them some lunch right and there's this token in the smart contract that facilitates that which is this pay out token function right here and what it does it just sends a fixed amount of tokens to some receivers that you can think about being your children for example in this case but obviously you don't want to kind of go there and manually execute that particular function you want that function to be automatically triggered every day at 12 noon for example to pay your children their lunch money right and so today we will talk about okay how we can facilitate that and why this doesn't work out of the box with ethereum or evm based compatible networks so the first realization you have to kind of like have when you develop a dap or your developer smart contracts is they're actually not smart they're pretty lazy the only thing what they do is they just have certain logic and certain certain state encoded in them and the logic basically defining how the state of this particular smart contract can change when you call a particular function right but the problem is if no one executes that particular function on the smart contract then this logic and the state changes associated with them will actually never occur they will never trigger so you always need a party sending a transaction and then the lunch money will be sent if no one sends a transaction nothing will happen in ethereum right and yeah so the problem here is that smart contracts they don't self execute or they don't conditionally execute you can't say hey i want to execute it not now but in the future based on certain conditions that you might want to define which can be arbitrary ones right so yeah why doesn't ethereum support this out of the box you might have heard about something like cron jobs on linux or something um or with web 2 so services you can like maybe um you you you know how to schedule something in the future but on ethereum this is actually not that straightforward because um like if you think about native natively automating stuff automation is kind of like a for loop that just runs forever and just constantly checks if certain conditions are met but you can't have these for loops within smart contracts right because uh smart contra like transactions always like executed right after each other you can only have one after another after another and if you have one transaction that might execute some logic which just runs forever then no other transaction will ever get into ethereum again right so the network kind of like is stuck and it will break so that's why you have something like gas limits that you have to define prior to actually sending a transaction you say okay my function can consume 200 000 gas units which equal the computational units on on the evm and you cannot you cannot um consume more than that so um yeah that's why you can't have these native for loops or like infinite loops within smart contracts itself and so what you have to do is you have to automate smart contracts um exogenous to the evm so outside of the evm um and the first question is okay why don't like the ethereum clients do that right why don't we all run full nodes or why don't the miners just do it on your behalf right but yeah it's uh quite computational um expensive to actually do that right uh you if you if you don't think about like one task or one drop but you think about like 50 or 100 or 50 000 jobs that have to be checked every block every couple of seconds this will increase the computational um requirements that these four nodes have to have to have right and this means that you have to have beefier servers that means only a few people can actually afford running them this means ethereum will become more centralized so that's why if you build like clients or if you book clients for ethereum for example you want to kind of like offload a lot of the computational complexities to other services for example like flashbots is a good example there are all these bundles that are formed are actually done by like a external party by these searchers and then they bundle it up they submitted to the network and then you can go on and then the miners just get the bundle of transaction i can get at mind so basically this conditional recurring transactions they have to be done outside of chain by an external network right or by an external entity so to say yeah so in like the web 2 or operating system world you are used to these cron jobs or if you use like cloud-based drop schedulers you know stuff like aws cloud watch or then you combine them with lambda functions you combine it with a couple of apis and you can kind of like build yourself an automative um an automation feature so to say for example like send a telegram notification every 12 hours to your users with a summary of their recent activity for example right and so the question is can we use these services to also automate smart contracts and uh yes you could you you could do that but it turns out it's like pretty cumbersome and pretty complex and there's a lot of overhead to actually do that now if you want to build an application or like just that i had before you want to send lunch money to your children every 12 hours every 24 hours right then i think uh it's pretty straightforward and you would actually be able to pull this off but if you talk about building a reliable and scalable decentralized application where you might have like ten thousands of these tasks running all the time there you really shouldn't shouldn't do that um and so yeah here just like a couple of examples that you that you need to consider when actually building such a thing you need to be able to listen to events you need to check every block if something becomes executable you need to monitor basically you will then be able you will be the party that will execute these transactions at the right time so you have to monitor the balance of your um of your of your of your externally owned accounts that will then send transactions you will have to send yourself alerts when these balances go too low you have to kind of catch re-orgs on ethereum right you might think your transaction got mined but maybe there's a re-org three three blocks down the road and your transaction actually doesn't didn't get mined right you can like realize that and then send it again they're all these edge cases um and yeah you have to deal with rpc unresponsiveness rpcs are like infuror alchemy or you're running your format if you want to connect and get information from the chain or send transactions to it right and if the one you're using goes down that you basically cannot connect i think meta infuria had an issue a couple of days ago and literally no one was able to send a transaction to a theorem anymore right and if your dab relies on you sending a transaction at a certain time you're in trouble and kind of like this whole complexity goes exponentially higher if you think about multi-chain if you not only have to run one client for ethereum but then you have to your dap is maybe on ethereum polygon phantom avalanche optimism right then you can like have to run four or five instances these rpcs are even more unreliable than um the ones on ethereum which are kind of kind of mature by now so yeah the the complexity just goes goes higher with that and then there's smaller things like defining optimal gas prices resubmitting transactions when they're stuck because when they're stuck and then you have five other transactions to send they may they might not get mined because the the one previously uses a nonsense lower than the one you're now using and so it's stuck you need to unstack it resubmit it and then there's the whole thing about secure private key management which is a complete rabbit tool to go into as well so yeah if you want to build like a scale of application then this is probably not the best idea so why because it's very time intensive right you need like an own team around the whole thing in order to build a scalable um and you don't want that right so you as the app developer you want to build your dap you want to focus on that and you want to outsource everything else that is not related to like the specific user experience of the people using your product and really to make this really 100 reliable is hard um yeah and so yeah and especially if you go multi-chain so and one important thing as well is if you're building a decentralized application and relies on certain parties executing transactions conditionally and at certain times in the future and you're the only one running it let's say your system goes down or you forgot to pay your aws bill or you run out of ease or whatever no one will execute it anymore right it's it's down so your decentralized application relies on the notion of your particular one party running um this client and if it goes down then the app goes down right so you you would like to do this in a more decentralized way having multiple node operators actually do that so what our hypothesis is is you basically need this native web free job scheduling solution that what we are allowed to build for the past couple of years and yeah this is kind of like how it looks like from an architecture perspective very high level and there's this layer on ethereum or on these networks which is the top one where you have smart contracts and then you have this middle layer which is basically okay how do i communicate the information with the various networks like ethereum and then there's the client side of the whole thing the the clients that the gelato operators run um and there are certain services that do certain parts right you have these job schedulers um on chain which is a smart contract which has several functions and then you can define arbitrary sort of tasks that they these gelato bots should monitor and then execute in certain uh based on certain conditions and these conditions can be defined in the resolver contracts where you can for example say hey when the interest rate from compound has changed to the one on other i i would like to execute a credit or loan refinancing transaction that refinances my loan to this protocol right in this case this smart contract that has this refinance and logic will be the target smart contract the top right one and the one defining when the interest rate has changed accordingly will be the resolver one so um yeah put resolver and target together you can like have to encode the payload and you submit it to the job scheduler smart contract and now uh gelato kind of like knows um that you want to have this automated right and then on the gelato client side there's this event listener service that listens to these events and say okay i know now that i should execute this refinance logic for this particular user and the checker part is in the backend basically the part basically constantly checks the smart contract and verifies okay can i do the refinancing now no i can't and then the next block can i do it now no i can't and it basically goes on like that and once it gets returned that it should execute this refines in transaction the executor part of the thing will basically get it mined reliably on any network that was specified yeah and then the benefits are probably quite obvious um it's basically serverless right so for me decentralized applications also means like the next generation of serverless applications you literally put your front end on ipfs you put your smart contracts on ethereum you run your um you do your automation with gelato and you can basically build applications put them online and you don't have to run anything and they could be transferring millions of dollars every day and this is usually how smart contracts work right and this is what what the power is so it's completely serverless um you don't have to deal with multiple rpcs like we are like the the bots aggregate everything under the hood they get transactions mind reliably fast cheap constantly resubmit to get them in they can deal with all these sort of edge cases that come with like ipc unresponsiveness or re-orgs that happen and then you have multi-chain works out of the box no single point of failure there multiple multiple balls running and then you don't need to worry about private key management in the cloud which is again super dangerous if you don't know what you're doing and then yeah there's a coordination layer in between so if you if you then decide to run multiple instances of your bots they will probably start colliding with each other and raising each other and one gets mined the others won't and all of them will have to pay transaction fees but you only execute their logic once um and so you would you want kind of a coordination layer between that says okay please now you're the one executing you're the one executing like only e2 way each two where you have validators and they have certain slots allocated to them and then they validate the block um yeah so this is kind of like an overview of the the like architecture of the network itself and then what we have done is we we've taken the liberty to build a couple of applications on top of that um or certain isolated certain parts of this whole thing and made it available for developers to use to kind of like either showcase what you can do with it or to to to kind of focus on particular other use cases that you can use this infrastructure network for and those are uni gelato ops and our new multi-chain relay api that i will talk about in a bit and i will just like very briefly touch upon all of them now gelatops is a very cool interface where you can just go to you paste in the contract edges that you have you select the function you want to automate like harvest this vault you paste in the vault address and then you define when you want to execute it you can just say hey this i want to call it every every three days or i want to have like a a custom resolver logic that defines how you can execute it right and then you just click on create task the task is submitted the bots will pick it up and they will start running it and executing the logic and you don't even you don't even have to talk to us or ask permission or something just go there create the task um you can deposit some eth or some medic on polygon or whatever and then you're done yeah this is how it looks and here just like a couple of uh examples of jobs other developers have created and if you go to app.js network there's this leaderboard where you can see all of the the like jobs and tasks that have been created and what they do and how many transactions they have and stuff and you can like compete against each other there and like just some some cool use cases that other projects have used let's say you are building a algorithmic stable coin right an algorithmic stable coin wants to always retain this one dollar pack with it right and it does so by having some sort of oracle and if the price of this particular asset moves above or below a dollar it needs to rebates the currency so to say by issuing more of it or burning some of it and this should then in theory put it back to this one dollar mark and this is basically just like a function that has to be called like every couple of minutes or every hour depending on the network and the transaction fees associated with it and this like there are a lot of projects on on phantom and everywhere where basically people just go there they they automate the rebasing and it happens other things are like harvesting or falls or compounding fees if you if you need to constantly compound the fees of your vaults um on a daily basis or just when the fees are sufficient to actually make it worthwhile paying for the transaction you can easily do it and then some of um some of the node opera some of the various node operators they always need to have eve balances chopped up in various accounts and you can basically use gelato to monitor these balances and then top them up accordingly um then yeah maker dao for example uses this to update adapt ceilings for for their uh for their volts and then you have like funny ones not all the default related ones let's say you you might know avogadro there are these nfts you can pet them and they're people building applications where you automate the padding of your avogadro every eight hours i don't know what the what's the reason behind that but maybe it makes these nfts uh worth more in the future right but this is the sort of thing that you can just rather than click it yourself every eight hours or automate it and then i know some people build applications that distribute convex rewards or olympus pro is a cool one there you can basically uh bond and and get uh and buy tokens at a discount in a week from now by just bonding right today and this kind of like redeeming on the of the bond in a week from now you can just automate with gelato so you don't even have to do it especially if you do like multiple ones you might not want to do it every single time and then other ones like claiming synthetic staking rewards every now right every now and so often so yeah this got like a bunch of stuff people built today and what we recently released which is also super cool is our multichain relay api that is already used in production today by a couple of applications and what it does is basically just let's say you're a developer and you have some sort of notion of prog of wanting to programmatically get transaction mind in certain times and in certain places and especially if you want to go multi-chain um and you don't want to do it like i like recurringly or if you don't want to do deferred transactions so like these conditional transactions but you just want to do it instantaneously right now um then this is really something you should check out um the the the most kind of like most known use cases gasless transactions so if you build a dap you don't want your users to hold eth or or some other network token on the network you're building then you can just use um this api can define a chain id and maybe your app is available in like five different networks right and you can just define a chain id and um get the transactions mined on behalf of the user without them actually having to pay for the transaction they just signed a message and the cool thing here is like right now when you build multi multi-chain applications you you always like let's say you there it's available on phantom and if you remain it or whatever the users always have to like change the network in between and then yeah sorry please connect to this network yeah sorry you need to change it again to this one right then the ux is pretty bad but like if you really build your application with meta transactions in mind then you don't even have to ask them to change the network anymore you can just like let them sign the message and gelato will relay the transactions on the right network on your behalf so they don't even know what network they need to connect to they just like are connected to any network and it just works out the box but in order to use that for meta transactions you you smart contracts need to support them and there's a lot of resources out there that will help you do that right yeah the cool thing here is you can pay with like any erc20 tokens instead of eth like die ucc um and yeah so games is a cool use case for that or also bridges because bridges always need to get transactions mined on all these networks right and so i had this this is some of them are using um this motion api cool this is kind of like how the it's just like a very simple api you can use um and the docs will be released pretty soon maybe over the weekend yeah and then this is an example a really cool one of an application that we actually built internally on top of gelato and this is basically an automated liquid liquidity management solution for unisof v3 um which is super cool because it basically uses rv3 you have to always put your money on your liquidity in certain ranges and when the price moves you're out of range you're not earning fees and so what this service does it allows managers to come in and put automated strategies on top where the um where rebalancing happens based on certain conditions that they define and they can just automate the rebalancing of liquidity to always be kind like around the current price and this was just like a kind of a use case we built but right now in g-uni we have over 10 of unison v3's total tvl already in there over 28 percent of unisport v3s total tvl on optimism are in there and yeah so a lot of projects are actually using it today to make liquidity mining schemes work on user v3 for example because it also makes it fungible so you don't have to worry about all any of the nft stuff that's just very complex yeah this is like a just like a snapshot of some of the projects using us today for all these certain type of applications so you're a good company if you want to check it out and yeah that's i think i'm over the 20 minutes already that's it connect with us if you need help with like automating something this weekend or this week just hit me up with some other guys from gelato in the back ahri and weston you can we wave you can ask them anything as well and yeah that's it thanks

Automatic transcript — names and jargon may be misspelled.