Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment Due query #5

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mevblocker/fees/.sqlfluff
Original file line number Diff line number Diff line change
@@ -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'
45 changes: 45 additions & 0 deletions mevblocker/fees/payment_due_4005800.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- 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(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)
AND blockNumber < (SELECT end_block FROM block_range)
GROUP BY 1, 2
)

SELECT
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 AS b
CROSS JOIN final_fee
Loading