StatisticsClient

@human-protocol/sdk


@human-protocol/sdk / statistics / StatisticsClient

Class: StatisticsClient

Defined in: statistics.ts:60

Introduction

This client enables obtaining statistical information from the subgraph.

Unlike other SDK clients, StatisticsClient does not require signer or provider to be provided. We just need to create a client object using relevant network data.

constructor(network: NetworkData)

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]);

Constructors

Constructor

new StatisticsClient(networkData): StatisticsClient

Defined in: statistics.ts:69

StatisticsClient constructor

Parameters

networkData

NetworkData

The network information required to connect to the Statistics contract

Returns

StatisticsClient

Properties

networkData

networkData: NetworkData

Defined in: statistics.ts:61


subgraphUrl

subgraphUrl: string

Defined in: statistics.ts:62

Methods

getEscrowStatistics()

getEscrowStatistics(filter): Promise<IEscrowStatistics>

Defined in: statistics.ts:122

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.
}
interface IDailyEscrow {
  timestamp: number;
  escrowsTotal: number;
  escrowsPending: number;
  escrowsSolved: number;
  escrowsPaid: number;
  escrowsCancelled: number;
};

interface IEscrowStatistics {
  totalEscrows: number;
  dailyEscrowsData: IDailyEscrow[];
};

Parameters

filter

IStatisticsFilter = {}

Statistics params with duration data

Returns

Promise<IEscrowStatistics>

Escrow statistics data.

Code example

import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';

const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);

const escrowStatistics = await statisticsClient.getEscrowStatistics();
const escrowStatisticsApril = await statisticsClient.getEscrowStatistics({
   from: new Date('2021-04-01'),
   to: new Date('2021-04-30'),
});

getHMTDailyData()

getHMTDailyData(filter): Promise<IDailyHMT[]>

Defined in: statistics.ts:478

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.
}
interface IDailyHMT {
  timestamp: number;
  totalTransactionAmount: bigint;
  totalTransactionCount: number;
  dailyUniqueSenders: number;
  dailyUniqueReceivers: number;
}

Parameters

filter

IStatisticsFilter = {}

Statistics params with duration data

Returns

Promise<IDailyHMT[]>

Daily HMToken statistics data.

Code example

import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';

const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);

const dailyHMTStats = await statisticsClient.getHMTStatistics();

console.log('Daily HMT statistics:', dailyHMTStats);

const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
  from: new Date(2023, 4, 8),
  to: new Date(2023, 5, 8),
});

console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);

getHMTHolders()

getHMTHolders(params): Promise<IHMTHolder[]>

Defined in: statistics.ts:407

This function returns the holders of the HMToken with optional filters and ordering.

Input parameters

Parameters

params

IHMTHoldersParams = {}

HMT Holders params with filters and ordering

Returns

Promise<IHMTHolder[]>

List of HMToken holders.

Code example

import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';

const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);

const hmtHolders = await statisticsClient.getHMTHolders({
  orderDirection: 'asc',
});

console.log('HMT holders:', hmtHolders.map((h) => ({
  ...h,
  balance: h.balance.toString(),
})));

getHMTStatistics()

getHMTStatistics(): Promise<IHMTStatistics>

Defined in: statistics.ts:366

This function returns the statistical data of HMToken.

interface IHMTStatistics {
  totalTransferAmount: bigint;
  totalTransferCount: number;
  totalHolders: number;
};

Returns

Promise<IHMTStatistics>

HMToken statistics data.

Code example

import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';

const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);

const hmtStatistics = await statisticsClient.getHMTStatistics();

console.log('HMT statistics:', {
  ...hmtStatistics,
  totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
});

getPaymentStatistics()

getPaymentStatistics(filter): Promise<IPaymentStatistics>

Defined in: statistics.ts:302

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.
}
interface IDailyPayment {
  timestamp: number;
  totalAmountPaid: bigint;
  totalCount: number;
  averageAmountPerWorker: bigint;
};

interface IPaymentStatistics {
  dailyPaymentsData: IDailyPayment[];
};

Parameters

filter

IStatisticsFilter = {}

Statistics params with duration data

Returns

Promise<IPaymentStatistics>

Payment statistics data.

Code example

import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';

const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);

console.log(
  'Payment statistics:',
  (await statisticsClient.getPaymentStatistics()).dailyPaymentsData.map(
    (p) => ({
      ...p,
      totalAmountPaid: p.totalAmountPaid.toString(),
      averageAmountPerJob: p.averageAmountPerJob.toString(),
      averageAmountPerWorker: p.averageAmountPerWorker.toString(),
    })
  )
);

console.log(
  'Payment statistics from 5/8 - 6/8:',
  (
    await statisticsClient.getPaymentStatistics({
      from: new Date(2023, 4, 8),
      to: new Date(2023, 5, 8),
    })
  ).dailyPaymentsData.map((p) => ({
    ...p,
    totalAmountPaid: p.totalAmountPaid.toString(),
    averageAmountPerJob: p.averageAmountPerJob.toString(),
    averageAmountPerWorker: p.averageAmountPerWorker.toString(),
  }))
);

getWorkerStatistics()

getWorkerStatistics(filter): Promise<IWorkerStatistics>

Defined in: statistics.ts:206

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.
}
interface IDailyWorker {
  timestamp: number;
  activeWorkers: number;
};

interface IWorkerStatistics {
  dailyWorkersData: IDailyWorker[];
};

Parameters

filter

IStatisticsFilter = {}

Statistics params with duration data

Returns

Promise<IWorkerStatistics>

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'),
});

Last updated