@streamflow/stream 7.0.0-alpha.5 → 7.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,10 +34,7 @@ Before creating and manipulating streams chain specific or generic StreamClient
34
34
  ### Solana
35
35
 
36
36
  ```javascript
37
- import {
38
- StreamflowSolana,
39
- Types,
40
- } from "@streamflow/stream";
37
+ import { StreamflowSolana } from "@streamflow/stream";
41
38
 
42
39
  const solanaClient = new StreamflowSolana.SolanaStreamClient(
43
40
  "https://api.mainnet-beta.solana.com"
@@ -47,10 +44,7 @@ const solanaClient = new StreamflowSolana.SolanaStreamClient(
47
44
  ### Aptos
48
45
 
49
46
  ```javascript
50
- import {
51
- StreamflowAptos,
52
- Types,
53
- } from "@streamflow/stream";
47
+ import { StreamflowAptos } from "@streamflow/stream";
54
48
 
55
49
  const aptosClient = new StreamflowAptos.AptosStreamClient(
56
50
  "https://fullnode.mainnet.aptoslabs.com/v1"
@@ -60,14 +54,11 @@ const aptosClient = new StreamflowAptos.AptosStreamClient(
60
54
  ### Ethereum
61
55
 
62
56
  ```javascript
63
- import {
64
- StreamflowEVM,
65
- Types,
66
- } from "@streamflow/stream";
57
+ import { StreamflowEVM } from "@streamflow/stream";
67
58
 
68
59
  const ethereumClient = new StreamflowEVM.EvmStreamClient(
69
60
  "YOUR_ETHEREUM_NODE_URL",
70
- Types.IChain.Ethereum,
61
+ IChain.Ethereum,
71
62
  signer // will be sender in a stream and authority for all stream related transactions
72
63
  );
73
64
  ```
@@ -75,14 +66,11 @@ const ethereumClient = new StreamflowEVM.EvmStreamClient(
75
66
  ### Polygon
76
67
 
77
68
  ```javascript
78
- import {
79
- StreamflowEVM,
80
- Types,
81
- } from "@streamflow/stream";
69
+ import { StreamflowEVM } from "@streamflow/stream";
82
70
 
83
71
  const polygonClient = new StreamflowEVM.EvmStreamClient(
84
72
  "YOUR_POLYGON_NODE_URL",
85
- Types.IChain.Polygon,
73
+ IChain.Polygon,
86
74
  signer // will be sender in a stream and authority for all stream related transactions
87
75
  );
88
76
  ```
@@ -90,14 +78,11 @@ const polygonClient = new StreamflowEVM.EvmStreamClient(
90
78
  ### BNB
91
79
 
92
80
  ```javascript
93
- import {
94
- StreamflowEVM,
95
- Types,
96
- } from "@streamflow/stream";
81
+ import { StreamflowEVM } from "@streamflow/stream";
97
82
 
98
83
  const bnbClient = new StreamflowEVM.EvmStreamClient(
99
84
  "https://bsc-dataseed1.binance.org/",
100
- Types.IChain.BNB,
85
+ IChain.BNB,
101
86
  signer // will be sender in a stream and authority for all stream related transactions
102
87
  );
103
88
  ```
@@ -105,10 +90,7 @@ const bnbClient = new StreamflowEVM.EvmStreamClient(
105
90
  ### Sui
106
91
 
107
92
  ```javascript
108
- import {
109
- StreamflowSui,
110
- Types,
111
- } from "@streamflow/stream";
93
+ import { StreamflowSui } from "@streamflow/stream";
112
94
 
113
95
  const suiClient = new StreamflowSui.SuiStreamClient(
114
96
  "https://fullnode.testnet.sui.io:443"
@@ -120,13 +102,13 @@ const suiClient = new StreamflowSui.SuiStreamClient(
120
102
  GenericStreamClient provides isomorphic interface to work with streams agnostic of chain.
121
103
 
122
104
  ```javascript
123
- import { GenericStreamClient, Types } from "@streamflow/stream";
105
+ import { GenericStreamClient } from "@streamflow/stream";
124
106
 
125
107
  const client =
126
108
  new GenericStreamClient<Types.IChain.Solana>({
127
- chain: Types.IChain.Solana, // Blockchain
109
+ chain: IChain.Solana, // Blockchain
128
110
  clusterUrl: "https://api.mainnet-beta.solana.com", // RPC cluster URL
129
- cluster: Types.ICluster.Mainnet, // (optional) (default: Mainnet)
111
+ cluster: ICluster.Mainnet, // (optional) (default: Mainnet)
130
112
  // ...rest chain specific params e.g. commitment for Solana
131
113
  });
132
114
  ```
@@ -148,7 +130,7 @@ const createStreamParams: Types.ICreateStreamData = {
148
130
  cliffAmount: 10, // Amount unlocked at the "cliff" timestamp.
149
131
  amountPerPeriod: getScaledBigNumber(5, 9), // Release rate: how many tokens are unlocked per each period.
150
132
  name: "Transfer to Jane Doe.", // The stream name or subject.
151
- canTopup: false, // setting to FALSE will effectively create a vesting contract.
133
+ canTopup: false, // Whether additional tokens can be deposited after creation, setting to FALSE will effectively create a vesting contract.
152
134
  canUpdateRate: false, // settings to TRUE allows sender to update amountPerPeriod
153
135
  cancelableBySender: true, // Whether or not sender can cancel the stream.
154
136
  cancelableByRecipient: false, // Whether or not recipient can cancel the stream.
@@ -156,12 +138,12 @@ const createStreamParams: Types.ICreateStreamData = {
156
138
  transferableByRecipient: false, // Whether or not recipient can transfer the stream.
157
139
  automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
158
140
  withdrawalFrequency: 10, // Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
159
- partner: null, // (optional) Partner's wallet address (string | null).
141
+ partner: undefined, // (optional) Partner's wallet address (string | undefined).
160
142
  };
161
143
 
162
144
  const solanaParams = {
163
145
  sender: wallet, // SignerWalletAdapter or Keypair of Sender account
164
- isNative: false // [optional] [WILL CREATE A wSOL STREAM] Wether Stream or Vesting should be paid with Solana native token or not
146
+ isNative: false // [optional] [WILL CREATE A wSOL STREAM] Whether Stream or Vesting should be paid with Solana native token or not
165
147
  };
166
148
 
167
149
  const aptosParams = {
@@ -193,7 +175,7 @@ const recipients = [
193
175
  amountPerPeriod: getScaledBgNumber(1, 9), //amount released every specified period epoch
194
176
  },
195
177
  ];
196
- const createStreamParams: Types.ICreateMultipleStreamData = {
178
+ const createMultiStreamsParams: ICreateMultipleStreamData = {
197
179
  recipients: recipients, // Solana recipient address.
198
180
  tokenId: "DNw99999M7e24g99999999WJirKeZ5fQc6KY999999gK", // SPL Token mint.
199
181
  start: 1643363040, // Timestamp (in seconds) when the stream/token vesting starts.
@@ -206,7 +188,7 @@ const createStreamParams: Types.ICreateMultipleStreamData = {
206
188
  transferableByRecipient: false, // Whether or not recipient can transfer the stream.
207
189
  automaticWithdrawal: true, // Whether or not a 3rd party (e.g. cron job, "cranker") can initiate a token withdraw/transfer.
208
190
  withdrawalFrequency: 10, // Relevant when automatic withdrawal is enabled. If greater than 0 our withdrawor will take care of withdrawals. If equal to 0 our withdrawor will skip, but everyone else can initiate withdrawals.
209
- partner: null, // (optional) Partner's wallet address (string | null).
191
+ partner: undefined, // (optional) Partner's wallet address (string | undefined).
210
192
  };
211
193
 
212
194
  const solanaParams = {
@@ -235,11 +217,11 @@ Please note that transaction fees for the scheduled transfers are paid upfront b
235
217
 
236
218
  ## Identifying created contracts (streams or vesting)
237
219
 
238
- All Stream Clients return `Types.ICreateResult` object (`createdMultiple` returns an Array) that has the following structure
220
+ All Stream Clients return `ICreateResult` object (`createMultiple` returns an Array) that has the following structure
239
221
 
240
222
  ```javascript
241
223
  interface ICreateResult {
242
- ixs: (TransactionInstruction | Types.TransactionPayload)[];
224
+ ixs: (TransactionInstruction | TransactionPayload)[];
243
225
  txId: string;
244
226
  metadataId: MetadataId;
245
227
  }
@@ -251,7 +233,7 @@ interface ICreateResult {
251
233
 
252
234
  ```javascript
253
235
  const withdrawStreamParams: Types.IWithdrawData = {
254
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be withdrawn from.
236
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be withdrawn from.
255
237
  amount: getScaledBgNumber(100, 9), // Requested amount to withdraw. If stream is completed, the whole amount will be withdrawn.
256
238
  };
257
239
 
@@ -281,14 +263,14 @@ try {
281
263
  ## Topup stream
282
264
 
283
265
  ```javascript
284
- const topupStreamParams: Types.ITopUpData = {
285
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be topped up.
266
+ const topupStreamParams: ITopUpData = {
267
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of a stream to be topped up.
286
268
  amount: getScaledBgNumber(100, 9), // Specified amount to topup (increases deposited amount).
287
269
  };
288
270
 
289
271
  const solanaParams = {
290
272
  invoker: wallet, // SignerWalletAdapter or Keypair signing the transaction
291
- isNative: // [ONLY FOR wSOL STREAMS] [optional] Wether topup is with Native Solanas
273
+ isNative: true // [ONLY FOR wSOL STREAMS] [optional] Wether topup is with Native Solanas
292
274
  };
293
275
 
294
276
  const aptosParams = {
@@ -313,9 +295,9 @@ try {
313
295
  ## Transfer stream to another recipient
314
296
 
315
297
  ```javascript
316
- const data: Types.ITransferData = {
317
- id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA",
318
- newRecipient: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier of a stream to be transferred.
298
+ const data: ITransferData = {
299
+ id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier (address) of the stream to be transferred
300
+ newRecipient: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99", // Identifier (address) of a stream to be transferred.
319
301
  };
320
302
 
321
303
  const solanaParams = {
@@ -344,7 +326,7 @@ try {
344
326
  ## Cancel stream
345
327
 
346
328
  ```javascript
347
- const cancelStreamParams: Types.ICancelData = {
329
+ const cancelStreamParams: ICancelData = {
348
330
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to be canceled.
349
331
  };
350
332
 
@@ -374,7 +356,7 @@ try {
374
356
  ## Update a stream
375
357
 
376
358
  ```javascript
377
- const updateStreamParams: Types.IUpdateData = {
359
+ const updateStreamParams: IUpdateData = {
378
360
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream to update.
379
361
  enableAutomaticWithdrawal: true, // [optional], allows to enable AW if it wasn't, disable is not possible
380
362
  withdrawFrequency: 60, // [optional], allows to update withdrawal frequency, may result in additional AW fees
@@ -405,7 +387,7 @@ try {
405
387
  ## Get one stream by its ID
406
388
 
407
389
  ```javascript
408
- const data: Types.IGetOneData = {
390
+ const data: IGetOneData = {
409
391
  id: "AAAAyotqTZZMAAAAmsD1JAgksT8NVAAAASfrGB5RAAAA", // Identifier of a stream
410
392
  };
411
393
 
@@ -444,10 +426,10 @@ console.log(remaining);
444
426
  ## Get multiple streams for a specific wallet address
445
427
 
446
428
  ```javascript
447
- const data: Types.IGetAllData = {
429
+ const data: IGetAllData = {
448
430
  address: "99h00075bKjVg000000tLdk4w42NyG3Mv0000dc0M99",
449
- type: Types.StreamType.All,
450
- direction: Types.StreamDirection.All,
431
+ type: StreamType.All, // StreamType.Vesting, StreamType.Lock, StreamType.Payment
432
+ direction: StreamDirection.All, // StreamDirection.Outgoing, StreamDirection.Incoming
451
433
  };
452
434
 
453
435
  try {
@@ -457,6 +439,22 @@ try {
457
439
  }
458
440
  ```
459
441
 
442
+ ## Search Solana Streams
443
+
444
+ Solana RPC is pretty rich in what data it can allow to filter by, so we expose a separate `searchStreams` method on `SolanaStreamClient`:
445
+
446
+ ```javascript
447
+ // All parameters are optional, so in theory you can just fetch all Streams
448
+ const params = {
449
+ mint: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
450
+ sender: "AKp8CxGbhsrsEsCFUtx7e3MWyW7SWi1uuSqv6N4BEohJ",
451
+ recipient: "9mqcpDjCHCPmttJp2t477oJ71NdAvJeSus8BcCrrvwy5",
452
+ }
453
+ // nativeStreamClient is exposed on a GenericStreamClient, you can also use SolanaStreamClient directly
454
+ // Return an Array of objects {publicKey: PublicKey, account: Stream}
455
+ const streams = await client.nativeStreamClient.searchStreams(params);
456
+ ```
457
+
460
458
  ## Handling errors
461
459
 
462
460
  `GenericStreamClient` wraps all errors when making on-chain calls with `ContractError` error class:
@@ -497,4 +495,4 @@ E.g, if the amount is 1 SOL than this amount in lamports is `1000 \* 10^9 = 1_00
497
495
 
498
496
  And `BigNumber(1_000_000_000)` is used.
499
497
 
500
- Use `getscaledBigNumber` and `getNumberFromBigNumber` utility functions for conversions between `BigNumber` and `Number` types.
498
+ Use `getScaledBigNumber` and `getNumberFromBigNumber` utility functions for conversions between `BigNumber` and `Number` types.
@@ -97,7 +97,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
97
97
  const senderTokens = await (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId);
98
98
  const recipientTokens = await (0, solana_1.ata)(mintPublicKey, recipientPublicKey, tokenProgramId);
99
99
  const streamflowTreasuryTokens = await (0, solana_1.ata)(mintPublicKey, constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
100
- const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
100
+ const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
101
101
  const partnerTokens = await (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId);
102
102
  if (isNative) {
103
103
  const totalFee = await this.getTotalFee({
@@ -186,7 +186,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
186
186
  const [escrowTokens] = web3_js_1.PublicKey.findProgramAddressSync([buffer_1.Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
187
187
  const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey);
188
188
  const senderTokens = await (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId);
189
- const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
189
+ const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
190
190
  const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
191
191
  computePrice,
192
192
  computeLimit,
@@ -562,6 +562,22 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
562
562
  return sortedStreams;
563
563
  return sortedStreams.filter((stream) => stream[1].type === type);
564
564
  }
565
+ async searchStreams(data) {
566
+ const filters = Object.entries(data)
567
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
568
+ .filter(([_, value]) => value) // Only keep entries where the value is truthy
569
+ .map(([key, value]) => ({
570
+ memcmp: {
571
+ offset: constants_js_1.STREAM_STRUCT_OFFSETS[key],
572
+ bytes: value,
573
+ },
574
+ }));
575
+ const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
576
+ return accounts.map(({ pubkey, account }) => ({
577
+ publicKey: pubkey,
578
+ account: new types_js_1.Contract((0, utils_js_1.decodeStream)(account.data)),
579
+ }));
580
+ }
565
581
  /**
566
582
  * Attempts updating the stream auto withdrawal params and amount per period
567
583
  */
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SOLANA_ERROR_MAP = exports.SOLANA_ERROR_MATCH_REGEX = exports.PARTNERS_SCHEMA = exports.PARTNER_SCHEMA = exports.AIRDROP_AMOUNT = exports.DEFAULT_STREAMFLOW_FEE = exports.FEES_METADATA_SEED = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.PARTNER_ORACLE_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
3
+ exports.SOLANA_ERROR_MAP = exports.SOLANA_ERROR_MATCH_REGEX = exports.PARTNERS_SCHEMA = exports.PARTNER_SCHEMA = exports.AIRDROP_AMOUNT = exports.DEFAULT_STREAMFLOW_FEE = exports.FEES_METADATA_SEED = exports.AIRDROP_TEST_TOKEN = exports.FEE_ORACLE_PUBLIC_KEY = exports.WITHDRAWOR_PUBLIC_KEY = exports.STREAMFLOW_TREASURY_PUBLIC_KEY = exports.PARTNER_ORACLE_PROGRAM_ID = exports.PROGRAM_ID = exports.CREATE_PARAMS_PADDING = exports.STREAM_STRUCT_OFFSETS = exports.STREAM_STRUCT_OFFSET_MINT = exports.STREAM_STRUCT_OFFSET_RECIPIENT = exports.STREAM_STRUCT_OFFSET_SENDER = exports.TX_FINALITY_CONFIRMED = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  const buffer_1 = require("buffer");
6
6
  const types_js_1 = require("../common/types.js");
7
7
  exports.TX_FINALITY_CONFIRMED = "confirmed";
8
8
  exports.STREAM_STRUCT_OFFSET_SENDER = 49;
9
9
  exports.STREAM_STRUCT_OFFSET_RECIPIENT = 113;
10
+ exports.STREAM_STRUCT_OFFSET_MINT = 177;
11
+ exports.STREAM_STRUCT_OFFSETS = {
12
+ mint: exports.STREAM_STRUCT_OFFSET_MINT,
13
+ recipient: exports.STREAM_STRUCT_OFFSET_RECIPIENT,
14
+ sender: exports.STREAM_STRUCT_OFFSET_SENDER,
15
+ };
10
16
  // Defined: https://github.com/streamflow-finance/protocol/blob/main/programs/protocol/src/state.rs#L25
11
17
  exports.CREATE_PARAMS_PADDING = 126;
12
18
  exports.PROGRAM_ID = {
@@ -1,6 +1,7 @@
1
1
  import PQueue from "p-queue";
2
2
  import { Connection, Keypair, PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
3
- import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "./types.js";
3
+ import { IProgramAccount } from "@streamflow/common/solana";
4
+ import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, ISearchStreams } from "./types.js";
4
5
  import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types.js";
5
6
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
6
7
  export declare class SolanaStreamClient extends BaseStreamClient {
@@ -96,6 +97,7 @@ export declare class SolanaStreamClient extends BaseStreamClient {
96
97
  * Streams are sorted by start time in ascending order.
97
98
  */
98
99
  get({ address, type, direction, }: IGetAllData): Promise<[string, Stream][]>;
100
+ searchStreams(data: ISearchStreams): Promise<IProgramAccount<Stream>[]>;
99
101
  /**
100
102
  * Attempts updating the stream auto withdrawal params and amount per period
101
103
  */
@@ -7,7 +7,7 @@ import { ata, checkOrCreateAtaBatch, signAndExecuteTransaction, getProgramAccoun
7
7
  import * as borsh from "borsh";
8
8
  import { Contract, } from "./types.js";
9
9
  import { decodeStream, extractSolanaErrorCode, sendAndConfirmStreamRawTransaction, signAllTransactionWithRecipients, } from "./utils.js";
10
- import { PROGRAM_ID, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, FEE_ORACLE_PUBLIC_KEY, DEFAULT_STREAMFLOW_FEE, PARTNER_ORACLE_PROGRAM_ID, FEES_METADATA_SEED, PARTNERS_SCHEMA, } from "./constants.js";
10
+ import { PROGRAM_ID, STREAMFLOW_TREASURY_PUBLIC_KEY, STREAM_STRUCT_OFFSET_RECIPIENT, STREAM_STRUCT_OFFSET_SENDER, TX_FINALITY_CONFIRMED, WITHDRAWOR_PUBLIC_KEY, FEE_ORACLE_PUBLIC_KEY, DEFAULT_STREAMFLOW_FEE, PARTNER_ORACLE_PROGRAM_ID, FEES_METADATA_SEED, PARTNERS_SCHEMA, STREAM_STRUCT_OFFSETS, } from "./constants.js";
11
11
  import { withdrawStreamInstruction, cancelStreamInstruction, transferStreamInstruction, topupStreamInstruction, createStreamInstruction, createUncheckedStreamInstruction, updateStreamInstruction, } from "./instructions.js";
12
12
  import { ICluster, StreamDirection, StreamType, } from "../common/types.js";
13
13
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
@@ -72,7 +72,7 @@ export class SolanaStreamClient extends BaseStreamClient {
72
72
  const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
73
73
  const recipientTokens = await ata(mintPublicKey, recipientPublicKey, tokenProgramId);
74
74
  const streamflowTreasuryTokens = await ata(mintPublicKey, STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId);
75
- const partnerPublicKey = partner ? new PublicKey(partner) : STREAMFLOW_TREASURY_PUBLIC_KEY;
75
+ const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
76
76
  const partnerTokens = await ata(mintPublicKey, partnerPublicKey, tokenProgramId);
77
77
  if (isNative) {
78
78
  const totalFee = await this.getTotalFee({
@@ -161,7 +161,7 @@ export class SolanaStreamClient extends BaseStreamClient {
161
161
  const [escrowTokens] = PublicKey.findProgramAddressSync([Buffer.from("strm"), metadataPubKey.toBuffer()], this.programId);
162
162
  const { tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
163
163
  const senderTokens = await ata(mintPublicKey, sender.publicKey, tokenProgramId);
164
- const partnerPublicKey = partner ? new PublicKey(partner) : STREAMFLOW_TREASURY_PUBLIC_KEY;
164
+ const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
165
165
  const ixs = prepareBaseInstructions(this.connection, {
166
166
  computePrice,
167
167
  computeLimit,
@@ -537,6 +537,22 @@ export class SolanaStreamClient extends BaseStreamClient {
537
537
  return sortedStreams;
538
538
  return sortedStreams.filter((stream) => stream[1].type === type);
539
539
  }
540
+ async searchStreams(data) {
541
+ const filters = Object.entries(data)
542
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
543
+ .filter(([_, value]) => value) // Only keep entries where the value is truthy
544
+ .map(([key, value]) => ({
545
+ memcmp: {
546
+ offset: STREAM_STRUCT_OFFSETS[key],
547
+ bytes: value,
548
+ },
549
+ }));
550
+ const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
551
+ return accounts.map(({ pubkey, account }) => ({
552
+ publicKey: pubkey,
553
+ account: new Contract(decodeStream(account.data)),
554
+ }));
555
+ }
540
556
  /**
541
557
  * Attempts updating the stream auto withdrawal params and amount per period
542
558
  */
@@ -1,9 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import { PublicKey } from "@solana/web3.js";
3
3
  import { Buffer } from "buffer";
4
+ import { ISearchStreams } from "./types.js";
4
5
  export declare const TX_FINALITY_CONFIRMED = "confirmed";
5
6
  export declare const STREAM_STRUCT_OFFSET_SENDER = 49;
6
7
  export declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
8
+ export declare const STREAM_STRUCT_OFFSET_MINT = 177;
9
+ export declare const STREAM_STRUCT_OFFSETS: Record<keyof ISearchStreams, number>;
7
10
  export declare const CREATE_PARAMS_PADDING = 126;
8
11
  export declare const PROGRAM_ID: {
9
12
  devnet: string;
@@ -4,6 +4,12 @@ import { ICluster, SolanaContractErrorCode } from "../common/types.js";
4
4
  export const TX_FINALITY_CONFIRMED = "confirmed";
5
5
  export const STREAM_STRUCT_OFFSET_SENDER = 49;
6
6
  export const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
7
+ export const STREAM_STRUCT_OFFSET_MINT = 177;
8
+ export const STREAM_STRUCT_OFFSETS = {
9
+ mint: STREAM_STRUCT_OFFSET_MINT,
10
+ recipient: STREAM_STRUCT_OFFSET_RECIPIENT,
11
+ sender: STREAM_STRUCT_OFFSET_SENDER,
12
+ };
7
13
  // Defined: https://github.com/streamflow-finance/protocol/blob/main/programs/protocol/src/state.rs#L25
8
14
  export const CREATE_PARAMS_PADDING = 126;
9
15
  export const PROGRAM_ID = {
@@ -4,6 +4,11 @@ import { AccountInfo, PublicKey, Keypair, VersionedTransaction } from "@solana/w
4
4
  import { ITransactionSolanaExt } from "@streamflow/common/solana";
5
5
  import BigNumber from "bignumber.js";
6
6
  import { IRecipient, Stream, StreamType } from "../common/types.js";
7
+ export interface ISearchStreams {
8
+ mint?: string;
9
+ sender?: string;
10
+ recipient?: string;
11
+ }
7
12
  export interface Account {
8
13
  pubkey: PublicKey;
9
14
  account: AccountInfo<Buffer>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "7.0.0-alpha.5",
3
+ "version": "7.0.0-alpha.7",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
6
6
  "main": "./dist/esm/index.js",
@@ -42,24 +42,24 @@
42
42
  "lint": "eslint --fix .",
43
43
  "prepublishOnly": "npm run lint && npm test && npm run build"
44
44
  },
45
- "gitHead": "bcff1ef3a32c9e11a9edb4822b0c28de33a8004c",
45
+ "gitHead": "cfa8d5784c12bd5dd40ff454043f6a796a161049",
46
46
  "devDependencies": {
47
- "@streamflow/eslint-config": "7.0.0-alpha.5",
47
+ "@streamflow/eslint-config": "7.0.0-alpha.7",
48
48
  "@types/ethereum-checksum-address": "^0.0.0",
49
49
  "date-fns": "2.28.0",
50
50
  "typescript": "^5.3.3"
51
51
  },
52
52
  "dependencies": {
53
- "@coral-xyz/borsh": "^0.29.0",
54
- "@manahippo/aptos-wallet-adapter": "1.0.6",
55
- "@mysten/sui.js": "^0.45.1",
53
+ "@coral-xyz/borsh": "0.30.1",
54
+ "@manahippo/aptos-wallet-adapter": "1.0.10",
55
+ "@mysten/sui.js": "0.54.1",
56
56
  "@solana/buffer-layout": "4.0.1 ",
57
57
  "@solana/spl-token": "0.3.6",
58
58
  "@solana/wallet-adapter-base": "0.9.19",
59
- "@solana/web3.js": "1.70.1",
60
- "@streamflow/common": "7.0.0-alpha.5",
59
+ "@solana/web3.js": "1.90.2",
60
+ "@streamflow/common": "7.0.0-alpha.7",
61
61
  "@suiet/wallet-kit": "0.2.22",
62
- "aptos": "1.4.0",
62
+ "aptos": "1.21.0",
63
63
  "bignumber.js": "^9.1.2",
64
64
  "borsh": "^2.0.0",
65
65
  "bs58": "5.0.0",