@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,27 +1,26 @@
1
1
  "use strict";
2
- var _a, _b, _c;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.SUI_MODULE_ERROR_MAP = exports.SUI_ERROR_MATCH_REGEX = exports.SUI_FEE_TABLE_IDS = exports.SUI_CONFIG_IDS = exports.SUI_PROGRAM_IDS = void 0;
5
- var types_js_1 = require("../common/types.js");
4
+ const types_js_1 = require("../common/types.js");
6
5
  // TODO: remove Devnet and Local addresses as they are not deployed, they are just a copy Testnet values
7
- exports.SUI_PROGRAM_IDS = (_a = {},
8
- _a[types_js_1.ICluster.Mainnet] = "0xe456a3a1d4e58e85b4b7175fabe6dae895b983f1379bb8948d6ec2f137b08a7b",
9
- _a[types_js_1.ICluster.Devnet] = "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
10
- _a[types_js_1.ICluster.Testnet] = "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
11
- _a[types_js_1.ICluster.Local] = "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
12
- _a);
13
- exports.SUI_CONFIG_IDS = (_b = {},
14
- _b[types_js_1.ICluster.Mainnet] = "0x6cf6760b64245b8d23ef57c28ddceb6adbd540a23a509fef29b82237da4ab87b",
15
- _b[types_js_1.ICluster.Devnet] = "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
16
- _b[types_js_1.ICluster.Testnet] = "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
17
- _b[types_js_1.ICluster.Local] = "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
18
- _b);
19
- exports.SUI_FEE_TABLE_IDS = (_c = {},
20
- _c[types_js_1.ICluster.Mainnet] = "0xad9b75399632583fb9fcae6b5bcca34e6542ab3bedb630ecbd3f15cb1cc48dbe",
21
- _c[types_js_1.ICluster.Devnet] = "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
22
- _c[types_js_1.ICluster.Testnet] = "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
23
- _c[types_js_1.ICluster.Local] = "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
24
- _c);
6
+ exports.SUI_PROGRAM_IDS = {
7
+ [types_js_1.ICluster.Mainnet]: "0xe456a3a1d4e58e85b4b7175fabe6dae895b983f1379bb8948d6ec2f137b08a7b",
8
+ [types_js_1.ICluster.Devnet]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
9
+ [types_js_1.ICluster.Testnet]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
10
+ [types_js_1.ICluster.Local]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
11
+ };
12
+ exports.SUI_CONFIG_IDS = {
13
+ [types_js_1.ICluster.Mainnet]: "0x6cf6760b64245b8d23ef57c28ddceb6adbd540a23a509fef29b82237da4ab87b",
14
+ [types_js_1.ICluster.Devnet]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
15
+ [types_js_1.ICluster.Testnet]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
16
+ [types_js_1.ICluster.Local]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
17
+ };
18
+ exports.SUI_FEE_TABLE_IDS = {
19
+ [types_js_1.ICluster.Mainnet]: "0xad9b75399632583fb9fcae6b5bcca34e6542ab3bedb630ecbd3f15cb1cc48dbe",
20
+ [types_js_1.ICluster.Devnet]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
21
+ [types_js_1.ICluster.Testnet]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
22
+ [types_js_1.ICluster.Local]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
23
+ };
25
24
  exports.SUI_ERROR_MATCH_REGEX = /MoveAbort\(MoveLocation \{ module: ModuleId \{ address: (\w+), name: Identifier\("([\w_]+)"\) }, function: \d+, instruction: \d+, function_name: Some\("([\w_]+)"\) }, (\d+)\) in command (\d+)/;
