This client enables to obtain statistical information from the subgraph.
Unlikely from the other SDK clients, StatisticsClient does not require signer or provider to be provided. We just need to create client object using relevant network data.
constructor(network: NetworkData)
A Signer or a Provider should be passed depending on the use case of this module:
Signer: when the user wants to use this model in order to send transactions caling the contract functions.
Provider: when the user wants to use this model in order to get information from the contracts or subgraph.
Installation
npm
npm install @human-protocol/sdk
yarn
yarn install @human-protocol/sdk
Code example
import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
This function returns the statistical data of escrows.
Input parameters
interface IStatisticsFilter {
from?: Date;
to?: Date;
first?: number; // (Optional) Number of transactions per page. Default is 10.
skip?: number; // (Optional) Number of transactions to skip. Default is 0.
orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
}
This function returns the statistical data of HMToken day by day.
Input parameters
interface IStatisticsFilter {
from?: Date;
to?: Date;
first?: number; // (Optional) Number of transactions per page. Default is 10.
skip?: number; // (Optional) Number of transactions to skip. Default is 0.
orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
}
This function returns the statistical data of payments.
Input parameters
interface IStatisticsFilter {
from?: Date;
to?: Date;
first?: number; // (Optional) Number of transactions per page. Default is 10.
skip?: number; // (Optional) Number of transactions to skip. Default is 0.
orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
}
type DailyPaymentData = {
timestamp: Date;
totalAmountPaid: BigNumber;
totalCount: number;
averageAmountPerWorker: BigNumber;
};
type PaymentStatistics = {
dailyPaymentsData: DailyPaymentData[];
};
This function returns the statistical data of workers.
Input parameters
interface IStatisticsFilter {
from?: Date;
to?: Date;
first?: number; // (Optional) Number of transactions per page. Default is 10.
skip?: number; // (Optional) Number of transactions to skip. Default is 0.
orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
}
type DailyWorkerData = {
timestamp: Date;
activeWorkers: number;
};
type WorkerStatistics = {
dailyWorkersData: DailyWorkerData[];
};
Parameters
• filter: IStatisticsFilter = {}
Statistics params with duration data
Returns
Promise<WorkerStatistics>
Worker statistics data.
Code example
import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
const workerStatistics = await statisticsClient.getWorkerStatistics();
const workerStatisticsApril = await statisticsClient.getWorkerStatistics({
from: new Date('2021-04-01'),
to: new Date('2021-04-30'),
});