@streamflow/stream 10.0.0-alpha.p313.e531e2c → 10.0.0-alpha.p317.e143b57

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/README.md CHANGED
@@ -99,7 +99,7 @@ const solanaInteractParams = {
99
99
 
100
100
  ## Create a Vesting Stream
101
101
 
102
- Vesting Streams are a type of Stream used to linearly unlock a given amount of tokens over a period of time. You can specify the amount, cliff, start time and releasePeriod along with other configuration that controls who can transfer or cancel the contract. For a Stream to be considered Vesting in the Streamflow App it has to match the criteria from the `isVesting` helper function (or `buildStreamType` returns `StreamType.Vesting`). The stream must not allow top-ups, the cliff amount must not be too close to the total amount and it must not be a Dynamic token lock.
102
+ Vesting Streams are a type of Stream used to linearly unlock a given amount of tokens over a period of time. You can specify the amount, cliff, start time and releasePeriod along with other configuration that controls who can transfer or cancel the contract. For a Stream to be considered Vesting in the Streamflow App it has to match the criteria from the `isVesting` helper function (or `buildStreamType` returns `StreamType.Vesting`). The cliff amount must not be too close to the total amount and it must not be a Dynamic token lock.
103
103
 
104
104
  For more details creating a Stream with arbitrary configuration see [General Stream creation](#general-stream-creation).
105
105
  For creating multiple Streams at once see [Create Multiple Streams](#create-multiple-streams-at-once).
@@ -426,7 +426,7 @@ console.log(remaining);
426
426
  ```javascript
427
427
  const data: IGetAllData = {
428
428
  address: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99",
429
- type: StreamType.All, // StreamType.Vesting, StreamType.Lock, StreamType.Payment
429
+ type: StreamType.All, // StreamType.Vesting, StreamType.Lock
430
430
  direction: StreamDirection.All, // StreamDirection.Outgoing, StreamDirection.Incoming
431
431
  };
432
432
 
@@ -59,11 +59,8 @@ var calculateUnlockedAmount = ({
59
59
  var isCliffCloseToDepositedAmount = (streamData) => {
60
60
  return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN3__default.default(1)));
61
61
  };
62
- var isPayment = (streamData) => {
63
- return streamData.canTopup;
64
- };
65
62
  var isVesting = (streamData) => {
66
- return !streamData.canTopup && !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
63
+ return !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
67
64
  };
68
65
  var isAligned = (stream) => {
69
66
  return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
@@ -78,13 +75,10 @@ var isTokenLock = (streamData) => {
78
75
  return !streamData.canTopup && !streamData.automaticWithdrawal && !streamData.cancelableBySender && !streamData.cancelableByRecipient && !streamData.transferableBySender && (isCliffCloseToDepositedAmount(streamData) || isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
79
76
  };
80
77
  var buildStreamType = (streamData) => {
81
- if (isVesting(streamData)) {
82
- return "vesting" /* Vesting */;
83
- }
84
78
  if (isTokenLock(streamData)) {
85
79
  return "lock" /* Lock */;
86
80
  }
87
- return "payment" /* Payment */;
81
+ return "vesting" /* Vesting */;
88
82
  };
89
83
  var decodeEndTime = (endTime) => {
90
84
  if (endTime.gt(new BN3__default.default(MAX_SAFE_UNIX_TIME_VALUE))) {
@@ -101,7 +95,6 @@ var StreamDirection = /* @__PURE__ */ ((StreamDirection2) => {
101
95
  })(StreamDirection || {});
102
96
  var StreamType = /* @__PURE__ */ ((StreamType2) => {
103
97
  StreamType2["All"] = "all";
104
- StreamType2["Payment"] = "payment";
105
98
  StreamType2["Vesting"] = "vesting";
106
99
  StreamType2["Lock"] = "lock";
107
100
  return StreamType2;
@@ -2671,7 +2664,7 @@ var SolanaStreamClient = class {
2671
2664
  return { ixs, txId: signature, metadataId };
2672
2665
  }
2673
2666
  async prepareCreateInstructions(streamParams, extParams) {
2674
- const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateStreamInstructions(streamParams, extParams);
2667
+ const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateLinearStreamInstructions(streamParams, extParams);
2675
2668
  return { ixs, metadata, metadataPubKey };
2676
2669
  }
2677
2670
  async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
@@ -2781,7 +2774,7 @@ var SolanaStreamClient = class {
2781
2774
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
2782
2775
  * @returns Create stream instructions
2783
2776
  */
2784
- async prepareCreateStreamInstructions({
2777
+ async prepareCreateLinearStreamInstructions({
2785
2778
  recipient,
2786
2779
  tokenId: mint,
2787
2780
  start,
@@ -3002,14 +2995,13 @@ var SolanaStreamClient = class {
3002
2995
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
3003
2996
  * @returns Create multiple transaction instructions
3004
2997
  */
3005
- async buildCreateMultipleTransactionInstructions(data, extParams) {
2998
+ async buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions = true) {
3006
2999
  const { recipients, ...streamParams } = data;
3007
3000
  const { sender, metadataPubKeys: metadataPubKeysExt, isNative, customInstructions } = extParams;
3008
3001
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
3009
3002
  const metadatas = [];
3010
3003
  const metadataToRecipient = {};
3011
3004
  const instructionsBatch = [];
3012
- const metadataPubKeys = metadataPubKeysExt || [];
3013
3005
  const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
3014
3006
  const mintPublicKey = new web3_js.PublicKey(data.tokenId);
3015
3007
  if (recipients.length === 0) {
@@ -3019,14 +3011,16 @@ var SolanaStreamClient = class {
3019
3011
  const recipientData = recipients[i];
3020
3012
  const createStreamData = { ...streamParams, ...recipientData };
3021
3013
  const createStreamExtParams = {
3022
- metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
3023
- ...extParams
3014
+ ...extParams,
3015
+ metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
3024
3016
  };
3025
3017
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
3026
3018
  createStreamData,
3027
3019
  createStreamExtParams
3028
3020
  );
3029
- await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3021
+ if (applyCustomAfterInstructions) {
3022
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3023
+ }
3030
3024
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
3031
3025
  metadatas.push(metadataPubKey.toBase58());
3032
3026
  instructionsBatch.push({
@@ -3074,9 +3068,9 @@ var SolanaStreamClient = class {
3074
3068
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
3075
3069
  * @returns Multiple transaction information
3076
3070
  */
3077
- async buildCreateMultipleTransactions(data, extParams) {
3071
+ async buildCreateMultipleTransactions(data, extParams, applyCustomAfterInstructions = true) {
3078
3072
  const { sender } = extParams;
3079
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3073
+ const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions);
3080
3074
  const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
3081
3075
  const batch = [];
3082
3076
  for (const { ixs, metadata, recipient } of instructionsBatch) {
@@ -3107,7 +3101,7 @@ var SolanaStreamClient = class {
3107
3101
  if (!sender.publicKey) {
3108
3102
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3109
3103
  }
3110
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3104
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3111
3105
  const errors = [];
3112
3106
  const signatures = [];
3113
3107
  const metadataPubKeys = metadataPubKeysExt || [];
@@ -3172,7 +3166,7 @@ var SolanaStreamClient = class {
3172
3166
  if (!sender.publicKey) {
3173
3167
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3174
3168
  }
3175
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3169
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3176
3170
  const errors = [];
3177
3171
  const signatures = [];
3178
3172
  const batch = [];
@@ -3334,7 +3328,7 @@ var SolanaStreamClient = class {
3334
3328
  }
3335
3329
  const { sender: senderPublicKey } = decodeStream(account.data);
3336
3330
  const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3337
- const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelStreamInstructions(cancelData, extParams);
3331
+ const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3338
3332
  return ixs;
3339
3333
  }
3340
3334
  /**
@@ -3382,7 +3376,7 @@ var SolanaStreamClient = class {
3382
3376
  * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3383
3377
  * @returns Transaction instructions
3384
3378
  */
3385
- async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3379
+ async prepareCancelLinearStream({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3386
3380
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3387
3381
  const streamPublicKey = new web3_js.PublicKey(id);
3388
3382
  const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
@@ -3795,11 +3789,11 @@ var SolanaStreamClient = class {
3795
3789
  return DEFAULT_STREAMFLOW_FEE;
3796
3790
  }
3797
3791
  /**
3798
- * Returns total fee percent, streamflow fees + partner fees
3799
- * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3800
- * @param chainSpecificParams additional parameters required by chain client
3801
- * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3802
- */
3792
+ * Returns total fee percent, streamflow fees + partner fees
3793
+ * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3794
+ * @param chainSpecificParams additional parameters required by chain client
3795
+ * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3796
+ */
3803
3797
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3804
3798
  async getTotalFee(getFeesData) {
3805
3799
  const fees = await this.getFees(getFeesData);
@@ -3824,6 +3818,21 @@ var SolanaStreamClient = class {
3824
3818
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3825
3819
  return senderPublicKey.equals(pda);
3826
3820
  }
3821
+ async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
3822
+ const dataArray = Array.isArray(data) ? data : [data];
3823
+ const results = await Promise.all(
3824
+ dataArray.map((item, index) => this.buildCreateMultipleTransactionInstructions(item, extParams, index === 0))
3825
+ );
3826
+ return {
3827
+ instructionsBatch: results.flatMap((r) => r.instructionsBatch),
3828
+ metadatas: results.flatMap((r) => r.metadatas),
3829
+ prepareInstructions: results.flatMap((r) => r.prepareInstructions),
3830
+ metadataToRecipient: results.reduce(
3831
+ (acc, r) => Object.assign(acc, r.metadataToRecipient),
3832
+ {}
3833
+ )
3834
+ };
3835
+ }
3827
3836
  /**
3828
3837
  * Utility function to generate metadata for a Contract or return existing Pubkey
3829
3838
  */
@@ -4354,7 +4363,6 @@ exports.isAligned = isAligned;
4354
4363
  exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
4355
4364
  exports.isCreateAlignedStreamData = isCreateAlignedStreamData;
4356
4365
  exports.isDynamicLock = isDynamicLock;
4357
- exports.isPayment = isPayment;
4358
4366
  exports.isTokenLock = isTokenLock;
4359
4367
  exports.isVesting = isVesting;
4360
4368
  exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;