@streamflow/stream 9.0.3 → 10.0.0-alpha.p313.3ce4d29

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 (42) hide show
  1. package/README.md +6 -62
  2. package/dist/cjs/index.cjs +421 -3786
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.cts +3 -186
  5. package/dist/cjs/solana/index.cjs +376 -301
  6. package/dist/cjs/solana/index.cjs.map +1 -1
  7. package/dist/cjs/solana/index.d.cts +1134 -17
  8. package/dist/esm/index.d.ts +3 -186
  9. package/dist/esm/index.js +239 -3617
  10. package/dist/esm/index.js.map +1 -1
  11. package/dist/esm/solana/index.d.ts +1134 -17
  12. package/dist/esm/solana/index.js +257 -232
  13. package/dist/esm/solana/index.js.map +1 -1
  14. package/package.json +4 -43
  15. package/dist/cjs/BaseStreamClient-DOyJqO7R.d.cts +0 -551
  16. package/dist/cjs/aptos/index.cjs +0 -456
  17. package/dist/cjs/aptos/index.cjs.map +0 -1
  18. package/dist/cjs/aptos/index.d.cts +0 -14
  19. package/dist/cjs/evm/index.cjs +0 -1915
  20. package/dist/cjs/evm/index.cjs.map +0 -1
  21. package/dist/cjs/evm/index.d.cts +0 -13
  22. package/dist/cjs/index-BMZATAYa.d.cts +0 -213
  23. package/dist/cjs/index-BgGtpOPg.d.cts +0 -850
  24. package/dist/cjs/index-DYIamO0j.d.cts +0 -203
  25. package/dist/cjs/index-Y0HH2ugY.d.cts +0 -136
  26. package/dist/cjs/sui/index.cjs +0 -1021
  27. package/dist/cjs/sui/index.cjs.map +0 -1
  28. package/dist/cjs/sui/index.d.cts +0 -13
  29. package/dist/esm/BaseStreamClient-DOyJqO7R.d.ts +0 -551
  30. package/dist/esm/aptos/index.d.ts +0 -14
  31. package/dist/esm/aptos/index.js +0 -443
  32. package/dist/esm/aptos/index.js.map +0 -1
  33. package/dist/esm/evm/index.d.ts +0 -13
  34. package/dist/esm/evm/index.js +0 -1902
  35. package/dist/esm/evm/index.js.map +0 -1
  36. package/dist/esm/index-D54wSYym.d.ts +0 -203
  37. package/dist/esm/index-Dp5DXxr-.d.ts +0 -850
  38. package/dist/esm/index-DrzqsoIB.d.ts +0 -136
  39. package/dist/esm/index-elpYUBph.d.ts +0 -213
  40. package/dist/esm/sui/index.d.ts +0 -13
  41. package/dist/esm/sui/index.js +0 -1011
  42. package/dist/esm/sui/index.js.map +0 -1
@@ -1,24 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var aptos = require('aptos');
4
- var common = require('@streamflow/common');
5
- var BN7 = require('bn.js');
6
- var buffer = require('buffer');
7
- require('@manahippo/aptos-wallet-adapter');
8
- var ethers = require('ethers');
9
- var ethereumChecksumAddress = require('ethereum-checksum-address');
3
+ var BN3 = require('bn.js');
10
4
  var bs58 = require('bs58');
5
+ var buffer = require('buffer');
11
6
  var splToken = require('@solana/spl-token');
12
7
  var web3_js = require('@solana/web3.js');
13
- var solana = require('@streamflow/common/solana');
8
+ var common = require('@streamflow/common');
14
9
  var borsh = require('borsh');
15
10
  var anchor = require('@coral-xyz/anchor');
16
11
  var BufferLayout = require('@solana/buffer-layout');
17
- var client = require('@mysten/sui/client');
18
- var transactions = require('@mysten/sui/transactions');
19
- var utils = require('@mysten/sui/utils');
20
- var bcs = require('@mysten/sui/bcs');
21
- var cryptography = require('@mysten/sui/cryptography');
22
12
 
23
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
24
14
 
@@ -40,412 +30,13 @@ function _interopNamespace(e) {
40
30
  return Object.freeze(n);
41
31
  }
42
32
 
43
- var BN7__default = /*#__PURE__*/_interopDefault(BN7);
33
+ var BN3__default = /*#__PURE__*/_interopDefault(BN3);
44
34
  var bs58__default = /*#__PURE__*/_interopDefault(bs58);
45
35
  var borsh__namespace = /*#__PURE__*/_interopNamespace(borsh);
46
36
  var BufferLayout__namespace = /*#__PURE__*/_interopNamespace(BufferLayout);
47
37
 
48
- var __create = Object.create;
49
- var __defProp = Object.defineProperty;
50
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
51
- var __getOwnPropNames = Object.getOwnPropertyNames;
52
- var __getProtoOf = Object.getPrototypeOf;
53
- var __hasOwnProp = Object.prototype.hasOwnProperty;
54
- var __commonJS = (cb, mod) => function __require() {
55
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
56
- };
57
- var __export = (target, all) => {
58
- for (var name in all)
59
- __defProp(target, name, { get: all[name], enumerable: true });
60
- };
61
- var __copyProps = (to, from, except, desc) => {
62
- if (from && typeof from === "object" || typeof from === "function") {
63
- for (let key of __getOwnPropNames(from))
64
- if (!__hasOwnProp.call(to, key) && key !== except)
65
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
66
- }
67
- return to;
68
- };
69
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
70
- // If the importer is in node compatibility mode or this is not an ESM
71
- // file that has been converted to a CommonJS file using a Babel-
72
- // compatible transform (i.e. "__esModule" has not been set), then set
73
- // "default" to the CommonJS "module.exports" for node compatibility.
74
- __defProp(target, "default", { value: mod, enumerable: true }) ,
75
- mod
76
- ));
77
-
78
- // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
79
- var require_retry_operation = __commonJS({
80
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module) {
81
- function RetryOperation(timeouts, options) {
82
- if (typeof options === "boolean") {
83
- options = { forever: options };
84
- }
85
- this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
86
- this._timeouts = timeouts;
87
- this._options = options || {};
88
- this._maxRetryTime = options && options.maxRetryTime || Infinity;
89
- this._fn = null;
90
- this._errors = [];
91
- this._attempts = 1;
92
- this._operationTimeout = null;
93
- this._operationTimeoutCb = null;
94
- this._timeout = null;
95
- this._operationStart = null;
96
- this._timer = null;
97
- if (this._options.forever) {
98
- this._cachedTimeouts = this._timeouts.slice(0);
99
- }
100
- }
101
- module.exports = RetryOperation;
102
- RetryOperation.prototype.reset = function() {
103
- this._attempts = 1;
104
- this._timeouts = this._originalTimeouts.slice(0);
105
- };
106
- RetryOperation.prototype.stop = function() {
107
- if (this._timeout) {
108
- clearTimeout(this._timeout);
109
- }
110
- if (this._timer) {
111
- clearTimeout(this._timer);
112
- }
113
- this._timeouts = [];
114
- this._cachedTimeouts = null;
115
- };
116
- RetryOperation.prototype.retry = function(err) {
117
- if (this._timeout) {
118
- clearTimeout(this._timeout);
119
- }
120
- if (!err) {
121
- return false;
122
- }
123
- var currentTime = (/* @__PURE__ */ new Date()).getTime();
124
- if (err && currentTime - this._operationStart >= this._maxRetryTime) {
125
- this._errors.push(err);
126
- this._errors.unshift(new Error("RetryOperation timeout occurred"));
127
- return false;
128
- }
129
- this._errors.push(err);
130
- var timeout = this._timeouts.shift();
131
- if (timeout === void 0) {
132
- if (this._cachedTimeouts) {
133
- this._errors.splice(0, this._errors.length - 1);
134
- timeout = this._cachedTimeouts.slice(-1);
135
- } else {
136
- return false;
137
- }
138
- }
139
- var self = this;
140
- this._timer = setTimeout(function() {
141
- self._attempts++;
142
- if (self._operationTimeoutCb) {
143
- self._timeout = setTimeout(function() {
144
- self._operationTimeoutCb(self._attempts);
145
- }, self._operationTimeout);
146
- if (self._options.unref) {
147
- self._timeout.unref();
148
- }
149
- }
150
- self._fn(self._attempts);
151
- }, timeout);
152
- if (this._options.unref) {
153
- this._timer.unref();
154
- }
155
- return true;
156
- };
157
- RetryOperation.prototype.attempt = function(fn, timeoutOps) {
158
- this._fn = fn;
159
- if (timeoutOps) {
160
- if (timeoutOps.timeout) {
161
- this._operationTimeout = timeoutOps.timeout;
162
- }
163
- if (timeoutOps.cb) {
164
- this._operationTimeoutCb = timeoutOps.cb;
165
- }
166
- }
167
- var self = this;
168
- if (this._operationTimeoutCb) {
169
- this._timeout = setTimeout(function() {
170
- self._operationTimeoutCb();
171
- }, self._operationTimeout);
172
- }
173
- this._operationStart = (/* @__PURE__ */ new Date()).getTime();
174
- this._fn(this._attempts);
175
- };
176
- RetryOperation.prototype.try = function(fn) {
177
- console.log("Using RetryOperation.try() is deprecated");
178
- this.attempt(fn);
179
- };
180
- RetryOperation.prototype.start = function(fn) {
181
- console.log("Using RetryOperation.start() is deprecated");
182
- this.attempt(fn);
183
- };
184
- RetryOperation.prototype.start = RetryOperation.prototype.try;
185
- RetryOperation.prototype.errors = function() {
186
- return this._errors;
187
- };
188
- RetryOperation.prototype.attempts = function() {
189
- return this._attempts;
190
- };
191
- RetryOperation.prototype.mainError = function() {
192
- if (this._errors.length === 0) {
193
- return null;
194
- }
195
- var counts = {};
196
- var mainError = null;
197
- var mainErrorCount = 0;
198
- for (var i = 0; i < this._errors.length; i++) {
199
- var error = this._errors[i];
200
- var message = error.message;
201
- var count = (counts[message] || 0) + 1;
202
- counts[message] = count;
203
- if (count >= mainErrorCount) {
204
- mainError = error;
205
- mainErrorCount = count;
206
- }
207
- }
208
- return mainError;
209
- };
210
- }
211
- });
212
-
213
- // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js
214
- var require_retry = __commonJS({
215
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports) {
216
- var RetryOperation = require_retry_operation();
217
- exports.operation = function(options) {
218
- var timeouts = exports.timeouts(options);
219
- return new RetryOperation(timeouts, {
220
- forever: options && (options.forever || options.retries === Infinity),
221
- unref: options && options.unref,
222
- maxRetryTime: options && options.maxRetryTime
223
- });
224
- };
225
- exports.timeouts = function(options) {
226
- if (options instanceof Array) {
227
- return [].concat(options);
228
- }
229
- var opts = {
230
- retries: 10,
231
- factor: 2,
232
- minTimeout: 1 * 1e3,
233
- maxTimeout: Infinity,
234
- randomize: false
235
- };
236
- for (var key in options) {
237
- opts[key] = options[key];
238
- }
239
- if (opts.minTimeout > opts.maxTimeout) {
240
- throw new Error("minTimeout is greater than maxTimeout");
241
- }
242
- var timeouts = [];
243
- for (var i = 0; i < opts.retries; i++) {
244
- timeouts.push(this.createTimeout(i, opts));
245
- }
246
- if (options && options.forever && !timeouts.length) {
247
- timeouts.push(this.createTimeout(i, opts));
248
- }
249
- timeouts.sort(function(a, b) {
250
- return a - b;
251
- });
252
- return timeouts;
253
- };
254
- exports.createTimeout = function(attempt, opts) {
255
- var random = opts.randomize ? Math.random() + 1 : 1;
256
- var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
257
- timeout = Math.min(timeout, opts.maxTimeout);
258
- return timeout;
259
- };
260
- exports.wrap = function(obj, options, methods) {
261
- if (options instanceof Array) {
262
- methods = options;
263
- options = null;
264
- }
265
- if (!methods) {
266
- methods = [];
267
- for (var key in obj) {
268
- if (typeof obj[key] === "function") {
269
- methods.push(key);
270
- }
271
- }
272
- }
273
- for (var i = 0; i < methods.length; i++) {
274
- var method = methods[i];
275
- var original = obj[method];
276
- obj[method] = function retryWrapper(original2) {
277
- var op = exports.operation(options);
278
- var args = Array.prototype.slice.call(arguments, 1);
279
- var callback = args.pop();
280
- args.push(function(err) {
281
- if (op.retry(err)) {
282
- return;
283
- }
284
- if (err) {
285
- arguments[0] = op.mainError();
286
- }
287
- callback.apply(this, arguments);
288
- });
289
- op.attempt(function() {
290
- original2.apply(obj, args);
291
- });
292
- }.bind(obj, original);
293
- obj[method].options = options;
294
- }
295
- };
296
- }
297
- });
298
-
299
- // ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js
300
- var require_retry2 = __commonJS({
301
- "../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports, module) {
302
- module.exports = require_retry();
303
- }
304
- });
305
-
306
- // aptos/index.ts
307
- var aptos_exports = {};
308
- __export(aptos_exports, {
309
- AptosStreamClient: () => AptosStreamClient,
310
- Contract: () => Contract,
311
- constants: () => constants_exports,
312
- default: () => AptosStreamClient,
313
- extractAptosErrorCode: () => extractAptosErrorCode,
314
- normalizeAptosAddress: () => normalizeAptosAddress
315
- });
316
- var StreamDirection = /* @__PURE__ */ ((StreamDirection2) => {
317
- StreamDirection2["Outgoing"] = "outgoing";
318
- StreamDirection2["Incoming"] = "incoming";
319
- StreamDirection2["All"] = "all";
320
- return StreamDirection2;
321
- })(StreamDirection || {});
322
- var StreamType = /* @__PURE__ */ ((StreamType2) => {
323
- StreamType2["All"] = "all";
324
- StreamType2["Payment"] = "payment";
325
- StreamType2["Vesting"] = "vesting";
326
- StreamType2["Lock"] = "lock";
327
- return StreamType2;
328
- })(StreamType || {});
329
- var ContractErrorCode = /* @__PURE__ */ ((ContractErrorCode2) => {
330
- ContractErrorCode2["ECONTRACT_NOT_INIT"] = "ECONTRACT_NOT_INIT";
331
- ContractErrorCode2["EBAD_AMOUNT"] = "EBAD_AMOUNT";
332
- ContractErrorCode2["ENO_PERMISSIONS"] = "ENO_PERMISSIONS";
333
- ContractErrorCode2["EBADINPUT"] = "EBADINPUT";
334
- ContractErrorCode2["ECLOSED"] = "ECLOSED";
335
- ContractErrorCode2["EBAD_INPUT_AMOUNT_PER_PERIOD"] = "EBAD_INPUT_AMOUNT_PER_PERIOD";
336
- ContractErrorCode2["EBAD_INPUT_PAUSABLE"] = "EBAD_INPUT_PAUSABLE";
337
- ContractErrorCode2["EBAD_INPUT_UPDATE_RATE"] = "EBAD_INPUT_UPDATE_RATE";
338
- ContractErrorCode2["EBAD_INPUT_CLIFF_AMOUNT"] = "EBAD_INPUT_CLIFF_AMOUNT";
339
- ContractErrorCode2["EBAD_INPUT_PERIOD"] = "EBAD_INPUT_PERIOD";
340
- ContractErrorCode2["EBAD_INPUT_START"] = "EBAD_INPUT_START";
341
- ContractErrorCode2["EBAD_INSUFFICIENT_TOKEN_ALLOWANCE"] = "EBAD_INSUFFICIENT_TOKEN_ALLOWANCE";
342
- ContractErrorCode2["EBAD_INSUFFICIENT_WITHDRAWAL_FEES"] = "EBAD_INSUFFICIENT_WITHDRAWAL_FEES";
343
- ContractErrorCode2["EBAD_INSUFFICIENT_AMOUNT"] = "EBAD_INSUFFICIENT_AMOUNT";
344
- ContractErrorCode2["EPAUSED"] = "EPAUSED";
345
- ContractErrorCode2["ENOTPAUSED"] = "ENOTPAUSED";
346
- ContractErrorCode2["ENO_RECIPIENT_COIN_ADDRESS"] = "ENO_RECIPIENT_COIN_ADDRESS";
347
- return ContractErrorCode2;
348
- })(ContractErrorCode || {});
349
- var SolanaContractErrorCode = /* @__PURE__ */ ((SolanaContractErrorCode2) => {
350
- SolanaContractErrorCode2["AccountsNotWritable"] = "AccountsNotWritable";
351
- SolanaContractErrorCode2["InvalidMetadata"] = "InvalidMetadata";
352
- SolanaContractErrorCode2["InvalidMetadataAccount"] = "InvalidMetadataAccount";
353
- SolanaContractErrorCode2["MetadataAccountMismatch"] = "MetadataAccountMismatch";
354
- SolanaContractErrorCode2["InvalidEscrowAccount"] = "InvalidEscrowAccount";
355
- SolanaContractErrorCode2["NotAssociated"] = "NotAssociated";
356
- SolanaContractErrorCode2["MintMismatch"] = "MintMismatch";
357
- SolanaContractErrorCode2["TransferNotAllowed"] = "TransferNotAllowed";
358
- SolanaContractErrorCode2["ContractClosed"] = "ContractClosed";
359
- SolanaContractErrorCode2["InvalidTreasury"] = "InvalidTreasury";
360
- SolanaContractErrorCode2["InvalidTimestamps"] = "InvalidTimestamps";
361
- SolanaContractErrorCode2["InvalidDepositConfiguration"] = "InvalidDepositConfiguration";
362
- SolanaContractErrorCode2["AmountIsZero"] = "AmountIsZero";
363
- SolanaContractErrorCode2["AmountMoreThanAvailable"] = "AmountMoreThanAvailable";
364
- SolanaContractErrorCode2["AmountAvailableIsZero"] = "AmountAvailableIsZero";
365
- SolanaContractErrorCode2["ArithmeticError"] = "ArithmeticError";
366
- SolanaContractErrorCode2["InvalidMetadataSize"] = "InvalidMetadataSize";
367
- SolanaContractErrorCode2["UninitializedMetadata"] = "UninitializedMetadata";
368
- SolanaContractErrorCode2["Unauthorized"] = "Unauthorized";
369
- SolanaContractErrorCode2["SelfTransfer"] = "SelfTransfer";
370
- SolanaContractErrorCode2["AlreadyPaused"] = "AlreadyPaused";
371
- SolanaContractErrorCode2["NotPaused"] = "NotPaused";
372
- SolanaContractErrorCode2["MetadataNotRentExempt"] = "MetadataNotRentExempt";
373
- return SolanaContractErrorCode2;
374
- })(SolanaContractErrorCode || {});
375
- var SolanaAlignedProxyErrorCode = /* @__PURE__ */ ((SolanaAlignedProxyErrorCode2) => {
376
- SolanaAlignedProxyErrorCode2["Unauthorized"] = "Unauthorized";
377
- SolanaAlignedProxyErrorCode2["ArithmeticError"] = "ArithmeticError";
378
- SolanaAlignedProxyErrorCode2["UnsupportedTokenExtensions"] = "UnsupportedTokenExtensions";
379
- SolanaAlignedProxyErrorCode2["PeriodTooShort"] = "PeriodTooShort";
380
- SolanaAlignedProxyErrorCode2["InvalidTickSize"] = "InvalidTickSize";
381
- SolanaAlignedProxyErrorCode2["InvalidPercentageBoundaries"] = "InvalidPercentageBoundaries";
382
- SolanaAlignedProxyErrorCode2["InvalidPriceBoundaries"] = "InvalidPriceBoundaries";
383
- SolanaAlignedProxyErrorCode2["UnsupportedOracle"] = "UnsupportedOracle";
384
- SolanaAlignedProxyErrorCode2["InvalidOracleAccount"] = "InvalidOracleAccount";
385
- SolanaAlignedProxyErrorCode2["InvalidOraclePrice"] = "InvalidOraclePrice";
386
- SolanaAlignedProxyErrorCode2["InvalidStreamMetadata"] = "InvalidStreamMetadata";
387
- SolanaAlignedProxyErrorCode2["AmountAlreadyUpdated"] = "AmountAlreadyUpdated";
388
- SolanaAlignedProxyErrorCode2["AllFundsUnlocked"] = "AllFundsUnlocked";
389
- return SolanaAlignedProxyErrorCode2;
390
- })(SolanaAlignedProxyErrorCode || {});
391
-
392
- // common/BaseStreamClient.ts
393
- var BaseStreamClient = class {
394
- /**
395
- * Returns total fee percent, streamflow fees + partner fees
396
- * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
397
- * @param chainSpecificParams additional parameters required by chain client
398
- * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
399
- */
400
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
401
- async getTotalFee(getFeesData, chainSpecificParams) {
402
- const fees = await this.getFees(getFeesData, chainSpecificParams);
403
- if (fees) {
404
- return fees.partnerFee + fees.streamflowFee;
405
- }
406
- return this.getDefaultStreamflowFee(chainSpecificParams);
407
- }
408
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
409
- extractErrorCode(err) {
410
- return null;
411
- }
412
- };
413
-
414
- // aptos/constants.ts
415
- var constants_exports = {};
416
- __export(constants_exports, {
417
- APTOS_ERROR_MATCH_REGEX: () => APTOS_ERROR_MATCH_REGEX,
418
- APTOS_MODULE_ERROR_MAP: () => APTOS_MODULE_ERROR_MAP,
419
- APTOS_PROGRAM_IDS: () => APTOS_PROGRAM_IDS
420
- });
421
- var APTOS_PROGRAM_IDS = {
422
- [common.ICluster.Mainnet]: "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0",
423
- // TODO: Add a correct programID for Test net
424
- [common.ICluster.Devnet]: "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
425
- [common.ICluster.Testnet]: "0xc6737de143d91b2f99a7e490d4f8348fdfa3bdd1eb8737a27d0455f8a3625688",
426
- [common.ICluster.Local]: "0x9009d93d52576bf9ac6dc6cf10b870610bcb316342fef6eff80662fbbfce51b0"
427
- };
428
- var APTOS_ERROR_MATCH_REGEX = /Move abort in [a-z0-9]+::([^:]+): ([A-Z_]+)/;
429
- var APTOS_MODULE_ERROR_MAP = {
430
- protocol: {
431
- 1: "ECONTRACT_NOT_INIT" /* ECONTRACT_NOT_INIT */,
432
- 2: "EBAD_AMOUNT" /* EBAD_AMOUNT */,
433
- 3: "ENO_PERMISSIONS" /* ENO_PERMISSIONS */,
434
- 4: "EBADINPUT" /* EBADINPUT */,
435
- 5: "ECLOSED" /* ECLOSED */,
436
- 6: "EBAD_INPUT_AMOUNT_PER_PERIOD" /* EBAD_INPUT_AMOUNT_PER_PERIOD */,
437
- 8: "EBAD_INPUT_UPDATE_RATE" /* EBAD_INPUT_UPDATE_RATE */,
438
- 9: "EBAD_INPUT_CLIFF_AMOUNT" /* EBAD_INPUT_CLIFF_AMOUNT */,
439
- 10: "EBAD_INPUT_PERIOD" /* EBAD_INPUT_PERIOD */,
440
- 11: "EBAD_INPUT_START" /* EBAD_INPUT_START */,
441
- 12: "ENO_RECIPIENT_COIN_ADDRESS" /* ENO_RECIPIENT_COIN_ADDRESS */
442
- }
443
- };
38
+ // solana/StreamClient.ts
444
39
  var MAX_SAFE_UNIX_TIME_VALUE = 864e10;
445
- var BASE_FEE = 1009900;
446
- var WITHDRAW_AVAILABLE_AMOUNT = new BN7__default.default("18446744073709551615");
447
-
448
- // common/contractUtils.ts
449
40
  var calculateUnlockedAmount = ({
450
41
  depositedAmount,
451
42
  cliff,
@@ -458,15 +49,15 @@ var calculateUnlockedAmount = ({
458
49
  fundsUnlockedAtLastRateChange
459
50
  }) => {
460
51
  const deposited = depositedAmount;
461
- if (currentTimestamp < cliff) return new BN7__default.default(0);
52
+ if (currentTimestamp < cliff) return new BN3__default.default(0);
462
53
  if (currentTimestamp > end) return deposited;
463
54
  const savedUnlockedFunds = lastRateChangeTime === 0 ? cliffAmount : fundsUnlockedAtLastRateChange;
464
55
  const savedUnlockedFundsTime = lastRateChangeTime === 0 ? cliff : lastRateChangeTime;
465
- const streamed = new BN7__default.default(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period)).mul(amountPerPeriod).add(savedUnlockedFunds);
56
+ const streamed = new BN3__default.default(Math.floor((currentTimestamp - savedUnlockedFundsTime) / period)).mul(amountPerPeriod).add(savedUnlockedFunds);
466
57
  return streamed.lt(deposited) ? streamed : deposited;
467
58
  };
468
59
  var isCliffCloseToDepositedAmount = (streamData) => {
469
- return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN7__default.default(1)));
60
+ return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN3__default.default(1)));
470
61
  };
