-
Notifications
You must be signed in to change notification settings - Fork 0
/
jediswap_token_pairs.sql
89 lines (84 loc) · 2.75 KB
/
jediswap_token_pairs.sql
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
WITH stark_to_eth_price AS (
SELECT
'STARK/ETH' AS pair_name,
block_date,
parameters::amount1Out::$`low` / parameters::amount0In::$`low` AS price
FROM mcdw.events
WHERE
chain_id = 5461067
AND contract_address = '0x02ed66297d146ecd91595c3174da61c1397e8b7fcecf25d423b1ba6717b0ece9'
AND event_name = 'Swap'
AND NOT reverted
AND block_date = CURDATE() -- Filter for today's date
AND parameters::amount0In::$`low` > 0
AND parameters::amount1Out::$`low` > 0
GROUP BY
block_date
),
stark_to_usdc_price AS (
SELECT
'STARK/USDC' AS pair_name,
block_date,
(parameters::amount1Out::$`low` / pow(10, 6)) / (parameters::amount0In::$`low` / pow(10, 18)) AS price
FROM
mcdw.events
WHERE
chain_id = 5461067
AND contract_address = '0x05726725e9507c3586cc0516449e2c74d9b201ab2747752bb0251aaa263c9a26'
AND event_name = 'Swap'
AND NOT reverted
AND block_date = CURDATE() -- Filter for today's date
AND parameters::amount0In::$`low` > 0
AND parameters::amount1Out::$`low` > 0
GROUP BY
block_date
),
eth_to_usdt_price AS (
SELECT
'ETH/USDT' AS pair_name,
block_date,
(parameters::amount1Out::$`low` / pow(10, 6)) / (parameters::amount0In::$`low` / pow(10, 18)) AS price
FROM
mcdw.events
WHERE
chain_id = 5461067
AND contract_address = '0x045e7131d776dddc137e30bdd490b431c7144677e97bf9369f629ed8d3fb7dd6'
AND event_name = 'Swap'
AND NOT reverted
AND block_date = CURDATE() -- Filter for today's date
AND parameters::amount0In::$`low` > 0
AND parameters::amount1Out::$`low` > 0
GROUP BY
block_date
),
dai_to_eth_price AS (
SELECT
'DAI/ETH' AS pair_name,
block_date,
(parameters::amount1Out::$`low` / pow(10, 18)) / (parameters::amount0In::$`low` / pow(10, 18)) AS price
FROM
mcdw.events
WHERE
chain_id = 5461067
AND contract_address = '0x07e2a13b40fc1119ec55e0bcf9428eedaa581ab3c924561ad4e955f95da63138'
AND event_name = 'Swap'
AND NOT reverted
AND block_date = CURDATE() -- Filter for today's date
AND parameters::amount0In::$`low` > 0
AND parameters::amount1Out::$`low` > 0
GROUP BY
block_date
)
SELECT
pair_name,
price
FROM
(
SELECT pair_name, block_date, price FROM stark_to_eth_price
UNION ALL
SELECT pair_name, block_date, price FROM stark_to_usdc_price
UNION ALL
SELECT pair_name, block_date, price FROM eth_to_usdt_price
UNION ALL
SELECT pair_name, block_date, price FROM dai_to_eth_price
) AS all_prices