generated from duneanalytics/DuneQueryRepo
-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
32d045b
commit 18029e6
Showing
8 changed files
with
212 additions
and
11 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,4 +1,8 @@ | ||
query_ids: | ||
- 3405541 | ||
- 3408002 | ||
- 3410544 | ||
- 3410549 | ||
- 3410550 | ||
- 3405947 | ||
- 3405929 |
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,23 @@ | ||
-- part of a query repo | ||
-- query name: Arbitrum Grants | ||
-- query link: https://dune.com/queries/3408002 | ||
|
||
|
||
SELECT | ||
grant_source | ||
, grant_blockchain | ||
, DATE_PARSE(gc.grant_date, '%m/%d/%Y') as grant_date | ||
, grant_name | ||
, grant_round | ||
, p.symbol as grant_token | ||
, sum(grant_amount) as grant_amount | ||
, sum(grant_amount*p.price) as grant_amount_usd | ||
, count(distinct grantee) as grantees | ||
, approx_percentile(grant_amount*p.price, 0.5) as median_grant_amount_usd | ||
FROM dune.cryptodatabytes.dataset_evm_grants gc | ||
LEFT JOIN prices.usd p ON p.blockchain = gc.grant_blockchain | ||
and p.contract_address = gc.grant_token_address | ||
and p.minute = DATE_PARSE(gc.grant_date, '%m/%d/%Y') | ||
WHERE grant_blockchain = 'arbitrum' | ||
GROUP BY 1, 2, 3, 4, 5, 6 | ||
ORDER BY 3 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
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,23 @@ | ||
-- part of a query repo | ||
-- query name: Optimism Grants | ||
-- query link: https://dune.com/queries/3410544 | ||
|
||
|
||
SELECT | ||
grant_source | ||
, grant_blockchain | ||
, DATE_PARSE(gc.grant_date, '%m/%d/%Y') as grant_date | ||
, grant_name | ||
, grant_round | ||
, p.symbol as grant_token | ||
, sum(grant_amount) as grant_amount | ||
, sum(grant_amount*p.price) as grant_amount_usd | ||
, count(distinct grantee) as grantees | ||
, approx_percentile(grant_amount*p.price, 0.5) as median_grant_amount_usd | ||
FROM dune.cryptodatabytes.dataset_evm_grants gc | ||
LEFT JOIN prices.usd p ON p.blockchain = gc.grant_blockchain | ||
and p.contract_address = gc.grant_token_address | ||
and p.minute = DATE_PARSE(gc.grant_date, '%m/%d/%Y') | ||
WHERE grant_blockchain = 'optimism' | ||
GROUP BY 1, 2, 3, 4, 5, 6 | ||
ORDER BY 3 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,47 @@ | ||
-- part of a query repo | ||
-- query name: Optimism Grants Charts | ||
-- query link: https://dune.com/queries/3410550 | ||
|
||
|
||
with | ||
grant_contracts as ( | ||
SELECT | ||
c.address | ||
, c.namespace | ||
, c.name | ||
, g.* | ||
, row_number() over (partition by c.address order by created_at desc) as latest | ||
FROM dune.cryptodatabytes.dataset_evm_grants g | ||
LEFT JOIN evms.contracts c ON g.grant_blockchain = c.blockchain and contains(split(g.dune_namespaces,','),c.namespace) | ||
) | ||
|
||
, ordered_traces as ( | ||
SELECT | ||
gc.grantee | ||
, gc.grant_blockchain | ||
, tr.tx_hash | ||
, tr.gas_used | ||
, tr.trace_address | ||
, tr.block_time | ||
, tx."from" as tx_from | ||
, tx.gas_price | ||
--we only want to keep the highest order trace call by a grantee contract. We do want to keep potential multi-calls so we use rank instead of row_number(). | ||
, rank() over (partition by gc.grantee, tr.tx_hash order by cardinality(trace_address) asc) as trace_order | ||
FROM optimism.traces tr | ||
JOIN grant_contracts gc ON tr.to = gc.address | ||
JOIN optimism.transactions tx ON tx.hash = tr.tx_hash | ||
WHERE tr.block_time >= timestamp '2023-12-01 00:00:00' | ||
AND tx.block_time >= timestamp '2023-12-01 00:00:00' | ||
AND gc.latest = 1 | ||
) | ||
|
||
SELECT | ||
date_trunc('week',block_time) as week | ||
, grantee | ||
, approx_distinct(tx_hash) as txs | ||
, approx_distinct(tx_from) as users | ||
, sum(gas_used*gas_price/1e18) as gas_fees_eth | ||
FROM ordered_traces | ||
WHERE trace_order = 1 | ||
GROUP BY 1,2 | ||
ORDER BY week DESC, txs 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,93 @@ | ||
-- part of a query repo | ||
-- query name: Optimism Grants Summary | ||
-- query link: https://dune.com/queries/3410549 | ||
|
||
|
||
with | ||
grant_contracts as ( | ||
SELECT | ||
c.address | ||
, c.namespace | ||
, c.name | ||
, g.* | ||
, row_number() over (partition by c.address order by created_at desc) as latest | ||
FROM dune.cryptodatabytes.dataset_evm_grants g | ||
LEFT JOIN evms.contracts c ON g.grant_blockchain = c.blockchain and contains(split(g.dune_namespaces,','),c.namespace) | ||
WHERE g.grant_blockchain = 'optimism' | ||
) | ||
|
||
, ordered_traces as ( | ||
SELECT | ||
gc.grantee | ||
, gc.grant_blockchain | ||
, tr.tx_hash | ||
, tr.gas_used | ||
, tr.trace_address | ||
, tr.block_time | ||
, tx."from" as tx_from | ||
, tx.gas_price | ||
--we only want to keep the highest order trace call by a grantee contract. We do want to keep potential multi-calls so we use rank instead of row_number(). | ||
, rank() over (partition by gc.grantee, tr.tx_hash order by cardinality(trace_address) asc) as trace_order | ||
FROM optimism.traces tr | ||
JOIN grant_contracts gc ON tr.to = gc.address | ||
JOIN optimism.transactions tx ON tx.hash = tr.tx_hash | ||
WHERE tr.block_time >= now() - interval '30' day | ||
AND tx.block_time >= now() - interval '30' day | ||
AND gc.latest = 1 | ||
) | ||
|
||
, blockchain_summary as ( | ||
SELECT | ||
blockchain as blockchain | ||
, approx_distinct(tx.hash) as txs_30d | ||
, approx_distinct(tx."from") as users_30d | ||
, sum(tx.gas_used*tx.gas_price/1e18) as gas_fees_eth_30d | ||
FROM evms.transactions tx | ||
WHERE tx.block_time >= now() - interval '30' day | ||
AND blockchain IN ('optimism') --add all optimism chains later | ||
GROUP BY 1 | ||
) | ||
|
||
, quality_users as ( | ||
with base as ( | ||
SELECT | ||
gc.grantee | ||
, tx."from" as user | ||
, count(distinct tx.hash) as txs | ||
FROM grant_contracts gc | ||
JOIN optimism.traces tr ON tr.to = gc.address AND gc.grant_blockchain = 'optimism' | ||
JOIN optimism.transactions tx ON tx.hash = tr.tx_hash AND tx.block_time = tr.block_time | ||
WHERE latest = 1 | ||
AND tr.block_time >= now() - interval '30' day | ||
AND tx.block_time >= now() - interval '30' day | ||
GROUP BY 1,2 | ||
HAVING count(distinct tx.hash) >= 5 | ||
) | ||
|
||
SELECT | ||
grantee | ||
, count(*) as q_users_30d | ||
FROM base | ||
group by 1 | ||
) | ||
|
||
SELECT | ||
case when gc.dashboard_link is null then substring(gc.grantee,1,20) | ||
else get_href(gc.dashboard_link, '📊 ' || substring(gc.grantee,1,20)) | ||
end as grantee | ||
, gc.grant_amount*p.price as grant_amount_usd | ||
, COALESCE(approx_distinct(tr.tx_hash),0) as txs_30d | ||
, COALESCE(approx_distinct(tr.tx_from),0) as users_30d | ||
, COALESCE(qu.q_users_30d,0) as q_users_30d | ||
, COALESCE(sum(tr.gas_used*tr.gas_price/1e18),0) as gas_fees_eth_30d | ||
, COALESCE(sum(cast(tr.gas_used*tr.gas_price/1e18 as double)/cast(blk.gas_fees_eth_30d as double)),0) as percent_total_fees_30d | ||
, array_agg(distinct grant_name || ' (#' || cast(grant_round as varchar) || ')') as grants | ||
FROM dune.cryptodatabytes.dataset_evm_grants gc | ||
LEFT JOIN ordered_traces tr ON tr.grantee = gc.grantee AND tr.trace_order = 1 | ||
LEFT JOIN quality_users qu ON qu.grantee = gc.grantee | ||
LEFT JOIN prices.usd p ON p.blockchain = 'optimism' | ||
and p.contract_address = gc.grant_token_address | ||
and p.minute = DATE_PARSE(gc.grant_date, '%m/%d/%Y') | ||
LEFT JOIN blockchain_summary blk ON blk.blockchain = gc.grant_blockchain --potential issues if protocol is deployed on multiple chains. How to handle? | ||
GROUP BY 1,2,qu.q_users_30d | ||
order by grant_amount_usd desc |