471
62
  var isPayment = (streamData) => {
472
63
  return streamData.canTopup;
@@ -496,111 +87,113 @@ var buildStreamType = (streamData) => {
496
87
  return "payment" /* Payment */;
497
88
  };
498
89
  var decodeEndTime = (endTime) => {
499
- if (endTime.gt(new BN7__default.default(MAX_SAFE_UNIX_TIME_VALUE))) {
90
+ if (endTime.gt(new BN3__default.default(MAX_SAFE_UNIX_TIME_VALUE))) {
500
91
  return MAX_SAFE_UNIX_TIME_VALUE;
501
92
  }
502
93
  return endTime.toNumber();
503
94
  };
504
-
505
- // aptos/utils.ts
506
- function extractAptosErrorCode(errorText) {
507
- const match = APTOS_ERROR_MATCH_REGEX.exec(errorText);
508
- return match?.[2] ?? null;
509
- }
510
- function isAddressSpecial(address) {
511
- if (address.length === 3) {
512
- return true;
513
- }
514
- return false;
515
- }
516
- function normalizeAptosAddress(address) {
517
- if (isAddressSpecial(address)) {
518
- return address;
519
- }
520
- const length = address.length;
521
- if (length === 66 || length < 3) {
522
- return address;
523
- }
524
- const missingZeros = 66 - length;
525
- return address.slice(0, 2) + "0".repeat(missingZeros) + address.slice(2);
526
- }
527
- var FEE_PRECISION = 4;
528
- var FEE_NORMALIZER = 10 ** FEE_PRECISION;
529
- var FEE_MULTIPLIER = new BN7__default.default(10 ** 6);
530
- var getBN = (value, decimals) => {
531
- const decimalPart = value - Math.trunc(value);
532
- const integerPart = new BN7__default.default(Math.trunc(value));
533
- const decimalE = new BN7__default.default(decimalPart * 1e9);
534
- const sum = integerPart.mul(new BN7__default.default(1e9)).add(decimalE);
535
- const resultE = sum.mul(new BN7__default.default(10).pow(new BN7__default.default(decimals)));
536
- return resultE.div(new BN7__default.default(1e9));
537
- };
538
- var getNumberFromBN = (value, decimals) => value.gt(new BN7__default.default(2 ** 53 - 1)) ? value.div(new BN7__default.default(10 ** decimals)).toNumber() : value.toNumber() / 10 ** decimals;
539
- var calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
540
- const totalFeeNormalized = new BN7__default.default(totalFee * FEE_NORMALIZER);
541
- return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
542
- };
543
- async function handleContractError(func, callback) {
544
- try {
545
- return await func();
546
- } catch (err) {
547
- if (err instanceof Error) {
548
- if (callback) {
549
- throw new common.ContractError(err, callback(err));
550
- }
551
- throw new common.ContractError(err);
552
- }
553
- throw err;
554
- }
555
- }
556
-
557
- // aptos/types.ts
95
+ var ALIGNED_PRECISION_FACTOR_POW = 9;
96
+ var StreamDirection = /* @__PURE__ */ ((StreamDirection2) => {
97
+ StreamDirection2["Outgoing"] = "outgoing";
98
+ StreamDirection2["Incoming"] = "incoming";
99
+ StreamDirection2["All"] = "all";
100
+ return StreamDirection2;
101
+ })(StreamDirection || {});
102
+ var StreamType = /* @__PURE__ */ ((StreamType2) => {
103
+ StreamType2["All"] = "all";
104
+ StreamType2["Payment"] = "payment";
105
+ StreamType2["Vesting"] = "vesting";
106
+ StreamType2["Lock"] = "lock";
107
+ return StreamType2;
108
+ })(StreamType || {});
109
+ var ContractErrorCode = /* @__PURE__ */ ((ContractErrorCode2) => {
110
+ ContractErrorCode2["AccountsNotWritable"] = "AccountsNotWritable";
111
+ ContractErrorCode2["InvalidMetadata"] = "InvalidMetadata";
112
+ ContractErrorCode2["InvalidMetadataAccount"] = "InvalidMetadataAccount";
113
+ ContractErrorCode2["MetadataAccountMismatch"] = "MetadataAccountMismatch";
114
+ ContractErrorCode2["InvalidEscrowAccount"] = "InvalidEscrowAccount";
115
+ ContractErrorCode2["NotAssociated"] = "NotAssociated";
116
+ ContractErrorCode2["MintMismatch"] = "MintMismatch";
117
+ ContractErrorCode2["TransferNotAllowed"] = "TransferNotAllowed";
118
+ ContractErrorCode2["ContractClosed"] = "ContractClosed";
119
+ ContractErrorCode2["InvalidTreasury"] = "InvalidTreasury";
120
+ ContractErrorCode2["InvalidTimestamps"] = "InvalidTimestamps";
121
+ ContractErrorCode2["InvalidDepositConfiguration"] = "InvalidDepositConfiguration";
122
+ ContractErrorCode2["AmountIsZero"] = "AmountIsZero";
123
+ ContractErrorCode2["AmountMoreThanAvailable"] = "AmountMoreThanAvailable";
124
+ ContractErrorCode2["AmountAvailableIsZero"] = "AmountAvailableIsZero";
125
+ ContractErrorCode2["ArithmeticError"] = "ArithmeticError";
126
+ ContractErrorCode2["InvalidMetadataSize"] = "InvalidMetadataSize";
127
+ ContractErrorCode2["UninitializedMetadata"] = "UninitializedMetadata";
128
+ ContractErrorCode2["Unauthorized"] = "Unauthorized";
129
+ ContractErrorCode2["SelfTransfer"] = "SelfTransfer";
130
+ ContractErrorCode2["AlreadyPaused"] = "AlreadyPaused";
131
+ ContractErrorCode2["NotPaused"] = "NotPaused";
132
+ ContractErrorCode2["MetadataNotRentExempt"] = "MetadataNotRentExempt";
133
+ return ContractErrorCode2;
134
+ })(ContractErrorCode || {});
135
+ var AlignedProxyErrorCode = /* @__PURE__ */ ((AlignedProxyErrorCode2) => {
136
+ AlignedProxyErrorCode2["Unauthorized"] = "Unauthorized";
137
+ AlignedProxyErrorCode2["ArithmeticError"] = "ArithmeticError";
138
+ AlignedProxyErrorCode2["UnsupportedTokenExtensions"] = "UnsupportedTokenExtensions";
139
+ AlignedProxyErrorCode2["PeriodTooShort"] = "PeriodTooShort";
140
+ AlignedProxyErrorCode2["InvalidTickSize"] = "InvalidTickSize";
141
+ AlignedProxyErrorCode2["InvalidPercentageBoundaries"] = "InvalidPercentageBoundaries";
142
+ AlignedProxyErrorCode2["InvalidPriceBoundaries"] = "InvalidPriceBoundaries";
143
+ AlignedProxyErrorCode2["UnsupportedOracle"] = "UnsupportedOracle";
144
+ AlignedProxyErrorCode2["InvalidOracleAccount"] = "InvalidOracleAccount";
145
+ AlignedProxyErrorCode2["InvalidOraclePrice"] = "InvalidOraclePrice";
146
+ AlignedProxyErrorCode2["InvalidStreamMetadata"] = "InvalidStreamMetadata";
147
+ AlignedProxyErrorCode2["AmountAlreadyUpdated"] = "AmountAlreadyUpdated";
148
+ AlignedProxyErrorCode2["AllFundsUnlocked"] = "AllFundsUnlocked";
149
+ return AlignedProxyErrorCode2;
150
+ })(AlignedProxyErrorCode || {});
558
151
  var Contract = class {
559
- constructor(stream, tokenId) {
560
- this.magic = 0;
561
- this.version = 0;
562
- this.createdAt = parseInt(stream.created);
563
- this.withdrawnAmount = new BN7__default.default(stream.withdrawn);
564
- this.canceledAt = parseInt(stream.canceled_at);
565
- this.end = parseInt(stream.end);
566
- this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
567
- this.sender = normalizeAptosAddress(stream.sender);
568
- this.senderTokens = normalizeAptosAddress(stream.sender);
569
- this.recipient = normalizeAptosAddress(stream.recipient);
570
- this.recipientTokens = normalizeAptosAddress(stream.recipient);
571
- this.mint = tokenId;
572
- this.escrowTokens = "";
573
- this.streamflowTreasury = "";
574
- this.streamflowTreasuryTokens = "";
575
- this.streamflowFeeTotal = new BN7__default.default(0);
576
- this.streamflowFeeWithdrawn = new BN7__default.default(0);
577
- this.streamflowFeePercent = parseInt(stream.fees.streamflow_fee_percentage) / 1e4;
578
- this.partnerFeeTotal = new BN7__default.default(0);
579
- this.partnerFeeWithdrawn = new BN7__default.default(0);
580
- this.partnerFeePercent = 0;
581
- this.partner = "";
582
- this.partnerTokens = "";
583
- this.start = parseInt(stream.start);
584
- this.depositedAmount = new BN7__default.default(stream.amount);
585
- this.period = parseInt(stream.period);
586
- this.amountPerPeriod = new BN7__default.default(stream.amount_per_period);
587
- this.cliff = parseInt(stream.start);
588
- this.cliffAmount = new BN7__default.default(stream.cliff_amount);
589
- this.cancelableBySender = stream.meta.cancelable_by_sender;
590
- this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
591
- this.automaticWithdrawal = stream.meta.automatic_withdrawal;
592
- this.transferableBySender = stream.meta.transferable_by_sender;
593
- this.transferableByRecipient = stream.meta.transferable_by_recipient;
594
- this.canTopup = stream.meta.can_topup;
595
- const name = stream.meta.contract_name.replace("0x", "");
596
- this.name = buffer.Buffer.from(name, "hex").toString("utf8");
597
- this.withdrawalFrequency = parseInt(stream.meta.withdrawal_frequency);
152
+ constructor(stream) {
153
+ this.magic = stream.magic.toNumber();
154
+ this.version = stream.version.toNumber();
155
+ this.createdAt = stream.createdAt.toNumber();
156
+ this.withdrawnAmount = stream.withdrawnAmount;
157
+ this.canceledAt = stream.canceledAt.toNumber();
158
+ this.end = decodeEndTime(stream.end);
159
+ this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
160
+ this.sender = stream.sender.toBase58();
161
+ this.senderTokens = stream.senderTokens.toBase58();
162
+ this.recipient = stream.recipient.toBase58();
163
+ this.recipientTokens = stream.recipientTokens.toBase58();
164
+ this.mint = stream.mint.toBase58();
165
+ this.escrowTokens = stream.escrowTokens.toBase58();
166
+ this.streamflowTreasury = stream.streamflowTreasury.toBase58();
167
+ this.streamflowTreasuryTokens = stream.streamflowTreasuryTokens.toBase58();
168
+ this.streamflowFeeTotal = stream.streamflowFeeTotal;
169
+ this.streamflowFeeWithdrawn = stream.streamflowFeeWithdrawn;
170
+ this.streamflowFeePercent = stream.streamflowFeePercent;
171
+ this.partnerFeeTotal = stream.partnerFeeTotal;
172
+ this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
173
+ this.partnerFeePercent = stream.partnerFeePercent;
174
+ this.partner = stream.partner.toBase58();
175
+ this.partnerTokens = stream.partnerTokens?.toBase58();
176
+ this.start = stream.start.toNumber();
177
+ this.depositedAmount = stream.depositedAmount;
178
+ this.period = stream.period.toNumber();
179
+ this.amountPerPeriod = stream.amountPerPeriod;
180
+ this.cliff = stream.cliff.toNumber();
181
+ this.cliffAmount = stream.cliffAmount;
182
+ this.cancelableBySender = stream.cancelableBySender;
183
+ this.cancelableByRecipient = stream.cancelableByRecipient;
184
+ this.automaticWithdrawal = stream.automaticWithdrawal;
185
+ this.transferableBySender = stream.transferableBySender;
186
+ this.transferableByRecipient = stream.transferableByRecipient;
187
+ this.canTopup = stream.canTopup;
188
+ this.name = stream.name;
189
+ this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
598
190
  this.closed = stream.closed;
599
- this.currentPauseStart = parseInt(stream.current_pause_start);
600
- this.pauseCumulative = new BN7__default.default(stream.pause_cumulative);
601
- this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
602
- this.fundsUnlockedAtLastRateChange = new BN7__default.default(stream.funds_unlocked_at_last_rate_change);
191
+ this.currentPauseStart = stream.currentPauseStart.toNumber();
192
+ this.pauseCumulative = stream.pauseCumulative;
193
+ this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
194
+ this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
603
195
  this.type = buildStreamType(this);
196
+ this.isAligned = false;
604
197
  }
605
198
  unlocked(currentTimestamp) {
606
199
  return calculateUnlockedAmount({
@@ -609,2194 +202,81 @@ var Contract = class {
609
202
  });
610
203
  }
611
204
  remaining(decimals) {
612
- return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
205
+ return common.getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
613
206
  }
614
207
  };
615
- var AptosWalletWrapper = class {
616
- constructor(wallet, client) {
617
- this.client = client;
618
- this.wallet = wallet;
619
- if (wallet instanceof aptos.AptosAccount) {
620
- this.address = wallet.address();
621
- } else {
622
- this.address = wallet.account.address;
623
- }
624
- }
625
- async signAndSubmitTransaction(input) {
626
- if (this.wallet instanceof aptos.AptosAccount) {
627
- const builder = new aptos.TransactionBuilderRemoteABI(this.client, {
628
- sender: this.address
629
- });
630
- const rawTxn = await builder.build(input.function, input.type_arguments, input.arguments);
631
- const res = await this.client.simulateTransaction(this.wallet, rawTxn);
632
- if (!res[0].success) {
633
- throw new Error(`Transaction Simulation failed: ${JSON.stringify(res)}`);
634
- }
635
- const signedTx = await this.client.signTransaction(this.wallet, rawTxn);
636
- const tx = await this.client.submitSignedBCSTransaction(signedTx);
637
- await this.client.waitForTransaction(tx.hash);
638
- return tx.hash;
639
- }
640
- return (await this.wallet.signAndSubmitTransaction(input)).hash;
208
+ var AlignedContract = class extends Contract {
209
+ constructor(stream, alignedProxy) {
210
+ super(stream);
211
+ this.minPrice = common.getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
212
+ this.maxPrice = common.getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
213
+ this.minPercentage = common.getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
214
+ this.maxPercentage = common.getNumberFromBN(alignedProxy.maxPercentage, ALIGNED_PRECISION_FACTOR_POW);
215
+ this.oracleType = Object.keys(alignedProxy.priceOracleType).find((key) => !!key) || "none";
216
+ this.tickSize = alignedProxy.tickSize.toNumber();
217
+ this.priceOracle = this.oracleType === "none" ? void 0 : alignedProxy.priceOracle.toBase58();
218
+ this.sender = alignedProxy.sender.toBase58();
219
+ this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
220
+ this.proxyAddress = stream.sender.toBase58();
221
+ this.initialAmountPerPeriod = alignedProxy.initialAmountPerPeriod;
222
+ this.initialPrice = common.getNumberFromBN(alignedProxy.initialPrice, ALIGNED_PRECISION_FACTOR_POW);
223
+ this.lastPrice = common.getNumberFromBN(alignedProxy.lastPrice, ALIGNED_PRECISION_FACTOR_POW);
224
+ this.lastAmountUpdateTime = alignedProxy.lastAmountUpdateTime.toNumber();
225
+ this.initialNetAmount = alignedProxy.initialNetAmount;
226
+ this.expiryTime = alignedProxy.expiryTime.toNumber();
227
+ this.expiryPercentage = common.getNumberFromBN(alignedProxy.expiryPercentage, ALIGNED_PRECISION_FACTOR_POW);
228
+ this.floorPrice = common.getNumberFromBN(alignedProxy.floorPrice, ALIGNED_PRECISION_FACTOR_POW);
229
+ this.type = buildStreamType(this);
230
+ this.isAligned = true;
641
231
  }
642
232
  };
643
-
644
- // aptos/StreamClient.ts
645
- var AptosStreamClient = class extends BaseStreamClient {
646
- constructor(clusterUrl, cluster = common.ICluster.Mainnet, maxGas = "10000", programId) {
647
- super();
648
- this.programId = programId ? programId : APTOS_PROGRAM_IDS[cluster];
649
- this.maxGas = maxGas;
650
- this.client = new aptos.AptosClient(clusterUrl);
651
- }
652
- /**
653
- * Creates a new stream/vesting contract.
654
- */
655
- async create(streamData, { senderWallet }) {
656
- const wallet = new AptosWalletWrapper(senderWallet, this.client);
657
- const result = this.generateMultiPayloads(
658
- {
659
- ...streamData,
660
- recipients: [{ ...streamData }]
661
- },
662
- wallet
663
- )[0];
664
- if (!result) {
665
- throw new Error("Failed to generate payload");
666
- }
667
- const [metadataId, payload] = result;
668
- const hash = await wallet.signAndSubmitTransaction(payload);
669
- return { ixs: [payload], txId: hash, metadataId };
670
- }
671
- /**
672
- * Creates multiple stream/vesting contracts.
673
- */
674
- async createMultiple(multipleStreamData, { senderWallet }) {
675
- const wallet = new AptosWalletWrapper(senderWallet, this.client);
676
- const payloads = this.generateMultiPayloads(multipleStreamData, wallet);
677
- const txs = [];
678
- const metadatas = [];
679
- const metadataToRecipient = {};
680
- const errors = [];
681
- for (let i = 0; i < payloads.length; i++) {
682
- const [metadataId, payload] = payloads[i];
683
- const recipient = multipleStreamData.recipients[i];
684
- try {
685
- const hash = await wallet.signAndSubmitTransaction(payload);
686
- txs.push(hash);
687
- } catch (e) {
688
- errors.push({
689
- error: e?.toString() ?? "Unknown error!",
690
- recipient: recipient.recipient
691
- });
692
- } finally {
693
- metadatas.push(metadataId);
694
- metadataToRecipient[metadataId] = recipient;
695
- }
696
- }
697
- return {
698
- txs,
699
- metadatas,
700
- metadataToRecipient,
701
- errors
702
- };
703
- }
704
- /**
705
- * Attempts withdrawing from the specified stream.
706
- */
707
- async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
708
- const payload = {
709
- type: "withdraw",
710
- function: `${this.programId}::protocol::withdraw`,
711
- type_arguments: [tokenId],
712
- arguments: [id, amount.toString()]
713
- };
714
- const wallet = new AptosWalletWrapper(senderWallet, this.client);
715
- const hash = await wallet.signAndSubmitTransaction(payload);
716
- return { ixs: [payload], txId: hash };
717
- }
718
- /**
719
- * Attempts canceling the specified stream.
720
- */
721
- async cancel(cancelData, { senderWallet, tokenId }) {
722
- const payload = {
723
- type: "cancel",
724
- function: `${this.programId}::protocol::cancel`,
725
- type_arguments: [tokenId],
726
- arguments: [cancelData.id]
727
- };
728
- const wallet = new AptosWalletWrapper(senderWallet, this.client);
729
- const hash = await wallet.signAndSubmitTransaction(payload);
730
- return { ixs: [payload], txId: hash };
731
- }
732
- /**
733
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
734
- */
735
- async transfer(transferData, { senderWallet, tokenId }) {
736
- const payload = {
737
- type: "transfer",
738
- function: `${this.programId}::protocol::transfer`,
739
- type_arguments: [tokenId],
740
- arguments: [transferData.id, transferData.newRecipient]
741
- };
742
- const wallet = new AptosWalletWrapper(senderWallet, this.client);
743
- const hash = await wallet.signAndSubmitTransaction(payload);
744
- return { ixs: [payload], txId: hash };
745
- }
746
- /**
747
- * Tops up stream account with specified amount.
748
- */
749
- async topup(topupData, { senderWallet, tokenId }) {
750
- const payload = {
751
- type: "topup",
752
- function: `${this.programId}::protocol::topup`,
753
- type_arguments: [tokenId],
754
- arguments: [topupData.id, topupData.amount.toString()]
755
- };
756
- const wallet = new AptosWalletWrapper(senderWallet, this.client);
757
- const hash = await wallet.signAndSubmitTransaction(payload);
758
- return { ixs: [payload], txId: hash };
759
- }
760
- /**
761
- * Fetch stream data by its id (address).
762
- */
763
- async getOne({ id }) {
764
- const contractResources = await this.client.getAccountResources(id);
765
- const contract = contractResources.find((r) => r.type.includes("protocol::Contract"));
766
- if (!contract) {
767
- throw new Error(`Contract with id ${id} could not be found!`);
768
- }
769
- const tokenIdMatch = contract.type.match(/0x[0-9a-f]+::protocol::Contract<(.*)>/);
770
- const tokenId = tokenIdMatch?.[1] ?? "";
771
- const { data } = contract;
772
- return new Contract(data, tokenId);
773
- }
774
- async get() {
775
- throw new Error("Get all method is not supported for Aptos chain!");
776
- }
777
- /**
778
- * Attempts updating the stream auto withdrawal params and amount per period
779
- */
780
- async update(updateData, { senderWallet, tokenId }) {
781
- const wallet = new AptosWalletWrapper(senderWallet, this.client);
782
- const payload = {
783
- type: "update",
784
- function: `${this.programId}::protocol::update`,
785
- type_arguments: [tokenId],
786
- arguments: [
787
- updateData.id,
788
- updateData.enableAutomaticWithdrawal ? [true] : [],
789
- updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
790
- updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : []
791
- ]
792
- };
793
- const hash = await wallet.signAndSubmitTransaction(payload);
794
- return { ixs: [payload], txId: hash };
795
- }
796
- async getFees({ address }) {
797
- const resource = await this.client.getAccountResource(this.programId, `${this.programId}::fees::FeeTable`);
798
- const data = resource.data;
799
- const value = await this.client.getTableItem(data.values.handle, {
800
- key_type: "address",
801
- key: address,
802
- value_type: "u64"
803
- });
804
- if (!value) {
805
- return null;
806
- }
807
- return { streamflowFee: Number(value) / 100, partnerFee: 0 };
808
- }
809
- async getDefaultStreamflowFee() {
810
- const resource = await this.client.getAccountResource(this.programId, `${this.programId}::admin::ConfigV2`);
811
- return Number(resource.data.streamflow_fees) / 100;
812
- }
813
- extractErrorCode(err) {
814
- return extractAptosErrorCode(err.toString() ?? "Unknown error!");
815
- }
816
- /**
817
- * Returns StreamClient protocol program ID.
818
- */
819
- getProgramId() {
820
- return this.programId;
821
- }
822
- getMaxGas() {
823
- return { max_gas_amount: this.maxGas };
824
- }
825
- // Utility function to prepare transaction payloads for multiple recipients.
826
- generateMultiPayloads(multipleStreamData, wallet) {
827
- return multipleStreamData.recipients.map((recipient) => {
828
- const acc = new aptos.AptosAccount();
829
- const seeds = acc.address();
830
- const encoder = new TextEncoder();
831
- const actualSeeds = encoder.encode(seeds.hex());
832
- const metadataId = aptos.AptosAccount.getResourceAccountAddress(wallet.address, actualSeeds);
833
- return [
834
- metadataId.toString(),
835
- {
836
- type: "create",
837
- function: `${this.programId}::protocol::create`,
838
- type_arguments: [multipleStreamData.tokenId],
839
- arguments: [
840
- seeds.hex(),
841
- recipient.amount.toString(),
842
- multipleStreamData.period,
843
- recipient.amountPerPeriod.toString(),
844
- multipleStreamData.start,
845
- recipient.cliffAmount.toString(),
846
- multipleStreamData.cancelableBySender,
847
- multipleStreamData.cancelableByRecipient,
848
- multipleStreamData.transferableBySender,
849
- multipleStreamData.transferableByRecipient,
850
- multipleStreamData.canTopup,
851
- multipleStreamData.canPause || false,
852
- multipleStreamData.canUpdateRate || false,
853
- multipleStreamData.automaticWithdrawal || false,
854
- multipleStreamData.withdrawalFrequency || 0,
855
- recipient.name,
856
- recipient.recipient
857
- ]
858
- }
859
- ];
860
- });
861
- }
862
- };
863
-
864
- // evm/index.ts
865
- var evm_exports = {};
866
- __export(evm_exports, {
867
- EvmContract: () => EvmContract,
868
- EvmStreamClient: () => EvmStreamClient,
869
- constants: () => constants_exports2,
870
- default: () => EvmStreamClient,
871
- ercAbi: () => ercAbi_default,
872
- extractEvmErrorCode: () => extractEvmErrorCode
873
- });
874
-
875
- // evm/constants.ts
876
- var constants_exports2 = {};
877
- __export(constants_exports2, {
878
- BNB_PROGRAM_IDS: () => BNB_PROGRAM_IDS,
879
- ETHEREUM_PROGRAM_IDS: () => ETHEREUM_PROGRAM_IDS,
880
- EVM_ERROR_MAP: () => EVM_ERROR_MAP,
881
- EVM_ERROR_MATCH_REGEX: () => EVM_ERROR_MATCH_REGEX,
882
- POLYGON_PROGRAM_IDS: () => POLYGON_PROGRAM_IDS
883
- });
884
- var ETHEREUM_PROGRAM_IDS = {
885
- [common.ICluster.Mainnet]: "0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2",
886
- [common.ICluster.Devnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
887
- [common.ICluster.Testnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
888
- [common.ICluster.Local]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d"
889
- };
890
- var BNB_PROGRAM_IDS = {
891
- [common.ICluster.Mainnet]: "0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2",
892
- [common.ICluster.Devnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
893
- [common.ICluster.Testnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
894
- [common.ICluster.Local]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d"
895
- };
896
- var POLYGON_PROGRAM_IDS = {
897
- [common.ICluster.Mainnet]: "0x94d4646Bd307Bf91CB1893BC64d976BF9E60D9B2",
898
- [common.ICluster.Devnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
899
- [common.ICluster.Testnet]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d",
900
- [common.ICluster.Local]: "0x5Db7a43D20De64E3a3BC765334a477026FD13E7d"
901
- };
902
- var EVM_ERROR_MATCH_REGEX = /execution reverted: ([A-Z_]+)/;
903
- var EVM_ERROR_MAP = {
904
- ECONTRACT_NOT_INIT: "ECONTRACT_NOT_INIT" /* ECONTRACT_NOT_INIT */,
905
- EBAD_AMOUNT: "EBAD_AMOUNT" /* EBAD_AMOUNT */,
906
- ENO_PERMISSIONS: "ENO_PERMISSIONS" /* ENO_PERMISSIONS */,
907
- EBADINPUT: "EBADINPUT" /* EBADINPUT */,
908
- ECLOSED: "ECLOSED" /* ECLOSED */,
909
- EBAD_INPUT_AMOUNT_PER_PERIOD: "EBAD_INPUT_AMOUNT_PER_PERIOD" /* EBAD_INPUT_AMOUNT_PER_PERIOD */,
910
- EBAD_INPUT_PAUSABLE: "EBAD_INPUT_PAUSABLE" /* EBAD_INPUT_PAUSABLE */,
911
- EBAD_INPUT_UPDATE_RATE: "EBAD_INPUT_UPDATE_RATE" /* EBAD_INPUT_UPDATE_RATE */,
912
- EBAD_INPUT_CLIFF_AMOUNT: "EBAD_INPUT_CLIFF_AMOUNT" /* EBAD_INPUT_CLIFF_AMOUNT */,
913
- EBAD_INPUT_PERIOD: "EBAD_INPUT_PERIOD" /* EBAD_INPUT_PERIOD */,
914
- EBAD_INPUT_START: "EBAD_INPUT_START" /* EBAD_INPUT_START */,
915
- EBAD_INSUFFICIENT_TOKEN_ALLOWANCE: "EBAD_INSUFFICIENT_TOKEN_ALLOWANCE" /* EBAD_INSUFFICIENT_TOKEN_ALLOWANCE */,
916
- EBAD_INSUFFICIENT_WITHDRAWAL_FEES: "EBAD_INSUFFICIENT_WITHDRAWAL_FEES" /* EBAD_INSUFFICIENT_WITHDRAWAL_FEES */
917
- };
918
-
919
- // evm/abi.ts
920
- var abi_default = [
921
- {
922
- anonymous: false,
923
- inputs: [
924
- {
925
- indexed: false,
926
- internalType: "address",
927
- name: "",
928
- type: "address"
929
- }
930
- ],
931
- name: "ContractCreated",
932
- type: "event"
933
- },
934
- {
935
- inputs: [
936
- {
937
- internalType: "address",
938
- name: "_stream_id",
939
- type: "address"
940
- }
941
- ],
942
- name: "cancel",
943
- outputs: [],
944
- stateMutability: "nonpayable",
945
- type: "function"
946
- },
947
- {
948
- inputs: [
949
- {
950
- internalType: "uint256",
951
- name: "_new_fees",
952
- type: "uint256"
953
- }
954
- ],
955
- name: "changeStreamflowFees",
956
- outputs: [],
957
- stateMutability: "nonpayable",
958
- type: "function"
959
- },
960
- {
961
- inputs: [
962
- {
963
- internalType: "address payable",
964
- name: "_new_treasury",
965
- type: "address"
966
- }
967
- ],
968
- name: "changeTreasury",
969
- outputs: [],
970
- stateMutability: "nonpayable",
971
- type: "function"
972
- },
973
- {
974
- inputs: [
975
- {
976
- internalType: "uint256",
977
- name: "_new_fee",
978
- type: "uint256"
979
- }
980
- ],
981
- name: "changeTxFee",
982
- outputs: [],
983
- stateMutability: "nonpayable",
984
- type: "function"
985
- },
986
- {
987
- inputs: [
988
- {
989
- internalType: "address payable",
990
- name: "_new_withdawor",
991
- type: "address"
992
- }
993
- ],
994
- name: "changeWithdrawor",
995
- outputs: [],
996
- stateMutability: "nonpayable",
997
- type: "function"
998
- },
999
- {
1000
- inputs: [],
1001
- name: "config",
1002
- outputs: [
1003
- {
1004
- internalType: "address",
1005
- name: "admin",
1006
- type: "address"
1007
- },
1008
- {
1009
- internalType: "uint256",
1010
- name: "streamflow_fees",
1011
- type: "uint256"
1012
- },
1013
- {
1014
- internalType: "address payable",
1015
- name: "treasury",
1016
- type: "address"
1017
- },
1018
- {
1019
- internalType: "address payable",
1020
- name: "withdrawor",
1021
- type: "address"
1022
- },
1023
- {
1024
- internalType: "uint256",
1025
- name: "tx_fee",
1026
- type: "uint256"
1027
- }
1028
- ],
1029
- stateMutability: "view",
1030
- type: "function"
1031
- },
1032
- {
1033
- inputs: [
1034
- {
1035
- internalType: "contract IERC20",
1036
- name: "_token",
1037
- type: "address"
1038
- },
1039
- {
1040
- internalType: "uint256",
1041
- name: "_amount",
1042
- type: "uint256"
1043
- },
1044
- {
1045
- internalType: "uint256",
1046
- name: "_period",
1047
- type: "uint256"
1048
- },
1049
- {
1050
- internalType: "uint256",
1051
- name: "_amount_per_period",
1052
- type: "uint256"
1053
- },
1054
- {
1055
- internalType: "uint256",
1056
- name: "_start",
1057
- type: "uint256"
1058
- },
1059
- {
1060
- internalType: "uint256",
1061
- name: "_cliff_amount",
1062
- type: "uint256"
1063
- },
1064
- {
1065
- components: [
1066
- {
1067
- internalType: "bool",
1068
- name: "cancelable_by_sender",
1069
- type: "bool"
1070
- },
1071
- {
1072
- internalType: "bool",
1073
- name: "cancelable_by_recipient",
1074
- type: "bool"
1075
- },
1076
- {
1077
- internalType: "bool",
1078
- name: "transferable_by_sender",
1079
- type: "bool"
1080
- },
1081
- {
1082
- internalType: "bool",
1083
- name: "transferable_by_recipient",
1084
- type: "bool"
1085
- },
1086
- {
1087
- internalType: "bool",
1088
- name: "can_topup",
1089
- type: "bool"
1090
- },
1091
- {
1092
- internalType: "bool",
1093
- name: "pausable",
1094
- type: "bool"
1095
- },
1096
- {
1097
- internalType: "bool",
1098
- name: "can_update_rate",
1099
- type: "bool"
1100
- },
1101
- {
1102
- internalType: "bool",
1103
- name: "automatic_withdrawal",
1104
- type: "bool"
1105
- },
1106
- {
1107
- internalType: "uint256",
1108
- name: "withdrawal_frequency",
1109
- type: "uint256"
1110
- },
1111
- {
1112
- internalType: "string",
1113
- name: "contract_name",
1114
- type: "string"
1115
- }
1116
- ],
1117
- internalType: "struct ContractMeta",
1118
- name: "_meta",
1119
- type: "tuple"
1120
- },
1121
- {
1122
- internalType: "address",
1123
- name: "_recipient",
1124
- type: "address"
1125
- },
1126
- {
1127
- internalType: "address",
1128
- name: "_partner",
1129
- type: "address"
1130
- }
1131
- ],
1132
- name: "create",
1133
- outputs: [],
1134
- stateMutability: "payable",
1135
- type: "function"
1136
- },
1137
- {
1138
- inputs: [
1139
- {
1140
- internalType: "address",
1141
- name: "_address",
1142
- type: "address"
1143
- }
1144
- ],
1145
- name: "feesRemove",
1146
- outputs: [],
1147
- stateMutability: "nonpayable",
1148
- type: "function"
1149
- },
1150
- {
1151
- inputs: [
1152
- {
1153
- internalType: "address",
1154
- name: "_address",
1155
- type: "address"
1156
- },
1157
- {
1158
- internalType: "uint256",
1159
- name: "streamflow_fee",
1160
- type: "uint256"
1161
- },
1162
- {
1163
- internalType: "uint256",
1164
- name: "partner_fee",
1165
- type: "uint256"
1166
- }
1167
- ],
1168
- name: "feesWrite",
1169
- outputs: [],
1170
- stateMutability: "nonpayable",
1171
- type: "function"
1172
- },
1173
- {
1174
- inputs: [],
1175
- name: "getAdmin",
1176
- outputs: [
1177
- {
1178
- internalType: "address",
1179
- name: "",
1180
- type: "address"
1181
- }
1182
- ],
1183
- stateMutability: "view",
1184
- type: "function"
1185
- },
1186
- {
1187
- inputs: [],
1188
- name: "getAll",
1189
- outputs: [
1190
- {
1191
- internalType: "address[]",
1192
- name: "",
1193
- type: "address[]"
1194
- },
1195
- {
1196
- components: [
1197
- {
1198
- internalType: "contract IERC20",
1199
- name: "token",
1200
- type: "address"
1201
- },
1202
- {
1203
- components: [
1204
- {
1205
- internalType: "bool",
1206
- name: "cancelable_by_sender",
1207
- type: "bool"
1208
- },
1209
- {
1210
- internalType: "bool",
1211
- name: "cancelable_by_recipient",
1212
- type: "bool"
1213
- },
1214
- {
1215
- internalType: "bool",
1216
- name: "transferable_by_sender",
1217
- type: "bool"
1218
- },
1219
- {
1220
- internalType: "bool",
1221
- name: "transferable_by_recipient",
1222
- type: "bool"
1223
- },
1224
- {
1225
- internalType: "bool",
1226
- name: "can_topup",
1227
- type: "bool"
1228
- },
1229
- {
1230
- internalType: "bool",
1231
- name: "pausable",
1232
- type: "bool"
1233
- },
1234
- {
1235
- internalType: "bool",
1236
- name: "can_update_rate",
1237
- type: "bool"
1238
- },
1239
- {
1240
- internalType: "bool",
1241
- name: "automatic_withdrawal",
1242
- type: "bool"
1243
- },
1244
- {
1245
- internalType: "uint256",
1246
- name: "withdrawal_frequency",
1247
- type: "uint256"
1248
- },
1249
- {
1250
- internalType: "string",
1251
- name: "contract_name",
1252
- type: "string"
1253
- }
1254
- ],
1255
- internalType: "struct ContractMeta",
1256
- name: "meta",
1257
- type: "tuple"
1258
- },
1259
- {
1260
- internalType: "uint256",
1261
- name: "amount",
1262
- type: "uint256"
1263
- },
1264
- {
1265
- internalType: "uint256",
1266
- name: "period",
1267
- type: "uint256"
1268
- },
1269
- {
1270
- internalType: "uint256",
1271
- name: "amount_per_period",
1272
- type: "uint256"
1273
- },
1274
- {
1275
- internalType: "uint256",
1276
- name: "start",
1277
- type: "uint256"
1278
- },
1279
- {
1280
- internalType: "uint256",
1281
- name: "end",
1282
- type: "uint256"
1283
- },
1284
- {
1285
- internalType: "uint256",
1286
- name: "cliff_amount",
1287
- type: "uint256"
1288
- },
1289
- {
1290
- internalType: "uint256",
1291
- name: "withdrawn",
1292
- type: "uint256"
1293
- },
1294
- {
1295
- internalType: "uint256",
1296
- name: "last_withdrawn_at",
1297
- type: "uint256"
1298
- },
1299
- {
1300
- internalType: "uint256",
1301
- name: "created",
1302
- type: "uint256"
1303
- },
1304
- {
1305
- internalType: "uint256",
1306
- name: "canceled_at",
1307
- type: "uint256"
1308
- },
1309
- {
1310
- internalType: "address",
1311
- name: "recipient",
1312
- type: "address"
1313
- },
1314
- {
1315
- internalType: "address",
1316
- name: "sender",
1317
- type: "address"
1318
- },
1319
- {
1320
- internalType: "address",
1321
- name: "partner",
1322
- type: "address"
1323
- },
1324
- {
1325
- components: [
1326
- {
1327
- internalType: "uint256",
1328
- name: "streamflow_fee_percentage",
1329
- type: "uint256"
1330
- },
1331
- {
1332
- internalType: "uint256",
1333
- name: "streamflow_fee",
1334
- type: "uint256"
1335
- },
1336
- {
1337
- internalType: "uint256",
1338
- name: "streamflow_fee_withdrawn",
1339
- type: "uint256"
1340
- },
1341
- {
1342
- internalType: "uint256",
1343
- name: "partner_fee_percentage",
1344
- type: "uint256"
1345
- },
1346
- {
1347
- internalType: "uint256",
1348
- name: "partner_fee",
1349
- type: "uint256"
1350
- },
1351
- {
1352
- internalType: "uint256",
1353
- name: "partner_fee_withdrawn",
1354
- type: "uint256"
1355
- },
1356
- {
1357
- internalType: "uint256",
1358
- name: "tx_fee",
1359
- type: "uint256"
1360
- }
1361
- ],
1362
- internalType: "struct FeesData",
1363
- name: "fees",
1364
- type: "tuple"
1365
- },
1366
- {
1367
- internalType: "bool",
1368
- name: "closed",
1369
- type: "bool"
1370
- },
1371
- {
1372
- internalType: "uint256",
1373
- name: "current_pause_start",
1374
- type: "uint256"
1375
- },
1376
- {
1377
- internalType: "uint256",
1378
- name: "pause_cumulative",
1379
- type: "uint256"
1380
- },
1381
- {
1382
- internalType: "uint256",
1383
- name: "last_rate_change_time",
1384
- type: "uint256"
1385
- },
1386
- {
1387
- internalType: "uint256",
1388
- name: "funds_unlocked_at_last_rate_change",
1389
- type: "uint256"
1390
- }
1391
- ],
1392
- internalType: "struct Contract[]",
1393
- name: "",
1394
- type: "tuple[]"
1395
- }
1396
- ],
1397
- stateMutability: "view",
1398
- type: "function"
1399
- },
1400
- {
1401
- inputs: [
1402
- {
1403
- internalType: "address",
1404
- name: "_id",
1405
- type: "address"
1406
- }
1407
- ],
1408
- name: "getById",
1409
- outputs: [
1410
- {
1411
- components: [
1412
- {
1413
- internalType: "contract IERC20",
1414
- name: "token",
1415
- type: "address"
1416
- },
1417
- {
1418
- components: [
1419
- {
1420
- internalType: "bool",
1421
- name: "cancelable_by_sender",
1422
- type: "bool"
1423
- },
1424
- {
1425
- internalType: "bool",
1426
- name: "cancelable_by_recipient",
1427
- type: "bool"
1428
- },
1429
- {
1430
- internalType: "bool",
1431
- name: "transferable_by_sender",
1432
- type: "bool"
1433
- },
1434
- {
1435
- internalType: "bool",
1436
- name: "transferable_by_recipient",
1437
- type: "bool"
1438
- },
1439
- {
1440
- internalType: "bool",
1441
- name: "can_topup",
1442
- type: "bool"
1443
- },
1444
- {
1445
- internalType: "bool",
1446
- name: "pausable",
1447
- type: "bool"
1448
- },
1449
- {
1450
- internalType: "bool",
1451
- name: "can_update_rate",
1452
- type: "bool"
1453
- },
1454
- {
1455
- internalType: "bool",
1456
- name: "automatic_withdrawal",
1457
- type: "bool"
1458
- },
1459
- {
1460
- internalType: "uint256",
1461
- name: "withdrawal_frequency",
1462
- type: "uint256"
1463
- },
1464
- {
1465
- internalType: "string",
1466
- name: "contract_name",
1467
- type: "string"
1468
- }
1469
- ],
1470
- internalType: "struct ContractMeta",
1471
- name: "meta",
1472
- type: "tuple"
1473
- },
1474
- {
1475
- internalType: "uint256",
1476
- name: "amount",
1477
- type: "uint256"
1478
- },
1479
- {
1480
- internalType: "uint256",
1481
- name: "period",
1482
- type: "uint256"
1483
- },
1484
- {
1485
- internalType: "uint256",
1486
- name: "amount_per_period",
1487
- type: "uint256"
1488
- },
1489
- {
1490
- internalType: "uint256",
1491
- name: "start",
1492
- type: "uint256"
1493
- },
1494
- {
1495
- internalType: "uint256",
1496
- name: "end",
1497
- type: "uint256"
1498
- },
1499
- {
1500
- internalType: "uint256",
1501
- name: "cliff_amount",
1502
- type: "uint256"
1503
- },
1504
- {
1505
- internalType: "uint256",
1506
- name: "withdrawn",
1507
- type: "uint256"
1508
- },
1509
- {
1510
- internalType: "uint256",
1511
- name: "last_withdrawn_at",
1512
- type: "uint256"
1513
- },
1514
- {
1515
- internalType: "uint256",
1516
- name: "created",
1517
- type: "uint256"
1518
- },
1519
- {
1520
- internalType: "uint256",
1521
- name: "canceled_at",
1522
- type: "uint256"
1523
- },
1524
- {
1525
- internalType: "address",
1526
- name: "recipient",
1527
- type: "address"
1528
- },
1529
- {
1530
- internalType: "address",
1531
- name: "sender",
1532
- type: "address"
1533
- },
1534
- {
1535
- internalType: "address",
1536
- name: "partner",
1537
- type: "address"
1538
- },
1539
- {
1540
- components: [
1541
- {
1542
- internalType: "uint256",
1543
- name: "streamflow_fee_percentage",
1544
- type: "uint256"
1545
- },
1546
- {
1547
- internalType: "uint256",
1548
- name: "streamflow_fee",
1549
- type: "uint256"
1550
- },
1551
- {
1552
- internalType: "uint256",
1553
- name: "streamflow_fee_withdrawn",
1554
- type: "uint256"
1555
- },
1556
- {
1557
- internalType: "uint256",
1558
- name: "partner_fee_percentage",
1559
- type: "uint256"
1560
- },
1561
- {
1562
- internalType: "uint256",
1563
- name: "partner_fee",
1564
- type: "uint256"
1565
- },
1566
- {
1567
- internalType: "uint256",
1568
- name: "partner_fee_withdrawn",
1569
- type: "uint256"
1570
- },
1571
- {
1572
- internalType: "uint256",
1573
- name: "tx_fee",
1574
- type: "uint256"
1575
- }
1576
- ],
1577
- internalType: "struct FeesData",
1578
- name: "fees",
1579
- type: "tuple"
1580
- },
1581
- {
1582
- internalType: "bool",
1583
- name: "closed",
1584
- type: "bool"
1585
- },
1586
- {
1587
- internalType: "uint256",
1588
- name: "current_pause_start",
1589
- type: "uint256"
1590
- },
1591
- {
1592
- internalType: "uint256",
1593
- name: "pause_cumulative",
1594
- type: "uint256"
1595
- },
1596
- {
1597
- internalType: "uint256",
1598
- name: "last_rate_change_time",
1599
- type: "uint256"
1600
- },
1601
- {
1602
- internalType: "uint256",
1603
- name: "funds_unlocked_at_last_rate_change",
1604
- type: "uint256"
1605
- }
1606
- ],
1607
- internalType: "struct Contract",
1608
- name: "",
1609
- type: "tuple"
1610
- }
1611
- ],
1612
- stateMutability: "view",
1613
- type: "function"
1614
- },
1615
- {
1616
- inputs: [
1617
- {
1618
- internalType: "address",
1619
- name: "_recipient",
1620
- type: "address"
1621
- }
1622
- ],
1623
- name: "getByRecipient",
1624
- outputs: [
1625
- {
1626
- internalType: "address[]",
1627
- name: "",
1628
- type: "address[]"
1629
- }
1630
- ],
1631
- stateMutability: "view",
1632
- type: "function"
1633
- },
1634
- {
1635
- inputs: [
1636
- {
1637
- internalType: "address",
1638
- name: "_sender",
1639
- type: "address"
1640
- }
1641
- ],
1642
- name: "getBySender",
1643
- outputs: [
1644
- {
1645
- internalType: "address[]",
1646
- name: "",
1647
- type: "address[]"
1648
- }
1649
- ],
1650
- stateMutability: "view",
1651
- type: "function"
1652
- },
1653
- {
1654
- inputs: [
1655
- {
1656
- internalType: "address",
1657
- name: "_address",
1658
- type: "address"
1659
- }
1660
- ],
1661
- name: "getFees",
1662
- outputs: [
1663
- {
1664
- components: [
1665
- {
1666
- internalType: "bool",
1667
- name: "exists",
1668
- type: "bool"
1669
- },
1670
- {
1671
- internalType: "uint256",
1672
- name: "streamflow_fee",
1673
- type: "uint256"
1674
- },
1675
- {
1676
- internalType: "uint256",
1677
- name: "partner_fee",
1678
- type: "uint256"
1679
- }
1680
- ],
1681
- internalType: "struct StreamflowFeeManager.FeeValue",
1682
- name: "",
1683
- type: "tuple"
1684
- }
1685
- ],
1686
- stateMutability: "view",
1687
- type: "function"
1688
- },
1689
- {
1690
- inputs: [
1691
- {
1692
- internalType: "address[]",
1693
- name: "_ids",
1694
- type: "address[]"
1695
- }
1696
- ],
1697
- name: "getMultiple",
1698
- outputs: [
1699
- {
1700
- components: [
1701
- {
1702
- internalType: "contract IERC20",
1703
- name: "token",
1704
- type: "address"
1705
- },
1706
- {
1707
- components: [
1708
- {
1709
- internalType: "bool",
1710
- name: "cancelable_by_sender",
1711
- type: "bool"
1712
- },
1713
- {
1714
- internalType: "bool",
1715
- name: "cancelable_by_recipient",
1716
- type: "bool"
1717
- },
1718
- {
1719
- internalType: "bool",
1720
- name: "transferable_by_sender",
1721
- type: "bool"
1722
- },
1723
- {
1724
- internalType: "bool",
1725
- name: "transferable_by_recipient",
1726
- type: "bool"
1727
- },
1728
- {
1729
- internalType: "bool",
1730
- name: "can_topup",
1731
- type: "bool"
1732
- },
1733
- {
1734
- internalType: "bool",
1735
- name: "pausable",
1736
- type: "bool"
1737
- },
1738
- {
1739
- internalType: "bool",
1740
- name: "can_update_rate",
1741
- type: "bool"
1742
- },
1743
- {
1744
- internalType: "bool",
1745
- name: "automatic_withdrawal",
1746
- type: "bool"
1747
- },
1748
- {
1749
- internalType: "uint256",
1750
- name: "withdrawal_frequency",
1751
- type: "uint256"
1752
- },
1753
- {
1754
- internalType: "string",
1755
- name: "contract_name",
1756
- type: "string"
1757
- }
1758
- ],
1759
- internalType: "struct ContractMeta",
1760
- name: "meta",
1761
- type: "tuple"
1762
- },
1763
- {
1764
- internalType: "uint256",
1765
- name: "amount",
1766
- type: "uint256"
1767
- },
1768
- {
1769
- internalType: "uint256",
1770
- name: "period",
1771
- type: "uint256"
1772
- },
1773
- {
1774
- internalType: "uint256",
1775
- name: "amount_per_period",
1776
- type: "uint256"
1777
- },
1778
- {
1779
- internalType: "uint256",
1780
- name: "start",
1781
- type: "uint256"
1782
- },
1783
- {
1784
- internalType: "uint256",
1785
- name: "end",
1786
- type: "uint256"
1787
- },
1788
- {
1789
- internalType: "uint256",
1790
- name: "cliff_amount",
1791
- type: "uint256"
1792
- },
1793
- {
1794
- internalType: "uint256",
1795
- name: "withdrawn",
1796
- type: "uint256"
1797
- },
1798
- {
1799
- internalType: "uint256",
1800
- name: "last_withdrawn_at",
1801
- type: "uint256"
1802
- },
1803
- {
1804
- internalType: "uint256",
1805
- name: "created",
1806
- type: "uint256"
1807
- },
1808
- {
1809
- internalType: "uint256",
1810
- name: "canceled_at",
1811
- type: "uint256"
1812
- },
1813
- {
1814
- internalType: "address",
1815
- name: "recipient",
1816
- type: "address"
1817
- },
1818
- {
1819
- internalType: "address",
1820
- name: "sender",
1821
- type: "address"
1822
- },
1823
- {
1824
- internalType: "address",
1825
- name: "partner",
1826
- type: "address"
1827
- },
1828
- {
1829
- components: [
1830
- {
1831
- internalType: "uint256",
1832
- name: "streamflow_fee_percentage",
1833
- type: "uint256"
1834
- },
1835
- {
1836
- internalType: "uint256",
1837
- name: "streamflow_fee",
1838
- type: "uint256"
1839
- },
1840
- {
1841
- internalType: "uint256",
1842
- name: "streamflow_fee_withdrawn",
1843
- type: "uint256"
1844
- },
1845
- {
1846
- internalType: "uint256",
1847
- name: "partner_fee_percentage",
1848
- type: "uint256"
1849
- },
1850
- {
1851
- internalType: "uint256",
1852
- name: "partner_fee",
1853
- type: "uint256"
1854
- },
1855
- {
1856
- internalType: "uint256",
1857
- name: "partner_fee_withdrawn",
1858
- type: "uint256"
1859
- },
1860
- {
1861
- internalType: "uint256",
1862
- name: "tx_fee",
1863
- type: "uint256"
1864
- }
1865
- ],
1866
- internalType: "struct FeesData",
1867
- name: "fees",
1868
- type: "tuple"
1869
- },
1870
- {
1871
- internalType: "bool",
1872
- name: "closed",
1873
- type: "bool"
1874
- },
1875
- {
1876
- internalType: "uint256",
1877
- name: "current_pause_start",
1878
- type: "uint256"
1879
- },
1880
- {
1881
- internalType: "uint256",
1882
- name: "pause_cumulative",
1883
- type: "uint256"
1884
- },
1885
- {
1886
- internalType: "uint256",
1887
- name: "last_rate_change_time",
1888
- type: "uint256"
1889
- },
1890
- {
1891
- internalType: "uint256",
1892
- name: "funds_unlocked_at_last_rate_change",
1893
- type: "uint256"
1894
- }
1895
- ],
1896
- internalType: "struct Contract[]",
1897
- name: "",
1898
- type: "tuple[]"
1899
- }
1900
- ],
1901
- stateMutability: "view",
1902
- type: "function"
1903
- },
1904
- {
1905
- inputs: [
1906
- {
1907
- internalType: "address",
1908
- name: "_address",
1909
- type: "address"
1910
- }
1911
- ],
1912
- name: "getStreamflowFee",
1913
- outputs: [
1914
- {
1915
- internalType: "uint256",
1916
- name: "",
1917
- type: "uint256"
1918
- }
1919
- ],
1920
- stateMutability: "view",
1921
- type: "function"
1922
- },
1923
- {
1924
- inputs: [],
1925
- name: "getStreamflowFees",
1926
- outputs: [
1927
- {
1928
- internalType: "uint256",
1929
- name: "",
1930
- type: "uint256"
1931
- }
1932
- ],
1933
- stateMutability: "view",
1934
- type: "function"
1935
- },
1936
- {
1937
- inputs: [
1938
- {
1939
- internalType: "address",
1940
- name: "_stream_id",
1941
- type: "address"
1942
- },
1943
- {
1944
- internalType: "uint256",
1945
- name: "_amount",
1946
- type: "uint256"
1947
- }
1948
- ],
1949
- name: "getTopUpWithdrawalFees",
1950
- outputs: [
1951
- {
1952
- components: [
1953
- {
1954
- internalType: "uint256",
1955
- name: "value",
1956
- type: "uint256"
1957
- },
1958
- {
1959
- internalType: "uint256",
1960
- name: "tx_fee",
1961
- type: "uint256"
1962
- }
1963
- ],
1964
- internalType: "struct WithdrawalFeesData",
1965
- name: "",
1966
- type: "tuple"
1967
- }
1968
- ],
1969
- stateMutability: "view",
1970
- type: "function"
1971
- },
1972
- {
1973
- inputs: [],
1974
- name: "getTreasuryAddress",
1975
- outputs: [
1976
- {
1977
- internalType: "address payable",
1978
- name: "",
1979
- type: "address"
1980
- }
1981
- ],
1982
- stateMutability: "view",
1983
- type: "function"
1984
- },
1985
- {
1986
- inputs: [],
1987
- name: "getTxFee",
1988
- outputs: [
1989
- {
1990
- internalType: "uint256",
1991
- name: "",
1992
- type: "uint256"
1993
- }
1994
- ],
1995
- stateMutability: "view",
1996
- type: "function"
1997
- },
1998
- {
1999
- inputs: [
2000
- {
2001
- internalType: "uint256",
2002
- name: "_amount",
2003
- type: "uint256"
2004
- },
2005
- {
2006
- internalType: "uint256",
2007
- name: "_period",
2008
- type: "uint256"
2009
- },
2010
- {
2011
- internalType: "uint256",
2012
- name: "_amount_per_period",
2013
- type: "uint256"
2014
- },
2015
- {
2016
- internalType: "uint256",
2017
- name: "_start",
2018
- type: "uint256"
2019
- },
2020
- {
2021
- internalType: "uint256",
2022
- name: "_cliff_amount",
2023
- type: "uint256"
2024
- },
2025
- {
2026
- internalType: "bool",
2027
- name: "_automatic_withdrawal",
2028
- type: "bool"
2029
- },
2030
- {
2031
- internalType: "uint256",
2032
- name: "_withdrawal_frequency",
2033
- type: "uint256"
2034
- }
2035
- ],
2036
- name: "getWithdrawalFees",
2037
- outputs: [
2038
- {
2039
- components: [
2040
- {
2041
- internalType: "uint256",
2042
- name: "value",
2043
- type: "uint256"
2044
- },
2045
- {
2046
- internalType: "uint256",
2047
- name: "tx_fee",
2048
- type: "uint256"
2049
- }
2050
- ],
2051
- internalType: "struct WithdrawalFeesData",
2052
- name: "",
2053
- type: "tuple"
2054
- }
2055
- ],
2056
- stateMutability: "view",
2057
- type: "function"
2058
- },
2059
- {
2060
- inputs: [],
2061
- name: "getWithdraworAddress",
2062
- outputs: [
2063
- {
2064
- internalType: "address payable",
2065
- name: "",
2066
- type: "address"
2067
- }
2068
- ],
2069
- stateMutability: "view",
2070
- type: "function"
2071
- },
2072
- {
2073
- inputs: [],
2074
- name: "initialize",
2075
- outputs: [],
2076
- stateMutability: "nonpayable",
2077
- type: "function"
2078
- },
2079
- {
2080
- inputs: [
2081
- {
2082
- internalType: "address",
2083
- name: "_stream_id",
2084
- type: "address"
2085
- },
2086
- {
2087
- internalType: "uint256",
2088
- name: "_amount",
2089
- type: "uint256"
2090
- }
2091
- ],
2092
- name: "topUp",
2093
- outputs: [],
2094
- stateMutability: "payable",
2095
- type: "function"
2096
- },
2097
- {
2098
- inputs: [
2099
- {
2100
- internalType: "address",
2101
- name: "_stream_id",
2102
- type: "address"
2103
- },
2104
- {
2105
- internalType: "address",
2106
- name: "new_recipient",
2107
- type: "address"
2108
- }
2109
- ],
2110
- name: "transfer",
2111
- outputs: [],
2112
- stateMutability: "nonpayable",
2113
- type: "function"
2114
- },
2115
- {
2116
- inputs: [
2117
- {
2118
- internalType: "address",
2119
- name: "_new_admin",
2120
- type: "address"
2121
- }
2122
- ],
2123
- name: "transferAdmin",
2124
- outputs: [],
2125
- stateMutability: "nonpayable",
2126
- type: "function"
2127
- },
2128
- {
2129
- inputs: [
2130
- {
2131
- internalType: "address",
2132
- name: "_stream_id",
2133
- type: "address"
2134
- },
2135
- {
2136
- internalType: "bool[]",
2137
- name: "_automatic_withdrawal",
2138
- type: "bool[]"
2139
- },
2140
- {
2141
- internalType: "uint256[]",
2142
- name: "_withdrawal_frequency",
2143
- type: "uint256[]"
2144
- },
2145
- {
2146
- internalType: "uint256[]",
2147
- name: "_amount_per_period",
2148
- type: "uint256[]"
2149
- }
2150
- ],
2151
- name: "update",
2152
- outputs: [],
2153
- stateMutability: "payable",
2154
- type: "function"
2155
- },
2156
- {
2157
- inputs: [
2158
- {
2159
- internalType: "address",
2160
- name: "_stream_id",
2161
- type: "address"
2162
- },
2163
- {
2164
- internalType: "uint256",
2165
- name: "_amount",
2166
- type: "uint256"
2167
- }
2168
- ],
2169
- name: "withdraw",
2170
- outputs: [],
2171
- stateMutability: "nonpayable",
2172
- type: "function"
2173
- }
2174
- ];
2175
-
2176
- // evm/ercAbi.ts
2177
- var ercAbi_default = [
2178
- {
2179
- constant: true,
2180
- inputs: [],
2181
- name: "name",
2182
- outputs: [
2183
- {
2184
- name: "",
2185
- type: "string"
2186
- }
2187
- ],
2188
- payable: false,
2189
- stateMutability: "view",
2190
- type: "function"
2191
- },
2192
- {
2193
- constant: false,
2194
- inputs: [
2195
- {
2196
- name: "_spender",
2197
- type: "address"
2198
- },
2199
- {
2200
- name: "_value",
2201
- type: "uint256"
2202
- }
2203
- ],
2204
- name: "approve",
2205
- outputs: [
2206
- {
2207
- name: "",
2208
- type: "bool"
2209
- }
2210
- ],
2211
- payable: false,
2212
- stateMutability: "nonpayable",
2213
- type: "function"
2214
- },
2215
- {
2216
- constant: true,
2217
- inputs: [],
2218
- name: "totalSupply",
2219
- outputs: [
2220
- {
2221
- name: "",
2222
- type: "uint256"
2223
- }
2224
- ],
2225
- payable: false,
2226
- stateMutability: "view",
2227
- type: "function"
2228
- },
2229
- {
2230
- constant: false,
2231
- inputs: [
2232
- {
2233
- name: "_from",
2234
- type: "address"
2235
- },
2236
- {
2237
- name: "_to",
2238
- type: "address"
2239
- },
2240
- {
2241
- name: "_value",
2242
- type: "uint256"
2243
- }
2244
- ],
2245
- name: "transferFrom",
2246
- outputs: [
2247
- {
2248
- name: "",
2249
- type: "bool"
2250
- }
2251
- ],
2252
- payable: false,
2253
- stateMutability: "nonpayable",
2254
- type: "function"
2255
- },
2256
- {
2257
- constant: true,
2258
- inputs: [],
2259
- name: "decimals",
2260
- outputs: [
2261
- {
2262
- name: "",
2263
- type: "uint8"
2264
- }
2265
- ],
2266
- payable: false,
2267
- stateMutability: "view",
2268
- type: "function"
2269
- },
2270
- {
2271
- constant: true,
2272
- inputs: [
2273
- {
2274
- name: "_owner",
2275
- type: "address"
2276
- }
2277
- ],
2278
- name: "balanceOf",
2279
- outputs: [
2280
- {
2281
- name: "balance",
2282
- type: "uint256"
2283
- }
2284
- ],
2285
- payable: false,
2286
- stateMutability: "view",
2287
- type: "function"
2288
- },
2289
- {
2290
- constant: true,
2291
- inputs: [],
2292
- name: "symbol",
2293
- outputs: [
2294
- {
2295
- name: "",
2296
- type: "string"
2297
- }
2298
- ],
2299
- payable: false,
2300
- stateMutability: "view",
2301
- type: "function"
2302
- },
2303
- {
2304
- constant: false,
2305
- inputs: [
2306
- {
2307
- name: "_to",
2308
- type: "address"
2309
- },
2310
- {
2311
- name: "_value",
2312
- type: "uint256"
2313
- }
2314
- ],
2315
- name: "transfer",
2316
- outputs: [
2317
- {
2318
- name: "",
2319
- type: "bool"
2320
- }
2321
- ],
2322
- payable: false,
2323
- stateMutability: "nonpayable",
2324
- type: "function"
2325
- },
2326
- {
2327
- constant: true,
2328
- inputs: [
2329
- {
2330
- name: "_owner",
2331
- type: "address"
2332
- },
2333
- {
2334
- name: "_spender",
2335
- type: "address"
2336
- }
2337
- ],
2338
- name: "allowance",
2339
- outputs: [
2340
- {
2341
- name: "",
2342
- type: "uint256"
2343
- }
2344
- ],
2345
- payable: false,
2346
- stateMutability: "view",
2347
- type: "function"
2348
- },
2349
- {
2350
- payable: true,
2351
- stateMutability: "payable",
2352
- type: "fallback"
2353
- },
2354
- {
2355
- anonymous: false,
2356
- inputs: [
2357
- {
2358
- indexed: true,
2359
- name: "owner",
2360
- type: "address"
2361
- },
2362
- {
2363
- indexed: true,
2364
- name: "spender",
2365
- type: "address"
2366
- },
2367
- {
2368
- indexed: false,
2369
- name: "value",
2370
- type: "uint256"
2371
- }
2372
- ],
2373
- name: "Approval",
2374
- type: "event"
2375
- },
2376
- {
2377
- anonymous: false,
2378
- inputs: [
2379
- {
2380
- indexed: true,
2381
- name: "from",
2382
- type: "address"
2383
- },
2384
- {
2385
- indexed: true,
2386
- name: "to",
2387
- type: "address"
2388
- },
2389
- {
2390
- indexed: false,
2391
- name: "value",
2392
- type: "uint256"
2393
- }
2394
- ],
2395
- name: "Transfer",
2396
- type: "event"
2397
- }
2398
- ];
2399
- var EvmContract = class {
2400
- constructor(stream) {
2401
- this.magic = 0;
2402
- this.version = 0;
2403
- this.createdAt = stream.created.toNumber();
2404
- this.withdrawnAmount = new BN7__default.default(stream.withdrawn.toString());
2405
- this.canceledAt = stream.canceled_at.toNumber();
2406
- this.end = stream.end.toNumber();
2407
- this.lastWithdrawnAt = stream.last_withdrawn_at.toNumber();
2408
- this.sender = stream.sender;
2409
- this.senderTokens = stream.sender;
2410
- this.recipient = stream.recipient;
2411
- this.recipientTokens = stream.recipient;
2412
- this.mint = stream.token.toLowerCase();
2413
- this.escrowTokens = "";
2414
- this.streamflowTreasury = "";
2415
- this.streamflowTreasuryTokens = "";
2416
- this.streamflowFeeTotal = new BN7__default.default(stream.fees.streamflow_fee.toString());
2417
- this.streamflowFeeWithdrawn = new BN7__default.default(stream.fees.streamflow_fee_withdrawn.toString());
2418
- this.streamflowFeePercent = stream.fees.streamflow_fee_percentage.toNumber() / 1e4;
2419
- this.partnerFeeTotal = new BN7__default.default(0);
2420
- this.partnerFeeWithdrawn = new BN7__default.default(0);
2421
- this.partnerFeePercent = 0;
2422
- this.partner = "";
2423
- this.partnerTokens = "";
2424
- this.start = stream.start.toNumber();
2425
- this.depositedAmount = new BN7__default.default(stream.amount.toString());
2426
- this.period = stream.period.toNumber();
2427
- this.amountPerPeriod = new BN7__default.default(stream.amount_per_period.toString());
2428
- this.cliff = stream.start.toNumber();
2429
- this.cliffAmount = new BN7__default.default(stream.cliff_amount.toString());
2430
- this.cancelableBySender = stream.meta.cancelable_by_sender;
2431
- this.cancelableByRecipient = stream.meta.cancelable_by_recipient;
2432
- this.automaticWithdrawal = stream.meta.automatic_withdrawal;
2433
- this.transferableBySender = stream.meta.transferable_by_sender;
2434
- this.transferableByRecipient = stream.meta.transferable_by_recipient;
2435
- this.canTopup = stream.meta.can_topup;
2436
- this.name = stream.meta.contract_name;
2437
- this.withdrawalFrequency = stream.meta.withdrawal_frequency.toNumber();
2438
- this.closed = stream.closed;
2439
- this.currentPauseStart = stream.current_pause_start.toNumber();
2440
- this.pauseCumulative = new BN7__default.default(stream.pause_cumulative.toString());
2441
- this.lastRateChangeTime = stream.last_rate_change_time.toNumber();
2442
- this.fundsUnlockedAtLastRateChange = new BN7__default.default(stream.funds_unlocked_at_last_rate_change.toString());
2443
- this.type = buildStreamType(this);
2444
- }
2445
- unlocked(currentTimestamp) {
2446
- return calculateUnlockedAmount({
2447
- ...this,
2448
- currentTimestamp
2449
- });
2450
- }
2451
- remaining(decimals) {
2452
- return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
2453
- }
2454
- };
2455
-
2456
- // evm/utils.ts
2457
- function extractEvmErrorCode(errorText) {
2458
- const match = EVM_ERROR_MATCH_REGEX.exec(errorText);
2459
- if (!match) {
2460
- return null;
2461
- }
2462
- return match[1];
2463
- }
2464
-
2465
- // evm/StreamClient.ts
2466
- var EvmStreamClient = class extends BaseStreamClient {
2467
- constructor(clusterUrl, chain, signer, cluster = common.ICluster.Mainnet, programId) {
2468
- super();
2469
- if (chain !== common.IChain.Ethereum && chain !== common.IChain.BNB && chain !== common.IChain.Polygon) {
2470
- throw new Error("Wrong chain. Supported chains are Ethereum , BNB and Polygon!");
2471
- }
2472
- if (programId) {
2473
- this.programId = programId;
2474
- } else {
2475
- switch (chain) {
2476
- case common.IChain.Ethereum:
2477
- this.programId = ETHEREUM_PROGRAM_IDS[cluster];
2478
- break;
2479
- case common.IChain.BNB:
2480
- this.programId = BNB_PROGRAM_IDS[cluster];
2481
- break;
2482
- case common.IChain.Polygon:
2483
- this.programId = POLYGON_PROGRAM_IDS[cluster];
2484
- break;
2485
- }
2486
- }
2487
- this.provider = new ethers.ethers.providers.JsonRpcProvider(clusterUrl);
2488
- this.signer = signer;
2489
- const baseContract = new ethers.ethers.Contract(this.programId, abi_default);
2490
- this.readContract = baseContract.connect(this.provider);
2491
- this.writeContract = baseContract.connect(this.signer);
2492
- }
2493
- async create(streamData) {
2494
- const multiParams = {
2495
- ...streamData,
2496
- recipients: [streamData]
2497
- };
2498
- const fees = await this.readContract.getWithdrawalFees(...this.getFeeParams(multiParams));
2499
- const args = (await this.generateMultiPayloads(multiParams))[0];
2500
- const sum = streamData.amount.mul(new BN7__default.default(BASE_FEE)).div(new BN7__default.default(1e6));
2501
- await this.approveTokens(streamData.tokenId, sum);
2502
- const result = await this.writeContract.create(...args, {
2503
- value: fees.value
2504
- });
2505
- const confirmedTx = await result.wait();
2506
- const metadataId = this.formatMetadataId(
2507
- confirmedTx.events.find((item) => item.event === "ContractCreated").args[0]
2508
- );
2509
- return {
2510
- ixs: [],
2511
- txId: result.hash,
2512
- metadataId
2513
- };
2514
- }
2515
- async createMultiple(multipleStreamData) {
2516
- const fees = await this.readContract.getWithdrawalFees(...this.getFeeParams(multipleStreamData));
2517
- const args = await this.generateMultiPayloads(multipleStreamData);
2518
- const sum = multipleStreamData.recipients.reduce((acc, v) => acc.add(v.amount), new BN7__default.default(0)).mul(new BN7__default.default(BASE_FEE)).div(new BN7__default.default(1e6));
2519
- await this.approveTokens(multipleStreamData.tokenId, sum);
2520
- const creationPromises = args.map((item) => this.writeContract.create(...item, { value: fees.value }));
2521
- const signatures = [];
2522
- const results = await Promise.all(creationPromises);
2523
- const confirmations = await Promise.allSettled(results.map((result) => result.wait()));
2524
- const successes = confirmations.filter((el) => el.status === "fulfilled").map((el) => el.value);
2525
- signatures.push(...successes.map((el) => el.hash));
2526
- const metadatas = confirmations.map(
2527
- (result) => result.status === "fulfilled" ? this.formatMetadataId(
2528
- result.value.events.find((item) => item.event === "ContractCreated").args[0]
2529
- ) : null
2530
- );
2531
- const metadataToRecipient = metadatas.reduce(
2532
- (acc, value, index) => {
2533
- if (value) {
2534
- acc[value] = multipleStreamData.recipients[index];
2535
- }
2536
- return acc;
2537
- },
2538
- {}
2539
- );
2540
- const failures = confirmations.filter((el) => el.status === "rejected").map((el) => el.reason);
2541
- return {
2542
- txs: signatures,
2543
- metadatas: metadatas.filter(Boolean),
2544
- metadataToRecipient,
2545
- errors: failures
2546
- };
2547
- }
2548
- async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }) {
2549
- const result = await this.writeContract.withdraw(id, amount.toString());
2550
- return {
2551
- ixs: [],
2552
- txId: result.hash
2553
- };
2554
- }
2555
- async cancel(cancelData) {
2556
- const result = await this.writeContract.cancel(cancelData.id);
2557
- return {
2558
- ixs: [],
2559
- txId: result.hash
2560
- };
2561
- }
2562
- async transfer(transferData) {
2563
- const result = await this.writeContract.transfer(transferData.id, transferData.newRecipient);
2564
- return {
2565
- ixs: [],
2566
- txId: result.hash
2567
- };
2568
- }
2569
- async topup(topupData) {
2570
- const fees = await this.readContract.getTopUpWithdrawalFees(topupData.id, topupData.amount.toString());
2571
- const sum = topupData.amount.mul(new BN7__default.default(BASE_FEE)).div(new BN7__default.default(1e6));
2572
- const stream = await this.getOne({ id: topupData.id });
2573
- await this.approveTokens(stream.mint, sum);
2574
- const result = await this.writeContract.topUp(topupData.id, topupData.amount.toString(), {
2575
- value: fees.value
2576
- });
2577
- return {
2578
- ixs: [],
2579
- txId: result.hash
2580
- };
2581
- }
2582
- async update(updateData) {
2583
- const result = await this.writeContract.update(
2584
- updateData.id,
2585
- updateData.enableAutomaticWithdrawal ? [true] : [],
2586
- updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
2587
- updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : []
2588
- );
2589
- return {
2590
- ixs: [],
2591
- txId: result.hash
2592
- };
2593
- }
2594
- async getOne({ id }) {
2595
- const result = await this.readContract.getById(id);
2596
- return new EvmContract(result);
2597
- }
2598
- async get({
2599
- address,
2600
- // type = StreamType.All,
2601
- direction = "all" /* All */
2602
- }) {
2603
- const addresses = [];
2604
- if (direction === "all" /* All */ || direction === "outgoing" /* Outgoing */) {
2605
- const senderAddresses = await this.readContract.getBySender(address);
2606
- addresses.push(...senderAddresses);
2607
- }
2608
- if (direction === "all" /* All */ || direction === "incoming" /* Incoming */) {
2609
- const recipientAddresses = await this.readContract.getByRecipient(address);
2610
- addresses.push(...recipientAddresses);
2611
- }
2612
- const uniqueAddresses = [...new Set(addresses)];
2613
- const results = await this.readContract.getMultiple(uniqueAddresses);
2614
- return results.map((result, index) => [uniqueAddresses[index], new EvmContract(result)]);
2615
- }
2616
- extractErrorCode(err) {
2617
- return extractEvmErrorCode(err.toString() ?? "Unknown error!");
2618
- }
2619
- async getFees({ address }) {
2620
- const fees = await this.readContract.getFees(address);
2621
- if (!fees.exists) {
2622
- return null;
2623
- }
2624
- return {
2625
- streamflowFee: fees.streamflow_fee.toNumber() / 100,
2626
- partnerFee: fees.partner_fee.toNumber() / 100
2627
- };
2628
- }
2629
- async getDefaultStreamflowFee() {
2630
- const fee = await this.readContract.getStreamflowFees();
2631
- return fee.toNumber() / 100;
2632
- }
2633
- /**
2634
- * Returns StreamClient protocol program ID.
2635
- */
2636
- getProgramId() {
2637
- return this.programId;
2638
- }
2639
- async approveTokens(tokenId, amount) {
2640
- const tokenContract = new ethers.ethers.Contract(tokenId, ercAbi_default, this.signer);
2641
- const address = await this.signer.getAddress();
2642
- const allowance = await tokenContract.allowance(address, this.programId);
2643
- if (new BN7__default.default(allowance.toString()).gte(amount)) {
2644
- return;
2645
- }
2646
- const approvalTx = await tokenContract.approve(this.programId, amount.toString());
2647
- await approvalTx.wait();
2648
- }
2649
- // Utility function to prepare transaction payloads for multiple recipients.
2650
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2651
- async generateMultiPayloads(multipleStreamData) {
2652
- const sender = await this.signer.getAddress();
2653
- return multipleStreamData.recipients.map((recipient) => {
2654
- return [
2655
- multipleStreamData.tokenId,
2656
- recipient.amount.toString(),
2657
- multipleStreamData.period,
2658
- recipient.amountPerPeriod.toString(),
2659
- multipleStreamData.start,
2660
- recipient.cliffAmount.toString(),
2661
- [
2662
- multipleStreamData.cancelableBySender,
2663
- multipleStreamData.cancelableByRecipient,
2664
- multipleStreamData.transferableBySender,
2665
- multipleStreamData.transferableByRecipient,
2666
- multipleStreamData.canTopup,
2667
- multipleStreamData.canPause || false,
2668
- multipleStreamData.canUpdateRate || false,
2669
- multipleStreamData.automaticWithdrawal || false,
2670
- multipleStreamData.withdrawalFrequency || 0,
2671
- recipient.name
2672
- ],
2673
- recipient.recipient,
2674
- multipleStreamData.partner || sender
2675
- ];
2676
- });
2677
- }
2678
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2679
- getFeeParams(multipleStreamData) {
2680
- return [
2681
- multipleStreamData.recipients[0].amount.toString(),
2682
- multipleStreamData.period,
2683
- multipleStreamData.recipients[0].amountPerPeriod.toString(),
2684
- multipleStreamData.start,
2685
- multipleStreamData.recipients[0].cliffAmount.toString(),
2686
- multipleStreamData.automaticWithdrawal || false,
2687
- multipleStreamData.withdrawalFrequency || 0
2688
- ];
2689
- }
2690
- formatMetadataId(id) {
2691
- return ethereumChecksumAddress.toChecksumAddress(`0x${id.slice(-40)}`);
2692
- }
2693
- };
2694
-
2695
- // solana/index.ts
2696
- var solana_exports = {};
2697
- __export(solana_exports, {
2698
- AlignedContract: () => AlignedContract,
2699
- Contract: () => Contract2,
2700
- ContractError: () => common.ContractError,
2701
- IChain: () => common.IChain,
2702
- ICluster: () => common.ICluster,
2703
- SolanaStreamClient: () => SolanaStreamClient,
2704
- cancelStreamInstruction: () => cancelStreamInstruction,
2705
- constants: () => constants_exports3,
2706
- createStreamInstruction: () => createStreamInstruction,
2707
- createUncheckedStreamInstruction: () => createUncheckedStreamInstruction,
2708
- decodeStream: () => decodeStream,
2709
- deriveContractPDA: () => deriveContractPDA,
2710
- deriveEscrowPDA: () => deriveEscrowPDA,
2711
- deriveTestOraclePDA: () => deriveTestOraclePDA,
2712
- extractSolanaErrorCode: () => extractSolanaErrorCode,
2713
- sendAndConfirmStreamRawTransaction: () => sendAndConfirmStreamRawTransaction,
2714
- signAllTransactionWithRecipients: () => signAllTransactionWithRecipients,
2715
- timelockIDL: () => timelockIDL_default,
2716
- topupStreamInstruction: () => topupStreamInstruction,
2717
- transferStreamInstruction: () => transferStreamInstruction,
2718
- updateStreamInstruction: () => updateStreamInstruction,
2719
- withdrawStreamInstruction: () => withdrawStreamInstruction
2720
- });
2721
-
2722
- // solana/constants.ts
2723
- var constants_exports3 = {};
2724
- __export(constants_exports3, {
2725
- AIRDROP_AMOUNT: () => AIRDROP_AMOUNT,
2726
- AIRDROP_TEST_TOKEN: () => AIRDROP_TEST_TOKEN,
2727
- ALIGNED_COMPUTE_LIMIT: () => ALIGNED_COMPUTE_LIMIT,
2728
- ALIGNED_PRECISION_FACTOR_POW: () => ALIGNED_PRECISION_FACTOR_POW,
2729
- ALIGNED_UNLOCKS_PROGRAM_ID: () => ALIGNED_UNLOCKS_PROGRAM_ID,
2730
- CONTRACT_DISCRIMINATOR: () => CONTRACT_DISCRIMINATOR,
2731
- CONTRACT_SEED: () => CONTRACT_SEED,
2732
- CREATE_PARAMS_PADDING: () => CREATE_PARAMS_PADDING,
2733
- DEFAULT_STREAMFLOW_FEE: () => DEFAULT_STREAMFLOW_FEE,
2734
- ESCROW_SEED: () => ESCROW_SEED,
2735
- FEES_METADATA_SEED: () => FEES_METADATA_SEED,
2736
- FEE_ORACLE_PUBLIC_KEY: () => FEE_ORACLE_PUBLIC_KEY,
2737
- ORIGINAL_CONTRACT_SENDER_OFFSET: () => ORIGINAL_CONTRACT_SENDER_OFFSET,
2738
- PARTNERS_SCHEMA: () => PARTNERS_SCHEMA,
2739
- PARTNER_ORACLE_PROGRAM_ID: () => PARTNER_ORACLE_PROGRAM_ID,
2740
- PARTNER_SCHEMA: () => PARTNER_SCHEMA,
2741
- PROGRAM_ID: () => PROGRAM_ID,
2742
- SOLANA_ERROR_MAP: () => SOLANA_ERROR_MAP,
2743
- SOLANA_ERROR_MATCH_REGEX: () => SOLANA_ERROR_MATCH_REGEX,
2744
- STREAMFLOW_TREASURY_PUBLIC_KEY: () => STREAMFLOW_TREASURY_PUBLIC_KEY,
2745
- STREAM_STRUCT_OFFSETS: () => STREAM_STRUCT_OFFSETS,
2746
- STREAM_STRUCT_OFFSET_CLOSED: () => STREAM_STRUCT_OFFSET_CLOSED,
2747
- STREAM_STRUCT_OFFSET_MINT: () => STREAM_STRUCT_OFFSET_MINT,
2748
- STREAM_STRUCT_OFFSET_RECIPIENT: () => STREAM_STRUCT_OFFSET_RECIPIENT,
2749
- STREAM_STRUCT_OFFSET_SENDER: () => STREAM_STRUCT_OFFSET_SENDER,
2750
- TEST_ORACLE_DISCRIMINATOR: () => TEST_ORACLE_DISCRIMINATOR,
2751
- TEST_ORACLE_SEED: () => TEST_ORACLE_SEED,
2752
- TX_FINALITY_CONFIRMED: () => TX_FINALITY_CONFIRMED,
2753
- WITHDRAWOR_PUBLIC_KEY: () => WITHDRAWOR_PUBLIC_KEY
2754
- });
2755
- var TX_FINALITY_CONFIRMED = "confirmed";
2756
- var ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
2757
- var STREAM_STRUCT_OFFSET_SENDER = 49;
2758
- var STREAM_STRUCT_OFFSET_RECIPIENT = 113;
2759
- var STREAM_STRUCT_OFFSET_MINT = 177;
2760
- var STREAM_STRUCT_OFFSET_CLOSED = 671;
2761
- var ALIGNED_PRECISION_FACTOR_POW = 9;
2762
- var STREAM_STRUCT_OFFSETS = {
2763
- mint: STREAM_STRUCT_OFFSET_MINT,
2764
- recipient: STREAM_STRUCT_OFFSET_RECIPIENT,
2765
- sender: STREAM_STRUCT_OFFSET_SENDER,
2766
- closed: STREAM_STRUCT_OFFSET_CLOSED
2767
- };
2768
- var CREATE_PARAMS_PADDING = 126;
2769
- var PROGRAM_ID = {
2770
- [common.ICluster.Devnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
2771
- [common.ICluster.Mainnet]: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
2772
- [common.ICluster.Testnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
2773
- [common.ICluster.Local]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ"
2774
- };
2775
- var ALIGNED_UNLOCKS_PROGRAM_ID = {
2776
- [common.ICluster.Devnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
2777
- [common.ICluster.Mainnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
2778
- [common.ICluster.Testnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
2779
- [common.ICluster.Local]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH"
2780
- };
2781
- var ALIGNED_COMPUTE_LIMIT = 3e5;
2782
- var CONTRACT_DISCRIMINATOR = [172, 138, 115, 242, 121, 67, 183, 26];
2783
- var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
2784
- var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
2785
- var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
2786
- var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
2787
- var PARTNER_ORACLE_PROGRAM_ID = "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa";
2788
- var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
2789
- var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
2790
- var FEE_ORACLE_PUBLIC_KEY = new web3_js.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
2791
- var AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
2792
- var FEES_METADATA_SEED = buffer.Buffer.from("strm_fees");
2793
- var DEFAULT_STREAMFLOW_FEE = 0.99;
2794
- var AIRDROP_AMOUNT = 1;
2795
- var PARTNER_SCHEMA = {
2796
- struct: {
2797
- pubkey: { array: { type: "u8", len: 32 } },
2798
- partner_fee: "f32",
2799
- strm_fee: "f32"
233
+ var TX_FINALITY_CONFIRMED = "confirmed";
234
+ var ORIGINAL_CONTRACT_SENDER_OFFSET = 9;
235
+ var STREAM_STRUCT_OFFSET_SENDER = 49;
236
+ var STREAM_STRUCT_OFFSET_RECIPIENT = 113;
237
+ var STREAM_STRUCT_OFFSET_MINT = 177;
238
+ var STREAM_STRUCT_OFFSET_CLOSED = 671;
239
+ var MAX_SAFE_UNIX_TIME_VALUE2 = 864e10;
240
+ var WITHDRAW_AVAILABLE_AMOUNT = new BN3__default.default("18446744073709551615");
241
+ var ALIGNED_PRECISION_FACTOR_POW2 = 9;
242
+ var STREAM_STRUCT_OFFSETS = {
243
+ mint: STREAM_STRUCT_OFFSET_MINT,
244
+ recipient: STREAM_STRUCT_OFFSET_RECIPIENT,
245
+ sender: STREAM_STRUCT_OFFSET_SENDER,
246
+ closed: STREAM_STRUCT_OFFSET_CLOSED
247
+ };
248
+ var CREATE_PARAMS_PADDING = 126;
249
+ var PROGRAM_ID = {
250
+ [common.ICluster.Devnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
251
+ [common.ICluster.Mainnet]: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
252
+ [common.ICluster.Testnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
253
+ [common.ICluster.Local]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ"
254
+ };
255
+ var ALIGNED_UNLOCKS_PROGRAM_ID = {
256
+ [common.ICluster.Devnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
257
+ [common.ICluster.Mainnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
258
+ [common.ICluster.Testnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
259
+ [common.ICluster.Local]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH"
260
+ };
261
+ var ALIGNED_COMPUTE_LIMIT = 3e5;
262
+ var CONTRACT_DISCRIMINATOR = [172, 138, 115, 242, 121, 67, 183, 26];
263
+ var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
264
+ var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
265
+ var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
266
+ var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
267
+ var PARTNER_ORACLE_PROGRAM_ID = "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa";
268
+ var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
269
+ var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
270
+ var FEE_ORACLE_PUBLIC_KEY = new web3_js.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
271
+ var AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
272
+ var FEES_METADATA_SEED = buffer.Buffer.from("strm_fees");
273
+ var DEFAULT_STREAMFLOW_FEE = 0.99;
274
+ var AIRDROP_AMOUNT = 1;
275
+ var PARTNER_SCHEMA = {
276
+ struct: {
277
+ pubkey: { array: { type: "u8", len: 32 } },
278
+ partner_fee: "f32",
279
+ strm_fee: "f32"
2800
280
  }
2801
281
  };
2802
282
  var PARTNERS_SCHEMA = { array: { type: PARTNER_SCHEMA } };
@@ -2839,88 +319,8 @@ var SOLANA_ERROR_MAP = {
2839
319
  6011: "AmountAlreadyUpdated" /* AmountAlreadyUpdated */,
2840
320
  6012: "AllFundsUnlocked" /* AllFundsUnlocked */
2841
321
  };
2842
- var Contract2 = class {
2843
- constructor(stream) {
2844
- this.magic = stream.magic.toNumber();
2845
- this.version = stream.version.toNumber();
2846
- this.createdAt = stream.createdAt.toNumber();
2847
- this.withdrawnAmount = stream.withdrawnAmount;
2848
- this.canceledAt = stream.canceledAt.toNumber();
2849
- this.end = decodeEndTime(stream.end);
2850
- this.lastWithdrawnAt = stream.lastWithdrawnAt.toNumber();
2851
- this.sender = stream.sender.toBase58();
2852
- this.senderTokens = stream.senderTokens.toBase58();
2853
- this.recipient = stream.recipient.toBase58();
2854
- this.recipientTokens = stream.recipientTokens.toBase58();
2855
- this.mint = stream.mint.toBase58();
2856
- this.escrowTokens = stream.escrowTokens.toBase58();
2857
- this.streamflowTreasury = stream.streamflowTreasury.toBase58();
2858
- this.streamflowTreasuryTokens = stream.streamflowTreasuryTokens.toBase58();
2859
- this.streamflowFeeTotal = stream.streamflowFeeTotal;
2860
- this.streamflowFeeWithdrawn = stream.streamflowFeeWithdrawn;
2861
- this.streamflowFeePercent = stream.streamflowFeePercent;
2862
- this.partnerFeeTotal = stream.partnerFeeTotal;
2863
- this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
2864
- this.partnerFeePercent = stream.partnerFeePercent;
2865
- this.partner = stream.partner.toBase58();
2866
- this.partnerTokens = stream.partnerTokens?.toBase58();
2867
- this.start = stream.start.toNumber();
2868
- this.depositedAmount = stream.depositedAmount;
2869
- this.period = stream.period.toNumber();
2870
- this.amountPerPeriod = stream.amountPerPeriod;
2871
- this.cliff = stream.cliff.toNumber();
2872
- this.cliffAmount = stream.cliffAmount;
2873
- this.cancelableBySender = stream.cancelableBySender;
2874
- this.cancelableByRecipient = stream.cancelableByRecipient;
2875
- this.automaticWithdrawal = stream.automaticWithdrawal;
2876
- this.transferableBySender = stream.transferableBySender;
2877
- this.transferableByRecipient = stream.transferableByRecipient;
2878
- this.canTopup = stream.canTopup;
2879
- this.name = stream.name;
2880
- this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
2881
- this.closed = stream.closed;
2882
- this.currentPauseStart = stream.currentPauseStart.toNumber();
2883
- this.pauseCumulative = stream.pauseCumulative;
2884
- this.lastRateChangeTime = stream.lastRateChangeTime.toNumber();
2885
- this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
2886
- this.type = buildStreamType(this);
2887
- this.isAligned = false;
2888
- }
2889
- unlocked(currentTimestamp) {
2890
- return calculateUnlockedAmount({
2891
- ...this,
2892
- currentTimestamp
2893
- });
2894
- }
2895
- remaining(decimals) {
2896
- return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
2897
- }
2898
- };
2899
- var AlignedContract = class extends Contract2 {
2900
- constructor(stream, alignedProxy) {
2901
- super(stream);
2902
- this.minPrice = getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW);
2903
- this.maxPrice = getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW);
2904
- this.minPercentage = getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW);
2905
- this.maxPercentage = getNumberFromBN(alignedProxy.maxPercentage, ALIGNED_PRECISION_FACTOR_POW);
2906
- this.oracleType = Object.keys(alignedProxy.priceOracleType).find((key) => !!key) || "none";
2907
- this.tickSize = alignedProxy.tickSize.toNumber();
2908
- this.priceOracle = this.oracleType === "none" ? void 0 : alignedProxy.priceOracle.toBase58();
2909
- this.sender = alignedProxy.sender.toBase58();
2910
- this.canceledAt = alignedProxy.streamCanceledTime.toNumber();
2911
- this.proxyAddress = stream.sender.toBase58();
2912
- this.initialAmountPerPeriod = alignedProxy.initialAmountPerPeriod;
2913
- this.initialPrice = getNumberFromBN(alignedProxy.initialPrice, ALIGNED_PRECISION_FACTOR_POW);
2914
- this.lastPrice = getNumberFromBN(alignedProxy.lastPrice, ALIGNED_PRECISION_FACTOR_POW);
2915
- this.lastAmountUpdateTime = alignedProxy.lastAmountUpdateTime.toNumber();
2916
- this.initialNetAmount = alignedProxy.initialNetAmount;
2917
- this.expiryTime = alignedProxy.expiryTime.toNumber();
2918
- this.expiryPercentage = getNumberFromBN(alignedProxy.expiryPercentage, ALIGNED_PRECISION_FACTOR_POW);
2919
- this.floorPrice = getNumberFromBN(alignedProxy.floorPrice, ALIGNED_PRECISION_FACTOR_POW);
2920
- this.type = buildStreamType(this);
2921
- this.isAligned = true;
2922
- }
2923
- };
322
+
323
+ // solana/layout.ts
2924
324
  var streamLayout = BufferLayout__namespace.struct([
2925
325
  BufferLayout__namespace.blob(8, "magic"),
2926
326
  BufferLayout__namespace.blob(1, "version"),
@@ -3080,20 +480,25 @@ var encodeUpdateStream = (values, data) => {
3080
480
  var topupStreamLayout = BufferLayout__namespace.struct([
3081
481
  BufferLayout__namespace.blob(8, "amount")
3082
482
  ]);
3083
-
3084
- // solana/lib/utils.ts
483
+ var FEE_PRECISION = 4;
484
+ var FEE_NORMALIZER = 10 ** FEE_PRECISION;
485
+ var FEE_MULTIPLIER = new BN3__default.default(10 ** 6);
3085
486
  var decoder = new TextDecoder("utf-8");
3086
487
  var LE = "le";
488
+ var calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
489
+ const totalFeeNormalized = new BN3__default.default(totalFee * FEE_NORMALIZER);
490
+ return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
491
+ };
3087
492
  var decodeStream = (buf) => {
3088
493
  const raw = streamLayout.decode(buf);
3089
494
  return {
3090
- magic: new BN7__default.default(raw.magic, LE),
3091
- version: new BN7__default.default(raw.version, LE),
3092
- createdAt: new BN7__default.default(raw.created_at, LE),
3093
- withdrawnAmount: new BN7__default.default(raw.withdrawn_amount, LE),
3094
- canceledAt: new BN7__default.default(raw.canceled_at, LE),
3095
- end: new BN7__default.default(raw.end_time, LE),
3096
- lastWithdrawnAt: new BN7__default.default(raw.last_withdrawn_at, LE),
495
+ magic: new BN3__default.default(raw.magic, LE),
496
+ version: new BN3__default.default(raw.version, LE),
497
+ createdAt: new BN3__default.default(raw.created_at, LE),
498
+ withdrawnAmount: new BN3__default.default(raw.withdrawn_amount, LE),
499
+ canceledAt: new BN3__default.default(raw.canceled_at, LE),
500
+ end: new BN3__default.default(raw.end_time, LE),
501
+ lastWithdrawnAt: new BN3__default.default(raw.last_withdrawn_at, LE),
3097
502
  sender: new web3_js.PublicKey(raw.sender),
3098
503
  senderTokens: new web3_js.PublicKey(raw.sender_tokens),
3099
504
  recipient: new web3_js.PublicKey(raw.recipient),
@@ -3102,20 +507,20 @@ var decodeStream = (buf) => {
3102
507
  escrowTokens: new web3_js.PublicKey(raw.escrow_tokens),
3103
508
  streamflowTreasury: new web3_js.PublicKey(raw.streamflow_treasury),
3104
509
  streamflowTreasuryTokens: new web3_js.PublicKey(raw.streamflow_treasury_tokens),
3105
- streamflowFeeTotal: new BN7__default.default(raw.streamflow_fee_total, LE),
3106
- streamflowFeeWithdrawn: new BN7__default.default(raw.streamflow_fee_withdrawn, LE),
510
+ streamflowFeeTotal: new BN3__default.default(raw.streamflow_fee_total, LE),
511
+ streamflowFeeWithdrawn: new BN3__default.default(raw.streamflow_fee_withdrawn, LE),
3107
512
  streamflowFeePercent: raw.streamflow_fee_percent,
3108
- partnerFeeTotal: new BN7__default.default(raw.partner_fee_total, LE),
3109
- partnerFeeWithdrawn: new BN7__default.default(raw.partner_fee_withdrawn, LE),
513
+ partnerFeeTotal: new BN3__default.default(raw.partner_fee_total, LE),
514
+ partnerFeeWithdrawn: new BN3__default.default(raw.partner_fee_withdrawn, LE),
3110
515
  partnerFeePercent: raw.partner_fee_percent,
3111
516
  partner: new web3_js.PublicKey(raw.partner),
3112
517
  partnerTokens: new web3_js.PublicKey(raw.partner_tokens),
3113
- start: new BN7__default.default(raw.start_time, LE),
3114
- depositedAmount: new BN7__default.default(raw.net_amount_deposited, LE),
3115
- period: new BN7__default.default(raw.period, LE),
3116
- amountPerPeriod: new BN7__default.default(raw.amount_per_period, LE),
3117
- cliff: new BN7__default.default(raw.cliff, LE),
3118
- cliffAmount: new BN7__default.default(raw.cliff_amount, LE),
518
+ start: new BN3__default.default(raw.start_time, LE),
519
+ depositedAmount: new BN3__default.default(raw.net_amount_deposited, LE),
520
+ period: new BN3__default.default(raw.period, LE),
521
+ amountPerPeriod: new BN3__default.default(raw.amount_per_period, LE),
522
+ cliff: new BN3__default.default(raw.cliff, LE),
523
+ cliffAmount: new BN3__default.default(raw.cliff_amount, LE),
3119
524
  cancelableBySender: Boolean(raw.cancelable_by_sender),
3120
525
  cancelableByRecipient: Boolean(raw.cancelable_by_recipient),
3121
526
  automaticWithdrawal: Boolean(raw.automatic_withdrawal),
@@ -3123,17 +528,17 @@ var decodeStream = (buf) => {
3123
528
  transferableByRecipient: Boolean(raw.transferable_by_recipient),
3124
529
  canTopup: Boolean(raw.can_topup),
3125
530
  name: decoder.decode(raw.stream_name),
3126
- withdrawFrequency: new BN7__default.default(raw.withdraw_frequency, LE),
531
+ withdrawFrequency: new BN3__default.default(raw.withdraw_frequency, LE),
3127
532
  closed: Boolean(raw.closed),
3128
- currentPauseStart: new BN7__default.default(raw.current_pause_start, LE),
3129
- pauseCumulative: new BN7__default.default(raw.pause_cumulative, LE),
3130
- lastRateChangeTime: new BN7__default.default(raw.last_rate_change_time, LE),
3131
- fundsUnlockedAtLastRateChange: new BN7__default.default(raw.funds_unlocked_at_last_rate_change, LE)
533
+ currentPauseStart: new BN3__default.default(raw.current_pause_start, LE),
534
+ pauseCumulative: new BN3__default.default(raw.pause_cumulative, LE),
535
+ lastRateChangeTime: new BN3__default.default(raw.last_rate_change_time, LE),
536
+ fundsUnlockedAtLastRateChange: new BN3__default.default(raw.funds_unlocked_at_last_rate_change, LE)
3132
537
  };
3133
538
  };
3134
539
  async function signAllTransactionWithRecipients(sender, items) {
3135
- const isKeypair = solana.isSignerKeypair(sender);
3136
- const isWallet = solana.isSignerWallet(sender);
540
+ const isKeypair = common.isSignerKeypair(sender);
541
+ const isWallet = common.isSignerWallet(sender);
3137
542
  if (isKeypair) {
3138
543
  return items.map((t) => {
3139
544
  t.tx.sign([sender]);
@@ -3151,7 +556,7 @@ async function signAllTransactionWithRecipients(sender, items) {
3151
556
  }
3152
557
  async function sendAndConfirmStreamRawTransaction(connection, batchItem, confirmationParams, throttleParams) {
3153
558
  try {
3154
- const completedTxSignature = await solana.executeTransaction(connection, batchItem.tx, confirmationParams, throttleParams);
559
+ const completedTxSignature = await common.executeTransaction(connection, batchItem.tx, confirmationParams, throttleParams);
3155
560
  return { ...batchItem, signature: completedTxSignature };
3156
561
  } catch (error) {
3157
562
  throw {
@@ -3160,6 +565,19 @@ async function sendAndConfirmStreamRawTransaction(connection, batchItem, confirm
3160
565
  };
3161
566
  }
3162
567
  }
568
+ async function handleContractError(func, callback) {
569
+ try {
570
+ return await func();
571
+ } catch (err) {
572
+ if (err instanceof Error) {
573
+ if (callback) {
574
+ throw new common.ContractError(err, callback(err));
575
+ }
576
+ throw new common.ContractError(err);
577
+ }
578
+ throw err;
579
+ }
580
+ }
3163
581
  function extractSolanaErrorCode(errorText, logs) {
3164
582
  let match = SOLANA_ERROR_MATCH_REGEX.exec(errorText);
3165
583
  if (!match && logs) {
@@ -5002,18 +2420,17 @@ var deriveTestOraclePDA = (programId, mint, creator) => {
5002
2420
  // solana/StreamClient.ts
5003
2421
  var METADATA_ACC_SIZE = 1104;
5004
2422
  var ALIGNED_METADATA_ACC_SIZE = 320;
5005
- var SolanaStreamClient = class extends BaseStreamClient {
2423
+ var SolanaStreamClient = class {
5006
2424
  /**
5007
2425
  * Create Stream instance
5008
2426
  */
5009
2427
  constructor(optionsOrClusterUrl, cluster = common.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
5010
- super();
5011
2428
  if (typeof optionsOrClusterUrl === "string") {
5012
2429
  this.commitment = commitment;
5013
2430
  this.connection = new web3_js.Connection(optionsOrClusterUrl, this.commitment);
5014
2431
  this.programId = programId !== "" ? new web3_js.PublicKey(programId) : new web3_js.PublicKey(PROGRAM_ID[cluster]);
5015
2432
  this.schedulingParams = {
5016
- sendThrottler: sendThrottler ?? solana.buildSendThrottler(sendRate)
2433
+ sendThrottler: sendThrottler ?? common.buildSendThrottler(sendRate)
5017
2434
  };
5018
2435
  } else {
5019
2436
  const {
@@ -5027,7 +2444,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5027
2444
  this.connection = new web3_js.Connection(clusterUrl, this.commitment);
5028
2445
  this.programId = programId2 !== "" ? new web3_js.PublicKey(programId2) : new web3_js.PublicKey(PROGRAM_ID[cluster2]);
5029
2446
  const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : void 0;
5030
- const sendThrottler2 = !sendScheduler ? solana.buildSendThrottler(1) : "sendRate" in sendScheduler ? solana.buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval) : sendScheduler;
2447
+ const sendThrottler2 = !sendScheduler ? common.buildSendThrottler(1) : "sendRate" in sendScheduler ? common.buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval) : sendScheduler;
5031
2448
  this.schedulingParams = {
5032
2449
  ...schedulingOptions,
5033
2450
  sendThrottler: sendThrottler2
@@ -5059,7 +2476,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5059
2476
  * (before stream creation) to ensure the WSOL account exists when the stream creation instruction executes.
5060
2477
  *
5061
2478
  * @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
5062
- * @param {Omit<ICreateStreamSolanaExt, "sender"> & { senderPublicKey: PublicKey }} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2479
+ * @param {Omit<ICreateStreamExt, "sender"> & { senderPublicKey: PublicKey }} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
5063
2480
  * @returns Transaction instructions and metadata ID
5064
2481
  */
5065
2482
  async buildCreateTransactionInstructions(data, extParams) {
@@ -5080,7 +2497,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5080
2497
  address: partnerPublicKey.toString()
5081
2498
  });
5082
2499
  const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
5083
- ixs.push(...await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
2500
+ ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
5084
2501
  }
5085
2502
  const {
5086
2503
  ixs: createIxs,
@@ -5106,13 +2523,13 @@ var SolanaStreamClient = class extends BaseStreamClient {
5106
2523
  * (before stream creation) to ensure the WSOL account exists when the stream creation instruction executes.
5107
2524
  *
5108
2525
  * @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
5109
- * @param {Omit<ICreateStreamSolanaExt, "sender"> & { senderPublicKey: PublicKey }} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2526
+ * @param {Omit<ICreateStreamExt, "sender"> & { senderPublicKey: PublicKey }} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
5110
2527
  * @returns Transaction and metadata information
5111
2528
  */
5112
2529
  async buildCreateTransaction(data, extParams) {
5113
2530
  const { sender } = extParams;
5114
2531
  const { ixs, metadataId, metadata } = await this.buildCreateTransactionInstructions(data, extParams);
5115
- const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, sender.publicKey, void 0, [
2532
+ const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, sender.publicKey, void 0, [
5116
2533
  metadata
5117
2534
  ]);
5118
2535
  return {
@@ -5127,7 +2544,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5127
2544
  * Creates a new stream/vesting contract.
5128
2545
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
5129
2546
  * @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
5130
- * @param {ICreateStreamSolanaExt} extParams - Transaction configuration including sender wallet, native token handling, and compute settings
2547
+ * @param {ICreateStreamExt} extParams - Transaction configuration including sender wallet, native token handling, and compute settings
5131
2548
  * @returns Create result
5132
2549
  */
5133
2550
  async create(data, extParams) {
@@ -5137,10 +2554,10 @@ var SolanaStreamClient = class extends BaseStreamClient {
5137
2554
  ...extParams,
5138
2555
  sender
5139
2556
  });
5140
- const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, sender.publicKey, void 0, [
2557
+ const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, sender.publicKey, void 0, [
5141
2558
  metadata
5142
2559
  ]);
5143
- const signature = await solana.signAndExecuteTransaction(
2560
+ const signature = await common.signAndExecuteTransaction(
5144
2561
  this.connection,
5145
2562
  sender,
5146
2563
  tx,
@@ -5197,13 +2614,13 @@ var SolanaStreamClient = class extends BaseStreamClient {
5197
2614
  common.invariant(metadataPubKey, "Metadata public key is required");
5198
2615
  let tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : void 0;
5199
2616
  if (!tokenProgramId) {
5200
- tokenProgramId = (await solana.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
2617
+ tokenProgramId = (await common.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
5201
2618
  }
5202
2619
  const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
5203
2620
  const streamflowProgramPublicKey = new web3_js.PublicKey(this.programId);
5204
2621
  const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
5205
2622
  const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
5206
- const ixs = solana.prepareBaseInstructions(this.connection, {
2623
+ const ixs = common.prepareBaseInstructions(this.connection, {
5207
2624
  computePrice,
5208
2625
  computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT
5209
2626
  });
@@ -5215,11 +2632,11 @@ var SolanaStreamClient = class extends BaseStreamClient {
5215
2632
  const encodedUIntArray = new TextEncoder().encode(streamName);
5216
2633
  const streamNameArray = Array.from(encodedUIntArray);
5217
2634
  const createIx = await this.alignedProxyProgram.methods.create({
5218
- startTime: new BN7__default.default(start),
2635
+ startTime: new BN3__default.default(start),
5219
2636
  netAmountDeposited: depositedAmount,
5220
- period: new BN7__default.default(period),
2637
+ period: new BN3__default.default(period),
5221
2638
  amountPerPeriod,
5222
- cliff: new BN7__default.default(cliff),
2639
+ cliff: new BN3__default.default(cliff),
5223
2640
  cliffAmount,
5224
2641
  transferableBySender,
5225
2642
  transferableByRecipient,
@@ -5228,15 +2645,15 @@ var SolanaStreamClient = class extends BaseStreamClient {
5228
2645
  canTopup,
5229
2646
  oracleType: !!oracleType ? { [oracleType]: {} } : { none: {} },
5230
2647
  streamName: streamNameArray,
5231
- minPrice: typeof minPrice === "number" ? common.getBN(minPrice, ALIGNED_PRECISION_FACTOR_POW) : minPrice,
5232
- maxPrice: typeof maxPrice === "number" ? common.getBN(maxPrice, ALIGNED_PRECISION_FACTOR_POW) : maxPrice,
5233
- minPercentage: typeof minPercentage === "number" ? common.getBN(minPercentage, ALIGNED_PRECISION_FACTOR_POW) : minPercentage,
5234
- maxPercentage: typeof maxPercentage === "number" ? common.getBN(maxPercentage, ALIGNED_PRECISION_FACTOR_POW) : maxPercentage,
5235
- tickSize: new BN7__default.default(tickSize || 1),
2648
+ minPrice: typeof minPrice === "number" ? common.getBN(minPrice, ALIGNED_PRECISION_FACTOR_POW2) : minPrice,
2649
+ maxPrice: typeof maxPrice === "number" ? common.getBN(maxPrice, ALIGNED_PRECISION_FACTOR_POW2) : maxPrice,
2650
+ minPercentage: typeof minPercentage === "number" ? common.getBN(minPercentage, ALIGNED_PRECISION_FACTOR_POW2) : minPercentage,
2651
+ maxPercentage: typeof maxPercentage === "number" ? common.getBN(maxPercentage, ALIGNED_PRECISION_FACTOR_POW2) : maxPercentage,
2652
+ tickSize: new BN3__default.default(tickSize || 1),
5236
2653
  skipInitial: skipInitial ?? false,
5237
- expiryTime: new BN7__default.default(expiryTime ?? 0),
5238
- expiryPercentage: typeof expiryPercentage === "number" ? common.getBN(expiryPercentage, ALIGNED_PRECISION_FACTOR_POW) : expiryPercentage ?? new BN7__default.default(0),
5239
- floorPrice: typeof floorPrice === "number" ? common.getBN(floorPrice, ALIGNED_PRECISION_FACTOR_POW) : floorPrice ?? new BN7__default.default(0)
2654
+ expiryTime: new BN3__default.default(expiryTime ?? 0),
2655
+ expiryPercentage: typeof expiryPercentage === "number" ? common.getBN(expiryPercentage, ALIGNED_PRECISION_FACTOR_POW2) : expiryPercentage ?? new BN3__default.default(0),
2656
+ floorPrice: typeof floorPrice === "number" ? common.getBN(floorPrice, ALIGNED_PRECISION_FACTOR_POW2) : floorPrice ?? new BN3__default.default(0)
5240
2657
  }).accountsPartial({
5241
2658
  payer: sender.publicKey,
5242
2659
  sender: sender.publicKey,
@@ -5258,7 +2675,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5258
2675
  * Creates a new stream/vesting contract.
5259
2676
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
5260
2677
  * @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
5261
- * @param {IPrepareCreateStreamSolanaExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
2678
+ * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
5262
2679
  * @returns Create stream instructions
5263
2680
  */
5264
2681
  async prepareCreateStreamInstructions({
@@ -5284,7 +2701,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5284
2701
  tokenProgramId: streamTokenProgramId
5285
2702
  }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
5286
2703
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
5287
- const ixs = solana.prepareBaseInstructions(this.connection, {
2704
+ const ixs = common.prepareBaseInstructions(this.connection, {
5288
2705
  computePrice,
5289
2706
  computeLimit
5290
2707
  });
@@ -5297,22 +2714,22 @@ var SolanaStreamClient = class extends BaseStreamClient {
5297
2714
  );
5298
2715
  let tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : void 0;
5299
2716
  if (!tokenProgramId) {
5300
- tokenProgramId = (await solana.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
2717
+ tokenProgramId = (await common.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
5301
2718
  }
5302
- const senderTokens = await solana.ata(mintPublicKey, sender.publicKey, tokenProgramId);
5303
- const recipientTokens = await solana.ata(mintPublicKey, recipientPublicKey, tokenProgramId);
5304
- const streamflowTreasuryTokens = await solana.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2719
+ const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2720
+ const recipientTokens = await common.ata(mintPublicKey, recipientPublicKey, tokenProgramId);
2721
+ const streamflowTreasuryTokens = await common.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
5305
2722
  const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
5306
- const partnerTokens = await solana.ata(mintPublicKey, partnerPublicKey, tokenProgramId);
2723
+ const partnerTokens = await common.ata(mintPublicKey, partnerPublicKey, tokenProgramId);
5307
2724
  ixs.push(
5308
2725
  await createStreamInstruction(
5309
2726
  {
5310
- start: new BN7__default.default(start),
2727
+ start: new BN3__default.default(start),
5311
2728
  depositedAmount,
5312
- period: new BN7__default.default(period),
2729
+ period: new BN3__default.default(period),
5313
2730
  amountPerPeriod,
5314
- cliff: new BN7__default.default(cliff),
5315
- cliffAmount: new BN7__default.default(cliffAmount),
2731
+ cliff: new BN3__default.default(cliff),
2732
+ cliffAmount: new BN3__default.default(cliffAmount),
5316
2733
  cancelableBySender,
5317
2734
  cancelableByRecipient,
5318
2735
  automaticWithdrawal,
@@ -5322,7 +2739,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5322
2739
  canUpdateRate: !!canUpdateRate,
5323
2740
  canPause: !!canPause,
5324
2741
  name,
5325
- withdrawFrequency: new BN7__default.default(automaticWithdrawal ? withdrawalFrequency : period)
2742
+ withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period)
5326
2743
  },
5327
2744
  this.programId,
5328
2745
  {
@@ -5359,7 +2776,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5359
2776
  *
5360
2777
  * If you are not sure if you should use create or create_unchecked, go for create to be safer.
5361
2778
  * @param {ICreateStreamData} data - Stream parameters including recipient, token, amount, schedule, and permissions
5362
- * @param {ICreateStreamSolanaExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
2779
+ * @param {ICreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
5363
2780
  * @returns Create result
5364
2781
  */
5365
2782
  async createUnchecked(data, extParams) {
@@ -5367,14 +2784,14 @@ var SolanaStreamClient = class extends BaseStreamClient {
5367
2784
  data,
5368
2785
  extParams
5369
2786
  );
5370
- const { tx, hash, context } = await solana.prepareTransaction(
2787
+ const { tx, hash, context } = await common.prepareTransaction(
5371
2788
  this.connection,
5372
2789
  ixs,
5373
2790
  extParams.sender.publicKey,
5374
2791
  void 0,
5375
2792
  [metadata]
5376
2793
  );
5377
- const signature = await solana.signAndExecuteTransaction(
2794
+ const signature = await common.signAndExecuteTransaction(
5378
2795
  this.connection,
5379
2796
  extParams.sender,
5380
2797
  tx,
@@ -5427,26 +2844,26 @@ var SolanaStreamClient = class extends BaseStreamClient {
5427
2844
  [buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
5428
2845
  this.programId
5429
2846
  );
5430
- const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mintPublicKey);
5431
- const senderTokens = await solana.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2847
+ const { tokenProgramId } = await common.getMintAndProgram(this.connection, mintPublicKey);
2848
+ const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
5432
2849
  const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
5433
- const ixs = solana.prepareBaseInstructions(this.connection, {
2850
+ const ixs = common.prepareBaseInstructions(this.connection, {
5434
2851
  computePrice,
5435
2852
  computeLimit
5436
2853
  });
5437
2854
  if (isNative) {
5438
2855
  const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
5439
2856
  const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
5440
- ixs.push(...await solana.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
2857
+ ixs.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
5441
2858
  }
5442
2859
  const createInstruction = await createUncheckedStreamInstruction(
5443
2860
  {
5444
- start: new BN7__default.default(start),
2861
+ start: new BN3__default.default(start),
5445
2862
  depositedAmount,
5446
- period: new BN7__default.default(period),
2863
+ period: new BN3__default.default(period),
5447
2864
  amountPerPeriod,
5448
- cliff: new BN7__default.default(cliff),
5449
- cliffAmount: new BN7__default.default(cliffAmount),
2865
+ cliff: new BN3__default.default(cliff),
2866
+ cliffAmount: new BN3__default.default(cliffAmount),
5450
2867
  cancelableBySender,
5451
2868
  cancelableByRecipient,
5452
2869
  automaticWithdrawal,
@@ -5456,7 +2873,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5456
2873
  canUpdateRate: !!canUpdateRate,
5457
2874
  canPause: !!canPause,
5458
2875
  name,
5459
- withdrawFrequency: new BN7__default.default(automaticWithdrawal ? withdrawalFrequency : period),
2876
+ withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period),
5460
2877
  recipient: recipientPublicKey,
5461
2878
  partner: partnerPublicKey
5462
2879
  },
@@ -5482,7 +2899,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5482
2899
  * Builds transaction instructions for creating multiple stream/vesting contracts without creating transactions.
5483
2900
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
5484
2901
  * @param {ICreateMultipleStreamData} data - Stream base parameters and array of recipients with individual amounts and settings
5485
- * @param {IPrepareCreateStreamSolanaExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2902
+ * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
5486
2903
  * @returns Create multiple transaction instructions
5487
2904
  */
5488
2905
  async buildCreateMultipleTransactionInstructions(data, extParams) {
@@ -5525,8 +2942,8 @@ var SolanaStreamClient = class extends BaseStreamClient {
5525
2942
  true
5526
2943
  );
5527
2944
  if (isNative) {
5528
- const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN7__default.default(0));
5529
- const nativeInstructions = await solana.prepareWrappedAccount(
2945
+ const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN3__default.default(0));
2946
+ const nativeInstructions = await common.prepareWrappedAccount(
5530
2947
  this.connection,
5531
2948
  sender.publicKey,
5532
2949
  totalDepositedAmount
@@ -5563,7 +2980,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5563
2980
  * ```
5564
2981
  *
5565
2982
  * @param {ICreateMultipleStreamData} data - Stream base parameters and array of recipients with individual amounts and settings
5566
- * @param {IPrepareCreateStreamSolanaExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2983
+ * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
5567
2984
  * @returns Multiple transaction information
5568
2985
  */
5569
2986
  async buildCreateMultipleTransactions(data, extParams) {
@@ -5572,11 +2989,11 @@ var SolanaStreamClient = class extends BaseStreamClient {
5572
2989
  const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
5573
2990
  const batch = [];
5574
2991
  for (const { ixs, metadata, recipient } of instructionsBatch) {
5575
- batch.push({ tx: solana.createVersionedTransaction(ixs, sender.publicKey, hash.blockhash, [metadata]), recipient });
2992
+ batch.push({ tx: common.createVersionedTransaction(ixs, sender.publicKey, hash.blockhash, [metadata]), recipient });
5576
2993
  }
5577
2994
  let prepareTx;
5578
2995
  if (prepareInstructions.length > 0) {
5579
- prepareTx = solana.createVersionedTransaction(prepareInstructions, sender.publicKey, hash.blockhash);
2996
+ prepareTx = common.createVersionedTransaction(prepareInstructions, sender.publicKey, hash.blockhash);
5580
2997
  }
5581
2998
  return {
5582
2999
  transactions: batch,
@@ -5591,7 +3008,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5591
3008
  * Creates multiple stream/vesting contracts.
5592
3009
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
5593
3010
  * @param {ICreateMultipleStreamData} data - Stream base parameters and array of recipients with individual amounts and settings
5594
- * @param {ICreateStreamSolanaExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
3011
+ * @param {ICreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
5595
3012
  * @returns Multiple transaction information
5596
3013
  */
5597
3014
  async createMultiple(data, extParams) {
@@ -5606,11 +3023,11 @@ var SolanaStreamClient = class extends BaseStreamClient {
5606
3023
  const batch = [];
5607
3024
  const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
5608
3025
  for (const { ixs, metadata, recipient } of instructionsBatch) {
5609
- batch.push({ tx: solana.createVersionedTransaction(ixs, sender.publicKey, hash.blockhash, [metadata]), recipient });
3026
+ batch.push({ tx: common.createVersionedTransaction(ixs, sender.publicKey, hash.blockhash, [metadata]), recipient });
5610
3027
  }
5611
3028
  if (prepareInstructions.length > 0) {
5612
3029
  batch.push({
5613
- tx: solana.createVersionedTransaction(prepareInstructions, sender.publicKey, hash.blockhash),
3030
+ tx: common.createVersionedTransaction(prepareInstructions, sender.publicKey, hash.blockhash),
5614
3031
  recipient: sender.publicKey.toBase58()
5615
3032
  });
5616
3033
  }
@@ -5624,13 +3041,13 @@ var SolanaStreamClient = class extends BaseStreamClient {
5624
3041
  for (const batchTx of signedBatch) {
5625
3042
  responses.push(
5626
3043
  ...await Promise.allSettled([
5627
- solana.executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams)
3044
+ common.executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams)
5628
3045
  ])
5629
3046
  );
5630
3047
  }
5631
3048
  } else {
5632
3049
  responses.push(
5633
- ...await solana.executeMultipleTransactions(
3050
+ ...await common.executeMultipleTransactions(
5634
3051
  this.connection,
5635
3052
  signedBatch.map((item) => item.tx),
5636
3053
  { hash, context },
@@ -5656,7 +3073,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5656
3073
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
5657
3074
  * In most cases, createMultiple should be used instead.
5658
3075
  * @param {ICreateMultipleStreamData} data - Stream base parameters and array of recipients with individual amounts and settings
5659
- * @param {ICreateStreamSolanaExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
3076
+ * @param {ICreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
5660
3077
  * @returns Multiple transaction information
5661
3078
  */
5662
3079
  async createMultipleSequential(data, extParams) {
@@ -5702,7 +3119,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5702
3119
  for (const batchTx of signedBatch) {
5703
3120
  responses.push(
5704
3121
  ...await Promise.allSettled([
5705
- solana.executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams)
3122
+ common.executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams)
5706
3123
  ])
5707
3124
  );
5708
3125
  }
@@ -5722,7 +3139,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5722
3139
  /**
5723
3140
  * Attempts withdrawing from the specified stream.
5724
3141
  * @param {IWithdrawData} withdrawData - Withdrawal parameters including stream ID and amount to withdraw
5725
- * @param {IInteractStreamSolanaExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3142
+ * @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
5726
3143
  * @returns Transaction result
5727
3144
  */
5728
3145
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
@@ -5734,8 +3151,8 @@ var SolanaStreamClient = class extends BaseStreamClient {
5734
3151
  );
5735
3152
  const metadata = new web3_js.PublicKey(id);
5736
3153
  await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
5737
- const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, invoker.publicKey);
5738
- const signature = await solana.signAndExecuteTransaction(
3154
+ const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, invoker.publicKey);
3155
+ const signature = await common.signAndExecuteTransaction(
5739
3156
  this.connection,
5740
3157
  extParams.invoker,
5741
3158
  tx,
@@ -5751,12 +3168,12 @@ var SolanaStreamClient = class extends BaseStreamClient {
5751
3168
  /**
5752
3169
  * Creates Transaction Instructions for withdrawal
5753
3170
  * @param {IWithdrawData} withdrawData - Withdrawal parameters including stream ID and amount to withdraw
5754
- * @param {IPrepareStreamSolanaExt} extParams - Transaction configuration including invoker wallet address, token account validation, and compute settings
3171
+ * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet address, token account validation, and compute settings
5755
3172
  * @returns Transaction instructions
5756
3173
  */
5757
3174
  async prepareWithdrawInstructions({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
5758
3175
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
5759
- const ixs = solana.prepareBaseInstructions(this.connection, {
3176
+ const ixs = common.prepareBaseInstructions(this.connection, {
5760
3177
  computePrice,
5761
3178
  computeLimit
5762
3179
  });
@@ -5765,9 +3182,9 @@ var SolanaStreamClient = class extends BaseStreamClient {
5765
3182
  common.invariant(escrow?.data, "Couldn't get account info");
5766
3183
  const data = decodeStream(escrow.data);
5767
3184
  const { sender, recipient, mint, streamflowTreasury, partner, recipientTokens, escrowTokens } = data;
5768
- const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
5769
- const streamflowTreasuryTokens = await solana.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
5770
- const partnerTokens = await solana.ata(mint, partner, tokenProgramId);
3185
+ const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3186
+ const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3187
+ const partnerTokens = await common.ata(mint, partner, tokenProgramId);
5771
3188
  const ataIx = await this.getCreateATAInstructions(
5772
3189
  [sender, recipient, streamflowTreasury, partner],
5773
3190
  mint,
@@ -5796,13 +3213,13 @@ var SolanaStreamClient = class extends BaseStreamClient {
5796
3213
  /**
5797
3214
  * Attempts canceling the specified stream.
5798
3215
  * @param {ICancelData} cancelData - Cancellation parameters including stream ID
5799
- * @param {IInteractStreamSolanaExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3216
+ * @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
5800
3217
  * @returns Transaction result
5801
3218
  */
5802
3219
  async cancel(cancelData, extParams) {
5803
3220
  const ixs = await this.prepareCancelInstructions(cancelData, extParams);
5804
- const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
5805
- const signature = await solana.signAndExecuteTransaction(
3221
+ const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
3222
+ const signature = await common.signAndExecuteTransaction(
5806
3223
  this.connection,
5807
3224
  extParams.invoker,
5808
3225
  tx,
@@ -5818,7 +3235,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5818
3235
  /**
5819
3236
  * Creates Transaction Instructions for cancel
5820
3237
  * @param {ICancelData} cancelData - Cancellation parameters including stream ID
5821
- * @param {IPrepareStreamSolanaExt} extParams - Transaction configuration including invoker wallet address, token account validation, and compute settings
3238
+ * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet address, token account validation, and compute settings
5822
3239
  * @returns Transaction instructions
5823
3240
  */
5824
3241
  async prepareCancelInstructions(cancelData, extParams) {
@@ -5835,7 +3252,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5835
3252
  /**
5836
3253
  * Creates Transaction Instructions for cancel
5837
3254
  * @param {ICancelData} cancelData - Cancellation parameters including stream ID
5838
- * @param {IPrepareStreamSolanaExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3255
+ * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
5839
3256
  * @returns Transaction instructions
5840
3257
  */
5841
3258
  async prepareCancelAlignedUnlockInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
@@ -5845,8 +3262,8 @@ var SolanaStreamClient = class extends BaseStreamClient {
5845
3262
  common.invariant(escrowAcc?.data, "Couldn't get account info");
5846
3263
  const streamData = decodeStream(escrowAcc.data);
5847
3264
  const { sender, recipient, mint, streamflowTreasury, partner, escrowTokens } = streamData;
5848
- const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
5849
- const ixs = solana.prepareBaseInstructions(this.connection, {
3265
+ const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3266
+ const ixs = common.prepareBaseInstructions(this.connection, {
5850
3267
  computePrice,
5851
3268
  computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT
5852
3269
  });
@@ -5874,7 +3291,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
5874
3291
  /**
5875
3292
  * Creates Transaction Instructions for cancel
5876
3293
  * @param {ICancelData} cancelData - Cancellation parameters including stream ID
5877
- * @param {IPrepareStreamSolanaExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3294
+ * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
5878
3295
  * @returns Transaction instructions
5879
3296
  */
5880
3297
  async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
@@ -5884,10 +3301,10 @@ var SolanaStreamClient = class extends BaseStreamClient {
5884
3301
  common.invariant(escrowAcc?.data, "Couldn't get account info");
5885
3302
  const data = decodeStream(escrowAcc.data);
5886
3303
  const { sender, recipient, partner, streamflowTreasury, mint, senderTokens, recipientTokens, escrowTokens } = data;
5887
- const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
5888
- const streamflowTreasuryTokens = await solana.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
5889
- const partnerTokens = await solana.ata(mint, partner, tokenProgramId);
5890
- const ixs = solana.prepareBaseInstructions(this.connection, {
3304
+ const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3305
+ const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3306
+ const partnerTokens = await common.ata(mint, partner, tokenProgramId);
3307
+ const ixs = common.prepareBaseInstructions(this.connection, {
5891
3308
  computePrice,
5892
3309
  computeLimit
5893
3310
  });
@@ -5922,13 +3339,13 @@ var SolanaStreamClient = class extends BaseStreamClient {
5922
3339
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
5923
3340
  * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
5924
3341
  * @param {ITransferData} transferData - Transfer parameters including stream ID and new recipient address
5925
- * @param {IInteractStreamSolanaExt} extParams - Transaction configuration including invoker wallet and compute settings
3342
+ * @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
5926
3343
  * @returns Transaction result
5927
3344
  */
5928
3345
  async transfer({ id, newRecipient }, extParams) {
5929
3346
  const ixs = await this.prepareTransferInstructions({ id, newRecipient }, extParams);
5930
- const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
5931
- const signature = await solana.signAndExecuteTransaction(
3347
+ const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
3348
+ const signature = await common.signAndExecuteTransaction(
5932
3349
  this.connection,
5933
3350
  extParams.invoker,
5934
3351
  tx,
@@ -5945,12 +3362,12 @@ var SolanaStreamClient = class extends BaseStreamClient {
5945
3362
  * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
5946
3363
  * Potential associated token account rent fee (to make it rent-exempt) is paid by the transaction initiator.
5947
3364
  * @param {ITransferData} transferData - Transfer parameters including stream ID and new recipient address
5948
- * @param {IPrepareStreamSolanaExt} extParams - Transaction configuration including invoker wallet and compute settings
3365
+ * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
5949
3366
  * @returns Transaction instructions
5950
3367
  */
5951
3368
  async prepareTransferInstructions({ id, newRecipient }, { invoker, computePrice, computeLimit = 100001 }) {
5952
3369
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
5953
- const ixs = solana.prepareBaseInstructions(this.connection, {
3370
+ const ixs = common.prepareBaseInstructions(this.connection, {
5954
3371
  computePrice,
5955
3372
  computeLimit
5956
3373
  });
@@ -5959,8 +3376,8 @@ var SolanaStreamClient = class extends BaseStreamClient {
5959
3376
  const escrow = await this.connection.getAccountInfo(stream);
5960
3377
  common.invariant(escrow?.data, "Couldn't get account info");
5961
3378
  const { mint } = decodeStream(escrow?.data);
5962
- const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
5963
- const newRecipientTokens = await solana.ata(mint, newRecipientPublicKey, tokenProgramId);
3379
+ const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3380
+ const newRecipientTokens = await common.ata(mint, newRecipientPublicKey, tokenProgramId);
5964
3381
  ixs.push(
5965
3382
  await transferStreamInstruction(this.programId, {
5966
3383
  authority: invoker.publicKey,
@@ -5979,13 +3396,13 @@ var SolanaStreamClient = class extends BaseStreamClient {
5979
3396
  /**
5980
3397
  * Tops up stream account with specified amount.
5981
3398
  * @param {ITopUpData} topupData - Top-up parameters including stream ID and amount to add
5982
- * @param {ITopUpStreamSolanaExt} extParams - Transaction configuration including invoker wallet, native token handling, and compute settings
3399
+ * @param {ITopUpStreamExt} extParams - Transaction configuration including invoker wallet, native token handling, and compute settings
5983
3400
  * @returns Transaction result
5984
3401
  */
5985
3402
  async topup({ id, amount }, extParams) {
5986
3403
  const ixs = await this.prepareTopupInstructions({ id, amount }, extParams);
5987
- const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
5988
- const signature = await solana.signAndExecuteTransaction(
3404
+ const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
3405
+ const signature = await common.signAndExecuteTransaction(
5989
3406
  this.connection,
5990
3407
  extParams.invoker,
5991
3408
  tx,
@@ -6001,14 +3418,14 @@ var SolanaStreamClient = class extends BaseStreamClient {
6001
3418
  /**
6002
3419
  * Create Transaction instructions for topup
6003
3420
  * @param {ITopUpData} topupData - Top-up parameters including stream ID and amount to add
6004
- * @param {ITopUpStreamSolanaExt} extParams - Transaction configuration including invoker wallet, native token handling, and compute settings
3421
+ * @param {ITopUpStreamExt} extParams - Transaction configuration including invoker wallet, native token handling, and compute settings
6005
3422
  * @returns Transaction instructions
6006
3423
  */
6007
3424
  async prepareTopupInstructions({ id, amount }, { invoker, isNative, computePrice, computeLimit }) {
6008
3425
  if (!invoker.publicKey) {
6009
3426
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
6010
3427
  }
6011
- const ixs = solana.prepareBaseInstructions(this.connection, {
3428
+ const ixs = common.prepareBaseInstructions(this.connection, {
6012
3429
  computePrice,
6013
3430
  computeLimit
6014
3431
  });
@@ -6018,11 +3435,11 @@ var SolanaStreamClient = class extends BaseStreamClient {
6018
3435
  throw new Error("Couldn't get account info");
6019
3436
  }
6020
3437
  const { mint, partner, senderTokens, escrowTokens } = decodeStream(escrow?.data);
6021
- const { tokenProgramId } = await solana.getMintAndProgram(this.connection, mint);
6022
- const streamflowTreasuryTokens = await solana.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
6023
- const partnerTokens = await solana.ata(mint, partner, tokenProgramId);
3438
+ const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3439
+ const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3440
+ const partnerTokens = await common.ata(mint, partner, tokenProgramId);
6024
3441
  if (isNative) {
6025
- ixs.push(...await solana.prepareWrappedAccount(this.connection, invoker.publicKey, amount));
3442
+ ixs.push(...await common.prepareWrappedAccount(this.connection, invoker.publicKey, amount));
6026
3443
  }
6027
3444
  ixs.push(
6028
3445
  await topupStreamInstruction(amount, this.programId, {
@@ -6063,7 +3480,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
6063
3480
  }
6064
3481
  return new AlignedContract(stream, alignedProxy);
6065
3482
  }
6066
- return new Contract2(stream);
3483
+ return new Contract(stream);
6067
3484
  }
6068
3485
  /**
6069
3486
  * Fetch all aligned outgoing streams/contracts by the provided public key.
@@ -6084,7 +3501,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
6084
3501
  }
6085
3502
  ]);
6086
3503
  const streamPubKeys = alignedOutgoingProgramAccounts.map((account) => account.account.stream);
6087
- const streamAccounts = await solana.getMultipleAccountsInfoBatched(this.connection, streamPubKeys, TX_FINALITY_CONFIRMED);
3504
+ const streamAccounts = await common.getMultipleAccountsInfoBatched(this.connection, streamPubKeys, TX_FINALITY_CONFIRMED);
6088
3505
  streamAccounts.forEach((account, index) => {
6089
3506
  if (account) {
6090
3507
  const alignedData = alignedOutgoingProgramAccounts[index].account;
@@ -6099,7 +3516,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
6099
3516
  const alignedProxyPDAs = alignedStreamsPubKeys.map(
6100
3517
  (streamPubKey) => deriveContractPDA(this.alignedProxyProgram.programId, new web3_js.PublicKey(streamPubKey))
6101
3518
  );
6102
- const alignedProxyAccounts = await solana.getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
3519
+ const alignedProxyAccounts = await common.getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
6103
3520
  alignedProxyAccounts.forEach((account, index) => {
6104
3521
  if (account && account.data.length === ALIGNED_METADATA_ACC_SIZE) {
6105
3522
  const alignedData = streamRecord[alignedStreamsPubKeys[index]];
@@ -6126,14 +3543,14 @@ var SolanaStreamClient = class extends BaseStreamClient {
6126
3543
  let streams = {};
6127
3544
  const shouldFetchAligned = type === "all" /* All */ || type === "vesting" /* Vesting */;
6128
3545
  if (direction !== "incoming" /* Incoming */) {
6129
- const outgoingStreamAccounts = await solana.getProgramAccounts(
3546
+ const outgoingStreamAccounts = await common.getProgramAccounts(
6130
3547
  this.connection,
6131
3548
  publicKey,
6132
3549
  STREAM_STRUCT_OFFSET_SENDER,
6133
3550
  this.programId
6134
3551
  );
6135
3552
  outgoingStreamAccounts.forEach((account) => {
6136
- streams[account.pubkey.toBase58()] = new Contract2(decodeStream(account.account.data));
3553
+ streams[account.pubkey.toBase58()] = new Contract(decodeStream(account.account.data));
6137
3554
  });
6138
3555
  if (shouldFetchAligned) {
6139
3556
  const alignedStreams = await this.getOutgoingAlignedStreams(address);
@@ -6141,7 +3558,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
6141
3558
  }
6142
3559
  }
6143
3560
  if (direction !== "outgoing" /* Outgoing */) {
6144
- const allIncomingAccounts = await solana.getProgramAccounts(
3561
+ const allIncomingAccounts = await common.getProgramAccounts(
6145
3562
  this.connection,
6146
3563
  publicKey,
6147
3564
  STREAM_STRUCT_OFFSET_RECIPIENT,
@@ -6153,7 +3570,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
6153
3570
  if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender)) {
6154
3571
  alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
6155
3572
  } else {
6156
- streams[account.pubkey.toBase58()] = new Contract2(allIncomingStreams[index]);
3573
+ streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
6157
3574
  }
6158
3575
  });
6159
3576
  if (shouldFetchAligned) {
@@ -6183,13 +3600,13 @@ var SolanaStreamClient = class extends BaseStreamClient {
6183
3600
  });
6184
3601
  return accounts.map(({ pubkey, account }) => ({
6185
3602
  publicKey: pubkey,
6186
- account: new Contract2(decodeStream(account.data))
3603
+ account: new Contract(decodeStream(account.data))
6187
3604
  }));
6188
3605
  }
6189
3606
  /**
6190
3607
  * Attempts updating the stream auto withdrawal params and amount per period
6191
3608
  * @param {IUpdateData} data - Update parameters including stream ID and new settings
6192
- * @param {IInteractStreamSolanaExt} extParams - Transaction configuration including invoker wallet and compute settings
3609
+ * @param {IInteractStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
6193
3610
  * @returns Transaction result
6194
3611
  */
6195
3612
  async update(data, extParams) {
@@ -6197,8 +3614,8 @@ var SolanaStreamClient = class extends BaseStreamClient {
6197
3614
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
6198
3615
  }
6199
3616
  const ixs = await this.prepareUpdateInstructions(data, extParams);
6200
- const { tx, hash, context } = await solana.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
6201
- const signature = await solana.signAndExecuteTransaction(
3617
+ const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
3618
+ const signature = await common.signAndExecuteTransaction(
6202
3619
  this.connection,
6203
3620
  extParams.invoker,
6204
3621
  tx,
@@ -6217,7 +3634,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
6217
3634
  /**
6218
3635
  * Create Transaction instructions for update
6219
3636
  * @param {IUpdateData} data - Update parameters including stream ID and new settings
6220
- * @param {IPrepareStreamSolanaExt} extParams - Transaction configuration including invoker wallet and compute settings
3637
+ * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet and compute settings
6221
3638
  * @returns Transaction instructions
6222
3639
  */
6223
3640
  async prepareUpdateInstructions(data, { invoker, computePrice, computeLimit }) {
@@ -6225,7 +3642,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
6225
3642
  const streamPublicKey = new web3_js.PublicKey(data.id);
6226
3643
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
6227
3644
  common.invariant(escrow, "Couldn't get account info");
6228
- const ixs = solana.prepareBaseInstructions(this.connection, {
3645
+ const ixs = common.prepareBaseInstructions(this.connection, {
6229
3646
  computePrice,
6230
3647
  computeLimit
6231
3648
  });
@@ -6270,6 +3687,20 @@ var SolanaStreamClient = class extends BaseStreamClient {
6270
3687
  async getDefaultStreamflowFee() {
6271
3688
  return DEFAULT_STREAMFLOW_FEE;
6272
3689
  }
3690
+ /**
3691
+ * Returns total fee percent, streamflow fees + partner fees
3692
+ * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3693
+ * @param chainSpecificParams additional parameters required by chain client
3694
+ * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3695
+ */
3696
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3697
+ async getTotalFee(getFeesData) {
3698
+ const fees = await this.getFees(getFeesData);
3699
+ if (fees) {
3700
+ return fees.partnerFee + fees.streamflowFee;
3701
+ }
3702
+ return this.getDefaultStreamflowFee();
3703
+ }
6273
3704
  /**
6274
3705
  * Extracts error code from an error
6275
3706
  * @param {Error} err - Error
@@ -6310,7 +3741,7 @@ var SolanaStreamClient = class extends BaseStreamClient {
6310
3741
  const uniqueOwners = Array.from(new Set(owners.map((owner) => owner.toBase58()))).map(
6311
3742
  (pkString) => new web3_js.PublicKey(pkString)
6312
3743
  );
6313
- return solana.checkOrCreateAtaBatch(this.connection, uniqueOwners, mint, invoker, programId);
3744
+ return common.checkOrCreateAtaBatch(this.connection, uniqueOwners, mint, invoker, programId);
6314
3745
  }
6315
3746
  async applyCustomAfterInstructions(ixs, customInstructions, metadata) {
6316
3747
  if (customInstructions?.after) {
@@ -6697,891 +4128,87 @@ var timelockIDL_default = {
6697
4128
  {
6698
4129
  name: "streamflowTreasury",
6699
4130
  isMut: true,
6700
- isSigner: false
6701
- },
6702
- {
6703
- name: "streamflowTreasuryTokens",
6704
- isMut: true,
6705
- isSigner: false
6706
- },
6707
- {
6708
- name: "withdrawor",
6709
- isMut: true,
6710
- isSigner: false
6711
- },
6712
- {
6713
- name: "partner",
6714
- isMut: true,
6715
- isSigner: false
6716
- },
6717
- {
6718
- name: "partnerTokens",
6719
- isMut: true,
6720
- isSigner: false
6721
- },
6722
- {
6723
- name: "mint",
6724
- isMut: false,
6725
- isSigner: false
6726
- },
6727
- {
6728
- name: "tokenProgram",
6729
- isMut: false,
6730
- isSigner: false
6731
- },
6732
- {
6733
- name: "systemProgram",
6734
- isMut: false,
6735
- isSigner: false
6736
- }
6737
- ],
6738
- args: [
6739
- {
6740
- name: "amount",
6741
- type: "u64"
6742
- }
6743
- ]
6744
- }
6745
- ]
6746
- };
6747
-
6748
- // sui/index.ts
6749
- var sui_exports = {};
6750
- __export(sui_exports, {
6751
- Contract: () => Contract3,
6752
- SuiStreamClient: () => SuiStreamClient,
6753
- constants: () => constants_exports4,
6754
- extractSuiErrorInfo: () => extractSuiErrorInfo,
6755
- getTransactionBlock: () => getTransactionBlock
6756
- });
6757
-
6758
- // sui/constants.ts
6759
- var constants_exports4 = {};
6760
- __export(constants_exports4, {
6761
- SUI_CONFIG_IDS: () => SUI_CONFIG_IDS,
6762
- SUI_ERROR_MATCH_REGEX: () => SUI_ERROR_MATCH_REGEX,
6763
- SUI_FEE_TABLE_IDS: () => SUI_FEE_TABLE_IDS,
6764
- SUI_MODULE_ERROR_MAP: () => SUI_MODULE_ERROR_MAP,
6765
- SUI_PROGRAM_IDS: () => SUI_PROGRAM_IDS
6766
- });
6767
- var SUI_PROGRAM_IDS = {
6768
- [common.ICluster.Mainnet]: "0xe456a3a1d4e58e85b4b7175fabe6dae895b983f1379bb8948d6ec2f137b08a7b",
6769
- [common.ICluster.Devnet]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
6770
- [common.ICluster.Testnet]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a",
6771
- [common.ICluster.Local]: "0x34dacd839e1758ebb70bdcd4e08f18fbfef5e2b96d9aa7ce2b4a71d96ca0df5a"
6772
- };
6773
- var SUI_CONFIG_IDS = {
6774
- [common.ICluster.Mainnet]: "0x6cf6760b64245b8d23ef57c28ddceb6adbd540a23a509fef29b82237da4ab87b",
6775
- [common.ICluster.Devnet]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
6776
- [common.ICluster.Testnet]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8",
6777
- [common.ICluster.Local]: "0xd6c9f5074584f58074ce56e3c5cc436d82258ec3285f186a0d6438a60bacdbf8"
6778
- };
6779
- var SUI_FEE_TABLE_IDS = {
6780
- [common.ICluster.Mainnet]: "0xad9b75399632583fb9fcae6b5bcca34e6542ab3bedb630ecbd3f15cb1cc48dbe",
6781
- [common.ICluster.Devnet]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
6782
- [common.ICluster.Testnet]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078",
6783
- [common.ICluster.Local]: "0x6057b093904c5bdfec1067d2b8a4dc35f65bcab03b3029ad716c4882b0f36078"
6784
- };
6785
- var 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+)/;
6786
- var SUI_MODULE_ERROR_MAP = {
6787
- protocol: {
6788
- 1: "ECONTRACT_NOT_INIT" /* ECONTRACT_NOT_INIT */,
6789
- 2: "EBAD_AMOUNT" /* EBAD_AMOUNT */,
6790
- 3: "ENO_PERMISSIONS" /* ENO_PERMISSIONS */,
6791
- 4: "EBADINPUT" /* EBADINPUT */,
6792
- 5: "ECLOSED" /* ECLOSED */,
6793
- 6: "EBAD_INPUT_AMOUNT_PER_PERIOD" /* EBAD_INPUT_AMOUNT_PER_PERIOD */,
6794
- 8: "EBAD_INPUT_UPDATE_RATE" /* EBAD_INPUT_UPDATE_RATE */,
6795
- 9: "EBAD_INPUT_CLIFF_AMOUNT" /* EBAD_INPUT_CLIFF_AMOUNT */,
6796
- 10: "EBAD_INPUT_PERIOD" /* EBAD_INPUT_PERIOD */,
6797
- 11: "EBAD_INPUT_START" /* EBAD_INPUT_START */,
6798
- 13: "EBAD_INSUFFICIENT_WITHDRAWAL_FEES" /* EBAD_INSUFFICIENT_WITHDRAWAL_FEES */,
6799
- 14: "EBAD_INSUFFICIENT_AMOUNT" /* EBAD_INSUFFICIENT_AMOUNT */,
6800
- 15: "EPAUSED" /* EPAUSED */,
6801
- 16: "ENOTPAUSED" /* ENOTPAUSED */
6802
- }
6803
- };
6804
- var Contract3 = class {
6805
- constructor(stream, tokenId) {
6806
- const meta = stream.meta.fields;
6807
- const fees = stream.fees.fields;
6808
- this.magic = 0;
6809
- this.version = parseInt(stream.version);
6810
- this.createdAt = parseInt(stream.created);
6811
- this.withdrawnAmount = new BN7__default.default(stream.withdrawn);
6812
- this.canceledAt = parseInt(stream.canceled_at);
6813
- this.end = parseInt(stream.end);
6814
- this.lastWithdrawnAt = parseInt(stream.last_withdrawn_at);
6815
- this.sender = stream.sender;
6816
- this.senderTokens = stream.sender;
6817
- this.recipient = stream.recipient;
6818
- this.recipientTokens = stream.recipient;
6819
- this.mint = tokenId;
6820
- this.escrowTokens = "";
6821
- this.streamflowTreasury = "";
6822
- this.streamflowTreasuryTokens = "";
6823
- this.streamflowFeeTotal = new BN7__default.default(0);
6824
- this.streamflowFeeWithdrawn = new BN7__default.default(0);
6825
- this.streamflowFeePercent = parseInt(fees.streamflow_fee_percentage) / 1e4;
6826
- this.partnerFeeTotal = new BN7__default.default(0);
6827
- this.partnerFeeWithdrawn = new BN7__default.default(0);
6828
- this.partnerFeePercent = parseInt(fees.partner_fee_percentage) / 1e4;
6829
- this.partner = stream.partner;
6830
- this.partnerTokens = "";
6831
- this.start = parseInt(stream.start);
6832
- this.depositedAmount = new BN7__default.default(stream.amount);
6833
- this.period = parseInt(stream.period);
6834
- this.amountPerPeriod = new BN7__default.default(stream.amount_per_period);
6835
- this.cliff = parseInt(stream.start);
6836
- this.cliffAmount = new BN7__default.default(stream.cliff_amount);
6837
- this.cancelableBySender = meta.cancelable_by_sender;
6838
- this.cancelableByRecipient = meta.cancelable_by_recipient;
6839
- this.automaticWithdrawal = meta.automatic_withdrawal;
6840
- this.transferableBySender = meta.transferable_by_sender;
6841
- this.transferableByRecipient = meta.transferable_by_recipient;
6842
- this.canTopup = meta.can_topup;
6843
- this.name = String.fromCharCode(...meta.contract_name);
6844
- this.withdrawalFrequency = parseInt(meta.withdrawal_frequency);
6845
- this.closed = stream.closed;
6846
- this.currentPauseStart = parseInt(stream.current_pause_start);
6847
- this.pauseCumulative = new BN7__default.default(stream.pause_cumulative);
6848
- this.lastRateChangeTime = parseInt(stream.last_rate_change_time);
6849
- this.fundsUnlockedAtLastRateChange = new BN7__default.default(stream.funds_unlocked_at_last_rate_change);
6850
- this.type = buildStreamType(this);
6851
- }
6852
- unlocked(currentTimestamp) {
6853
- return calculateUnlockedAmount({
6854
- ...this,
6855
- currentTimestamp
6856
- });
6857
- }
6858
- remaining(decimals) {
6859
- return getNumberFromBN(this.depositedAmount.sub(this.withdrawnAmount), decimals);
6860
- }
6861
- };
6862
-
6863
- // ../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
6864
- var import_retry = __toESM(require_retry2());
6865
-
6866
- // ../../node_modules/.pnpm/is-network-error@1.1.0/node_modules/is-network-error/index.js
6867
- var objectToString = Object.prototype.toString;
6868
- var isError = (value) => objectToString.call(value) === "[object Error]";
6869
- var errorMessages = /* @__PURE__ */ new Set([
6870
- "network error",
6871
- // Chrome
6872
- "Failed to fetch",
6873
- // Chrome
6874
- "NetworkError when attempting to fetch resource.",
6875
- // Firefox
6876
- "The Internet connection appears to be offline.",
6877
- // Safari 16
6878
- "Load failed",
6879
- // Safari 17+
6880
- "Network request failed",
6881
- // `cross-fetch`
6882
- "fetch failed",
6883
- // Undici (Node.js)
6884
- "terminated"
6885
- // Undici (Node.js)
6886
- ]);
6887
- function isNetworkError(error) {
6888
- const isValid = error && isError(error) && error.name === "TypeError" && typeof error.message === "string";
6889
- if (!isValid) {
6890
- return false;
6891
- }
6892
- if (error.message === "Load failed") {
6893
- return error.stack === void 0;
6894
- }
6895
- return errorMessages.has(error.message);
6896
- }
6897
-
6898
- // ../../node_modules/.pnpm/p-retry@6.2.1/node_modules/p-retry/index.js
6899
- var AbortError = class extends Error {
6900
- constructor(message) {
6901
- super();
6902
- if (message instanceof Error) {
6903
- this.originalError = message;
6904
- ({ message } = message);
6905
- } else {
6906
- this.originalError = new Error(message);
6907
- this.originalError.stack = this.stack;
6908
- }
6909
- this.name = "AbortError";
6910
- this.message = message;
6911
- }
6912
- };
6913
- var decorateErrorWithCounts = (error, attemptNumber, options) => {
6914
- const retriesLeft = options.retries - (attemptNumber - 1);
6915
- error.attemptNumber = attemptNumber;
6916
- error.retriesLeft = retriesLeft;
6917
- return error;
6918
- };
6919
- async function pRetry(input, options) {
6920
- return new Promise((resolve, reject) => {
6921
- options = { ...options };
6922
- options.onFailedAttempt ?? (options.onFailedAttempt = () => {
6923
- });
6924
- options.shouldRetry ?? (options.shouldRetry = () => true);
6925
- options.retries ?? (options.retries = 10);
6926
- const operation = import_retry.default.operation(options);
6927
- const abortHandler = () => {
6928
- operation.stop();
6929
- reject(options.signal?.reason);
6930
- };
6931
- if (options.signal && !options.signal.aborted) {
6932
- options.signal.addEventListener("abort", abortHandler, { once: true });
6933
- }
6934
- const cleanUp = () => {
6935
- options.signal?.removeEventListener("abort", abortHandler);
6936
- operation.stop();
6937
- };
6938
- operation.attempt(async (attemptNumber) => {
6939
- try {
6940
- const result = await input(attemptNumber);
6941
- cleanUp();
6942
- resolve(result);
6943
- } catch (error) {
6944
- try {
6945
- if (!(error instanceof Error)) {
6946
- throw new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
6947
- }
6948
- if (error instanceof AbortError) {
6949
- throw error.originalError;
6950
- }
6951
- if (error instanceof TypeError && !isNetworkError(error)) {
6952
- throw error;
6953
- }
6954
- decorateErrorWithCounts(error, attemptNumber, options);
6955
- if (!await options.shouldRetry(error)) {
6956
- operation.stop();
6957
- reject(error);
6958
- }
6959
- await options.onFailedAttempt(error);
6960
- if (!operation.retry(error)) {
6961
- throw operation.mainError();
6962
- }
6963
- } catch (finalError) {
6964
- decorateErrorWithCounts(finalError, attemptNumber, options);
6965
- cleanUp();
6966
- reject(finalError);
4131
+ isSigner: false
4132
+ },
4133
+ {
4134
+ name: "streamflowTreasuryTokens",
4135
+ isMut: true,
4136
+ isSigner: false
4137
+ },
4138
+ {
4139
+ name: "withdrawor",
4140
+ isMut: true,
4141
+ isSigner: false
4142
+ },
4143
+ {
4144
+ name: "partner",
4145
+ isMut: true,
4146
+ isSigner: false
4147
+ },
4148
+ {
4149
+ name: "partnerTokens",
4150
+ isMut: true,
4151
+ isSigner: false
4152
+ },
4153
+ {
4154
+ name: "mint",
4155
+ isMut: false,
4156
+ isSigner: false
4157
+ },
4158
+ {
4159
+ name: "tokenProgram",
4160
+ isMut: false,
4161
+ isSigner: false
4162
+ },
4163
+ {
4164
+ name: "systemProgram",
4165
+ isMut: false,
4166
+ isSigner: false
6967
4167
  }
6968
- }
6969
- });
6970
- });
6971
- }
6972
-
6973
- // sui/utils.ts
6974
- function extractSuiErrorInfo(errorText) {
6975
- const error = { text: errorText };
6976
- const match = SUI_ERROR_MATCH_REGEX.exec(errorText);
6977
- if (!match) {
6978
- return error;
6979
- }
6980
- const moduleName = match[2];
6981
- const errorCode = Number(match[4]);
6982
- const errorName = SUI_MODULE_ERROR_MAP[moduleName] ? SUI_MODULE_ERROR_MAP[moduleName][errorCode] : void 0;
6983
- const index = Number(match[5]);
6984
- if (index) {
6985
- error.index = index;
6986
- }
6987
- if (errorName) {
6988
- error.parsed = {
6989
- module: moduleName,
6990
- code: errorCode,
6991
- name: errorName
6992
- };
6993
- }
6994
- return error;
6995
- }
6996
- function getTransactionBlock(client, input) {
6997
- return pRetry(() => client.getTransactionBlock(input), {
6998
- retries: 5,
6999
- shouldRetry: (error) => error.message.includes("Could not find the referenced transaction"),
7000
- minTimeout: 500,
7001
- maxTimeout: 1e3
7002
- });
7003
- }
7004
- function isSignerKeypair2(walletOrKeypair) {
7005
- return walletOrKeypair instanceof cryptography.Keypair || walletOrKeypair.constructor === cryptography.Keypair || walletOrKeypair.constructor.name === cryptography.Keypair.prototype.constructor.name || "getSecretKey" in walletOrKeypair;
7006
- }
7007
- var SuiWalletWrapper = class {
7008
- constructor(wallet, client) {
7009
- this.client = client;
7010
- this.wallet = wallet;
7011
- if (isSignerKeypair2(wallet)) {
7012
- this.address = wallet.toSuiAddress();
7013
- } else {
7014
- this.address = wallet.address;
7015
- }
7016
- }
7017
- async signAndExecuteTransaction(input) {
7018
- if (isSignerKeypair2(this.wallet)) {
7019
- return this.client.signAndExecuteTransaction({
7020
- ...input,
7021
- // @ts-ignore
7022
- signer: this.wallet
7023
- });
7024
- }
7025
- return this.wallet.signAndExecuteTransaction(input);
7026
- }
7027
- };
7028
-
7029
- // sui/StreamClient.ts
7030
- var SuiStreamClient = class extends BaseStreamClient {
7031
- constructor(clusterUrl, cluster = common.ICluster.Mainnet, ids) {
7032
- super();
7033
- this.programId = ids?.program ? ids.program : SUI_PROGRAM_IDS[cluster];
7034
- this.configId = ids?.config ? ids.config : SUI_CONFIG_IDS[cluster];
7035
- this.feeTableId = ids?.feeTable ? ids.feeTable : SUI_FEE_TABLE_IDS[cluster];
7036
- this.client = new client.SuiClient({ url: clusterUrl });
7037
- }
7038
- /**
7039
- * Creates a new stream/vesting contract.
7040
- */
7041
- async create(streamData, { senderWallet }) {
7042
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
7043
- const totalFee = await this.getTotalFee({
7044
- address: streamData.partner ?? wallet.address
7045
- });
7046
- const [tx] = await this.generateCreateBlock(
7047
- wallet.address,
7048
- {
7049
- ...streamData,
7050
- recipients: [{ ...streamData }]
7051
- },
7052
- totalFee
7053
- );
7054
- const { digest, events } = await wallet.signAndExecuteTransaction({
7055
- transaction: tx,
7056
- options: { showEvents: true }
7057
- });
7058
- return {
7059
- ixs: [],
7060
- txId: digest,
7061
- metadataId: events[0].parsedJson.address
7062
- };
7063
- }
7064
- /**
7065
- * Creates multiple stream/vesting contracts.
7066
- * We don't chain transactions in one Block so that one failed transaction does not revert all others.
7067
- */
7068
- async createMultiple(multipleStreamData, { senderWallet }) {
7069
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
7070
- const totalFee = await this.getTotalFee({
7071
- address: multipleStreamData.partner ?? wallet.address
7072
- });
7073
- const [tx, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
7074
- const txs = [];
7075
- const metadatas = [];
7076
- const metadataToRecipient = {};
7077
- const errors = [];
7078
- try {
7079
- const executedTx = await wallet.signAndExecuteTransaction({
7080
- transaction: tx,
7081
- options: { showEffects: true, showEvents: true }
7082
- });
7083
- const digest = executedTx.digest;
7084
- const { events, effects } = !executedTx.effects || typeof executedTx.effects === "string" ? await getTransactionBlock(this.client, { digest, options: { showEvents: true, showEffects: true } }) : executedTx;
7085
- txs.push(digest);
7086
- if (effects.status.status === "failure") {
7087
- multipleStreamData.recipients.forEach((recipient) => {
7088
- errors.push({
7089
- error: effects.status.error ?? "Unknown error!",
7090
- recipient: recipient.recipient
7091
- });
7092
- });
7093
- } else {
7094
- multipleStreamData.recipients.forEach((recipient, index) => {
7095
- const metadataId = events[index].parsedJson.address;
7096
- metadatas.push(metadataId);
7097
- metadataToRecipient[metadataId] = recipient;
7098
- });
7099
- }
7100
- } catch (e) {
7101
- const errorInfo = extractSuiErrorInfo(e.toString() ?? "Unknown error!");
7102
- multipleStreamData.recipients.forEach((recipient, index) => {
7103
- if (errorInfo.index === void 0 || errorInfo.index < index + firstIndex || errorInfo.index >= multipleStreamData.recipients.length + firstIndex || errorInfo.index === index + firstIndex) {
7104
- errors.push({
7105
- error: errorInfo.text,
7106
- recipient: recipient.recipient,
7107
- contractErrorCode: errorInfo.parsed?.name
7108
- });
4168
+ ],
4169
+ args: [
4170
+ {
4171
+ name: "amount",
4172
+ type: "u64"
7109
4173
  }
7110
- });
7111
- }
7112
- return {
7113
- txs,
7114
- metadatas,
7115
- metadataToRecipient,
7116
- errors
7117
- };
7118
- }
7119
- /**
7120
- * Attempts withdrawing from the specified stream.
7121
- */
7122
- async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
7123
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
7124
- const tx = new transactions.Transaction();
7125
- tx.moveCall({
7126
- target: `${this.programId}::protocol::withdraw`,
7127
- typeArguments: [tokenId],
7128
- arguments: [
7129
- tx.object(id),
7130
- tx.object(this.configId),
7131
- tx.object(utils.SUI_CLOCK_OBJECT_ID),
7132
- tx.pure.u64(amount.toString())
7133
- ]
7134
- });
7135
- const { digest } = await wallet.signAndExecuteTransaction({
7136
- transaction: tx
7137
- });
7138
- return {
7139
- ixs: [],
7140
- txId: digest
7141
- };
7142
- }
7143
- /**
7144
- * Attempts canceling the specified stream.
7145
- */
7146
- async cancel(cancelData, { senderWallet, tokenId }) {
7147
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
7148
- const tx = new transactions.Transaction();
7149
- tx.moveCall({
7150
- target: `${this.programId}::protocol::cancel`,
7151
- typeArguments: [tokenId],
7152
- arguments: [tx.object(cancelData.id), tx.object(this.configId), tx.object(utils.SUI_CLOCK_OBJECT_ID)]
7153
- });
7154
- const { digest } = await wallet.signAndExecuteTransaction({
7155
- transaction: tx
7156
- });
7157
- return {
7158
- ixs: [],
7159
- txId: digest
7160
- };
7161
- }
7162
- /**
7163
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
7164
- */
7165
- async transfer(transferData, { senderWallet, tokenId }) {
7166
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
7167
- const tx = new transactions.Transaction();
7168
- tx.moveCall({
7169
- target: `${this.programId}::protocol::transfer`,
7170
- typeArguments: [tokenId],
7171
- arguments: [tx.object(transferData.id), tx.pure.address(transferData.newRecipient)]
7172
- });
7173
- const { digest } = await wallet.signAndExecuteTransaction({
7174
- transaction: tx
7175
- });
7176
- return {
7177
- ixs: [],
7178
- txId: digest
7179
- };
7180
- }
7181
- /**
7182
- * Tops up stream account with specified amount.
7183
- */
7184
- async topup(topupData, { senderWallet, tokenId }) {
7185
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
7186
- const tx = new transactions.Transaction();
7187
- const coins = await this.getAllCoins(wallet.address, tokenId);
7188
- const stream = await this.getOne({ id: topupData.id });
7189
- const totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
7190
- const coinObject = this.splitCoinObjectForAmount(tx, topupData.amount, tokenId, coins, totalFee);
7191
- tx.moveCall({
7192
- target: `${this.programId}::protocol::topup`,
7193
- typeArguments: [tokenId],
7194
- arguments: [
7195
- tx.object(topupData.id),
7196
- tx.object(this.configId),
7197
- coinObject,
7198
- tx.gas,
7199
- tx.pure.u64(topupData.amount.toString())
7200
- ]
7201
- });
7202
- this.returnSplittedCoinObject(tx, tokenId, coins, coinObject);
7203
- const { digest } = await wallet.signAndExecuteTransaction({
7204
- transaction: tx
7205
- });
7206
- return {
7207
- ixs: [],
7208
- txId: digest
7209
- };
7210
- }
7211
- /**
7212
- * Fetch stream data by its id (address).
7213
- */
7214
- async getOne({ id }) {
7215
- const response = await this.client.getObject({
7216
- id,
7217
- options: {
7218
- showContent: true
7219
- }
7220
- });
7221
- if (!response.data) {
7222
- throw new Error(`Contract with id ${id} could not be found!`);
7223
- }
7224
- const content = response.data.content;
7225
- if (content.dataType !== "moveObject") {
7226
- throw new Error(`Not a Move Object!`);
7227
- }
7228
- return new Contract3(
7229
- content.fields,
7230
- "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2::strmt::STRMT"
7231
- );
7232
- }
7233
- async get() {
7234
- throw new Error("Get all method is not supported for Sui chain!");
7235
- }
7236
- /**
7237
- * Attempts updating the stream auto withdrawal params and amount per period
7238
- */
7239
- async update(updateData, { senderWallet, tokenId }) {
7240
- const wallet = new SuiWalletWrapper(senderWallet, this.client);
7241
- const tx = new transactions.Transaction();
7242
- tx.moveCall({
7243
- target: `${this.programId}::protocol::update`,
7244
- typeArguments: [tokenId],
7245
- arguments: [
7246
- tx.object(updateData.id),
7247
- tx.object(this.configId),
7248
- tx.object(utils.SUI_CLOCK_OBJECT_ID),
7249
- tx.gas,
7250
- bcs.bcs.vector(bcs.bcs.bool()).serialize(updateData.enableAutomaticWithdrawal !== void 0 ? [updateData.enableAutomaticWithdrawal] : []),
7251
- bcs.bcs.vector(bcs.bcs.u64()).serialize(updateData.withdrawFrequency !== void 0 ? [updateData.withdrawFrequency.toString()] : []),
7252
- bcs.bcs.vector(bcs.bcs.u64()).serialize(updateData.amountPerPeriod !== void 0 ? [updateData.amountPerPeriod.toString()] : [])
7253
4174
  ]
7254
- });
7255
- const { digest } = await wallet.signAndExecuteTransaction({
7256
- transaction: tx
7257
- });
7258
- return {
7259
- ixs: [],
7260
- txId: digest
7261
- };
7262
- }
7263
- extractErrorCode(err) {
7264
- const errorInfo = extractSuiErrorInfo(err.toString() ?? "Unknown error!");
7265
- return errorInfo?.parsed?.name || null;
7266
- }
7267
- async getFees({ address }) {
7268
- const response = await this.client.getObject({
7269
- id: this.feeTableId,
7270
- options: {
7271
- showContent: true
7272
- }
7273
- });
7274
- const content = response.data.content;
7275
- if (content.dataType !== "moveObject") {
7276
- throw new Error(`Not a Move Object!`);
7277
- }
7278
- const fields = content.fields;
7279
- const fieldsResponse = await this.client.getDynamicFields({
7280
- parentId: fields.values.fields.id.id
7281
- });
7282
- const partnerDynamicField = fieldsResponse.data.filter((item) => item.name.value === address)[0];
7283
- if (!partnerDynamicField) {
7284
- return null;
7285
- }
7286
- const valueResponse = await this.client.getObject({
7287
- id: partnerDynamicField.objectId,
7288
- options: {
7289
- showContent: true
7290
- }
7291
- });
7292
- const valueContent = valueResponse.data.content;
7293
- if (valueContent.dataType !== "moveObject") {
7294
- throw new Error(`Not a Move Object!`);
7295
- }
7296
- const valueFields = valueContent.fields.value.fields;
7297
- return {
7298
- streamflowFee: Number(valueFields.streamflow_fee) / 100,
7299
- partnerFee: Number(valueFields.partner_fee) / 100
7300
- };
7301
- }
7302
- async getDefaultStreamflowFee() {
7303
- const response = await this.client.getObject({
7304
- id: this.configId,
7305
- options: {
7306
- showContent: true
7307
- }
7308
- });
7309
- const content = response.data.content;
7310
- if (content.dataType !== "moveObject") {
7311
- throw new Error(`Not a Move Object!`);
7312
- }
7313
- const fields = content.fields;
7314
- return Number(fields.streamflow_fee) / 100;
7315
- }
7316
- /**
7317
- * Returns StreamClient protocol program ID.
7318
- */
7319
- getProgramId() {
7320
- return this.programId;
7321
- }
7322
- /**
7323
- * Utility function to generate Transaction Block to create streams
7324
- */
7325
- async generateCreateBlock(walletAddress, multipleStreamData, totalFee) {
7326
- let coins = await this.getAllCoins(walletAddress, multipleStreamData.tokenId);
7327
- const totalAmount = multipleStreamData.recipients.map((recipiient) => recipiient.amount).reduce((prev, current) => current.add(prev));
7328
- const tx = new transactions.Transaction();
7329
- const coinObject = this.splitCoinObjectForAmount(tx, totalAmount, multipleStreamData.tokenId, coins, totalFee);
7330
- coins = [coins[0]];
7331
- let firstIndex = null;
7332
- multipleStreamData.recipients.forEach((recipient) => {
7333
- const result = tx.moveCall({
7334
- target: `${this.programId}::protocol::create`,
7335
- typeArguments: [multipleStreamData.tokenId],
7336
- arguments: [
7337
- tx.object(this.configId),
7338
- tx.object(this.feeTableId),
7339
- tx.object(utils.SUI_CLOCK_OBJECT_ID),
7340
- coinObject,
7341
- tx.gas,
7342
- tx.pure.u64(recipient.amount.toString()),
7343
- tx.pure.u64(multipleStreamData.period),
7344
- tx.pure.u64(recipient.amountPerPeriod.toString()),
7345
- tx.pure.u64(multipleStreamData.start),
7346
- tx.pure.u64(recipient.cliffAmount.toString()),
7347
- tx.pure.bool(multipleStreamData.cancelableBySender),
7348
- tx.pure.bool(multipleStreamData.cancelableByRecipient),
7349
- tx.pure.bool(multipleStreamData.transferableBySender),
7350
- tx.pure.bool(multipleStreamData.transferableByRecipient),
7351
- tx.pure.bool(multipleStreamData.canTopup),
7352
- tx.pure.bool(!!multipleStreamData.canPause),
7353
- tx.pure.bool(!!multipleStreamData.canUpdateRate),
7354
- tx.pure.bool(!!multipleStreamData.automaticWithdrawal),
7355
- tx.pure.u64(multipleStreamData.withdrawalFrequency || 0),
7356
- tx.pure.string(recipient.name),
7357
- tx.pure.address(recipient.recipient),
7358
- tx.pure.address(multipleStreamData.partner || walletAddress)
7359
- ]
7360
- });
7361
- if (result.$kind === "Result" && firstIndex === null) {
7362
- firstIndex = result.Result;
7363
- }
7364
- });
7365
- this.returnSplittedCoinObject(tx, multipleStreamData.tokenId, coins, coinObject);
7366
- return [tx, firstIndex];
7367
- }
7368
- /**
7369
- * Returns all coins owned by a Wallet
7370
- * @param walletAddress wallet address
7371
- * @param coinType coin type
7372
- * @returns Array of Coin Structs
7373
- */
7374
- async getAllCoins(walletAddress, coinType) {
7375
- let coinsResponse = await this.client.getCoins({
7376
- owner: walletAddress,
7377
- coinType
7378
- });
7379
- const coins = coinsResponse.data;
7380
- while (coinsResponse.hasNextPage) {
7381
- coinsResponse = await this.client.getCoins({
7382
- owner: walletAddress,
7383
- coinType,
7384
- cursor: coinsResponse.nextCursor
7385
- });
7386
- coins.push(...coinsResponse.data);
7387
- }
7388
- return coins;
7389
- }
7390
- /**
7391
- * Utility function to split Coin object and use splitted object for stream operations.
7392
- * We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
7393
- * This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
7394
- * @param tx current transanction block
7395
- * @param amount minimal amount of coins requried
7396
- * @param coinType coin type
7397
- * @param coins array of owned coins of the same type
7398
- * @param totalFee partner and treasury fees
7399
- * @returns Coin Object to use in a Move Call
7400
- */
7401
- splitCoinObjectForAmount(tx, amount, coinType, coins, totalFee) {
7402
- const coinObject = coinType === utils.SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
7403
- if (coins.length > 1) {
7404
- tx.mergeCoins(
7405
- coinObject,
7406
- coins.slice(1).map((item) => tx.object(item.coinObjectId))
7407
- );
7408
- }
7409
- const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
7410
- return tx.splitCoins(coinObject, [tx.pure.u64(totalAmount.toString())])[0];
7411
- }
7412
- /**
7413
- * Return previously splitted Coin Object to owner and merge it to to rebate storage fees
7414
- * @param tx current transaction
7415
- * @param coinType coin type
7416
- * @param coinObject splitted object
7417
- * @param coins array of objects used in
7418
- */
7419
- returnSplittedCoinObject(tx, coinType, coins, coinObject) {
7420
- const firstCoinObject = coinType === utils.SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
7421
- tx.mergeCoins(firstCoinObject, [coinObject]);
7422
- }
7423
- };
7424
-
7425
- // common/GenericStreamClient.ts
7426
- var GenericStreamClient = class extends BaseStreamClient {
7427
- constructor(options) {
7428
- super();
7429
- this.chain = options.chain;
7430
- switch (options.chain) {
7431
- case common.IChain.Solana:
7432
- this.nativeStreamClient = new SolanaStreamClient(options);
7433
- break;
7434
- case common.IChain.Aptos:
7435
- this.nativeStreamClient = new AptosStreamClient(
7436
- options.clusterUrl,
7437
- options.cluster,
7438
- options.maxGas,
7439
- options.programId
7440
- );
7441
- break;
7442
- case common.IChain.BNB:
7443
- case common.IChain.Ethereum:
7444
- case common.IChain.Polygon:
7445
- this.nativeStreamClient = new EvmStreamClient(
7446
- options.clusterUrl,
7447
- options.chain,
7448
- options.signer,
7449
- options.cluster,
7450
- options.programId
7451
- );
7452
- break;
7453
- case common.IChain.Sui:
7454
- this.nativeStreamClient = new SuiStreamClient(
7455
- options.clusterUrl,
7456
- options.cluster,
7457
- options.ids
7458
- );
7459
4175
  }
7460
- }
7461
- /**
7462
- * Creates a new stream/vesting contract.
7463
- */
7464
- create(streamData, chainSpecificParams) {
7465
- return handleContractError(
7466
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7467
- () => this.nativeStreamClient.create(streamData, chainSpecificParams),
7468
- this.nativeStreamClient.extractErrorCode
7469
- );
7470
- }
7471
- /**
7472
- * Creates multiple stream/vesting contracts.
7473
- */
7474
- createMultiple(multipleStreamData, chainSpecificParams) {
7475
- return handleContractError(
7476
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7477
- () => this.nativeStreamClient.createMultiple(multipleStreamData, chainSpecificParams),
7478
- this.nativeStreamClient.extractErrorCode
7479
- );
7480
- }
7481
- /**
7482
- * Attempts withdrawing from the specified stream.
7483
- */
7484
- withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, chainSpecificParams) {
7485
- return handleContractError(
7486
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7487
- () => this.nativeStreamClient.withdraw({ id, amount }, chainSpecificParams),
7488
- this.nativeStreamClient.extractErrorCode
7489
- );
7490
- }
7491
- /**
7492
- * Attempts canceling the specified stream.
7493
- */
7494
- cancel(cancelData, chainSpecificParams) {
7495
- return handleContractError(
7496
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7497
- () => this.nativeStreamClient.cancel(cancelData, chainSpecificParams),
7498
- this.nativeStreamClient.extractErrorCode
7499
- );
7500
- }
7501
- /**
7502
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
7503
- */
7504
- transfer(transferData, chainSpecificParams) {
7505
- return handleContractError(
7506
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7507
- () => this.nativeStreamClient.transfer(transferData, chainSpecificParams),
7508
- this.nativeStreamClient.extractErrorCode
7509
- );
7510
- }
7511
- /**
7512
- * Tops up stream account with specified amount.
7513
- */
7514
- topup(topupData, chainSpecificParams) {
7515
- return handleContractError(
7516
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7517
- () => this.nativeStreamClient.topup(topupData, chainSpecificParams),
7518
- this.nativeStreamClient.extractErrorCode
7519
- );
7520
- }
7521
- /**
7522
- * Fetch stream data by its id (address).
7523
- */
7524
- getOne(getOneData) {
7525
- return this.nativeStreamClient.getOne(getOneData);
7526
- }
7527
- /**
7528
- * Fetch streams by sender or recipient address.
7529
- */
7530
- get(getAllData) {
7531
- return this.nativeStreamClient.get(getAllData);
7532
- }
7533
- /**
7534
- * Attempts updating the stream auto withdrawal params and amount per period
7535
- */
7536
- update(updateData, chainSpecificParams) {
7537
- return handleContractError(
7538
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7539
- () => this.nativeStreamClient.update(updateData, chainSpecificParams),
7540
- this.nativeStreamClient.extractErrorCode
7541
- );
7542
- }
7543
- /**
7544
- * Returns streamflow and partner fees for the specific wallet in %
7545
- */
7546
- getFees(getFeesData) {
7547
- return this.nativeStreamClient.getFees(getFeesData);
7548
- }
7549
- /**
7550
- * Returns default Streamflow Fee in %
7551
- */
7552
- getDefaultStreamflowFee() {
7553
- return this.nativeStreamClient.getDefaultStreamflowFee();
7554
- }
4176
+ ]
7555
4177
  };
7556
4178
 
7557
4179
  Object.defineProperty(exports, "ContractError", {
7558
4180
  enumerable: true,
7559
4181
  get: function () { return common.ContractError; }
7560
4182
  });
7561
- Object.defineProperty(exports, "IChain", {
7562
- enumerable: true,
7563
- get: function () { return common.IChain; }
7564
- });
7565
4183
  Object.defineProperty(exports, "ICluster", {
7566
4184
  enumerable: true,
7567
4185
  get: function () { return common.ICluster; }
7568
4186
  });
4187
+ Object.defineProperty(exports, "getBN", {
4188
+ enumerable: true,
4189
+ get: function () { return common.getBN; }
4190
+ });
4191
+ Object.defineProperty(exports, "getNumberFromBN", {
4192
+ enumerable: true,
4193
+ get: function () { return common.getNumberFromBN; }
4194
+ });
7569
4195
  exports.AIRDROP_AMOUNT = AIRDROP_AMOUNT;
7570
4196
  exports.AIRDROP_TEST_TOKEN = AIRDROP_TEST_TOKEN;
7571
4197
  exports.ALIGNED_COMPUTE_LIMIT = ALIGNED_COMPUTE_LIMIT;
7572
- exports.ALIGNED_PRECISION_FACTOR_POW = ALIGNED_PRECISION_FACTOR_POW;
4198
+ exports.ALIGNED_PRECISION_FACTOR_POW = ALIGNED_PRECISION_FACTOR_POW2;
7573
4199
  exports.ALIGNED_UNLOCKS_PROGRAM_ID = ALIGNED_UNLOCKS_PROGRAM_ID;
7574
- exports.BASE_FEE = BASE_FEE;
4200
+ exports.AlignedContract = AlignedContract;
4201
+ exports.AlignedProxyErrorCode = AlignedProxyErrorCode;
7575
4202
  exports.CONTRACT_DISCRIMINATOR = CONTRACT_DISCRIMINATOR;
7576
4203
  exports.CONTRACT_SEED = CONTRACT_SEED;
7577
4204
  exports.CREATE_PARAMS_PADDING = CREATE_PARAMS_PADDING;
4205
+ exports.Contract = Contract;
7578
4206
  exports.ContractErrorCode = ContractErrorCode;
7579
4207
  exports.DEFAULT_STREAMFLOW_FEE = DEFAULT_STREAMFLOW_FEE;
7580
4208
  exports.ESCROW_SEED = ESCROW_SEED;
7581
4209
  exports.FEES_METADATA_SEED = FEES_METADATA_SEED;
7582
4210
  exports.FEE_ORACLE_PUBLIC_KEY = FEE_ORACLE_PUBLIC_KEY;
7583
- exports.GenericStreamClient = GenericStreamClient;
7584
- exports.MAX_SAFE_UNIX_TIME_VALUE = MAX_SAFE_UNIX_TIME_VALUE;
4211
+ exports.MAX_SAFE_UNIX_TIME_VALUE = MAX_SAFE_UNIX_TIME_VALUE2;
7585
4212
  exports.ORIGINAL_CONTRACT_SENDER_OFFSET = ORIGINAL_CONTRACT_SENDER_OFFSET;
7586
4213
  exports.PARTNERS_SCHEMA = PARTNERS_SCHEMA;
7587
4214
  exports.PARTNER_ORACLE_PROGRAM_ID = PARTNER_ORACLE_PROGRAM_ID;
@@ -7595,14 +4222,9 @@ exports.STREAM_STRUCT_OFFSET_CLOSED = STREAM_STRUCT_OFFSET_CLOSED;
7595
4222
  exports.STREAM_STRUCT_OFFSET_MINT = STREAM_STRUCT_OFFSET_MINT;
7596
4223
  exports.STREAM_STRUCT_OFFSET_RECIPIENT = STREAM_STRUCT_OFFSET_RECIPIENT;
7597
4224
  exports.STREAM_STRUCT_OFFSET_SENDER = STREAM_STRUCT_OFFSET_SENDER;
7598
- exports.SolanaAlignedProxyErrorCode = SolanaAlignedProxyErrorCode;
7599
- exports.SolanaContractErrorCode = SolanaContractErrorCode;
4225
+ exports.SolanaStreamClient = SolanaStreamClient;
7600
4226
  exports.StreamDirection = StreamDirection;
7601
4227
  exports.StreamType = StreamType;
7602
- exports.StreamflowAptos = aptos_exports;
7603
- exports.StreamflowEVM = evm_exports;
7604
- exports.StreamflowSolana = solana_exports;
7605
- exports.StreamflowSui = sui_exports;
7606
4228
  exports.TEST_ORACLE_DISCRIMINATOR = TEST_ORACLE_DISCRIMINATOR;
7607
4229
  exports.TEST_ORACLE_SEED = TEST_ORACLE_SEED;
7608
4230
  exports.TX_FINALITY_CONFIRMED = TX_FINALITY_CONFIRMED;
@@ -7611,9 +4233,15 @@ exports.WITHDRAW_AVAILABLE_AMOUNT = WITHDRAW_AVAILABLE_AMOUNT;
7611
4233
  exports.buildStreamType = buildStreamType;
7612
4234
  exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
7613
4235
  exports.calculateUnlockedAmount = calculateUnlockedAmount;
4236
+ exports.cancelStreamInstruction = cancelStreamInstruction;
4237
+ exports.createStreamInstruction = createStreamInstruction;
4238
+ exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
7614
4239
  exports.decodeEndTime = decodeEndTime;
7615
- exports.getBN = getBN;
7616
- exports.getNumberFromBN = getNumberFromBN;
4240
+ exports.decodeStream = decodeStream;
4241
+ exports.deriveContractPDA = deriveContractPDA;
4242
+ exports.deriveEscrowPDA = deriveEscrowPDA;
4243
+ exports.deriveTestOraclePDA = deriveTestOraclePDA;
4244
+ exports.extractSolanaErrorCode = extractSolanaErrorCode;
7617
4245
  exports.handleContractError = handleContractError;
7618
4246
  exports.isAligned = isAligned;
7619
4247
  exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
@@ -7622,5 +4250,12 @@ exports.isDynamicLock = isDynamicLock;
7622
4250
  exports.isPayment = isPayment;
7623
4251
  exports.isTokenLock = isTokenLock;
7624
4252
  exports.isVesting = isVesting;
4253
+ exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
4254
+ exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
4255
+ exports.timelockIDL = timelockIDL_default;
4256
+ exports.topupStreamInstruction = topupStreamInstruction;
4257
+ exports.transferStreamInstruction = transferStreamInstruction;
4258
+ exports.updateStreamInstruction = updateStreamInstruction;
4259
+ exports.withdrawStreamInstruction = withdrawStreamInstruction;
7625
4260
  //# sourceMappingURL=index.cjs.map
7626
4261
  //# sourceMappingURL=index.cjs.map