@ethersphere/bee-js 9.4.1 → 9.5.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/cjs/bee.js CHANGED
@@ -1011,13 +1011,24 @@ class Bee {
1011
1011
  return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
1012
1012
  }
1013
1013
  /**
1014
- * Deposit tokens from overlay address into chequebook
1014
+ * Deposit tokens from node wallet into chequebook
1015
1015
  *
1016
1016
  * @param amount Amount of tokens to deposit (must be positive integer)
1017
1017
  * @param gasPrice Gas Price in WEI for the transaction call
1018
1018
  * @return string Hash of the transaction
1019
+ * @deprecated Use `depositBZZToChequebook` instead.
1019
1020
  */
1020
1021
  async depositTokens(amount, gasPrice, options) {
1022
+ return this.depositBZZToChequebook(amount, gasPrice, options);
1023
+ }
1024
+ /**
1025
+ * Deposit tokens from node wallet into chequebook
1026
+ *
1027
+ * @param amount Amount of tokens to deposit (must be positive integer)
1028
+ * @param gasPrice Gas Price in WEI for the transaction call
1029
+ * @return string Hash of the transaction
1030
+ */
1031
+ async depositBZZToChequebook(amount, gasPrice, options) {
1021
1032
  const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
1022
1033
  let gasPriceString;
1023
1034
  if (gasPrice) {
@@ -1026,13 +1037,24 @@ class Bee {
1026
1037
  return chequebook.depositTokens(this.getRequestOptionsForCall(options), amountString, gasPriceString);
1027
1038
  }
1028
1039
  /**
1029
- * Withdraw tokens from the chequebook to the overlay address
1040
+ * Withdraw tokens from the chequebook to the node wallet
1030
1041
  *
1031
1042
  * @param amount Amount of tokens to withdraw (must be positive integer)
1032
1043
  * @param gasPrice Gas Price in WEI for the transaction call
1033
1044
  * @return string Hash of the transaction
1045
+ * @deprecated Use `withdrawBZZFromChequebook` instead.
1034
1046
  */
1035
1047
  async withdrawTokens(amount, gasPrice, options) {
1048
+ return this.withdrawBZZFromChequebook(amount, gasPrice, options);
1049
+ }
1050
+ /**
1051
+ * Withdraw tokens from the chequebook to the node wallet
1052
+ *
1053
+ * @param amount Amount of tokens to withdraw (must be positive integer)
1054
+ * @param gasPrice Gas Price in WEI for the transaction call
1055
+ * @return string Hash of the transaction
1056
+ */
1057
+ async withdrawBZZFromChequebook(amount, gasPrice, options) {
1036
1058
  // TODO: check BZZ in tests
1037
1059
  const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
1038
1060
  let gasPriceString;
@@ -1041,6 +1063,16 @@ class Bee {
1041
1063
  }
1042
1064
  return chequebook.withdrawTokens(this.getRequestOptionsForCall(options), amountString, gasPriceString);
1043
1065
  }
1066
+ async withdrawBZZToExternalWallet(amount, address, options) {
1067
+ amount = amount instanceof tokens_1.BZZ ? amount : tokens_1.BZZ.fromPLUR(amount);
1068
+ address = new typed_bytes_1.EthAddress(address);
1069
+ return states.withdrawBZZ(this.getRequestOptionsForCall(options), amount, address);
1070
+ }
1071
+ async withdrawDAIToExternalWallet(amount, address, options) {
1072
+ amount = amount instanceof tokens_1.DAI ? amount : tokens_1.DAI.fromWei(amount);
1073
+ address = new typed_bytes_1.EthAddress(address);
1074
+ return states.withdrawDAI(this.getRequestOptionsForCall(options), amount, address);
1075
+ }
1044
1076
  /*
1045
1077
  * Settlements endpoint
1046
1078
  */
@@ -1124,7 +1156,7 @@ class Bee {
1124
1156
  return states.getChainState(this.getRequestOptionsForCall(options));
1125
1157
  }
1126
1158
  /**
1127
- * Get wallet balances for xDai and BZZ of the Bee node
1159
+ * Get wallet balances for DAI and BZZ of the Bee node
1128
1160
  *
1129
1161
  * @param options
1130
1162
  */
@@ -1342,7 +1374,7 @@ class Bee {
1342
1374
  return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(options), transactionHash);
1343
1375
  }
1344
1376
  /**
1345
- * Cancel currently pending transaction
1377
+ * Cancels a currently pending transaction
1346
1378
  * @param transactionHash
1347
1379
  * @param gasPrice
1348
1380
  */
@@ -1355,20 +1387,48 @@ class Bee {
1355
1387
  return transactions.cancelTransaction(this.getRequestOptionsForCall(options), transactionHash, gasPriceString);
1356
1388
  }
1357
1389
  /**
1358
- * Gets the staked amount of BZZ (in PLUR unit) as number string.
1390
+ * Gets the amount of staked BZZ
1359
1391
  *
1360
- * @param options
1392
+ * @param options HTTP request options, such as `headers` or `timeout`
1361
1393
  */
1362
1394
  async getStake(options) {
1363
1395
  return stake.getStake(this.getRequestOptionsForCall(options));
1364
1396
  }
1365
1397
  /**
1366
- * Deposits given amount of BZZ token (in PLUR unit).
1398
+ * Gets the amount of withdrawable staked BZZ.
1399
+ *
1400
+ * @param options HTTP request options, such as `headers` or `timeout`
1401
+ */
1402
+ async getWithdrawableStake(options) {
1403
+ return stake.getWithdrawableStake(this.getRequestOptionsForCall(options));
1404
+ }
1405
+ /**
1406
+ * Withdraws ALL surplus staked BZZ to the node wallet.
1407
+ *
1408
+ * Use the `getWithdrawableStake` method to check how much surplus stake is available.
1409
+ *
1410
+ * @param options HTTP request options, such as `headers` or `timeout`
1411
+ */
1412
+ async withdrawSurplusStake(options) {
1413
+ return stake.withdrawSurplusStake(this.getRequestOptionsForCall(options));
1414
+ }
1415
+ /**
1416
+ * Withdraws all staked BZZ to the node wallet.
1417
+ *
1418
+ * **Only available when the staking contract is paused and is in the process of being migrated to a new contract!**
1419
+ *
1420
+ * @param options HTTP request options, such as `headers` or `timeout`
1421
+ */
1422
+ async migrateStake(options) {
1423
+ return stake.migrateStake(this.getRequestOptionsForCall(options));
1424
+ }
1425
+ /**
1426
+ * Stakes the given amount of BZZ. Initial deposit must be at least 10 BZZ.
1367
1427
  *
1368
1428
  * Be aware that staked BZZ tokens can **not** be withdrawn.
1369
1429
  *
1370
- * @param amount Amount of BZZ token (in PLUR unit) to be staked. Minimum is 100_000_000_000_000_000 PLUR (10 BZZ).
1371
- * @param options
1430
+ * @param amount Amount of BZZ tokens to be staked. If not providing a `BZZ` instance, the amount is denoted in PLUR.
1431
+ * @param options HTTP request options, such as `headers` or `timeout`
1372
1432
  */
1373
1433
  async depositStake(amount, options, requestOptions) {
1374
1434
  const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
@@ -1378,9 +1438,9 @@ class Bee {
1378
1438
  return stake.stake(this.getRequestOptionsForCall(requestOptions), amountString, options);
1379
1439
  }
1380
1440
  /**
1381
- * Get current status of node in redistribution game
1441
+ * Gets current status of node in redistribution game
1382
1442
  *
1383
- * @param options
1443
+ * @param options HTTP request options, such as `headers` or `timeout`
1384
1444
  */
1385
1445
  async getRedistributionState(options) {
1386
1446
  return stake.getRedistributionState(this.getRequestOptionsForCall(options));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRedistributionState = exports.stake = exports.getStake = void 0;
3
+ exports.getRedistributionState = exports.stake = exports.migrateStake = exports.withdrawSurplusStake = exports.getWithdrawableStake = exports.getStake = void 0;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
5
  const headers_1 = require("../../utils/headers");
6
6
  const http_1 = require("../../utils/http");
@@ -10,7 +10,7 @@ const typed_bytes_1 = require("../../utils/typed-bytes");
10
10
  const STAKE_ENDPOINT = 'stake';
11
11
  const REDISTRIBUTION_ENDPOINT = 'redistributionstate';
12
12
  /**
13
- * Gets the staked amount
13
+ * Gets the amount of staked BZZ
14
14
  *
15
15
  * @param requestOptions Options for making requests
16
16
  */
@@ -24,12 +24,46 @@ async function getStake(requestOptions) {
24
24
  return tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.stakedAmount, { name: 'stakedAmount' }));
25
25
  }
26
26
  exports.getStake = getStake;
27
+ /**
28
+ * Gets the amount of withdrawable staked BZZ
29
+ *
30
+ * @param requestOptions Options for making requests
31
+ */
32
+ async function getWithdrawableStake(requestOptions) {
33
+ const response = await (0, http_1.http)(requestOptions, {
34
+ method: 'get',
35
+ responseType: 'json',
36
+ url: `${STAKE_ENDPOINT}/withdrawable`,
37
+ });
38
+ const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
39
+ return tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.withdrawableAmount, { name: 'withdrawableAmount' }));
40
+ }
41
+ exports.getWithdrawableStake = getWithdrawableStake;
42
+ async function withdrawSurplusStake(requestOptions) {
43
+ const response = await (0, http_1.http)(requestOptions, {
44
+ method: 'delete',
45
+ responseType: 'json',
46
+ url: `${STAKE_ENDPOINT}/withdrawable`,
47
+ });
48
+ const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
49
+ return new typed_bytes_1.TransactionId(cafe_utility_1.Types.asHexString(body.txHash, { name: 'txHash' }));
50
+ }
51
+ exports.withdrawSurplusStake = withdrawSurplusStake;
52
+ async function migrateStake(requestOptions) {
53
+ const response = await (0, http_1.http)(requestOptions, {
54
+ method: 'delete',
55
+ responseType: 'json',
56
+ url: STAKE_ENDPOINT,
57
+ });
58
+ const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
59
+ return new typed_bytes_1.TransactionId(cafe_utility_1.Types.asHexString(body.txHash, { name: 'txHash' }));
60
+ }
61
+ exports.migrateStake = migrateStake;
27
62
  /**
28
63
  * Stake given amount of tokens.
29
64
  *
30
65
  * @param requestOptions Options for making requests
31
66
  * @param amount
32
- * @param options
33
67
  */
