> ## Documentation Index
> Fetch the complete documentation index at: https://docs.olympex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Gas and fees

> What a swap costs: gas paid to the chain, the gas fields the API returns and how far to trust them, and the integrator fee you can charge. Plus how limit orders and DCA reimburse the execution gas.

A swap carries two kinds of cost. Gas pays the chain to execute the transaction: your wallet pays it in the chain's native token, and none of it goes to Olympex. Fees are shares of the trade itself: the Olympex protocol fee, which every quote for an API account includes, and your integrator fee when you set one. The API estimates gas to help you display costs, but the gas limit of the transaction you send is your decision. Limit orders and DCA work differently: Olympex sends the execution transaction, pays its gas, and is reimbursed in tokens. See [Limit orders and DCA](#limit-orders-and-dca).

## What a swap costs

| Cost | Paid in | Where to read it |
| - | - | - |
| Gas | The native token, paid by `account` | Your own estimate before sending. For display: `dataFeeTransaction` in a single-chain quote. |
| Cross-chain transfer costs | Vary by provider | `estimateCostInUSD` in a cross-chain quote: the provider's estimate of the transfer's cost in USD. What it includes varies by provider. |
| Integrator fee | Output token (single-chain) or source token (cross-chain) | `integratorFeeBreakdown.integratorMarginAmount` |
| Olympex protocol fee | Output token (single-chain) or source token (cross-chain) | `integratorFeeBreakdown.protocolFeeAmount` |
| Liquidity-source fees | The traded token, inside the route | Not itemized, and not part of `integratorFeeBreakdown`. Some liquidity sources charge their own fee within the route. It is already deducted from `outAmount`. |
| Price impact and slippage | Reflected in the output | [Slippage and price impact](/concepts/slippage-and-price-impact) |

## The `gasPrice` hint

Single-chain quotes and swaps require `params.gasPrice`: a gas price in whole gwei, as a string such as `"35"`. It is a hint. Some liquidity sources use it when they price a route. The fee estimates in `dataFeeTransaction` don't use it: `dataFeeTransaction.effectiveGasPrice` reports the gas price the estimate used, in wei. On chains with EIP-1559 fees it is a maximum fee per gas (`maxFeePerGas`, about twice the latest base fee plus a priority fee), so treat the estimates as high rather than as the expected cost. In the example on the [Get a quote](/api-reference/quotes/get-quote) page, the request sends `"35"` and the estimate uses an `effectiveGasPrice` of `385800996250` wei, about 386 gwei.

Send the chain's gas price from your RPC (`eth_gasPrice`) so sources that use the hint price realistically. Convert it from wei to whole gwei, rounded up, for example `Math.ceil(Number(gasPriceWei) / 1e9).toString()`. Some sources reject fractional gwei: `openOceanV3`, for example, fails on `"35.2"` and drops out of the comparison. The hint doesn't set the gas price of your transaction: `POST /swap` returns no gas price, and your wallet or signer sets the fee parameters when it sends. Cross-chain requests don't take `gasPrice`.

On a chain whose gas price is below 1 gwei, rounding up sends `"1"`, which is higher than the real price, so the sources that use the hint price gas as more expensive than it is. The API also accepts a decimal hint such as `"0.05"`, but then the sources that reject fractional gwei drop out of the comparison. Send whole gwei, rounded up, so that every source can quote. Either way, the hint doesn't change what your transaction pays for gas.

## Gas estimates in a quote

Add `includeGasInfo: true` to a single-chain quote to receive `dataFeeTransaction`, a gas cost estimate for the winning route:

| Field | Unit | Example |
| - | - | - |
| `effectiveGasPrice` | Wei | `385800996250` |
| `transactionFee` | Wei. Equals `estimatedGas × effectiveGasPrice`. | `608972212142767500` |
| `transactionFeeInUSD` | USD | `0.074812` |
| `transactionFeeInToken` | Human-readable units of the input token | `0.074812` |
| `valueToApprove` | Human-readable units of the input token. Equals `amount + transactionFeeInToken`. | `10.074812` |
| `nativePrice` | USD per native token | `0.12285` |
| `tokenPrice` | USD per input token | `1` |

The example is a 10 USDT quote on Polygon. `estimatedGas` of `1578462` at `385800996250` wei per gas gives `608972212142767500` wei, about 0.609 POL. At `0.12285` USD per POL that is about 0.075 USD, which is 0.074812 USDT at a token price of 1 USD.

`dataFeeTransaction` is based on the winning source's `estimatedGas`. If the source returns no estimate, the quote omits both `estimatedGas` and `dataFeeTransaction`. If it reports `"0"`, `dataFeeTransaction` is present but its fee fields are zero. Check for both before you display a cost.

