@streamflow/stream 7.1.1 → 7.2.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.
@@ -18,7 +18,7 @@ class GenericStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
18
18
  this.chain = options.chain;
19
19
  switch (options.chain) {
20
20
  case types_js_1.IChain.Solana:
21
- this.nativeStreamClient = new index_js_3.SolanaStreamClient(options.clusterUrl, options.cluster, options.commitment, options.programId, options.sendRate, options.sendThrottler);
21
+ this.nativeStreamClient = new index_js_3.SolanaStreamClient(options);
22
22
  break;
23
23
  case types_js_1.IChain.Aptos:
24
24
  this.nativeStreamClient = new index_js_1.AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaAlignedProxyErrorCode = exports.SolanaContractErrorCode = exports.ContractErrorCode = exports.StreamType = exports.StreamDirection = exports.ContractError = exports.ICluster = exports.IChain = void 0;
3
+ exports.SolanaAlignedProxyErrorCode = exports.SolanaContractErrorCode = exports.ContractErrorCode = exports.StreamType = exports.StreamDirection = exports.ICluster = exports.IChain = exports.ContractError = void 0;
4
4
  var common_1 = require("@streamflow/common");
5
+ Object.defineProperty(exports, "ContractError", { enumerable: true, get: function () { return common_1.ContractError; } });
5
6
  Object.defineProperty(exports, "IChain", { enumerable: true, get: function () { return common_1.IChain; } });
6
7
  Object.defineProperty(exports, "ICluster", { enumerable: true, get: function () { return common_1.ICluster; } });
7
- Object.defineProperty(exports, "ContractError", { enumerable: true, get: function () { return common_1.ContractError; } });
8
8
  var StreamDirection;
9
9
  (function (StreamDirection) {
10
10
  StreamDirection["Outgoing"] = "outgoing";
@@ -53,12 +53,32 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
53
53
  /**
54
54
  * Create Stream instance
55
55
  */
56
- constructor(clusterUrl, cluster = types_js_2.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
56
+ constructor(optionsOrClusterUrl, cluster = types_js_2.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
57
57
  super();
58
- this.commitment = commitment;
59
- this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
60
- this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_js_1.PROGRAM_ID[cluster]);
61
- this.sendThrottler = sendThrottler ?? (0, solana_1.buildSendThrottler)(sendRate);
58
+ if (typeof optionsOrClusterUrl === "string") {
59
+ this.commitment = commitment;
60
+ this.connection = new web3_js_1.Connection(optionsOrClusterUrl, this.commitment);
61
+ this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_js_1.PROGRAM_ID[cluster]);
62
+ this.schedulingParams = {
63
+ sendThrottler: sendThrottler ?? (0, solana_1.buildSendThrottler)(sendRate),
64
+ };
65
+ }
66
+ else {
67
+ const { clusterUrl, cluster = types_js_2.ICluster.Mainnet, commitment = "confirmed", programId = "", sendScheduler, } = optionsOrClusterUrl;
68
+ this.commitment = commitment;
69
+ this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
70
+ this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_js_1.PROGRAM_ID[cluster]);
71
+ const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : undefined;
72
+ const sendThrottler = !sendScheduler
73
+ ? (0, solana_1.buildSendThrottler)(1)
74
+ : "sendRate" in sendScheduler
75
+ ? (0, solana_1.buildSendThrottler)(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval)
76
+ : sendScheduler;
77
+ this.schedulingParams = {
78
+ ...schedulingOptions,
79
+ sendThrottler,
80
+ };
81
+ }
62
82
  const alignedUnlocksProgram = {
63
83
  ...streamflow_aligned_unlocks_json_1.default,
64
84
  address: streamflow_aligned_unlocks_json_1.default.address,
@@ -79,14 +99,14 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
79
99
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
80
100
  */
81
101
  async create(data, extParams) {
82
- const { partner, amount } = data;
102
+ const { partner, amount, tokenProgramId } = data;
83
103
  const { isNative, sender } = extParams;
84
104
  const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
85
105
  const mintPublicKey = new web3_js_1.PublicKey(data.tokenId);
86
106
  if (!sender.publicKey) {
87
107
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
88
108
  }
89
- const ixs = await this.getCreateATAInstructions([constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
109
+ const ixs = await this.getCreateATAInstructions([constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true, tokenProgramId ? new web3_js_1.PublicKey(tokenProgramId) : undefined);
90
110
  const { ixs: createIxs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
91
111
  ixs.push(...createIxs);
92
112
  if (isNative) {
@@ -101,7 +121,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
101
121
  hash,
102
122
  context,
103
123
  commitment: this.getCommitment(),
104
- }, { sendThrottler: this.sendThrottler });
124
+ }, this.schedulingParams);
105
125
  return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
106
126
  }
107
127
  async prepareCreateInstructions(streamParams, extParams) {
@@ -111,7 +131,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
111
131
  return { ixs, metadata, metadataPubKey };
112
132
  }
113
133
  async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
114
- const { tokenId: mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, partner, recipient, cliffAmount, amountPerPeriod, amount: depositedAmount, name: streamName, minPrice, maxPercentage, minPercentage, maxPrice, skipInitial, tickSize, priceOracle, oracleType, } = streamParams;
134
+ const { tokenId: mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, partner, recipient, cliffAmount, amountPerPeriod, amount: depositedAmount, name: streamName, minPrice, maxPercentage, minPercentage, maxPrice, skipInitial, tickSize, priceOracle, oracleType, tokenProgramId: streamTokenProgramId, } = streamParams;
115
135
  const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
116
136
  if (!sender.publicKey) {
117
137
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
@@ -123,7 +143,10 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
123
143
  const mintPublicKey = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
124
144
  const metadata = !metadataPubKeys ? web3_js_1.Keypair.generate() : undefined;
125
145
  const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
126
- const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey);
146
+ let tokenProgramId = streamTokenProgramId ? new web3_js_1.PublicKey(streamTokenProgramId) : undefined;
147
+ if (!tokenProgramId) {
148
+ tokenProgramId = (await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)).tokenProgramId;
149
+ }
127
150
  const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
128
151
  const streamflowProgramPublicKey = new web3_js_1.PublicKey(this.programId);
129
152
  const escrowPDA = (0, derive_accounts_js_1.deriveEscrowPDA)(streamflowProgramPublicKey, metadataPubKey);
@@ -178,7 +201,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
178
201
  * Creates a new stream/vesting contract.
179
202
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
180
203
  */
181
- async prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
204
+ async prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, tokenProgramId: streamTokenProgramId, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
182
205
  if (!sender.publicKey) {
183
206
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
184
207
  }
@@ -190,7 +213,10 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
190
213
  const recipientPublicKey = new web3_js_1.PublicKey(recipient);
191
214
  const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
192
215
  const [escrowTokens] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
193
- const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey);
216
+ let tokenProgramId = streamTokenProgramId ? new web3_js_1.PublicKey(streamTokenProgramId) : undefined;
217
+ if (!tokenProgramId) {
218
+ tokenProgramId = (await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey)).tokenProgramId;
219
+ }
194
220
  const senderTokens = await (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId);
195
221
  const recipientTokens = await (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId);
196
222
  const streamflowTreasuryTokens = await (0, solana_1.ata)(mintPublicKey, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
@@ -252,7 +278,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
252
278
  hash,
253
279
  context,
254
280
  commitment: this.getCommitment(),
255
- }, { sendThrottler: this.sendThrottler });
281
+ }, this.schedulingParams);
256
282
  return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
