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

# Economics

> Settlement fees, the 3-way fee split, surplus management, settler rewards, gas reimbursement, and wash trade resistance.

## Overview

Geode's economic model ensures three things:

1. **Settlers are incentivized** to settle batches promptly
2. **Wash trading is unprofitable** — batches can't extract more than they contribute
3. **The protocol captures value** from direct swap activity while permanently strengthening curve markets

<Info>
  **Core invariant**: A batch cannot withdraw more settlement reward than that batch economically contributed, except for a tightly capped gas reimbursement.
</Info>

## Fee Sources

| Fee                              | Rate          | Source                                       | Beneficiary                                  |
| -------------------------------- | ------------- | -------------------------------------------- | -------------------------------------------- |
| Settlement fee                   | 0.1% (10 bps) | Deducted from each filled intent's input     | Settler                                      |
| Direct swap fee (curve pools)    | 0.3% (30 bps) | Charged on direct swaps via `beforeSwap`     | 1/3 curve reserve, 1/3 treasury, 1/3 surplus |
| Direct swap fee (standard pools) | Configurable  | Charged on non-intent swaps via `beforeSwap` | \~1/3 treasury, \~2/3 surplus                |
| Gas reimbursement                | Gas-based     | Drawn from surplus, capped per batch         | Settler                                      |

## The 3-Way Fee Split (Curve Pools)

Direct swaps on curve pools charge a 0.3% fee that is split three ways:

| Share | BPS    | Destination       | Purpose                                                                     |
| ----- | ------ | ----------------- | --------------------------------------------------------------------------- |
| \~1/3 | 3334   | Curve ETH reserve | **Permanently increases the floor price** — this ETH can never be withdrawn |
| \~1/3 | 3333   | Protocol treasury | Protocol revenue                                                            |
| \~1/3 | \~3333 | Surplus pool      | Funds settler gas reimbursement                                             |

The reserve fee is the most interesting piece — it means every direct swap permanently ratchets the curve's floor price upward. The more trading activity a token has, the higher its floor.

<Info>
  For **standard pools** (non-curve), there is no reserve fee. The fee is split \~1/3 to treasury and \~2/3 to surplus.
</Info>

## Settlement Fee

Every filled intent pays a settlement fee from its own input **before** that input routes to internal matching, the curve, or the AMM:

```
gross input = intent.amountIn
settlement fee = gross input × settlementFeeBps / 10,000
net input = gross input - settlement fee
```

* **Buy intents**: fee is denominated in currency0 (e.g., WETH)
* **Sell intents**: fee is denominated in currency1 (e.g., the token)
* Only **net input** participates in matching, curve, or AMM routing
* The fee amount remains in the PoolManager as unrouted balance

The settler claims these fees via `poolManager.take()` at the end of settlement.

### Why Input-Side?

Deducting fees from the input (not the output) has important properties:

<CardGroup cols={2}>
  <Card title="One-Sided Batches Work" icon="check">
    A batch with only buys (or only sells) still produces fees. There's no dependency on opposite-side intents existing.
  </Card>

  <Card title="Self-Funding" icon="coins">
    Each batch's fees come from that batch's participants — not from a shared pool that could be drained.
  </Card>

  <Card title="Clean Distribution" icon="arrows-split-up-and-left">
    Output distribution is already net of fees. No cross-side deduction needed — each buyer/seller gets their full pro-rata share.
  </Card>

  <Card title="Curve Integrity" icon="chart-line">
    In curve mode, curve reserves receive net input. Fees never inflate the Geocurve's price or reserves.
  </Card>
</CardGroup>

## Settler Reward

The total reward a settler earns from a batch:

```
settlerReward = batchSettlementFees + min(surplusAvailable, gasReimbursement)
```

### Component 1: Batch Settlement Fees

```
buyFees  = totalFilledBuyInput  × settlementFeeBps / 10,000   (in currency0)
sellFees = totalFilledSellInput × settlementFeeBps / 10,000   (in currency1)
```

The settler always receives these in full — they come from the intent owners' own deposits.

### Component 2: Gas Reimbursement

```
gasUsed = gasStart - gasleft()
gasCost = gasUsed × tx.gasprice
gasReimbursement = min(
    gasCost × gasReimbursementMultiplier / 100,
    maxGasReimbursement
)
```

Gas reimbursement is drawn from the pool's accumulated surplus. Key properties:

* **Capped**: never exceeds `maxGasReimbursement` per batch (default: 0.01 ETH)
* **Gas-based**: scales with actual gas consumed, NOT with matched volume
* **Surplus-funded**: draws from `surplusCurrency0` then `surplusCurrency1`
* **Best-effort**: if surplus is insufficient, the settler receives less

This serves as a **liveness backstop** — settlement remains viable even when fees alone don't cover gas costs.

### SettlerPaid Event

Every settler payment emits an on-chain audit trail:

```solidity theme={null}
event SettlerPaid(
    PoolId indexed poolId,
    address indexed settler,
    uint256 settlementFee0,      // from buyer input (currency0)
    uint256 settlementFee1,      // from seller input (currency1)
    uint256 gasReimbursement0,   // from surplusCurrency0
    uint256 gasReimbursement1    // from surplusCurrency1
);
```

