Limit Orders Protecc: Powered by Gelato, mistX Labs, and Flashbots

Eduardo Carvalho
Gelato Network
Published in
4 min readNov 8, 2021

Ethereum users have long been reminded of the dangerous and sophisticated bots lurking in the mempool. In particular, Decentralized Exchange (DEX) users wanting to place market orders will often be preyed upon by bots that either immediately decode their trade’s intent, or are able to do so via simulation. This opens up a broad range of frontrun exploits, including sandwich trading: A bot is able to place a transaction immediately before the user’s in order to inflate her price, and then proceed to take profit by submitting another transaction right after. Typically the amount of profit a bot can extract is upper-bounded by a user-defined slippage tolerance, but sandwich bots tend not to discriminate against it as long as it is profitable for them. Hence most trades that are sandwichable will be sandwiched by said bots, yielding poor user experience and becoming detrimental for Ethereum in the long-term if left untackled.

Another type of order which is both straightforward and important to users of Centralized Exchanges are limit orders, in that users specify the minimum price they are willing to have their order settled for. This is not immediately trivial to bring to DeFi, as limit orders may take hours or days until the market is able to offer its required price, meaning that there has to be an off-chain backend that executes the required smart contract calls at the right time. At Gelato, we have built both the on and off-chain infrastructure required to bring limit orders to DeFi users and developers, in a way that is easy to integrate with multiple DeFi protocols. Ease of integration with any dApp is ensured by our react library. The user can submit any valid order between two tokens, and we ensure that the appropriate ETH transaction fee is discounted while delivering the best possible execution price. On top of what we built, it would be nice to have a means of protecting users from frontrunning exploits, starting with the Ethereum mainnet.

Enter post-Flashbots Ethereum

Flashbots have built mev-geth, a version of the geth client that implements a blind auction model: Bots and users submit one or more transactions in a sequence, usually called a bundle, and bid for a portion of current block space. However, instead of submitting to the mempool, bundles are privately submitted to a relay endpoint that lives off-chain. In this relay, the winning bids are determined by ranking according to effective profit paid to the miner and then forwarded to said miners who will build and propose the block — you will find more details in the Flashbots Docs below:

While improved user experience has been a goal since the launch of mev-geth, some time was needed in order to build the off-chain tooling required to allow users to enjoy the transaction privacy and ordering features that mev-geth offers. Earlier this year, mistX Labs pioneered UniswapV2 and SushiSwap market orders via their DEX that utilizes Flashbots. Users not only enjoy the frontrun protection that comes with privately submitted transactions but also do not pay upon having their transactions reverting, leading to considerable gas cost savings on Ethereum mainnet. Moreover, with the recent introduction of Mega Bundles, more users can reliably benefit from Flashbots privacy due to increased block space allowance. This has led the mistX Labs team to build the mistX API, where anyone can submit raw signed transactions in private. The mistX API builds and signs the corresponding bundle with a highly-reputed private key while taking care of other backend details such as re-submission and error logging.

We are proud to announce that, in collaboration with mistX Labs, we have combined the best of both worlds: A version of our Limit Orders service that is fully compatible with Flashbots, where submission is done via the mistX API.

We have just launched the first version on our Sorbet Finance UI. We welcome everyone to try it and reach out to us with any questions or feedback. We look forward to bringing improved UX to Ethereum mainnet users, and further welcome dApp and protocol developers to integrate this service.

About Gelato Network

Gelato Network is web3’s automation network, enabling developers to automate & relay arbitrary smart contract executions on and across all EVM-based compatible blockchains such as Ethereum.

Gelato’s goal is to provide developers with a reliable, scalable & decentralized network to which they can outsource all of their web3 related DevOps operations.

Examples of which features are powered by Gelato include:

  • Limit Orders on PancakeSwap
  • Periodically updating debt ceilings on MakerDAO
  • Offering users gasless token claims on Connext
  • Automatically compounding yield farming vaults on Beefy Finance
  • Automating the breeding of new digital racehorse NFTs on ZED RUN
  • Rebasing of algorithmic stablecoins with Tomb Finance
  • Updating price oracles on Abracadabra


► Check out what we’ve been working on at 🍦 https://gelato.network/🍦

Connect with us:

🐦 Twitter | 💬 Telegram | 📺 YouTube | 🔗Linktree

--

--