# Dynamic Fees

*This is an ongoing case study on TWAMMs where fees can be adjusted based on future orders that are queued to be executed. Below is a problem and related parameters we're researching.*

### Problem Statement

> What is the optimal swap fee discount for dedicated arbitrageurs (toxic, atomic swaps, short term) to maximize price updates for traders (non-toxic, non-atomic swaps, long term) and MEV kickback to LPs?

<figure><img src="https://4121718674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ7bY0xe83NKFmbUiEyBZ%2Fuploads%2FZctf2paJ8bPTWx4yT5vI%2Fdynamic_fees.png?alt=media&#x26;token=fa4590fb-8d9f-4dde-95c3-9d168e2bf286" alt=""><figcaption></figcaption></figure>

### Optimization

* LPs: maximize swap fees & MEV remittance to compensate for IL and toxic flow from arbitrageurs
* Traders: maximize price updates of assets to keep parity with external venues and get a smoother order fill
* Arbitrageurs: maximize MEV opportunity and minimize swap fee for a profitable arbitrage opportunity

### Assumptions

* Pool parameters:
  * ETH/USDC
  * Partner Fee: Dedicated Arbitrageur (0.025%)
  * Short Term Fee: Mempool Users (0.05%)
  * Long Term Fee: Traders (0.15%)
* Gas (transaction) fees can vary on number of virtual orders that need to be executed
  * For the purpose of this problem, assume a fixed amount
* Trades last multiple blocks and can be cancelled at any time
* Mempool arbitrageurs will always exploit opportunity if dedicated arbitrage don’t act in time
* Dedicated arbitrageurs get a fee discount to get a first right arbitrage opportunity

### Background

* TWAMMs have two swap interfaces: non-atomic swap (traders), atomic swap (arbitrageurs)
* TWAMM pools are 2 asset, 50/50 Uni V2 style pools that follow `X*Y=K` invariant
* Dedicated arbitrageur fees can be changed in-flight and are customizable per pool
* Long term trades create back running opportunities as prices move on the bonding curve
  * Traders are primarily uninformed flow (non-toxic), benefit from arbitrageurs keeping prices fresh
* Dedicated arbitrageurs remit share of MEV extracted to LPs for the swap fee discount
  * Arbitrageurs are informed flow (toxic), profit from correcting prices and pay gas to write traders virtual orders on-chain
* LPs get swap fees from long term traders, and MEV + discounted short term swap fees from arbitrageurs
* MEV remitted to pools are automatically invested and distributed pro-rata to LPs similar to swap fees, but on a weekly basis

### Existing Solutions

* Private relays: ineffective because `first right advantage` is negated after the first block
* Rook auctions: group of arbitrageurs bid on the arbitrage opportunity, 90% of bid is remitted back to LPs. Note `bid != potential MEV opportunity`
* SLAs: require off-chain agreements and trust with 3rd parties to behave ethically

### Related Research

{% embed url="<https://a16zcrypto.com/content/article/lvr-quantifying-the-cost-of-providing-liquidity-to-automated-market-makers/>" %}

{% embed url="<https://research.paradigm.xyz/uniswaps-alchemy>" %}
