@human-protocol/sdk 1.1.16 → 1.1.18

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/src/kvstore.ts CHANGED
@@ -5,11 +5,14 @@ import {
5
5
  KVStore__factory,
6
6
  } from '@human-protocol/core/typechain-types';
7
7
  import { Signer, ethers } from 'ethers';
8
+ import { BaseEthersClient } from './base';
8
9
  import { NETWORKS } from './constants';
9
10
  import { requiresSigner } from './decorators';
10
11
  import { ChainId } from './enums';
11
12
  import {
12
13
  ErrorInvalidAddress,
14
+ ErrorInvalidHash,
15
+ ErrorInvalidUrl,
13
16
  ErrorKVStoreArrayLength,
14
17
  ErrorKVStoreEmptyKey,
15
18
  ErrorProviderDoesNotExist,
@@ -17,6 +20,7 @@ import {
17
20
  ErrorUnsupportedChainID,
18
21
  } from './error';
19
22
  import { NetworkData } from './types';
23
+ import { isValidUrl } from './utils';
20
24
 
21
25
  /**
22
26
  * ## Introduction
@@ -87,33 +91,43 @@ import { NetworkData } from './types';
87
91
  * const kvstoreClient = await KVStoreClient.build(signer);
88
92
  * ```
89
93
  */
90
- export class KVStoreClient {
94
+ export class KVStoreClient extends BaseEthersClient {
91
95
  private contract: KVStore;
92
- private signerOrProvider: Signer | Provider;
93
96
 
94
97
  /**
95
98
  * **KVStoreClient constructor**
96
99
  *
97
100
  * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
98
101
  * @param {NetworkData} network - The network information required to connect to the KVStore contract
102
+ * @param {number | undefined} gasPriceMultiplier - The multiplier to apply to the gas price
99
103
  */
100
- constructor(signerOrProvider: Signer | Provider, network: NetworkData) {
104
+ constructor(
105
+ signerOrProvider: Signer | Provider,
106
+ networkData: NetworkData,
107
+ gasPriceMultiplier?: number
108
+ ) {
109
+ super(signerOrProvider, networkData, gasPriceMultiplier);
110
+
101
111
  this.contract = KVStore__factory.connect(
102
- network.kvstoreAddress,
112
+ networkData.kvstoreAddress,
103
113
  signerOrProvider
104
114
  );
105
- this.signerOrProvider = signerOrProvider;
106
115
  }
107
116
 
108
117
  /**
109
118
  * Creates an instance of KVStoreClient from a Signer or Provider.
110
119
  *
111
120
  * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
121
+ * @param {number | undefined} gasPriceMultiplier - The multiplier to apply to the gas price
122
+ *
112
123
  * @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
113
124
  * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
114
125
  * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
115
126
  */
116
- public static async build(signerOrProvider: Signer | Provider) {
127
+ public static async build(
128
+ signerOrProvider: Signer | Provider,
129
+ gasPriceMultiplier?: number
130
+ ) {
117
131
  let network: Network;
118
132
  if (Signer.isSigner(signerOrProvider)) {
119
133
  if (!signerOrProvider.provider) {
@@ -132,7 +146,7 @@ export class KVStoreClient {
132
146
  throw ErrorUnsupportedChainID;
133
147
  }
134
148
 
135
- return new KVStoreClient(signerOrProvider, networkData);
149
+ return new KVStoreClient(signerOrProvider, networkData, gasPriceMultiplier);
136
150
  }
137
151
 
138
152
  /**
@@ -166,7 +180,9 @@ export class KVStoreClient {
166
180
  if (!Signer.isSigner(this.signerOrProvider)) throw ErrorSigner;
167
181
  if (key === '') throw ErrorKVStoreEmptyKey;
168
182
  try {
169
- await this.contract?.set(key, value);
183
+ await this.contract?.set(key, value, {
184
+ ...(await this.gasPriceOptions()),
185
+ });
170
186
  } catch (e) {
171
187
  if (e instanceof Error) throw Error(`Failed to set value: ${e.message}`);
172
188
  }
@@ -195,7 +211,7 @@ export class KVStoreClient {
195
211
  * const signer = new Wallet(privateKey, provider);
196
212
  * const kvstoreClient = await KVStoreClient.build(signer);
197
213
  *
198
- * const keys = ['Role', 'Webhook_url'];
214
+ * const keys = ['role', 'webhookUrl'];
199
215
  * const values = ['RecordingOracle', 'http://localhost'];
200
216
  * await kvstoreClient.set(keys, values);
201
217
  * ```
@@ -207,13 +223,67 @@ export class KVStoreClient {
207
223
  if (keys.includes('')) throw ErrorKVStoreEmptyKey;
208
224
 
209
225
  try {
210
- await this.contract?.setBulk(keys, values);
226
+ await this.contract?.setBulk(keys, values, {
227
+ ...(await this.gasPriceOptions()),
228
+ });
211
229
  } catch (e) {
212
230
  if (e instanceof Error)
213
231
  throw Error(`Failed to set bulk values: ${e.message}`);
214
232
  }
215
233
  }
216
234
 
235
+ /**
236
+ * This function sets a URL value for the address that submits the transaction.
237
+ *
238
+ * @param {string} url URL to set
239
+ * @param {string | undefined} urlKey Configurable URL key. `url` by default.
240
+ * @returns Returns void if successful. Throws error if any.
241
+ *
242
+ *
243
+ * **Code example**
244
+ *
245
+ * ```ts
246
+ * import { Wallet, providers } from 'ethers';
247
+ * import { KVStoreClient } from '@human-protocol/sdk';
248
+ *
249
+ * const rpcUrl = 'YOUR_RPC_URL';
250
+ * const privateKey = 'YOUR_PRIVATE_KEY'
251
+ *
252
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
253
+ * const signer = new Wallet(privateKey, provider);
254
+ * const kvstoreClient = await KVStoreClient.build(signer);
255
+ *
256
+ * await kvstoreClient.setURL('example.com');
257
+ * await kvstoreClient.setURL('linkedin.com/example', 'linkedinUrl);
258
+ * ```
259
+ */
260
+ @requiresSigner
261
+ public async setURL(url: string, urlKey = 'url'): Promise<void> {
262
+ if (!Signer.isSigner(this.signerOrProvider)) {
263
+ throw ErrorSigner;
264
+ }
265
+
266
+ if (!isValidUrl(url)) {
267
+ throw ErrorInvalidUrl;
268
+ }
269
+
270
+ const content = await fetch(url).then((res) => res.text());
271
+ const contentHash = ethers.utils.keccak256(
272
+ ethers.utils.toUtf8Bytes(content)
273
+ );
274
+
275
+ const hashKey = urlKey + 'Hash';
276
+
277
+ try {
278
+ await this.contract.setBulk([urlKey, hashKey], [url, contentHash], {
279
+ ...(await this.gasPriceOptions()),
280
+ });
281
+ } catch (e) {
282
+ if (e instanceof Error)
283
+ throw Error(`Failed to set URL and hash: ${e.message}`);
284
+ }
285
+ }
286
+
217
287
  /**
218
288
  * This function returns the value for a specified key and address.
219
289
  *
@@ -250,4 +320,66 @@ export class KVStoreClient {
250
320
  return e;
251
321
  }
252
322
  }
323
+
324
+ /**
325
+ * This function returns the URL value for the given entity.
326
+ *
327
+ * @param {string} address Address from which to get the URL value.
328
+ * @param {string} urlKey Configurable URL key. `url` by default.
329
+ * @returns {string} URL value for the given address if exists, and the content is valid
330
+ *
331
+ *
332
+ * **Code example**
333
+ *
334
+ * ```ts
335
+ * import { providers } from 'ethers';
336
+ * import { KVStoreClient } from '@human-protocol/sdk';
337
+ *
338
+ * const rpcUrl = 'YOUR_RPC_URL';
339
+ *
340
+ * const provider = new providers.JsonRpcProvider(rpcUrl);
341
+ * const kvstoreClient = await KVStoreClient.build(provider);
342
+ *
343
+ * const url = await kvstoreClient.getURL('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
344
+ * const linkedinUrl = await kvstoreClient.getURL(
345
+ * '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
346
+ * 'linkedinUrl'
347
+ * );
348
+ * ```
349
+ */
350
+ public async getURL(address: string, urlKey = 'url'): Promise<string> {
351
+ if (!ethers.utils.isAddress(address)) throw ErrorInvalidAddress;
352
+ const hashKey = urlKey + 'Hash';
353
+
354
+ let url = '',
355
+ hash = '';
356
+
357
+ try {
358
+ url = await this.contract?.get(address, urlKey);
359
+ } catch (e) {
360
+ if (e instanceof Error) throw Error(`Failed to get URL: ${e.message}`);
361
+ }
362
+
363
+ // Return empty string
364
+ if (!url?.length) {
365
+ return '';
366
+ }
367
+
368
+ try {
369
+ hash = await this.contract?.get(address, hashKey);
370
+ } catch (e) {
371
+ if (e instanceof Error) throw Error(`Failed to get Hash: ${e.message}`);
372
+ }
373
+
374
+ const content = await fetch(url).then((res) => res.text());
375
+ const contentHash = ethers.utils.keccak256(
376
+ ethers.utils.toUtf8Bytes(content)
377
+ );
378
+
379
+ if (hash !== contentHash) {
380
+ throw ErrorInvalidHash;
381
+ }
382
+
383
+ return url;
384
+ }
253
385
  }
package/src/staking.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  } from '@human-protocol/core/typechain-types';
14
14
  import { BigNumber, Signer, ethers } from 'ethers';
15
15
  import gqlFetch from 'graphql-request';
16
+ import { BaseEthersClient } from './base';
16
17
  import { NETWORKS } from './constants';
17
18
  import { requiresSigner } from './decorators';
18
19
  import { ChainId } from './enums';
@@ -102,48 +103,61 @@ import { GET_LEADER_QUERY, GET_LEADERS_QUERY } from './graphql/queries/staking';
102
103
  * const stakingClient = await StakingClient.build(provider);
103
104
  * ```
104
105
  */
105
- export class StakingClient {
106
- public signerOrProvider: Signer | Provider;
107
- public network: NetworkData;
106
+ export class StakingClient extends BaseEthersClient {
108
107
  public tokenContract: HMToken;
109
108
  public stakingContract: Staking;
110
109
  public escrowFactoryContract: EscrowFactory;
110
+ public rewardPoolContract: RewardPool;
111
111
 
112
112
  /**
113
113
  * **StakingClient constructor**
114
114
  *
115
115
  * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
116
116
  * @param {NetworkData} network - The network information required to connect to the Staking contract
117
+ * @param {number | undefined} gasPriceMultiplier - The multiplier to apply to the gas price
117
118
  */
118
- constructor(signerOrProvider: Signer | Provider, network: NetworkData) {
119
+ constructor(
120
+ signerOrProvider: Signer | Provider,
121
+ networkData: NetworkData,
122
+ gasPriceMultiplier?: number
123
+ ) {
124
+ super(signerOrProvider, networkData, gasPriceMultiplier);
125
+
119
126
  this.stakingContract = Staking__factory.connect(
120
- network.stakingAddress,
127
+ networkData.stakingAddress,
121
128
  signerOrProvider
122
129
  );
123
130
 
124
131
  this.escrowFactoryContract = EscrowFactory__factory.connect(
125
- network.factoryAddress,
132
+ networkData.factoryAddress,
126
133
  signerOrProvider
127
134
  );
128
135
 
129
136
  this.tokenContract = HMToken__factory.connect(
130
- network.hmtAddress,
137
+ networkData.hmtAddress,
131
138
  signerOrProvider
132
139
  );
133
140
 
134
- this.signerOrProvider = signerOrProvider;
135
- this.network = network;
141
+ this.rewardPoolContract = RewardPool__factory.connect(
142
+ networkData.rewardPoolAddress,
143
+ this.signerOrProvider
144
+ );
136
145
  }
137
146
 
138
147
  /**
139
148
  * Creates an instance of StakingClient from a Signer or Provider.
140
149
  *
141
150
  * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
151
+ * @param {number | undefined} gasPriceMultiplier - The multiplier to apply to the gas price
152
+ *
142
153
  * @returns {Promise<StakingClient>} - An instance of StakingClient
143
154
  * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
144
155
  * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
145
156
  */
146
- public static async build(signerOrProvider: Signer | Provider) {
157
+ public static async build(
158
+ signerOrProvider: Signer | Provider,
159
+ gasPriceMultiplier?: number
160
+ ) {
147
161
  let network: Network;
148
162
  if (Signer.isSigner(signerOrProvider)) {
149
163
  if (!signerOrProvider.provider) {
@@ -162,7 +176,22 @@ export class StakingClient {
162
176
  throw ErrorUnsupportedChainID;
163
177
  }
164
178
 
165
- return new StakingClient(signerOrProvider, networkData);
179
+ return new StakingClient(signerOrProvider, networkData, gasPriceMultiplier);
180
+ }
181
+
182
+ /**
183
+ * Check if escrow exists
184
+ *
185
+ * @param escrowAddress Escrow address to check against
186
+ */
187
+ private async checkValidEscrow(escrowAddress: string) {
188
+ if (!ethers.utils.isAddress(escrowAddress)) {
189
+ throw ErrorInvalidEscrowAddressProvided;
190
+ }
191
+
192
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
193
+ throw ErrorEscrowAddressIsNotProvidedByFactory;
194
+ }
166
195
  }
167
196
 
168
197
  /**
@@ -200,7 +229,9 @@ export class StakingClient {
200
229
  }
201
230
 
202
231
  try {
203
- await this.tokenContract.approve(this.stakingContract.address, amount);
232
+ await this.tokenContract.approve(this.stakingContract.address, amount, {
233
+ ...(await this.gasPriceOptions()),
234
+ });
204
235
  return;
205
236
  } catch (e) {
206
237
  return throwError(e);
@@ -245,7 +276,9 @@ export class StakingClient {
245
276
  }
246
277
 
247
278
  try {
248
- await this.stakingContract.stake(amount);
279
+ await this.stakingContract.stake(amount, {
280
+ ...(await this.gasPriceOptions()),
281
+ });
249
282
  return;
250
283
  } catch (e) {
251
284
  return throwError(e);
@@ -289,7 +322,9 @@ export class StakingClient {
289
322
  }
290
323
 
291
324
  try {
292
- await this.stakingContract.unstake(amount);
325
+ await this.stakingContract.unstake(amount, {
326
+ ...(await this.gasPriceOptions()),
327
+ });
293
328
  return;
294
329
  } catch (e) {
295
330
  return throwError(e);
@@ -323,7 +358,9 @@ export class StakingClient {
323
358
  @requiresSigner
324
359
  public async withdraw(): Promise<void> {
325
360
  try {
326
- await this.stakingContract.withdraw();
361
+ await this.stakingContract.withdraw({
362
+ ...(await this.gasPriceOptions()),
363
+ });
327
364
  return;
328
365
  } catch (e) {
329
366
  return throwError(e);
@@ -380,16 +417,12 @@ export class StakingClient {
380
417
  throw ErrorInvalidStakerAddressProvided;
381
418
  }
382
419
 
383
- if (!ethers.utils.isAddress(escrowAddress)) {
384
- throw ErrorInvalidEscrowAddressProvided;
385
- }
386
-
387
- if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
388
- throw ErrorEscrowAddressIsNotProvidedByFactory;
389
- }
420
+ await this.checkValidEscrow(escrowAddress);
390
421
 
391
422
  try {
392
- await this.stakingContract.slash(slasher, staker, escrowAddress, amount);
423
+ await this.stakingContract.slash(slasher, staker, escrowAddress, amount, {
424
+ ...(await this.gasPriceOptions()),
425
+ });
393
426
 
394
427
  return;
395
428
  } catch (e) {
@@ -437,16 +470,12 @@ export class StakingClient {
437
470
  throw ErrorInvalidStakingValueSign;
438
471
  }
439
472
 
440
- if (!ethers.utils.isAddress(escrowAddress)) {
441
- throw ErrorInvalidEscrowAddressProvided;
442
- }
443
-
444
- if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
445
- throw ErrorEscrowAddressIsNotProvidedByFactory;
446
- }
473
+ await this.checkValidEscrow(escrowAddress);
447
474
 
448
475
  try {
449
- await this.stakingContract.allocate(escrowAddress, amount);
476
+ await this.stakingContract.allocate(escrowAddress, amount, {
477
+ ...(await this.gasPriceOptions()),
478
+ });
450
479
  return;
451
480
  } catch (e) {
452
481
  return throwError(e);
@@ -481,16 +510,12 @@ export class StakingClient {
481
510
  */
482
511
  @requiresSigner
483
512
  public async closeAllocation(escrowAddress: string): Promise<void> {
484
- if (!ethers.utils.isAddress(escrowAddress)) {
485
- throw ErrorInvalidEscrowAddressProvided;
486
- }
487
-
488
- if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
489
- throw ErrorEscrowAddressIsNotProvidedByFactory;
490
- }
513
+ await this.checkValidEscrow(escrowAddress);
491
514
 
492
515
  try {
493
- await this.stakingContract.closeAllocation(escrowAddress);
516
+ await this.stakingContract.closeAllocation(escrowAddress, {
517
+ ...(await this.gasPriceOptions()),
518
+ });
494
519
  return;
495
520
  } catch (e) {
496
521
  return throwError(e);
@@ -519,26 +544,17 @@ export class StakingClient {
519
544
  * const signer = new Wallet(privateKey, provider);
520
545
  * const stakingClient = await StakingClient.build(signer);
521
546
  *
522
- * await stakingClient.distributeRewards('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
547
+ * await stakingClient.distributeReward('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
523
548
  * ```
524
549
  */
525
550
  @requiresSigner
526
- public async distributeRewards(escrowAddress: string): Promise<void> {
527
- if (!ethers.utils.isAddress(escrowAddress)) {
528
- throw ErrorInvalidEscrowAddressProvided;
529
- }
530
-
531
- if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
532
- throw ErrorEscrowAddressIsNotProvidedByFactory;
533
- }
551
+ public async distributeReward(escrowAddress: string): Promise<void> {
552
+ await this.checkValidEscrow(escrowAddress);
534
553
 
535
554
  try {
536
- const rewardPoolContract: RewardPool = RewardPool__factory.connect(
537
- await this.stakingContract.rewardPool(),
538
- this.signerOrProvider
539
- );
540
-
541
- await rewardPoolContract.distributeReward(escrowAddress);
555
+ this.rewardPoolContract.distributeReward(escrowAddress, {
556
+ ...(await this.gasPriceOptions()),
557
+ });
542
558
  return;
543
559
  } catch (e) {
544
560
  return throwError(e);
@@ -574,7 +590,7 @@ export class StakingClient {
574
590
  try {
575
591
  const { leader } = await gqlFetch<{
576
592
  leader: ILeader;
577
- }>(this.network.subgraphUrl, GET_LEADER_QUERY, {
593
+ }>(this.networkData.subgraphUrl, GET_LEADER_QUERY, {
578
594
  address: address.toLowerCase(),
579
595
  });
580
596
 
@@ -609,7 +625,7 @@ export class StakingClient {
609
625
  try {
610
626
  const { leaders } = await gqlFetch<{
611
627
  leaders: ILeader[];
612
- }>(this.network.subgraphUrl, GET_LEADERS_QUERY(filter), {
628
+ }>(this.networkData.subgraphUrl, GET_LEADERS_QUERY(filter), {
613
629
  role: filter.role,
614
630
  });
615
631
 
@@ -641,13 +657,7 @@ export class StakingClient {
641
657
  * ```
642
658
  */
643
659
  public async getAllocation(escrowAddress: string): Promise<IAllocation> {
644
- if (!ethers.utils.isAddress(escrowAddress)) {
645
- throw ErrorInvalidEscrowAddressProvided;
646
- }
647
-
648
- if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
649
- throw ErrorEscrowAddressIsNotProvidedByFactory;
650
- }
660
+ await this.checkValidEscrow(escrowAddress);
651
661
 
652
662
  try {
653
663
  const result = await this.stakingContract.getAllocation(escrowAddress);
@@ -686,7 +696,7 @@ export class StakingClient {
686
696
  try {
687
697
  const { rewardAddedEvents } = await gqlFetch<{
688
698
  rewardAddedEvents: RewardAddedEventData[];
689
- }>(this.network.subgraphUrl, GET_REWARD_ADDED_EVENTS_QUERY, {
699
+ }>(this.networkData.subgraphUrl, GET_REWARD_ADDED_EVENTS_QUERY, {
690
700
  slasherAddress: slasherAddress.toLowerCase(),
691
701
  });
692
702
 
package/src/statistics.ts CHANGED
@@ -58,15 +58,15 @@ import { throwError } from './utils';
58
58
  * ```
59
59
  */
60
60
  export class StatisticsClient {
61
- public network: NetworkData;
61
+ public networkData: NetworkData;
62
62
 
63
63
  /**
64
64
  * **StatisticsClient constructor**
65
65
  *
66
- * @param {NetworkData} network - The network information required to connect to the Statistics contract
66
+ * @param {NetworkData} networkData - The network information required to connect to the Statistics contract
67
67
  */
68
- constructor(network: NetworkData) {
69
- this.network = network;
68
+ constructor(networkData: NetworkData) {
69
+ this.networkData = networkData;
70
70
  }
71
71
 
72
72
  /**
@@ -124,11 +124,11 @@ export class StatisticsClient {
124
124
  try {
125
125
  const { escrowStatistics } = await gqlFetch<{
126
126
  escrowStatistics: EscrowStatisticsData;
127
- }>(this.network.subgraphUrl, GET_ESCROW_STATISTICS_QUERY);
127
+ }>(this.networkData.subgraphUrl, GET_ESCROW_STATISTICS_QUERY);
128
128
 
129
129
  const { eventDayDatas } = await gqlFetch<{
130
130
  eventDayDatas: EventDayData[];
131
- }>(this.network.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
131
+ }>(this.networkData.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
132
132
  from: params.from ? params.from.getTime() / 1000 : undefined,
133
133
  to: params.to ? params.to.getTime() / 1000 : undefined,
134
134
  });
@@ -199,7 +199,7 @@ export class StatisticsClient {
199
199
  try {
200
200
  const { eventDayDatas } = await gqlFetch<{
201
201
  eventDayDatas: EventDayData[];
202
- }>(this.network.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
202
+ }>(this.networkData.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
203
203
  from: params.from ? params.from.getTime() / 1000 : undefined,
204
204
  to: params.to ? params.to.getTime() / 1000 : undefined,
205
205
  });
@@ -288,7 +288,7 @@ export class StatisticsClient {
288
288
  try {
289
289
  const { eventDayDatas } = await gqlFetch<{
290
290
  eventDayDatas: EventDayData[];
291
- }>(this.network.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
291
+ }>(this.networkData.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
292
292
  from: params.from ? params.from.getTime() / 1000 : undefined,
293
293
  to: params.to ? params.to.getTime() / 1000 : undefined,
294
294
  });
@@ -398,15 +398,15 @@ export class StatisticsClient {
398
398
  try {
399
399
  const { hmtokenStatistics } = await gqlFetch<{
400
400
  hmtokenStatistics: HMTStatisticsData;
401
- }>(this.network.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY);
401
+ }>(this.networkData.subgraphUrl, GET_HMTOKEN_STATISTICS_QUERY);
402
402
 
403
403
  const { holders } = await gqlFetch<{
404
404
  holders: HMTHolderData[];
405
- }>(this.network.subgraphUrl, GET_HOLDERS_QUERY);
405
+ }>(this.networkData.subgraphUrl, GET_HOLDERS_QUERY);
406
406
 
407
407
  const { eventDayDatas } = await gqlFetch<{
408
408
  eventDayDatas: EventDayData[];
409
- }>(this.network.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
409
+ }>(this.networkData.subgraphUrl, GET_EVENT_DAY_DATA_QUERY(params), {
410
410
  from: params.from ? params.from.getTime() / 1000 : undefined,
411
411
  to: params.to ? params.to.getTime() / 1000 : undefined,
412
412
  });
package/src/storage.ts CHANGED
@@ -217,6 +217,7 @@ export class StorageClient {
217
217
  try {
218
218
  await this.client.putObject(bucket, key, content, {
219
219
  'Content-Type': 'application/json',
220
+ 'Cache-Control': 'no-store',
220
221
  });
221
222
 
222
223
  return {
package/src/utils.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { ethers } from 'ethers';
2
+ import { Provider } from '@ethersproject/abstract-provider';
3
+ import { BigNumber, Signer, ethers } from 'ethers';
3
4
 
4
5
  import {
5
6
  ContractExecutionError,
7
+ ErrorMissingGasPrice,
6
8
  EthereumError,
7
9
  InvalidArgumentError,
8
10
  NonceExpired,
@@ -71,3 +73,29 @@ export const isValidUrl = (url: string) => {
71
73
  return false;
72
74
  }
73
75
  };
76
+
77
+ /**
78
+ * Increase/Decrease gas price
79
+ *
80
+ * @returns {Promise<BigNumber>} Returns the adjusted gas price
81
+ */
82
+ export const gasPriceAdjusted = async (
83
+ signerOrProvider: Signer | Provider,
84
+ gasPriceMultiplier: number
85
+ ): Promise<BigNumber> => {
86
+ let gasPrice;
87
+
88
+ if (Signer.isSigner(signerOrProvider)) {
89
+ gasPrice = (await signerOrProvider.provider?.getFeeData())?.gasPrice;
90
+ } else {
91
+ gasPrice = (await signerOrProvider.getFeeData()).gasPrice;
92
+ }
93
+
94
+ if (!gasPrice) {
95
+ throw ErrorMissingGasPrice;
96
+ }
97
+
98
+ return gasPrice
99
+ .mul(ethers.utils.parseEther(gasPriceMultiplier.toString()))
100
+ .div(ethers.utils.parseEther('1'));
101
+ };