@streamflow/stream 7.0.0-alpha.2 → 7.0.0-alpha.20

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 (78) hide show
  1. package/README.md +70 -67
  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 +28 -37
  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 +4 -3
  13. package/dist/cjs/common/contractUtils.js +33 -18
  14. package/dist/cjs/common/types.js +30 -1
  15. package/dist/cjs/common/utils.js +38 -80
  16. package/dist/cjs/evm/StreamClient.js +198 -456
  17. package/dist/cjs/evm/constants.js +19 -20
  18. package/dist/cjs/evm/types.js +25 -34
  19. package/dist/cjs/evm/utils.js +2 -2
  20. package/dist/cjs/index.js +10 -10
  21. package/dist/cjs/solana/StreamClient.js +759 -1090
  22. package/dist/cjs/solana/constants.js +44 -11
  23. package/dist/cjs/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
  24. package/dist/cjs/solana/descriptor/streamflow_aligned_unlocks.js +2 -0
  25. package/dist/cjs/solana/index.js +2 -1
  26. package/dist/cjs/solana/instructions.js +75 -81
  27. package/dist/cjs/solana/layout.js +7 -8
  28. package/dist/cjs/solana/lib/derive-accounts.js +17 -0
  29. package/dist/cjs/solana/lib/utils.js +127 -0
  30. package/dist/cjs/solana/types.js +40 -27
  31. package/dist/cjs/sui/StreamClient.js +325 -571
  32. package/dist/cjs/sui/constants.js +19 -20
  33. package/dist/cjs/sui/types.js +28 -62
  34. package/dist/cjs/sui/utils.js +7 -7
  35. package/dist/cjs/sui/wallet.js +13 -63
  36. package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
  37. package/dist/esm/aptos/index.d.ts +3 -3
  38. package/dist/esm/aptos/index.js +3 -3
  39. package/dist/esm/aptos/types.d.ts +14 -14
  40. package/dist/esm/aptos/types.js +13 -13
  41. package/dist/esm/common/GenericStreamClient.d.ts +4 -4
  42. package/dist/esm/common/GenericStreamClient.js +4 -4
  43. package/dist/esm/common/constants.d.ts +3 -2
  44. package/dist/esm/common/constants.js +3 -2
  45. package/dist/esm/common/contractUtils.d.ts +18 -15
  46. package/dist/esm/common/contractUtils.js +19 -6
  47. package/dist/esm/common/types.d.ts +112 -57
  48. package/dist/esm/common/types.js +29 -0
  49. package/dist/esm/common/utils.d.ts +11 -11
  50. package/dist/esm/common/utils.js +19 -16
  51. package/dist/esm/evm/StreamClient.d.ts +2 -2
  52. package/dist/esm/evm/StreamClient.js +7 -7
  53. package/dist/esm/evm/types.d.ts +14 -14
  54. package/dist/esm/evm/types.js +13 -13
  55. package/dist/esm/index.d.ts +9 -9
  56. package/dist/esm/index.js +9 -9
  57. package/dist/esm/solana/StreamClient.d.ts +24 -16
  58. package/dist/esm/solana/StreamClient.js +324 -156
  59. package/dist/esm/solana/constants.d.ts +17 -0
  60. package/dist/esm/solana/constants.js +35 -1
  61. package/dist/esm/solana/descriptor/idl/streamflow_aligned_unlocks.json +1471 -0
  62. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.d.ts +1272 -0
  63. package/dist/esm/solana/descriptor/streamflow_aligned_unlocks.js +1 -0
  64. package/dist/esm/solana/index.d.ts +2 -1
  65. package/dist/esm/solana/index.js +2 -1
  66. package/dist/esm/solana/instructions.d.ts +17 -17
  67. package/dist/esm/solana/instructions.js +18 -19
  68. package/dist/esm/solana/lib/derive-accounts.d.ts +4 -0
  69. package/dist/esm/solana/lib/derive-accounts.js +11 -0
  70. package/dist/esm/solana/{utils.d.ts → lib/utils.d.ts} +1 -3
  71. package/dist/esm/solana/{utils.js → lib/utils.js} +28 -34
  72. package/dist/esm/solana/types.d.ts +72 -39
  73. package/dist/esm/solana/types.js +32 -4
  74. package/dist/esm/sui/StreamClient.js +1 -1
  75. package/dist/esm/sui/types.d.ts +14 -14
  76. package/dist/esm/sui/types.js +13 -13
  77. package/package.json +12 -10
  78. package/dist/cjs/solana/utils.js +0 -222
