@streamflow/stream 11.0.4 → 11.0.5-alpha.p335.5ff1599

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, BatchItem, BatchItemError, BatchItemResult, BatchItemSuccess, CONTRACT_DISCRIMINATOR, CONTRACT_SEED, CREATE_PARAMS_PADDING, ChangeOracleParams, ClientCreationOptions, Contract, ContractErrorCode, CreateParams, CreateTestOracleParams, DEFAULT_AUTO_CLAIM_FEE_SOL, DEFAULT_CREATION_FEE_SOL, DEFAULT_STREAMFLOW_FEE, DecodedStream, ESCROW_SEED, FEES_METADATA_SEED, FEE_ORACLE_PUBLIC_KEY, 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, MetadataRecipientHashMap, ORIGINAL_CONTRACT_SENDER_OFFSET, OracleType, OracleTypeName, PARTNERS_SCHEMA, PARTNER_ORACLE_PROGRAM_ID, PARTNER_SCHEMA, PROGRAM_ID, 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, TestOracle, TransactionSchedulingOptions, UpdateTestOracleParams, WITHDRAWOR, WITHDRAWOR_PUBLIC_KEY, WITHDRAW_AVAILABLE_AMOUNT, buildStreamType, calculateTotalAmountToDeposit, calculateUnlockedAmount, cancelStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, deriveTestOraclePDA, extractSolanaErrorCode, getMetadataKey, handleContractError, isAligned, isCliffCloseToDepositedAmount, isCreateAlignedStreamData, isDynamicLock, isTokenLock, isVesting, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, timelockIDL, topupStreamInstruction, transferStreamInstruction, 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, IRecipient, ISearchStreams, ITopUpData, ITopUpStreamExt, ITransactionExtWithInstructions, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, InstructionGenerator, LinearStream, MAX_SAFE_UNIX_TIME_VALUE, 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, createUncheckedStreamInstruction, decodeEndTime, decodeStream, deriveContractPDA, deriveEscrowPDA, deriveRepopulatedMetadataPDA, 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';
@@ -2543,6 +2543,146 @@ var deriveRepopulatedMetadataPDA = (programId, streamMetadata) => {
2543
2543
  return web3_js.PublicKey.findProgramAddressSync([REPOPULATED_METADATA_SEED, streamMetadata.toBuffer()], programId)[0];
2544
2544
  };
2545
2545
 
