Skip to content

Instantly share code, notes, and snippets.

@vivekascoder
Created September 20, 2024 09:21
Show Gist options
  • Save vivekascoder/2738408c824219d98e45120afde4c048 to your computer and use it in GitHub Desktop.
Save vivekascoder/2738408c824219d98e45120afde4c048 to your computer and use it in GitHub Desktop.
CREATE MATERIALIZED VIEW IF NOT EXISTS daily_volume AS
WITH parameters AS (
SELECT
'0x9cdAA94733a682013Ff8AfD72BA59FB63619C98d' AS pool_addr,
EXTRACT(EPOCH FROM NOW() - INTERVAL '24 hours') AS last_time
),
combined AS (
SELECT amount, "blockTimestamp", pool
FROM "AddLiquidity"
WHERE "blockTimestamp" >= (SELECT last_time FROM parameters)
UNION ALL
SELECT amount, "blockTimestamp", pool
FROM "OpenLong"
WHERE "blockTimestamp" >= (SELECT last_time FROM parameters)
UNION ALL
SELECT amount, "blockTimestamp", pool
FROM "OpenShort"
WHERE "blockTimestamp" >= (SELECT last_time FROM parameters)
)
SELECT SUM(amount) AS daily_volume, pool from combined
group by pool;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment