Build scalable dapps with Gelato Transaction Relay - Luis Schliesske (@gitpusha) @ETHDubaiConf

ETHDubai 2022 · 31 Mar 2022 · 25:23

Luis Schliesske of Gelato explains why smart contracts cannot run themselves and how Gelato's automation and relay network fills the gap, at ETHDubai 2022. He covers the pain of running your own bots (private keys, chain reorgs, RPC outages, gas pricing), how resolvers, checkers and executors work, and products such as Gelato Ops, the multi-chain relay API for gasless transactions and Arrakis, the liquidity project spun out of Gelato. Q&A covers front-running and Flashbots, supported chains, a protocol fee of around 10 percent and gas price limits.

Speakers

Topics

From ETHDubai 2022, hosted by DeFi Dubai.

Transcript

GM everybody. Today I'm going to present to you Web3's automation protocol. I'm Luis, I'm founder and legendary member at Gelato. You might also find me as Gitpusher on Telegram and Twitter. So let's start with an example contract here. Some of you might be, I think now this one is off again. Oh yeah, now it works. So some of you might be smart contract developers here. And this is a very simple contract. It's auto token payout. So let's explain Gelato or the need for Gelato by the example of this very simple smart contract. Say you have children, the receivers, and you want to pay them lunch money once every day. Say you want to pay them 10 Shiba Inu every day to buy some lunch somewhere. Now the problem is that the smart contract itself cannot automatically pay out your children. So you would have to go and click a button every day to pay each of them their lunch money.

So smart contracts are lazy. They only define certain logic and states and the logic only gets triggered after an EUA, like an externally owned account, sends a transaction to them. So if no one actually sends a transaction to the smart contract, nothing will happen. So I think there's some common misbelief that smart contracts are like super smart and they automate everything by themselves. But actually at the end of the day, there's always a human or a bot who sends a transaction to trigger the code and execute some function on a smart contract. Smart contracts cannot self-execute. They cannot execute conditionally or recurrently. And this is very different to Web2 applications like JavaScript servers, Node.js servers that run in infinite loops and can respond to incoming requests for always basically, right?

A smart contract cannot do that. So how do we automate with them? Well, Ethereum doesn't support automation. Ethereum doesn't support conditional or recurring executions. And the same goes goes for any other EVM compatible chain or blockchain for that matter. The reason why that's not supported as part of the execution model is because of gas limits. So in the blockchain, you want to be able to sync a network of nodes about on a straight transition in a very short amount of time. And this is a global distributed network of nodes.

So basically, you have to form a block and everything inside of this block has to be synchronous. You cannot basically have arbitrary code execution. The execution has to be finite and that's why you have to define a gas limit and the gas limit corresponds to computational units. And once your gas is used up in a smart contract, you're charged for it. Your transaction is included in the block. The miner gets the money and the block is done. You can't do anything else after that. So that's why we can't have things like set interval and JavaScript or I don't know what programming language you use, but you can't have these basically web server loops that you would be used to from web to development.

Now, there are some people that are maybe like heavy like Solana fans or something and they're a big fan of beefy nodes and they might say, "Hey, but why don't we just let Ethereum clients, miners or full nodes simply, you know, monitor networks for these conditions, for everybody's conditions and then automate tasks for them as part of the block creation." Well, this would make those nodes computationally super expensive, even more expensive than they already are. And at Ethereum, at least, the the ideal we have is that everybody should be able to run one of these nodes by themselves one of one of these days. And believe me, like running a gelato node is already quite computationally expensive.

We have a we have a DevOps guy here who can who can prove that to you. He's he's in the crowd. So yeah, if you want to talk to him about that, it's it's not easy. So yeah, probably not a good place to put it on the Ethereum client itself. That's why for recurring transaction execution for smart contract automation, you do need an off-chain external network. In Web 2, automation is very common. So there's cron jobs for Linux kernels and there's cloud-based job schedules. You're probably using some app that is completely automated in Web 2 every day, like your your messenger apps, all the software as a service application.

