@human-protocol/sdk 1.1.11 → 1.1.13

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 (56) hide show
  1. package/README.md +2 -0
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/constants.js +14 -14
  4. package/dist/error.d.ts +8 -0
  5. package/dist/error.d.ts.map +1 -1
  6. package/dist/error.js +10 -2
  7. package/dist/escrow.d.ts +31 -11
  8. package/dist/escrow.d.ts.map +1 -1
  9. package/dist/escrow.js +133 -37
  10. package/dist/graphql/queries/escrow.d.ts +1 -0
  11. package/dist/graphql/queries/escrow.d.ts.map +1 -1
  12. package/dist/graphql/queries/escrow.js +18 -2
  13. package/dist/graphql/queries/index.d.ts +1 -0
  14. package/dist/graphql/queries/index.d.ts.map +1 -1
  15. package/dist/graphql/queries/index.js +1 -0
  16. package/dist/graphql/queries/payout.d.ts +3 -0
  17. package/dist/graphql/queries/payout.d.ts.map +1 -0
  18. package/dist/graphql/queries/payout.js +49 -0
  19. package/dist/graphql/queries/staking.d.ts +4 -0
  20. package/dist/graphql/queries/staking.d.ts.map +1 -0
  21. package/dist/graphql/queries/staking.js +58 -0
  22. package/dist/graphql/queries/statistics.d.ts.map +1 -1
  23. package/dist/graphql/queries/statistics.js +10 -2
  24. package/dist/graphql/types.d.ts +24 -2
  25. package/dist/graphql/types.d.ts.map +1 -1
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +2 -1
  29. package/dist/interfaces.d.ts +34 -9
  30. package/dist/interfaces.d.ts.map +1 -1
  31. package/dist/staking.d.ts +8 -8
  32. package/dist/staking.d.ts.map +1 -1
  33. package/dist/staking.js +16 -38
  34. package/dist/statistics.d.ts.map +1 -1
  35. package/dist/statistics.js +2 -8
  36. package/dist/storage.d.ts +3 -0
  37. package/dist/storage.d.ts.map +1 -1
  38. package/dist/storage.js +3 -0
  39. package/dist/types.d.ts +18 -0
  40. package/dist/types.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/constants.ts +16 -14
  43. package/src/error.ts +14 -0
  44. package/src/escrow.ts +189 -46
  45. package/src/graphql/queries/escrow.ts +26 -2
  46. package/src/graphql/queries/index.ts +1 -0
  47. package/src/graphql/queries/payout.ts +47 -0
  48. package/src/graphql/queries/staking.ts +57 -0
  49. package/src/graphql/queries/statistics.ts +10 -2
  50. package/src/graphql/types.ts +29 -2
  51. package/src/index.ts +2 -1
  52. package/src/interfaces.ts +35 -14
  53. package/src/staking.ts +23 -53
  54. package/src/statistics.ts +2 -12
  55. package/src/storage.ts +3 -0
  56. package/src/types.ts +20 -0
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { StakingClient } from './staking';
2
2
  import { StorageClient } from './storage';
3
3
  import { KVStoreClient } from './kvstore';
4
- import { EscrowClient } from './escrow';
4
+ import { EscrowClient, EscrowUtils } from './escrow';
5
5
  import { StatisticsClient } from './statistics';
6
6
 
7
7
  export * from './constants';
@@ -14,5 +14,6 @@ export {
14
14
  StorageClient,
15
15
  KVStoreClient,
16
16
  EscrowClient,
17
+ EscrowUtils,
17
18
  StatisticsClient,
18
19
  };
package/src/interfaces.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { BigNumber } from 'ethers';
2
+ import { EscrowStatus } from './types';
3
+ import { ChainId } from './enums';
2
4
 
