@streamflow/stream 7.4.7 → 7.4.9

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.
@@ -100,7 +100,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
100
100
  */
101
101
  async create(data, extParams) {
102
102
  const { partner, amount, tokenProgramId } = data;
103
- const { isNative, sender } = extParams;
103
+ const { isNative, sender, customInstructions } = extParams;
104
104
  const partnerPublicKey = partner ? new web3_js_1.PublicKey(partner) : constants_js_1.WITHDRAWOR_PUBLIC_KEY;
105
105
  const mintPublicKey = new web3_js_1.PublicKey(data.tokenId);
106
106
  if (!sender.publicKey) {
@@ -116,7 +116,8 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
116
116
  const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(amount, totalFee);
117
117
  ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, sender.publicKey, totalAmount)));
118
118
  }
119
- const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.sender.publicKey, undefined, metadata);
119
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
120
+ const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, sender.publicKey, undefined, metadata);
120
121
  const signature = await (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.sender, tx, {
121
122
  hash,
122
123
  context,
@@ -353,7 +354,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
353
354
  */
354
355
  async createMultiple(data, extParams) {
355
356
  const { recipients, ...streamParams } = data;
356
- const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit } = extParams;
357
+ const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit, customInstructions, } = extParams;
357
358
  const metadatas = [];
358
359
  const metadataToRecipient = {};
359
360
  const errors = [];
@@ -377,8 +378,10 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
377
378
  metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
378
379
  computePrice,
379
380
  computeLimit,
381
+ customInstructions,
380
382
  };
381
383
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(createStreamData, createStreamExtParams);
384
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
382
385
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
383
386
  metadatas.push(metadataPubKey.toBase58());
384
387
  instructionsBatch.push({
@@ -460,7 +463,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
460
463
  */
461
464
  async createMultipleSequential(data, extParams) {
462
465
  const { recipients, ...streamParams } = data;
463
- const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit } = extParams;
466
+ const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit, customInstructions, } = extParams;
464
467
  const metadatas = [];
465
468
  const metadataToRecipient = {};
466
469
  const errors = [];
@@ -484,8 +487,10 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
484
487
  metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
485
488
  computePrice,
486
489
  computeLimit,
490
+ customInstructions,
487
491
  };
488
492
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(createStreamData, createStreamExtParams);
493
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
489
494
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
490
495
  metadatas.push(metadataPubKey.toBase58());
491
496
  instructionsBatch.push({
@@ -554,8 +559,14 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
554
559
  * Attempts withdrawing from the specified stream.
555
560
  */
556
561
  async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
562
+ const { invoker, customInstructions } = extParams;
563
+ if (!invoker.publicKey) {
564
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
565
+ }
557
566
  const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
558
- const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
567
+ const metadata = new web3_js_1.PublicKey(id);
568
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
569
+ const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, invoker.publicKey);
559
570
  const signature = await (0, solana_1.signAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
560
571
  hash,
561
572
  context,
@@ -1011,5 +1022,16 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
1011
1022
  const uniqueOwners = Array.from(new Set(owners.map((owner) => owner.toBase58()))).map((pkString) => new web3_js_1.PublicKey(pkString));
1012
1023
  return (0, solana_1.checkOrCreateAtaBatch)(this.connection, uniqueOwners, mint, invoker, programId);
1013
1024
  }
1025
+ async applyCustomAfterInstructions(ixs, customInstructions, metadata) {
1026
+ if (customInstructions?.after) {
1027
+ const afterInstructions = typeof customInstructions.after === "function"
1028
+ ? await customInstructions.after({
1029
+ instructions: ixs,
1030
+ metadata,
1031
+ })
1032
+ : customInstructions.after;
1033
+ ixs.push(...afterInstructions);
1034
+ }
1035
+ }
1014
1036
  }
1015
1037
  exports.SolanaStreamClient = SolanaStreamClient;
@@ -2,7 +2,7 @@
2
2
  "address": "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
