-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from AcalaNetwork/migrate-dune-queries
migrate dune queries
- Loading branch information
Showing
50 changed files
with
1,539 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#copy and paste this file into a .env file to run scripts locally. 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= |
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,2 @@ | ||
|
||
.env |
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,6 @@ | ||
# Acala Dex Dune Dashboard | ||
|
||
Quries for [Acala Stats](https://dune.com/euphrates/acala-dex) dune dashboard | ||
|
||
## Commands | ||
pull latest queries:`python3 scripts/pull_from_dune.py` |
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,12 @@ | ||
query_ids: | ||
- 3751506 | ||
- 3769045 | ||
- 3799555 | ||
- 3799550 | ||
- 3799556 | ||
- 3782192 | ||
- 3799562 | ||
- 3799524 | ||
- 3799554 | ||
- 3799539 | ||
- 3799558 |
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,106 @@ | ||
-- part of a query repo | ||
-- query name: dex_liquidity_tx | ||
-- query link: https://dune.com/queries/3769045 | ||
|
||
|
||
WITH liquidity_tx_raw AS ( | ||
SELECT | ||
block_time, | ||
block_number, | ||
method, | ||
block_hash, | ||
extrinsic_id, | ||
extrinsic_hash, | ||
event_id, | ||
JSON_EXTRACT_SCALAR(data, '$[0]') AS address, | ||
JSON_EXTRACT(data, '$[1]') AS token0_json, | ||
CAST(JSON_EXTRACT(data, '$[2]') AS VARCHAR) AS amount0_varchar, | ||
JSON_EXTRACT(data, '$[3]') AS token1_json, | ||
CAST(JSON_EXTRACT(data, '$[4]') AS VARCHAR) AS amount1_varchar, | ||
CAST(JSON_EXTRACT(data, '$[5]') AS VARCHAR) AS share_diff_varchar | ||
FROM acala.events | ||
WHERE section = 'dex' | ||
AND (method = 'AddLiquidity' OR method = 'RemoveLiquidity') | ||
), | ||
|
||
liquidity_tx_extracted AS ( | ||
SELECT | ||
*, | ||
CASE | ||
WHEN JSON_EXTRACT_SCALAR(X.token0_json, '$.token') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"Token":"', | ||
JSON_EXTRACT_SCALAR(X.token0_json, '$.token'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token0_json, '$.liquidCrowdloan') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"LiquidCrowdloan":"', | ||
JSON_EXTRACT_SCALAR(X.token0_json, '$.liquidCrowdloan'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token0_json, '$.foreignAsset') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"ForeignAsset":"', | ||
JSON_EXTRACT_SCALAR(X.token0_json, '$.foreignAsset'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token0_json, '$.erc20') IS NOT NULL THEN '{"ForeignAsset":"14"}' | ||
END AS token0_varchar, | ||
|
||
CASE | ||
WHEN JSON_EXTRACT_SCALAR(X.token1_json, '$.token') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"Token":"', | ||
JSON_EXTRACT_SCALAR(X.token1_json, '$.token'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token1_json, '$.liquidCrowdloan') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"LiquidCrowdloan":"', | ||
JSON_EXTRACT_SCALAR(X.token1_json, '$.liquidCrowdloan'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token1_json, '$.foreignAsset') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"ForeignAsset":"', | ||
JSON_EXTRACT_SCALAR(X.token1_json, '$.foreignAsset'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token1_json, '$.erc20') IS NOT NULL THEN '{"ForeignAsset":"14"}' | ||
END AS token1_varchar | ||
FROM liquidity_tx_raw X | ||
), | ||
|
||
liquidity_tx_parsed AS ( | ||
SELECT | ||
*, | ||
B.symbol AS token0, | ||
B.decimals AS decimals0, | ||
C.symbol AS token1, | ||
C.decimals AS decimals1 | ||
FROM liquidity_tx_extracted A | ||
JOIN query_3670410 B ON A.token0_varchar = B.asset | ||
JOIN query_3670410 C ON A.token1_varchar = C.asset | ||
) | ||
|
||
SELECT | ||
D.block_time, | ||
D.method, | ||
D.address, | ||
D.token0, | ||
CAST(D.amount0_varchar AS DOUBLE) / POWER(10, D.decimals0) AS amount0, | ||
D.token1, | ||
CAST(D.amount1_varchar AS DOUBLE) / POWER(10, D.decimals1) AS amount1, | ||
D.block_number, | ||
D.extrinsic_hash as tx_hash | ||
FROM liquidity_tx_parsed D | ||
WHERE D.amount0_varchar NOT LIKE '0x%' | ||
AND D.amount1_varchar NOT LIKE '0x%' | ||
ORDER BY 1 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,135 @@ | ||
-- part of a query repo | ||
-- query name: dex_swaps | ||
-- query link: https://dune.com/queries/3751506 | ||
|
||
|
||
WITH dex_swap_raw AS ( | ||
SELECT | ||
block_time, | ||
block_number, | ||
block_hash, | ||
extrinsic_id, | ||
extrinsic_hash, | ||
event_id, | ||
JSON_EXTRACT_SCALAR(data, '$[0]') AS address, | ||
JSON_EXTRACT(data, '$[1][0]') AS token_in_json, | ||
JSON_ARRAY_GET(JSON_EXTRACT(data, '$[1]'), -1) AS token_out_json, | ||
JSON_VALUE(data, 'strict $[2][0]') AS amount_in_varchar, | ||
JSON_VALUE(data, 'strict $[2][last]') AS amount_out_varchar | ||
FROM acala.events | ||
WHERE section = 'dex' | ||
AND method = 'Swap' | ||
), | ||
|
||
dex_swap_raw_extracted AS ( | ||
SELECT | ||
*, | ||
CASE | ||
WHEN JSON_EXTRACT_SCALAR(X.token_in_json, '$.token') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"Token":"', | ||
JSON_EXTRACT_SCALAR(X.token_in_json, '$.token'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token_in_json, '$.liquidCrowdloan') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"LiquidCrowdloan":"', | ||
JSON_EXTRACT_SCALAR(X.token_in_json, '$.liquidCrowdloan'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token_in_json, '$.foreignAsset') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"ForeignAsset":"', | ||
JSON_EXTRACT_SCALAR(X.token_in_json, '$.foreignAsset'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token_in_json, '$.erc20') IS NOT NULL THEN '{"ForeignAsset":"14"}' | ||
END AS token_in_varchar, | ||
|
||
CASE | ||
WHEN JSON_EXTRACT_SCALAR(X.token_out_json, '$.token') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"Token":"', | ||
JSON_EXTRACT_SCALAR(X.token_out_json, '$.token'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token_out_json, '$.liquidCrowdloan') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"LiquidCrowdloan":"', | ||
JSON_EXTRACT_SCALAR(X.token_out_json, '$.liquidCrowdloan'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token_out_json, '$.foreignAsset') IS NOT NULL THEN ( | ||
CONCAT( | ||
'{"ForeignAsset":"', | ||
JSON_EXTRACT_SCALAR(X.token_out_json, '$.foreignAsset'), | ||
'"}' | ||
) | ||
) | ||
WHEN JSON_EXTRACT_SCALAR(X.token_out_json, '$.erc20') IS NOT NULL THEN '{"ForeignAsset":"14"}' | ||
END AS token_out_varchar | ||
FROM dex_swap_raw X | ||
), | ||
|
||
dex_swap_parsed AS ( | ||
SELECT | ||
*, | ||
CASE | ||
WHEN starts_with(amount_in_varchar, '0x') | ||
THEN varbinary_to_uint256(FROM_HEX(amount_in_varchar)) | ||
ELSE CAST(amount_in_varchar as uint256) | ||
END AS amount_in_uint256, | ||
CASE | ||
WHEN starts_with(amount_out_varchar, '0x') | ||
THEN varbinary_to_uint256(FROM_HEX(amount_out_varchar)) | ||
ELSE CAST(amount_out_varchar as uint256) | ||
END AS amount_out_uint256 , | ||
B.symbol AS token_in, | ||
B.decimals AS decimals_in, | ||
C.symbol AS token_out, | ||
C.decimals AS decimals_out | ||
FROM dex_swap_raw_extracted A | ||
JOIN query_3670410 B ON A.token_in_varchar = B.asset | ||
JOIN query_3670410 C ON A.token_out_varchar = C.asset | ||
), | ||
|
||
dex_swap_formatted AS ( | ||
SELECT | ||
D.block_time, | ||
D.address, | ||
D.amount_in_uint256 / POWER(10, D.decimals_in) AS amount_in, | ||
D.token_in, | ||
D.amount_out_uint256 / POWER(10, D.decimals_out) AS amount_out, | ||
D.token_out, | ||
D.block_number, | ||
D.extrinsic_hash as tx_hash, | ||
DATE_TRUNC('day', D.block_time) AS day | ||
FROM dex_swap_parsed D | ||
) | ||
|
||
|
||
SELECT | ||
E.block_time, | ||
E.address, | ||
E.token_in, | ||
E.amount_in, | ||
E.token_out, | ||
E.amount_out, | ||
CASE | ||
WHEN E.token_in IN ('AUSD', 'USDC') THEN E.amount_in | ||
WHEN E.token_in = 'DOT' THEN E.amount_in * P.price | ||
WHEN E.token_out IN ('AUSD', 'USDC') THEN E.amount_out | ||
WHEN E.token_out = 'DOT' THEN E.amount_out * P.price | ||
ELSE 0 | ||
END AS usd_value, | ||
E.block_number, | ||
E.tx_hash | ||
FROM dex_swap_formatted E | ||
LEFT JOIN prices.usd_daily P | ||
ON E.day = P.day AND P.symbol = 'DOT' | ||
ORDER BY 1 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,11 @@ | ||
-- part of a query repo | ||
-- query name: pol_tvl_ausd_intr | ||
-- query link: https://dune.com/queries/3799562 | ||
|
||
|
||
SELECT | ||
day_timestamp, | ||
token0_tvl AS aseed_tvl, | ||
token1_tvl AS intr_tvl | ||
FROM query_3782346 AS pool_tvl | ||
WHERE pool_name = 'AUSD/INTR' |
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,11 @@ | ||
-- part of a query repo | ||
-- query name: pool_tvl_aca_ausd | ||
-- query link: https://dune.com/queries/3799554 | ||
|
||
|
||
SELECT | ||
day_timestamp, | ||
token0_tvl AS aca_tvl, | ||
token1_tvl AS aseed_tvl | ||
FROM query_3782346 AS pool_tvl | ||
WHERE pool_name = 'ACA/AUSD' |
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,12 @@ | ||
-- part of a query repo | ||
-- query name: pool_tvl_aca_usdc | ||
-- query link: https://dune.com/queries/3799539 | ||
|
||
|
||
SELECT | ||
day_timestamp, | ||
token0_tvl AS aca_tvl, | ||
token1_tvl AS usdc_tvl | ||
-- usd_value AS usd_tvl | ||
FROM query_3782346 AS pool_tvl | ||
WHERE pool_name = 'ACA/USDC' |
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,11 @@ | ||
-- part of a query repo | ||
-- query name: pool_tvl_ausd_ibtc | ||
-- query link: https://dune.com/queries/3799558 | ||
|
||
|
||
SELECT | ||
day_timestamp, | ||
token0_tvl AS aseed_tvl, | ||
token1_tvl AS ibtc_tvl | ||
FROM query_3782346 AS pool_tvl | ||
WHERE pool_name = 'AUSD/IBTC' |
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,11 @@ | ||
-- part of a query repo | ||
-- query name: pool_tvl_ausd_lcdot | ||
-- query link: https://dune.com/queries/3799550 | ||
|
||
|
||
SELECT | ||
day_timestamp, | ||
token0_tvl AS aseed_tvl, | ||
token1_tvl AS lcdot_tvl | ||
FROM query_3782346 AS pool_tvl | ||
WHERE pool_name = 'AUSD/lcDOT' |
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,11 @@ | ||
-- part of a query repo | ||
-- query name: pool_tvl_ausd_ldot | ||
-- query link: https://dune.com/queries/3799555 | ||
|
||
|
||
SELECT | ||
day_timestamp, | ||
token0_tvl AS aseed_tvl, | ||
token1_tvl AS ldot_tvl | ||
FROM query_3782346 AS pool_tvl | ||
WHERE pool_name = 'AUSD/LDOT' |
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,11 @@ | ||
-- part of a query repo | ||
-- query name: pool_tvl_dot_lcdot | ||
-- query link: https://dune.com/queries/3799524 | ||
|
||
|
||
SELECT | ||
day_timestamp, | ||
token0_tvl AS dot_tvl, | ||
token1_tvl AS lcdot_tvl | ||
FROM query_3782346 AS pool_tvl | ||
WHERE pool_name = 'DOT/lcDOT' |
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,11 @@ | ||
-- part of a query repo | ||
-- query name: pool_tvl_dot_unq | ||
-- query link: https://dune.com/queries/3799556 | ||
|
||
|
||
SELECT | ||
day_timestamp, | ||
token0_tvl AS dot_tvl, | ||
token1_tvl AS unq_tvl | ||
FROM query_3782346 AS pool_tvl | ||
WHERE pool_name = 'DOT/UNQ' |
Oops, something went wrong.