FeePool
Manages the fee normalization pool for GhostTracking. Absorbs the difference between actual network fees and the flat fee displayed to users.
Source
packages/contracts/FeePool.compact
Ledgers
| Ledger | Type | Description |
|---|---|---|
user_deposits | Map<Bytes, Counter> | Deposits per user |
pool_balance | Counter | Current pool balance |
total_normalized | Counter | Total normalization events |
total_deposited | Counter | Total deposits received |
config | Map<Bytes, Counter> | Configuration (key 0x01 = flat fee) |
Circuits
initialize(flat_fee: Counter)
Sets the flat fee amount. All normalized transactions will display this fee.
deposit(user_id: Bytes, amount: Counter)
Adds funds to the normalization pool. Updates both the user's deposit balance and the global pool balance.
normalizeFee(user_id: Bytes, actual_fee: Counter)
Records a fee normalization event. The pool absorbs the difference between the actual fee and the flat fee:
- If
actual_fee < flat_fee: pool receivesflat_fee - actual_fee - If
actual_fee > flat_fee: pool paysactual_fee - flat_fee
getUserDeposit(): Counter
Returns the calling user's total deposits.
getPoolBalance(): Counter
Returns the current pool balance.
getTotalNormalized(): Counter
Returns the total number of normalization events.
How Fee Normalization Works
Without GhostTracking:
User A pays fee: 847,293 ← unique fingerprint
User B pays fee: 1,203,847 ← unique fingerprint
With GhostTracking:
User A pays fee: 1,000,000 ← flat fee
User B pays fee: 1,000,000 ← flat fee
Pool absorbs: (1,000,000 - 847,293) + (1,203,847 - 1,000,000) = 356,554
The pool must be funded to cover periods where actual fees exceed the flat fee. The FeeReserve contract can subsidize the pool during bootstrapping.