@human-protocol/sdk 4.0.3 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/escrow.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { ContractRunner, Overrides } from 'ethers';
2
2
  import { BaseEthersClient } from './base';
3
- import { ChainId, OrderDirection } from './enums';
3
+ import { ChainId } from './enums';
4
4
  import { EscrowData, StatusEvent } from './graphql';
5
- import { IEscrowConfig, IEscrowsFilter } from './interfaces';
6
- import { EscrowCancel, EscrowStatus, EscrowWithdraw, NetworkData, TransactionLikeWithNonce } from './types';
5
+ import { IEscrowConfig, IEscrowsFilter, IPayoutFilter, IStatusEventFilter } from './interfaces';
6
+ import { EscrowCancel, EscrowStatus, EscrowWithdraw, NetworkData, TransactionLikeWithNonce, Payout } from './types';
7
7
  /**
8
8
  * ## Introduction
9
9
  *
@@ -895,14 +895,7 @@ export declare class EscrowUtils {
895
895
  * };
896
896
  * ```
897
897
  *
898
- * @param {ChainId} chainId - List of network IDs to query for status events.
899
- * @param {EscrowStatus[]} [statuses] - Optional array of statuses to query for. If not provided, queries for all statuses.
900
- * @param {Date} [from] - Optional start date to filter events.
901
- * @param {Date} [to] - Optional end date to filter events.
902
- * @param {string} [launcher] - Optional launcher address to filter events. Must be a valid Ethereum address.
903
- * @param {number} [first] - Optional number of transactions per page. Default is 10.
904
- * @param {number} [skip] - Optional number of transactions to skip. Default is 0.
905
- * @param {OrderDirection} [orderDirection] - Optional order of the results. Default is DESC.
898
+ * @param {IStatusEventFilter} filter Filter parameters.
906
899
  * @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
907
900
  *
908
901
  * **Code example**
@@ -913,16 +906,43 @@ export declare class EscrowUtils {
913
906
  * (async () => {
914
907
  * const fromDate = new Date('2023-01-01');
915
908
  * const toDate = new Date('2023-12-31');
916
- * const statusEvents = await EscrowUtils.getStatusEvents(
917
- * [ChainId.POLYGON, ChainId.MAINNET],
918
- * [EscrowStatus.Pending, EscrowStatus.Complete],
919
- * fromDate,
920
- * toDate
921
- * );
909
+ * const statusEvents = await EscrowUtils.getStatusEvents({
910
+ * chainId: ChainId.POLYGON,
911
+ * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
912
+ * from: fromDate,
913
+ * to: toDate
914
+ * });
922
915
  * console.log(statusEvents);
923
916
  * })();
924
917
  * ```
925
918
  */
926
- static getStatusEvents(chainId: ChainId, statuses?: EscrowStatus[], from?: Date, to?: Date, launcher?: string, first?: number, skip?: number, orderDirection?: OrderDirection): Promise<StatusEvent[]>;
919
+ static getStatusEvents(filter: IStatusEventFilter): Promise<StatusEvent[]>;
920
+ /**
921
+ * This function returns the payouts for a given set of networks.
922
+ *
923
+ * > This uses Subgraph
924
+ *
925
+ * **Input parameters**
926
+ * Fetch payouts from the subgraph.
927
+ *
928
+ * @param {IPayoutFilter} filter Filter parameters.
929
+ * @returns {Promise<Payout[]>} List of payouts matching the filters.
930
+ *
931
+ * **Code example**
932
+ *
933
+ * ```ts
934
+ * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
935
+ *
936
+ * const payouts = await EscrowUtils.getPayouts({
937
+ * chainId: ChainId.POLYGON,
938
+ * escrowAddress: '0x1234567890123456789012345678901234567890',
939
+ * recipient: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
940
+ * from: new Date('2023-01-01'),
941
+ * to: new Date('2023-12-31')
942
+ * });
943
+ * console.log(payouts);
944
+ * ```
945
+ */
946
+ static getPayouts(filter: IPayoutFilter): Promise<Payout[]>;
927
947
  }
928
948
  //# sourceMappingURL=escrow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../src/escrow.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAY,SAAS,EAAkB,MAAM,QAAQ,CAAC;AAE7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG1C,OAAO,EAAE,O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AM,GAAG,OAAO,CAAC,MAAM,CAAC;CAiBhE;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,WAAW;IACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+FG;WACiB,UAAU,CAC5B,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,UAAU,EAAE,CAAC;IA2DxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwDG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,UAAU,CAAC;IAoBtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuDG;WACiB,eAAe,CACjC,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,WAAW,EAAE,CAAC;IA+DzB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;WACiB,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAiCzE"}
package/dist/escrow.js CHANGED
@@ -1536,14 +1536,7 @@ class EscrowUtils {
1536
1536
  * };
1537
1537
  * ```
1538
1538
  *
1539
- * @param {ChainId} chainId - List of network IDs to query for status events.
1540
- * @param {EscrowStatus[]} [statuses] - Optional array of statuses to query for. If not provided, queries for all statuses.
1541
- * @param {Date} [from] - Optional start date to filter events.
1542
- * @param {Date} [to] - Optional end date to filter events.
1543
- * @param {string} [launcher] - Optional launcher address to filter events. Must be a valid Ethereum address.
1544
- * @param {number} [first] - Optional number of transactions per page. Default is 10.
1545
- * @param {number} [skip] - Optional number of transactions to skip. Default is 0.
1546
- * @param {OrderDirection} [orderDirection] - Optional order of the results. Default is DESC.
1539
+ * @param {IStatusEventFilter} filter Filter parameters.
1547
1540
  * @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
1548
1541
  *
1549
1542
  * **Code example**
@@ -1554,23 +1547,25 @@ class EscrowUtils {
1554
1547
  * (async () => {
1555
1548
  * const fromDate = new Date('2023-01-01');
1556
1549
  * const toDate = new Date('2023-12-31');
1557
- * const statusEvents = await EscrowUtils.getStatusEvents(
1558
- * [ChainId.POLYGON, ChainId.MAINNET],
1559
- * [EscrowStatus.Pending, EscrowStatus.Complete],
1560
- * fromDate,
1561
- * toDate
1562
- * );
1550
+ * const statusEvents = await EscrowUtils.getStatusEvents({
1551
+ * chainId: ChainId.POLYGON,
1552
+ * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
1553
+ * from: fromDate,
1554
+ * to: toDate
1555
+ * });
1563
1556
  * console.log(statusEvents);
1564
1557
  * })();
1565
1558
  * ```
