Skip to content

Commit

Permalink
add queries
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhong5297 committed Jan 23, 2024
1 parent cc8eab4 commit 90a23ea
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 234 deletions.
11 changes: 11 additions & 0 deletions queries/12_months_dex_volume___7486.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- part of a query repo
-- query name: 12 Months DEX volume
-- query link: https://dune.com/queries/7486


SELECT
SUM(CAST(amount_usd AS DOUBLE)) / 1000000000 /* Convert to billion :D */ AS usd_volume_in_billion
FROM
dex."trades" AS t
WHERE
block_time >= NOW() - INTERVAL '12' month
11 changes: 11 additions & 0 deletions queries/30_days_dex_volume___8243.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- part of a query repo
-- query name: 30 days DEX volume
-- query link: https://dune.com/queries/8243


SELECT
SUM(CAST(amount_usd AS DOUBLE) / 1e9) AS usd_volume_in_billion
FROM
dex."trades" AS t
WHERE
block_time > NOW() - INTERVAL '30' day
43 changes: 43 additions & 0 deletions queries/aggregator_by_volume_📢___21689.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- part of a query repo
-- query name: Aggregator by volume 📢
-- query link: https://dune.com/queries/21689


WITH
seven_day_volume AS (
SELECT
project AS "Project",
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume
FROM
dex_aggregator.trades AS t
WHERE
block_time > CURRENT_TIMESTAMP - INTERVAL '7' day
GROUP BY
1
),
one_day_volume AS (
SELECT
project AS "Project",
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume
FROM
dex_aggregator.trades AS t
WHERE
block_time > CURRENT_TIMESTAMP - INTERVAL '1' day
GROUP BY
1
)
SELECT
ROW_NUMBER() OVER (
ORDER BY
SUM(seven.usd_volume) DESC NULLS FIRST
) AS "Rank",
seven."Project",
SUM(seven.usd_volume) AS "7 Days Volume",
SUM(one.usd_volume) AS "24 Hours Volume"
FROM
seven_day_volume AS seven
LEFT JOIN one_day_volume AS one ON seven."Project" = one."Project"
GROUP BY
2
ORDER BY
3 DESC NULLS FIRST
25 changes: 25 additions & 0 deletions queries/daily_dex_volume___4388.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- part of a query repo
-- query name: Daily DEX volume
-- query link: https://dune.com/queries/4388


/* Migration success :)
There are some cases such as unnest/sequence and array/json functions the migrator won't take care of for you
(but we have examples of in the docs linked above!)
If you're still running into issues, check out the doc examples https://dune.com/docs/reference/dune-v2/query-engine/
or reach out to us in the Dune discord in the #dune-sql channel.
*/
SELECT
project,
DATE_TRUNC('day', block_time),
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume
FROM
dex."trades" AS t
WHERE
block_time > DATE_TRUNC('day', NOW()) - INTERVAL '30' day
AND block_time < DATE_TRUNC('day', NOW())
GROUP BY
1,
2
19 changes: 19 additions & 0 deletions queries/dex_24_hours_volume___4234.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- part of a query repo
-- query name: DEX 24 hours volume
-- query link: https://dune.com/queries/4234


/* Migration success :)
There are some cases such as unnest/sequence and array/json functions the migrator won't take care of for you
(but we have examples of in the docs linked above!)
If you're still running into issues, check out the doc examples https://dune.com/docs/reference/dune-v2/query-engine/
or reach out to us in the Dune discord in the #dune-sql channel.
*/
SELECT
SUM(CAST(amount_usd AS DOUBLE)) / 1e9 AS billion_volume
FROM
dex."trades" AS t
WHERE
block_time > NOW() - INTERVAL '24' hour
13 changes: 13 additions & 0 deletions queries/dex_7_days_volume___4235.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- part of a query repo
-- query name: DEX 7 days volume
-- query link: https://dune.com/queries/4235


