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

Commit 82bd2d0

Browse files
authored
Merge pull request #30 from Xeonus/fix-core-pools-page
chore: fix core pool page
2 parents 1059eac + a2000d2 commit 82bd2d0

6 files changed

Lines changed: 89 additions & 46 deletions

File tree

src/data/maxis/maxiStaticTypes.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
// Define the structure of a single record in your CSV data.
2+
// Note: The current_fees CSV (v2_earned_fees_*.csv) only has pool_id, chain, symbol, earned_fees
3+
// The incentives CSV (v2_incentives_*.csv) has all fields including fee breakdown
24
export interface PoolFeeRecord {
35
pool_id: string;
46
chain: string;
57
symbol: string;
68
earned_fees: string;
7-
fees_to_vebal: string;
8-
fees_to_dao: string;
9-
total_incentives: string;
10-
aura_incentives: string;
11-
bal_incentives: string;
12-
redirected_incentives: string;
13-
reroute_incentives: number;
9+
// The following fields are only available in historical incentives CSVs
10+
fees_to_vebal?: string;
11+
fees_to_dao?: string;
12+
fees_to_beets?: string;
13+
total_incentives?: string;
14+
aura_incentives?: string;
15+
bal_incentives?: string;
16+
redirected_incentives?: string;
17+
reroute_incentives?: number;
18+
bpt_price?: string;
1419
date_string?: string;
1520
last_join_exit?: string;
21+
is_partner?: string;
1622
}
1723

