@streamflow/stream 4.0.3 → 4.1.0-beta.1
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.
- package/dist/__tests__/aptos/streamClient.spec.js +1 -1
- package/dist/aptos/StreamClient.d.ts +4 -3
- package/dist/aptos/StreamClient.js +13 -6
- package/dist/aptos/types.d.ts +2 -18
- package/dist/aptos/types.js +5 -6
- package/dist/common/BaseStreamClient.d.ts +11 -9
- package/dist/common/GenericStreamClient.d.ts +25 -12
- package/dist/common/GenericStreamClient.js +18 -5
- package/dist/common/types.d.ts +30 -1
- package/dist/common/types.js +2 -0
- package/dist/common/utils.js +6 -3
- package/dist/evm/StreamClient.d.ts +28 -0
- package/dist/evm/StreamClient.js +419 -0
- package/dist/evm/abi.d.ts +111 -0
- package/dist/evm/abi.js +1257 -0
- package/dist/evm/constants.d.ts +3 -0
- package/dist/evm/constants.js +17 -0
- package/dist/evm/ercAbi.d.ts +39 -0
- package/dist/evm/ercAbi.js +224 -0
- package/dist/evm/index.d.ts +2 -0
- package/dist/evm/index.js +24 -0
- package/dist/evm/types.d.ts +126 -0
- package/dist/evm/types.js +63 -0
- package/dist/solana/StreamClient.d.ts +11 -11
- package/dist/solana/StreamClient.js +90 -89
- package/dist/solana/types.d.ts +2 -2
- package/dist/solana/types.js +5 -6
- package/dist/solana/utils.js +1 -1
- package/package.json +4 -1
|
@@ -141,13 +141,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
141
141
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
142
142
|
*/
|
|
143
143
|
SolanaStreamClient.prototype.create = function (_a, _b) {
|
|
144
|
-
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d;
|
|
145
|
-
var sender = _b.sender, _e = _b.
|
|
144
|
+
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
|
|
145
|
+
var sender = _b.sender, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
146
146
|
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
-
var ixs, mintPublicKey, recipientPublicKey, metadata,
|
|
148
|
-
var
|
|
149
|
-
return __generator(this, function (
|
|
150
|
-
switch (
|
|
147
|
+
var ixs, mintPublicKey, recipientPublicKey, metadata, _f, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _g, commitment, hash, tx, signature;
|
|
148
|
+
var _h;
|
|
149
|
+
return __generator(this, function (_j) {
|
|
150
|
+
switch (_j.label) {
|
|
151
151
|
case 0:
|
|
152
152
|
if (!sender.publicKey) {
|
|
153
153
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -158,30 +158,30 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
158
158
|
metadata = web3_js_1.Keypair.generate();
|
|
159
159
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
160
160
|
case 1:
|
|
161
|
-
|
|
161
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
162
162
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
163
163
|
case 2:
|
|
164
|
-
senderTokens =
|
|
164
|
+
senderTokens = _j.sent();
|
|
165
165
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
166
166
|
case 3:
|
|
167
|
-
recipientTokens =
|
|
167
|
+
recipientTokens = _j.sent();
|
|
168
168
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
169
169
|
case 4:
|
|
170
|
-
streamflowTreasuryTokens =
|
|
170
|
+
streamflowTreasuryTokens = _j.sent();
|
|
171
171
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
172
172
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
173
173
|
case 5:
|
|
174
|
-
partnerTokens =
|
|
174
|
+
partnerTokens = _j.sent();
|
|
175
175
|
if (!isNative) return [3 /*break*/, 7];
|
|
176
176
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
177
177
|
case 6:
|
|
178
|
-
|
|
178
|
+
_g = _j.sent();
|
|
179
179
|
return [3 /*break*/, 8];
|
|
180
180
|
case 7:
|
|
181
|
-
|
|
182
|
-
|
|
181
|
+
_g = [];
|
|
182
|
+
_j.label = 8;
|
|
183
183
|
case 8:
|
|
184
|
-
nativeInstructions =
|
|
184
|
+
nativeInstructions = _g;
|
|
185
185
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
186
186
|
start: new bn_js_1.default(start),
|
|
187
187
|
depositedAmount: depositedAmount,
|
|
@@ -220,17 +220,17 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
220
220
|
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
221
221
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
222
222
|
case 9:
|
|
223
|
-
hash =
|
|
224
|
-
tx = (
|
|
223
|
+
hash = _j.sent();
|
|
224
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
225
225
|
feePayer: sender.publicKey,
|
|
226
226
|
blockhash: hash.blockhash,
|
|
227
227
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
228
|
-
})).add.apply(
|
|
228
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
229
229
|
tx.partialSign(metadata);
|
|
230
230
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
231
231
|
case 10:
|
|
232
|
-
signature =
|
|
233
|
-
return [2 /*return*/, { ixs: ixs,
|
|
232
|
+
signature = _j.sent();
|
|
233
|
+
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadata.publicKey.toBase58() }];
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
236
|
});
|
|
@@ -246,13 +246,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
246
246
|
* If you are not sure if you should use create or create_unchecked, go for create to be safer.
|
|
247
247
|
*/
|
|
248
248
|
SolanaStreamClient.prototype.createUnchecked = function (_a, _b) {
|
|
249
|
-
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d;
|
|
250
|
-
var sender = _b.sender, _e = _b.
|
|
249
|
+
var recipient = _a.recipient, mint = _a.tokenId, start = _a.start, depositedAmount = _a.amount, period = _a.period, cliff = _a.cliff, cliffAmount = _a.cliffAmount, amountPerPeriod = _a.amountPerPeriod, name = _a.name, canTopup = _a.canTopup, cancelableBySender = _a.cancelableBySender, cancelableByRecipient = _a.cancelableByRecipient, transferableBySender = _a.transferableBySender, transferableByRecipient = _a.transferableByRecipient, _c = _a.automaticWithdrawal, automaticWithdrawal = _c === void 0 ? false : _c, _d = _a.withdrawalFrequency, withdrawalFrequency = _d === void 0 ? 0 : _d, partner = _a.partner;
|
|
250
|
+
var sender = _b.sender, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
251
251
|
return __awaiter(this, void 0, void 0, function () {
|
|
252
|
-
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction,
|
|
253
|
-
var
|
|
254
|
-
return __generator(this, function (
|
|
255
|
-
switch (
|
|
252
|
+
var mintPublicKey, recipientPublicKey, metadata, rentToExempt, createMetadataInstruction, _f, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _g, createInstruction, commitment, ixs, hash, tx, signature;
|
|
253
|
+
var _h;
|
|
254
|
+
return __generator(this, function (_j) {
|
|
255
|
+
switch (_j.label) {
|
|
256
256
|
case 0:
|
|
257
257
|
if (!sender.publicKey) {
|
|
258
258
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -262,7 +262,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
262
262
|
metadata = web3_js_1.Keypair.generate();
|
|
263
263
|
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
264
264
|
case 1:
|
|
265
|
-
rentToExempt =
|
|
265
|
+
rentToExempt = _j.sent();
|
|
266
266
|
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
267
267
|
programId: this.programId,
|
|
268
268
|
space: METADATA_ACC_SIZE,
|
|
@@ -272,21 +272,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
272
272
|
});
|
|
273
273
|
return [4 /*yield*/, web3_js_1.PublicKey.findProgramAddress([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId)];
|
|
274
274
|
case 2:
|
|
275
|
-
|
|
275
|
+
_f = __read.apply(void 0, [_j.sent(), 1]), escrowTokens = _f[0];
|
|
276
276
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
277
277
|
case 3:
|
|
278
|
-
senderTokens =
|
|
278
|
+
senderTokens = _j.sent();
|
|
279
279
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
280
280
|
if (!isNative) return [3 /*break*/, 5];
|
|
281
281
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
282
282
|
case 4:
|
|
283
|
-
|
|
283
|
+
_g = _j.sent();
|
|
284
284
|
return [3 /*break*/, 6];
|
|
285
285
|
case 5:
|
|
286
|
-
|
|
287
|
-
|
|
286
|
+
_g = [];
|
|
287
|
+
_j.label = 6;
|
|
288
288
|
case 6:
|
|
289
|
-
nativeInstructions =
|
|
289
|
+
nativeInstructions = _g;
|
|
290
290
|
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
291
291
|
start: new bn_js_1.default(start),
|
|
292
292
|
depositedAmount: depositedAmount,
|
|
@@ -321,17 +321,17 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
321
321
|
ixs = [createMetadataInstruction, createInstruction];
|
|
322
322
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
323
323
|
case 7:
|
|
324
|
-
hash =
|
|
325
|
-
tx = (
|
|
324
|
+
hash = _j.sent();
|
|
325
|
+
tx = (_h = new web3_js_1.Transaction({
|
|
326
326
|
feePayer: sender.publicKey,
|
|
327
327
|
blockhash: hash.blockhash,
|
|
328
328
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
329
|
-
})).add.apply(
|
|
329
|
+
})).add.apply(_h, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
330
330
|
tx.partialSign(metadata);
|
|
331
331
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
332
332
|
case 8:
|
|
333
|
-
signature =
|
|
334
|
-
return [2 /*return*/, { ixs: ixs,
|
|
333
|
+
signature = _j.sent();
|
|
334
|
+
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadata.publicKey.toBase58() }];
|
|
335
335
|
}
|
|
336
336
|
});
|
|
337
337
|
});
|
|
@@ -341,13 +341,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
341
341
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
342
342
|
*/
|
|
343
343
|
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
344
|
-
var sender = _a.sender, _b = _a.
|
|
344
|
+
var sender = _a.sender, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
|
|
345
345
|
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
-
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData,
|
|
347
|
-
var e_1,
|
|
346
|
+
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, recipients_1, recipients_1_1, recipientData, _c, tx, metadata, metadataPubKey, e_1_1, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signedBatch, prepareTx, batchTransactionsCalls, responses, successes, failures, metadataIds;
|
|
347
|
+
var e_1, _d, _e;
|
|
348
348
|
var _this = this;
|
|
349
|
-
return __generator(this, function (
|
|
350
|
-
switch (
|
|
349
|
+
return __generator(this, function (_f) {
|
|
350
|
+
switch (_f.label) {
|
|
351
351
|
case 0:
|
|
352
352
|
recipients = data.recipients;
|
|
353
353
|
if (!sender.publicKey) {
|
|
@@ -358,36 +358,35 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
358
358
|
errors = [];
|
|
359
359
|
signatures = [];
|
|
360
360
|
batch = [];
|
|
361
|
-
|
|
361
|
+
_f.label = 1;
|
|
362
362
|
case 1:
|
|
363
|
-
|
|
363
|
+
_f.trys.push([1, 6, 7, 8]);
|
|
364
364
|
recipients_1 = __values(recipients), recipients_1_1 = recipients_1.next();
|
|
365
|
-
|
|
365
|
+
_f.label = 2;
|
|
366
366
|
case 2:
|
|
367
367
|
if (!!recipients_1_1.done) return [3 /*break*/, 5];
|
|
368
368
|
recipientData = recipients_1_1.value;
|
|
369
369
|
return [4 /*yield*/, this.prepareStreamTransaction(recipientData, data, {
|
|
370
370
|
sender: sender,
|
|
371
|
-
partner: partner,
|
|
372
371
|
})];
|
|
373
372
|
case 3:
|
|
374
|
-
|
|
373
|
+
_c = _f.sent(), tx = _c.tx, metadata = _c.metadata;
|
|
375
374
|
metadataPubKey = metadata.publicKey.toBase58();
|
|
376
375
|
metadataToRecipient[metadataPubKey] = recipientData;
|
|
377
376
|
metadatas.push(metadata);
|
|
378
377
|
batch.push({ tx: tx, recipient: recipientData.recipient });
|
|
379
|
-
|
|
378
|
+
_f.label = 4;
|
|
380
379
|
case 4:
|
|
381
380
|
recipients_1_1 = recipients_1.next();
|
|
382
381
|
return [3 /*break*/, 2];
|
|
383
382
|
case 5: return [3 /*break*/, 8];
|
|
384
383
|
case 6:
|
|
385
|
-
e_1_1 =
|
|
384
|
+
e_1_1 = _f.sent();
|
|
386
385
|
e_1 = { error: e_1_1 };
|
|
387
386
|
return [3 /*break*/, 8];
|
|
388
387
|
case 7:
|
|
389
388
|
try {
|
|
390
|
-
if (recipients_1_1 && !recipients_1_1.done && (
|
|
389
|
+
if (recipients_1_1 && !recipients_1_1.done && (_d = recipients_1.return)) _d.call(recipients_1);
|
|
391
390
|
}
|
|
392
391
|
finally { if (e_1) throw e_1.error; }
|
|
393
392
|
return [7 /*endfinally*/];
|
|
@@ -396,21 +395,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
396
395
|
totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
|
|
397
396
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
398
397
|
case 9:
|
|
399
|
-
nativeInstructions =
|
|
398
|
+
nativeInstructions = _f.sent();
|
|
400
399
|
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
401
400
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
402
401
|
case 10:
|
|
403
|
-
hash =
|
|
404
|
-
prepareTransaction = (
|
|
402
|
+
hash = _f.sent();
|
|
403
|
+
prepareTransaction = (_e = new web3_js_1.Transaction({
|
|
405
404
|
feePayer: sender.publicKey,
|
|
406
405
|
blockhash: hash.blockhash,
|
|
407
406
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
408
|
-
})).add.apply(
|
|
407
|
+
})).add.apply(_e, __spreadArray([], __read(nativeInstructions), false));
|
|
409
408
|
batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
|
|
410
|
-
|
|
409
|
+
_f.label = 11;
|
|
411
410
|
case 11: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
|
|
412
411
|
case 12:
|
|
413
|
-
signedBatch =
|
|
412
|
+
signedBatch = _f.sent();
|
|
414
413
|
signedBatch.forEach(function (item, index) {
|
|
415
414
|
item.tx.lastValidBlockHeight = batch[index].tx.lastValidBlockHeight;
|
|
416
415
|
});
|
|
@@ -418,15 +417,15 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
418
417
|
prepareTx = signedBatch.pop();
|
|
419
418
|
return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
|
|
420
419
|
case 13:
|
|
421
|
-
|
|
422
|
-
|
|
420
|
+
_f.sent();
|
|
421
|
+
_f.label = 14;
|
|
423
422
|
case 14:
|
|
424
423
|
batchTransactionsCalls = signedBatch.map(function (el) {
|
|
425
424
|
return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
|
|
426
425
|
});
|
|
427
426
|
return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
|
|
428
427
|
case 15:
|
|
429
|
-
responses =
|
|
428
|
+
responses = _f.sent();
|
|
430
429
|
successes = responses
|
|
431
430
|
.filter(function (el) { return el.status === "fulfilled"; })
|
|
432
431
|
.map(function (el) { return el.value; });
|
|
@@ -435,7 +434,8 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
435
434
|
.filter(function (el) { return el.status === "rejected"; })
|
|
436
435
|
.map(function (el) { return el.reason; });
|
|
437
436
|
errors.push.apply(errors, __spreadArray([], __read(failures), false));
|
|
438
|
-
|
|
437
|
+
metadataIds = metadatas.map(function (pk) { return pk.publicKey.toBase58(); });
|
|
438
|
+
return [2 /*return*/, { txs: signatures, metadatas: metadataIds, metadataToRecipient: metadataToRecipient, errors: errors }];
|
|
439
439
|
}
|
|
440
440
|
});
|
|
441
441
|
});
|
|
@@ -495,7 +495,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
495
495
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
496
496
|
case 5:
|
|
497
497
|
signature = _d.sent();
|
|
498
|
-
return [2 /*return*/, { ixs: ixs,
|
|
498
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
499
499
|
}
|
|
500
500
|
});
|
|
501
501
|
});
|
|
@@ -507,7 +507,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
507
507
|
var id = _a.id;
|
|
508
508
|
var invoker = _b.invoker;
|
|
509
509
|
return __awaiter(this, void 0, void 0, function () {
|
|
510
|
-
var streamPublicKey,
|
|
510
|
+
var streamPublicKey, escrowAcc, data, streamflowTreasuryTokens, partnerTokens, ixs, commitment, hash, tx, signature;
|
|
511
511
|
var _c;
|
|
512
512
|
return __generator(this, function (_d) {
|
|
513
513
|
switch (_d.label) {
|
|
@@ -518,11 +518,11 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
518
518
|
streamPublicKey = new web3_js_1.PublicKey(id);
|
|
519
519
|
return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
|
|
520
520
|
case 1:
|
|
521
|
-
|
|
522
|
-
if (!(
|
|
521
|
+
escrowAcc = _d.sent();
|
|
522
|
+
if (!(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data)) {
|
|
523
523
|
throw new Error("Couldn't get account info");
|
|
524
524
|
}
|
|
525
|
-
data = (0, utils_1.decodeStream)(
|
|
525
|
+
data = (0, utils_1.decodeStream)(escrowAcc === null || escrowAcc === void 0 ? void 0 : escrowAcc.data);
|
|
526
526
|
return [4 /*yield*/, (0, utils_1.ata)(data.mint, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
527
527
|
case 2:
|
|
528
528
|
streamflowTreasuryTokens = _d.sent();
|
|
@@ -557,7 +557,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
557
557
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
558
558
|
case 5:
|
|
559
559
|
signature = _d.sent();
|
|
560
|
-
return [2 /*return*/, { ixs: ixs,
|
|
560
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
561
561
|
}
|
|
562
562
|
});
|
|
563
563
|
});
|
|
@@ -614,7 +614,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
614
614
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
615
615
|
case 4:
|
|
616
616
|
signature = _d.sent();
|
|
617
|
-
return [2 /*return*/, { ixs: ixs,
|
|
617
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
618
618
|
}
|
|
619
619
|
});
|
|
620
620
|
});
|
|
@@ -685,7 +685,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
685
685
|
return [4 /*yield*/, this.sign(invoker, tx, hash)];
|
|
686
686
|
case 8:
|
|
687
687
|
signature = _f.sent();
|
|
688
|
-
return [2 /*return*/, { ixs: ixs,
|
|
688
|
+
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
689
689
|
}
|
|
690
690
|
});
|
|
691
691
|
});
|
|
@@ -715,25 +715,26 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
715
715
|
* Streams are sorted by start time in ascending order.
|
|
716
716
|
*/
|
|
717
717
|
SolanaStreamClient.prototype.get = function (_a) {
|
|
718
|
-
var
|
|
718
|
+
var address = _a.address, _b = _a.type, type = _b === void 0 ? types_2.StreamType.All : _b, _c = _a.direction, direction = _c === void 0 ? types_2.StreamDirection.All : _c;
|
|
719
719
|
return __awaiter(this, void 0, void 0, function () {
|
|
720
|
-
var accounts, outgoingAccounts, incomingAccounts, offset, streams, sortedStreams;
|
|
720
|
+
var publicKey, accounts, outgoingAccounts, incomingAccounts, offset, streams, sortedStreams;
|
|
721
721
|
return __generator(this, function (_d) {
|
|
722
722
|
switch (_d.label) {
|
|
723
723
|
case 0:
|
|
724
|
+
publicKey = new web3_js_1.PublicKey(address);
|
|
724
725
|
accounts = [];
|
|
725
726
|
if (!(direction === "all")) return [3 /*break*/, 3];
|
|
726
|
-
return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection,
|
|
727
|
+
return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, publicKey, constants_1.STREAM_STRUCT_OFFSET_SENDER, this.programId)];
|
|
727
728
|
case 1:
|
|
728
729
|
outgoingAccounts = _d.sent();
|
|
729
|
-
return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection,
|
|
730
|
+
return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, publicKey, constants_1.STREAM_STRUCT_OFFSET_RECIPIENT, this.programId)];
|
|
730
731
|
case 2:
|
|
731
732
|
incomingAccounts = _d.sent();
|
|
732
733
|
accounts = __spreadArray(__spreadArray([], __read(outgoingAccounts), false), __read(incomingAccounts), false);
|
|
733
734
|
return [3 /*break*/, 5];
|
|
734
735
|
case 3:
|
|
735
736
|
offset = direction === "outgoing" ? constants_1.STREAM_STRUCT_OFFSET_SENDER : constants_1.STREAM_STRUCT_OFFSET_RECIPIENT;
|
|
736
|
-
return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection,
|
|
737
|
+
return [4 /*yield*/, (0, utils_1.getProgramAccounts)(this.connection, publicKey, offset, this.programId)];
|
|
737
738
|
case 4:
|
|
738
739
|
accounts = _d.sent();
|
|
739
740
|
_d.label = 5;
|
|
@@ -830,7 +831,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
830
831
|
signature = _b.sent();
|
|
831
832
|
return [2 /*return*/, {
|
|
832
833
|
ixs: [updateIx],
|
|
833
|
-
|
|
834
|
+
txId: signature,
|
|
834
835
|
}];
|
|
835
836
|
}
|
|
836
837
|
});
|
|
@@ -841,13 +842,13 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
841
842
|
*/
|
|
842
843
|
SolanaStreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams, solanaExtendedConfig) {
|
|
843
844
|
return __awaiter(this, void 0, void 0, function () {
|
|
844
|
-
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency,
|
|
845
|
-
var
|
|
846
|
-
return __generator(this, function (
|
|
847
|
-
switch (
|
|
845
|
+
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, ixs, commitment, recipientPublicKey, mintPublicKey, metadata, _c, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
|
|
846
|
+
var _d;
|
|
847
|
+
return __generator(this, function (_e) {
|
|
848
|
+
switch (_e.label) {
|
|
848
849
|
case 0:
|
|
849
|
-
mint = streamParams.tokenId, start = streamParams.start, period = streamParams.period, cliff = streamParams.cliff, canTopup = streamParams.canTopup, cancelableBySender = streamParams.cancelableBySender, cancelableByRecipient = streamParams.cancelableByRecipient, transferableBySender = streamParams.transferableBySender, transferableByRecipient = streamParams.transferableByRecipient, _a = streamParams.automaticWithdrawal, automaticWithdrawal = _a === void 0 ? false : _a, _b = streamParams.withdrawalFrequency, withdrawalFrequency = _b === void 0 ? 0 : _b;
|
|
850
|
-
sender = solanaExtendedConfig.sender
|
|
850
|
+
mint = streamParams.tokenId, start = streamParams.start, period = streamParams.period, cliff = streamParams.cliff, canTopup = streamParams.canTopup, cancelableBySender = streamParams.cancelableBySender, cancelableByRecipient = streamParams.cancelableByRecipient, transferableBySender = streamParams.transferableBySender, transferableByRecipient = streamParams.transferableByRecipient, _a = streamParams.automaticWithdrawal, automaticWithdrawal = _a === void 0 ? false : _a, _b = streamParams.withdrawalFrequency, withdrawalFrequency = _b === void 0 ? 0 : _b, partner = streamParams.partner;
|
|
851
|
+
sender = solanaExtendedConfig.sender;
|
|
851
852
|
if (!sender.publicKey) {
|
|
852
853
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
853
854
|
}
|
|
@@ -856,20 +857,20 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
856
857
|
recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
857
858
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
858
859
|
metadata = web3_js_1.Keypair.generate();
|
|
859
|
-
|
|
860
|
+
_c = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadata.publicKey.toBuffer()], this.programId), 1), escrowTokens = _c[0];
|
|
860
861
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
861
862
|
case 1:
|
|
862
|
-
senderTokens =
|
|
863
|
+
senderTokens = _e.sent();
|
|
863
864
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
864
865
|
case 2:
|
|
865
|
-
recipientTokens =
|
|
866
|
+
recipientTokens = _e.sent();
|
|
866
867
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
867
868
|
case 3:
|
|
868
|
-
streamflowTreasuryTokens =
|
|
869
|
+
streamflowTreasuryTokens = _e.sent();
|
|
869
870
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
870
871
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
871
872
|
case 4:
|
|
872
|
-
partnerTokens =
|
|
873
|
+
partnerTokens = _e.sent();
|
|
873
874
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
874
875
|
start: new bn_js_1.default(start),
|
|
875
876
|
depositedAmount: recipient.amount,
|
|
@@ -907,12 +908,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
907
908
|
}));
|
|
908
909
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
909
910
|
case 5:
|
|
910
|
-
hash =
|
|
911
|
-
tx = (
|
|
911
|
+
hash = _e.sent();
|
|
912
|
+
tx = (_d = new web3_js_1.Transaction({
|
|
912
913
|
feePayer: sender.publicKey,
|
|
913
914
|
blockhash: hash.blockhash,
|
|
914
915
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
915
|
-
})).add.apply(
|
|
916
|
+
})).add.apply(_d, __spreadArray([], __read(ixs), false));
|
|
916
917
|
tx.partialSign(metadata);
|
|
917
918
|
return [2 /*return*/, { tx: tx, metadata: metadata }];
|
|
918
919
|
}
|
package/dist/solana/types.d.ts
CHANGED
|
@@ -171,7 +171,7 @@ export interface Stream {
|
|
|
171
171
|
canTopup: boolean;
|
|
172
172
|
name: string;
|
|
173
173
|
withdrawalFrequency: number;
|
|
174
|
-
unlocked(currentTimestamp: number
|
|
174
|
+
unlocked(currentTimestamp: number): BN;
|
|
175
175
|
}
|
|
176
176
|
export declare class Contract implements Stream {
|
|
177
177
|
magic: number;
|
|
@@ -212,7 +212,7 @@ export declare class Contract implements Stream {
|
|
|
212
212
|
name: string;
|
|
213
213
|
withdrawalFrequency: number;
|
|
214
214
|
constructor(stream: DecodedStream);
|
|
215
|
-
unlocked(currentTimestamp: number
|
|
215
|
+
unlocked(currentTimestamp: number): BN;
|
|
216
216
|
remaining(decimals: number): number;
|
|
217
217
|
}
|
|
218
218
|
export interface DecodedStream {
|
package/dist/solana/types.js
CHANGED
|
@@ -49,15 +49,14 @@ var Contract = /** @class */ (function () {
|
|
|
49
49
|
this.name = stream.name;
|
|
50
50
|
this.withdrawalFrequency = stream.withdrawFrequency.toNumber();
|
|
51
51
|
}
|
|
52
|
-
Contract.prototype.unlocked = function (currentTimestamp
|
|
53
|
-
var deposited =
|
|
52
|
+
Contract.prototype.unlocked = function (currentTimestamp) {
|
|
53
|
+
var deposited = this.depositedAmount;
|
|
54
54
|
if (currentTimestamp < this.cliff)
|
|
55
|
-
return 0;
|
|
55
|
+
return new bn_js_1.default(0);
|
|
56
56
|
if (currentTimestamp > this.end)
|
|
57
57
|
return deposited;
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
return streamed < deposited ? streamed : deposited;
|
|
58
|
+
var streamed = this.cliffAmount.add(new bn_js_1.default(Math.floor((currentTimestamp - this.cliff) / this.period)).mul(this.amountPerPeriod));
|
|
59
|
+
return streamed.lt(deposited) ? streamed : deposited;
|
|
61
60
|
};
|
|
62
61
|
Contract.prototype.remaining = function (decimals) {
|
|
63
62
|
return (0, utils_1.getNumberFromBN)(this.depositedAmount.sub(this.withdrawnAmount), decimals);
|
package/dist/solana/utils.js
CHANGED
|
@@ -144,7 +144,7 @@ var formatDecodedStream = function (stream) {
|
|
|
144
144
|
name: stream.name,
|
|
145
145
|
withdrawalFrequency: stream.withdrawFrequency.toNumber(),
|
|
146
146
|
unlocked: function () {
|
|
147
|
-
return 0;
|
|
147
|
+
return new bn_js_1.default(0);
|
|
148
148
|
},
|
|
149
149
|
withdrawn: function () {
|
|
150
150
|
return new bn_js_1.default(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.1.0-beta.1",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"gitHead": "a37306eba0e762af096db642fa22f07194014cfd",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/bn.js": "5.1.1",
|
|
17
|
+
"@types/ethereum-checksum-address": "^0.0.0",
|
|
17
18
|
"@types/jest": "29.2.4",
|
|
18
19
|
"date-fns": "2.28.0",
|
|
19
20
|
"eslint": "8.29.0",
|
|
@@ -35,6 +36,8 @@
|
|
|
35
36
|
"aptos": "1.4.0",
|
|
36
37
|
"bn.js": "5.2.1",
|
|
37
38
|
"bs58": "5.0.0",
|
|
39
|
+
"ethereum-checksum-address": "0.0.8",
|
|
40
|
+
"ethers": "5.7.2",
|
|
38
41
|
"js-sha256": "0.9.0"
|
|
39
42
|
}
|
|
40
43
|
}
|