Skip to content

Uniswap/protocol-fees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Uniswap Fee Collection

A unified system for collecting and converting fees from arbitrary revenue sources on arbitrary chains.

Table of Contents

Overview

Uniswap Fee Collection is a maximally fault-tolerant system designed to collect fees from any revenue source on any blockchain and convert them efficiently. The system uses competitive economic incentives to ensure timely fee collection while maintaining decentralized governance through immutable smart contracts.

Goals

  • Universal Support: Collect fees from arbitrary revenue sources across arbitrary chains
  • Maximum Fault Tolerance: Recover from chain downtime, bridge failures, and other infrastructure issues
  • Economic Efficiency: Competitive mechanisms ensure optimal fee collection and conversion

Architecture

The Uniswap system consists of three core layers that work together across all supported chains:

1. Token Jar

Each chain deploys a local Token Jar - an immutable smart contract that serves as the collection point for all fees on that chain.

Fee Sources β†’ Token Jar β†’ Releaser β†’ Fee Conversion

Key Properties:

  • Universal Collector: Receives fees from all sources on the chain
  • Single Admin: Only the releaser can withdraw assets
  • Atomic Operations: Full balance transfers only

The Token Jar defines one role: the releaser, which can atomically transfer the full balance of specified assets to a recipient address.

2. Fee Sources

Fee Sources are adapter contracts that channel fees from various protocols into the local Token Jar. They handle the diversity of fee collection mechanisms across different protocols.

Push vs Pull Models

Push Sources (e.g., Uniswap V2):

  • Fees automatically flow to Token Jar
  • Direct integration with protocol fee recipients
  • Minimal ongoing maintenance

Pull Sources (e.g., Uniswap V3/V4):

  • Require explicit collection calls
  • Adapter contracts enable permissionless collection
  • Anyone can trigger fee collection to Token Jar

Supported Protocols

Uniswap V2

  • LP tokens minted directly to Token Jar
  • 1/6 of swap fees collected as protocol revenue
  • Zero additional infrastructure required

Uniswap V3

  • V3FeeAdapter contract owns factory privileges
  • Permissionless protocol fee collection
  • Configurable fee rates per fee tier

Uniswap V4 (TBD)

  • V4FeeAdapter as ProtocolFeeAdapter
  • Not included as part of the initial fee enablement

3. Releasers

Releasers are smart contracts that serve as the releaser for Token Jars. They implement the business logic for converting collected fees into protocol value.

UNI Burn (Mainnet)

On Ethereum mainnet where UNI tokens exist:

Searcher β†’ Pay UNI β†’ Releaser β†’ Release Assets β†’ Burn UNI

Mechanism:

  1. Searcher pays a fixed UNI amount to Releaser
  2. Releaser releases Token Jar contents to searcher's specified recipient
  3. UNI tokens are burned (sent to 0xdead), reducing total supply
  4. Searcher profits from asset value exceeding UNI burn cost

Cross-Chain UNI Burn (OP Stack L2s)

For OP Stack L2 chains (Unichain, Optimism, Base, etc.) where only bridged UNI exists:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                          L2 (Unichain)                          β”‚
β”‚                                                                 β”‚
β”‚  Searcher β†’ Pay Bridged UNI β†’ OptimismBridgedResourceFirepit   β”‚
β”‚                                      β”‚                          β”‚
β”‚                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚                              β”‚               β”‚                  β”‚
β”‚                        Release Assets   Bridge Withdrawal       β”‚
β”‚                        to Recipient     (L2β†’L1)                β”‚
β”‚                                              β”‚                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
                                        7-day challenge
                                            period
                                               β”‚
                                               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       Ethereum Mainnet (L1)                      β”‚
β”‚                                                                  β”‚
β”‚              L1StandardBridge β†’ Transfer UNI β†’ 0xdead (Burn)    β”‚
β”‚                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Mechanism:

The OptimismBridgedResourceFirepit implements a two-stage burn process:

