Skip to content

Commit 4725e91

Browse files
committed
fix doublezero flashtrade
1 parent 281f76a commit 4725e91

File tree

2 files changed

+108
-106
lines changed

2 files changed

+108
-106
lines changed

fees/doublezero/index.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@ const fetch: any = async (_a: any, _b: any, options: FetchOptions) => {
1010
const dailyFees = options.createBalances();
1111

1212
const query = `
13-
with initialize_deposit_account as (
14-
select
15-
account_arguments[1] as deposit_account
16-
from solana.instruction_calls
17-
left join dune.the_flyingfish_glide.result_validators_app_details
18-
on account_arguments[2] = validator_account
19-
where executing_account = 'dzrevZC94tBLwuHw1dyynZxaXTWyp7yocsinyEVPtt4'
20-
and bytearray_substring(data, 1, 8) = 0x09af49b1ebce3065
21-
and block_date >= date '2025-10-02'
22-
and tx_success
13+
WITH initialize_deposit_account AS (
14+
SELECT
15+
account_arguments[1] AS deposit_account
16+
FROM solana.instruction_calls
17+
WHERE
18+
executing_account = 'dzrevZC94tBLwuHw1dyynZxaXTWyp7yocsinyEVPtt4'
19+
AND BYTEARRAY_SUBSTRING(data, 1, 8) = 0x09af49b1ebce3065
20+
AND block_date >= TRY_CAST('2025-10-02' AS DATE)
21+
AND tx_success
2322
)
24-
select
25-
sum(bytearray_to_bigint(bytearray_reverse(bytearray_substring(data,1+8,8))) / 1e9) as fee
26-
from solana.instruction_calls
27-
left join initialize_deposit_account
28-
on deposit_account = account_arguments[3]
29-
where executing_account = 'dzrevZC94tBLwuHw1dyynZxaXTWyp7yocsinyEVPtt4'
30-
and bytearray_substring(data, 1, 8) = 0xf1858bc4f612713b
31-
and tx_success
32-
and TIME_RANGE
23+
SELECT
24+
SUM(
25+
BYTEARRAY_TO_BIGINT(BYTEARRAY_REVERSE(BYTEARRAY_SUBSTRING(data, 1 + 8, 8))) / 1e9
26+
) AS fee
27+
FROM solana.instruction_calls
28+
LEFT JOIN initialize_deposit_account
29+
ON deposit_account = account_arguments[3]
30+
WHERE
31+
executing_account = 'dzrevZC94tBLwuHw1dyynZxaXTWyp7yocsinyEVPtt4'
32+
AND BYTEARRAY_SUBSTRING(data, 1, 8) = 0xf1858bc4f612713b
33+
AND tx_success
34+
AND TIME_RANGE
3335
`;
3436

3537
const fees = await queryDuneSql(options, query);

fees/flashtrade.ts

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -3,119 +3,119 @@ import { CHAIN } from "../helpers/chains";
33
import fetchURL from "../utils/fetchURL";
44

55
interface Pool {
6-
poolName: string;
7-
date: string;
8-
totalRevenue: string;
9-
totalProtocolFee: string;
6+
poolName: string;
7+
date: string;
8+
totalRevenue: string;
9+
totalProtocolFee: string;
1010
}
1111

1212
const urlRevStats = "https://api.prod.flash.trade/protocol-fees/daily";
1313

1414
const calculateProtocolRevenue = (stats: Pool[]) => {
15-
const protocolRevenue = stats.reduce((sum, item) => sum + parseFloat(item.totalProtocolFee) / 1e6, 0);
16-
return protocolRevenue;
15+
const protocolRevenue = stats.reduce((sum, item) => sum + parseFloat(item.totalProtocolFee) / 1e6, 0);
16+
return protocolRevenue;
1717
};
1818

1919
const calculateteHolderRevenue = (stats: Pool[]) => {
20-
const holderRevenue = stats.reduce((sum, item) => sum + parseFloat(item.totalRevenue) / 1e6, 0);
21-
return holderRevenue;
20+
const holderRevenue = stats.reduce((sum, item) => sum + parseFloat(item.totalRevenue) / 1e6, 0);
21+
return holderRevenue;
2222
};
2323

2424
const pools = [
25-
"Crypto.1",
26-
"Virtual.1",
27-
"Governance.1",
28-
"Community.1",
29-
"Community.2",
30-
"Community.3",
31-
"Trump.1",
25+
"Crypto.1",
26+
"Virtual.1",
27+
"Governance.1",
28+
"Community.1",
29+
"Community.2",
30+
"Community.3",
31+
"Trump.1",
3232
]
3333

3434
const fetch = async (_a: any, _b: any, options: FetchOptions): Promise<FetchResultFees> => {
35-
const timestamp = options.startOfDay;
36-
const targetDate = new Date(timestamp * 1000).toISOString().split('T')[0];
35+
const timestamp = options.startOfDay;
36+
const targetDate = new Date(timestamp * 1000).toISOString().split('T')[0];
37+
38+
const poolFeesData: { [pool: string]: number } = {};
39+
let dailyFees = 0;
40+
41+
for (const pool of pools) {
42+
const url = `https://api.prod.flash.trade/pnl-info/cumulative-pnl-per-day?poolName=${pool}&startDate=2023-01-01%2000:00:00&endDate=${targetDate}%2023:59:59`;
43+
const res = await fetchURL(url);
44+
const poolFees = (res[targetDate]?.totalFees / 1e6) || 0;
45+
poolFeesData[pool] = poolFees;
46+
dailyFees += poolFees;
47+
}
48+
49+
const dailyRevStatsResponse = await fetchURL(urlRevStats);
50+
const dailyStats: Pool[] = dailyRevStatsResponse;
51+
52+
const todayStats = dailyStats.filter(item => {
53+
const itemDate = new Date(item.date).toISOString().split('T')[0];
54+
return itemDate === targetDate;
55+
});
56+
57+
// June 19, 2025 timestamp (when holder revenue started)
58+
const holderRevenueStartTimestamp = 1750291200;
59+
60+
let dailyHoldersRevenue = 0;
61+
let dailyProtocolRevenue = 0;
62+
let dailyRevenue = 0;
63+
64+
if (timestamp > holderRevenueStartTimestamp) {
65+
// After June 19, 2025: Use API data for holder and protocol revenue
66+
dailyHoldersRevenue = calculateteHolderRevenue(todayStats);
67+
dailyProtocolRevenue = calculateProtocolRevenue(todayStats);
68+
dailyRevenue = dailyProtocolRevenue + dailyHoldersRevenue;
69+
} else {
70+
// Before June 19, 2025: Apply specific revenue percentages per pool
71+
const poolRevenueRates: { [key: string]: number } = {
72+
"Crypto.1": 0.30,
73+
"Virtual.1": 0.30,
74+
"Governance.1": 0.30,
75+
"Community.1": 0.00,
76+
"Community.2": 0.00,
77+
"Community.3": 0.05,
78+
"Trump.1": 0.05,
79+
};
3780

38-
const poolFeesData: { [pool: string]: number } = {};
39-
let dailyFees = 0;
40-
4181
for (const pool of pools) {
42-
const url = `https://api.prod.flash.trade/pnl-info/cumulative-pnl-per-day?poolName=${pool}&startDate=2023-01-01%2000:00:00&endDate=${targetDate}%2023:59:59`;
43-
const res = await fetchURL(url);
44-
const poolFees = (res[targetDate]?.totalFees / 1e6) || 0;
45-
poolFeesData[pool] = poolFees;
46-
dailyFees += poolFees;
82+
const rate = poolRevenueRates[pool] || 0;
83+
if (rate > 0) {
84+
const poolFees = poolFeesData[pool] || 0;
85+
dailyRevenue += poolFees * rate;
86+
}
4787
}
4888

49-
const dailyRevStatsResponse = await fetchURL(urlRevStats);
50-
const dailyStats: Pool[] = dailyRevStatsResponse;
51-
52-
const todayStats = dailyStats.filter(item => {
53-
const itemDate = new Date(item.date).toISOString().split('T')[0];
54-
return itemDate === targetDate;
55-
});
56-
57-
// June 19, 2025 timestamp (when holder revenue started)
58-
const holderRevenueStartTimestamp = 1750291200;
59-
60-
let dailyHoldersRevenue = 0;
61-
let dailyProtocolRevenue = 0;
62-
let dailyRevenue = 0;
63-
64-
if (timestamp > holderRevenueStartTimestamp) {
65-
// After June 19, 2025: Use API data for holder and protocol revenue
66-
dailyHoldersRevenue = calculateteHolderRevenue(todayStats);
67-
dailyProtocolRevenue = calculateProtocolRevenue(todayStats);
68-
dailyRevenue = dailyProtocolRevenue + dailyHoldersRevenue;
69-
} else {
70-
// Before June 19, 2025: Apply specific revenue percentages per pool
71-
const poolRevenueRates: { [key: string]: number } = {
72-
"Crypto.1": 0.30,
73-
"Virtual.1": 0.30,
74-
"Governance.1": 0.30,
75-
"Community.1": 0.00,
76-
"Community.2": 0.00,
77-
"Community.3": 0.05,
78-
"Trump.1": 0.05,
79-
};
80-
81-
for (const pool of pools) {
82-
const rate = poolRevenueRates[pool] || 0;
83-
if (rate > 0) {
84-
const poolFees = poolFeesData[pool] || 0;
85-
dailyRevenue += poolFees * rate;
86-
}
87-
}
88-
89-
dailyProtocolRevenue = dailyRevenue; // All revenue goes to protocol before holder revenue started
90-
dailyHoldersRevenue = 0;
91-
}
89+
dailyProtocolRevenue = dailyRevenue; // All revenue goes to protocol before holder revenue started
90+
dailyHoldersRevenue = 0;
91+
}
9292

93-
const dailySupplySideRevenue = dailyFees - dailyRevenue;
93+
const dailySupplySideRevenue = dailyFees > dailyRevenue ? dailyFees - dailyRevenue : 0;
9494

95-
return {
96-
dailyFees,
97-
dailyUserFees: dailyFees,
98-
dailyRevenue,
99-
dailyProtocolRevenue,
100-
dailyHoldersRevenue,
101-
dailySupplySideRevenue,
102-
};
95+
return {
96+
dailyFees,
97+
dailyUserFees: dailyFees,
98+
dailyRevenue,
99+
dailyProtocolRevenue,
100+
dailyHoldersRevenue,
101+
dailySupplySideRevenue,
102+
};
103103
};
104104

105105
const methodology = {
106-
Fees: 'All fees generated by the pools.',
107-
Revenue: 'Sum of protocol revenue and holder revenue.',
108-
ProtocolRevenue: 'Before 2025-06-19: Crypto.1/Virtual.1/Governance.1 pools at 30%, Community.3/Trump.1 pools at 5%, Community.1/Community.2 at 0%. After 2025-06-19: dynamic based on API.',
109-
HolderRevenue: 'Token holder revenue started from 2025-06-19, 0 before that date.',
110-
SupplySideRevenue: 'Fees paid to LP pools.',
106+
Fees: 'All fees generated by the pools.',
107+
Revenue: 'Sum of protocol revenue and holder revenue.',
108+
ProtocolRevenue: 'Before 2025-06-19: Crypto.1/Virtual.1/Governance.1 pools at 30%, Community.3/Trump.1 pools at 5%, Community.1/Community.2 at 0%. After 2025-06-19: dynamic based on API.',
109+
HolderRevenue: 'Token holder revenue started from 2025-06-19, 0 before that date.',
110+
SupplySideRevenue: 'Fees paid to LP pools.',
111111
}
112112

113113
const adapter: Adapter = {
114-
version: 1,
115-
chains: [CHAIN.SOLANA],
116-
fetch,
117-
start: '2023-12-29',
118-
methodology
114+
version: 1,
115+
chains: [CHAIN.SOLANA],
116+
fetch,
117+
start: '2023-12-29',
118+
methodology
119119
};
120120

121121
export default adapter;

0 commit comments

Comments
 (0)