@streamflow/stream 11.3.0 → 11.4.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.
@@ -31,6 +31,10 @@ interface IBaseStreamConfig {
31
31
  canPause?: boolean;
32
32
  canUpdateRate?: boolean;
33
33
  partner?: string;
34
+ partnerLink?: {
35
+ address: string;
36
+ isSigner: boolean;
37
+ };
34
38
  tokenProgramId?: string | PublicKey;
35
39
  }
36
40
  type IAlignedStreamConfig = {
@@ -352,10 +356,15 @@ interface IPrepareStreamExt extends Omit<IInteractStreamExt, "invoker"> {
352
356
  publicKey: PublicKey | null;
353
357
  };
354
358
  }
355
- interface ITopUpStreamExt extends ITransactionExt {
356
- invoker: SignerWalletAdapter | Keypair;
359
+ interface IPrepareTopUpstreamExt extends ITransactionExt {
360
+ invoker: {
361
+ publicKey: PublicKey | null;
362
+ };
357
363
  isNative?: boolean;
358
364
  }
365
+ interface ITopUpStreamExt extends IPrepareTopUpstreamExt {
366
+ invoker: SignerWalletAdapter | Keypair;
367
+ }
359
368
  interface ICreateStreamInstructions {
360
369
  ixs: TransactionInstruction[];
361
370
  metadata: Keypair | undefined;
@@ -573,6 +582,10 @@ declare class SolanaStreamClient {
573
582
  */
574
583
  create(data: ICreateStreamData, extParams: ICreateStreamExt): Promise<ICreateResult>;
575
584
  prepareCreateInstructions(streamParams: ICreateStreamData, extParams: IPrepareCreateStreamExt): Promise<ICreateStreamInstructions>;
585
+ /**
586
+ * Builds instructions for creating an aligned unlock stream.
587
+ * For Token-2022 mints with a transfer hook, partner link and hook accounts are appended as remaining accounts.
588
+ */
576
589
  prepareCreateAlignedUnlockInstructions(streamParams: ICreateAlignedStreamData, extParams: IPrepareCreateStreamExt): Promise<ICreateStreamInstructions>;
577
590
  /**
578
591
  * Creates a new stream/vesting contract.
@@ -581,7 +594,7 @@ declare class SolanaStreamClient {
581
594
  * @param {IPrepareCreateStreamExt} extParams - Transaction configuration including sender wallet, metadata keys, and compute settings
582
595
  * @returns Create stream instructions
583
596
  */
584
- prepareCreateLinearStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, tokenProgramId: streamTokenProgramId, nonce, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: IPrepareCreateStreamExt): Promise<ICreateStreamInstructions>;
597
+ prepareCreateLinearStreamInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canPause, canUpdateRate, canTopup, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, partnerLink, tokenProgramId: streamTokenProgramId, nonce, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: IPrepareCreateStreamExt): Promise<ICreateStreamInstructions>;
585
598
  /**
586
599
  * Creates a new stream/vesting contract using unchecked instruction.
587
600
  *
@@ -599,7 +612,7 @@ declare class SolanaStreamClient {
599
612
  /**
600
613
  * Create Transaction instructions for `createUnchecked`
601
614
  */
602
- prepareCreateUncheckedInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, canUpdateRate, canPause, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, nonce, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: IPrepareCreateStreamExt): Promise<{
615
+ prepareCreateUncheckedInstructions({ recipient, tokenId: mint, start, amount: depositedAmount, period, cliff, cliffAmount, amountPerPeriod, name, canTopup, canUpdateRate, canPause, cancelableBySender, cancelableByRecipient, transferableBySender, transferableByRecipient, automaticWithdrawal, withdrawalFrequency, partner, partnerLink, nonce, }: ICreateStreamData, { sender, metadataPubKeys, isNative, computePrice, computeLimit }: IPrepareCreateStreamExt): Promise<{
603
616
  ixs: TransactionInstruction[];
604
617
  metadata: Keypair | undefined;
605
618
  metadataPubKey: PublicKey;
@@ -746,7 +759,7 @@ declare class SolanaStreamClient {
746
759
  * @param {ITopUpStreamExt} extParams - Transaction configuration including invoker wallet, native token handling, and compute settings
747
760
  * @returns Transaction instructions
748
761
  */
749
- prepareTopupInstructions({ id, amount }: ITopUpData, { invoker, isNative, computePrice, computeLimit }: ITopUpStreamExt): Promise<TransactionInstruction[]>;
762
+ prepareTopupInstructions({ id, amount }: ITopUpData, { invoker, isNative, computePrice, computeLimit }: IPrepareTopUpstreamExt): Promise<TransactionInstruction[]>;
750
763
  /**
751
764
  * Fetch stream data by its id (address).
752
765
  * @param {IGetOneData} getData - Query parameters containing the stream ID to fetch
@@ -838,6 +851,16 @@ declare class SolanaStreamClient {
838
851
  * Utility function to generate metadata for a Contract or return existing Pubkey
839
852
  */
840
853
  private getOrCreateStreamMetadata;
854
+ /**
855
+ * Returns the configured transfer hook program for a Token-2022 mint, if present.
856
+ */
857
+ private getTransferHookProgramId;
858
+ /**
859
+ * Appends transfer-hook extra metas for each potential token transfer performed by the instruction.
860
+ *
861
+ * Transfer hook may rely on additional accounts/PDAs - derivation path is configured on the transfer hook metadata account, so for each potential transfer we need to check whether these accounts are needed and add them.
862
+ */
863
+ private addTransferHookAccounts;
841
864
  /**
842
865
  * Returns insrtuctions for creating associated token accounts for the provided owners
843
866
  */
@@ -930,6 +953,10 @@ interface CreateStreamAccounts {
930
953
  associatedTokenProgram: PublicKey;
931
954
  withdrawor: PublicKey;
932
955
  systemProgram: PublicKey;
956
+ partnerLink?: {
957
+ pubkey: PublicKey;
958
+ isSigner: boolean;
959
+ };
933
960
  }
934
961
  declare const createStreamInstruction: (data: CreateStreamData, programId: PublicKey, accounts: CreateStreamAccounts) => Promise<TransactionInstruction>;
935
962
  interface CreateUncheckedStreamData {
@@ -965,6 +992,10 @@ interface CreateUncheckedStreamAccounts {
965
992
  tokenProgram: PublicKey;
966
993
  withdrawor: PublicKey;
967
994
  systemProgram: PublicKey;
995
+ partnerLink?: {
996
+ pubkey: PublicKey;
997
+ isSigner: boolean;
998
+ };
968
999
  }
969
1000
  declare const createUncheckedStreamInstruction: (data: CreateUncheckedStreamData, programId: PublicKey, accounts: CreateUncheckedStreamAccounts) => Promise<TransactionInstruction>;
970
1001
  interface CreateStreamV2Data {
@@ -1426,4 +1457,4 @@ declare const createClient: (options?: ApiClientOptions) => ApiClient;
1426
1457
 
1427
1458
  declare const transformContract: (schema: ContractSchema) => Promise<Stream>;
1428
1459
 
1429
- export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, type Account, AlignedContract, AlignedProxyErrorCode, type AlignedStream, type AlignedStreamData, type AlignedUnlocksContract, type ApiClient, type ApiClientOptions, type BatchItem, type BatchItemError, type BatchItemResult, type BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, type Chain, type ChangeOracleParams, type ClientCreationOptions, Contract, ContractErrorCode, type ContractSchema, type ContractType, type CreateParams, type CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, type DecodedStream, type DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, type GetContractsOptions, type IAlignedStreamConfig, type IBaseStreamConfig, type ICancelData, type ICreateAlignedStreamData, type ICreateExt, type ICreateLinearStreamData, type ICreateMultiError, type ICreateMultipleAlignedStreamData, type ICreateMultipleLinearStreamData, type ICreateMultipleStreamData, type ICreateResult, type ICreateStreamData, type ICreateStreamExt, type ICreateStreamInstructions, type IFees, type IGetAllData, type IGetFeesData, type IGetOneData, type IInteractData, type IInteractStreamExt, type IMultiTransactionResult, type IPrepareCreateStreamExt, type IPrepareStreamExt, type IRecipient, type ISearchStreams, type ITopUpData, type ITopUpStreamExt, type ITransactionExtWithInstructions, type ITransactionResult, type ITransferData, type IUpdateData, type IWithdrawData, type InstructionGenerator, type LinearStream, MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, type MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, type OracleType, type OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, type PriceOracleType, REPOPULATED_METADATA_SEED, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, type Stream, type StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, type TabulariumContract, type TestOracle, type TransactionSchedulingOptions, type UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createClient, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, _default as timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction };
1460
+ export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, type Account, AlignedContract, AlignedProxyErrorCode, type AlignedStream, type AlignedStreamData, type AlignedUnlocksContract, type ApiClient, type ApiClientOptions, type BatchItem, type BatchItemError, type BatchItemResult, type BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, type Chain, type ChangeOracleParams, type ClientCreationOptions, Contract, ContractErrorCode, type ContractSchema, type ContractType, type CreateParams, type CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, type DecodedStream, type DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, type GetContractsOptions, type IAlignedStreamConfig, type IBaseStreamConfig, type ICancelData, type ICreateAlignedStreamData, type ICreateExt, type ICreateLinearStreamData, type ICreateMultiError, type ICreateMultipleAlignedStreamData, type ICreateMultipleLinearStreamData, type ICreateMultipleStreamData, type ICreateResult, type ICreateStreamData, type ICreateStreamExt, type ICreateStreamInstructions, type IFees, type IGetAllData, type IGetFeesData, type IGetOneData, type IInteractData, type IInteractStreamExt, type IMultiTransactionResult, type IPrepareCreateStreamExt, type IPrepareStreamExt, type IPrepareTopUpstreamExt, type IRecipient, type ISearchStreams, type ITopUpData, type ITopUpStreamExt, type ITransactionExtWithInstructions, type ITransactionResult, type ITransferData, type IUpdateData, type IWithdrawData, type InstructionGenerator, type LinearStream, MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, type MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, type OracleType, type OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, type PriceOracleType, REPOPULATED_METADATA_SEED, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, type Stream, type StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, type TabulariumContract, type TestOracle, type TransactionSchedulingOptions, type UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createClient, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, _default as timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction };
@@ -1,4 +1,4 @@
1
- export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, Account, AlignedContract, AlignedProxyErrorCode, AlignedStream, AlignedStreamData, AlignedUnlocksContract, ApiClient, ApiClientOptions, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, ContractSchema, ContractType, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, IAlignedStreamConfig, IBaseStreamConfig, ICancelData, ICreateAlignedStreamData, ICreateExt, ICreateLinearStreamData, ICreateMultiError, ICreateMultipleAlignedStreamData, ICreateMultipleLinearStreamData, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, ICreateStreamExt, ICreateStreamInstructions, IFees, IGetAllData, IGetFeesData, IGetOneData, IInteractData, IInteractStreamExt, IMultiTransactionResult, IPrepareCreateStreamExt, IPrepareStreamExt, IRecipient, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, InstructionGenerator, LinearStream, MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, PriceOracleType, REPOPULATED_METADATA_SEED, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, Stream, StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TabulariumContract, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createClient, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction } from './solana/index.js';
1
+ export { AIRDROP_AMOUNT, AIRDROP_TEST_TOKEN, ALIGNED_COMPUTE_LIMIT, ALIGNED_PRECISION_FACTOR_POW, ALIGNED_UNLOCKS_PROGRAM_ID, Account, AlignedContract, AlignedProxyErrorCode, AlignedStream, AlignedStreamData, AlignedUnlocksContract, ApiClient, ApiClientOptions, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, Chain, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, ContractSchema, ContractType, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, DynamicContractSchema, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, GetContractsOptions, IAlignedStreamConfig, IBaseStreamConfig, ICancelData, ICreateAlignedStreamData, ICreateExt, ICreateLinearStreamData, ICreateMultiError, ICreateMultipleAlignedStreamData, ICreateMultipleLinearStreamData, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, ICreateStreamExt, ICreateStreamInstructions, IFees, IGetAllData, IGetFeesData, IGetOneData, IInteractData, IInteractStreamExt, IMultiTransactionResult, IPrepareCreateStreamExt, IPrepareStreamExt, IPrepareTopUpstreamExt, IRecipient, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, InstructionGenerator, LinearStream, MAX_SAFE_UNIX_TIME_VALUE, METADATA_SEED, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, PriceOracleType, REPOPULATED_METADATA_SEED, SOLANA_ERROR_MAP, SOLANA_ERROR_MATCH_REGEX, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSETS, STREAM_STRUCT_OFFSET_CLOSED, STREAM_STRUCT_OFFSET_MINT, STREAM_STRUCT_OFFSET_OLD_METADATA_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, SolanaStreamClient, Stream, StreamClientOptions, StreamDirection, StreamType, TEST_ORACLE_DISCRIMINATOR, TEST_ORACLE_SEED, TX_FINALITY_CONFIRMED, TabulariumContract, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createClient, createStreamInstruction, createStreamV2Instruction, createUncheckedStreamInstruction, createUncheckedStreamV2Instruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveStreamMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, transformContract, updateStreamInstruction, withdrawStreamInstruction } from './solana/index.js';
2
2
  export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
3
3
  import 'p-queue';
4
4
  import '@solana/web3.js';
package/dist/esm/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import BN3 from 'bn.js';
2
2
  import bs58 from 'bs58';
3
3
  import { Buffer } from 'buffer';
4
- import { NATIVE_MINT, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/spl-token';
4
+ import { NATIVE_MINT, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, getTransferHook, addExtraAccountMetasForExecute } from '@solana/spl-token';
5
5
  import { PublicKey, TransactionInstruction, Connection, Keypair, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
6
- import { ICluster, getNumberFromBN, isSignerKeypair, isSignerWallet, executeTransaction, ContractError, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, prepareTransaction, signAndExecuteTransaction, invariant, getMintAndProgram, prepareBaseInstructions, getBN, ata, createVersionedTransaction, executeMultipleTransactions, getMultipleAccountsInfoBatched, getProgramAccounts, isDev, checkOrCreateAtaBatch, pk } from '@streamflow/common';
6
+ import { ICluster, getNumberFromBN, isSignerKeypair, isSignerWallet, executeTransaction, ContractError, buildSendThrottler, assertHasPublicKey, prepareWrappedAccount, prepareTransaction, signAndExecuteTransaction, invariant, getMintAndProgram, ata, prepareBaseInstructions, getBN, createVersionedTransaction, executeMultipleTransactions, getMultipleAccountsInfoBatched, getProgramAccounts, isDev, checkOrCreateAtaBatch, pk } from '@streamflow/common';
7
7
  export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
8
8
  import * as borsh from 'borsh';
9
9
  import { Program } from '@coral-xyz/anchor';
@@ -697,6 +697,9 @@ var createStreamInstruction = async (data, programId, accounts) => {
697
697
  },
698
698
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
699
699
  ];
700
+ if (accounts.partnerLink) {
701
+ keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
702
+ }
700
703
  let bufferData = Buffer.alloc(createStreamLayout.span);
701
704
  const encodedUIntArray = new TextEncoder().encode(data.name);
702
705
  const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
@@ -747,6 +750,9 @@ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
747
750
  { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
748
751
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
749
752
  ];
753
+ if (accounts.partnerLink) {
754
+ keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
755
+ }
750
756
  if (accounts.payer) {
751
757
  keys.unshift({
752
758
  pubkey: accounts.payer,
@@ -820,6 +826,9 @@ var createStreamV2Instruction = async (data, programId, accounts) => {
820
826
  },
821
827
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
822
828
  ];
829
+ if (accounts.partnerLink) {
830
+ keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
831
+ }
823
832
  let bufferData = Buffer.alloc(createStreamV2Layout.span);
824
833
  const encodedUIntArray = new TextEncoder().encode(data.name);
825
834
  const streamNameBuffer = Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
@@ -871,6 +880,9 @@ var createUncheckedStreamV2Instruction = async (data, programId, accounts) => {
871
880
  { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
872
881
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
873
882
  ];
883
+ if (accounts.partnerLink) {
884
+ keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
885
+ }
874
886
  if (accounts.payer) {
875
887
  keys.unshift({
876
888
  pubkey: accounts.payer,
@@ -3025,6 +3037,10 @@ var SolanaStreamClient = class {
3025
3037
  const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateLinearStreamInstructions(streamParams, extParams);
3026
3038
  return { ixs, metadata, metadataPubKey };
3027
3039
  }
3040
+ /**
3041
+ * Builds instructions for creating an aligned unlock stream.
3042
+ * For Token-2022 mints with a transfer hook, partner link and hook accounts are appended as remaining accounts.
3043
+ */
3028
3044
  async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
3029
3045
  const {
3030
3046
  tokenId: mint,
@@ -3037,6 +3053,7 @@ var SolanaStreamClient = class {
3037
3053
  transferableBySender,
3038
3054
  transferableByRecipient,
3039
3055
  partner,
3056
+ partnerLink,
3040
3057
  recipient,
3041
3058
  cliffAmount,
3042
3059
  amountPerPeriod,
@@ -3066,13 +3083,17 @@ var SolanaStreamClient = class {
3066
3083
  const metadata = !metadataPubKeys ? Keypair.generate() : void 0;
3067
3084
  const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
3068
3085
  invariant(metadataPubKey, "Metadata public key is required");
3069
- let tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : void 0;
3070
- if (!tokenProgramId) {
3071
- tokenProgramId = (await getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
3072
- }
3086
+ const { mint: mintAccount, tokenProgramId: detectedTokenProgramId } = await getMintAndProgram(
3087
+ this.connection,
3088
+ mintPublicKey
3089
+ );
3090
+ const tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : detectedTokenProgramId;
3091
+ const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
3073
3092
  const partnerPublicKey = partner ? new PublicKey(partner) : sender.publicKey;
3074
3093
  const streamflowProgramPublicKey = new PublicKey(this.programId);
3075
3094
  const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
3095
+ const proxyMetadata = deriveContractPDA(this.alignedProxyProgram.programId, metadataPubKey);
3096
+ const proxyTokens = await ata(mintPublicKey, proxyMetadata, tokenProgramId);
3076
3097
  const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
3077
3098
  const ixs = prepareBaseInstructions(this.connection, {
3078
3099
  computePrice,
@@ -3085,7 +3106,7 @@ var SolanaStreamClient = class {
3085
3106
  }
3086
3107
  const encodedUIntArray = new TextEncoder().encode(streamName);
3087
3108
  const streamNameArray = Array.from(encodedUIntArray);
3088
- const createIx = await this.alignedProxyProgram.methods.create({
3109
+ const createMethod = this.alignedProxyProgram.methods.create({
3089
3110
  startTime: new BN3(start),
3090
3111
  netAmountDeposited: depositedAmount,
3091
3112
  period: new BN3(period),
@@ -3121,7 +3142,18 @@ var SolanaStreamClient = class {
3121
3142
  priceOracle: oracle,
3122
3143
  tokenProgram: tokenProgramId,
3123
3144
  streamflowProgram: this.programId
3124
- }).instruction();
3145
+ });
3146
+ const remainingAccounts = partnerLink ? [{ pubkey: new PublicKey(partnerLink.address), isSigner: partnerLink.isSigner, isWritable: false }] : [];
3147
+ const createIx = await (remainingAccounts.length > 0 ? createMethod.remainingAccounts(remainingAccounts) : createMethod).instruction();
3148
+ await this.addTransferHookAccounts(createIx, {
3149
+ mint: mintPublicKey,
3150
+ mintAccount,
3151
+ tokenProgramId,
3152
+ potentialTransfers: [
3153
+ { source: senderTokens, destination: proxyTokens, owner: sender.publicKey },
3154
+ { source: proxyTokens, destination: escrowPDA, owner: proxyMetadata }
3155
+ ]
3156
+ });
3125
3157
  ixs.push(createIx);
3126
3158
  return { ixs, metadata, metadataPubKey };
3127
3159
  }
@@ -3152,6 +3184,7 @@ var SolanaStreamClient = class {
3152
3184
  automaticWithdrawal = false,
3153
3185
  withdrawalFrequency = 0,
3154
3186
  partner,
3187
+ partnerLink,
3155
3188
  tokenProgramId: streamTokenProgramId,
3156
3189
  nonce
3157
3190
  }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
@@ -3173,10 +3206,11 @@ var SolanaStreamClient = class {
3173
3206
  [Buffer.from("strm"), metadataPubKey.toBuffer()],
3174
3207
  this.programId
3175
3208
  );
3176
- let tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : void 0;
3177
- if (!tokenProgramId) {
3178
- tokenProgramId = (await getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
3179
- }
3209
+ const { mint: mintAccount, tokenProgramId: detectedTokenProgramId } = await getMintAndProgram(
3210
+ this.connection,
3211
+ mintPublicKey
3212
+ );
3213
+ const tokenProgramId = streamTokenProgramId ? new PublicKey(streamTokenProgramId) : detectedTokenProgramId;
3180
3214
  const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
3181
3215
  const recipientTokens = await ata(mintPublicKey, recipientPublicKey, tokenProgramId);
3182
3216
  const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
@@ -3200,7 +3234,8 @@ var SolanaStreamClient = class {
3200
3234
  tokenProgram: tokenProgramId,
3201
3235
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
3202
3236
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3203
- systemProgram: SystemProgram.programId
3237
+ systemProgram: SystemProgram.programId,
3238
+ partnerLink: partnerLink ? { pubkey: new PublicKey(partnerLink.address), isSigner: partnerLink.isSigner } : void 0
3204
3239
  };
3205
3240
  const baseData = {
3206
3241
  start: new BN3(start),
@@ -3220,11 +3255,14 @@ var SolanaStreamClient = class {
3220
3255
  name,
3221
3256
  withdrawFrequency: new BN3(automaticWithdrawal ? withdrawalFrequency : period)
3222
3257
  };
3223
- if (nonce != null) {
3224
- ixs.push(await createStreamV2Instruction({ ...baseData, nonce }, this.programId, accounts));
3225
- } else {
3226
- ixs.push(await createStreamInstruction(baseData, this.programId, accounts));
3227
- }
3258
+ const createIx = nonce != null ? await createStreamV2Instruction({ ...baseData, nonce }, this.programId, accounts) : await createStreamInstruction(baseData, this.programId, accounts);
3259
+ await this.addTransferHookAccounts(createIx, {
3260
+ mint: mintPublicKey,
3261
+ mintAccount,
3262
+ tokenProgramId,
3263
+ potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: sender.publicKey }]
3264
+ });
3265
+ ixs.push(createIx);
3228
3266
  return { ixs, metadata, metadataPubKey };
3229
3267
  }
3230
3268
  /**
@@ -3285,6 +3323,7 @@ var SolanaStreamClient = class {
3285
3323
  automaticWithdrawal = false,
3286
3324
  withdrawalFrequency = 0,
3287
3325
  partner,
3326
+ partnerLink,
3288
3327
  nonce
3289
3328
  }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
3290
3329
  assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
@@ -3301,7 +3340,7 @@ var SolanaStreamClient = class {
3301
3340
  [Buffer.from("strm"), metadataPubKey.toBuffer()],
3302
3341
  this.programId
3303
3342
  );
3304
- const { tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
3343
+ const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
3305
3344
  const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
3306
3345
  const partnerPublicKey = partner ? new PublicKey(partner) : sender.publicKey;
3307
3346
  const ixs = prepareBaseInstructions(this.connection, {
@@ -3324,7 +3363,8 @@ var SolanaStreamClient = class {
3324
3363
  timelockProgram: this.programId,
3325
3364
  tokenProgram: tokenProgramId,
3326
3365
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3327
- systemProgram: SystemProgram.programId
3366
+ systemProgram: SystemProgram.programId,
3367
+ partnerLink: partnerLink ? { pubkey: new PublicKey(partnerLink.address), isSigner: partnerLink.isSigner } : void 0
3328
3368
  };
3329
3369
  const baseData = {
3330
3370
  start: new BN3(start),
@@ -3352,6 +3392,12 @@ var SolanaStreamClient = class {
3352
3392
  this.programId,
3353
3393
  accounts
3354
3394
  );
3395
+ await this.addTransferHookAccounts(createInstruction, {
3396
+ mint: mintPublicKey,
3397
+ mintAccount,
3398
+ tokenProgramId,
3399
+ potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: sender.publicKey }]
3400
+ });
3355
3401
  ixs.push(createInstruction);
3356
3402
  } else {
3357
3403
  const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
@@ -3363,6 +3409,12 @@ var SolanaStreamClient = class {
3363
3409
  newAccountPubkey: metadataPubKey
3364
3410
  });
3365
3411
  const createInstruction = await createUncheckedStreamInstruction(baseData, this.programId, accounts);
3412
+ await this.addTransferHookAccounts(createInstruction, {
3413
+ mint: mintPublicKey,
3414
+ mintAccount,
3415
+ tokenProgramId,
3416
+ potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: sender.publicKey }]
3417
+ });
3366
3418
  ixs.push(createMetadataInstruction, createInstruction);
3367
3419
  }
3368
3420
  return { ixs, metadata, metadataPubKey };
@@ -3393,6 +3445,12 @@ var SolanaStreamClient = class {
3393
3445
  ...extParams,
3394
3446
  metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
3395
3447
  };
3448
+ const wrapInstructions = [];
3449
+ if (isNative) {
3450
+ const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
3451
+ const recipientAmount = calculateTotalAmountToDeposit(recipientData.amount, totalFee);
3452
+ wrapInstructions.push(...await prepareWrappedAccount(this.connection, sender.publicKey, recipientAmount));
3453
+ }
3396
3454
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
3397
3455
  createStreamData,
3398
3456
  createStreamExtParams
@@ -3403,17 +3461,12 @@ var SolanaStreamClient = class {
3403
3461
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
3404
3462
  metadatas.push(metadataPubKey.toBase58());
3405
3463
  instructionsBatch.push({
3406
- ixs,
3464
+ ixs: [...wrapInstructions, ...ixs],
3407
3465
  metadata,
3408
3466
  recipient: recipientData.recipient
3409
3467
  });
3410
3468
  }
3411
3469
  const prepareInstructions = await this.getCreateATAInstructions([partnerPublicKey], mintPublicKey, sender, true);
3412
- if (isNative) {
3413
- const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN3(0));
3414
- const nativeInstructions = await prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
3415
- prepareInstructions.push(...nativeInstructions);
3416
- }
3417
3470
  return {
3418
3471
  instructionsBatch,
3419
3472
  metadatas,
@@ -3643,7 +3696,7 @@ var SolanaStreamClient = class {
3643
3696
  invariant(escrow?.data, "Couldn't get account info");
3644
3697
  const data = decodeStream(escrow.data);
3645
3698
  const { sender, recipient, mint, streamflowTreasury, partner, recipientTokens, escrowTokens } = data;
3646
- const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
3699
+ const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mint);
3647
3700
  const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3648
3701
  const partnerTokens = await ata(mint, partner, tokenProgramId);
3649
3702
  const ataIx = await this.getCreateATAInstructions(
@@ -3653,22 +3706,30 @@ var SolanaStreamClient = class {
3653
3706
  checkTokenAccounts,
3654
3707
  tokenProgramId
3655
3708
  );
3656
- ixs.push(
3657
- ...ataIx,
3658
- await withdrawStreamInstruction(amount, this.programId, {
3659
- partner,
3660
- partnerTokens,
3661
- mint,
3662
- streamflowTreasuryTokens,
3663
- recipientTokens,
3664
- escrowTokens,
3665
- authority: invoker.publicKey,
3666
- recipient: invoker.publicKey,
3667
- metadata: streamPublicKey,
3668
- streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3669
- tokenProgram: tokenProgramId
3670
- })
3671
- );
3709
+ const withdrawIx = await withdrawStreamInstruction(amount, this.programId, {
3710
+ partner,
3711
+ partnerTokens,
3712
+ mint,
3713
+ streamflowTreasuryTokens,
3714
+ recipientTokens,
3715
+ escrowTokens,
3716
+ authority: invoker.publicKey,
3717
+ recipient: invoker.publicKey,
3718
+ metadata: streamPublicKey,
3719
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3720
+ tokenProgram: tokenProgramId
3721
+ });
3722
+ await this.addTransferHookAccounts(withdrawIx, {
3723
+ mint,
3724
+ mintAccount,
3725
+ tokenProgramId,
3726
+ potentialTransfers: [
3727
+ { source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
3728
+ { source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
3729
+ { source: escrowTokens, destination: partnerTokens, owner: streamPublicKey }
3730
+ ]
3731
+ });
3732
+ ixs.push(...ataIx, withdrawIx);
3672
3733
  return ixs;
3673
3734
  }
3674
3735
  /**
@@ -3707,8 +3768,7 @@ var SolanaStreamClient = class {
3707
3768
  }
3708
3769
  const decoded = decodeStream(account.data);
3709
3770
  const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender);
3710
- const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3711
- return ixs;
3771
+ return isAlignedUnlock ? this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : this.prepareCancelLinearStream(cancelData, extParams);
3712
3772
  }
3713
3773
  /**
3714
3774
  * Creates Transaction Instructions for cancel
@@ -3723,7 +3783,13 @@ var SolanaStreamClient = class {
3723
3783
  invariant(escrowAcc?.data, "Couldn't get account info");
3724
3784
  const streamData = decodeStream(escrowAcc.data);
3725
3785
  const { sender, recipient, mint, streamflowTreasury, partner, escrowTokens } = streamData;
3726
- const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
3786
+ const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mint);
3787
+ const senderTokens = await ata(mint, sender, tokenProgramId);
3788
+ const recipientTokens = await ata(mint, recipient, tokenProgramId);
3789
+ const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3790
+ const partnerTokens = await ata(mint, partner, tokenProgramId);
3791
+ const proxyMetadata = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3792
+ const proxyTokens = await ata(mint, proxyMetadata, tokenProgramId);
3727
3793
  const ixs = prepareBaseInstructions(this.connection, {
3728
3794
  computePrice,
3729
3795
  computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT
@@ -3735,7 +3801,7 @@ var SolanaStreamClient = class {
3735
3801
  checkTokenAccounts,
3736
3802
  tokenProgramId
3737
3803
  );
3738
- const cancelIx = await this.alignedProxyProgram.methods.cancel().accountsPartial({
3804
+ const cancelMethod = this.alignedProxyProgram.methods.cancel().accountsPartial({
3739
3805
  mint,
3740
3806
  partner,
3741
3807
  recipient,
@@ -3745,7 +3811,20 @@ var SolanaStreamClient = class {
3745
3811
  streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3746
3812
  tokenProgram: tokenProgramId,
3747
3813
  streamflowProgram: this.programId
3748
- }).instruction();
3814
+ });
3815
+ const cancelIx = await cancelMethod.instruction();
3816
+ await this.addTransferHookAccounts(cancelIx, {
3817
+ mint,
3818
+ mintAccount,
3819
+ tokenProgramId,
3820
+ potentialTransfers: [
3821
+ { source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
3822
+ { source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
3823
+ { source: escrowTokens, destination: partnerTokens, owner: streamPublicKey },
3824
+ { source: escrowTokens, destination: proxyTokens, owner: streamPublicKey },
3825
+ { source: proxyTokens, destination: senderTokens, owner: proxyMetadata }
3826
+ ]
3827
+ });
3749
3828
  ixs.push(...ataIx, cancelIx);
3750
3829
  return ixs;
3751
3830
  }
@@ -3762,7 +3841,7 @@ var SolanaStreamClient = class {
3762
3841
  invariant(escrowAcc?.data, "Couldn't get account info");
3763
3842
  const data = decodeStream(escrowAcc.data);
3764
3843
  const { sender, recipient, partner, streamflowTreasury, mint, senderTokens, recipientTokens, escrowTokens } = data;
3765
- const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
3844
+ const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mint);
3766
3845
  const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3767
3846
  const partnerTokens = await ata(mint, partner, tokenProgramId);
3768
3847
  const ixs = prepareBaseInstructions(this.connection, {
@@ -3776,24 +3855,33 @@ var SolanaStreamClient = class {
3776
3855
  checkTokenAccounts,
3777
3856
  tokenProgramId
3778
3857
  );
3779
- ixs.push(
3780
- ...ixsAta,
3781
- await cancelStreamInstruction(this.programId, {
3782
- sender,
3783
- senderTokens,
3784
- recipient,
3785
- recipientTokens,
3786
- streamflowTreasuryTokens,
3787
- partner,
3788
- partnerTokens,
3789
- mint,
3790
- escrowTokens,
3791
- authority: invoker.publicKey,
3792
- metadata: streamPublicKey,
3793
- streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3794
- tokenProgram: tokenProgramId
3795
- })
3796
- );
3858
+ const cancelIx = await cancelStreamInstruction(this.programId, {
3859
+ sender,
3860
+ senderTokens,
3861
+ recipient,
3862
+ recipientTokens,
3863
+ streamflowTreasuryTokens,
3864
+ partner,
3865
+ partnerTokens,
3866
+ mint,
3867
+ escrowTokens,
3868
+ authority: invoker.publicKey,
3869
+ metadata: streamPublicKey,
3870
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3871
+ tokenProgram: tokenProgramId
3872
+ });
3873
+ await this.addTransferHookAccounts(cancelIx, {
3874
+ mint,
3875
+ mintAccount,
3876
+ tokenProgramId,
3877
+ potentialTransfers: [
3878
+ { source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
3879
+ { source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
3880
+ { source: escrowTokens, destination: partnerTokens, owner: streamPublicKey },
3881
+ { source: escrowTokens, destination: senderTokens, owner: streamPublicKey }
3882
+ ]
3883
+ });
3884
+ ixs.push(...ixsAta, cancelIx);
3797
3885
  return ixs;
3798
3886
  }
3799
3887
  /**
@@ -3896,28 +3984,35 @@ var SolanaStreamClient = class {
3896
3984
  throw new Error("Couldn't get account info");
3897
3985
  }
3898
3986
  const { mint, partner, senderTokens, escrowTokens } = decodeStream(escrow?.data);
3899
- const { tokenProgramId } = await getMintAndProgram(this.connection, mint);
3987
+ const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mint);
3900
3988
  const streamflowTreasuryTokens = await ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3901
3989
  const partnerTokens = await ata(mint, partner, tokenProgramId);
3990
+ const totalFee = await this.getTotalFee({ address: partner.toBase58() });
3991
+ const totalAmountToTransfer = calculateTotalAmountToDeposit(amount, totalFee);
3902
3992
  if (isNative) {
3903
- ixs.push(...await prepareWrappedAccount(this.connection, invoker.publicKey, amount));
3993
+ ixs.push(...await prepareWrappedAccount(this.connection, invoker.publicKey, totalAmountToTransfer));
3904
3994
  }
3905
- ixs.push(
3906
- await topupStreamInstruction(amount, this.programId, {
3907
- sender: invoker.publicKey,
3908
- senderTokens,
3909
- metadata: streamPublicKey,
3910
- escrowTokens,
3911
- streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3912
- streamflowTreasuryTokens,
3913
- partner,
3914
- partnerTokens,
3915
- mint,
3916
- tokenProgram: tokenProgramId,
3917
- withdrawor: WITHDRAWOR_PUBLIC_KEY,
3918
- systemProgram: SystemProgram.programId
3919
- })
3920
- );
3995
+ const topupIx = await topupStreamInstruction(amount, this.programId, {
3996
+ sender: invoker.publicKey,
3997
+ senderTokens,
3998
+ metadata: streamPublicKey,
3999
+ escrowTokens,
4000
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
4001
+ streamflowTreasuryTokens,
4002
+ partner,
4003
+ partnerTokens,
4004
+ mint,
4005
+ tokenProgram: tokenProgramId,
4006
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
4007
+ systemProgram: SystemProgram.programId
4008
+ });
4009
+ await this.addTransferHookAccounts(topupIx, {
4010
+ mint,
4011
+ mintAccount,
4012
+ tokenProgramId,
4013
+ potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: invoker.publicKey }]
4014
+ });
4015
+ ixs.push(topupIx);
3921
4016
  return ixs;
3922
4017
  }
3923
4018
  /**
@@ -4323,6 +4418,40 @@ var SolanaStreamClient = class {
4323
4418
  }
4324
4419
  return { metadata, metadataPubKey };
4325
4420
  }
4421
+ /**
4422
+ * Returns the configured transfer hook program for a Token-2022 mint, if present.
4423
+ */
4424
+ getTransferHookProgramId(mintAccount, tokenProgramId) {
4425
+ if (!tokenProgramId.equals(TOKEN_2022_PROGRAM_ID)) {
4426
+ return null;
4427
+ }
4428
+ return getTransferHook(mintAccount)?.programId ?? null;
4429
+ }
4430
+ /**
4431
+ * Appends transfer-hook extra metas for each potential token transfer performed by the instruction.
4432
+ *
4433
+ * Transfer hook may rely on additional accounts/PDAs - derivation path is configured on the transfer hook metadata account, so for each potential transfer we need to check whether these accounts are needed and add them.
4434
+ */
4435
+ async addTransferHookAccounts(instruction, params) {
4436
+ const { mint, mintAccount, tokenProgramId, potentialTransfers } = params;
4437
+ const transferHookProgramId = this.getTransferHookProgramId(mintAccount, tokenProgramId);
4438
+ if (!transferHookProgramId) {
4439
+ return;
4440
+ }
4441
+ for (const transfer of potentialTransfers) {
4442
+ await addExtraAccountMetasForExecute(
4443
+ this.connection,
4444
+ instruction,
4445
+ transferHookProgramId,
4446
+ transfer.source,
4447
+ mint,
4448
+ transfer.destination,
4449
+ transfer.owner,
4450
+ 1n,
4451
+ this.getCommitment()
4452
+ );
4453
+ }
4454
+ }
4326
4455
  /**
4327
4456
  * Returns insrtuctions for creating associated token accounts for the provided owners
4328
4457
  */