# Gas Profile Snapshot

**Highlights**

* Market/taker fills stay \~82k gas per price level regardless of maker count; sweeps across multiple levels drive the step-ups (\~169k for 10-level sweeps, \~833k–940k for 100-level sweeps depending on path).
* Limit placement into populated levels remains \~98k–160k gas for typical depth; creating a new level costs \~358k–475k.
* Maintainers should batch where possible: cancellation and claim paths are linear (\~66k for one order, \~4.00M sells / \~4.02M buys for 100); withdrawals remain \~5.1k.

> These figures are from an internal benchmark harness and should be treated as indicative. Gas numbers will vary by compiler version, optimizer settings, and chain rules.

## Limit Orders (placement)

| Scenario                                               | Gas Used  |
| ------------------------------------------------------ | --------- |
| Sell limit (new level, empty book)                     | `473,566` |
| Sell limit (new level, +10 levels)                     | `357,962` |
| Sell limit (new level, +100 levels)                    | `359,987` |
| Sell limit (existing level, 0 resting) (not new level) | `338,684` |
| Sell limit (existing level, 1 resting)                 | `151,247` |
| Sell limit (existing level, 2 resting)                 | `150,525` |
| Sell limit (existing level, 5 resting)                 | `151,856` |
| Sell limit (existing level, 10 resting)                | `153,909` |
| Sell limit (existing level, 100 resting)               | `159,350` |
| Sell limit (existing level, 1,000 resting)             | `205,206` |
| Sell limit (existing level, 10,000 resting)            | `236,661` |
| Buy limit (new level)                                  | `474,814` |
| Buy limit (existing level, 0 resting) (not new level)  | `279,969` |
| Buy limit (existing level, 1 resting)                  | `98,077`  |
| Buy limit (existing level, 2 resting)                  | `154,570` |
| Buy limit (existing level, 5 resting)                  | `155,901` |
| Buy limit (existing level, 10 resting)                 | `157,954` |
| Buy limit (existing level, 100 resting)                | `163,396` |
| Buy limit (existing level, 1,000 resting)              | `209,251` |
| Buy limit (existing level, 10,000 resting)             | `240,705` |

## Taker / Market Orders

| Scenario                                   | Gas Used  |
| ------------------------------------------ | --------- |
| Market taker (1 maker, same price)         | `82,525`  |
| Market taker (10 makers, same price)       | `82,467`  |
| Market taker (100 makers, same price)      | `82,473`  |
| Market taker (100 makers, 10 price levels) | `169,227` |
| Market taker (10 makers, diff price)       | `169,266` |
| Market taker (100 makers, diff price)      | `833,428` |

## Sell-Side Taker Orders

| Scenario                                   | Gas Used  |
| ------------------------------------------ | --------- |
| Market sell taker (1 maker, same price)    | `82,555`  |
| Market sell taker (10 makers, same price)  | `82,549`  |
| Market sell taker (100 makers, same price) | `82,555`  |
| Market sell taker (10 makers, diff price)  | `150,180` |
| Market sell taker (100 makers, diff price) | `826,267` |

## IOC Orders

| Scenario              | Gas Used  |
| --------------------- | --------- |
| IOC taker (1 maker)   | `86,052`  |
| IOC taker (10 makers) | `172,755` |

## Sell-Side IOC Orders

| Scenario                   | Gas Used  |
| -------------------------- | --------- |
| IOC sell taker (1 maker)   | `86,025`  |
| IOC sell taker (10 makers) | `153,634` |

## marketBuy() and marketSell()

| Scenario                            | Gas Used  |
| ----------------------------------- | --------- |
| marketBuy (1 maker)                 | `94,984`  |
| marketBuy (10 makers, same price)   | `94,984`  |
| marketBuy (10 makers, diff price)   | `171,845` |
| marketBuy (100 makers, same price)  | `94,986`  |
| marketBuy (100 makers, diff price)  | `940,448` |
| marketSell (1 maker)                | `94,026`  |
| marketSell (10 makers, same price)  | `94,026`  |
| marketSell (10 makers, diff price)  | `161,166` |
| marketSell (100 makers, same price) | `94,028`  |
| marketSell (100 makers, diff price) | `832,571` |

## Matches and Size Updates

| Scenario                         | Gas Used    |
| -------------------------------- | ----------- |
| Limit order w/ match (1 maker)   | `82,595`    |
| Limit order w/ match (10 makers) | `169,322`   |
| decreaseOrderSize (single order) | `60,283`    |
| decreaseOrderSizes (mixed 5)     | `156,711`   |
| decreaseOrderSizes (batch 10)    | `305,459`   |
| decreaseOrderSizes (batch 100)   | `3,094,664` |

## Claims, Cancellations, Withdrawals

| Scenario                                     | Gas Used    |
| -------------------------------------------- | ----------- |
| makerClaim (1 order / 1 taker)               | `42,248`    |
| makerClaim (10 orders / 10 takers)           | `134,673`   |
| makerClaim (100 orders / 100 takers)         | `1,098,052` |
| makerClaim (100 orders / 1 taker same price) | `1,250,204` |
| makerClaim (100 orders / 1 taker diff price) | `1,098,543` |
| Cancel sell (1 order)                        | `66,400`    |
| Cancel sell (10 orders)                      | `424,253`   |
| Cancel sell (100 orders)                     | `4,002,974` |
| Cancel buy (1 order)                         | `66,579`    |
| Cancel buy (10 orders)                       | `426,043`   |
| Cancel buy (100 orders)                      | `4,020,874` |
| Withdraw (after trade)                       | `5,153`     |

## Operational Guidance

* Matching cost per level is O(1).
* Batch operations (cancel/claim/decrease) when possible to amortise per-call overhead; a 100-order batch cancel is \~4.00M sell / \~4.02M buy vs 100 separate \~6.6M+.
* `withdrawTokens` remains effectively constant at \~5.1k and can be safely batched with other actions via `withdrawAfter` flags.


---

# Agent Instructions: 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:

```
GET https://dbookio.gitbook.io/dbook/technical-documentation/orderbook-contract/gas-profile.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