257
283
  }
258
284
  /**
@@ -395,7 +421,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
395
421
  const signedBatch = await (0, utils_js_1.signAllTransactionWithRecipients)(sender, batch);
396
422
  if (prepareInstructions.length > 0) {
397
423
  const prepareTx = signedBatch.pop();
398
- await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
424
+ await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context }, this.schedulingParams);
399
425
  }
400
426
  const responses = [];
401
427
  if (metadataPubKeys.length > 0) {
@@ -403,7 +429,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
403
429
  //ephemeral signer need to be used first before proceeding with the next
404
430
  for (const batchTx of signedBatch) {
405
431
  responses.push(...(await Promise.allSettled([
406
- (0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context }, { sendThrottler: this.sendThrottler }),
432
+ (0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context }, this.schedulingParams),
407
433
  ])));
408
434
  }
409
435
  }
@@ -411,7 +437,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
411
437
  //send all transactions in parallel and wait for them to settle.
412
438
  //it allows to speed up the process of sending transactions
413
439
  //we then filter all promise responses and handle failed transactions
414
- responses.push(...(await (0, solana_1.executeMultipleTransactions)(this.connection, signedBatch.map((item) => item.tx), { hash, context }, { sendThrottler: this.sendThrottler })));
440
+ responses.push(...(await (0, solana_1.executeMultipleTransactions)(this.connection, signedBatch.map((item) => item.tx), { hash, context }, this.schedulingParams)));
415
441
  }
416
442
  responses.forEach((item, index) => {
417
443
  if (item.status === "fulfilled") {
@@ -502,12 +528,12 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
502
528
  const signedBatch = await (0, utils_js_1.signAllTransactionWithRecipients)(sender, batch);
503
529
  if (prepareInstructions.length > 0) {
504
530
  const prepareTx = signedBatch.shift();
505
- await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
531
+ await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context }, this.schedulingParams);
506
532
  }
507
533
  const responses = [];
508
534
  for (const batchTx of signedBatch) {
509
535
  responses.push(...(await Promise.allSettled([
510
- (0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context }, { sendThrottler: this.sendThrottler }),
536
+ (0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context }, this.schedulingParams),
511
537
  ])));
512
538
  }
513
539
  responses.forEach((item, index) => {
@@ -534,7 +560,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
534
560
  hash,
535
561
  context,
536
562
  commitment: this.getCommitment(),
537
- }, { sendThrottler: this.sendThrottler });
563
+ }, this.schedulingParams);
538
564
  return { ixs, txId: signature };
539
565
  }
540
566
  /**
@@ -584,7 +610,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
584
610
  hash,
585
611
  context,
586
612
  commitment: this.getCommitment(),
587
- }, { sendThrottler: this.sendThrottler });
613
+ }, this.schedulingParams);
588
614
  return { ixs, txId: signature };
589
615
  }
590
616
  async prepareCancelInstructions(cancelData, extParams) {
@@ -684,7 +710,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
684
710
  hash,
685
711
  context,
686
712
  commitment: this.getCommitment(),
687
- }, { sendThrottler: this.sendThrottler });
713
+ }, this.schedulingParams);
688
714
  return { ixs, txId: signature };
689
715
  }
690
716
  /**
@@ -731,7 +757,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
731
757
  hash,
732
758
  context,
733
759
  commitment: this.getCommitment(),
734
- }, { sendThrottler: this.sendThrottler });
760
+ }, this.schedulingParams);
735
761
  return { ixs, txId: signature };
736
762
  }
737
763
  /**
@@ -899,7 +925,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
899
925
  hash,
900
926
  context,
901
927
  commitment: this.getCommitment(),
902
- }, { sendThrottler: this.sendThrottler });
928
+ }, this.schedulingParams);
903
929
  return {
904
930
  ixs,
905
931
  txId: signature,
@@ -1,8 +1,8 @@
1
1
  import { Wallet } from "ethers";
2
2
  import { describe, expect, test } from "vitest";
3
3
  import { StreamflowAptos, StreamflowEVM, StreamflowSolana, StreamflowSui } from "../../index.js";
4
- import { default as GenericStreamClient, } from "../../common/GenericStreamClient.js";
5
- import { IChain, ICluster } from "../../common/types.js";
4
+ import { default as GenericStreamClient } from "../../common/GenericStreamClient.js";
5
+ import { IChain, ICluster, } from "../../common/types.js";
6
6
  describe("GenericStreamClient", () => {
7
7
  describe.each([
8
8
  {
@@ -1,41 +1,9 @@
1
- import { Commitment, ConnectionConfig } from "@solana/web3.js";
2
- import { Signer } from "ethers";
3
- import PQueue from "p-queue";
4
1
  import { BaseStreamClient } from "./BaseStreamClient.js";
5
- import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream, IFees, IGetFeesData } from "./types.js";
2
+ import { ICancelData, IChain, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData, ITransactionResult, IMultiTransactionResult, ICreateResult, IGetAllData, Stream, IFees, IGetFeesData, AptosStreamClientOptions, SuiStreamClientOptions, EvmStreamClientOptions, SolanaStreamClientOptions } from "./types.js";
6
3
  import { AptosStreamClient, ICreateStreamAptosExt, ITransactionAptosExt } from "../aptos/index.js";
7
4
  import { EvmStreamClient } from "../evm/index.js";
8
5
  import { SolanaStreamClient, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "../solana/index.js";
9
- import { ICreateStreamSuiExt, ITransactionSuiExt, ISuiIdParameters, SuiStreamClient } from "../sui/index.js";
10
- export interface SolanaStreamClientOptions {
11
- chain: IChain.Solana;
12
- clusterUrl: string;
13
- cluster?: ICluster;
14
- programId?: string;
15
- commitment?: Commitment | ConnectionConfig;
16
- sendRate?: number;
17
- sendThrottler?: PQueue;
18
- }
19
- export interface AptosStreamClientOptions {
20
- chain: IChain.Aptos;
21
- clusterUrl: string;
22
- cluster?: ICluster;
23
- programId?: string;
24
- maxGas?: string;
25
- }
26
- export interface EvmStreamClientOptions {
27
- chain: IChain.Ethereum | IChain.BNB | IChain.Polygon;
28
- clusterUrl: string;
29
- signer: Signer;
30
- cluster?: ICluster;
31
- programId?: string;
32
- }
33
- export interface SuiStreamClientOptions {
34
- chain: IChain.Sui;
35
- clusterUrl: string;
36
- cluster?: ICluster;
37
- ids?: ISuiIdParameters;
38
- }
6
+ import { ICreateStreamSuiExt, ITransactionSuiExt, SuiStreamClient } from "../sui/index.js";
39
7
  /** Type referencing options for specific Chain Client */
