@streamflow/stream 13.3.1 → 13.5.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.
@@ -1,4 +1,4 @@
1
- export { k as BatchCreationItem, l as BatchExecuteResult, m as BatchInstructionResult, p as BuildTransactionFn, q as BuildTransactionOptions, r as BuiltTransaction, C as CancelFn, w as CreateBatchFn, x as CreateFn, y as CreateInstructionResult, F as Env, G as ExecuteBatchFn, H as ExecuteBatchSequentialFn, J as ExecuteFn, K as ExecutionEnv, T as ICreateLockBatchParams, U as ICreateLockParams, a0 as ICreateVestingBatchParams, a1 as ICreateVestingParams, a8 as ILockBatchRecipient, aj as IVestingBatchRecipient, am as InstructionResult, an as Invoker, aq as NativeOptions, at as SignFn, az as TopupFn, aB as TransferFn, aC as UpdateFn, aE as WithdrawFn, aF as buildLockBatchParams, aG as buildLockParams, aH as buildTransaction, aI as buildVestingBatchParams, aJ as buildVestingParams, aK as cancel, aL as computeAmountPerPeriod, aM as create, aN as createBatch, aO as createClientFromEnv, aP as createLock, aQ as createLockBatch, aR as createVesting, aS as createVestingBatch, aT as execute, aU as executeBatch, aV as executeBatchSequential, aW as resolveConnection, aX as resolveDuration, aY as sign, aZ as topup, a_ as transfer, a$ as update, b0 as withdraw } from '../../index-aMPWxsk6.js';
1
+ export { l as BatchCreationItem, m as BatchExecuteResult, n as BatchInstructionResult, q as BuildTransactionFn, r as BuildTransactionOptions, s as BuiltTransaction, C as CancelFn, x as CreateBatchFn, y as CreateFn, z as CreateInstructionResult, G as Env, H as ExecuteBatchFn, J as ExecuteBatchSequentialFn, K as ExecuteFn, L as ExecutionEnv, T as ICreateLockBatchParams, U as ICreateLockParams, a0 as ICreateVestingBatchParams, a1 as ICreateVestingParams, a8 as ILockBatchRecipient, aj as IVestingBatchRecipient, am as InstructionResult, an as Invoker, aq as NativeOptions, at as SignFn, az as TopupFn, aB as TransferFn, aC as UpdateFn, aE as WithdrawFn, aF as buildLockBatchParams, aG as buildLockParams, aH as buildTransaction, aI as buildVestingBatchParams, aJ as buildVestingParams, aK as cancel, aL as computeAmountPerPeriod, aM as create, aN as createBatch, aO as createClientFromEnv, aP as createLock, aQ as createLockBatch, aR as createVesting, aS as createVestingBatch, aT as execute, aU as executeBatch, aV as executeBatchSequential, aW as resolveConnection, aX as resolveDuration, aY as sign, aZ as topup, a_ as transfer, a$ as update, b0 as withdraw } from '../../index-FDwxtRYV.js';
2
2
  import '@solana/wallet-adapter-base';
3
3
  import '@solana/web3.js';
4
4
  import '@streamflow/common';
@@ -1,8 +1,8 @@
1
1
  import { PublicKey, Connection, Keypair, SystemProgram, TransactionMessage, VersionedTransaction, TransactionInstruction, SYSVAR_RENT_PUBKEY } from '@solana/web3.js';
2
- import { ICluster, prepareBaseInstructions, prepareTransaction, executeTransaction, executeMultipleTransactions, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, signAndExecuteTransaction, invariant, getMintAndProgram, ata, getBN, createVersionedTransaction, getMultipleAccountsInfoBatched, getProgramAccounts, isDev, checkOrCreateAtaBatch, pk, isSignerKeypair, isSignerWallet, getNumberFromBN } from '@streamflow/common';
2
+ import { ICluster, prepareBaseInstructions, prepareTransaction, executeTransaction, executeMultipleTransactions, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, signAndExecuteTransaction, invariant, getMintAndProgram, ata, getBN, createVersionedTransaction, getMultipleAccountsInfoBatched, getProgramAccounts, pk, isDev, checkOrCreateAtaBatch, isSignerKeypair, isSignerWallet, getNumberFromBN } from '@streamflow/common';
3
3
  import BN3 from 'bn.js';
4
4
  import bs58 from 'bs58';
5
- import { Buffer } from 'buffer';
5
+ import { Buffer as Buffer$1 } from 'buffer';
6
6
  import { NATIVE_MINT, TOKEN_2022_PROGRAM_ID, getTransferHook, addExtraAccountMetasForExecute, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
7
7
  import * as borsh from 'borsh';
8
8
  import { Program } from '@coral-xyz/anchor';
@@ -54,6 +54,24 @@ var isTokenLock = (streamData) => {
54
54
  }
55
55
  return false;
56
56
  };
