raho2023-08-27 07:23 PM
Updated 2023-08-28
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
›
⌄
--0x5e349eca2dc61aBCd9dD99Ce94d04136151a09Ee
WITH all_delegations AS (
SELECT
DELEGATOR,
TO_DELEGATE AS delegate,
NEW_BALANCE - PREVIOUS_BALANCE AS amount,
BLOCK_TIMESTAMP
FROM optimism.core.fact_delegations
WHERE TO_DELEGATE = lower('{{delegate}}')
UNION ALL
SELECT
DELEGATOR,
FROM_DELEGATE AS delegate,
-(NEW_BALANCE - PREVIOUS_BALANCE) AS amount,
BLOCK_TIMESTAMP
FROM optimism.core.fact_delegations
WHERE FROM_DELEGATE = lower('{{delegate}}')
),
latest_delegations AS (
SELECT
DELEGATOR,
amount,
ROW_NUMBER() OVER (PARTITION BY DELEGATOR ORDER BY BLOCK_TIMESTAMP DESC) AS rn
FROM all_delegations
),
summed_del AS (
SELECT
DELEGATOR,
SUM(amount) AS tot_amount
FROM latest_delegations
WHERE rn = 1
Run a query to Download Data