-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpepe_dune.sql
More file actions
95 lines (77 loc) · 2.94 KB
/
pepe_dune.sql
File metadata and controls
95 lines (77 loc) · 2.94 KB
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
89
90
91
92
93
94
95
-- 转账明细
select "from", "to", value, evt_block_date from erc20_ethereum.evt_transfer where contract_address=0x6982508145454ce325ddbe47a25d4ec3d2311933 and evt_block_number >= 17046105 limit 10;
select * from pepe_multichain.pepetoken_evt_transfer where contract_address=0x6982508145454ce325ddbe47a25d4ec3d2311933 limit 1;
-- select * from erc20_ethereum.evt_transfer where evt_block_number>=17046105 and contract_address = 0x6982508145454ce325ddbe47a25d4ec3d2311933
-- select * from shib_ethereum.SHIB_evt_Transfer limit 10
-- select "from", "to", value, evt_block_date from erc20_ethereum.evt_transfer where contract_address=0x6982508145454ce325ddbe47a25d4ec3d2311933 and evt_block_number >= 17046105 limit 10;
-- select * from pepe_multichain.pepetoken_evt_transfer where contract_address=0x6982508145454ce325ddbe47a25d4ec3d2311933 limit 1;
-- 用户持仓明细
WITH
balance_changes AS (
SELECT
"from" AS address,
- value AS balance_change
FROM
erc20_ethereum.evt_transfer
where contract_address=0x6982508145454ce325ddbe47a25d4ec3d2311933 and evt_block_number >= 17046105
UNION ALL
SELECT
"to" AS address,
value AS balance_change
FROM
erc20_ethereum.evt_transfer
where contract_address=0x6982508145454ce325ddbe47a25d4ec3d2311933 and evt_block_number >= 17046105
),
address_balances AS (
SELECT
address,
SUM(balance_change)/1e18 AS balance
FROM
balance_changes
GROUP BY
address
HAVING
SUM(balance_change) > 0
)
SELECT
*
FROM
address_balances
ORDER BY balance desc;
-- 总持币数量及发行量
select
count(address) as holders,
sum(balance) as totalSupply
from query_5218166
-- https://dune.com/queries/5218166
select
count(address) as holders,
sum(balance) as totalSupply
from query_6558387
-- https://dune.com/queries/6558387
-- 每日交易笔数
select DATE_TRUNC('day', evt_block_time) day, count(*) as txs
from erc20_ethereum.evt_transfer
where contract_address=0x6982508145454ce325ddbe47a25d4ec3d2311933 and evt_block_time >= CURRENT_TIMESTAMP - INTERVAL '180' day
group by 1
order by 1
-- pepe 价格
select * from prices.usd where blockchain='ethereum' and contract_address=0x6982508145454ce325ddbe47a25d4ec3d2311933 limit 10;
-- 输出每天的交易总额(过去 7 天)
WITH daily_transactions AS (
select DATE_TRUNC('day', evt_block_time) day, SUM(value) / 1e18 AS total_transfer_amount
from erc20_ethereum.evt_transfer
where contract_address=0x6982508145454ce325ddbe47a25d4ec3d2311933 and evt_block_time >= CURRENT_TIMESTAMP - INTERVAL '7' day
group by 1
order by 1
),
pepe_daily_volume as (
select dt.day, total_transfer_amount, price from daily_transactions dt JOIN prices.usd_daily d on d.day = dt.day
where d.contract_address = 0x6982508145454ce325ddbe47a25d4ec3d2311933 and d.blockchain = 'ethereum'
)
SELECT
day,
SUM(total_transfer_amount * price) AS usd_volume
FROM
pepe_daily_volume
group by 1 order by 1