34
68
  async function stake(requestOptions, amount, options) {
35
69
  const repsonse = await (0, http_1.http)(requestOptions, {
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getWalletBalance = exports.getChainState = exports.getReserveState = void 0;
3
+ exports.withdrawDAI = exports.withdrawBZZ = exports.getWalletBalance = exports.getChainState = exports.getReserveState = void 0;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
5
  const http_1 = require("../../utils/http");
6
6
  const tokens_1 = require("../../utils/tokens");
7
7
  const type_1 = require("../../utils/type");
8
+ const typed_bytes_1 = require("../../utils/typed-bytes");
8
9
  const workaround_1 = require("../../utils/workaround");
9
10
  const RESERVE_STATE_ENDPOINT = 'reservestate';
10
11
  const WALLET_ENDPOINT = 'wallet';
@@ -69,3 +70,25 @@ async function getWalletBalance(requestOptions) {
69
70
  };
70
71
  }
71
72
  exports.getWalletBalance = getWalletBalance;
73
+ async function withdrawBZZ(requestOptions, amount, address) {
74
+ const response = await (0, http_1.http)(requestOptions, {
75
+ method: 'post',
76
+ url: `${WALLET_ENDPOINT}/withdraw/bzz`,
77
+ responseType: 'json',
78
+ params: { amount: amount.toPLURString(), address: address.toHex() },
79
+ });
80
+ const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
81
+ return new typed_bytes_1.TransactionId(cafe_utility_1.Types.asString(body.transactionHash, { name: 'transactionHash' }));
82
+ }
83
+ exports.withdrawBZZ = withdrawBZZ;
84
+ async function withdrawDAI(requestOptions, amount, address) {
85
+ const response = await (0, http_1.http)(requestOptions, {
86
+ method: 'post',
87
+ url: `${WALLET_ENDPOINT}/withdraw/nativetoken`,
88
+ responseType: 'json',
89
+ params: { amount: amount.toWeiString(), address: address.toHex() },
90
+ });
91
+ const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
92
+ return new typed_bytes_1.TransactionId(cafe_utility_1.Types.asString(body.transactionHash, { name: 'transactionHash' }));
93
+ }
94
+ exports.withdrawDAI = withdrawDAI;