Query editor
/* ============================================================================Q5b · Revenue by launched token — top 20 (fork of 8807767, launch leaderboard)----------------------------------------------------------------------------Which launches drove protocol revenue, across the whole pipeline:curve_revenue Tsunami curve fee on the token's bonding curve, net of creator sharehook_revenue Tsunami 1% hook fee on the token's graduated Calamari pool, net ofcreator share. Current-shape SwapFeeAccrued names the curve; for thetwo legacy hooks (no curve in the event) each accrual is paired withthe Swap in the same tx on a pool that uses that hook.calamari_revenue Calamari's 0.1% v4 protocol fee on the token's pool(s), valued offthe pool's quote leg.foundation_share = protocol revenue x {{foundation_share_pct}}%.revenue_since_campaign_usd uses {{campaign_start}} for the push window.========================================================================== */WITH launches AS (SELECT * FROM query_9105569),pools AS (SELECT * FROM query_9105572 WHERE tsunami_token IS NOT NULL),fee_sched AS (SELECT factory, block_number AS from_block,coalesce(lead(block_number) OVER (PARTITION BY factory ORDER BY block_number), 9999999999) AS to_block,fee_bps, creator_pctFROM (SELECT contract_address AS factory, block_number,cast(bytearray_to_uint256(bytearray_substring(data, 1, 32)) AS double) AS fee_bps,cast(bytearray_to_uint256(bytearray_substring(data, 33, 32)) AS double) AS creator_pctFROM ink.logsWHERE contract_address IN (0x5934a5c377309453746ee8aa5194f671930c09fa, 0x1fc16511f5fa4b4c1591ffeb8c38affc367076f1)AND topic0 = 0xd347e206f25a89b917fc9482f1a2d294d749baa4dc9bde7fb495ee11fe491643UNION ALLSELECT * FROM (VALUES (0x5934a5c377309453746ee8aa5194f671930c09fa, 0, 100e0, 0e0),(0x1fc16511f5fa4b4c1591ffeb8c38affc367076f1, 0, 100e0, 0e0)) AS t(factory, block_number, fee_bps, creator_pct))),px AS (SELECT timestamp AS hr, contract_address, price FROM prices.hourWHERE blockchain = 'ink' AND timestamp >= TIMESTAMP '2026-08-31'),-- ---------- curve phasecurve_rev AS (SELECT la.token, l.block_time, l.tx_from,CASE WHEN l.topic0 = 0x69c2c4bbea56030830cfa2a660af4e5e5f9922742272cac7cccfa1d78f18d568THEN cast(bytearray_to_uint256(l.topic1) AS double)ELSE cast(bytearray_to_uint256(bytearray_substring(l.data, 1, 32)) AS double) * 10000 / (10000 - s.fee_bps) END/ power(10, la.quote_decimals) AS gross,s.fee_bps,CASE WHEN la.fee_share IS NOT NULL AND l.block_number >= la.fee_share_from_block THEN s.creator_pct ELSE 0 END AS creator_pct,la.quote_tokenFROM ink.logs lJOIN launches la ON la.curve = l.contract_addressJOIN fee_sched s ON s.factory = la.factory AND l.block_number >= s.from_block AND l.block_number < s.to_blockWHERE l.topic0 IN (0x69c2c4bbea56030830cfa2a660af4e5e5f9922742272cac7cccfa1d78f18d568,0xb2888c28870dcbc5cc52fecadfbeeb35cf0b439bfd459ade61b675289c008be0)AND l.block_number >= 54686019),curve_tok AS (SELECT c.token,sum(c.gross * c.fee_bps / 10000 * (1 - c.creator_pct / 100) * p.price) AS curve_revenue_usd,