@human-protocol/sdk 4.1.5 → 4.3.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 +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 +10 -8
- 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 +6 -6
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +23 -24
- package/dist/graphql/queries/escrow.js +1 -1
- package/dist/interfaces.d.ts +2 -2
- 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/staking.d.ts.map +1 -1
- package/dist/staking.js +6 -5
- package/dist/utils.d.ts +7 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +17 -1
- package/package.json +6 -6
- package/src/base.ts +23 -1
- package/src/constants.ts +10 -7
- package/src/error.ts +2 -2
- package/src/escrow.ts +44 -27
- package/src/graphql/queries/escrow.ts +1 -1
- package/src/interfaces.ts +2 -2
- package/src/kvstore.ts +47 -3
- package/src/staking.ts +18 -5
- package/src/utils.ts +15 -0
package/dist/staking.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,OAAO,EAEP,OAAO,EAER,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAc1C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,aAAc,SAAQ,gBAAgB;IAC1C,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,qBAAqB,EAAE,aAAa,CAAC;IAE5C;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;IAmB5D;;;;;;;;OAQG;WACiB,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBzE;;;;OAIG;YACW,gBAAgB;IAU9B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAEU,YAAY,CACvB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAuBhB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IAEU,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,OAAO,EAEP,OAAO,EAER,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAc1C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,aAAc,SAAQ,gBAAgB;IAC1C,aAAa,EAAE,OAAO,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,qBAAqB,EAAE,aAAa,CAAC;IAE5C;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;IAmB5D;;;;;;;;OAQG;WACiB,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBzE;;;;OAIG;YACW,gBAAgB;IAU9B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAEU,YAAY,CACvB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAuBhB;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IAEU,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAsB5E;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IAEU,OAAO,CAClB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAsBhB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IAEU,QAAQ,CAAC,SAAS,GAAE,SAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAW/D;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IAEU,KAAK,CAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC,IAAI,CAAC;IAoChB;;;;;;;;;;;;;;;;;;;OAmBG;IACU,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAiCvE"}
|
package/dist/staking.js
CHANGED
|
@@ -165,7 +165,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
165
165
|
throw error_1.ErrorInvalidStakingValueSign;
|
|
166
166
|
}
|
|
167
167
|
try {
|
|
168
|
-
await (await this.tokenContract.approve(await this.stakingContract.getAddress(), amount, txOptions)).wait();
|
|
168
|
+
await (await this.tokenContract.approve(await this.stakingContract.getAddress(), amount, this.applyTxDefaults(txOptions))).wait();
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
171
|
catch (e) {
|
|
@@ -207,7 +207,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
207
207
|
throw error_1.ErrorInvalidStakingValueSign;
|
|
208
208
|
}
|
|
209
209
|
try {
|
|
210
|
-
await (await this.stakingContract.stake(amount, txOptions)).wait();
|
|
210
|
+
await (await this.stakingContract.stake(amount, this.applyTxDefaults(txOptions))).wait();
|
|
211
211
|
return;
|
|
212
212
|
}
|
|
213
213
|
catch (e) {
|
|
@@ -248,7 +248,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
248
248
|
throw error_1.ErrorInvalidStakingValueSign;
|
|
249
249
|
}
|
|
250
250
|
try {
|
|
251
|
-
await (await this.stakingContract.unstake(amount, txOptions)).wait();
|
|
251
|
+
await (await this.stakingContract.unstake(amount, this.applyTxDefaults(txOptions))).wait();
|
|
252
252
|
return;
|
|
253
253
|
}
|
|
254
254
|
catch (e) {
|
|
@@ -281,7 +281,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
281
281
|
*/
|
|
282
282
|
async withdraw(txOptions = {}) {
|
|
283
283
|
try {
|
|
284
|
-
await (await this.stakingContract.withdraw(txOptions)).wait();
|
|
284
|
+
await (await this.stakingContract.withdraw(this.applyTxDefaults(txOptions))).wait();
|
|
285
285
|
return;
|
|
286
286
|
}
|
|
287
287
|
catch (e) {
|
|
@@ -330,7 +330,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
330
330
|
}
|
|
331
331
|
await this.checkValidEscrow(escrowAddress);
|
|
332
332
|
try {
|
|
333
|
-
await (await this.stakingContract.slash(slasher, staker, escrowAddress, amount, txOptions)).wait();
|
|
333
|
+
await (await this.stakingContract.slash(slasher, staker, escrowAddress, amount, this.applyTxDefaults(txOptions))).wait();
|
|
334
334
|
return;
|
|
335
335
|
}
|
|
336
336
|
catch (e) {
|
|
@@ -363,6 +363,7 @@ class StakingClient extends base_1.BaseEthersClient {
|
|
|
363
363
|
}
|
|
364
364
|
try {
|
|
365
365
|
const stakerInfo = await this.stakingContract.stakes(stakerAddress);
|
|
366
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
366
367
|
const currentBlock = await this.runner.provider.getBlockNumber();
|
|
367
368
|
const tokensWithdrawable = stakerInfo.tokensLockedUntil !== 0n &&
|
|
368
369
|
currentBlock >= stakerInfo.tokensLockedUntil
|
package/dist/utils.d.ts
CHANGED
|
@@ -13,6 +13,13 @@ export declare const throwError: (e: any) => never;
|
|
|
13
13
|
* @returns
|
|
14
14
|
*/
|
|
15
15
|
export declare const isValidUrl: (url: string) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* **Check if a string is a valid JSON.*
|
|
18
|
+
*
|
|
19
|
+
* @param {string} input
|
|
20
|
+
* @returns {boolean}
|
|
21
|
+
*/
|
|
22
|
+
export declare const isValidJson: (input: string) => boolean;
|
|
16
23
|
/**
|
|
17
24
|
* **Get the subgraph URL.*
|
|
18
25
|
*
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,YAOrC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,aAAa,WAAW,WAatD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,IAAI,KAAG,MAE7C,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,GAAG,UAgBhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,YAOrC,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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUnixTimestamp = exports.getSubgraphUrl = exports.isValidUrl = exports.throwError = void 0;
|
|
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
6
|
const enums_1 = require("./enums");
|
|
@@ -52,6 +52,22 @@ const isValidUrl = (url) => {
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
exports.isValidUrl = isValidUrl;
|
|
55
|
+
/**
|
|
56
|
+
* **Check if a string is a valid JSON.*
|
|
57
|
+
*
|
|
58
|
+
* @param {string} input
|
|
59
|
+
* @returns {boolean}
|
|
60
|
+
*/
|
|
61
|
+
const isValidJson = (input) => {
|
|
62
|
+
try {
|
|
63
|
+
JSON.parse(input);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
exports.isValidJson = isValidJson;
|
|
55
71
|
/**
|
|
56
72
|
* **Get the subgraph URL.*
|
|
57
73
|
*
|
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.
|
|
4
|
+
"version": "4.3.0",
|
|
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,9 +38,9 @@
|
|
|
38
38
|
]
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@human-protocol/core": "
|
|
41
|
+
"@human-protocol/core": "4.2.1",
|
|
42
42
|
"axios": "^1.4.0",
|
|
43
|
-
"ethers": "~6.
|
|
43
|
+
"ethers": "~6.15.0",
|
|
44
44
|
"graphql": "^16.8.1",
|
|
45
45
|
"graphql-request": "^6.1.0",
|
|
46
46
|
"graphql-tag": "^2.12.6",
|
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,
|
|
@@ -36,7 +39,7 @@ export const NETWORKS: {
|
|
|
36
39
|
subgraphUrl:
|
|
37
40
|
'https://api.studio.thegraph.com/query/74256/ethereum/version/latest',
|
|
38
41
|
subgraphUrlApiKey:
|
|
39
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/
|
|
42
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmQwp4Rr2J4UbPFykb9eXg2t7GPcGRS6WT7QzExZtv32jK',
|
|
40
43
|
oldSubgraphUrl: '',
|
|
41
44
|
oldFactoryAddress: '',
|
|
42
45
|
},
|
|
@@ -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/QmURrhnEXimGnRzjeN3B4VMmioUeBHUBg4WJ7KZzJ7em8g',
|
|
55
58
|
oldSubgraphUrl: '',
|
|
56
59
|
oldFactoryAddress: '',
|
|
57
60
|
},
|
|
@@ -66,7 +69,7 @@ export const NETWORKS: {
|
|
|
66
69
|
subgraphUrl:
|
|
67
70
|
'https://api.studio.thegraph.com/query/74256/bsc/version/latest',
|
|
68
71
|
subgraphUrlApiKey:
|
|
69
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/
|
|
72
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmT2VoBLjAfc4pQzDmeCGra6weoLuk2jPRgnRz5iSMUw1t',
|
|
70
73
|
oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
|
|
71
74
|
oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
|
|
72
75
|
},
|
|
@@ -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/QmZHqbiyAAwrmqsVJLhTEdejVGYJpXfJAkJXUw7C2VV1TD',
|
|
85
88
|
oldSubgraphUrl:
|
|
86
89
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest',
|
|
87
90
|
oldFactoryAddress: '0xaae6a2646c1f88763e62e0cd08ad050ea66ac46f',
|
|
@@ -97,7 +100,7 @@ export const NETWORKS: {
|
|
|
97
100
|
subgraphUrl:
|
|
98
101
|
'https://api.studio.thegraph.com/query/74256/polygon/version/latest',
|
|
99
102
|
subgraphUrlApiKey:
|
|
100
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/
|
|
103
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmT72ecfx6Zaje21kLNi17kDJTpPKFYvzQETDyLpQgDrPu',
|
|
101
104
|
oldSubgraphUrl:
|
|
102
105
|
'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon',
|
|
103
106
|
oldFactoryAddress: '0x45eBc3eAE6DA485097054ae10BA1A0f8e8c7f794',
|
|
@@ -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/QmeeE9bVkat1mkbQg1R6SXLuLadXxoNCY5b7CEQkmu6cQi',
|
|
117
120
|
oldSubgraphUrl: '',
|
|
118
121
|
oldFactoryAddress: '',
|
|
119
122
|
},
|
|
@@ -128,7 +131,7 @@ export const NETWORKS: {
|
|
|
128
131
|
subgraphUrl:
|
|
129
132
|
'https://api.studio.thegraph.com/query/74256/amoy/version/latest',
|
|
130
133
|
subgraphUrlApiKey:
|
|
131
|
-
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/
|
|
134
|
+
'https://gateway-arbitrum.network.thegraph.com/api/[SUBGRAPH_API_KEY]/deployments/id/QmQiLaFKusXLzKrpZvQDg7vETLhdfPgzWJN3Uxp3bE9K9W',
|
|
132
135
|
oldSubgraphUrl: '',
|
|
133
136
|
oldFactoryAddress: '',
|
|
134
137
|
},
|
package/src/error.ts
CHANGED
|
@@ -202,9 +202,9 @@ export const ErrorManifestFileDoesNotExist = new Error(
|
|
|
202
202
|
export const ErrorInvalidUrl = new Error('Invalid URL string');
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
|
-
* @constant {Error} -
|
|
205
|
+
* @constant {Error} - Invalid manifest.
|
|
206
206
|
*/
|
|
207
|
-
export const
|
|
207
|
+
export const ErrorInvalidManifest = new Error('Invalid manifest');
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
210
|
* @constant {Error} - List of handlers cannot be empty.
|
package/src/escrow.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
ErrorInvalidAddress,
|
|
25
25
|
ErrorInvalidEscrowAddressProvided,
|
|
26
26
|
ErrorInvalidExchangeOracleAddressProvided,
|
|
27
|
+
ErrorInvalidManifest,
|
|
27
28
|
ErrorInvalidRecordingOracleAddressProvided,
|
|
28
29
|
ErrorInvalidReputationOracleAddressProvided,
|
|
29
30
|
ErrorInvalidTokenAddress,
|
|
@@ -37,7 +38,6 @@ import {
|
|
|
37
38
|
ErrorTotalFeeMustBeLessThanHundred,
|
|
38
39
|
ErrorTransferEventNotFoundInTransactionLogs,
|
|
39
40
|
ErrorUnsupportedChainID,
|
|
40
|
-
ErrorUrlIsEmptyString,
|
|
41
41
|
InvalidEthereumAddressError,
|
|
42
42
|
} from './error';
|
|
43
43
|
import {
|
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
import {
|
|
67
67
|
getSubgraphUrl,
|
|
68
68
|
getUnixTimestamp,
|
|
69
|
+
isValidJson,
|
|
69
70
|
isValidUrl,
|
|
70
71
|
throwError,
|
|
71
72
|
} from './utils';
|
|
@@ -250,7 +251,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
250
251
|
tokenAddress,
|
|
251
252
|
trustedHandlers,
|
|
252
253
|
jobRequesterId,
|
|
253
|
-
txOptions
|
|
254
|
+
this.applyTxDefaults(txOptions)
|
|
254
255
|
)
|
|
255
256
|
).wait();
|
|
256
257
|
|
|
@@ -302,7 +303,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
302
303
|
* recordingOracleFee: BigInt('10'),
|
|
303
304
|
* reputationOracleFee: BigInt('10'),
|
|
304
305
|
* exchangeOracleFee: BigInt('10'),
|
|
305
|
-
*
|
|
306
|
+
* manifest: 'http://localhost/manifest.json',
|
|
306
307
|
* manifestHash: 'b5dad76bf6772c0f07fd5e048f6e75a5f86ee079',
|
|
307
308
|
* };
|
|
308
309
|
* await escrowClient.setup(escrowAddress, escrowConfig);
|
|
@@ -321,7 +322,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
321
322
|
recordingOracleFee,
|
|
322
323
|
reputationOracleFee,
|
|
323
324
|
exchangeOracleFee,
|
|
324
|
-
|
|
325
|
+
manifest,
|
|
325
326
|
manifestHash,
|
|
326
327
|
} = escrowConfig;
|
|
327
328
|
|
|
@@ -353,12 +354,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
353
354
|
throw ErrorTotalFeeMustBeLessThanHundred;
|
|
354
355
|
}
|
|
355
356
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (!isValidUrl(manifestUrl)) {
|
|
361
|
-
throw ErrorInvalidUrl;
|
|
357
|
+
const isManifestValid = isValidUrl(manifest) || isValidJson(manifest);
|
|
358
|
+
if (!isManifestValid) {
|
|
359
|
+
throw ErrorInvalidManifest;
|
|
362
360
|
}
|
|
363
361
|
|
|
364
362
|
if (!manifestHash) {
|
|
@@ -380,9 +378,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
380
378
|
reputationOracleFee,
|
|
381
379
|
recordingOracleFee,
|
|
382
380
|
exchangeOracleFee,
|
|
383
|
-
|
|
381
|
+
manifest,
|
|
384
382
|
manifestHash,
|
|
385
|
-
txOptions
|
|
383
|
+
this.applyTxDefaults(txOptions)
|
|
386
384
|
)
|
|
387
385
|
).wait();
|
|
388
386
|
|
|
@@ -446,7 +444,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
446
444
|
this.runner
|
|
447
445
|
);
|
|
448
446
|
await (
|
|
449
|
-
await tokenContract.transfer(
|
|
447
|
+
await tokenContract.transfer(
|
|
448
|
+
escrowAddress,
|
|
449
|
+
amount,
|
|
450
|
+
this.applyTxDefaults(txOptions)
|
|
451
|
+
)
|
|
450
452
|
).wait();
|
|
451
453
|
|
|
452
454
|
return;
|
|
@@ -495,7 +497,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
495
497
|
}
|
|
496
498
|
|
|
497
499
|
if (!url) {
|
|
498
|
-
throw
|
|
500
|
+
throw ErrorInvalidUrl;
|
|
499
501
|
}
|
|
500
502
|
|
|
501
503
|
if (!isValidUrl(url)) {
|
|
@@ -513,7 +515,13 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
513
515
|
try {
|
|
514
516
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
515
517
|
|
|
516
|
-
await (
|
|
518
|
+
await (
|
|
519
|
+
await escrowContract.storeResults(
|
|
520
|
+
url,
|
|
521
|
+
hash,
|
|
522
|
+
this.applyTxDefaults(txOptions)
|
|
523
|
+
)
|
|
524
|
+
).wait();
|
|
517
525
|
|
|
518
526
|
return;
|
|
519
527
|
} catch (e) {
|
|
@@ -563,7 +571,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
563
571
|
try {
|
|
564
572
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
565
573
|
|
|
566
|
-
await (
|
|
574
|
+
await (
|
|
575
|
+
await escrowContract.complete(this.applyTxDefaults(txOptions))
|
|
576
|
+
).wait();
|
|
567
577
|
return;
|
|
568
578
|
} catch (e) {
|
|
569
579
|
return throwError(e);
|
|
@@ -640,7 +650,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
640
650
|
finalResultsHash,
|
|
641
651
|
txId,
|
|
642
652
|
forceComplete,
|
|
643
|
-
txOptions
|
|
653
|
+
this.applyTxDefaults(txOptions)
|
|
644
654
|
)
|
|
645
655
|
).wait();
|
|
646
656
|
} else {
|
|
@@ -653,7 +663,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
653
663
|
finalResultsUrl,
|
|
654
664
|
finalResultsHash,
|
|
655
665
|
txId,
|
|
656
|
-
txOptions
|
|
666
|
+
this.applyTxDefaults(txOptions)
|
|
657
667
|
)
|
|
658
668
|
).wait();
|
|
659
669
|
}
|
|
@@ -706,7 +716,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
706
716
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
707
717
|
|
|
708
718
|
const transactionReceipt = await (
|
|
709
|
-
await escrowContract.cancel(txOptions)
|
|
719
|
+
await escrowContract.cancel(this.applyTxDefaults(txOptions))
|
|
710
720
|
).wait();
|
|
711
721
|
|
|
712
722
|
let amountTransferred: bigint | undefined = undefined;
|
|
@@ -803,7 +813,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
803
813
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
804
814
|
|
|
805
815
|
await (
|
|
806
|
-
await escrowContract.addTrustedHandlers(
|
|
816
|
+
await escrowContract.addTrustedHandlers(
|
|
817
|
+
trustedHandlers,
|
|
818
|
+
this.applyTxDefaults(txOptions)
|
|
819
|
+
)
|
|
807
820
|
).wait();
|
|
808
821
|
return;
|
|
809
822
|
} catch (e) {
|
|
@@ -863,7 +876,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
863
876
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
864
877
|
|
|
865
878
|
const transactionReceipt = await (
|
|
866
|
-
await escrowContract.withdraw(
|
|
879
|
+
await escrowContract.withdraw(
|
|
880
|
+
tokenAddress,
|
|
881
|
+
this.applyTxDefaults(txOptions)
|
|
882
|
+
)
|
|
867
883
|
).wait();
|
|
868
884
|
|
|
869
885
|
let amountTransferred: bigint | undefined = undefined;
|
|
@@ -955,6 +971,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
955
971
|
forceComplete = false,
|
|
956
972
|
txOptions: Overrides = {}
|
|
957
973
|
): Promise<TransactionLikeWithNonce> {
|
|
974
|
+
txOptions = this.applyTxDefaults(txOptions);
|
|
958
975
|
await this.ensureCorrectBulkPayoutInput(
|
|
959
976
|
escrowAddress,
|
|
960
977
|
recipients,
|
|
@@ -1043,7 +1060,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1043
1060
|
});
|
|
1044
1061
|
|
|
1045
1062
|
if (!finalResultsUrl) {
|
|
1046
|
-
throw
|
|
1063
|
+
throw ErrorInvalidUrl;
|
|
1047
1064
|
}
|
|
1048
1065
|
|
|
1049
1066
|
if (!isValidUrl(finalResultsUrl)) {
|
|
@@ -1153,7 +1170,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1153
1170
|
}
|
|
1154
1171
|
|
|
1155
1172
|
/**
|
|
1156
|
-
* This function returns the manifest
|
|
1173
|
+
* This function returns the manifest. Could be a URL or a JSON string.
|
|
1157
1174
|
*
|
|
1158
1175
|
* @param {string} escrowAddress Address of the escrow.
|
|
1159
1176
|
* @returns {Promise<string>} Url of the manifest.
|
|
@@ -1169,10 +1186,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
1169
1186
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
1170
1187
|
* const escrowClient = await EscrowClient.build(provider);
|
|
1171
1188
|
*
|
|
1172
|
-
* const
|
|
1189
|
+
* const manifest = await escrowClient.getManifest('0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
1173
1190
|
* ```
|
|
1174
1191
|
*/
|
|
1175
|
-
async
|
|
1192
|
+
async getManifest(escrowAddress: string): Promise<string> {
|
|
1176
1193
|
if (!ethers.isAddress(escrowAddress)) {
|
|
1177
1194
|
throw ErrorInvalidEscrowAddressProvided;
|
|
1178
1195
|
}
|
|
@@ -1631,7 +1648,7 @@ export class EscrowUtils {
|
|
|
1631
1648
|
* intermediateResultsUrl?: string;
|
|
1632
1649
|
* launcher: string;
|
|
1633
1650
|
* manifestHash?: string;
|
|
1634
|
-
*
|
|
1651
|
+
* manifest?: string;
|
|
1635
1652
|
* recordingOracle?: string;
|
|
1636
1653
|
* reputationOracle?: string;
|
|
1637
1654
|
* exchangeOracle?: string;
|
|
@@ -1752,7 +1769,7 @@ export class EscrowUtils {
|
|
|
1752
1769
|
* intermediateResultsUrl?: string;
|
|
1753
1770
|
* launcher: string;
|
|
1754
1771
|
* manifestHash?: string;
|
|
1755
|
-
*
|
|
1772
|
+
* manifest?: string;
|
|
1756
1773
|
* recordingOracle?: string;
|
|
1757
1774
|
* reputationOracle?: string;
|
|
1758
1775
|
* exchangeOracle?: string;
|
package/src/interfaces.ts
CHANGED
|
@@ -75,7 +75,7 @@ export interface IEscrow {
|
|
|
75
75
|
intermediateResultsUrl?: string;
|
|
76
76
|
launcher: string;
|
|
77
77
|
manifestHash?: string;
|
|
78
|
-
|
|
78
|
+
manifest?: string;
|
|
79
79
|
recordingOracle?: string;
|
|
80
80
|
reputationOracle?: string;
|
|
81
81
|
exchangeOracle?: string;
|
|
@@ -105,7 +105,7 @@ export interface IEscrowConfig {
|
|
|
105
105
|
recordingOracleFee: bigint;
|
|
106
106
|
reputationOracleFee: bigint;
|
|
107
107
|
exchangeOracleFee: bigint;
|
|
108
|
-
|
|
108
|
+
manifest: string;
|
|
109
109
|
manifestHash: string;
|
|
110
110
|
}
|
|
111
111
|
|
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/staking.ts
CHANGED
|
@@ -207,7 +207,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
207
207
|
await this.tokenContract.approve(
|
|
208
208
|
await this.stakingContract.getAddress(),
|
|
209
209
|
amount,
|
|
210
|
-
txOptions
|
|
210
|
+
this.applyTxDefaults(txOptions)
|
|
211
211
|
)
|
|
212
212
|
).wait();
|
|
213
213
|
return;
|
|
@@ -254,7 +254,12 @@ export class StakingClient extends BaseEthersClient {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
try {
|
|
257
|
-
await (
|
|
257
|
+
await (
|
|
258
|
+
await this.stakingContract.stake(
|
|
259
|
+
amount,
|
|
260
|
+
this.applyTxDefaults(txOptions)
|
|
261
|
+
)
|
|
262
|
+
).wait();
|
|
258
263
|
return;
|
|
259
264
|
} catch (e) {
|
|
260
265
|
return throwError(e);
|
|
@@ -301,7 +306,12 @@ export class StakingClient extends BaseEthersClient {
|
|
|
301
306
|
}
|
|
302
307
|
|
|
303
308
|
try {
|
|
304
|
-
await (
|
|
309
|
+
await (
|
|
310
|
+
await this.stakingContract.unstake(
|
|
311
|
+
amount,
|
|
312
|
+
this.applyTxDefaults(txOptions)
|
|
313
|
+
)
|
|
314
|
+
).wait();
|
|
305
315
|
return;
|
|
306
316
|
} catch (e) {
|
|
307
317
|
return throwError(e);
|
|
@@ -335,7 +345,9 @@ export class StakingClient extends BaseEthersClient {
|
|
|
335
345
|
@requiresSigner
|
|
336
346
|
public async withdraw(txOptions: Overrides = {}): Promise<void> {
|
|
337
347
|
try {
|
|
338
|
-
await (
|
|
348
|
+
await (
|
|
349
|
+
await this.stakingContract.withdraw(this.applyTxDefaults(txOptions))
|
|
350
|
+
).wait();
|
|
339
351
|
return;
|
|
340
352
|
} catch (e) {
|
|
341
353
|
return throwError(e);
|
|
@@ -402,7 +414,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
402
414
|
staker,
|
|
403
415
|
escrowAddress,
|
|
404
416
|
amount,
|
|
405
|
-
txOptions
|
|
417
|
+
this.applyTxDefaults(txOptions)
|
|
406
418
|
)
|
|
407
419
|
).wait();
|
|
408
420
|
|
|
@@ -439,6 +451,7 @@ export class StakingClient extends BaseEthersClient {
|
|
|
439
451
|
|
|
440
452
|
try {
|
|
441
453
|
const stakerInfo = await this.stakingContract.stakes(stakerAddress);
|
|
454
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
442
455
|
const currentBlock = await this.runner.provider!.getBlockNumber();
|
|
443
456
|
|
|
444
457
|
const tokensWithdrawable =
|