@human-protocol/sdk 1.1.5 → 1.1.6
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/README.md +80 -1
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +24 -5
- package/dist/encryption.d.ts +84 -0
- package/dist/encryption.d.ts.map +1 -0
- package/dist/encryption.js +202 -0
- package/dist/error.d.ts +2 -2
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +3 -3
- package/dist/escrow.d.ts +32 -15
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +74 -37
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -14
- package/dist/interfaces.d.ts +10 -12
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +19 -8
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +38 -9
- package/dist/queries.d.ts +3 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +4 -7
- package/dist/staking.d.ts +16 -7
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +40 -12
- package/dist/storage.d.ts +2 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +9 -3
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/constants.ts +24 -5
- package/src/encryption.ts +223 -0
- package/src/error.ts +2 -4
- package/src/escrow.ts +112 -70
- package/src/index.ts +6 -12
- package/src/interfaces.ts +10 -13
- package/src/kvstore.ts +51 -14
- package/src/queries.ts +15 -7
- package/src/staking.ts +60 -24
- package/src/storage.ts +14 -3
- package/src/types.ts +8 -0
- package/dist/init.d.ts +0 -13
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -35
- package/src/init.ts +0 -45
package/dist/escrow.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../src/escrow.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../src/escrow.ts"],"names":[],"mappings":"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"}
|
package/dist/escrow.js
CHANGED
|
@@ -9,25 +9,51 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
|
|
12
|
+
exports.EscrowClient = void 0;
|
|
13
13
|
const typechain_types_1 = require("@human-protocol/core/typechain-types");
|
|
14
14
|
const ethers_1 = require("ethers");
|
|
15
|
-
const error_1 = require("./error");
|
|
16
|
-
const utils_1 = require("./utils");
|
|
17
15
|
const constants_1 = require("./constants");
|
|
18
|
-
const queries_1 = require("./queries");
|
|
19
16
|
const decorators_1 = require("./decorators");
|
|
17
|
+
const error_1 = require("./error");
|
|
18
|
+
const queries_1 = require("./queries");
|
|
19
|
+
const utils_1 = require("./utils");
|
|
20
20
|
class EscrowClient {
|
|
21
21
|
/**
|
|
22
|
-
* **
|
|
22
|
+
* **EscrowClient constructor**
|
|
23
23
|
*
|
|
24
|
-
*
|
|
24
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
25
|
+
* @param {NetworkData} network - The network information required to connect to the Escrow contract
|
|
25
26
|
*/
|
|
26
|
-
constructor(
|
|
27
|
-
this.
|
|
28
|
-
this.network =
|
|
29
|
-
this.
|
|
30
|
-
|
|
27
|
+
constructor(signerOrProvider, network) {
|
|
28
|
+
this.escrowFactoryContract = typechain_types_1.EscrowFactory__factory.connect(network.factoryAddress, signerOrProvider);
|
|
29
|
+
this.network = network;
|
|
30
|
+
this.signerOrProvider = signerOrProvider;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates an instance of EscrowClient from a Signer or Provider.
|
|
34
|
+
*
|
|
35
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
36
|
+
* @returns {Promise<EscrowClient>} - An instance of EscrowClient
|
|
37
|
+
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
38
|
+
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
39
|
+
*/
|
|
40
|
+
static async build(signerOrProvider) {
|
|
41
|
+
let network;
|
|
42
|
+
if (ethers_1.Signer.isSigner(signerOrProvider)) {
|
|
43
|
+
if (!signerOrProvider.provider) {
|
|
44
|
+
throw error_1.ErrorProviderDoesNotExist;
|
|
45
|
+
}
|
|
46
|
+
network = await signerOrProvider.provider.getNetwork();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
network = await signerOrProvider.getNetwork();
|
|
50
|
+
}
|
|
51
|
+
const chainId = network.chainId;
|
|
52
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
53
|
+
if (!networkData) {
|
|
54
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
55
|
+
}
|
|
56
|
+
return new EscrowClient(signerOrProvider, networkData);
|
|
31
57
|
}
|
|
32
58
|
/**
|
|
33
59
|
* Creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
|
|
@@ -67,7 +93,7 @@ class EscrowClient {
|
|
|
67
93
|
* @throws {Error} - An error object if an error occurred.
|
|
68
94
|
*/
|
|
69
95
|
async setup(escrowAddress, escrowConfig) {
|
|
70
|
-
const { recordingOracle, reputationOracle, recordingOracleFee, reputationOracleFee, manifestUrl,
|
|
96
|
+
const { recordingOracle, reputationOracle, recordingOracleFee, reputationOracleFee, manifestUrl, manifestHash, } = escrowConfig;
|
|
71
97
|
if (!ethers_1.ethers.utils.isAddress(recordingOracle)) {
|
|
72
98
|
throw error_1.ErrorInvalidRecordingOracleAddressProvided;
|
|
73
99
|
}
|
|
@@ -89,7 +115,7 @@ class EscrowClient {
|
|
|
89
115
|
if (!(0, utils_1.isValidUrl)(manifestUrl)) {
|
|
90
116
|
throw error_1.ErrorInvalidUrl;
|
|
91
117
|
}
|
|
92
|
-
if (!
|
|
118
|
+
if (!manifestHash) {
|
|
93
119
|
throw error_1.ErrorHashIsEmptyString;
|
|
94
120
|
}
|
|
95
121
|
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
@@ -97,7 +123,7 @@ class EscrowClient {
|
|
|
97
123
|
}
|
|
98
124
|
try {
|
|
99
125
|
this.escrowContract = typechain_types_1.Escrow__factory.connect(escrowAddress, this.signerOrProvider);
|
|
100
|
-
await this.escrowContract.setup(recordingOracle,
|
|
126
|
+
await this.escrowContract.setup(reputationOracle, recordingOracle, reputationOracleFee, recordingOracleFee, manifestUrl, manifestHash);
|
|
101
127
|
return;
|
|
102
128
|
}
|
|
103
129
|
catch (e) {
|
|
@@ -413,6 +439,28 @@ class EscrowClient {
|
|
|
413
439
|
return (0, utils_1.throwError)(e);
|
|
414
440
|
}
|
|
415
441
|
}
|
|
442
|
+
/**
|
|
443
|
+
* Returns the intermediate results file URL.
|
|
444
|
+
*
|
|
445
|
+
* @param {string} escrowAddress - Address of the escrow.
|
|
446
|
+
* @returns {Promise<void>}
|
|
447
|
+
* @throws {Error} - An error object if an error occurred.
|
|
448
|
+
*/
|
|
449
|
+
async getIntermediateResultsUrl(escrowAddress) {
|
|
450
|
+
if (!ethers_1.ethers.utils.isAddress(escrowAddress)) {
|
|
451
|
+
throw error_1.ErrorInvalidEscrowAddressProvided;
|
|
452
|
+
}
|
|
453
|
+
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
454
|
+
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
455
|
+
}
|
|
456
|
+
try {
|
|
457
|
+
this.escrowContract = typechain_types_1.Escrow__factory.connect(escrowAddress, this.signerOrProvider);
|
|
458
|
+
return this.escrowContract.intermediateResultsUrl();
|
|
459
|
+
}
|
|
460
|
+
catch (e) {
|
|
461
|
+
return (0, utils_1.throwError)(e);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
416
464
|
/**
|
|
417
465
|
* Returns the value for a specified key and address
|
|
418
466
|
*
|
|
@@ -458,10 +506,10 @@ class EscrowClient {
|
|
|
458
506
|
}
|
|
459
507
|
}
|
|
460
508
|
/**
|
|
461
|
-
* Returns the
|
|
509
|
+
* Returns the escrow addresses created by a job requester.
|
|
462
510
|
*
|
|
463
511
|
* @param {IEscrowsFilter} requesterAddress - Address of the requester.
|
|
464
|
-
* @returns {Promise<
|
|
512
|
+
* @returns {Promise<string[]>}
|
|
465
513
|
* @throws {Error} - An error object if an error occurred.
|
|
466
514
|
*/
|
|
467
515
|
async getLaunchedEscrows(requesterAddress) {
|
|
@@ -469,38 +517,27 @@ class EscrowClient {
|
|
|
469
517
|
throw error_1.ErrorInvalidAddress;
|
|
470
518
|
}
|
|
471
519
|
try {
|
|
472
|
-
const { data } = await (0, utils_1.gqlFetch)(this.network.subgraphUrl, (0, queries_1.RAW_LAUNCHED_ESCROWS_QUERY)()
|
|
473
|
-
|
|
474
|
-
});
|
|
475
|
-
return data;
|
|
520
|
+
const { data } = await (0, utils_1.gqlFetch)(this.network.subgraphUrl, (0, queries_1.RAW_LAUNCHED_ESCROWS_QUERY)(requesterAddress));
|
|
521
|
+
return data.data.launchedEscrows.map((escrow) => escrow.id);
|
|
476
522
|
}
|
|
477
523
|
catch (e) {
|
|
478
524
|
return (0, utils_1.throwError)(e);
|
|
479
525
|
}
|
|
480
526
|
}
|
|
481
527
|
/**
|
|
482
|
-
* Returns the
|
|
528
|
+
* Returns the escrow addresses based on a specified filter.
|
|
483
529
|
*
|
|
484
|
-
* @param {
|
|
485
|
-
* @
|
|
486
|
-
* @returns {Promise<void>}
|
|
530
|
+
* @param {IEscrowsFilter} filter - Filter parameters.
|
|
531
|
+
* @returns {Promise<string[]>}
|
|
487
532
|
* @throws {Error} - An error object if an error occurred.
|
|
488
533
|
*/
|
|
489
|
-
async getEscrowsFiltered(
|
|
490
|
-
if (!ethers_1.ethers.utils.isAddress(
|
|
534
|
+
async getEscrowsFiltered(filter) {
|
|
535
|
+
if (filter?.address && !ethers_1.ethers.utils.isAddress(filter?.address)) {
|
|
491
536
|
throw error_1.ErrorInvalidAddress;
|
|
492
537
|
}
|
|
493
|
-
if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
|
|
494
|
-
throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
|
|
495
|
-
}
|
|
496
538
|
try {
|
|
497
|
-
const { data } = await (0, utils_1.gqlFetch)(this.network.subgraphUrl, (0, queries_1.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY)(
|
|
498
|
-
|
|
499
|
-
status: filter.status,
|
|
500
|
-
from: filter.from,
|
|
501
|
-
tro: filter.to,
|
|
502
|
-
});
|
|
503
|
-
return data;
|
|
539
|
+
const { data } = await (0, utils_1.gqlFetch)(this.network.subgraphUrl, (0, queries_1.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY)(filter.address, filter.status, filter.from, filter.to));
|
|
540
|
+
return data.data.launchedEscrows.map((escrow) => escrow.id);
|
|
504
541
|
}
|
|
505
542
|
catch (e) {
|
|
506
543
|
return (0, utils_1.throwError)(e);
|
|
@@ -611,4 +648,4 @@ __decorate([
|
|
|
611
648
|
__metadata("design:paramtypes", [String, Array]),
|
|
612
649
|
__metadata("design:returntype", Promise)
|
|
613
650
|
], EscrowClient.prototype, "addTrustedHandlers", null);
|
|
614
|
-
exports.
|
|
651
|
+
exports.EscrowClient = EscrowClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import EscrowClient from './escrow';
|
|
1
|
+
import { StakingClient } from './staking';
|
|
2
|
+
import { StorageClient } from './storage';
|
|
3
|
+
import { KVStoreClient } from './kvstore';
|
|
4
|
+
import { EscrowClient } from './escrow';
|
|
6
5
|
export * from './constants';
|
|
7
6
|
export * from './types';
|
|
8
7
|
export * from './enums';
|
|
9
|
-
export
|
|
8
|
+
export * from './interfaces';
|
|
9
|
+
export { StakingClient, StorageClient, KVStoreClient, EscrowClient };
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,21 +13,17 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.EscrowClient = exports.KVStoreClient = exports.StorageClient = exports.StakingClient =
|
|
21
|
-
const
|
|
22
|
-
exports
|
|
23
|
-
const
|
|
24
|
-
exports
|
|
25
|
-
const
|
|
26
|
-
exports
|
|
27
|
-
const
|
|
28
|
-
exports
|
|
29
|
-
const escrow_1 = __importDefault(require("./escrow"));
|
|
30
|
-
exports.EscrowClient = escrow_1.default;
|
|
17
|
+
exports.EscrowClient = exports.KVStoreClient = exports.StorageClient = exports.StakingClient = void 0;
|
|
18
|
+
const staking_1 = require("./staking");
|
|
19
|
+
Object.defineProperty(exports, "StakingClient", { enumerable: true, get: function () { return staking_1.StakingClient; } });
|
|
20
|
+
const storage_1 = require("./storage");
|
|
21
|
+
Object.defineProperty(exports, "StorageClient", { enumerable: true, get: function () { return storage_1.StorageClient; } });
|
|
22
|
+
const kvstore_1 = require("./kvstore");
|
|
23
|
+
Object.defineProperty(exports, "KVStoreClient", { enumerable: true, get: function () { return kvstore_1.KVStoreClient; } });
|
|
24
|
+
const escrow_1 = require("./escrow");
|
|
25
|
+
Object.defineProperty(exports, "EscrowClient", { enumerable: true, get: function () { return escrow_1.EscrowClient; } });
|
|
31
26
|
__exportStar(require("./constants"), exports);
|
|
32
27
|
__exportStar(require("./types"), exports);
|
|
33
28
|
__exportStar(require("./enums"), exports);
|
|
29
|
+
__exportStar(require("./interfaces"), exports);
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { BigNumber
|
|
2
|
-
import {
|
|
3
|
-
import { NetworkData } from './types';
|
|
4
|
-
export interface IClientParams {
|
|
5
|
-
signerOrProvider: Signer | Provider;
|
|
6
|
-
network: NetworkData;
|
|
7
|
-
}
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
import { EscrowStatus } from './types';
|
|
8
3
|
export interface IAllocation {
|
|
9
4
|
escrowAddress: string;
|
|
10
5
|
staker: string;
|
|
@@ -24,9 +19,9 @@ export interface IStaker {
|
|
|
24
19
|
tokensAvailable: BigNumber;
|
|
25
20
|
}
|
|
26
21
|
export interface IEscrowsFilter {
|
|
27
|
-
address
|
|
22
|
+
address?: string;
|
|
28
23
|
role?: number;
|
|
29
|
-
status?:
|
|
24
|
+
status?: EscrowStatus;
|
|
30
25
|
from?: Date;
|
|
31
26
|
to?: Date;
|
|
32
27
|
}
|
|
@@ -36,9 +31,12 @@ export interface IEscrowConfig {
|
|
|
36
31
|
recordingOracleFee: BigNumber;
|
|
37
32
|
reputationOracleFee: BigNumber;
|
|
38
33
|
manifestUrl: string;
|
|
39
|
-
|
|
34
|
+
manifestHash: string;
|
|
40
35
|
}
|
|
41
|
-
export interface
|
|
42
|
-
|
|
36
|
+
export interface IKeyPair {
|
|
37
|
+
privateKey: string;
|
|
38
|
+
publicKey: string;
|
|
39
|
+
passphrase: string;
|
|
40
|
+
revocationCertificate?: string;
|
|
43
41
|
}
|
|
44
42
|
//# sourceMappingURL=interfaces.d.ts.map
|
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,YAAY,EAAE,SAAS,CAAC;IACxB,eAAe,EAAE,SAAS,CAAC;IAC3B,YAAY,EAAE,SAAS,CAAC;IACxB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,eAAe,EAAE,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,SAAS,CAAC;IAC9B,mBAAmB,EAAE,SAAS,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
package/dist/kvstore.d.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Provider } from '@ethersproject/abstract-provider';
|
|
2
|
+
import { Signer } from 'ethers';
|
|
3
|
+
import { NetworkData } from './types';
|
|
4
|
+
export declare class KVStoreClient {
|
|
4
5
|
private contract;
|
|
5
6
|
private signerOrProvider;
|
|
6
7
|
/**
|
|
7
|
-
* **
|
|
8
|
+
* **KVStoreClient constructor**
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
11
|
+
* @param {NetworkData} network - The network information required to connect to the KVStore contract
|
|
10
12
|
*/
|
|
11
|
-
constructor(
|
|
13
|
+
constructor(signerOrProvider: Signer | Provider, network: NetworkData);
|
|
14
|
+
/**
|
|
15
|
+
* Creates an instance of KVStoreClient from a Signer or Provider.
|
|
16
|
+
*
|
|
17
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
18
|
+
* @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
|
|
19
|
+
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
20
|
+
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
21
|
+
*/
|
|
22
|
+
static build(signerOrProvider: Signer | Provider): Promise<KVStoreClient>;
|
|
12
23
|
/**
|
|
13
24
|
* Sets a key-value pair in the contract
|
|
14
25
|
*
|
|
@@ -32,9 +43,9 @@ export default class KVStoreClient {
|
|
|
32
43
|
*
|
|
33
44
|
* @param {string} address - The Ethereum address associated with the key-value pair
|
|
34
45
|
* @param {string} key - The key of the key-value pair to get
|
|
35
|
-
* @returns {string} - The value of the key-value pair if it exists
|
|
46
|
+
* @returns {Promise<string>} - The value of the key-value pair if it exists
|
|
36
47
|
* @throws {Error} - An error object if an error occurred
|
|
37
48
|
*/
|
|
38
|
-
get(address: string, key: string): Promise<string
|
|
49
|
+
get(address: string, key: string): Promise<string>;
|
|
39
50
|
}
|
|
40
51
|
//# sourceMappingURL=kvstore.d.ts.map
|
package/dist/kvstore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAM5D,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAYxC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,gBAAgB,CAAoB;IAE5C;;;;;OAKG;gBACS,gBAAgB,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,EAAE,WAAW;IAQrE;;;;;;;OAOG;WACiB,KAAK,CAAC,gBAAgB,EAAE,MAAM,GAAG,QAAQ;IAsB7D;;;;;;;OAOG;IAEU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3D;;;;;;;OAOG;IAEU,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAarE;;;;;;;OAOG;IACU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYhE"}
|
package/dist/kvstore.js
CHANGED
|
@@ -9,20 +9,48 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.KVStoreClient = void 0;
|
|
12
13
|
const typechain_types_1 = require("@human-protocol/core/typechain-types");
|
|
13
14
|
const ethers_1 = require("ethers");
|
|
14
|
-
const
|
|
15
|
+
const constants_1 = require("./constants");
|
|
15
16
|
const decorators_1 = require("./decorators");
|
|
17
|
+
const error_1 = require("./error");
|
|
16
18
|
class KVStoreClient {
|
|
17
19
|
/**
|
|
18
|
-
* **
|
|
20
|
+
* **KVStoreClient constructor**
|
|
19
21
|
*
|
|
20
|
-
*
|
|
22
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
23
|
+
* @param {NetworkData} network - The network information required to connect to the KVStore contract
|
|
21
24
|
*/
|
|
22
|
-
constructor(
|
|
23
|
-
this.
|
|
24
|
-
this.
|
|
25
|
-
|
|
25
|
+
constructor(signerOrProvider, network) {
|
|
26
|
+
this.contract = typechain_types_1.KVStore__factory.connect(network.factoryAddress, signerOrProvider);
|
|
27
|
+
this.signerOrProvider = signerOrProvider;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of KVStoreClient from a Signer or Provider.
|
|
31
|
+
*
|
|
32
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
33
|
+
* @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
|
|
34
|
+
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
35
|
+
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
36
|
+
*/
|
|
37
|
+
static async build(signerOrProvider) {
|
|
38
|
+
let network;
|
|
39
|
+
if (ethers_1.Signer.isSigner(signerOrProvider)) {
|
|
40
|
+
if (!signerOrProvider.provider) {
|
|
41
|
+
throw error_1.ErrorProviderDoesNotExist;
|
|
42
|
+
}
|
|
43
|
+
network = await signerOrProvider.provider.getNetwork();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
network = await signerOrProvider.getNetwork();
|
|
47
|
+
}
|
|
48
|
+
const chainId = network.chainId;
|
|
49
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
50
|
+
if (!networkData) {
|
|
51
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
52
|
+
}
|
|
53
|
+
return new KVStoreClient(signerOrProvider, networkData);
|
|
26
54
|
}
|
|
27
55
|
/**
|
|
28
56
|
* Sets a key-value pair in the contract
|
|
@@ -73,7 +101,7 @@ class KVStoreClient {
|
|
|
73
101
|
*
|
|
74
102
|
* @param {string} address - The Ethereum address associated with the key-value pair
|
|
75
103
|
* @param {string} key - The key of the key-value pair to get
|
|
76
|
-
* @returns {string} - The value of the key-value pair if it exists
|
|
104
|
+
* @returns {Promise<string>} - The value of the key-value pair if it exists
|
|
77
105
|
* @throws {Error} - An error object if an error occurred
|
|
78
106
|
*/
|
|
79
107
|
async get(address, key) {
|
|
@@ -88,6 +116,7 @@ class KVStoreClient {
|
|
|
88
116
|
catch (e) {
|
|
89
117
|
if (e instanceof Error)
|
|
90
118
|
throw Error(`Failed to get value: ${e.message}`);
|
|
119
|
+
return e;
|
|
91
120
|
}
|
|
92
121
|
}
|
|
93
122
|
}
|
|
@@ -103,4 +132,4 @@ __decorate([
|
|
|
103
132
|
__metadata("design:paramtypes", [Array, Array]),
|
|
104
133
|
__metadata("design:returntype", Promise)
|
|
105
134
|
], KVStoreClient.prototype, "setBulk", null);
|
|
106
|
-
exports.
|
|
135
|
+
exports.KVStoreClient = KVStoreClient;
|
package/dist/queries.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { EscrowStatus } from './types';
|
|
1
2
|
export declare const RAW_REWARDS_QUERY: (slasherAddress: string) => string;
|
|
2
|
-
export declare const RAW_LAUNCHED_ESCROWS_QUERY: () => string;
|
|
3
|
-
export declare const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY: () => string;
|
|
3
|
+
export declare const RAW_LAUNCHED_ESCROWS_QUERY: (requesterAddress: string) => string;
|
|
4
|
+
export declare const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY: (address?: string, status?: EscrowStatus, from?: Date, to?: Date) => string;
|
|
4
5
|
//# sourceMappingURL=queries.d.ts.map
|
package/dist/queries.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,mBAAoB,MAAM,WAKpD,CAAC;AAEL,eAAO,MAAM,0BAA0B,
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,eAAO,MAAM,iBAAiB,mBAAoB,MAAM,WAKpD,CAAC;AAEL,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,WAI/D,CAAC;AAEL,eAAO,MAAM,mCAAmC,aACpC,MAAM,WACP,YAAY,SACd,IAAI,OACN,IAAI,WAMG,CAAC"}
|
package/dist/queries.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = exports.RAW_LAUNCHED_ESCROWS_QUERY = exports.RAW_REWARDS_QUERY = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
4
5
|
const RAW_REWARDS_QUERY = (slasherAddress) => `{
|
|
5
6
|
rewardAddedEvents(id: "${slasherAddress}") {
|
|
6
7
|
escrow,
|
|
@@ -8,15 +9,11 @@ const RAW_REWARDS_QUERY = (slasherAddress) => `{
|
|
|
8
9
|
}
|
|
9
10
|
}`;
|
|
10
11
|
exports.RAW_REWARDS_QUERY = RAW_REWARDS_QUERY;
|
|
11
|
-
const RAW_LAUNCHED_ESCROWS_QUERY = () => `{
|
|
12
|
-
launchedEscrows(where: { from: $
|
|
12
|
+
const RAW_LAUNCHED_ESCROWS_QUERY = (requesterAddress) => `{
|
|
13
|
+
launchedEscrows(where: { from: ${requesterAddress} }) {
|
|
13
14
|
id
|
|
14
15
|
}
|
|
15
16
|
}`;
|
|
16
17
|
exports.RAW_LAUNCHED_ESCROWS_QUERY = RAW_LAUNCHED_ESCROWS_QUERY;
|
|
17
|
-
const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = () => `{
|
|
18
|
-
launchedEscrows(where: { from: $address, status: $status, timestamp_gte: $from, timestamp_lte: $to }) {
|
|
19
|
-
id
|
|
20
|
-
}
|
|
21
|
-
}`;
|
|
18
|
+
const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = (address, status, from, to) => `{ launchedEscrows(where: { ${address ? 'from: "' + address + '", ' : ''}${status ? 'status: "' + types_1.EscrowStatus[status] + '", ' : ''}${from ? 'timestamp_gte: "' + from?.valueOf() + '", ' : ''}${to ? 'timestamp_lte: "' + to?.valueOf() + '"' : ''}}) { id }}`;
|
|
22
19
|
exports.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = RAW_LAUNCHED_ESCROWS_FILTERED_QUERY;
|
package/dist/staking.d.ts
CHANGED
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import { Provider } from '@ethersproject/abstract-provider';
|
|
2
|
-
import { HMToken, Staking
|
|
2
|
+
import { EscrowFactory, HMToken, Staking } from '@human-protocol/core/typechain-types';
|
|
3
3
|
import { BigNumber, Signer } from 'ethers';
|
|
4
|
+
import { IAllocation, IReward, IStaker } from './interfaces';
|
|
4
5
|
import { NetworkData } from './types';
|
|
5
|
-
|
|
6
|
-
export default class StakingClient {
|
|
7
|
-
readonly clientParams: IClientParams;
|
|
6
|
+
export declare class StakingClient {
|
|
8
7
|
signerOrProvider: Signer | Provider;
|
|
9
8
|
network: NetworkData;
|
|
10
9
|
tokenContract: HMToken;
|
|
11
10
|
stakingContract: Staking;
|
|
12
11
|
escrowFactoryContract: EscrowFactory;
|
|
13
12
|
/**
|
|
14
|
-
* **
|
|
13
|
+
* **StakingClient constructor**
|
|
15
14
|
*
|
|
16
|
-
* @param {
|
|
15
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
16
|
+
* @param {NetworkData} network - The network information required to connect to the Staking contract
|
|
17
17
|
*/
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(signerOrProvider: Signer | Provider, network: NetworkData);
|
|
19
|
+
/**
|
|
20
|
+
* Creates an instance of StakingClient from a Signer or Provider.
|
|
21
|
+
*
|
|
22
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
23
|
+
* @returns {Promise<StakingClient>} - An instance of StakingClient
|
|
24
|
+
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
25
|
+
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
26
|
+
*/
|
|
27
|
+
static build(signerOrProvider: Signer | Provider): Promise<StakingClient>;
|
|
19
28
|
/**
|
|
20
29
|
* **Approves the staking contract to transfer a specified amount of tokens when the user stakes.
|
|
21
30
|
* **It increases the allowance for the staking contract.*
|
package/dist/staking.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAE5D,OAAO,EACL,aAAa,EAEb,OAAO,EAIP,OAAO,EAER,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAenD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC,qBAAa,aAAa;IACjB,gBAAgB,EAAE,MAAM,GAAG,QAAQ,CAAC;IACpC,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,qBAAqB,EAAE,aAAa,CAAC;IAE5C;;;;;OAKG;gBACS,gBAAgB,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,EAAE,WAAW;IAoBrE;;;;;;;OAOG;WACiB,KAAK,CAAC,gBAAgB,EAAE,MAAM,GAAG,QAAQ;IAsB7D;;;;;;;OAOG;IAEU,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB3D;;;;;;OAMG;IAEU,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBpD;;;;;;;OAOG;IAEU,OAAO,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBtD;;;;;OAKG;IAEU,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAStC;;;;;;;;;;OAUG;IAEU,KAAK,CAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,IAAI,CAAC;IAkChB;;;;;;;OAOG;IAEU,QAAQ,CACnB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,IAAI,CAAC;IAyBhB;;;;;;OAMG;IAEU,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBlE;;;;;;OAMG;IAEU,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBpE;;;;;;OAMG;IACU,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA6BxD;;;;;OAKG;IACU,aAAa,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IA+BhD;;;;;;OAMG;IACU,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAiBvE;;;;;;OAMG;IACU,UAAU,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;CAqBpE"}
|
package/dist/staking.js
CHANGED
|
@@ -9,25 +9,53 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StakingClient = void 0;
|
|
12
13
|
const typechain_types_1 = require("@human-protocol/core/typechain-types");
|
|
13
14
|
const ethers_1 = require("ethers");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
const decorators_1 = require("./decorators");
|
|
14
17
|
const error_1 = require("./error");
|
|
15
|
-
const utils_1 = require("./utils");
|
|
16
18
|
const queries_1 = require("./queries");
|
|
17
|
-
const
|
|
19
|
+
const utils_1 = require("./utils");
|
|
18
20
|
class StakingClient {
|
|
19
21
|
/**
|
|
20
|
-
* **
|
|
22
|
+
* **StakingClient constructor**
|
|
23
|
+
*
|
|
24
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
25
|
+
* @param {NetworkData} network - The network information required to connect to the Staking contract
|
|
26
|
+
*/
|
|
27
|
+
constructor(signerOrProvider, network) {
|
|
28
|
+
this.stakingContract = typechain_types_1.Staking__factory.connect(network.stakingAddress, signerOrProvider);
|
|
29
|
+
this.escrowFactoryContract = typechain_types_1.EscrowFactory__factory.connect(network.factoryAddress, signerOrProvider);
|
|
30
|
+
this.tokenContract = typechain_types_1.HMToken__factory.connect(network.hmtAddress, signerOrProvider);
|
|
31
|
+
this.signerOrProvider = signerOrProvider;
|
|
32
|
+
this.network = network;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates an instance of StakingClient from a Signer or Provider.
|
|
21
36
|
*
|
|
22
|
-
* @param {
|
|
37
|
+
* @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
|
|
38
|
+
* @returns {Promise<StakingClient>} - An instance of StakingClient
|
|
39
|
+
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
40
|
+
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
23
41
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
static async build(signerOrProvider) {
|
|
43
|
+
let network;
|
|
44
|
+
if (ethers_1.Signer.isSigner(signerOrProvider)) {
|
|
45
|
+
if (!signerOrProvider.provider) {
|
|
46
|
+
throw error_1.ErrorProviderDoesNotExist;
|
|
47
|
+
}
|
|
48
|
+
network = await signerOrProvider.provider.getNetwork();
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
network = await signerOrProvider.getNetwork();
|
|
52
|
+
}
|
|
53
|
+
const chainId = network.chainId;
|
|
54
|
+
const networkData = constants_1.NETWORKS[chainId];
|
|
55
|
+
if (!networkData) {
|
|
56
|
+
throw error_1.ErrorUnsupportedChainID;
|
|
57
|
+
}
|
|
58
|
+
return new StakingClient(signerOrProvider, networkData);
|
|
31
59
|
}
|
|
32
60
|
/**
|
|
33
61
|
* **Approves the staking contract to transfer a specified amount of tokens when the user stakes.
|
|
@@ -378,4 +406,4 @@ __decorate([
|
|
|
378
406
|
__metadata("design:paramtypes", [String]),
|
|
379
407
|
__metadata("design:returntype", Promise)
|
|
380
408
|
], StakingClient.prototype, "distributeRewards", null);
|
|
381
|
-
exports.
|
|
409
|
+
exports.StakingClient = StakingClient;
|
package/dist/storage.d.ts
CHANGED
package/dist/storage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE,
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAgB;IAEpC;;;;;OAKG;gBACS,WAAW,EAAE,kBAAkB,EAAE,MAAM,EAAE,aAAa;IAclE;;;;;OAKG;IACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAoB1E;;;;;OAKG;WACiB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAsBlE;;;;;;OAMG;IACU,WAAW,CACtB,KAAK,EAAE,GAAG,EAAE,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,EAAE,CAAC;IAkCxB;;;;;OAKG;IACU,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;OAKG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAqB5D"}
|