Skip to content

Commit 1cba03a

Browse files
authored
EIP1559 (#15)
1 parent f67cb2a commit 1cba03a

9 files changed

+280
-2
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.9.0
1+
v1.9.1

dune/gas/Block_TxFees.sql

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
WITH tx AS(
2+
SELECT
3+
block_number,
4+
t.hash,
5+
type,
6+
gas_price as gas_price,
7+
t.gas_used,
8+
CASE WHEN priority_fee_per_gas IS NOT NULL THEN priority_fee_per_gas ELSE gas_price-b.base_fee_per_gas END as priority_fee_per_gas,
9+
b.base_fee_per_gas as block_base_fee
10+
FROM ethereum.transactions t
11+
LEFT JOIN ethereum.blocks b ON block_number = number
12+
WHERE block_time > now() - INTERVAL '6 hours'
13+
AND success
14+
),
15+
block_fees AS(
16+
SELECT
17+
block_number,
18+
block_base_fee,
19+
AVG(priority_fee_per_gas/1e9) as avg_priority_fee,
20+
SUM(gas_used*priority_fee_per_gas)/1e18 as priority_fee,
21+
SUM(gas_used*Block_base_fee)/1e18 as base_fee,
22+
COUNT(hash) FILTER (WHERE type = 'Legacy') AS legacy_count,
23+
COUNT(hash) FILTER (WHERE type = 'DynamicFee') AS dynamicFee_count
24+
FROM tx
25+
GROUP BY 1,2
26+
)
27+
SELECT
28+
block_number,
29+
block_base_fee/1e9 as "Base Fee (Gwei)",
30+
AVG(block_base_fee/1e9) OVER (order by block_number Rows Between 5 preceding and current row) as "Base Fee MA (Gwei)",
31+
avg_priority_fee as "Tip (Gwei)",
32+
AVG(avg_priority_fee) OVER (order by block_number Rows Between 5 preceding and current row) as "Tip MA(Gwei)",
33+
priority_fee as "Block Tips (ETH)",
34+
base_fee as "Block Base Fees (ETH)",
35+
legacy_count as "Legacy # TX",
36+
dynamicFee_count as "Dynamic # TX",
37+
avg(priority_fee) OVER (order by block_number Rows Between 30 preceding and current row) as "Block Tips MA (ETH)",
38+
avg(base_fee) OVER (order by block_number Rows Between 30 preceding and current row) as "Block Base Fees MA (ETH)",
39+
avg(legacy_count) OVER (order by block_number Rows Between 30 preceding and current row) as "Legacy MA # TX",
40+
avg(dynamicFee_count) OVER (order by block_number Rows Between 30 preceding and current row) as "Dynamic MA # TX"
41+
FROM block_fees
42+
ORDER BY block_number DESC

dune/gas/EIP1559_BlockData.sql

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SELECT
2+
number,
3+
gas_limit,
4+
gas_used,
5+
base_fee_per_gas/1e9 as base_fee,
6+
(gas_used * base_fee_per_gas)/1e18 as "Burned ETH per Block",
7+
avg(base_fee_per_gas/1e9) OVER (order by number Rows Between 5 preceding and current row) as basefee_ma_5bk,
8+
avg((gas_used * base_fee_per_gas)/1e18) OVER (order by number Rows Between 30 preceding and current row) as "MA Burned ETH per Block",
9+
gas_used/gas_limit as "Block Usage",
10+
avg(gas_used/gas_limit) OVER (order by number Rows Between 30 preceding and current row) as "MA Block Usage",
11+
sum((gas_used * base_fee_per_gas)/1e18) OVER (order by number) as total_burn,
12+
0.5 as "Target Block Usage",
13+
2 as "Deflationary Limit"
14+
FROM ethereum.blocks
15+
WHERE time > now() - INTERVAL '6 hours'
16+
ORDER BY number DESC

dune/gas/Legacy_v_Dynamic_Fees.sql

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
WITH tx AS(
2+
SELECT
3+
block_number,
4+
t.hash,
5+
type,
6+
gas_price as gas_price,
7+
t.gas_used,
8+
CASE WHEN priority_fee_per_gas IS NOT NULL THEN priority_fee_per_gas ELSE gas_price-b.base_fee_per_gas END as priority_fee_per_gas,
9+
b.base_fee_per_gas as block_base_fee
10+
FROM ethereum.transactions t
11+
LEFT JOIN ethereum.blocks b ON block_number = number
12+
WHERE block_time > now() - INTERVAL '6 hours'
13+
AND success
14+
),
15+
block_fees AS(
16+
SELECT
17+
block_number,
18+
block_base_fee,
19+
AVG(priority_fee_per_gas/1e9) as avg_priority_fee,
20+
SUM(gas_used*priority_fee_per_gas)/1e18 as priority_fee,
21+
SUM(gas_used*Block_base_fee)/1e18 as base_fee,
22+
COUNT(hash) FILTER (WHERE type = 'Legacy') AS legacy_count,
23+
COUNT(hash) FILTER (WHERE type = 'DynamicFee') AS dynamicFee_count
24+
FROM tx
25+
GROUP BY 1,2
26+
)
27+
SELECT
28+
block_number,
29+
block_base_fee/1e9 as "Base Fee (Gwei)",
30+
AVG(block_base_fee/1e9) OVER (order by block_number Rows Between 5 preceding and current row) as "Base Fee MA (Gwei)",
31+
avg_priority_fee as "Tip (Gwei)",
32+
AVG(avg_priority_fee) OVER (order by block_number Rows Between 5 preceding and current row) as "Tip MA(Gwei)",
33+
priority_fee as "Block Tips (ETH)",
34+
base_fee as "Block Base Fees (ETH)",
35+
legacy_count as "Legacy # TX",
36+
dynamicFee_count as "Dynamic # TX",
37+
avg(priority_fee) OVER (order by block_number Rows Between 30 preceding and current row) as "Block Tips MA (ETH)",
38+
avg(base_fee) OVER (order by block_number Rows Between 30 preceding and current row) as "Block Base Fees MA (ETH)",
39+
avg(legacy_count) OVER (order by block_number Rows Between 30 preceding and current row) as "Legacy MA # TX",
40+
avg(dynamicFee_count) OVER (order by block_number Rows Between 30 preceding and current row) as "Dynamic MA # TX"
41+
FROM block_fees
42+
ORDER BY block_number DESC

dune/gas/Tips_v_BaseFee.sql

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
WITH tx AS(
2+
SELECT
3+
-- date_trunc('hour', block_time) + date_part('minute', block_time)::int / 5 * interval '5 min' as minute,
4+
date_trunc('minute', block_time) as minute,
5+
block_number,
6+
t.hash,
7+
type,
8+
--gas_price as gas_price,
9+
t.gas_used as tx_gas_used,
10+
CASE WHEN priority_fee_per_gas IS NOT NULL THEN priority_fee_per_gas ELSE gas_price-b.base_fee_per_gas END as priority_fee_per_gas,
11+
b.base_fee_per_gas as block_base_fee
12+
FROM ethereum.transactions t
13+
LEFT JOIN ethereum.blocks b ON block_number = number
14+
WHERE block_time > now() - INTERVAL '1 days'
15+
AND success
16+
),
17+
block_fees AS(
18+
SELECT
19+
block_number,
20+
minute,
21+
SUM(tx_gas_used*priority_fee_per_gas)/1e18 as priority_total,
22+
SUM(tx_gas_used*Block_base_fee)/1e18 as base_total
23+
FROM tx
24+
GROUP BY 1,2
25+
),
26+
minute_fees AS(
27+
SELECT
28+
t.minute,
29+
AVG(block_base_fee) AS block_base_fee,
30+
AVG(priority_fee_per_gas/1e9) as avg_priority_fee,
31+
AVG(priority_total) as priority_total,
32+
AVG(base_total) as base_total,
33+
COUNT(hash) FILTER (WHERE type = 'Legacy') AS legacy_count,
34+
COUNT(hash) FILTER (WHERE type = 'DynamicFee') AS dynamicFee_count
35+
FROM tx t
36+
LEFT JOIN block_fees b ON t.minute=b.minute
37+
GROUP BY 1
38+
)
39+
40+
SELECT
41+
minute,
42+
block_base_fee/1e9 as "Base Fee (Gwei)",
43+
--AVG(block_base_fee/1e9) OVER (order by minute Rows Between 5 preceding and current row) as "Base Fee MA (Gwei)",
44+
avg_priority_fee as "Tip (Gwei)",
45+
--AVG(avg_priority_fee) OVER (order by minute Rows Between 5 preceding and current row) as "Tip MA(Gwei)",
46+
priority_total as "Block Tips (ETH)",
47+
base_total as "Block Base Fees (ETH)",
48+
legacy_count as "Legacy # TX",
49+
dynamicFee_count as "Dynamic # TX"
50+
--avg(priority_total) OVER (order by minute Rows Between 30 preceding and current row) as "Block Tips MA (ETH)",
51+
--avg(base_total) OVER (order by minute Rows Between 30 preceding and current row) as "Block Base Fees MA (ETH)",
52+
--avg(legacy_count) OVER (order by minute Rows Between 30 preceding and current row) as "Legacy MA # TX",
53+
--avg(dynamicFee_count) OVER (order by minute Rows Between 30 preceding and current row) as "Dynamic MA # TX"
54+
FROM minute_fees
55+
ORDER BY minute DESC

dune/gas/Weekly_BlockTxFees.sql

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
WITH tx AS(
2+
SELECT
3+
date_trunc('hour', block_time) as hour,
4+
block_number,
5+
t.hash,
6+
type,
7+
--gas_price as gas_price,
8+
t.gas_used,
9+
CASE WHEN priority_fee_per_gas IS NOT NULL THEN priority_fee_per_gas ELSE gas_price-b.base_fee_per_gas END as priority_fee_per_gas,
10+
b.base_fee_per_gas as block_base_fee
11+
FROM ethereum.transactions t
12+
LEFT JOIN ethereum.blocks b ON block_number = number
13+
WHERE block_time > now() - INTERVAL '1 weeks'
14+
AND success
15+
),
16+
block_fees AS(
17+
SELECT
18+
block_number,
19+
hour,
20+
SUM(gas_used*priority_fee_per_gas)/1e18 as priority_total,
21+
SUM(gas_used*Block_base_fee)/1e18 as base_total
22+
FROM tx
23+
GROUP BY 1,2
24+
),
25+
hour_fees AS(
26+
SELECT
27+
t.hour,
28+
AVG(block_base_fee) AS block_base_fee,
29+
AVG(priority_fee_per_gas/1e9) as avg_priority_fee,
30+
AVG(priority_total) as priority_total,
31+
AVG(base_total) as base_total,
32+
COUNT(hash) FILTER (WHERE type = 'Legacy') AS legacy_count,
33+
COUNT(hash) FILTER (WHERE type = 'DynamicFee') AS dynamicFee_count
34+
FROM tx t
35+
LEFT JOIN block_fees b ON t.hour=b.hour
36+
GROUP BY 1
37+
)
38+
39+
SELECT
40+
hour,
41+
block_base_fee/1e9 as "Base Fee (Gwei)",
42+
--AVG(block_base_fee/1e9) OVER (order by hour Rows Between 5 preceding and current row) as "Base Fee MA (Gwei)",
43+
avg_priority_fee as "Tip (Gwei)",
44+
--AVG(avg_priority_fee) OVER (order by hour Rows Between 5 preceding and current row) as "Tip MA(Gwei)",
45+
priority_total as "Block Tips (ETH)",
46+
base_total as "Block Base Fees (ETH)",
47+
legacy_count as "Legacy # TX",
48+
dynamicFee_count as "Dynamic # TX"
49+
--avg(priority_total) OVER (order by hour Rows Between 30 preceding and current row) as "Block Tips MA (ETH)",
50+
--avg(base_total) OVER (order by hour Rows Between 30 preceding and current row) as "Block Base Fees MA (ETH)",
51+
--avg(legacy_count) OVER (order by hour Rows Between 30 preceding and current row) as "Legacy MA # TX",
52+
--avg(dynamicFee_count) OVER (order by hour Rows Between 30 preceding and current row) as "Dynamic MA # TX"
53+
FROM hour_fees
54+
ORDER BY hour DESC

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dune-snippets",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "Dune Analytics Snippets",
55
"main": "index.js",
66
"files": [
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
WITH uniswap_trades AS (
2+
SELECT tx_hash, usd_amount
3+
FROM dex."trades" d
4+
WHERE project = 'Uniswap' AND version ='2'
5+
AND block_time >= (DATE_TRUNC('hour', CURRENT_TIMESTAMP) - '24 hours'::INTERVAL)
6+
), -- transaction hash in UNISWAP v2
7+
8+
dex_trade_type AS (
9+
SELECT "to",
10+
CASE WHEN "to" in ('\x7a250d5630b4cf539739df2c5dacb4c659f2488d','\xf164fc0ec4e93095b804a4795bbe1e041497b92a','\xc9f8878ebba65ab04743f374f57fb652981e222c') then 'Uniswap'
11+
WHEN "to" in ('\x111111125434b319222cdbf8c261674adb56f3ae','\x1111111254fc78fdddb1ca73c8c15f91342af92e','\x11111112542d85b3ef69ae05771c2dccff4faa26') then '1inch'
12+
WHEN "to" in ('\xdef1c0ded9bec7f1a1670819833240f027b25eff','\x881d40237659c251811cec9c364ef91dc08d300c') then '0x'
13+
WHEN "to"='\xf90e98f3d8dce44632e5020abf2e122e0f99dfab' then 'Paraswap'
14+
WHEN "to"='\xa356867fdcea8e71aeaf87805808803806231fdc' then 'DODO V2'
15+
WHEN "to"='\x7c40c393dc0f283f318791d746d894ddd3693572' then 'Mooncats'
16+
WHEN "to" in ('\x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9','\x63a3f444e97d14e671e7ee323c4234c8095e3516','\x498c5431eb517101582988fbb36431ddaac8f4b1') then 'AAVE Flashloan'
17+
WHEN "to"='\xa013afbb9a92cef49e898c87c060e6660e050569' then 'Furucombo'
18+
ELSE NULL END AS label,
19+
SUBSTRING(t.input, 1, 4), -- get first 4 characters in the input
20+
s.signature, -- identfier?
21+
COUNT(*), -- count number of tos?
22+
MIN(block_time) as first_seen,
23+
MAX(t.tx_hash::text) as example_tx, -- 1 trace contains multiple tx, get max
24+
SUM(usd_amount) as amt
25+
FROM ethereum."traces" t
26+
JOIN uniswap_trades u on u.tx_hash = t.tx_hash -- join uniswap with the same tx hashes in ethereum
27+
LEFT JOIN ethereum."signatures" s on s.id = substring(t.input,1,4)
28+
WHERE
29+
trace_address::text = '{}'
30+
-- only top level call
31+
AND t.block_time >= (DATE_TRUNC('hour',CURRENT_TIMESTAMP) - '24 hours'::INTERVAL)
32+
GROUP BY 1,2,3,4
33+
HAVING COUNT(*) >= 0
34+
ORDER BY 5 desc, 8 desc)
35+
36+
SELECT "to",label,"substring",signature,"count",first_seen,example_tx,"amt"
37+
FROM dex_trade_type dt
38+
WHERE dt.label = {{param}}
39+
-- on dune frontend, enter example, 'uniswap trader'
40+
41+
42+
43+
--select * from ethereum."signatures" limit 10
44+
45+
-- look closer into this tx example
46+
-- https://bloxy.info/tx/0xbeca2c54c268e4616b3e44adcfc9df05f88380a561d8b4966343ede9c0add8ae
47+
48+
49+
--select substring(input,1,4) from ethereum."traces" where tx_hash = '\xffe0f7a47b877259b09c4465727c7d0d315020ae48e80845538f2c2fd95471c9'

tests/view_dependencies.sql

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- source: https://stackoverflow.com/a/48770535/1838257
2+
3+
--CREATE OR REPLACE VIEW dune_user_generated.gosuto_view_dependencies AS
4+
SELECT DISTINCT srcobj.oid AS src_oid,
5+
srcnsp.nspname AS src_schemaname,
6+
srcobj.relname AS src_objectname,
7+
tgtobj.oid AS dependent_viewoid,
8+
tgtnsp.nspname AS dependant_schemaname,
9+
tgtobj.relname AS dependant_objectname
10+
FROM pg_class srcobj
11+
JOIN pg_depend srcdep ON srcobj.oid = srcdep.refobjid
12+
JOIN pg_depend tgtdep ON srcdep.objid = tgtdep.objid
13+
JOIN pg_class tgtobj ON tgtdep.refobjid = tgtobj.oid AND srcobj.oid <> tgtobj.oid
14+
LEFT JOIN pg_namespace srcnsp ON srcobj.relnamespace = srcnsp.oid
15+
LEFT JOIN pg_namespace tgtnsp ON tgtobj.relnamespace = tgtnsp.oid
16+
WHERE tgtdep.deptype = 'i'::"char" AND tgtobj.relkind = 'v'::"char"
17+
AND src_objectname LIKE '%badgerdao%'
18+
-- filter like so:
19+
-- SELECT * FROM dune_user_generated.gosuto_view_dependencies
20+
-- WHERE src_objectname LIKE '%filter_word%'

0 commit comments

Comments
 (0)