Skip to content

Commit 163d055

Browse files
Update clanker.ts (DefiLlama#3760)
* Update clanker.ts 1. Added V31: clanker_base.Clanker_v31_evt_TokenCreated 2. Added V4: clanker_v4_base.clanker_evt_tokencreated 3. Kept existing: V3, V2, V1, and V0 (SocialDex) 4. Added proper filtering: Including the evt_tx_from filter for SocialDex 5. Updated start date: Changed from "2024-11-22" to "2024-11-08" to cover V4 What was missing: - V31 and V4 token creation events - Proper SocialDex filtering with evt_tx_from addresses - Comments matching the token dictionary format * refactor * clanker takes 20% fee from the LP fees --------- Co-authored-by: treeoflife2 <sol.analyzoor@gmail.com>
1 parent 7dd37ca commit 163d055

File tree

1 file changed

+112
-99
lines changed

1 file changed

+112
-99
lines changed

fees/clanker.ts

Lines changed: 112 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,102 @@ import { FetchOptions, SimpleAdapter } from "../adapters/types";
22
import { CHAIN } from "../helpers/chains";
33
import { queryDuneSql } from "../helpers/dune";
44

5-
const fetchFees = async (_a: any, _b: any, options: FetchOptions) => {
6-
const dailyFees = options.createBalances();
7-
const res = await queryDuneSql(options, `
8-
WITH created_contracts AS (
9-
SELECT
10-
'Clanker' AS projects
11-
, tokenAddress
12-
FROM
13-
socialdex_base.SocialDexDeployer_evt_TokenCreated
14-
WHERE evt_block_time > TIMESTAMP '2024-11-27'
15-
AND evt_block_time <= from_unixtime(${options.endTimestamp})
16-
17-
UNION ALL
18-
19-
SELECT
20-
'Clanker' as projects
21-
, tokenAddress
22-
FROM clanker_base.Clanker_V1_evt_TokenCreated
23-
WHERE evt_block_time > TIMESTAMP '2024-11-27'
24-
AND evt_block_time <= from_unixtime(${options.endTimestamp})
25-
26-
UNION ALL
27-
28-
SELECT
29-
'Clanker' as projects
30-
, tokenAddress
31-
FROM clanker_base.Clanker_v2_evt_TokenCreated
32-
WHERE evt_block_time > TIMESTAMP '2024-11-08'
33-
AND evt_block_time <= from_unixtime(${options.endTimestamp})
34-
35-
UNION ALL
36-
37-
SELECT
38-
'Clanker' as projects
39-
, tokenAddress
40-
FROM clanker_base.Clanker_v3_evt_TokenCreated
41-
WHERE evt_block_time > TIMESTAMP '2024-11-08'
42-
AND evt_block_time <= from_unixtime(${options.endTimestamp})
43-
),
44-
dex_trades AS (
45-
SELECT
46-
*
47-
FROM
48-
dex.trades t
49-
WHERE
50-
t.blockchain = 'base'
51-
AND TIME_RANGE
52-
AND amount_usd > 1
53-
),
54-
daily_fees AS (
55-
SELECT
56-
d_day,
57-
projects,
58-
SUM(fees) AS daily_fees
59-
FROM (
5+
const fetch = async (_a: any, _b: any, options: FetchOptions) => {
6+
const dailyFees = options.createBalances();
7+
const res = await queryDuneSql(options, `
8+
WITH created_contracts AS (
9+
/* ---------- V31 (added) ---------- */
10+
SELECT
11+
'Clanker' AS projects,
12+
tokenAddress
13+
FROM
14+
clanker_base.Clanker_v31_evt_TokenCreated
15+
WHERE evt_block_time > TIMESTAMP '2024-11-27'
16+
AND evt_block_time <= from_unixtime(${options.endTimestamp})
17+
18+
UNION ALL
19+
20+
/* ---------- V4 (added) ---------- */
6021
SELECT
61-
DATE_TRUNC('day', block_time) AS d_day,
62-
a.tokenAddress,
63-
a.projects,
64-
SUM(amount_usd * 0.01) AS fees
22+
'Clanker' AS projects,
23+
tokenAddress
24+
FROM
25+
clanker_v4_base.clanker_evt_tokencreated
26+
WHERE evt_block_time > TIMESTAMP '2024-11-08'
27+
AND evt_block_time <= from_unixtime(${options.endTimestamp})
28+
29+
UNION ALL
30+
31+
/* ---------- V3 (existing) ---------- */
32+
SELECT
33+
'Clanker' as projects,
34+
tokenAddress
35+
FROM clanker_base.Clanker_v3_evt_TokenCreated
36+
WHERE evt_block_time > TIMESTAMP '2024-11-08'
37+
AND evt_block_time <= from_unixtime(${options.endTimestamp})
38+
39+
UNION ALL
40+
41+
/* ---------- V2 (existing) ---------- */
42+
SELECT
43+
'Clanker' as projects,
44+
tokenAddress
45+
FROM clanker_base.Clanker_v2_evt_TokenCreated
46+
WHERE evt_block_time > TIMESTAMP '2024-11-08'
47+
AND evt_block_time <= from_unixtime(${options.endTimestamp})
48+
49+
UNION ALL
50+
51+
/* ---------- V1 (existing) ---------- */
52+
SELECT
53+
'Clanker' as projects,
54+
tokenAddress
55+
FROM clanker_base.Clanker_V1_evt_TokenCreated
56+
WHERE evt_block_time > TIMESTAMP '2024-11-27'
57+
AND evt_block_time <= from_unixtime(${options.endTimestamp})
58+
59+
UNION ALL
60+
61+
/* ---------- V0 - SocialDex (existing) ---------- */
62+
SELECT
63+
'Clanker' AS projects,
64+
tokenAddress
65+
FROM
66+
socialdex_base.SocialDexDeployer_evt_TokenCreated
67+
WHERE evt_block_time > TIMESTAMP '2024-11-27'
68+
AND evt_block_time <= from_unixtime(${options.endTimestamp})
69+
AND evt_tx_from IN (0xe0c959eedcfd004952441ea4fb4b8f5af424e74b,
70+
0xc204af95b0307162118f7bc36a91c9717490ab69)
71+
),
72+
dex_trades AS (
73+
SELECT
74+
*
75+
FROM
76+
dex.trades t
77+
WHERE
78+
t.blockchain = 'base'
79+
AND t.block_time >= from_unixtime(${options.startTimestamp})
80+
AND t.block_time < from_unixtime(${options.endTimestamp})
81+
AND amount_usd > 1
82+
),
83+
daily_fees AS (
84+
SELECT
85+
SUM(amount_usd * 0.01) AS df
6586
FROM
6687
dex_trades t
6788
INNER JOIN
6889
created_contracts a
6990
ON
7091
a.tokenAddress = t.token_bought_address
71-
GROUP BY
72-
1, 2, 3
92+
WHERE
93+
t.blockchain = 'base'
94+
AND TIME_RANGE
95+
AND amount_usd > 1
7396
7497
UNION ALL
7598
7699
SELECT
77-
DATE_TRUNC('day', block_time) AS d_day,
78-
a.tokenAddress,
79-
a.projects,
80-
SUM(amount_usd * 0.01) AS fees
100+
SUM(amount_usd * 0.01) AS df
81101
FROM
82102
dex_trades t
83103
INNER JOIN
@@ -88,45 +108,38 @@ const fetchFees = async (_a: any, _b: any, options: FetchOptions) => {
88108
t.blockchain = 'base'
89109
AND TIME_RANGE
90110
AND amount_usd > 1
91-
GROUP BY
92-
1, 2, 3
93-
) AS combined_fees
94-
GROUP BY
95-
1, 2
96-
)
97-
SELECT
98-
d_day,
99-
daily_fees
100-
FROM
101-
daily_fees
102-
WHERE
103-
d_day <> DATE_TRUNC('day', NOW())
104-
ORDER BY
105-
d_day DESC
106-
`);
107-
dailyFees.addUSDValue(res[0].daily_fees);
108-
return {
109-
dailyFees,
110-
dailyRevenue: dailyFees,
111-
dailyProtocolRevenue: dailyFees,
112-
};
111+
)
112+
SELECT
113+
SUM(df) AS daily_fees_usd
114+
FROM
115+
daily_fees
116+
`);
117+
118+
dailyFees.addUSDValue(res[0].daily_fees_usd);
119+
const dailyProtocolRevenue = dailyFees.clone(0.2) // 20% of fees to protocol
120+
121+
return {
122+
dailyFees,
123+
dailyRevenue: dailyProtocolRevenue,
124+
dailyProtocolRevenue: dailyProtocolRevenue,
125+
};
113126
};
114127

115128
const adapter: SimpleAdapter = {
116-
version: 1,
117-
adapter: {
118-
[CHAIN.BASE]: {
119-
fetch: fetchFees,
120-
start: "2024-11-22",
121-
meta: {
122-
methodology: {
123-
Fees: "All trading and launching tokens fees paid by users.",
124-
Revenue: "All fees are collected by Clanker protocol.",
125-
ProtocolRevenue: "Trading fees are collected by Clanker protocol.",
129+
version: 1,
130+
adapter: {
131+
[CHAIN.BASE]: {
132+
fetch,
133+
start: "2024-11-08", // Updated to cover V4 start date
134+
meta: {
135+
methodology: {
136+
Fees: "All trading and launching tokens fees paid by users.",
137+
Revenue: "Clanker protocol collects 20% of LP fees.",
138+
ProtocolRevenue: "Clanker protocol collects 20% of LP fees.",
139+
}
126140
}
127-
}
141+
},
128142
},
129-
},
130143
};
131144

132145
export default adapter;

0 commit comments

Comments
 (0)