3
5
  export interface IAllocation {
4
6
  escrowAddress: string;
@@ -13,37 +15,48 @@ export interface IReward {
13
15
  amount: BigNumber;
14
16
  }
15
17
 
16
- export interface IStaker {
17
- staker: string;
18
- tokensStaked: BigNumber;
19
- tokensAllocated: BigNumber;
20
- tokensLocked: BigNumber;
21
- tokensLockedUntil: BigNumber;
22
- tokensAvailable: BigNumber;
18
+ export interface ILeader {
19
+ id: string;
20
+ address: string;
21
+ amountStaked: BigNumber;
22
+ amountAllocated: BigNumber;
23
+ amountLocked: BigNumber;
24
+ lockedUntilTimestamp: BigNumber;
25
+ amountWithdrawn: BigNumber;
26
+ amountSlashed: BigNumber;
27
+ reputation: BigNumber;
28
+ reward: BigNumber;
29
+ amountJobsLaunched: BigNumber;
30
+ role?: string;
31
+ fee?: BigNumber;
32
+ publicKey?: string;
33
+ webhookUrl?: string;
34
+ url?: string;
23
35
  }
24
36
 
25
- type EscrowStatus =
26
- | 'Launched'
27
- | 'Pending'
28
- | 'Partial'
29
- | 'Paid'
30
- | 'Complete'
31
- | 'Cancelled';
37
+ export interface ILeadersFilter {
38
+ role?: string;
39
+ }
32
40
 
33
41
  export interface IEscrowsFilter {
34
42
  launcher?: string;
35
43
  reputationOracle?: string;
36
44
  recordingOracle?: string;
45
+ exchangeOracle?: string;
46
+ jobRequesterId?: string;
37
47
  status?: EscrowStatus;
38
48
  from?: Date;
39
49
  to?: Date;
50
+ networks: ChainId[];
40
51
  }
41
52
 
42
53
  export interface IEscrowConfig {
43
54
  recordingOracle: string;
44
55
  reputationOracle: string;
56
+ exchangeOracle: string;
45
57
  recordingOracleFee: BigNumber;
46
58
  reputationOracleFee: BigNumber;
59
+ exchangeOracleFee: BigNumber;
47
60
  manifestUrl: string;
48
61
  manifestHash: string;
49
62
  }
@@ -58,4 +71,12 @@ export interface IKeyPair {
58
71
  export interface IStatisticsParams {
59
72
  from?: Date;
60
73
  to?: Date;
74
+ limit?: number;
75
+ }
76
+
77
+ export interface IPayoutFilter {
78
+ escrowAddress?: string;
79
+ recipient?: string;
80
+ from?: Date;
81
+ to?: Date;
61
82
  }
package/src/staking.ts CHANGED
@@ -24,14 +24,14 @@ import {
24
24
  ErrorInvalidStakingValueSign,
25
25
  ErrorInvalidStakingValueType,
26
26
  ErrorProviderDoesNotExist,
27
- ErrorStakingGetStakers,
28
27
  ErrorUnsupportedChainID,
29
28
  } from './error';
30
- import { IAllocation, IReward, IStaker } from './interfaces';
29
+ import { IAllocation, ILeader, ILeadersFilter, IReward } from './interfaces';
31
30
  import { NetworkData } from './types';
32
31
  import { throwError } from './utils';
33
32
  import { GET_REWARD_ADDED_EVENTS_QUERY } from './graphql/queries/reward';
34
33
  import { RewardAddedEventData } from './graphql';
34
+ import { GET_LEADER_QUERY, GET_LEADERS_QUERY } from './graphql/queries/staking';
35
35
 
36
36
  export class StakingClient {
37
37
  public signerOrProvider: Signer | Provider;
@@ -333,75 +333,45 @@ export class StakingClient {
333
333
  }
334
334
 
335
335
  /**
336
- * **Returns the staking information about an staker address.*
336
+ * **Returns the leader details for a given address**
337
337
  *
338
- * @param {string} staker - Address of the staker
339
- * @returns {Promise<IStaker>} - Return staking information of the specified address
338
+ * @param {string} address - Leader address
339
+ * @returns {Promise<ILeader>} - Return leader details
340
340
  * @throws {Error} - An error object if an error occurred, result otherwise
341
341
  */
342
- public async getStaker(staker: string): Promise<IStaker> {
343
- if (!ethers.utils.isAddress(staker)) {
342
+ public async getLeader(address: string): Promise<ILeader> {
343
+ if (!ethers.utils.isAddress(address)) {
344
344
  throw ErrorInvalidStakerAddressProvided;
345
345
  }
346
346
 
347
347
  try {
348
- const result = await this.stakingContract.getStaker(staker);
349
-
350
- const tokensStaked = BigNumber.from(result.tokensStaked),
351
- tokensAllocated = BigNumber.from(result.tokensAllocated),
352
- tokensLocked = BigNumber.from(result.tokensLocked),
353
- tokensLockedUntil = BigNumber.from(result.tokensLockedUntil);
354
-
355
- const tokensAvailable = tokensStaked
356
- .sub(tokensAllocated)
357
- .sub(tokensLocked);
358
-
359
- return {
360
- staker,
361
- tokensStaked,
362
- tokensAllocated,
363
- tokensLocked,
364
- tokensLockedUntil,
365
- tokensAvailable,
366
- };
348
+ const { leader } = await gqlFetch<{
349
+ leader: ILeader;
350
+ }>(this.network.subgraphUrl, GET_LEADER_QUERY, {
351
+ address,
352
+ });
353
+
354
+ return leader;
367
355
  } catch (e) {
368
356
  return throwError(e);
369
357
  }
370
358
  }
371
359
 
372
360
  /**
373
- * **Returns the staking information about all stakers of the protocol.*
361
+ * **Returns the leaders data **
374
362
  *
375
- * @returns {Promise<IStaker[]>} - Return an array with all stakers information
363
+ * @returns {Promise<ILeader[]>} - Return an array with leaders data
376
364
  * @throws {Error} - An error object if an error occurred, results otherwise
377
365
  */
378
- public async getAllStakers(): Promise<IStaker[]> {
366
+ public async getLeaders(filter: ILeadersFilter = {}): Promise<ILeader[]> {
379
367
  try {
380
- const result = await this.stakingContract.getListOfStakers();
381
-
382
- if (result[1].length === 0) {
383
- throw ErrorStakingGetStakers;
384
- }
385
-
386
- return result[1].map((staker: any, index: number) => {
387
- const tokensStaked = BigNumber.from(staker.tokensStaked),
388
- tokensAllocated = BigNumber.from(staker.tokensAllocated),
389
- tokensLocked = BigNumber.from(staker.tokensLocked),
390
- tokensLockedUntil = BigNumber.from(staker.tokensLockedUntil);
391
-
392
- const tokensAvailable = tokensStaked
393
- .sub(tokensAllocated)
394
- .sub(tokensLocked);
395
-
396
- return {
397
- staker: result[0][index],
398
- tokensStaked,
399
- tokensAllocated,
400
- tokensLocked,
401
- tokensLockedUntil,
402
- tokensAvailable,
403
- };
368
+ const { leaders } = await gqlFetch<{
369
+ leaders: ILeader[];
370
+ }>(this.network.subgraphUrl, GET_LEADERS_QUERY(filter), {
371
+ role: filter.role,
404
372
  });
373
+
374
+ return leaders;
405
375
  } catch (e) {
406
376
  return throwError(e);
407
377
  }
package/src/statistics.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { BigNumber } from 'ethers';
2
3
  import gqlFetch from 'graphql-request';
3
4
 
4
5
  import {
@@ -18,7 +19,6 @@ import {
18
19
  import { IStatisticsParams } from './interfaces';
19
20
  import { NetworkData } from './types';
20
21
  import { throwError } from './utils';
21
- import { BigNumber } from 'ethers';
22
22
 
23
23
  export class StatisticsClient {
24
24
  public network: NetworkData;
@@ -92,11 +92,6 @@ export class StatisticsClient {
92
92
  dailyWorkersData: eventDayDatas.map((eventDayData) => ({
93
93
  timestamp: new Date(+eventDayData.timestamp * 1000),
94
94
  activeWorkers: +eventDayData.dailyWorkerCount,
95
- averageJobsSolved:
96
- eventDayData.dailyWorkerCount === '0'
97
- ? 0
98
- : +eventDayData.dailyBulkPayoutEventCount /
99
- +eventDayData.dailyWorkerCount,
100
95
  })),
101
96
  };
102
97
  } catch (e: any) {
@@ -127,12 +122,6 @@ export class StatisticsClient {
127
122
  timestamp: new Date(+eventDayData.timestamp * 1000),
128
123
  totalAmountPaid: BigNumber.from(eventDayData.dailyPayoutAmount),
129
124
  totalCount: +eventDayData.dailyPayoutCount,
130
- averageAmountPerJob:
131
- eventDayData.dailyBulkPayoutEventCount === '0'
132
- ? BigNumber.from(0)
133
- : BigNumber.from(eventDayData.dailyPayoutAmount).div(
134
- eventDayData.dailyBulkPayoutEventCount
135
- ),
136
125
  averageAmountPerWorker:
137
126
  eventDayData.dailyWorkerCount === '0'
138
127
  ? BigNumber.from(0)
@@ -176,6 +165,7 @@ export class StatisticsClient {
176
165
  totalTransferAmount: BigNumber.from(
177
166
  hmtokenStatistics.totalValueTransfered
178
167
  ),
168
+ totalTransferCount: Number(hmtokenStatistics.totalTransferEventCount),
179
169
  totalHolders: +hmtokenStatistics.holders,
180
170
  holders: holders.map((holder) => ({
181
171
  address: holder.address,
package/src/storage.ts CHANGED
@@ -13,6 +13,9 @@ import { UploadFile, StorageCredentials, StorageParams } from './types';
13
13
  import { isValidUrl } from './utils';
14
14
  import { HttpStatus } from './constants';
15
15
 
16
+ /**
17
+ * @deprecated StorageClient is deprecated. Use Minio.Client directly.
18
+ */
16
19
  export class StorageClient {
17
20
  private client: Minio.Client;
18
21
  private clientParams: StorageParams;
package/src/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { BigNumber } from 'ethers';
2
+
1
3
  /**
2
4
  * Enum for escrow statuses.
3
5
  * @readonly
@@ -33,6 +35,7 @@ export enum EscrowStatus {
33
35
  /**
34
36
  * AWS/GCP cloud storage access data
35
37
  * @readonly
38
+ * @deprecated StorageClient is deprecated. Use Minio.Client directly.
36
39
  */
37
40
  export type StorageCredentials = {
38
41
  /**
@@ -45,6 +48,9 @@ export type StorageCredentials = {
45
48
  secretKey: string;
46
49
  };
47
50
 
51
+ /**
52
+ * @deprecated StorageClient is deprecated. Use Minio.Client directly.
53
+ */
48
54
  export type StorageParams = {
49
55
  /**
50
56
  * Request endPoint
@@ -132,3 +138,17 @@ export type NetworkData = {
132
138
  */
133
139
  oldFactoryAddress: string;
134
140
  };
141
+
142
+ /**
143
+ * Represents the response data for an escrow cancellation.
144
+ */
145
+ export type EscrowCancel = {
146
+ /**
147
+ * The hash of the transaction associated with the escrow cancellation.
148
+ */
149
+ txHash: string;
150
+ /**
151
+ * The amount refunded in the escrow cancellation.
152
+ */
153
+ amountRefunded: BigNumber;
154
+ };