@streamflow/stream 10.0.0-alpha.p313.fe3720a → 10.0.0

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
@@ -19,6 +19,10 @@ You can also `getOne` stream and `get` multiple streams.
19
19
  - [Create a Token Lock](#create-a-token-lock)
20
20
  - [Streamflow app token lock criteria](#streamflow-app-token-lock-criteria)
21
21
  - [Example for creating a token lock](#example-for-creating-a-token-lock)
22
+ - [Create a Price-based Stream (Aligned)](#create-a-price-based-stream-aligned)
23
+ - [Example for creating a Price-based Vesting Stream](#example-for-creating-a-price-based-vesting-stream)
24
+ - [Create a Price-based Lock](#create-a-price-based-lock)
25
+ - [Fetching Aligned Stream Data](#fetching-aligned-stream-data)
22
26
  - [General Stream creation](#general-stream-creation)
23
27
  - [Create multiple streams at once](#create-multiple-streams-at-once)
24
28
  - [Identifying created Streams](#identifying-created-streams)
@@ -72,7 +76,7 @@ import { StreamflowSolana } from "@streamflow/stream";
72
76
  const solanaClient = new StreamflowSolana.SolanaStreamClient(
73
77
  "https://api.mainnet-beta.solana.com"
74
78
  );
75
-
79
+ ```
76
80
 
77
81
  ## Universal parameters
78
82
 
@@ -214,6 +218,147 @@ try {
214
218
  const { ixs } = await client.prepareCreateStreamInstructions(createTokenLockParams, solanaCreateParams)
215
219
  ```
216
220
 
221
+ ## Create a Price-based Stream (Aligned)
222
+
223
+ Price-based Streams (also known as Aligned or Dynamic Streams) are a type of Stream where the unlock rate dynamically adjusts based on the price of a token as reported by a price oracle. The unlock percentage scales between `minPercentage` and `maxPercentage` based on whether the current price is at or below `minPrice` or at or above `maxPrice`. This allows for vesting schedules that accelerate or decelerate based on token price performance.
224
+
225
+ Price-based Streams require all the standard stream parameters plus additional price-based configuration parameters. The unlock rate is recalculated periodically based on the oracle price, making the vesting schedule responsive to market conditions.
226
+
227
+ Streamflow's custom oracles can be fetched through the Oracle API
228
+ - Endpoint -> `https://oracle-api-public.streamflow.finance/oracle/{mint}`
229
+ - [API Docs](https://oracle-api-public.streamflow.finance/docs)
230
+
231
+ For more details creating a Stream with arbitrary configuration see [General Stream creation](#general-stream-creation).
232
+
233
+ ### Example for creating a Price-based Vesting Stream
234
+
235
+ The following code will create a Price-based Stream that adjusts its unlock rate based on token price. When the price is at or below `minPrice`, it unlocks at `minPercentage` rate. When the price is at or above `maxPrice`, it unlocks at `maxPercentage` rate. For prices between these bounds, the unlock rate scales proportionally.
236
+
237
+ ```javascript
238
+ const tokenDecimals = 9;
239
+ const totalAmount = getBN(1000, tokenDecimals);
240
+ const cliffAmount = getBN(100, tokenDecimals);
241
+
242
+ const day = 60 * 60 * 24; // in seconds
243
+ const twoWeeks = day * 14;
244
+
245
+ const mint = "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK"
246
+ const remainingAmount = totalAmount.sub(cliffAmount);
247
+ const baseAmountPerPeriod = remainingAmount.divn(twoWeeks);
248
+
249
+ const priceOracleAddress = await fetch(`https://oracle-api.streamflow.finance/oracle/${mint}`).then(res => res.json()).then(data => data.address);
250
+
251
+ const createPriceBasedParams: Types.ICreateAlignedStreamData = {
252
+ recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address.
253
+ tokenId: mint, // Token mint address.
254
+ start: 1643363040, // Timestamp (in seconds) when the stream starts.
255
+ amount: totalAmount,
256
+ period: day, // 1 day for daily unlock updates
257
+ cliff: 1643363040, // Cliff timestamp in seconds.
258
+ cliffAmount: cliffAmount, // Amount unlocked at the "cliff" timestamp.
259
+ amountPerPeriod: baseAmountPerPeriod, // Base release rate (will be adjusted based on price).
260
+ name: "Price-based Vesting for Jane Doe.", // The stream name or subject.
261
+ transferableBySender: false, // not possible for aligned streams
262
+ automaticWithdrawal: false, // not possible for aligned streams
263
+ // Price-based configuration parameters - NOTE: all of these must be present in the creation order for the created Stream to be price-based
264
+ minPrice: 0.05, // Minimum price threshold. If current price <= minPrice, minPercentage is used.
265
+ maxPrice: 1.0, // Maximum price threshold. If current price >= maxPrice, maxPercentage is used.
266
+ minPercentage: 1, // Minimum unlock percentage (in basis points, e.g., 1 = 0.01%). Used when price <= minPrice.
267
+ maxPercentage: 1000, // Maximum unlock percentage (in basis points, e.g., 1000 = 10%). Used when price >= maxPrice.
268
+ // If either of these are omitted or oracleType is set to "none" the resulting Stream will behave like a regular Stream
269
+ oracleType: "test", // "test" is passed if you are using Streamflow's price oracles, you can also pass "pyth" if you are passing a Pyth price oracle to priceOracle
270
+ priceOracle: priceOracleAddress, // Address of the price oracle, either a Streamflow oracle address, or a Pyth oracle address.
271
+ skipInitial: false, // [optional] Whether to skip initial unlock amount update when the stream starts. Defaults to false.
272
+ tickSize: 1, // [optional] Tick size for percentage calculations when price is between minPrice and maxPrice. Defaults to 1.
273
+ };
274
+
275
+ try {
276
+ const { ixs, tx, metadata } = await client.create(createPriceBasedParams, solanaCreateParams);
277
+ } catch (exception) {
278
+ }
279
+
280
+ const { ixs } = await client.prepareCreateStreamInstructions(createPriceBasedParams, solanaCreateParams)
281
+ ```
282
+ ## Create a Price-based Lock
283
+
284
+ You can also create a Stream that behaves similar to a token Lock and unlocks at a specific price. There are some technical limitations that cause a small portion of the tokens to be unlocked over time that depends on the contract amount and number of decimals, but for most cases the time it would take for the whole contract to be unlocked would be measured in decades or even hundreds of years. You can achieve this with the following settings:
285
+
286
+ ```javascript
287
+ const targetPrice = 100; // Price at which you want tokens to unlock
288
+ const minPrice = targetPrice - 1;
289
+ const maxPrice = targetPrice;
290
+ const minPercentage = 0;
291
+ const maxPercentage = 100;
292
+ const totalAmount = new BN(1000000);
293
+ const amountPerPeriod = totalAmount;
294
+ const cliffAmount = new BN(0); // No cliff for price-based lock
295
+
296
+ const createPriceBasedParams: Types.ICreateAlignedStreamData = {
297
+ recipient: "4ih00075bKjVg000000tLdk4w42NyG3Mv0000dc0M00", // Recipient address.
298
+ tokenId: mint, // Token mint address.
299
+ start: 1643363040, // Timestamp (in seconds) when the stream starts.
300
+ amount: totalAmount,
301
+ period: 30, // 30 seconds so in case the target price is reached, the oracle has 30 seconds to fetch the price and update the contract release rate
302
+ cliff: 1643363040, // Cliff timestamp in seconds (should match start for price-based lock).
303
+ cliffAmount: cliffAmount, // Amount unlocked at the "cliff" timestamp.
304
+ amountPerPeriod: amountPerPeriod, // Will be updated to 1 as long as price below targetPrice,
305
+ // meaning that tokens are unlocked at rate of 1 smallest denominator of the token per each period (if token has 9 decimals that is 0.000000001 token every 30 seconds)
306
+ name: "Price-based Lock for Jane Doe.",
307
+ transferableBySender: false, // not possible for aligned streams
308
+ automaticWithdrawal: false, // not possible for aligned streams
309
+ // Price-based configuration parameters - NOTE: all of these must be present in the creation order for the created Stream to be price-based
310
+ minPrice, // Minimum price threshold. If current price <= minPrice, minPercentage is used.
311
+ maxPrice, // Maximum price threshold. If current price >= maxPrice, maxPercentage is used.
312
+ minPercentage, // Minimum unlock percentage (in basis points, e.g., 1 = 0.01%). Used when price <= minPrice.
313
+ maxPercentage, // Maximum unlock percentage (in basis points, e.g., 1000 = 10%). Used when price >= maxPrice.
314
+ // If either of these are omitted or oracleType is set to "none" the resulting Stream will behave like a regular Stream
315
+ oracleType: "test", // "test" is passed if you are using Streamflow's price oracles, you can also pass "pyth" if you are passing a Pyth price oracle to priceOracle
316
+ priceOracle: priceOracleAddress, // Address of the price oracle, either a Streamflow oracle address, or a Pyth oracle address.
317
+ skipInitial: false, // In this case it should not be set to true
318
+ // These parameters make sense for a price-based token lock
319
+ floorPrice: 20, // lower bound targetPrice - at or below this price tokens will be unlocked
320
+ expiryTime: 1643364640, // If the targetPrice has not been reached by this point in time, the tokens will be unlocked
321
+ expiryPercentage: maxPercentage, // The percentage unlock rate of tokens after expiryTime, it should be maxPercentage or 100
322
+
323
+ };
324
+ ```
325
+
326
+ ### Fetching Aligned Stream Data
327
+
328
+ When you fetch a price-based stream using `getOne()`, `get()` or `searchStreams()`, it automatically returns an `AlignedContract` instance if the stream is price-based. You can check if a stream is aligned and access its price-based properties:
329
+
330
+ ```javascript
331
+ import { isAligned, getNumberFromBN } from "@streamflow/stream";
332
+
333
+ const tokenDecimals = 9; // Token decimals for the stream's token
334
+
335
+ const stream = await client.getOne({
336
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
337
+ });
338
+
339
+ // Check if the stream is price-based (aligned)
340
+ if (isAligned(stream)) {
341
+ console.log("Min Price:", stream.minPrice);
342
+ console.log("Max Price:", stream.maxPrice);
343
+ console.log("Min Percentage:", stream.minPercentage);
344
+ console.log("Max Percentage:", stream.maxPercentage);
345
+ console.log("Tick Size:", stream.tickSize);
346
+ console.log("Oracle Type:", stream.oracleType); // "test", "pyth", or "none"
347
+ console.log("Price Oracle Address:", stream.priceOracle);
348
+ console.log("Initial Price:", stream.initialPrice);
349
+ console.log("Last Price:", stream.lastPrice);
350
+ console.log("Last Amount Update Time:", stream.lastAmountUpdateTime);
351
+ console.log("Initial Amount Per Period:", getNumberFromBN(stream.initialAmountPerPeriod, tokenDecimals));
352
+ console.log("Expiry Time:", stream.expiryTime);
353
+ console.log("Expiry Percentage:", stream.expiryPercentage);
354
+ console.log("Floor Price:", stream.floorPrice);
355
+ console.log("Proxy Address:", stream.proxyAddress);
356
+ }
357
+ ```
358
+
359
+ All standard stream properties (like `amount`, `withdrawnAmount`, `unlocked()`, etc.) are also available on aligned streams, as `AlignedContract` extends the base `Contract` class.
360
+
361
+ > **Note:** Price-based Streams use a separate proxy program (Aligned Unlocks) to manage the dynamic unlock logic. The unlock rate is recalculated periodically based on the oracle price. Automatic withdrawal and rate updates are not supported for price-based streams.
217
362
 
218
363
  ## General Stream creation
219
364
 
@@ -63,7 +63,7 @@ var isVesting = (streamData) => {
63
63
  return !isCliffCloseToDepositedAmount(streamData) && !isDynamicLock(streamData.minPrice, streamData.maxPrice, streamData.minPercentage, streamData.maxPercentage);
64
64
  };
65
65
  var isAligned = (stream) => {
66
- return "minPrice" in stream && "maxPrice" in stream && "minPercentage" in stream && "maxPercentage" in stream;
66
+ return stream.isAligned;
67
67
  };
68
68
  var isCreateAlignedStreamData = (obj) => {
69
69
  return "minPrice" in obj && "maxPrice" in obj && "minPercentage" in obj && "maxPercentage" in obj;
@@ -251,25 +251,40 @@ var ALIGNED_UNLOCKS_PROGRAM_ID = {
251
251
  [common.ICluster.Testnet]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
252
252
  [common.ICluster.Local]: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH"
253
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
+ };
254
266
  var ALIGNED_COMPUTE_LIMIT = 3e5;
255
267
  var CONTRACT_DISCRIMINATOR = [172, 138, 115, 242, 121, 67, 183, 26];
256
268
  var TEST_ORACLE_DISCRIMINATOR = [198, 49, 63, 134, 232, 251, 168, 28];
257
269
  var CONTRACT_SEED = buffer.Buffer.from("contract", "utf-8");
258
270
  var ESCROW_SEED = buffer.Buffer.from("strm", "utf-8");
259
271
  var TEST_ORACLE_SEED = buffer.Buffer.from("test-oracle", "utf-8");
260
- var PARTNER_ORACLE_PROGRAM_ID = "pardpVtPjC8nLj1Dwncew62mUzfChdCX1EaoZe8oCAa";
261
272
  var STREAMFLOW_TREASURY_PUBLIC_KEY = new web3_js.PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
262
- var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey("wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u");
263
- var FEE_ORACLE_PUBLIC_KEY = new web3_js.PublicKey("B743wFVk2pCYhV91cn287e1xY7f1vt4gdY48hhNiuQmT");
273
+ var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
274
+ var WITHDRAWOR_PUBLIC_KEY = new web3_js.PublicKey(WITHDRAWOR);
264
275
  var AIRDROP_TEST_TOKEN = "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj";
265
276
  var FEES_METADATA_SEED = buffer.Buffer.from("strm_fees");
266
- 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;
267
280
  var AIRDROP_AMOUNT = 1;
268
281
  var PARTNER_SCHEMA = {
269
282
  struct: {
270
283
  pubkey: { array: { type: "u8", len: 32 } },
271
- partner_fee: "f32",
272
- strm_fee: "f32"
284
+ creation_fee: "u32",
285
+ auto_claim_fee: "u32",
286
+ token_fee_percent: "f32",
287
+ buffer: { array: { type: "u8", len: 16 } }
273
288
  }
274
289
  };
275
290
  var PARTNERS_SCHEMA = { array: { type: PARTNER_SCHEMA } };
@@ -2522,6 +2537,8 @@ var SolanaStreamClient = class {
2522
2537
  this.commitment = commitment;
2523
2538
  this.connection = new web3_js.Connection(optionsOrClusterUrl, this.commitment);
2524
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]);
2525
2542
  this.schedulingParams = {
2526
2543
  sendThrottler: sendThrottler ?? common.buildSendThrottler(sendRate)
2527
2544
  };
@@ -2536,6 +2553,8 @@ var SolanaStreamClient = class {
2536
2553
  this.commitment = commitment2;
2537
2554
  this.connection = new web3_js.Connection(clusterUrl, this.commitment);
2538
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]);
2539
2558
  const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : void 0;
2540
2559
  const sendThrottler2 = !sendScheduler ? common.buildSendThrottler(1) : "sendRate" in sendScheduler ? common.buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval) : sendScheduler;
2541
2560
  this.schedulingParams = {
@@ -2576,7 +2595,7 @@ var SolanaStreamClient = class {
2576
2595
  const { partner, amount, tokenProgramId } = data;
2577
2596
  const { isNative, sender, customInstructions } = extParams;
2578
2597
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
2579
- const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2598
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
2580
2599
  const mintPublicKey = new web3_js.PublicKey(data.tokenId);
2581
2600
  const ixs = await this.getCreateATAInstructions(
2582
2601
  [partnerPublicKey],
@@ -2712,7 +2731,7 @@ var SolanaStreamClient = class {
2712
2731
  if (!tokenProgramId) {
2713
2732
  tokenProgramId = (await common.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
2714
2733
  }
2715
- const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2734
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
2716
2735
  const streamflowProgramPublicKey = new web3_js.PublicKey(this.programId);
2717
2736
  const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
2718
2737
  const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
@@ -2759,7 +2778,7 @@ var SolanaStreamClient = class {
2759
2778
  partner: partnerPublicKey,
2760
2779
  recipient: recipientPublicKey,
2761
2780
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
2762
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
2781
+ feeOracle: this.feeOraclePublicKey,
2763
2782
  priceOracle: oracle,
2764
2783
  tokenProgram: tokenProgramId,
2765
2784
  streamflowProgram: this.programId
@@ -2815,7 +2834,7 @@ var SolanaStreamClient = class {
2815
2834
  const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2816
2835
  const recipientTokens = await common.ata(mintPublicKey, recipientPublicKey, tokenProgramId);
2817
2836
  const streamflowTreasuryTokens = await common.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
2818
- const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2837
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
2819
2838
  const partnerTokens = await common.ata(mintPublicKey, partnerPublicKey, tokenProgramId);
2820
2839
  ixs.push(
2821
2840
  await createStreamInstruction(
@@ -2850,7 +2869,7 @@ var SolanaStreamClient = class {
2850
2869
  partner: partnerPublicKey,
2851
2870
  partnerTokens,
2852
2871
  mint: new web3_js.PublicKey(mint),
2853
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
2872
+ feeOracle: this.feeOraclePublicKey,
2854
2873
  rent: web3_js.SYSVAR_RENT_PUBKEY,
2855
2874
  timelockProgram: this.programId,
2856
2875
  tokenProgram: tokenProgramId,
@@ -2939,7 +2958,7 @@ var SolanaStreamClient = class {
2939
2958
  );
2940
2959
  const { tokenProgramId } = await common.getMintAndProgram(this.connection, mintPublicKey);
2941
2960
  const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
2942
- const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
2961
+ const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
2943
2962
  const ixs = common.prepareBaseInstructions(this.connection, {
2944
2963
  computePrice,
2945
2964
  computeLimit
@@ -2977,7 +2996,7 @@ var SolanaStreamClient = class {
2977
2996
  metadata: metadataPubKey,
2978
2997
  escrowTokens,
2979
2998
  mint: new web3_js.PublicKey(mint),
2980
- feeOracle: FEE_ORACLE_PUBLIC_KEY,
2999
+ feeOracle: this.feeOraclePublicKey,
2981
3000
  rent: web3_js.SYSVAR_RENT_PUBKEY,
2982
3001
  timelockProgram: this.programId,
2983
3002
  tokenProgram: tokenProgramId,
@@ -2995,15 +3014,14 @@ var SolanaStreamClient = class {
2995
3014
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
2996
3015
  * @returns Create multiple transaction instructions
2997
3016
  */
2998
- async buildCreateMultipleTransactionInstructions(data, extParams) {
3017
+ async buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions = true) {
2999
3018
  const { recipients, ...streamParams } = data;
3000
3019
  const { sender, metadataPubKeys: metadataPubKeysExt, isNative, customInstructions } = extParams;
3001
3020
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
3002
3021
  const metadatas = [];
3003
3022
  const metadataToRecipient = {};
3004
3023
  const instructionsBatch = [];
3005
- const metadataPubKeys = metadataPubKeysExt || [];
3006
- 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;
3007
3025
  const mintPublicKey = new web3_js.PublicKey(data.tokenId);
3008
3026
  if (recipients.length === 0) {
3009
3027
  throw new Error("Recipients array is empty!");
@@ -3012,14 +3030,16 @@ var SolanaStreamClient = class {
3012
3030
  const recipientData = recipients[i];
3013
3031
  const createStreamData = { ...streamParams, ...recipientData };
3014
3032
  const createStreamExtParams = {
3015
- metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : void 0,
3016
- ...extParams
3033
+ ...extParams,
3034
+ metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
3017
3035
  };
3018
3036
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
3019
3037
  createStreamData,
3020
3038
  createStreamExtParams
3021
3039
  );
3022
- await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3040
+ if (applyCustomAfterInstructions) {
3041
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
3042
+ }
3023
3043
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
3024
3044
  metadatas.push(metadataPubKey.toBase58());
3025
3045
  instructionsBatch.push({
@@ -3067,9 +3087,9 @@ var SolanaStreamClient = class {
3067
3087
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender public key, native token handling, and custom instructions
3068
3088
  * @returns Multiple transaction information
3069
3089
  */
3070
- async buildCreateMultipleTransactions(data, extParams) {
3090
+ async buildCreateMultipleTransactions(data, extParams, applyCustomAfterInstructions = true) {
3071
3091
  const { sender } = extParams;
3072
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3092
+ const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams, applyCustomAfterInstructions);
3073
3093
  const { value: hash, context } = await this.connection.getLatestBlockhashAndContext();
3074
3094
  const batch = [];
3075
3095
  for (const { ixs, metadata, recipient } of instructionsBatch) {
@@ -3100,7 +3120,7 @@ var SolanaStreamClient = class {
3100
3120
  if (!sender.publicKey) {
3101
3121
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3102
3122
  }
3103
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3123
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3104
3124
  const errors = [];
3105
3125
  const signatures = [];
3106
3126
  const metadataPubKeys = metadataPubKeysExt || [];
@@ -3165,7 +3185,7 @@ var SolanaStreamClient = class {
3165
3185
  if (!sender.publicKey) {
3166
3186
  throw new Error("Sender's PublicKey is not available, check passed wallet adapter!");
3167
3187
  }
3168
- const { instructionsBatch, metadatas, metadataToRecipient, prepareInstructions } = await this.buildCreateMultipleTransactionInstructions(data, extParams);
3188
+ const { instructionsBatch, metadatas, prepareInstructions, metadataToRecipient } = await this.flatBuildCreateMultipleTransactionInstructions(data, extParams);
3169
3189
  const errors = [];
3170
3190
  const signatures = [];
3171
3191
  const batch = [];
@@ -3679,20 +3699,41 @@ var SolanaStreamClient = class {
3679
3699
  const accounts = await this.connection.getProgramAccounts(this.programId, {
3680
3700
  filters
3681
3701
  });
3682
- const mapped = await Promise.all(
3683
- accounts.map(async ({ pubkey, account }) => {
3684
- const stream = decodeStream(account.data);
3685
- if (this.isAlignedUnlock(pubkey, stream.sender)) {
3686
- const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
3687
- deriveContractPDA(this.alignedProxyProgram.programId, pubkey)
3688
- );
3689
- common.invariant(alignedProxy, "Couldn't get aligned proxy account info");
3690
- return { publicKey: pubkey, account: new AlignedContract(stream, alignedProxy) };
3691
- }
3692
- return { publicKey: pubkey, account: new Contract(stream) };
3693
- })
3694
- );
3695
- return mapped;
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) {
3708
+ return accounts.map(({ pubkey, account }) => ({
3709
+ pubkey,
3710
+ stream: decodeStream(account.data)
3711
+ }));
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
+ });
3696
3737
  }
3697
3738
  /**
3698
3739
  * Attempts updating the stream auto withdrawal params and amount per period
@@ -3762,35 +3803,47 @@ var SolanaStreamClient = class {
3762
3803
  * @returns Fees
3763
3804
  */
3764
3805
  async getFees({ address }) {
3765
- const [metadataPubKey] = web3_js.PublicKey.findProgramAddressSync(
3766
- [buffer.Buffer.from(FEES_METADATA_SEED)],
3767
- new web3_js.PublicKey(PARTNER_ORACLE_PROGRAM_ID)
3768
- );
3769
- const data = await this.connection.getAccountInfo(metadataPubKey);
3806
+ const data = await this.connection.getAccountInfo(this.feeOraclePublicKey);
3770
3807
  if (!data) {
3771
3808
  return null;
3772
3809
  }
3773
3810
  const partners = borsh__namespace.deserialize(PARTNERS_SCHEMA, data.data);
3774
- const filteredPartners = partners.filter((item) => new web3_js.PublicKey(item.pubkey).toString() === address);
3775
- if (filteredPartners.length === 0) {
3776
- 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
+ }
3777
3821
  }
3778
- return {
3779
- streamflowFee: Number(filteredPartners[0].strm_fee.toFixed(4)),
3780
- partnerFee: Number(filteredPartners[0].partner_fee.toFixed(4))
3781
- };
3822
+ return null;
3782
3823
  }
3783
3824
  /**
3784
3825
  * Gets default streamflow fee
3785
3826
  * @returns Default streamflow fee
3786
3827
  */
3787
3828
  async getDefaultStreamflowFee() {
3788
- 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
+ };
3789
3843
  }
3790
3844
  /**
3791
3845
  * Returns total fee percent, streamflow fees + partner fees
3792
3846
  * @param getFeesData structure with address for which we need to derive fee, either sender or partner usually
3793
- * @param chainSpecificParams additional parameters required by chain client
3794
3847
  * @returns fee as floating number, so if fee is 0.99%, it will return 0.99
3795
3848
  */
3796
3849
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -3817,6 +3870,21 @@ var SolanaStreamClient = class {
3817
3870
  const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3818
3871
  return senderPublicKey.equals(pda);
3819
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
+ }
3820
3888
  /**
3821
3889
  * Utility function to generate metadata for a Contract or return existing Pubkey
3822
3890
  */
@@ -4304,6 +4372,8 @@ exports.CONTRACT_SEED = CONTRACT_SEED;
4304
4372
  exports.CREATE_PARAMS_PADDING = CREATE_PARAMS_PADDING;
4305
4373
  exports.Contract = Contract;
4306
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;
4307
4377
  exports.DEFAULT_STREAMFLOW_FEE = DEFAULT_STREAMFLOW_FEE;
4308
4378
  exports.ESCROW_SEED = ESCROW_SEED;
4309
4379
  exports.FEES_METADATA_SEED = FEES_METADATA_SEED;
@@ -4328,6 +4398,7 @@ exports.StreamType = StreamType;
4328
4398
  exports.TEST_ORACLE_DISCRIMINATOR = TEST_ORACLE_DISCRIMINATOR;
4329
4399
  exports.TEST_ORACLE_SEED = TEST_ORACLE_SEED;
4330
4400
  exports.TX_FINALITY_CONFIRMED = TX_FINALITY_CONFIRMED;
4401
+ exports.WITHDRAWOR = WITHDRAWOR;
4331
4402
  exports.WITHDRAWOR_PUBLIC_KEY = WITHDRAWOR_PUBLIC_KEY;
4332
4403
  exports.WITHDRAW_AVAILABLE_AMOUNT = WITHDRAW_AVAILABLE_AMOUNT;
4333
4404
  exports.buildStreamType = buildStreamType;