Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 180d dex bot volume by day #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions queries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ query_ids:
- 4424
- 21689
- 4234
- 2687239
80 changes: 80 additions & 0 deletions queries/daily_dex_bot_volume__2687239.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
WITH
botActivityByDay AS (
SELECT
DATE_TRUNC ('day', block_time) AS block_date, -- DATE_TRUNC ('{{Granularity}}', block_time) AS block_date,
bot,
SUM(amount_usd) AS volumeUSD,
SUM(fee_usd) AS botRevenueUSD,
COUNT(DISTINCT (user)) AS numberOfUsers,
COUNT(DISTINCT (tx_hash)) AS numberOfTrades
FROM
dune.unibot.result_dex_trading_bot_trades
WHERE
isLastTradeInTransaction = true
-- AND blockchain IN (
-- SELECT
-- blockchain
-- FROM
-- UNNEST (SPLIT ('{{Blockchain}}', ',')) as b (blockchain)
-- )
GROUP BY
bot,
DATE_TRUNC ('day', block_time) -- DATE_TRUNC ('{{Granularity}}', block_time)
),
defCafeActivityByDay AS (
SELECT
DATE_TRUNC ('day', block_date) AS block_date, -- DATE_TRUNC ('{{Granularity}}', block_date) AS block_date,
'0xDefCafe' AS bot,
SUM(totalVolumeUSD) AS volumeUSD,
SUM(totalFeesUSD) AS botRevenueUSD,
MIN(numberOfUsers) AS numberOfUsers,
SUM(numberOfTrades) AS numberOfTrades
FROM
query_3040168 -- 0xDefCafe only has aggregated data
-- WHERE
-- blockchain IN (
-- SELECT
-- blockchain
-- FROM
-- UNNEST (SPLIT ('{{Blockchain}}', ',')) as b (blockchain)
-- )
GROUP BY
DATE_TRUNC ('day', block_time) -- DATE_TRUNC ('{{Granularity}}', block_time)
),
botActivityByDayWithCumulativeValues AS (
SELECT
*,
SUM(volumeUSD) OVER (
PARTITION BY
bot
ORDER BY
block_date
) AS cumulative_volumeUSD,
SUM(numberOfTrades) OVER (
PARTITION BY
bot
ORDER BY
block_date
) AS cumulative_numberOfTrades
FROM
(
SELECT
*
FROM
botActivityByDay
UNION ALL
SELECT
*
FROM
defCafeActivityByDay
)
)
SELECT
*
FROM
botActivityByDayWithCumulativeValues
WHERE
block_date >= NOW () - INTERVAL '180' day --'{{Timeframe in Days}}' day
ORDER BY
block_date DESC,
bot ASC