Stage 1 - L2 Collection:

  1. Searcher calls release() with the current nonce, assets to release, and recipient
  2. Searcher pays a fixed amount of bridged UNI tokens
  3. UNI is transferred to the Firepit contract (not burned yet)
  4. Token Jar contents are released to the searcher's specified recipient

Stage 2 - L1 Bridge & Burn:

  1. The _afterRelease() hook automatically initiates an L2β†’L1 bridge withdrawal
  2. Bridged UNI is burned on L2 via the L2StandardBridge
  3. A cross-domain message is queued for L1
  4. After the 7-day challenge period, L1 UNI is transferred to 0xdead

Key Properties:

  • Same Economics: Searchers profit when fee asset value exceeds UNI threshold cost
  • Nonce Protection: Sequential nonces prevent front-running and ensure deterministic ordering
  • Fault Tolerant: If bridge is unavailable, fees safely accumulate in TokenJar until recovery
  • Native Bridge Security: Uses Optimism's canonical bridge infrastructure

Configuration:

Parameter Value Description
RESOURCE Bridged UNI OptimismMintableERC20 token on L2
THRESHOLD 2000 UNI Amount required per release
WITHDRAWAL_MIN_GAS 100,000 Gas for L1 transfer to burn address
L1_RESOURCE_RECIPIENT 0xdead Final burn destination on mainnet

(Future) Hub-and-Spoke Cross-Chain

Note: Additional cross-chain patterns are planned for future development

For non-OP Stack chains:

Searcher β†’ Burn UNI (Mainnet) β†’ Bridge Message β†’ Release Assets (Spoke)

Economic Incentives

The system relies on economic competition to ensure efficient operation:

  • Profit Motive: Searchers compete when asset value exceeds burn costs
  • Automatic Timing: No manual intervention required
  • Gas Optimization: Bundled operations reduce transaction costs
  • MEV Resistance: Fixed burn amounts prevent extraction

Fault Tolerance (In-Progress)

Uniswap is designed to handle infrastructure failures gracefully:

  • Bridge Failures: Each chain operates independently
  • Chain Downtime: Fees accumulate until chain recovery
  • Oracle Failures: Economic incentives work without price feeds

Deployment Architecture

Ethereum Mainnet
β”œβ”€β”€ Token Jar
β”œβ”€β”€ UNI Burn Releaser (Firepit.sol)
β”œβ”€β”€ V2 Fee Source (feeTo)
β”œβ”€β”€ V3 Fee Source (V3FeeAdapter.sol)

Crosschain system coming at a later date

Deployed Addresses

Ethereum Mainnet (Chain ID: 1)

Contract Address
MainnetDeployer 0xd3Aa12B99892b7D95BBAA27AEf222A8E2a038C0C
TokenJar 0xf38521f130fcCF29dB1961597bc5d2B60F995f85
Releaser (Firepit) 0x0D5Cd355e2aBEB8fb1552F56c965B867346d6721
V3FeeAdapter 0x5E74C9f42EEd283bFf3744fBD1889d398d40867d
UNI Vesting 0xCa046A83EDB78F74aE338bb5A291bF6FdAc9e1D2
Agreement Anchor 1 0xC707467e7fb43Fe7Cc55264F892Dd2D7f8Fc27C8
Agreement Anchor 2 0x33A56942Fe57f3697FE0fF52aB16cb0ba9b8eadd
Agreement Anchor 3 0xF9F85a17cC6De9150Cd139f64b127976a1dE91D1

Unichain (Chain ID: 130)

Contract Address
UnichainDeployer 0xD16c47bf3ae22e0B2BAc5925D990b81416f18dea
TokenJar 0xD576BDF6b560079a4c204f7644e556DbB19140b5
Releaser (OptimismBridgedResourceFirepit) 0xe0A780E9105aC10Ee304448224Eb4A2b11A77eeB

Development

Prerequisites

  • Foundry - Ethereum development toolkit
  • Node.js - For additional tooling

Installation

# Clone the repository
git clone https://github.com/Uniswap/protocol-fees
cd protocol-fees

# Install dependencies
forge install

# Build contracts
forge build

Testing

# Run all tests
forge test

# Run with verbosity
forge test -vvv

