The Protocol Fee Allocator v2 is the official system for distributing protocol fees collected across the Balancer ecosystem on a biweekly basis.
This system processes fee data from multiple chains, calculates fee allocations according to governance-approved parameters, and generates executable Safe transactions for distribution.
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .envRequired:
DRPC_KEY- API key from dRPC for querying multichain data
Optional (but recommended for deterministic block fetching and reproducible results):
GRAPH_API_KEY- API key for The GraphEXPLORER_API_KEY_MAINNET- Etherscan API keyEXPLORER_API_KEY_ARBITRUM- Arbiscan API keyEXPLORER_API_KEY_POLYGON- Polygonscan API keyEXPLORER_API_KEY_BASE- Basescan API keyEXPLORER_API_KEY_GNOSIS- Gnosisscan API key
# Run both v2 and v3 allocations with automatic payload merging
python main_combined.py
# Run with specific timestamps
python main_combined.py --ts_now <end_timestamp> --ts_in_the_past <start_timestamp>
# Run with specific date range string
python main_combined.py --date_range_string 2025-04-24_2025-05-08# Basic run (uses default timestamps - last 2 weeks from odd Thursday)
python main.py
# Run with specific protocol version (v2 or v3)
python main.py --protocol_version v3
# Run with custom output file names
python main.py --fees_file_name v2_fees_2025-04-24_2025-05-08.json --output_file_name v2_incentives_2025-04-24_2025-05-08.csv
# Full example for v2
python main.py \
--ts_now 1715270400 \
--ts_in_the_past 1714060800 \
--fees_file_name v2_fees_2025-04-24_2025-05-08.json \
--output_file_name v2_incentives_2025-04-24_2025-05-08.csv \
--protocol_version v2# Install dev dependencies
pip install -r requirements-dev.txt
# Run all tests
python -m pytest -s-
Fee Collection: Every Thursday at 9am UTC, GitHub Actions triggers fee collection via Mimic API
- Workflow:
.github/workflows/get_mimic_report.yaml - Creates fee files in
fee_allocator/fees_collected/
- Workflow:
-
Fee Allocation: When fee files are merged, allocation is automatically triggered
- Workflow:
.github/workflows/trigger_fee_collection.yaml - Runs combined allocation for both v2 and v3 using
main_combined.py - Automatically merges payloads and deduplicates transfers
- Workflow:
-
Manual Collection: Can be triggered manually for specific dates
- Workflow:
.github/workflows/collect_fees.yaml - Runs single protocol version allocation
- Specify end date and protocol version (v2 or v3)
- Workflow:
The allocator generates several output files:
-
Incentive CSVs:
fee_allocator/allocations/incentives/v2_incentives_<start>_<end>.csvv3_incentives_<start>_<end>.csv
-
Bribe CSVs:
fee_allocator/allocations/output_for_msig/v2_bribes_<date>.csvv3_bribes_<date>.csv
-
Non-core pool CSVs:
fee_allocator/allocations/noncore/v2_noncore_<start>_<end>.csvv3_noncore_<start>_<end>.csv
-
Partner CSVs:
fee_allocator/allocations/partner/v2_partner_<start>_<end>.csvv3_partner_<start>_<end>.csv
-
Payloads:
fee_allocator/payloads/v2_<date>.json- Safe transaction payload for v2v3_<date>.json- Safe transaction payload for v3<date>.json- Combined v2+v3 payload
-
Reconciliation:
fee_allocator/summaries/v2_recon.json- v2 reconciliation datav3_recon.json- v3 reconciliation data
fee_allocator/- Main packagefee_allocator.py- Main allocator logicaccounting/- Defines chain-agnostic configuration and data as well as chain-specific accounting logicallocations/- Output CSV filesfees_collected/- Input fee JSON files from Mimicpayloads/- Safe transaction payloadssummaries/- Reconciliation reports
tests/- Test suitemain.py- CLI entry point for single protocol runsmain_combined.py- CLI entry point for combined v2+v3 runscombine_payloads.py- Utility to merge v2/v3 payloads with deduplication
biweekly-runs- Main branch for biweekly fee runsgha-mimic-fees-*- Auto-created branches for Mimic reportsgha-biweekly-fees-*- Auto-created branches for fee allocationsmanual-fees-*- Branches for manual fee collections