@streamflow/stream 4.0.0 → 4.0.1

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,5 +1,5 @@
1
1
  import { BaseStreamClient } from "../common/BaseStreamClient";
2
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
2
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
3
3
  import { Contract, ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "./types";
4
4
  export default class AptosStreamClient extends BaseStreamClient {
5
5
  private programId;
@@ -34,10 +34,6 @@ export default class AptosStreamClient extends BaseStreamClient {
34
34
  * Fetch stream data by its id (address).
35
35
  */
36
36
  getOne({ id }: IGetOneData): Promise<Contract>;
37
- /**
38
- * Attempts updating the stream auto withdrawal params and amount per period
39
- */
40
- update(updateData: IUpdateData, { senderWallet, tokenId }: ITransactionAptosExt): Promise<ITransactionResult>;
41
37
  /**
42
38
  * Returns StreamClient protocol program ID.
43
39
  */
@@ -287,35 +287,6 @@ var AptosStreamClient = /** @class */ (function (_super) {
287
287
  });
288
288
  });
289
289
  };
290
- /**
291
- * Attempts updating the stream auto withdrawal params and amount per period
292
- */
293
- AptosStreamClient.prototype.update = function (updateData, _a) {
294
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
295
- return __awaiter(this, void 0, void 0, function () {
296
- var payload, hash;
297
- return __generator(this, function (_b) {
298
- switch (_b.label) {
299
- case 0:
300
- payload = {
301
- type: "update",
302
- function: "".concat(this.programId, "::protocol::update"),
303
- type_arguments: [tokenId],
304
- arguments: [
305
- updateData.id,
306
- updateData.enableAutomaticWithdrawal ? [true] : [],
307
- updateData.withdrawFrequency ? [updateData.withdrawFrequency.toString()] : [],
308
- updateData.amountPerPeriod ? [updateData.amountPerPeriod.toString()] : [],
309
- ],
310
- };
311
- return [4 /*yield*/, senderWallet.signAndSubmitTransaction(payload)];
312
- case 1:
313
- hash = (_b.sent()).hash;
314
- return [2 /*return*/, { txId: hash }];
315
- }
316
- });
317
- });
318
- };
319
290
  /**
320
291
  * Returns StreamClient protocol program ID.
321
292
  */
