@human-protocol/sdk 2.1.3 → 3.0.1

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.
Files changed (70) hide show
  1. package/README.md +23 -80
  2. package/dist/constants.d.ts +1 -0
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +56 -24
  5. package/dist/enums.d.ts +7 -2
  6. package/dist/enums.d.ts.map +1 -1
  7. package/dist/enums.js +8 -2
  8. package/dist/error.d.ts +16 -0
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +18 -2
  11. package/dist/escrow.d.ts +91 -7
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +154 -39
  14. package/dist/graphql/queries/escrow.d.ts +1 -0
  15. package/dist/graphql/queries/escrow.d.ts.map +1 -1
  16. package/dist/graphql/queries/escrow.js +50 -9
  17. package/dist/graphql/queries/hmtoken.d.ts +1 -1
  18. package/dist/graphql/queries/hmtoken.d.ts.map +1 -1
  19. package/dist/graphql/queries/hmtoken.js +23 -7
  20. package/dist/graphql/queries/kvstore.d.ts +2 -0
  21. package/dist/graphql/queries/kvstore.d.ts.map +1 -0
  22. package/dist/graphql/queries/kvstore.js +28 -0
  23. package/dist/graphql/queries/statistics.d.ts.map +1 -1
  24. package/dist/graphql/queries/statistics.js +2 -0
  25. package/dist/graphql/queries/transaction.d.ts +4 -0
  26. package/dist/graphql/queries/transaction.d.ts.map +1 -0
  27. package/dist/graphql/queries/transaction.js +64 -0
  28. package/dist/graphql/types.d.ts +19 -0
  29. package/dist/graphql/types.d.ts.map +1 -1
  30. package/dist/index.d.ts +2 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +3 -1
  33. package/dist/interfaces.d.ts +35 -4
  34. package/dist/interfaces.d.ts.map +1 -1
  35. package/dist/kvstore.d.ts +84 -0
  36. package/dist/kvstore.d.ts.map +1 -1
  37. package/dist/kvstore.js +103 -1
  38. package/dist/operator.d.ts +5 -2
  39. package/dist/operator.d.ts.map +1 -1
  40. package/dist/operator.js +68 -57
  41. package/dist/statistics.d.ts +29 -2
  42. package/dist/statistics.d.ts.map +1 -1
  43. package/dist/statistics.js +53 -7
  44. package/dist/transaction.d.ts +75 -0
  45. package/dist/transaction.d.ts.map +1 -0
  46. package/dist/transaction.js +130 -0
  47. package/dist/types.d.ts +4 -0
  48. package/dist/types.d.ts.map +1 -1
  49. package/dist/utils.d.ts +9 -0
  50. package/dist/utils.d.ts.map +1 -1
  51. package/dist/utils.js +21 -1
  52. package/package.json +7 -6
  53. package/src/constants.ts +73 -23
  54. package/src/enums.ts +7 -1
  55. package/src/error.ts +23 -0
  56. package/src/escrow.ts +199 -51
  57. package/src/graphql/queries/escrow.ts +53 -8
  58. package/src/graphql/queries/hmtoken.ts +23 -7
  59. package/src/graphql/queries/kvstore.ts +23 -0
  60. package/src/graphql/queries/statistics.ts +2 -0
  61. package/src/graphql/queries/transaction.ts +64 -0
  62. package/src/graphql/types.ts +22 -0
  63. package/src/index.ts +2 -0
  64. package/src/interfaces.ts +40 -4
  65. package/src/kvstore.ts +114 -1
  66. package/src/operator.ts +90 -69
  67. package/src/statistics.ts +63 -9
  68. package/src/transaction.ts +152 -0
  69. package/src/types.ts +4 -0
  70. package/src/utils.ts +25 -0
package/src/escrow.ts CHANGED
@@ -12,7 +12,7 @@ import gqlFetch from 'graphql-request';
12
12
  import { BaseEthersClient } from './base';