3
3
  "metadata": {
4
4
  "name": "streamflow_aligned_unlocks",
5
- "version": "1.1.0",
5
+ "version": "1.1.1",
6
6
  "spec": "0.1.0",
7
7
  "description": "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics"
8
8
  },
@@ -512,12 +512,10 @@
512
512
  }
513
513
  },
514
514
  {
515
- "name": "recipient",
516
- "writable": true
515
+ "name": "recipient"
517
516
  },
518
517
  {
519
518
  "name": "recipient_tokens",
520
- "writable": true,
521
519
  "pda": {
522
520
  "seeds": [
523
521
  {
@@ -1167,6 +1165,20 @@
1167
1165
  ],
1168
1166
  "type": "u64"
1169
1167
  },
1168
+ {
1169
+ "name": "initial_net_amount",
1170
+ "docs": [
1171
+ "Initial deposited amount"
1172
+ ],
1173
+ "type": "u64"
1174
+ },
1175
+ {
1176
+ "name": "mint",
1177
+ "docs": [
1178
+ "Mint for which the contract was created"
1179
+ ],
1180
+ "type": "pubkey"
1181
+ },
1170
1182
  {
1171
1183
  "name": "buffer",
1172
1184
  "docs": [
@@ -1389,6 +1401,10 @@
1389
1401
  {
1390
1402
  "name": "authority",
1391
1403
  "type": "pubkey"
1404
+ },
1405
+ {
1406
+ "name": "mint",
1407
+ "type": "pubkey"
1392
1408
  }
1393
1409
  ]
1394
1410
  }
@@ -2,16 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deriveTestOraclePDA = exports.deriveEscrowPDA = exports.deriveContractPDA = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
- const constants_1 = require("../constants");
5
+ const constants_js_1 = require("../constants.js");
6
6
  const deriveContractPDA = (programId, streamMetadata) => {
7
- return web3_js_1.PublicKey.findProgramAddressSync([constants_1.CONTRACT_SEED, streamMetadata.toBuffer()], programId)[0];
7
+ return web3_js_1.PublicKey.findProgramAddressSync([constants_js_1.CONTRACT_SEED, streamMetadata.toBuffer()], programId)[0];
8
8
  };
9
9
  exports.deriveContractPDA = deriveContractPDA;
10
10
  const deriveEscrowPDA = (programId, streamMetadata) => {
11
- return web3_js_1.PublicKey.findProgramAddressSync([constants_1.ESCROW_SEED, streamMetadata.toBuffer()], programId)[0];
11
+ return web3_js_1.PublicKey.findProgramAddressSync([constants_js_1.ESCROW_SEED, streamMetadata.toBuffer()], programId)[0];
12
12
  };
13
13
  exports.deriveEscrowPDA = deriveEscrowPDA;
14
14
  const deriveTestOraclePDA = (programId, mint, creator) => {
15
- return web3_js_1.PublicKey.findProgramAddressSync([constants_1.TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
15
+ return web3_js_1.PublicKey.findProgramAddressSync([constants_js_1.TEST_ORACLE_SEED, mint.toBuffer(), creator.toBuffer()], programId)[0];
16
16
  };
17
17
  exports.deriveTestOraclePDA = deriveTestOraclePDA;
@@ -5,7 +5,7 @@ import { Program } from "@coral-xyz/anchor";
5
5
  import { ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, ISearchStreams, ICreateStreamInstructions } from "./types.js";
6
6
  import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateResult, ICreateStreamData, IGetAllData, IGetFeesData, IGetOneData, IFees, IMultiTransactionResult, ITopUpData, ITransactionResult, ITransferData, IUpdateData, IWithdrawData, Stream, ICreateAlignedStreamData, SolanaStreamClientOptions } from "../common/types.js";
7
7
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
8
- import { StreamflowAlignedUnlocks as AlignedUnlocksProgramType } from "./descriptor/streamflow_aligned_unlocks";
8
+ import { StreamflowAlignedUnlocks as AlignedUnlocksProgramType } from "./descriptor/streamflow_aligned_unlocks.js";
9
9
  /**
10
10
  * Solana Client creation options
11
11
  * @property cluster {@link ICluster} cluster type
@@ -146,4 +146,5 @@ export declare class SolanaStreamClient extends BaseStreamClient {
146
146
  * Returns insrtuctions for creating associated token accounts for the provided owners
147
147
  */
148
148
  private getCreateATAInstructions;
149
+ private applyCustomAfterInstructions;
149
150
  }
@@ -76,7 +76,7 @@ export class SolanaStreamClient extends BaseStreamClient {
76
76
  */
77
77
  async create(data, extParams) {
78
78
  const { partner, amount, tokenProgramId } = data;
79
- const { isNative, sender } = extParams;
79
+ const { isNative, sender, customInstructions } = extParams;
80
80
  const partnerPublicKey = partner ? new PublicKey(partner) : WITHDRAWOR_PUBLIC_KEY;
81
81
  const mintPublicKey = new PublicKey(data.tokenId);
82
82
  if (!sender.publicKey) {
@@ -92,7 +92,8 @@ export class SolanaStreamClient extends BaseStreamClient {
92
92
  const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
93
93
  ixs.push(...(await prepareWrappedAccount(this.connection, sender.publicKey, totalAmount)));
94
94
  }
95
- const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.sender.publicKey, undefined, metadata);
95
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
96
+ const { tx, hash, context } = await prepareTransaction(this.connection, ixs, sender.publicKey, undefined, metadata);
96
97
  const signature = await signAndExecuteTransaction(this.connection, extParams.sender, tx, {
97
98
  hash,
98
99
  context,
@@ -329,7 +330,7 @@ export class SolanaStreamClient extends BaseStreamClient {
329
330
  */
330
331
  async createMultiple(data, extParams) {
331
332
  const { recipients, ...streamParams } = data;
332
- const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit } = extParams;
333
+ const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit, customInstructions, } = extParams;
333
334
  const metadatas = [];
334
335
  const metadataToRecipient = {};
335
336
  const errors = [];
@@ -353,8 +354,10 @@ export class SolanaStreamClient extends BaseStreamClient {
353
354
  metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
354
355
  computePrice,
355
356
  computeLimit,
357
+ customInstructions,
356
358
  };
357
359
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(createStreamData, createStreamExtParams);
360
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
358
361
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
359
362
  metadatas.push(metadataPubKey.toBase58());
360
363
  instructionsBatch.push({
@@ -436,7 +439,7 @@ export class SolanaStreamClient extends BaseStreamClient {
436
439
  */
437
440
  async createMultipleSequential(data, extParams) {
438
441
  const { recipients, ...streamParams } = data;
439
- const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit } = extParams;
442
+ const { sender, metadataPubKeys: metadataPubKeysExt, isNative, computePrice, computeLimit, customInstructions, } = extParams;
440
443
  const metadatas = [];
441
444
  const metadataToRecipient = {};
442
445
  const errors = [];
@@ -460,8 +463,10 @@ export class SolanaStreamClient extends BaseStreamClient {
460
463
  metadataPubKeys: metadataPubKeys[i] ? [metadataPubKeys[i]] : undefined,
461
464
  computePrice,
462
465
  computeLimit,
466
+ customInstructions,
463
467
  };
464
468
  const { ixs, metadata, metadataPubKey } = await this.prepareCreateInstructions(createStreamData, createStreamExtParams);
469
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadataPubKey);
465
470
  metadataToRecipient[metadataPubKey.toBase58()] = recipientData;
466
471
  metadatas.push(metadataPubKey.toBase58());
467
472
  instructionsBatch.push({
@@ -530,8 +535,14 @@ export class SolanaStreamClient extends BaseStreamClient {
530
535
  * Attempts withdrawing from the specified stream.
531
536
  */
532
537
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, extParams) {
538
+ const { invoker, customInstructions } = extParams;
539
+ if (!invoker.publicKey) {
540
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
541
+ }
533
542
  const ixs = await this.prepareWithdrawInstructions({ id, amount }, extParams);
534
- const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
543
+ const metadata = new PublicKey(id);
544
+ await this.applyCustomAfterInstructions(ixs, customInstructions, metadata);
545
+ const { tx, hash, context } = await prepareTransaction(this.connection, ixs, invoker.publicKey);
535
546
  const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, {
536
547
  hash,
537
548
  context,
@@ -987,4 +998,15 @@ export class SolanaStreamClient extends BaseStreamClient {
987
998
  const uniqueOwners = Array.from(new Set(owners.map((owner) => owner.toBase58()))).map((pkString) => new PublicKey(pkString));
988
999
  return checkOrCreateAtaBatch(this.connection, uniqueOwners, mint, invoker, programId);
989
1000
  }
1001
+ async applyCustomAfterInstructions(ixs, customInstructions, metadata) {
1002
+ if (customInstructions?.after) {
1003
+ const afterInstructions = typeof customInstructions.after === "function"
1004
+ ? await customInstructions.after({
1005
+ instructions: ixs,
1006
+ metadata,
1007
+ })
1008
+ : customInstructions.after;
1009
+ ixs.push(...afterInstructions);
1010
+ }
1011
+ }
990
1012
  }
@@ -2,7 +2,7 @@
2
2
  "address": "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH",
3
3
  "metadata": {
4
4
  "name": "streamflow_aligned_unlocks",
5
- "version": "1.1.0",
5
+ "version": "1.1.1",
6
6
  "spec": "0.1.0",
7
7
  "description": "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics"
8
8
  },
@@ -512,12 +512,10 @@
512
512
  }
513
513
  },
514
514
  {
515
- "name": "recipient",
516
- "writable": true
515
+ "name": "recipient"
517
516
  },
518
517
  {
519
518
  "name": "recipient_tokens",
520
- "writable": true,
521
519
  "pda": {
522
520
  "seeds": [
523
521
  {
@@ -1167,6 +1165,20 @@
1167
1165
  ],
1168
1166
  "type": "u64"
1169
1167
  },
1168
+ {
1169
+ "name": "initial_net_amount",
1170
+ "docs": [
1171
+ "Initial deposited amount"
1172
+ ],
1173
+ "type": "u64"
1174
+ },
1175
+ {
1176
+ "name": "mint",
1177
+ "docs": [
1178
+ "Mint for which the contract was created"
1179
+ ],
1180
+ "type": "pubkey"
1181
+ },
1170
1182
  {
1171
1183
  "name": "buffer",
1172
1184
  "docs": [
@@ -1389,6 +1401,10 @@
1389
1401
  {
1390
1402
  "name": "authority",
1391
1403
  "type": "pubkey"
1404
+ },
1405
+ {
1406
+ "name": "mint",
1407
+ "type": "pubkey"
1392
1408
  }
1393
1409
  ]
1394
1410
  }
@@ -8,7 +8,7 @@ export type StreamflowAlignedUnlocks = {
8
8
  address: "aSTRM2NKoKxNnkmLWk9sz3k74gKBk9t7bpPrTGxMszH";
9
9
  metadata: {
10
10
  name: "streamflowAlignedUnlocks";
11
- version: "1.1.0";
11
+ version: "1.1.1";
12
12
  spec: "0.1.0";
13
13
  description: "Proxy to update unlock amount within Streamflow vesting protocol according to Token performance and other metrics";
14
14
  };
@@ -466,11 +466,9 @@ export type StreamflowAlignedUnlocks = {
466
466
  },
467
467
  {
468
468
  name: "recipient";
469
- writable: true;
470
469
  },
471
470
  {
472
471
  name: "recipientTokens";
473
- writable: true;
474
472
  pda: {
475
473
  seeds: [
476
474
  {
@@ -1002,6 +1000,16 @@ export type StreamflowAlignedUnlocks = {
1002
1000
  docs: ["Initial token price at the time of Contract creation"];
1003
1001
  type: "u64";
1004
1002
  },
1003
+ {
1004
+ name: "initialNetAmount";
1005
+ docs: ["Initial deposited amount"];
1006
+ type: "u64";
1007
+ },
1008
+ {
1009
+ name: "mint";
1010
+ docs: ["Mint for which the contract was created"];
1011
+ type: "pubkey";
1012
+ },
1005
1013
  {
1006
1014
  name: "buffer";
1007
1015
  docs: ["Buffer for additional fields"];
@@ -1188,6 +1196,10 @@ export type StreamflowAlignedUnlocks = {
1188
1196
  {
1189
1197
  name: "authority";
1190
1198
  type: "pubkey";
1199
+ },
1200
+ {
1201
+ name: "mint";
1202
+ type: "pubkey";
1191
1203
  }
1192
1204
  ];
1193
1205
  };
@@ -1,5 +1,5 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
- import { CONTRACT_SEED, ESCROW_SEED, TEST_ORACLE_SEED } from "../constants";
2
+ import { CONTRACT_SEED, ESCROW_SEED, TEST_ORACLE_SEED } from "../constants.js";
3
3
  export const deriveContractPDA = (programId, streamMetadata) => {
4
4
  return PublicKey.findProgramAddressSync([CONTRACT_SEED, streamMetadata.toBuffer()], programId)[0];
5
5
  };
@@ -29,11 +29,16 @@ export interface ICreateSolanaExt {
29
29
  sender: SignerWalletAdapter | Keypair;
30
30
  isNative?: boolean;
31
31
  }
32
- export interface ICreateStreamSolanaExt extends ICreateSolanaExt, ITransactionSolanaExt {
32
+ export interface ITransactionSolanaExtWithInstructions extends ITransactionSolanaExt {
33
+ customInstructions?: {
34
+ after?: InstructionGenerator;
35
+ };
36
+ }
37
+ export interface ICreateStreamSolanaExt extends ICreateSolanaExt, ITransactionSolanaExtWithInstructions {
33
38
  metadataPubKeys?: PublicKey[];
34
39
  partner?: string | null;
35
40
  }
36
- export interface IInteractStreamSolanaExt extends ITransactionSolanaExt {
41
+ export interface IInteractStreamSolanaExt extends ITransactionSolanaExtWithInstructions {
37
42
  invoker: SignerWalletAdapter | Keypair;
38
43
  checkTokenAccounts?: boolean;
39
44
  }
@@ -164,3 +169,7 @@ export interface BatchItemError extends BatchItem {
164
169
  error: string;
165
170
  }
166
171
  export type BatchItemResult = BatchItemSuccess | BatchItemError;
172
+ export type InstructionGenerator = TransactionInstruction[] | ((params: {
173
+ instructions: TransactionInstruction[];
174
+ metadata?: PublicKey;
175
+ }) => TransactionInstruction[] | Promise<TransactionInstruction[]>);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "7.4.7",
3
+ "version": "7.4.9",
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,9 +42,9 @@
42
42
  "lint": "eslint --fix .",
43
43
  "prepublishOnly": "pnpm run lint && pnpm run test run && pnpm run build"
44
44
  },
45
- "gitHead": "547087120cbe214f96bf08adca92466a5d449edf",
45
+ "gitHead": "3d238ef48e2ce620bac3eb9936c965a891acd943",
46
46
  "devDependencies": {
47
- "@streamflow/eslint-config": "7.4.7",
47
+ "@streamflow/eslint-config": "7.4.9",
48
48
  "@types/bn.js": "5.1.1",
49
49
  "@types/ethereum-checksum-address": "^0.0.0",
50
50
  "date-fns": "2.28.0",
@@ -59,7 +59,7 @@
59
59
  "@solana/spl-token": "0.4.9",
60
60
  "@solana/wallet-adapter-base": "0.9.19",
61
61
  "@solana/web3.js": "1.95.4",
62
- "@streamflow/common": "7.4.7",
62
+ "@streamflow/common": "7.4.9",
63
63
  "@suiet/wallet-kit": "^0.3.3",
64
64
  "aptos": "1.21.0",
65
65
  "bn.js": "5.2.1",