1566
1559
  */
1567
- static async getStatusEvents(chainId, statuses, from, to, launcher, first, skip, orderDirection) {
1560
+ static async getStatusEvents(filter) {
1561
+ const { chainId, statuses, from, to, launcher, first = 10, skip = 0, orderDirection = enums_1.OrderDirection.DESC, } = filter;
1568
1562
  if (launcher && !ethers_1.ethers.isAddress(launcher)) {
1569
1563
  throw error_1.ErrorInvalidAddress;
1570
1564
  }
1571
- first = first !== undefined ? Math.min(first, 1000) : 10;
1572
- skip = skip || 0;
1573
- orderDirection = orderDirection || enums_1.OrderDirection.DESC;
1565
+ const networkData = constants_1.NETWORKS[chainId];
1566
+ if (!networkData) {
1567
+ throw error_1.ErrorUnsupportedChainID;
1568
+ }
1574
1569
  // If statuses are not provided, use all statuses except Launched
1575
1570
  const effectiveStatuses = statuses ?? [
1576
1571
  types_1.EscrowStatus.Launched,
@@ -1580,19 +1575,15 @@ class EscrowUtils {
1580
1575
  types_1.EscrowStatus.Complete,
1581
1576
  types_1.EscrowStatus.Cancelled,
1582
1577
  ];
1583
- const networkData = constants_1.NETWORKS[chainId];
1584
- if (!networkData) {
1585
- throw error_1.ErrorUnsupportedChainID;
1586
- }
1587
1578
  const statusNames = effectiveStatuses.map((status) => types_1.EscrowStatus[status]);
1588
1579
  const data = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_STATUS_UPDATES_QUERY)(from, to, launcher), {
1589
1580
  status: statusNames,
1590
1581
  from: from ? (0, utils_1.getUnixTimestamp)(from) : undefined,
1591
1582
  to: to ? (0, utils_1.getUnixTimestamp)(to) : undefined,
1592
1583
  launcher: launcher || undefined,
1593
- orderDirection: orderDirection,
1594
- first: first,
1595
- skip: skip,
1584
+ orderDirection,
1585
+ first: Math.min(first, 1000),
1586
+ skip,
1596
1587
  });
1597
1588
  if (!data || !data['escrowStatusEvents']) {
1598
1589
  return [];
@@ -1604,5 +1595,56 @@ class EscrowUtils {
1604
1595
  }));
1605
1596
  return eventsWithChainId;
1606
1597
  }
1598
+ /**
1599
+ * This function returns the payouts for a given set of networks.
1600
+ *
1601
+ * > This uses Subgraph
1602
+ *
1603
+ * **Input parameters**
1604
+ * Fetch payouts from the subgraph.
1605
+ *
1606
+ * @param {IPayoutFilter} filter Filter parameters.
1607
+ * @returns {Promise<Payout[]>} List of payouts matching the filters.
1608
+ *
1609
+ * **Code example**
1610
+ *
1611
+ * ```ts
1612
+ * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1613
+ *
1614
+ * const payouts = await EscrowUtils.getPayouts({
1615
+ * chainId: ChainId.POLYGON,
1616
+ * escrowAddress: '0x1234567890123456789012345678901234567890',
1617
+ * recipient: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
1618
+ * from: new Date('2023-01-01'),
1619
+ * to: new Date('2023-12-31')
1620
+ * });
1621
+ * console.log(payouts);
1622
+ * ```
1623
+ */
1624
+ static async getPayouts(filter) {
1625
+ const networkData = constants_1.NETWORKS[filter.chainId];
1626
+ if (!networkData) {
1627
+ throw error_1.ErrorUnsupportedChainID;
1628
+ }
1629
+ if (filter.escrowAddress && !ethers_1.ethers.isAddress(filter.escrowAddress)) {
1630
+ throw error_1.ErrorInvalidAddress;
1631
+ }
1632
+ if (filter.recipient && !ethers_1.ethers.isAddress(filter.recipient)) {
1633
+ throw error_1.ErrorInvalidAddress;
1634
+ }
1635
+ const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
1636
+ const skip = filter.skip || 0;
1637
+ const orderDirection = filter.orderDirection || enums_1.OrderDirection.DESC;
1638
+ const { payouts } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, graphql_1.GET_PAYOUTS_QUERY)(filter), {
1639
+ escrowAddress: filter.escrowAddress?.toLowerCase(),
1640
+ recipient: filter.recipient?.toLowerCase(),
1641
+ from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
1642
+ to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
1643
+ first: Math.min(first, 1000),
1644
+ skip,
1645
+ orderDirection,
1646
+ });
1647
+ return payouts || [];
1648
+ }
1607
1649
  }
1608
1650
  exports.EscrowUtils = EscrowUtils;
