@streamflow/stream 7.0.0-alpha.1 → 7.0.0-alpha.11

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.
Files changed (64) hide show
  1. package/README.md +65 -68
  2. package/dist/cjs/__tests__/aptos/streamClient.spec.js +83 -134
  3. package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +9 -9
  4. package/dist/cjs/aptos/StreamClient.js +162 -367
  5. package/dist/cjs/aptos/constants.js +7 -8
  6. package/dist/cjs/aptos/index.js +3 -3
  7. package/dist/cjs/aptos/types.js +32 -41
  8. package/dist/cjs/aptos/utils.js +4 -4
  9. package/dist/cjs/aptos/wallet.js +20 -75
  10. package/dist/cjs/common/BaseStreamClient.js +11 -59
  11. package/dist/cjs/common/GenericStreamClient.js +46 -72
  12. package/dist/cjs/common/constants.js +2 -2
  13. package/dist/cjs/common/contractUtils.js +16 -17
  14. package/dist/cjs/common/utils.js +34 -84
  15. package/dist/cjs/evm/StreamClient.js +198 -456
  16. package/dist/cjs/evm/constants.js +19 -20
  17. package/dist/cjs/evm/types.js +25 -34
  18. package/dist/cjs/evm/utils.js +2 -2
  19. package/dist/cjs/index.js +10 -10
  20. package/dist/cjs/solana/StreamClient.js +608 -1090
  21. package/dist/cjs/solana/constants.js +16 -11
  22. package/dist/cjs/solana/instructions.js +76 -80
  23. package/dist/cjs/solana/layout.js +7 -8
  24. package/dist/cjs/solana/types.js +15 -25
  25. package/dist/cjs/solana/utils.js +77 -154
  26. package/dist/cjs/sui/StreamClient.js +325 -571
  27. package/dist/cjs/sui/constants.js +19 -20
  28. package/dist/cjs/sui/types.js +28 -62
  29. package/dist/cjs/sui/utils.js +7 -7
  30. package/dist/cjs/sui/wallet.js +13 -63
  31. package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
  32. package/dist/esm/aptos/index.d.ts +3 -3
  33. package/dist/esm/aptos/index.js +3 -3
  34. package/dist/esm/aptos/types.d.ts +12 -12
  35. package/dist/esm/aptos/types.js +13 -13
  36. package/dist/esm/common/GenericStreamClient.d.ts +4 -4
  37. package/dist/esm/common/GenericStreamClient.js +4 -4
  38. package/dist/esm/common/constants.d.ts +2 -2
  39. package/dist/esm/common/constants.js +2 -2
  40. package/dist/esm/common/contractUtils.d.ts +14 -14
  41. package/dist/esm/common/contractUtils.js +6 -6
  42. package/dist/esm/common/types.d.ts +19 -19
  43. package/dist/esm/common/utils.d.ts +11 -11
  44. package/dist/esm/common/utils.js +16 -19
  45. package/dist/esm/evm/StreamClient.d.ts +2 -2
  46. package/dist/esm/evm/StreamClient.js +7 -7
  47. package/dist/esm/evm/types.d.ts +37 -37
  48. package/dist/esm/evm/types.js +13 -13
  49. package/dist/esm/index.d.ts +9 -9
  50. package/dist/esm/index.js +9 -9
  51. package/dist/esm/solana/StreamClient.d.ts +3 -1
  52. package/dist/esm/solana/StreamClient.js +38 -22
  53. package/dist/esm/solana/constants.d.ts +3 -0
  54. package/dist/esm/solana/constants.js +6 -0
  55. package/dist/esm/solana/instructions.d.ts +17 -17
  56. package/dist/esm/solana/instructions.js +19 -18
  57. package/dist/esm/solana/types.d.ts +41 -36
  58. package/dist/esm/solana/types.js +2 -2
  59. package/dist/esm/solana/utils.d.ts +2 -0
  60. package/dist/esm/solana/utils.js +32 -26
  61. package/dist/esm/sui/StreamClient.js +1 -1
  62. package/dist/esm/sui/types.d.ts +12 -12
  63. package/dist/esm/sui/types.js +13 -13
  64. package/package.json +10 -11
