@streamflow/stream 4.0.1 → 4.0.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.
@@ -1,5 +1,5 @@
1
1
  import { BaseStreamClient } from "../common/BaseStreamClient";
2
- import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IWithdrawData } from "../common/types";
2
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, 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,6 +34,10 @@ 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>;
37
41
  /**
38
42
  * Returns StreamClient protocol program ID.
39
43
  */
@@ -287,6 +287,35 @@ 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
+ };
290
319
  /**
291
320
  * Returns StreamClient protocol program ID.
292
321
  */
@@ -1,4 +1,4 @@
1
- import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData } from "./types";
1
+ import { ICreateStreamData, ICreateMultipleStreamData, IWithdrawData, ICancelData, ITransferData, ITopUpData, IGetOneData, IUpdateData } 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,4 +7,5 @@ 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>;
10
11
  }
@@ -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, IWithdrawData } from "./types";
5
+ import { ICancelData, IChain, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, 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,5 +52,9 @@ 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>;
55
59
  }
56
60
  export {};
@@ -119,6 +119,19 @@ 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
+ };
122
135
  return GenericStreamClient;
123
136
  }(BaseStreamClient_1.BaseStreamClient));
124
137
  exports.default = GenericStreamClient;
@@ -29,6 +29,12 @@ 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
+ }
32
38
  export interface ICancelData {
33
39
  id: string;
34
40
  }
@@ -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, IWithdrawData } from "../common/types";
3
+ import { ICancelData, ICluster, ICreateMultipleStreamData, ICreateStreamData, IGetOneData, ITopUpData, ITransferData, IUpdateData, IWithdrawData } from "../common/types";
4
4
  import { BaseStreamClient } from "../common/BaseStreamClient";
5
5
  export default class SolanaStreamClient extends BaseStreamClient {
6
6
  private connection;
@@ -60,6 +60,10 @@ 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>;
63
67
  /**
64
68
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
65
69
  */
@@ -787,6 +787,52 @@ var SolanaStreamClient = /** @class */ (function (_super) {
787
787
  });
788
788
  });
789
789
  };
790
+ /**
791
+ * Attempts updating the stream auto withdrawal params and amount per period
792
+ */
793
+ SolanaStreamClient.prototype.update = function (data, _a) {
794
+ var invoker = _a.invoker;
795
+ return __awaiter(this, void 0, void 0, function () {
796
+ var streamPublicKey, escrow, updateIx, commitment, hash, tx, signature;
797
+ return __generator(this, function (_b) {
798
+ switch (_b.label) {
799
+ case 0:
800
+ if (!invoker.publicKey) {
801
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
802
+ }
803
+ streamPublicKey = new web3_js_1.PublicKey(data.id);
804
+ return [4 /*yield*/, this.connection.getAccountInfo(streamPublicKey)];
805
+ case 1:
806
+ escrow = _b.sent();
807
+ if (!escrow) {
808
+ throw new Error("Couldn't get account info");
809
+ }
810
+ updateIx = (0, instructions_1.updateStreamInstruction)(data, this.programId, {
811
+ authority: invoker.publicKey,
812
+ metadata: streamPublicKey,
813
+ withdrawor: constants_1.WITHDRAWOR_PUBLIC_KEY,
814
+ systemProgram: web3_js_1.SystemProgram.programId,
815
+ });
816
+ commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
817
+ return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
818
+ case 2:
819
+ hash = _b.sent();
820
+ tx = new web3_js_1.Transaction({
821
+ feePayer: invoker.publicKey,
822
+ blockhash: hash.blockhash,
823
+ lastValidBlockHeight: hash.lastValidBlockHeight,
824
+ }).add(updateIx);
825
+ return [4 /*yield*/, this.sign(invoker, tx, hash)];
826
+ case 3:
827
+ signature = _b.sent();
828
+ return [2 /*return*/, {
829
+ ixs: [updateIx],
830
+ tx: signature,
831
+ }];
832
+ }
833
+ });
834
+ });
835
+ };
790
836
  /**
791
837
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
792
838
  */
@@ -76,6 +76,11 @@ 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
+ }
79
84
  export interface ITopupStreamLayout {
80
85
  amount: Uint8Array;
81
86
  }
@@ -1,5 +1,6 @@
1
1
  import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
2
2
  import BN from "bn.js";
