@streamflow/stream 4.0.0-beta.0 → 4.0.0

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
  */
@@ -786,6 +786,51 @@ var SolanaStreamClient = /** @class */ (function (_super) {
786
786
  });
787
787
  });
788
788
  };
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
+ };
789
834
  /**
790
835
  * Forms instructions from params, creates a raw transaction and fetch recent blockhash.
791
836
  */
@@ -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,35 @@ 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;
256
285
  var cancelStreamInstruction = function (programId, _a) {
257
286
  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
287
  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 : 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;
116
153
  /**
117
154
  * Topup stream instruction layout
118
155
  */
@@ -250,7 +250,7 @@ function sendAndConfirmStreamRawTransaction(connection, batchItem) {
250
250
  return [2 /*return*/, __assign(__assign({}, batchItem), { signature: completedTxSignature })];
251
251
  case 2:
252
252
  error_1 = _b.sent();
253
- throw { recipient: batchItem.recipient, error: error_1 };
253
+ throw { recipient: batchItem.recipient, error: error_1.toString() };
254
254
  case 3: return [2 /*return*/];
255
255
  }
256
256
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "4.0.0-beta.0",
3
+ "version": "4.0.0",
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/",