13
13
  import { DEFAULT_TX_ID, NETWORKS } from './constants';
14
14
  import { requiresSigner } from './decorators';
15
- import { ChainId } from './enums';
15
+ import { ChainId, OrderDirection } from './enums';
16
16
  import {
17
17
  ErrorAmountMustBeGreaterThanZero,
18
18
  ErrorAmountsCannotBeEmptyArray,
@@ -41,10 +41,12 @@ import {
41
41
  EscrowData,
42
42
  GET_ESCROWS_QUERY,
43
43
  GET_ESCROW_BY_ADDRESS_QUERY,
44
+ GET_STATUS_UPDATES_QUERY,
45
+ StatusEvent,
44
46
  } from './graphql';
45
47
  import { IEscrowConfig, IEscrowsFilter } from './interfaces';
46
48
  import { EscrowCancel, EscrowStatus, NetworkData } from './types';
47
- import { isValidUrl, throwError } from './utils';
49
+ import { getSubgraphUrl, isValidUrl, throwError } from './utils';
48
50
 
49
51
  /**
50
52
  * ## Introduction
@@ -1399,7 +1401,7 @@ export class EscrowClient extends BaseEthersClient {
1399
1401
  * import { ChainId, EscrowUtils } from '@human-protocol/sdk';
1400
1402
  *
1401
1403
  * const escrowAddresses = new EscrowUtils.getEscrows({
1402
- * networks: [ChainId.POLYGON_AMOY]
1404
+ * network: ChainId.POLYGON_AMOY
1403
1405
  * });
1404
1406
  * ```
1405
1407
  */
@@ -1412,7 +1414,7 @@ export class EscrowUtils {
1412
1414
  *
1413
1415
  * ```ts
1414
1416
  * interface IEscrowsFilter {
1415
- * networks: ChainId[];
1417
+ * chainId: ChainId;
1416
1418
  * launcher?: string;
1417
1419
  * reputationOracle?: string;
1418
1420
  * recordingOracle?: string;
@@ -1421,6 +1423,9 @@ export class EscrowUtils {
1421
1423
  * status?: EscrowStatus;
1422
1424
  * from?: Date;
1423
1425
  * to?: Date;
1426
+ * first?: number;
1427
+ * skip?: number;
1428
+ * orderDirection?: OrderDirection;
1424
1429
  * }
1425
1430
  * ```
1426
1431
  *
@@ -1441,12 +1446,19 @@ export class EscrowUtils {
1441
1446
  * AVALANCHE_TESTNET = 43113,
1442
1447
  * CELO = 42220,
1443
1448
  * CELO_ALFAJORES = 44787,
1444
- * SKALE = 1273227453,
1449
+ * = 1273227453,
1445
1450
  * LOCALHOST = 1338,
1446
1451
  * }
1447
1452
  * ```
1448
1453
  *
1449
1454
  * ```ts
1455
+ * enum OrderDirection {
1456
+ * ASC = 'asc',
1457
+ * DESC = 'desc',
1458
+ * }
1459
+ * ```
1460
+ *
1461
+ * ```ts
1450
1462
  * enum EscrowStatus {
1451
1463
  * Launched,
1452
1464
  * Pending,
@@ -1497,7 +1509,7 @@ export class EscrowUtils {
1497
1509
  * status: EscrowStatus.Pending,
1498
1510
  * from: new Date(2023, 4, 8),
1499
1511
  * to: new Date(2023, 5, 8),
1500
- * networks: [ChainId.POLYGON_AMOY]
1512
+ * chainId: ChainId.POLYGON_AMOY
1501
1513
  * };
1502
1514
  * const escrowDatas = await EscrowUtils.getEscrows(filters);
1503
1515
  * ```
@@ -1505,9 +1517,6 @@ export class EscrowUtils {
1505
1517
  public static async getEscrows(
1506
1518
  filter: IEscrowsFilter
1507
1519
  ): Promise<EscrowData[]> {
1508
- if (!filter?.networks?.length) {
1509
- throw ErrorUnsupportedChainID;
1510
- }
1511
1520
  if (filter.launcher && !ethers.isAddress(filter.launcher)) {
1512
1521
  throw ErrorInvalidAddress;
1513
1522
  }
@@ -1524,42 +1533,46 @@ export class EscrowUtils {
1524
1533
  throw ErrorInvalidAddress;
1525
1534
  }
1526
1535
 
1527
- try {
1528
- const escrowAddresses: EscrowData[] = [];
1529
- for (const chainId of filter.networks) {
1530
- const networkData = NETWORKS[chainId];
1536
+ const first =
1537
+ filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
1538
+ const skip = filter.skip || 0;
1539
+ const orderDirection = filter.orderDirection || OrderDirection.DESC;
1531
1540
 
1532
- if (!networkData) {
1533
- throw ErrorUnsupportedChainID;
1534
- }
1541
+ const networkData = NETWORKS[filter.chainId];
1535
1542
 
1536
- const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
1537
- networkData.subgraphUrl,
1538
- GET_ESCROWS_QUERY(filter),
1539
- {
1540
- ...filter,
1541
- launcher: filter.launcher?.toLowerCase(),
1542
- reputationOracle: filter.reputationOracle?.toLowerCase(),
1543
- recordingOracle: filter.recordingOracle?.toLowerCase(),
1544
- exchangeOracle: filter.exchangeOracle?.toLowerCase(),
1545
- status:
1546
- filter.status !== undefined
1547
- ? Object.entries(EscrowStatus).find(
1548
- ([, value]) => value === filter.status
1549
- )?.[0]
1550
- : undefined,
1551
- from: filter.from ? +filter.from.getTime() / 1000 : undefined,
1552
- to: filter.to ? +filter.to.getTime() / 1000 : undefined,
1553
- }
1554
- );
1555
- escrows.map((escrow) => (escrow.chainId = networkData.chainId));
1556
- escrowAddresses.push(...escrows);
1543
+ if (!networkData) {
1544
+ throw ErrorUnsupportedChainID;
1545
+ }
1546
+
1547
+ const { escrows } = await gqlFetch<{ escrows: EscrowData[] }>(
1548
+ getSubgraphUrl(networkData),
1549
+ GET_ESCROWS_QUERY(filter),
1550
+ {
1551
+ ...filter,
1552
+ launcher: filter.launcher?.toLowerCase(),
1553
+ reputationOracle: filter.reputationOracle?.toLowerCase(),
1554
+ recordingOracle: filter.recordingOracle?.toLowerCase(),
1555
+ exchangeOracle: filter.exchangeOracle?.toLowerCase(),
1556
+ status:
1557
+ filter.status !== undefined
1558
+ ? Object.entries(EscrowStatus).find(
1559
+ ([, value]) => value === filter.status
1560
+ )?.[0]
1561
+ : undefined,
1562
+ from: filter.from ? +filter.from.getTime() / 1000 : undefined,
1563
+ to: filter.to ? +filter.to.getTime() / 1000 : undefined,
1564
+ orderDirection: orderDirection,
1565
+ first: first,
1566
+ skip: skip,
1557
1567
  }
1558
- escrowAddresses.sort((a, b) => Number(b.createdAt) - Number(a.createdAt));
1559
- return escrowAddresses;
1560
- } catch (e: any) {
1561
- return throwError(e);
1568
+ );
1569
+ escrows.map((escrow) => (escrow.chainId = networkData.chainId));
1570
+
1571
+ if (!escrows) {
1572
+ return [];
1562
1573
  }
1574
+
1575
+ return escrows;
1563
1576
  }
1564
1577
 
1565
1578
  /**
@@ -1586,7 +1599,6 @@ export class EscrowUtils {
1586
1599
  * AVALANCHE_TESTNET = 43113,
1587
1600
  * CELO = 42220,
1588
1601
  * CELO_ALFAJORES = 44787,
1589
- * SKALE = 1273227453,
1590
1602
  * LOCALHOST = 1338,
1591
1603
  * }
1592
1604
  * ```
@@ -1645,16 +1657,152 @@ export class EscrowUtils {
1645
1657
  throw ErrorInvalidAddress;
1646
1658
  }
1647
1659
 
1648
- try {
1649
- const { escrow } = await gqlFetch<{ escrow: EscrowData }>(
1650
- networkData.subgraphUrl,
1651
- GET_ESCROW_BY_ADDRESS_QUERY(),
1652
- { escrowAddress: escrowAddress.toLowerCase() }
1653
- );
1660
+ const { escrow } = await gqlFetch<{ escrow: EscrowData }>(
1661
+ getSubgraphUrl(networkData),
1662
+ GET_ESCROW_BY_ADDRESS_QUERY(),
1663
+ { escrowAddress: escrowAddress.toLowerCase() }
1664
+ );
1654
1665
 
1655
- return escrow || null;
1656
- } catch (e: any) {
1657
- return throwError(e);
1666
+ return escrow || null;
1667
+ }
1668
+
1669
+ /**
1670
+ * This function returns the status events for a given set of networks within an optional date range.
1671
+ *
1672
+ * > This uses Subgraph
1673
+ *
1674
+ * **Input parameters**
1675
+ *
1676
+ * ```ts
1677
+ * enum ChainId {
1678
+ * ALL = -1,
1679
+ * MAINNET = 1,
1680
+ * RINKEBY = 4,
1681
+ * GOERLI = 5,
1682
+ * SEPOLIA = 11155111,
1683
+ * BSC_MAINNET = 56,
1684
+ * BSC_TESTNET = 97,
1685
+ * POLYGON = 137,
1686
+ * POLYGON_MUMBAI = 80001,
1687
+ * POLYGON_AMOY = 80002,
1688
+ * MOONBEAM = 1284,
1689
+ * MOONBASE_ALPHA = 1287,
1690
+ * AVALANCHE = 43114,
1691
+ * AVALANCHE_TESTNET = 43113,
1692
+ * CELO = 42220,
1693
+ * CELO_ALFAJORES = 44787,
1694
+ * LOCALHOST = 1338,
1695
+ * XLAYER_TESTNET = 195,
1696
+ * XLAYER = 196,
1697
+ * }
1698
+ * ```
1699
+ *
1700
+ * ```ts
1701
+ * enum OrderDirection {
1702
+ * ASC = 'asc',
1703
+ * DESC = 'desc',
1704
+ * }
1705
+ * ```
1706
+ *
1707
+ * ```ts
1708
+ * type Status = {
1709
+ * escrowAddress: string;
1710
+ * timestamp: string;
1711
+ * status: string;
1712
+ * };
1713
+ * ```
1714
+ *
1715
+ * @param {ChainId} chainId - List of network IDs to query for status events.
1716
+ * @param {EscrowStatus[]} [statuses] - Optional array of statuses to query for. If not provided, queries for all statuses.
1717
+ * @param {Date} [from] - Optional start date to filter events.
1718
+ * @param {Date} [to] - Optional end date to filter events.
1719
+ * @param {string} [launcher] - Optional launcher address to filter events. Must be a valid Ethereum address.
1720
+ * @param {number} [first] - Optional number of transactions per page. Default is 10.
1721
+ * @param {number} [skip] - Optional number of transactions to skip. Default is 0.
1722
+ * @param {OrderDirection} [orderDirection] - Optional order of the results. Default is DESC.
1723
+ * @returns {Promise<StatusEvent[]>} - Array of status events with their corresponding statuses.
1724
+ *
1725
+ * **Code example**
1726
+ *
1727
+ * ```ts
1728
+ * import { ChainId, EscrowUtils, EscrowStatus } from '@human-protocol/sdk';
1729
+ *
1730
+ * (async () => {
1731
+ * const fromDate = new Date('2023-01-01');
1732
+ * const toDate = new Date('2023-12-31');
1733
+ * const statusEvents = await EscrowUtils.getStatusEvents(
1734
+ * [ChainId.POLYGON, ChainId.MAINNET],
1735
+ * [EscrowStatus.Pending, EscrowStatus.Complete],
1736
+ * fromDate,
1737
+ * toDate
1738
+ * );
1739
+ * console.log(statusEvents);
1740
+ * })();
1741
+ * ```
1742
+ */
1743
+
1744
+ public static async getStatusEvents(
1745
+ chainId: ChainId,
1746
+ statuses?: EscrowStatus[],
1747
+ from?: Date,
1748
+ to?: Date,
1749
+ launcher?: string,
1750
+ first?: number,
1751
+ skip?: number,
1752
+ orderDirection?: OrderDirection
1753
+ ): Promise<StatusEvent[]> {
1754
+ if (launcher && !ethers.isAddress(launcher)) {
1755
+ throw ErrorInvalidAddress;
1658
1756
  }
1757
+
1758
+ first = first !== undefined ? Math.min(first, 1000) : 10;
1759
+ skip = skip || 0;
1760
+ orderDirection = orderDirection || OrderDirection.DESC;
1761
+
1762
+ // If statuses are not provided, use all statuses except Launched
1763
+ const effectiveStatuses = statuses ?? [
1764
+ EscrowStatus.Launched,
1765
+ EscrowStatus.Pending,
1766
+ EscrowStatus.Partial,
1767
+ EscrowStatus.Paid,
1768
+ EscrowStatus.Complete,
1769
+ EscrowStatus.Cancelled,
1770
+ ];
1771
+
1772
+ const networkData = NETWORKS[chainId];
1773
+ if (!networkData) {
1774
+ throw ErrorUnsupportedChainID;
1775
+ }
1776
+
1777
+ const statusNames = effectiveStatuses.map((status) => EscrowStatus[status]);
1778
+
1779
+ const data = await gqlFetch<{
1780
+ escrowStatusEvents: StatusEvent[];
1781
+ }>(
1782
+ getSubgraphUrl(networkData),
1783
+ GET_STATUS_UPDATES_QUERY(from, to, launcher),
1784
+ {
1785
+ status: statusNames,
1786
+ from: from ? Math.floor(from.getTime() / 1000) : undefined,
1787
+ to: to ? Math.floor(to.getTime() / 1000) : undefined,
1788
+ launcher: launcher || undefined,
1789
+ orderDirection: orderDirection,
1790
+ first: first,
1791
+ skip: skip,
1792
+ }
1793
+ );
1794
+
1795
+ if (!data || !data['escrowStatusEvents']) {
1796
+ return [];
1797
+ }
1798
+
1799
+ const statusEvents = data['escrowStatusEvents'] as StatusEvent[];
1800
+
1801
+ const eventsWithChainId = statusEvents.map((event) => ({
1802
+ ...event,
1803
+ chainId,
1804
+ }));
1805
+
1806
+ return eventsWithChainId;
1659
1807
  }
1660
1808
  }
@@ -51,14 +51,14 @@ export const GET_ESCROWS_QUERY = (filter: IEscrowsFilter) => {
51
51
 
52
52
  const WHERE_CLAUSE = `
53
53
  where: {
54
- ${launcher ? `launcher: $launcher` : ''}
55
- ${jobRequesterId ? `jobRequesterId: $jobRequesterId` : ''}
56
- ${reputationOracle ? `reputationOracle: $reputationOracle` : ''}
57
- ${recordingOracle ? `recordingOracle: $recordingOracle` : ''}
58
- ${exchangeOracle ? `exchangeOracle: $exchangeOracle` : ''}
59
- ${status !== undefined ? `status: $status` : ''}
60
- ${from ? `createdAt_gte: $from` : ''}
61
- ${to ? `createdAt_lte: $to` : ''}
54
+ ${launcher ? `launcher: $launcher,` : ''}
55
+ ${jobRequesterId ? `jobRequesterId: $jobRequesterId,` : ''}
56
+ ${reputationOracle ? `reputationOracle: $reputationOracle,` : ''}
57
+ ${recordingOracle ? `recordingOracle: $recordingOracle,` : ''}
58
+ ${exchangeOracle ? `exchangeOracle: $exchangeOracle,` : ''}
59
+ ${status !== undefined ? `status: $status,` : ''}
60
+ ${from ? `createdAt_gte: $from,` : ''}
61
+ ${to ? `createdAt_lte: $to,` : ''}
62
62
  }
63
63
  `;
64
64
 
@@ -72,9 +72,16 @@ export const GET_ESCROWS_QUERY = (filter: IEscrowsFilter) => {
72
72
  $status: String
73
73
  $from: Int
74
74
  $to: Int
75
+ $orderDirection: String
76
+ $first: Int
77
+ $skip: Int
75
78
  ) {
76
79
  escrows(
77
80
  ${WHERE_CLAUSE}
81
+ orderBy: createdAt,
82
+ orderDirection: $orderDirection,
83
+ first: $first,
84
+ skip: $skip
78
85
  ) {
79
86
  ...EscrowFields
80
87
  }
@@ -82,3 +89,41 @@ export const GET_ESCROWS_QUERY = (filter: IEscrowsFilter) => {
82
89
  ${ESCROW_FRAGMENT}
83
90
  `;
84
91
  };
92
+
93
+ export const GET_STATUS_UPDATES_QUERY = (
94
+ from?: Date,
95
+ to?: Date,
96
+ launcher?: string
97
+ ) => {
98
+ const WHERE_CLAUSE = `
99
+ where: {
100
+ status_in: $status
101
+ ${from ? `timestamp_gte: $from` : ''}
102
+ ${to ? `timestamp_lte: $to` : ''}
103
+ ${launcher ? `launcher: $launcher` : ''}
104
+ }
105
+ `;
106
+ return gql`
107
+ query getStatus(
108
+ $status: [String!]!
109
+ $from: Int
110
+ $to: Int
111
+ $launcher: String
112
+ $orderDirection: String
113
+ $first: Int
114
+ $skip: Int
115
+ ) {
116
+ escrowStatusEvents(
117
+ ${WHERE_CLAUSE}
118
+ orderBy: timestamp,
119
+ orderDirection: $orderDirection,
120
+ first: $first,
121
+ skip: $skip
122
+ ) {
123
+ escrowAddress,
124
+ timestamp,
125
+ status,
126
+ }
127
+ }
128
+ `;
129
+ };
@@ -7,11 +7,27 @@ const HOLDER_FRAGMENT = gql`
7
7
  }
8
8
  `;
9
9
 
10
- export const GET_HOLDERS_QUERY = gql`
11
- query GetHolders {
12
- holders {
13
- ...HolderFields
10
+ export const GET_HOLDERS_QUERY = (address?: string) => {
11
+ const WHERE_CLAUSE = `
12
+ where: {
13
+ ${address ? `address: $address,` : ''}
14
14
  }
15
- }
16
- ${HOLDER_FRAGMENT}
17
- `;
15
+ `;
16
+
17
+ return gql`
18
+ query GetHolders(
19
+ $address: String
20
+ $orderBy: String
21
+ $orderDirection: String
22
+ ) {
23
+ holders(
24
+ ${WHERE_CLAUSE}
25
+ orderBy: $orderBy,
26
+ orderDirection: $orderDirection
27
+ ) {
28
+ ...HolderFields
29
+ }
30
+ }
31
+ ${HOLDER_FRAGMENT}
32
+ `;
33
+ };
@@ -0,0 +1,23 @@
1
+ import gql from 'graphql-tag';
2
+
3
+ const KVSTORE_FRAGMENT = gql`
4
+ fragment KVStoreFields on KVStore {
5
+ id
6
+ block
7
+ timestamp
8
+ address
9
+ key
10
+ value
11
+ }
12
+ `;
13
+
14
+ export const GET_KVSTORE_BY_ADDRESS_QUERY = () => {
15
+ return gql`
16
+ query getKVStoreData($address: String!) {
17
+ kvstores(where: { address: $address }) {
18
+ ...KVStoreFields
19
+ }
20
+ }
21
+ ${KVSTORE_FRAGMENT}
22
+ `;
23
+ };
@@ -47,6 +47,8 @@ const EVENT_DAY_DATA_FRAGMENT = gql`
47
47
  dailyPayoutAmount
48
48
  dailyHMTTransferCount
49
49
  dailyHMTTransferAmount
50
+ dailyUniqueSenders
51
+ dailyUniqueReceivers
50
52
  }
51
53
  `;
52
54
 
@@ -0,0 +1,64 @@
1
+ import gql from 'graphql-tag';
2
+ import { ITransactionsFilter } from '../../../src/interfaces';
3
+
4
+ const TRANSACTION_FRAGMENT = gql`
5
+ fragment TransactionFields on Transaction {
6
+ block
7
+ txHash
8
+ from
9
+ to
10
+ timestamp
11
+ value
12
+ method
13
+ }
14
+ `;
15
+
16
+ export const GET_TRANSACTIONS_QUERY = (filter: ITransactionsFilter) => {
17
+ const { startDate, endDate, startBlock, endBlock, fromAddress, toAddress } =
18
+ filter;
19
+
20
+ const WHERE_CLAUSE = `
21
+ where: {
22
+ ${fromAddress ? `from: $fromAddress,` : ''}
23
+ ${toAddress ? `to: $toAddress,` : ''}
24
+ ${startDate ? `timestamp_gte: $startDate,` : ''}
25
+ ${endDate ? `timestamp_lte: $endDate,` : ''}
26
+ ${startBlock ? `block_gte: $startBlock,` : ''}
27
+ ${endBlock ? `block_lte: $endBlock,` : ''}
28
+ }
29
+ `;
30
+
31
+ return gql`
32
+ query getTransactions(
33
+ $fromAddress: String
34
+ $toAddress: String
35
+ $startDate: Int
36
+ $endDate: Int
37
+ $startBlock: Int
38
+ $endBlock: Int
39
+ $orderDirection: String
40
+ $first: Int
41
+ $skip: Int
42
+ ) {
43
+ transactions(
44
+ ${WHERE_CLAUSE}
45
+ orderBy: timestamp,
46
+ orderDirection: $orderDirection,
47
+ first: $first,
48
+ skip: $skip
49
+ ) {
50
+ ...TransactionFields
51
+ }
52
+ }
53
+ ${TRANSACTION_FRAGMENT}
54
+ `;
55
+ };
56
+
57
+ export const GET_TRANSACTION_QUERY = gql`
58
+ query getTransaction($hash: String!) {
59
+ transaction(id: $hash) {
60
+ ...TransactionFields
61
+ }
62
+ }
63
+ ${TRANSACTION_FRAGMENT}
64
+ `;
@@ -1,3 +1,5 @@
1
+ import { ChainId } from '../enums';
2
+
1
3
  export type EscrowData = {
2
4
  id: string;
3
5
  address: string;
@@ -72,6 +74,8 @@ export type EventDayData = {
72
74
  dailyPayoutAmount: string;
73
75
  dailyHMTTransferCount: string;
74
76
  dailyHMTTransferAmount: string;
77
+ dailyUniqueSenders: string;
78
+ dailyUniqueReceivers: string;
75
79
  };
76
80
 
77
81
  export type RewardAddedEventData = {
@@ -129,6 +133,8 @@ export type DailyHMTData = {
129
133
  timestamp: Date;
130
134
  totalTransactionAmount: bigint;
131
135
  totalTransactionCount: number;
136
+ dailyUniqueSenders: number;
137
+ dailyUniqueReceivers: number;
132
138
  };
133
139
 
134
140
  export type HMTStatistics = {
@@ -155,3 +161,19 @@ export type DailyTaskData = {
155
161
  export type TaskStatistics = {
156
162
  dailyTasksData: DailyTaskData[];
157
163
  };
164
+
165
+ export type StatusEvent = {
166
+ timestamp: number;
167
+ escrowAddress: string;
168
+ status: string;
169
+ chainId: ChainId;
170
+ };
171
+
172
+ export type KVStoreData = {
173
+ id: string;
174
+ address: string;
175
+ key: string;
176
+ value: string;
177
+ timestamp: Date;
178
+ block: number;
179
+ };
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import { EscrowClient, EscrowUtils } from './escrow';
5
5
  import { StatisticsClient } from './statistics';
6
6
  import { Encryption, EncryptionUtils } from './encryption';
7
7
  import { OperatorUtils } from './operator';
8
+ import { TransactionUtils } from './transaction';
8
9
 
9
10
  export * from './constants';
10
11
  export * from './types';
@@ -21,4 +22,5 @@ export {
21
22
  Encryption,
22
23
  EncryptionUtils,
23
24
  OperatorUtils,
25
+ TransactionUtils,
24
26
  };
package/src/interfaces.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EscrowStatus } from './types';
2
- import { ChainId } from './enums';
2
+ import { ChainId, OrderDirection } from './enums';
3
3
 
4
4
  export interface IAllocation {
5
5
  escrowAddress: string;
@@ -40,7 +40,7 @@ export interface ILeaderSubgraph extends Omit<ILeader, 'jobTypes'> {
40
40
  }
41
41
 
42
42
  export interface ILeadersFilter {
43
- networks: ChainId[];
43
+ chainId: ChainId;
44
44
  role?: string;
45
45
  }
46
46
 
@@ -66,7 +66,7 @@ export interface IOperatorSubgraph extends Omit<IOperator, 'jobTypes'> {
66
66
  jobTypes?: string;
67
67
  }
68
68
 
69
- export interface IEscrowsFilter {
69
+ export interface IEscrowsFilter extends IPagination {
70
70
  launcher?: string;
71
71
  reputationOracle?: string;
72
72
  recordingOracle?: string;
@@ -75,7 +75,7 @@ export interface IEscrowsFilter {
75
75
  status?: EscrowStatus;
76
76
  from?: Date;
77
77
  to?: Date;
78
- networks: ChainId[];
78
+ chainId: ChainId;
79
79
  }
80
80
 
81
81
  export interface IEscrowConfig {
@@ -102,9 +102,45 @@ export interface IStatisticsParams {
102
102
  limit?: number;
103
103
  }
104
104
 
105
+ export interface IHMTHoldersParams {
106
+ address?: string;
107
+ orderDirection?: 'asc' | 'desc';
108
+ }
109
+
105
110
  export interface IPayoutFilter {
106
111
  escrowAddress?: string;
107
112
  recipient?: string;
108
113
  from?: Date;
109
114
  to?: Date;
110
115
  }
116
+
117
+ export interface IKVStore {
118
+ key: string;
119
+ value: string;
120
+ }
121
+
122
+ export interface ITransaction {
123
+ block: bigint;
124
+ txHash: string;
125
+ from: string;
126
+ to: string;
127
+ timestamp: bigint;
128
+ value: string;
129
+ method: string;
130
+ }
131
+
132
+ export interface ITransactionsFilter extends IPagination {
133
+ chainId: ChainId;
134
+ startBlock?: number;
135
+ endBlock?: number;
136
+ startDate?: Date;
137
+ endDate?: Date;
138
+ fromAddress?: string;
139
+ toAddress?: string;
140
+ }
141
+
142
+ export interface IPagination {
143
+ first?: number;
144
+ skip?: number;
145
+ orderDirection?: OrderDirection;
146
+ }