2546
+ // solana/api-public/client.ts
2547
+ var DEFAULT_API_URL = "https://api-public.streamflow.finance";
2548
+ var DEFAULT_DEVNET_API_URL = "https://api-public-staging.streamflow.finance";
2549
+ var createClient = (options) => {
2550
+ const apiUrl = options?.apiUrl ?? options?.cluster === "mainnet" ? DEFAULT_API_URL : DEFAULT_DEVNET_API_URL;
2551
+ const fetchFn = options?.fetchFn ?? fetch;
2552
+ const fetchResource = async (url, options2) => {
2553
+ const res = await fetchFn(url, {
2554
+ method: "GET",
2555
+ headers: { "Content-Type": "application/json" },
2556
+ ...{}
2557
+ });
2558
+ if (!res.ok) {
2559
+ const text = await res.text().catch(() => "");
2560
+ throw new Error(`Tabularium API error`, {
2561
+ cause: new Error(`: ${res.status} ${res.statusText}${text ? ` - ${text}` : ""}`)
2562
+ });
2563
+ }
2564
+ return res.json();
2565
+ };
2566
+ return {
2567
+ getContracts: async (opts) => {
2568
+ const params = new URLSearchParams();
2569
+ if (opts?.sender) params.set("sender", opts.sender);
2570
+ if (opts?.recipient) params.set("recipient", opts.recipient);
2571
+ const url = `${apiUrl}/v2/api/contracts/tabularium/${params.toString() ? `?${params.toString()}` : ""}`;
2572
+ return fetchResource(url);
2573
+ },
2574
+ getContract: async (address) => {
2575
+ const url = `${apiUrl}/v2/api/contracts/tabularium/${encodeURIComponent(address)}`;
2576
+ return fetchResource(url);
2577
+ }
2578
+ };
2579
+ };
2580
+ var isoToUnix = (iso) => {
2581
+ if (!iso) return 0;
2582
+ const time = new Date(iso).getTime();
2583
+ return Number.isNaN(time) ? 0 : Math.floor(time / 1e3);
2584
+ };
2585
+ var toBN = (value) => new BN3__default.default(value);
2586
+ var mapOracleType = (apiType) => {
2587
+ if (!apiType) return { none: {} };
2588
+ const mapping = {
2589
+ TEST: { test: {} },
2590
+ PYTH: { pyth: {} },
2591
+ SWITCHBOARD: { switchboard: {} }
2592
+ };
2593
+ return mapping[apiType] ?? { none: {} };
2594
+ };
2595
+ async function toDecodedStream(schema) {
2596
+ const mint = common.pk(schema.mint);
2597
+ const sender = common.pk(schema.sender);
2598
+ const recipient = common.pk(schema.recipient);
2599
+ const partner = schema.partner ? common.pk(schema.partner) : sender;
2600
+ const [senderTokens, recipientTokens, partnerTokens, streamflowTreasuryTokens] = await Promise.all([
2601
+ common.ata(mint, sender),
2602
+ common.ata(mint, recipient),
2603
+ common.ata(mint, partner),
2604
+ common.ata(mint, STREAMFLOW_TREASURY_PUBLIC_KEY)
2605
+ ]);
2606
+ return {
2607
+ magic: toBN(4),
2608
+ version: toBN(4),
2609
+ createdAt: toBN(isoToUnix(schema.createdDt)),
2610
+ withdrawnAmount: toBN(schema.claimedAmount),
2611
+ canceledAt: toBN(isoToUnix(schema.canceledDt)),
2612
+ end: toBN(isoToUnix(schema.endDt)),
2613
+ lastWithdrawnAt: toBN(isoToUnix(schema.lastClaimedDt)),
2614
+ sender,
2615
+ senderTokens,
2616
+ recipient,
2617
+ recipientTokens,
2618
+ mint,
2619
+ escrowTokens: schema.escrow ? common.pk(schema.escrow) : web3_js.PublicKey.default,
2620
+ streamflowTreasury: STREAMFLOW_TREASURY_PUBLIC_KEY,
2621
+ streamflowTreasuryTokens,
2622
+ streamflowFeeTotal: toBN(schema.streamflowFee),
2623
+ streamflowFeeWithdrawn: toBN(schema.streamflowFeeWithdrawn),
2624
+ streamflowFeePercent: parseFloat(schema.streamflowFeePercentage) || 0,
2625
+ partnerFeeTotal: toBN(schema.partnerFee),
2626
+ partnerFeeWithdrawn: toBN(schema.partnerFeeWithdrawn),
2627
+ partnerFeePercent: parseFloat(schema.partnerFeePercentage) || 0,
2628
+ partner,
2629
+ partnerTokens,
2630
+ start: toBN(isoToUnix(schema.startDt)),
2631
+ depositedAmount: toBN(schema.amount),
2632
+ period: toBN(schema.period),
2633
+ amountPerPeriod: toBN(schema.amountPerPeriod),
2634
+ cliff: toBN(isoToUnix(schema.startDt)),
2635
+ cliffAmount: toBN(schema.cliffAmount),
2636
+ cancelableBySender: schema.isCancelableBySender,
2637
+ cancelableByRecipient: schema.isCancelableByRecipient,
2638
+ automaticWithdrawal: schema.hasAutoClaim,
2639
+ transferableBySender: schema.isTransferableBySender,
2640
+ transferableByRecipient: schema.isTransferableByRecipient,
2641
+ canTopup: schema.canTopup,
2642
+ name: schema.name,
2643
+ withdrawFrequency: toBN(schema.autoClaimPeriod),
2644
+ closed: schema.isClosed,
2645
+ currentPauseStart: toBN(0),
2646
+ pauseCumulative: toBN(schema.pauseCumulative),
2647
+ lastRateChangeTime: toBN(isoToUnix(schema.lastRateUpdateDt)),
2648
+ fundsUnlockedAtLastRateChange: toBN(schema.amountUnlockedAtLastRateUpdate),
2649
+ oldMetadata: web3_js.PublicKey.default
2650
+ };
2651
+ }
2652
+ function toPrecisionBN(value, precision = ALIGNED_PRECISION_FACTOR_POW2) {
2653
+ return common.getBN(typeof value === "number" ? value : parseFloat(value), precision);
2654
+ }
2655
+ function toAlignedProxy(dynamic) {
2656
+ const proxy = {
2657
+ sender: common.pk(dynamic.sender),
2658
+ minPrice: toPrecisionBN(dynamic.minPrice),
2659
+ maxPrice: toPrecisionBN(dynamic.maxPrice),
2660
+ minPercentage: toPrecisionBN(dynamic.minPercentage),
2661
+ maxPercentage: toPrecisionBN(dynamic.maxPercentage),
2662
+ priceOracleType: mapOracleType(dynamic.priceOracleType),
2663
+ priceOracle: dynamic.priceOracleAddress ? common.pk(dynamic.priceOracleAddress) : web3_js.PublicKey.default,
2664
+ tickSize: toPrecisionBN(dynamic.tickSize),
2665
+ initialAmountPerPeriod: toBN(dynamic.initialAmountPerPeriod),
2666
+ initialPrice: toPrecisionBN(dynamic.initialPrice),
2667
+ lastPrice: toPrecisionBN(dynamic.lastPrice),
2668
+ lastAmountUpdateTime: toBN(isoToUnix(dynamic.expiryDt)),
2669
+ initialNetAmount: toBN(dynamic.initialAmount),
2670
+ expiryTime: toBN(isoToUnix(dynamic.expiryDt)),
2671
+ expiryPercentage: toPrecisionBN(dynamic.expiryPercentage),
2672
+ floorPrice: toPrecisionBN(dynamic.floorPrice),
2673
+ streamCanceledTime: dynamic.streamCanceledTime ? toBN(dynamic.streamCanceledTime) : toBN(0)
2674
+ };
2675
+ return proxy;
2676
+ }
2677
+ var transformContract = async (schema) => {
2678
+ const decodedStream = await toDecodedStream(schema);
2679
+ if (schema.dynamicContract) {
2680
+ const alignedProxy = toAlignedProxy(schema.dynamicContract);
2681
+ return new AlignedContract(decodedStream, alignedProxy);
2682
+ }
2683
+ return new Contract(decodedStream);
2684
+ };
2685
+
2546
2686
  // solana/StreamClient.ts
