From 31d897d4dfe446eb848698cd14d4d988b096222f Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Wed, 21 Aug 2024 16:00:33 +0200 Subject: [PATCH 1/2] Payment Due query --- mevblocker/fees/.sqlfluff | 3 ++ mevblocker/fees/payment_due_4005800.sql | 48 +++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 mevblocker/fees/payment_due_4005800.sql diff --git a/mevblocker/fees/.sqlfluff b/mevblocker/fees/.sqlfluff index 33374734..ea7d0555 100644 --- a/mevblocker/fees/.sqlfluff +++ b/mevblocker/fees/.sqlfluff @@ -1,3 +1,6 @@ [sqlfluff:templater:jinja:context] start='2024-08-01 12:00' end='2024-08-02 12:00' +fee_computation_start='2024-08-01 12:00' +fee_computation_end='2024-08-02 12:00' +billing_date='2024-08-01 12:00' diff --git a/mevblocker/fees/payment_due_4005800.sql b/mevblocker/fees/payment_due_4005800.sql new file mode 100644 index 00000000..38f55afd --- /dev/null +++ b/mevblocker/fees/payment_due_4005800.sql @@ -0,0 +1,48 @@ +-- Computes the weekly payment due for each connected builder +-- Parameters: +-- {{fee_computation_start}} - the start timestamp for the per block fee computation subquery +-- {{fee_computation_end}} - the end timestamp for the per block fee computation subquery +-- {{billing_date}} - the date at which the query is run + +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 '{{billing_date}}' - INTERVAL '7' DAY + AND time < TIMESTAMP '{{billing_date}}' +), + +final_fee AS ( + SELECT avg_block_fee_wei + FROM "query_4002039(start='{{fee_computation_start}}', end='{{fee_computation_end}}')" +), + +-- selects the count of blocks each builder won in the billing period +builder_blocks AS ( + SELECT + label, + billing_address, + COUNT(*) AS blocks_won + FROM ethereum.raw_0004 + INNER JOIN query_4001804 AS info + ON + (CONTAINS(info.extra_data, FROM_HEX(b.block.extraData)) OR CONTAINS(info.builder_addresses, FROM_HEX(b.block.miner))) --noqa: RF01 + AND blockNumber >= start_block + AND blockNumber < end_block + AND blockNumber >= (SELECT start_block FROM block_range) + AND blockNumber < (SELECT end_block FROM block_range) + GROUP BY 1, 2 +) + +-- rename columns for backwards compatibility +SELECT + label AS miner_label, + billing_address AS miner_biller_address, + blocks_won, + avg_block_fee_wei AS weekly_fee, + blocks_won * avg_block_fee_wei AS amount_due_wei, + blocks_won * avg_block_fee_wei / 1e18 AS amount_due_eth +FROM builder_blocks +CROSS JOIN final_fee From e99fb97ce894a33a4609c98c60fa8da1a8d12b30 Mon Sep 17 00:00:00 2001 From: Felix Leupold Date: Wed, 21 Aug 2024 16:06:17 +0200 Subject: [PATCH 2/2] undo renaming --- mevblocker/fees/payment_due_4005800.sql | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mevblocker/fees/payment_due_4005800.sql b/mevblocker/fees/payment_due_4005800.sql index 38f55afd..23d6bd0b 100644 --- a/mevblocker/fees/payment_due_4005800.sql +++ b/mevblocker/fees/payment_due_4005800.sql @@ -28,7 +28,7 @@ builder_blocks AS ( FROM ethereum.raw_0004 INNER JOIN query_4001804 AS info ON - (CONTAINS(info.extra_data, FROM_HEX(b.block.extraData)) OR CONTAINS(info.builder_addresses, FROM_HEX(b.block.miner))) --noqa: RF01 + (CONTAINS(info.extra_data, FROM_HEX(block.extraData)) OR CONTAINS(info.builder_addresses, FROM_HEX(block.miner))) --noqa: RF01 AND blockNumber >= start_block AND blockNumber < end_block AND blockNumber >= (SELECT start_block FROM block_range) @@ -36,13 +36,10 @@ builder_blocks AS ( GROUP BY 1, 2 ) --- rename columns for backwards compatibility SELECT - label AS miner_label, - billing_address AS miner_biller_address, - blocks_won, + b.*, avg_block_fee_wei AS weekly_fee, blocks_won * avg_block_fee_wei AS amount_due_wei, blocks_won * avg_block_fee_wei / 1e18 AS amount_due_eth -FROM builder_blocks +FROM builder_blocks AS b CROSS JOIN final_fee