@human-protocol/sdk 1.1.19 → 2.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.
- package/dist/base.d.ts +4 -5
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +3 -3
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +4 -2
- package/dist/error.d.ts +0 -6
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -14
- package/dist/escrow.d.ts +23 -24
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +86 -90
- package/dist/graphql/queries/{staking.d.ts → operator.d.ts} +2 -1
- package/dist/graphql/queries/operator.d.ts.map +1 -0
- package/dist/graphql/queries/{staking.js → operator.js} +24 -1
- package/dist/graphql/types.d.ts +5 -6
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/interfaces.d.ts +28 -18
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +8 -9
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +18 -31
- package/dist/operator.d.ts +68 -0
- package/dist/operator.d.ts.map +1 -0
- package/dist/operator.js +153 -0
- package/dist/staking.d.ts +24 -91
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +47 -166
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +7 -6
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +0 -7
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +8 -28
- package/package.json +4 -4
- package/src/base.ts +5 -6
- package/src/decorators.ts +3 -2
- package/src/error.ts +0 -12
- package/src/escrow.ts +101 -114
- package/src/graphql/queries/{staking.ts → operator.ts} +24 -0
- package/src/graphql/types.ts +5 -7
- package/src/index.ts +2 -0
- package/src/interfaces.ts +30 -18
- package/src/kvstore.ts +20 -38
- package/src/operator.ts +192 -0
- package/src/staking.ts +49 -182
- package/src/statistics.ts +8 -9
- package/src/types.ts +1 -3
- package/src/utils.ts +7 -29
- package/dist/graphql/queries/staking.d.ts.map +0 -1
package/dist/statistics.js
CHANGED
|
@@ -264,11 +264,12 @@ class StatisticsClient {
|
|
|
264
264
|
return {
|
|
265
265
|
dailyPaymentsData: eventDayDatas.map((eventDayData) => ({
|
|
266
266
|
timestamp: new Date(+eventDayData.timestamp * 1000),
|
|
267
|
-
totalAmountPaid: ethers_1.
|
|
267
|
+
totalAmountPaid: ethers_1.ethers.toBigInt(eventDayData.dailyPayoutAmount),
|
|
268
268
|
totalCount: +eventDayData.dailyPayoutCount,
|
|
269
269
|
averageAmountPerWorker: eventDayData.dailyWorkerCount === '0'
|
|
270
|
-
? ethers_1.
|
|
271
|
-
: ethers_1.
|
|
270
|
+
? ethers_1.ethers.toBigInt(0)
|
|
271
|
+
: ethers_1.ethers.toBigInt(eventDayData.dailyPayoutAmount) /
|
|
272
|
+
ethers_1.ethers.toBigInt(eventDayData.dailyWorkerCount),
|
|
272
273
|
})),
|
|
273
274
|
};
|
|
274
275
|
}
|
|
@@ -366,16 +367,16 @@ class StatisticsClient {
|
|
|
366
367
|
to: params.to ? params.to.getTime() / 1000 : undefined,
|
|
367
368
|
});
|
|
368
369
|
return {
|
|
369
|
-
totalTransferAmount: ethers_1.
|
|
370
|
+
totalTransferAmount: ethers_1.ethers.toBigInt(hmtokenStatistics.totalValueTransfered),
|
|
370
371
|
totalTransferCount: Number(hmtokenStatistics.totalTransferEventCount),
|
|
371
372
|
totalHolders: +hmtokenStatistics.holders,
|
|
372
373
|
holders: holders.map((holder) => ({
|
|
373
374
|
address: holder.address,
|
|
374
|
-
balance: ethers_1.
|
|
375
|
+
balance: ethers_1.ethers.toBigInt(holder.balance),
|
|
375
376
|
})),
|
|
376
377
|
dailyHMTData: eventDayDatas.map((eventDayData) => ({
|
|
377
378
|
timestamp: new Date(+eventDayData.timestamp * 1000),
|
|
378
|
-
totalTransactionAmount: ethers_1.
|
|
379
|
+
totalTransactionAmount: ethers_1.ethers.toBigInt(eventDayData.dailyHMTTransferAmount),
|
|
379
380
|
totalTransactionCount: +eventDayData.dailyHMTTransferCount,
|
|
380
381
|
})),
|
|
381
382
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BigNumber } from 'ethers';
|
|
2
1
|
/**
|
|
3
2
|
* Enum for escrow statuses.
|
|
4
3
|
* @readonly
|
|
@@ -144,6 +143,6 @@ export type EscrowCancel = {
|
|
|
144
143
|
/**
|
|
145
144
|
* The amount refunded in the escrow cancellation.
|
|
146
145
|
*/
|
|
147
|
-
amountRefunded:
|
|
146
|
+
amountRefunded: bigint;
|
|
148
147
|
};
|
|
149
148
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;CACV;AAED;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC"}
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,eAAO,MAAM,UAAU,MAAO,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,YAOrC,CAAC"}
|
package/dist/utils.js
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidUrl = exports.throwError =
|
|
3
|
+
exports.isValidUrl = exports.throwError = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
6
|
const error_1 = require("./error");
|
|
7
|
-
/**
|
|
8
|
-
* **Get specific error text.*
|
|
9
|
-
*
|
|
10
|
-
* @param {any} error - An error message.
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
const getRevertReason = (error) => {
|
|
14
|
-
const prefix = "reverted with reason string '";
|
|
15
|
-
const suffix = "'";
|
|
16
|
-
const message = error.data.substring(error.data.indexOf(prefix) + prefix.length);
|
|
17
|
-
return message.substring(0, message.indexOf(suffix));
|
|
18
|
-
};
|
|
19
|
-
exports.getRevertReason = getRevertReason;
|
|
20
7
|
/**
|
|
21
8
|
* **Handle and throw the error.*
|
|
22
9
|
*
|
|
@@ -24,29 +11,22 @@ exports.getRevertReason = getRevertReason;
|
|
|
24
11
|
* @returns
|
|
25
12
|
*/
|
|
26
13
|
const throwError = (e) => {
|
|
27
|
-
if (
|
|
14
|
+
if (ethers_1.ethers.isError(e, 'INVALID_ARGUMENT')) {
|
|
28
15
|
throw new error_1.InvalidArgumentError(e.message);
|
|
29
16
|
}
|
|
30
|
-
else if (e
|
|
31
|
-
throw new error_1.
|
|
32
|
-
}
|
|
33
|
-
else if (e.code === ethers_1.ethers.utils.Logger.errors.CALL_EXCEPTION) {
|
|
34
|
-
const reason = (0, exports.getRevertReason)(e.data);
|
|
35
|
-
throw new error_1.ContractExecutionError(reason);
|
|
36
|
-
}
|
|
37
|
-
else if (e.code === ethers_1.ethers.utils.Logger.errors.UNPREDICTABLE_GAS_LIMIT) {
|
|
38
|
-
throw new error_1.UnpredictableGasLimit(e.message);
|
|
17
|
+
else if (ethers_1.ethers.isError(e, 'CALL_EXCEPTION')) {
|
|
18
|
+
throw new error_1.ContractExecutionError(e.reason);
|
|
39
19
|
}
|
|
40
|
-
else if (
|
|
20
|
+
else if (ethers_1.ethers.isError(e, 'TRANSACTION_REPLACED')) {
|
|
41
21
|
throw new error_1.TransactionReplaced(e.message);
|
|
42
22
|
}
|
|
43
|
-
else if (
|
|
23
|
+
else if (ethers_1.ethers.isError(e, 'REPLACEMENT_UNDERPRICED')) {
|
|
44
24
|
throw new error_1.ReplacementUnderpriced(e.message);
|
|
45
25
|
}
|
|
46
|
-
else if (
|
|
26
|
+
else if (ethers_1.ethers.isError(e, 'NUMERIC_FAULT')) {
|
|
47
27
|
throw new error_1.NumericFault(e.message);
|
|
48
28
|
}
|
|
49
|
-
else if (
|
|
29
|
+
else if (ethers_1.ethers.isError(e, 'NONCE_EXPIRED')) {
|
|
50
30
|
throw new error_1.NonceExpired(e.message);
|
|
51
31
|
}
|
|
52
32
|
else {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@human-protocol/sdk",
|
|
3
3
|
"description": "Human Protocol SDK",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
7
7
|
"dist"
|
|
@@ -40,11 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@human-protocol/core": "*",
|
|
43
|
-
"aws-sdk": "^2.
|
|
43
|
+
"aws-sdk": "^2.1528.0",
|
|
44
44
|
"axios": "^1.4.0",
|
|
45
45
|
"crypto": "^1.0.1",
|
|
46
|
-
"
|
|
47
|
-
"graphql": "^16.7.1",
|
|
46
|
+
"graphql": "^16.8.1",
|
|
48
47
|
"graphql-request": "^6.1.0",
|
|
49
48
|
"graphql-tag": "^2.12.6",
|
|
50
49
|
"minio": "^7.0.32",
|
|
@@ -63,6 +62,7 @@
|
|
|
63
62
|
"./src/encryption.ts",
|
|
64
63
|
"./src/escrow.ts",
|
|
65
64
|
"./src/kvstore.ts",
|
|
65
|
+
"./src/operator.ts",
|
|
66
66
|
"./src/staking.ts",
|
|
67
67
|
"./src/storage.ts",
|
|
68
68
|
"./src/statistics.ts"
|
package/src/base.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Signer } from 'ethers';
|
|
1
|
+
import { ContractRunner } from 'ethers';
|
|
3
2
|
import { NetworkData } from './types';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -9,17 +8,17 @@ import { NetworkData } from './types';
|
|
|
9
8
|
*
|
|
10
9
|
*/
|
|
11
10
|
export abstract class BaseEthersClient {
|
|
12
|
-
protected
|
|
11
|
+
protected runner: ContractRunner;
|
|
13
12
|
public networkData: NetworkData;
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* **BaseClient constructor**
|
|
17
16
|
*
|
|
18
|
-
* @param {
|
|
17
|
+
* @param {ContractRunner} runner The Signer or Provider object to interact with the Ethereum network
|
|
19
18
|
* @param {NetworkData} networkData The network information required to connect to the contracts
|
|
20
19
|
*/
|
|
21
|
-
constructor(
|
|
20
|
+
constructor(runner: ContractRunner, networkData: NetworkData) {
|
|
22
21
|
this.networkData = networkData;
|
|
23
|
-
this.
|
|
22
|
+
this.runner = runner;
|
|
24
23
|
}
|
|
25
24
|
}
|
package/src/decorators.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Signer } from 'ethers';
|
|
3
2
|
import { ErrorSigner } from './error';
|
|
4
3
|
|
|
5
4
|
export function requiresSigner(
|
|
@@ -10,7 +9,9 @@ export function requiresSigner(
|
|
|
10
9
|
const originalMethod = descriptor.value;
|
|
11
10
|
|
|
12
11
|
descriptor.value = async function (this: any, ...args: any[]) {
|
|
13
|
-
|
|
12
|
+
try {
|
|
13
|
+
!this.runner.getAddress();
|
|
14
|
+
} catch {
|
|
14
15
|
throw ErrorSigner;
|
|
15
16
|
}
|
|
16
17
|
|
package/src/error.ts
CHANGED
|
@@ -283,18 +283,6 @@ export class InvalidArgumentError extends EthereumError {
|
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
-
export class OutOfGasError extends EthereumError {
|
|
287
|
-
constructor(message: string) {
|
|
288
|
-
super(`Out of gas: ${message}`);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export class UnpredictableGasLimit extends EthereumError {
|
|
293
|
-
constructor(message: string) {
|
|
294
|
-
super(`Unpredictable gas limit: ${message}`);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
286
|
export class ReplacementUnderpriced extends EthereumError {
|
|
299
287
|
constructor(message: string) {
|
|
300
288
|
super(`Replacement underpriced: ${message}`);
|