@streamflow/stream 7.2.1 → 7.3.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,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const client_1 = require("@mysten/sui.js/client");
4
- const transactions_1 = require("@mysten/sui.js/transactions");
5
- const utils_1 = require("@mysten/sui.js/utils");
3
+ const bcs_1 = require("@mysten/bcs");
4
+ const client_1 = require("@mysten/sui/client");
5
+ const transactions_1 = require("@mysten/sui/transactions");
6
+ const utils_1 = require("@mysten/sui/utils");
7
+ const bcs_2 = require("@mysten/sui/bcs");
6
8
  const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
7
9
  const types_js_1 = require("../common/types.js");
8
10
  const constants_js_1 = require("./constants.js");
@@ -27,12 +29,12 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
27
29
  const totalFee = await this.getTotalFee({
28
30
  address: streamData.partner ?? wallet.address,
29
31
  });
30
- const [txb] = await this.generateCreateBlock(wallet.address, {
32
+ const [tx] = await this.generateCreateBlock(wallet.address, {
31
33
  ...streamData,
32
34
  recipients: [{ ...streamData }],
33
35
  }, totalFee);
34
- const { digest, events } = await wallet.signAndExecuteTransactionBlock({
35
- transactionBlock: txb,
36
+ const { digest, events } = await wallet.signAndExecuteTransaction({
37
+ transaction: tx,
36
38
  options: { showEvents: true },
37
39
  });
38
40
  return {
@@ -50,18 +52,45 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
50
52
  const totalFee = await this.getTotalFee({
51
53
  address: multipleStreamData.partner ?? wallet.address,
52
54
  });
53
- const [txb, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
55
+ const [tx, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
54
56
  const txs = [];
55
57
  const metadatas = [];
56
58
  const metadataToRecipient = {};
57
59
  const errors = [];
58
60
  try {
59
- const { digest, events, effects } = await wallet.signAndExecuteTransactionBlock({
60
- transactionBlock: txb,
61
+ const { digest, events, effects } = await wallet.signAndExecuteTransaction({
62
+ transaction: tx,
61
63
  options: { showEffects: true, showEvents: true },
62
64
  });
63
65
  txs.push(digest);
64
- if (effects.status.status === "failure") {
66
+ // effects may be string according to Sui Wallet standard
67
+ // https://github.com/MystenLabs/ts-sdks/blob/main/packages/wallet-standard/src/features/suiSignAndExecuteTransaction.ts#L34
68
+ // Loosely ported from https://github.com/MystenLabs/ts-sdks/blob/main/packages/graphql-transport/src/mappers/transaction-block.ts#L376
69
+ let effectsShort = undefined;
70
+ if (typeof effects === "string") {
71
+ const parsedEffects = bcs_2.bcs.TransactionEffects.parse((0, bcs_1.fromBase64)(effects));
72
+ const currentEffects = parsedEffects.V2 || parsedEffects.V1;
73
+ if (currentEffects) {
74
+ effectsShort = currentEffects.status.Success
75
+ ? {
76
+ status: "success",
77
+ }
78
+ : {
79
+ status: "failure",
80
+ error: currentEffects.status.$kind,
81
+ };
82
+ }
83
+ }
84
+ else if (effects && effects.status) {
85
+ effectsShort = {
86
+ status: effects.status.status,
87
+ error: effects.status.error,
88
+ };
89
+ }
90
+ if (!effectsShort) {
91
+ console.warn(`Got no effects from the transaction ${digest}, raw: ${effects}`);
92
+ }
93
+ if (effectsShort?.status === "failure") {
65
94
  multipleStreamData.recipients.forEach((recipient) => {
66
95
  errors.push({
67
96
  error: effects.status.error ?? "Unknown error!",
@@ -104,19 +133,19 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
104
133
  */
105
134
  async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
106
135
  const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
107
- const txb = new transactions_1.TransactionBlock();
108
- txb.moveCall({
136
+ const tx = new transactions_1.Transaction();
137
+ tx.moveCall({
109
138
  target: `${this.programId}::protocol::withdraw`,
110
139
  typeArguments: [tokenId],
111
140
  arguments: [
112
- txb.object(id),
113
- txb.object(this.configId),
114
- txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
115
- txb.pure(amount.toString()),
141
+ tx.object(id),
142
+ tx.object(this.configId),
143
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
144
+ tx.pure.u64(amount.toString()),
116
145
  ],
117
146
  });
118
- const { digest } = await wallet.signAndExecuteTransactionBlock({
119
- transactionBlock: txb,
147
+ const { digest } = await wallet.signAndExecuteTransaction({
148
+ transaction: tx,
120
149
  });
121
150
  return {
122
151
  ixs: [],
@@ -128,14 +157,14 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
128
157
  */
129
158
  async cancel(cancelData, { senderWallet, tokenId }) {
130
159
  const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
131
- const txb = new transactions_1.TransactionBlock();
132
- txb.moveCall({
160
+ const tx = new transactions_1.Transaction();
161
+ tx.moveCall({
133
162
  target: `${this.programId}::protocol::cancel`,
134
163
  typeArguments: [tokenId],
135
- arguments: [txb.object(cancelData.id), txb.object(this.configId), txb.object(utils_1.SUI_CLOCK_OBJECT_ID)],
164
+ arguments: [tx.object(cancelData.id), tx.object(this.configId), tx.object(utils_1.SUI_CLOCK_OBJECT_ID)],
136
165
  });
137
- const { digest } = await wallet.signAndExecuteTransactionBlock({
138
- transactionBlock: txb,
166
+ const { digest } = await wallet.signAndExecuteTransaction({
167
+ transaction: tx,
139
168
  });
140
169
  return {
141
170
  ixs: [],
@@ -147,14 +176,14 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
147
176
  */
148
177
  async transfer(transferData, { senderWallet, tokenId }) {
149
178
  const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
150
- const txb = new transactions_1.TransactionBlock();
151
- txb.moveCall({
179
+ const tx = new transactions_1.Transaction();
180
+ tx.moveCall({
152
181
  target: `${this.programId}::protocol::transfer`,
153
182
  typeArguments: [tokenId],
154
- arguments: [txb.object(transferData.id), txb.pure(transferData.newRecipient)],
183
+ arguments: [tx.object(transferData.id), tx.pure.address(transferData.newRecipient)],
155
184
  });
156
- const { digest } = await wallet.signAndExecuteTransactionBlock({
157
- transactionBlock: txb,
185
+ const { digest } = await wallet.signAndExecuteTransaction({
186
+ transaction: tx,
158
187
  });
159
188
  return {
160
189
  ixs: [],
@@ -166,25 +195,25 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
166
195
  */
167
196
  async topup(topupData, { senderWallet, tokenId }) {
168
197
  const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
169
- const txb = new transactions_1.TransactionBlock();
198
+ const tx = new transactions_1.Transaction();
170
199
  const coins = await this.getAllCoins(wallet.address, tokenId);
171
200
  const stream = await this.getOne({ id: topupData.id });
172
201
  const totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
173
- const coinObject = this.splitCoinObjectForAmount(txb, topupData.amount, tokenId, coins, totalFee);
174
- txb.moveCall({
202
+ const coinObject = this.splitCoinObjectForAmount(tx, topupData.amount, tokenId, coins, totalFee);
203
+ tx.moveCall({
175
204
  target: `${this.programId}::protocol::topup`,
176
205
  typeArguments: [tokenId],
177
206
  arguments: [
178
- txb.object(topupData.id),
179
- txb.object(this.configId),
207
+ tx.object(topupData.id),
208
+ tx.object(this.configId),
180
209
  coinObject,
181
- txb.gas,
182
- txb.pure(topupData.amount.toString()),
210
+ tx.gas,
211
+ tx.pure.u64(topupData.amount.toString()),
183
212
  ],
184
213
  });
185
- this.returnSplittedCoinObject(txb, tokenId, coins, coinObject);
186
- const { digest } = await wallet.signAndExecuteTransactionBlock({
187
- transactionBlock: txb,
214
+ this.returnSplittedCoinObject(tx, tokenId, coins, coinObject);
215
+ const { digest } = await wallet.signAndExecuteTransaction({
216
+ transaction: tx,
188
217
  });
189
218
  return {
190
219
  ixs: [],
@@ -218,22 +247,28 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
218
247
  */
219
248
  async update(updateData, { senderWallet, tokenId }) {
220
249
  const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
221
- const txb = new transactions_1.TransactionBlock();
222
- txb.moveCall({
250
+ const tx = new transactions_1.Transaction();
251
+ tx.moveCall({
223
252
  target: `${this.programId}::protocol::update`,
224
253
  typeArguments: [tokenId],
225
254
  arguments: [
226
- txb.object(updateData.id),
227
- txb.object(this.configId),
228
- txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
229
- txb.gas,
230
- txb.pure(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : [], "vector<bool>"),
231
- txb.pure(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : [], "vector<u64>"),
232
- txb.pure(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : [], "vector<u64>"),
255
+ tx.object(updateData.id),
256
+ tx.object(this.configId),
257
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
258
+ tx.gas,
259
+ bcs_2.bcs
260
+ .vector(bcs_2.bcs.bool())
261
+ .serialize(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : []),
262
+ bcs_2.bcs
263
+ .vector(bcs_2.bcs.u64())
264
+ .serialize(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : []),
265
+ bcs_2.bcs
266
+ .vector(bcs_2.bcs.u64())
267
+ .serialize(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : []),
233
268
  ],
234
269
  });
235
- const { digest } = await wallet.signAndExecuteTransactionBlock({
236
- transactionBlock: txb,
270
+ const { digest } = await wallet.signAndExecuteTransaction({
271
+ transaction: tx,
237
272
  });
238
273
  return {
239
274
  ixs: [],
@@ -307,45 +342,45 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
307
342
  const totalAmount = multipleStreamData.recipients
308
343
  .map((recipiient) => recipiient.amount)
309
344
  .reduce((prev, current) => current.add(prev));
310
- const txb = new transactions_1.TransactionBlock();
311
- const coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
345
+ const tx = new transactions_1.Transaction();
346
+ const coinObject = this.splitCoinObjectForAmount(tx, totalAmount, multipleStreamData.tokenId, coins, totalFee);
312
347
  coins = [coins[0]];
313
348
  let firstIndex = null;
314
349
  multipleStreamData.recipients.forEach((recipient) => {
315
- const result = txb.moveCall({
350
+ const result = tx.moveCall({
316
351
  target: `${this.programId}::protocol::create`,
317
352
  typeArguments: [multipleStreamData.tokenId],
318
353
  arguments: [
319
- txb.object(this.configId),
320
- txb.object(this.feeTableId),
321
- txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
354
+ tx.object(this.configId),
355
+ tx.object(this.feeTableId),
356
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
322
357
  coinObject,
323
- txb.gas,
324
- txb.pure(recipient.amount.toString()),
325
- txb.pure(multipleStreamData.period),
326
- txb.pure(recipient.amountPerPeriod.toString()),
327
- txb.pure(multipleStreamData.start),
328
- txb.pure(recipient.cliffAmount.toString()),
329
- txb.pure(multipleStreamData.cancelableBySender),
330
- txb.pure(multipleStreamData.cancelableByRecipient),
331
- txb.pure(multipleStreamData.transferableBySender),
332
- txb.pure(multipleStreamData.transferableByRecipient),
333
- txb.pure(multipleStreamData.canTopup),
334
- txb.pure(!!multipleStreamData.canPause),
335
- txb.pure(!!multipleStreamData.canUpdateRate),
336
- txb.pure(!!multipleStreamData.automaticWithdrawal),
337
- txb.pure(multipleStreamData.withdrawalFrequency || 0),
338
- txb.pure(recipient.name),
339
- txb.pure(recipient.recipient),
340
- txb.pure(multipleStreamData.partner || walletAddress),
358
+ tx.gas,
359
+ tx.pure.u64(recipient.amount.toString()),
360
+ tx.pure.u64(multipleStreamData.period),
361
+ tx.pure.u64(recipient.amountPerPeriod.toString()),
362
+ tx.pure.u64(multipleStreamData.start),
363
+ tx.pure.u64(recipient.cliffAmount.toString()),
364
+ tx.pure.bool(multipleStreamData.cancelableBySender),
365
+ tx.pure.bool(multipleStreamData.cancelableByRecipient),
366
+ tx.pure.bool(multipleStreamData.transferableBySender),
367
+ tx.pure.bool(multipleStreamData.transferableByRecipient),
368
+ tx.pure.bool(multipleStreamData.canTopup),
369
+ tx.pure.bool(!!multipleStreamData.canPause),
370
+ tx.pure.bool(!!multipleStreamData.canUpdateRate),
371
+ tx.pure.bool(!!multipleStreamData.automaticWithdrawal),
372
+ tx.pure.u64(multipleStreamData.withdrawalFrequency || 0),
373
+ tx.pure.string(recipient.name),
374
+ tx.pure.address(recipient.recipient),
375
+ tx.pure.address(multipleStreamData.partner || walletAddress),
341
376
  ],
342
377
  });
343
- if (result.kind === "Result" && firstIndex === null) {
344
- firstIndex = result.index;
378
+ if (result.$kind === "Result" && firstIndex === null) {
379
+ firstIndex = result.Result;
345
380
  }
346
381
  });
347
- this.returnSplittedCoinObject(txb, multipleStreamData.tokenId, coins, coinObject);
348
- return [txb, firstIndex];
382
+ this.returnSplittedCoinObject(tx, multipleStreamData.tokenId, coins, coinObject);
383
+ return [tx, firstIndex];
349
384
  }
350
385
  /**
351
386
  * Returns all coins owned by a Wallet
@@ -373,30 +408,31 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
373
408
  * Utility function to split Coin object and use splitted object for stream operations.
374
409
  * We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
375
410
  * This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
376
- * @param txb current transanction block
411
+ * @param tx current transanction block
377
412
  * @param amount minimal amount of coins requried
378
413
  * @param coinType coin type
379
414
  * @param coins array of owned coins of the same type
415
+ * @param totalFee partner and treasury fees
380
416
  * @returns Coin Object to use in a Move Call
381
417
  */
382
- splitCoinObjectForAmount(txb, amount, coinType, coins, totalFee) {
383
- const coinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
418
+ splitCoinObjectForAmount(tx, amount, coinType, coins, totalFee) {
419
+ const coinObject = coinType === utils_1.SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
384
420
  if (coins.length > 1) {
385
- txb.mergeCoins(coinObject, coins.slice(1).map((item) => txb.object(item.coinObjectId)));
421
+ tx.mergeCoins(coinObject, coins.slice(1).map((item) => tx.object(item.coinObjectId)));
386
422
  }
387
423
  const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(amount, totalFee);
388
- return txb.splitCoins(coinObject, [txb.pure(totalAmount.toString())])[0];
424
+ return tx.splitCoins(coinObject, [tx.pure.u64(totalAmount.toString())])[0];
389
425
  }
390
426
  /**
391
427
  * Return previously splitted Coin Object to owner and merge it to to rebate storage fees
392
- * @param txb current transanction block
428
+ * @param tx current transaction
393
429
  * @param coinType coin type
394
430
  * @param coinObject splitted object
395
431
  * @param coins array of objects used in
396
432
  */
397
- returnSplittedCoinObject(txb, coinType, coins, coinObject) {
398
- const firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
399
- txb.mergeCoins(firstCoinObject, [coinObject]);
433
+ returnSplittedCoinObject(tx, coinType, coins, coinObject) {
434
+ const firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
435
+ tx.mergeCoins(firstCoinObject, [coinObject]);
400
436
  }
401
437
  }
402
438
  exports.default = SuiStreamClient;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SuiWalletWrapper = void 0;
4
4
  exports.isSignerKeypair = isSignerKeypair;
5
- const cryptography_1 = require("@mysten/sui.js/cryptography");
5
+ const cryptography_1 = require("@mysten/sui/cryptography");
6
6
  /**
7
7
  * Utility function to check if the transaction initiator is a Wallet object
8
8
  * @param {Keypair | WalletContextState} walletOrKeypair - Wallet or Keypair in question
@@ -12,7 +12,7 @@ function isSignerKeypair(walletOrKeypair) {
12
12
  return (walletOrKeypair instanceof cryptography_1.Keypair ||
13
13
  walletOrKeypair.constructor === cryptography_1.Keypair ||
14
14
  walletOrKeypair.constructor.name === cryptography_1.Keypair.prototype.constructor.name ||
15
- "export" in walletOrKeypair);
15
+ "getSecretKey" in walletOrKeypair);
16
16
  }
17
17
  class SuiWalletWrapper {
18
18
  constructor(wallet, client) {
@@ -25,16 +25,16 @@ class SuiWalletWrapper {
25
25
  this.address = wallet.address;
26
26
  }
27
27
  }
28
- async signAndExecuteTransactionBlock(input) {
28
+ async signAndExecuteTransaction(input) {
29
29
  if (isSignerKeypair(this.wallet)) {
30
- return this.client.signAndExecuteTransactionBlock({
30
+ return this.client.signAndExecuteTransaction({
31
31
  ...input,
32
32
  // @ts-ignore
33
33
  signer: this.wallet,
34
34
  });
35
35
  }
36
36
  // @ts-ignore
37
- return this.wallet.signAndExecuteTransactionBlock(input);
37
+ return this.wallet.signAndExecuteTransaction(input);
38
38
  }
39
39
  }
40
40
  exports.SuiWalletWrapper = SuiWalletWrapper;
@@ -63,16 +63,17 @@ export default class SuiStreamClient extends BaseStreamClient {
63
63
  * Utility function to split Coin object and use splitted object for stream operations.
64
64
  * We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
65
65
  * This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
66
- * @param txb current transanction block
66
+ * @param tx current transanction block
67
67
  * @param amount minimal amount of coins requried
68
68
  * @param coinType coin type
69
69
  * @param coins array of owned coins of the same type
70
+ * @param totalFee partner and treasury fees
70
71
  * @returns Coin Object to use in a Move Call
71
72
  */
72
73
  private splitCoinObjectForAmount;
73
74
  /**
74
75
  * Return previously splitted Coin Object to owner and merge it to to rebate storage fees
75
- * @param txb current transanction block
76
+ * @param tx current transaction
76
77
  * @param coinType coin type
77
78
  * @param coinObject splitted object
78
79
  * @param coins array of objects used in
@@ -1,6 +1,8 @@
1
- import { SuiClient } from "@mysten/sui.js/client";
2
- import { TransactionBlock } from "@mysten/sui.js/transactions";
3
- import { SUI_CLOCK_OBJECT_ID, SUI_TYPE_ARG } from "@mysten/sui.js/utils";
1
+ import { fromBase64 } from "@mysten/bcs";
2
+ import { SuiClient } from "@mysten/sui/client";
3
+ import { Transaction } from "@mysten/sui/transactions";
4
+ import { SUI_CLOCK_OBJECT_ID, SUI_TYPE_ARG } from "@mysten/sui/utils";
5
+ import { bcs } from "@mysten/sui/bcs";
4
6
  import { BaseStreamClient } from "../common/BaseStreamClient.js";
5
7
  import { ICluster, } from "../common/types.js";
6
8
  import { SUI_PROGRAM_IDS, SUI_FEE_TABLE_IDS, SUI_CONFIG_IDS } from "./constants.js";
@@ -29,12 +31,12 @@ export default class SuiStreamClient extends BaseStreamClient {
29
31
  const totalFee = await this.getTotalFee({
30
32
  address: streamData.partner ?? wallet.address,
31
33
  });
32
- const [txb] = await this.generateCreateBlock(wallet.address, {
34
+ const [tx] = await this.generateCreateBlock(wallet.address, {
33
35
  ...streamData,
34
36
  recipients: [{ ...streamData }],
35
37
  }, totalFee);
36
- const { digest, events } = await wallet.signAndExecuteTransactionBlock({
37
- transactionBlock: txb,
38
+ const { digest, events } = await wallet.signAndExecuteTransaction({
39
+ transaction: tx,
38
40
  options: { showEvents: true },
39
41
  });
40
42
  return {
@@ -52,18 +54,45 @@ export default class SuiStreamClient extends BaseStreamClient {
52
54
  const totalFee = await this.getTotalFee({
53
55
  address: multipleStreamData.partner ?? wallet.address,
54
56
  });
55
- const [txb, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
57
+ const [tx, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
56
58
  const txs = [];
57
59
  const metadatas = [];
58
60
  const metadataToRecipient = {};
59
61
  const errors = [];
60
62
  try {
61
- const { digest, events, effects } = await wallet.signAndExecuteTransactionBlock({
62
- transactionBlock: txb,
63
+ const { digest, events, effects } = await wallet.signAndExecuteTransaction({
64
+ transaction: tx,
63
65
  options: { showEffects: true, showEvents: true },
64
66
  });
65
67
  txs.push(digest);
66
- if (effects.status.status === "failure") {
68
+ // effects may be string according to Sui Wallet standard
69
+ // https://github.com/MystenLabs/ts-sdks/blob/main/packages/wallet-standard/src/features/suiSignAndExecuteTransaction.ts#L34
70
+ // Loosely ported from https://github.com/MystenLabs/ts-sdks/blob/main/packages/graphql-transport/src/mappers/transaction-block.ts#L376
71
+ let effectsShort = undefined;
72
+ if (typeof effects === "string") {
73
+ const parsedEffects = bcs.TransactionEffects.parse(fromBase64(effects));
74
+ const currentEffects = parsedEffects.V2 || parsedEffects.V1;
75
+ if (currentEffects) {
76
+ effectsShort = currentEffects.status.Success
77
+ ? {
78
+ status: "success",
79
+ }
80
+ : {
81
+ status: "failure",
82
+ error: currentEffects.status.$kind,
83
+ };
84
+ }
85
+ }
86
+ else if (effects && effects.status) {
87
+ effectsShort = {
88
+ status: effects.status.status,
89
+ error: effects.status.error,
90
+ };
91
+ }
92
+ if (!effectsShort) {
93
+ console.warn(`Got no effects from the transaction ${digest}, raw: ${effects}`);
94
+ }
95
+ if (effectsShort?.status === "failure") {
67
96
  multipleStreamData.recipients.forEach((recipient) => {
68
97
  errors.push({
69
98
  error: effects.status.error ?? "Unknown error!",
@@ -106,19 +135,19 @@ export default class SuiStreamClient extends BaseStreamClient {
106
135
  */
107
136
  async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
108
137
  const wallet = new SuiWalletWrapper(senderWallet, this.client);
109
- const txb = new TransactionBlock();
110
- txb.moveCall({
138
+ const tx = new Transaction();
139
+ tx.moveCall({
111
140
  target: `${this.programId}::protocol::withdraw`,
112
141
  typeArguments: [tokenId],
113
142
  arguments: [
114
- txb.object(id),
115
- txb.object(this.configId),
116
- txb.object(SUI_CLOCK_OBJECT_ID),
117
- txb.pure(amount.toString()),
143
+ tx.object(id),
144
+ tx.object(this.configId),
145
+ tx.object(SUI_CLOCK_OBJECT_ID),
146
+ tx.pure.u64(amount.toString()),
118
147
  ],
119
148
  });
120
- const { digest } = await wallet.signAndExecuteTransactionBlock({
121
- transactionBlock: txb,
149
+ const { digest } = await wallet.signAndExecuteTransaction({
150
+ transaction: tx,
122
151
  });
123
152
  return {
124
153
  ixs: [],
@@ -130,14 +159,14 @@ export default class SuiStreamClient extends BaseStreamClient {
130
159
  */
131
160
  async cancel(cancelData, { senderWallet, tokenId }) {
132
161
  const wallet = new SuiWalletWrapper(senderWallet, this.client);
133
- const txb = new TransactionBlock();
134
- txb.moveCall({
162
+ const tx = new Transaction();
163
+ tx.moveCall({
135
164
  target: `${this.programId}::protocol::cancel`,
136
165
  typeArguments: [tokenId],
137
- arguments: [txb.object(cancelData.id), txb.object(this.configId), txb.object(SUI_CLOCK_OBJECT_ID)],
166
+ arguments: [tx.object(cancelData.id), tx.object(this.configId), tx.object(SUI_CLOCK_OBJECT_ID)],
138
167
  });
139
- const { digest } = await wallet.signAndExecuteTransactionBlock({
140
- transactionBlock: txb,
168
+ const { digest } = await wallet.signAndExecuteTransaction({
169
+ transaction: tx,
141
170
  });
142
171
  return {
143
172
  ixs: [],
@@ -149,14 +178,14 @@ export default class SuiStreamClient extends BaseStreamClient {
149
178
  */
150
179
  async transfer(transferData, { senderWallet, tokenId }) {
151
180
  const wallet = new SuiWalletWrapper(senderWallet, this.client);
152
- const txb = new TransactionBlock();
153
- txb.moveCall({
181
+ const tx = new Transaction();
182
+ tx.moveCall({
154
183
  target: `${this.programId}::protocol::transfer`,
155
184
  typeArguments: [tokenId],
156
- arguments: [txb.object(transferData.id), txb.pure(transferData.newRecipient)],
185
+ arguments: [tx.object(transferData.id), tx.pure.address(transferData.newRecipient)],
157
186
  });
158
- const { digest } = await wallet.signAndExecuteTransactionBlock({
159
- transactionBlock: txb,
187
+ const { digest } = await wallet.signAndExecuteTransaction({
188
+ transaction: tx,
160
189
  });
161
190
  return {
162
191
  ixs: [],
@@ -168,25 +197,25 @@ export default class SuiStreamClient extends BaseStreamClient {
168
197
  */
169
198
  async topup(topupData, { senderWallet, tokenId }) {
170
199
  const wallet = new SuiWalletWrapper(senderWallet, this.client);
171
- const txb = new TransactionBlock();
200
+ const tx = new Transaction();
172
201
  const coins = await this.getAllCoins(wallet.address, tokenId);
173
202
  const stream = await this.getOne({ id: topupData.id });
174
203
  const totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
175
- const coinObject = this.splitCoinObjectForAmount(txb, topupData.amount, tokenId, coins, totalFee);
176
- txb.moveCall({
204
+ const coinObject = this.splitCoinObjectForAmount(tx, topupData.amount, tokenId, coins, totalFee);
205
+ tx.moveCall({
177
206
  target: `${this.programId}::protocol::topup`,
178
207
  typeArguments: [tokenId],
179
208
  arguments: [
180
- txb.object(topupData.id),
181
- txb.object(this.configId),
209
+ tx.object(topupData.id),
210
+ tx.object(this.configId),
182
211
  coinObject,
183
- txb.gas,
184
- txb.pure(topupData.amount.toString()),
212
+ tx.gas,
213
+ tx.pure.u64(topupData.amount.toString()),
185
214
  ],
186
215
  });
187
- this.returnSplittedCoinObject(txb, tokenId, coins, coinObject);
188
- const { digest } = await wallet.signAndExecuteTransactionBlock({
189
- transactionBlock: txb,
216
+ this.returnSplittedCoinObject(tx, tokenId, coins, coinObject);
217
+ const { digest } = await wallet.signAndExecuteTransaction({
218
+ transaction: tx,
190
219
  });
191
220
  return {
192
221
  ixs: [],
@@ -220,22 +249,28 @@ export default class SuiStreamClient extends BaseStreamClient {
220
249
  */
221
250
  async update(updateData, { senderWallet, tokenId }) {
222
251
  const wallet = new SuiWalletWrapper(senderWallet, this.client);
223
- const txb = new TransactionBlock();
224
- txb.moveCall({
252
+ const tx = new Transaction();
253
+ tx.moveCall({
225
254
  target: `${this.programId}::protocol::update`,
226
255
  typeArguments: [tokenId],
227
256
  arguments: [
228
- txb.object(updateData.id),
229
- txb.object(this.configId),
230
- txb.object(SUI_CLOCK_OBJECT_ID),
231
- txb.gas,
232
- txb.pure(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : [], "vector<bool>"),
233
- txb.pure(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : [], "vector<u64>"),
234
- txb.pure(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : [], "vector<u64>"),
257
+ tx.object(updateData.id),
258
+ tx.object(this.configId),
259
+ tx.object(SUI_CLOCK_OBJECT_ID),
260
+ tx.gas,
261
+ bcs
262
+ .vector(bcs.bool())
263
+ .serialize(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : []),
264
+ bcs
265
+ .vector(bcs.u64())
266
+ .serialize(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : []),
267
+ bcs
268
+ .vector(bcs.u64())
269
+ .serialize(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : []),
235
270
  ],
236
271
  });
237
- const { digest } = await wallet.signAndExecuteTransactionBlock({
238
- transactionBlock: txb,
272
+ const { digest } = await wallet.signAndExecuteTransaction({
273
+ transaction: tx,
239
274
  });
240
275
  return {
241
276
  ixs: [],
@@ -309,45 +344,45 @@ export default class SuiStreamClient extends BaseStreamClient {
309
344
  const totalAmount = multipleStreamData.recipients
310
345
  .map((recipiient) => recipiient.amount)
311
346
  .reduce((prev, current) => current.add(prev));
312
- const txb = new TransactionBlock();
313
- const coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
347
+ const tx = new Transaction();
348
+ const coinObject = this.splitCoinObjectForAmount(tx, totalAmount, multipleStreamData.tokenId, coins, totalFee);
314
349
  coins = [coins[0]];
315
350
  let firstIndex = null;
316
351
  multipleStreamData.recipients.forEach((recipient) => {
317
- const result = txb.moveCall({
352
+ const result = tx.moveCall({
318
353
  target: `${this.programId}::protocol::create`,
319
354
  typeArguments: [multipleStreamData.tokenId],
320
355
  arguments: [
321
- txb.object(this.configId),
322
- txb.object(this.feeTableId),
323
- txb.object(SUI_CLOCK_OBJECT_ID),
356
+ tx.object(this.configId),
357
+ tx.object(this.feeTableId),
358
+ tx.object(SUI_CLOCK_OBJECT_ID),
324
359
  coinObject,
325
- txb.gas,
326
- txb.pure(recipient.amount.toString()),
327
- txb.pure(multipleStreamData.period),
328
- txb.pure(recipient.amountPerPeriod.toString()),
329
- txb.pure(multipleStreamData.start),
330
- txb.pure(recipient.cliffAmount.toString()),
331
- txb.pure(multipleStreamData.cancelableBySender),
332
- txb.pure(multipleStreamData.cancelableByRecipient),
333
- txb.pure(multipleStreamData.transferableBySender),
334
- txb.pure(multipleStreamData.transferableByRecipient),
335
- txb.pure(multipleStreamData.canTopup),
336
- txb.pure(!!multipleStreamData.canPause),
337
- txb.pure(!!multipleStreamData.canUpdateRate),
338
- txb.pure(!!multipleStreamData.automaticWithdrawal),
339
- txb.pure(multipleStreamData.withdrawalFrequency || 0),
340
- txb.pure(recipient.name),
341
- txb.pure(recipient.recipient),
342
- txb.pure(multipleStreamData.partner || walletAddress),
360
+ tx.gas,
361
+ tx.pure.u64(recipient.amount.toString()),
362
+ tx.pure.u64(multipleStreamData.period),
363
+ tx.pure.u64(recipient.amountPerPeriod.toString()),
364
+ tx.pure.u64(multipleStreamData.start),
365
+ tx.pure.u64(recipient.cliffAmount.toString()),
366
+ tx.pure.bool(multipleStreamData.cancelableBySender),
367
+ tx.pure.bool(multipleStreamData.cancelableByRecipient),
368
+ tx.pure.bool(multipleStreamData.transferableBySender),
369
+ tx.pure.bool(multipleStreamData.transferableByRecipient),
370
+ tx.pure.bool(multipleStreamData.canTopup),
371
+ tx.pure.bool(!!multipleStreamData.canPause),
372
+ tx.pure.bool(!!multipleStreamData.canUpdateRate),
373
+ tx.pure.bool(!!multipleStreamData.automaticWithdrawal),
374
+ tx.pure.u64(multipleStreamData.withdrawalFrequency || 0),
375
+ tx.pure.string(recipient.name),
376
+ tx.pure.address(recipient.recipient),
377
+ tx.pure.address(multipleStreamData.partner || walletAddress),
343
378
  ],
344
379
  });
345
- if (result.kind === "Result" && firstIndex === null) {
346
- firstIndex = result.index;
380
+ if (result.$kind === "Result" && firstIndex === null) {
381
+ firstIndex = result.Result;
347
382
  }
348
383
  });
349
- this.returnSplittedCoinObject(txb, multipleStreamData.tokenId, coins, coinObject);
350
- return [txb, firstIndex];
384
+ this.returnSplittedCoinObject(tx, multipleStreamData.tokenId, coins, coinObject);
385
+ return [tx, firstIndex];
351
386
  }
352
387
  /**
353
388
  * Returns all coins owned by a Wallet
@@ -375,29 +410,30 @@ export default class SuiStreamClient extends BaseStreamClient {
375
410
  * Utility function to split Coin object and use splitted object for stream operations.
376
411
  * We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
377
412
  * This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
378
- * @param txb current transanction block
413
+ * @param tx current transanction block
379
414
  * @param amount minimal amount of coins requried
380
415
  * @param coinType coin type
381
416
  * @param coins array of owned coins of the same type
417
+ * @param totalFee partner and treasury fees
382
418
  * @returns Coin Object to use in a Move Call
383
419
  */
384
- splitCoinObjectForAmount(txb, amount, coinType, coins, totalFee) {
385
- const coinObject = coinType === SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
420
+ splitCoinObjectForAmount(tx, amount, coinType, coins, totalFee) {
421
+ const coinObject = coinType === SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
386
422
  if (coins.length > 1) {
387
- txb.mergeCoins(coinObject, coins.slice(1).map((item) => txb.object(item.coinObjectId)));
423
+ tx.mergeCoins(coinObject, coins.slice(1).map((item) => tx.object(item.coinObjectId)));
388
424
  }
389
425
  const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
390
- return txb.splitCoins(coinObject, [txb.pure(totalAmount.toString())])[0];
426
+ return tx.splitCoins(coinObject, [tx.pure.u64(totalAmount.toString())])[0];
391
427
  }
392
428
  /**
393
429
  * Return previously splitted Coin Object to owner and merge it to to rebate storage fees
394
- * @param txb current transanction block
430
+ * @param tx current transaction
395
431
  * @param coinType coin type
396
432
  * @param coinObject splitted object
397
433
  * @param coins array of objects used in
398
434
  */
399
- returnSplittedCoinObject(txb, coinType, coins, coinObject) {
400
- const firstCoinObject = coinType === SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
401
- txb.mergeCoins(firstCoinObject, [coinObject]);
435
+ returnSplittedCoinObject(tx, coinType, coins, coinObject) {
436
+ const firstCoinObject = coinType === SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
437
+ tx.mergeCoins(firstCoinObject, [coinObject]);
402
438
  }
403
439
  }
@@ -1,7 +1,7 @@
1
- import { Keypair } from "@mysten/sui.js/cryptography";
1
+ import { Keypair } from "@mysten/sui/cryptography";
2
2
  import { WalletContextState } from "@suiet/wallet-kit";
3
- import { TransactionBlock } from "@mysten/sui.js/transactions";
4
- import { ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions } from "@mysten/sui.js/client";
3
+ import { Transaction } from "@mysten/sui/transactions";
4
+ import { ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions } from "@mysten/sui/client";
5
5
  import BN from "bn.js";
6
6
  import { LinearStream, StreamType } from "../common/types.js";
7
7
  export interface ICreateStreamSuiExt {
@@ -161,7 +161,7 @@ export interface SuiErrorInfo {
161
161
  parsed?: SuiParsedError;
162
162
  }
163
163
  export interface SuiSignAndExecuteTransactionBlockInput {
164
- transactionBlock: TransactionBlock;
164
+ transaction: Transaction;
165
165
  requestType?: ExecuteTransactionRequestType;
166
166
  options?: SuiTransactionBlockResponseOptions;
167
167
  }
@@ -1,6 +1,6 @@
1
- import { Keypair } from "@mysten/sui.js/cryptography";
1
+ import { Keypair } from "@mysten/sui/cryptography";
2
2
  import { WalletContextState } from "@suiet/wallet-kit";
3
- import { SuiClient, SuiTransactionBlockResponse } from "@mysten/sui.js/client";
3
+ import { SuiClient, SuiTransactionBlockResponse } from "@mysten/sui/client";
4
4
  import { SuiSignAndExecuteTransactionBlockInput } from "./types.js";
5
5
  /**
6
6
  * Utility function to check if the transaction initiator is a Wallet object
@@ -13,5 +13,5 @@ export declare class SuiWalletWrapper<T extends WalletContextState | Keypair> {
13
13
  address: string;
14
14
  client: SuiClient;
15
15
  constructor(wallet: T, client: SuiClient);
16
- signAndExecuteTransactionBlock(input: SuiSignAndExecuteTransactionBlockInput): Promise<SuiTransactionBlockResponse>;
16
+ signAndExecuteTransaction(input: SuiSignAndExecuteTransactionBlockInput): Promise<SuiTransactionBlockResponse>;
17
17
  }
@@ -1,4 +1,4 @@
1
- import { Keypair } from "@mysten/sui.js/cryptography";
1
+ import { Keypair } from "@mysten/sui/cryptography";
2
2
  /**
3
3
  * Utility function to check if the transaction initiator is a Wallet object
4
4
  * @param {Keypair | WalletContextState} walletOrKeypair - Wallet or Keypair in question
@@ -8,7 +8,7 @@ export function isSignerKeypair(walletOrKeypair) {
8
8
  return (walletOrKeypair instanceof Keypair ||
9
9
  walletOrKeypair.constructor === Keypair ||
10
10
  walletOrKeypair.constructor.name === Keypair.prototype.constructor.name ||
11
- "export" in walletOrKeypair);
11
+ "getSecretKey" in walletOrKeypair);
12
12
  }
13
13
  export class SuiWalletWrapper {
14
14
  wallet;
@@ -24,15 +24,15 @@ export class SuiWalletWrapper {
24
24
  this.address = wallet.address;
25
25
  }
26
26
  }
27
- async signAndExecuteTransactionBlock(input) {
27
+ async signAndExecuteTransaction(input) {
28
28
  if (isSignerKeypair(this.wallet)) {
29
- return this.client.signAndExecuteTransactionBlock({
29
+ return this.client.signAndExecuteTransaction({
30
30
  ...input,
31
31
  // @ts-ignore
32
32
  signer: this.wallet,
33
33
  });
34
34
  }
35
35
  // @ts-ignore
36
- return this.wallet.signAndExecuteTransactionBlock(input);
36
+ return this.wallet.signAndExecuteTransaction(input);
37
37
  }
38
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/stream",
3
- "version": "7.2.1",
3
+ "version": "7.3.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/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": "56f65828955f62400c0b2eebaeb53c7f123dca60",
45
+ "gitHead": "1c65f9af2f486790e926beb8a6103f42ea805311",
46
46
  "devDependencies": {
47
- "@streamflow/eslint-config": "7.2.1",
47
+ "@streamflow/eslint-config": "7.3.1",
48
48
  "@types/bn.js": "5.1.1",
49
49
  "@types/ethereum-checksum-address": "^0.0.0",
50
50
  "date-fns": "2.28.0",
@@ -54,13 +54,14 @@
54
54
  "@coral-xyz/anchor": "^0.30.1",
55
55
  "@coral-xyz/borsh": "0.30.1",
56
56
  "@manahippo/aptos-wallet-adapter": "1.0.10",
57
- "@mysten/sui.js": "0.54.1",
57
+ "@mysten/bcs": "1.1.0",
58
+ "@mysten/sui": "1.12.0",
58
59
  "@solana/buffer-layout": "4.0.1",
59
60
  "@solana/spl-token": "0.4.9",
60
61
  "@solana/wallet-adapter-base": "0.9.19",
61
62
  "@solana/web3.js": "1.95.4",
62
- "@streamflow/common": "7.2.1",
63
- "@suiet/wallet-kit": "0.2.22",
63
+ "@streamflow/common": "7.3.1",
64
+ "@suiet/wallet-kit": "^0.3.3",
64
65
  "aptos": "1.21.0",
65
66
  "bn.js": "5.2.1",
66
67
  "borsh": "^2.0.0",