Skip to content

Commit 8be321e

Browse files
committed
Track Beezie Claw Fee/Revenue
1 parent ad213ba commit 8be321e

File tree

1 file changed

+67
-20
lines changed

1 file changed

+67
-20
lines changed

fees/beezie.ts

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,95 @@
44
* Claw pull: user pays to play the claw machine (money in → claw wallet). That is gross take from plays, not final profit.
55
* Claw SWAP: after a win, the user can sell the prize back to Beezie within the offer window (money out ← claw wallet).
66
* We report net economics as inflows minus SWAP payouts; see https://docs.beezie.com/our-offerings/the-claw
7+
*
8+
* Tier names match known machine wallets; any factory machine not in those lists is "Other".
79
*/
810

911
import { Dependencies, FetchOptions, SimpleAdapter } from "../adapters/types";
1012
import { CHAIN } from "../helpers/chains";
1113
import { queryDuneSql } from "../helpers/dune";
1214

13-
/** Single breakdown line: net of plays vs. SWAP buybacks */
14-
const CLAW_NET_REVENUE = "Claw net revenue (plays minus SWAP buybacks)";
15+
/** Exclude Beezie internal flows so pulls/swaps reflect user↔machine only */
16+
const INTERNAL_WALLET = "0x80d7c04b738ef379971a6b73f25b1a71ea1c820d";
1517

16-
const INTERNAL_WALLET = "0x80d7C04B738eF379971a6b73f25B1A71ea1c820D";
18+
/** Dune varbinary literals (lowercase hex) — must match analytics tier buckets */
19+
const TIER_CASE = `
20+
CASE
21+
WHEN claw_wallet IN (
22+
0x25acd3ccb939703a742187d6f504428c684ea50c,
23+
0x8ed22e2569e4a5b4a872299591f0ac016ce19f4e,
24+
0xfdf28b9b957baed8f3d9962effa9b0fe1e189d6a,
25+
0x92d79b4b48230d44f915d47fea6c5f63c4565a69,
26+
0xa34426b958bc792bf2640befa204df579d81b3bf
27+
) THEN 'Wildcard'
28+
WHEN claw_wallet IN (
29+
0x044cec512d7a5d6852a1b1f1bf5bb9f746962073,
30+
0x1334e20c249b2c7b45a6b4bafa2947163d74c8b6,
31+
0x6f4aba86b9e441f77a51fa4d9fc47001e5bf1072,
32+
0x08f49b9d64a807ec00b1ba986dc9392c26029fcb
33+
) THEN 'Gold TCG'
34+
WHEN claw_wallet IN (
35+
0x7b8958961517daa2a0bea01249a9ac17f27725d6,
36+
0x7d71dfc365e6518d40cfdb3f10068be0974e9992,
37+
0x686328b1a104819dda8e8fa5681694a7b93e4061,
38+
0x310b050b945c7b9ee66704ca137ddac003371508,
39+
0x406762fc03d59776e2ea3c6546588aaf1813f173
40+
) THEN 'Silver TCG'
41+
WHEN claw_wallet IN (0x5dfb0592e11d63fdaa880020e69f81cc122d2c97) THEN 'Platinum TCG'
42+
ELSE 'Other'
43+
END`;
1744

