Skip to content

Commit

Permalink
added claim queries (#12)
Browse files Browse the repository at this point in the history
* added claim queries

* added new queries
  • Loading branch information
shunjizhan authored Nov 26, 2024
1 parent a3b9799 commit 4fd2aa6
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 23 deletions.
8 changes: 5 additions & 3 deletions dune-euphrates/queries.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
query_ids:
- 3988562
- 3988572
- 4333164
- 3393781
- 3397059
- 3397026
- 4333079
- 3999276
- 3393781
- 3397026
- 3988562
12 changes: 6 additions & 6 deletions dune-euphrates/queries/daily_usd_flow___3999276.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-- part of a query repo
-- query name: daily_usd_flow
-- query name: usd_flow
-- query link: https://dune.com/queries/3999276


WITH daily_token_flow AS (
WITH weekly_token_flow AS (
SELECT
DATE_TRUNC('day', "timestamp") AS day,
DATE_TRUNC('week', "timestamp") AS day,
pool_id,
pool_name,
-- SUM(CASE WHEN type = 'stake' THEN token_amount_ui ELSE token_amount_ui * -1 END) AS token_amount,
Expand All @@ -16,11 +16,11 @@ WITH daily_token_flow AS (
ORDER BY 1, 2
),

daily_usd_flow AS (
weekly_usd_flow AS (
SELECT
*,
dot_price.price * A.dot_amount_ui + jitosol_price.price * A.jitosol_amount_ui as "total_usd"
FROM daily_token_flow A
FROM weekly_token_flow A
LEFT JOIN query_3989007 as dot_price
ON A.day = dot_price.day
AND dot_price.symbol = 'DOT'
Expand All @@ -31,5 +31,5 @@ daily_usd_flow AS (
)

SELECT *
FROM daily_usd_flow
FROM weekly_usd_floww
FROM daily_usd_flow
13 changes: 13 additions & 0 deletions dune-euphrates/queries/euphrates_claims_total___4333164.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- part of a query repo
-- query name: euphrates_claims_total
-- query link: https://dune.com/queries/4333164


SELECT
DATE_TRUNC('week', timestamp) AS day,
SUM(amount_ui) as aca_amount,
SUM(SUM(amount_ui)) OVER (ORDER BY DATE_TRUNC('week', timestamp)) as cumulative_aca
FROM query_4333079 /* euphrates claims v3 */
WHERE reward_type = 0x0000000000000000000100000000000000000000
GROUP BY 1
ORDER BY 1
21 changes: 21 additions & 0 deletions dune-euphrates/queries/euphrates_claims_v3___4333079.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- part of a query repo
-- query name: euphrates_claims_v3
-- query link: https://dune.com/queries/4333079


SELECT
FROM_ISO8601_TIMESTAMP("timestamp") AS "timestamp",
block_number,
pool_id,
amount,
amount_ui,
reward_type,
CASE
WHEN reward_type = 0x0000000000000000000100000000000000000000 THEN 'aca'
WHEN reward_type = 0x892ddd9387dbdecedaef878bd7acf8603109227f THEN 'tai'
ELSE '???'
END AS reward,
recipient,
tx_hash
FROM dune.euphrates.dataset_euphrates_claims_v3
ORDER BY 1 DESC
14 changes: 11 additions & 3 deletions dune-euphrates/queries/latest_euphrates_stats___3397059.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ latest_tx_stats AS (
FROM query_3397026 -- users and transactions
ORDER BY 1 DESC
LIMIT 1
),

latest_claim_stats AS (
SELECT cumulative_aca
FROM query_4333164
ORDER BY 1 DESC
LIMIT 1
)

SELECT *
FROM latest_pool_stats A
CROSS JOIN latest_cumulative_stats B
CROSS JOIN latest_tx_stats C
FROM latest_pool_stats
CROSS JOIN latest_cumulative_stats
CROSS JOIN latest_tx_stats
CROSS JOIN latest_claim_stats
36 changes: 25 additions & 11 deletions dune-euphrates/queries/users_and_transactions___3397026.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,44 @@
-- query link: https://dune.com/queries/3397026


WITH daily_stats AS (
WITH weekly_stats AS (
SELECT
DATE_TRUNC('day', "timestamp") as day,
COUNT(*) AS daily_tx_count,
COUNT(DISTINCT "recipient") AS daily_users
FROM query_3988562 /* euphrates tx v2 */
DATE_TRUNC('week', "timestamp") as day,
COUNT(*) AS weekly_tx_count,
COUNT(DISTINCT "recipient") AS weekly_users
FROM (
SELECT "timestamp", "recipient" FROM query_3988562 /* euphrates tx v3 */
UNION ALL
SELECT "timestamp", "recipient" FROM query_4333079 /* euphrates claims v3 */
)
GROUP BY 1
),

cumulative_stats AS (
SELECT
day,
SUM(daily_tx_count) OVER (ORDER BY day) AS cumulative_tx_count,
SUM(daily_users) OVER (ORDER BY day) AS cumulative_users
FROM daily_stats
SUM(weekly_tx_count) OVER (ORDER BY day) AS cumulative_tx_count,
SUM(weekly_users) OVER (ORDER BY day) AS cumulative_users,
(
SELECT COUNT(DISTINCT recipient)
FROM (
SELECT "recipient", "timestamp" FROM query_3988562 /* euphrates tx v3 */
UNION ALL
SELECT "recipient", "timestamp" FROM query_4333079 /* euphrates claims v3 */
) all_tx
WHERE "timestamp" <= day
) AS cumulative_distinct_users
FROM weekly_stats
)

SELECT
ds.day,
ds.daily_tx_count,
ds.weekly_tx_count,
cs.cumulative_tx_count,
ds.daily_users,
ds.weekly_users,
cs.cumulative_users
FROM
daily_stats ds
weekly_stats ds
JOIN
cumulative_stats cs ON ds.day = cs.day
ORDER BY
Expand Down

0 comments on commit 4fd2aa6

Please sign in to comment.