2547
2687
  var METADATA_ACC_SIZE = 1104;
2548
2688
  var ALIGNED_METADATA_ACC_SIZE = 320;
@@ -2585,6 +2725,9 @@ var SolanaStreamClient = class {
2585
2725
  address: streamflow_aligned_unlocks_default.address
2586
2726
  };
2587
2727
  this.alignedProxyProgram = new anchor.Program(alignedUnlocksProgram, { connection: this.connection });
2728
+ this.apiClient = createClient(
2729
+ typeof optionsOrClusterUrl === "object" && optionsOrClusterUrl.cluster !== common.ICluster.Mainnet ? { cluster: "devnet" } : { cluster: "mainnet" }
2730
+ );
2588
2731
  }
2589
2732
  getConnection() {
2590
2733
  return this.connection;
@@ -3364,7 +3507,7 @@ var SolanaStreamClient = class {
3364
3507
  throw new Error("Impossible to cancel a stream contract that does not exist");
3365
3508
  }
3366
3509
  const decoded = decodeStream(account.data);
3367
- const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender, decoded.oldMetadata);
3510
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender);
3368
3511
  const ixs = isAlignedUnlock ? await this.prepareCancelAlignedUnlockInstructions(cancelData, extParams) : await this.prepareCancelLinearStream(cancelData, extParams);
3369
3512
  return ixs;
3370
3513
  }
@@ -3600,17 +3743,21 @@ var SolanaStreamClient = class {
3600
3743
  }
3601
3744
  ]
3602
3745
  });
3603
- if (migrated.length === 0) {
3604
- throw new Error("Couldn't get account info.");
3746
+ if (migrated.length > 0) {
3747
+ return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
3748
+ }
3749
+ try {
3750
+ const contract = await this.apiClient.getContract(id);
3751
+ return await transformContract(contract);
3752
+ } catch (cause) {
3753
+ throw new Error(`Couldn't get account info from chain or Tabularium`, { cause });
3605
3754
  }
3606
- return this.decodeStreamAccount(migrated[0].pubkey, migrated[0].account.data);
3607
3755
  }
