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

[Impact Metric Submission]: Optimism Onchain 6 Months Metrics #46

Open
BenraouaneSoufiane opened this issue Jun 8, 2024 · 0 comments
Open
Assignees
Labels
c:community Datasets and notebook templates

Comments

@BenraouaneSoufiane
Copy link

BenraouaneSoufiane commented Jun 8, 2024

Optimism Onchain 6 Months Metrics

Tags

  • OP
  • OPTIMISTIC
  • OPTIMISM

Brief description

This metric calculated using the superchain subproject on the opensource-observer directory/repository (optimism_traces table). I classified records by month since project inception, then I sum the records of last 6 months using sum function

SQL code block

WITH traces AS (SELECT *,
FROM `opensource-observer.superchain.optimism_traces`
),
txs_or_users_6_months AS (
SELECT  COUNT(from_address) AS txs_or_users_6_months,
FROM traces
WHERE DATE(TIMESTAMP_TRUNC(block_timestamp, MONTH))  >= DATE_ADD(CURRENT_DATE(), INTERVAL -6 MONTH) 
),
new_txs_or_users_6_months AS (
SELECT COUNT(DISTINCT from_address) AS new_txs_or_users_6_months,
FROM traces
WHERE DATE(TIMESTAMP_TRUNC(block_timestamp, MONTH)) >= DATE_ADD(CURRENT_DATE(), INTERVAL -6 MONTH)
),
user_base_per_month AS (SELECT DATE (TIMESTAMP_TRUNC(block_timestamp, MONTH)) AS months
  ,from_address,COUNT(from_address) AS number_of_txs
FROM traces
GROUP BY months, from_address ORDER BY months ASC),
less_active_users_6_months AS (

SELECT COUNT(user_base_per_month.from_address) AS less_active_users_6_months
FROM user_base_per_month
WHERE user_base_per_month.number_of_txs < 10 AND user_base_per_month.months >= DATE_ADD(CURRENT_DATE(), INTERVAL -6 MONTH) ),
more_active_users_6_months AS (
SELECT COUNT(user_base_per_month.number_of_txs) AS more_active_users_6_months
FROM user_base_per_month
WHERE user_base_per_month.number_of_txs >= 10  AND user_base_per_month.months >= DATE_ADD(CURRENT_DATE(), INTERVAL -6 MONTH) 
),
high_frequency_users_6_months AS (
SELECT COUNT(user_base_per_month.number_of_txs) AS high_frequency_users_6_months
FROM user_base_per_month
WHERE user_base_per_month.number_of_txs >= 1000 AND user_base_per_month.months >= DATE_ADD(CURRENT_DATE(), INTERVAL -6 MONTH) 
),
blocks_6_months AS (
SELECT COUNT(DISTINCT block_number) AS blocks_6_months,
FROM traces
WHERE DATE(TIMESTAMP_TRUNC(block_timestamp, MONTH)) >= DATE_ADD(CURRENT_DATE(), INTERVAL -6 MONTH)

),
gas_6_months AS (
SELECT SUM(gas) AS gas_6_months,
FROM traces
WHERE DATE(TIMESTAMP_TRUNC(block_timestamp, MONTH)) >= DATE_ADD(CURRENT_DATE(), INTERVAL -6 MONTH)
),
gas_used_6_months AS (
SELECT SUM(gas_used) AS gas_used_6_months,
FROM traces
WHERE DATE(TIMESTAMP_TRUNC(block_timestamp, MONTH)) >= DATE_ADD(CURRENT_DATE(), INTERVAL -6 MONTH)
),
amount_6_months AS (
SELECT SUM(value) AS amount_6_months,
FROM traces
WHERE DATE(TIMESTAMP_TRUNC(block_timestamp, MONTH)) >= DATE_ADD(CURRENT_DATE(), INTERVAL -6 MONTH)
)
SELECT a.txs_or_users_6_months, b.new_txs_or_users_6_months, c.less_active_users_6_months, d.more_active_users_6_months, e.high_frequency_users_6_months, f.blocks_6_months, g.gas_6_months, h.gas_used_6_months, i.amount_6_months
FROM txs_or_users_6_months a, new_txs_or_users_6_months b, less_active_users_6_months c, more_active_users_6_months d, high_frequency_users_6_months e, blocks_6_months f, gas_6_months g, gas_used_6_months h, amount_6_months i


@BenraouaneSoufiane BenraouaneSoufiane added the c:community Datasets and notebook templates label Jun 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:community Datasets and notebook templates
Projects
None yet
Development

No branches or pull requests

2 participants