Pine AnalyticsNeptune Metrics copy copy
Updated 2025-01-23
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
›
⌄
WITH tab1 as (
SELECT
tx.tx_id,
block_timestamp,
pre_bal.value AS pre_token_balance,
post_bal.value AS post_token_balance,
pre_token_balance['mint'] as token,
pre_token_balance['owner'] as owner,
pre_token_balance['uiTokenAmount']['amount'] / power(10, 9) as pre_balance,
post_token_balance['uiTokenAmount']['amount'] / power(10, 9) as post_balance,
post_balance - pre_balance as net_balance,
pre_token_balance as a
FROM
eclipse.core.fact_transactions tx,
LATERAL FLATTEN(input => tx.PRE_TOKEN_BALANCES) pre_bal,
LATERAL FLATTEN(input => tx.POST_TOKEN_BALANCES) post_bal
WHERE
pre_bal.index = post_bal.index
and token like 'FATF66HHhz8Yf2zxMXZXjmzu8NFArwtCJGEsj7rHC8i4'
and SUCCEEDED
and block_timestamp > '2024-01-01'
),
latest_balances AS (
SELECT
owner,
token,
post_balance as balance,
block_timestamp,
ROW_NUMBER() OVER (PARTITION BY owner ORDER BY block_timestamp DESC) as rn
FROM tab1
)
SELECT
owner,
token,
balance as current_balance,
block_timestamp as last_updated_at
QueryRunArchived: QueryRun has been archived