@human-protocol/sdk 5.0.0-beta.2 → 5.0.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.
@@ -1,4 +1,4 @@
1
- import { ChainId } from '../enums';
1
+ import { IReputationNetwork } from '../interfaces';
2
2
 
3
3
  export type EscrowData = {
4
4
  id: string;
@@ -7,24 +7,56 @@ export type EscrowData = {
7
7
  balance: string;
8
8
  count: string;
9
9
  factoryAddress: string;
10
- finalResultsUrl?: string;
11
- finalResultsHash?: string;
12
- intermediateResultsUrl?: string;
13
- intermediateResultsHash?: string;
10
+ finalResultsUrl: string | null;
11
+ finalResultsHash: string | null;
12
+ intermediateResultsUrl: string | null;
13
+ intermediateResultsHash: string | null;
14
14
  launcher: string;
15
- manifestHash?: string;
16
- manifestUrl?: string;
17
- recordingOracle?: string;
18
- reputationOracle?: string;
19
- exchangeOracle?: string;
20
- recordingOracleFee?: string;
21
- reputationOracleFee?: string;
22
- exchangeOracleFee?: string;
15
+ jobRequesterId: string | null;
16
+ manifestHash: string | null;
17
+ manifest: string | null;
18
+ recordingOracle: string | null;
19
+ reputationOracle: string | null;
20
+ exchangeOracle: string | null;
21
+ recordingOracleFee: string | null;
22
+ reputationOracleFee: string | null;
23
+ exchangeOracleFee: string | null;
23
24
  status: string;
24
25
  token: string;
25
26
  totalFundedAmount: string;
26
27
  createdAt: string;
27
- chainId: number;
28
+ };
29
+
30
+ export type WorkerData = {
31
+ id: string;
32
+ address: string;
33
+ totalHMTAmountReceived: string;
34
+ payoutCount: string;
35
+ };
36
+
37
+ export type InternalTransactionData = {
38
+ from: string;
39
+ to: string;
40
+ value: string;
41
+ method: string;
42
+ receiver: string | null;
43
+ escrow: string | null;
44
+ token: string | null;
45
+ id: string | null;
46
+ };
47
+
48
+ export type TransactionData = {
49
+ block: string;
50
+ txHash: string;
51
+ from: string;
52
+ to: string;
53
+ timestamp: string;
54
+ value: string;
55
+ method: string;
56
+ receiver: string | null;
57
+ escrow: string | null;
58
+ token: string | null;
59
+ internalTransactions: InternalTransactionData[];
28
60
  };
29
61
 
30
62
  export type HMTStatisticsData = {
@@ -77,86 +109,15 @@ export type RewardAddedEventData = {
77
109
  amount: string;
78
110
  };
79
111
 
80
- export type DailyEscrowData = {
81
- timestamp: Date;
82
- escrowsTotal: number;
83
- escrowsPending: number;
84
- escrowsSolved: number;
85
- escrowsPaid: number;
86
- escrowsCancelled: number;
87
- };
88
-
89
- export type EscrowStatistics = {
90
- totalEscrows: number;
91
- dailyEscrowsData: DailyEscrowData[];
92
- };
93
-
94
- export type DailyWorkerData = {
95
- timestamp: Date;
96
- activeWorkers: number;
97
- };
98
-
99
- export type WorkerStatistics = {
100
- dailyWorkersData: DailyWorkerData[];
101
- };
102
-
103
- export type DailyPaymentData = {
104
- timestamp: Date;
105
- totalAmountPaid: bigint;
106
- totalCount: number;
107
- averageAmountPerWorker: bigint;
108
- };
109
-
110
- export type PaymentStatistics = {
111
- dailyPaymentsData: DailyPaymentData[];
112
- };
113
-
114
112
  export type HMTHolderData = {
115
113
  address: string;
116
114
  balance: string;
117
115
  };
118
116
 
119
- export type HMTHolder = {
120
- address: string;
121
- balance: bigint;
122
- };
123
-
124
- export type DailyHMTData = {
125
- timestamp: Date;
126
- totalTransactionAmount: bigint;
127
- totalTransactionCount: number;
128
- dailyUniqueSenders: number;
129
- dailyUniqueReceivers: number;
130
- };
131
-
132
- export type HMTStatistics = {
133
- totalTransferAmount: bigint;
134
- totalTransferCount: number;
135
- totalHolders: number;
136
- };
137
-
138
- export type IMDataEntity = {
139
- served: number;
140
- solved: number;
141
- };
142
-
143
- export type IMData = Record<string, IMDataEntity>;
144
-
145
- export type DailyTaskData = {
146
- timestamp: Date;
147
- tasksTotal: number;
148
- tasksSolved: number;
149
- };
150
-
151
- export type TaskStatistics = {
152
- dailyTasksData: DailyTaskData[];
153
- };
154
-
155
117
  export type StatusEvent = {
156
- timestamp: number;
118
+ timestamp: string;
157
119
  escrowAddress: string;
158
120
  status: string;
159
- chainId: ChainId;
160
121
  };
161
122
 
162
123
  export type KVStoreData = {
@@ -165,5 +126,65 @@ export type KVStoreData = {
165
126
  key: string;
166
127
  value: string;
167
128
  timestamp: Date;
168
- block: number;
129
+ block: string;
130
+ };
131
+
132
+ export type StakerData = {
133
+ id: string;
134
+ address: string;
135
+ stakedAmount: string;
136
+ lockedAmount: string;
137
+ withdrawnAmount: string;
138
+ slashedAmount: string;
139
+ lockedUntilTimestamp: string;
140
+ lastDepositTimestamp: string;
141
+ };
142
+
143
+ export interface IOperatorSubgraph {
144
+ id: string;
145
+ address: string;
146
+ amountJobsProcessed: string;
147
+ role: string | null;
148
+ fee: string | null;
149
+ publicKey: string | null;
150
+ webhookUrl: string | null;
151
+ website: string | null;
152
+ url: string | null;
153
+ registrationNeeded: boolean | null;
154
+ registrationInstructions: string | null;
155
+ name: string | null;
156
+ category: string | null;
157
+ jobTypes: string | string[] | null;
158
+ reputationNetworks: { address: string }[];
159
+ staker: {
160
+ stakedAmount: string;
161
+ lockedAmount: string;
162
+ lockedUntilTimestamp: string;
163
+ withdrawnAmount: string;
164
+ slashedAmount: string;
165
+ lastDepositTimestamp: string;
166
+ } | null;
167
+ }
168
+
169
+ export interface IReputationNetworkSubgraph
170
+ extends Omit<IReputationNetwork, 'operators'> {
171
+ operators: IOperatorSubgraph[];
172
+ }
173
+
174
+ export type PayoutData = {
175
+ id: string;
176
+ escrowAddress: string;
177
+ recipient: string;
178
+ amount: string;
179
+ createdAt: string;
180
+ };
181
+
182
+ export type CancellationRefundData = {
183
+ id: string;
184
+ escrowAddress: string;
185
+ receiver: string;
186
+ amount: string;
187
+ block: string;
188
+ timestamp: string;
189
+ txHash: string;
169
190
  };
package/src/interfaces.ts CHANGED
@@ -10,50 +10,24 @@ export interface IOperator {
10
10
  id: string;
11
11
  chainId: ChainId;
12
12
  address: string;
13
- stakedAmount: bigint;
14
- lockedAmount: bigint;
15
- lockedUntilTimestamp: bigint;
16
- withdrawnAmount: bigint;
17
- slashedAmount: bigint;
18
- amountJobsProcessed: bigint;
19
- role?: string;
20
- fee?: bigint;
21
- publicKey?: string;
22
- webhookUrl?: string;
23
- website?: string;
24
- url?: string;
25
- jobTypes?: string[];
26
- registrationNeeded?: boolean;
27
- registrationInstructions?: string;
28
- reputationNetworks?: string[];
29
- name?: string;
30
- category?: string;
31
- }
32
-
33
- export interface IOperatorSubgraph {
34
- id: string;
35
- address: string;
36
- amountJobsProcessed: bigint;
37
- role?: string;
38
- fee?: bigint;
39
- publicKey?: string;
40
- webhookUrl?: string;
41
- website?: string;
42
- url?: string;
43
- registrationNeeded?: boolean;
44
- registrationInstructions?: string;
45
- name?: string;
46
- category?: string;
47
- jobTypes?: string | string[];
48
- reputationNetworks?: { address: string }[];
49
- staker?: {
50
- stakedAmount: bigint;
51
- lockedAmount: bigint;
52
- lockedUntilTimestamp: bigint;
53
- withdrawnAmount: bigint;
54
- slashedAmount: bigint;
55
- lastDepositTimestamp: bigint;
56
- };
13
+ stakedAmount: bigint | null;
14
+ lockedAmount: bigint | null;
15
+ lockedUntilTimestamp: number | null;
16
+ withdrawnAmount: bigint | null;
17
+ slashedAmount: bigint | null;
18
+ amountJobsProcessed: bigint | null;
19
+ role: string | null;
20
+ fee: bigint | null;
21
+ publicKey: string | null;
22
+ webhookUrl: string | null;
23
+ website: string | null;
24
+ url: string | null;
25
+ jobTypes: string[] | null;
26
+ registrationNeeded: boolean | null;
27
+ registrationInstructions: string | null;
28
+ reputationNetworks: string[];
29
+ name: string | null;
30
+ category: string | null;
57
31
  }
58
32
 
59
33
  export interface IOperatorsFilter extends IPagination {
@@ -69,35 +43,31 @@ export interface IReputationNetwork {
69
43
  operators: IOperator[];
70
44
  }
71
45
 
72
- export interface IReputationNetworkSubgraph
73
- extends Omit<IReputationNetwork, 'operators'> {
74
- operators: IOperatorSubgraph[];
75
- }
76
-
77
46
  export interface IEscrow {
78
47
  id: string;
79
48
  address: string;
80
- amountPaid: string;
81
- balance: string;
82
- count: string;
49
+ amountPaid: bigint;
50
+ balance: bigint;
51
+ count: number;
83
52
  factoryAddress: string;
84
- finalResultsUrl?: string;
85
- finalResultsHash?: string;
86
- intermediateResultsUrl?: string;
87
- intermediateResultsHash?: string;
53
+ finalResultsUrl: string | null;
54
+ finalResultsHash: string | null;
55
+ intermediateResultsUrl: string | null;
56
+ intermediateResultsHash: string | null;
88
57
  launcher: string;
89
- manifestHash?: string;
90
- manifest?: string;
91
- recordingOracle?: string;
92
- reputationOracle?: string;
93
- exchangeOracle?: string;
94
- recordingOracleFee?: string;
95
- reputationOracleFee?: string;
96
- exchangeOracleFee?: string;
58
+ jobRequesterId: string | null;
59
+ manifestHash: string | null;
60
+ manifest: string | null;
61
+ recordingOracle: string | null;
62
+ reputationOracle: string | null;
63
+ exchangeOracle: string | null;
64
+ recordingOracleFee: number | null;
65
+ reputationOracleFee: number | null;
66
+ exchangeOracleFee: number | null;
97
67
  status: string;
98
68
  token: string;
99
- totalFundedAmount: string;
100
- createdAt: string;
69
+ totalFundedAmount: bigint;
70
+ createdAt: number;
101
71
  chainId: number;
102
72
  }
103
73
 
@@ -156,11 +126,11 @@ export interface IKVStore {
156
126
  export interface InternalTransaction {
157
127
  from: string;
158
128
  to: string;
159
- value: string;
129
+ value: bigint;
160
130
  method: string;
161
- receiver?: string;
162
- escrow?: string;
163
- token?: string;
131
+ receiver: string | null;
132
+ escrow: string | null;
133
+ token: string | null;
164
134
  }
165
135
 
166
136
  export interface ITransaction {
@@ -168,12 +138,12 @@ export interface ITransaction {
168
138
  txHash: string;
169
139
  from: string;
170
140
  to: string;
171
- timestamp: bigint;
172
- value: string;
141
+ timestamp: number;
142
+ value: bigint;
173
143
  method: string;
174
- receiver?: string;
175
- escrow?: string;
176
- token?: string;
144
+ receiver: string | null;
145
+ escrow: string | null;
146
+ token: string | null;
177
147
  internalTransactions: InternalTransaction[];
178
148
  }
179
149
 
@@ -214,7 +184,7 @@ export interface IStatusEventFilter extends IPagination {
214
184
  export interface IWorker {
215
185
  id: string;
216
186
  address: string;
217
- totalHMTAmountReceived: number;
187
+ totalHMTAmountReceived: bigint;
218
188
  payoutCount: number;
219
189
  }
220
190
 
@@ -228,10 +198,10 @@ export interface IStaker {
228
198
  address: string;
229
199
  stakedAmount: bigint;
230
200
  lockedAmount: bigint;
231
- lockedUntil: bigint;
232
201
  withdrawableAmount: bigint;
233
202
  slashedAmount: bigint;
234
- lastDepositTimestamp: bigint;
203
+ lockedUntil: number;
204
+ lastDepositTimestamp: number;
235
205
  }
236
206
 
237
207
  export interface IStakersFilter extends IPagination {
@@ -258,3 +228,87 @@ export interface ICancellationRefundFilter extends IPagination {
258
228
  from?: Date;
259
229
  to?: Date;
260
230
  }
231
+
232
+ export interface IDailyEscrow {
233
+ timestamp: number;
234
+ escrowsTotal: number;
235
+ escrowsPending: number;
236
+ escrowsSolved: number;
237
+ escrowsPaid: number;
238
+ escrowsCancelled: number;
239
+ }
240
+
241
+ export interface IEscrowStatistics {
242
+ totalEscrows: number;
243
+ dailyEscrowsData: IDailyEscrow[];
244
+ }
245
+
246
+ export interface IDailyWorker {
247
+ timestamp: number;
248
+ activeWorkers: number;
249
+ }
250
+
251
+ export interface IWorkerStatistics {
252
+ dailyWorkersData: IDailyWorker[];
253
+ }
254
+
255
+ export interface IDailyPayment {
256
+ timestamp: number;
257
+ totalAmountPaid: bigint;
258
+ totalCount: number;
259
+ averageAmountPerWorker: bigint;
260
+ }
261
+
262
+ export interface IPaymentStatistics {
263
+ dailyPaymentsData: IDailyPayment[];
264
+ }
265
+
266
+ export interface IHMTStatistics {
267
+ totalTransferAmount: bigint;
268
+ totalTransferCount: number;
269
+ totalHolders: number;
270
+ }
271
+
272
+ export interface IHMTHolder {
273
+ address: string;
274
+ balance: bigint;
275
+ }
276
+
277
+ export interface IDailyHMT {
278
+ timestamp: number;
279
+ totalTransactionAmount: bigint;
280
+ totalTransactionCount: number;
281
+ dailyUniqueSenders: number;
282
+ dailyUniqueReceivers: number;
283
+ }
284
+
285
+ export interface IStatusEvent {
286
+ timestamp: number;
287
+ escrowAddress: string;
288
+ status: EscrowStatus;
289
+ chainId: ChainId;
290
+ }
291
+
292
+ export interface ICancellationRefund {
293
+ id: string;
294
+ escrowAddress: string;
295
+ receiver: string;
296
+ amount: bigint;
297
+ block: number;
298
+ timestamp: number;
299
+ txHash: string;
300
+ }
301
+
302
+ export interface IPayout {
303
+ id: string;
304
+ escrowAddress: string;
305
+ recipient: string;
306
+ amount: bigint;
307
+ createdAt: number;
308
+ }
309
+
310
+ export interface IEscrowWithdraw {
311
+ txHash: string;
312
+ tokenAddress: string;
313
+ withdrawnAmount: bigint;
314
+ }
package/src/operator.ts CHANGED
@@ -1,14 +1,12 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import gqlFetch from 'graphql-request';
3
+ import { IOperator, IOperatorsFilter, IReward } from './interfaces';
4
+ import { GET_REWARD_ADDED_EVENTS_QUERY } from './graphql/queries/reward';
3
5
  import {
4
- IOperator,
5
6
  IOperatorSubgraph,
6
- IOperatorsFilter,
7
7
  IReputationNetworkSubgraph,
8
- IReward,
9
- } from './interfaces';
10
- import { GET_REWARD_ADDED_EVENTS_QUERY } from './graphql/queries/reward';
11
- import { RewardAddedEventData } from './graphql';
8
+ RewardAddedEventData,
9
+ } from './graphql';
12
10
  import {
13
11
  GET_LEADER_QUERY,
14
12
  GET_LEADERS_QUERY,
@@ -236,14 +234,20 @@ function mapOperator(operator: IOperatorSubgraph, chainId: ChainId): IOperator {
236
234
  id: operator.id,
237
235
  chainId,
238
236
  address: operator.address,
239
- stakedAmount: BigInt(staker?.stakedAmount || 0),
240
- lockedAmount: BigInt(staker?.lockedAmount || 0),
241
- lockedUntilTimestamp: BigInt(staker?.lockedUntilTimestamp || 0),
242
- withdrawnAmount: BigInt(staker?.withdrawnAmount || 0),
243
- slashedAmount: BigInt(staker?.slashedAmount || 0),
244
- amountJobsProcessed: BigInt(operator.amountJobsProcessed || 0),
237
+ stakedAmount: staker?.stakedAmount ? BigInt(staker?.stakedAmount) : null,
238
+ lockedAmount: staker?.lockedAmount ? BigInt(staker?.lockedAmount) : null,
239
+ lockedUntilTimestamp: staker?.lockedUntilTimestamp
240
+ ? Number(staker.lockedUntilTimestamp) * 1000
241
+ : null,
242
+ withdrawnAmount: staker?.withdrawnAmount
243
+ ? BigInt(staker?.withdrawnAmount)
244
+ : null,
245
+ slashedAmount: staker?.slashedAmount ? BigInt(staker?.slashedAmount) : null,
246
+ amountJobsProcessed: operator.amountJobsProcessed
247
+ ? BigInt(operator.amountJobsProcessed)
248
+ : null,
245
249
  role: operator.role,
246
- fee: operator.fee ? BigInt(operator.fee) : undefined,
250
+ fee: operator.fee ? BigInt(operator.fee) : null,
247
251
  publicKey: operator.publicKey,
248
252
  webhookUrl: operator.webhookUrl,
249
253
  website: operator.website,
package/src/staking.ts CHANGED
@@ -24,6 +24,7 @@ import {
24
24
  ErrorUnsupportedChainID,
25
25
  } from './error';
26
26
  import { IStaker, IStakersFilter, StakerInfo } from './interfaces';
27
+ import { StakerData } from './graphql';
27
28
  import { NetworkData } from './types';
28
29
  import { getSubgraphUrl, throwError } from './utils';
29
30
  import {
@@ -509,7 +510,7 @@ export class StakingUtils {
509
510
  throw ErrorUnsupportedChainID;
510
511
  }
511
512
 
512
- const { staker } = await gqlFetch<{ staker: IStaker }>(
513
+ const { staker } = await gqlFetch<{ staker: StakerData }>(
513
514
  getSubgraphUrl(networkData),
514
515
  GET_STAKER_BY_ADDRESS_QUERY,
515
516
  { id: stakerAddress.toLowerCase() }
@@ -519,7 +520,7 @@ export class StakingUtils {
519
520
  throw ErrorStakerNotFound;
520
521
  }
521
522
 
522
- return staker;
523
+ return mapStaker(staker);
523
524
  }
524
525
 
525
526
  /**
@@ -539,7 +540,7 @@ export class StakingUtils {
539
540
  throw ErrorUnsupportedChainID;
540
541
  }
541
542
 
542
- const { stakers } = await gqlFetch<{ stakers: IStaker[] }>(
543
+ const { stakers } = await gqlFetch<{ stakers: StakerData[] }>(
543
544
  getSubgraphUrl(networkData),
544
545
  GET_STAKERS_QUERY(filter),
545
546
  {
@@ -577,6 +578,18 @@ export class StakingUtils {
577
578
  return [];
578
579
  }
579
580
 
580
- return stakers;
581
+ return stakers.map((s) => mapStaker(s));
581
582
  }
582
583
  }
584
+
585
+ function mapStaker(s: StakerData): IStaker {
586
+ return {
587
+ address: s.address,
588
+ stakedAmount: BigInt(s.stakedAmount),
589
+ lockedAmount: BigInt(s.lockedAmount),
590
+ withdrawableAmount: BigInt(s.withdrawnAmount),
591
+ slashedAmount: BigInt(s.slashedAmount),
592
+ lockedUntil: Number(s.lockedUntilTimestamp) * 1000,
593
+ lastDepositTimestamp: Number(s.lastDepositTimestamp) * 1000,
594
+ };
595
+ }