@streamflow/stream 5.10.4 → 5.11.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.
@@ -13,14 +13,24 @@ export interface ICreateStreamSolanaExt {
13
13
  metadataPubKeys?: PublicKey[];
14
14
  partner?: string | null;
15
15
  isNative?: boolean;
16
+ computePrice?: number;
17
+ computeLimit?: number;
16
18
  }
17
19
  export interface IInteractStreamSolanaExt {
18
20
  invoker: SignerWalletAdapter | Keypair;
19
21
  checkTokenAccounts?: boolean;
22
+ computePrice?: number;
23
+ computeLimit?: number;
20
24
  }
21
25
  export interface ITopUpStreamSolanaExt {
22
26
  invoker: SignerWalletAdapter | Keypair;
23
27
  isNative?: boolean;
28
+ computePrice?: number;
29
+ computeLimit?: number;
30
+ }
31
+ export interface ITransactionSolanaExt {
32
+ computePrice?: number;
33
+ computeLimit?: number;
24
34
  }
25
35
  export interface CreateStreamData {
26
36
  recipient: string;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
3
- import { Connection, Keypair, PublicKey, Transaction, BlockhashWithExpiryBlockHeight } from "@solana/web3.js";
3
+ import { Connection, Keypair, PublicKey, TransactionInstruction, Transaction, BlockhashWithExpiryBlockHeight, Commitment } from "@solana/web3.js";
4
4
  import { AtaParams, DecodedStream, Account, BatchItem, BatchItemResult } from "./types";
5
5
  export declare const decodeStream: (buf: Buffer) => DecodedStream;
6
6
  /**
@@ -24,6 +24,19 @@ export declare function isSignerWallet(walletOrKeypair: Keypair | SignerWalletAd
24
24
  * @returns {boolean} - Returns true if parameter is a Keypair.
25
25
  */
26
26
  export declare function isSignerKeypair(walletOrKeypair: Keypair | SignerWalletAdapter): walletOrKeypair is Keypair;
27
+ /**
28
+ * Creates a Transaction with given instructions and optionally signs it
29
+ * @param connection - Solana client connection
30
+ * @param ixs - Instructions to add to the Transaction
31
+ * @param payer - PublicKey of payer
32
+ * @param commitment - optional Commitment that will be used to fetch latest blockhash
33
+ * @param partialSigners - optional signers that will be used to partially sign a Transaction
34
+ * @returns Transaction and Blockhash
35
+ */
36
+ export declare function prepareTransaction(connection: Connection, ixs: TransactionInstruction[], payer: PublicKey | undefined | null, commitment?: Commitment, ...partialSigners: (Keypair | undefined)[]): Promise<{
37
+ tx: Transaction;
38
+ hash: BlockhashWithExpiryBlockHeight;
39
+ }>;
27
40
  export declare function signTransaction(invoker: Keypair | SignerWalletAdapter, tx: Transaction): Promise<Transaction>;
28
41
  /**
29
42
  * Sign passed BatchItems with wallet request or KeyPair
@@ -71,11 +71,22 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
71
71
  }
72
72
  return to.concat(ar || Array.prototype.slice.call(from));
73
73
  };
74
+ var __values = (this && this.__values) || function(o) {
75
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
76
+ if (m) return m.call(o);
77
+ if (o && typeof o.length === "number") return {
78
+ next: function () {
79
+ if (o && i >= o.length) o = void 0;
80
+ return { value: o && o[i++], done: !o };
81
+ }
82
+ };
83
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
84
+ };
74
85
  var __importDefault = (this && this.__importDefault) || function (mod) {
75
86
  return (mod && mod.__esModule) ? mod : { "default": mod };
76
87
  };
77
88
  Object.defineProperty(exports, "__esModule", { value: true });
78
- exports.extractSolanaErrorCode = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.ataBatchExist = exports.ata = exports.sendAndConfirmStreamRawTransaction = exports.signAndExecuteTransaction = exports.signAllTransactionWithRecipients = exports.signTransaction = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = exports.decodeStream = void 0;
89
+ exports.extractSolanaErrorCode = exports.createAtaBatch = exports.generateCreateAtaBatchTx = exports.ataBatchExist = exports.ata = exports.sendAndConfirmStreamRawTransaction = exports.signAndExecuteTransaction = exports.signAllTransactionWithRecipients = exports.signTransaction = exports.prepareTransaction = exports.isSignerKeypair = exports.isSignerWallet = exports.getProgramAccounts = exports.decodeStream = void 0;
79
90
  var spl_token_1 = require("@solana/spl-token");
80
91
  var web3_js_1 = require("@solana/web3.js");
81
92
  var bn_js_1 = __importDefault(require("bn.js"));
@@ -177,6 +188,54 @@ function isSignerKeypair(walletOrKeypair) {
177
188
  walletOrKeypair.constructor.name === web3_js_1.Keypair.prototype.constructor.name);
178
189
  }
179
190
  exports.isSignerKeypair = isSignerKeypair;
191
+ /**
192
+ * Creates a Transaction with given instructions and optionally signs it
193
+ * @param connection - Solana client connection
194
+ * @param ixs - Instructions to add to the Transaction
195
+ * @param payer - PublicKey of payer
196
+ * @param commitment - optional Commitment that will be used to fetch latest blockhash
197
+ * @param partialSigners - optional signers that will be used to partially sign a Transaction
198
+ * @returns Transaction and Blockhash
199
+ */
200
+ function prepareTransaction(connection, ixs, payer, commitment) {
201
+ var partialSigners = [];
202
+ for (var _i = 4; _i < arguments.length; _i++) {
203
+ partialSigners[_i - 4] = arguments[_i];
204
+ }
205
+ return __awaiter(this, void 0, void 0, function () {
206
+ var hash, tx, partialSigners_1, partialSigners_1_1, signer;
207
+ var _a, e_1, _b;
208
+ return __generator(this, function (_c) {
209
+ switch (_c.label) {
210
+ case 0: return [4 /*yield*/, connection.getLatestBlockhash(commitment)];
211
+ case 1:
212
+ hash = _c.sent();
213
+ tx = (_a = new web3_js_1.Transaction({
214
+ feePayer: payer,
215
+ blockhash: hash.blockhash,
216
+ lastValidBlockHeight: hash.lastValidBlockHeight,
217
+ })).add.apply(_a, __spreadArray([], __read(ixs), false));
218
+ try {
219
+ for (partialSigners_1 = __values(partialSigners), partialSigners_1_1 = partialSigners_1.next(); !partialSigners_1_1.done; partialSigners_1_1 = partialSigners_1.next()) {
220
+ signer = partialSigners_1_1.value;
221
+ if (signer) {
222
+ tx.partialSign(signer);
223
+ }
224
+ }
225
+ }
226
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
227
+ finally {
228
+ try {
229
+ if (partialSigners_1_1 && !partialSigners_1_1.done && (_b = partialSigners_1.return)) _b.call(partialSigners_1);
230
+ }
231
+ finally { if (e_1) throw e_1.error; }
232
+ }
233
+ return [2 /*return*/, { tx: tx, hash: hash }];
234
+ }
235
+ });
236
+ });
237
+ }
238
+ exports.prepareTransaction = prepareTransaction;
180
239
  function signTransaction(invoker, tx) {
181
240
  return __awaiter(this, void 0, void 0, function () {
182
241
  var signedTx;
@@ -359,8 +418,7 @@ exports.ataBatchExist = ataBatchExist;
359
418
  */
360
419
  function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
361
420
  return __awaiter(this, void 0, void 0, function () {
362
- var ixs, hash, tx;
363
- var _a;
421
+ var ixs, _a, tx, hash;
364
422
  var _this = this;
365
423
  return __generator(this, function (_b) {
366
424
  switch (_b.label) {
@@ -381,14 +439,9 @@ function generateCreateAtaBatchTx(connection, payer, paramsBatch) {
381
439
  }))];
382
440
  case 1:
383
441
  ixs = _b.sent();
384
- return [4 /*yield*/, connection.getLatestBlockhash()];
442
+ return [4 /*yield*/, prepareTransaction(connection, ixs, payer)];
385
443
  case 2:
386
- hash = _b.sent();
387
- tx = (_a = new web3_js_1.Transaction({
388
- feePayer: payer,
389
- blockhash: hash.blockhash,
390
- lastValidBlockHeight: hash.lastValidBlockHeight,
391
- })).add.apply(_a, __spreadArray([], __read(ixs), false));
444
+ _a = _b.sent(), tx = _a.tx, hash = _a.hash;
392
445
  return [2 /*return*/, { tx: tx, hash: hash }];
393
446
  }
394
447
  });
@@ -19,7 +19,7 @@ export default class SuiStreamClient extends BaseStreamClient {
19
19
  /**
20
20
  * Attempts withdrawing from the specified stream.
21
21
  */
22
- withdraw(withdrawData: IWithdrawData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
22
+ withdraw({ id, amount }: IWithdrawData, { senderWallet, tokenId }: ITransactionSuiExt): Promise<ITransactionResult>;
23
23
  /**
24
24
  * Attempts canceling the specified stream.
25
25
  */
@@ -97,6 +97,7 @@ var types_2 = require("./types");
97
97
  var utils_2 = require("./utils");
98
98
  var wallet_1 = require("./wallet");
99
99
  var utils_3 = require("../common/utils");
100
+ var constants_2 = require("../common/constants");
100
101
  var SuiStreamClient = /** @class */ (function (_super) {
101
102
  __extends(SuiStreamClient, _super);
102
103
  function SuiStreamClient(clusterUrl, cluster, ids) {
@@ -223,12 +224,13 @@ var SuiStreamClient = /** @class */ (function (_super) {
223
224
  /**
224
225
  * Attempts withdrawing from the specified stream.
225
226
  */
226
- SuiStreamClient.prototype.withdraw = function (withdrawData, _a) {
227
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
227
+ SuiStreamClient.prototype.withdraw = function (_a, _b) {
228
+ var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
229
+ var senderWallet = _b.senderWallet, tokenId = _b.tokenId;
228
230
  return __awaiter(this, void 0, void 0, function () {
229
231
  var wallet, txb, digest;
230
- return __generator(this, function (_b) {
231
- switch (_b.label) {
232
+ return __generator(this, function (_d) {
233
+ switch (_d.label) {
232
234
  case 0:
233
235
  wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
234
236
  txb = new transactions_1.TransactionBlock();
@@ -236,17 +238,17 @@ var SuiStreamClient = /** @class */ (function (_super) {
236
238
  target: "".concat(this.programId, "::protocol::withdraw"),
237
239
  typeArguments: [tokenId],
238
240
  arguments: [
239
- txb.object(withdrawData.id),
241
+ txb.object(id),
240
242
  txb.object(this.configId),
241
243
  txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
242
- txb.pure(withdrawData.amount.toString()),
244
+ txb.pure(amount.toString()),
243
245
  ],
244
246
  });
245
247
  return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
246
248
  transactionBlock: txb,
247
249
  })];
248
250
  case 1:
249
- digest = (_b.sent()).digest;
251
+ digest = (_d.sent()).digest;
250
252
  return [2 /*return*/, {
251
253
  ixs: [],
252
254
  txId: digest,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "5.10.4",
3
+ "version": "5.11.1",
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",
@@ -11,7 +11,7 @@
11
11
  "lint": "eslint .",
12
12
  "prepublishOnly": "npm run lint && npm test && npm run build"
13
13
  },
14
- "gitHead": "6391e45fba526e981e5fb576109f79b5d6418197",
14
+ "gitHead": "8ae9fa79978ff85a5c7b9cbd073ff5407787f268",
15
15
  "devDependencies": {
16
16
  "@types/bn.js": "5.1.1",
17
17
  "@types/ethereum-checksum-address": "^0.0.0",