40
8
  type StreamClientOptions<T extends IChain> = T extends IChain.Solana ? SolanaStreamClientOptions : T extends IChain.Aptos ? AptosStreamClientOptions : T extends IChain.Sui ? SuiStreamClientOptions : EvmStreamClientOptions;
41
9
  /** Type referencing Chain Client implementation */
@@ -18,7 +18,7 @@ export default class GenericStreamClient extends BaseStreamClient {
18
18
  this.chain = options.chain;
19
19
  switch (options.chain) {
20
20
  case IChain.Solana:
21
- this.nativeStreamClient = new SolanaStreamClient(options.clusterUrl, options.cluster, options.commitment, options.programId, options.sendRate, options.sendThrottler);
21
+ this.nativeStreamClient = new SolanaStreamClient(options);
22
22
  break;
23
23
  case IChain.Aptos:
24
24
  this.nativeStreamClient = new AptosStreamClient(options.clusterUrl, options.cluster, options.maxGas, options.programId);
@@ -1,8 +1,12 @@
1
1
  import { Address } from "@coral-xyz/anchor";
2
- import { TransactionInstruction } from "@solana/web3.js";
2
+ import { Commitment, ConnectionConfig, PublicKey, TransactionInstruction } from "@solana/web3.js";
3
+ import { IChain, ICluster } from "@streamflow/common";
3
4
  import { Types } from "aptos";
4
5
  import BN from "bn.js";
5
- export { IChain, ICluster, ContractError } from "@streamflow/common";
6
+ import type { Signer } from "ethers";
7
+ import type { default as PQueue } from "p-queue";
8
+ import { ISuiIdParameters } from "../sui/index.js";
9
+ export { ContractError, IChain, ICluster } from "@streamflow/common";
6
10
  export interface IRecipient {
7
11
  recipient: string;
8
12
  amount: BN;
@@ -25,6 +29,7 @@ export interface IBaseStreamConfig {
25
29
  canPause?: boolean;
26
30
  canUpdateRate?: boolean;
27
31
  partner?: string;
32
+ tokenProgramId?: string | PublicKey;
28
33
  }
29
34
  export type IAlignedStreamConfig = {
30
35
  minPrice: number;
@@ -282,3 +287,62 @@ export declare enum SolanaAlignedProxyErrorCode {
282
287
  /** All funds are already unlocked */
283
288
  AllFundsUnlocked = "AllFundsUnlocked"
284
289
  }
290
+ /**
291
+ * @interface
292
+ */
293
+ export interface SolanaTransactionSchedulingOptions {
294
+ /**
295
+ * concurrency rate for scheduling
296
+ */
297
+ sendRate: number;
298
+ /**
299
+ * time interval between consecutive sends
300
+ */
301
+ sendInterval?: number;
302
+ /**
303
+ * time interval before confirming the transaction
304
+ */
305
+ waitBeforeConfirming?: number;
306
+ }
307
+ /**
308
+ * @interface
309
+ */
310
+ export interface SolanaStreamClientOptions {
311
+ chain: IChain.Solana;
312
+ clusterUrl: string;
313
+ cluster?: ICluster;
314
+ programId?: string;
315
+ commitment?: Commitment | ConnectionConfig;
316
+ sendRate?: number;
317
+ sendThrottler?: PQueue;
318
+ sendScheduler?: PQueue | SolanaTransactionSchedulingOptions;
319
+ }
320
+ /**
321
+ * @interface
322
+ */
323
+ export interface AptosStreamClientOptions {
324
+ chain: IChain.Aptos;
325
+ clusterUrl: string;
326
+ cluster?: ICluster;
327
+ programId?: string;
328
+ maxGas?: string;
329
+ }
330
+ /**
331
+ * @interface
332
+ */
333
+ export interface EvmStreamClientOptions {
334
+ chain: IChain.Ethereum | IChain.BNB | IChain.Polygon;
335
+ clusterUrl: string;
336
+ signer: Signer;
337
+ cluster?: ICluster;
338
+ programId?: string;
339
+ }
340
+ /**
341
+ * @interface
342
+ */
343
+ export interface SuiStreamClientOptions {
344
+ chain: IChain.Sui;
345
+ clusterUrl: string;
346
+ cluster?: ICluster;
347
+ ids?: ISuiIdParameters;
348
+ }
@@ -1,4 +1,4 @@
1
- export { IChain, ICluster, ContractError } from "@streamflow/common";
1
+ export { ContractError, IChain, ICluster } from "@streamflow/common";
2
2
  export var StreamDirection;
3
3
  (function (StreamDirection) {
4
4
  StreamDirection["Outgoing"] = "outgoing";
@@ -2,18 +2,29 @@ import PQueue from "p-queue";
2
2
  import { Connection, Keypair, PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
3
3
  import { IProgramAccount } from "@streamflow/common/solana";
4
4
  import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, ISearchStreams, ICreateStreamInstructions } from "./types.js";
5
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream, ICreateAlignedStreamData } from "../common/types.js";
5
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream, ICreateAlignedStreamData, SolanaStreamClientOptions } from "../common/types.js";
6
6
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
7
+ /**
8
+ * Solana Client creation options
9
+ * @property cluster {@link ICluster} cluster type
10
+ * @property clusterUrl cluster url
11
+ * @interface ClientCreationOptions
12
+ */
13
+ export type ClientCreationOptions = Omit<SolanaStreamClientOptions, "chain" | "sendRate" | "sendThrottler">;
7
14
  export declare class SolanaStreamClient extends BaseStreamClient {
8
15
  private connection;
9
16
  private programId;
10
17
  private commitment;
11
- private sendThrottler;
12
18
  private alignedProxyProgram;
19
+ private schedulingParams;
13
20
  /**
14
- * Create Stream instance
21
+ * Create Stream instance with flat arguments
15
22
  */
16
23
  constructor(clusterUrl: string, cluster?: ICluster, commitment?: Commitment | ConnectionConfig, programId?: string, sendRate?: number, sendThrottler?: PQueue);
24
+ /**
25
+ * Create Stream instance with options
26
+ */
27
+ constructor(options: ClientCreationOptions);
17
28
  getConnection(): Connection;
18
29
  getCommitment(): Commitment | undefined;
19
30
  getProgramId(): string;
@@ -28,7 +39,7 @@ export declare class SolanaStreamClient extends BaseStreamClient {
28
39
  * Creates a new stream/vesting contract.
29
40
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
30
41
  */
31
- prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: ICreateStreamSolanaExt): Promise<ICreateStreamInstructions>;
42
+ prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, tokenProgramId: streamTokenProgramId, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: ICreateStreamSolanaExt): Promise<ICreateStreamInstructions>;
32
43
  /**
33
44
  * Creates a new stream/vesting contract using unchecked instruction.
34
45
  *
@@ -24,17 +24,37 @@ export class SolanaStreamClient extends BaseStreamClient {
24
24
  connection;
25
25
  programId;
26
26
  commitment;
27
- sendThrottler;
28
27
  alignedProxyProgram;
28
+ schedulingParams;
29
29
  /**
30
30
  * Create Stream instance
31
31
  */
32
- constructor(clusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
32
+ constructor(optionsOrClusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler) {
33
33
  super();
34
- this.commitment = commitment;
35
- this.connection = new Connection(clusterUrl, this.commitment);
36
- this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(PROGRAM_ID[cluster]);
37
- this.sendThrottler = sendThrottler ?? buildSendThrottler(sendRate);
34
+ if (typeof optionsOrClusterUrl === "string") {
35
+ this.commitment = commitment;
36
+ this.connection = new Connection(optionsOrClusterUrl, this.commitment);
37
+ this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(PROGRAM_ID[cluster]);
38
+ this.schedulingParams = {
39
+ sendThrottler: sendThrottler ?? buildSendThrottler(sendRate),
40
+ };
41
+ }
42
+ else {
43
+ const { clusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendScheduler, } = optionsOrClusterUrl;
44
+ this.commitment = commitment;
45
+ this.connection = new Connection(clusterUrl, this.commitment);
46
+ this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(PROGRAM_ID[cluster]);
47
+ const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : undefined;
48
+ const sendThrottler = !sendScheduler
49
+ ? buildSendThrottler(1)
50
+ : "sendRate" in sendScheduler
51
+ ? buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval)
52
+ : sendScheduler;
53
+ this.schedulingParams = {
54
+ ...schedulingOptions,
55
+ sendThrottler,
56
+ };
57
+ }
38
58
  const alignedUnlocksProgram = {
39
59
  ...StreamflowAlignedUnlocksIDL,
40
60
  address: StreamflowAlignedUnlocksIDL.address,
@@ -55,14 +75,14 @@ export class SolanaStreamClient extends BaseStreamClient {
55
75
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
56
76
  */
57
77
  async create(data, extParams) {
58
- const { partner, amount } = data;
78
+ const { partner, amount, tokenProgramId } = data;
59
79
  const { isNative, sender } = extParams;
60
80
  const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
61
81
  const mintPublicKey = new PublicKey(data.tokenId);
62
82
  if (!sender.publicKey) {
63
83
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
64
84
  }
65
- const ixs = await this.getCreateATAInstructions([STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true);
85
+ const ixs = await this.getCreateATAInstructions([STREAMFLOW_TREASURY_PUBLIC_KEY, partnerPublicKey], mintPublicKey, sender, true, tokenProgramId ? new PublicKey(tokenProgramId) : undefined);
66
86
  const { ixs: createIxs, metadata, metadataPubKey } = await this.prepareCreateInstructions(data, extParams);
67
87
  ixs.push(...createIxs);
68
88
  if (isNative) {
@@ -77,7 +97,7 @@ export class SolanaStreamClient extends BaseStreamClient {
77
97
  hash,
78
98
  context,
79
99
  commitment: this.getCommitment(),
80
- }, { sendThrottler: this.sendThrottler });
100
+ }, this.schedulingParams);
81
101
  return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
82
102
  }
83
103
  async prepareCreateInstructions(streamParams, extParams) {
@@ -87,7 +107,7 @@ export class SolanaStreamClient extends BaseStreamClient {
87
107
  return { ixs, metadata, metadataPubKey };
88
108
  }
89
109
  async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
90
- const { tokenId: mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, partner, recipient, cliffAmount, amountPerPeriod, amount: depositedAmount, name: streamName, minPrice, maxPercentage, minPercentage, maxPrice, skipInitial, tickSize, priceOracle, oracleType, } = streamParams;
110
+ const { tokenId: mint, start, period, cliff, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, partner, recipient, cliffAmount, amountPerPeriod, amount: depositedAmount, name: streamName, minPrice, maxPercentage, minPercentage, maxPrice, skipInitial, tickSize, priceOracle, oracleType, tokenProgramId: streamTokenProgramId, } = streamParams;
91
111
  const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
92
112
  if (!sender.publicKey) {
93
113
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
@@ -99,7 +119,10 @@ export class SolanaStreamClient extends BaseStreamClient {
99
119
  const mintPublicKey = isNative ? NATIVE_MINT : new PublicKey(mint);
100
120
  const metadata = !metadataPubKeys ? Keypair.generate() : undefined;
101
121
  const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
102
- const { tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
122
+ let tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : undefined;
123
+ if (!tokenProgramId) {
124
+ tokenProgramId = (await getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
125
+ }
103
126
  const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
104
127
  const streamflowProgramPublicKey = new PublicKey(this.programId);
105
128
  const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
@@ -154,7 +177,7 @@ export class SolanaStreamClient extends BaseStreamClient {
154
177
  * Creates a new stream/vesting contract.
155
178
  * All fees are paid by sender (escrow metadata account rent, escrow token account rent, recipient's associated token account rent, Streamflow's service fee).
156
179
  */
157
- async prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
180
+ async prepareCreateStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal = false, withdrawalFrequency = 0, partner, tokenProgramId: streamTokenProgramId, }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
158
181
  if (!sender.publicKey) {
159
182
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
160
183
  }
@@ -166,7 +189,10 @@ export class SolanaStreamClient extends BaseStreamClient {
166
189
  const recipientPublicKey = new PublicKey(recipient);
167
190
  const { metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys);
168
191
  const [escrowTokens] = PublicKey.findProgramAddressSync([Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
169
- const { tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
192
+ let tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : undefined;
193
+ if (!tokenProgramId) {
194
+ tokenProgramId = (await getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
195
+ }
170
196
  const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
171
197
  const recipientTokens = await ata(mintPublicKey, recipientPublicKey, tokenProgramId);
172
198
  const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
@@ -228,7 +254,7 @@ export class SolanaStreamClient extends BaseStreamClient {
228
254
  hash,
229
255
  context,
230
256
  commitment: this.getCommitment(),
231
- }, { sendThrottler: this.sendThrottler });
257
+ }, this.schedulingParams);
232
258
  return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
233
259
  }
234
260
  /**
@@ -371,7 +397,7 @@ export class SolanaStreamClient extends BaseStreamClient {
371
397
  const signedBatch = await signAllTransactionWithRecipients(sender, batch);
372
398
  if (prepareInstructions.length > 0) {
373
399
  const prepareTx = signedBatch.pop();
374
- await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
400
+ await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
375
401
  }
376
402
  const responses = [];
377
403
  if (metadataPubKeys.length > 0) {
@@ -379,7 +405,7 @@ export class SolanaStreamClient extends BaseStreamClient {
379
405
  //ephemeral signer need to be used first before proceeding with the next
380
406
  for (const batchTx of signedBatch) {
381
407
  responses.push(...(await Promise.allSettled([
382
- executeTransaction(this.connection, batchTx.tx, { hash, context }, { sendThrottler: this.sendThrottler }),
408
+ executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams),
383
409
  ])));
384
410
  }
385
411
  }
@@ -387,7 +413,7 @@ export class SolanaStreamClient extends BaseStreamClient {
387
413
  //send all transactions in parallel and wait for them to settle.
388
414
  //it allows to speed up the process of sending transactions
389
415
  //we then filter all promise responses and handle failed transactions
390
- responses.push(...(await executeMultipleTransactions(this.connection, signedBatch.map((item) => item.tx), { hash, context }, { sendThrottler: this.sendThrottler })));
416
+ responses.push(...(await executeMultipleTransactions(this.connection, signedBatch.map((item) => item.tx), { hash, context }, this.schedulingParams)));
391
417
  }
392
418
  responses.forEach((item, index) => {
393
419
  if (item.status === "fulfilled") {
@@ -478,12 +504,12 @@ export class SolanaStreamClient extends BaseStreamClient {
478
504
  const signedBatch = await signAllTransactionWithRecipients(sender, batch);
479
505
  if (prepareInstructions.length > 0) {
480
506
  const prepareTx = signedBatch.shift();
481
- await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, { sendThrottler: this.sendThrottler });
507
+ await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
482
508
  }
483
509
  const responses = [];
484
510
  for (const batchTx of signedBatch) {
485
511
  responses.push(...(await Promise.allSettled([
486
- executeTransaction(this.connection, batchTx.tx, { hash, context }, { sendThrottler: this.sendThrottler }),
512
+ executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams),
487
513
  ])));
488
514
  }
489
515
  responses.forEach((item, index) => {
@@ -510,7 +536,7 @@ export class SolanaStreamClient extends BaseStreamClient {
510
536
  hash,
511
537
  context,
512
538
  commitment: this.getCommitment(),
513
- }, { sendThrottler: this.sendThrottler });
539
+ }, this.schedulingParams);
514
540
  return { ixs, txId: signature };
515
541
  }
516
542
  /**
@@ -560,7 +586,7 @@ export class SolanaStreamClient extends BaseStreamClient {
560
586
  hash,
561
587
  context,
562
588
  commitment: this.getCommitment(),
563
- }, { sendThrottler: this.sendThrottler });
589
+ }, this.schedulingParams);
564
590
  return { ixs, txId: signature };
565
591
  }
566
592
  async prepareCancelInstructions(cancelData, extParams) {
@@ -660,7 +686,7 @@ export class SolanaStreamClient extends BaseStreamClient {
660
686
  hash,
661
687
  context,
662
688
  commitment: this.getCommitment(),
663
- }, { sendThrottler: this.sendThrottler });
689
+ }, this.schedulingParams);
664
690
  return { ixs, txId: signature };
665
691
  }
666
692
  /**
@@ -707,7 +733,7 @@ export class SolanaStreamClient extends BaseStreamClient {
707
733
  hash,
708
734
  context,
709
735
  commitment: this.getCommitment(),
710
- }, { sendThrottler: this.sendThrottler });
736
+ }, this.schedulingParams);
711
737
  return { ixs, txId: signature };
712
738
  }
713
739
  /**
@@ -875,7 +901,7 @@ export class SolanaStreamClient extends BaseStreamClient {
875
901
  hash,
876
902
  context,
877
903
  commitment: this.getCommitment(),
878
- }, { sendThrottler: this.sendThrottler });
904
+ }, this.schedulingParams);
879
905
  return {
880
906
  ixs,
881
907
  txId: signature,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "7.1.1",
3
+ "version": "7.2.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": "pnpm run lint && pnpm run test run && pnpm run build"
44
44
  },
45
- "gitHead": "6828e48741b4abf46f4a8aae9d9512b4cb587e84",
45
+ "gitHead": "56f65828955f62400c0b2eebaeb53c7f123dca60",
46
46
  "devDependencies": {
47
- "@streamflow/eslint-config": "7.1.1",
47
+ "@streamflow/eslint-config": "7.2.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.1.1",
62
+ "@streamflow/common": "7.2.1",
63
63
  "@suiet/wallet-kit": "0.2.22",
64
64
  "aptos": "1.21.0",
65
65
  "bn.js": "5.2.1",