Off-chain monitoring can verify:

* Settlement fees scale linearly with volume (input-funded)
* Gas reimbursement is constant across volume tiers (gas-based, capped)

## Surplus Management

### Accumulation

Surplus comes from **direct swap fees** — the fee charged by the `beforeSwap` hook on non-intent swappers:

* **Curve pools**: 1/3 of the 0.3% fee goes to surplus (\~0.1% per swap)
* **Standard pools**: \~2/3 of the fee goes to surplus

Surplus is held as ERC20 balance on the hook contract itself.

### Draw-Down

Surplus is drawn for two purposes only:

1. **Gas reimbursement** — capped, per-batch, gas-based (for any pool)
2. **Deployer royalty** — curve pools only, sized from matched volume

Surplus is **never** used to fund settlement fees. Settlement fees are self-funded by each batch's participants.

## Wash Trade Resistance

### The Attack

A wash trader submits matched buy and sell intents for the same amount. In a naive surplus-funded model, the settler reward would scale with matched volume, allowing surplus extraction.

### The Defense

Under Geode's per-intent fee model, wash trading is **strictly net-negative**:

<Steps>
  <Step title="Buy Side Pays">
    `washAmount × settlementFeeBps / 10,000` from currency0 input
  </Step>

  <Step title="Sell Side Pays">
    `washAmount × settlementFeeBps / 10,000` from currency1 input
  </Step>

  <Step title="Net P&L">
    The washer loses fees on both sides. They receive back less than deposited. The net cost is always negative.
  </Step>

  <Step title="Surplus Exposure Limited">
    Gas reimbursement is capped at `maxGasReimbursement` (0.01 ETH) regardless of volume. The washer can't inflate the gas draw by adding more volume.
  </Step>
</Steps>

### Worked Example

At default parameters (0.1% fee, 0.01 ETH gas cap):

| Wash Volume | Fee Cost (Both Sides) | Max Surplus Extracted | Net P\&L      |
| ----------- | --------------------- | --------------------- | ------------- |
| 1 ETH       | 0.002 ETH             | 0.01 ETH              | +0.008 ETH    |
| 5 ETH       | 0.01 ETH              | 0.01 ETH              | **0 ETH**     |
| 10 ETH      | 0.02 ETH              | 0.01 ETH              | **-0.01 ETH** |
| 50 ETH      | 0.10 ETH              | 0.01 ETH              | **-0.09 ETH** |

The break-even point is \~5 ETH. Above that, every additional ETH of wash volume costs the attacker more. The gas draw remains constant.

## Gas Cost Profile

Settlement gas scales approximately linearly with batch size after a fixed overhead:

| Batch Size (N) | Total Gas | Per-Intent Gas |
| -------------- | --------- | -------------- |
| 1              | \~397K    | \~397K         |
| 5              | \~556K    | \~111K         |
| 10             | \~1.06M   | \~106K         |
| 25             | \~2.58M   | \~103K         |
| 50             | \~5.16M   | \~103K         |

The per-intent marginal cost converges to \~103K gas. The fixed overhead (\~290K) covers batch validation, clearing price computation, and settler payment.

## Default Parameters

| Parameter                     | Value                     | Description                                     |
| ----------------------------- | ------------------------- | ----------------------------------------------- |
| `settlementFeeBps`            | 10 (0.1%)                 | Per-intent fee on input amount                  |
| `directSwapFeeBps`            | 30 (0.3%) for curve pools | Fee on direct swaps, split 3 ways               |
| `maxGasReimbursement`         | 0.01 ETH                  | Hard cap on surplus draw per batch              |
| `gasReimbursementMultiplier`  | 150 (1.5×)                | Gas cost multiplier (covers gas + margin)       |
| `batchInterval`               | 1 block                   | Minimum blocks between settlements              |
| `maxBatchSize`                | 128                       | Maximum intents per side per batch              |
| `PROTOCOL_FEE_SHARE_BPS`      | 3333 (\~1/3)              | Protocol's share of direct swap fees            |
| `CURVE_RESERVE_FEE_SHARE_BPS` | 3334 (\~1/3)              | Curve reserve's share (permanent floor ratchet) |

## Security Properties

| Property                                  | Mechanism                                                        |
| ----------------------------------------- | ---------------------------------------------------------------- |
| Fees come from intent owner's own input   | Input-side deduction before routing                              |
| One-sided batches pay fees                | No dependency on opposite-side output                            |
| Wash trading is net-negative              | Both sides pay fees; surplus draw is capped                      |
| Surplus cannot be drained by volume       | Gas reimbursement is gas-based, not volume-based                 |
| Curve reserves reflect net economics      | Net input after fee deduction                                    |
| Floor price only goes up                  | Reserve fee portion permanently increases ETH reserve            |
| Settler competition prevents manipulation | First valid batch wins; omitted intents lose to complete batches |

<Note>
  **Verified**: All economic properties are tested in `SettlementEconomics.t.sol` and `CurveDirectSwap.t.sol` — including adversarial wash trade scenarios, gas cap enforcement, fee split verification, and curve state invariants.
</Note>
