Skip to content

Commit bee05c7

Browse files
committed
feat: add tvw and borrowed amount usd to rankings
1 parent 1234e09 commit bee05c7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

migrations/000016_rankings.up.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ returns table (
77
old_total DOUBLE PRECISION,
88
old_collateral_underlying DOUBLE PRECISION,
99
old_profit_underlying DOUBLE PRECISION,
10+
old_borrowed_amount_usd DOUBLE PRECISION,
11+
old_twv_usd DOUBLE PRECISION,
1012
old_hf varchar(80),
1113
sid varchar(100),
1214
new_total DOUBLE PRECISION,
@@ -24,6 +26,7 @@ returns table (
2426
collateral_usd DOUBLE PRECISION,
2527
profit_underlying DOUBLE PRECISION,
2628
collateral_underlying DOUBLE PRECISION,
29+
2730
roi DOUBLE PRECISION
2831
)
2932
language plpgsql
@@ -41,10 +44,12 @@ BEGIN
4144
(t2.new_profit_underlying-t1.old_profit_underlying) * price profit_usd, t1.old_collateral_underlying*price collateral_usd,
4245
(t2.new_profit_underlying-t1.old_profit_underlying) profit_underlying, t1.old_collateral_underlying collateral_underlying,
4346

44-
(t2.new_profit_underlying-t1.old_profit_underlying)/(t1.old_collateral_underlying) roi FROM
47+
(t2.new_profit_underlying-t1.old_profit_underlying)/(t1.old_collateral_underlying) roi FROM
4548

4649
(SELECT distinct on (d.session_id) d.total_value_usd old_total,
4750
d.collateral_underlying old_collateral_underlying, d.profit_underlying as old_profit_underlying,
51+
((cal_borrowed_amt_with_interest_bi::float8 * total_value_usd)/ cal_total_value_bi::float8) old_borrowed_amount_usd,
52+
((cal_threshold_value_bi::float8 * total_value_usd)/ cal_total_value_bi::float8) old_twv_usd,
4853
cal_health_factor old_hf, d.session_id sid
4954
FROM debts d WHERE block_num >= (SELECT min(id) FROM blocks WHERE timestamp > (extract(epoch from now())::bigint - $1))
5055
order by d.session_id, block_num) t1

0 commit comments

Comments
 (0)