diff --git a/src/sql/accounts/accounts_stake_address.sql b/src/sql/accounts/accounts_stake_address.sql index 1ed299b6..b1543ef3 100644 --- a/src/sql/accounts/accounts_stake_address.sql +++ b/src/sql/accounts/accounts_stake_address.sql @@ -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 ( @@ -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 ( @@ -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"