@streamflow/stream 7.0.0-alpha.3 → 7.0.0-alpha.5

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.
@@ -1,21 +1,20 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.SOLANA_ERROR_MAP = exports.SOLANA_ERROR_MATCH_REGEX = exports.PARTNERS_SCHEMA = exports.PARTNER_SCHEMA = exports.AIRDROP_AMOUNT = exports.DEFAULT_STREAMFLOW_FEE = exports.FEES_METADATA_SEED = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.PARTNER_ORACLE_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
5
- var web3_js_1 = require("@solana/web3.js");
6
- var buffer_1 = require("buffer");
7
- var types_js_1 = require("../common/types.js");
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const buffer_1 = require("buffer");
6
+ const types_js_1 = require("../common/types.js");
8
7
  exports.TX_FINALITY_CONFIRMED = "confirmed";
9
8
  exports.STREAM_STRUCT_OFFSET_SENDER = 49;
10
9
  exports.STREAM_STRUCT_OFFSET_RECIPIENT = 113;
11
10
  // Defined: https://github.com/streamflow-finance/protocol/blob/main/programs/protocol/src/state.rs#L25
12
11
  exports.CREATE_PARAMS_PADDING = 126;
13
- exports.PROGRAM_ID = (_a = {},
14
- _a[types_js_1.ICluster.Devnet] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
15
- _a[types_js_1.ICluster.Mainnet] = "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
16
- _a[types_js_1.ICluster.Testnet] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
17
- _a[types_js_1.ICluster.Local] = "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
18
- _a);
12
+ exports.PROGRAM_ID = {
13
+ [types_js_1.ICluster.Devnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
14
+ [types_js_1.ICluster.Mainnet]: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m",
15
+ [types_js_1.ICluster.Testnet]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
16
+ [types_js_1.ICluster.Local]: "HqDGZjaVRXJ9MGRQEw7qDc2rAr6iH1n1kAQdCZaCMfMZ",
17
+ };
19
18
  exports.PARTNER_ORACLE_PROGRAM_ID = "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa";
20
19
  exports.STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js_1.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
21
20
  exports.WITHDRAWOR_PUBLIC_KEY = new web3_js_1.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
@@ -24,17 +24,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
27
- var buffer_1 = require("buffer");
28
- var web3_js_1 = require("@solana/web3.js");
29
- var node_crypto_1 = require("node:crypto");
30
- var Layout = __importStar(require("./layout.js"));
31
- var utils_js_1 = require("./utils.js");
32
- var hasher = function () { return (0, node_crypto_1.createHash)("sha256"); };
33
- var sha256 = {
34
- digest: function (data) { return new Uint8Array(hasher().update(data).digest()); },
27
+ const buffer_1 = require("buffer");
28
+ const web3_js_1 = require("@solana/web3.js");
29
+ const node_crypto_1 = require("node:crypto");
30
+ const Layout = __importStar(require("./layout.js"));
31
+ const utils_js_1 = require("./utils.js");
32
+ const hasher = () => (0, node_crypto_1.createHash)("sha256");
33
+ const sha256 = {
34
+ digest: (data) => new Uint8Array(hasher().update(data).digest()),
35
35
  };
36
- var createStreamInstruction = function (data, programId, accounts) {
37
- var keys = [
36
+ const createStreamInstruction = (data, programId, accounts) => {
37
+ const keys = [
38
38
  { pubkey: accounts.sender, isSigner: true, isWritable: true },
39
39
  { pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
40
40
  { pubkey: accounts.recipient, isSigner: false, isWritable: true },
@@ -66,10 +66,10 @@ var createStreamInstruction = function (data, programId, accounts) {
66
66
  },
67
67
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
68
68
  ];
69
- var bufferData = buffer_1.Buffer.alloc(Layout.createStreamLayout.span);
70
- var encodedUIntArray = new TextEncoder().encode(data.name);
71
- var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
72
- var decodedData = {
69
+ let bufferData = buffer_1.Buffer.alloc(Layout.createStreamLayout.span);
70
+ const encodedUIntArray = new TextEncoder().encode(data.name);
71
+ const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
72
+ const decodedData = {
73
73
  start_time: (0, utils_js_1.toBuffer)(data.start),
74
74
  net_amount_deposited: (0, utils_js_1.toBuffer)(data.depositedAmount),
75
75
  period: (0, utils_js_1.toBuffer)(data.period),
@@ -89,18 +89,18 @@ var createStreamInstruction = function (data, programId, accounts) {
89
89
  stream_name: streamNameBuffer,
90
90
  withdraw_frequency: (0, utils_js_1.toBuffer)(data.withdrawFrequency),
91
91
  };
92
- var encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
92
+ const encodeLength = Layout.createStreamLayout.encode(decodedData, bufferData);
93
93
  bufferData = bufferData.slice(0, encodeLength);
94
94
  bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:create")).slice(0, 8), bufferData, buffer_1.Buffer.alloc(10)]);
95
95
  return new web3_js_1.TransactionInstruction({
96
- keys: keys,
97
- programId: programId,
96
+ keys,
97
+ programId,
98
98
  data: bufferData,
99
99
  });
100
100
  };
101
101
  exports.createStreamInstruction = createStreamInstruction;
102
- var createUncheckedStreamInstruction = function (data, programId, accounts) {
103
- var keys = [
102
+ const createUncheckedStreamInstruction = (data, programId, accounts) => {
103
+ const keys = [
104
104
  { pubkey: accounts.sender, isSigner: true, isWritable: true },
105
105
  { pubkey: accounts.senderTokens, isSigner: false, isWritable: true },
106
106
  { pubkey: accounts.metadata, isSigner: false, isWritable: true },
@@ -120,10 +120,10 @@ var createUncheckedStreamInstruction = function (data, programId, accounts) {
120
120
  isWritable: true,
121
121
  });
122
122
  }
123
- var bufferData = buffer_1.Buffer.alloc(Layout.createUncheckedStreamLayout.span);
124
- var encodedUIntArray = new TextEncoder().encode(data.name);
125
- var streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
126
- var decodedData = {
123
+ let bufferData = buffer_1.Buffer.alloc(Layout.createUncheckedStreamLayout.span);
124
+ const encodedUIntArray = new TextEncoder().encode(data.name);
125
+ const streamNameBuffer = buffer_1.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
126
+ const decodedData = {
127
127
  start_time: (0, utils_js_1.toBuffer)(data.start),
128
128
  net_amount_deposited: (0, utils_js_1.toBuffer)(data.depositedAmount),
129
129
  period: (0, utils_js_1.toBuffer)(data.period),
@@ -143,22 +143,21 @@ var createUncheckedStreamInstruction = function (data, programId, accounts) {
143
143
  pausable: Number(data.canPause),
144
144
  can_update_rate: Number(data.canUpdateRate),
145
145
  };
146
- var encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
146
+ const encodeLength = Layout.createUncheckedStreamLayout.encode(decodedData, bufferData);
147
147
  bufferData = bufferData.slice(0, encodeLength);
148
- var digest = accounts.payer
148
+ const digest = accounts.payer
149
149
  ? sha256.digest("global:create_unchecked_with_payer")
150
150
  : sha256.digest("global:create_unchecked");
151
151
  bufferData = buffer_1.Buffer.concat([buffer_1.Buffer.from(digest).slice(0, 8), bufferData, buffer_1.Buffer.alloc(10)]);
152
152
  return new web3_js_1.TransactionInstruction({
153
- keys: keys,
154
- programId: programId,
153
+ keys,
154
+ programId,
155
155
  data: bufferData,
156
156
  });
157
157
  };
158
158
  exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
159
- var withdrawStreamInstruction = function (amount, programId, _a) {
160
- var authority = _a.authority, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
161
- var keys = [
159
+ const withdrawStreamInstruction = (amount, programId, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
160
+ const keys = [
162
161
  { pubkey: authority, isSigner: true, isWritable: true },
163
162
  { pubkey: recipient, isSigner: false, isWritable: true },
164
163
  { pubkey: recipientTokens, isSigner: false, isWritable: true },
@@ -175,33 +174,32 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
175
174
  { pubkey: mint, isSigner: false, isWritable: true },
176
175
  { pubkey: tokenProgram, isSigner: false, isWritable: false },
177
176
  ];
178
- var data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
179
- var decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
180
- var encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
177
+ let data = buffer_1.Buffer.alloc(Layout.withdrawStreamLayout.span);
178
+ const decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
179
+ const encodeLength = Layout.withdrawStreamLayout.encode(decodedData, data);
181
180
  data = data.slice(0, encodeLength);
182
181
  data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:withdraw")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
183
182
  return new web3_js_1.TransactionInstruction({
184
- keys: keys,
185
- programId: programId,
186
- data: data,
183
+ keys,
184
+ programId,
185
+ data,
187
186
  });
188
187
  };
189
188
  exports.withdrawStreamInstruction = withdrawStreamInstruction;
190
- var updateStreamInstruction = function (params, programId, _a) {
191
- var authority = _a.authority, metadata = _a.metadata, withdrawor = _a.withdrawor, systemProgram = _a.systemProgram;
192
- var keys = [
189
+ const updateStreamInstruction = (params, programId, { authority, metadata, withdrawor, systemProgram }) => {
190
+ const keys = [
193
191
  { pubkey: authority, isSigner: true, isWritable: true },
194
192
  { pubkey: metadata, isSigner: false, isWritable: true },
195
193
  { pubkey: withdrawor, isSigner: false, isWritable: true },
196
194
  { pubkey: systemProgram, isSigner: false, isWritable: false },
197
195
  ];
198
- var data = buffer_1.Buffer.alloc(100);
199
- var decodedData = {
196
+ let data = buffer_1.Buffer.alloc(100);
197
+ const decodedData = {
200
198
  enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
201
199
  withdraw_frequency: params.withdrawFrequency ? (0, utils_js_1.toBuffer)(params.withdrawFrequency) : undefined,
202
200
  amount_per_period: params.amountPerPeriod ? (0, utils_js_1.toBuffer)(params.amountPerPeriod) : undefined,
203
201
  };
204
- var encodeLength = Layout.encodeUpdateStream(decodedData, data);
202
+ const encodeLength = Layout.encodeUpdateStream(decodedData, data);
205
203
  data = data.slice(0, encodeLength);
206
204
  data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:update")).slice(0, 8), data, buffer_1.Buffer.alloc(20)]);
207
205
  return new web3_js_1.TransactionInstruction({
@@ -211,9 +209,8 @@ var updateStreamInstruction = function (params, programId, _a) {
211
209
  });
212
210
  };
213
211
  exports.updateStreamInstruction = updateStreamInstruction;
214
- var cancelStreamInstruction = function (programId, _a) {
215
- var authority = _a.authority, sender = _a.sender, senderTokens = _a.senderTokens, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
216
- var keys = [
212
+ const cancelStreamInstruction = (programId, { authority, sender, senderTokens, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }) => {
213
+ const keys = [
217
214
  { pubkey: authority, isSigner: true, isWritable: false },
218
215
  { pubkey: sender, isSigner: false, isWritable: true },
219
216
  { pubkey: senderTokens, isSigner: false, isWritable: true },
@@ -232,17 +229,16 @@ var cancelStreamInstruction = function (programId, _a) {
232
229
  { pubkey: mint, isSigner: false, isWritable: true },
233
230
  { pubkey: tokenProgram, isSigner: false, isWritable: false },
234
231
  ];
235
- var data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:cancel")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
232
+ const data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:cancel")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
236
233
  return new web3_js_1.TransactionInstruction({
237
- keys: keys,
238
- programId: programId,
239
- data: data,
234
+ keys,
235
+ programId,
236
+ data,
240
237
  });
241
238
  };
242
239
  exports.cancelStreamInstruction = cancelStreamInstruction;
243
- var transferStreamInstruction = function (programId, _a) {
244
- var authority = _a.authority, newRecipient = _a.newRecipient, newRecipientTokens = _a.newRecipientTokens, metadata = _a.metadata, mint = _a.mint, rent = _a.rent, tokenProgram = _a.tokenProgram, associatedTokenProgram = _a.associatedTokenProgram, systemProgram = _a.systemProgram;
245
- var keys = [
240
+ const transferStreamInstruction = (programId, { authority, newRecipient, newRecipientTokens, metadata, mint, rent, tokenProgram, associatedTokenProgram, systemProgram, }) => {
241
+ const keys = [
246
242
  { pubkey: authority, isSigner: true, isWritable: true },
247
243
  { pubkey: newRecipient, isSigner: false, isWritable: true },
248
244
  { pubkey: newRecipientTokens, isSigner: false, isWritable: true },
@@ -253,17 +249,16 @@ var transferStreamInstruction = function (programId, _a) {
253
249
  { pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
254
250
  { pubkey: systemProgram, isSigner: false, isWritable: false },
255
251
  ];
256
- var data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:transfer_recipient")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
252
+ const data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:transfer_recipient")).slice(0, 8), buffer_1.Buffer.alloc(10)]);
257
253
  return new web3_js_1.TransactionInstruction({
258
- keys: keys,
259
- programId: programId,
260
- data: data,
254
+ keys,
255
+ programId,
256
+ data,
261
257
  });
262
258
  };
263
259
  exports.transferStreamInstruction = transferStreamInstruction;
264
- var topupStreamInstruction = function (amount, programId, _a) {
265
- var sender = _a.sender, senderTokens = _a.senderTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram, withdrawor = _a.withdrawor, systemProgram = _a.systemProgram;
266
- var keys = [
260
+ const topupStreamInstruction = (amount, programId, { sender, senderTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, withdrawor, systemProgram, }) => {
261
+ const keys = [
267
262
  { pubkey: sender, isSigner: true, isWritable: true },
268
263
  { pubkey: senderTokens, isSigner: false, isWritable: true },
269
264
  { pubkey: metadata, isSigner: false, isWritable: true },
@@ -281,15 +276,15 @@ var topupStreamInstruction = function (amount, programId, _a) {
281
276
  { pubkey: tokenProgram, isSigner: false, isWritable: false },
282
277
  { pubkey: systemProgram, isSigner: false, isWritable: false },
283
278
  ];
284
- var data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
285
- var decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
286
- var encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
279
+ let data = buffer_1.Buffer.alloc(Layout.topupStreamLayout.span);
280
+ const decodedData = { amount: (0, utils_js_1.toBuffer)(amount) };
281
+ const encodeLength = Layout.topupStreamLayout.encode(decodedData, data);
287
282
  data = data.slice(0, encodeLength);
288
283
  data = buffer_1.Buffer.concat([buffer_1.Buffer.from(sha256.digest("global:topup")).slice(0, 8), data, buffer_1.Buffer.alloc(10)]);
289
284
  return new web3_js_1.TransactionInstruction({
290
- keys: keys,
291
- programId: programId,
292
- data: data,
285
+ keys,
286
+ programId,
287
+ data,
293
288
  });
294
289
  };
295
290
  exports.topupStreamInstruction = topupStreamInstruction;
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.topupStreamLayout = exports.encodeUpdateStream = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.partnerLayout = exports.streamLayout = void 0;
27
- var BufferLayout = __importStar(require("@solana/buffer-layout"));
28
- var constants_js_1 = require("./constants.js");
27
+ const BufferLayout = __importStar(require("@solana/buffer-layout"));
28
+ const constants_js_1 = require("./constants.js");
29
29
  /**
30
30
  * Stream layout
31
31
  */
@@ -141,9 +141,8 @@ exports.withdrawStreamLayout = BufferLayout.struct([
141
141
  /**
142
142
  * Encode stream instruction layout
143
143
  */
144
- var encodeUpdateStream = function (values, data) {
145
- var _a, _b, _c;
146
- var structs = [];
144
+ const encodeUpdateStream = (values, data) => {
145
+ const structs = [];
147
146
  if (values.enable_automatic_withdrawal) {
148
147
  structs.push(BufferLayout.u8("enable_automatic_withdrawal_exists"));
149
148
  structs.push(BufferLayout.u8("enable_automatic_withdrawal"));
@@ -167,11 +166,11 @@ var encodeUpdateStream = function (values, data) {
167
166
  }
168
167
  return BufferLayout.struct(structs).encode({
169
168
  enable_automatic_withdrawal_exists: values.enable_automatic_withdrawal ? 1 : 0,
170
- enable_automatic_withdrawal: (_a = values.enable_automatic_withdrawal) !== null && _a !== void 0 ? _a : 0,
169
+ enable_automatic_withdrawal: values.enable_automatic_withdrawal ?? 0,
171
170
  withdraw_frequency_exists: values.withdraw_frequency ? 1 : 0,
172
- withdraw_frequency: (_b = values.withdraw_frequency) !== null && _b !== void 0 ? _b : 0,
171
+ withdraw_frequency: values.withdraw_frequency ?? 0,
173
172
  amount_per_period_exists: values.amount_per_period ? 1 : 0,
174
- amount_per_period: (_c = values.amount_per_period) !== null && _c !== void 0 ? _c : 0,
173
+ amount_per_period: values.amount_per_period ?? 0,
175
174
  }, data);
176
175
  };
177
176
  exports.encodeUpdateStream = encodeUpdateStream;
@@ -1,22 +1,10 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.Contract = void 0;
15
- var contractUtils_js_1 = require("../common/contractUtils.js");
16
- var utils_js_1 = require("../common/utils.js");
17
- var Contract = /** @class */ (function () {
18
- function Contract(stream) {
19
- var _a;
4
+ const contractUtils_js_1 = require("../common/contractUtils.js");
5
+ const utils_js_1 = require("../common/utils.js");
6
+ class Contract {
7
+ constructor(stream) {
20
8
  this.magic = stream.magic.toNumber();
21
9
  this.version = stream.version.toNumber();
22
10
  this.createdAt = stream.createdAt.toNumber();
@@ -39,7 +27,7 @@ var Contract = /** @class */ (function () {
39
27
  this.partnerFeeWithdrawn = stream.partnerFeeWithdrawn;
40
28
  this.partnerFeePercent = stream.partnerFeePercent.toNumber();
41
29
  this.partner = stream.partner.toBase58();
42
- this.partnerTokens = (_a = stream.partnerTokens) === null || _a === void 0 ? void 0 : _a.toBase58();
30
+ this.partnerTokens = stream.partnerTokens?.toBase58();
43
31
  this.start = stream.start.toNumber();
44
32
  this.depositedAmount = stream.depositedAmount;
45
33
  this.period = stream.period.toNumber();
@@ -61,12 +49,14 @@ var Contract = /** @class */ (function () {
61
49
  this.fundsUnlockedAtLastRateChange = stream.fundsUnlockedAtLastRateChange;
62
50
  this.type = (0, contractUtils_js_1.buildStreamType)(this);
63
51
  }
64
- Contract.prototype.unlocked = function (currentTimestamp) {
65
- return (0, contractUtils_js_1.calculateUnlockedAmount)(__assign(__assign({}, this), { currentTimestamp: currentTimestamp }));
66
- };
67
- Contract.prototype.remaining = function (decimals) {
52
+ unlocked(currentTimestamp) {
53
+ return (0, contractUtils_js_1.calculateUnlockedAmount)({
54
+ ...this,
55
+ currentTimestamp,
56
+ });
57
+ }
58
+ remaining(decimals) {
68
59
  return (0, utils_js_1.getNumberFromBigNumber)(this.depositedAmount.minus(this.withdrawnAmount), decimals);
69
- };
70
- return Contract;
71
- }());
60
+ }
61
+ }
72
62
  exports.Contract = Contract;
@@ -1,87 +1,25 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __values = (this && this.__values) || function(o) {
50
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
51
- if (m) return m.call(o);
52
- if (o && typeof o.length === "number") return {
53
- next: function () {
54
- if (o && i >= o.length) o = void 0;
55
- return { value: o && o[i++], done: !o };
56
- }
57
- };
58
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
59
- };
60
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
61
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
62
4
  };
63
5
  Object.defineProperty(exports, "__esModule", { value: true });
64
6
  exports.extractSolanaErrorCode = exports.sendAndConfirmStreamRawTransaction = exports.signAllTransactionWithRecipients = exports.decodeStream = exports.toBuffer = void 0;
65
- var web3_js_1 = require("@solana/web3.js");
66
- var solana_1 = require("@streamflow/common/solana");
67
- var bignumber_js_1 = __importDefault(require("bignumber.js"));
68
- var layout_js_1 = require("./layout.js");
69
- var constants_js_1 = require("./constants.js");
70
- var decoder = new TextDecoder("utf-8");
71
- var toUInt64String = function (uintArr) {
72
- return new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getBigUint64(0, true).toString();
73
- };
74
- var toUInt8 = function (uintArr) {
75
- return new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getUint8(0);
76
- };
77
- var toBuffer = function (bigNumber) {
78
- var dv = new DataView(new ArrayBuffer(8), 0);
7
+ const web3_js_1 = require("@solana/web3.js");
8
+ const solana_1 = require("@streamflow/common/solana");
9
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
10
+ const layout_js_1 = require("./layout.js");
11
+ const constants_js_1 = require("./constants.js");
12
+ const decoder = new TextDecoder("utf-8");
13
+ const toUInt64String = (uintArr) => new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getBigUint64(0, true).toString();
14
+ const toUInt8 = (uintArr) => new DataView(uintArr.buffer, uintArr.byteOffset, uintArr.byteLength).getUint8(0);
15
+ const toBuffer = (bigNumber) => {
16
+ const dv = new DataView(new ArrayBuffer(8), 0);
79
17
  dv.setBigUint64(0, BigInt(bigNumber.integerValue().toString()), true);
80
18
  return Buffer.from(dv.buffer);
81
19
  };
82
20
  exports.toBuffer = toBuffer;
83
- var decodeStream = function (buf) {
84
- var raw = layout_js_1.streamLayout.decode(buf);
21
+ const decodeStream = (buf) => {
22
+ const raw = layout_js_1.streamLayout.decode(buf);
85
23
  return {
86
24
  magic: (0, bignumber_js_1.default)(toUInt64String(raw.magic)),
87
25
  version: (0, bignumber_js_1.default)(toUInt8(raw.version)),
@@ -134,31 +72,26 @@ exports.decodeStream = decodeStream;
134
72
  * @param {BatchItem[]} items - Multiple recipient contracts split into separate items
135
73
  * @return {BatchItem[]} - Returns items with signatures.
136
74
  */
137
- function signAllTransactionWithRecipients(sender, items) {
138
- return __awaiter(this, void 0, void 0, function () {
139
- var isKeypair, isWallet, signedTxs_1;
140
- return __generator(this, function (_a) {
141
- switch (_a.label) {
142
- case 0:
143
- isKeypair = (0, solana_1.isSignerKeypair)(sender);
144
- isWallet = (0, solana_1.isSignerWallet)(sender);
145
- if (!isKeypair) return [3 /*break*/, 1];
146
- return [2 /*return*/, items.map(function (t) {
147
- t.tx.sign([sender]);
148
- return { tx: t.tx, recipient: t.recipient };
149
- })];
150
- case 1:
151
- if (!isWallet) return [3 /*break*/, 3];
152
- return [4 /*yield*/, sender.signAllTransactions(items.map(function (t) { return t.tx; }))];
153
- case 2:
154
- signedTxs_1 = _a.sent();
155
- return [2 /*return*/, items.map(function (item, index) { return (__assign(__assign({}, item), { tx: signedTxs_1[index] })); })];
156
- case 3:
157
- // If signer is not passed
158
- return [2 /*return*/, []];
159
- }
75
+ async function signAllTransactionWithRecipients(sender, items) {
76
+ const isKeypair = (0, solana_1.isSignerKeypair)(sender);
77
+ const isWallet = (0, solana_1.isSignerWallet)(sender);
78
+ if (isKeypair) {
79
+ return items.map((t) => {
80
+ t.tx.sign([sender]);
81
+ return { tx: t.tx, recipient: t.recipient };
160
82
  });
161
- });
83
+ }
84
+ else if (isWallet) {
85
+ const signedTxs = await sender.signAllTransactions(items.map((t) => t.tx));
86
+ return items.map((item, index) => ({
87
+ ...item,
88
+ tx: signedTxs[index],
89
+ }));
90
+ }
91
+ else {
92
+ // If signer is not passed
93
+ return [];
94
+ }
162
95
  }
163
96
  exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
164
97
  /**
@@ -169,54 +102,33 @@ exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
169
102
  * @param throttleParams - rate or throttler instance to throttle TX sending - to not spam the blockchain too much
170
103
  * @return {Promise<BatchItemResult>} - Returns settled transaction item
171
104
  */
172
- function sendAndConfirmStreamRawTransaction(connection, batchItem, confirmationParams, throttleParams) {
173
- return __awaiter(this, void 0, void 0, function () {
174
- var completedTxSignature, error_1;
175
- return __generator(this, function (_a) {
176
- switch (_a.label) {
177
- case 0:
178
- _a.trys.push([0, 2, , 3]);
179
- return [4 /*yield*/, (0, solana_1.executeTransaction)(connection, batchItem.tx, confirmationParams, throttleParams)];
180
- case 1:
181
- completedTxSignature = _a.sent();
182
- return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
183
- case 2:
184
- error_1 = _a.sent();
185
- throw {
186
- recipient: batchItem.recipient,
187
- error: error_1,
188
- };
189
- case 3: return [2 /*return*/];
190
- }
191
- });
192
- });
105
+ async function sendAndConfirmStreamRawTransaction(connection, batchItem, confirmationParams, throttleParams) {
106
+ try {
107
+ const completedTxSignature = await (0, solana_1.executeTransaction)(connection, batchItem.tx, confirmationParams, throttleParams);
108
+ return { ...batchItem, signature: completedTxSignature };
109
+ }
110
+ catch (error) {
111
+ throw {
112
+ recipient: batchItem.recipient,
113
+ error,
114
+ };
115
+ }
193
116
  }
194
117
  exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;
195
118
  function extractSolanaErrorCode(errorText, logs) {
196
- var e_1, _a;
197
- var match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
119
+ let match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(errorText);
198
120
  if (!match && logs) {
199
- try {
200
- for (var logs_1 = __values(logs), logs_1_1 = logs_1.next(); !logs_1_1.done; logs_1_1 = logs_1.next()) {
201
- var logLine = logs_1_1.value;
202
- match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(logLine);
203
- if (match !== null) {
204
- break;
205
- }
206
- }
207
- }
208
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
209
- finally {
210
- try {
211
- if (logs_1_1 && !logs_1_1.done && (_a = logs_1.return)) _a.call(logs_1);
121
+ for (const logLine of logs) {
122
+ match = constants_js_1.SOLANA_ERROR_MATCH_REGEX.exec(logLine);
123
+ if (match !== null) {
124
+ break;
212
125
  }
213
- finally { if (e_1) throw e_1.error; }
214
126
  }
215
127
  }
216
128
  if (!match) {
217
129
  return null;
218
130
  }
219
- var errorCode = Number(match[1]);
131
+ const errorCode = Number(match[1]);
220
132
  return constants_js_1.SOLANA_ERROR_MAP[errorCode] || null;
221
133
  }
222
134
  exports.extractSolanaErrorCode = extractSolanaErrorCode;