`estimatedGas` is the liquidity source's estimate for its own part of the route. It doesn't include the Olympex contracts, so the swap transaction uses more gas: in measured swaps, two to three and a half times the quoted `estimatedGas`. Treat `dataFeeTransaction`, and the `transactionFeeInToken` and `valueToApprove` derived from it, as a lower bound. For the transaction you send, estimate gas yourself, as described [below](#estimatedgas-and-gaslimit-are-estimates).

`valueToApprove` combines the input amount and the estimated gas, both expressed in the input token. The approval that `POST /swap` calldata needs is the exact input amount; see [Approvals](/concepts/security-model#approvals). For a limit order, `valueToApprove` is the starting point for the allowance: see [Limit orders and DCA](#limit-orders-and-dca).

### `gasMultiplier`

`params.gasMultiplier` scales `estimatedGas` when `includeGasInfo` is `true`:

| Value | Multiplier |
| - | - |
| `NONE` (default) | 1× |
| `LOW` | 1.55× |
| `MEDIUM` | 2× |
| `HIGH` | 4× |

Because `transactionFee` is `estimatedGas × effectiveGasPrice`, the fee estimate and the USD and token amounts derived from it scale too. The quote echoes the value in `quote.gasMultiplier`. Use it to show a conservative cost. It changes only the estimate in the quote: `POST /swap` doesn't take it, so it has no effect on the calldata.

## `estimatedGas` and `gasLimit` are estimates

The gas fields come from the liquidity source or provider, and their quality varies:

| Response | Field | What to know |
| - | - | - |
| Single-chain quote | `estimatedGas` | Gas units. `"0"`, or no `estimatedGas` field, means the source gave no estimate. |
| Single-chain swap | `estimatedGas` | `"1500000"` is a placeholder used when the source gives no estimate. It can also be `"0"`. |
| Cross-chain quote | `estimatedGas` | The unit depends on the provider: gas units or a fee in wei. Display only. |
| Cross-chain swap | `estimatedGas` | `"1500000"` is a placeholder used when the provider gives no estimate. Otherwise the unit depends on the provider: for `okx` it is the transaction's gas price in wei, not an amount of gas. Don't use it. |
| Swap, both modes | `gasLimit` | `estimatedGas × 2`. Not reliable. In the single-chain example, the `"1500000"` placeholder becomes a `gasLimit` of `"3000000"`. |

Estimate gas yourself for the exact transaction you send, then add a buffer, for example 20%:

```json eth_estimateGas (data shortened) theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_estimateGas",
  "params": [
    {
      "from": "0x1E67cb01969D79B2B895179e4A07D24a839dBb52",
      "to": "0xA91e13e8BfEbbC57ea008bfb2dE94AdD3F484E68",
      "data": "0x8ad0a76c0000000000000000000000000000000000000000000000000000000000000020…0000000000000000",
      "value": "0x0"
    }
  ]
}
```

`from` is the `account` you sent to `/swap`, and `to`, `data` (or `calldata`) and `value` come from the `/swap` response, with `value` converted to hex. The `data` value above is shortened: send the full calldata. For ERC-20 input, the estimate fails until your approval of `contractToApprove` is mined, because the simulated swap has no allowance to spend.

Run the estimate for every swap, not only to size the gas limit. A `200` from `POST /swap` doesn't guarantee that the calldata executes: a source can build calldata that reverts. If the estimate reverts and the allowance, the balance and the expiry are in order, don't send the transaction. Build the swap again with the next `aggregatorId` in the quote's `aggregatorOrder`, or, for a cross-chain transfer, request a new quote. See [Falling back with `aggregatorOrder`](/concepts/aggregation-and-routing#falling-back-with-aggregatororder).

<Warning>
  Don't send `gasLimit` or `estimatedGas` as your transaction's gas limit by default. Too low a limit makes the transaction revert and still costs gas. Use `gasLimit` only as a fallback when your own estimate isn't available.
</Warning>

## Integrator fees

You can charge your own fee on each trade. Add a top-level `fees` object to [`POST /quotes`](/api-reference/quotes/get-quote) and [`POST /swap`](/api-reference/swap/build-swap):

```json theme={null}
{
  "fees": {
    "feeBps": 25,
    "feeRecipient": "0x1E67cb01969D79B2B895179e4A07D24a839dBb52"
  },
  "mode": "single-chain",
  "params": {
    "amount": "10",
    "chainId": 137,
    "gasPrice": "35",
    "inTokenAddress": "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
    "outTokenAddress": "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
    "slippage": "1"
  }
}
```

| Field | Rules |
| - | - |
| `feeBps` | Integer from 0 to 100, in basis points. `25` is 0.25% and `100`, the maximum, is 1%. |
| `feeRecipient` | EVM address that receives your fee. Required when `feeBps` is greater than 0. The zero address is rejected. |

Fees apply only to signed requests from API accounts, and are ignored otherwise. Send the same `fees` object on the quote and the swap, so the quote you show matches the calldata you send.

### The fee breakdown

Quotes for API accounts include the Olympex protocol fee, shown in `integratorFeeBreakdown`. Every quote carries the breakdown, including when you send no `fees` object: `integratorMarginBps` and `integratorMarginAmount` are then `0`, and the protocol fee still applies. Its rate is as returned in `integratorFeeBreakdown`; the examples show `15`, which is 0.15%.

| Field | Meaning |
| - | - |
| `protocolFeeBps` | The Olympex protocol fee rate, in basis points. `15` is 0.15%. It can be fractional. |
| `integratorMarginBps` | Your `fees.feeBps`, in basis points. `0` when you send no `fees`. |
| `protocolFeeAmount` | The protocol fee, in base units of the output token for single-chain and of the source token for cross-chain. |
| `integratorMarginAmount` | Your fee, in the same units as `protocolFeeAmount`. |

<Note>
  `protocolFeeBps` is in basis points, like `feeBps`: divide it by 100 to get a percentage. It can be fractional, so parse it as a decimal number, not an integer.
</Note>

In the single-chain example on [Get a quote](/api-reference/quotes/get-quote), 10 USDT quotes `outAmount` `"9979975"` with a `protocolFeeAmount` of `"14969"`, which is 0.014969 USDC. With `"feeBps": 25`, the same trade returns `integratorMarginBps` `25`, an `outAmount` of `"9954962"`, and `"14932"` base units for the protocol fee and `"24887"` for your fee.

Read the protocol fee rate from each response instead of hard-coding it. For commercial terms, contact [partners@olympex.io](mailto:partners@olympex.io).

## Limit orders and DCA

For [limit orders](/concepts/limit-orders) and [DCA strategies](/concepts/dca), Olympex sends the execution transaction and pays its gas in the native token. The maker reimburses it in tokens, so the maker needs native token only for its own approvals. The two products differ in which token pays and in what the allowance must cover:

| | Swap | Limit order | DCA order |
| - | - | - | - |
| Who pays the gas | Your wallet (`account`), in the native token | Olympex, reimbursed by the maker | Olympex, reimbursed by the maker |
| Reimbursed in | Not applicable | The token sold (`inTokenAddress`), as a second transfer from `accountTo` | The token bought (`tokenAddressTo`), out of the order's output |
| Allowance to cover | The exact input amount, to `contractToApprove` | `amount` plus the gas cost in `inTokenAddress`, plus a buffer, to the order contract | `totalAmount`, to the order contract |

To estimate a limit order's gas cost, request a single-chain quote for the same chain, pair and amount with `includeGasInfo: true`. `dataFeeTransaction.transactionFeeInToken` is the estimate in the token sold, and `valueToApprove` is `amount` plus that estimate. Both are low: the estimate leaves out the Olympex contracts, and the maker reimburses the gas the execution transaction actually uses, at the gas price it actually pays, converted to the token sold. The order's `gasPrice` field doesn't cap that cost. So add a generous buffer, for example by requesting the quote with `gasMultiplier` `HIGH`. Convert the total to base units before you approve it. [Order signatures and allowances](/concepts/order-authorization#how-much-to-approve) covers the allowance, including how several orders share it.

The limit-order and DCA endpoints don't take a `fees` object: integrator fees apply to `POST /quotes` and `POST /swap`. For commercial terms on limit orders and DCA, contact [partners@olympex.io](mailto:partners@olympex.io).

## What this means for your integration

* Send the `gasPrice` hint from your RPC as whole gwei, rounded up (`"1"` on a chain below 1 gwei), and let your wallet set the transaction's fees.
* Estimate gas yourself with a buffer for every swap, and don't send one whose estimate reverts. Use `gasLimit` only as a fallback, and `dataFeeTransaction` and `estimateCostInUSD` for display.
* Send the same `fees` on `/quotes` and `/swap`, and read `protocolFeeBps` as basis points. Liquidity-source fees are already in `outAmount`.
* For a limit order, approve `amount` plus the gas estimate in the token sold, with a generous buffer. For a DCA strategy, approve `totalAmount`.

## Related

<CardGroup cols={2}>
  <Card title="Slippage and price impact" icon="gauge" href="/concepts/slippage-and-price-impact">
    The costs that show up in the output.
  </Card>

  <Card title="Execute a swap" icon="bolt" href="/guides/execute-a-swap">
    Approve, estimate gas and send.
  </Card>

  <Card title="Get a quote" icon="code" href="/api-reference/quotes/get-quote">
    `includeGasInfo`, `gasMultiplier` and `fees`.
  </Card>

  <Card title="Order signatures and allowances" icon="signature" href="/concepts/order-authorization">
    How much to approve for limit orders and DCA.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.