Fee Management Overview

VinuSwap extends Uniswap V3 with a flexible fee management system that allows dynamic fee computation and multi-account fee distribution.

Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│                              SWAP EXECUTION                                 │
│                                                                             │
│  User → SwapRouter → VinuSwapPool.swap()                                   │
│                            │                                                │
│                            ▼                                                │
│                   ┌─────────────────┐                                      │
│                   │   feeManager    │ ← IFeeManager.computeFee(fee)        │
│                   └────────┬────────┘                                      │
│                            │                                                │
│           ┌────────────────┼────────────────┐                              │
│           ▼                ▼                ▼                              │
│  ┌─────────────────┐ ┌──────────────┐ ┌───────────────────────┐           │
│  │  TieredDiscount │ │  NoDiscount  │ │ OverridableFeeManager │           │
│  │ Balance-based   │ │  Passthrough │ │    Per-pool routing   │           │
│  │   discounts     │ │              │ │                       │           │
│  └─────────────────┘ └──────────────┘ └───────────────────────┘           │
└─────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│                           FEE COLLECTION                                    │
│                                                                             │
│  Pool.protocolFees → Controller.collectProtocolFees()                      │
│                            │                                                │
│                            ▼                                                │
│                   ┌─────────────────┐                                      │
│                   │   Controller    │                                      │
│                   │ Fee Distribution│                                      │
│                   └────────┬────────┘                                      │
│                            │                                                │
│           ┌────────────────┼────────────────┐                              │
│           ▼                ▼                ▼                              │
│      ┌─────────┐      ┌─────────┐      ┌─────────┐                        │
│      │Account 1│      │Account 2│      │Account 3│                        │
│      │Share: 1 │      │Share: 2 │      │Share: 2 │                        │
│      └─────────┘      └─────────┘      └─────────┘                        │
└─────────────────────────────────────────────────────────────────────────────┘

Components

IFeeManager Interface

The core interface for fee computation:

  • Called during every swap

  • Can modify the fee dynamically

  • Must return a valid fee (< 1,000,000)

Full Reference →

TieredDiscount

Balance-based fee discounts:

Full Reference →

OverridableFeeManager

Per-pool fee manager routing:

Full Reference →

Controller

Protocol fee collection and distribution:

  • Collects protocol fees from pools

  • Distributes to multiple accounts with configurable shares

  • Manages pool creation and initialization

Full Reference →

Fee Flow

1. Swap Fee Application

2. Protocol Fee Split

3. Fee Distribution

Configuration

Setting Up Fee Management

  1. Deploy Fee Managers:

  1. Create Pool with Fee Manager:

  1. Configure Controller:

Setting Protocol Fees

Collecting Fees

Fee Manager Implementations

NoDiscount

Passthrough implementation - returns fee unchanged:

Custom Fee Managers

Create custom logic by implementing IFeeManager:

Security Considerations

Fee Manager Trust

  • Fee managers are called during every swap

  • Malicious fee managers could:

    • Return extremely high fees

    • Consume excessive gas

    • Revert to block swaps

  • Only use audited fee manager implementations

Protocol Fee Bounds

  • Protocol fee is limited: 0 or 4-10 (10-25% of LP fees)

  • Cannot be set to capture all fees

Controller Access

  • Only designated accounts can withdraw their shares

  • Controller owner can add/remove accounts

  • Consider timelock for owner operations

Best Practices

  1. Start Simple: Use NoDiscount initially, add complexity later

  2. Test Thoroughly: Fee manager bugs affect every swap

  3. Monitor Gas: Complex fee calculations increase swap costs

  4. Audit Custom Managers: Critical path for every trade

  5. Use Multisig: Protect owner functions with multisig/timelock

Last updated