-- This query has been migrated to run on DuneSQL.
-- If you need to change back because you’re seeing issues, use the Query History view to restore the previous version.
-- If you notice a regression, please email [email protected].

SELECT
SUM(amount_usd)/1e9 AS billion_volume
FROM dex.trades t
WHERE block_time > now() - interval '7' day
45 changes: 45 additions & 0 deletions queries/dex_by_volume_🏦___4319.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
-- part of a query repo
-- query name: DEX by volume 🏦
-- query link: https://dune.com/queries/4319


WITH
seven_day_volume AS (
SELECT
project AS "Project",
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume
FROM
dex."trades" AS t
WHERE
block_time > NOW() - INTERVAL '7' day
GROUP BY
1
),
one_day_volume AS (
SELECT
project AS "Project",
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume
FROM
dex."trades" AS t
WHERE
block_time > NOW() - INTERVAL '1' day
GROUP BY
1
)
SELECT
ROW_NUMBER() OVER (
ORDER BY
SUM(seven.usd_volume) DESC NULLS FIRST
) AS "Rank",
seven."Project",
SUM(seven.usd_volume) AS "7 Days Volume",
SUM(one.usd_volume) AS "24 Hours Volume"
FROM
seven_day_volume AS seven
LEFT JOIN one_day_volume AS one ON seven."Project" = one."Project"
WHERE
NOT seven.usd_volume IS NULL
GROUP BY
2
ORDER BY
3 DESC NULLS FIRST
36 changes: 36 additions & 0 deletions queries/ethereum_share_of_dex_volume_🍰___21693.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- part of a query repo
-- query name: Ethereum share of DEX volume 🍰
-- query link: https://dune.com/queries/21693


/* Migration success :)
There are some cases such as unnest/sequence and array/json functions the migrator won't take care of for you
(but we have examples of in the docs linked below!)
If you're still running into issues, check out the doc examples https://dune.com/docs/reference/dune-v2/query-engine/
or reach out to us in the Dune discord in the #dune-sql channel.
*/
WITH
eth AS (
SELECT
SUM(CAST(amount_usd AS DOUBLE)) / 1e9 AS eth_bill_vol
FROM
dex."trades" AS t
WHERE
t.blockchain = 'ethereum'
AND block_time > NOW() - INTERVAL '7' day
),
all AS (
SELECT
SUM(CAST(amount_usd AS DOUBLE)) / 1e9 AS all_bill_vol
FROM
dex."trades" AS t
WHERE
block_time > NOW() - INTERVAL '7' day
)
SELECT
eth_bill_vol / all_bill_vol * 100 AS agg_share
FROM
eth,
all
16 changes: 16 additions & 0 deletions queries/monthly_dex_volume_by_project___1847.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- part of a query repo
-- query name: Monthly DEX Volume By Project
-- query link: https://dune.com/queries/1847


SELECT
project,
DATE_TRUNC('month', block_time),
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume
FROM
dex."trades" AS t
WHERE
block_time > CAST('2019-01-01' AS TIMESTAMP)
GROUP BY
1,
2
16 changes: 16 additions & 0 deletions queries/monthly_dex_volume_grouped_by____4424.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- part of a query repo
-- query name: Monthly DEX volume grouped by year
-- query link: https://dune.com/queries/4424


SELECT
date_format(block_time, '%Y') AS year,
date_format(block_time, '%m') AS month,
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume
FROM
dex."trades" AS t
WHERE
block_time >= CAST('2019-01-01' AS TIMESTAMP)
GROUP BY
1,
2
19 changes: 19 additions & 0 deletions queries/number_of_dex_traders___14138.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- part of a query repo
-- query name: Number of DEX traders
-- query link: https://dune.com/queries/14138


SELECT
COUNT(*)
FROM
(
SELECT
maker AS user
FROM
dex.trades
UNION
SELECT
taker AS address
FROM
dex.trades
) AS traders
Loading

0 comments on commit 90a23ea

Please sign in to comment.