@human-protocol/sdk 5.0.0-beta.0 → 5.0.0-beta.2
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 +10 -1
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +21 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -4
- package/dist/escrow.d.ts +2 -2
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +13 -12
- package/dist/graphql/queries/escrow.d.ts.map +1 -1
- package/dist/graphql/queries/escrow.js +5 -0
- package/dist/graphql/types.d.ts +5 -0
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/interfaces.d.ts +5 -0
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +25 -0
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +42 -3
- package/dist/operator.d.ts +2 -2
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +1 -1
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +5 -5
- package/dist/transaction.d.ts +2 -2
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +7 -8
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/package.json +6 -5
- package/src/base.ts +23 -1
- package/src/constants.ts +6 -3
- package/src/escrow.ts +29 -13
- package/src/graphql/queries/escrow.ts +5 -0
- package/src/graphql/types.ts +5 -0
- package/src/index.ts +12 -0
- package/src/interfaces.ts +5 -0
- package/src/kvstore.ts +47 -3
- package/src/operator.ts +3 -3
- package/src/staking.ts +17 -5
- package/src/transaction.ts +2 -2
- package/src/utils.ts +8 -8
- package/src/worker.ts +1 -1
package/dist/staking.js
CHANGED
|
@@ -171,7 +171,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
171
171
|
throw error_1.ErrorInvalidStakingValueSign;
|
|
172
172
|
}
|
|
173
173
|
try {
|
|
174
|
-
await (await this.tokenContract.approve(await this.stakingContract.getAddress(), amount, txOptions)).wait();
|
|
174
|
+
await (await this.tokenContract.approve(await this.stakingContract.getAddress(), amount, this.applyTxDefaults(txOptions))).wait();
|
|
175
175
|
return;
|
|
176
176
|
}
|
|
177
177
|
catch (e) {
|
|
@@ -213,7 +213,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
213
213
|
throw error_1.ErrorInvalidStakingValueSign;
|
|
214
214
|
}
|
|
215
215
|
try {
|
|
216
|
-
await (await this.stakingContract.stake(amount, txOptions)).wait();
|
|
216
|
+
await (await this.stakingContract.stake(amount, this.applyTxDefaults(txOptions))).wait();
|
|
217
217
|
return;
|
|
218
218
|
}
|
|
219
219
|
catch (e) {
|
|
@@ -254,7 +254,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
254
254
|
throw error_1.ErrorInvalidStakingValueSign;
|
|
255
255
|
}
|
|
256
256
|
try {
|
|
257
|
-
await (await this.stakingContract.unstake(amount, txOptions)).wait();
|
|
257
|
+
await (await this.stakingContract.unstake(amount, this.applyTxDefaults(txOptions))).wait();
|
|
258
258
|
return;
|
|
259
259
|
}
|
|
260
260
|
catch (e) {
|
|
@@ -287,7 +287,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
287
287
|
*/
|
|
288
288
|
async withdraw(txOptions = {}) {
|
|
289
289
|
try {
|
|
290
|
-
await (await this.stakingContract.withdraw(txOptions)).wait();
|
|
290
|
+
await (await this.stakingContract.withdraw(this.applyTxDefaults(txOptions))).wait();
|
|
291
291
|
return;
|
|
292
292
|
}
|
|
293
293
|
catch (e) {
|
|
@@ -336,7 +336,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
336
336
|
}
|
|
337
337
|
await this.checkValidEscrow(escrowAddress);
|
|
338
338
|
try {
|
|
339
|
-
await (await this.stakingContract.slash(slasher, staker, escrowAddress, amount, txOptions)).wait();
|
|
339
|
+
await (await this.stakingContract.slash(slasher, staker, escrowAddress, amount, this.applyTxDefaults(txOptions))).wait();
|
|
340
340
|
return;
|
|
341
341
|
}
|
|
342
342
|
catch (e) {
|
package/dist/transaction.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export declare class TransactionUtils {
|
|
|
22
22
|
*
|
|
23
23
|
* @param {ChainId} chainId The chain ID.
|
|
24
24
|
* @param {string} hash The transaction hash.
|
|
25
|
-
* @returns {Promise<ITransaction>} Returns the transaction details.
|
|
25
|
+
* @returns {Promise<ITransaction | null>} - Returns the transaction details or null if not found.
|
|
26
26
|
*
|
|
27
27
|
* **Code example**
|
|
28
28
|
*
|
|
@@ -32,7 +32,7 @@ export declare class TransactionUtils {
|
|
|
32
32
|
* const transaction = await TransactionUtils.getTransaction(ChainId.POLYGON, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
|
-
static getTransaction(chainId: ChainId, hash: string): Promise<ITransaction>;
|
|
35
|
+
static getTransaction(chainId: ChainId, hash: string): Promise<ITransaction | null>;
|
|
36
36
|
/**
|
|
37
37
|
* This function returns all transaction details based on the provided filter.
|
|
38
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAUlD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGjE,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAUlD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAGjE,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAmB/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2DG;WACiB,eAAe,CACjC,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,YAAY,EAAE,CAAC;CA2C3B"}
|
package/dist/transaction.js
CHANGED
|
@@ -34,7 +34,7 @@ class TransactionUtils {
|
|
|
34
34
|
*
|
|
35
35
|
* @param {ChainId} chainId The chain ID.
|
|
36
36
|
* @param {string} hash The transaction hash.
|
|
37
|
-
* @returns {Promise<ITransaction>} Returns the transaction details.
|
|
37
|
+
* @returns {Promise<ITransaction | null>} - Returns the transaction details or null if not found.
|
|
38
38
|
*
|
|
39
39
|
* **Code example**
|
|
40
40
|
*
|
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":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,OAMxC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,OAO3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,WAAW,WAatD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAE7C,CAAC"}
|
package/dist/utils.js
CHANGED
|
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getUnixTimestamp = exports.getSubgraphUrl = exports.isValidJson = exports.isValidUrl = exports.throwError = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
|
+
const validator_1 = require("validator");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
6
8
|
const enums_1 = require("./enums");
|
|
7
9
|
const error_1 = require("./error");
|
|
8
|
-
const constants_1 = require("./constants");
|
|
9
10
|
/**
|
|
10
11
|
* **Handle and throw the error.*
|
|
11
12
|
*
|
|
@@ -43,13 +44,11 @@ exports.throwError = throwError;
|
|
|
43
44
|
* @returns
|
|
44
45
|
*/
|
|
45
46
|
const isValidUrl = (url) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
47
|
+
return (0, validator_1.isURL)(url, {
|
|
48
|
+
require_protocol: true,
|
|
49
|
+
protocols: ['http', 'https'],
|
|
50
|
+
require_tld: false,
|
|
51
|
+
});
|
|
53
52
|
};
|
|
54
53
|
exports.isValidUrl = isValidUrl;
|
|
55
54
|
/**
|
package/dist/worker.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare class WorkerUtils {
|
|
|
6
6
|
*
|
|
7
7
|
* @param {ChainId} chainId The chain ID.
|
|
8
8
|
* @param {string} address The worker address.
|
|
9
|
-
* @returns {Promise<IWorker>} Returns the worker details.
|
|
9
|
+
* @returns {Promise<IWorker | null>} - Returns the worker details or null if not found.
|
|
10
10
|
*
|
|
11
11
|
* **Code example**
|
|
12
12
|
*
|
package/dist/worker.js
CHANGED
|
@@ -17,7 +17,7 @@ class WorkerUtils {
|
|
|
17
17
|
*
|
|
18
18
|
* @param {ChainId} chainId The chain ID.
|
|
19
19
|
* @param {string} address The worker address.
|
|
20
|
-
* @returns {Promise<IWorker>} Returns the worker details.
|
|
20
|
+
* @returns {Promise<IWorker | null>} - Returns the worker details or null if not found.
|
|
21
21
|
*
|
|
22
22
|
* **Code example**
|
|
23
23
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@human-protocol/sdk",
|
|
3
3
|
"description": "Human Protocol SDK",
|
|
4
|
-
"version": "5.0.0-beta.
|
|
4
|
+
"version": "5.0.0-beta.2",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
7
7
|
"dist"
|
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"clean": "tsc --build --clean && rm -rf ./dist",
|
|
13
13
|
"clean:doc": "rm -rf ../../../../docs/sdk/typescript/",
|
|
14
|
-
"build": "tsc --build",
|
|
14
|
+
"build": "yarn clean && tsc --build",
|
|
15
15
|
"build:doc": "yarn clean:doc && typedoc --plugin typedoc-plugin-markdown --out ../../../../docs/sdk/typescript/",
|
|
16
|
-
"prepublish": "yarn build",
|
|
17
16
|
"test": "vitest -u",
|
|
18
17
|
"lint": "eslint .",
|
|
19
18
|
"lint:fix": "eslint . --fix",
|
|
20
|
-
"format": "prettier --write '**/*.{ts,json}'"
|
|
19
|
+
"format": "prettier --write '**/*.{ts,json}'",
|
|
20
|
+
"prepack": "[ \"${SKIP_PREPACK:-}\" = \"true\" ] && exit 0 || yarn build"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"url": "https://github.com/humanprotocol/human-protocol.git",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
]
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@human-protocol/core": "
|
|
41
|
+
"@human-protocol/core": "5.0.0-beta.2",
|
|
42
42
|
"axios": "^1.4.0",
|
|
43
43
|
"ethers": "~6.15.0",
|
|
44
44
|
"graphql": "^16.8.1",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"minio": "7.1.3",
|
|
48
48
|
"openpgp": "^5.11.2",
|
|
49
49
|
"secp256k1": "^5.0.1",
|
|
50
|
+
"validator": "^13.12.0",
|
|
50
51
|
"vitest": "^3.0.9"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
package/src/base.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ContractRunner } from 'ethers';
|
|
1
|
+
import { ContractRunner, Overrides } from 'ethers';
|
|
2
2
|
import { NetworkData } from './types';
|
|
3
|
+
import { ChainId } from './enums';
|
|
4
|
+
import { DEFAULT_AURORA_GAS_PRICE } from './constants';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* ## Introduction
|
|
@@ -21,4 +23,24 @@ export abstract class BaseEthersClient {
|
|
|
21
23
|
this.networkData = networkData;
|
|
22
24
|
this.runner = runner;
|
|
23
25
|
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Internal helper to enrich transaction overrides with network specific defaults.
|
|
29
|
+
*
|
|
30
|
+
* Aurora networks use a fixed gas price. We always override any user provided
|
|
31
|
+
* gasPrice with the canonical DEFAULT_AURORA_GAS_PRICE to avoid mismatches
|
|
32
|
+
* or tx failures due to an unexpected value. For other networks the user
|
|
33
|
+
* supplied fee parameters are left untouched.
|
|
34
|
+
*/
|
|
35
|
+
protected applyTxDefaults(txOptions: Overrides = {}): Overrides {
|
|
36
|
+
if (this.networkData.chainId === ChainId.AURORA_TESTNET) {
|
|
37
|
+
return {
|
|
38
|
+
...txOptions,
|
|
39
|
+
gasPrice: DEFAULT_AURORA_GAS_PRICE,
|
|
40
|
+
maxFeePerGas: undefined,
|
|
41
|
+
maxPriorityFeePerGas: undefined,
|
|
42
|
+
} as Overrides;
|
|
43
|
+
}
|
|
44
|
+
return txOptions;
|
|
45
|
+
}
|
|
24
46
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
1
2
|
import { ChainId } from './enums';
|
|
2
3
|
import { NetworkData } from './types';
|
|
3
4
|
|
|
@@ -11,6 +12,8 @@ export const DEFAULT_PORT = 9000;
|
|
|
11
12
|
|
|
12
13
|
export const DEFAULT_USE_SSL = false;
|
|
13
14
|
|
|
15
|
+
export const DEFAULT_AURORA_GAS_PRICE = ethers.parseUnits('0.07', 'gwei');
|
|
16
|
+
|
|
14
17
|
export enum HttpStatus {
|
|
15
18
|
OK = 200,
|
|
16
19
|
CREATED = 201,
|
|
@@ -51,7 +54,7 @@ export const NETWORKS: {
|
|
|
51
54
|
subgraphUrl:
|
|
52
55
|
'https://api.studio.thegraph.com/query/74256/sepolia/version/latest',
|
|
53
56
|
subgraphUrlApiKey:
|
|
54
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/
|
|
57
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmaDx3yapopC5xbXqqpkuZ5yLNPjs35wui9kyLS2oX55uE',
|
|
55
58
|
oldSubgraphUrl: '',
|
|
56
59
|
oldFactoryAddress: '',
|
|
57
60
|
},
|
|
@@ -81,7 +84,7 @@ export const NETWORKS: {
|
|
|
81
84
|
subgraphUrl:
|
|
82
85
|
'https://api.studio.thegraph.com/query/74256/bsc-testnet/version/latest',
|
|
83
86
|
subgraphUrlApiKey:
|
|
84
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/
|
|
87
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/Qmezp2vvVWXasTeyBmLHUaMA8WyX253r7RXcs1M4Zw2hN8',
|
|
85
88
|
oldSubgraphUrl:
|
|
86
89
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
|
|
87
90
|
oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
|
|
@@ -113,7 +116,7 @@ export const NETWORKS: {
|
|
|
113
116
|
subgraphUrl:
|
|
114
117
|
'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
|
|
115
118
|
subgraphUrlApiKey:
|
|
116
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/
|
|
119
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmZq6nAyJZgTqCEChm95xqntPpHJ7mnMBi9iDPDAQSyxZa',
|
|
117
120
|
oldSubgraphUrl: '',
|
|
118
121
|
oldFactoryAddress: '',
|
|
119
122
|
},
|
package/src/escrow.ts
CHANGED
|
@@ -245,7 +245,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
245
245
|
await this.escrowFactoryContract.createEscrow(
|
|
246
246
|
tokenAddress,
|
|
247
247
|
jobRequesterId,
|
|
248
|
-
txOptions
|
|
248
|
+
this.applyTxDefaults(txOptions)
|
|
249
249
|
)
|
|
250
250
|
).wait();
|
|
251
251
|
|
|
@@ -374,7 +374,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
374
374
|
exchangeOracleFee,
|
|
375
375
|
manifest,
|
|
376
376
|
manifestHash,
|
|
377
|
-
txOptions
|
|
377
|
+
this.applyTxDefaults(txOptions)
|
|
378
378
|
)
|
|
379
379
|
).wait();
|
|
380
380
|
|
|
@@ -438,7 +438,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
438
438
|
this.runner
|
|
439
439
|
);
|
|
440
440
|
await (
|
|
441
|
-
await tokenContract.transfer(
|
|
441
|
+
await tokenContract.transfer(
|
|
442
|
+
escrowAddress,
|
|
443
|
+
amount,
|
|
444
|
+
this.applyTxDefaults(txOptions)
|
|
445
|
+
)
|
|
442
446
|
).wait();
|
|
443
447
|
|
|
444
448
|
return;
|
|
@@ -559,7 +563,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
559
563
|
url,
|
|
560
564
|
hash,
|
|
561
565
|
fundsToReserve,
|
|
562
|
-
txOptions
|
|
566
|
+
this.applyTxDefaults(txOptions)
|
|
563
567
|
)
|
|
564
568
|
).wait();
|
|
565
569
|
} else {
|
|
@@ -567,7 +571,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
567
571
|
await escrowContract['storeResults(string,string)'](
|
|
568
572
|
url,
|
|
569
573
|
hash,
|
|
570
|
-
txOptions
|
|
574
|
+
this.applyTxDefaults(txOptions)
|
|
571
575
|
)
|
|
572
576
|
).wait();
|
|
573
577
|
}
|
|
@@ -623,7 +627,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
623
627
|
try {
|
|
624
628
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
625
629
|
|
|
626
|
-
await (
|
|
630
|
+
await (
|
|
631
|
+
await escrowContract.complete(this.applyTxDefaults(txOptions))
|
|
632
|
+
).wait();
|
|
627
633
|
return;
|
|
628
634
|
} catch (e) {
|
|
629
635
|
return throwError(e);
|
|
@@ -763,7 +769,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
763
769
|
finalResultsHash,
|
|
764
770
|
id,
|
|
765
771
|
forceComplete,
|
|
766
|
-
txOptions
|
|
772
|
+
this.applyTxDefaults(txOptions)
|
|
767
773
|
)
|
|
768
774
|
).wait();
|
|
769
775
|
} else {
|
|
@@ -777,7 +783,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
777
783
|
finalResultsHash,
|
|
778
784
|
id,
|
|
779
785
|
forceComplete,
|
|
780
|
-
txOptions
|
|
786
|
+
this.applyTxDefaults(txOptions)
|
|
781
787
|
)
|
|
782
788
|
).wait();
|
|
783
789
|
}
|
|
@@ -831,7 +837,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
831
837
|
|
|
832
838
|
try {
|
|
833
839
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
834
|
-
await (
|
|
840
|
+
await (
|
|
841
|
+
await escrowContract.cancel(this.applyTxDefaults(txOptions))
|
|
842
|
+
).wait();
|
|
835
843
|
} catch (e) {
|
|
836
844
|
return throwError(e);
|
|
837
845
|
}
|
|
@@ -877,7 +885,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
877
885
|
|
|
878
886
|
try {
|
|
879
887
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
880
|
-
await (
|
|
888
|
+
await (
|
|
889
|
+
await escrowContract.requestCancellation(
|
|
890
|
+
this.applyTxDefaults(txOptions)
|
|
891
|
+
)
|
|
892
|
+
).wait();
|
|
881
893
|
} catch (e) {
|
|
882
894
|
return throwError(e);
|
|
883
895
|
}
|
|
@@ -935,7 +947,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
935
947
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
936
948
|
|
|
937
949
|
const transactionReceipt = await (
|
|
938
|
-
await escrowContract.withdraw(
|
|
950
|
+
await escrowContract.withdraw(
|
|
951
|
+
tokenAddress,
|
|
952
|
+
this.applyTxDefaults(txOptions)
|
|
953
|
+
)
|
|
939
954
|
).wait();
|
|
940
955
|
|
|
941
956
|
let amountTransferred: bigint | undefined = undefined;
|
|
@@ -1027,6 +1042,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1027
1042
|
forceComplete = false,
|
|
1028
1043
|
txOptions: Overrides = {}
|
|
1029
1044
|
): Promise<TransactionLikeWithNonce> {
|
|
1045
|
+
txOptions = this.applyTxDefaults(txOptions);
|
|
1030
1046
|
await this.ensureCorrectBulkPayoutInput(
|
|
1031
1047
|
escrowAddress,
|
|
1032
1048
|
recipients,
|
|
@@ -1913,7 +1929,7 @@ export class EscrowUtils {
|
|
|
1913
1929
|
*
|
|
1914
1930
|
* @param {ChainId} chainId Network in which the escrow has been deployed
|
|
1915
1931
|
* @param {string} escrowAddress Address of the escrow
|
|
1916
|
-
* @returns {IEscrow} Escrow data
|
|
1932
|
+
* @returns {Promise<IEscrow | null>} - Escrow data or null if not found.
|
|
1917
1933
|
*
|
|
1918
1934
|
* **Code example**
|
|
1919
1935
|
*
|
|
@@ -1926,7 +1942,7 @@ export class EscrowUtils {
|
|
|
1926
1942
|
public static async getEscrow(
|
|
1927
1943
|
chainId: ChainId,
|
|
1928
1944
|
escrowAddress: string
|
|
1929
|
-
): Promise<IEscrow> {
|
|
1945
|
+
): Promise<IEscrow | null> {
|
|
1930
1946
|
const networkData = NETWORKS[chainId];
|
|
1931
1947
|
|
|
1932
1948
|
if (!networkData) {
|
|
@@ -9,8 +9,10 @@ const ESCROW_FRAGMENT = gql`
|
|
|
9
9
|
count
|
|
10
10
|
factoryAddress
|
|
11
11
|
finalResultsUrl
|
|
12
|
+
finalResultsHash
|
|
12
13
|
id
|
|
13
14
|
intermediateResultsUrl
|
|
15
|
+
intermediateResultsHash
|
|
14
16
|
jobRequesterId
|
|
15
17
|
launcher
|
|
16
18
|
manifestHash
|
|
@@ -18,6 +20,9 @@ const ESCROW_FRAGMENT = gql`
|
|
|
18
20
|
recordingOracle
|
|
19
21
|
reputationOracle
|
|
20
22
|
exchangeOracle
|
|
23
|
+
recordingOracleFee
|
|
24
|
+
reputationOracleFee
|
|
25
|
+
exchangeOracleFee
|
|
21
26
|
status
|
|
22
27
|
token
|
|
23
28
|
totalFundedAmount
|
package/src/graphql/types.ts
CHANGED
|
@@ -8,13 +8,18 @@ export type EscrowData = {
|
|
|
8
8
|
count: string;
|
|
9
9
|
factoryAddress: string;
|
|
10
10
|
finalResultsUrl?: string;
|
|
11
|
+
finalResultsHash?: string;
|
|
11
12
|
intermediateResultsUrl?: string;
|
|
13
|
+
intermediateResultsHash?: string;
|
|
12
14
|
launcher: string;
|
|
13
15
|
manifestHash?: string;
|
|
14
16
|
manifestUrl?: string;
|
|
15
17
|
recordingOracle?: string;
|
|
16
18
|
reputationOracle?: string;
|
|
17
19
|
exchangeOracle?: string;
|
|
20
|
+
recordingOracleFee?: string;
|
|
21
|
+
reputationOracleFee?: string;
|
|
22
|
+
exchangeOracleFee?: string;
|
|
18
23
|
status: string;
|
|
19
24
|
token: string;
|
|
20
25
|
totalFundedAmount: string;
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,18 @@ export * from './types';
|
|
|
13
13
|
export * from './enums';
|
|
14
14
|
export * from './interfaces';
|
|
15
15
|
|
|
16
|
+
export {
|
|
17
|
+
EthereumError,
|
|
18
|
+
InvalidArgumentError,
|
|
19
|
+
ReplacementUnderpriced,
|
|
20
|
+
NumericFault,
|
|
21
|
+
NonceExpired,
|
|
22
|
+
TransactionReplaced,
|
|
23
|
+
ContractExecutionError,
|
|
24
|
+
InvalidEthereumAddressError,
|
|
25
|
+
InvalidKeyError,
|
|
26
|
+
} from './error';
|
|
27
|
+
|
|
16
28
|
export {
|
|
17
29
|
StakingClient,
|
|
18
30
|
StorageClient,
|
package/src/interfaces.ts
CHANGED
|
@@ -82,13 +82,18 @@ export interface IEscrow {
|
|
|
82
82
|
count: string;
|
|
83
83
|
factoryAddress: string;
|
|
84
84
|
finalResultsUrl?: string;
|
|
85
|
+
finalResultsHash?: string;
|
|
85
86
|
intermediateResultsUrl?: string;
|
|
87
|
+
intermediateResultsHash?: string;
|
|
86
88
|
launcher: string;
|
|
87
89
|
manifestHash?: string;
|
|
88
90
|
manifest?: string;
|
|
89
91
|
recordingOracle?: string;
|
|
90
92
|
reputationOracle?: string;
|
|
91
93
|
exchangeOracle?: string;
|
|
94
|
+
recordingOracleFee?: string;
|
|
95
|
+
reputationOracleFee?: string;
|
|
96
|
+
exchangeOracleFee?: string;
|
|
92
97
|
status: string;
|
|
93
98
|
token: string;
|
|
94
99
|
totalFundedAmount: string;
|
package/src/kvstore.ts
CHANGED
|
@@ -175,7 +175,9 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
175
175
|
): Promise<void> {
|
|
176
176
|
if (key === '') throw ErrorKVStoreEmptyKey;
|
|
177
177
|
try {
|
|
178
|
-
await (
|
|
178
|
+
await (
|
|
179
|
+
await this.contract.set(key, value, this.applyTxDefaults(txOptions))
|
|
180
|
+
).wait();
|
|
179
181
|
} catch (e) {
|
|
180
182
|
if (e instanceof Error) throw Error(`Failed to set value: ${e.message}`);
|
|
181
183
|
}
|
|
@@ -220,7 +222,13 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
220
222
|
if (keys.includes('')) throw ErrorKVStoreEmptyKey;
|
|
221
223
|
|
|
222
224
|
try {
|
|
223
|
-
await (
|
|
225
|
+
await (
|
|
226
|
+
await this.contract.setBulk(
|
|
227
|
+
keys,
|
|
228
|
+
values,
|
|
229
|
+
this.applyTxDefaults(txOptions)
|
|
230
|
+
)
|
|
231
|
+
).wait();
|
|
224
232
|
} catch (e) {
|
|
225
233
|
if (e instanceof Error)
|
|
226
234
|
throw Error(`Failed to set bulk values: ${e.message}`);
|
|
@@ -273,7 +281,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
273
281
|
await this.contract.setBulk(
|
|
274
282
|
[urlKey, hashKey],
|
|
275
283
|
[url, contentHash],
|
|
276
|
-
txOptions
|
|
284
|
+
this.applyTxDefaults(txOptions)
|
|
277
285
|
)
|
|
278
286
|
).wait();
|
|
279
287
|
} catch (e) {
|
|
@@ -281,6 +289,42 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
281
289
|
throw Error(`Failed to set URL and hash: ${e.message}`);
|
|
282
290
|
}
|
|
283
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* Gets the value of a key-value pair in the contract.
|
|
294
|
+
*
|
|
295
|
+
* @param {string} address Address from which to get the key value.
|
|
296
|
+
* @param {string} key Key to obtain the value.
|
|
297
|
+
* @returns {string} Value of the key.
|
|
298
|
+
*
|
|
299
|
+
*
|
|
300
|
+
* **Code example**
|
|
301
|
+
*
|
|
302
|
+
* > Need to have available stake.
|
|
303
|
+
*
|
|
304
|
+
* ```ts
|
|
305
|
+
* import { providers } from 'ethers';
|
|
306
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
307
|
+
*
|
|
308
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
309
|
+
*
|
|
310
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
311
|
+
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
312
|
+
*
|
|
313
|
+
* const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
public async get(address: string, key: string): Promise<string> {
|
|
317
|
+
if (key === '') throw ErrorKVStoreEmptyKey;
|
|
318
|
+
if (!ethers.isAddress(address)) throw ErrorInvalidAddress;
|
|
319
|
+
|
|
320
|
+
try {
|
|
321
|
+
const result = await this.contract?.get(address, key);
|
|
322
|
+
return result;
|
|
323
|
+
} catch (e) {
|
|
324
|
+
if (e instanceof Error) throw Error(`Failed to get value: ${e.message}`);
|
|
325
|
+
return e;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
284
328
|
}
|
|
285
329
|
|
|
286
330
|
/**
|
package/src/operator.ts
CHANGED
|
@@ -30,7 +30,7 @@ export class OperatorUtils {
|
|
|
30
30
|
*
|
|
31
31
|
* @param {ChainId} chainId Network in which the operator is deployed
|
|
32
32
|
* @param {string} address Operator address.
|
|
33
|
-
* @returns {Promise<IOperator>} Returns the operator details.
|
|
33
|
+
* @returns {Promise<IOperator | null>} - Returns the operator details or null if not found.
|
|
34
34
|
*
|
|
35
35
|
* **Code example**
|
|
36
36
|
*
|
|
@@ -43,7 +43,7 @@ export class OperatorUtils {
|
|
|
43
43
|
public static async getOperator(
|
|
44
44
|
chainId: ChainId,
|
|
45
45
|
address: string
|
|
46
|
-
): Promise<IOperator> {
|
|
46
|
+
): Promise<IOperator | null> {
|
|
47
47
|
if (!ethers.isAddress(address)) {
|
|
48
48
|
throw ErrorInvalidStakerAddressProvided;
|
|
49
49
|
}
|
|
@@ -60,7 +60,7 @@ export class OperatorUtils {
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
if (!operator) {
|
|
63
|
-
return null
|
|
63
|
+
return null;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
return mapOperator(operator, chainId);
|
package/src/staking.ts
CHANGED
|
@@ -213,7 +213,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
213
213
|
await this.tokenContract.approve(
|
|
214
214
|
await this.stakingContract.getAddress(),
|
|
215
215
|
amount,
|
|
216
|
-
txOptions
|
|
216
|
+
this.applyTxDefaults(txOptions)
|
|
217
217
|
)
|
|
218
218
|
).wait();
|
|
219
219
|
return;
|
|
@@ -260,7 +260,12 @@ export class StakingClient extends BaseEthersClient {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
try {
|
|
263
|
-
await (
|
|
263
|
+
await (
|
|
264
|
+
await this.stakingContract.stake(
|
|
265
|
+
amount,
|
|
266
|
+
this.applyTxDefaults(txOptions)
|
|
267
|
+
)
|
|
268
|
+
).wait();
|
|
264
269
|
return;
|
|
265
270
|
} catch (e) {
|
|
266
271
|
return throwError(e);
|
|
@@ -307,7 +312,12 @@ export class StakingClient extends BaseEthersClient {
|
|
|
307
312
|
}
|
|
308
313
|
|
|
309
314
|
try {
|
|
310
|
-
await (
|
|
315
|
+
await (
|
|
316
|
+
await this.stakingContract.unstake(
|
|
317
|
+
amount,
|
|
318
|
+
this.applyTxDefaults(txOptions)
|
|
319
|
+
)
|
|
320
|
+
).wait();
|
|
311
321
|
return;
|
|
312
322
|
} catch (e) {
|
|
313
323
|
return throwError(e);
|
|
@@ -341,7 +351,9 @@ export class StakingClient extends BaseEthersClient {
|
|
|
341
351
|
@requiresSigner
|
|
342
352
|
public async withdraw(txOptions: Overrides = {}): Promise<void> {
|
|
343
353
|
try {
|
|
344
|
-
await (
|
|
354
|
+
await (
|
|
355
|
+
await this.stakingContract.withdraw(this.applyTxDefaults(txOptions))
|
|
356
|
+
).wait();
|
|
345
357
|
return;
|
|
346
358
|
} catch (e) {
|
|
347
359
|
return throwError(e);
|
|
@@ -408,7 +420,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
408
420
|
staker,
|
|
409
421
|
escrowAddress,
|
|
410
422
|
amount,
|
|
411
|
-
txOptions
|
|
423
|
+
this.applyTxDefaults(txOptions)
|
|
412
424
|
)
|
|
413
425
|
).wait();
|
|
414
426
|
|
package/src/transaction.ts
CHANGED
|
@@ -37,7 +37,7 @@ export class TransactionUtils {
|
|
|
37
37
|
*
|
|
38
38
|
* @param {ChainId} chainId The chain ID.
|
|
39
39
|
* @param {string} hash The transaction hash.
|
|
40
|
-
* @returns {Promise<ITransaction>} Returns the transaction details.
|
|
40
|
+
* @returns {Promise<ITransaction | null>} - Returns the transaction details or null if not found.
|
|
41
41
|
*
|
|
42
42
|
* **Code example**
|
|
43
43
|
*
|
|
@@ -50,7 +50,7 @@ export class TransactionUtils {
|
|
|
50
50
|
public static async getTransaction(
|
|
51
51
|
chainId: ChainId,
|
|
52
52
|
hash: string
|
|
53
|
-
): Promise<ITransaction> {
|
|
53
|
+
): Promise<ITransaction | null> {
|
|
54
54
|
if (!ethers.isHexString(hash)) {
|
|
55
55
|
throw ErrorInvalidHashProvided;
|
|
56
56
|
}
|