26
25
  exports.SUI_MODULE_ERROR_MAP = {
27
26
  protocol: {
@@ -1,56 +1,20 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
- if (ar || !(i in from)) {
32
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
- ar[i] = from[i];
34
- }
35
- }
36
- return to.concat(ar || Array.prototype.slice.call(from));
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
6
  exports.Contract = void 0;
43
- var bignumber_js_1 = __importDefault(require("bignumber.js"));
44
- var contractUtils_js_1 = require("../common/contractUtils.js");
45
- var utils_js_1 = require("../common/utils.js");
46
- var Contract = /** @class */ (function () {
47
- function Contract(stream, tokenId) {
48
- var meta = stream.meta.fields;
49
- var fees = stream.fees.fields;
7
+ const bn_js_1 = __importDefault(require("bn.js"));
8
+ const contractUtils_js_1 = require("../common/contractUtils.js");
9
+ const utils_js_1 = require("../common/utils.js");
10
+ class Contract {
11
+ constructor(stream, tokenId) {
12
+ const meta = stream.meta.fields;
13
+ const fees = stream.fees.fields;
50
14
  this.magic = 0;
51
15
  this.version = parseInt(stream.version);
52
16
  this.createdAt = parseInt(stream.created);
53
- this.withdrawnAmount = (0, bignumber_js_1.default)(stream.withdrawn);
17
+ this.withdrawnAmount = new bn_js_1.default(stream.withdrawn);
54
18
  this.canceledAt = parseInt(stream.canceled_at);
55
19
  this.end = parseInt(stream.end);
56
20
  this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
@@ -62,41 +26,43 @@ var Contract = /** @class */ (function () {
62
26
  this.escrowTokens = "";
63
27
  this.streamflowTreasury = "";
64
28
  this.streamflowTreasuryTokens = "";
65
- this.streamflowFeeTotal = (0, bignumber_js_1.default)(0);
66
- this.streamflowFeeWithdrawn = (0, bignumber_js_1.default)(0);
29
+ this.streamflowFeeTotal = new bn_js_1.default(0);
30
+ this.streamflowFeeWithdrawn = new bn_js_1.default(0);
67
31
  this.streamflowFeePercent = parseInt(fees.streamflow_fee_percentage) / 10000;
68
- this.partnerFeeTotal = (0, bignumber_js_1.default)(0);
69
- this.partnerFeeWithdrawn = (0, bignumber_js_1.default)(0);
32
+ this.partnerFeeTotal = new bn_js_1.default(0);
33
+ this.partnerFeeWithdrawn = new bn_js_1.default(0);
70
34
  this.partnerFeePercent = parseInt(fees.partner_fee_percentage) / 10000;
71
35
  this.partner = stream.partner;
72
36
  this.partnerTokens = "";
73
37
  this.start = parseInt(stream.start);
74
- this.depositedAmount = (0, bignumber_js_1.default)(stream.amount);
38
+ this.depositedAmount = new bn_js_1.default(stream.amount);
75
39
  this.period = parseInt(stream.period);
76
- this.amountPerPeriod = (0, bignumber_js_1.default)(stream.amount_per_period);
40
+ this.amountPerPeriod = new bn_js_1.default(stream.amount_per_period);
77
41
  this.cliff = parseInt(stream.start);
78
- this.cliffAmount = (0, bignumber_js_1.default)(stream.cliff_amount);
42
+ this.cliffAmount = new bn_js_1.default(stream.cliff_amount);
79
43
  this.cancelableBySender = meta.cancelable_by_sender;
80
44
  this.cancelableByRecipient = meta.cancelable_by_recipient;
81
45
  this.automaticWithdrawal = meta.automatic_withdrawal;
82
46
  this.transferableBySender = meta.transferable_by_sender;
83
47
  this.transferableByRecipient = meta.transferable_by_recipient;
84
48
  this.canTopup = meta.can_topup;
85
- this.name = String.fromCharCode.apply(String, __spreadArray([], __read(meta.contract_name), false));
49
+ this.name = String.fromCharCode(...meta.contract_name);
86
50
  this.withdrawalFrequency = parseInt(meta.withdrawal_frequency);
87
51
  this.closed = stream.closed;
88
52
  this.currentPauseStart = parseInt(stream.current_pause_start);
89
- this.pauseCumulative = (0, bignumber_js_1.default)(stream.pause_cumulative);
53
+ this.pauseCumulative = new bn_js_1.default(stream.pause_cumulative);
90
54
  this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
91
- this.fundsUnlockedAtLastRateChange = (0, bignumber_js_1.default)(stream.funds_unlocked_at_last_rate_change);
55
+ this.fundsUnlockedAtLastRateChange = new bn_js_1.default(stream.funds_unlocked_at_last_rate_change);
92
56
  this.type = (0, contractUtils_js_1.buildStreamType)(this);
93
57
  }
94
- Contract.prototype.unlocked = function (currentTimestamp) {
95
- return (0, contractUtils_js_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
96
- };
97
- Contract.prototype.remaining = function (decimals) {
98
- return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
99
- };
100
- return Contract;
101
- }());
58
+ unlocked(currentTimestamp) {
59
+ return (0, contractUtils_js_1.calculateUnlockedAmount)({
60
+ ...this,
61
+ currentTimestamp,
62
+ });
63
+ }
64
+ remaining(decimals) {
65
+ return (0, utils_js_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
66
+ }
67
+ }
102
68
  exports.Contract = Contract;
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractSuiErrorInfo = void 0;
4
- var constants_js_1 = require("./constants.js");
4
+ const constants_js_1 = require("./constants.js");
5
5
  function extractSuiErrorInfo(errorText) {
6
- var error = { text: errorText };
7
- var match = constants_js_1.SUI_ERROR_MATCH_REGEX.exec(errorText);
6
+ const error = { text: errorText };
7
+ const match = constants_js_1.SUI_ERROR_MATCH_REGEX.exec(errorText);
8
8
  if (!match) {
9
9
  return error;
10
10
  }
11
- var moduleName = match[2];
12
- var errorCode = Number(match[4]);
13
- var errorName = constants_js_1.SUI_MODULE_ERROR_MAP[moduleName] ? constants_js_1.SUI_MODULE_ERROR_MAP[moduleName][errorCode] : undefined;
14
- var index = Number(match[5]);
11
+ const moduleName = match[2];
12
+ const errorCode = Number(match[4]);
13
+ const errorName = constants_js_1.SUI_MODULE_ERROR_MAP[moduleName] ? constants_js_1.SUI_MODULE_ERROR_MAP[moduleName][errorCode] : undefined;
14
+ const index = Number(match[5]);
15
15
  if (index) {
16
16
  error.index = index;
17
17
  }
@@ -1,54 +1,7 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
2
  Object.defineProperty(exports, "__esModule", { value: true });
50
3
  exports.SuiWalletWrapper = exports.isSignerKeypair = void 0;
51
- var cryptography_1 = require("@mysten/sui.js/cryptography");
4
+ const cryptography_1 = require("@mysten/sui.js/cryptography");
52
5
  /**
53
6
  * Utility function to check if the transaction initiator is a Wallet object
54
7
  * @param {Keypair | WalletContextState} walletOrKeypair - Wallet or Keypair in question
@@ -61,8 +14,8 @@ function isSignerKeypair(walletOrKeypair) {
61
14
  "export" in walletOrKeypair);
62
15
  }
63
16
  exports.isSignerKeypair = isSignerKeypair;
64
- var SuiWalletWrapper = /** @class */ (function () {
65
- function SuiWalletWrapper(wallet, client) {
17
+ class SuiWalletWrapper {
18
+ constructor(wallet, client) {
66
19
  this.client = client;
67
20
  this.wallet = wallet;
68
21
  if (isSignerKeypair(wallet)) {
@@ -72,19 +25,16 @@ var SuiWalletWrapper = /** @class */ (function () {
72
25
  this.address = wallet.address;
73
26
  }
74
27
  }
75
- SuiWalletWrapper.prototype.signAndExecuteTransactionBlock = function (input) {
76
- return __awaiter(this, void 0, void 0, function () {
77
- return __generator(this, function (_a) {
78
- if (isSignerKeypair(this.wallet)) {
79
- return [2 /*return*/, this.client.signAndExecuteTransactionBlock(__assign(__assign({}, input), {
80
- // @ts-ignore
81
- signer: this.wallet }))];
82
- }
28
+ async signAndExecuteTransactionBlock(input) {
29
+ if (isSignerKeypair(this.wallet)) {
30
+ return this.client.signAndExecuteTransactionBlock({
31
+ ...input,
83
32
  // @ts-ignore
84
- return [2 /*return*/, this.wallet.signAndExecuteTransactionBlock(input)];
33
+ signer: this.wallet,
85
34
  });
86
- });
87
- };
88
- return SuiWalletWrapper;
89
- }());
35
+ }
36
+ // @ts-ignore
37
+ return this.wallet.signAndExecuteTransactionBlock(input);
38
+ }
39
+ }
90
40
  exports.SuiWalletWrapper = SuiWalletWrapper;
@@ -1,4 +1,4 @@
1
- import { BigNumber } from "bignumber.js";
1
+ import { BN } from "bn.js";
2
2
  import { describe, expect, test, beforeEach, vi } from "vitest";
3
3
  import AptosStreamClient from "../../aptos/StreamClient.js";
4
4
  import { ICluster } from "../../common/types.js";
@@ -32,10 +32,10 @@ describe("AptosStreamClient", () => {
32
32
  };
33
33
  const mockRecipient = {
34
34
  recipient: "0xtest",
35
- amount: BigNumber(1000),
35
+ amount: new BN(1000),
36
36
  name: "test name",
37
- cliffAmount: 1,
38
- amountPerPeriod: BigNumber(1),
37
+ cliffAmount: new BN(1),
38
+ amountPerPeriod: new BN(1),
39
39
  };
40
40
  const mockData = {
41
41
  period: 100,
@@ -1,4 +1,4 @@
1
1
  export { default, default as AptosStreamClient } from "./StreamClient.js";
2
- export * from "./utils";
3
- export * from "./types";
4
- export * as constants from "./constants";
2
+ export * from "./utils.js";
3
+ export * from "./types.js";
4
+ export * as constants from "./constants.js";
@@ -1,4 +1,4 @@
1
1
  export { default, default as AptosStreamClient } from "./StreamClient.js";
2
- export * from "./utils";
3
- export * from "./types";
4
- export * as constants from "./constants";
2
+ export * from "./utils.js";
3
+ export * from "./types.js";
4
+ export * as constants from "./constants.js";
@@ -1,7 +1,7 @@
1
1
  import { AptosAccount } from "aptos";
2
2
  import { WalletContextState } from "@manahippo/aptos-wallet-adapter";
3
- import BigNumber from "bignumber.js";
4
- import { Stream, StreamType } from "../common/types.js";
3
+ import BN from "bn.js";
4
+ import { LinearStream, StreamType } from "../common/types.js";
5
5
  export interface ICreateStreamAptosExt {
6
6
  senderWallet: WalletContextState | AptosAccount;
7
7
  }
@@ -59,11 +59,11 @@ export interface ConfigResource {
59
59
  tx_fee: string;
60
60
  withdrawor: string;
61
61
  }
62
- export declare class Contract implements Stream {
62
+ export declare class Contract implements LinearStream {
63
63
  magic: number;
64
64
  version: number;
65
65
  createdAt: number;
66
- withdrawnAmount: BigNumber;
66
+ withdrawnAmount: BN;
67
67
  canceledAt: number;
68
68
  end: number;
69
69
  lastWithdrawnAt: number;
@@ -75,20 +75,20 @@ export declare class Contract implements Stream {
75
75
  escrowTokens: string;
76
76
  streamflowTreasury: string;
77
77
  streamflowTreasuryTokens: string;
78
- streamflowFeeTotal: BigNumber;
79
- streamflowFeeWithdrawn: BigNumber;
78
+ streamflowFeeTotal: BN;
79
+ streamflowFeeWithdrawn: BN;
80
80
  streamflowFeePercent: number;
81
- partnerFeeTotal: BigNumber;
82
- partnerFeeWithdrawn: BigNumber;
81
+ partnerFeeTotal: BN;
82
+ partnerFeeWithdrawn: BN;
83
83
  partnerFeePercent: number;
84
84
  partner: string;
85
85
  partnerTokens: string;
86
86
  start: number;
87
- depositedAmount: BigNumber;
87
+ depositedAmount: BN;
88
88
  period: number;
89
- amountPerPeriod: BigNumber;
89
+ amountPerPeriod: BN;
90
90
  cliff: number;
91
- cliffAmount: BigNumber;
91
+ cliffAmount: BN;
92
92
  cancelableBySender: boolean;
93
93
  cancelableByRecipient: boolean;
94
94
  automaticWithdrawal: boolean;
@@ -99,11 +99,11 @@ export declare class Contract implements Stream {
99
99
  withdrawalFrequency: number;
100
100
  closed: boolean;
101
101
  currentPauseStart: number;
102
- pauseCumulative: BigNumber;
102
+ pauseCumulative: BN;
103
103
  lastRateChangeTime: number;
104
- fundsUnlockedAtLastRateChange: BigNumber;
104
+ fundsUnlockedAtLastRateChange: BN;
105
105
  type: StreamType;
106
106
  constructor(stream: StreamResource, tokenId: string);
107
- unlocked(currentTimestamp: number): BigNumber;
107
+ unlocked(currentTimestamp: number): BN;
108
108
  remaining(decimals: number): number;
109
109
  }
@@ -1,8 +1,8 @@
1
- import BigNumber from "bignumber.js";
1
+ import BN from "bn.js";
2
2
  import { Buffer } from "buffer";
3
3
  import { buildStreamType, calculateUnlockedAmount } from "../common/contractUtils.js";
4
4
  import { normalizeAptosAddress } from "./utils.js";
5
- import { getNumberFromBigNumber } from "../common/utils.js";
5
+ import { getNumberFromBN } from "../common/utils.js";
6
6
  export class Contract {
7
7
  magic;
8
8
  version;
@@ -51,7 +51,7 @@ export class Contract {
51
51
  this.magic = 0;
52
52
  this.version = 0;
53
53
  this.createdAt = parseInt(stream.created);
54
- this.withdrawnAmount = BigNumber(stream.withdrawn);
54
+ this.withdrawnAmount = new BN(stream.withdrawn);
55
55
  this.canceledAt = parseInt(stream.canceled_at);
56
56
  this.end = parseInt(stream.end);
57
57
  this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
@@ -63,20 +63,20 @@ export class Contract {
63
63
  this.escrowTokens = "";
64
64
  this.streamflowTreasury = "";
65
65
  this.streamflowTreasuryTokens = "";
66
- this.streamflowFeeTotal = BigNumber(0);
67
- this.streamflowFeeWithdrawn = BigNumber(0);
66
+ this.streamflowFeeTotal = new BN(0);
67
+ this.streamflowFeeWithdrawn = new BN(0);
68
68
  this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 10000;
69
- this.partnerFeeTotal = BigNumber(0);
70
- this.partnerFeeWithdrawn = BigNumber(0);
69
+ this.partnerFeeTotal = new BN(0);
70
+ this.partnerFeeWithdrawn = new BN(0);
71
71
  this.partnerFeePercent = 0;
72
72
  this.partner = "";
73
73
  this.partnerTokens = "";
74
74
  this.start = parseInt(stream.start);
75
- this.depositedAmount = BigNumber(stream.amount);
75
+ this.depositedAmount = new BN(stream.amount);
76
76
  this.period = parseInt(stream.period);
77
- this.amountPerPeriod = BigNumber(stream.amount_per_period);
77
+ this.amountPerPeriod = new BN(stream.amount_per_period);
78
78
  this.cliff = parseInt(stream.start);
79
- this.cliffAmount = BigNumber(stream.cliff_amount);
79
+ this.cliffAmount = new BN(stream.cliff_amount);
80
80
  this.cancelableBySender = stream.meta.cancelable_by_sender;
81
81
  this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
82
82
  this.automaticWithdrawal = stream.meta.automatic_withdrawal;
@@ -88,9 +88,9 @@ export class Contract {
88
88
  this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
89
89
  this.closed = stream.closed;
90
90
  this.currentPauseStart = parseInt(stream.current_pause_start);
91
- this.pauseCumulative = BigNumber(stream.pause_cumulative);
91
+ this.pauseCumulative = new BN(stream.pause_cumulative);
92
92
  this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
93
- this.fundsUnlockedAtLastRateChange = BigNumber(stream.funds_unlocked_at_last_rate_change);
93
+ this.fundsUnlockedAtLastRateChange = new BN(stream.funds_unlocked_at_last_rate_change);
94
94
  this.type = buildStreamType(this);
95
95
  }
96
96
  unlocked(currentTimestamp) {
@@ -100,6 +100,6 @@ export class Contract {
100
100
  });
101
101
  }
102
102
  remaining(decimals) {
103
- return getNumberFromBigNumber(this.depositedAmount.minus(this.withdrawnAmount), decimals);
103
+ return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
104
104
  }
105
105
  }
@@ -3,10 +3,10 @@ import { Signer } from "ethers";
3
3
  import PQueue from "p-queue";
4
4
  import { BaseStreamClient } from "./BaseStreamClient.js";
5
5
  import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream, IFees, IGetFeesData } from "./types.js";
6
- import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos";
7
- import { EvmStreamClient } from "../evm";
8
- import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana";
9
- import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui";
6
+ import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos/index.js";
7
+ import { EvmStreamClient } from "../evm/index.js";
8
+ import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana/index.js";
9
+ import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui/index.js";
10
10
  export interface SolanaStreamClientOptions {
11
11
  chain: IChain.Solana;
12
12
  clusterUrl: string;
@@ -1,10 +1,10 @@
1
1
  import { BaseStreamClient } from "./BaseStreamClient.js";
2
2
  import { IChain, } from "./types.js";
3
3
  import { handleContractError } from "./utils.js";
4
- import { AptosStreamClient } from "../aptos";
5
- import { EvmStreamClient } from "../evm";
6
- import { SolanaStreamClient } from "../solana";
7
- import { SuiStreamClient } from "../sui";
4
+ import { AptosStreamClient } from "../aptos/index.js";
5
+ import { EvmStreamClient } from "../evm/index.js";
6
+ import { SolanaStreamClient, } from "../solana/index.js";
7
+ import { SuiStreamClient } from "../sui/index.js";
8
8
  import { WITHDRAW_AVAILABLE_AMOUNT } from "./constants.js";
9
9
  /** Generic Stream Client implementation that wrap Chain Client methods and enriches error messages if possible
10
10
  * @property {StreamClientType} - Chain Client implementation
@@ -1,3 +1,4 @@
1
- import BigNumber from "bignumber.js";
1
+ import BN from "bn.js";
2
+ export declare const MAX_SAFE_UNIX_TIME_VALUE = 8640000000000;
2
3
  export declare const BASE_FEE = 1009900;
3
- export declare const WITHDRAW_AVAILABLE_AMOUNT: BigNumber;
4
+ export declare const WITHDRAW_AVAILABLE_AMOUNT: BN;
@@ -1,3 +1,4 @@
1
- import BigNumber from "bignumber.js";
1
+ import BN from "bn.js";
2
+ export const MAX_SAFE_UNIX_TIME_VALUE = 8640000000000;
2
3
  export const BASE_FEE = 1009900; // Buffer to include usual fees when calculating stream amount
3
- export const WITHDRAW_AVAILABLE_AMOUNT = BigNumber("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
4
+ export const WITHDRAW_AVAILABLE_AMOUNT = new BN("18446744073709551615"); // Magical number to withdraw all available amount from a Contract
@@ -1,29 +1,31 @@
1
- import BigNumber from "bignumber.js";
2
- import { StreamType } from "./types.js";
1
+ import BN from "bn.js";
2
+ import { AlignedStream, ICreateAlignedStreamData, ICreateStreamData, Stream, StreamType } from "./types.js";
3
3
  interface ICalculateUnlockedAmount {
4
- depositedAmount: BigNumber;
4
+ depositedAmount: BN;
5
5
  cliff: number;
6
- cliffAmount: BigNumber;
6
+ cliffAmount: BN;
7
7
  end: number;
8
8
  currentTimestamp: number;
9
9
  lastRateChangeTime: number;
10
10
  period: number;
11
- amountPerPeriod: BigNumber;
12
- fundsUnlockedAtLastRateChange: BigNumber;
11
+ amountPerPeriod: BN;
12
+ fundsUnlockedAtLastRateChange: BN;
13
13
  }
14
- export declare const calculateUnlockedAmount: ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }: ICalculateUnlockedAmount) => BigNumber;
14
+ export declare const calculateUnlockedAmount: ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }: ICalculateUnlockedAmount) => BN;
15
15
  export declare const isCliffCloseToDepositedAmount: (streamData: {
16
- depositedAmount: BigNumber;
17
- cliffAmount: BigNumber;
16
+ depositedAmount: BN;
17
+ cliffAmount: BN;
18
18
  }) => boolean;
19
19
  export declare const isPayment: (streamData: {
20
20
  canTopup: boolean;
21
21
  }) => boolean;
22
22
  export declare const isVesting: (streamData: {
23
23
  canTopup: boolean;
24
- depositedAmount: BigNumber;
25
- cliffAmount: BigNumber;
24
+ depositedAmount: BN;
25
+ cliffAmount: BN;
26
26
  }) => boolean;
27
+ export declare const isAligned: (stream: Stream) => stream is AlignedStream;
28
+ export declare const isCreateAlignedStreamData: (obj: ICreateStreamData) => obj is ICreateAlignedStreamData;
27
29
  export declare const isTokenLock: (streamData: {
28
30
  canTopup: boolean;
29
31
  automaticWithdrawal: boolean;
@@ -31,8 +33,8 @@ export declare const isTokenLock: (streamData: {
31
33
  cancelableByRecipient: boolean;
32
34
  transferableBySender: boolean;
33
35
  transferableByRecipient: boolean;
34
- depositedAmount: BigNumber;
35
- cliffAmount: BigNumber;
36
+ depositedAmount: BN;
37
+ cliffAmount: BN;
36
38
  }) => boolean;
37
39
  export declare const buildStreamType: (streamData: {
38
40
  canTopup: boolean;
@@ -41,7 +43,8 @@ export declare const buildStreamType: (streamData: {
41
43
  cancelableByRecipient: boolean;
42
44
  transferableBySender: boolean;
43
45
  transferableByRecipient: boolean;
44
- depositedAmount: BigNumber;
45
- cliffAmount: BigNumber;
46
+ depositedAmount: BN;
47
+ cliffAmount: BN;
46
48
  }) => StreamType;
49
+ export declare const decodeEndTime: (endTime: BN) => number;
47
50
  export {};
@@ -1,20 +1,21 @@
1
- import BigNumber from "bignumber.js";
1
+ import BN from "bn.js";
2
2
  import { StreamType } from "./types.js";
3
+ import { MAX_SAFE_UNIX_TIME_VALUE } from "./constants.js";
3
4
  export const calculateUnlockedAmount = ({ depositedAmount, cliff, cliffAmount, end, currentTimestamp, lastRateChangeTime, period, amountPerPeriod, fundsUnlockedAtLastRateChange, }) => {
4
5
  const deposited = depositedAmount;
5
6
  if (currentTimestamp < cliff)
6
- return BigNumber(0);
7
+ return new BN(0);
7
8
  if (currentTimestamp > end)
8
9
  return deposited;
9
10
  const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
10
11
  const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
11
- const streamed = BigNumber(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
12
- .times(amountPerPeriod)
13
- .plus(savedUnlockedFunds);
12
+ const streamed = new BN(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period))
13
+ .mul(amountPerPeriod)
14
+ .add(savedUnlockedFunds);
14
15
  return streamed.lt(deposited) ? streamed : deposited;
15
16
  };
16
17
  export const isCliffCloseToDepositedAmount = (streamData) => {
17
- return streamData.cliffAmount.gte(streamData.depositedAmount.minus(BigNumber(1)));
18
+ return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN(1)));
18
19
  };
19
20
  export const isPayment = (streamData) => {
20
21
  return streamData.canTopup;
@@ -22,6 +23,12 @@ export const isPayment = (streamData) => {
22
23
  export const isVesting = (streamData) => {
23
24
  return !streamData.canTopup && !isCliffCloseToDepositedAmount(streamData);
24
25
  };
26
+ export const isAligned = (stream) => {
27
+ return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
28
+ };
29
+ export const isCreateAlignedStreamData = (obj) => {
30
+ return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
31
+ };
25
32
  export const isTokenLock = (streamData) => {
26
33
  return (!streamData.canTopup &&
27
34
  !streamData.automaticWithdrawal &&
@@ -40,3 +47,9 @@ export const buildStreamType = (streamData) => {
40
47
  }
41
48
  return StreamType.Payment;
42
49
  };
50
+ export const decodeEndTime = (endTime) => {
51
+ if (endTime.gt(new BN(MAX_SAFE_UNIX_TIME_VALUE))) {
52
+ return MAX_SAFE_UNIX_TIME_VALUE;
53
+ }
54
+ return endTime.toNumber();
55
+ };