Multipartite2022-03-28 Reserve balance prediction (transfer_events , test with balances)
Updated 2022-03-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
›
⌄
--Warning, even if using CAST( AS DECIMAL(20,8)), a spreadsheet will truncate full-balance-prediction significant figures,
--producing inconsistency with the block changes. (Thus, use those changes directly.)
SELECT block_id, reserve_balance
FROM (
SELECT block_id, SUM(reserve_net_change) OVER(ORDER BY block_id ASC) AS reserve_balance
FROM (
SELECT block_id, SUM(reserve_change) AS reserve_net_change
FROM
(
SELECT block_id, (CASE
WHEN from_address = to_address THEN 0
WHEN from_address = 'thor1dheycdevq39qlkxs2a6wuuzyn4aqxhve4qxtxt' THEN -1
WHEN to_address = 'thor1dheycdevq39qlkxs2a6wuuzyn4aqxhve4qxtxt' THEN 1
END) * CAST(POWER(10,-8) * amount_e8 AS DECIMAL(38,8)) AS reserve_change
--CAST() is necessary for decimal precision, but a spreadsheet program may still truncate it or its display.
FROM thorchain.transfer_events
WHERE (from_address = 'thor1dheycdevq39qlkxs2a6wuuzyn4aqxhve4qxtxt') OR (to_address = 'thor1dheycdevq39qlkxs2a6wuuzyn4aqxhve4qxtxt')
)
GROUP BY block_id
)
)
WHERE block_id IN (4708800)
ORDER BY block_id ASC
Run a query to Download Data