@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.
@@ -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.cjs';
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.cjs';
2
2
  export { ContractError, ICluster, getBN, getNumberFromBN } from '@streamflow/common';
3
3
  import 'p-queue';
4
4
  import '@solana/web3.js';
@@ -723,6 +723,9 @@ var createStreamInstruction = async (data, programId, accounts) => {
723
723
  },
724
724
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
725
725
  ];
726
+ if (accounts.partnerLink) {
727
+ keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
728
+ }
726
729
  let bufferData = buffer.Buffer.alloc(createStreamLayout.span);
727
730
  const encodedUIntArray = new TextEncoder().encode(data.name);
728
731
  const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
@@ -773,6 +776,9 @@ var createUncheckedStreamInstruction = async (data, programId, accounts) => {
773
776
  { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
774
777
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
775
778
  ];
779
+ if (accounts.partnerLink) {
780
+ keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
781
+ }
776
782
  if (accounts.payer) {
777
783
  keys.unshift({
778
784
  pubkey: accounts.payer,
@@ -846,6 +852,9 @@ var createStreamV2Instruction = async (data, programId, accounts) => {
846
852
  },
847
853
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
848
854
  ];
855
+ if (accounts.partnerLink) {
856
+ keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
857
+ }
849
858
  let bufferData = buffer.Buffer.alloc(createStreamV2Layout.span);
850
859
  const encodedUIntArray = new TextEncoder().encode(data.name);
851
860
  const streamNameBuffer = buffer.Buffer.alloc(64).fill(encodedUIntArray, 0, encodedUIntArray.byteLength);
@@ -897,6 +906,9 @@ var createUncheckedStreamV2Instruction = async (data, programId, accounts) => {
897
906
  { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
898
907
  { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }
899
908
  ];
909
+ if (accounts.partnerLink) {
910
+ keys.push({ pubkey: accounts.partnerLink.pubkey, isSigner: accounts.partnerLink.isSigner, isWritable: false });
911
+ }
900
912
  if (accounts.payer) {
901
913
  keys.unshift({
902
914
  pubkey: accounts.payer,
@@ -3051,6 +3063,10 @@ var SolanaStreamClient = class {
3051
3063
  const { ixs, metadata, metadataPubKey } = isCreateAlignedStreamData(streamParams) ? await this.prepareCreateAlignedUnlockInstructions(streamParams, extParams) : await this.prepareCreateLinearStreamInstructions(streamParams, extParams);
3052
3064
  return { ixs, metadata, metadataPubKey };
3053
3065
  }
3066
+ /**
3067
+ * Builds instructions for creating an aligned unlock stream.
3068
+ * For Token-2022 mints with a transfer hook, partner link and hook accounts are appended as remaining accounts.
3069
+ */
3054
3070
  async prepareCreateAlignedUnlockInstructions(streamParams, extParams) {
3055
3071
  const {
3056
3072
  tokenId: mint,
@@ -3063,6 +3079,7 @@ var SolanaStreamClient = class {
3063
3079
  transferableBySender,
3064
3080
  transferableByRecipient,
3065
3081
  partner,
3082
+ partnerLink,
3066
3083
  recipient,
3067
3084
  cliffAmount,
3068
3085
  amountPerPeriod,
@@ -3092,13 +3109,17 @@ var SolanaStreamClient = class {
3092
3109
  const metadata = !metadataPubKeys ? web3_js.Keypair.generate() : void 0;
3093
3110
  const metadataPubKey = metadata ? metadata.publicKey : metadataPubKeys[0];
3094
3111
  common.invariant(metadataPubKey, "Metadata public key is required");
3095
- let tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : void 0;
3096
- if (!tokenProgramId) {
3097
- tokenProgramId = (await common.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
3098
- }
3112
+ const { mint: mintAccount, tokenProgramId: detectedTokenProgramId } = await common.getMintAndProgram(
3113
+ this.connection,
3114
+ mintPublicKey
3115
+ );
3116
+ const tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : detectedTokenProgramId;
3117
+ const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
3099
3118
  const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
3100
3119
  const streamflowProgramPublicKey = new web3_js.PublicKey(this.programId);
3101
3120
  const escrowPDA = deriveEscrowPDA(streamflowProgramPublicKey, metadataPubKey);
3121
+ const proxyMetadata = deriveContractPDA(this.alignedProxyProgram.programId, metadataPubKey);
3122
+ const proxyTokens = await common.ata(mintPublicKey, proxyMetadata, tokenProgramId);
3102
3123
  const oracle = priceOracle ?? deriveTestOraclePDA(this.alignedProxyProgram.programId, mintPublicKey, sender.publicKey);
3103
3124
  const ixs = common.prepareBaseInstructions(this.connection, {
3104
3125
  computePrice,
@@ -3111,7 +3132,7 @@ var SolanaStreamClient = class {
3111
3132
  }
3112
3133
  const encodedUIntArray = new TextEncoder().encode(streamName);
3113
3134
  const streamNameArray = Array.from(encodedUIntArray);
3114
- const createIx = await this.alignedProxyProgram.methods.create({
3135
+ const createMethod = this.alignedProxyProgram.methods.create({
3115
3136
  startTime: new BN3__default.default(start),
3116
3137
  netAmountDeposited: depositedAmount,
3117
3138
  period: new BN3__default.default(period),
@@ -3147,7 +3168,18 @@ var SolanaStreamClient = class {
3147
3168
  priceOracle: oracle,
3148
3169
  tokenProgram: tokenProgramId,
3149
3170
  streamflowProgram: this.programId
3150
- }).instruction();
3171
+ });
3172
+ const remainingAccounts = partnerLink ? [{ pubkey: new web3_js.PublicKey(partnerLink.address), isSigner: partnerLink.isSigner, isWritable: false }] : [];
3173
+ const createIx = await (remainingAccounts.length > 0 ? createMethod.remainingAccounts(remainingAccounts) : createMethod).instruction();
3174
+ await this.addTransferHookAccounts(createIx, {
3175
+ mint: mintPublicKey,
3176
+ mintAccount,
3177
+ tokenProgramId,
3178
+ potentialTransfers: [
3179
+ { source: senderTokens, destination: proxyTokens, owner: sender.publicKey },
3180
+ { source: proxyTokens, destination: escrowPDA, owner: proxyMetadata }
3181
+ ]
3182
+ });
3151
3183
  ixs.push(createIx);
3152
3184
  return { ixs, metadata, metadataPubKey };
3153
3185
  }
@@ -3178,6 +3210,7 @@ var SolanaStreamClient = class {
3178
3210
  automaticWithdrawal = false,
3179
3211
  withdrawalFrequency = 0,
3180
3212
  partner,
3213
+ partnerLink,
3181
3214
  tokenProgramId: streamTokenProgramId,
3182
3215
  nonce
3183
3216
  }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
@@ -3199,10 +3232,11 @@ var SolanaStreamClient = class {
3199
3232
  [buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
3200
3233
  this.programId
3201
3234
  );
3202
- let tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : void 0;
3203
- if (!tokenProgramId) {
3204
- tokenProgramId = (await common.getMintAndProgram(this.connection, mintPublicKey)).tokenProgramId;
3205
- }
3235
+ const { mint: mintAccount, tokenProgramId: detectedTokenProgramId } = await common.getMintAndProgram(
3236
+ this.connection,
3237
+ mintPublicKey
3238
+ );
3239
+ const tokenProgramId = streamTokenProgramId ? new web3_js.PublicKey(streamTokenProgramId) : detectedTokenProgramId;
3206
3240
  const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
3207
3241
  const recipientTokens = await common.ata(mintPublicKey, recipientPublicKey, tokenProgramId);
3208
3242
  const streamflowTreasuryTokens = await common.ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
@@ -3226,7 +3260,8 @@ var SolanaStreamClient = class {
3226
3260
  tokenProgram: tokenProgramId,
3227
3261
  associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
3228
3262
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3229
- systemProgram: web3_js.SystemProgram.programId
3263
+ systemProgram: web3_js.SystemProgram.programId,
3264
+ partnerLink: partnerLink ? { pubkey: new web3_js.PublicKey(partnerLink.address), isSigner: partnerLink.isSigner } : void 0
3230
3265
  };
3231
3266
  const baseData = {
3232
3267
  start: new BN3__default.default(start),
@@ -3246,11 +3281,14 @@ var SolanaStreamClient = class {
3246
3281
  name,
3247
3282
  withdrawFrequency: new BN3__default.default(automaticWithdrawal ? withdrawalFrequency : period)
3248
3283
  };
3249
- if (nonce != null) {
3250
- ixs.push(await createStreamV2Instruction({ ...baseData, nonce }, this.programId, accounts));
3251
- } else {
3252
- ixs.push(await createStreamInstruction(baseData, this.programId, accounts));
3253
- }
3284
+ const createIx = nonce != null ? await createStreamV2Instruction({ ...baseData, nonce }, this.programId, accounts) : await createStreamInstruction(baseData, this.programId, accounts);
3285
+ await this.addTransferHookAccounts(createIx, {
3286
+ mint: mintPublicKey,
3287
+ mintAccount,
3288
+ tokenProgramId,
3289
+ potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: sender.publicKey }]
3290
+ });
3291
+ ixs.push(createIx);
3254
3292
  return { ixs, metadata, metadataPubKey };
3255
3293
  }
3256
3294
  /**
@@ -3311,6 +3349,7 @@ var SolanaStreamClient = class {
3311
3349
  automaticWithdrawal = false,
3312
3350
  withdrawalFrequency = 0,
3313
3351
  partner,
3352
+ partnerLink,
3314
3353
  nonce
3315
3354
  }, { sender, metadataPubKeys, isNative = false, computePrice, computeLimit }) {
3316
3355
  common.assertHasPublicKey(sender, "Sender's PublicKey is not available, check passed wallet adapter!");
@@ -3327,7 +3366,7 @@ var SolanaStreamClient = class {
3327
3366
  [buffer.Buffer.from("strm"), metadataPubKey.toBuffer()],
3328
3367
  this.programId
3329
3368
  );
3330
- const { tokenProgramId } = await common.getMintAndProgram(this.connection, mintPublicKey);
3369
+ const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mintPublicKey);
3331
3370
  const senderTokens = await common.ata(mintPublicKey, sender.publicKey, tokenProgramId);
3332
3371
  const partnerPublicKey = partner ? new web3_js.PublicKey(partner) : sender.publicKey;
3333
3372
  const ixs = common.prepareBaseInstructions(this.connection, {
@@ -3350,7 +3389,8 @@ var SolanaStreamClient = class {
3350
3389
  timelockProgram: this.programId,
3351
3390
  tokenProgram: tokenProgramId,
3352
3391
  withdrawor: WITHDRAWOR_PUBLIC_KEY,
3353
- systemProgram: web3_js.SystemProgram.programId
3392
+ systemProgram: web3_js.SystemProgram.programId,
3393
+ partnerLink: partnerLink ? { pubkey: new web3_js.PublicKey(partnerLink.address), isSigner: partnerLink.isSigner } : void 0
3354
3394
  };
3355
3395
  const baseData = {
3356
3396
  start: new BN3__default.default(start),
@@ -3378,6 +3418,12 @@ var SolanaStreamClient = class {
3378
3418
  this.programId,
3379
3419
  accounts
3380
3420
  );
3421
+ await this.addTransferHookAccounts(createInstruction, {
3422
+ mint: mintPublicKey,
3423
+ mintAccount,
3424
+ tokenProgramId,
3425
+ potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: sender.publicKey }]
3426
+ });
3381
3427
  ixs.push(createInstruction);
3382
3428
  } else {
3383
3429
  const rentToExempt = await this.connection.getMinimumBalanceForRentExemption(METADATA_ACC_SIZE);
@@ -3389,6 +3435,12 @@ var SolanaStreamClient = class {
3389
3435
  newAccountPubkey: metadataPubKey
3390
3436
  });
3391
3437
  const createInstruction = await createUncheckedStreamInstruction(baseData, this.programId, accounts);
3438
+ await this.addTransferHookAccounts(createInstruction, {
3439
+ mint: mintPublicKey,
3440
+ mintAccount,
3441
+ tokenProgramId,
3442
+ potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: sender.publicKey }]
3443
+ });
3392
3444
  ixs.push(createMetadataInstruction, createInstruction);
3393
3445
  }
3394
3446
  return { ixs, metadata, metadataPubKey };
@@ -3419,6 +3471,12 @@ var SolanaStreamClient = class {
3419
3471
  ...extParams,
3420
3472
  metadataPubKeys: metadataPubKeysExt?.[i] ? [metadataPubKeysExt[i]] : void 0
3421
3473
  };
3474
+ const wrapInstructions = [];
3475
+ if (isNative) {
3476
+ const totalFee = await this.getTotalFee({ address: partnerPublicKey.toString() });
3477
+ const recipientAmount = calculateTotalAmountToDeposit(recipientData.amount, totalFee);
3478
+ wrapInstructions.push(...await common.prepareWrappedAccount(this.connection, sender.publicKey, recipientAmount));
3479
+ }
3422
3480
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(
3423
3481
  createStreamData,
3424
3482
  createStreamExtParams
@@ -3429,17 +3487,12 @@ var SolanaStreamClient = class {
3429
3487
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
3430
3488
  metadatas.push(metadataPubKey.toBase58());
3431
3489
  instructionsBatch.push({
3432
- ixs,
3490
+ ixs: [...wrapInstructions, ...ixs],
3433
3491
  metadata,
3434
3492
  recipient: recipientData.recipient
3435
3493
  });
3436
3494
  }
3437
3495
  const prepareInstructions = await this.getCreateATAInstructions([partnerPublicKey], mintPublicKey, sender, true);
3438
- if (isNative) {
3439
- const totalDepositedAmount = recipients.reduce((acc, recipient) => recipient.amount.add(acc), new BN3__default.default(0));
3440
- const nativeInstructions = await common.prepareWrappedAccount(this.connection, sender.publicKey, totalDepositedAmount);
3441
- prepareInstructions.push(...nativeInstructions);
3442
- }
3443
3496
  return {
3444
3497
  instructionsBatch,
3445
3498
  metadatas,
@@ -3669,7 +3722,7 @@ var SolanaStreamClient = class {
3669
3722
  common.invariant(escrow?.data, "Couldn't get account info");
3670
3723
  const data = decodeStream(escrow.data);
3671
3724
  const { sender, recipient, mint, streamflowTreasury, partner, recipientTokens, escrowTokens } = data;
3672
- const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3725
+ const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3673
3726
  const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3674
3727
  const partnerTokens = await common.ata(mint, partner, tokenProgramId);
3675
3728
  const ataIx = await this.getCreateATAInstructions(
@@ -3679,22 +3732,30 @@ var SolanaStreamClient = class {
3679
3732
  checkTokenAccounts,
3680
3733
  tokenProgramId
3681
3734
  );
3682
- ixs.push(
3683
- ...ataIx,
3684
- await withdrawStreamInstruction(amount, this.programId, {
3685
- partner,
3686
- partnerTokens,
3687
- mint,
3688
- streamflowTreasuryTokens,
3689
- recipientTokens,
3690
- escrowTokens,
3691
- authority: invoker.publicKey,
3692
- recipient: invoker.publicKey,
3693
- metadata: streamPublicKey,
3694
- streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3695
- tokenProgram: tokenProgramId
3696
- })
3697
- );
3735
+ const withdrawIx = await withdrawStreamInstruction(amount, this.programId, {
3736
+ partner,
3737
+ partnerTokens,
3738
+ mint,
3739
+ streamflowTreasuryTokens,
3740
+ recipientTokens,
3741
+ escrowTokens,
3742
+ authority: invoker.publicKey,
3743
+ recipient: invoker.publicKey,
3744
+ metadata: streamPublicKey,
3745
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3746
+ tokenProgram: tokenProgramId
3747
+ });
3748
+ await this.addTransferHookAccounts(withdrawIx, {
3749
+ mint,
3750
+ mintAccount,
3751
+ tokenProgramId,
3752
+ potentialTransfers: [
3753
+ { source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
3754
+ { source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
3755
+ { source: escrowTokens, destination: partnerTokens, owner: streamPublicKey }
3756
+ ]
3757
+ });
3758
+ ixs.push(...ataIx, withdrawIx);
3698
3759
  return ixs;
3699
3760
  }
3700
3761
  /**
@@ -3733,8 +3794,7 @@ var SolanaStreamClient = class {
3733
3794
  }
3734
3795
  const decoded = decodeStream(account.data);
3735
3796
  const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender);
3736
- const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3737
- return ixs;
3797
+ return isAlignedUnlock ? this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : this.prepareCancelLinearStream(cancelData, extParams);
3738
3798
  }
3739
3799
  /**
3740
3800
  * Creates Transaction Instructions for cancel
@@ -3749,7 +3809,13 @@ var SolanaStreamClient = class {
3749
3809
  common.invariant(escrowAcc?.data, "Couldn't get account info");
3750
3810
  const streamData = decodeStream(escrowAcc.data);
3751
3811
  const { sender, recipient, mint, streamflowTreasury, partner, escrowTokens } = streamData;
3752
- const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3812
+ const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3813
+ const senderTokens = await common.ata(mint, sender, tokenProgramId);
3814
+ const recipientTokens = await common.ata(mint, recipient, tokenProgramId);
3815
+ const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3816
+ const partnerTokens = await common.ata(mint, partner, tokenProgramId);
3817
+ const proxyMetadata = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3818
+ const proxyTokens = await common.ata(mint, proxyMetadata, tokenProgramId);
3753
3819
  const ixs = common.prepareBaseInstructions(this.connection, {
3754
3820
  computePrice,
3755
3821
  computeLimit: computeLimit ?? ALIGNED_COMPUTE_LIMIT
@@ -3761,7 +3827,7 @@ var SolanaStreamClient = class {
3761
3827
  checkTokenAccounts,
3762
3828
  tokenProgramId
3763
3829
  );
3764
- const cancelIx = await this.alignedProxyProgram.methods.cancel().accountsPartial({
3830
+ const cancelMethod = this.alignedProxyProgram.methods.cancel().accountsPartial({
3765
3831
  mint,
3766
3832
  partner,
3767
3833
  recipient,
@@ -3771,7 +3837,20 @@ var SolanaStreamClient = class {
3771
3837
  streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3772
3838
  tokenProgram: tokenProgramId,
3773
3839
  streamflowProgram: this.programId
3774
- }).instruction();
3840
+ });
3841
+ const cancelIx = await cancelMethod.instruction();
3842
+ await this.addTransferHookAccounts(cancelIx, {
3843
+ mint,
3844
+ mintAccount,
3845
+ tokenProgramId,
3846
+ potentialTransfers: [
3847
+ { source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
3848
+ { source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
3849
+ { source: escrowTokens, destination: partnerTokens, owner: streamPublicKey },
3850
+ { source: escrowTokens, destination: proxyTokens, owner: streamPublicKey },
3851
+ { source: proxyTokens, destination: senderTokens, owner: proxyMetadata }
3852
+ ]
3853
+ });
3775
3854
  ixs.push(...ataIx, cancelIx);
3776
3855
  return ixs;
3777
3856
  }
@@ -3788,7 +3867,7 @@ var SolanaStreamClient = class {
3788
3867
  common.invariant(escrowAcc?.data, "Couldn't get account info");
3789
3868
  const data = decodeStream(escrowAcc.data);
3790
3869
  const { sender, recipient, partner, streamflowTreasury, mint, senderTokens, recipientTokens, escrowTokens } = data;
3791
- const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3870
+ const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3792
3871
  const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3793
3872
  const partnerTokens = await common.ata(mint, partner, tokenProgramId);
3794
3873
  const ixs = common.prepareBaseInstructions(this.connection, {
@@ -3802,24 +3881,33 @@ var SolanaStreamClient = class {
3802
3881
  checkTokenAccounts,
3803
3882
  tokenProgramId
3804
3883
  );
3805
- ixs.push(
3806
- ...ixsAta,
3807
- await cancelStreamInstruction(this.programId, {
3808
- sender,
3809
- senderTokens,
3810
- recipient,
3811
- recipientTokens,
3812
- streamflowTreasuryTokens,
3813
- partner,
3814
- partnerTokens,
3815
- mint,
3816
- escrowTokens,
3817
- authority: invoker.publicKey,
3818
- metadata: streamPublicKey,
3819
- streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3820
- tokenProgram: tokenProgramId
3821
- })
3822
- );
3884
+ const cancelIx = await cancelStreamInstruction(this.programId, {
3885
+ sender,
3886
+ senderTokens,
3887
+ recipient,
3888
+ recipientTokens,
3889
+ streamflowTreasuryTokens,
3890
+ partner,
3891
+ partnerTokens,
3892
+ mint,
3893
+ escrowTokens,
3894
+ authority: invoker.publicKey,
3895
+ metadata: streamPublicKey,
3896
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3897
+ tokenProgram: tokenProgramId
3898
+ });
3899
+ await this.addTransferHookAccounts(cancelIx, {
3900
+ mint,
3901
+ mintAccount,
3902
+ tokenProgramId,
3903
+ potentialTransfers: [
3904
+ { source: escrowTokens, destination: recipientTokens, owner: streamPublicKey },
3905
+ { source: escrowTokens, destination: streamflowTreasuryTokens, owner: streamPublicKey },
3906
+ { source: escrowTokens, destination: partnerTokens, owner: streamPublicKey },
3907
+ { source: escrowTokens, destination: senderTokens, owner: streamPublicKey }
3908
+ ]
3909
+ });
3910
+ ixs.push(...ixsAta, cancelIx);
3823
3911
  return ixs;
3824
3912
  }
3825
3913
  /**
@@ -3922,28 +4010,35 @@ var SolanaStreamClient = class {
3922
4010
  throw new Error("Couldn't get account info");
3923
4011
  }
3924
4012
  const { mint, partner, senderTokens, escrowTokens } = decodeStream(escrow?.data);
3925
- const { tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
4013
+ const { mint: mintAccount, tokenProgramId } = await common.getMintAndProgram(this.connection, mint);
3926
4014
  const streamflowTreasuryTokens = await common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
3927
4015
  const partnerTokens = await common.ata(mint, partner, tokenProgramId);
4016
+ const totalFee = await this.getTotalFee({ address: partner.toBase58() });
4017
+ const totalAmountToTransfer = calculateTotalAmountToDeposit(amount, totalFee);
3928
4018
  if (isNative) {
3929
- ixs.push(...await common.prepareWrappedAccount(this.connection, invoker.publicKey, amount));
4019
+ ixs.push(...await common.prepareWrappedAccount(this.connection, invoker.publicKey, totalAmountToTransfer));
3930
4020
  }
3931
- ixs.push(
3932
- await topupStreamInstruction(amount, this.programId, {
3933
- sender: invoker.publicKey,
3934
- senderTokens,
3935
- metadata: streamPublicKey,
3936
- escrowTokens,
3937
- streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
3938
- streamflowTreasuryTokens,
3939
- partner,
3940
- partnerTokens,
3941
- mint,
3942
- tokenProgram: tokenProgramId,
3943
- withdrawor: WITHDRAWOR_PUBLIC_KEY,
3944
- systemProgram: web3_js.SystemProgram.programId
3945
- })
3946
- );
4021
+ const topupIx = await topupStreamInstruction(amount, this.programId, {
4022
+ sender: invoker.publicKey,
4023
+ senderTokens,
4024
+ metadata: streamPublicKey,
4025
+ escrowTokens,
4026
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
4027
+ streamflowTreasuryTokens,
4028
+ partner,
4029
+ partnerTokens,
4030
+ mint,
4031
+ tokenProgram: tokenProgramId,
4032
+ withdrawor: WITHDRAWOR_PUBLIC_KEY,
4033
+ systemProgram: web3_js.SystemProgram.programId
4034
+ });
4035
+ await this.addTransferHookAccounts(topupIx, {
4036
+ mint,
4037
+ mintAccount,
4038
+ tokenProgramId,
4039
+ potentialTransfers: [{ source: senderTokens, destination: escrowTokens, owner: invoker.publicKey }]
4040
+ });
4041
+ ixs.push(topupIx);
3947
4042
  return ixs;
3948
4043
  }
3949
4044
  /**
@@ -4349,6 +4444,40 @@ var SolanaStreamClient = class {
4349
4444
  }
4350
4445
  return { metadata, metadataPubKey };
4351
4446
  }
4447
+ /**
4448
+ * Returns the configured transfer hook program for a Token-2022 mint, if present.
4449
+ */
4450
+ getTransferHookProgramId(mintAccount, tokenProgramId) {
4451
+ if (!tokenProgramId.equals(splToken.TOKEN_2022_PROGRAM_ID)) {
4452
+ return null;
4453
+ }
4454
+ return splToken.getTransferHook(mintAccount)?.programId ?? null;
4455
+ }
4456
+ /**
4457
+ * Appends transfer-hook extra metas for each potential token transfer performed by the instruction.
4458
+ *
4459
+ * 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.
4460
+ */
4461
+ async addTransferHookAccounts(instruction, params) {
4462
+ const { mint, mintAccount, tokenProgramId, potentialTransfers } = params;
4463
+ const transferHookProgramId = this.getTransferHookProgramId(mintAccount, tokenProgramId);
4464
+ if (!transferHookProgramId) {
4465
+ return;
4466
+ }
4467
+ for (const transfer of potentialTransfers) {
4468
+ await splToken.addExtraAccountMetasForExecute(
4469
+ this.connection,
4470
+ instruction,
4471
+ transferHookProgramId,
4472
+ transfer.source,
4473
+ mint,
4474
+ transfer.destination,
4475
+ transfer.owner,
4476
+ 1n,
4477
+ this.getCommitment()
4478
+ );
4479
+ }
4480
+ }
4352
4481
  /**
4353
4482
  * Returns insrtuctions for creating associated token accounts for the provided owners
4354
4483
  */