@@ -1,4 +1,4 @@
1
- import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData } from "./types";
1
+ import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData } from "./types";
2
2
  export declare abstract class BaseStreamClient {
3
3
  protected abstract create(streamData: ICreateStreamData, chainSpecificParams: any): Promise<any>;
4
4
  protected abstract createMultiple(multipleStreamData: ICreateMultipleStreamData, chainSpecificParams: any): Promise<any>;
@@ -7,5 +7,4 @@ export declare abstract class BaseStreamClient {
7
7
  protected abstract transfer(transferData: ITransferData, chainSpecificParams: any): Promise<any>;
8
8
  protected abstract topup(topupData: ITopUpData, chainSpecificParams: any): Promise<any>;
9
9
  protected abstract getOne(getOneData: IGetOneData, chainSpecificParams: any): Promise<any>;
10
- protected abstract update(updateData: IUpdateData, chainSpecificParams: any): Promise<any>;
11
10
  }
@@ -2,7 +2,7 @@ import { Commitment, ConnectionConfig } from "@solana/web3.js";
2
2
  import SolanaStreamClient from "../solana/StreamClient";
3
3
  import AptosStreamClient from "../aptos/StreamClient";
4
4
  import { BaseStreamClient } from "./BaseStreamClient";
5
- import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "./types";
5
+ import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "./types";
6
6
  import { CreateMultiResponse, CreateResponse, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt, Stream, TxResponse } from "../solana";
7
7
  import { ICreateStreamAptosExt, IMultiTransactionResult, ITransactionAptosExt, ITransactionResult } from "../aptos";
8
8
  export interface SolanaStreamClientOptions {
@@ -52,9 +52,5 @@ export default class GenericStreamClient extends BaseStreamClient {
52
52
  * Fetch stream data by its id (address).
53
53
  */
54
54
  getOne(getOneData: IGetOneData): Promise<Stream>;
55
- /**
56
- * Attempts updating the stream auto withdrawal params and amount per period
57
- */
58
- update(updateData: IUpdateData, chainSpecificParams: ITransactionAptosExt | IInteractStreamSolanaExt): Promise<TxResponse | ITransactionResult>;
59
55
  }
60
56
  export {};
@@ -119,19 +119,6 @@ var GenericStreamClient = /** @class */ (function (_super) {
119
119
  GenericStreamClient.prototype.getOne = function (getOneData) {
120
120
  return this.nativeStreamClient.getOne(getOneData);
121
121
  };
122
- /**
123
- * Attempts updating the stream auto withdrawal params and amount per period
124
- */
125
- GenericStreamClient.prototype.update = function (updateData, chainSpecificParams) {
126
- if (this.nativeStreamClient instanceof StreamClient_1.default) {
127
- var params = chainSpecificParams;
128
- return this.nativeStreamClient.update(updateData, params);
129
- }
130
- else {
131
- var params = chainSpecificParams;
132
- return this.nativeStreamClient.update(updateData, params);
133
- }
134
- };
135
122
  return GenericStreamClient;
136
123
  }(BaseStreamClient_1.BaseStreamClient));
137
124
  exports.default = GenericStreamClient;
@@ -29,12 +29,6 @@ export interface IWithdrawData {
29
29
  id: string;
30
30
  amount: BN;
31
31
  }
32
- export interface IUpdateData {
33
- id: string;
34
- enableAutomaticWithdrawal?: boolean;
35
- withdrawFrequency?: BN;
36
- amountPerPeriod?: BN;
37
- }
38
32
  export interface ICancelData {
39
33
  id: string;
40
34
  }
@@ -1,6 +1,6 @@
1
1
  import { Connection, Commitment, ConnectionConfig } from "@solana/web3.js";
2
2
  import { Stream as StreamData, GetAllParams, CreateResponse, CreateMultiResponse, TxResponse, ICreateStreamSolanaExt, IInteractStreamSolanaExt, ITopUpStreamSolanaExt } from "./types";
3
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
3
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
4
4
  import { BaseStreamClient } from "../common/BaseStreamClient";
5
5
  export default class SolanaStreamClient extends BaseStreamClient {
6
6
  private connection;
@@ -60,10 +60,6 @@ export default class SolanaStreamClient extends BaseStreamClient {
60
60
  */
61
61
  get({ wallet, type, direction, }: GetAllParams): Promise<[string, StreamData][]>;
62
62
  private sign;
63
- /**
64
- * Attempts updating the stream auto withdrawal params and amount per period
65
- */
66
- update(data: IUpdateData, { invoker }: IInteractStreamSolanaExt): Promise<TxResponse>;
67
63
  /**
68
64
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
69
65
  */
@@ -757,25 +757,26 @@ var SolanaStreamClient = /** @class */ (function (_super) {
757
757
  };
758
758
  SolanaStreamClient.prototype.sign = function (invoker, tx, hash) {
759
759
  return __awaiter(this, void 0, void 0, function () {
760
- var rawTx, confirmationStrategy, signature;
760
+ var signedTx, rawTx, confirmationStrategy, signature;
761
761
  return __generator(this, function (_a) {
762
762
  switch (_a.label) {
763
763
  case 0:
764
764
  if (!(0, utils_1.isSignerWallet)(invoker)) return [3 /*break*/, 2];
765
765
  return [4 /*yield*/, invoker.signTransaction(tx)];
766
766
  case 1:
767
- _a.sent();
767
+ signedTx = _a.sent();
768
768
  return [3 /*break*/, 3];
769
769
  case 2:
770
770
  tx.partialSign(invoker);
771
+ signedTx = tx;
771
772
  _a.label = 3;
772
773
  case 3:
773
- rawTx = tx.serialize();
774
- if (!hash.lastValidBlockHeight || !tx.signature || !hash.blockhash)
774
+ rawTx = signedTx.serialize();
775
+ if (!hash.lastValidBlockHeight || !signedTx.signature || !hash.blockhash)
775
776
  throw Error("Error with transaction parameters.");
776
777
  confirmationStrategy = {
777
778
  lastValidBlockHeight: hash.lastValidBlockHeight,
778
- signature: bs58_1.default.encode(tx.signature),
779
+ signature: bs58_1.default.encode(signedTx.signature),
779
780
  blockhash: hash.blockhash,
780
781
  };
781
782
  return [4 /*yield*/, (0, web3_js_1.sendAndConfirmRawTransaction)(this.connection, rawTx, confirmationStrategy)];
@@ -786,51 +787,6 @@ var SolanaStreamClient = /** @class */ (function (_super) {
786
787
  });
787
788
  });
788
789
  };
789
- /**
790
- * Attempts updating the stream auto withdrawal params and amount per period
791
- */
792
- SolanaStreamClient.prototype.update = function (data, _a) {
793
- var invoker = _a.invoker;
794
- return __awaiter(this, void 0, void 0, function () {
795
- var ixs, streamPublicKey, escrow, commitment, hash, tx, signature;
796
- var _b;
797
- return __generator(this, function (_c) {
798
- switch (_c.label) {
799
- case 0:
800
- if (!invoker.publicKey) {
801
- throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
802
- }
803
- ixs = [];
804
- streamPublicKey = new web3_js_1.PublicKey(data.id);
805
- return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
806
- case 1:
807
- escrow = _c.sent();
808
- if (!(escrow === null || escrow === void 0 ? void 0 : escrow.data)) {
809
- throw new Error("Couldn't get account info");
810
- }
811
- ixs.push((0, instructions_1.updateStreamInstruction)(data, this.programId, {
812
- authority: invoker.publicKey,
813
- metadata: streamPublicKey,
814
- withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
815
- systemProgram: web3_js_1.SystemProgram.programId,
816
- }));
817
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
818
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
819
- case 2:
820
- hash = _c.sent();
821
- tx = (_b = new web3_js_1.Transaction({
822
- feePayer: invoker.publicKey,
823
- blockhash: hash.blockhash,
824
- lastValidBlockHeight: hash.lastValidBlockHeight,
825
- })).add.apply(_b, __spreadArray([], __read(ixs), false));
826
- return [4 /*yield*/, this.sign(invoker, tx, hash)];
827
- case 3:
828
- signature = _c.sent();
829
- return [2 /*return*/, { ixs: ixs, tx: signature }];
830
- }
831
- });
832
- });
833
- };
834
790
  /**
835
791
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
836
792
  */
@@ -76,11 +76,6 @@ export interface ICreateUncheckedStreamLayout {
76
76
  export interface IWithdrawStreamLayout {
77
77
  amount: Uint8Array;
78
78
  }
79
- export interface IUpdateStreamLayout {
80
- enable_automatic_withdrawal?: number;
81
- withdraw_frequency?: Uint8Array;
82
- amount_per_period?: Uint8Array;
83
- }
84
79
  export interface ITopupStreamLayout {
85
80
  amount: Uint8Array;
86
81
  }
@@ -1,6 +1,5 @@
1
1
  import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
2
2
  import BN from "bn.js";
3
- import { IUpdateData } from "../common/types";
4
3
  interface CreateStreamData {
5
4
  start: BN;
6
5
  depositedAmount: BN;
@@ -85,13 +84,6 @@ interface WithdrawAccounts {
85
84
  tokenProgram: PublicKey;
86
85
  }
87
86
  export declare const withdrawStreamInstruction: (amount: BN, programId: PublicKey, { authority, recipient, recipientTokens, metadata, escrowTokens, streamflowTreasury, streamflowTreasuryTokens, partner, partnerTokens, mint, tokenProgram, }: WithdrawAccounts) => TransactionInstruction;
88
- interface UpdateAccounts {
89
- authority: PublicKey;
90
- metadata: PublicKey;
91
- withdrawor: PublicKey;
92
- systemProgram: PublicKey;
93
- }
94
- export declare const updateStreamInstruction: (params: IUpdateData, programId: PublicKey, { authority, metadata, withdrawor, systemProgram }: UpdateAccounts) => TransactionInstruction;
95
87
  interface CancelAccounts {
96
88
  authority: PublicKey;
97
89
  sender: PublicKey;
@@ -87,7 +87,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
87
87
  return (mod && mod.__esModule) ? mod : { "default": mod };
88
88
  };
89
89
  Object.defineProperty(exports, "__esModule", { value: true });
90
- exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
90
+ exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
91
91
  var buffer_1 = require("buffer");
92
92
  var web3_js_1 = require("@solana/web3.js");
93
93
  var bn_js_1 = __importDefault(require("bn.js"));
@@ -253,35 +253,6 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
253
253
  });
254
254
  };
255
255
  exports.withdrawStreamInstruction = withdrawStreamInstruction;
256
- var updateStreamInstruction = function (params, programId, _a) {
257
- var _b, _c;
258
- var authority = _a.authority, metadata = _a.metadata, withdrawor = _a.withdrawor, systemProgram = _a.systemProgram;
259
- var keys = [
260
- { pubkey: authority, isSigner: true, isWritable: true },
261
- { pubkey: metadata, isSigner: false, isWritable: true },
262
- { pubkey: withdrawor, isSigner: false, isWritable: true },
263
- { pubkey: systemProgram, isSigner: false, isWritable: false },
264
- ];
265
- var data = buffer_1.Buffer.alloc(100);
266
- var decodedData = {
267
- enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
268
- withdraw_frequency: (_b = params.withdrawFrequency) === null || _b === void 0 ? void 0 : _b.toArrayLike(buffer_1.Buffer, "le", 8),
269
- amount_per_period: (_c = params.amountPerPeriod) === null || _c === void 0 ? void 0 : _c.toArrayLike(buffer_1.Buffer, "le", 8),
270
- };
271
- var encodeLength = Layout.encodeUpdateStream(decodedData, data);
272
- data = data.slice(0, encodeLength);
273
- data = buffer_1.Buffer.concat([
274
- buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:update")).slice(0, 8),
275
- data,
276
- buffer_1.Buffer.alloc(20),
277
- ]);
278
- return new web3_js_1.TransactionInstruction({
279
- keys: keys,
280
- programId: programId,
281
- data: data,
282
- });
283
- };
284
- exports.updateStreamInstruction = updateStreamInstruction;
285
256
  var cancelStreamInstruction = function (programId, _a) {
286
257
  var authority = _a.authority, sender = _a.sender, senderTokens = _a.senderTokens, recipient = _a.recipient, recipientTokens = _a.recipientTokens, metadata = _a.metadata, escrowTokens = _a.escrowTokens, streamflowTreasury = _a.streamflowTreasury, streamflowTreasuryTokens = _a.streamflowTreasuryTokens, partner = _a.partner, partnerTokens = _a.partnerTokens, mint = _a.mint, tokenProgram = _a.tokenProgram;
287
258
  var keys = [
@@ -1,6 +1,5 @@
1
- /// <reference types="node" />
2
1
  import * as BufferLayout from "@solana/buffer-layout";
3
- import { ICreateStreamLayout, ICreateUncheckedStreamLayout, IStreamLayout, ITopupStreamLayout, IUpdateStreamLayout, IWithdrawStreamLayout } from "./instructionTypes";
2
+ import { ICreateStreamLayout, ICreateUncheckedStreamLayout, IStreamLayout, ITopupStreamLayout, IWithdrawStreamLayout } from "./instructionTypes";
4
3
  /**
5
4
  * Stream layout
6
5
  */
@@ -17,10 +16,6 @@ export declare const createUncheckedStreamLayout: BufferLayout.Structure<ICreate
17
16
  * Withdraw stream instruction layout
18
17
  */
19
18
  export declare const withdrawStreamLayout: BufferLayout.Structure<IWithdrawStreamLayout>;
20
- /**
21
- * Encode stream instruction layout
22
- */
23
- export declare const encodeUpdateStream: (values: IUpdateStreamLayout, data: Buffer) => number;
24
19
  /**
25
20
  * Topup stream instruction layout
26
21
  */
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.topupStreamLayout = exports.encodeUpdateStream = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
26
+ exports.topupStreamLayout = exports.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
27
27
  var BufferLayout = __importStar(require("@solana/buffer-layout"));
28
28
  /**
29
29
  * Stream layout
@@ -113,43 +113,6 @@ exports.createUncheckedStreamLayout = BufferLayout.struct([
113
113
  * Withdraw stream instruction layout
114
114
  */
115
115
  exports.withdrawStreamLayout = BufferLayout.struct([BufferLayout.blob(8, "amount")]);
116
- /**
117
- * Encode stream instruction layout
118
- */
119
- var encodeUpdateStream = function (values, data) {
120
- var _a, _b, _c;
121
- var structs = [];
122
- if (values.enable_automatic_withdrawal) {
123
- structs.push(BufferLayout.u8("enable_automatic_withdrawal_exists"));
124
- structs.push(BufferLayout.u8("enable_automatic_withdrawal"));
125
- }
126
- else {
127
- structs.push(BufferLayout.u8("enable_automatic_withdrawal_exists"));
128
- }
129
- if (values.withdraw_frequency) {
130
- structs.push(BufferLayout.u8("withdraw_frequency_exists"));
131
- structs.push(BufferLayout.blob(8, "withdraw_frequency"));
132
- }
133
- else {
134
- structs.push(BufferLayout.u8("withdraw_frequency_exists"));
135
- }
136
- if (values.amount_per_period) {
137
- structs.push(BufferLayout.u8("amount_per_period_exists"));
138
- structs.push(BufferLayout.blob(8, "amount_per_period"));
139
- }
140
- else {
141
- structs.push(BufferLayout.u8("amount_per_period_exists"));
142
- }
143
- return BufferLayout.struct(structs).encode({
144
- enable_automatic_withdrawal_exists: values.enable_automatic_withdrawal ? 1 : 0,
145
- enable_automatic_withdrawal: (_a = values.enable_automatic_withdrawal) !== null && _a !== void 0 ? _a : 0,
146
- withdraw_frequency_exists: values.withdraw_frequency ? 1 : 0,
147
- withdraw_frequency: (_b = values.withdraw_frequency) !== null && _b !== void 0 ? _b : new Uint8Array(),
148
- amount_per_period_exists: values.amount_per_period ? 1 : 0,
149
- amount_per_period: (_c = values.amount_per_period) !== null && _c !== void 0 ? _c : new Uint8Array(),
150
- }, data);
151
- };
152
- exports.encodeUpdateStream = encodeUpdateStream;
153
116
  /**
154
117
  * Topup stream instruction layout
155
118
  */
@@ -195,28 +195,26 @@ exports.isSignerWallet = isSignerWallet;
195
195
  */
196
196
  function signAllTransactionWithRecipients(sender, items) {
197
197
  return __awaiter(this, void 0, void 0, function () {
198
- var signed_batch, isKeypair, isWallet;
198
+ var isKeypair, isWallet, signedTxs_1;
199
199
  return __generator(this, function (_a) {
200
200
  switch (_a.label) {
201
201
  case 0:
202
- signed_batch = [];
203
202
  isKeypair = sender instanceof web3_js_1.Keypair;
204
203
  isWallet = isSignerWallet(sender);
205
- if (!isKeypair && !isWallet)
206
- return [2 /*return*/, signed_batch];
207
204
  if (!isKeypair) return [3 /*break*/, 1];
208
- items.map(function (t) {
209
- t.tx.partialSign(sender);
210
- return { tx: t.tx, recipient: t.recipient };
211
- });
212
- return [3 /*break*/, 3];
205
+ return [2 /*return*/, items.map(function (t) {
206
+ t.tx.partialSign(sender);
207
+ return { tx: t.tx, recipient: t.recipient };
208
+ })];
213
209
  case 1:
214
210
  if (!isWallet) return [3 /*break*/, 3];
215
211
  return [4 /*yield*/, sender.signAllTransactions(items.map(function (t) { return t.tx; }))];
216
212
  case 2:
217
- _a.sent();
218
- _a.label = 3;
219
- case 3: return [2 /*return*/, items];
213
+ signedTxs_1 = _a.sent();
214
+ return [2 /*return*/, items.map(function (item, index) { return (__assign(__assign({}, item), { tx: signedTxs_1[index] })); })];
215
+ case 3:
216
+ // If signer is not passed
217
+ return [2 /*return*/, []];
220
218
  }
221
219
  });
222
220
  });
@@ -250,7 +248,7 @@ function sendAndConfirmStreamRawTransaction(connection, batchItem) {
250
248
  return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
251
249
  case 2:
252
250
  error_1 = _b.sent();
253
- throw { recipient: batchItem.recipient, error: error_1.toString() };
251
+ throw { recipient: batchItem.recipient, error: error_1 };
254
252
  case 3: return [2 /*return*/];
255
253
  }
256
254
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "JavaScript SDK to interact with Streamflow protocol.",
5
5
  "main": "dist/index.js",
6
6
  "homepage": "https://github.com/streamflow-finance/js-sdk/",