They all have automations and they're all using frameworks like AWS Lambda or some other APIs. So why can't smart contract developers simply just also use AWS Lambda or whatever their own scripting to automate their smart contracts? Well, smart contracts and blockchains can be a bit of a pain in the butt, to be honest. There's a lot of things that can go wrong at any time. So first of all, what do we want the system to do, right? We want it to listen to events.

We want to check if they're executable every block. Then if we want to write our own script to automate our own smart contracts, we have to put our private keynote server somewhere. Make sure that it always has enough ETH on there to execute all the automations we want to execute. Maybe if you're just automating for yourself, that's not such a big issue. But if you want to automate for like a multi-user application, you might have some pretty big ETH balances on there. Unfortunately, because gas is expensive on Ethereum. So that also gives you like this sort of security risk. You know, you have to put a lot of funds on a key that's on a server. You have to get really good at like security operations for that to be safe.

And then there's nasty things like chain reorgs, especially on like Polygon. They can be really deep. BSC, don't even get me started on that. I've seen reorgs there that are like 200 blocks deep. So a reorg is basically when your transaction gets included and you think it's included, but then the chain somehow moves to another chain and it's not included anymore. If you run a programmatic application that is supposed to track of what task has been executed over time, you need to have like a final result, right? So to deal with reorgs, it's really hard. You have to add a bunch of code to your application to make sure you do that properly.

You have to simulate transactions before you send them in order to make sure that they don't revert. Otherwise, you're paying costs of the network for basically a non-execution. You have to handle with all these RPC unresponsiveness. Like, you know, Infura has been down in the past. So how do you handle with that if you want to guarantee your users 100% uptime? Then you have to add multi-chain support to also be available on every chain. You have to take care of efficient gas price estimation. You have to take care of re-submissions of transactions when they get stuck. It's a pain.

So I think serverless is a great model of the last 10 years and I think we can also have serverless applications on Ethereum. So basically if you don't have serverless applications, if you don't have gelato network, then it's very time intensive to build a system and maintain it from scratch to support automation in your application. It creates a lot of overhead. You need like a dedicated DevOps team to basically ensure 100% uptime. It's very hard to guarantee this uptime and you have to also do monitoring.

You have to execute multiple jobs and it gets exponentially more complex the more networks you add to it. And even if you achieve that, even if you are that 10x engineer, at the end of the day, you are then the single point of failure of your whole application. And probably in decentralized applications, you don't want to build applications where everything relies on your script somewhere on Heroku or wherever you deploy, right? So we do need a Web3 job scheduling solution for everybody. And that's basically gelato.

We started gelato three years ago in 2019 and we had this vision to become Web3's automation protocol. And basically it's still the same vision today. We saw this future and it's really developing now. There's more and more automated applications. If you think about limit orders, if you think about auto compounding of yields, Yearn is a great project which also has automation built in, right? And there's so many projects using us today already and we see it growing every day that it's pretty clear that actually this vision of needing a separate external protocol to automate smart contracts is for real.

So gelato works by basically having job schedulers and resolvers. The resolver is the part that you as a smart contract developer would need to write yourself in order to integrate with the protocol. And a job scheduler is just either an on-chain smart contract or an API that you can submit your tasks to and the resolver will tell the gelato network when your task is executable and what payload to execute it with. So gelato then under the hood is just a bunch of clients that people can run. They have event listeners to listen to the events that you define that they should react to. They have checkers to check certain conditions that you can define. Like for example, for a limit order, is the price of that user's limit order reached on Uniswap?

If so, then please execute it. And then you have the executors which are very, very specialized software modules to get thousands of transactions mined reliably on-chain in a reasonable amount of time. So yeah, the client is quite heavy and actually we're working on our private beta and we will release this beta this summer. It will be the first stable release of this client and we will onboard more node operators to the network and grow it from there. So the benefits of using gelato is that you don't need to self-host servers on AWS or other cloud providers. You have these really cool RPC aggregation and multiple fallback methods so you never rely on just Infura or one RPC only.

