Keyrock[2] Bridge + Price (APT)
Updated 2024-02-26
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
⌄
-- forked from andreafiandro / [2] Bridge + Price (SOL) @ https://flipsidecrypto.xyz/andreafiandro/q/9tzUzG4J2Pht/2-bridge-price-sol
WITH
prices AS (
WITH raw_data AS (
SELECT livequery.live.udf_api('https://api.coingecko.com/api/v3/coins/aptos/market_chart?vs_currency=usd&days=max') AS resp
)
SELECT
'prices' AS key,
date_trunc('day', TO_TIMESTAMP(value[0]::string)) AS day, -- Truncate the timestamp to align with bridge dates
value[1] AS price
FROM
raw_data,
LATERAL FLATTEN (input => resp:data:prices)
),
bridge AS (
SELECT
date_trunc('day', block_timestamp) as date,
COUNT(DISTINCT TX_HASH) as total_txs
FROM
ethereum.defi.ez_bridge_activity
WHERE
block_timestamp > '{{starting_date}}'
AND Destination_chain = 'aptos'
GROUP BY
date
)
SELECT b.date AS day, COALESCE(total_txs, 0) AS total_txs, price
FROM bridge b
LEFT JOIN prices p ON b.date = p.day
WHERE (b.date >= '{{starting_date}}' OR b.date >= (SELECT MAX(date) FROM bridge));
/*