@@ -1,3 +1,3 @@
1
- import { IPayoutFilter } from '../../interfaces';
1
+ import { IPayoutFilter } from 'src/interfaces';
2
2
  export declare const GET_PAYOUTS_QUERY: (filter: IPayoutFilter) => import("graphql").DocumentNode;
3
3
  //# sourceMappingURL=payout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"payout.d.ts","sourceRoot":"","sources":["../../../src/graphql/queries/payout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAYjD,eAAO,MAAM,iBAAiB,WAAY,aAAa,mCAiCtD,CAAC"}
1
+ {"version":3,"file":"payout.d.ts","sourceRoot":"","sources":["../../../src/graphql/queries/payout.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAY/C,eAAO,MAAM,iBAAiB,WAAY,aAAa,mCAkCtD,CAAC"}
@@ -23,9 +23,6 @@ const GET_PAYOUTS_QUERY = (filter) => {
23
23
  ${from ? `createdAt_gte: $from` : ''}
24
24
  ${to ? `createdAt_lt: $to` : ''}
25
25
  }
26
- `;
27
- const LIMIT_CLAUSE = `
28
- first: 1000
29
26
  `;
30
27
  return (0, graphql_tag_1.default) `
31
28
  query getPayouts(
@@ -33,12 +30,16 @@ const GET_PAYOUTS_QUERY = (filter) => {
33
30
  $recipient: String
34
31
  $from: Int
35
32
  $to: Int
33
+ $first: Int
34
+ $skip: Int
35
+ $orderDirection: String
36
36
  ) {
37
37
  payouts(
38
38
  ${WHERE_CLAUSE}
39
39
  orderBy: createdAt,
40
- orderDirection: desc,
41
- ${LIMIT_CLAUSE}
40
+ orderDirection: $orderDirection,
41
+ first: $first,
42
+ skip: $skip
42
43
  ) {
43
44
  ...PayoutFields
44
45
  }
@@ -0,0 +1,4 @@
1
+ import { IWorkersFilter } from '../../interfaces';
2
+ export declare const GET_WORKER_QUERY: import("graphql").DocumentNode;
3
+ export declare const GET_WORKERS_QUERY: (filter: IWorkersFilter) => import("graphql").DocumentNode;
4
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/graphql/queries/worker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,eAAO,MAAM,gBAAgB,gCAS5B,CAAC;AAEF,eAAO,MAAM,iBAAiB,WAAY,cAAc,mCA0BvD,CAAC"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GET_WORKERS_QUERY = exports.GET_WORKER_QUERY = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ exports.GET_WORKER_QUERY = (0, graphql_tag_1.default) `
9
+ query GetWorker($address: String!) {
10
+ worker(id: $address) {
11
+ id
12
+ address
13
+ totalAmountReceived
14
+ payoutCount
15
+ }
16
+ }
17
+ `;
18
+ const GET_WORKERS_QUERY = (filter) => {
19
+ const { address } = filter;
20
+ return (0, graphql_tag_1.default) `
21
+ query GetWorkers(
22
+ $address: String
23
+ $first: Int
24
+ $skip: Int
25
+ $orderBy: String
26
+ $orderDirection: String
27
+ ) {
28
+ workers(
29
+ where: {
30
+ ${address ? 'address: $address,' : ''}
31
+ }
32
+ first: $first
33
+ skip: $skip
34
+ orderBy: $orderBy
35
+ orderDirection: $orderDirection
36
+ ) {
37
+ id
38
+ address
39
+ totalAmountReceived
40
+ payoutCount
41
+ }
42
+ }`;
43
+ };
44
+ exports.GET_WORKERS_QUERY = GET_WORKERS_QUERY;
package/dist/index.d.ts CHANGED
@@ -6,9 +6,10 @@ import { StatisticsClient } from './statistics';
6
6
  import { Encryption, EncryptionUtils } from './encryption';
7
7
  import { OperatorUtils } from './operator';
8
8
  import { TransactionUtils } from './transaction';
9
+ import { WorkerUtils } from './worker';
9
10
  export * from './constants';
10
11
  export * from './types';
11
12
  export * from './enums';
12
13
  export * from './interfaces';
13
- export { StakingClient, StorageClient, KVStoreClient, KVStoreUtils, EscrowClient, EscrowUtils, StatisticsClient, Encryption, EncryptionUtils, OperatorUtils, TransactionUtils, };
14
+ export { StakingClient, StorageClient, KVStoreClient, KVStoreUtils, EscrowClient, EscrowUtils, StatisticsClient, Encryption, EncryptionUtils, OperatorUtils, TransactionUtils, WorkerUtils, };
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,C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f,aAAa,EACb,gBAAgB,EAChB,WAAW,GACZ,CAAC"}
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.TransactionUtils = exports.OperatorUtils = exports.EncryptionUtils = exports.Encryption = exports.StatisticsClient = exports.EscrowUtils = exports.EscrowClient = exports.KVStoreUtils = exports.KVStoreClient = exports.StorageClient = exports.StakingClient = void 0;
17
+ exports.WorkerUtils = exports.TransactionUtils = exports.OperatorUtils = exports.EncryptionUtils = exports.Encryption = exports.StatisticsClient = exports.EscrowUtils = exports.EscrowClient = exports.KVStoreUtils = exports.KVStoreClient = exports.StorageClient = exports.StakingClient = void 0;
18
18
  const staking_1 = require("./staking");
19
19
  Object.defineProperty(exports, "StakingClient", { enumerable: true, get: function () { return staking_1.StakingClient; } });
20
20
  const storage_1 = require("./storage");
@@ -34,6 +34,8 @@ const operator_1 = require("./operator");
34
34
  Object.defineProperty(exports, "OperatorUtils", { enumerable: true, get: function () { return operator_1.OperatorUtils; } });
35
35
  const transaction_1 = require("./transaction");
36
36
  Object.defineProperty(exports, "TransactionUtils", { enumerable: true, get: function () { return transaction_1.TransactionUtils; } });
37
+ const worker_1 = require("./worker");
38
+ Object.defineProperty(exports, "WorkerUtils", { enumerable: true, get: function () { return worker_1.WorkerUtils; } });
37
39
  __exportStar(require("./constants"), exports);
38
40
  __exportStar(require("./types"), exports);
39
41
  __exportStar(require("./enums"), exports);
@@ -90,7 +90,8 @@ export interface IStatisticsFilter extends IPagination {
90
90
  export interface IHMTHoldersParams extends IPagination {
91
91
  address?: string;
92
92
  }
93
- export interface IPayoutFilter {
93
+ export interface IPayoutFilter extends IPagination {
94
+ chainId: ChainId;
94
95
  escrowAddress?: string;
95
96
  recipient?: string;
96
97
  from?: Date;
@@ -142,4 +143,22 @@ export interface StakerInfo {
142
143
  lockedUntil: bigint;
143
144
  withdrawableAmount: bigint;
144
145
  }
146
+ export interface IStatusEventFilter extends IPagination {
147
+ chainId: ChainId;
148
+ statuses?: EscrowStatus[];
149
+ from?: Date;
150
+ to?: Date;
151
+ launcher?: string;
152
+ }
153
+ export interface IWorker {
154
+ id: string;
155
+ address: string;
156
+ totalAmountReceived: number;
157
+ payoutCount: number;
158
+ }
159
+ export interface IWorkersFilter extends IPagination {
160
+ chainId: ChainId;
161
+ address?: string;
162
+ orderBy?: string;
163
+ }
145
164
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAElD,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,EAAE,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,E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GED
@@ -163,6 +163,31 @@ export type EscrowWithdraw = {
163
163
  */
164
164
  amountWithdrawn: bigint;
165
165
  };
166
+ /**
167
+ * Represents a payout from an escrow.
168
+ */
169
+ export type Payout = {
170
+ /**
171
+ * Unique identifier of the payout.
172
+ */
173
+ id: string;
174
+ /**
175
+ * The address of the escrow associated with the payout.
176
+ */
177
+ escrowAddress: string;
178
+ /**
179
+ * The address of the recipient who received the payout.
180
+ */
181
+ recipient: string;
182
+ /**
183
+ * The amount paid to the recipient.
184
+ */
185
+ amount: bigint;
186
+ /**
187
+ * The timestamp when the payout was created (in UNIX format).
188
+ */
189
+ createdAt: number;
190
+ };
166
191
  export type TransactionLikeWithNonce = TransactionLike & {
167
192
  nonce: number;
168
193
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;CACV;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IAC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C;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,eAAe,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { ChainId } from './enums';
2
+ import { IWorker, IWorkersFilter } from './interfaces';
3
+ export declare class WorkerUtils {
4
+ /**
5
+ * This function returns the worker data for the given address.
6
+ *
7
+ * @param {ChainId} chainId The chain ID.
8
+ * @param {string} address The worker address.
9
+ * @returns {Promise<IWorker>} Returns the worker details.
10
+ *
11
+ * **Code example**
12
+ *
13
+ * ```ts
14
+ * import { WorkerUtils, ChainId } from '@human-protocol/sdk';
15
+ *
16
+ * const worker = await WorkerUtils.getWorker(ChainId.POLYGON, '0x1234567890abcdef1234567890abcdef12345678');
17
+ * ```
18
+ */
19
+ static getWorker(chainId: ChainId, address: string): Promise<IWorker | null>;
20
+ /**
21
+ * This function returns all worker details based on the provided filter.
22
+ *
23
+ * **Input parameters**
24
+ *
25
+ * ```ts
26
+ * interface IWorkersFilter {
27
+ * chainId: ChainId; // List of chain IDs to query.
28
+ * address?: string; // (Optional) The worker address to filter by.
29
+ * orderBy?: string; // (Optional) The field to order by. Default is 'payoutCount'.
30
+ * orderDirection?: OrderDirection; // (Optional) The direction of the order. Default is 'DESC'.
31
+ * first?: number; // (Optional) Number of workers per page. Default is 10.
32
+ * skip?: number; // (Optional) Number of workers to skip. Default is 0.
33
+ * }
34
+ * ```
35
+ *
36
+ * ```ts
37
+ * type IWorker = {
38
+ * id: string;
39
+ * address: string;
40
+ * totalAmountReceived: string;
41
+ * payoutCount: number;
42
+ * };
43
+ * ```
44
+ *
45
+ * @param {IWorkersFilter} filter Filter for the workers.
46
+ * @returns {Promise<IWorker[]>} Returns an array with all the worker details.
47
+ *
48
+ * **Code example**
49
+ *
50
+ * ```ts
51
+ * import { WorkerUtils, ChainId } from '@human-protocol/sdk';
52
+ *
53
+ * const filter: IWorkersFilter = {
54
+ * chainId: ChainId.POLYGON,
55
+ * first: 10,
56
+ * skip: 0,
57
+ * };
58
+ * const workers = await WorkerUtils.getWorkers(filter);
59
+ * ```
60
+ */
61
+ static getWorkers(filter: IWorkersFilter): Promise<IWorker[]>;
62
+ }
63
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAGlD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAIvD,qBAAa,WAAW;IACtB;;;;;;;;;;;;;;OAcG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAmB1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;WACiB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CA+B3E"}
package/dist/worker.js ADDED
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WorkerUtils = void 0;
7
+ const graphql_request_1 = __importDefault(require("graphql-request"));
8
+ const constants_1 = require("./constants");
9
+ const enums_1 = require("./enums");
10
+ const error_1 = require("./error");
11
+ const worker_1 = require("./graphql/queries/worker");
12
+ const utils_1 = require("./utils");
13
+ const ethers_1 = require("ethers");
14
+ class WorkerUtils {
15
+ /**
16
+ * This function returns the worker data for the given address.
17
+ *
18
+ * @param {ChainId} chainId The chain ID.
19
+ * @param {string} address The worker address.
20
+ * @returns {Promise<IWorker>} Returns the worker details.
21
+ *
22
+ * **Code example**
23
+ *
24
+ * ```ts
25
+ * import { WorkerUtils, ChainId } from '@human-protocol/sdk';
26
+ *
27
+ * const worker = await WorkerUtils.getWorker(ChainId.POLYGON, '0x1234567890abcdef1234567890abcdef12345678');
28
+ * ```
29
+ */
30
+ static async getWorker(chainId, address) {
31
+ const networkData = constants_1.NETWORKS[chainId];
32
+ if (!networkData) {
33
+ throw error_1.ErrorUnsupportedChainID;
34
+ }
35
+ if (!ethers_1.ethers.isAddress(address)) {
36
+ throw error_1.ErrorInvalidAddress;
37
+ }
38
+ const { worker } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), worker_1.GET_WORKER_QUERY, {
39
+ address: address.toLowerCase(),
40
+ });
41
+ return worker || null;
42
+ }
43
+ /**
44
+ * This function returns all worker details based on the provided filter.
45
+ *
46
+ * **Input parameters**
47
+ *
48
+ * ```ts
49
+ * interface IWorkersFilter {
50
+ * chainId: ChainId; // List of chain IDs to query.
51
+ * address?: string; // (Optional) The worker address to filter by.
52
+ * orderBy?: string; // (Optional) The field to order by. Default is 'payoutCount'.
53
+ * orderDirection?: OrderDirection; // (Optional) The direction of the order. Default is 'DESC'.
54
+ * first?: number; // (Optional) Number of workers per page. Default is 10.
55
+ * skip?: number; // (Optional) Number of workers to skip. Default is 0.
56
+ * }
57
+ * ```
58
+ *
59
+ * ```ts
60
+ * type IWorker = {
61
+ * id: string;
62
+ * address: string;
63
+ * totalAmountReceived: string;
64
+ * payoutCount: number;
65
+ * };
66
+ * ```
67
+ *
68
+ * @param {IWorkersFilter} filter Filter for the workers.
69
+ * @returns {Promise<IWorker[]>} Returns an array with all the worker details.
70
+ *
71
+ * **Code example**
72
+ *
73
+ * ```ts
74
+ * import { WorkerUtils, ChainId } from '@human-protocol/sdk';
75
+ *
76
+ * const filter: IWorkersFilter = {
77
+ * chainId: ChainId.POLYGON,
78
+ * first: 10,
79
+ * skip: 0,
80
+ * };
81
+ * const workers = await WorkerUtils.getWorkers(filter);
82
+ * ```
83
+ */
84
+ static async getWorkers(filter) {
85
+ const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
86
+ const skip = filter.skip || 0;
87
+ const orderBy = filter.orderBy || 'payoutCount';
88
+ const orderDirection = filter.orderDirection || enums_1.OrderDirection.DESC;
89
+ const networkData = constants_1.NETWORKS[filter.chainId];
90
+ if (!networkData) {
91
+ throw error_1.ErrorUnsupportedChainID;
92
+ }
93
+ if (filter.address && !ethers_1.ethers.isAddress(filter.address)) {
94
+ throw error_1.ErrorInvalidAddress;
95
+ }
96
+ const { workers } = await (0, graphql_request_1.default)((0, utils_1.getSubgraphUrl)(networkData), (0, worker_1.GET_WORKERS_QUERY)(filter), {
97
+ address: filter?.address?.toLowerCase(),
98
+ first: first,
99
+ skip: skip,
100
+ orderBy: orderBy,
101
+ orderDirection: orderDirection,
102
+ });
103
+ if (!workers) {
104
+ return [];
105
+ }
106
+ return workers;
107
+ }
108
+ }
109
+ exports.WorkerUtils = WorkerUtils;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "4.0.3",
4
+ "version": "4.1.0",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -47,7 +47,7 @@
47
47
  "minio": "7.1.3",
48
48
  "openpgp": "^5.11.2",
49
49
  "secp256k1": "^5.0.1",
50
- "vitest": "^1.6.0"
50
+ "vitest": "^3.0.9"
51
51
  },
52
52
  "devDependencies": {
53
53
  "typedoc": "^0.27.5",
package/src/escrow.ts CHANGED
@@ -44,16 +44,23 @@ import {
44
44
  EscrowData,
45
45
  GET_ESCROWS_QUERY,
46
46
  GET_ESCROW_BY_ADDRESS_QUERY,
47
+ GET_PAYOUTS_QUERY,
47
48
  GET_STATUS_UPDATES_QUERY,
48
49
  StatusEvent,
49
50
  } from './graphql';
50
- import { IEscrowConfig, IEscrowsFilter } from './interfaces';
51
+ import {
52
+ IEscrowConfig,
53
+ IEscrowsFilter,
54
+ IPayoutFilter,
55
+ IStatusEventFilter,
56
+ } from './interfaces';
51
57
  import {
52
58
  EscrowCancel,
53
59
  EscrowStatus,
54
60
  EscrowWithdraw,
55
61
  NetworkData,
56
62
  TransactionLikeWithNonce,
63
+ Payout,
57
64
  } from './types';
58
65
  import {
59
66
  getSubgraphUrl,
@@ -1828,14 +1835,7 @@ export class EscrowUtils {
1828
1835
  * };
1829
1836
  * ```
1830
1837
  *
1831
- * @param {ChainId} chainId - List of network IDs to query for status events.
1832
- * @param {EscrowStatus[]} [statuses] - Optional array of statuses to query for. If not provided, queries for all statuses.
1833
- * @param {Date} [from] - Optional start date to filter events.
1834
- * @param {Date} [to] - Optional end date to filter events.
1835
- * @param {string} [launcher] - Optional launcher address to filter events. Must be a valid Ethereum address.
1836
- * @param {number} [first] - Optional number of transactions per page. Default is 10.
1837
- * @param {number} [skip] - Optional number of transactions to skip. Default is 0.
1838
- * @param {OrderDirection} [orderDirection] - Optional order of the results. Default is DESC.
1838
+ * @param {IStatusEventFilter} filter Filter parameters.
1839
1839
  * @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
1840
1840
  *
1841
1841
  * **Code example**
@@ -1846,34 +1846,38 @@ export class EscrowUtils {
1846
1846
  * (async () => {
1847
1847
  * const fromDate = new Date('2023-01-01');
1848
1848
  * const toDate = new Date('2023-12-31');
1849
- * const statusEvents = await EscrowUtils.getStatusEvents(
1850
- * [ChainId.POLYGON, ChainId.MAINNET],
1851
- * [EscrowStatus.Pending, EscrowStatus.Complete],
1852
- * fromDate,
1853
- * toDate
1854
- * );
1849
+ * const statusEvents = await EscrowUtils.getStatusEvents({
1850
+ * chainId: ChainId.POLYGON,
1851
+ * statuses: [EscrowStatus.Pending, EscrowStatus.Complete],
1852
+ * from: fromDate,
1853
+ * to: toDate
1854
+ * });
1855
1855
  * console.log(statusEvents);
1856
1856
  * })();
1857
1857
  * ```
1858
1858
  */
1859
-
1860
1859
  public static async getStatusEvents(
1861
- chainId: ChainId,
1862
- statuses?: EscrowStatus[],
1863
- from?: Date,
1864
- to?: Date,
1865
- launcher?: string,
1866
- first?: number,
1867
- skip?: number,
1868
- orderDirection?: OrderDirection
1860
+ filter: IStatusEventFilter
1869
1861
  ): Promise<StatusEvent[]> {
1862
+ const {
1863
+ chainId,
1864
+ statuses,
1865
+ from,
1866
+ to,
1867
+ launcher,
1868
+ first = 10,
1869
+ skip = 0,
1870
+ orderDirection = OrderDirection.DESC,
1871
+ } = filter;
1872
+
1870
1873
  if (launcher && !ethers.isAddress(launcher)) {
1871
1874
  throw ErrorInvalidAddress;
1872
1875
  }
1873
1876
 
1874
- first = first !== undefined ? Math.min(first, 1000) : 10;
1875
- skip = skip || 0;
1876
- orderDirection = orderDirection || OrderDirection.DESC;
1877
+ const networkData = NETWORKS[chainId];
1878
+ if (!networkData) {
1879
+ throw ErrorUnsupportedChainID;
1880
+ }
1877
1881
 
1878
1882
  // If statuses are not provided, use all statuses except Launched
1879
1883
  const effectiveStatuses = statuses ?? [
@@ -1885,11 +1889,6 @@ export class EscrowUtils {
1885
1889
  EscrowStatus.Cancelled,
1886
1890
  ];
1887
1891
 
1888
- const networkData = NETWORKS[chainId];
1889
- if (!networkData) {
1890
- throw ErrorUnsupportedChainID;
1891
- }
1892
-
1893
1892
  const statusNames = effectiveStatuses.map((status) => EscrowStatus[status]);
1894
1893
 
1895
1894
  const data = await gqlFetch<{
@@ -1902,9 +1901,9 @@ export class EscrowUtils {
1902
1901
  from: from ? getUnixTimestamp(from) : undefined,
1903
1902
  to: to ? getUnixTimestamp(to) : undefined,
1904
1903
  launcher: launcher || undefined,
1905
- orderDirection: orderDirection,
1906
- first: first,
1907
- skip: skip,
1904
+ orderDirection,
1905
+ first: Math.min(first, 1000),
1906
+ skip,
1908
1907
  }
1909
1908
  );
1910
1909
 
@@ -1921,4 +1920,64 @@ export class EscrowUtils {
1921
1920
 
1922
1921
  return eventsWithChainId;
1923
1922
  }
1923
+
1924
+ /**
1925
+ * This function returns the payouts for a given set of networks.
1926
+ *
1927
+ * > This uses Subgraph
1928
+ *
1929
+ * **Input parameters**
1930
+ * Fetch payouts from the subgraph.
1931
+ *
1932
+ * @param {IPayoutFilter} filter Filter parameters.
1933
+ * @returns {Promise<Payout[]>} List of payouts matching the filters.
1934
+ *
1935
+ * **Code example**
1936
+ *
1937
+ * ```ts
1938
+ * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1939
+ *
1940
+ * const payouts = await EscrowUtils.getPayouts({
1941
+ * chainId: ChainId.POLYGON,
1942
+ * escrowAddress: '0x1234567890123456789012345678901234567890',
1943
+ * recipient: '0xabcdefabcdefabcdefabcdefabcdefabcdefabcdef',
1944
+ * from: new Date('2023-01-01'),
1945
+ * to: new Date('2023-12-31')
1946
+ * });
1947
+ * console.log(payouts);
1948
+ * ```
1949
+ */
1950
+ public static async getPayouts(filter: IPayoutFilter): Promise<Payout[]> {
1951
+ const networkData = NETWORKS[filter.chainId];
1952
+ if (!networkData) {
1953
+ throw ErrorUnsupportedChainID;
1954
+ }
1955
+ if (filter.escrowAddress && !ethers.isAddress(filter.escrowAddress)) {
1956
+ throw ErrorInvalidAddress;
1957
+ }
1958
+ if (filter.recipient && !ethers.isAddress(filter.recipient)) {
1959
+ throw ErrorInvalidAddress;
1960
+ }
1961
+
1962
+ const first =
1963
+ filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
1964
+ const skip = filter.skip || 0;
1965
+ const orderDirection = filter.orderDirection || OrderDirection.DESC;
1966
+
1967
+ const { payouts } = await gqlFetch<{ payouts: Payout[] }>(
1968
+ getSubgraphUrl(networkData),
1969
+ GET_PAYOUTS_QUERY(filter),
1970
+ {
1971
+ escrowAddress: filter.escrowAddress?.toLowerCase(),
1972
+ recipient: filter.recipient?.toLowerCase(),
1973
+ from: filter.from ? getUnixTimestamp(filter.from) : undefined,
1974
+ to: filter.to ? getUnixTimestamp(filter.to) : undefined,
1975
+ first: Math.min(first, 1000),
1976
+ skip,
1977
+ orderDirection,
1978
+ }
1979
+ );
1980
+
1981
+ return payouts || [];
1982
+ }
1924
1983
  }
@@ -1,5 +1,5 @@
1
1
  import gql from 'graphql-tag';
2
- import { IPayoutFilter } from '../../interfaces';
2
+ import { IPayoutFilter } from 'src/interfaces';
3
3
 
4
4
  const PAYOUT_FRAGMENT = gql`
5
5
  fragment PayoutFields on Payout {
@@ -22,9 +22,6 @@ export const GET_PAYOUTS_QUERY = (filter: IPayoutFilter) => {
22
22
  ${to ? `createdAt_lt: $to` : ''}
23
23
  }
24
24
  `;
25
- const LIMIT_CLAUSE = `
26
- first: 1000
27
- `;
28
25
 
29
26
  return gql`
30
27
  query getPayouts(
@@ -32,12 +29,16 @@ export const GET_PAYOUTS_QUERY = (filter: IPayoutFilter) => {
32
29
  $recipient: String
33
30
  $from: Int
34
31
  $to: Int
32
+ $first: Int
33
+ $skip: Int
34
+ $orderDirection: String
35
35
  ) {
36
36
  payouts(
37
37
  ${WHERE_CLAUSE}
38
38
  orderBy: createdAt,
39
- orderDirection: desc,
40
- ${LIMIT_CLAUSE}
39
+ orderDirection: $orderDirection,
40
+ first: $first,
41
+ skip: $skip
41
42
  ) {
42
43
  ...PayoutFields
43
44
  }
@@ -0,0 +1,41 @@
1
+ import gql from 'graphql-tag';
2
+ import { IWorkersFilter } from '../../interfaces';
3
+
4
+ export const GET_WORKER_QUERY = gql`
5
+ query GetWorker($address: String!) {
6
+ worker(id: $address) {
7
+ id
8
+ address
9
+ totalAmountReceived
10
+ payoutCount
11
+ }
12
+ }
13
+ `;
14
+
15
+ export const GET_WORKERS_QUERY = (filter: IWorkersFilter) => {
16
+ const { address } = filter;
17
+
18
+ return gql`
19
+ query GetWorkers(
20
+ $address: String
21
+ $first: Int
22
+ $skip: Int
23
+ $orderBy: String
24
+ $orderDirection: String
25
+ ) {
26
+ workers(
27
+ where: {
28
+ ${address ? 'address: $address,' : ''}
29
+ }
30
+ first: $first
31
+ skip: $skip
32
+ orderBy: $orderBy
33
+ orderDirection: $orderDirection
34
+ ) {
35
+ id
36
+ address
37
+ totalAmountReceived
38
+ payoutCount
39
+ }
40
+ }`;
41
+ };
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ import { StatisticsClient } from './statistics';
6
6
  import { Encryption, EncryptionUtils } from './encryption';
7
7
  import { OperatorUtils } from './operator';
8
8
  import { TransactionUtils } from './transaction';
9
+ import { WorkerUtils } from './worker';
9
10
 
10
11
  export * from './constants';
11
12
  export * from './types';
@@ -24,4 +25,5 @@ export {
24
25
  EncryptionUtils,
25
26
  OperatorUtils,
26
27
  TransactionUtils,
28
+ WorkerUtils,
27
29
  };
package/src/interfaces.ts CHANGED
@@ -103,7 +103,8 @@ export interface IHMTHoldersParams extends IPagination {
103
103
  address?: string;
104
104
  }
105
105
 
106
- export interface IPayoutFilter {
106
+ export interface IPayoutFilter extends IPagination {
107
+ chainId: ChainId;
107
108
  escrowAddress?: string;
108
109
  recipient?: string;
109
110
  from?: Date;
@@ -161,3 +162,24 @@ export interface StakerInfo {
161
162
  lockedUntil: bigint;
162
163
  withdrawableAmount: bigint;
163
164
  }
165
+
166
+ export interface IStatusEventFilter extends IPagination {
167
+ chainId: ChainId;
168
+ statuses?: EscrowStatus[];
169
+ from?: Date;
170
+ to?: Date;
171
+ launcher?: string;
172
+ }
173
+
174
+ export interface IWorker {
175
+ id: string;
176
+ address: string;
177
+ totalAmountReceived: number;
178
+ payoutCount: number;
179
+ }
180
+
181
+ export interface IWorkersFilter extends IPagination {
182
+ chainId: ChainId;
183
+ address?: string;
184
+ orderBy?: string;
185
+ }
package/src/types.ts CHANGED
@@ -171,4 +171,30 @@ export type EscrowWithdraw = {
171
171
  amountWithdrawn: bigint;
172
172
  };
173
173
 
174
+ /**
175
+ * Represents a payout from an escrow.
176
+ */
177
+ export type Payout = {
178
+ /**
179
+ * Unique identifier of the payout.
180
+ */
181
+ id: string;
182
+ /**
183
+ * The address of the escrow associated with the payout.
184
+ */
185
+ escrowAddress: string;
186
+ /**
187
+ * The address of the recipient who received the payout.
188
+ */
189
+ recipient: string;
190
+ /**
191
+ * The amount paid to the recipient.
192
+ */
193
+ amount: bigint;
194
+ /**
195
+ * The timestamp when the payout was created (in UNIX format).
196
+ */
197
+ createdAt: number;
198
+ };
199
+
174
200
  export type TransactionLikeWithNonce = TransactionLike & { nonce: number };
package/src/worker.ts ADDED
@@ -0,0 +1,120 @@
1
+ import gqlFetch from 'graphql-request';
2
+ import { NETWORKS } from './constants';
3
+ import { ChainId, OrderDirection } from './enums';
4
+ import { ErrorInvalidAddress, ErrorUnsupportedChainID } from './error';
5
+ import { GET_WORKER_QUERY, GET_WORKERS_QUERY } from './graphql/queries/worker';
6
+ import { IWorker, IWorkersFilter } from './interfaces';
7
+ import { getSubgraphUrl } from './utils';
8
+ import { ethers } from 'ethers';
9
+
10
+ export class WorkerUtils {
11
+ /**
12
+ * This function returns the worker data for the given address.
13
+ *
14
+ * @param {ChainId} chainId The chain ID.
15
+ * @param {string} address The worker address.
16
+ * @returns {Promise<IWorker>} Returns the worker details.
17
+ *
18
+ * **Code example**
19
+ *
20
+ * ```ts
21
+ * import { WorkerUtils, ChainId } from '@human-protocol/sdk';
22
+ *
23
+ * const worker = await WorkerUtils.getWorker(ChainId.POLYGON, '0x1234567890abcdef1234567890abcdef12345678');
24
+ * ```
25
+ */
26
+ public static async getWorker(
27
+ chainId: ChainId,
28
+ address: string
29
+ ): Promise<IWorker | null> {
30
+ const networkData = NETWORKS[chainId];
31
+
32
+ if (!networkData) {
33
+ throw ErrorUnsupportedChainID;
34
+ }
35
+ if (!ethers.isAddress(address)) {
36
+ throw ErrorInvalidAddress;
37
+ }
38
+
39
+ const { worker } = await gqlFetch<{
40
+ worker: IWorker;
41
+ }>(getSubgraphUrl(networkData), GET_WORKER_QUERY, {
42
+ address: address.toLowerCase(),
43
+ });
44
+
45
+ return worker || null;
46
+ }
47
+
48
+ /**
49
+ * This function returns all worker details based on the provided filter.
50
+ *
51
+ * **Input parameters**
52
+ *
53
+ * ```ts
54
+ * interface IWorkersFilter {
55
+ * chainId: ChainId; // List of chain IDs to query.
56
+ * address?: string; // (Optional) The worker address to filter by.
57
+ * orderBy?: string; // (Optional) The field to order by. Default is 'payoutCount'.
58
+ * orderDirection?: OrderDirection; // (Optional) The direction of the order. Default is 'DESC'.
59
+ * first?: number; // (Optional) Number of workers per page. Default is 10.
60
+ * skip?: number; // (Optional) Number of workers to skip. Default is 0.
61
+ * }
62
+ * ```
63
+ *
64
+ * ```ts
65
+ * type IWorker = {
66
+ * id: string;
67
+ * address: string;
68
+ * totalAmountReceived: string;
69
+ * payoutCount: number;
70
+ * };
71
+ * ```
72
+ *
73
+ * @param {IWorkersFilter} filter Filter for the workers.
74
+ * @returns {Promise<IWorker[]>} Returns an array with all the worker details.
75
+ *
76
+ * **Code example**
77
+ *
78
+ * ```ts
79
+ * import { WorkerUtils, ChainId } from '@human-protocol/sdk';
80
+ *
81
+ * const filter: IWorkersFilter = {
82
+ * chainId: ChainId.POLYGON,
83
+ * first: 10,
84
+ * skip: 0,
85
+ * };
86
+ * const workers = await WorkerUtils.getWorkers(filter);
87
+ * ```
88
+ */
89
+ public static async getWorkers(filter: IWorkersFilter): Promise<IWorker[]> {
90
+ const first =
91
+ filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
92
+ const skip = filter.skip || 0;
93
+ const orderBy = filter.orderBy || 'payoutCount';
94
+ const orderDirection = filter.orderDirection || OrderDirection.DESC;
95
+
96
+ const networkData = NETWORKS[filter.chainId];
97
+ if (!networkData) {
98
+ throw ErrorUnsupportedChainID;
99
+ }
100
+ if (filter.address && !ethers.isAddress(filter.address)) {
101
+ throw ErrorInvalidAddress;
102
+ }
103
+
104
+ const { workers } = await gqlFetch<{
105
+ workers: IWorker[];
106
+ }>(getSubgraphUrl(networkData), GET_WORKERS_QUERY(filter), {
107
+ address: filter?.address?.toLowerCase(),
108
+ first: first,
109
+ skip: skip,
110
+ orderBy: orderBy,
111
+ orderDirection: orderDirection,
112
+ });
113
+
114
+ if (!workers) {
115
+ return [];
116
+ }
117
+
118
+ return workers;
119
+ }
120
+ }