Basically these bots aggregate all of them for you and some of these bots even run their own nodes. I know that the gelato bot, for example, runs BC nodes, Polygon nodes, Ethereum nodes, all of that. And it has multi-chain support, it works on all the most popular EVM compatible networks and there's also no single point of failure. So the protocol is open, executors can join it. We have a GEL token, soon we will release staking of that token so anybody with a stake can join at the moment. It's still a permissioned whitelist but we want to move to a more open model with this token.

And yeah, there's reliable transaction relaying, the transaction always gets fast, gets mined fast and you don't need to self-manage any of the private keys anymore on your servers. The whole thing catches reorgs for you, you don't have to worry about that pain. And what's also really cool and what's like the original vision of gelato is that bots come together and they are actually coordinated in a consensus network to avoid them raising each other to execute your tasks. So an old system like MakerDAO for example actually had an open keeper system and there basically the idea is that anybody that wants to liquidate a Maker Vault can do so but what ends up happening is that all of these bots are trying to get the penalty, they're all raising each other, there's like, I don't know, maybe 10 of them or something and only one of them wins.

It's a winner takes all and all the others have their reverted transactions, they have huge costs so the whole system bleeds so much value to the miner and it's not really sustainable. You need a protocol to coordinate these bots efficiently to tell them, now it's your turn to execute this transaction, now it's your turn, now it's your turn. And that's basically what we've built, a fully parallelized algorithm to coordinate bots in the network. So yeah, let's talk about some products, some of the bigger ones that gelato has shipped. So Giuni is an automated liquidity management platform which is actually an application in and of itself. It started out as a pilot project so we're currently spinning it out into its own project.

It's not infrastructure, it's just like an application on top of Uniswap. But it's really cool for Uniswap with really automated liquidity management. Then GelatoOps is really like the core general framework that developers should give a try. It has a nice UI, it's a bit like GitHub Actions if you think about it. And you can go there and basically automate any smart contract. And then we have the multi-chain relay API which is used by bridges to just relay transactions in real time across networks. So yeah, GelatoOps works like this. You basically can define a contract that you want to automate.

For example, a vault that you want to harvest. Then you can define, like in the simple case, you can define, okay, let's define a time interval. I want to call this harvest function every three days. You create the task on the UI and it's done. Every three days your vault will get harvested and you can imagine this with any smart contract. The logic you can define as a developer in your resolver is arbitrary. Anything you want, automate it. You can automate with this very simple UI and just by deploying your own resolver. If you need help doing that, there's documentation and also we are more than happy to help you in our telegram. So we have some cool jobs live today already.

For example, a lot of people use GelatoOps to rebase algorithmic stablecoins. I know that on Phantom there's a lot of stuff going on there. There's compounding fees and yield farming vaults and people also use this to auto-top up their accounts. Maybe you even run a bot yourself and you deplete the balance there and you want to use Gelato to just automatically top up the balance from some secure multi-sick or something. And then Maker, for example, uses this to update their debt ceilings periodically. Someone built an Avogadji petting service, which I think was really cool. So you can also automate gaming, NFTs and all of this.

Yeah, and distributing convex rewards, redeeming Olympus bonds and claiming weekly staking rewards on synthetics are some of the things we've seen. But there's more added every day and some of these use cases really we never thought of that are built on top of GelatoOps. And the cool thing is you don't even have to, it's permissionless, you don't have to talk to us. You can just deploy your resolver, use this UI and just start the automation. Sometimes we see some new transactions on the network, we never talk to the people that automate them. The multi-chain relay API is basically for bridges, for games or NFT platforms that want to support gasless transactions for their users and general bot operators.

