forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[indexer] Add inactive share tracking (aptos-labs#8363)
* Add inactive share tracking * add view for easy access * add a new query for wallet * remove backfilling code
- Loading branch information
1 parent
022bcba
commit 19a5669
Showing
9 changed files
with
466 additions
and
55 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
crates/indexer/migrations/2023-05-22-234344_delegated_staking_improvements/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- This file should undo anything in `up.sql` | ||
ALTER TABLE current_delegated_staking_pool_balances DROP COLUMN IF EXISTS operator_commission_percentage, | ||
DROP COLUMN IF EXISTS inactive_table_handle, | ||
DROP COLUMN IF EXISTS active_table_handle; | ||
DROP INDEX IF EXISTS cdspb_inactive_index; | ||
ALTER TABLE delegated_staking_pool_balances DROP COLUMN IF EXISTS operator_commission_percentage, | ||
DROP COLUMN IF EXISTS inactive_table_handle, | ||
DROP COLUMN IF EXISTS active_table_handle; | ||
ALTER TABLE current_delegator_balances DROP COLUMN IF EXISTS parent_table_handle; | ||
ALTER TABLE current_delegator_balances DROP CONSTRAINT current_delegator_balances_pkey; | ||
ALTER TABLE current_delegator_balances | ||
ADD CONSTRAINT current_delegator_balances_pkey PRIMARY KEY ( | ||
delegator_address, | ||
pool_address, | ||
pool_type | ||
); | ||
CREATE OR REPLACE VIEW num_active_delegator_per_pool AS | ||
SELECT pool_address, | ||
COUNT(DISTINCT delegator_address) AS num_active_delegator | ||
FROM current_delegator_balances | ||
WHERE shares > 0 | ||
GROUP BY 1; | ||
DROP VIEW IF EXISTS delegator_distinct_pool; | ||
DROP VIEW IF EXISTS address_events_summary; |
46 changes: 46 additions & 0 deletions
46
crates/indexer/migrations/2023-05-22-234344_delegated_staking_improvements/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- Your SQL goes here | ||
-- adding new fields to staking pool balances for display and handling inactive pools | ||
ALTER TABLE current_delegated_staking_pool_balances | ||
ADD COLUMN IF NOT EXISTS operator_commission_percentage NUMERIC NOT NULL, | ||
ADD COLUMN IF NOT EXISTS inactive_table_handle VARCHAR(66) NOT NULL, | ||
ADD COLUMN IF NOT EXISTS active_table_handle VARCHAR(66) NOT NULL; | ||
CREATE INDEX IF NOT EXISTS cdspb_inactive_index ON current_delegated_staking_pool_balances (inactive_table_handle); | ||
-- adding new fields to staking pool balances for display and handling inactive pools | ||
ALTER TABLE delegated_staking_pool_balances | ||
ADD COLUMN IF NOT EXISTS operator_commission_percentage NUMERIC NOT NULL, | ||
ADD COLUMN IF NOT EXISTS inactive_table_handle VARCHAR(66) NOT NULL, | ||
ADD COLUMN IF NOT EXISTS active_table_handle VARCHAR(66) NOT NULL; | ||
-- add new field to composite primary key because technically a user could have inactive pools | ||
ALTER TABLE current_delegator_balances | ||
ADD COLUMN IF NOT EXISTS parent_table_handle VARCHAR(66) NOT NULL; | ||
ALTER TABLE current_delegator_balances DROP CONSTRAINT current_delegator_balances_pkey; | ||
ALTER TABLE current_delegator_balances | ||
ADD CONSTRAINT current_delegator_balances_pkey PRIMARY KEY ( | ||
delegator_address, | ||
pool_address, | ||
pool_type, | ||
table_handle | ||
); | ||
-- need this for delegation staking | ||
CREATE OR REPLACE VIEW num_active_delegator_per_pool AS | ||
SELECT pool_address, | ||
COUNT(DISTINCT delegator_address) AS num_active_delegator | ||
FROM current_delegator_balances | ||
WHERE shares > 0 | ||
AND pool_type = 'active_shares' | ||
GROUP BY 1; | ||
-- need this for delegation staking | ||
CREATE OR REPLACE VIEW delegator_distinct_pool AS | ||
SELECT delegator_address, | ||
pool_address | ||
FROM current_delegator_balances | ||
WHERE shares > 0 | ||
GROUP BY 1, | ||
2; | ||
-- new query for wallet | ||
CREATE OR REPLACE VIEW address_events_summary AS | ||
SELECT account_address, | ||
min(transaction_block_height) AS min_block_height, | ||
count(DISTINCT transaction_version) AS num_distinct_versions | ||
FROM events | ||
GROUP BY 1 |
Oops, something went wrong.