3608
3756
  async decodeStreamAccount(pubkey, data) {
3609
3757
  const stream = decodeStream(data);
3610
- const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
3611
- if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
3758
+ if (this.isAlignedUnlock(pubkey, stream.sender)) {
3612
3759
  const alignedProxy = await this.alignedProxyProgram.account.contract.fetch(
3613
- deriveContractPDA(this.alignedProxyProgram.programId, metadataKey)
3760
+ deriveContractPDA(this.alignedProxyProgram.programId, pubkey)
3614
3761
  );
3615
3762
  if (!alignedProxy) {
3616
3763
  throw new Error("Couldn't get proxy account info.");
@@ -3651,9 +3798,7 @@ var SolanaStreamClient = class {
3651
3798
  const streams = {};
3652
3799
  const alignedStreamsPubKeys = Object.keys(streamRecord);
3653
3800
  const alignedProxyPDAs = alignedStreamsPubKeys.map((streamPubKey) => {
3654
- const pubkey = new web3_js.PublicKey(streamPubKey);
3655
- const metadataKey = getMetadataKey(pubkey, streamRecord[streamPubKey].oldMetadata);
3656
- return deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
3801
+ return deriveContractPDA(this.alignedProxyProgram.programId, new web3_js.PublicKey(streamPubKey));
3657
3802
  });
3658
3803
  const alignedProxyAccounts = await common.getMultipleAccountsInfoBatched(this.connection, alignedProxyPDAs);
3659
3804
  alignedProxyAccounts.forEach((account, index) => {
@@ -3676,7 +3821,8 @@ var SolanaStreamClient = class {
3676
3821
  async get({
3677
3822
  address,
3678
3823
  type = "all" /* All */,
3679
- direction = "all" /* All */
3824
+ direction = "all" /* All */,
3825
+ filters
3680
3826
  }) {
3681
3827
  const publicKey = new web3_js.PublicKey(address);
3682
3828
  let streams = {};
@@ -3706,7 +3852,7 @@ var SolanaStreamClient = class {
3706
3852
  const allIncomingStreams = allIncomingAccounts.map((account) => decodeStream(account.account.data));
3707
3853
  const alignedDecoded = {};
3708
3854
  allIncomingAccounts.forEach((account, index) => {
3709
- if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender, allIncomingStreams[index].oldMetadata)) {
3855
+ if (this.isAlignedUnlock(account.pubkey, allIncomingStreams[index].sender)) {
3710
3856
  alignedDecoded[account.pubkey.toBase58()] = allIncomingStreams[index];
3711
3857
  } else {
3712
3858
  streams[account.pubkey.toBase58()] = new Contract(allIncomingStreams[index]);
@@ -3717,6 +3863,10 @@ var SolanaStreamClient = class {
3717
3863
  streams = { ...streams, ...incomingAlignedStreams };
3718
3864
  }
3719
3865
  }
3866
+ if (filters?.closed) {
3867
+ const closedStreams = await this.getClosedStreams(address, direction);
3868
+ streams = { ...streams, ...closedStreams };
3869
+ }
3720
3870
  const sortedStreams = Object.entries(streams).sort(([, stream1], [, stream2]) => stream2.start - stream1.start);
3721
3871
  if (type === "all" /* All */) return sortedStreams;
3722
3872
  return sortedStreams.filter((stream) => stream[1].type === type);
@@ -3751,9 +3901,8 @@ var SolanaStreamClient = class {
3751
3901
  collectAlignedEntries(decoded) {
3752
3902
  const entries = [];
3753
3903
  decoded.forEach(({ pubkey, stream }, index) => {
3754
- if (this.isAlignedUnlock(pubkey, stream.sender, stream.oldMetadata)) {
3755
- const metadataKey = getMetadataKey(pubkey, stream.oldMetadata);
3756
- entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, metadataKey) });
3904
+ if (this.isAlignedUnlock(pubkey, stream.sender)) {
3905
+ entries.push({ index, pda: deriveContractPDA(this.alignedProxyProgram.programId, pubkey) });
3757
3906
  }
3758
3907
  });
3759
3908
  return entries;
@@ -3814,7 +3963,7 @@ var SolanaStreamClient = class {
3814
3963
  const escrow = await this.connection.getAccountInfo(streamPublicKey);
3815
3964
  common.invariant(escrow, "Couldn't get account info");
3816
3965
  const decoded = decodeStream(escrow.data);
3817
- const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender, decoded.oldMetadata);
3966
+ const isAlignedUnlock = this.isAlignedUnlock(streamPublicKey, decoded.sender);
3818
3967
  if (isAlignedUnlock && (data.enableAutomaticWithdrawal !== void 0 || data.amountPerPeriod !== void 0)) {
3819
3968
  throw new Error("Automatic withdrawal and rate update are not possible in price-based vesting!");
3820
3969
  }
@@ -3908,9 +4057,8 @@ var SolanaStreamClient = class {
3908
4057
  * Utility function that checks whether the associated stream address is an aligned unlock contract, indicated by whether the sender/creator is a PDA.
3909
4058
  * For migrated streams, the PDA was derived from the old metadata key.
3910
4059
  */
3911
- isAlignedUnlock(streamPublicKey, senderPublicKey, oldMetadata) {
3912
- const metadataKey = oldMetadata ? getMetadataKey(streamPublicKey, oldMetadata) : streamPublicKey;
3913
- const pda = deriveContractPDA(this.alignedProxyProgram.programId, metadataKey);
4060
+ isAlignedUnlock(streamPublicKey, senderPublicKey) {
4061
+ const pda = deriveContractPDA(this.alignedProxyProgram.programId, streamPublicKey);
3914
4062
  return senderPublicKey.equals(pda);
3915
4063
  }
3916
4064
  async flatBuildCreateMultipleTransactionInstructions(data, extParams) {
@@ -3928,6 +4076,40 @@ var SolanaStreamClient = class {
3928
4076
  )
3929
4077
  };
3930
4078
  }
4079
+ /**
4080
+ * Gets closed streams for a given owner and direction
4081
+ * @param owner - Owner address
4082
+ * @param direction - Stream direction
4083
+ * @returns Record of closed streams
4084
+ */
4085
+ async getClosedStreams(owner, direction = "all" /* All */) {
4086
+ const streams = {};
4087
+ try {
4088
+ const tabulariumContracts = await this.apiClient.getContracts({
4089
+ sender: direction !== "incoming" /* Incoming */ ? owner : void 0,
4090
+ recipient: direction !== "outgoing" /* Outgoing */ ? owner : void 0
4091
+ });
4092
+ for (const contract of tabulariumContracts) {
4093
+ if (!streams[contract.address]) {
4094
+ try {
4095
+ const transformed = await transformContract(contract);
4096
+ streams[contract.address] = transformed;
4097
+ } catch (cause) {
4098
+ if (common.isDev) {
4099
+ throw new Error(`Failed to transform contract ${contract.address}:`, { cause });
4100
+ }
4101
+ console.warn(new Error(`Failed to transform contract ${contract.address}:`, { cause }));
4102
+ }
4103
+ }
4104
+ }
4105
+ } catch (cause) {
4106
+ if (common.isDev) {
4107
+ throw new Error("Failed to get data from the service", { cause });
4108
+ }
4109
+ console.warn(new Error("Failed to get data from the service", { cause }));
4110
+ }
4111
+ return streams;
4112
+ }
3931
4113
  /**
3932
4114
  * Utility function to generate metadata for a Contract or return existing Pubkey
3933
4115
  */
@@ -4450,6 +4632,7 @@ exports.buildStreamType = buildStreamType;
4450
4632
  exports.calculateTotalAmountToDeposit = calculateTotalAmountToDeposit;
4451
4633
  exports.calculateUnlockedAmount = calculateUnlockedAmount;
4452
4634
  exports.cancelStreamInstruction = cancelStreamInstruction;
4635
+ exports.createClient = createClient;
4453
4636
  exports.createStreamInstruction = createStreamInstruction;
4454
4637
  exports.createUncheckedStreamInstruction = createUncheckedStreamInstruction;
4455
4638
  exports.decodeEndTime = decodeEndTime;
@@ -4472,6 +4655,7 @@ exports.signAllTransactionWithRecipients = signAllTransactionWithRecipients;
4472
4655
  exports.timelockIDL = timelockIDL_default;
4473
4656
  exports.topupStreamInstruction = topupStreamInstruction;
4474
4657
  exports.transferStreamInstruction = transferStreamInstruction;
4658
+ exports.transformContract = transformContract;
4475
4659
  exports.updateStreamInstruction = updateStreamInstruction;
4476
4660
  exports.withdrawStreamInstruction = withdrawStreamInstruction;
4477
4661
  //# sourceMappingURL=index.cjs.map