@@ -20,7 +20,7 @@ import {
2020 fetchAllSupplierByStatus ,
2121 fetchAllSupplierByUnstakingEndBlockId ,
2222 fetchAllSupplierServiceConfigBySupplier ,
23- fetchAllTransactions ,
23+ fetchAllTransactions , fetchAllValidatorByStatus ,
2424} from "./pagination" ;
2525
2626export async function handleAddBlockReports ( block : CosmosBlock ) : Promise < void > {
@@ -44,6 +44,8 @@ export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
4444 { unstakedApps, unstakedTokensByApp } ,
4545 { stakedGateways, stakedTokensByGateway } ,
4646 { unstakedGateways, unstakedTokensByGateway } ,
47+ { stakedTokensByValidators, stakedValidators } ,
48+ { unstakingTokensByValidators, unstakingValidators }
4749 ] = await Promise . all ( [
4850 getRelaysData ( blockHeight ) ,
4951 getTransactionsData ( blockHeight ) ,
@@ -56,6 +58,8 @@ export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
5658 getUnstakedAppsData ( blockHeight ) ,
5759 getStakedGatewaysData ( ) ,
5860 getUnstakedGatewaysData ( blockHeight ) ,
61+ getStakedValidatorsData ( ) ,
62+ getUnstakingValidatorsData ( ) ,
5963 ] ) ;
6064
6165 blockEntity . totalComputedUnits = computedUnits ;
@@ -80,6 +84,10 @@ export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
8084 blockEntity . stakedGatewaysTokens = stakedTokensByGateway ;
8185 blockEntity . unstakedGateways = unstakedGateways ;
8286 blockEntity . unstakedGatewaysTokens = unstakedTokensByGateway ;
87+ blockEntity . stakedValidators = stakedValidators ;
88+ blockEntity . stakedValidatorsTokens = stakedTokensByValidators ;
89+ blockEntity . unstakingValidators = unstakingValidators ;
90+ blockEntity . unstakingValidatorsTokens = unstakingTokensByValidators ;
8391
8492 await Promise . all ( [
8593 blockEntity . save ( ) ,
@@ -230,6 +238,26 @@ async function getUnstakingSuppliersData() {
230238 } ;
231239}
232240
241+ async function getStakedValidatorsData ( ) {
242+ const stakedValidators = await fetchAllValidatorByStatus ( StakeStatus . Staked ) ;
243+ const stakedTokensByValidators = stakedValidators . reduce ( ( acc , validator ) => acc + BigInt ( validator . stakeAmount ) , BigInt ( 0 ) ) ;
244+
245+ return {
246+ stakedValidators : stakedValidators . length ,
247+ stakedTokensByValidators : stakedTokensByValidators ,
248+ } ;
249+ }
250+
251+ async function getUnstakingValidatorsData ( ) {
252+ const unstakingValidators = await fetchAllValidatorByStatus ( StakeStatus . Unstaking ) ;
253+ const unstakingTokensByValidators = unstakingValidators . reduce ( ( acc , validator ) => acc + BigInt ( validator . stakeAmount ) , BigInt ( 0 ) ) ;
254+
255+ return {
256+ unstakingValidators : unstakingValidators . length ,
257+ unstakingTokensByValidators,
258+ } ;
259+ }
260+
233261async function getTook ( block : CosmosBlock ) {
234262 if ( block . header . height === 1 ) {
235263 return 0 ;
0 commit comments