Skip to main content

Determining gas requirements

Determining gas requirements (gasreq) for your offer logic in a maker contract is important to avoid failures, save on provision, and make offers as attractable as possible. There is a lot that can be said and calculated about gas requirements - we will focus on the essential here, and give you pointers for your own assessments.

What to test​

To determine the gasreq, you need to measure the worst case gas usage when makerExecute and makerPosthook are called. There could be exception cases which are very gas costly, where you simply want the offer to fail instead (and you could skip those).

As a strat builder, you should verify your gas usage in some specific scenarios, and compare deltas to other scenarios tested here. You should then use the results to set a gasreq for your strat which covers the desired worst-case scenarios. The gas measurements are for the inner-most operation.

The gasreq should be taken into account when provisioning.

Exisiting strategies​

MangroveOrder​

Here, we will calculate the optimum gasreq to use MangroveOrder, a Forwarder logic with a simple router:

  • MangroveOrder's most expensive case is 148451 (more details here)

It's worth mentioning as well that there is a slightly more expensive path going through Mangrove core, which should be taken into account:

  • 19675 is the comparable case for core (see here)
  • 22841 is the more expensive path, which would be if an offer existed in the same bin as the reposted offer (see here)

The difference between the two is just above 3000, hence we add that and round up to get an optimum gasreq of 82000 for MangroveOrder.

Kandel​

Standard Kandel​

Here, we will calculate the optimum gasreq to use the Kandel strategy:

  • Kandel's most expensive case is 121413 (see here)

Similarly to MangroveOrder, there is a more expensive path going through Mangrove core to be taken into account:

  • 44339 is the comparable case for core (see here)
  • 45090 is the more expensive path, if another offer existed on the dual offer's bin (see here)
  • The difference is below 1000.

Similarly for the primary offer:

  • 19675 is the comparable case for core (see here)
  • 22841 is the more expensive path, if an offer existed in the same bin as the reposted offer (see here)
  • The difference is just above 3000, so we add both (4000) and round it up to get 126000.