@@ -21,6 +21,7 @@ import {
2121 fetchAllSupplierByUnstakingEndBlockId ,
2222 fetchAllSupplierServiceConfigBySupplier ,
2323 fetchAllTransactions ,
24+ fetchAllValidatorByStatus ,
2425} from "./pagination" ;
2526
2627export async function handleAddBlockReports ( block : CosmosBlock ) : Promise < void > {
@@ -44,6 +45,8 @@ export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
4445 { unstakedApps, unstakedTokensByApp } ,
4546 { stakedGateways, stakedTokensByGateway } ,
4647 { unstakedGateways, unstakedTokensByGateway } ,
48+ { stakedTokensByValidators, stakedValidators } ,
49+ { unstakingTokensByValidators, unstakingValidators }
4750 ] = await Promise . all ( [
4851 getRelaysData ( blockHeight ) ,
4952 getTransactionsData ( blockHeight ) ,
@@ -56,6 +59,8 @@ export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
5659 getUnstakedAppsData ( blockHeight ) ,
5760 getStakedGatewaysData ( ) ,
5861 getUnstakedGatewaysData ( blockHeight ) ,
62+ getStakedValidatorsData ( ) ,
63+ getUnstakingValidatorsData ( ) ,
5964 ] ) ;
6065
6166 blockEntity . totalComputedUnits = computedUnits ;
@@ -80,6 +85,10 @@ export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
8085 blockEntity . stakedGatewaysTokens = stakedTokensByGateway ;
8186 blockEntity . unstakedGateways = unstakedGateways ;
8287 blockEntity . unstakedGatewaysTokens = unstakedTokensByGateway ;
88+ blockEntity . stakedValidators = stakedValidators ;
89+ blockEntity . stakedValidatorsTokens = stakedTokensByValidators ;
90+ blockEntity . unstakingValidators = unstakingValidators ;
91+ blockEntity . unstakingValidatorsTokens = unstakingTokensByValidators ;
8392
8493 await Promise . all ( [
8594 blockEntity . save ( ) ,
@@ -230,6 +239,26 @@ async function getUnstakingSuppliersData() {
230239 } ;
231240}
232241
242+ async function getStakedValidatorsData ( ) {
243+ const stakedValidators = await fetchAllValidatorByStatus ( StakeStatus . Staked ) ;
244+ const stakedTokensByValidators = stakedValidators . reduce ( ( acc , validator ) => acc + BigInt ( validator . stakeAmount ) , BigInt ( 0 ) ) ;
245+
246+ return {
247+ stakedValidators : stakedValidators . length ,
248+ stakedTokensByValidators : stakedTokensByValidators ,
249+ } ;
250+ }
251+
252+ async function getUnstakingValidatorsData ( ) {
253+ const unstakingValidators = await fetchAllValidatorByStatus ( StakeStatus . Unstaking ) ;
254+ const unstakingTokensByValidators = unstakingValidators . reduce ( ( acc , validator ) => acc + BigInt ( validator . stakeAmount ) , BigInt ( 0 ) ) ;
255+
256+ return {
257+ unstakingValidators : unstakingValidators . length ,
258+ unstakingTokensByValidators,
259+ } ;
260+ }
261+
233262async function getTook ( block : CosmosBlock ) {
234263 if ( block . header . height === 1 ) {
235264 return 0 ;
0 commit comments