So if you have a relay component in your application, then basically you can replace it with Gelato's relay API so that it's serverless, you don't have to run that server anymore. You can trust on a network of nodes to do it. You have all the benefits, it's very scalable. You can, for example, offer your users to pay in your own token or any ERC-20 instead of ETH or Matic or whatever. And it works on all the popular EVM networks. And yeah, so some cool use cases, for example, would be user onboarding for games. You can, your users don't need a wallet, they don't need to go to an exchange to buy some networks token to start playing. They can, if you integrate this multi-chain relay API, they can get started by submitting signatures to off-chain to the network and then some bot on the network will do the transactions for them if the developer is willing to pay for the user's transactions.

Which many developers are these days, I think. So yeah, a very simple quick snapshot of the API. It's, you just specify the chain, the destination address of the contract, the payload, the token address you want to pay with, the fee and bam, your transaction gets mined on this chain in a very reliable and quick manner. So Giuni, that's the automated liquidity management, definitely deserves mention here. It is its own project now, but it started as Inside Gelato and what it enables you to do is to automatically compound the fees you earn in Uniswap V3 pool. Uniswap doesn't support that natively for LPs.

And it also automatically, like in the future, we will do automatic rebalancing around the price so you can have very efficient concentrated liquidity and maximize your yield. And that's also being heavily used by a lot of projects already. Actually, it amassed a TVL of half a billion, depends on the price, of course, of the tokens. And yeah, so this was already announced. We spun this project out into Arrakis. You should, if you like Uniswap V3 automation, you should visit Arrakis to see what we did there. So today, there's a bunch of projects using us already.

This wasn't updated. I think we started in 2019. Our first version was out in 2020. And since then, SpookySwap on Phantom, for example, SpiritSwap, PancakeSwap on Binance Smart Chain, on Ethereum Maker uses us, Arwe has used us, Beefy Finance. A lot of cool dApps already use us for automation. So if you want to join the Gelato gang, if you want to build automated dApps yourself, you will be in good hands. And we're more than happy to welcome you to the community and help you build these apps. So yeah, if you want to reach out, send me an email, Luis@gelatoDigital.

Might be wiser to send it to hi@gelatoDigital. I've been a bit slow with my emails recently. But otherwise, just jump into our Telegram on gelato.network. You will find all the links to our social. Thanks a lot for listening. And yeah, let's build some automated dApps together. Thank you very much. I've got a question of my own. So what about front-run protection before today's jobs? Oh, very good that you mentioned it. Yeah, actually that's not on the slides. There are some cool things that are not on the slides.

We, on Mainnet, we already support, like all our transactions go through Flashbots. So we are quite close with the Flashbots team. And the problem is that Flashbots doesn't exist on every chain yet. So as soon as it's rolled out on other chains, we will use it by default. I think like I came to this realization myself. I've been in Ethereum for a long time. And at first I thought something like Flashbots is not so great. Because it's like using private relayers to the miners and so on. It seemed a bit weird. But now that I understand MEV and so on, going through a public mempool is just crazy. Even for like some little things, we never thought there would be MEV.

But we got front-run on like some relay transactions and so on. So yeah, we are using Flashbots on Mainnet and on other chains. We have to design the application in certain ways that they don't emit any MEV during the execution. Thank you very much. Any more questions? Hey, which chains are supported right now by Gelato? We are on Ethereum, Polygon, BSC or BNB chain now. Phantom, Avalanche, all the EVM chains.

Boba, Optimism, Arbitrum. Noses chain. Yeah. And I think we are deploying to StarkNet soon and also looking to Solana and so on. And what about Solana? So is it more complicated or not? To be honest, I'm not an expert yet. So we will see. But definitely people at Solana, I think they are more in the camp of okay, these nodes can be quite beefy. I don't think the nodes would ever support like automation built in there as well because that's just adding so much more complexity to them outside of the normal consensus protocol. So, but yeah.

