@streamflow/stream 10.0.0-alpha.p313.3ce4d29 → 10.0.0-alpha.p313.43acc5b

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/esm/index.js CHANGED
@@ -33,14 +33,11 @@ var calculateUnlockedAmount = ({
33
33
  var isCliffCloseToDepositedAmount = (streamData) => {
34
34
  return streamData.cliffAmount.gte(streamData.depositedAmount.sub(new BN3(1)));
35
35
  };
36
- var isPayment = (streamData) => {
37
- return streamData.canTopup;
38
- };
39
36
  var isVesting = (streamData) => {
40
- return !streamData.canTopup && !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
37
+ return !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
41
38
  };
42
39
  var isAligned = (stream) => {
43
- return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
40
+ return stream.isAligned;
44
41
  };
45
42
  var isCreateAlignedStreamData = (obj) => {
46
43
  return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
@@ -52,13 +49,10 @@ var isTokenLock = (streamData) => {
52
49
  return !streamData.canTopup && !streamData.automaticWithdrawal && !streamData.cancelableBySender && !streamData.cancelableByRecipient && !streamData.transferableBySender && (isCliffCloseToDepositedAmount(streamData) || isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage));
53
50
  };
54
51
  var buildStreamType = (streamData) => {
55
- if (isVesting(streamData)) {
56
- return "vesting" /* Vesting */;
57
- }
58
52
  if (isTokenLock(streamData)) {
59
53
  return "lock" /* Lock */;
60
54
  }
61
- return "payment" /* Payment */;
55
+ return "vesting" /* Vesting */;
62
56
  };
63
57
  var decodeEndTime = (endTime) => {
64
58
  if (endTime.gt(new BN3(MAX_SAFE_UNIX_TIME_VALUE))) {
@@ -75,7 +69,6 @@ var StreamDirection = /* @__PURE__ */ ((StreamDirection2) => {
75
69
  })(StreamDirection || {});
76
70
  var StreamType = /* @__PURE__ */ ((StreamType2) => {
77
71
  StreamType2["All"] = "all";
78
- StreamType2["Payment"] = "payment";
79
72
  StreamType2["Vesting"] = "vesting";
80
73
  StreamType2["Lock"] = "lock";
81
74
  return StreamType2;
@@ -232,25 +225,40 @@ var ALIGNED_UNLOCKS_PROGRAM_ID = {
232
225
  [ICluster.Testnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
233
226
  [ICluster.Local]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH"
234
227
  };
228
+ var PARTNER_ORACLE_PROGRAM_ID = {
229
+ [ICluster.Devnet]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3",
230
+ [ICluster.Mainnet]: "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa",
231
+ [ICluster.Testnet]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3",
232
+ [ICluster.Local]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3"
233
+ };
234
+ var FEE_ORACLE_PUBLIC_KEY = {
235
+ [ICluster.Devnet]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs",
236
+ [ICluster.Mainnet]: "B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT",
237
+ [ICluster.Testnet]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs",
238
+ [ICluster.Local]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs"
239
+ };
235
240
  var ALIGNED_COMPUTE_LIMIT = 3e5;
236
241
  var CONTRACT_DISCRIMINATOR = [172, 138, 115, 242, 121, 67, 183, 26];
237
242
  var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
238
243
  var CONTRACT_SEED = Buffer.from("contract", "utf-8");
239
244
  var ESCROW_SEED = Buffer.from("strm", "utf-8");
240
245
  var TEST_ORACLE_SEED = Buffer.from("test-oracle", "utf-8");
241
- var PARTNER_ORACLE_PROGRAM_ID = "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa";
242
246
  var STREAMFLOW_TREASURY_PUBLIC_KEY = new PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
243
- var WITHDRAWOR_PUBLIC_KEY = new PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
244
- var FEE_ORACLE_PUBLIC_KEY = new PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
247
+ var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
248
+ var WITHDRAWOR_PUBLIC_KEY = new PublicKey(WITHDRAWOR);
245
249
  var AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
246
250
  var FEES_METADATA_SEED = Buffer.from("strm_fees");
247
- var DEFAULT_STREAMFLOW_FEE = 0.99;
251
+ var DEFAULT_CREATION_FEE_SOL = 9e7;
252
+ var DEFAULT_AUTO_CLAIM_FEE_SOL = 19e7;
253
+ var DEFAULT_STREAMFLOW_FEE = 0.19;
248
254
  var AIRDROP_AMOUNT = 1;
249
255
  var PARTNER_SCHEMA = {
250
256
  struct: {
251
257
  pubkey: { array: { type: "u8", len: 32 } },
252
- partner_fee: "f32",
253
- strm_fee: "f32"
258
+ creation_fee: "u32",
259
+ auto_claim_fee: "u32",
260
+ token_fee_percent: "f32",
261
+ buffer: { array: { type: "u8", len: 16 } }
254
262
  }
255
263
  };
256
264
  var PARTNERS_SCHEMA = { array: { type: PARTNER_SCHEMA } };
@@ -886,7 +894,7 @@ var streamflow_aligned_unlocks_default = {
886
894
  address: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
887
895
  metadata: {
888
896
  name: "streamflow_aligned_unlocks",
889
- version: "1.3.0",
897
+ version: "1.4.0",
890
898
  spec: "0.1.0",
891
899
  description: "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics"
892
900
  },
@@ -1760,6 +1768,80 @@ var streamflow_aligned_unlocks_default = {
1760
1768
  ],
1761
1769
  args: []
1762
1770
  },
1771
+ {
1772
+ name: "update_contract",
1773
+ discriminator: [
1774
+ 78,
1775
+ 184,
1776
+ 162,
1777
+ 174,
1778
+ 233,
1779
+ 5,
1780
+ 40,
1781
+ 82
1782
+ ],
1783
+ accounts: [
1784
+ {
1785
+ name: "sender",
1786
+ writable: true,
1787
+ signer: true
1788
+ },
1789
+ {
1790
+ name: "proxy_metadata",
1791
+ docs: [
1792
+ "Proxy Contract"
1793
+ ],
1794
+ writable: true,
1795
+ pda: {
1796
+ seeds: [
1797
+ {
1798
+ kind: "const",
1799
+ value: [
1800
+ 99,
1801
+ 111,
1802
+ 110,
1803
+ 116,
1804
+ 114,
1805
+ 97,
1806
+ 99,
1807
+ 116
1808
+ ]
1809
+ },
1810
+ {
1811
+ kind: "account",
1812
+ path: "stream_metadata"
1813
+ }
1814
+ ]
1815
+ }
1816
+ },
1817
+ {
1818
+ name: "stream_metadata",
1819
+ writable: true
1820
+ },
1821
+ {
1822
+ name: "withdrawor",
1823
+ writable: true
1824
+ },
1825
+ {
1826
+ name: "streamflow_program",
1827
+ address: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m"
1828
+ },
1829
+ {
1830
+ name: "system_program",
1831
+ address: "11111111111111111111111111111111"
1832
+ }
1833
+ ],
1834
+ args: [
1835
+ {
1836
+ name: "params",
1837
+ type: {
1838
+ defined: {
1839
+ name: "UpdateContractParams"
1840
+ }
1841
+ }
1842
+ }
1843
+ ]
1844
+ },
1763
1845
  {
1764
1846
  name: "update_test_oracle",
1765
1847
  discriminator: [
@@ -2355,6 +2437,32 @@ var streamflow_aligned_unlocks_default = {
2355
2437
  ]
2356
2438
  }
2357
2439
  },
2440
+ {
2441
+ name: "UpdateContractParams",
2442
+ type: {
2443
+ kind: "struct",
2444
+ fields: [
2445
+ {
2446
+ name: "transferable_by_sender",
2447
+ type: {
2448
+ option: "bool"
2449
+ }
2450
+ },
2451
+ {
2452
+ name: "transferable_by_recipient",
2453
+ type: {
2454
+ option: "bool"
2455
+ }
2456
+ },
2457
+ {
2458
+ name: "cancelable_by_sender",
2459
+ type: {
2460
+ option: "bool"
2461
+ }
2462
+ }
2463
+ ]
2464
+ }
2465
+ },
2358
2466
  {
2359
2467
  name: "UpdateTestOracleParams",
2360
2468
  type: {
@@ -2403,6 +2511,8 @@ var SolanaStreamClient = class {
2403
2511
  this.commitment = commitment;
2404
2512
  this.connection = new Connection(optionsOrClusterUrl, this.commitment);
2405
2513
  this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(PROGRAM_ID[cluster]);
2514
+ this.partnerOracleProgramId = new PublicKey(PARTNER_ORACLE_PROGRAM_ID[cluster]);
2515
+ this.feeOraclePublicKey = new PublicKey(FEE_ORACLE_PUBLIC_KEY[cluster]);
2406
2516
  this.schedulingParams = {
2407
2517
  sendThrottler: sendThrottler ?? buildSendThrottler(sendRate)
2408
2518
  };
@@ -2417,6 +2527,8 @@ var SolanaStreamClient = class {
2417
2527
  this.commitment = commitment2;
2418
2528
  this.connection = new Connection(clusterUrl, this.commitment);
2419
2529
  this.programId = programId2 !== "" ? new PublicKey(programId2) : new PublicKey(PROGRAM_ID[cluster2]);
2530
+ this.partnerOracleProgramId = new PublicKey(PARTNER_ORACLE_PROGRAM_ID[cluster2]);
2531
+ this.feeOraclePublicKey = new PublicKey(FEE_ORACLE_PUBLIC_KEY[cluster2]);
2420
2532
  const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : void 0;
2421
2533
  const sendThrottler2 = !sendScheduler ? buildSendThrottler(1) : "sendRate" in sendScheduler ? buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval) : sendScheduler;
2422
2534
  this.schedulingParams = {
@@ -2457,7 +2569,7 @@ var SolanaStreamClient = class {
2457
2569
  const { partner, amount, tokenProgramId } = data;
2458
2570
  const { isNative, sender, customInstructions } = extParams;
2459
2571
  assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2460
- const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2572
+ const partnerPublicKey = partner ? new PublicKey(partner) : sender.publicKey;
2461
2573
  const mintPublicKey = new PublicKey(data.tokenId);
2462
2574
  const ixs = await this.getCreateATAInstructions(
2463
2575
  [partnerPublicKey],
@@ -2545,7 +2657,7 @@ var SolanaStreamClient = class {
2545
2657
  return { ixs, txId: signature, metadataId };
2546
2658
  }
2547
2659
  async prepareCreateInstructions(streamParams, extParams) {
2548
- const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateStreamInstructions(streamParams, extParams);
2660
+ const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateLinearStreamInstructions(streamParams, extParams);
2549
2661
  return { ixs, metadata, metadataPubKey };
2550
2662
  }
2551
2663
  async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
@@ -2579,7 +2691,10 @@ var SolanaStreamClient = class {
2579
2691
  floorPrice
2580
2692
  } = streamParams;
2581
2693
  const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
2582
- invariant(priceOracle || !oracleType || oracleType === "none", "Price oracle is required for the specified oracle type");
2694
+ invariant(
2695
+ priceOracle || !oracleType || oracleType === "none",
2696
+ "Price oracle is required for the specified oracle type"
2697
+ );
2583
2698
  assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2584
2699
  const recipientPublicKey = new PublicKey(recipient);
2585
2700
  const mintPublicKey = isNative ? NATIVE_MINT : new PublicKey(mint);
@@ -2590,7 +2705,7 @@ var SolanaStreamClient = class {
2590
2705
  if (!tokenProgramId) {
2591
2706
  tokenProgramId = (await getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
2592
2707
  }
2593
- const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2708
+ const partnerPublicKey = partner ? new PublicKey(partner) : sender.publicKey;
2594
2709
  const streamflowProgramPublicKey = new PublicKey(this.programId);
2595
2710
  const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
2596
2711
  const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
@@ -2637,7 +2752,7 @@ var SolanaStreamClient = class {
2637
2752
  partner: partnerPublicKey,
2638
2753
  recipient: recipientPublicKey,
2639
2754
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
2640
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
2755
+ feeOracle: this.feeOraclePublicKey,
2641
2756
  priceOracle: oracle,
2642
2757
  tokenProgram: tokenProgramId,
2643
2758
  streamflowProgram: this.programId
@@ -2652,7 +2767,7 @@ var SolanaStreamClient = class {
2652
2767
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
2653
2768
  * @returns Create stream instructions
2654
2769
  */
2655
- async prepareCreateStreamInstructions({
2770
+ async prepareCreateLinearStreamInstructions({
2656
2771
  recipient,
2657
2772
  tokenId: mint,
2658
2773
  start,
@@ -2693,7 +2808,7 @@ var SolanaStreamClient = class {
2693
2808
  const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
2694
2809
  const recipientTokens = await ata(mintPublicKey, recipientPublicKey, tokenProgramId);
2695
2810
  const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2696
- const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2811
+ const partnerPublicKey = partner ? new PublicKey(partner) : sender.publicKey;
2697
2812
  const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
2698
2813
  ixs.push(
2699
2814
  await createStreamInstruction(
@@ -2728,7 +2843,7 @@ var SolanaStreamClient = class {
2728
2843
  partner: partnerPublicKey,
2729
2844
  partnerTokens,
2730
2845
  mint: new PublicKey(mint),
2731
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
2846
+ feeOracle: this.feeOraclePublicKey,
2732
2847
  rent: SYSVAR_RENT_PUBKEY,
2733
2848
  timelockProgram: this.programId,
2734
2849
  tokenProgram: tokenProgramId,
@@ -2754,10 +2869,7 @@ var SolanaStreamClient = class {
2754
2869
  * @returns Create result
2755
2870
  */
2756
2871
  async createUnchecked(data, extParams) {
2757
- const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(
2758
- data,
2759
- extParams
2760
- );
2872
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(data, extParams);
2761
2873
  const { tx, hash, context } = await prepareTransaction(
2762
2874
  this.connection,
2763
2875
  ixs,
@@ -2820,7 +2932,7 @@ var SolanaStreamClient = class {
2820
2932
  );
2821
2933
  const { tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
2822
2934
  const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
2823
- const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2935
+ const partnerPublicKey = partner ? new PublicKey(partner) : sender.publicKey;
2824
2936
  const ixs = prepareBaseInstructions(this.connection, {
2825
2937
  computePrice,
2826
2938
  computeLimit
@@ -2858,7 +2970,7 @@ var SolanaStreamClient = class {
2858
2970
  metadata: metadataPubKey,
2859
2971
  escrowTokens,
2860
2972
  mint: new PublicKey(mint),
2861
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
2973
+ feeOracle: this.feeOraclePublicKey,
2862
2974
  rent: SYSVAR_RENT_PUBKEY,
2863
2975
  timelockProgram: this.programId,
2864
2976
  tokenProgram: tokenProgramId,
@@ -2876,15 +2988,14 @@ var SolanaStreamClient = class {
2876
2988
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2877
2989
  * @returns Create multiple transaction instructions
2878
2990
  */
2879
- async buildCreateMultipleTransactionInstructions(data, extParams) {
2991
+ async buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions = true) {
2880
2992
  const { recipients, ...streamParams } = data;
2881
2993
  const { sender, metadataPubKeys: metadataPubKeysExt, isNative, customInstructions } = extParams;
2882
2994
  assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2883
2995
  const metadatas = [];
2884
2996
  const metadataToRecipient = {};
2885
2997
  const instructionsBatch = [];
2886
- const metadataPubKeys = metadataPubKeysExt || [];
2887
- const partnerPublicKey = data.partner ? new PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
2998
+ const partnerPublicKey = data.partner ? new PublicKey(data.partner) : sender.publicKey;
2888
2999
  const mintPublicKey = new PublicKey(data.tokenId);
2889
3000
  if (recipients.length === 0) {
2890
3001
  throw new Error("Recipients array is empty!");
@@ -2893,14 +3004,16 @@ var SolanaStreamClient = class {
2893
3004
  const recipientData = recipients[i];
2894
3005
  const createStreamData = { ...streamParams, ...recipientData };
2895
3006
  const createStreamExtParams = {
2896
- metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
2897
- ...extParams
3007
+ ...extParams,
3008
+ metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
2898
3009
  };
2899
3010
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
2900
3011
  createStreamData,
2901
3012
  createStreamExtParams
2902
3013
  );
2903
- await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3014
+ if (applyCustomAfterInstructions) {
3015
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3016
+ }
2904
3017
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
2905
3018
  metadatas.push(metadataPubKey.toBase58());
2906
3019
  instructionsBatch.push({
@@ -2909,19 +3022,10 @@ var SolanaStreamClient = class {
2909
3022
  recipient: recipientData.recipient
2910
3023
  });
2911
3024
  }
2912
- const prepareInstructions = await this.getCreateATAInstructions(
2913
- [partnerPublicKey],
2914
- mintPublicKey,
2915
- sender,
2916
- true
2917
- );
3025
+ const prepareInstructions = await this.getCreateATAInstructions([partnerPublicKey], mintPublicKey, sender, true);
2918
3026
  if (isNative) {
2919
3027
  const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN3(0));
2920
- const nativeInstructions = await prepareWrappedAccount(
2921
- this.connection,
2922
- sender.publicKey,
2923
- totalDepositedAmount
2924
- );
3028
+ const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2925
3029
  prepareInstructions.push(...nativeInstructions);
2926
3030
  }
2927
3031
  return {
@@ -2957,9 +3061,9 @@ var SolanaStreamClient = class {
2957
3061
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2958
3062
  * @returns Multiple transaction information
2959
3063
  */
2960
- async buildCreateMultipleTransactions(data, extParams) {
3064
+ async buildCreateMultipleTransactions(data, extParams, applyCustomAfterInstructions = true) {
2961
3065
  const { sender } = extParams;
2962
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3066
+ const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions);
2963
3067
  const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
2964
3068
  const batch = [];
2965
3069
  for (const { ixs, metadata, recipient } of instructionsBatch) {
@@ -2990,7 +3094,7 @@ var SolanaStreamClient = class {
2990
3094
  if (!sender.publicKey) {
2991
3095
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
2992
3096
  }
2993
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3097
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
2994
3098
  const errors = [];
2995
3099
  const signatures = [];
2996
3100
  const metadataPubKeys = metadataPubKeysExt || [];
@@ -3055,7 +3159,7 @@ var SolanaStreamClient = class {
3055
3159
  if (!sender.publicKey) {
3056
3160
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3057
3161
  }
3058
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3162
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3059
3163
  const errors = [];
3060
3164
  const signatures = [];
3061
3165
  const batch = [];
@@ -3119,10 +3223,7 @@ var SolanaStreamClient = class {
3119
3223
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
3120
3224
  const { invoker, customInstructions } = extParams;
3121
3225
  assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3122
- const ixs = await this.prepareWithdrawInstructions(
3123
- { id, amount },
3124
- extParams
3125
- );
3226
+ const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
3126
3227
  const metadata = new PublicKey(id);
3127
3228
  await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
3128
3229
  const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker.publicKey);
@@ -3220,7 +3321,7 @@ var SolanaStreamClient = class {
3220
3321
  }
3221
3322
  const { sender: senderPublicKey } = decodeStream(account.data);
3222
3323
  const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3223
- const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelStreamInstructions(cancelData, extParams);
3324
+ const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3224
3325
  return ixs;
3225
3326
  }
3226
3327
  /**
@@ -3268,7 +3369,7 @@ var SolanaStreamClient = class {
3268
3369
  * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3269
3370
  * @returns Transaction instructions
3270
3371
  */
3271
- async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3372
+ async prepareCancelLinearStream({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3272
3373
  assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3273
3374
  const streamPublicKey = new PublicKey(id);
3274
3375
  const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
@@ -3572,11 +3673,42 @@ var SolanaStreamClient = class {
3572
3673
  const accounts = await this.connection.getProgramAccounts(this.programId, {
3573
3674
  filters
3574
3675
  });
3676
+ const decoded = this.decodeStreamsFromAccounts(accounts);
3677
+ const alignedEntries = this.collectAlignedEntries(decoded);
3678
+ const alignedProxies = await this.fetchAlignedProxiesByEntries(alignedEntries);
3679
+ return this.mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies);
3680
+ }
3681
+ decodeStreamsFromAccounts(accounts) {
3575
3682
  return accounts.map(({ pubkey, account }) => ({
3576
- publicKey: pubkey,
3577
- account: new Contract(decodeStream(account.data))
3683
+ pubkey,
3684
+ stream: decodeStream(account.data)
3578
3685
  }));
3579
3686
  }
3687
+ collectAlignedEntries(decoded) {
3688
+ const entries = [];
3689
+ decoded.forEach(({ pubkey, stream }, index) => {
3690
+ if (this.isAlignedUnlock(pubkey, stream.sender)) {
3691
+ entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, pubkey) });
3692
+ }
3693
+ });
3694
+ return entries;
3695
+ }
3696
+ async fetchAlignedProxiesByEntries(aligned) {
3697
+ if (aligned.length === 0) return [];
3698
+ const res = await this.alignedProxyProgram.account.contract.fetchMultiple(aligned.map((a) => a.pda));
3699
+ return res;
3700
+ }
3701
+ mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies) {
3702
+ return decoded.map(({ pubkey, stream }, idx) => {
3703
+ const alignedIdx = alignedEntries.findIndex((a) => a.index === idx);
3704
+ if (alignedIdx !== -1) {
3705
+ const alignedProxy = alignedProxies[alignedIdx];
3706
+ invariant(alignedProxy, "Couldn't get aligned proxy account info");
3707
+ return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
3708
+ }
3709
+ return { publicKey: pubkey, account: new Contract(stream) };
3710
+ });
3711
+ }
3580
3712
  /**
3581
3713
  * Attempts updating the stream auto withdrawal params and amount per period
3582
3714
  * @param {IUpdateData} data - Update parameters including stream ID and new settings
@@ -3616,17 +3748,26 @@ var SolanaStreamClient = class {
3616
3748
  const streamPublicKey = new PublicKey(data.id);
3617
3749
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
3618
3750
  invariant(escrow, "Couldn't get account info");
3751
+ const { sender: senderPublicKey } = decodeStream(escrow.data);
3752
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3753
+ if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
3754
+ throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
3755
+ }
3619
3756
  const ixs = prepareBaseInstructions(this.connection, {
3620
3757
  computePrice,
3621
3758
  computeLimit
3622
3759
  });
3623
3760
  ixs.push(
3624
- await updateStreamInstruction(data, this.programId, {
3761
+ await (isAlignedUnlock ? this.alignedProxyProgram.methods.updateContract({
3762
+ transferableBySender: data.transferableBySender ?? null,
3763
+ transferableByRecipient: data.transferableByRecipient ?? null,
3764
+ cancelableBySender: data.cancelableBySender ?? null
3765
+ }).accounts({ sender: invoker.publicKey, streamMetadata: streamPublicKey, withdrawor: WITHDRAWOR_PUBLIC_KEY }).accountsPartial({ streamflowProgram: this.programId }).instruction() : updateStreamInstruction(data, this.programId, {
3625
3766
  authority: invoker.publicKey,
3626
3767
  metadata: streamPublicKey,
3627
3768
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3628
3769
  systemProgram: SystemProgram.programId
3629
- })
3770
+ }))
3630
3771
  );
3631
3772
  return ixs;
3632
3773
  }
@@ -3636,35 +3777,47 @@ var SolanaStreamClient = class {
3636
3777
  * @returns Fees
3637
3778
  */
3638
3779
  async getFees({ address }) {
3639
- const [metadataPubKey] = PublicKey.findProgramAddressSync(
3640
- [Buffer.from(FEES_METADATA_SEED)],
3641
- new PublicKey(PARTNER_ORACLE_PROGRAM_ID)
3642
- );
3643
- const data = await this.connection.getAccountInfo(metadataPubKey);
3780
+ const data = await this.connection.getAccountInfo(this.feeOraclePublicKey);
3644
3781
  if (!data) {
3645
3782
  return null;
3646
3783
  }
3647
3784
  const partners = borsh.deserialize(PARTNERS_SCHEMA, data.data);
3648
- const filteredPartners = partners.filter((item) => new PublicKey(item.pubkey).toString() === address);
3649
- if (filteredPartners.length === 0) {
3650
- return null;
3785
+ for (const partner of partners) {
3786
+ const partnerAddress = new PublicKey(partner.pubkey).toString();
3787
+ if (partnerAddress === address) {
3788
+ return {
3789
+ creationFeeSol: Number(partner.creation_fee),
3790
+ autoClaimFeeSol: Number(partner.auto_claim_fee),
3791
+ streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
3792
+ partnerFee: 0
3793
+ };
3794
+ }
3651
3795
  }
3652
- return {
3653
- streamflowFee: Number(filteredPartners[0].strm_fee.toFixed(4)),
3654
- partnerFee: Number(filteredPartners[0].partner_fee.toFixed(4))
3655
- };
3796
+ return null;
3656
3797
  }
3657
3798
  /**
3658
3799
  * Gets default streamflow fee
3659
3800
  * @returns Default streamflow fee
3660
3801
  */
3661
3802
  async getDefaultStreamflowFee() {
3662
- return DEFAULT_STREAMFLOW_FEE;
3803
+ return (await this.getDefaultFees()).streamflowFee;
3804
+ }
3805
+ /**
3806
+ * Get all defaults fees applied by the protocol.
3807
+ *
3808
+ * Protocol will use fees set for WITHDRAWOR as default if they are set.
3809
+ */
3810
+ async getDefaultFees() {
3811
+ return await this.getFees({ address: WITHDRAWOR }) || {
3812
+ creationFeeSol: DEFAULT_CREATION_FEE_SOL,
3813
+ autoClaimFeeSol: DEFAULT_AUTO_CLAIM_FEE_SOL,
3814
+ streamflowFee: DEFAULT_STREAMFLOW_FEE,
3815
+ partnerFee: 0
3816
+ };
3663
3817
  }
3664
3818
  /**
3665
3819
  * Returns total fee percent, streamflow fees + partner fees
3666
3820
  * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3667
- * @param chainSpecificParams additional parameters required by chain client
3668
3821
  * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3669
3822
  */
3670
3823
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -3685,12 +3838,27 @@ var SolanaStreamClient = class {
3685
3838
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3686
3839
  }
3687
3840
  /**
3688
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3689
- */
3841
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3842
+ */
3690
3843
  isAlignedUnlock(streamPublicKey, senderPublicKey) {
3691
3844
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3692
3845
  return senderPublicKey.equals(pda);
3693
3846
  }
3847
+ async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
3848
+ const dataArray = Array.isArray(data) ? data : [data];
3849
+ const results = await Promise.all(
3850
+ dataArray.map((item, index) => this.buildCreateMultipleTransactionInstructions(item, extParams, index === 0))
3851
+ );
3852
+ return {
3853
+ instructionsBatch: results.flatMap((r) => r.instructionsBatch),
3854
+ metadatas: results.flatMap((r) => r.metadatas),
3855
+ prepareInstructions: results.flatMap((r) => r.prepareInstructions),
3856
+ metadataToRecipient: results.reduce(
3857
+ (acc, r) => Object.assign(acc, r.metadataToRecipient),
3858
+ {}
3859
+ )
3860
+ };
3861
+ }
3694
3862
  /**
3695
3863
  * Utility function to generate metadata for a Contract or return existing Pubkey
3696
3864
  */
@@ -4150,6 +4318,6 @@ var timelockIDL_default = {
4150
4318
  ]
4151
4319
  };
4152
4320
 
4153
- export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW2 as ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, AlignedContract, AlignedProxyErrorCode, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Contract, ContractErrorCode, DEFAULT_STREAMFLOW_FEE, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, MAX_SAFE_UNIX_TIME_VALUE2 as MAX_SAFE_UNIX_TIME_VALUE, ORIGINAL_CONTRACT_SENDER_OFFSET, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isPayment, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL_default as timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction };
4321
+ export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW2 as ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, AlignedContract, AlignedProxyErrorCode, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Contract, ContractErrorCode, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, MAX_SAFE_UNIX_TIME_VALUE2 as MAX_SAFE_UNIX_TIME_VALUE, ORIGINAL_CONTRACT_SENDER_OFFSET, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveTestOraclePDA, extractSolanaErrorCode, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL_default as timelockIDL, topupStreamInstruction, transferStreamInstruction, updateStreamInstruction, withdrawStreamInstruction };
4154
4322
  //# sourceMappingURL=index.js.map
4155
4323
  //# sourceMappingURL=index.js.map