@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.
@@ -59,14 +59,11 @@ 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
- return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
66
+ return stream.isAligned;
70
67
  };
71
68
  var isCreateAlignedStreamData = (obj) => {
72
69
  return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
@@ -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;
@@ -258,25 +251,40 @@ var ALIGNED_UNLOCKS_PROGRAM_ID = {
258
251
  [common.ICluster.Testnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
259
252
  [common.ICluster.Local]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH"
260
253
  };
254
+ var PARTNER_ORACLE_PROGRAM_ID = {
255
+ [common.ICluster.Devnet]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3",
256
+ [common.ICluster.Mainnet]: "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa",
257
+ [common.ICluster.Testnet]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3",
258
+ [common.ICluster.Local]: "pardoTarcc6HKsPcbXkVycxsJsoN9QEzrdHgVdHAGY3"
259
+ };
260
+ var FEE_ORACLE_PUBLIC_KEY = {
261
+ [common.ICluster.Devnet]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs",
262
+ [common.ICluster.Mainnet]: "B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT",
263
+ [common.ICluster.Testnet]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs",
264
+ [common.ICluster.Local]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs"
265
+ };
261
266
  var ALIGNED_COMPUTE_LIMIT = 3e5;
262
267
  var CONTRACT_DISCRIMINATOR = [172, 138, 115, 242, 121, 67, 183, 26];
263
268
  var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
264
269
  var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
265
270
  var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
266
271
  var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
267
- var PARTNER_ORACLE_PROGRAM_ID = "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa";
268
272
  var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
269
- var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
270
- var FEE_ORACLE_PUBLIC_KEY = new web3_js.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
273
+ var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
274
+ var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey(WITHDRAWOR);
271
275
  var AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
272
276
  var FEES_METADATA_SEED = buffer.Buffer.from("strm_fees");
273
- var DEFAULT_STREAMFLOW_FEE = 0.99;
277
+ var DEFAULT_CREATION_FEE_SOL = 9e7;
278
+ var DEFAULT_AUTO_CLAIM_FEE_SOL = 19e7;
279
+ var DEFAULT_STREAMFLOW_FEE = 0.19;
274
280
  var AIRDROP_AMOUNT = 1;
275
281
  var PARTNER_SCHEMA = {
276
282
  struct: {
277
283
  pubkey: { array: { type: "u8", len: 32 } },
278
- partner_fee: "f32",
279
- strm_fee: "f32"
284
+ creation_fee: "u32",
285
+ auto_claim_fee: "u32",
286
+ token_fee_percent: "f32",
287
+ buffer: { array: { type: "u8", len: 16 } }
280
288
  }
281
289
  };
282
290
  var PARTNERS_SCHEMA = { array: { type: PARTNER_SCHEMA } };
@@ -912,7 +920,7 @@ var streamflow_aligned_unlocks_default = {
912
920
  address: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
913
921
  metadata: {
914
922
  name: "streamflow_aligned_unlocks",
915
- version: "1.3.0",
923
+ version: "1.4.0",
916
924
  spec: "0.1.0",
917
925
  description: "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics"
918
926
  },
@@ -1786,6 +1794,80 @@ var streamflow_aligned_unlocks_default = {
1786
1794
  ],
1787
1795
  args: []
1788
1796
  },
1797
+ {
1798
+ name: "update_contract",
1799
+ discriminator: [
1800
+ 78,
1801
+ 184,
1802
+ 162,
1803
+ 174,
1804
+ 233,
1805
+ 5,
1806
+ 40,
1807
+ 82
1808
+ ],
1809
+ accounts: [
1810
+ {
1811
+ name: "sender",
1812
+ writable: true,
1813
+ signer: true
1814
+ },
1815
+ {
1816
+ name: "proxy_metadata",
1817
+ docs: [
1818
+ "Proxy Contract"
1819
+ ],
1820
+ writable: true,
1821
+ pda: {
1822
+ seeds: [
1823
+ {
1824
+ kind: "const",
1825
+ value: [
1826
+ 99,
1827
+ 111,
1828
+ 110,
1829
+ 116,
1830
+ 114,
1831
+ 97,
1832
+ 99,
1833
+ 116
1834
+ ]
1835
+ },
1836
+ {
1837
+ kind: "account",
1838
+ path: "stream_metadata"
1839
+ }
1840
+ ]
1841
+ }
1842
+ },
1843
+ {
1844
+ name: "stream_metadata",
1845
+ writable: true
1846
+ },
1847
+ {
1848
+ name: "withdrawor",
1849
+ writable: true
1850
+ },
1851
+ {
1852
+ name: "streamflow_program",
1853
+ address: "strmRqUCoQUgGUan5YhzUZa6KqdzwX5L6FpUxfmKg5m"
1854
+ },
1855
+ {
1856
+ name: "system_program",
1857
+ address: "11111111111111111111111111111111"
1858
+ }
1859
+ ],
1860
+ args: [
1861
+ {
1862
+ name: "params",
1863
+ type: {
1864
+ defined: {
1865
+ name: "UpdateContractParams"
1866
+ }
1867
+ }
1868
+ }
1869
+ ]
1870
+ },
1789
1871
  {
1790
1872
  name: "update_test_oracle",
1791
1873
  discriminator: [
@@ -2381,6 +2463,32 @@ var streamflow_aligned_unlocks_default = {
2381
2463
  ]
2382
2464
  }
2383
2465
  },
2466
+ {
2467
+ name: "UpdateContractParams",
2468
+ type: {
2469
+ kind: "struct",
2470
+ fields: [
2471
+ {
2472
+ name: "transferable_by_sender",
2473
+ type: {
2474
+ option: "bool"
2475
+ }
2476
+ },
2477
+ {
2478
+ name: "transferable_by_recipient",
2479
+ type: {
2480
+ option: "bool"
2481
+ }
2482
+ },
2483
+ {
2484
+ name: "cancelable_by_sender",
2485
+ type: {
2486
+ option: "bool"
2487
+ }
2488
+ }
2489
+ ]
2490
+ }
2491
+ },
2384
2492
  {
2385
2493
  name: "UpdateTestOracleParams",
2386
2494
  type: {
@@ -2429,6 +2537,8 @@ var SolanaStreamClient = class {
2429
2537
  this.commitment = commitment;
2430
2538
  this.connection = new web3_js.Connection(optionsOrClusterUrl, this.commitment);
2431
2539
  this.programId = programId !== "" ? new web3_js.PublicKey(programId) : new web3_js.PublicKey(PROGRAM_ID[cluster]);
2540
+ this.partnerOracleProgramId = new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID[cluster]);
2541
+ this.feeOraclePublicKey = new web3_js.PublicKey(FEE_ORACLE_PUBLIC_KEY[cluster]);
2432
2542
  this.schedulingParams = {
2433
2543
  sendThrottler: sendThrottler ?? common.buildSendThrottler(sendRate)
2434
2544
  };
@@ -2443,6 +2553,8 @@ var SolanaStreamClient = class {
2443
2553
  this.commitment = commitment2;
2444
2554
  this.connection = new web3_js.Connection(clusterUrl, this.commitment);
2445
2555
  this.programId = programId2 !== "" ? new web3_js.PublicKey(programId2) : new web3_js.PublicKey(PROGRAM_ID[cluster2]);
2556
+ this.partnerOracleProgramId = new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID[cluster2]);
2557
+ this.feeOraclePublicKey = new web3_js.PublicKey(FEE_ORACLE_PUBLIC_KEY[cluster2]);
2446
2558
  const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : void 0;
2447
2559
  const sendThrottler2 = !sendScheduler ? common.buildSendThrottler(1) : "sendRate" in sendScheduler ? common.buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval) : sendScheduler;
2448
2560
  this.schedulingParams = {
@@ -2483,7 +2595,7 @@ var SolanaStreamClient = class {
2483
2595
  const { partner, amount, tokenProgramId } = data;
2484
2596
  const { isNative, sender, customInstructions } = extParams;
2485
2597
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2486
- const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2598
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
2487
2599
  const mintPublicKey = new web3_js.PublicKey(data.tokenId);
2488
2600
  const ixs = await this.getCreateATAInstructions(
2489
2601
  [partnerPublicKey],
@@ -2571,7 +2683,7 @@ var SolanaStreamClient = class {
2571
2683
  return { ixs, txId: signature, metadataId };
2572
2684
  }
2573
2685
  async prepareCreateInstructions(streamParams, extParams) {
2574
- const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateStreamInstructions(streamParams, extParams);
2686
+ const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateLinearStreamInstructions(streamParams, extParams);
2575
2687
  return { ixs, metadata, metadataPubKey };
2576
2688
  }
2577
2689
  async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
@@ -2605,7 +2717,10 @@ var SolanaStreamClient = class {
2605
2717
  floorPrice
2606
2718
  } = streamParams;
2607
2719
  const { isNative, sender, computeLimit, computePrice, metadataPubKeys } = extParams;
2608
- common.invariant(priceOracle || !oracleType || oracleType === "none", "Price oracle is required for the specified oracle type");
2720
+ common.invariant(
2721
+ priceOracle || !oracleType || oracleType === "none",
2722
+ "Price oracle is required for the specified oracle type"
2723
+ );
2609
2724
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2610
2725
  const recipientPublicKey = new web3_js.PublicKey(recipient);
2611
2726
  const mintPublicKey = isNative ? splToken.NATIVE_MINT : new web3_js.PublicKey(mint);
@@ -2616,7 +2731,7 @@ var SolanaStreamClient = class {
2616
2731
  if (!tokenProgramId) {
2617
2732
  tokenProgramId = (await common.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
2618
2733
  }
2619
- const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2734
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
2620
2735
  const streamflowProgramPublicKey = new web3_js.PublicKey(this.programId);
2621
2736
  const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
2622
2737
  const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
@@ -2663,7 +2778,7 @@ var SolanaStreamClient = class {
2663
2778
  partner: partnerPublicKey,
2664
2779
  recipient: recipientPublicKey,
2665
2780
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
2666
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
2781
+ feeOracle: this.feeOraclePublicKey,
2667
2782
  priceOracle: oracle,
2668
2783
  tokenProgram: tokenProgramId,
2669
2784
  streamflowProgram: this.programId
@@ -2678,7 +2793,7 @@ var SolanaStreamClient = class {
2678
2793
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
2679
2794
  * @returns Create stream instructions
2680
2795
  */
2681
- async prepareCreateStreamInstructions({
2796
+ async prepareCreateLinearStreamInstructions({
2682
2797
  recipient,
2683
2798
  tokenId: mint,
2684
2799
  start,
@@ -2719,7 +2834,7 @@ var SolanaStreamClient = class {
2719
2834
  const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2720
2835
  const recipientTokens = await common.ata(mintPublicKey, recipientPublicKey, tokenProgramId);
2721
2836
  const streamflowTreasuryTokens = await common.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2722
- const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2837
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
2723
2838
  const partnerTokens = await common.ata(mintPublicKey, partnerPublicKey, tokenProgramId);
2724
2839
  ixs.push(
2725
2840
  await createStreamInstruction(
@@ -2754,7 +2869,7 @@ var SolanaStreamClient = class {
2754
2869
  partner: partnerPublicKey,
2755
2870
  partnerTokens,
2756
2871
  mint: new web3_js.PublicKey(mint),
2757
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
2872
+ feeOracle: this.feeOraclePublicKey,
2758
2873
  rent: web3_js.SYSVAR_RENT_PUBKEY,
2759
2874
  timelockProgram: this.programId,
2760
2875
  tokenProgram: tokenProgramId,
@@ -2780,10 +2895,7 @@ var SolanaStreamClient = class {
2780
2895
  * @returns Create result
2781
2896
  */
2782
2897
  async createUnchecked(data, extParams) {
2783
- const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(
2784
- data,
2785
- extParams
2786
- );
2898
+ const { ixs, metadata, metadataPubKey } = await this.prepareCreateUncheckedInstructions(data, extParams);
2787
2899
  const { tx, hash, context } = await common.prepareTransaction(
2788
2900
  this.connection,
2789
2901
  ixs,
@@ -2846,7 +2958,7 @@ var SolanaStreamClient = class {
2846
2958
  );
2847
2959
  const { tokenProgramId } = await common.getMintAndProgram(this.connection, mintPublicKey);
2848
2960
  const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2849
- const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2961
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
2850
2962
  const ixs = common.prepareBaseInstructions(this.connection, {
2851
2963
  computePrice,
2852
2964
  computeLimit
@@ -2884,7 +2996,7 @@ var SolanaStreamClient = class {
2884
2996
  metadata: metadataPubKey,
2885
2997
  escrowTokens,
2886
2998
  mint: new web3_js.PublicKey(mint),
2887
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
2999
+ feeOracle: this.feeOraclePublicKey,
2888
3000
  rent: web3_js.SYSVAR_RENT_PUBKEY,
2889
3001
  timelockProgram: this.programId,
2890
3002
  tokenProgram: tokenProgramId,
@@ -2902,15 +3014,14 @@ var SolanaStreamClient = class {
2902
3014
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2903
3015
  * @returns Create multiple transaction instructions
2904
3016
  */
2905
- async buildCreateMultipleTransactionInstructions(data, extParams) {
3017
+ async buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions = true) {
2906
3018
  const { recipients, ...streamParams } = data;
2907
3019
  const { sender, metadataPubKeys: metadataPubKeysExt, isNative, customInstructions } = extParams;
2908
3020
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2909
3021
  const metadatas = [];
2910
3022
  const metadataToRecipient = {};
2911
3023
  const instructionsBatch = [];
2912
- const metadataPubKeys = metadataPubKeysExt || [];
2913
- const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : WITHDRAWOR_PUBLIC_KEY;
3024
+ const partnerPublicKey = data.partner ? new web3_js.PublicKey(data.partner) : sender.publicKey;
2914
3025
  const mintPublicKey = new web3_js.PublicKey(data.tokenId);
2915
3026
  if (recipients.length === 0) {
2916
3027
  throw new Error("Recipients array is empty!");
@@ -2919,14 +3030,16 @@ var SolanaStreamClient = class {
2919
3030
  const recipientData = recipients[i];
2920
3031
  const createStreamData = { ...streamParams, ...recipientData };
2921
3032
  const createStreamExtParams = {
2922
- metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
2923
- ...extParams
3033
+ ...extParams,
3034
+ metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
2924
3035
  };
2925
3036
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
2926
3037
  createStreamData,
2927
3038
  createStreamExtParams
2928
3039
  );
2929
- await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3040
+ if (applyCustomAfterInstructions) {
3041
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3042
+ }
2930
3043
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
2931
3044
  metadatas.push(metadataPubKey.toBase58());
2932
3045
  instructionsBatch.push({
@@ -2935,19 +3048,10 @@ var SolanaStreamClient = class {
2935
3048
  recipient: recipientData.recipient
2936
3049
  });
2937
3050
  }
2938
- const prepareInstructions = await this.getCreateATAInstructions(
2939
- [partnerPublicKey],
2940
- mintPublicKey,
2941
- sender,
2942
- true
2943
- );
3051
+ const prepareInstructions = await this.getCreateATAInstructions([partnerPublicKey], mintPublicKey, sender, true);
2944
3052
  if (isNative) {
2945
3053
  const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN3__default.default(0));
2946
- const nativeInstructions = await common.prepareWrappedAccount(
2947
- this.connection,
2948
- sender.publicKey,
2949
- totalDepositedAmount
2950
- );
3054
+ const nativeInstructions = await common.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
2951
3055
  prepareInstructions.push(...nativeInstructions);
2952
3056
  }
2953
3057
  return {
@@ -2983,9 +3087,9 @@ var SolanaStreamClient = class {
2983
3087
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2984
3088
  * @returns Multiple transaction information
2985
3089
  */
2986
- async buildCreateMultipleTransactions(data, extParams) {
3090
+ async buildCreateMultipleTransactions(data, extParams, applyCustomAfterInstructions = true) {
2987
3091
  const { sender } = extParams;
2988
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3092
+ const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions);
2989
3093
  const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
2990
3094
  const batch = [];
2991
3095
  for (const { ixs, metadata, recipient } of instructionsBatch) {
@@ -3016,7 +3120,7 @@ var SolanaStreamClient = class {
3016
3120
  if (!sender.publicKey) {
3017
3121
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3018
3122
  }
3019
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3123
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3020
3124
  const errors = [];
3021
3125
  const signatures = [];
3022
3126
  const metadataPubKeys = metadataPubKeysExt || [];
@@ -3081,7 +3185,7 @@ var SolanaStreamClient = class {
3081
3185
  if (!sender.publicKey) {
3082
3186
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3083
3187
  }
3084
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3188
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3085
3189
  const errors = [];
3086
3190
  const signatures = [];
3087
3191
  const batch = [];
@@ -3145,10 +3249,7 @@ var SolanaStreamClient = class {
3145
3249
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
3146
3250
  const { invoker, customInstructions } = extParams;
3147
3251
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3148
- const ixs = await this.prepareWithdrawInstructions(
3149
- { id, amount },
3150
- extParams
3151
- );
3252
+ const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
3152
3253
  const metadata = new web3_js.PublicKey(id);
3153
3254
  await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
3154
3255
  const { tx, hash, context } = await common.prepareTransaction(this.connection, ixs, invoker.publicKey);
@@ -3246,7 +3347,7 @@ var SolanaStreamClient = class {
3246
3347
  }
3247
3348
  const { sender: senderPublicKey } = decodeStream(account.data);
3248
3349
  const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3249
- const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelStreamInstructions(cancelData, extParams);
3350
+ const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3250
3351
  return ixs;
3251
3352
  }
3252
3353
  /**
@@ -3294,7 +3395,7 @@ var SolanaStreamClient = class {
3294
3395
  * @param {IPrepareStreamExt} extParams - Transaction configuration including invoker wallet, token account validation, and compute settings
3295
3396
  * @returns Transaction instructions
3296
3397
  */
3297
- async prepareCancelStreamInstructions({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3398
+ async prepareCancelLinearStream({ id }, { invoker, checkTokenAccounts, computePrice, computeLimit }) {
3298
3399
  common.assertHasPublicKey(invoker, "Invoker's PublicKey is not available, check passed wallet adapter!");
3299
3400
  const streamPublicKey = new web3_js.PublicKey(id);
3300
3401
  const escrowAcc = await this.connection.getAccountInfo(streamPublicKey);
@@ -3598,11 +3699,42 @@ var SolanaStreamClient = class {
3598
3699
  const accounts = await this.connection.getProgramAccounts(this.programId, {
3599
3700
  filters
3600
3701
  });
3702
+ const decoded = this.decodeStreamsFromAccounts(accounts);
3703
+ const alignedEntries = this.collectAlignedEntries(decoded);
3704
+ const alignedProxies = await this.fetchAlignedProxiesByEntries(alignedEntries);
3705
+ return this.mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies);
3706
+ }
3707
+ decodeStreamsFromAccounts(accounts) {
3601
3708
  return accounts.map(({ pubkey, account }) => ({
3602
- publicKey: pubkey,
3603
- account: new Contract(decodeStream(account.data))
3709
+ pubkey,
3710
+ stream: decodeStream(account.data)
3604
3711
  }));
3605
3712
  }
3713
+ collectAlignedEntries(decoded) {
3714
+ const entries = [];
3715
+ decoded.forEach(({ pubkey, stream }, index) => {
3716
+ if (this.isAlignedUnlock(pubkey, stream.sender)) {
3717
+ entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, pubkey) });
3718
+ }
3719
+ });
3720
+ return entries;
3721
+ }
3722
+ async fetchAlignedProxiesByEntries(aligned) {
3723
+ if (aligned.length === 0) return [];
3724
+ const res = await this.alignedProxyProgram.account.contract.fetchMultiple(aligned.map((a) => a.pda));
3725
+ return res;
3726
+ }
3727
+ mapDecodedToProgramAccounts(decoded, alignedEntries, alignedProxies) {
3728
+ return decoded.map(({ pubkey, stream }, idx) => {
3729
+ const alignedIdx = alignedEntries.findIndex((a) => a.index === idx);
3730
+ if (alignedIdx !== -1) {
3731
+ const alignedProxy = alignedProxies[alignedIdx];
3732
+ common.invariant(alignedProxy, "Couldn't get aligned proxy account info");
3733
+ return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
3734
+ }
3735
+ return { publicKey: pubkey, account: new Contract(stream) };
3736
+ });
3737
+ }
3606
3738
  /**
3607
3739
  * Attempts updating the stream auto withdrawal params and amount per period
3608
3740
  * @param {IUpdateData} data - Update parameters including stream ID and new settings
@@ -3642,17 +3774,26 @@ var SolanaStreamClient = class {
3642
3774
  const streamPublicKey = new web3_js.PublicKey(data.id);
3643
3775
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
3644
3776
  common.invariant(escrow, "Couldn't get account info");
3777
+ const { sender: senderPublicKey } = decodeStream(escrow.data);
3778
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, senderPublicKey);
3779
+ if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
3780
+ throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
3781
+ }
3645
3782
  const ixs = common.prepareBaseInstructions(this.connection, {
3646
3783
  computePrice,
3647
3784
  computeLimit
3648
3785
  });
3649
3786
  ixs.push(
3650
- await updateStreamInstruction(data, this.programId, {
3787
+ await (isAlignedUnlock ? this.alignedProxyProgram.methods.updateContract({
3788
+ transferableBySender: data.transferableBySender ?? null,
3789
+ transferableByRecipient: data.transferableByRecipient ?? null,
3790
+ cancelableBySender: data.cancelableBySender ?? null
3791
+ }).accounts({ sender: invoker.publicKey, streamMetadata: streamPublicKey, withdrawor: WITHDRAWOR_PUBLIC_KEY }).accountsPartial({ streamflowProgram: this.programId }).instruction() : updateStreamInstruction(data, this.programId, {
3651
3792
  authority: invoker.publicKey,
3652
3793
  metadata: streamPublicKey,
3653
3794
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3654
3795
  systemProgram: web3_js.SystemProgram.programId
3655
- })
3796
+ }))
3656
3797
  );
3657
3798
  return ixs;
3658
3799
  }
@@ -3662,35 +3803,47 @@ var SolanaStreamClient = class {
3662
3803
  * @returns Fees
3663
3804
  */
3664
3805
  async getFees({ address }) {
3665
- const [metadataPubKey] = web3_js.PublicKey.findProgramAddressSync(
3666
- [buffer.Buffer.from(FEES_METADATA_SEED)],
3667
- new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID)
3668
- );
3669
- const data = await this.connection.getAccountInfo(metadataPubKey);
3806
+ const data = await this.connection.getAccountInfo(this.feeOraclePublicKey);
3670
3807
  if (!data) {
3671
3808
  return null;
3672
3809
  }
3673
3810
  const partners = borsh__namespace.deserialize(PARTNERS_SCHEMA, data.data);
3674
- const filteredPartners = partners.filter((item) => new web3_js.PublicKey(item.pubkey).toString() === address);
3675
- if (filteredPartners.length === 0) {
3676
- return null;
3811
+ for (const partner of partners) {
3812
+ const partnerAddress = new web3_js.PublicKey(partner.pubkey).toString();
3813
+ if (partnerAddress === address) {
3814
+ return {
3815
+ creationFeeSol: Number(partner.creation_fee),
3816
+ autoClaimFeeSol: Number(partner.auto_claim_fee),
3817
+ streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
3818
+ partnerFee: 0
3819
+ };
3820
+ }
3677
3821
  }
3678
- return {
3679
- streamflowFee: Number(filteredPartners[0].strm_fee.toFixed(4)),
3680
- partnerFee: Number(filteredPartners[0].partner_fee.toFixed(4))
3681
- };
3822
+ return null;
3682
3823
  }
3683
3824
  /**
3684
3825
  * Gets default streamflow fee
3685
3826
  * @returns Default streamflow fee
3686
3827
  */
3687
3828
  async getDefaultStreamflowFee() {
3688
- return DEFAULT_STREAMFLOW_FEE;
3829
+ return (await this.getDefaultFees()).streamflowFee;
3830
+ }
3831
+ /**
3832
+ * Get all defaults fees applied by the protocol.
3833
+ *
3834
+ * Protocol will use fees set for WITHDRAWOR as default if they are set.
3835
+ */
3836
+ async getDefaultFees() {
3837
+ return await this.getFees({ address: WITHDRAWOR }) || {
3838
+ creationFeeSol: DEFAULT_CREATION_FEE_SOL,
3839
+ autoClaimFeeSol: DEFAULT_AUTO_CLAIM_FEE_SOL,
3840
+ streamflowFee: DEFAULT_STREAMFLOW_FEE,
3841
+ partnerFee: 0
3842
+ };
3689
3843
  }
3690
3844
  /**
3691
3845
  * Returns total fee percent, streamflow fees + partner fees
3692
3846
  * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3693
- * @param chainSpecificParams additional parameters required by chain client
3694
3847
  * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3695
3848
  */
3696
3849
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -3711,12 +3864,27 @@ var SolanaStreamClient = class {
3711
3864
  return extractSolanaErrorCode(err.toString() ?? "Unknown error!", logs);
3712
3865
  }
3713
3866
  /**
3714
- * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3715
- */
3867
+ * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA
3868
+ */
3716
3869
  isAlignedUnlock(streamPublicKey, senderPublicKey) {
3717
3870
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3718
3871
  return senderPublicKey.equals(pda);
3719
3872
  }
3873
+ async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
3874
+ const dataArray = Array.isArray(data) ? data : [data];
3875
+ const results = await Promise.all(
3876
+ dataArray.map((item, index) => this.buildCreateMultipleTransactionInstructions(item, extParams, index === 0))
3877
+ );
3878
+ return {
3879
+ instructionsBatch: results.flatMap((r) => r.instructionsBatch),
3880
+ metadatas: results.flatMap((r) => r.metadatas),
3881
+ prepareInstructions: results.flatMap((r) => r.prepareInstructions),
3882
+ metadataToRecipient: results.reduce(
3883
+ (acc, r) => Object.assign(acc, r.metadataToRecipient),
3884
+ {}
3885
+ )
3886
+ };
3887
+ }
3720
3888
  /**
3721
3889
  * Utility function to generate metadata for a Contract or return existing Pubkey
3722
3890
  */
@@ -4204,6 +4372,8 @@ exports.CONTRACT_SEED = CONTRACT_SEED;
4204
4372
  exports.CREATE_PARAMS_PADDING = CREATE_PARAMS_PADDING;
4205
4373
  exports.Contract = Contract;
4206
4374
  exports.ContractErrorCode = ContractErrorCode;
4375
+ exports.DEFAULT_AUTO_CLAIM_FEE_SOL = DEFAULT_AUTO_CLAIM_FEE_SOL;
4376
+ exports.DEFAULT_CREATION_FEE_SOL = DEFAULT_CREATION_FEE_SOL;
4207
4377
  exports.DEFAULT_STREAMFLOW_FEE = DEFAULT_STREAMFLOW_FEE;
4208
4378
  exports.ESCROW_SEED = ESCROW_SEED;
4209
4379
  exports.FEES_METADATA_SEED = FEES_METADATA_SEED;
@@ -4228,6 +4398,7 @@ exports.StreamType = StreamType;
4228
4398
  exports.TEST_ORACLE_DISCRIMINATOR = TEST_ORACLE_DISCRIMINATOR;
4229
4399
  exports.TEST_ORACLE_SEED = TEST_ORACLE_SEED;
4230
4400
  exports.TX_FINALITY_CONFIRMED = TX_FINALITY_CONFIRMED;
4401
+ exports.WITHDRAWOR = WITHDRAWOR;
4231
4402
  exports.WITHDRAWOR_PUBLIC_KEY = WITHDRAWOR_PUBLIC_KEY;
4232
4403
  exports.WITHDRAW_AVAILABLE_AMOUNT = WITHDRAW_AVAILABLE_AMOUNT;
4233
4404
  exports.buildStreamType = buildStreamType;
@@ -4247,7 +4418,6 @@ exports.isAligned = isAligned;
4247
4418
  exports.isCliffCloseToDepositedAmount = isCliffCloseToDepositedAmount;
4248
4419
  exports.isCreateAlignedStreamData = isCreateAlignedStreamData;
4249
4420
  exports.isDynamicLock = isDynamicLock;
4250
- exports.isPayment = isPayment;
4251
4421
  exports.isTokenLock = isTokenLock;
4252
4422
  exports.isVesting = isVesting;
4253
4423
  exports.sendAndConfirmStreamRawTransaction = sendAndConfirmStreamRawTransaction;