@streamflow/stream 5.7.0 → 5.7.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/solana/StreamClient.d.ts +4 -0
- package/dist/solana/StreamClient.js +130 -85
- package/package.json +2 -2
|
@@ -69,4 +69,8 @@ export default class SolanaStreamClient extends BaseStreamClient {
|
|
|
69
69
|
* Forms instructions from params, creates a raw transaction and fetch recent blockhash.
|
|
70
70
|
*/
|
|
71
71
|
private prepareStreamTransaction;
|
|
72
|
+
/**
|
|
73
|
+
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
74
|
+
*/
|
|
75
|
+
private getOrCreateStreamMetadata;
|
|
72
76
|
}
|
|
@@ -87,6 +87,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
87
87
|
}
|
|
88
88
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
89
89
|
};
|
|
90
|
+
var __values = (this && this.__values) || function(o) {
|
|
91
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
92
|
+
if (m) return m.call(o);
|
|
93
|
+
if (o && typeof o.length === "number") return {
|
|
94
|
+
next: function () {
|
|
95
|
+
if (o && i >= o.length) o = void 0;
|
|
96
|
+
return { value: o && o[i++], done: !o };
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
100
|
+
};
|
|
90
101
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
91
102
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
92
103
|
};
|
|
@@ -133,10 +144,10 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
133
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;
|
|
134
145
|
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
135
146
|
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
-
var ixs, mintPublicKey, recipientPublicKey, metadata, metadataPubKey,
|
|
137
|
-
var
|
|
138
|
-
return __generator(this, function (
|
|
139
|
-
switch (
|
|
147
|
+
var ixs, mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, _g, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, nativeInstructions, _h, commitment, hash, tx, signature;
|
|
148
|
+
var _j;
|
|
149
|
+
return __generator(this, function (_k) {
|
|
150
|
+
switch (_k.label) {
|
|
140
151
|
case 0:
|
|
141
152
|
if (!sender.publicKey) {
|
|
142
153
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -144,38 +155,31 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
144
155
|
ixs = [];
|
|
145
156
|
mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
|
|
146
157
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
147
|
-
metadata =
|
|
148
|
-
|
|
149
|
-
metadata = web3_js_1.Keypair.generate();
|
|
150
|
-
metadataPubKey = metadata.publicKey;
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
metadataPubKey = metadataPubKeys[0];
|
|
154
|
-
}
|
|
155
|
-
_f = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _f[0];
|
|
158
|
+
_f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
|
|
159
|
+
_g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
|
|
156
160
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
157
161
|
case 1:
|
|
158
|
-
senderTokens =
|
|
162
|
+
senderTokens = _k.sent();
|
|
159
163
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
160
164
|
case 2:
|
|
161
|
-
recipientTokens =
|
|
165
|
+
recipientTokens = _k.sent();
|
|
162
166
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
163
167
|
case 3:
|
|
164
|
-
streamflowTreasuryTokens =
|
|
168
|
+
streamflowTreasuryTokens = _k.sent();
|
|
165
169
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
166
170
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
167
171
|
case 4:
|
|
168
|
-
partnerTokens =
|
|
172
|
+
partnerTokens = _k.sent();
|
|
169
173
|
if (!isNative) return [3 /*break*/, 6];
|
|
170
174
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
171
175
|
case 5:
|
|
172
|
-
|
|
176
|
+
_h = _k.sent();
|
|
173
177
|
return [3 /*break*/, 7];
|
|
174
178
|
case 6:
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
_h = [];
|
|
180
|
+
_k.label = 7;
|
|
177
181
|
case 7:
|
|
178
|
-
nativeInstructions =
|
|
182
|
+
nativeInstructions = _h;
|
|
179
183
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
180
184
|
start: new bn_js_1.default(start),
|
|
181
185
|
depositedAmount: depositedAmount,
|
|
@@ -214,18 +218,18 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
214
218
|
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
215
219
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
216
220
|
case 8:
|
|
217
|
-
hash =
|
|
218
|
-
tx = (
|
|
221
|
+
hash = _k.sent();
|
|
222
|
+
tx = (_j = new web3_js_1.Transaction({
|
|
219
223
|
feePayer: sender.publicKey,
|
|
220
224
|
blockhash: hash.blockhash,
|
|
221
225
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
222
|
-
})).add.apply(
|
|
226
|
+
})).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
223
227
|
if (metadata) {
|
|
224
228
|
tx.partialSign(metadata);
|
|
225
229
|
}
|
|
226
230
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
227
231
|
case 9:
|
|
228
|
-
signature =
|
|
232
|
+
signature = _k.sent();
|
|
229
233
|
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
230
234
|
}
|
|
231
235
|
});
|
|
@@ -245,27 +249,20 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
245
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;
|
|
246
250
|
var sender = _b.sender, metadataPubKeys = _b.metadataPubKeys, _e = _b.isNative, isNative = _e === void 0 ? false : _e;
|
|
247
251
|
return __awaiter(this, void 0, void 0, function () {
|
|
248
|
-
var mintPublicKey, recipientPublicKey, metadata, metadataPubKey, rentToExempt, createMetadataInstruction,
|
|
249
|
-
var
|
|
250
|
-
return __generator(this, function (
|
|
251
|
-
switch (
|
|
252
|
+
var mintPublicKey, recipientPublicKey, _f, metadata, metadataPubKey, rentToExempt, createMetadataInstruction, _g, escrowTokens, senderTokens, partnerPublicKey, nativeInstructions, _h, createInstruction, commitment, ixs, hash, tx, signature;
|
|
253
|
+
var _j;
|
|
254
|
+
return __generator(this, function (_k) {
|
|
255
|
+
switch (_k.label) {
|
|
252
256
|
case 0:
|
|
253
257
|
if (!sender.publicKey) {
|
|
254
258
|
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
255
259
|
}
|
|
256
260
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
257
261
|
recipientPublicKey = new web3_js_1.PublicKey(recipient);
|
|
258
|
-
metadata =
|
|
259
|
-
if (!metadataPubKeys) {
|
|
260
|
-
metadata = web3_js_1.Keypair.generate();
|
|
261
|
-
metadataPubKey = metadata.publicKey;
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
metadataPubKey = metadataPubKeys[0];
|
|
265
|
-
}
|
|
262
|
+
_f = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _f.metadata, metadataPubKey = _f.metadataPubKey;
|
|
266
263
|
return [4 /*yield*/, this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE)];
|
|
267
264
|
case 1:
|
|
268
|
-
rentToExempt =
|
|
265
|
+
rentToExempt = _k.sent();
|
|
269
266
|
createMetadataInstruction = web3_js_1.SystemProgram.createAccount({
|
|
270
267
|
programId: this.programId,
|
|
271
268
|
space: METADATA_ACC_SIZE,
|
|
@@ -273,21 +270,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
273
270
|
fromPubkey: sender === null || sender === void 0 ? void 0 : sender.publicKey,
|
|
274
271
|
newAccountPubkey: metadataPubKey,
|
|
275
272
|
});
|
|
276
|
-
|
|
273
|
+
_g = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _g[0];
|
|
277
274
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
278
275
|
case 2:
|
|
279
|
-
senderTokens =
|
|
276
|
+
senderTokens = _k.sent();
|
|
280
277
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
281
278
|
if (!isNative) return [3 /*break*/, 4];
|
|
282
279
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, depositedAmount)];
|
|
283
280
|
case 3:
|
|
284
|
-
|
|
281
|
+
_h = _k.sent();
|
|
285
282
|
return [3 /*break*/, 5];
|
|
286
283
|
case 4:
|
|
287
|
-
|
|
288
|
-
|
|
284
|
+
_h = [];
|
|
285
|
+
_k.label = 5;
|
|
289
286
|
case 5:
|
|
290
|
-
nativeInstructions =
|
|
287
|
+
nativeInstructions = _h;
|
|
291
288
|
createInstruction = (0, instructions_1.createUncheckedStreamInstruction)({
|
|
292
289
|
start: new bn_js_1.default(start),
|
|
293
290
|
depositedAmount: depositedAmount,
|
|
@@ -322,18 +319,18 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
322
319
|
ixs = [createMetadataInstruction, createInstruction];
|
|
323
320
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
324
321
|
case 6:
|
|
325
|
-
hash =
|
|
326
|
-
tx = (
|
|
322
|
+
hash = _k.sent();
|
|
323
|
+
tx = (_j = new web3_js_1.Transaction({
|
|
327
324
|
feePayer: sender.publicKey,
|
|
328
325
|
blockhash: hash.blockhash,
|
|
329
326
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
330
|
-
})).add.apply(
|
|
327
|
+
})).add.apply(_j, __spreadArray(__spreadArray([], __read(nativeInstructions), false), __read(ixs), false));
|
|
331
328
|
if (metadata) {
|
|
332
329
|
tx.partialSign(metadata);
|
|
333
330
|
}
|
|
334
331
|
return [4 /*yield*/, this.sign(sender, tx, hash)];
|
|
335
332
|
case 7:
|
|
336
|
-
signature =
|
|
333
|
+
signature = _k.sent();
|
|
337
334
|
return [2 /*return*/, { ixs: ixs, txId: signature, metadataId: metadataPubKey.toBase58() }];
|
|
338
335
|
}
|
|
339
336
|
});
|
|
@@ -346,11 +343,11 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
346
343
|
SolanaStreamClient.prototype.createMultiple = function (data, _a) {
|
|
347
344
|
var sender = _a.sender, metadataPubKeys = _a.metadataPubKeys, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
|
|
348
345
|
return __awaiter(this, void 0, void 0, function () {
|
|
349
|
-
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, i, recipientData, _c, tx, metadataPubKey, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signedBatch, prepareTx, batchTransactionsCalls,
|
|
350
|
-
var
|
|
346
|
+
var recipients, metadatas, metadataToRecipient, errors, signatures, batch, i, recipientData, _c, tx, metadataPubKey, totalDepositedAmount, nativeInstructions, commitment, hash, prepareTransaction, signedBatch, prepareTx, responses, signedBatch_1, signedBatch_1_1, batchTx, _d, _e, _f, _g, e_1_1, batchTransactionsCalls, _h, _j, _k, _l, successes, failures;
|
|
347
|
+
var _m, e_1, _o;
|
|
351
348
|
var _this = this;
|
|
352
|
-
return __generator(this, function (
|
|
353
|
-
switch (
|
|
349
|
+
return __generator(this, function (_p) {
|
|
350
|
+
switch (_p.label) {
|
|
354
351
|
case 0:
|
|
355
352
|
recipients = data.recipients;
|
|
356
353
|
if (!sender.publicKey) {
|
|
@@ -363,7 +360,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
363
360
|
batch = [];
|
|
364
361
|
metadataPubKeys = metadataPubKeys || [];
|
|
365
362
|
i = 0;
|
|
366
|
-
|
|
363
|
+
_p.label = 1;
|
|
367
364
|
case 1:
|
|
368
365
|
if (!(i < recipients.length)) return [3 /*break*/, 4];
|
|
369
366
|
recipientData = recipients[i];
|
|
@@ -372,11 +369,11 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
372
369
|
metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
|
|
373
370
|
})];
|
|
374
371
|
case 2:
|
|
375
|
-
_c =
|
|
372
|
+
_c = _p.sent(), tx = _c.tx, metadataPubKey = _c.metadataPubKey;
|
|
376
373
|
metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
|
|
377
374
|
metadatas.push(metadataPubKey.toBase58());
|
|
378
375
|
batch.push({ tx: tx, recipient: recipientData.recipient });
|
|
379
|
-
|
|
376
|
+
_p.label = 3;
|
|
380
377
|
case 3:
|
|
381
378
|
i++;
|
|
382
379
|
return [3 /*break*/, 1];
|
|
@@ -385,21 +382,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
385
382
|
totalDepositedAmount = recipients.reduce(function (acc, recipient) { return recipient.amount.add(acc); }, new bn_js_1.default(0));
|
|
386
383
|
return [4 /*yield*/, (0, instructions_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount)];
|
|
387
384
|
case 5:
|
|
388
|
-
nativeInstructions =
|
|
385
|
+
nativeInstructions = _p.sent();
|
|
389
386
|
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
390
387
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
391
388
|
case 6:
|
|
392
|
-
hash =
|
|
393
|
-
prepareTransaction = (
|
|
389
|
+
hash = _p.sent();
|
|
390
|
+
prepareTransaction = (_m = new web3_js_1.Transaction({
|
|
394
391
|
feePayer: sender.publicKey,
|
|
395
392
|
blockhash: hash.blockhash,
|
|
396
393
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
397
|
-
})).add.apply(
|
|
394
|
+
})).add.apply(_m, __spreadArray([], __read(nativeInstructions), false));
|
|
398
395
|
batch.push({ tx: prepareTransaction, recipient: sender.publicKey.toBase58() });
|
|
399
|
-
|
|
396
|
+
_p.label = 7;
|
|
400
397
|
case 7: return [4 /*yield*/, (0, utils_1.signAllTransactionWithRecipients)(sender, batch)];
|
|
401
398
|
case 8:
|
|
402
|
-
signedBatch =
|
|
399
|
+
signedBatch = _p.sent();
|
|
403
400
|
signedBatch.forEach(function (item, index) {
|
|
404
401
|
item.tx.lastValidBlockHeight = batch[index].tx.lastValidBlockHeight;
|
|
405
402
|
});
|
|
@@ -407,15 +404,55 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
407
404
|
prepareTx = signedBatch.pop();
|
|
408
405
|
return [4 /*yield*/, (0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx)];
|
|
409
406
|
case 9:
|
|
410
|
-
|
|
411
|
-
|
|
407
|
+
_p.sent();
|
|
408
|
+
_p.label = 10;
|
|
412
409
|
case 10:
|
|
410
|
+
responses = [];
|
|
411
|
+
if (!(metadataPubKeys.length > 0)) return [3 /*break*/, 19];
|
|
412
|
+
_p.label = 11;
|
|
413
|
+
case 11:
|
|
414
|
+
_p.trys.push([11, 16, 17, 18]);
|
|
415
|
+
signedBatch_1 = __values(signedBatch), signedBatch_1_1 = signedBatch_1.next();
|
|
416
|
+
_p.label = 12;
|
|
417
|
+
case 12:
|
|
418
|
+
if (!!signedBatch_1_1.done) return [3 /*break*/, 15];
|
|
419
|
+
batchTx = signedBatch_1_1.value;
|
|
420
|
+
_e = (_d = responses.push).apply;
|
|
421
|
+
_f = [responses];
|
|
422
|
+
_g = [[]];
|
|
423
|
+
return [4 /*yield*/, Promise.allSettled([
|
|
424
|
+
(0, utils_1.sendAndConfirmStreamRawTransaction)(this.connection, batchTx),
|
|
425
|
+
])];
|
|
426
|
+
case 13:
|
|
427
|
+
_e.apply(_d, _f.concat([__spreadArray.apply(void 0, _g.concat([__read.apply(void 0, [(_p.sent())]), false]))]));
|
|
428
|
+
_p.label = 14;
|
|
429
|
+
case 14:
|
|
430
|
+
signedBatch_1_1 = signedBatch_1.next();
|
|
431
|
+
return [3 /*break*/, 12];
|
|
432
|
+
case 15: return [3 /*break*/, 18];
|
|
433
|
+
case 16:
|
|
434
|
+
e_1_1 = _p.sent();
|
|
435
|
+
e_1 = { error: e_1_1 };
|
|
436
|
+
return [3 /*break*/, 18];
|
|
437
|
+
case 17:
|
|
438
|
+
try {
|
|
439
|
+
if (signedBatch_1_1 && !signedBatch_1_1.done && (_o = signedBatch_1.return)) _o.call(signedBatch_1);
|
|
440
|
+
}
|
|
441
|
+
finally { if (e_1) throw e_1.error; }
|
|
442
|
+
return [7 /*endfinally*/];
|
|
443
|
+
case 18: return [3 /*break*/, 21];
|
|
444
|
+
case 19:
|
|
413
445
|
batchTransactionsCalls = signedBatch.map(function (el) {
|
|
414
446
|
return (0, utils_1.sendAndConfirmStreamRawTransaction)(_this.connection, el);
|
|
415
447
|
});
|
|
448
|
+
_j = (_h = responses.push).apply;
|
|
449
|
+
_k = [responses];
|
|
450
|
+
_l = [[]];
|
|
416
451
|
return [4 /*yield*/, Promise.allSettled(batchTransactionsCalls)];
|
|
417
|
-
case
|
|
418
|
-
|
|
452
|
+
case 20:
|
|
453
|
+
_j.apply(_h, _k.concat([__spreadArray.apply(void 0, _l.concat([__read.apply(void 0, [(_p.sent())]), false]))]));
|
|
454
|
+
_p.label = 21;
|
|
455
|
+
case 21:
|
|
419
456
|
successes = responses
|
|
420
457
|
.filter(function (el) { return el.status === "fulfilled"; })
|
|
421
458
|
.map(function (el) { return el.value; });
|
|
@@ -833,10 +870,10 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
833
870
|
*/
|
|
834
871
|
SolanaStreamClient.prototype.prepareStreamTransaction = function (recipient, streamParams, solanaExtendedConfig) {
|
|
835
872
|
return __awaiter(this, void 0, void 0, function () {
|
|
836
|
-
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, metadataPubKeys, ixs, commitment, recipientPublicKey, mintPublicKey, metadata, metadataPubKey,
|
|
837
|
-
var
|
|
838
|
-
return __generator(this, function (
|
|
839
|
-
switch (
|
|
873
|
+
var mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, _a, automaticWithdrawal, _b, withdrawalFrequency, partner, sender, metadataPubKeys, ixs, commitment, recipientPublicKey, mintPublicKey, _c, metadata, metadataPubKey, _d, escrowTokens, senderTokens, recipientTokens, streamflowTreasuryTokens, partnerPublicKey, partnerTokens, hash, tx;
|
|
874
|
+
var _e;
|
|
875
|
+
return __generator(this, function (_f) {
|
|
876
|
+
switch (_f.label) {
|
|
840
877
|
case 0:
|
|
841
878
|
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;
|
|
842
879
|
sender = solanaExtendedConfig.sender, metadataPubKeys = solanaExtendedConfig.metadataPubKeys;
|
|
@@ -847,28 +884,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
847
884
|
commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
848
885
|
recipientPublicKey = new web3_js_1.PublicKey(recipient.recipient);
|
|
849
886
|
mintPublicKey = new web3_js_1.PublicKey(mint);
|
|
850
|
-
metadata =
|
|
851
|
-
|
|
852
|
-
metadata = web3_js_1.Keypair.generate();
|
|
853
|
-
metadataPubKey = metadata.publicKey;
|
|
854
|
-
}
|
|
855
|
-
else {
|
|
856
|
-
metadataPubKey = metadataPubKeys[0];
|
|
857
|
-
}
|
|
858
|
-
_c = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _c[0];
|
|
887
|
+
_c = this.getOrCreateStreamMetadata(metadataPubKeys), metadata = _c.metadata, metadataPubKey = _c.metadataPubKey;
|
|
888
|
+
_d = __read(web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId), 1), escrowTokens = _d[0];
|
|
859
889
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, sender.publicKey)];
|
|
860
890
|
case 1:
|
|
861
|
-
senderTokens =
|
|
891
|
+
senderTokens = _f.sent();
|
|
862
892
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, recipientPublicKey)];
|
|
863
893
|
case 2:
|
|
864
|
-
recipientTokens =
|
|
894
|
+
recipientTokens = _f.sent();
|
|
865
895
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY)];
|
|
866
896
|
case 3:
|
|
867
|
-
streamflowTreasuryTokens =
|
|
897
|
+
streamflowTreasuryTokens = _f.sent();
|
|
868
898
|
partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
|
|
869
899
|
return [4 /*yield*/, (0, utils_1.ata)(mintPublicKey, partnerPublicKey)];
|
|
870
900
|
case 4:
|
|
871
|
-
partnerTokens =
|
|
901
|
+
partnerTokens = _f.sent();
|
|
872
902
|
ixs.push((0, instructions_1.createStreamInstruction)({
|
|
873
903
|
start: new bn_js_1.default(start),
|
|
874
904
|
depositedAmount: recipient.amount,
|
|
@@ -906,12 +936,12 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
906
936
|
}));
|
|
907
937
|
return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
|
|
908
938
|
case 5:
|
|
909
|
-
hash =
|
|
910
|
-
tx = (
|
|
939
|
+
hash = _f.sent();
|
|
940
|
+
tx = (_e = new web3_js_1.Transaction({
|
|
911
941
|
feePayer: sender.publicKey,
|
|
912
942
|
blockhash: hash.blockhash,
|
|
913
943
|
lastValidBlockHeight: hash.lastValidBlockHeight,
|
|
914
|
-
})).add.apply(
|
|
944
|
+
})).add.apply(_e, __spreadArray([], __read(ixs), false));
|
|
915
945
|
if (metadata) {
|
|
916
946
|
tx.partialSign(metadata);
|
|
917
947
|
}
|
|
@@ -920,6 +950,21 @@ var SolanaStreamClient = /** @class */ (function (_super) {
|
|
|
920
950
|
});
|
|
921
951
|
});
|
|
922
952
|
};
|
|
953
|
+
/**
|
|
954
|
+
* Utility function to generate metadata for a Contract or return existing Pubkey
|
|
955
|
+
*/
|
|
956
|
+
SolanaStreamClient.prototype.getOrCreateStreamMetadata = function (metadataPubKeys) {
|
|
957
|
+
var metadata;
|
|
958
|
+
var metadataPubKey;
|
|
959
|
+
if (!metadataPubKeys) {
|
|
960
|
+
metadata = web3_js_1.Keypair.generate();
|
|
961
|
+
metadataPubKey = metadata.publicKey;
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
964
|
+
metadataPubKey = metadataPubKeys[0];
|
|
965
|
+
}
|
|
966
|
+
return { metadata: metadata, metadataPubKey: metadataPubKey };
|
|
967
|
+
};
|
|
923
968
|
return SolanaStreamClient;
|
|
924
969
|
}(BaseStreamClient_1.BaseStreamClient));
|
|
925
970
|
exports.default = SolanaStreamClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "5.7.
|
|
3
|
+
"version": "5.7.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/",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"lint": "eslint .",
|
|
12
12
|
"prepublishOnly": "npm run lint && npm test && npm run build"
|
|
13
13
|
},
|
|
14
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "c28cc0748df1a67de8977faf0286566f74ad1faa",
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/bn.js": "5.1.1",
|
|
17
17
|
"@types/ethereum-checksum-address": "^0.0.0",
|