Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ type Block @entity {
stakedGatewaysTokens: BigInt
unstakedGateways: Int
unstakedGatewaysTokens: BigInt
stakedValidators: Int
stakedValidatorsTokens: BigInt
unstakingValidators: Int
unstakingValidatorsTokens: BigInt
}

# This handle all the information that is coming with the block but is not often used
Expand Down
14 changes: 14 additions & 0 deletions src/mappings/poktroll/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Supplier,
SupplierServiceConfig,
Transaction,
Validator,
} from "../../types";
import { fetchPaginatedRecords } from "../utils/db";

Expand Down Expand Up @@ -105,6 +106,19 @@ export async function fetchAllSupplierByUnstakingEndBlockId(blockId: bigint): Pr
});
}

// validator

export async function fetchAllValidatorByStatus(status: StakeStatus): Promise<Validator[]> {
return fetchPaginatedRecords({
fetchFn: (options) => Validator.getByStakeStatus(status, options),
initialOptions: {
// add order and direction to speedup if there is a way
// orderBy: 'id', // Order results by ID
// orderDirection: 'ASC', // Ascending order
},
});
}

// gateway

export async function fetchAllGatewayByStatus(status: StakeStatus): Promise<Gateway[]> {
Expand Down
29 changes: 29 additions & 0 deletions src/mappings/poktroll/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
fetchAllSupplierByUnstakingEndBlockId,
fetchAllSupplierServiceConfigBySupplier,
fetchAllTransactions,
fetchAllValidatorByStatus,
} from "./pagination";

export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
Expand All @@ -44,6 +45,8 @@ export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
{ unstakedApps, unstakedTokensByApp },
{ stakedGateways, stakedTokensByGateway },
{ unstakedGateways, unstakedTokensByGateway },
{ stakedTokensByValidators, stakedValidators },
{ unstakingTokensByValidators, unstakingValidators }
] = await Promise.all([
getRelaysData(blockHeight),
getTransactionsData(blockHeight),
Expand All @@ -56,6 +59,8 @@ export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
getUnstakedAppsData(blockHeight),
getStakedGatewaysData(),
getUnstakedGatewaysData(blockHeight),
getStakedValidatorsData(),
getUnstakingValidatorsData(),
]);

blockEntity.totalComputedUnits = computedUnits;
Expand All @@ -80,6 +85,10 @@ export async function handleAddBlockReports(block: CosmosBlock): Promise<void> {
blockEntity.stakedGatewaysTokens = stakedTokensByGateway;
blockEntity.unstakedGateways = unstakedGateways;
blockEntity.unstakedGatewaysTokens = unstakedTokensByGateway;
blockEntity.stakedValidators = stakedValidators;
blockEntity.stakedValidatorsTokens = stakedTokensByValidators;
blockEntity.unstakingValidators = unstakingValidators;
blockEntity.unstakingValidatorsTokens = unstakingTokensByValidators;

await Promise.all([
blockEntity.save(),
Expand Down Expand Up @@ -230,6 +239,26 @@ async function getUnstakingSuppliersData() {
};
}

async function getStakedValidatorsData() {
const stakedValidators = await fetchAllValidatorByStatus(StakeStatus.Staked);
const stakedTokensByValidators = stakedValidators.reduce((acc, validator) => acc + BigInt(validator.stakeAmount), BigInt(0));

return {
stakedValidators: stakedValidators.length,
stakedTokensByValidators: stakedTokensByValidators,
};
}

async function getUnstakingValidatorsData() {
const unstakingValidators = await fetchAllValidatorByStatus(StakeStatus.Unstaking);
const unstakingTokensByValidators = unstakingValidators.reduce((acc, validator) => acc + BigInt(validator.stakeAmount), BigInt(0));

return {
unstakingValidators: unstakingValidators.length,
unstakingTokensByValidators,
};
}

async function getTook(block: CosmosBlock) {
if (block.header.height === 1) {
return 0;
Expand Down
Loading