-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.9.0 | ||
v1.9.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
WITH tx AS( | ||
SELECT | ||
block_number, | ||
t.hash, | ||
type, | ||
gas_price as gas_price, | ||
t.gas_used, | ||
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, | ||
b.base_fee_per_gas as block_base_fee | ||
FROM ethereum.transactions t | ||
LEFT JOIN ethereum.blocks b ON block_number = number | ||
WHERE block_time > now() - INTERVAL '6 hours' | ||
AND success | ||
), | ||
block_fees AS( | ||
SELECT | ||
block_number, | ||
block_base_fee, | ||
AVG(priority_fee_per_gas/1e9) as avg_priority_fee, | ||
SUM(gas_used*priority_fee_per_gas)/1e18 as priority_fee, | ||
SUM(gas_used*Block_base_fee)/1e18 as base_fee, | ||
COUNT(hash) FILTER (WHERE type = 'Legacy') AS legacy_count, | ||
COUNT(hash) FILTER (WHERE type = 'DynamicFee') AS dynamicFee_count | ||
FROM tx | ||
GROUP BY 1,2 | ||
) | ||
SELECT | ||
block_number, | ||
block_base_fee/1e9 as "Base Fee (Gwei)", | ||
AVG(block_base_fee/1e9) OVER (order by block_number Rows Between 5 preceding and current row) as "Base Fee MA (Gwei)", | ||
avg_priority_fee as "Tip (Gwei)", | ||
AVG(avg_priority_fee) OVER (order by block_number Rows Between 5 preceding and current row) as "Tip MA(Gwei)", | ||
priority_fee as "Block Tips (ETH)", | ||
base_fee as "Block Base Fees (ETH)", | ||
legacy_count as "Legacy # TX", | ||
dynamicFee_count as "Dynamic # TX", | ||
avg(priority_fee) OVER (order by block_number Rows Between 30 preceding and current row) as "Block Tips MA (ETH)", | ||
avg(base_fee) OVER (order by block_number Rows Between 30 preceding and current row) as "Block Base Fees MA (ETH)", | ||
avg(legacy_count) OVER (order by block_number Rows Between 30 preceding and current row) as "Legacy MA # TX", | ||
avg(dynamicFee_count) OVER (order by block_number Rows Between 30 preceding and current row) as "Dynamic MA # TX" | ||
FROM block_fees | ||
ORDER BY block_number DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
SELECT | ||
number, | ||
gas_limit, | ||
gas_used, | ||
base_fee_per_gas/1e9 as base_fee, | ||
(gas_used * base_fee_per_gas)/1e18 as "Burned ETH per Block", | ||
avg(base_fee_per_gas/1e9) OVER (order by number Rows Between 5 preceding and current row) as basefee_ma_5bk, | ||
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", | ||
gas_used/gas_limit as "Block Usage", | ||
avg(gas_used/gas_limit) OVER (order by number Rows Between 30 preceding and current row) as "MA Block Usage", | ||
sum((gas_used * base_fee_per_gas)/1e18) OVER (order by number) as total_burn, | ||
0.5 as "Target Block Usage", | ||
2 as "Deflationary Limit" | ||
FROM ethereum.blocks | ||
WHERE time > now() - INTERVAL '6 hours' | ||
ORDER BY number DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
WITH tx AS( | ||
SELECT | ||
block_number, | ||
t.hash, | ||
type, | ||
gas_price as gas_price, | ||
t.gas_used, | ||
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, | ||
b.base_fee_per_gas as block_base_fee | ||
FROM ethereum.transactions t | ||
LEFT JOIN ethereum.blocks b ON block_number = number | ||
WHERE block_time > now() - INTERVAL '6 hours' | ||
AND success | ||
), | ||
block_fees AS( | ||
SELECT | ||
block_number, | ||
block_base_fee, | ||
AVG(priority_fee_per_gas/1e9) as avg_priority_fee, | ||
SUM(gas_used*priority_fee_per_gas)/1e18 as priority_fee, | ||
SUM(gas_used*Block_base_fee)/1e18 as base_fee, | ||
COUNT(hash) FILTER (WHERE type = 'Legacy') AS legacy_count, | ||
COUNT(hash) FILTER (WHERE type = 'DynamicFee') AS dynamicFee_count | ||
FROM tx | ||
GROUP BY 1,2 | ||
) | ||
SELECT | ||
block_number, | ||
block_base_fee/1e9 as "Base Fee (Gwei)", | ||
AVG(block_base_fee/1e9) OVER (order by block_number Rows Between 5 preceding and current row) as "Base Fee MA (Gwei)", | ||
avg_priority_fee as "Tip (Gwei)", | ||
AVG(avg_priority_fee) OVER (order by block_number Rows Between 5 preceding and current row) as "Tip MA(Gwei)", | ||
priority_fee as "Block Tips (ETH)", | ||
base_fee as "Block Base Fees (ETH)", | ||
legacy_count as "Legacy # TX", | ||
dynamicFee_count as "Dynamic # TX", | ||
avg(priority_fee) OVER (order by block_number Rows Between 30 preceding and current row) as "Block Tips MA (ETH)", | ||
avg(base_fee) OVER (order by block_number Rows Between 30 preceding and current row) as "Block Base Fees MA (ETH)", | ||
avg(legacy_count) OVER (order by block_number Rows Between 30 preceding and current row) as "Legacy MA # TX", | ||
avg(dynamicFee_count) OVER (order by block_number Rows Between 30 preceding and current row) as "Dynamic MA # TX" | ||
FROM block_fees | ||
ORDER BY block_number DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
WITH tx AS( | ||
SELECT | ||
-- date_trunc('hour', block_time) + date_part('minute', block_time)::int / 5 * interval '5 min' as minute, | ||
date_trunc('minute', block_time) as minute, | ||
block_number, | ||
t.hash, | ||
type, | ||
--gas_price as gas_price, | ||
t.gas_used as tx_gas_used, | ||
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, | ||
b.base_fee_per_gas as block_base_fee | ||
FROM ethereum.transactions t | ||
LEFT JOIN ethereum.blocks b ON block_number = number | ||
WHERE block_time > now() - INTERVAL '1 days' | ||
AND success | ||
), | ||
block_fees AS( | ||
SELECT | ||
block_number, | ||
minute, | ||
SUM(tx_gas_used*priority_fee_per_gas)/1e18 as priority_total, | ||
SUM(tx_gas_used*Block_base_fee)/1e18 as base_total | ||
FROM tx | ||
GROUP BY 1,2 | ||
), | ||
minute_fees AS( | ||
SELECT | ||
t.minute, | ||
AVG(block_base_fee) AS block_base_fee, | ||
AVG(priority_fee_per_gas/1e9) as avg_priority_fee, | ||
AVG(priority_total) as priority_total, | ||
AVG(base_total) as base_total, | ||
COUNT(hash) FILTER (WHERE type = 'Legacy') AS legacy_count, | ||
COUNT(hash) FILTER (WHERE type = 'DynamicFee') AS dynamicFee_count | ||
FROM tx t | ||
LEFT JOIN block_fees b ON t.minute=b.minute | ||
GROUP BY 1 | ||
) | ||
|
||
SELECT | ||
minute, | ||
block_base_fee/1e9 as "Base Fee (Gwei)", | ||
--AVG(block_base_fee/1e9) OVER (order by minute Rows Between 5 preceding and current row) as "Base Fee MA (Gwei)", | ||
avg_priority_fee as "Tip (Gwei)", | ||
--AVG(avg_priority_fee) OVER (order by minute Rows Between 5 preceding and current row) as "Tip MA(Gwei)", | ||
priority_total as "Block Tips (ETH)", | ||
base_total as "Block Base Fees (ETH)", | ||
legacy_count as "Legacy # TX", | ||
dynamicFee_count as "Dynamic # TX" | ||
--avg(priority_total) OVER (order by minute Rows Between 30 preceding and current row) as "Block Tips MA (ETH)", | ||
--avg(base_total) OVER (order by minute Rows Between 30 preceding and current row) as "Block Base Fees MA (ETH)", | ||
--avg(legacy_count) OVER (order by minute Rows Between 30 preceding and current row) as "Legacy MA # TX", | ||
--avg(dynamicFee_count) OVER (order by minute Rows Between 30 preceding and current row) as "Dynamic MA # TX" | ||
FROM minute_fees | ||
ORDER BY minute DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
WITH tx AS( | ||
SELECT | ||
date_trunc('hour', block_time) as hour, | ||
block_number, | ||
t.hash, | ||
type, | ||
--gas_price as gas_price, | ||
t.gas_used, | ||
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, | ||
b.base_fee_per_gas as block_base_fee | ||
FROM ethereum.transactions t | ||
LEFT JOIN ethereum.blocks b ON block_number = number | ||
WHERE block_time > now() - INTERVAL '1 weeks' | ||
AND success | ||
), | ||
block_fees AS( | ||
SELECT | ||
block_number, | ||
hour, | ||
SUM(gas_used*priority_fee_per_gas)/1e18 as priority_total, | ||
SUM(gas_used*Block_base_fee)/1e18 as base_total | ||
FROM tx | ||
GROUP BY 1,2 | ||
), | ||
hour_fees AS( | ||
SELECT | ||
t.hour, | ||
AVG(block_base_fee) AS block_base_fee, | ||
AVG(priority_fee_per_gas/1e9) as avg_priority_fee, | ||
AVG(priority_total) as priority_total, | ||
AVG(base_total) as base_total, | ||
COUNT(hash) FILTER (WHERE type = 'Legacy') AS legacy_count, | ||
COUNT(hash) FILTER (WHERE type = 'DynamicFee') AS dynamicFee_count | ||
FROM tx t | ||
LEFT JOIN block_fees b ON t.hour=b.hour | ||
GROUP BY 1 | ||
) | ||
|
||
SELECT | ||
hour, | ||
block_base_fee/1e9 as "Base Fee (Gwei)", | ||
--AVG(block_base_fee/1e9) OVER (order by hour Rows Between 5 preceding and current row) as "Base Fee MA (Gwei)", | ||
avg_priority_fee as "Tip (Gwei)", | ||
--AVG(avg_priority_fee) OVER (order by hour Rows Between 5 preceding and current row) as "Tip MA(Gwei)", | ||
priority_total as "Block Tips (ETH)", | ||
base_total as "Block Base Fees (ETH)", | ||
legacy_count as "Legacy # TX", | ||
dynamicFee_count as "Dynamic # TX" | ||
--avg(priority_total) OVER (order by hour Rows Between 30 preceding and current row) as "Block Tips MA (ETH)", | ||
--avg(base_total) OVER (order by hour Rows Between 30 preceding and current row) as "Block Base Fees MA (ETH)", | ||
--avg(legacy_count) OVER (order by hour Rows Between 30 preceding and current row) as "Legacy MA # TX", | ||
--avg(dynamicFee_count) OVER (order by hour Rows Between 30 preceding and current row) as "Dynamic MA # TX" | ||
FROM hour_fees | ||
ORDER BY hour DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
WITH uniswap_trades AS ( | ||
SELECT tx_hash, usd_amount | ||
FROM dex."trades" d | ||
WHERE project = 'Uniswap' AND version ='2' | ||
AND block_time >= (DATE_TRUNC('hour', CURRENT_TIMESTAMP) - '24 hours'::INTERVAL) | ||
), -- transaction hash in UNISWAP v2 | ||
|
||
dex_trade_type AS ( | ||
SELECT "to", | ||
CASE WHEN "to" in ('\x7a250d5630b4cf539739df2c5dacb4c659f2488d','\xf164fc0ec4e93095b804a4795bbe1e041497b92a','\xc9f8878ebba65ab04743f374f57fb652981e222c') then 'Uniswap' | ||
WHEN "to" in ('\x111111125434b319222cdbf8c261674adb56f3ae','\x1111111254fc78fdddb1ca73c8c15f91342af92e','\x11111112542d85b3ef69ae05771c2dccff4faa26') then '1inch' | ||
WHEN "to" in ('\xdef1c0ded9bec7f1a1670819833240f027b25eff','\x881d40237659c251811cec9c364ef91dc08d300c') then '0x' | ||
WHEN "to"='\xf90e98f3d8dce44632e5020abf2e122e0f99dfab' then 'Paraswap' | ||
WHEN "to"='\xa356867fdcea8e71aeaf87805808803806231fdc' then 'DODO V2' | ||
WHEN "to"='\x7c40c393dc0f283f318791d746d894ddd3693572' then 'Mooncats' | ||
WHEN "to" in ('\x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9','\x63a3f444e97d14e671e7ee323c4234c8095e3516','\x498c5431eb517101582988fbb36431ddaac8f4b1') then 'AAVE Flashloan' | ||
WHEN "to"='\xa013afbb9a92cef49e898c87c060e6660e050569' then 'Furucombo' | ||
ELSE NULL END AS label, | ||
SUBSTRING(t.input, 1, 4), -- get first 4 characters in the input | ||
s.signature, -- identfier? | ||
COUNT(*), -- count number of tos? | ||
MIN(block_time) as first_seen, | ||
MAX(t.tx_hash::text) as example_tx, -- 1 trace contains multiple tx, get max | ||
SUM(usd_amount) as amt | ||
FROM ethereum."traces" t | ||
JOIN uniswap_trades u on u.tx_hash = t.tx_hash -- join uniswap with the same tx hashes in ethereum | ||
LEFT JOIN ethereum."signatures" s on s.id = substring(t.input,1,4) | ||
WHERE | ||
trace_address::text = '{}' | ||
-- only top level call | ||
AND t.block_time >= (DATE_TRUNC('hour',CURRENT_TIMESTAMP) - '24 hours'::INTERVAL) | ||
GROUP BY 1,2,3,4 | ||
HAVING COUNT(*) >= 0 | ||
ORDER BY 5 desc, 8 desc) | ||
|
||
SELECT "to",label,"substring",signature,"count",first_seen,example_tx,"amt" | ||
FROM dex_trade_type dt | ||
WHERE dt.label = {{param}} | ||
-- on dune frontend, enter example, 'uniswap trader' | ||
|
||
|
||
|
||
--select * from ethereum."signatures" limit 10 | ||
|
||
-- look closer into this tx example | ||
-- https://bloxy.info/tx/0xbeca2c54c268e4616b3e44adcfc9df05f88380a561d8b4966343ede9c0add8ae | ||
|
||
|
||
--select substring(input,1,4) from ethereum."traces" where tx_hash = '\xffe0f7a47b877259b09c4465727c7d0d315020ae48e80845538f2c2fd95471c9' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- source: https://stackoverflow.com/a/48770535/1838257 | ||
|
||
--CREATE OR REPLACE VIEW dune_user_generated.gosuto_view_dependencies AS | ||
SELECT DISTINCT srcobj.oid AS src_oid, | ||
srcnsp.nspname AS src_schemaname, | ||
srcobj.relname AS src_objectname, | ||
tgtobj.oid AS dependent_viewoid, | ||
tgtnsp.nspname AS dependant_schemaname, | ||
tgtobj.relname AS dependant_objectname | ||
FROM pg_class srcobj | ||
JOIN pg_depend srcdep ON srcobj.oid = srcdep.refobjid | ||
JOIN pg_depend tgtdep ON srcdep.objid = tgtdep.objid | ||
JOIN pg_class tgtobj ON tgtdep.refobjid = tgtobj.oid AND srcobj.oid <> tgtobj.oid | ||
LEFT JOIN pg_namespace srcnsp ON srcobj.relnamespace = srcnsp.oid | ||
LEFT JOIN pg_namespace tgtnsp ON tgtobj.relnamespace = tgtnsp.oid | ||
WHERE tgtdep.deptype = 'i'::"char" AND tgtobj.relkind = 'v'::"char" | ||
AND src_objectname LIKE '%badgerdao%' | ||
-- filter like so: | ||
-- SELECT * FROM dune_user_generated.gosuto_view_dependencies | ||
-- WHERE src_objectname LIKE '%filter_word%' |