From accd1c84281e633a1c2e088de299eff1580407b6 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Tue, 18 Feb 2025 18:52:46 -0500 Subject: [PATCH 1/4] add timestamp to additional tables --- indexers/db/docker-entrypoint-initdb.d/init-db.sql | 3 +++ indexers/staking/schema.graphql | 3 +++ indexers/staking/src/mappings/db.ts | 6 ++++++ indexers/staking/src/mappings/mappingHandlers.ts | 3 +++ 4 files changed, 15 insertions(+) diff --git a/indexers/db/docker-entrypoint-initdb.d/init-db.sql b/indexers/db/docker-entrypoint-initdb.d/init-db.sql index 5c329d25c..35ab245dc 100644 --- a/indexers/db/docker-entrypoint-initdb.d/init-db.sql +++ b/indexers/db/docker-entrypoint-initdb.d/init-db.sql @@ -1218,6 +1218,7 @@ CREATE TABLE staking.deposit_histories ( effective_domain_epoch_pending integer NOT NULL, amount_pending numeric NOT NULL, storage_fee_deposit_pending numeric NOT NULL, + timestamp timestamp with time zone NOT NULL, block_height numeric NOT NULL, _id uuid NOT NULL, _block_range int8range NOT NULL @@ -1437,6 +1438,7 @@ CREATE TABLE staking.operator_staking_histories ( total_storage_fee_deposit numeric NOT NULL, share_price numeric NOT NULL, partial_status text NOT NULL, + timestamp timestamp with time zone NOT NULL, block_height numeric NOT NULL, _id uuid NOT NULL, _block_range int8range NOT NULL @@ -1563,6 +1565,7 @@ CREATE TABLE staking.withdrawal_histories ( unlock_at_confirmed_domain_block_number numeric NOT NULL, shares numeric NOT NULL, storage_fee_refund numeric NOT NULL, + timestamp timestamp with time zone NOT NULL, block_height numeric NOT NULL, _id uuid NOT NULL, _block_range int8range NOT NULL diff --git a/indexers/staking/schema.graphql b/indexers/staking/schema.graphql index bb67e1679..ebe4ef4e0 100644 --- a/indexers/staking/schema.graphql +++ b/indexers/staking/schema.graphql @@ -177,6 +177,7 @@ type OperatorStakingHistory @entity { totalStorageFeeDeposit: BigInt! sharePrice: BigInt! partialStatus: String! + timestamp: Date! blockHeight: BigInt! } @@ -194,6 +195,7 @@ type DepositHistory @entity { effectiveDomainEpochPending: Int! amountPending: BigInt! storageFeeDepositPending: BigInt! + timestamp: Date! blockHeight: BigInt! } @@ -208,5 +210,6 @@ type WithdrawalHistory @entity { unlockAtConfirmedDomainBlockNumber: BigInt! shares: BigInt! storageFeeRefund: BigInt! + timestamp: Date! blockHeight: BigInt! } diff --git a/indexers/staking/src/mappings/db.ts b/indexers/staking/src/mappings/db.ts index d8b1648f1..50da17463 100644 --- a/indexers/staking/src/mappings/db.ts +++ b/indexers/staking/src/mappings/db.ts @@ -393,6 +393,7 @@ export function createOperatorStakingHistory( totalStorageFeeDeposit: bigint, sharePrice: bigint, partialStatus: string, + timestamp: Date, blockHeight: bigint ): OperatorStakingHistory { return OperatorStakingHistory.create({ @@ -408,6 +409,7 @@ export function createOperatorStakingHistory( totalStorageFeeDeposit, sharePrice, partialStatus, + timestamp, blockHeight, }); } @@ -425,6 +427,7 @@ export function createDepositHistory( effectiveDomainEpochPending: number, amountPending: bigint, storageFeeDepositPending: bigint, + timestamp: Date, blockHeight: bigint ): DepositHistory { return DepositHistory.create({ @@ -441,6 +444,7 @@ export function createDepositHistory( effectiveDomainEpochPending, amountPending, storageFeeDepositPending, + timestamp, blockHeight, }); } @@ -455,6 +459,7 @@ export function createWithdrawalHistory( unlockAtConfirmedDomainBlockNumber: bigint, shares: bigint, storageFeeRefund: bigint, + timestamp: Date, blockHeight: bigint ): WithdrawalHistory { return WithdrawalHistory.create({ @@ -468,6 +473,7 @@ export function createWithdrawalHistory( unlockAtConfirmedDomainBlockNumber, shares, storageFeeRefund, + timestamp, blockHeight, }); } diff --git a/indexers/staking/src/mappings/mappingHandlers.ts b/indexers/staking/src/mappings/mappingHandlers.ts index 6dad5ef73..b0cfe7c9c 100644 --- a/indexers/staking/src/mappings/mappingHandlers.ts +++ b/indexers/staking/src/mappings/mappingHandlers.ts @@ -107,6 +107,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { operator.operatorDetails.totalStorageFeeDeposit, sharePrice, stringify(operator.operatorDetails.partialStatus), + blockTimestamp, height ) ); @@ -142,6 +143,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { data.pending?.effectiveDomainEpoch ?? 0, data.pending?.amount ?? ZERO_BIGINT, data.pending?.storageFeeDeposit ?? ZERO_BIGINT, + blockTimestamp, height ) ); @@ -178,6 +180,7 @@ export async function handleBlock(_block: SubstrateBlock): Promise { data.withdrawalInShares === null ? ZERO_BIGINT : data.withdrawalInShares.storageFeeRefund, + blockTimestamp, height ) ); From 948661a8b7f34410ed244e97fb2c01e1b4b08400 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Tue, 18 Feb 2025 19:00:37 -0500 Subject: [PATCH 2/4] add block height and extrinsic to bundle submission --- indexers/db/docker-entrypoint-initdb.d/init-db.sql | 2 ++ indexers/staking/schema.graphql | 2 ++ indexers/staking/src/mappings/db.ts | 4 ++++ indexers/staking/src/mappings/eventHandler.ts | 6 +++++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/indexers/db/docker-entrypoint-initdb.d/init-db.sql b/indexers/db/docker-entrypoint-initdb.d/init-db.sql index 35ab245dc..1f0397906 100644 --- a/indexers/db/docker-entrypoint-initdb.d/init-db.sql +++ b/indexers/db/docker-entrypoint-initdb.d/init-db.sql @@ -1179,6 +1179,8 @@ CREATE TABLE staking.bundle_submissions ( consensus_storage_fee numeric NOT NULL, domain_execution_fee numeric NOT NULL, burned_balance numeric NOT NULL, + block_height numeric NOT NULL, + extrinsic_id text NOT NULL, event_id text NOT NULL, _id uuid NOT NULL, _block_range int8range NOT NULL diff --git a/indexers/staking/schema.graphql b/indexers/staking/schema.graphql index ebe4ef4e0..ccdf71355 100644 --- a/indexers/staking/schema.graphql +++ b/indexers/staking/schema.graphql @@ -120,6 +120,8 @@ type BundleSubmission @entity { consensusStorageFee: BigInt! domainExecutionFee: BigInt! burnedBalance: BigInt! + blockHeight: BigInt! + extrinsicId: String! eventId: String! } diff --git a/indexers/staking/src/mappings/db.ts b/indexers/staking/src/mappings/db.ts index 50da17463..a85da0b89 100644 --- a/indexers/staking/src/mappings/db.ts +++ b/indexers/staking/src/mappings/db.ts @@ -315,6 +315,8 @@ export function createBundleSubmission( consensusStorageFee: bigint, domainExecutionFee: bigint, burnedBalance: bigint, + blockHeight: bigint, + extrinsicId: string, eventId: string ): BundleSubmission { return BundleSubmission.create({ @@ -342,6 +344,8 @@ export function createBundleSubmission( consensusStorageFee, domainExecutionFee, burnedBalance, + blockHeight, + extrinsicId, eventId, }); } diff --git a/indexers/staking/src/mappings/eventHandler.ts b/indexers/staking/src/mappings/eventHandler.ts index e9271042a..6c36f0fdf 100644 --- a/indexers/staking/src/mappings/eventHandler.ts +++ b/indexers/staking/src/mappings/eventHandler.ts @@ -326,9 +326,11 @@ export const EVENT_HANDLERS: Record = { "domains.BundleStored": ({ event, cache, + extrinsic, extrinsicSigner, + height, + extrinsicId, eventId, - extrinsic, }) => { const bundleHash = event.event.data[1].toString(); const _extrinsic = extrinsic.method.args[0].toPrimitive() as any; @@ -388,6 +390,8 @@ export const EVENT_HANDLERS: Record = { BigInt(consensusStorageFee), BigInt(domainExecutionFee), BigInt(burnedBalance), + height, + extrinsicId, eventId ) ); From f239b0caa105178390d1463dd9ff400883e88a95 Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Tue, 18 Feb 2025 19:01:30 -0500 Subject: [PATCH 3/4] remove un-necessary type casting for math --- .../db/docker-entrypoint-initdb.d/init-db.sql | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/indexers/db/docker-entrypoint-initdb.d/init-db.sql b/indexers/db/docker-entrypoint-initdb.d/init-db.sql index 1f0397906..e7ea8bc02 100644 --- a/indexers/db/docker-entrypoint-initdb.d/init-db.sql +++ b/indexers/db/docker-entrypoint-initdb.d/init-db.sql @@ -2671,12 +2671,12 @@ CREATE OR REPLACE FUNCTION staking.handle_deposit_events() RETURNS TRIGGER BEGIN UPDATE staking.domains SET - total_deposits = staking.domains.total_deposits::NUMERIC(78) + NEW.amount::NUMERIC(78) + total_deposits = staking.domains.total_deposits + NEW.amount WHERE id = NEW.domain_id; UPDATE staking.operators SET - total_deposits = staking.operators.total_deposits::NUMERIC(78) + NEW.amount::NUMERIC(78) + total_deposits = staking.operators.total_deposits + NEW.amount WHERE id = NEW.operator_id; IF NOT EXISTS ( @@ -2752,8 +2752,8 @@ BEGIN ELSE UPDATE staking.nominators SET - total_deposits = staking.nominators.total_deposits::NUMERIC(78) + NEW.amount::NUMERIC(78), - total_deposits_count = staking.nominators.total_deposits_count::NUMERIC(78) + 1, + total_deposits = staking.nominators.total_deposits + NEW.amount, + total_deposits_count = staking.nominators.total_deposits_count + 1, updated_at = NEW.block_height WHERE id = NEW.nominator_id; END IF; @@ -2822,9 +2822,9 @@ BEGIN NEW.block_height -- updated_at ) ON CONFLICT (id) DO UPDATE SET - total_deposits = staking.accounts.total_deposits::NUMERIC(78) + NEW.total_amount::NUMERIC(78), - current_total_stake = staking.accounts.current_total_stake::NUMERIC(78) + NEW.amount::NUMERIC(78), - current_storage_fee_deposit = staking.accounts.current_storage_fee_deposit::NUMERIC(78) + NEW.storage_fee_deposit::NUMERIC(78), + total_deposits = staking.accounts.total_deposits + NEW.total_amount, + current_total_stake = staking.accounts.current_total_stake + NEW.amount, + current_storage_fee_deposit = staking.accounts.current_storage_fee_deposit + NEW.storage_fee_deposit, updated_at = NEW.block_height; RETURN NEW; @@ -2908,17 +2908,17 @@ BEGIN UPDATE staking.domains SET - total_tax_collected = staking.domains.total_tax_collected::NUMERIC(78) + NEW.amount::NUMERIC(78) + total_tax_collected = staking.domains.total_tax_collected + NEW.amount WHERE id = NEW.domain_id; UPDATE staking.operators SET - total_tax_collected = staking.operators.total_tax_collected::NUMERIC(78) + NEW.amount::NUMERIC(78) + total_tax_collected = staking.operators.total_tax_collected + NEW.amount WHERE id = NEW.operator_id; UPDATE staking.accounts SET - total_tax_collected = staking.accounts.total_tax_collected::NUMERIC(78) + NEW.amount::NUMERIC(78) + total_tax_collected = staking.accounts.total_tax_collected + NEW.amount WHERE id = operator_account_id; RETURN NEW; @@ -2937,12 +2937,12 @@ CREATE OR REPLACE FUNCTION staking.handle_operator_rewards_events() RETURNS TRIG BEGIN UPDATE staking.domains SET - total_rewards_collected = staking.domains.total_rewards_collected::NUMERIC(78) + NEW.amount::NUMERIC(78) + total_rewards_collected = staking.domains.total_rewards_collected + NEW.amount WHERE id = NEW.domain_id; UPDATE staking.operators SET - total_rewards_collected = staking.operators.total_rewards_collected::NUMERIC(78) + NEW.amount::NUMERIC(78) + total_rewards_collected = staking.operators.total_rewards_collected + NEW.amount WHERE id = NEW.operator_id; RETURN NEW; @@ -2961,37 +2961,37 @@ CREATE OR REPLACE FUNCTION staking.handle_bundle_submissions_events() RETURNS TR BEGIN UPDATE staking.domains SET - total_transfers_in = staking.domains.total_transfers_in::NUMERIC(78) + NEW.total_transfers_in::NUMERIC(78), - transfers_in_count = staking.domains.transfers_in_count::NUMERIC(78) + NEW.transfers_in_count::NUMERIC(78), - total_transfers_out = staking.domains.total_transfers_out::NUMERIC(78) + NEW.total_transfers_out::NUMERIC(78), - transfers_out_count = staking.domains.transfers_out_count::NUMERIC(78) + NEW.transfers_out_count::NUMERIC(78), - total_rejected_transfers_claimed = staking.domains.total_rejected_transfers_claimed::NUMERIC(78) + NEW.total_rejected_transfers_claimed::NUMERIC(78), - rejected_transfers_claimed_count = staking.domains.rejected_transfers_claimed_count::NUMERIC(78) + NEW.rejected_transfers_claimed_count::NUMERIC(78), - total_transfers_rejected = staking.domains.total_transfers_rejected::NUMERIC(78) + NEW.total_transfers_rejected::NUMERIC(78), - transfers_rejected_count = staking.domains.transfers_rejected_count::NUMERIC(78) + NEW.transfers_rejected_count::NUMERIC(78), - total_volume = staking.domains.total_volume::NUMERIC(78) + NEW.total_volume::NUMERIC(78), - total_consensus_storage_fee = staking.domains.total_consensus_storage_fee::NUMERIC(78) + NEW.consensus_storage_fee::NUMERIC(78), - total_domain_execution_fee = staking.domains.total_domain_execution_fee::NUMERIC(78) + NEW.domain_execution_fee::NUMERIC(78), - total_burned_balance = staking.domains.total_burned_balance::NUMERIC(78) + NEW.burned_balance::NUMERIC(78) , + total_transfers_in = staking.domains.total_transfers_in + NEW.total_transfers_in, + transfers_in_count = staking.domains.transfers_in_count + NEW.transfers_in_count, + total_transfers_out = staking.domains.total_transfers_out + NEW.total_transfers_out, + transfers_out_count = staking.domains.transfers_out_count + NEW.transfers_out_count, + total_rejected_transfers_claimed = staking.domains.total_rejected_transfers_claimed + NEW.total_rejected_transfers_claimed, + rejected_transfers_claimed_count = staking.domains.rejected_transfers_claimed_count + NEW.rejected_transfers_claimed_count, + total_transfers_rejected = staking.domains.total_transfers_rejected + NEW.total_transfers_rejected, + transfers_rejected_count = staking.domains.transfers_rejected_count + NEW.transfers_rejected_count, + total_volume = staking.domains.total_volume + NEW.total_volume, + total_consensus_storage_fee = staking.domains.total_consensus_storage_fee + NEW.consensus_storage_fee, + total_domain_execution_fee = staking.domains.total_domain_execution_fee + NEW.domain_execution_fee, + total_burned_balance = staking.domains.total_burned_balance + NEW.burned_balance , bundle_count = staking.domains.bundle_count + 1, last_bundle_at = NEW.consensus_block_number WHERE id = NEW.domain_id; UPDATE staking.operators SET - total_transfers_in = staking.operators.total_transfers_in::NUMERIC(78) + NEW.total_transfers_in::NUMERIC(78), - transfers_in_count = staking.operators.transfers_in_count::NUMERIC(78) + NEW.transfers_in_count::NUMERIC(78), - total_transfers_out = staking.operators.total_transfers_out::NUMERIC(78) + NEW.total_transfers_out::NUMERIC(78), - transfers_out_count = staking.operators.transfers_out_count::NUMERIC(78) + NEW.transfers_out_count::NUMERIC(78), - total_rejected_transfers_claimed = staking.operators.total_rejected_transfers_claimed::NUMERIC(78) + NEW.total_rejected_transfers_claimed::NUMERIC(78), - rejected_transfers_claimed_count = staking.operators.rejected_transfers_claimed_count::NUMERIC(78) + NEW.rejected_transfers_claimed_count::NUMERIC(78), - total_transfers_rejected = staking.operators.total_transfers_rejected::NUMERIC(78) + NEW.total_transfers_rejected::NUMERIC(78), - transfers_rejected_count = staking.operators.transfers_rejected_count::NUMERIC(78) + NEW.transfers_rejected_count::NUMERIC(78), - total_volume = staking.operators.total_volume::NUMERIC(78) + NEW.total_volume::NUMERIC(78), - total_consensus_storage_fee = staking.operators.total_consensus_storage_fee::NUMERIC(78) + NEW.consensus_storage_fee::NUMERIC(78), - total_domain_execution_fee = staking.operators.total_domain_execution_fee::NUMERIC(78) + NEW.domain_execution_fee::NUMERIC(78), - total_burned_balance = staking.operators.total_burned_balance::NUMERIC(78) + NEW.burned_balance::NUMERIC(78), - bundle_count = staking.operators.bundle_count::NUMERIC(78) + 1, + total_transfers_in = staking.operators.total_transfers_in + NEW.total_transfers_in, + transfers_in_count = staking.operators.transfers_in_count + NEW.transfers_in_count, + total_transfers_out = staking.operators.total_transfers_out + NEW.total_transfers_out, + transfers_out_count = staking.operators.transfers_out_count + NEW.transfers_out_count, + total_rejected_transfers_claimed = staking.operators.total_rejected_transfers_claimed + NEW.total_rejected_transfers_claimed, + rejected_transfers_claimed_count = staking.operators.rejected_transfers_claimed_count + NEW.rejected_transfers_claimed_count, + total_transfers_rejected = staking.operators.total_transfers_rejected + NEW.total_transfers_rejected, + transfers_rejected_count = staking.operators.transfers_rejected_count + NEW.transfers_rejected_count, + total_volume = staking.operators.total_volume + NEW.total_volume, + total_consensus_storage_fee = staking.operators.total_consensus_storage_fee + NEW.consensus_storage_fee, + total_domain_execution_fee = staking.operators.total_domain_execution_fee + NEW.domain_execution_fee, + total_burned_balance = staking.operators.total_burned_balance + NEW.burned_balance, + bundle_count = staking.operators.bundle_count + 1, last_bundle_at = NEW.consensus_block_number WHERE id = NEW.operator_id; @@ -3111,28 +3111,28 @@ CREATE OR REPLACE FUNCTION staking.handle_unlocked_events() RETURNS TRIGGER BEGIN UPDATE staking.domains SET - total_withdrawals = staking.domains.total_withdrawals::NUMERIC(78) + NEW.amount::NUMERIC(78), + total_withdrawals = staking.domains.total_withdrawals + NEW.amount, updated_at = NEW.block_height WHERE id = NEW.domain_id; UPDATE staking.operators SET - total_withdrawals = staking.operators.total_withdrawals::NUMERIC(78) + NEW.amount::NUMERIC(78), + total_withdrawals = staking.operators.total_withdrawals + NEW.amount, updated_at = NEW.block_height WHERE id = NEW.operator_id; UPDATE staking.nominators SET - total_withdrawal_amounts = staking.nominators.total_withdrawal_amounts::NUMERIC(78) + NEW.amount::NUMERIC(78), - total_storage_fee_refund = staking.nominators.total_storage_fee_refund::NUMERIC(78) + NEW.storage_fee::NUMERIC(78), - total_withdrawals = staking.nominators.total_withdrawals::NUMERIC(78) + NEW.amount::NUMERIC(78), - total_withdrawals_count = staking.nominators.total_withdrawal_amounts::NUMERIC(78) + 1, + total_withdrawal_amounts = staking.nominators.total_withdrawal_amounts + NEW.amount, + total_storage_fee_refund = staking.nominators.total_storage_fee_refund + NEW.storage_fee, + total_withdrawals = staking.nominators.total_withdrawals + NEW.amount, + total_withdrawals_count = staking.nominators.total_withdrawal_amounts + 1, updated_at = NEW.block_height WHERE id = NEW.nominator_id; UPDATE staking.accounts SET - total_withdrawals = staking.accounts.total_withdrawals::NUMERIC(78) + NEW.amount::NUMERIC(78), + total_withdrawals = staking.accounts.total_withdrawals + NEW.amount, updated_at = NEW.block_height WHERE id = NEW.account_id; From d91813baeb7526d7029c5b92ff123a88138ce86d Mon Sep 17 00:00:00 2001 From: Marc-Aurele Besner <82244926+marc-aurele-besner@users.noreply.github.com> Date: Tue, 18 Feb 2025 19:13:39 -0500 Subject: [PATCH 4/4] add total_deposits_count and total_withdrawals_count on accounts, domains and operators tables --- .../db/docker-entrypoint-initdb.d/init-db.sql | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/indexers/db/docker-entrypoint-initdb.d/init-db.sql b/indexers/db/docker-entrypoint-initdb.d/init-db.sql index e7ea8bc02..42c19763c 100644 --- a/indexers/db/docker-entrypoint-initdb.d/init-db.sql +++ b/indexers/db/docker-entrypoint-initdb.d/init-db.sql @@ -1141,6 +1141,8 @@ CREATE TABLE staking.accounts ( total_deposits numeric NOT NULL, total_estimated_withdrawals numeric NOT NULL, total_withdrawals numeric NOT NULL, + total_deposits_count numeric NOT NULL, + total_withdrawals_count numeric NOT NULL, total_tax_collected numeric NOT NULL, current_total_stake numeric NOT NULL, current_storage_fee_deposit numeric NOT NULL, @@ -1315,6 +1317,8 @@ CREATE TABLE staking.domains ( total_deposits numeric NOT NULL, total_estimated_withdrawals numeric NOT NULL, total_withdrawals numeric NOT NULL, + total_deposits_count numeric NOT NULL, + total_withdrawals_count numeric NOT NULL, total_tax_collected numeric NOT NULL, total_rewards_collected numeric NOT NULL, total_transfers_in numeric NOT NULL, @@ -1477,6 +1481,8 @@ CREATE TABLE staking.operators ( total_deposits numeric NOT NULL, total_estimated_withdrawals numeric NOT NULL, total_withdrawals numeric NOT NULL, + total_deposits_count numeric NOT NULL, + total_withdrawals_count numeric NOT NULL, total_tax_collected numeric NOT NULL, total_rewards_collected numeric NOT NULL, total_transfers_in numeric NOT NULL, @@ -2474,6 +2480,8 @@ BEGIN total_deposits, total_estimated_withdrawals, total_withdrawals, + total_deposits_count, + total_withdrawals_count, total_tax_collected, total_rewards_collected, total_transfers_in, @@ -2519,6 +2527,8 @@ BEGIN 0, -- total_deposits 0, -- total_estimated_withdrawals 0, -- total_withdrawals + 0, -- total_deposits_count + 0, -- total_withdrawals_count 0, -- total_tax_collected 0, -- total_rewards_collected 0, -- total_transfers_in @@ -2584,6 +2594,8 @@ BEGIN total_deposits, total_estimated_withdrawals, total_withdrawals, + total_deposits_count, + total_withdrawals_count, total_tax_collected, total_rewards_collected, total_transfers_in, @@ -2627,6 +2639,8 @@ BEGIN 0, -- total_deposits 0, -- total_estimated_withdrawals 0, -- total_withdrawals + 0, -- total_deposits_count + 0, -- total_withdrawals_count 0, -- total_tax_collected 0, -- total_rewards_collected 0, -- total_transfers_in @@ -2671,12 +2685,14 @@ CREATE OR REPLACE FUNCTION staking.handle_deposit_events() RETURNS TRIGGER BEGIN UPDATE staking.domains SET - total_deposits = staking.domains.total_deposits + NEW.amount + total_deposits = staking.domains.total_deposits + NEW.amount, + total_deposits_count = staking.domains.total_deposits_count + 1 WHERE id = NEW.domain_id; UPDATE staking.operators SET - total_deposits = staking.operators.total_deposits + NEW.amount + total_deposits = staking.operators.total_deposits + NEW.amount, + total_deposits_count = staking.operators.total_deposits_count + 1 WHERE id = NEW.operator_id; IF NOT EXISTS ( @@ -2795,6 +2811,8 @@ BEGIN total_deposits, total_estimated_withdrawals, total_withdrawals, + total_deposits_count, + total_withdrawals_count, total_tax_collected, current_total_stake, current_storage_fee_deposit, @@ -2810,6 +2828,8 @@ BEGIN NEW.total_amount, -- total_deposits (start with the new deposit amount) 0, -- total_estimated_withdrawals 0, -- total_withdrawals + 0, -- total_deposits_count + 0, -- total_withdrawals_count 0, -- total_tax_collected NEW.amount, -- current_total_stake NEW.storage_fee_deposit, -- current_storage_fee_deposit @@ -2823,6 +2843,7 @@ BEGIN ) ON CONFLICT (id) DO UPDATE SET total_deposits = staking.accounts.total_deposits + NEW.total_amount, + total_deposits_count = staking.accounts.total_deposits_count + 1, current_total_stake = staking.accounts.current_total_stake + NEW.amount, current_storage_fee_deposit = staking.accounts.current_storage_fee_deposit + NEW.storage_fee_deposit, updated_at = NEW.block_height; @@ -3112,12 +3133,14 @@ BEGIN UPDATE staking.domains SET total_withdrawals = staking.domains.total_withdrawals + NEW.amount, + total_withdrawals_count = staking.domains.total_withdrawals_count + 1, updated_at = NEW.block_height WHERE id = NEW.domain_id; UPDATE staking.operators SET total_withdrawals = staking.operators.total_withdrawals + NEW.amount, + total_withdrawals_count = staking.operators.total_withdrawals_count + 1, updated_at = NEW.block_height WHERE id = NEW.operator_id; @@ -3126,13 +3149,14 @@ BEGIN total_withdrawal_amounts = staking.nominators.total_withdrawal_amounts + NEW.amount, total_storage_fee_refund = staking.nominators.total_storage_fee_refund + NEW.storage_fee, total_withdrawals = staking.nominators.total_withdrawals + NEW.amount, - total_withdrawals_count = staking.nominators.total_withdrawal_amounts + 1, + total_withdrawals_count = staking.nominators.total_withdrawals_count + 1, updated_at = NEW.block_height WHERE id = NEW.nominator_id; UPDATE staking.accounts SET total_withdrawals = staking.accounts.total_withdrawals + NEW.amount, + total_withdrawals_count = staking.accounts.total_withdrawals_count + 1, updated_at = NEW.block_height WHERE id = NEW.account_id;