1845
const fetch = async (_a: any, _b: any, options: FetchOptions) => {
1946
const dailyFees = options.createBalances();
2047

2148
const query = `
2249
WITH claw_wallets AS (
23-
SELECT clawMachine AS claw_wallet
50+
SELECT DISTINCT clawMachine AS claw_wallet
2451
FROM beezie_base.beezieclawmachinefactoryv2_evt_clawmachinecreated
2552
),
53+
machine_tier AS (
54+
SELECT
55+
claw_wallet,
56+
${TIER_CASE} AS claw_name
57+
FROM claw_wallets
58+
),
2659
inflows AS (
27-
SELECT SUM(amount_usd) AS total
60+
SELECT
61+
mt.claw_name,
62+
COALESCE(SUM(t.amount_usd), 0) AS total
2863
FROM tokens_base.transfers t
29-
INNER JOIN claw_wallets cw ON t."to" = cw.claw_wallet
64+
INNER JOIN machine_tier mt ON t."to" = mt.claw_wallet
3065
WHERE t."from" != ${INTERNAL_WALLET}
3166
AND t.block_time >= from_unixtime(${options.startTimestamp})
3267
AND t.block_time < from_unixtime(${options.endTimestamp})
68+
GROUP BY 1
3369
),
3470
outflows AS (
35-
SELECT SUM(amount_usd) AS total
71+
SELECT
72+
mt.claw_name,
73+
COALESCE(SUM(t.amount_usd), 0) AS total
3674
FROM tokens_base.transfers t
37-
INNER JOIN claw_wallets cw ON t."from" = cw.claw_wallet
75+
INNER JOIN machine_tier mt ON t."from" = mt.claw_wallet
3876
WHERE t."to" != ${INTERNAL_WALLET}
3977
AND t.block_time >= from_unixtime(${options.startTimestamp})
4078
AND t.block_time < from_unixtime(${options.endTimestamp})
79+
GROUP BY 1
80+
),
81+
names AS (
82+
SELECT DISTINCT claw_name FROM machine_tier
4183
)
4284
SELECT
43-
COALESCE(inflows.total, 0) - COALESCE(outflows.total, 0) AS net_revenue
44-
FROM inflows, outflows
85+
n.claw_name,
86+
COALESCE(i.total, 0) - COALESCE(o.total, 0) AS net_revenue
87+
FROM names n
88+
LEFT JOIN inflows i ON n.claw_name = i.claw_name
89+
LEFT JOIN outflows o ON n.claw_name = o.claw_name
4590
`;
4691

47-
const result = await queryDuneSql(options, query);
48-
dailyFees.addUSDValue(result[0]?.net_revenue ?? 0, CLAW_NET_REVENUE);
92+
const rows: { claw_name: string; net_revenue: number }[] = await queryDuneSql(options, query);
93+
for (const row of rows) {
94+
dailyFees.addUSDValue(row.net_revenue ?? 0, row.claw_name);
95+
}
4996

5097
return {
5198
dailyFees,
@@ -54,6 +101,8 @@ const fetch = async (_a: any, _b: any, options: FetchOptions) => {
54101
};
55102
};
56103

104+
const tierNetDesc = "Net for this claw tier: token inflows to those machine wallets (plays) minus outflows (SWAP / buyback payouts).";
105+
57106
const adapter: SimpleAdapter = {
58107
version: 1,
59108
fetch,
@@ -63,17 +112,15 @@ const adapter: SimpleAdapter = {
63112
dependencies: [Dependencies.DUNE],
64113
allowNegativeValue: true,
65114
methodology: {
66-
Fees: "Claw play payments to machine wallets minus SWAP buybacks paid to users who sell prizes back.",
67-
Revenue: "Same as fees: net claw economics after SWAP payouts.",
115+
Fees: "Net claw economics after SWAP payouts, split by tier.",
116+
Revenue: "Net claw economics after SWAP payouts, split by tier.",
68117
},
69118
breakdownMethodology: {
70119
Fees: {
71-
[CLAW_NET_REVENUE]:
72-
"Sum of token inflows to claw machines (plays) minus outflows from those wallets (SWAP / buyback payouts), excluding the internal Beezie wallet.",
73-
},
74-
Revenue: {
75-
[CLAW_NET_REVENUE]:
76-
"Sum of token inflows to claw machines (plays) minus outflows from those wallets (SWAP / buyback payouts), excluding the internal Beezie wallet.",
120+
['Wildcard']: tierNetDesc,
121+
['Gold TCG']: tierNetDesc,
122+
['Silver TCG']: tierNetDesc,
123+
['Platinum TCG']: tierNetDesc,
77124
},
78125
},
79126
};

0 commit comments

Comments
 (0)