@streamflow/stream 7.0.0 → 7.0.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.
|
@@ -426,6 +426,102 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
426
426
|
});
|
|
427
427
|
return { txs: signatures, metadatas, metadataToRecipient, errors };
|
|
428
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Creates multiple stream/vesting contracts, and send all transactions sequentially.
|
|
431
|
+
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
432
|
+
*/
|
|
433
|
+
async createMultipleSequential(data, extParams) {
|
|
434
|
+
const { recipients, ...streamParams } = data;
|
|
435
|
+
const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit } = extParams;
|
|
436
|
+
const metadatas = [];
|
|
437
|
+
const metadataToRecipient = {};
|
|
438
|
+
const errors = [];
|
|
439
|
+
const signatures = [];
|
|
440
|
+
const batch = [];
|
|
441
|
+
const instructionsBatch = [];
|
|
442
|
+
const metadataPubKeys = metadataPubKeysExt || [];
|
|
443
|
+
const partnerPublicKey = data.partner ? new web3_js_1.PublicKey(data.partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
|
|
444
|
+
const mintPublicKey = new web3_js_1.PublicKey(data.tokenId);
|
|
445
|
+
if (recipients.length === 0) {
|
|
446
|
+
throw new Error("Recipients array is empty!");
|
|
447
|
+
}
|
|
448
|
+
if (!sender.publicKey) {
|
|
449
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
450
|
+
}
|
|
451
|
+
for (let i = 0; i < recipients.length; i++) {
|
|
452
|
+
const recipientData = recipients[i];
|
|
453
|
+
const createStreamData = { ...streamParams, ...recipientData };
|
|
454
|
+
const createStreamExtParams = {
|
|
455
|
+
sender,
|
|
456
|
+
metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
|
|
457
|
+
computePrice,
|
|
458
|
+
computeLimit,
|
|
459
|
+
};
|
|
460
|
+
const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(createStreamData, createStreamExtParams);
|
|
461
|
+
metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
|
|
462
|
+
metadatas.push(metadataPubKey.toBase58());
|
|
463
|
+
instructionsBatch.push({
|
|
464
|
+
ixs,
|
|
465
|
+
metadata,
|
|
466
|
+
recipient: recipientData.recipient,
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
|
|
470
|
+
for (const { ixs, metadata, recipient } of instructionsBatch) {
|
|
471
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
472
|
+
payerKey: sender.publicKey,
|
|
473
|
+
recentBlockhash: hash.blockhash,
|
|
474
|
+
instructions: ixs,
|
|
475
|
+
}).compileToV0Message();
|
|
476
|
+
const tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
477
|
+
if (metadata) {
|
|
478
|
+
tx.sign([metadata]);
|
|
479
|
+
}
|
|
480
|
+
batch.push({ tx, recipient });
|
|
481
|
+
}
|
|
482
|
+
const prepareInstructions = await this.getCreateATAInstructions([constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
|
|
483
|
+
if (isNative) {
|
|
484
|
+
const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new bn_js_1.default(0));
|
|
485
|
+
const nativeInstructions = await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalDepositedAmount);
|
|
486
|
+
prepareInstructions.push(...nativeInstructions);
|
|
487
|
+
}
|
|
488
|
+
if (prepareInstructions.length > 0) {
|
|
489
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
490
|
+
payerKey: sender.publicKey,
|
|
491
|
+
recentBlockhash: hash.blockhash,
|
|
492
|
+
instructions: prepareInstructions,
|
|
493
|
+
}).compileToV0Message();
|
|
494
|
+
const tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
495
|
+
batch.push({
|
|
496
|
+
tx,
|
|
497
|
+
recipient: sender.publicKey.toBase58(),
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
const signedBatch = await (0, utils_js_1.signAllTransactionWithRecipients)(sender, batch);
|
|
501
|
+
if (prepareInstructions.length > 0) {
|
|
502
|
+
const prepareTx = signedBatch.pop();
|
|
503
|
+
await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
|
|
504
|
+
}
|
|
505
|
+
const responses = [];
|
|
506
|
+
for (const batchTx of signedBatch) {
|
|
507
|
+
responses.push(...(await Promise.allSettled([
|
|
508
|
+
(0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context }, { sendThrottler: this.sendThrottler }),
|
|
509
|
+
])));
|
|
510
|
+
}
|
|
511
|
+
responses.forEach((item, index) => {
|
|
512
|
+
if (item.status === "fulfilled") {
|
|
513
|
+
signatures.push(item.value);
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
errors.push({
|
|
517
|
+
recipient: signedBatch[index].recipient,
|
|
518
|
+
error: item.reason,
|
|
519
|
+
contractErrorCode: this.extractErrorCode(item.reason) || undefined,
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
});
|
|
523
|
+
return { txs: signatures, metadatas, metadataToRecipient, errors };
|
|
524
|
+
}
|
|
429
525
|
/**
|
|
430
526
|
* Attempts withdrawing from the specified stream.
|
|
431
527
|
*/
|
|
@@ -53,6 +53,11 @@ export declare class SolanaStreamClient extends BaseStreamClient {
|
|
|
53
53
|
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
54
54
|
*/
|
|
55
55
|
createMultiple(data: ICreateMultipleStreamData, extParams: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Creates multiple stream/vesting contracts, and send all transactions sequentially.
|
|
58
|
+
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
59
|
+
*/
|
|
60
|
+
createMultipleSequential(data: ICreateMultipleStreamData, extParams: ICreateStreamSolanaExt): Promise<IMultiTransactionResult>;
|
|
56
61
|
/**
|
|
57
62
|
* Attempts withdrawing from the specified stream.
|
|
58
63
|
*/
|
|
@@ -402,6 +402,102 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
402
402
|
});
|
|
403
403
|
return { txs: signatures, metadatas, metadataToRecipient, errors };
|
|
404
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* Creates multiple stream/vesting contracts, and send all transactions sequentially.
|
|
407
|
+
* All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
|
|
408
|
+
*/
|
|
409
|
+
async createMultipleSequential(data, extParams) {
|
|
410
|
+
const { recipients, ...streamParams } = data;
|
|
411
|
+
const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit } = extParams;
|
|
412
|
+
const metadatas = [];
|
|
413
|
+
const metadataToRecipient = {};
|
|
414
|
+
const errors = [];
|
|
415
|
+
const signatures = [];
|
|
416
|
+
const batch = [];
|
|
417
|
+
const instructionsBatch = [];
|
|
418
|
+
const metadataPubKeys = metadataPubKeysExt || [];
|
|
419
|
+
const partnerPublicKey = data.partner ? new PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
|
|
420
|
+
const mintPublicKey = new PublicKey(data.tokenId);
|
|
421
|
+
if (recipients.length === 0) {
|
|
422
|
+
throw new Error("Recipients array is empty!");
|
|
423
|
+
}
|
|
424
|
+
if (!sender.publicKey) {
|
|
425
|
+
throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
|
|
426
|
+
}
|
|
427
|
+
for (let i = 0; i < recipients.length; i++) {
|
|
428
|
+
const recipientData = recipients[i];
|
|
429
|
+
const createStreamData = { ...streamParams, ...recipientData };
|
|
430
|
+
const createStreamExtParams = {
|
|
431
|
+
sender,
|
|
432
|
+
metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
|
|
433
|
+
computePrice,
|
|
434
|
+
computeLimit,
|
|
435
|
+
};
|
|
436
|
+
const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(createStreamData, createStreamExtParams);
|
|
437
|
+
metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
|
|
438
|
+
metadatas.push(metadataPubKey.toBase58());
|
|
439
|
+
instructionsBatch.push({
|
|
440
|
+
ixs,
|
|
441
|
+
metadata,
|
|
442
|
+
recipient: recipientData.recipient,
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
|
|
446
|
+
for (const { ixs, metadata, recipient } of instructionsBatch) {
|
|
447
|
+
const messageV0 = new TransactionMessage({
|
|
448
|
+
payerKey: sender.publicKey,
|
|
449
|
+
recentBlockhash: hash.blockhash,
|
|
450
|
+
instructions: ixs,
|
|
451
|
+
}).compileToV0Message();
|
|
452
|
+
const tx = new VersionedTransaction(messageV0);
|
|
453
|
+
if (metadata) {
|
|
454
|
+
tx.sign([metadata]);
|
|
455
|
+
}
|
|
456
|
+
batch.push({ tx, recipient });
|
|
457
|
+
}
|
|
458
|
+
const prepareInstructions = await this.getCreateATAInstructions([STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
|
|
459
|
+
if (isNative) {
|
|
460
|
+
const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN(0));
|
|
461
|
+
const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
|
|
462
|
+
prepareInstructions.push(...nativeInstructions);
|
|
463
|
+
}
|
|
464
|
+
if (prepareInstructions.length > 0) {
|
|
465
|
+
const messageV0 = new TransactionMessage({
|
|
466
|
+
payerKey: sender.publicKey,
|
|
467
|
+
recentBlockhash: hash.blockhash,
|
|
468
|
+
instructions: prepareInstructions,
|
|
469
|
+
}).compileToV0Message();
|
|
470
|
+
const tx = new VersionedTransaction(messageV0);
|
|
471
|
+
batch.push({
|
|
472
|
+
tx,
|
|
473
|
+
recipient: sender.publicKey.toBase58(),
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
const signedBatch = await signAllTransactionWithRecipients(sender, batch);
|
|
477
|
+
if (prepareInstructions.length > 0) {
|
|
478
|
+
const prepareTx = signedBatch.pop();
|
|
479
|
+
await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
|
|
480
|
+
}
|
|
481
|
+
const responses = [];
|
|
482
|
+
for (const batchTx of signedBatch) {
|
|
483
|
+
responses.push(...(await Promise.allSettled([
|
|
484
|
+
executeTransaction(this.connection, batchTx.tx, { hash, context }, { sendThrottler: this.sendThrottler }),
|
|
485
|
+
])));
|
|
486
|
+
}
|
|
487
|
+
responses.forEach((item, index) => {
|
|
488
|
+
if (item.status === "fulfilled") {
|
|
489
|
+
signatures.push(item.value);
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
492
|
+
errors.push({
|
|
493
|
+
recipient: signedBatch[index].recipient,
|
|
494
|
+
error: item.reason,
|
|
495
|
+
contractErrorCode: this.extractErrorCode(item.reason) || undefined,
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
return { txs: signatures, metadatas, metadataToRecipient, errors };
|
|
500
|
+
}
|
|
405
501
|
/**
|
|
406
502
|
* Attempts withdrawing from the specified stream.
|
|
407
503
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/stream",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow protocol.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"main": "./dist/esm/index.js",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"lint": "eslint --fix .",
|
|
43
43
|
"prepublishOnly": "npm run lint && npm test && npm run build"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "1d52555f15b31f9267ab841e3238a596ca6b7e6f",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@streamflow/eslint-config": "7.0.
|
|
47
|
+
"@streamflow/eslint-config": "7.0.1",
|
|
48
48
|
"@types/bn.js": "5.1.1",
|
|
49
49
|
"@types/ethereum-checksum-address": "^0.0.0",
|
|
50
50
|
"date-fns": "2.28.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@solana/spl-token": "0.4.9",
|
|
60
60
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
61
61
|
"@solana/web3.js": "1.95.4",
|
|
62
|
-
"@streamflow/common": "7.0.
|
|
62
|
+
"@streamflow/common": "7.0.1",
|
|
63
63
|
"@suiet/wallet-kit": "0.2.22",
|
|
64
64
|
"aptos": "1.21.0",
|
|
65
65
|
"bn.js": "5.2.1",
|