Skip to content

Commit

Permalink
fixup! wip: naive insta_rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
sorki committed Mar 31, 2024
1 parent d714773 commit ac370ad
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/sql/accounts/accounts_stake_address.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ SELECT sa.view AS "stake_address",
SELECT *
FROM queried_addr
)
) + COALESCE(rewards_sum.amount, 0) + COALESCE(instant_rewards_sum.amount, 0) + COALESCE(refunds_sum.amount, 0) + COALESCE(instant_refunds_sum.amount, 0) - COALESCE(withdrawals_sum.amount, 0)
) + COALESCE(rewards_sum.amount, 0) + COALESCE(instant_rewards_sum.amount, 0) + COALESCE(refunds_sum.amount, 0) - COALESCE(withdrawals_sum.amount, 0)
-- SUM of all utxos + withdrawables (rewards (all types including rewards + refunds + treasury + reserves) - withdrawals
)::TEXT AS "controlled_amount", -- cast to TEXT to avoid number overflow
(
Expand All @@ -82,7 +82,7 @@ SELECT sa.view AS "stake_address",
COALESCE(treasury_sum.amount, 0)::TEXT AS "treasury_sum", -- cast to TEXT to avoid number overflow
(
(
COALESCE(rewards_sum.amount, 0) + COALESCE(instant_rewards_sum.amount, 0) + COALESCE(refunds_sum.amount, 0) + COALESCE(instant_refunds_sum.amount, 0) - COALESCE(withdrawals_sum.amount, 0)
COALESCE(rewards_sum.amount, 0) + COALESCE(instant_rewards_sum.amount, 0) - COALESCE(withdrawals_sum.amount, 0)
)
)::TEXT AS "withdrawable_amount", -- cast to TEXT to avoid number overflow
(
Expand Down Expand Up @@ -141,23 +141,6 @@ FROM stake_address sa
)
GROUP BY addr_id
) AS "refunds_sum" ON (refunds_sum.addr_id = sa.id)
LEFT JOIN (
SELECT addr_id,
SUM(amount) AS "amount"
FROM instant_reward
WHERE (
addr_id = (
SELECT *
FROM queried_addr
)
AND spendable_epoch <= (
SELECT *
FROM current_epoch
)
AND type <> 'refund'
)
GROUP BY addr_id
) AS "instant_refunds_sum" ON (instant_refunds_sum.addr_id = sa.id)
LEFT JOIN (
SELECT addr_id,
SUM(amount) AS "amount"
Expand Down

0 comments on commit ac370ad

Please sign in to comment.