# Generate coverage
forge coverage

Project Structure

src/
β”œβ”€β”€ TokenJar.sol             // General purpose contract for receiving fees
β”œβ”€β”€ Deployer.sol              // A deployer contract to instantiate the initial contracts
β”œβ”€β”€ base
β”‚   β”œβ”€β”€ Nonce.sol             // Utility contract to safely sequence multiple pending transactions
β”‚   └── ResourceManager.sol.  // Utility contract for defining the `RESOURCE` token and its amount requirements
β”œβ”€β”€ feeAdapters
β”‚   β”œβ”€β”€ V3FeeAdapter.sol   // Logic for Uniswap v3 fee-setting and collection
β”‚   └── V4FeeAdapter.sol   // Work-in-progress logic for Uniswap v4 fee-setting and collection
β”œβ”€β”€ interfaces/               // interfaces
β”œβ”€β”€ libraries
β”‚   β”œβ”€β”€ ArrayLib.sol          // Utility library
└── releasers
    β”œβ”€β”€ ExchangeReleaser.sol              // Abstract contract to exchange a RESOURCE for Token Jar assets
    β”œβ”€β”€ Firepit.sol                       // Burns UNI directly on mainnet (RESOURCE_RECIPIENT = 0xdead)
    └── OptimismBridgedResourceFirepit.sol // Two-stage burn for OP Stack L2s via bridge withdrawal

test
β”œβ”€β”€ TokenJar.t.sol
β”œβ”€β”€ Deployer.t.sol                        // Test Deployer configures the system properly
β”œβ”€β”€ ExchangeReleaser.t.sol
β”œβ”€β”€ Firepit.t.sol
β”œβ”€β”€ OptimismBridgedResourceFirepit.t.sol  // Tests for L2 bridge burn mechanism
β”œβ”€β”€ ProtocolFees.fork.t.sol               // Fork tests against Ethereum Mainnet, using Deployer.sol
β”œβ”€β”€ V3FeeAdapter.t.sol
β”œβ”€β”€ V4FeeAdapter.t.sol
β”œβ”€β”€ interfaces/                           // interfaces for integrations
β”œβ”€β”€ mocks/                                // mocks and examples
└── utils
    └── ProtocolFeesTestBase.sol          // Test base that configures the system

Governance Proposal

For additional commentary and information please see Uniswap Governance Proposal #92

With the system already deployed, Uniswap Governance can elect into the system by executing the following calls:

Contract Address Calldata function function signature parameters
UniswapV3Factory 0x1F98431c8aD98523631AE4a59f267346ea31F984 0x13af40350000000000000000000000001a9c8182c09f50c8318d769245bea52c32be35bc setOwner(address _owner) 0x13af4035 0xTOKENJAR
FeeToSetter 0x18e433c7Bf8A2E1d0197CE5d8f9AFAda1A771360 0xa2e74af60000000000000000000000001a9c8182c09f50c8318d769245bea52c32be35bc setFeeToSetter(address feeToSetter_) 0xa2e74af6 0x1a9C8182C09F50C8318d769245beA52c32BE35BC
UniswapV2Factory 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f 0xf46901ed0000000000000000000000001a9c8182c09f50c8318d769245bea52c32be35bc setFeeTo(address _feeTo) 0xf46901ed 0xTOKENJAR

Security

Audits: Audit reports available in audit/

  • OpenZeppelin
  • Spearbit

Future Development

Protocol Fee Auctions

Advanced mechanism design for optimizing fee collection efficiency through auction-based competition.

Additional Protocol Support

  • Uniswap v4
  • UniswapX fee integration
  • Interface fee collection
  • Third-party protocol adapters

Cross-chain Expansion

  • Additional L2 and L1 chain support
  • Alternative bridge integrations
  • Rollup-specific optimizations

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Implement changes with comprehensive tests
  4. Submit a pull request

License

This project is licensed under AGPL-3.0-only.

Support

For questions or issues, please open an issue in the repository.

About

πŸ¦„ Smart contracts for Uniswap protocol fees πŸ¦„

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 7