57
+ var isStrictTokenLockCreate = (data, now = Math.floor(Date.now() / 1e3)) => {
58
+ if (data.canTopup || data.automaticWithdrawal || data.cancelableBySender || data.cancelableByRecipient || data.transferableBySender) {
59
+ return false;
60
+ }
61
+ if (!isCliffCloseToDepositedAmount({ depositedAmount: data.amount, cliffAmount: data.cliffAmount })) {
62
+ return false;
63
+ }
64
+ if (data.cliffAmount.gt(data.amount) || data.amountPerPeriod.isZero()) {
65
+ return false;
66
+ }
67
+ const remaining = data.amount.sub(data.cliffAmount);
68
+ const periodsLeft = remaining.add(data.amountPerPeriod).subn(1).div(data.amountPerPeriod);
69
+ const cliff = data.start === 0 ? now : data.cliff;
70
+ const unlockStart = cliff > 0 ? cliff : data.start;
71
+ const end = new BN3(unlockStart).add(periodsLeft.mul(new BN3(data.period)));
72
+ const cliffEndGap = end.sub(new BN3(cliff));
73
+ return !cliffEndGap.isNeg() && cliffEndGap.lten(MAX_CLIFF_END_GAP_SECONDS);
74
+ };
57
75
  var buildStreamType = (streamData) => {
58
76
  if (isTokenLock(streamData)) {
59
77
  return "lock" /* Lock */;
@@ -197,15 +215,15 @@ var FEE_ORACLE_PUBLIC_KEY = {
197
215
  [ICluster.Local]: "Aa2JJfFzUN3V54DXUHRBJowFw416xfZHpPk9DaNy3iYs"
198
216
  };
199
217
  var ALIGNED_COMPUTE_LIMIT = 3e5;
200
- var CONTRACT_SEED = Buffer.from("contract", "utf-8");
201
- var ESCROW_SEED = Buffer.from("strm", "utf-8");
202
- var TEST_ORACLE_SEED = Buffer.from("test-oracle", "utf-8");
203
- var METADATA_SEED = Buffer.from("strm-met", "utf-8");
204
- Buffer.from("strm-rep", "utf-8");
218
+ var CONTRACT_SEED = Buffer$1.from("contract", "utf-8");
219
+ var ESCROW_SEED = Buffer$1.from("strm", "utf-8");
220
+ var TEST_ORACLE_SEED = Buffer$1.from("test-oracle", "utf-8");
221
+ var METADATA_SEED = Buffer$1.from("strm-met", "utf-8");
222
+ Buffer$1.from("strm-rep", "utf-8");
205
223
  var STREAMFLOW_TREASURY_PUBLIC_KEY = new PublicKey("5SEpbdjFK5FxwTvfsGMXVQTD2v4M2c5tyRTxhdsPkgDw");
206
224
  var WITHDRAWOR = "wdrwhnCv4pzW8beKsbPa4S2UDZrXenjg16KJdKSpb5u";
207
225
  var WITHDRAWOR_PUBLIC_KEY = new PublicKey(WITHDRAWOR);
208
- Buffer.from("strm_fees");
226
+ Buffer$1.from("strm_fees");
209
227
  var DEFAULT_CREATION_FEE_SOL = 9e7;
210
228
  var DEFAULT_AUTO_CLAIM_FEE_SOL = 19e7;
211
229
  var DEFAULT_STREAMFLOW_FEE = 0.19;
@@ -448,7 +466,13 @@ var encodeUpdateStream = (values, data) => {
448
466
  structs.push(BufferLayout.u8("cancelable_by_sender_exists"));
449
467
  structs.push(BufferLayout.u8("cancelable_by_sender"));
450
468
  } else {
451
- structs.push(BufferLayout.u8("cancelable_by_sender"));
469
+ structs.push(BufferLayout.u8("cancelable_by_sender_exists"));
470
+ }
471
+ if (values.stream_name) {
472
+ structs.push(BufferLayout.u8("stream_name_exists"));
473
+ structs.push(BufferLayout.blob(64, "stream_name"));
474
+ } else {
475
+ structs.push(BufferLayout.u8("stream_name_exists"));
452
476
  }
453
477
  return BufferLayout.struct(structs).encode(
454
478
  {
@@ -463,7 +487,9 @@ var encodeUpdateStream = (values, data) => {
463
487
  transferable_by_recipient_exists: values.transferable_by_recipient !== void 0 ? 1 : 0,
464
488
  transferable_by_recipient: values.transferable_by_recipient ?? 0,
465
489
  cancelable_by_sender_exists: values.cancelable_by_sender !== void 0 ? 1 : 0,
466
- cancelable_by_sender: values.cancelable_by_sender ?? 0
490
+ cancelable_by_sender: values.cancelable_by_sender ?? 0,
491
+ stream_name_exists: values.stream_name ? 1 : 0,
492
+ stream_name: values.stream_name ?? 0
467
493
  },
468
494
  data
469
495
  );
@@ -480,6 +506,13 @@ var calculateTotalAmountToDeposit = (depositedAmount, totalFee) => {
480
506
  const totalFeeNormalized = new BN3(totalFee * FEE_NORMALIZER);
481
507
  return depositedAmount.mul(totalFeeNormalized.add(FEE_MULTIPLIER)).div(FEE_MULTIPLIER);
482
508
  };
509
+ var encodeStreamName = (name) => {
510
+ const encoded = new TextEncoder().encode(name);
511
+ return Buffer.alloc(64).fill(encoded, 0, encoded.byteLength);
512
+ };
513
+ var encodeStreamNameAsArray = (name) => {
514
+ return Array.from(encodeStreamName(name));
515
+ };
483
516
  var decodeStream = (buf) => {
484
517
  const raw = streamLayout.decode(buf);
485
518
  return {
@@ -622,16 +655,14 @@ var createStreamInstruction = async (data, programId, accounts) => {
622
655
  if (accounts.partnerLink) {
623
656
  keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
624
657
  }
625
- let bufferData = Buffer.alloc(createStreamLayout.span);
626
- const encodedUIntArray = new TextEncoder().encode(data.name);
627
- const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
658
+ let bufferData = Buffer$1.alloc(createStreamLayout.span);
628
659
  const decodedData = {
629
- start_time: data.start.toArrayLike(Buffer, "le", 8),
630
- net_amount_deposited: data.depositedAmount.toArrayLike(Buffer, "le", 8),
631
- period: data.period.toArrayLike(Buffer, "le", 8),
632
- amount_per_period: data.amountPerPeriod.toArrayLike(Buffer, "le", 8),
633
- cliff: data.cliff.toArrayLike(Buffer, "le", 8),
634
- cliff_amount: data.cliffAmount.toArrayLike(Buffer, "le", 8),
660
+ start_time: data.start.toArrayLike(Buffer$1, "le", 8),
661
+ net_amount_deposited: data.depositedAmount.toArrayLike(Buffer$1, "le", 8),
662
+ period: data.period.toArrayLike(Buffer$1, "le", 8),
663
+ amount_per_period: data.amountPerPeriod.toArrayLike(Buffer$1, "le", 8),
664
+ cliff: data.cliff.toArrayLike(Buffer$1, "le", 8),
665
+ cliff_amount: data.cliffAmount.toArrayLike(Buffer$1, "le", 8),
635
666
  cancelable_by_sender: Number(data.cancelableBySender),
636
667
  cancelable_by_recipient: Number(data.cancelableByRecipient),
637
668
  automatic_withdrawal: Number(data.automaticWithdrawal),
@@ -642,15 +673,15 @@ var createStreamInstruction = async (data, programId, accounts) => {
642
673
  can_update_rate: Number(data.canUpdateRate),
643
674
  _can_update_rate_discriminator: 1,
644
675
  pausable: Number(data.canPause),
645
- stream_name: streamNameBuffer,
646
- withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8)
676
+ stream_name: encodeStreamName(data.name),
677
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer$1, "le", 8)
647
678
  };
648
679
  const encodeLength = createStreamLayout.encode(decodedData, bufferData);
649
680
  bufferData = bufferData.slice(0, encodeLength);
650
- bufferData = Buffer.concat([
651
- Buffer.from(await sha256.digest("global:create")).slice(0, 8),
681
+ bufferData = Buffer$1.concat([
682
+ Buffer$1.from(await sha256.digest("global:create")).slice(0, 8),
652
683
  bufferData,
653
- Buffer.alloc(10)
684
+ Buffer$1.alloc(10)
654
685
  ]);
655
686
  return new TransactionInstruction({
656
687
  keys,
@@ -682,16 +713,16 @@ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
682
713
  isWritable: true
683
714
  });
684
715
  }
685
- let bufferData = Buffer.alloc(createUncheckedStreamLayout.span);
716
+ let bufferData = Buffer$1.alloc(createUncheckedStreamLayout.span);
686
717
  const encodedUIntArray = new TextEncoder().encode(data.name);
687
- const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
718
+ const streamNameBuffer = Buffer$1.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
688
719
  const decodedData = {
689
- start_time: data.start.toArrayLike(Buffer, "le", 8),
690
- net_amount_deposited: data.depositedAmount.toArrayLike(Buffer, "le", 8),
691
- period: data.period.toArrayLike(Buffer, "le", 8),
692
- amount_per_period: data.amountPerPeriod.toArrayLike(Buffer, "le", 8),
693
- cliff: data.cliff.toArrayLike(Buffer, "le", 8),
694
- cliff_amount: data.cliffAmount.toArrayLike(Buffer, "le", 8),
720
+ start_time: data.start.toArrayLike(Buffer$1, "le", 8),
721
+ net_amount_deposited: data.depositedAmount.toArrayLike(Buffer$1, "le", 8),
722
+ period: data.period.toArrayLike(Buffer$1, "le", 8),
723
+ amount_per_period: data.amountPerPeriod.toArrayLike(Buffer$1, "le", 8),
724
+ cliff: data.cliff.toArrayLike(Buffer$1, "le", 8),
725
+ cliff_amount: data.cliffAmount.toArrayLike(Buffer$1, "le", 8),
695
726
  cancelable_by_sender: Number(data.cancelableBySender),
696
727
  cancelable_by_recipient: Number(data.cancelableByRecipient),
697
728
  automatic_withdrawal: Number(data.automaticWithdrawal),
@@ -699,7 +730,7 @@ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
699
730
  transferable_by_recipient: Number(data.transferableByRecipient),
700
731
  can_topup: Number(data.canTopup),
701
732
  stream_name: streamNameBuffer,
702
- withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8),
733
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer$1, "le", 8),
703
734
  recipient: data.recipient.toBuffer(),
704
735
  partner: data.partner.toBuffer(),
705
736
  pausable: Number(data.canPause),
@@ -708,7 +739,7 @@ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
708
739
  const encodeLength = createUncheckedStreamLayout.encode(decodedData, bufferData);
709
740
  bufferData = bufferData.slice(0, encodeLength);
710
741
  const digest = accounts.payer ? await sha256.digest("global:create_unchecked_with_payer") : await sha256.digest("global:create_unchecked");
711
- bufferData = Buffer.concat([Buffer.from(digest).slice(0, 8), bufferData, Buffer.alloc(10)]);
742
+ bufferData = Buffer$1.concat([Buffer$1.from(digest).slice(0, 8), bufferData, Buffer$1.alloc(10)]);
712
743
  return new TransactionInstruction({
713
744
  keys,
714
745
  programId,
@@ -751,18 +782,18 @@ var createStreamV2Instruction = async (data, programId, accounts) => {
751
782
  if (accounts.partnerLink) {
752
783
  keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
753
784
  }
754
- let bufferData = Buffer.alloc(createStreamV2Layout.span);
785
+ let bufferData = Buffer$1.alloc(createStreamV2Layout.span);
755
786
  const encodedUIntArray = new TextEncoder().encode(data.name);
756
- const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
757
- const nonceBuffer = Buffer.alloc(4);
787
+ const streamNameBuffer = Buffer$1.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
788
+ const nonceBuffer = Buffer$1.alloc(4);
758
789
  nonceBuffer.writeUInt32LE(data.nonce);
759
790
  const decodedData = {
760
- start_time: data.start.toArrayLike(Buffer, "le", 8),
761
- net_amount_deposited: data.depositedAmount.toArrayLike(Buffer, "le", 8),
762
- period: data.period.toArrayLike(Buffer, "le", 8),
763
- amount_per_period: data.amountPerPeriod.toArrayLike(Buffer, "le", 8),
764
- cliff: data.cliff.toArrayLike(Buffer, "le", 8),
765
- cliff_amount: data.cliffAmount.toArrayLike(Buffer, "le", 8),
791
+ start_time: data.start.toArrayLike(Buffer$1, "le", 8),
792
+ net_amount_deposited: data.depositedAmount.toArrayLike(Buffer$1, "le", 8),
793
+ period: data.period.toArrayLike(Buffer$1, "le", 8),
794
+ amount_per_period: data.amountPerPeriod.toArrayLike(Buffer$1, "le", 8),
795
+ cliff: data.cliff.toArrayLike(Buffer$1, "le", 8),
796
+ cliff_amount: data.cliffAmount.toArrayLike(Buffer$1, "le", 8),
766
797
  cancelable_by_sender: Number(data.cancelableBySender),
767
798
  cancelable_by_recipient: Number(data.cancelableByRecipient),
768
799
  automatic_withdrawal: Number(data.automaticWithdrawal),
@@ -770,17 +801,17 @@ var createStreamV2Instruction = async (data, programId, accounts) => {
770
801
  transferable_by_recipient: Number(data.transferableByRecipient),
771
802
  can_topup: Number(data.canTopup),
772
803
  stream_name: streamNameBuffer,
773
- withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8),
804
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer$1, "le", 8),
774
805
  pausable: Number(data.canPause),
775
806
  can_update_rate: Number(data.canUpdateRate),
776
807
  nonce: nonceBuffer
777
808
  };
778
809
  const encodeLength = createStreamV2Layout.encode(decodedData, bufferData);
779
810
  bufferData = bufferData.slice(0, encodeLength);
780
- bufferData = Buffer.concat([
781
- Buffer.from(await sha256.digest("global:create_v2")).slice(0, 8),
811
+ bufferData = Buffer$1.concat([
812
+ Buffer$1.from(await sha256.digest("global:create_v2")).slice(0, 8),
782
813
  bufferData,
783
- Buffer.alloc(10)
814
+ Buffer$1.alloc(10)
784
815
  ]);
785
816
  return new TransactionInstruction({
786
817
  keys,
@@ -812,18 +843,18 @@ var createUncheckedStreamV2Instruction = async (data, programId, accounts) => {
812
843
  isWritable: true
813
844
  });
814
845
  }
815
- let bufferData = Buffer.alloc(createUncheckedStreamV2Layout.span);
846
+ let bufferData = Buffer$1.alloc(createUncheckedStreamV2Layout.span);
816
847
  const encodedUIntArray = new TextEncoder().encode(data.name);
817
- const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
818
- const nonceBuffer = Buffer.alloc(4);
848
+ const streamNameBuffer = Buffer$1.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
849
+ const nonceBuffer = Buffer$1.alloc(4);
819
850
  nonceBuffer.writeUInt32LE(data.nonce);
820
851
  const decodedData = {
821
- start_time: data.start.toArrayLike(Buffer, "le", 8),
822
- net_amount_deposited: data.depositedAmount.toArrayLike(Buffer, "le", 8),
823
- period: data.period.toArrayLike(Buffer, "le", 8),
824
- amount_per_period: data.amountPerPeriod.toArrayLike(Buffer, "le", 8),
825
- cliff: data.cliff.toArrayLike(Buffer, "le", 8),
826
- cliff_amount: data.cliffAmount.toArrayLike(Buffer, "le", 8),
852
+ start_time: data.start.toArrayLike(Buffer$1, "le", 8),
853
+ net_amount_deposited: data.depositedAmount.toArrayLike(Buffer$1, "le", 8),
854
+ period: data.period.toArrayLike(Buffer$1, "le", 8),
855
+ amount_per_period: data.amountPerPeriod.toArrayLike(Buffer$1, "le", 8),
856
+ cliff: data.cliff.toArrayLike(Buffer$1, "le", 8),
857
+ cliff_amount: data.cliffAmount.toArrayLike(Buffer$1, "le", 8),
827
858
  cancelable_by_sender: Number(data.cancelableBySender),
828
859
  cancelable_by_recipient: Number(data.cancelableByRecipient),
829
860
  automatic_withdrawal: Number(data.automaticWithdrawal),
@@ -831,7 +862,7 @@ var createUncheckedStreamV2Instruction = async (data, programId, accounts) => {
831
862
  transferable_by_recipient: Number(data.transferableByRecipient),
832
863
  can_topup: Number(data.canTopup),
833
864
  stream_name: streamNameBuffer,
834
- withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer, "le", 8),
865
+ withdraw_frequency: data.withdrawFrequency.toArrayLike(Buffer$1, "le", 8),
835
866
  recipient: data.recipient.toBuffer(),
836
867
  partner: data.partner.toBuffer(),
837
868
  pausable: Number(data.canPause),
@@ -841,7 +872,7 @@ var createUncheckedStreamV2Instruction = async (data, programId, accounts) => {
841
872
  const encodeLength = createUncheckedStreamV2Layout.encode(decodedData, bufferData);
842
873
  bufferData = bufferData.slice(0, encodeLength);
843
874
  const digest = accounts.payer ? await sha256.digest("global:create_unchecked_with_payer_v2") : await sha256.digest("global:create_unchecked_v2");
844
- bufferData = Buffer.concat([Buffer.from(digest).slice(0, 8), bufferData, Buffer.alloc(10)]);
875
+ bufferData = Buffer$1.concat([Buffer$1.from(digest).slice(0, 8), bufferData, Buffer$1.alloc(10)]);
845
876
  return new TransactionInstruction({
846
877
  keys,
847
878
  programId,
@@ -878,11 +909,11 @@ var withdrawStreamInstruction = async (amount, programId, {
878
909
  { pubkey: mint, isSigner: false, isWritable: true },
879
910
  { pubkey: tokenProgram, isSigner: false, isWritable: false }
880
911
  ];
881
- let data = Buffer.alloc(withdrawStreamLayout.span);
882
- const decodedData = { amount: amount.toArrayLike(Buffer, "le", 8) };
912
+ let data = Buffer$1.alloc(withdrawStreamLayout.span);
913
+ const decodedData = { amount: amount.toArrayLike(Buffer$1, "le", 8) };
883
914
  const encodeLength = withdrawStreamLayout.encode(decodedData, data);
884
915
  data = data.slice(0, encodeLength);
885
- data = Buffer.concat([Buffer.from(await sha256.digest("global:withdraw")).slice(0, 8), data, Buffer.alloc(10)]);
916
+ data = Buffer$1.concat([Buffer$1.from(await sha256.digest("global:withdraw")).slice(0, 8), data, Buffer$1.alloc(10)]);
886
917
  return new TransactionInstruction({
887
918
  keys,
888
919
  programId,
@@ -896,18 +927,19 @@ var updateStreamInstruction = async (params, programId, { authority, metadata, w
896
927
  { pubkey: withdrawor, isSigner: false, isWritable: true },
897
928
  { pubkey: systemProgram, isSigner: false, isWritable: false }
898
929
  ];
899
- let data = Buffer.alloc(100);
930
+ let data = Buffer$1.alloc(100);
900
931
  const decodedData = {
901
932
  enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
902
- withdraw_frequency: params.withdrawFrequency ? params.withdrawFrequency.toArrayLike(Buffer, "le", 8) : void 0,
903
- amount_per_period: params.amountPerPeriod ? params.amountPerPeriod.toArrayLike(Buffer, "le", 8) : void 0,
933
+ withdraw_frequency: params.withdrawFrequency ? params.withdrawFrequency.toArrayLike(Buffer$1, "le", 8) : void 0,
934
+ amount_per_period: params.amountPerPeriod ? params.amountPerPeriod.toArrayLike(Buffer$1, "le", 8) : void 0,
904
935
  transferable_by_sender: params.transferableBySender !== void 0 ? Number(params.transferableBySender) : void 0,
905
936
  transferable_by_recipient: params.transferableByRecipient !== void 0 ? Number(params.transferableByRecipient) : void 0,
906
- cancelable_by_sender: params.cancelableBySender !== void 0 ? Number(params.cancelableBySender) : void 0
937
+ cancelable_by_sender: params.cancelableBySender !== void 0 ? Number(params.cancelableBySender) : void 0,
938
+ stream_name: params.name !== void 0 ? encodeStreamName(params.name) : void 0
907
939
  };
908
940
  const encodeLength = encodeUpdateStream(decodedData, data);
909
941
  data = data.slice(0, encodeLength);
910
- data = Buffer.concat([Buffer.from(await sha256.digest("global:update")).slice(0, 8), data, Buffer.alloc(20)]);
942
+ data = Buffer$1.concat([Buffer$1.from(await sha256.digest("global:update")).slice(0, 8), data, Buffer$1.alloc(20)]);
911
943
  return new TransactionInstruction({
912
944
  keys,
913
945
  programId,
@@ -948,7 +980,7 @@ var cancelStreamInstruction = async (programId, {
948
980
  { pubkey: mint, isSigner: false, isWritable: true },
949
981
  { pubkey: tokenProgram, isSigner: false, isWritable: false }
950
982
  ];
951
- const data = Buffer.concat([Buffer.from(await sha256.digest("global:cancel")).slice(0, 8), Buffer.alloc(10)]);
983
+ const data = Buffer$1.concat([Buffer$1.from(await sha256.digest("global:cancel")).slice(0, 8), Buffer$1.alloc(10)]);
952
984
  return new TransactionInstruction({
953
985
  keys,
954
986
  programId,
@@ -977,9 +1009,9 @@ var transferStreamInstruction = async (programId, {
977
1009
  { pubkey: associatedTokenProgram, isSigner: false, isWritable: false },
978
1010
  { pubkey: systemProgram, isSigner: false, isWritable: false }
979
1011
  ];
980
- const data = Buffer.concat([
981
- Buffer.from(await sha256.digest("global:transfer_recipient")).slice(0, 8),
982
- Buffer.alloc(10)
1012
+ const data = Buffer$1.concat([
1013
+ Buffer$1.from(await sha256.digest("global:transfer_recipient")).slice(0, 8),
1014
+ Buffer$1.alloc(10)
983
1015
  ]);
984
1016
  return new TransactionInstruction({
985
1017
  keys,
@@ -1007,10 +1039,10 @@ var claimRoutedFeeStreamInstruction = async (destination, programId, {
1007
1039
  { pubkey: mint, isSigner: false, isWritable: true },
1008
1040
  { pubkey: tokenProgram, isSigner: false, isWritable: false }
1009
1041
  ];
1010
- const data = Buffer.concat([
1011
- Buffer.from(await sha256.digest("global:claim_routed_fee")).slice(0, 8),
1012
- Buffer.from([destination === "treasury" ? 0 : 1]),
1013
- Buffer.alloc(10)
1042
+ const data = Buffer$1.concat([
1043
+ Buffer$1.from(await sha256.digest("global:claim_routed_fee")).slice(0, 8),
1044
+ Buffer$1.from([destination === "treasury" ? 0 : 1]),
1045
+ Buffer$1.alloc(10)
1014
1046
  ]);
1015
1047
  return new TransactionInstruction({
1016
1048
  keys,
@@ -1050,11 +1082,11 @@ var topupStreamInstruction = async (amount, programId, {
1050
1082
  { pubkey: tokenProgram, isSigner: false, isWritable: false },
1051
1083
  { pubkey: systemProgram, isSigner: false, isWritable: false }
1052
1084
  ];
1053
- let data = Buffer.alloc(topupStreamLayout.span);
1054
- const decodedData = { amount: amount.toArrayLike(Buffer, "le", 8) };
1085
+ let data = Buffer$1.alloc(topupStreamLayout.span);
1086
+ const decodedData = { amount: amount.toArrayLike(Buffer$1, "le", 8) };
1055
1087
  const encodeLength = topupStreamLayout.encode(decodedData, data);
1056
1088
  data = data.slice(0, encodeLength);
1057
- data = Buffer.concat([Buffer.from(await sha256.digest("global:topup")).slice(0, 8), data, Buffer.alloc(10)]);
1089
+ data = Buffer$1.concat([Buffer$1.from(await sha256.digest("global:topup")).slice(0, 8), data, Buffer$1.alloc(10)]);
1058
1090
  return new TransactionInstruction({
1059
1091
  keys,
1060
1092
  programId,
@@ -3030,6 +3062,17 @@ var streamflow_aligned_unlocks_default = {
3030
3062
  type: {
3031
3063
  option: "bool"
3032
3064
  }
3065
+ },
3066
+ {
3067
+ name: "stream_name",
3068
+ type: {
3069
+ option: {
3070
+ array: [
3071
+ "u8",
3072
+ 64
3073
+ ]
3074
+ }
3075
+ }
3033
3076
  }
3034
3077
  ]
3035
3078
  }
@@ -3071,7 +3114,7 @@ var deriveTestOraclePDA = (programId, mint, creator) => {
3071
3114
  };
3072
3115
  var deriveStreamMetadataPDA = (programId, mint, sender, nonce) => {
3073
3116
  return PublicKey.findProgramAddressSync(
3074
- [METADATA_SEED, mint.toBuffer(), sender.toBuffer(), new BN3(nonce).toArrayLike(Buffer, "be", 4)],
3117
+ [METADATA_SEED, mint.toBuffer(), sender.toBuffer(), new BN3(nonce).toArrayLike(Buffer$1, "be", 4)],
3075
3118
  programId
3076
3119
  )[0];
3077
3120
  };
@@ -3226,6 +3269,27 @@ var transformContract = async (schema) => {
3226
3269
  // solana/StreamClient.ts
3227
3270
  var METADATA_ACC_SIZE = 1104;
3228
3271
  var ALIGNED_METADATA_ACC_SIZE = 320;
3272
+ var PARTNER_LINK_DISCRIMINATOR = Buffer$1.from([114, 220, 250, 94, 181, 182, 195, 222]);
3273
+ var PARTNER_LINK_SIZE = 8 + 32 + 32 + 32;
3274
+ var decodePartnerLink = (data) => data.length >= PARTNER_LINK_SIZE && data.subarray(0, 8).equals(PARTNER_LINK_DISCRIMINATOR) ? { partnerPubkey: new PublicKey(data.subarray(8, 40)), linkedPubkey: new PublicKey(data.subarray(40, 72)) } : null;
3275
+ var findFees = (partners, address) => {
3276
+ const filteredPartners = partners.filter((partner2) => new PublicKey(partner2.pubkey).toString() === address);
3277
+ if (filteredPartners.length === 0) {
3278
+ return null;
3279
+ }
3280
+ if (filteredPartners.length > 1) {
3281
+ throw new Error("More than one partner found, fees fetching is not possible.");
3282
+ }
3283
+ const partner = filteredPartners[0];
3284
+ return {
3285
+ creationFeeSol: Number(partner.creation_fee),
3286
+ autoClaimFeeSol: Number(partner.auto_claim_fee),
3287
+ streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
3288
+ streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
3289
+ partnerFee: 0
3290
+ };
3291
+ };
3292
+ var getWrapFeePercent = (rates, data) => isStrictTokenLockCreate(data) ? rates.streamflowLockFee : rates.streamflowFee;
3229
3293
  var SolanaStreamClient = class {
3230
3294
  /**
3231
3295
  * Create Stream instance
@@ -3319,10 +3383,8 @@ var SolanaStreamClient = class {
3319
3383
  tokenProgramId ? new PublicKey(tokenProgramId) : void 0
3320
3384
  );
3321
3385
  if (isNative) {
3322
- const totalFee = await this.getTotalFee({
3323
- address: partnerPublicKey.toString()
3324
- });
3325
- const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
3386
+ const rates = await this.getCreateFeeRates(data.partnerLink, sender.publicKey);
3387
+ const totalAmount = calculateTotalAmountToDeposit(amount, getWrapFeePercent(rates, data));
3326
3388
  ixs.push(...await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
3327
3389
  }
3328
3390
  const {
@@ -3467,8 +3529,6 @@ var SolanaStreamClient = class {
3467
3529
  ...await this.getCreateATAInstructions([recipientPublicKey], mintPublicKey, sender, true, tokenProgramId)
3468
3530
  );
3469
3531
  }
3470
- const encodedUIntArray = new TextEncoder().encode(streamName);
3471
- const streamNameArray = Array.from(encodedUIntArray);
3472
3532
  const createMethod = this.alignedProxyProgram.methods.create({
3473
3533
  startTime: new BN3(start),
3474
3534
  netAmountDeposited: depositedAmount,
@@ -3482,7 +3542,7 @@ var SolanaStreamClient = class {
3482
3542
  cancelableBySender,
3483
3543
  canTopup,
3484
3544
  oracleType: !!oracleType ? { [oracleType]: {} } : { none: {} },
3485
- streamName: streamNameArray,
3545
+ streamName: encodeStreamNameAsArray(streamName),
3486
3546
  minPrice: typeof minPrice === "number" ? getBN(minPrice, ALIGNED_PRECISION_FACTOR_POW2) : minPrice,
3487
3547
  maxPrice: typeof maxPrice === "number" ? getBN(maxPrice, ALIGNED_PRECISION_FACTOR_POW2) : maxPrice,
3488
3548
  minPercentage: typeof minPercentage === "number" ? getBN(minPercentage, ALIGNED_PRECISION_FACTOR_POW2) : minPercentage,
@@ -3566,7 +3626,7 @@ var SolanaStreamClient = class {
3566
3626
  ({ metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys));
3567
3627
  }
3568
3628
  const [escrowTokens] = PublicKey.findProgramAddressSync(
3569
- [Buffer.from("strm"), metadataPubKey.toBuffer()],
3629
+ [Buffer$1.from("strm"), metadataPubKey.toBuffer()],
3570
3630
  this.programId
3571
3631
  );
3572
3632
  const { mint: mintAccount, tokenProgramId: detectedTokenProgramId } = await getMintAndProgram(
@@ -3700,7 +3760,7 @@ var SolanaStreamClient = class {
3700
3760
  ({ metadata, metadataPubKey } = this.getOrCreateStreamMetadata(metadataPubKeys));
3701
3761
  }
3702
3762
  const [escrowTokens] = PublicKey.findProgramAddressSync(
3703
- [Buffer.from("strm"), metadataPubKey.toBuffer()],
3763
+ [Buffer$1.from("strm"), metadataPubKey.toBuffer()],
3704
3764
  this.programId
3705
3765
  );
3706
3766
  const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
@@ -3711,7 +3771,20 @@ var SolanaStreamClient = class {
3711
3771
  computeLimit
3712
3772
  });
3713
3773
  if (isNative) {
3714
- const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
3774
+ const rates = await this.getCreateFeeRates(partnerLink, sender.publicKey);
3775
+ const totalFee = getWrapFeePercent(rates, {
3776
+ start,
3777
+ amount: depositedAmount,
3778
+ period,
3779
+ cliff,
3780
+ cliffAmount,
3781
+ amountPerPeriod,
3782
+ canTopup,
3783
+ automaticWithdrawal,
3784
+ cancelableBySender,
3785
+ cancelableByRecipient,
3786
+ transferableBySender
3787
+ });
3715
3788
  const totalAmount = calculateTotalAmountToDeposit(depositedAmount, totalFee);
3716
3789
  ixs.push(...await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount));
3717
3790
  }
@@ -3801,6 +3874,7 @@ var SolanaStreamClient = class {
3801
3874
  if (recipients.length === 0) {
3802
3875
  throw new Error("Recipients array is empty!");
3803
3876
  }
3877
+ const wrapFeeRates = isNative ? await this.getCreateFeeRates(data.partnerLink, sender.publicKey) : void 0;
3804
3878
  for (let i = 0; i < recipients.length; i++) {
3805
3879
  const recipientData = recipients[i];
3806
3880
  const createStreamData = { ...streamParams, ...recipientData };
@@ -3809,8 +3883,8 @@ var SolanaStreamClient = class {
3809
3883
  metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
3810
3884
  };
3811
3885
  const wrapInstructions = [];
3812
- if (isNative) {
3813
- const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
3886
+ if (wrapFeeRates) {
3887
+ const totalFee = getWrapFeePercent(wrapFeeRates, createStreamData);
3814
3888
  const recipientAmount = calculateTotalAmountToDeposit(recipientData.amount, totalFee);
3815
3889
  wrapInstructions.push(...await prepareWrappedAccount(this.connection, sender.publicKey, recipientAmount));
3816
3890
  }
@@ -4704,7 +4778,8 @@ var SolanaStreamClient = class {
4704
4778
  await (isAlignedUnlock ? this.alignedProxyProgram.methods.updateContract({
4705
4779
  transferableBySender: data.transferableBySender ?? null,
4706
4780
  transferableByRecipient: data.transferableByRecipient ?? null,
4707
- cancelableBySender: data.cancelableBySender ?? null
4781
+ cancelableBySender: data.cancelableBySender ?? null,
4782
+ streamName: data.name !== void 0 ? encodeStreamNameAsArray(data.name) : null
4708
4783
  }).accounts({ sender: invoker.publicKey, streamMetadata: streamPublicKey, withdrawor: WITHDRAWOR_PUBLIC_KEY }).accountsPartial({ streamflowProgram: this.programId }).instruction() : updateStreamInstruction(data, this.programId, {
4709
4784
  authority: invoker.publicKey,
4710
4785
  metadata: streamPublicKey,
@@ -4720,26 +4795,38 @@ var SolanaStreamClient = class {
4720
4795
  * @returns Fees
4721
4796
  */
4722
4797
  async getFees({ address }) {
4798
+ const partners = await this.getFeeRows();
4799
+ return partners ? findFees(partners, address) : null;
4800
+ }
4801
+ async getFeeRows() {
4723
4802
  const data = await this.connection.getAccountInfo(this.feeOraclePublicKey);
4724
- if (!data) {
4725
- return null;
4726
- }
4727
- const partners = borsh.deserialize(PARTNERS_SCHEMA, data.data);
4728
- const filteredPartners = partners.filter((partner2) => new PublicKey(partner2.pubkey).toString() === address);
4729
- if (filteredPartners.length === 0) {
4730
- return null;
4731
- }
4732
- if (filteredPartners.length > 1) {
4733
- throw new Error("More than one partner found, fees fetching is not possible.");
4803
+ return data ? borsh.deserialize(PARTNERS_SCHEMA, data.data) : null;
4804
+ }
4805
+ /**
4806
+ * Fee rates the program applies to a create from `sender` with `partnerLink`, used to size the WSOL wrap.
4807
+ * Mirrors `resolve_vesting_partner`: a `partnerLink` counts if it signs or the partner oracle owns it, and a
4808
+ * PartnerLink account stands for its partner. A link to another wallet fails the program's lookup, which then
4809
+ * charges its hardcoded fallback and skips the sender's own row. Otherwise the sender's own row, then the
4810
+ * partner's, then the default row. `partner` only takes a share and never picks the row.
4811
+ */
4812
+ async getCreateFeeRates(partnerLink, sender) {
4813
+ const fallback = { streamflowFee: DEFAULT_STREAMFLOW_FEE, streamflowLockFee: DEFAULT_STREAMFLOW_FEE };
4814
+ let linkedPartner;
4815
+ if (partnerLink?.isSigner) {
4816
+ linkedPartner = pk(partnerLink.address).toBase58();
4817
+ } else if (partnerLink) {
4818
+ const address = pk(partnerLink.address);
4819
+ const account = await this.connection.getAccountInfo(address);
4820
+ if (account?.owner.equals(this.partnerOracleProgramId)) {
4821
+ const link = decodePartnerLink(account.data);
4822
+ if (link && !link.linkedPubkey.equals(sender)) {
4823
+ return fallback;
4824
+ }
4825
+ linkedPartner = (link?.partnerPubkey ?? address).toBase58();
4826
+ }
4734
4827
  }
4735
- const partner = filteredPartners[0];
4736
- return {
4737
- creationFeeSol: Number(partner.creation_fee),
4738
- autoClaimFeeSol: Number(partner.auto_claim_fee),
4739
- streamflowFee: Number(partner.token_fee_percent.toFixed(4)),
4740
- streamflowLockFee: Number(partner.token_lock_token_fee_percent.toFixed(4)),
4741
- partnerFee: 0
4742
- };
4828
+ const partners = await this.getFeeRows() ?? [];
4829
+ return findFees(partners, sender.toBase58()) ?? (linkedPartner ? findFees(partners, linkedPartner) : null) ?? findFees(partners, WITHDRAWOR) ?? fallback;
4743
4830
  }
4744
4831
  /**
4745
4832
  * Gets default streamflow fee