3
+ import { IUpdateData } from "../common/types";
3
4
  interface CreateStreamData {
4
5
  start: BN;
5
6
  depositedAmount: BN;
@@ -84,6 +85,13 @@ interface WithdrawAccounts {
84
85
  tokenProgram: PublicKey;
85
86
  }
86
87
  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;
87
95
  interface CancelAccounts {
88
96
  authority: PublicKey;
89
97
  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.withdrawStreamInstruction = exports.createUncheckedStreamInstruction = exports.createStreamInstruction = void 0;
90
+ exports.prepareWrappedAccount = exports.topupStreamInstruction = exports.transferStreamInstruction = exports.cancelStreamInstruction = exports.updateStreamInstruction = 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,6 +253,38 @@ var withdrawStreamInstruction = function (amount, programId, _a) {
253
253
  });
254
254
  };
255
255
  exports.withdrawStreamInstruction = withdrawStreamInstruction;
256
+ var updateStreamInstruction = function (params, programId, _a) {
257
+ var authority = _a.authority, metadata = _a.metadata, withdrawor = _a.withdrawor, systemProgram = _a.systemProgram;
258
+ var keys = [
259
+ { pubkey: authority, isSigner: true, isWritable: true },
260
+ { pubkey: metadata, isSigner: false, isWritable: true },
261
+ { pubkey: withdrawor, isSigner: false, isWritable: true },
262
+ { pubkey: systemProgram, isSigner: false, isWritable: false },
263
+ ];
264
+ var data = buffer_1.Buffer.alloc(100);
265
+ var decodedData = {
266
+ enable_automatic_withdrawal: Number(params.enableAutomaticWithdrawal),
267
+ withdraw_frequency: params.withdrawFrequency
268
+ ? params.withdrawFrequency.toArrayLike(buffer_1.Buffer, "le", 8)
269
+ : undefined,
270
+ amount_per_period: params.amountPerPeriod
271
+ ? params.amountPerPeriod.toArrayLike(buffer_1.Buffer, "le", 8)
272
+ : undefined,
273
+ };
274
+ var encodeLength = Layout.encodeUpdateStream(decodedData, data);
275
+ data = data.slice(0, encodeLength);
276
+ data = buffer_1.Buffer.concat([
277
+ buffer_1.Buffer.from(js_sha256_1.sha256.digest("global:update")).slice(0, 8),
278
+ data,
279
+ buffer_1.Buffer.alloc(20),
280
+ ]);
281
+ return new web3_js_1.TransactionInstruction({
282
+ keys: keys,
283
+ programId: programId,
284
+ data: data,
285
+ });
286
+ };
287
+ exports.updateStreamInstruction = updateStreamInstruction;
256
288
  var cancelStreamInstruction = function (programId, _a) {
257
289
  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;
258
290
  var keys = [
@@ -1,5 +1,6 @@
1
+ /// <reference types="node" />
1
2
  import * as BufferLayout from "@solana/buffer-layout";
2
- import { ICreateStreamLayout, ICreateUncheckedStreamLayout, IStreamLayout, ITopupStreamLayout, IWithdrawStreamLayout } from "./instructionTypes";
3
+ import { ICreateStreamLayout, ICreateUncheckedStreamLayout, IStreamLayout, ITopupStreamLayout, IUpdateStreamLayout, IWithdrawStreamLayout } from "./instructionTypes";
3
4
  /**
4
5
  * Stream layout
5
6
  */
@@ -16,6 +17,10 @@ export declare const createUncheckedStreamLayout: BufferLayout.Structure<ICreate
16
17
  * Withdraw stream instruction layout
17
18
  */
18
19
  export declare const withdrawStreamLayout: BufferLayout.Structure<IWithdrawStreamLayout>;
20
+ /**
21
+ * Encode stream instruction layout
22
+ */
23
+ export declare const encodeUpdateStream: (values: IUpdateStreamLayout, data: Buffer) => number;
19
24
  /**
20
25
  * Topup stream instruction layout
21
26
  */
@@ -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.withdrawStreamLayout = exports.createUncheckedStreamLayout = exports.createStreamLayout = exports.streamLayout = void 0;
26
+ exports.topupStreamLayout = exports.encodeUpdateStream = 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,6 +113,43 @@ 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 : 0,
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 : 0,
150
+ }, data);
151
+ };
152
+ exports.encodeUpdateStream = encodeUpdateStream;
116
153
  /**
117
154
  * Topup stream instruction layout
118
155
  */
@@ -248,7 +248,7 @@ function sendAndConfirmStreamRawTransaction(connection, batchItem) {
248
248
  return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
249
249
  case 2:
250
250
  error_1 = _b.sent();
251
- throw { recipient: batchItem.recipient, error: error_1 };
251
+ throw { recipient: batchItem.recipient, error: error_1.toString() };
252
252
  case 3: return [2 /*return*/];
253
253
  }
254
254
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
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/",