@human-protocol/sdk 3.0.8 → 4.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.
- package/dist/constants.d.ts +4 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +11 -151
- package/dist/decorators.js +1 -1
- package/dist/encryption.d.ts +21 -29
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +17 -29
- package/dist/enums.d.ts +5 -12
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +6 -12
- package/dist/error.d.ts +31 -28
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +36 -33
- package/dist/escrow.d.ts +104 -88
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +192 -131
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +15 -5
- package/dist/interfaces.d.ts +12 -2
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +15 -15
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +15 -15
- package/dist/operator.d.ts +11 -10
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +23 -11
- package/dist/staking.d.ts +38 -21
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +62 -21
- package/dist/statistics.d.ts +10 -29
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +18 -37
- package/dist/storage.d.ts +13 -18
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +13 -18
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +3 -5
- package/dist/types.d.ts +6 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +7 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +11 -2
- package/package.json +1 -1
- package/src/constants.ts +11 -174
- package/src/decorators.ts +1 -1
- package/src/encryption.ts +21 -29
- package/src/enums.ts +5 -11
- package/src/error.ts +39 -37
- package/src/escrow.ts +257 -151
- package/src/graphql/queries/operator.ts +15 -5
- package/src/interfaces.ts +13 -2
- package/src/kvstore.ts +16 -16
- package/src/operator.ts +26 -12
- package/src/staking.ts +71 -22
- package/src/statistics.ts +19 -38
- package/src/storage.ts +13 -18
- package/src/transaction.ts +5 -7
- package/src/types.ts +6 -2
- package/src/utils.ts +10 -1
package/src/statistics.ts
CHANGED
|
@@ -20,26 +20,21 @@ import {
|
|
|
20
20
|
} from './graphql';
|
|
21
21
|
import { IHMTHoldersParams, IStatisticsFilter } from './interfaces';
|
|
22
22
|
import { NetworkData } from './types';
|
|
23
|
-
import { getSubgraphUrl, throwError } from './utils';
|
|
23
|
+
import { getSubgraphUrl, getUnixTimestamp, throwError } from './utils';
|
|
24
24
|
import { OrderDirection } from './enums';
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* ## Introduction
|
|
28
28
|
*
|
|
29
|
-
* This client enables
|
|
29
|
+
* This client enables obtaining statistical information from the subgraph.
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
* We just need to create client object using relevant network data.
|
|
31
|
+
* Unlike other SDK clients, `StatisticsClient` does not require `signer` or `provider` to be provided.
|
|
32
|
+
* We just need to create a client object using relevant network data.
|
|
33
33
|
*
|
|
34
34
|
* ```ts
|
|
35
35
|
* constructor(network: NetworkData)
|
|
36
36
|
* ```
|
|
37
37
|
*
|
|
38
|
-
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
39
|
-
*
|
|
40
|
-
* - **Signer**: when the user wants to use this model in order to send transactions caling the contract functions.
|
|
41
|
-
* - **Provider**: when the user wants to use this model in order to get information from the contracts or subgraph.
|
|
42
|
-
*
|
|
43
38
|
* ## Installation
|
|
44
39
|
*
|
|
45
40
|
* ### npm
|
|
@@ -77,7 +72,6 @@ export class StatisticsClient {
|
|
|
77
72
|
/**
|
|
78
73
|
* This function returns the statistical data of escrows.
|
|
79
74
|
*
|
|
80
|
-
*
|
|
81
75
|
* **Input parameters**
|
|
82
76
|
*
|
|
83
77
|
* ```ts
|
|
@@ -106,10 +100,8 @@ export class StatisticsClient {
|
|
|
106
100
|
* };
|
|
107
101
|
* ```
|
|
108
102
|
*
|
|
109
|
-
*
|
|
110
103
|
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
111
|
-
* @returns {EscrowStatistics} Escrow statistics data.
|
|
112
|
-
*
|
|
104
|
+
* @returns {Promise<EscrowStatistics>} Escrow statistics data.
|
|
113
105
|
*
|
|
114
106
|
* **Code example**
|
|
115
107
|
*
|
|
@@ -141,8 +133,8 @@ export class StatisticsClient {
|
|
|
141
133
|
const { eventDayDatas } = await gqlFetch<{
|
|
142
134
|
eventDayDatas: EventDayData[];
|
|
143
135
|
}>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
|
|
144
|
-
from: filter.from ? filter.from
|
|
145
|
-
to: filter.to ? filter.to
|
|
136
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
137
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
146
138
|
orderDirection: orderDirection,
|
|
147
139
|
first: first,
|
|
148
140
|
skip: skip,
|
|
@@ -169,7 +161,6 @@ export class StatisticsClient {
|
|
|
169
161
|
/**
|
|
170
162
|
* This function returns the statistical data of workers.
|
|
171
163
|
*
|
|
172
|
-
*
|
|
173
164
|
* **Input parameters**
|
|
174
165
|
*
|
|
175
166
|
* ```ts
|
|
@@ -193,10 +184,8 @@ export class StatisticsClient {
|
|
|
193
184
|
* };
|
|
194
185
|
* ```
|
|
195
186
|
*
|
|
196
|
-
*
|
|
197
187
|
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
198
|
-
* @returns {WorkerStatistics} Worker statistics data.
|
|
199
|
-
*
|
|
188
|
+
* @returns {Promise<WorkerStatistics>} Worker statistics data.
|
|
200
189
|
*
|
|
201
190
|
* **Code example**
|
|
202
191
|
*
|
|
@@ -224,8 +213,8 @@ export class StatisticsClient {
|
|
|
224
213
|
const { eventDayDatas } = await gqlFetch<{
|
|
225
214
|
eventDayDatas: EventDayData[];
|
|
226
215
|
}>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
|
|
227
|
-
from: filter.from ? filter.from
|
|
228
|
-
to: filter.to ? filter.to
|
|
216
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
217
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
229
218
|
orderDirection: orderDirection,
|
|
230
219
|
first: first,
|
|
231
220
|
skip: skip,
|
|
@@ -245,7 +234,6 @@ export class StatisticsClient {
|
|
|
245
234
|
/**
|
|
246
235
|
* This function returns the statistical data of payments.
|
|
247
236
|
*
|
|
248
|
-
*
|
|
249
237
|
* **Input parameters**
|
|
250
238
|
*
|
|
251
239
|
* ```ts
|
|
@@ -271,10 +259,8 @@ export class StatisticsClient {
|
|
|
271
259
|
* };
|
|
272
260
|
* ```
|
|
273
261
|
*
|
|
274
|
-
*
|
|
275
262
|
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
276
|
-
* @returns {PaymentStatistics} Payment statistics data.
|
|
277
|
-
*
|
|
263
|
+
* @returns {Promise<PaymentStatistics>} Payment statistics data.
|
|
278
264
|
*
|
|
279
265
|
* **Code example**
|
|
280
266
|
*
|
|
@@ -323,8 +309,8 @@ export class StatisticsClient {
|
|
|
323
309
|
const { eventDayDatas } = await gqlFetch<{
|
|
324
310
|
eventDayDatas: EventDayData[];
|
|
325
311
|
}>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
|
|
326
|
-
from: filter.from ? filter.from
|
|
327
|
-
to: filter.to ? filter.to
|
|
312
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
313
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
328
314
|
orderDirection: orderDirection,
|
|
329
315
|
first: first,
|
|
330
316
|
skip: skip,
|
|
@@ -350,7 +336,7 @@ export class StatisticsClient {
|
|
|
350
336
|
/**
|
|
351
337
|
* This function returns the statistical data of HMToken.
|
|
352
338
|
*
|
|
353
|
-
*
|
|
339
|
+
* ```ts
|
|
354
340
|
* type HMTStatistics = {
|
|
355
341
|
* totalTransferAmount: BigNumber;
|
|
356
342
|
* totalTransferCount: BigNumber;
|
|
@@ -358,9 +344,7 @@ export class StatisticsClient {
|
|
|
358
344
|
* };
|
|
359
345
|
* ```
|
|
360
346
|
*
|
|
361
|
-
*
|
|
362
|
-
* @returns {HMTStatistics} HMToken statistics data.
|
|
363
|
-
*
|
|
347
|
+
* @returns {Promise<HMTStatistics>} HMToken statistics data.
|
|
364
348
|
*
|
|
365
349
|
* **Code example**
|
|
366
350
|
*
|
|
@@ -401,7 +385,7 @@ export class StatisticsClient {
|
|
|
401
385
|
* **Input parameters**
|
|
402
386
|
*
|
|
403
387
|
* @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
|
|
404
|
-
* @returns {HMTHolder[]} List of HMToken holders.
|
|
388
|
+
* @returns {Promise<HMTHolder[]>} List of HMToken holders.
|
|
405
389
|
*
|
|
406
390
|
* **Code example**
|
|
407
391
|
*
|
|
@@ -447,7 +431,6 @@ export class StatisticsClient {
|
|
|
447
431
|
/**
|
|
448
432
|
* This function returns the statistical data of HMToken day by day.
|
|
449
433
|
*
|
|
450
|
-
*
|
|
451
434
|
* **Input parameters**
|
|
452
435
|
*
|
|
453
436
|
* ```ts
|
|
@@ -470,10 +453,8 @@ export class StatisticsClient {
|
|
|
470
453
|
* }
|
|
471
454
|
* ```
|
|
472
455
|
*
|
|
473
|
-
*
|
|
474
456
|
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
475
|
-
* @returns {DailyHMTData[]} Daily HMToken statistics data.
|
|
476
|
-
*
|
|
457
|
+
* @returns {Promise<DailyHMTData[]>} Daily HMToken statistics data.
|
|
477
458
|
*
|
|
478
459
|
* **Code example**
|
|
479
460
|
*
|
|
@@ -506,8 +487,8 @@ export class StatisticsClient {
|
|
|
506
487
|
const { eventDayDatas } = await gqlFetch<{
|
|
507
488
|
eventDayDatas: EventDayData[];
|
|
508
489
|
}>(this.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(filter), {
|
|
509
|
-
from: filter.from ? filter.from
|
|
510
|
-
to: filter.to ? filter.to
|
|
490
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
491
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
511
492
|
orderDirection: orderDirection,
|
|
512
493
|
first: first,
|
|
513
494
|
skip: skip,
|
package/src/storage.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { HttpStatus } from './constants';
|
|
|
19
19
|
*
|
|
20
20
|
* ## Introduction
|
|
21
21
|
*
|
|
22
|
-
* This client enables
|
|
22
|
+
* This client enables interacting with S3 cloud storage services like Amazon S3 Bucket, Google Cloud Storage, and others.
|
|
23
23
|
*
|
|
24
24
|
* The instance creation of `StorageClient` should be made using its constructor:
|
|
25
25
|
*
|
|
@@ -27,7 +27,7 @@ import { HttpStatus } from './constants';
|
|
|
27
27
|
* constructor(params: StorageParams, credentials?: StorageCredentials)
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
|
-
* > If credentials
|
|
30
|
+
* > If credentials are not provided, it uses anonymous access to the bucket for downloading files.
|
|
31
31
|
*
|
|
32
32
|
* ## Installation
|
|
33
33
|
*
|
|
@@ -68,7 +68,7 @@ export class StorageClient {
|
|
|
68
68
|
* **Storage client constructor**
|
|
69
69
|
*
|
|
70
70
|
* @param {StorageParams} params - Cloud storage params
|
|
71
|
-
* @param {StorageCredentials} credentials - Optional. Cloud storage access data. If credentials
|
|
71
|
+
* @param {StorageCredentials} credentials - Optional. Cloud storage access data. If credentials are not provided - use anonymous access to the bucket
|
|
72
72
|
*/
|
|
73
73
|
constructor(params: StorageParams, credentials?: StorageCredentials) {
|
|
74
74
|
try {
|
|
@@ -89,8 +89,7 @@ export class StorageClient {
|
|
|
89
89
|
*
|
|
90
90
|
* @param {string[]} keys Array of filenames to download.
|
|
91
91
|
* @param {string} bucket Bucket name.
|
|
92
|
-
* @returns {any[]} Returns an array of
|
|
93
|
-
*
|
|
92
|
+
* @returns {Promise<any[]>} Returns an array of JSON files downloaded and parsed into objects.
|
|
94
93
|
*
|
|
95
94
|
* **Code example**
|
|
96
95
|
*
|
|
@@ -131,18 +130,17 @@ export class StorageClient {
|
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
/**
|
|
134
|
-
* This function downloads files from a
|
|
135
|
-
*
|
|
136
|
-
* @param {string} url Url of the file to download.
|
|
137
|
-
* @returns {any} Returns the JSON file downloaded and parsed into object.
|
|
133
|
+
* This function downloads files from a URL.
|
|
138
134
|
*
|
|
135
|
+
* @param {string} url URL of the file to download.
|
|
136
|
+
* @returns {Promise<any>} Returns the JSON file downloaded and parsed into an object.
|
|
139
137
|
*
|
|
140
138
|
* **Code example**
|
|
141
139
|
*
|
|
142
140
|
* ```ts
|
|
143
141
|
* import { StorageClient } from '@human-protocol/sdk';
|
|
144
142
|
*
|
|
145
|
-
* const file = await
|
|
143
|
+
* const file = await StorageClient.downloadFileFromUrl('http://localhost/file.json');
|
|
146
144
|
* ```
|
|
147
145
|
*/
|
|
148
146
|
public static async downloadFileFromUrl(url: string): Promise<any> {
|
|
@@ -170,10 +168,9 @@ export class StorageClient {
|
|
|
170
168
|
/**
|
|
171
169
|
* This function uploads files to a bucket.
|
|
172
170
|
*
|
|
173
|
-
* @param {any[]} files Array of objects to upload serialized into
|
|
171
|
+
* @param {any[]} files Array of objects to upload serialized into JSON.
|
|
174
172
|
* @param {string} bucket Bucket name.
|
|
175
|
-
* @returns {UploadFile[]} Returns an array of
|
|
176
|
-
*
|
|
173
|
+
* @returns {Promise<UploadFile[]>} Returns an array of uploaded file metadata.
|
|
177
174
|
*
|
|
178
175
|
* **Code example**
|
|
179
176
|
*
|
|
@@ -240,8 +237,7 @@ export class StorageClient {
|
|
|
240
237
|
* This function checks if a bucket exists.
|
|
241
238
|
*
|
|
242
239
|
* @param {string} bucket Bucket name.
|
|
243
|
-
* @returns {boolean} Returns `true` if exists, `false` if it doesn't.
|
|
244
|
-
*
|
|
240
|
+
* @returns {Promise<boolean>} Returns `true` if exists, `false` if it doesn't.
|
|
245
241
|
*
|
|
246
242
|
* **Code example**
|
|
247
243
|
*
|
|
@@ -268,11 +264,10 @@ export class StorageClient {
|
|
|
268
264
|
}
|
|
269
265
|
|
|
270
266
|
/**
|
|
271
|
-
* This function
|
|
267
|
+
* This function lists all file names contained in the bucket.
|
|
272
268
|
*
|
|
273
269
|
* @param {string} bucket Bucket name.
|
|
274
|
-
* @returns {
|
|
275
|
-
*
|
|
270
|
+
* @returns {Promise<string[]>} Returns the list of file names contained in the bucket.
|
|
276
271
|
*
|
|
277
272
|
* **Code example**
|
|
278
273
|
*
|
package/src/transaction.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { NETWORKS } from './constants';
|
|
|
5
5
|
import { ChainId, OrderDirection } from './enums';
|
|
6
6
|
import {
|
|
7
7
|
ErrorCannotUseDateAndBlockSimultaneously,
|
|
8
|
-
|
|
8
|
+
ErrorInvalidHashProvided,
|
|
9
9
|
ErrorUnsupportedChainID,
|
|
10
10
|
} from './error';
|
|
11
11
|
import {
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
GET_TRANSACTION_QUERY,
|
|
14
14
|
} from './graphql/queries/transaction';
|
|
15
15
|
import { ITransaction, ITransactionsFilter } from './interfaces';
|
|
16
|
-
import { getSubgraphUrl } from './utils';
|
|
16
|
+
import { getSubgraphUrl, getUnixTimestamp } from './utils';
|
|
17
17
|
|
|
18
18
|
export class TransactionUtils {
|
|
19
19
|
/**
|
|
@@ -36,7 +36,7 @@ export class TransactionUtils {
|
|
|
36
36
|
hash: string
|
|
37
37
|
): Promise<ITransaction> {
|
|
38
38
|
if (!ethers.isHexString(hash)) {
|
|
39
|
-
throw
|
|
39
|
+
throw ErrorInvalidHashProvided;
|
|
40
40
|
}
|
|
41
41
|
const networkData = NETWORKS[chainId];
|
|
42
42
|
|
|
@@ -132,11 +132,9 @@ export class TransactionUtils {
|
|
|
132
132
|
fromAddress: filter?.fromAddress,
|
|
133
133
|
toAddress: filter?.toAddress,
|
|
134
134
|
startDate: filter?.startDate
|
|
135
|
-
?
|
|
136
|
-
: undefined,
|
|
137
|
-
endDate: filter.endDate
|
|
138
|
-
? Math.floor(filter.endDate.getTime() / 1000)
|
|
135
|
+
? getUnixTimestamp(filter?.startDate)
|
|
139
136
|
: undefined,
|
|
137
|
+
endDate: filter.endDate ? getUnixTimestamp(filter.endDate) : undefined,
|
|
140
138
|
startBlock: filter.startBlock ? filter.startBlock : undefined,
|
|
141
139
|
endBlock: filter.endBlock ? filter.endBlock : undefined,
|
|
142
140
|
orderDirection: orderDirection,
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TransactionLike } from 'ethers';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Enum for escrow statuses.
|
|
3
5
|
* @readonly
|
|
@@ -21,7 +23,7 @@ export enum EscrowStatus {
|
|
|
21
23
|
*/
|
|
22
24
|
Paid,
|
|
23
25
|
/**
|
|
24
|
-
* Escrow is finished
|
|
26
|
+
* Escrow is finished.
|
|
25
27
|
*/
|
|
26
28
|
Complete,
|
|
27
29
|
/**
|
|
@@ -124,7 +126,7 @@ export type NetworkData = {
|
|
|
124
126
|
*/
|
|
125
127
|
subgraphUrl: string;
|
|
126
128
|
/**
|
|
127
|
-
* Subgraph URL
|
|
129
|
+
* Subgraph URL API key
|
|
128
130
|
*/
|
|
129
131
|
subgraphUrlApiKey: string;
|
|
130
132
|
/**
|
|
@@ -168,3 +170,5 @@ export type EscrowWithdraw = {
|
|
|
168
170
|
*/
|
|
169
171
|
amountWithdrawn: bigint;
|
|
170
172
|
};
|
|
173
|
+
|
|
174
|
+
export type TransactionLikeWithNonce = TransactionLike & { nonce: number };
|
package/src/utils.ts
CHANGED
|
@@ -57,7 +57,6 @@ export const isValidUrl = (url: string) => {
|
|
|
57
57
|
* **Get the subgraph URL.*
|
|
58
58
|
*
|
|
59
59
|
* @param {NetworkData} networkData
|
|
60
|
-
* @param {string} apiKey
|
|
61
60
|
* @returns
|
|
62
61
|
*/
|
|
63
62
|
export const getSubgraphUrl = (networkData: NetworkData) => {
|
|
@@ -74,3 +73,13 @@ export const getSubgraphUrl = (networkData: NetworkData) => {
|
|
|
74
73
|
|
|
75
74
|
return subgraphUrl;
|
|
76
75
|
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* **Convert a date to Unix timestamp (seconds since epoch).*
|
|
79
|
+
*
|
|
80
|
+
* @param {Date} date
|
|
81
|
+
* @returns {number}
|
|
82
|
+
*/
|
|
83
|
+
export const getUnixTimestamp = (date: Date): number => {
|
|
84
|
+
return Math.floor(date.getTime() / 1000);
|
|
85
|
+
};
|