-
Notifications
You must be signed in to change notification settings - Fork 42
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
c458a9b
commit 0c1c2ee
Showing
10 changed files
with
349 additions
and
22 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,7 +1,7 @@ | ||
#copy and paste this file into a .env file. You will also need to add the DUNE_API_KEY into the repo settings under "Secrets and Variables" | ||
|
||
#add a dune API key - you can create one under team settings (https://dune.com/settings/teams/manage/{team_name}/api). You must be on the premium plan. | ||
dune_api_key= | ||
DUNE_API_KEY= | ||
|
||
#generate a github token, giving the actions, workflows, and content permissions (read and write). Create this using this link (https://github.com/settings/personal-access-tokens/new). | ||
github_token= | ||
GITHUB_TOKEN= |
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,17 +1,41 @@ | ||
print('test action hello wrld') | ||
|
||
import os | ||
import yaml | ||
from dune_client.client import DuneClient | ||
from dotenv import load_dotenv | ||
import sys | ||
import codecs | ||
|
||
# Set the default encoding to UTF-8 | ||
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) | ||
|
||
dotenv_path = os.path.join(os.path.dirname(__file__), '..', '.env') | ||
load_dotenv(dotenv_path) | ||
|
||
dune = DuneClient.from_env() | ||
dune = DuneClient.from_env() | ||
|
||
# Read the queries.yml file | ||
with open('queries.yml', 'r') as file: | ||
with open('queries.yml', 'r', encoding='utf-8') as file: | ||
data = yaml.safe_load(file) | ||
|
||
# Extract the query_ids from the data | ||
query_ids = [id for id in data['query_ids']] | ||
|
||
for id in query_ids: | ||
query = dune.get_query(id) | ||
print(query) | ||
print('updating query {}, {}'.format(query.base.query_id, query.base.name)) | ||
|
||
# Check if file exists | ||
file_path = os.path.join(os.path.dirname(__file__), '..', 'queries', f'query_{query.base.query_id}.sql') | ||
if os.path.exists(file_path): | ||
# Update existing file | ||
with open(file_path, 'r+', encoding='utf-8') as file: | ||
content = file.read() | ||
file.seek(0, 0) | ||
file.write(f'-- {query.base.name}\n-- https://dune.com/queries/{query.base.query_id}\n\n\n{query.sql}') | ||
else: | ||
# Create new file and directories if they don't exist | ||
os.makedirs(os.path.dirname(file_path), exist_ok=True) | ||
with open(file_path, 'w', encoding='utf-8') as file: | ||
file.write(f'-- {query.base.name}\n-- https://dune.com/queries/{query.base.query_id}\n\n\n{query.sql}') | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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,85 @@ | ||
-- DEX by volume 🏦 | ||
-- https://dune.com/queries/3237721 | ||
|
||
|
||
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 | ||
-- DEX by volume 🏦 | ||
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 |
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,27 @@ | ||
-- Weekly DEX volume by chain | ||
-- https://dune.com/queries/3237723 | ||
|
||
|
||
SELECT | ||
blockchain, | ||
DATE_TRUNC('week', block_time), | ||
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume | ||
FROM | ||
dex."trades" AS t /* AND block_time < date_trunc('week', Now()) -- Add this line to see stats from current week */ | ||
WHERE | ||
block_time > NOW() - INTERVAL '365' day | ||
GROUP BY | ||
1, | ||
2 | ||
-- Weekly DEX volume by chain | ||
SELECT | ||
blockchain, | ||
DATE_TRUNC('week', block_time), | ||
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume | ||
FROM | ||
dex."trades" AS t /* AND block_time < date_trunc('week', Now()) -- Add this line to see stats from current week */ | ||
WHERE | ||
block_time > NOW() - INTERVAL '365' day | ||
GROUP BY | ||
1, | ||
2 |
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,81 @@ | ||
-- Aggregator by volume 📢 | ||
-- https://dune.com/queries/3237726 | ||
|
||
|
||
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 | ||
-- Aggregator by volume 📢 | ||
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 |
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,27 @@ | ||
-- Weekly DEX volume | ||
-- https://dune.com/queries/3237738 | ||
|
||
|
||
SELECT | ||
project, | ||
DATE_TRUNC('week', block_time), | ||
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume | ||
FROM | ||
dex."trades" AS t /* AND block_time < date_trunc('week', Now()) -- Add this line to see stats from current week */ | ||
WHERE | ||
block_time > NOW() - INTERVAL '365' day | ||
GROUP BY | ||
1, | ||
2 | ||
-- Weekly DEX volume | ||
SELECT | ||
project, | ||
DATE_TRUNC('week', block_time), | ||
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume | ||
FROM | ||
dex."trades" AS t /* AND block_time < date_trunc('week', Now()) -- Add this line to see stats from current week */ | ||
WHERE | ||
block_time > NOW() - INTERVAL '365' day | ||
GROUP BY | ||
1, | ||
2 |
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,27 @@ | ||
-- Weekly DEX Aggregator volume | ||
-- https://dune.com/queries/3237742 | ||
|
||
|
||
SELECT | ||
project, | ||
DATE_TRUNC('week', block_time), | ||
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume | ||
FROM | ||
dex_aggregator.trades AS t /* AND block_time < date_trunc('week', Now()) -- Add this line to see stats from current week */ | ||
WHERE | ||
block_time > NOW() - INTERVAL '365' day | ||
GROUP BY | ||
1, | ||
2 | ||
-- Weekly DEX Aggregator volume | ||
SELECT | ||
project, | ||
DATE_TRUNC('week', block_time), | ||
SUM(CAST(amount_usd AS DOUBLE)) AS usd_volume | ||
FROM | ||
dex_aggregator.trades AS t /* AND block_time < date_trunc('week', Now()) -- Add this line to see stats from current week */ | ||
WHERE | ||
block_time > NOW() - INTERVAL '365' day | ||
GROUP BY | ||
1, | ||
2 |
Oops, something went wrong.