@streamflow/stream 6.3.9 → 6.4.2

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
@@ -458,6 +458,22 @@ try {
458
458
  }
459
459
  ```
460
460
 
461
+ ## Search Solana Streams
462
+
463
+ Solana RPC is pretty rich in what data it can allow to filter by, so we expose a separate `searchStreams` method on `SolanaStreamClient`:
464
+
465
+ ```javascript
466
+ // All parameters are optional, so in theory you can just fetch all Streams
467
+ const params = {
468
+ mint: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263",
469
+ sender: "AKp8CxGbhsrsEsCFUtx7e3MWyW7SWi1uuSqv6N4BEohJ",
470
+ recipient: "9mqcpDjCHCPmttJp2t477oJ71NdAvJeSus8BcCrrvwy5",
471
+ }
472
+ // nativeStreamClient is exposed on a GenericStreamClient, you can also use SolanaStreamClient directly
473
+ // Return an Array of objects {publicKey: PublicKey, account: Stream}
474
+ const streams = await client.nativeStreamClient.searchStreams(params);
475
+ ```
476
+
461
477
  ## Handling errors
462
478
 
463
479
  `GenericStreamClient` wraps all errors when making on-chain calls with `ContractError` error class:
@@ -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";
3
+ import { IProgramAccount } from "@streamflow/common/solana";
4
+ import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, ISearchStreams } from "./types";
4
5
  import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream } from "../common/types";
5
6
  import { BaseStreamClient } from "../common/BaseStreamClient";
6
7
  export default class SolanaStreamClient extends BaseStreamClient {
@@ -96,6 +97,7 @@ export default 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
  */
@@ -228,7 +228,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
228
228
  return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY, tokenProgramId)];
229
229
  case 4:
230
230
  streamflowTreasuryTokens = _m.sent();
231
- partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
231
+ partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.WITHDRAWOR_PUBLIC_KEY;
232
232
  return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, partnerPublicKey, tokenProgramId)];
233
233
  case 5:
234
234
  partnerTokens = _m.sent();
@@ -356,7 +356,7 @@ var SolanaStreamClient = /** @class */ (function (_super) {
356
356
  return [4 /*yield*/, (0, solana_1.ata)(mintPublicKey, sender.publicKey, tokenProgramId)];
357
357
  case 3:
358
358
  senderTokens = _m.sent();
359
- partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.STREAMFLOW_TREASURY_PUBLIC_KEY;
359
+ partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_1.WITHDRAWOR_PUBLIC_KEY;
360
360
  ixs = (0, solana_1.prepareBaseInstructions)(this.connection, {
361
361
  computePrice: computePrice,
362
362
  computeLimit: computeLimit,
@@ -985,6 +985,41 @@ var SolanaStreamClient = /** @class */ (function (_super) {
985
985
  });
986
986
  });
987
987
  };
988
+ SolanaStreamClient.prototype.searchStreams = function (data) {
989
+ return __awaiter(this, void 0, void 0, function () {
990
+ var filters, accounts;
991
+ return __generator(this, function (_a) {
992
+ switch (_a.label) {
993
+ case 0:
994
+ filters = Object.entries(data)
995
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
996
+ .filter(function (_a) {
997
+ var _b = __read(_a, 2), _ = _b[0], value = _b[1];
998
+ return value;
999
+ }) // Only keep entries where the value is truthy
1000
+ .map(function (_a) {
1001
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
1002
+ return ({
1003
+ memcmp: {
1004
+ offset: constants_1.STREAM_STRUCT_OFFSETS[key],
1005
+ bytes: value,
1006
+ },
1007
+ });
1008
+ });
1009
+ return [4 /*yield*/, this.connection.getProgramAccounts(this.programId, { filters: filters })];
1010
+ case 1:
1011
+ accounts = _a.sent();
1012
+ return [2 /*return*/, accounts.map(function (_a) {
1013
+ var pubkey = _a.pubkey, account = _a.account;
1014
+ return ({
1015
+ publicKey: pubkey,
1016
+ account: new types_1.Contract((0, utils_1.decodeStream)(account.data)),
1017
+ });
1018
+ })];
1019
+ }
1020
+ });
1021
+ });
1022
+ };
988
1023
  /**
989
1024
  * Attempts updating the stream auto withdrawal params and amount per period
990
1025
  */
@@ -1,7 +1,10 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
+ import { ISearchStreams } from "./types";
2
3
  export declare const TX_FINALITY_CONFIRMED = "confirmed";
3
4
  export declare const STREAM_STRUCT_OFFSET_SENDER = 49;
4
5
  export declare const STREAM_STRUCT_OFFSET_RECIPIENT = 113;
6
+ export declare const STREAM_STRUCT_OFFSET_MINT = 177;
7
+ export declare const STREAM_STRUCT_OFFSETS: Record<keyof ISearchStreams, number>;
5
8
  export declare const CREATE_PARAMS_PADDING = 126;
6
9
  export declare const PROGRAM_ID: {
7
10
  devnet: string;
@@ -1,12 +1,18 @@
1
1
  "use strict";
2
2
  var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- 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;
4
+ 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;
5
5
  var web3_js_1 = require("@solana/web3.js");
6
6
  var types_1 = require("../common/types");
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 = (_a = {},
@@ -3,6 +3,11 @@ import { AccountInfo, PublicKey, Keypair, VersionedTransaction } from "@solana/w
3
3
  import { ITransactionSolanaExt } from "@streamflow/common/solana";
4
4
  import BN from "bn.js";
5
5
  import { IRecipient, Stream, StreamType } from "../common/types";
6
+ export interface ISearchStreams {
7
+ mint?: string;
8
+ sender?: string;
9
+ recipient?: string;
10
+ }
6
11
  export interface Account {
7
12
  pubkey: PublicKey;
8
13
  account: AccountInfo<Buffer>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "6.3.9",
3
+ "version": "6.4.2",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "homepage": "https://github.com/streamflow-finance/js-sdk/",
6
6
  "main": "dist/index.js",
@@ -35,9 +35,9 @@
35
35
  "lint": "eslint --fix .",
36
36
  "prepublishOnly": "npm run lint && npm test && npm run build"
37
37
  },
38
- "gitHead": "b1f7b91920868a65feee3e04837357a1cb521f5b",
38
+ "gitHead": "1c317073936ec2e6da6dee0d5a33cdb1e50f6776",
39
39
  "devDependencies": {
40
- "@streamflow/eslint-config": "6.3.9",
40
+ "@streamflow/eslint-config": "6.4.2",
41
41
  "@types/bn.js": "5.1.1",
42
42
  "@types/ethereum-checksum-address": "^0.0.0",
43
43
  "@types/jest": "29.2.4",
@@ -54,7 +54,7 @@
54
54
  "@solana/spl-token": "0.3.6",
55
55
  "@solana/wallet-adapter-base": "0.9.19",
56
56
  "@solana/web3.js": "1.70.1",
57
- "@streamflow/common": "6.3.9",
57
+ "@streamflow/common": "6.4.2",
58
58
  "@suiet/wallet-kit": "0.2.22",
59
59
  "aptos": "1.4.0",
60
60
  "bn.js": "5.2.1",