docs/content/standards/deepbookv3/contract-information/ewma.mdx
DeepBook implements an exponentially weighted moving average (EWMA) system to dynamically adjust taker fees based on network gas prices. This feature helps prevent toxic takers from using high gas prices to prioritize their transactions and pick off stale maker orders.
The system tracks gas prices over time and applies a penalty fee to takers when the current gas price is unusually high compared to recent history. This protects makers from having their orders filled during periods of abnormal network activity where toxic takers might try to front-run or take advantage of stale orders.
The EWMA system calculates a smoothed average and variance of recent gas prices, then compares the current gas price against this historical baseline. When the current gas price is significantly elevated (beyond a threshold measured in standard deviations), an additional taker fee penalty is applied.
z_score = (current_gas_price - mean) / standard_deviation
if z_score > z_score_threshold:
apply additional_taker_fee
The following table shows a sample configuration parameters for the EWMA system:
| Parameter | Value | Meaning |
|---|---|---|
| Alpha | 0.1 (100000000) | 10% weight on new data, 90% on history |
| Mean | 1,478 | Average gas price (smoothed) |
| Variance | 43,270,831 | Volatility measure |
| Std deviation | 6,578 | Calculated: √variance |
| Z-score threshold | 3.0 | Trigger: 3 standard deviations |
| Additional taker fee | 0.1% (1000000) | Penalty fee added |
The penalty is applied only when all of the following conditions are met:
Penalty Threshold = Mean + (Z-Score Threshold × Std Dev)
Penalty Threshold = 1,478 + (3.0 × 6,578)
Penalty Threshold = 1,478 + 19,734
Penalty Threshold ≈ 21,212