Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit 3df4084

Browse files
committed
fetch remote fees if fees dont exist
1 parent 8af541e commit 3df4084

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

fee_allocator/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from web3 import Web3
77
import os
88
from dotenv import load_dotenv
9+
import json
910

1011

1112

@@ -96,3 +97,24 @@ def get_block_by_ts(timestamp, chain: "CorePoolChain", before=False):
9697
return int(data["result"])
9798
else:
9899
return chain.subgraph.get_first_block_after_utc_timestamp(timestamp)
100+
101+
def fetch_collected_fees(start_date: str, end_date: str, fees_file_name: str = None) -> dict:
102+
# If fees_file_name is provided, use that directly
103+
if fees_file_name:
104+
filename = fees_file_name
105+
else:
106+
filename = f"fees_{start_date}_{end_date}.json"
107+
108+
local_path = f"fee_allocator/fees_collected/{filename}"
109+
if os.path.exists(local_path):
110+
with open(local_path) as f:
111+
return json.load(f)
112+
113+
v1_fees = f"https://raw.githubusercontent.com/BalancerMaxis/protocol_fee_allocator/main/fee_allocator/fees_collected/{filename}"
114+
response = requests.get(v1_fees)
115+
116+
if response.status_code == 200:
117+
print(f"fetched collected fees from: {v1_fees}")
118+
return response.json()
119+
120+
raise FileNotFoundError(f"Could not find fees file {filename} locally or remotely")

main.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import argparse
2-
import json
32
import os
43
from datetime import datetime
4+
import pytz
55

66
from dotenv import load_dotenv
77

88
from fee_allocator.fee_allocator import FeeAllocator
9-
from fee_allocator.utils import get_last_thursday_odd_week
9+
from fee_allocator.utils import get_last_thursday_odd_week, fetch_collected_fees
1010

1111

1212
parser = argparse.ArgumentParser()
@@ -29,17 +29,17 @@
2929

3030
def main() -> None:
3131
load_dotenv()
32-
ts_now = parser.parse_args().ts_now or TS_NOW
33-
ts_in_the_past = parser.parse_args().ts_in_the_past or TS_2_WEEKS_AGO
32+
args = parser.parse_args()
33+
ts_now = args.ts_now or TS_NOW
34+
ts_in_the_past = args.ts_in_the_past or TS_2_WEEKS_AGO
3435
print(
3536
f"\n\n\n------\nRunning from timestamps {ts_in_the_past} to {ts_now}\n------\n\n\n"
3637
)
37-
fees_file_name = parser.parse_args().fees_file_name or "current_fees_collected.json"
38-
input_fees_path = f"fee_allocator/fees_collected/{fees_file_name}"
38+
39+
start_date = datetime.fromtimestamp(ts_in_the_past, tz=pytz.UTC).strftime("%Y-%m-%d")
40+
end_date = datetime.fromtimestamp(ts_now, tz=pytz.UTC).strftime("%Y-%m-%d")
3941

40-
with open(input_fees_path) as f:
41-
input_fees = json.load(f)
42-
42+
input_fees = fetch_collected_fees(start_date, end_date, args.fees_file_name)
4343
date_range = (ts_in_the_past, ts_now)
4444

4545
fee_allocator = FeeAllocator(input_fees, date_range)

0 commit comments

Comments
 (0)