From 438bd1b04d97835b784a67fc0d42c239aea52251 Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Wed, 21 Aug 2024 12:52:13 +0200 Subject: [PATCH 1/3] Monthly fee query --- mevblocker/fees/fee_4001804.sql | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 mevblocker/fees/fee_4001804.sql diff --git a/mevblocker/fees/fee_4001804.sql b/mevblocker/fees/fee_4001804.sql new file mode 100644 index 00000000..292a32d8 --- /dev/null +++ b/mevblocker/fees/fee_4001804.sql @@ -0,0 +1,64 @@ +-- Computes the monthly per block fee that MEVBlocker subscribed builders need to pay for every block they land. +-- Parameters: +-- {{start}} - the timestamp for which the analysis should start (inclusively) +-- {{end}} - the timestamp for which the analysis should end (exclusively) + +WITH block_range AS ( + SELECT + MIN(number) AS start_block, + MAX(number) + 1 AS end_block -- range is exclusive + FROM ethereum.blocks + WHERE + time >= TIMESTAMP '{{start}}' + AND time < TIMESTAMP '{{end}}' +), + +builders_extra_data AS ( + SELECT + start_block, + end_block, + ed.extra_data_item + FROM query_4001804 + CROSS JOIN UNNEST(extra_data) AS ed (extra_data_item) +), + +builder_addresses AS ( + SELECT + start_block, + end_block, + t.builder_address + FROM query_4001804 + CROSS JOIN UNNEST(builder_addresses) AS t (builder_address) +), + +-- select number of blocks from subscribed builders +blocks AS ( + SELECT COUNT(*) AS cnt_blocks + FROM ethereum.raw_0004 + WHERE + ( + FROM_HEX(block.extraData) IN (SELECT extra_data_item FROM builders_extra_data WHERE blockNumber >= start_block AND blockNumber < end_block) + OR FROM_HEX(block.miner) IN (SELECT builder_address FROM builder_addresses WHERE blockNumber >= start_block AND blockNumber < end_block) + ) + AND blockNumber >= (SELECT start_block FROM block_range) + AND blockNumber < (SELECT end_block FROM block_range) +), + +-- select total fee +fee AS ( + SELECT + SUM(user_tip_wei) AS total_user_tip_wei, + SUM(backrun_value_wei) AS total_backrun_value_wei, + SUM(backrun_tip_wei) AS total_backrun_tip_wei, + SUM(block_fee_wei) AS total_fee_wei + FROM "query_3999838(start='{{start}}', end='{{end}}')" +) + +-- compute average fee per block +SELECT + f.*, + b.cnt_blocks AS total_blocks, + (f.total_fee_wei / b.cnt_blocks) AS avg_block_fee_wei, + (f.total_fee_wei / b.cnt_blocks / 1e18) AS avg_block_fee +FROM fee AS f +CROSS JOIN blocks AS b From c6290e78a50396bdecfc568a5b7cf8a05de281b9 Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Wed, 21 Aug 2024 12:58:06 +0200 Subject: [PATCH 2/3] lint --- mevblocker/fees/fee_4001804.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mevblocker/fees/fee_4001804.sql b/mevblocker/fees/fee_4001804.sql index 292a32d8..8865bed9 100644 --- a/mevblocker/fees/fee_4001804.sql +++ b/mevblocker/fees/fee_4001804.sql @@ -34,14 +34,14 @@ builder_addresses AS ( -- select number of blocks from subscribed builders blocks AS ( SELECT COUNT(*) AS cnt_blocks - FROM ethereum.raw_0004 + FROM ethereum.raw_0004 AS b WHERE ( - FROM_HEX(block.extraData) IN (SELECT extra_data_item FROM builders_extra_data WHERE blockNumber >= start_block AND blockNumber < end_block) - OR FROM_HEX(block.miner) IN (SELECT builder_address FROM builder_addresses WHERE blockNumber >= start_block AND blockNumber < end_block) + FROM_HEX(b.block.extraData) IN (SELECT extra_data_item FROM builders_extra_data WHERE blockNumber >= start_block AND blockNumber < end_block) --noqa: RF01 + OR FROM_HEX(b.block.miner) IN (SELECT builder_address FROM builder_addresses WHERE blockNumber >= start_block AND blockNumber < end_block) --noqa: RF01 ) - AND blockNumber >= (SELECT start_block FROM block_range) - AND blockNumber < (SELECT end_block FROM block_range) + AND b.blockNumber >= (SELECT start_block FROM block_range) + AND b.blockNumber < (SELECT end_block FROM block_range) ), -- select total fee From fce0673513cc00ed1c9b9885d2f379ce57c6ab3f Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Wed, 21 Aug 2024 12:59:53 +0200 Subject: [PATCH 3/3] rename --- mevblocker/fees/{fee_4001804.sql => fee_4002039.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename mevblocker/fees/{fee_4001804.sql => fee_4002039.sql} (100%) diff --git a/mevblocker/fees/fee_4001804.sql b/mevblocker/fees/fee_4002039.sql similarity index 100% rename from mevblocker/fees/fee_4001804.sql rename to mevblocker/fees/fee_4002039.sql