> For the complete documentation index, see [llms.txt](https://docs.mangrove.exchange/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mangrove.exchange/dev/strat-lib/guides/determining-gas-requirements.md).

# Determining gas requirements

Determining [gas requirements (gasreq)](/dev/quick-links/glossary.md#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[​](https://old.docs.mangrove.exchange/developers/strat-lib/guides/howtoGasreq#what-to-test) <a href="#what-to-test" id="what-to-test"></a>

To determine the `gasreq`, you need to measure the **worst case gas usage** when [`makerExecute`](/dev/quick-links/glossary.md#makerexecute) and [`makerPosthook`](/dev/quick-links/glossary.md#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](https://github.com/mangrovedao/mangrove-core/blob/2ae172805fd8b309c30b2dc877dba66245abbb3e/test/core/gas/README.md#scenarios). 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](/dev/protocol/technical-references/makers/offer-provisions.md).

### Exisiting strategies[​](https://old.docs.mangrove.exchange/developers/strat-lib/guides/howtoGasreq#exisiting-strategies) <a href="#exisiting-strategies" id="exisiting-strategies"></a>

#### MangroveOrder[​](https://old.docs.mangrove.exchange/developers/strat-lib/guides/howtoGasreq#mangroveorder) <a href="#mangroveorder" id="mangroveorder"></a>

Here, we will calculate the optimum `gasreq` to use [MangroveOrder](/dev/strat-lib/technical-references/api-preferences/strats/src/strategies/mangroveorder.md), a Forwarder logic with a [simple router](/dev/strat-lib/technical-references/liquidity-routing.md):

* MangroveOrder's most expensive case is `148451` (more details [here](https://github.com/mangrovedao/mangrove-strats/blob/a265abeb96a053e386d346c7c9e431878382749c/test/strategies/MgvOrder.gasreq.t.sol#L18))

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](https://github.com/mangrovedao/mangrove-strats/blob/a265abeb96a053e386d346c7c9e431878382749c/test/strategies/MgvOrder.gasreq.t.sol#L22))
* `22841` is the more expensive path, which would be if an offer existed in the same bin as the reposted offer (see [here](https://github.com/mangrovedao/mangrove-strats/blob/a265abeb96a053e386d346c7c9e431878382749c/test/strategies/MgvOrder.gasreq.t.sol#L23))

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[​](https://old.docs.mangrove.exchange/developers/strat-lib/guides/howtoGasreq#kandel) <a href="#kandel" id="kandel"></a>

**Standard Kandel**[**​**](https://old.docs.mangrove.exchange/developers/strat-lib/guides/howtoGasreq#standard-kandel)

Here, we will calculate the optimum `gasreq` to use the [Kandel](/dev/strat-lib/technical-references/api-preferences/strats/src/strategies/offer_maker/market_making/kandel.md) strategy:

* Kandel's most expensive case is `121413` (see [here](https://github.com/mangrovedao/mangrove-strats/blob/a265abeb96a053e386d346c7c9e431878382749c/test/strategies/kandel/Kandel.gasreq.t.sol#L21))

Similarly to [MangroveOrder](/dev/strat-lib/technical-references/api-preferences/strats/src/strategies/mangroveorder.md), there is a more expensive path going through Mangrove core to be taken into account:

* `44339` is the comparable case for core (see [here](https://github.com/mangrovedao/mangrove-strats/blob/a265abeb96a053e386d346c7c9e431878382749c/test/strategies/kandel/Kandel.gasreq.t.sol#L23))
* `45090` is the more expensive path, if another offer existed on the dual offer's bin (see [here](https://github.com/mangrovedao/mangrove-strats/blob/a265abeb96a053e386d346c7c9e431878382749c/test/strategies/kandel/Kandel.gasreq.t.sol#L24))
* The difference is below `1000`.

Similarly for the primary offer:

* `19675` is the comparable case for core (see [here](https://github.com/mangrovedao/mangrove-strats/blob/a265abeb96a053e386d346c7c9e431878382749c/test/strategies/kandel/Kandel.gasreq.t.sol#L27))
* `22841` is the more expensive path, if an offer existed in the same bin as the reposted offer (see [here](https://github.com/mangrovedao/mangrove-strats/blob/a265abeb96a053e386d346c7c9e431878382749c/test/strategies/kandel/Kandel.gasreq.t.sol#L28))
* The difference is just above `3000`, so we add both (`4000`) and round it up to get `126000`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mangrove.exchange/dev/strat-lib/guides/determining-gas-requirements.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
