@human-protocol/sdk 4.2.0 → 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 +3 -1
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +11 -10
- 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/package.json +6 -6
- package/src/base.ts +23 -1
- package/src/constants.ts +3 -0
- package/src/escrow.ts +29 -10
- package/src/kvstore.ts +47 -3
- package/src/staking.ts +18 -5
package/dist/base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContractRunner } from 'ethers';
|
|
1
|
+
import { ContractRunner, Overrides } from 'ethers';
|
|
2
2
|
import { NetworkData } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* ## Introduction
|
|
@@ -16,5 +16,14 @@ export declare abstract class BaseEthersClient {
|
|
|
16
16
|
* @param {NetworkData} networkData The network information required to connect to the contracts
|
|
17
17
|
*/
|
|
18
18
|
constructor(runner: ContractRunner, networkData: NetworkData);
|
|
19
|
+
/**
|
|
20
|
+
* Internal helper to enrich transaction overrides with network specific defaults.
|
|
21
|
+
*
|
|
22
|
+
* Aurora networks use a fixed gas price. We always override any user provided
|
|
23
|
+
* gasPrice with the canonical DEFAULT_AURORA_GAS_PRICE to avoid mismatches
|
|
24
|
+
* or tx failures due to an unexpected value. For other networks the user
|
|
25
|
+
* supplied fee parameters are left untouched.
|
|
26
|
+
*/
|
|
27
|
+
protected applyTxDefaults(txOptions?: Overrides): Overrides;
|
|
19
28
|
}
|
|
20
29
|
//# sourceMappingURL=base.d.ts.map
|
package/dist/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAItC;;;;;GAKG;AACH,8BAAsB,gBAAgB;IACpC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC;IAC1B,WAAW,EAAE,WAAW,CAAC;IAEhC;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;IAK5D;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,CAAC,SAAS,GAAE,SAAc,GAAG,SAAS;CAWhE"}
|
package/dist/base.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseEthersClient = void 0;
|
|
4
|
+
const enums_1 = require("./enums");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
4
6
|
/**
|
|
5
7
|
* ## Introduction
|
|
6
8
|
*
|
|
@@ -18,5 +20,24 @@ class BaseEthersClient {
|
|
|
18
20
|
this.networkData = networkData;
|
|
19
21
|
this.runner = runner;
|
|
20
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Internal helper to enrich transaction overrides with network specific defaults.
|
|
25
|
+
*
|
|
26
|
+
* Aurora networks use a fixed gas price. We always override any user provided
|
|
27
|
+
* gasPrice with the canonical DEFAULT_AURORA_GAS_PRICE to avoid mismatches
|
|
28
|
+
* or tx failures due to an unexpected value. For other networks the user
|
|
29
|
+
* supplied fee parameters are left untouched.
|
|
30
|
+
*/
|
|
31
|
+
applyTxDefaults(txOptions = {}) {
|
|
32
|
+
if (this.networkData.chainId === enums_1.ChainId.AURORA_TESTNET) {
|
|
33
|
+
return {
|
|
34
|
+
...txOptions,
|
|
35
|
+
gasPrice: constants_1.DEFAULT_AURORA_GAS_PRICE,
|
|
36
|
+
maxFeePerGas: undefined,
|
|
37
|
+
maxPriorityFeePerGas: undefined,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return txOptions;
|
|
41
|
+
}
|
|
21
42
|
}
|
|
22
43
|
exports.BaseEthersClient = BaseEthersClient;
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const DEFAULT_ENDPOINT = "localhost";
|
|
|
5
5
|
export declare const DEFAULT_REGION = "eu";
|
|
6
6
|
export declare const DEFAULT_PORT = 9000;
|
|
7
7
|
export declare const DEFAULT_USE_SSL = false;
|
|
8
|
+
export declare const DEFAULT_AURORA_GAS_PRICE: bigint;
|
|
8
9
|
export declare enum HttpStatus {
|
|
9
10
|
OK = 200,
|
|
10
11
|
CREATED = 201,
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAO,MAAM,qBAAqB,0BAA0B,CAAC;AAE7D,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAE5C,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,eAAO,MAAM,wBAAwB,QAAoC,CAAC;AAE1E,oBAAY,UAAU;IACpB,EAAE,MAAM;IACR,OAAO,MAAM;IACb,WAAW,MAAM;IACjB,YAAY,MAAM;IAClB,gBAAgB,MAAM;IACtB,SAAS,MAAM;IACf,SAAS,MAAM;IACf,qBAAqB,MAAM;CAC5B;AAED,eAAO,MAAM,QAAQ,EAAE;KACpB,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,WAAW;CA0HnC,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;CAavB,CAAC;AAEF,eAAO,MAAM,IAAI;;;;;CAKhB,CAAC;AAEF,eAAO,MAAM,4BAA4B,uBAAuB,CAAC;AAEjE,eAAO,MAAM,4BAA4B,KAAK,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ESCROW_BULK_PAYOUT_MAX_ITEMS = exports.SUBGRAPH_API_KEY_PLACEHOLDER = exports.Role = exports.KVStoreKeys = exports.NETWORKS = exports.HttpStatus = exports.DEFAULT_USE_SSL = exports.DEFAULT_PORT = exports.DEFAULT_REGION = exports.DEFAULT_ENDPOINT = exports.DEFAULT_PUBLIC_BUCKET = void 0;
|
|
3
|
+
exports.ESCROW_BULK_PAYOUT_MAX_ITEMS = exports.SUBGRAPH_API_KEY_PLACEHOLDER = exports.Role = exports.KVStoreKeys = exports.NETWORKS = exports.HttpStatus = exports.DEFAULT_AURORA_GAS_PRICE = exports.DEFAULT_USE_SSL = exports.DEFAULT_PORT = exports.DEFAULT_REGION = exports.DEFAULT_ENDPOINT = exports.DEFAULT_PUBLIC_BUCKET = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
4
5
|
const enums_1 = require("./enums");
|
|
5
6
|
exports.DEFAULT_PUBLIC_BUCKET = 'escrow-public-results';
|
|
6
7
|
exports.DEFAULT_ENDPOINT = 'localhost';
|
|
7
8
|
exports.DEFAULT_REGION = 'eu';
|
|
8
9
|
exports.DEFAULT_PORT = 9000;
|
|
9
10
|
exports.DEFAULT_USE_SSL = false;
|
|
11
|
+
exports.DEFAULT_AURORA_GAS_PRICE = ethers_1.ethers.parseUnits('0.07', 'gwei');
|
|
10
12
|
var HttpStatus;
|
|
11
13
|
(function (HttpStatus) {
|
|
12
14
|
HttpStatus[HttpStatus["OK"] = 200] = "OK";
|
package/dist/escrow.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../src/escrow.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAY,SAAS,EAAkB,MAAM,QAAQ,CAAC;AAE7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AA0BlD,OAAO,EAML,WAAW,EACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,OAAO,EACP,aAAa,EACb,cAAc,EACd,aAAa,EACb,kBAAkB,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,WAAW,EACX,wBAAwB,EACxB,MAAM,EACP,MAAM,SAAS,CAAC;AASjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,OAAO,CAAC,qBAAqB,CAAgB;IAE7C;;;;;OAKG;gBACS,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,WAAW;IAS5D;;;;;;;;OAQG;WACiB,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC;IAiBxE;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAQzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IAEU,YAAY,CACvB,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,EAAE,EACzB,cAAc,EAAE,MAAM,EACtB,SAAS,GAAE,SA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,CACjC,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,WAAW,EAAE,CAAC;IA+DzB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;WACiB,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAiCzE"}
|
package/dist/escrow.js
CHANGED
|
@@ -180,7 +180,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
180
180
|
}
|
|
181
181
|
});
|
|
182
182
|
try {
|
|
183
|
-
const result = await (await this.escrowFactoryContract.createEscrow(tokenAddress, trustedHandlers, jobRequesterId, txOptions)).wait();
|
|
183
|
+
const result = await (await this.escrowFactoryContract.createEscrow(tokenAddress, trustedHandlers, jobRequesterId, this.applyTxDefaults(txOptions))).wait();
|
|
184
184
|
const event = result?.logs?.find(({ topics }) => topics.includes(ethers_1.ethers.id('LaunchedV2(address,address,string)')))?.args;
|
|
185
185
|
if (!event) {
|
|
186
186
|
throw error_1.ErrorLaunchedEventIsNotEmitted;
|
|
@@ -263,7 +263,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
263
263
|
}
|
|
264
264
|
try {
|
|
265
265
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
266
|
-
await (await escrowContract.setup(reputationOracle, recordingOracle, exchangeOracle, reputationOracleFee, recordingOracleFee, exchangeOracleFee, manifest, manifestHash, txOptions)).wait();
|
|
266
|
+
await (await escrowContract.setup(reputationOracle, recordingOracle, exchangeOracle, reputationOracleFee, recordingOracleFee, exchangeOracleFee, manifest, manifestHash, this.applyTxDefaults(txOptions))).wait();
|
|
267
267
|
return;
|
|
268
268
|
}
|
|
269
269
|
catch (e) {
|
|
@@ -310,7 +310,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
310
310
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
311
311
|
const tokenAddress = await escrowContract.token();
|
|
312
312
|
const tokenContract = typechain_types_1.HMToken__factory.connect(tokenAddress, this.runner);
|
|
313
|
-
await (await tokenContract.transfer(escrowAddress, amount, txOptions)).wait();
|
|
313
|
+
await (await tokenContract.transfer(escrowAddress, amount, this.applyTxDefaults(txOptions))).wait();
|
|
314
314
|
return;
|
|
315
315
|
}
|
|
316
316
|
catch (e) {
|
|
@@ -363,7 +363,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
363
363
|
}
|
|
364
364
|
try {
|
|
365
365
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
366
|
-
await (await escrowContract.storeResults(url, hash, txOptions)).wait();
|
|
366
|
+
await (await escrowContract.storeResults(url, hash, this.applyTxDefaults(txOptions))).wait();
|
|
367
367
|
return;
|
|
368
368
|
}
|
|
369
369
|
catch (e) {
|
|
@@ -405,7 +405,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
405
405
|
}
|
|
406
406
|
try {
|
|
407
407
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
408
|
-
await (await escrowContract.complete(txOptions)).wait();
|
|
408
|
+
await (await escrowContract.complete(this.applyTxDefaults(txOptions))).wait();
|
|
409
409
|
return;
|
|
410
410
|
}
|
|
411
411
|
catch (e) {
|
|
@@ -455,10 +455,10 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
455
455
|
try {
|
|
456
456
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
457
457
|
if (forceComplete) {
|
|
458
|
-
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete, txOptions)).wait();
|
|
458
|
+
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256,bool)'](recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete, this.applyTxDefaults(txOptions))).wait();
|
|
459
459
|
}
|
|
460
460
|
else {
|
|
461
|
-
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256)'](recipients, amounts, finalResultsUrl, finalResultsHash, txId, txOptions)).wait();
|
|
461
|
+
await (await escrowContract['bulkPayOut(address[],uint256[],string,string,uint256)'](recipients, amounts, finalResultsUrl, finalResultsHash, txId, this.applyTxDefaults(txOptions))).wait();
|
|
462
462
|
}
|
|
463
463
|
return;
|
|
464
464
|
}
|
|
@@ -501,7 +501,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
501
501
|
}
|
|
502
502
|
try {
|
|
503
503
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
504
|
-
const transactionReceipt = await (await escrowContract.cancel(txOptions)).wait();
|
|
504
|
+
const transactionReceipt = await (await escrowContract.cancel(this.applyTxDefaults(txOptions))).wait();
|
|
505
505
|
let amountTransferred = undefined;
|
|
506
506
|
const tokenAddress = await escrowContract.token();
|
|
507
507
|
const tokenContract = typechain_types_1.HMToken__factory.connect(tokenAddress, this.runner);
|
|
@@ -577,7 +577,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
577
577
|
}
|
|
578
578
|
try {
|
|
579
579
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
580
|
-
await (await escrowContract.addTrustedHandlers(trustedHandlers, txOptions)).wait();
|
|
580
|
+
await (await escrowContract.addTrustedHandlers(trustedHandlers, this.applyTxDefaults(txOptions))).wait();
|
|
581
581
|
return;
|
|
582
582
|
}
|
|
583
583
|
catch (e) {
|
|
@@ -626,7 +626,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
626
626
|
}
|
|
627
627
|
try {
|
|
628
628
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
629
|
-
const transactionReceipt = await (await escrowContract.withdraw(tokenAddress, txOptions)).wait();
|
|
629
|
+
const transactionReceipt = await (await escrowContract.withdraw(tokenAddress, this.applyTxDefaults(txOptions))).wait();
|
|
630
630
|
let amountTransferred = undefined;
|
|
631
631
|
const tokenContract = typechain_types_1.ERC20__factory.connect(tokenAddress, this.runner);
|
|
632
632
|
if (transactionReceipt)
|
|
@@ -698,6 +698,7 @@ class EscrowClient extends base_1.BaseEthersClient {
|
|
|
698
698
|
* (await signer.sendTransaction(rawTransaction)).wait();
|
|
699
699
|
*/
|
|
700
700
|
async createBulkPayoutTransaction(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash, txId, forceComplete = false, txOptions = {}) {
|
|
701
|
+
txOptions = this.applyTxDefaults(txOptions);
|
|
701
702
|
await this.ensureCorrectBulkPayoutInput(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash);
|
|
702
703
|
const signer = this.runner;
|
|
703
704
|
try {
|
package/dist/kvstore.d.ts
CHANGED
|
@@ -176,6 +176,31 @@ export declare class KVStoreClient extends BaseEthersClient {
|
|
|
176
176
|
* ```
|
|
177
177
|
*/
|
|
178
178
|
setFileUrlAndHash(url: string, urlKey?: string, txOptions?: Overrides): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Gets the value of a key-value pair in the contract.
|
|
181
|
+
*
|
|
182
|
+
* @param {string} address Address from which to get the key value.
|
|
183
|
+
* @param {string} key Key to obtain the value.
|
|
184
|
+
* @returns {string} Value of the key.
|
|
185
|
+
*
|
|
186
|
+
*
|
|
187
|
+
* **Code example**
|
|
188
|
+
*
|
|
189
|
+
* > Need to have available stake.
|
|
190
|
+
*
|
|
191
|
+
* ```ts
|
|
192
|
+
* import { providers } from 'ethers';
|
|
193
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
194
|
+
*
|
|
195
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
196
|
+
*
|
|
197
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
198
|
+
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
199
|
+
*
|
|
200
|
+
* const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
get(address: string, key: string): Promise<string>;
|
|
179
204
|
}
|
|
180
205
|
/**
|
|
181
206
|
* ## Introduction
|
package/dist/kvstore.d.ts.map
CHANGED
|
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lB;;;;;;;;;;;;;;;;;;;OAmBG;WACiB,uBAAuB,CACzC,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,SAAQ,GACb,OAAO,CAAC,MAAM,CAAC;IAqClB;;;;;;;;;;;;;;;;;;OAkBG;WACiB,YAAY,CAC9B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC;CAenB"}
|
package/dist/kvstore.js
CHANGED
|
@@ -154,7 +154,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
154
154
|
if (key === '')
|
|
155
155
|
throw error_1.ErrorKVStoreEmptyKey;
|
|
156
156
|
try {
|
|
157
|
-
await (await this.contract.set(key, value, txOptions)).wait();
|
|
157
|
+
await (await this.contract.set(key, value, this.applyTxDefaults(txOptions))).wait();
|
|
158
158
|
}
|
|
159
159
|
catch (e) {
|
|
160
160
|
if (e instanceof Error)
|
|
@@ -196,7 +196,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
196
196
|
if (keys.includes(''))
|
|
197
197
|
throw error_1.ErrorKVStoreEmptyKey;
|
|
198
198
|
try {
|
|
199
|
-
await (await this.contract.setBulk(keys, values, txOptions)).wait();
|
|
199
|
+
await (await this.contract.setBulk(keys, values, this.applyTxDefaults(txOptions))).wait();
|
|
200
200
|
}
|
|
201
201
|
catch (e) {
|
|
202
202
|
if (e instanceof Error)
|
|
@@ -237,13 +237,52 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
237
237
|
const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
|
|
238
238
|
const hashKey = urlKey + '_hash';
|
|
239
239
|
try {
|
|
240
|
-
await (await this.contract.setBulk([urlKey, hashKey], [url, contentHash], txOptions)).wait();
|
|
240
|
+
await (await this.contract.setBulk([urlKey, hashKey], [url, contentHash], this.applyTxDefaults(txOptions))).wait();
|
|
241
241
|
}
|
|
242
242
|
catch (e) {
|
|
243
243
|
if (e instanceof Error)
|
|
244
244
|
throw Error(`Failed to set URL and hash: ${e.message}`);
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Gets the value of a key-value pair in the contract.
|
|
249
|
+
*
|
|
250
|
+
* @param {string} address Address from which to get the key value.
|
|
251
|
+
* @param {string} key Key to obtain the value.
|
|
252
|
+
* @returns {string} Value of the key.
|
|
253
|
+
*
|
|
254
|
+
*
|
|
255
|
+
* **Code example**
|
|
256
|
+
*
|
|
257
|
+
* > Need to have available stake.
|
|
258
|
+
*
|
|
259
|
+
* ```ts
|
|
260
|
+
* import { providers } from 'ethers';
|
|
261
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
262
|
+
*
|
|
263
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
264
|
+
*
|
|
265
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
266
|
+
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
267
|
+
*
|
|
268
|
+
* const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
async get(address, key) {
|
|
272
|
+
if (key === '')
|
|
273
|
+
throw error_1.ErrorKVStoreEmptyKey;
|
|
274
|
+
if (!ethers_1.ethers.isAddress(address))
|
|
275
|
+
throw error_1.ErrorInvalidAddress;
|
|
276
|
+
try {
|
|
277
|
+
const result = await this.contract?.get(address, key);
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
catch (e) {
|
|
281
|
+
if (e instanceof Error)
|
|
282
|
+
throw Error(`Failed to get value: ${e.message}`);
|
|
283
|
+
return e;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
247
286
|
}
|
|
248
287
|
exports.KVStoreClient = KVStoreClient;
|
|
249
288
|
__decorate([
|
package/dist/staking.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staking.d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B,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/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,
|
package/src/escrow.ts
CHANGED
|
@@ -251,7 +251,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
251
251
|
tokenAddress,
|
|
252
252
|
trustedHandlers,
|
|
253
253
|
jobRequesterId,
|
|
254
|
-
txOptions
|
|
254
|
+
this.applyTxDefaults(txOptions)
|
|
255
255
|
)
|
|
256
256
|
).wait();
|
|
257
257
|
|
|
@@ -380,7 +380,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
380
380
|
exchangeOracleFee,
|
|
381
381
|
manifest,
|
|
382
382
|
manifestHash,
|
|
383
|
-
txOptions
|
|
383
|
+
this.applyTxDefaults(txOptions)
|
|
384
384
|
)
|
|
385
385
|
).wait();
|
|
386
386
|
|
|
@@ -444,7 +444,11 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
444
444
|
this.runner
|
|
445
445
|
);
|
|
446
446
|
await (
|
|
447
|
-
await tokenContract.transfer(
|
|
447
|
+
await tokenContract.transfer(
|
|
448
|
+
escrowAddress,
|
|
449
|
+
amount,
|
|
450
|
+
this.applyTxDefaults(txOptions)
|
|
451
|
+
)
|
|
448
452
|
).wait();
|
|
449
453
|
|
|
450
454
|
return;
|
|
@@ -511,7 +515,13 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
511
515
|
try {
|
|
512
516
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
513
517
|
|
|
514
|
-
await (
|
|
518
|
+
await (
|
|
519
|
+
await escrowContract.storeResults(
|
|
520
|
+
url,
|
|
521
|
+
hash,
|
|
522
|
+
this.applyTxDefaults(txOptions)
|
|
523
|
+
)
|
|
524
|
+
).wait();
|
|
515
525
|
|
|
516
526
|
return;
|
|
517
527
|
} catch (e) {
|
|
@@ -561,7 +571,9 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
561
571
|
try {
|
|
562
572
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
563
573
|
|
|
564
|
-
await (
|
|
574
|
+
await (
|
|
575
|
+
await escrowContract.complete(this.applyTxDefaults(txOptions))
|
|
576
|
+
).wait();
|
|
565
577
|
return;
|
|
566
578
|
} catch (e) {
|
|
567
579
|
return throwError(e);
|
|
@@ -638,7 +650,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
638
650
|
finalResultsHash,
|
|
639
651
|
txId,
|
|
640
652
|
forceComplete,
|
|
641
|
-
txOptions
|
|
653
|
+
this.applyTxDefaults(txOptions)
|
|
642
654
|
)
|
|
643
655
|
).wait();
|
|
644
656
|
} else {
|
|
@@ -651,7 +663,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
651
663
|
finalResultsUrl,
|
|
652
664
|
finalResultsHash,
|
|
653
665
|
txId,
|
|
654
|
-
txOptions
|
|
666
|
+
this.applyTxDefaults(txOptions)
|
|
655
667
|
)
|
|
656
668
|
).wait();
|
|
657
669
|
}
|
|
@@ -704,7 +716,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
704
716
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
705
717
|
|
|
706
718
|
const transactionReceipt = await (
|
|
707
|
-
await escrowContract.cancel(txOptions)
|
|
719
|
+
await escrowContract.cancel(this.applyTxDefaults(txOptions))
|
|
708
720
|
).wait();
|
|
709
721
|
|
|
710
722
|
let amountTransferred: bigint | undefined = undefined;
|
|
@@ -801,7 +813,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
801
813
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
802
814
|
|
|
803
815
|
await (
|
|
804
|
-
await escrowContract.addTrustedHandlers(
|
|
816
|
+
await escrowContract.addTrustedHandlers(
|
|
817
|
+
trustedHandlers,
|
|
818
|
+
this.applyTxDefaults(txOptions)
|
|
819
|
+
)
|
|
805
820
|
).wait();
|
|
806
821
|
return;
|
|
807
822
|
} catch (e) {
|
|
@@ -861,7 +876,10 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
861
876
|
const escrowContract = this.getEscrowContract(escrowAddress);
|
|
862
877
|
|
|
863
878
|
const transactionReceipt = await (
|
|
864
|
-
await escrowContract.withdraw(
|
|
879
|
+
await escrowContract.withdraw(
|
|
880
|
+
tokenAddress,
|
|
881
|
+
this.applyTxDefaults(txOptions)
|
|
882
|
+
)
|
|
865
883
|
).wait();
|
|
866
884
|
|
|
867
885
|
let amountTransferred: bigint | undefined = undefined;
|
|
@@ -953,6 +971,7 @@ export class EscrowClient extends BaseEthersClient {
|
|
|
953
971
|
forceComplete = false,
|
|
954
972
|
txOptions: Overrides = {}
|
|
955
973
|
): Promise<TransactionLikeWithNonce> {
|
|
974
|
+
txOptions = this.applyTxDefaults(txOptions);
|
|
956
975
|
await this.ensureCorrectBulkPayoutInput(
|
|
957
976
|
escrowAddress,
|
|
958
977
|
recipients,
|
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 =
|