In any camp of people that think that a lot of people should run these nodes and that should be kind of lightweight, building something like Gelato into the core client is not really an option, I would say. So you will always need like this external middleware that we have built. Okay, thank you. Hi. What about the gas fees? How can I set the gas fee? I've seen that you have the protocol fee, but I know that flashbots, they take their separate fee and you pay that fee directly to miner. And how can you set that fee?

Because in fact, some people can front run you even in flashbots, privately, when they know that your transaction is scheduled for some time, they can set the lower fee and use that and then basically front run you inside the private pool. How can you handle that? Yeah. So just in general, front running is like not a huge issue for us in like the popular sense where you think about, I don't know, sandwich trades on Uniswap or something. Like all the applications we built are usually sort of front run protection in the, protected in the application design, like limit orders for example.

The amount of MEV you can extract is very minimal. So first of all, you have to start there. Your application should ideally be designed with MEV in mind and not be front runnable. There shouldn't be any MEV leaks to an arbitrary message sender and that's how you can prevent anybody from sniping your transaction. We have protocols already used Gelato like as the platform of their decentralized relayers. So they even have modifiers like only Gelato can call this function and then nobody can snipe us in the mempool, only Gelato bots can. So, but to your question, you can specify a gas price and you would have to build that into your resolver and define like a, at least like a maximum gas price or a minimum gas price to be used.

I think inside flash bots, the point is that it's a sealed bid auction, right? It's private. So, I mean the gas you pay actually also goes directly to the miner. So we're sending transactions via flash bots that don't have this block.coinbase, whatever. They just pay normal gas fees. Gas fees are also MEV, right? So, so yeah, we didn't have any issues, any issues there. Yeah, good question. So there is a protocol fee. Gelato actually has been a revenue product revenue generating protocol from day one. And usually it's around 10% on top of the normal transaction fee.

So if you schedule, for example, some, some automated compounding or something, then it would be, and that would normally cost you $1 with Gelato will cost you $1 and 10 cents for the service. Okay. And when the gas price in Mainnet is 400 Guay and my transaction is set for 200 Guay max gas price, what happens when it is supposed to be sent but it can't be? It's waiting or what?

These are very, very detailed questions, I have to say, but that's, that's good. So yeah, I mean, if the Mainnet gas price is 400 Guay and your transaction is 200 Guay, then it's simply, it won't be sent to the network. But yeah, this requires some custom logic actually for gas price specification. You're right about that, yeah. And do you have the tools to set this custom gas price in your Gelato network? Yeah, actually the first use case we did was minting Qi gas tokens. That was before the EIP.

But yeah, so that was also like you specified the gas price that you want, like a lower gas price to mint them because that would give you some profit later on if the gas price goes up again. So yeah, we have built these things to be honest, we haven't done so in a long time. And I know it's possible, but recently no one has requested it. So, but it's definitely possible. You can do it in the smart contract level or like you could also specify it at the back end. You mentioned that G-Unit allows automated rebarancings on Units of v3. I was curious, what kind of algorithm does it use to create a new price range for the LP position?

Once the price goes up. Sir, you want the alpha. So, I mean, to be honest, I think part of the reason G-Uni is so successful, or I should say Arrakis now, it's called Arrakis now, is because we realized very early on that people get wrecked. We try to auto-rebalance them, they get absolutely wrecked. And the answer is there is currently at least no known formula or good algorithm to solve it. There's a bunch of really smart people working on this, Arrakis included. But yeah, actually, at the moment, all of the G-Uni pools, they still just auto-compound the fee.

We switched off the auto-rebalancing a while ago because it wasn't too good for the users. But now we have a research team working on these algorithms, but I actually don't know the exact algorithms and I'm not even sure if they will be published or not. But there's a team working on this to ship this to G-Uni users. All right, I think that's a wrap. Yeah, thank you very much for your speech. Thank you very much. It was really useful and probably a really good tool for everyone to use if you need some sort of automation. Because I know so many people who've got like 10 tabs open just to claim the rewards every day.

Yeah, don't do that. Use gelato. We want to save some time there.