August 13, 2022

This article was first posted on this site.

The profitability of a cryptoasset trading strategy running on Ethereum DEXes is dictated to a large extent by its gas optimization strategy. With too low a gas price, someone else’s bot will beat you to your trade. But with too high a gas price, your profit may be completely eaten away in fees. With dfuse’s new Speculative Execution endpoints, your bot can understand the other transactions in the mempool and see which ones it has to beat out, and which ones to let pass because they are not competing for the same trade. 

Ethereum DeFi traders are competing against each other in a completely new market system, looking to optimize profits each step of the way. Compared to traditional market books which fill orders on a first-come-first-served basis, blocks on Ethereum are mined on average every 12 seconds. This means that having your trade filled first in the block is the primary requirement to becoming profitable. The second step is to understand which transactions you can safely allow to pass before yours.

In this all-pay auction system for priority block inclusion, it is commonplace to see gas prices fluctuate wildly from one block to another. This can be triggered by a simple Ethereum token transfer wanting to complete immediately, causing a trading bot to bid higher than the transfer, or by 2 or more bots competing for the same arbitrage opportunity, or even for different opportunities. This means that within any block, you may see 2 bots outbidding each other when in reality they could each complete their desired trades with a lower priority inclusion in the block. 

dfuse on solana network

Most trading bots cannot decode other transactions in the mempool, forcing them to set their gas price using incomplete information. This is because the event traces are only unpacked and understood once the transaction has been processed by a node. With dfuse’s Speculative Execution – State Tracker endpoint, you can filter the mempool for any transactions that seek to pass through any of the trading pairs which you intend your trade route to take. These are the only transactions that are important to you in that moment, and thus the only ones that need to be included in your gas pricing strategy. 

Additionally, our Speculative Execution – Execute endpoint enables you to pass an unsigned transaction and returns deep execution traces based on the current state. Some of the ways in which our users are currently benefiting from this include:

  • Ensuring that their transactions have the desired outcome, saving on failed transactions costs
  • Optimizing gas usage by inspecting how much gas each call within the tree will consume
  • Setting an optimal gas price to compete against only relevant transactions within the mempool
  • Optimize your use of gas tokens to bring down your transaction cost
  • Getting an accurate picture of the number of protocol tokens you will be farming as a basis for an accurate profit analysis

If you’d like to try out some examples of how you can utilize these endpoints, please play around with these samples in our in-browser playground. Since queries will read data from the mempool, you will need to update the hash in the query variables tab to a transaction that is currently in the mempool at the time of viewing. 

  • Execute – Pass all of the relevant info within the query variables
  • Execute – Provide a hash of a pending transaction from the mempool (returns speculative execution state when it was first seen in the mempool, does not update as state continues to change)
  • Execute – Provide a hash of a pending transaction from the mempool (returns speculative execution state against each updated state)
  • State Tracker – Pass in query variables to filter the mempool against

Set yourself apart by getting your data from Ethereum’s fastest data source. Sign up for a dfuse account today, and explore how you can build a bot that maximizes your profit.

Leave a Reply

Your email address will not be published.