@@ -1,87 +1,46 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
5
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.getNumberFromBN = exports.getBN = void 0;
43
- var bn_js_1 = __importDefault(require("bn.js"));
44
- var types_js_1 = require("./types.js");
45
- var FEE_PRECISION = 4;
46
- var FEE_NORMALIZER = Math.pow(10, FEE_PRECISION);
47
- var FEE_MULTIPLIER = new bn_js_1.default(Math.pow(10, 6));
6
+ exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.getScaledBigNumber = exports.getNumberFromBigNumber = void 0;
7
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
8
+ const types_js_1 = require("./types.js");
9
+ const FEE_PRECISION = 4;
10
+ const FEE_NORMALIZER = 10 ** FEE_PRECISION;
11
+ const FEE_MULTIPLIER = (0, bignumber_js_1.default)(10 ** 6);
48
12
  /**
49
- * Used for conversion of token amounts to their Big Number representation.
50
- * Get Big Number representation in the smallest units from the same value in the highest units.
51
- * @param {number} value - Number of tokens you want to convert to its BN representation.
13
+ * Used for token amounts conversion from their Big Number representation to number.
14
+ * Get value in the highest units from BigNumber representation of the same value in the smallest units.
15
+ * @param {BigNumber} value - Big Number representation of value in the smallest units.
52
16
  * @param {number} decimals - Number of decimals the token has.
53
17
  */
54
- var getBN = function (value, decimals) {
55
- var decimalPart = value - Math.trunc(value);
56
- var integerPart = new bn_js_1.default(Math.trunc(value));
57
- var decimalE = new bn_js_1.default(decimalPart * 1e9);
58
- var sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
59
- var resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
60
- return resultE.div(new bn_js_1.default(1e9));
18
+ const getNumberFromBigNumber = (bigNum, decimals) => {
19
+ return bigNum.div((0, bignumber_js_1.default)(10).pow(decimals)).toNumber();
61
20
  };
62
- exports.getBN = getBN;
21
+ exports.getNumberFromBigNumber = getNumberFromBigNumber;
63
22
  /**
64
- * Used for token amounts conversion from their Big Number representation to number.
65
- * Get value in the highest units from BN representation of the same value in the smallest units.
66
- * @param {BN} value - Big Number representation of value in the smallest units.
23
+ * Used for conversion of token amounts to their Big Number representation.
24
+ * Get Big Number representation in the smallest units from the same value in the highest units.
25
+ * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
67
26
  * @param {number} decimals - Number of decimals the token has.
68
27
  */
69
- var getNumberFromBN = function (value, decimals) {
70
- return value.gt(new bn_js_1.default(Math.pow(2, 53) - 1)) ? value.div(new bn_js_1.default(Math.pow(10, decimals))).toNumber() : value.toNumber() / Math.pow(10, decimals);
28
+ const getScaledBigNumber = (value, decimals) => {
29
+ return new bignumber_js_1.default(value).times(new bignumber_js_1.default(10).pow(decimals));
71
30
  };
72
- exports.getNumberFromBN = getNumberFromBN;
31
+ exports.getScaledBigNumber = getScaledBigNumber;
73
32
  /**
74
33
  * Calculate total amount of a Contract including all fees.
75
- * - first we convert fee floating to a BN with up to 4 decimals precision
34
+ * - first we convert fee floating to a BigNumber with up to 4 decimals precision
76
35
  * - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
77
36
  * to receive a total number and not percentage of depositedAmount
78
37
  * @param depositedAmount deposited raw tokens
79
38
  * @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
80
39
  * @returns total tokens amount that Contract will retrieve from the Sender
81
40
  */
82
- var calculateTotalAmountToDeposit = function (depositedAmount, totalFee) {
83
- var totalFeeNormalized = new bn_js_1.default(totalFee * FEE_NORMALIZER);
84
- return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
41
+ const calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
42
+ const totalFeeNormalized = (0, bignumber_js_1.default)(totalFee).times(FEE_NORMALIZER);
43
+ return depositedAmount.times(totalFeeNormalized.plus(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
85
44
  };
86
45
  exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
87
46
  /**
@@ -90,27 +49,18 @@ exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
90
49
  * @param callback callback that may be used to extract error code
91
50
  * @returns {T}
92
51
  */
93
- function handleContractError(func, callback) {
94
- return __awaiter(this, void 0, void 0, function () {
95
- var err_1;
96
- return __generator(this, function (_a) {
97
- switch (_a.label) {
98
- case 0:
99
- _a.trys.push([0, 2, , 3]);
100
- return [4 /*yield*/, func()];
101
- case 1: return [2 /*return*/, _a.sent()];
102
- case 2:
103
- err_1 = _a.sent();
104
- if (err_1 instanceof Error) {
105
- if (callback) {
106
- throw new types_js_1.ContractError(err_1, callback(err_1));
107
- }
108
- throw new types_js_1.ContractError(err_1);
109
- }
110
- throw err_1;
111
- case 3: return [2 /*return*/];
52
+ async function handleContractError(func, callback) {
53
+ try {
54
+ return await func();
55
+ }
56
+ catch (err) {
57
+ if (err instanceof Error) {
58
+ if (callback) {
59
+ throw new types_js_1.ContractError(err, callback(err));
112
60
  }
113
- });
114
- });
61
+ throw new types_js_1.ContractError(err);
62
+ }
63
+ throw err;
64
+ }
115
65
  }
116
66
  exports.handleContractError = handleContractError;