@human-protocol/sdk 5.0.0 → 5.2.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/base.d.ts +1 -10
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +0 -21
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +7 -22
- package/dist/encryption.js +1 -1
- package/dist/enums.d.ts +0 -1
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +0 -1
- package/dist/error.d.ts +8 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +9 -1
- package/dist/escrow.d.ts +14 -17
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +34 -33
- package/dist/interfaces.d.ts +14 -0
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +9 -5
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +15 -15
- package/dist/operator.d.ts +9 -5
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +16 -16
- package/dist/staking.d.ts +6 -3
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +13 -15
- package/dist/statistics.d.ts +13 -7
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +24 -22
- package/dist/storage.js +4 -4
- package/dist/transaction.d.ts +5 -3
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +8 -11
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +66 -1
- package/dist/worker.d.ts +5 -3
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +8 -10
- package/package.json +8 -5
- package/src/base.ts +1 -23
- package/src/constants.ts +6 -24
- package/src/encryption.ts +1 -1
- package/src/enums.ts +0 -1
- package/src/error.ts +14 -0
- package/src/escrow.ts +70 -64
- package/src/interfaces.ts +15 -0
- package/src/kvstore.ts +26 -24
- package/src/operator.ts +54 -26
- package/src/staking.ts +28 -27
- package/src/statistics.ts +87 -47
- package/src/storage.ts +4 -4
- package/src/transaction.ts +39 -26
- package/src/utils.ts +81 -0
- package/src/worker.ts +32 -17
package/src/operator.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
IOperator,
|
|
4
|
+
IOperatorsFilter,
|
|
5
|
+
IReward,
|
|
6
|
+
SubgraphOptions,
|
|
7
|
+
} from './interfaces';
|
|
4
8
|
import { GET_REWARD_ADDED_EVENTS_QUERY } from './graphql/queries/reward';
|
|
5
9
|
import {
|
|
6
10
|
IOperatorSubgraph,
|
|
@@ -18,7 +22,7 @@ import {
|
|
|
18
22
|
ErrorInvalidStakerAddressProvided,
|
|
19
23
|
ErrorUnsupportedChainID,
|
|
20
24
|
} from './error';
|
|
21
|
-
import { getSubgraphUrl } from './utils';
|
|
25
|
+
import { getSubgraphUrl, customGqlFetch } from './utils';
|
|
22
26
|
import { ChainId, OrderDirection } from './enums';
|
|
23
27
|
import { NETWORKS } from './constants';
|
|
24
28
|
|
|
@@ -28,6 +32,7 @@ export class OperatorUtils {
|
|
|
28
32
|
*
|
|
29
33
|
* @param {ChainId} chainId Network in which the operator is deployed
|
|
30
34
|
* @param {string} address Operator address.
|
|
35
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
31
36
|
* @returns {Promise<IOperator | null>} - Returns the operator details or null if not found.
|
|
32
37
|
*
|
|
33
38
|
* **Code example**
|
|
@@ -40,7 +45,8 @@ export class OperatorUtils {
|
|
|
40
45
|
*/
|
|
41
46
|
public static async getOperator(
|
|
42
47
|
chainId: ChainId,
|
|
43
|
-
address: string
|
|
48
|
+
address: string,
|
|
49
|
+
options?: SubgraphOptions
|
|
44
50
|
): Promise<IOperator | null> {
|
|
45
51
|
if (!ethers.isAddress(address)) {
|
|
46
52
|
throw ErrorInvalidStakerAddressProvided;
|
|
@@ -51,10 +57,11 @@ export class OperatorUtils {
|
|
|
51
57
|
throw ErrorUnsupportedChainID;
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
const { operator } = await
|
|
60
|
+
const { operator } = await customGqlFetch<{
|
|
55
61
|
operator: IOperatorSubgraph;
|
|
56
62
|
}>(getSubgraphUrl(networkData), GET_LEADER_QUERY, {
|
|
57
63
|
address: address.toLowerCase(),
|
|
64
|
+
options,
|
|
58
65
|
});
|
|
59
66
|
|
|
60
67
|
if (!operator) {
|
|
@@ -68,6 +75,7 @@ export class OperatorUtils {
|
|
|
68
75
|
* This function returns all the operator details of the protocol.
|
|
69
76
|
*
|
|
70
77
|
* @param {IOperatorsFilter} filter Filter for the operators.
|
|
78
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
71
79
|
* @returns {Promise<IOperator[]>} Returns an array with all the operator details.
|
|
72
80
|
*
|
|
73
81
|
* **Code example**
|
|
@@ -82,7 +90,8 @@ export class OperatorUtils {
|
|
|
82
90
|
* ```
|
|
83
91
|
*/
|
|
84
92
|
public static async getOperators(
|
|
85
|
-
filter: IOperatorsFilter
|
|
93
|
+
filter: IOperatorsFilter,
|
|
94
|
+
options?: SubgraphOptions
|
|
86
95
|
): Promise<IOperator[]> {
|
|
87
96
|
const first =
|
|
88
97
|
filter.first !== undefined && filter.first > 0
|
|
@@ -107,16 +116,21 @@ export class OperatorUtils {
|
|
|
107
116
|
throw ErrorUnsupportedChainID;
|
|
108
117
|
}
|
|
109
118
|
|
|
110
|
-
const { operators } = await
|
|
119
|
+
const { operators } = await customGqlFetch<{
|
|
111
120
|
operators: IOperatorSubgraph[];
|
|
112
|
-
}>(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
}>(
|
|
122
|
+
getSubgraphUrl(networkData),
|
|
123
|
+
GET_LEADERS_QUERY(filter),
|
|
124
|
+
{
|
|
125
|
+
minStakedAmount: filter?.minStakedAmount,
|
|
126
|
+
roles: filter?.roles,
|
|
127
|
+
orderBy: orderBy,
|
|
128
|
+
orderDirection: orderDirection,
|
|
129
|
+
first: first,
|
|
130
|
+
skip: skip,
|
|
131
|
+
},
|
|
132
|
+
options
|
|
133
|
+
);
|
|
120
134
|
|
|
121
135
|
if (!operators) {
|
|
122
136
|
return [];
|
|
@@ -131,6 +145,7 @@ export class OperatorUtils {
|
|
|
131
145
|
* @param {ChainId} chainId Network in which the reputation network is deployed
|
|
132
146
|
* @param {string} address Address of the reputation oracle.
|
|
133
147
|
* @param {string} [role] - (Optional) Role of the operator.
|
|
148
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
134
149
|
* @returns {Promise<IOperator[]>} - Returns an array of operator details.
|
|
135
150
|
*
|
|
136
151
|
* **Code example**
|
|
@@ -144,19 +159,25 @@ export class OperatorUtils {
|
|
|
144
159
|
public static async getReputationNetworkOperators(
|
|
145
160
|
chainId: ChainId,
|
|
146
161
|
address: string,
|
|
147
|
-
role?: string
|
|
162
|
+
role?: string,
|
|
163
|
+
options?: SubgraphOptions
|
|
148
164
|
): Promise<IOperator[]> {
|
|
149
165
|
const networkData = NETWORKS[chainId];
|
|
150
166
|
|
|
151
167
|
if (!networkData) {
|
|
152
168
|
throw ErrorUnsupportedChainID;
|
|
153
169
|
}
|
|
154
|
-
const { reputationNetwork } = await
|
|
170
|
+
const { reputationNetwork } = await customGqlFetch<{
|
|
155
171
|
reputationNetwork: IReputationNetworkSubgraph;
|
|
156
|
-
}>(
|
|
157
|
-
|
|
158
|
-
role
|
|
159
|
-
|
|
172
|
+
}>(
|
|
173
|
+
getSubgraphUrl(networkData),
|
|
174
|
+
GET_REPUTATION_NETWORK_QUERY(role),
|
|
175
|
+
{
|
|
176
|
+
address: address.toLowerCase(),
|
|
177
|
+
role: role,
|
|
178
|
+
},
|
|
179
|
+
options
|
|
180
|
+
);
|
|
160
181
|
|
|
161
182
|
if (!reputationNetwork) return [];
|
|
162
183
|
|
|
@@ -170,6 +191,7 @@ export class OperatorUtils {
|
|
|
170
191
|
*
|
|
171
192
|
* @param {ChainId} chainId Network in which the rewards are deployed
|
|
172
193
|
* @param {string} slasherAddress Slasher address.
|
|
194
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
173
195
|
* @returns {Promise<IReward[]>} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
|
|
174
196
|
*
|
|
175
197
|
* **Code example**
|
|
@@ -182,7 +204,8 @@ export class OperatorUtils {
|
|
|
182
204
|
*/
|
|
183
205
|
public static async getRewards(
|
|
184
206
|
chainId: ChainId,
|
|
185
|
-
slasherAddress: string
|
|
207
|
+
slasherAddress: string,
|
|
208
|
+
options?: SubgraphOptions
|
|
186
209
|
): Promise<IReward[]> {
|
|
187
210
|
if (!ethers.isAddress(slasherAddress)) {
|
|
188
211
|
throw ErrorInvalidSlasherAddressProvided;
|
|
@@ -193,11 +216,16 @@ export class OperatorUtils {
|
|
|
193
216
|
throw ErrorUnsupportedChainID;
|
|
194
217
|
}
|
|
195
218
|
|
|
196
|
-
const { rewardAddedEvents } = await
|
|
219
|
+
const { rewardAddedEvents } = await customGqlFetch<{
|
|
197
220
|
rewardAddedEvents: RewardAddedEventData[];
|
|
198
|
-
}>(
|
|
199
|
-
|
|
200
|
-
|
|
221
|
+
}>(
|
|
222
|
+
getSubgraphUrl(networkData),
|
|
223
|
+
GET_REWARD_ADDED_EVENTS_QUERY,
|
|
224
|
+
{
|
|
225
|
+
slasherAddress: slasherAddress.toLowerCase(),
|
|
226
|
+
},
|
|
227
|
+
options
|
|
228
|
+
);
|
|
201
229
|
|
|
202
230
|
if (!rewardAddedEvents) return [];
|
|
203
231
|
|
package/src/staking.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
Staking__factory,
|
|
8
8
|
} from '@human-protocol/core/typechain-types';
|
|
9
9
|
import { ContractRunner, Overrides, ethers } from 'ethers';
|
|
10
|
-
import gqlFetch from 'graphql-request';
|
|
11
10
|
import { BaseEthersClient } from './base';
|
|
12
11
|
import { NETWORKS } from './constants';
|
|
13
12
|
import { requiresSigner } from './decorators';
|
|
@@ -23,10 +22,15 @@ import {
|
|
|
23
22
|
ErrorStakerNotFound,
|
|
24
23
|
ErrorUnsupportedChainID,
|
|
25
24
|
} from './error';
|
|
26
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
IStaker,
|
|
27
|
+
IStakersFilter,
|
|
28
|
+
StakerInfo,
|
|
29
|
+
SubgraphOptions,
|
|
30
|
+
} from './interfaces';
|
|
27
31
|
import { StakerData } from './graphql';
|
|
28
32
|
import { NetworkData } from './types';
|
|
29
|
-
import { getSubgraphUrl, throwError } from './utils';
|
|
33
|
+
import { getSubgraphUrl, customGqlFetch, throwError } from './utils';
|
|
30
34
|
import {
|
|
31
35
|
GET_STAKER_BY_ADDRESS_QUERY,
|
|
32
36
|
GET_STAKERS_QUERY,
|
|
@@ -214,7 +218,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
214
218
|
await this.tokenContract.approve(
|
|
215
219
|
await this.stakingContract.getAddress(),
|
|
216
220
|
amount,
|
|
217
|
-
|
|
221
|
+
txOptions
|
|
218
222
|
)
|
|
219
223
|
).wait();
|
|
220
224
|
return;
|
|
@@ -261,12 +265,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
261
265
|
}
|
|
262
266
|
|
|
263
267
|
try {
|
|
264
|
-
await (
|
|
265
|
-
await this.stakingContract.stake(
|
|
266
|
-
amount,
|
|
267
|
-
this.applyTxDefaults(txOptions)
|
|
268
|
-
)
|
|
269
|
-
).wait();
|
|
268
|
+
await (await this.stakingContract.stake(amount, txOptions)).wait();
|
|
270
269
|
return;
|
|
271
270
|
} catch (e) {
|
|
272
271
|
return throwError(e);
|
|
@@ -313,12 +312,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
313
312
|
}
|
|
314
313
|
|
|
315
314
|
try {
|
|
316
|
-
await (
|
|
317
|
-
await this.stakingContract.unstake(
|
|
318
|
-
amount,
|
|
319
|
-
this.applyTxDefaults(txOptions)
|
|
320
|
-
)
|
|
321
|
-
).wait();
|
|
315
|
+
await (await this.stakingContract.unstake(amount, txOptions)).wait();
|
|
322
316
|
return;
|
|
323
317
|
} catch (e) {
|
|
324
318
|
return throwError(e);
|
|
@@ -352,9 +346,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
352
346
|
@requiresSigner
|
|
353
347
|
public async withdraw(txOptions: Overrides = {}): Promise<void> {
|
|
354
348
|
try {
|
|
355
|
-
await (
|
|
356
|
-
await this.stakingContract.withdraw(this.applyTxDefaults(txOptions))
|
|
357
|
-
).wait();
|
|
349
|
+
await (await this.stakingContract.withdraw(txOptions)).wait();
|
|
358
350
|
return;
|
|
359
351
|
} catch (e) {
|
|
360
352
|
return throwError(e);
|
|
@@ -421,7 +413,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
421
413
|
staker,
|
|
422
414
|
escrowAddress,
|
|
423
415
|
amount,
|
|
424
|
-
|
|
416
|
+
txOptions
|
|
425
417
|
)
|
|
426
418
|
).wait();
|
|
427
419
|
|
|
@@ -458,7 +450,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
458
450
|
|
|
459
451
|
try {
|
|
460
452
|
const stakerInfo = await this.stakingContract.stakes(stakerAddress);
|
|
461
|
-
|
|
453
|
+
|
|
462
454
|
const currentBlock = await this.runner.provider!.getBlockNumber();
|
|
463
455
|
|
|
464
456
|
const tokensWithdrawable =
|
|
@@ -495,11 +487,13 @@ export class StakingUtils {
|
|
|
495
487
|
*
|
|
496
488
|
* @param {ChainId} chainId Network in which the staking contract is deployed
|
|
497
489
|
* @param {string} stakerAddress Address of the staker
|
|
490
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
498
491
|
* @returns {Promise<IStaker>} Staker info from subgraph
|
|
499
492
|
*/
|
|
500
493
|
public static async getStaker(
|
|
501
494
|
chainId: ChainId,
|
|
502
|
-
stakerAddress: string
|
|
495
|
+
stakerAddress: string,
|
|
496
|
+
options?: SubgraphOptions
|
|
503
497
|
): Promise<IStaker> {
|
|
504
498
|
if (!ethers.isAddress(stakerAddress)) {
|
|
505
499
|
throw ErrorInvalidStakerAddressProvided;
|
|
@@ -510,10 +504,11 @@ export class StakingUtils {
|
|
|
510
504
|
throw ErrorUnsupportedChainID;
|
|
511
505
|
}
|
|
512
506
|
|
|
513
|
-
const { staker } = await
|
|
507
|
+
const { staker } = await customGqlFetch<{ staker: StakerData }>(
|
|
514
508
|
getSubgraphUrl(networkData),
|
|
515
509
|
GET_STAKER_BY_ADDRESS_QUERY,
|
|
516
|
-
{ id: stakerAddress.toLowerCase() }
|
|
510
|
+
{ id: stakerAddress.toLowerCase() },
|
|
511
|
+
options
|
|
517
512
|
);
|
|
518
513
|
|
|
519
514
|
if (!staker) {
|
|
@@ -526,9 +521,14 @@ export class StakingUtils {
|
|
|
526
521
|
/**
|
|
527
522
|
* Gets all stakers from the subgraph with filters, pagination and ordering.
|
|
528
523
|
*
|
|
524
|
+
* @param {IStakersFilter} filter Stakers filter with pagination and ordering
|
|
525
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
529
526
|
* @returns {Promise<IStaker[]>} Array of stakers
|
|
530
527
|
*/
|
|
531
|
-
public static async getStakers(
|
|
528
|
+
public static async getStakers(
|
|
529
|
+
filter: IStakersFilter,
|
|
530
|
+
options?: SubgraphOptions
|
|
531
|
+
): Promise<IStaker[]> {
|
|
532
532
|
const first =
|
|
533
533
|
filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
534
534
|
const skip = filter.skip || 0;
|
|
@@ -540,7 +540,7 @@ export class StakingUtils {
|
|
|
540
540
|
throw ErrorUnsupportedChainID;
|
|
541
541
|
}
|
|
542
542
|
|
|
543
|
-
const { stakers } = await
|
|
543
|
+
const { stakers } = await customGqlFetch<{ stakers: StakerData[] }>(
|
|
544
544
|
getSubgraphUrl(networkData),
|
|
545
545
|
GET_STAKERS_QUERY(filter),
|
|
546
546
|
{
|
|
@@ -572,7 +572,8 @@ export class StakingUtils {
|
|
|
572
572
|
orderDirection: orderDirection,
|
|
573
573
|
first: first,
|
|
574
574
|
skip: skip,
|
|
575
|
-
}
|
|
575
|
+
},
|
|
576
|
+
options
|
|
576
577
|
);
|
|
577
578
|
if (!stakers) {
|
|
578
579
|
return [];
|
package/src/statistics.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import gqlFetch from 'graphql-request';
|
|
3
|
-
|
|
4
2
|
import { OrderDirection } from './enums';
|
|
5
3
|
import {
|
|
6
4
|
EscrowStatisticsData,
|
|
@@ -21,9 +19,15 @@ import {
|
|
|
21
19
|
IPaymentStatistics,
|
|
22
20
|
IStatisticsFilter,
|
|
23
21
|
IWorkerStatistics,
|
|
22
|
+
SubgraphOptions,
|
|
24
23
|
} from './interfaces';
|
|
25
24
|
import { NetworkData } from './types';
|
|
26
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
getSubgraphUrl,
|
|
27
|
+
getUnixTimestamp,
|
|
28
|
+
customGqlFetch,
|
|
29
|
+
throwError,
|
|
30
|
+
} from './utils';
|
|
27
31
|
|
|
28
32
|
/**
|
|
29
33
|
* ## Introduction
|
|
@@ -103,6 +107,7 @@ export class StatisticsClient {
|
|
|
103
107
|
* ```
|
|
104
108
|
*
|
|
105
109
|
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
110
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
106
111
|
* @returns {Promise<IEscrowStatistics>} Escrow statistics data.
|
|
107
112
|
*
|
|
108
113
|
* **Code example**
|
|
@@ -120,7 +125,8 @@ export class StatisticsClient {
|
|
|
120
125
|
* ```
|
|
121
126
|
*/
|
|
122
127
|
async getEscrowStatistics(
|
|
123
|
-
filter: IStatisticsFilter = {}
|
|
128
|
+
filter: IStatisticsFilter = {},
|
|
129
|
+
options?: SubgraphOptions
|
|
124
130
|
): Promise<IEscrowStatistics> {
|
|
125
131
|
try {
|
|
126
132
|
const first =
|
|
@@ -128,19 +134,24 @@ export class StatisticsClient {
|
|
|
128
134
|
const skip = filter.skip || 0;
|
|
129
135
|
const orderDirection = filter.orderDirection || OrderDirection.ASC;
|
|
130
136
|
|
|
131
|
-
const { escrowStatistics } = await
|
|
137
|
+
const { escrowStatistics } = await customGqlFetch<{
|
|
132
138
|
escrowStatistics: EscrowStatisticsData;
|
|
133
|
-
}>(this.subgraphUrl, GET_ESCROW_STATISTICS_QUERY);
|
|
139
|
+
}>(this.subgraphUrl, GET_ESCROW_STATISTICS_QUERY, options);
|
|
134
140
|
|
|
135
|
-
const { eventDayDatas } = await
|
|
141
|
+
const { eventDayDatas } = await customGqlFetch<{
|
|
136
142
|
eventDayDatas: EventDayData[];
|
|
137
|
-
}>(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
}>(
|
|
144
|
+
this.subgraphUrl,
|
|
145
|
+
GET_EVENT_DAY_DATA_QUERY(filter),
|
|
146
|
+
{
|
|
147
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
148
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
149
|
+
orderDirection: orderDirection,
|
|
150
|
+
first: first,
|
|
151
|
+
skip: skip,
|
|
152
|
+
},
|
|
153
|
+
options
|
|
154
|
+
);
|
|
144
155
|
|
|
145
156
|
return {
|
|
146
157
|
totalEscrows: escrowStatistics?.totalEscrowCount
|
|
@@ -187,6 +198,7 @@ export class StatisticsClient {
|
|
|
187
198
|
* ```
|
|
188
199
|
*
|
|
189
200
|
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
201
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
190
202
|
* @returns {Promise<IWorkerStatistics>} Worker statistics data.
|
|
191
203
|
*
|
|
192
204
|
* **Code example**
|
|
@@ -204,7 +216,8 @@ export class StatisticsClient {
|
|
|
204
216
|
* ```
|
|
205
217
|
*/
|
|
206
218
|
async getWorkerStatistics(
|
|
207
|
-
filter: IStatisticsFilter = {}
|
|
219
|
+
filter: IStatisticsFilter = {},
|
|
220
|
+
options?: SubgraphOptions
|
|
208
221
|
): Promise<IWorkerStatistics> {
|
|
209
222
|
try {
|
|
210
223
|
const first =
|
|
@@ -212,15 +225,20 @@ export class StatisticsClient {
|
|
|
212
225
|
const skip = filter.skip || 0;
|
|
213
226
|
const orderDirection = filter.orderDirection || OrderDirection.ASC;
|
|
214
227
|
|
|
215
|
-
const { eventDayDatas } = await
|
|
228
|
+
const { eventDayDatas } = await customGqlFetch<{
|
|
216
229
|
eventDayDatas: EventDayData[];
|
|
217
|
-
}>(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
230
|
+
}>(
|
|
231
|
+
this.subgraphUrl,
|
|
232
|
+
GET_EVENT_DAY_DATA_QUERY(filter),
|
|
233
|
+
{
|
|
234
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
235
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
236
|
+
orderDirection: orderDirection,
|
|
237
|
+
first: first,
|
|
238
|
+
skip: skip,
|
|
239
|
+
},
|
|
240
|
+
options
|
|
241
|
+
);
|
|
224
242
|
|
|
225
243
|
return {
|
|
226
244
|
dailyWorkersData: eventDayDatas.map((eventDayData) => ({
|
|
@@ -262,6 +280,7 @@ export class StatisticsClient {
|
|
|
262
280
|
* ```
|
|
263
281
|
*
|
|
264
282
|
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
283
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
265
284
|
* @returns {Promise<IPaymentStatistics>} Payment statistics data.
|
|
266
285
|
*
|
|
267
286
|
* **Code example**
|
|
@@ -300,7 +319,8 @@ export class StatisticsClient {
|
|
|
300
319
|
* ```
|
|
301
320
|
*/
|
|
302
321
|
async getPaymentStatistics(
|
|
303
|
-
filter: IStatisticsFilter = {}
|
|
322
|
+
filter: IStatisticsFilter = {},
|
|
323
|
+
options?: SubgraphOptions
|
|
304
324
|
): Promise<IPaymentStatistics> {
|
|
305
325
|
try {
|
|
306
326
|
const first =
|
|
@@ -308,15 +328,20 @@ export class StatisticsClient {
|
|
|
308
328
|
const skip = filter.skip || 0;
|
|
309
329
|
const orderDirection = filter.orderDirection || OrderDirection.ASC;
|
|
310
330
|
|
|
311
|
-
const { eventDayDatas } = await
|
|
331
|
+
const { eventDayDatas } = await customGqlFetch<{
|
|
312
332
|
eventDayDatas: EventDayData[];
|
|
313
|
-
}>(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
333
|
+
}>(
|
|
334
|
+
this.subgraphUrl,
|
|
335
|
+
GET_EVENT_DAY_DATA_QUERY(filter),
|
|
336
|
+
{
|
|
337
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
338
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
339
|
+
orderDirection: orderDirection,
|
|
340
|
+
first: first,
|
|
341
|
+
skip: skip,
|
|
342
|
+
},
|
|
343
|
+
options
|
|
344
|
+
);
|
|
320
345
|
|
|
321
346
|
return {
|
|
322
347
|
dailyPaymentsData: eventDayDatas.map((eventDayData) => ({
|
|
@@ -346,6 +371,7 @@ export class StatisticsClient {
|
|
|
346
371
|
* };
|
|
347
372
|
* ```
|
|
348
373
|
*
|
|
374
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
349
375
|
* @returns {Promise<IHMTStatistics>} HMToken statistics data.
|
|
350
376
|
*
|
|
351
377
|
* **Code example**
|
|
@@ -363,11 +389,11 @@ export class StatisticsClient {
|
|
|
363
389
|
* });
|
|
364
390
|
* ```
|
|
365
391
|
*/
|
|
366
|
-
async getHMTStatistics(): Promise<IHMTStatistics> {
|
|
392
|
+
async getHMTStatistics(options?: SubgraphOptions): Promise<IHMTStatistics> {
|
|
367
393
|
try {
|
|
368
|
-
const { hmtokenStatistics } = await
|
|
394
|
+
const { hmtokenStatistics } = await customGqlFetch<{
|
|
369
395
|
hmtokenStatistics: HMTStatisticsData;
|
|
370
|
-
}>(this.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY);
|
|
396
|
+
}>(this.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY, options);
|
|
371
397
|
|
|
372
398
|
return {
|
|
373
399
|
totalTransferAmount: BigInt(hmtokenStatistics.totalValueTransfered),
|
|
@@ -385,6 +411,7 @@ export class StatisticsClient {
|
|
|
385
411
|
* **Input parameters**
|
|
386
412
|
*
|
|
387
413
|
* @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
|
|
414
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
388
415
|
* @returns {Promise<IHMTHolder[]>} List of HMToken holders.
|
|
389
416
|
*
|
|
390
417
|
* **Code example**
|
|
@@ -404,19 +431,23 @@ export class StatisticsClient {
|
|
|
404
431
|
* })));
|
|
405
432
|
* ```
|
|
406
433
|
*/
|
|
407
|
-
async getHMTHolders(
|
|
434
|
+
async getHMTHolders(
|
|
435
|
+
params: IHMTHoldersParams = {},
|
|
436
|
+
options?: SubgraphOptions
|
|
437
|
+
): Promise<IHMTHolder[]> {
|
|
408
438
|
try {
|
|
409
439
|
const { address, orderDirection } = params;
|
|
410
440
|
const query = GET_HOLDERS_QUERY(address);
|
|
411
441
|
|
|
412
|
-
const { holders } = await
|
|
442
|
+
const { holders } = await customGqlFetch<{ holders: HMTHolderData[] }>(
|
|
413
443
|
this.subgraphUrl,
|
|
414
444
|
query,
|
|
415
445
|
{
|
|
416
446
|
address,
|
|
417
447
|
orderBy: 'balance',
|
|
418
448
|
orderDirection,
|
|
419
|
-
}
|
|
449
|
+
},
|
|
450
|
+
options
|
|
420
451
|
);
|
|
421
452
|
|
|
422
453
|
return holders.map((holder) => ({
|
|
@@ -454,6 +485,7 @@ export class StatisticsClient {
|
|
|
454
485
|
* ```
|
|
455
486
|
*
|
|
456
487
|
* @param {IStatisticsFilter} filter Statistics params with duration data
|
|
488
|
+
* @param {SubgraphOptions} options Optional configuration for subgraph requests.
|
|
457
489
|
* @returns {Promise<IDailyHMT[]>} Daily HMToken statistics data.
|
|
458
490
|
*
|
|
459
491
|
* **Code example**
|
|
@@ -475,22 +507,30 @@ export class StatisticsClient {
|
|
|
475
507
|
* console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);
|
|
476
508
|
* ```
|
|
477
509
|
*/
|
|
478
|
-
async getHMTDailyData(
|
|
510
|
+
async getHMTDailyData(
|
|
511
|
+
filter: IStatisticsFilter = {},
|
|
512
|
+
options?: SubgraphOptions
|
|
513
|
+
): Promise<IDailyHMT[]> {
|
|
479
514
|
try {
|
|
480
515
|
const first =
|
|
481
516
|
filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
|
|
482
517
|
const skip = filter.skip || 0;
|
|
483
518
|
const orderDirection = filter.orderDirection || OrderDirection.ASC;
|
|
484
519
|
|
|
485
|
-
const { eventDayDatas } = await
|
|
520
|
+
const { eventDayDatas } = await customGqlFetch<{
|
|
486
521
|
eventDayDatas: EventDayData[];
|
|
487
|
-
}>(
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
522
|
+
}>(
|
|
523
|
+
this.subgraphUrl,
|
|
524
|
+
GET_EVENT_DAY_DATA_QUERY(filter),
|
|
525
|
+
{
|
|
526
|
+
from: filter.from ? getUnixTimestamp(filter.from) : undefined,
|
|
527
|
+
to: filter.to ? getUnixTimestamp(filter.to) : undefined,
|
|
528
|
+
orderDirection: orderDirection,
|
|
529
|
+
first: first,
|
|
530
|
+
skip: skip,
|
|
531
|
+
},
|
|
532
|
+
options
|
|
533
|
+
);
|
|
494
534
|
|
|
495
535
|
return eventDayDatas.map((eventDayData) => ({
|
|
496
536
|
timestamp: +eventDayData.timestamp * 1000,
|
package/src/storage.ts
CHANGED
|
@@ -79,7 +79,7 @@ export class StorageClient {
|
|
|
79
79
|
accessKey: credentials?.accessKey ?? '',
|
|
80
80
|
secretKey: credentials?.secretKey ?? '',
|
|
81
81
|
});
|
|
82
|
-
} catch
|
|
82
|
+
} catch {
|
|
83
83
|
throw ErrorStorageClientNotInitialized;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -122,7 +122,7 @@ export class StorageClient {
|
|
|
122
122
|
const content = response?.read();
|
|
123
123
|
|
|
124
124
|
return { key, content: JSON.parse(content?.toString('utf-8') || '') };
|
|
125
|
-
} catch
|
|
125
|
+
} catch {
|
|
126
126
|
throw ErrorStorageFileNotFound;
|
|
127
127
|
}
|
|
128
128
|
})
|
|
@@ -160,7 +160,7 @@ export class StorageClient {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
return data;
|
|
163
|
-
} catch
|
|
163
|
+
} catch {
|
|
164
164
|
throw ErrorStorageFileNotFound;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
@@ -226,7 +226,7 @@ export class StorageClient {
|
|
|
226
226
|
}/${bucket}/${key}`,
|
|
227
227
|
hash,
|
|
228
228
|
};
|
|
229
|
-
} catch
|
|
229
|
+
} catch {
|
|
230
230
|
throw ErrorStorageFileNotUploaded;
|
|
231
231
|
}
|
|
232
232
|
})
|