@@ -1,82 +1,49 @@
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.getScaledBigNumber = exports.getNumberFromBigNumber = void 0;
43
- var bignumber_js_1 = __importDefault(require("bignumber.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 = (0, bignumber_js_1.default)(Math.pow(10, 6));
6
+ exports.handleContractError = exports.calculateTotalAmountToDeposit = exports.getNumberFromBN = exports.getBN = void 0;
7
+ const bn_js_1 = __importDefault(require("bn.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 = new bn_js_1.default(10 ** 6);
48
12
  /**
49
- * Used for token amounts conversion from their Big Number representation to number.
50
- * Get value in the highest units from BigNumber representation of the same value in the smallest units.
51
- * @param {BigNumber} value - Big Number representation of value in the smallest units.
13
+ * Used for conversion of token amounts to their Big Number representation.
14
+ * Get Big Number representation in the smallest units from the same value in the highest units.
15
+ * @param {number} value - Number of tokens you want to convert to its BN representation.
52
16
  * @param {number} decimals - Number of decimals the token has.
53
17
  */
54
- var getNumberFromBigNumber = function (bigNum, decimals) {
55
- return bigNum.div((0, bignumber_js_1.default)(10).pow(decimals)).toNumber();
18
+ const getBN = (value, decimals) => {
19
+ const decimalPart = value - Math.trunc(value);
20
+ const integerPart = new bn_js_1.default(Math.trunc(value));
21
+ const decimalE = new bn_js_1.default(decimalPart * 1e9);
22
+ const sum = integerPart.mul(new bn_js_1.default(1e9)).add(decimalE);
23
+ const resultE = sum.mul(new bn_js_1.default(10).pow(new bn_js_1.default(decimals)));
24
+ return resultE.div(new bn_js_1.default(1e9));
56
25
  };
57
- exports.getNumberFromBigNumber = getNumberFromBigNumber;
26
+ exports.getBN = getBN;
58
27
  /**
59
- * Used for conversion of token amounts to their Big Number representation.
60
- * Get Big Number representation in the smallest units from the same value in the highest units.
61
- * @param {number} value - Number of tokens you want to convert to its BigNumber representation.
28
+ * Used for token amounts conversion from their Big Number representation to number.
29
+ * Get value in the highest units from BN representation of the same value in the smallest units.
30
+ * @param {BN} value - Big Number representation of value in the smallest units.
62
31
  * @param {number} decimals - Number of decimals the token has.
63
32
  */
64
- var getScaledBigNumber = function (value, decimals) {
65
- return new bignumber_js_1.default(value).times(new bignumber_js_1.default(10).pow(decimals));
66
- };
67
- exports.getScaledBigNumber = getScaledBigNumber;
33
+ const getNumberFromBN = (value, decimals) => value.gt(new bn_js_1.default(2 ** 53 - 1)) ? value.div(new bn_js_1.default(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
34
+ exports.getNumberFromBN = getNumberFromBN;
68
35
  /**
69
36
  * Calculate total amount of a Contract including all fees.
70
- * - first we convert fee floating to a BigNumber with up to 4 decimals precision
37
+ * - first we convert fee floating to a BN with up to 4 decimals precision
71
38
  * - then we reverse the fee with `FEE_MULTIPLIER` to safely multiply it by depositedAmount
72
39
  * to receive a total number and not percentage of depositedAmount
73
40
  * @param depositedAmount deposited raw tokens
74
41
  * @param totalFee sum of all fees in percentage as floating number, e.g. 0.99% should be supplied as 0.99
75
42
  * @returns total tokens amount that Contract will retrieve from the Sender
76
43
  */
77
- var calculateTotalAmountToDeposit = function (depositedAmount, totalFee) {
78
- var totalFeeNormalized = (0, bignumber_js_1.default)(totalFee).times(FEE_NORMALIZER);
79
- return depositedAmount.times(totalFeeNormalized.plus(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
44
+ const calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
45
+ const totalFeeNormalized = new bn_js_1.default(totalFee * FEE_NORMALIZER);
46
+ return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
80
47
  };
81
48
  exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
82
49
  /**
@@ -85,27 +52,18 @@ exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
85
52
  * @param callback callback that may be used to extract error code
86
53
  * @returns {T}
87
54
  */
88
- function handleContractError(func, callback) {
89
- return __awaiter(this, void 0, void 0, function () {
90
- var err_1;
91
- return __generator(this, function (_a) {
92
- switch (_a.label) {
93
- case 0:
94
- _a.trys.push([0, 2, , 3]);
95
- return [4 /*yield*/, func()];
96
- case 1: return [2 /*return*/, _a.sent()];
97
- case 2:
98
- err_1 = _a.sent();
99
- if (err_1 instanceof Error) {
100
- if (callback) {
101
- throw new types_js_1.ContractError(err_1, callback(err_1));
102
- }
103
- throw new types_js_1.ContractError(err_1);
104
- }
105
- throw err_1;
106
- case 3: return [2 /*return*/];
55
+ async function handleContractError(func, callback) {
56
+ try {
57
+ return await func();
58
+ }
59
+ catch (err) {
60
+ if (err instanceof Error) {
61
+ if (callback) {
62
+ throw new types_js_1.ContractError(err, callback(err));
107
63
  }
108
- });
109
- });
64
+ throw new types_js_1.ContractError(err);
65
+ }
66
+ throw err;
67
+ }
110
68
  }
111
69
  exports.handleContractError = handleContractError;