@streamflow/stream 10.0.0-alpha.p313.4470e29 → 10.0.0-alpha.p313.ac76c04

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.
@@ -905,7 +905,7 @@ var streamflow_aligned_unlocks_default = {
905
905
  address: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
906
906
  metadata: {
907
907
  name: "streamflow_aligned_unlocks",
908
- version: "1.3.0",
908
+ version: "1.4.0",
909
909
  spec: "0.1.0",
910
910
  description: "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics"
911
911
  },
@@ -1779,6 +1779,80 @@ var streamflow_aligned_unlocks_default = {
1779
1779
  ],
1780
1780
  args: []
1781
1781
  },
1782
+ {
1783
+ name: "update_contract",
1784
+ discriminator: [
1785
+ 78,
1786
+ 184,
1787
+ 162,
1788
+ 174,
1789
+ 233,
1790
+ 5,
1791
+ 40,
1792
+ 82
1793
+ ],
1794
+ accounts: [
1795
+ {
1796
+ name: "sender",
1797
+ writable: true,
1798
+ signer: true
1799
+ },
1800
+ {
1801
+ name: "proxy_metadata",
1802
+ docs: [
1803
+ "Proxy Contract"
1804
+ ],
1805
+ writable: true,
1806
+ pda: {
1807
+ seeds: [
1808
+ {
1809
+ kind: "const",
1810
+ value: [
1811
+ 99,
1812
+ 111,
1813
+ 110,
1814
+ 116,
1815
+ 114,
1816
+ 97,
1817
+ 99,
1818
+ 116
1819
+ ]
1820
+ },
1821
+ {
1822
+ kind: "account",
1823
+ path: "stream_metadata"
1824
+ }
1825
+ ]
1826
+ }
1827
+ },
1828
+ {
1829
+ name: "stream_metadata",
1830
+ writable: true
1831
+ },
1832
+ {
1833
+ name: "withdrawor",
1834
+ writable: true
1835
+ },
1836
+ {
1837
+ name: "streamflow_program",
1838
+ address: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m"
1839
+ },
1840
+ {
1841
+ name: "system_program",
1842
+ address: "11111111111111111111111111111111"
1843
+ }
1844
+ ],
1845
+ args: [
1846
+ {
1847
+ name: "params",
1848
+ type: {
1849
+ defined: {
1850
+ name: "UpdateContractParams"
1851
+ }
1852
+ }
1853
+ }
1854
+ ]
1855
+ },
1782
1856
  {
1783
1857
  name: "update_test_oracle",
1784
1858
  discriminator: [
@@ -2374,6 +2448,32 @@ var streamflow_aligned_unlocks_default = {
2374
2448
  ]
2375
2449
  }
2376
2450
  },
