Skip to content

Commit

Permalink
fix: instant_reward -> reward_rest
Browse files Browse the repository at this point in the history
  • Loading branch information
1000101 committed Jun 11, 2024
1 parent fc6221c commit bf13285
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ CREATE INDEX IF NOT EXISTS bf_idx_redeemer_tx_id ON redeemer USING btree (tx_id)
CREATE INDEX IF NOT EXISTS bf_idx_col_tx_out ON collateral_tx_out USING btree (tx_id);
CREATE INDEX IF NOT EXISTS bf_idx_ma_tx_mint_ident ON ma_tx_mint USING btree (ident);
CREATE INDEX IF NOT EXISTS bf_idx_ma_tx_out_ident ON ma_tx_out USING btree (ident);
CREATE INDEX IF NOT EXISTS bf_idx_instant_reward_addr_id ON instant_reward USING btree (addr_id);
CREATE INDEX IF NOT EXISTS bf_idx_instant_reward_spendable_epoch ON instant_reward USING btree (spendable_epoch);
CREATE INDEX IF NOT EXISTS bf_idx_reward_rest_addr_id ON reward_rest USING btree (addr_id);
CREATE INDEX IF NOT EXISTS bf_idx_reward_rest_spendable_epoch ON reward_rest USING btree (spendable_epoch);
```

### Docker
Expand Down
23 changes: 14 additions & 9 deletions src/sql/accounts/accounts_stake_address.sql
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,23 @@ 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(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
) + 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
(
COALESCE(rewards_sum.amount, 0) + COALESCE(instant_rewards_sum.amount, 0)
)::TEXT AS "rewards_sum", -- cast to TEXT to avoid number overflow
COALESCE(withdrawals_sum.amount, 0)::TEXT AS "withdrawals_sum", -- cast to TEXT to avoid number overflow
COALESCE(reserves_sum.amount, 0)::TEXT AS "reserves_sum", -- cast to TEXT to avoid number overflow
COALESCE(treasury_sum.amount, 0)::TEXT AS "treasury_sum", -- cast to TEXT to avoid number overflow
)::TEXT AS "rewards_sum",
-- cast to TEXT to avoid number overflow
COALESCE(withdrawals_sum.amount, 0)::TEXT AS "withdrawals_sum",
-- cast to TEXT to avoid number overflow
COALESCE(reserves_sum.amount, 0)::TEXT AS "reserves_sum",
-- cast to TEXT to avoid number overflow
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(withdrawals_sum.amount, 0)
)::TEXT AS "withdrawable_amount", -- cast to TEXT to avoid number overflow
)::TEXT AS "withdrawable_amount",
-- cast to TEXT to avoid number overflow
(
SELECT pool_id
FROM queried_pool
Expand All @@ -107,7 +112,7 @@ FROM stake_address sa
LEFT JOIN (
SELECT addr_id,
SUM(amount) AS "amount"
FROM instant_reward
FROM reward_rest
WHERE (
addr_id = (
SELECT *
Expand Down
2 changes: 1 addition & 1 deletion src/sql/network/network.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ circulating_supply AS (
)
) + (
SELECT COALESCE(SUM(amount), 0)
FROM instant_reward
FROM reward_rest
WHERE spendable_epoch <= (
SELECT *
FROM current_epoch
Expand Down
2 changes: 1 addition & 1 deletion src/sql/pools/pools_extended.sql
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ live_stake_accounts_instant_rewards AS (
SELECT lsa.pool_hash_id,
COALESCE(SUM(amount), 0) AS "amount_instant_rewards_pool"
FROM live_stake_accounts lsa
JOIN instant_reward ir ON (lsa.stake_address_id = ir.addr_id)
JOIN reward_rest rr ON (lsa.stake_address_id = rr.addr_id)
WHERE spendable_epoch <= (
SELECT epoch_no
FROM current_epoch
Expand Down
8 changes: 4 additions & 4 deletions src/sql/pools/pools_pool_id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ live_stake_accounts_rewards AS (
)
),
live_stake_accounts_instant_rewards AS (
SELECT (COALESCE(SUM(ir.amount), 0)) AS "amount_instant_rewards"
SELECT (COALESCE(SUM(rr.amount), 0)) AS "amount_instant_rewards"
FROM live_stake_accounts lsa
JOIN instant_reward ir ON (lsa.stake_address_id = ir.addr_id)
WHERE ir.spendable_epoch <= (
JOIN reward_rest rr ON (lsa.stake_address_id = rr.addr_id)
WHERE rr.spendable_epoch <= (
SELECT epoch_no
FROM current_epoch
)
Expand Down Expand Up @@ -395,7 +395,7 @@ SELECT ph.view AS "pool_id",
) + COALESCE(
(
SELECT SUM(amount) AS "amount"
FROM instant_reward
FROM reward_rest
WHERE (
addr_id IN (
SELECT *
Expand Down
6 changes: 3 additions & 3 deletions src/sql/pools/pools_pool_id_delegators.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ SELECT "address" AS "address",
)
) + (
SELECT COALESCE(SUM(amount), 0)
FROM instant_reward ir
WHERE (ir.addr_id = address_id)
AND ir.spendable_epoch <= (
FROM reward_rest rr
WHERE (rr.addr_id = address_id)
AND rr.spendable_epoch <= (
SELECT *
FROM current_epoch
)
Expand Down
2 changes: 1 addition & 1 deletion src/sql/pools/unpaged/pools_extended.sql
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ live_stake_accounts_instant_rewards AS (
SELECT lsa.pool_hash_id,
COALESCE(SUM(amount), 0) AS "amount_instant_rewards_pool"
FROM live_stake_accounts lsa
JOIN instant_reward ir ON (lsa.stake_address_id = ir.addr_id)
JOIN reward_rest rr ON (lsa.stake_address_id = rr.addr_id)
WHERE spendable_epoch <= (
SELECT epoch_no
FROM current_epoch
Expand Down

0 comments on commit bf13285

Please sign in to comment.