1824
export interface FeeAllocations {

src/data/maxis/useGetCollectedFeesSummary.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {FeeAllocations} from "./maxiStaticTypes";
22
import React, { useEffect, useState } from 'react';
33
import historicalData from './static/historical_fee_allocations_monthly.json';
44

5+
// Cutoff timestamp: January 30, 2025 00:00:00 UTC
6+
const V2_CUTOFF_TIMESTAMP = 1738195200;
7+
58
export default function useGetCollectedFeesSummary () : { feeData: FeeAllocations[], loading: boolean, error: string } {
69

710
const [feeData, setFeeData] = useState<FeeAllocations[]>([]);
@@ -11,14 +14,34 @@ export default function useGetCollectedFeesSummary () : { feeData: FeeAllocation
1114
useEffect(() => {
1215
const fetchData = async () => {
1316
try {
14-
const response = await fetch('https://raw.githubusercontent.com/BalancerMaxis/protocol_fee_allocator/main/fee_allocator/summaries/recon.json');
15-
if (!response.ok) {
16-
throw new Error('Network response was not ok');
17+
// Fetch from both old and new endpoints in parallel
18+
const [oldResponse, v2Response] = await Promise.all([
19+
fetch('https://raw.githubusercontent.com/BalancerMaxis/protocol_fee_allocator/main/fee_allocator/summaries/recon.json'),
20+
fetch('https://raw.githubusercontent.com/BalancerMaxis/protocol_fee_allocator_v2/refs/heads/collect-fees-cron/fee_allocator/summaries/v2_recon.json')
21+
]);
22+
23+
let oldData: FeeAllocations[] = [];
24+
let v2Data: FeeAllocations[] = [];
25+
26+
if (oldResponse.ok) {
27+
oldData = await oldResponse.json();
28+
// Filter old data to only include entries up to and including the cutoff
29+
oldData = oldData.filter(entry => entry.periodEnd <= V2_CUTOFF_TIMESTAMP);
1730
}
18-
const fetchedData = await response.json();
1931

20-
// Combine the fetched data with historical data
21-
const combinedData = [...historicalData, ...fetchedData];
32+
if (v2Response.ok) {
33+
v2Data = await v2Response.json();
34+
// Filter v2 data to only include entries after the cutoff
35+
v2Data = v2Data.filter(entry => entry.periodEnd > V2_CUTOFF_TIMESTAMP);
36+
} else {
37+
console.warn('Failed to fetch v2 recon data');
38+
}
39+
40+
// Combine historical data, filtered old data, and v2 data
41+
// Sort by periodEnd to ensure chronological order
42+
const combinedData = [...historicalData, ...oldData, ...v2Data]
43+
.sort((a, b) => a.periodEnd - b.periodEnd);
44+
2245
setFeeData(combinedData);
2346
} catch (error) {
2447
if (error instanceof Error) {

src/data/maxis/useGetCorePoolCurrentFees.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,34 @@ export default function useGetCorePoolCurrentFees(): PoolFeeRecord[] {
3232
const fetchData = async () => {
3333
try {
3434
const feeEndpoint = generateFeeEndpoint();
35-
console.log('Fetching from:', feeEndpoint); // Optional: for debugging
35+
console.log('Fetching current fees from:', feeEndpoint);
3636

3737
const response = await fetch(feeEndpoint);
38-
const reader = response.body?.getReader();
39-
const result = await reader?.read(); // raw array
40-
const decoder = new TextDecoder('utf-8');
41-
const csv = decoder.decode(result?.value); // convert the raw array to string
42-
43-
// Modify the CSV string to insert 'poolId' as the first header.
44-
const correctedCsv = csv.replace(/^,/, 'poolId,');
38+
if (!response.ok) {
39+
if (response.status === 404) {
40+
console.warn('Current fees file not found:', feeEndpoint);
41+
setData([]);
42+
return;
43+
}
44+
throw new Error(`HTTP error! status: ${response.status}`);
45+
}
4546

46-
// Now, parse the corrected CSV string.
47-
const results = Papa.parse(correctedCsv, {
47+
const csv = await response.text();
48+
const results = Papa.parse(csv, {
4849
header: true,
4950
skipEmptyLines: true,
5051
});
5152

5253
if (results.errors.length > 0) {
53-
// Handle the error or throw it.
54-
console.log("CSV PARSING", results);
55-
throw new Error('Error parsing CSV data');
54+
console.log("CSV PARSING errors:", results.errors);
5655
}
5756

58-
setData(results.data as PoolFeeRecord[]);
57+
const parsedData = results.data as PoolFeeRecord[];
58+
console.log('Parsed current fees, count:', parsedData.length);
59+
setData(parsedData);
5960
} catch (error) {
60-
console.error("Error fetching data: ", error);
61+
console.error("Error fetching current fees data:", error);
62+
setData([]);
6163
}
6264
};
6365

src/data/maxis/useGetCorePoolHistoricalFees.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,26 @@ export default function useGetCorePoolHistoricalFees(endDate: string): PoolFeeRe
3535
feeEndpoint = `${basePath}${pathSegment}/allocations/incentives_${startDate}_${endDate}.csv`;
3636
}
3737

38-
console.log('Fetching historical data from:', feeEndpoint); // Optional: for debugging
38+
console.log('Fetching historical data from:', feeEndpoint);
3939

4040
const response = await fetch(feeEndpoint);
41-
const reader = response.body?.getReader();
42-
const result = await reader?.read(); // raw array
43-
const decoder = new TextDecoder('utf-8');
44-
let csv = decoder.decode(result?.value); // convert the raw array to string
41+
if (!response.ok) {
42+
if (response.status === 404) {
43+
// File doesn't exist yet (current epoch not processed), return empty data
44+
console.warn(`Historical data not available yet for ${startDate} to ${endDate}`);
45+
setData([]);
46+
return;
47+
}
48+
throw new Error(`HTTP error! status: ${response.status}`);
49+
}
50+
51+
// Use response.text() to get the entire response body
52+
let csv = await response.text();
4553

4654
let correctedCsv: string;
4755
if (useNewEndpoint) {
48-
// New endpoint: leave as is (should have pool_id), just handle missing header
49-
correctedCsv = csv.replace(/^,/, 'pool_id,');
56+
// New endpoint: v2 format already has proper headers (pool_id)
57+
correctedCsv = csv;
5058
} else {
5159
// Old endpoint: convert poolId to pool_id for consistency
5260
correctedCsv = csv.replace(/^,/, 'poolId,'); // First handle missing header
@@ -60,7 +68,6 @@ export default function useGetCorePoolHistoricalFees(endDate: string): PoolFeeRe
6068
});
6169

6270
if (results.errors.length > 0) {
63-
// Handle the error or throw it.
6471
console.log("CSV PARSING ERROR:", results.errors);
6572
throw new Error('Error parsing CSV data');
6673
}

src/data/maxis/useGetTotalFeesCollected.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ export default function useGetCollectedFees(endDate: string): NetworkFees | unde
3737
feeEndpoint = `${basePath}${pathSegment}/fees_collected/fees_${startDate}_${endDate}.json`;
3838
}
3939

40-
console.log('Fetching collected fees from:', feeEndpoint); // Optional: for debugging
40+
console.log('Fetching collected fees from:', feeEndpoint);
4141

4242
const response = await fetch(feeEndpoint);
4343
if (!response.ok) {
44-
// If the server response was not ok, throw an error
44+
if (response.status === 404) {
45+
// File doesn't exist yet (current epoch not processed), return undefined
46+
console.warn(`Collected fees data not available yet for ${startDate} to ${endDate}`);
47+
setData(undefined);
48+
return;
49+
}
4550
throw new Error(`Error fetching data: ${response.statusText}`);
4651
}
4752
const fees: NetworkFees = await response.json();

src/pages/CorePools/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ function calculateDelta(historicalFees: NetworkFees, poolFeeRecords: PoolFeeReco
4545

4646
// Sum up fees_to_vebal, fees_to_dao, and total_incentives from historicalData
4747
const totalHistoricalSum = poolFeeRecords.reduce((acc, record) => {
48-
const feesToVebal = parseFloat(record.fees_to_vebal);
49-
const feesToDao = parseFloat(record.fees_to_dao);
50-
const totalIncentives = parseFloat(record.total_incentives);
48+
const feesToVebal = parseFloat(record.fees_to_vebal || '0');
49+
const feesToDao = parseFloat(record.fees_to_dao || '0');
50+
const totalIncentives = parseFloat(record.total_incentives || '0');
5151
return acc + feesToVebal + feesToDao + totalIncentives;
5252
}, 0);
5353

@@ -93,9 +93,9 @@ export default function CorePools() {
9393
totalSwept = totalSwept / 1000000
9494
// Sum up fees_to_vebal, fees_to_dao, and total_incentives from historicalData
9595
totalHistoricalSum = historicalData.reduce((acc, record) => {
96-
const feesToVebal = parseFloat(record.fees_to_vebal);
97-
const feesToDao = parseFloat(record.fees_to_dao);
98-
const totalIncentives = parseFloat(record.total_incentives);
96+
const feesToVebal = parseFloat(record.fees_to_vebal || '0');
97+
const feesToDao = parseFloat(record.fees_to_dao || '0');
98+
const totalIncentives = parseFloat(record.total_incentives || '0');
9999
return acc + feesToVebal + feesToDao + totalIncentives;
100100
}, 0);
101101

@@ -577,7 +577,7 @@ export default function CorePools() {
577577

578578
{selectedPeriod === "Current Fee Epoch" ?
579579
<Grid item xs={11}>
580-
{corePools && globalPools && globalPools.length > 10 ?
580+
{corePools && globalPools && globalPools.length > 0 ?
581581
<CorePoolTable poolDatas={globalPools} corePools={corePools}/> :
582582
<Grid
583583
container
@@ -591,7 +591,7 @@ export default function CorePools() {
591591

592592
</Grid> :
593593
<Grid item xs={11}>
594-
{corePools && globalPools && globalPools.length > 10 ?
594+
{corePools && globalPools && globalPools.length > 0 ?
595595
<CorePoolHistoricalTable poolDatas={globalPools} corePools={corePools}/> :
596596
<Grid
597597
container

0 commit comments

Comments
 (0)