2451
+ {
2452
+ name: "UpdateContractParams",
2453
+ type: {
2454
+ kind: "struct",
2455
+ fields: [
2456
+ {
2457
+ name: "transferable_by_sender",
2458
+ type: {
2459
+ option: "bool"
2460
+ }
2461
+ },
2462
+ {
2463
+ name: "transferable_by_recipient",
2464
+ type: {
2465
+ option: "bool"
2466
+ }
2467
+ },
2468
+ {
2469
+ name: "cancelable_by_sender",
2470
+ type: {
2471
+ option: "bool"
2472
+ }
2473
+ }
2474
+ ]
2475
+ }
2476
+ },
2377
2477
  {
2378
2478
  name: "UpdateTestOracleParams",
2379
2479
  type: {
@@ -2564,7 +2664,7 @@ var SolanaStreamClient = class {
2564
2664
  return { ixs, txId: signature, metadataId };
2565
2665
  }
2566
2666
  async prepareCreateInstructions(streamParams, extParams) {
2567
- 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);
2568
2668
  return { ixs, metadata, metadataPubKey };
2569
2669
  }
2570
2670
  async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
@@ -2598,7 +2698,10 @@ var SolanaStreamClient = class {
2598
2698
  floorPrice
2599
2699
  } = streamParams;
2600
2700
  const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
2601
- common.invariant(priceOracle || !oracleType || oracleType === "none", "Price oracle is required for the specified oracle type");
2701
+ common.invariant(
2702
+ priceOracle || !oracleType || oracleType === "none",
2703
+ "Price oracle is required for the specified oracle type"
2704
+ );
2602
2705
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2603
2706
  const recipientPublicKey = new web3_js.PublicKey(recipient);
2604
2707
  const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
@@ -2671,7 +2774,7 @@ var SolanaStreamClient = class {
2671
2774
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
2672
2775
  * @returns Create stream instructions
2673
2776
  */
2674
- async prepareCreateStreamInstructions({
2777
+ async prepareCreateLinearStreamInstructions({
2675
2778
  recipient,
2676
2779
  tokenId: mint,
2677
2780
  start,
@@ -2773,10 +2876,7 @@ var SolanaStreamClient = class {
2773
2876
  * @returns Create result
2774
2877
  */
2775
2878
  async createUnchecked(data, extParams) {
2776
- const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(
2777
- data,
2778
- extParams
2779
- );
2879
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(data, extParams);
2780
2880
  const { tx, hash, context } = await common.prepareTransaction(
2781
2881
  this.connection,
2782
2882
  ixs,
@@ -2895,7 +2995,7 @@ var SolanaStreamClient = class {
2895
2995
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2896
2996
  * @returns Create multiple transaction instructions
2897
2997
  */
2898
- async buildCreateMultipleTransactionInstructions(data, extParams) {
2998
+ async buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions = true) {
2899
2999
  const { recipients, ...streamParams } = data;
2900
3000
  const { sender, metadataPubKeys: metadataPubKeysExt, isNative, customInstructions } = extParams;
2901
3001
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
@@ -2919,7 +3019,9 @@ var SolanaStreamClient = class {
2919
3019
  createStreamData,
2920
3020
  createStreamExtParams
2921
3021
  );
2922
- await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3022
+ if (applyCustomAfterInstructions) {
3023
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3024
+ }
2923
3025
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
2924
3026
  metadatas.push(metadataPubKey.toBase58());
2925
3027
  instructionsBatch.push({
@@ -2928,19 +3030,10 @@ var SolanaStreamClient = class {
2928
3030
  recipient: recipientData.recipient
2929
3031
  });
2930
3032
  }
2931
- const prepareInstructions = await this.getCreateATAInstructions(
2932
- [partnerPublicKey],
2933
- mintPublicKey,
2934
- sender,
2935
- true
2936
- );
3033
+ const prepareInstructions = await this.getCreateATAInstructions([partnerPublicKey], mintPublicKey, sender, true);
2937
3034
  if (isNative) {
2938
3035
  const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN3__default.default(0));
2939
- const nativeInstructions = await common.prepareWrappedAccount(
2940
- this.connection,
2941
- sender.publicKey,
2942
- totalDepositedAmount
2943
- );
3036
+ const nativeInstructions = await common.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2944
3037
  prepareInstructions.push(...nativeInstructions);
2945
3038
  }
2946
3039
  return {
@@ -2976,9 +3069,9 @@ var SolanaStreamClient = class {
2976
3069
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2977
3070
  * @returns Multiple transaction information
2978
3071
  */
2979
- async buildCreateMultipleTransactions(data, extParams) {
3072
+ async buildCreateMultipleTransactions(data, extParams, applyCustomAfterInstructions = true) {
2980
3073
  const { sender } = extParams;
2981
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3074
+ const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions);
2982
3075
  const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
2983
3076
  const batch = [];
2984
3077
  for (const { ixs, metadata, recipient } of instructionsBatch) {
@@ -3009,7 +3102,7 @@ var SolanaStreamClient = class {
3009
3102
  if (!sender.publicKey) {
3010
3103
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3011
3104
  }
3012
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3105
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3013
3106
  const errors = [];
3014
3107
  const signatures = [];
3015
3108
  const metadataPubKeys = metadataPubKeysExt || [];
@@ -3074,7 +3167,7 @@ var SolanaStreamClient = class {
3074
3167
  if (!sender.publicKey) {
3075
3168
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3076
3169
  }
3077
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3170
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3078
3171
  const errors = [];
3079
3172
  const signatures = [];
3080
3173
  const batch = [];
@@ -3138,10 +3231,7 @@ var SolanaStreamClient = class {
3138
3231
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
3139
3232
  const { invoker, customInstructions } = extParams;
3140
3233
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3141
- const ixs = await this.prepareWithdrawInstructions(
3142
- { id, amount },
3143
- extParams
3144
- );
3234
+ const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
3145
3235
  const metadata = new web3_js.PublicKey(id);
3146
3236
  await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
3147
3237
  const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, invoker.publicKey);
@@ -3239,7 +3329,7 @@ var SolanaStreamClient = class {
3239
3329
  }
3240
3330
  const { sender: senderPublicKey } = decodeStream(account.data);
3241
3331
  const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3242
- const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelStreamInstructions(cancelData, extParams);
3332
+ const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3243
3333
  return ixs;
3244
3334
  }
3245
3335
  /**
@@ -3287,7 +3377,7 @@ var SolanaStreamClient = class {
3287
3377
  * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3288
3378
  * @returns Transaction instructions
3289
3379
  */
3290
- async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3380
+ async prepareCancelLinearStream({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3291
3381
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3292
3382
  const streamPublicKey = new web3_js.PublicKey(id);
3293
3383
  const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
@@ -3645,17 +3735,26 @@ var SolanaStreamClient = class {
3645
3735
  const streamPublicKey = new web3_js.PublicKey(data.id);
3646
3736
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
3647
3737
  common.invariant(escrow, "Couldn't get account info");
3738
+ const { sender: senderPublicKey } = decodeStream(escrow.data);
3739
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3740
+ if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
3741
+ throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
3742
+ }
3648
3743
  const ixs = common.prepareBaseInstructions(this.connection, {
3649
3744
  computePrice,
3650
3745
  computeLimit
3651
3746
  });
3652
3747
  ixs.push(
3653
- await updateStreamInstruction(data, this.programId, {
3748
+ await (isAlignedUnlock ? this.alignedProxyProgram.methods.updateContract({
3749
+ transferableBySender: data.transferableBySender ?? null,
3750
+ transferableByRecipient: data.transferableByRecipient ?? null,
3751
+ cancelableBySender: data.cancelableBySender ?? null
3752
+ }).accounts({ sender: invoker.publicKey, streamMetadata: streamPublicKey, withdrawor: WITHDRAWOR_PUBLIC_KEY }).accountsPartial({ streamflowProgram: this.programId }).instruction() : updateStreamInstruction(data, this.programId, {
3654
3753
  authority: invoker.publicKey,
3655
3754
  metadata: streamPublicKey,
3656
3755
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3657
3756
  systemProgram: web3_js.SystemProgram.programId
3658
- })
3757
+ }))
3659
3758
  );
3660
3759
  return ixs;
3661
3760
  }
@@ -3691,11 +3790,11 @@ var SolanaStreamClient = class {
3691
3790
  return DEFAULT_STREAMFLOW_FEE;
3692
3791
  }
3693
3792
  /**
3694
- * Returns total fee percent, streamflow fees + partner fees
3695
- * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3696
- * @param chainSpecificParams additional parameters required by chain client
3697
- * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3698
- */
3793
+ * Returns total fee percent, streamflow fees + partner fees
3794
+ * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3795
+ * @param chainSpecificParams additional parameters required by chain client
3796
+ * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3797
+ */
3699
3798
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3700
3799
  async getTotalFee(getFeesData) {
3701
3800
  const fees = await this.getFees(getFeesData);
@@ -3714,12 +3813,27 @@ var SolanaStreamClient = class {
3714
3813
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3715
3814
  }
3716
3815
  /**
3717
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3718
- */
3816
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3817
+ */
3719
3818
  isAlignedUnlock(streamPublicKey, senderPublicKey) {
3720
3819
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3721
3820
  return senderPublicKey.equals(pda);
3722
3821
  }
3822
+ async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
3823
+ const dataArray = Array.isArray(data) ? data : [data];
3824
+ const results = await Promise.all(
3825
+ dataArray.map((item, index) => this.buildCreateMultipleTransactionInstructions(item, extParams, index === 0))
3826
+ );
3827
+ return {
3828
+ instructionsBatch: results.flatMap((r) => r.instructionsBatch),
3829
+ metadatas: results.flatMap((r) => r.metadatas),
3830
+ prepareInstructions: results.flatMap((r) => r.prepareInstructions),
3831
+ metadataToRecipient: results.reduce(
3832
+ (acc, r) => Object.assign(acc, r.metadataToRecipient),
3833
+ {}
3834
+ )
3835
+ };
3836
+ }
3723
3837
  /**
3724
3838
  * Utility function to generate metadata for a Contract or return existing Pubkey
3725
3839
  */