@streamflow/stream 7.2.1 → 7.3.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.
- package/dist/cjs/sui/StreamClient.js +93 -85
- package/dist/cjs/sui/wallet.js +5 -5
- package/dist/esm/sui/StreamClient.d.ts +3 -2
- package/dist/esm/sui/StreamClient.js +93 -85
- package/dist/esm/sui/types.d.ts +4 -4
- package/dist/esm/sui/wallet.d.ts +3 -3
- package/dist/esm/sui/wallet.js +5 -5
- package/package.json +6 -6
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const client_1 = require("@mysten/sui
|
|
4
|
-
const transactions_1 = require("@mysten/sui
|
|
5
|
-
const utils_1 = require("@mysten/sui
|
|
3
|
+
const client_1 = require("@mysten/sui/client");
|
|
4
|
+
const transactions_1 = require("@mysten/sui/transactions");
|
|
5
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
6
|
+
const bcs_1 = require("@mysten/sui/bcs");
|
|
6
7
|
const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
|
|
7
8
|
const types_js_1 = require("../common/types.js");
|
|
8
9
|
const constants_js_1 = require("./constants.js");
|
|
@@ -27,12 +28,12 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
27
28
|
const totalFee = await this.getTotalFee({
|
|
28
29
|
address: streamData.partner ?? wallet.address,
|
|
29
30
|
});
|
|
30
|
-
const [
|
|
31
|
+
const [tx] = await this.generateCreateBlock(wallet.address, {
|
|
31
32
|
...streamData,
|
|
32
33
|
recipients: [{ ...streamData }],
|
|
33
34
|
}, totalFee);
|
|
34
|
-
const { digest, events } = await wallet.
|
|
35
|
-
|
|
35
|
+
const { digest, events } = await wallet.signAndExecuteTransaction({
|
|
36
|
+
transaction: tx,
|
|
36
37
|
options: { showEvents: true },
|
|
37
38
|
});
|
|
38
39
|
return {
|
|
@@ -50,14 +51,14 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
50
51
|
const totalFee = await this.getTotalFee({
|
|
51
52
|
address: multipleStreamData.partner ?? wallet.address,
|
|
52
53
|
});
|
|
53
|
-
const [
|
|
54
|
+
const [tx, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
|
|
54
55
|
const txs = [];
|
|
55
56
|
const metadatas = [];
|
|
56
57
|
const metadataToRecipient = {};
|
|
57
58
|
const errors = [];
|
|
58
59
|
try {
|
|
59
|
-
const { digest, events, effects } = await wallet.
|
|
60
|
-
|
|
60
|
+
const { digest, events, effects } = await wallet.signAndExecuteTransaction({
|
|
61
|
+
transaction: tx,
|
|
61
62
|
options: { showEffects: true, showEvents: true },
|
|
62
63
|
});
|
|
63
64
|
txs.push(digest);
|
|
@@ -104,19 +105,19 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
104
105
|
*/
|
|
105
106
|
async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
|
|
106
107
|
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
107
|
-
const
|
|
108
|
-
|
|
108
|
+
const tx = new transactions_1.Transaction();
|
|
109
|
+
tx.moveCall({
|
|
109
110
|
target: `${this.programId}::protocol::withdraw`,
|
|
110
111
|
typeArguments: [tokenId],
|
|
111
112
|
arguments: [
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
tx.object(id),
|
|
114
|
+
tx.object(this.configId),
|
|
115
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
116
|
+
tx.pure.u64(amount.toString()),
|
|
116
117
|
],
|
|
117
118
|
});
|
|
118
|
-
const { digest } = await wallet.
|
|
119
|
-
|
|
119
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
120
|
+
transaction: tx,
|
|
120
121
|
});
|
|
121
122
|
return {
|
|
122
123
|
ixs: [],
|
|
@@ -128,14 +129,14 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
128
129
|
*/
|
|
129
130
|
async cancel(cancelData, { senderWallet, tokenId }) {
|
|
130
131
|
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
131
|
-
const
|
|
132
|
-
|
|
132
|
+
const tx = new transactions_1.Transaction();
|
|
133
|
+
tx.moveCall({
|
|
133
134
|
target: `${this.programId}::protocol::cancel`,
|
|
134
135
|
typeArguments: [tokenId],
|
|
135
|
-
arguments: [
|
|
136
|
+
arguments: [tx.object(cancelData.id), tx.object(this.configId), tx.object(utils_1.SUI_CLOCK_OBJECT_ID)],
|
|
136
137
|
});
|
|
137
|
-
const { digest } = await wallet.
|
|
138
|
-
|
|
138
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
139
|
+
transaction: tx,
|
|
139
140
|
});
|
|
140
141
|
return {
|
|
141
142
|
ixs: [],
|
|
@@ -147,14 +148,14 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
147
148
|
*/
|
|
148
149
|
async transfer(transferData, { senderWallet, tokenId }) {
|
|
149
150
|
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
150
|
-
const
|
|
151
|
-
|
|
151
|
+
const tx = new transactions_1.Transaction();
|
|
152
|
+
tx.moveCall({
|
|
152
153
|
target: `${this.programId}::protocol::transfer`,
|
|
153
154
|
typeArguments: [tokenId],
|
|
154
|
-
arguments: [
|
|
155
|
+
arguments: [tx.object(transferData.id), tx.pure.address(transferData.newRecipient)],
|
|
155
156
|
});
|
|
156
|
-
const { digest } = await wallet.
|
|
157
|
-
|
|
157
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
158
|
+
transaction: tx,
|
|
158
159
|
});
|
|
159
160
|
return {
|
|
160
161
|
ixs: [],
|
|
@@ -166,25 +167,25 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
166
167
|
*/
|
|
167
168
|
async topup(topupData, { senderWallet, tokenId }) {
|
|
168
169
|
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
169
|
-
const
|
|
170
|
+
const tx = new transactions_1.Transaction();
|
|
170
171
|
const coins = await this.getAllCoins(wallet.address, tokenId);
|
|
171
172
|
const stream = await this.getOne({ id: topupData.id });
|
|
172
173
|
const totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
|
|
173
|
-
const coinObject = this.splitCoinObjectForAmount(
|
|
174
|
-
|
|
174
|
+
const coinObject = this.splitCoinObjectForAmount(tx, topupData.amount, tokenId, coins, totalFee);
|
|
175
|
+
tx.moveCall({
|
|
175
176
|
target: `${this.programId}::protocol::topup`,
|
|
176
177
|
typeArguments: [tokenId],
|
|
177
178
|
arguments: [
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
tx.object(topupData.id),
|
|
180
|
+
tx.object(this.configId),
|
|
180
181
|
coinObject,
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
tx.gas,
|
|
183
|
+
tx.pure.u64(topupData.amount.toString()),
|
|
183
184
|
],
|
|
184
185
|
});
|
|
185
|
-
this.returnSplittedCoinObject(
|
|
186
|
-
const { digest } = await wallet.
|
|
187
|
-
|
|
186
|
+
this.returnSplittedCoinObject(tx, tokenId, coins, coinObject);
|
|
187
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
188
|
+
transaction: tx,
|
|
188
189
|
});
|
|
189
190
|
return {
|
|
190
191
|
ixs: [],
|
|
@@ -218,22 +219,28 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
218
219
|
*/
|
|
219
220
|
async update(updateData, { senderWallet, tokenId }) {
|
|
220
221
|
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
221
|
-
const
|
|
222
|
-
|
|
222
|
+
const tx = new transactions_1.Transaction();
|
|
223
|
+
tx.moveCall({
|
|
223
224
|
target: `${this.programId}::protocol::update`,
|
|
224
225
|
typeArguments: [tokenId],
|
|
225
226
|
arguments: [
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
227
|
+
tx.object(updateData.id),
|
|
228
|
+
tx.object(this.configId),
|
|
229
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
230
|
+
tx.gas,
|
|
231
|
+
bcs_1.bcs
|
|
232
|
+
.vector(bcs_1.bcs.bool())
|
|
233
|
+
.serialize(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : []),
|
|
234
|
+
bcs_1.bcs
|
|
235
|
+
.vector(bcs_1.bcs.u64())
|
|
236
|
+
.serialize(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : []),
|
|
237
|
+
bcs_1.bcs
|
|
238
|
+
.vector(bcs_1.bcs.u64())
|
|
239
|
+
.serialize(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : []),
|
|
233
240
|
],
|
|
234
241
|
});
|
|
235
|
-
const { digest } = await wallet.
|
|
236
|
-
|
|
242
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
243
|
+
transaction: tx,
|
|
237
244
|
});
|
|
238
245
|
return {
|
|
239
246
|
ixs: [],
|
|
@@ -307,45 +314,45 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
307
314
|
const totalAmount = multipleStreamData.recipients
|
|
308
315
|
.map((recipiient) => recipiient.amount)
|
|
309
316
|
.reduce((prev, current) => current.add(prev));
|
|
310
|
-
const
|
|
311
|
-
const coinObject = this.splitCoinObjectForAmount(
|
|
317
|
+
const tx = new transactions_1.Transaction();
|
|
318
|
+
const coinObject = this.splitCoinObjectForAmount(tx, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
312
319
|
coins = [coins[0]];
|
|
313
320
|
let firstIndex = null;
|
|
314
321
|
multipleStreamData.recipients.forEach((recipient) => {
|
|
315
|
-
const result =
|
|
322
|
+
const result = tx.moveCall({
|
|
316
323
|
target: `${this.programId}::protocol::create`,
|
|
317
324
|
typeArguments: [multipleStreamData.tokenId],
|
|
318
325
|
arguments: [
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
326
|
+
tx.object(this.configId),
|
|
327
|
+
tx.object(this.feeTableId),
|
|
328
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
322
329
|
coinObject,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
330
|
+
tx.gas,
|
|
331
|
+
tx.pure.u64(recipient.amount.toString()),
|
|
332
|
+
tx.pure.u64(multipleStreamData.period),
|
|
333
|
+
tx.pure.u64(recipient.amountPerPeriod.toString()),
|
|
334
|
+
tx.pure.u64(multipleStreamData.start),
|
|
335
|
+
tx.pure.u64(recipient.cliffAmount.toString()),
|
|
336
|
+
tx.pure.bool(multipleStreamData.cancelableBySender),
|
|
337
|
+
tx.pure.bool(multipleStreamData.cancelableByRecipient),
|
|
338
|
+
tx.pure.bool(multipleStreamData.transferableBySender),
|
|
339
|
+
tx.pure.bool(multipleStreamData.transferableByRecipient),
|
|
340
|
+
tx.pure.bool(multipleStreamData.canTopup),
|
|
341
|
+
tx.pure.bool(!!multipleStreamData.canPause),
|
|
342
|
+
tx.pure.bool(!!multipleStreamData.canUpdateRate),
|
|
343
|
+
tx.pure.bool(!!multipleStreamData.automaticWithdrawal),
|
|
344
|
+
tx.pure.u64(multipleStreamData.withdrawalFrequency || 0),
|
|
345
|
+
tx.pure.string(recipient.name),
|
|
346
|
+
tx.pure.address(recipient.recipient),
|
|
347
|
+
tx.pure.address(multipleStreamData.partner || walletAddress),
|
|
341
348
|
],
|
|
342
349
|
});
|
|
343
|
-
if (result
|
|
344
|
-
firstIndex = result.
|
|
350
|
+
if (result.$kind === "Result" && firstIndex === null) {
|
|
351
|
+
firstIndex = result.Result;
|
|
345
352
|
}
|
|
346
353
|
});
|
|
347
|
-
this.returnSplittedCoinObject(
|
|
348
|
-
return [
|
|
354
|
+
this.returnSplittedCoinObject(tx, multipleStreamData.tokenId, coins, coinObject);
|
|
355
|
+
return [tx, firstIndex];
|
|
349
356
|
}
|
|
350
357
|
/**
|
|
351
358
|
* Returns all coins owned by a Wallet
|
|
@@ -373,30 +380,31 @@ class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
373
380
|
* Utility function to split Coin object and use splitted object for stream operations.
|
|
374
381
|
* We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
|
|
375
382
|
* This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
|
|
376
|
-
* @param
|
|
383
|
+
* @param tx current transanction block
|
|
377
384
|
* @param amount minimal amount of coins requried
|
|
378
385
|
* @param coinType coin type
|
|
379
386
|
* @param coins array of owned coins of the same type
|
|
387
|
+
* @param totalFee partner and treasury fees
|
|
380
388
|
* @returns Coin Object to use in a Move Call
|
|
381
389
|
*/
|
|
382
|
-
splitCoinObjectForAmount(
|
|
383
|
-
const coinObject = coinType === utils_1.SUI_TYPE_ARG ?
|
|
390
|
+
splitCoinObjectForAmount(tx, amount, coinType, coins, totalFee) {
|
|
391
|
+
const coinObject = coinType === utils_1.SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
|
|
384
392
|
if (coins.length > 1) {
|
|
385
|
-
|
|
393
|
+
tx.mergeCoins(coinObject, coins.slice(1).map((item) => tx.object(item.coinObjectId)));
|
|
386
394
|
}
|
|
387
395
|
const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(amount, totalFee);
|
|
388
|
-
return
|
|
396
|
+
return tx.splitCoins(coinObject, [tx.pure.u64(totalAmount.toString())])[0];
|
|
389
397
|
}
|
|
390
398
|
/**
|
|
391
399
|
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
|
392
|
-
* @param
|
|
400
|
+
* @param tx current transaction
|
|
393
401
|
* @param coinType coin type
|
|
394
402
|
* @param coinObject splitted object
|
|
395
403
|
* @param coins array of objects used in
|
|
396
404
|
*/
|
|
397
|
-
returnSplittedCoinObject(
|
|
398
|
-
const firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ?
|
|
399
|
-
|
|
405
|
+
returnSplittedCoinObject(tx, coinType, coins, coinObject) {
|
|
406
|
+
const firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
|
|
407
|
+
tx.mergeCoins(firstCoinObject, [coinObject]);
|
|
400
408
|
}
|
|
401
409
|
}
|
|
402
410
|
exports.default = SuiStreamClient;
|
package/dist/cjs/sui/wallet.js
CHANGED
|
@@ -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
|
|
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
|
-
"
|
|
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
|
|
28
|
+
async signAndExecuteTransaction(input) {
|
|
29
29
|
if (isSignerKeypair(this.wallet)) {
|
|
30
|
-
return this.client.
|
|
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.
|
|
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
|
|
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
|
|
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,7 @@
|
|
|
1
|
-
import { SuiClient } from "@mysten/sui
|
|
2
|
-
import {
|
|
3
|
-
import { SUI_CLOCK_OBJECT_ID, SUI_TYPE_ARG } from "@mysten/sui
|
|
1
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
2
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
3
|
+
import { SUI_CLOCK_OBJECT_ID, SUI_TYPE_ARG } from "@mysten/sui/utils";
|
|
4
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
4
5
|
import { BaseStreamClient } from "../common/BaseStreamClient.js";
|
|
5
6
|
import { ICluster, } from "../common/types.js";
|
|
6
7
|
import { SUI_PROGRAM_IDS, SUI_FEE_TABLE_IDS, SUI_CONFIG_IDS } from "./constants.js";
|
|
@@ -29,12 +30,12 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
29
30
|
const totalFee = await this.getTotalFee({
|
|
30
31
|
address: streamData.partner ?? wallet.address,
|
|
31
32
|
});
|
|
32
|
-
const [
|
|
33
|
+
const [tx] = await this.generateCreateBlock(wallet.address, {
|
|
33
34
|
...streamData,
|
|
34
35
|
recipients: [{ ...streamData }],
|
|
35
36
|
}, totalFee);
|
|
36
|
-
const { digest, events } = await wallet.
|
|
37
|
-
|
|
37
|
+
const { digest, events } = await wallet.signAndExecuteTransaction({
|
|
38
|
+
transaction: tx,
|
|
38
39
|
options: { showEvents: true },
|
|
39
40
|
});
|
|
40
41
|
return {
|
|
@@ -52,14 +53,14 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
52
53
|
const totalFee = await this.getTotalFee({
|
|
53
54
|
address: multipleStreamData.partner ?? wallet.address,
|
|
54
55
|
});
|
|
55
|
-
const [
|
|
56
|
+
const [tx, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
|
|
56
57
|
const txs = [];
|
|
57
58
|
const metadatas = [];
|
|
58
59
|
const metadataToRecipient = {};
|
|
59
60
|
const errors = [];
|
|
60
61
|
try {
|
|
61
|
-
const { digest, events, effects } = await wallet.
|
|
62
|
-
|
|
62
|
+
const { digest, events, effects } = await wallet.signAndExecuteTransaction({
|
|
63
|
+
transaction: tx,
|
|
63
64
|
options: { showEffects: true, showEvents: true },
|
|
64
65
|
});
|
|
65
66
|
txs.push(digest);
|
|
@@ -106,19 +107,19 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
106
107
|
*/
|
|
107
108
|
async withdraw({ id, amount = WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
|
|
108
109
|
const wallet = new SuiWalletWrapper(senderWallet, this.client);
|
|
109
|
-
const
|
|
110
|
-
|
|
110
|
+
const tx = new Transaction();
|
|
111
|
+
tx.moveCall({
|
|
111
112
|
target: `${this.programId}::protocol::withdraw`,
|
|
112
113
|
typeArguments: [tokenId],
|
|
113
114
|
arguments: [
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
tx.object(id),
|
|
116
|
+
tx.object(this.configId),
|
|
117
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
118
|
+
tx.pure.u64(amount.toString()),
|
|
118
119
|
],
|
|
119
120
|
});
|
|
120
|
-
const { digest } = await wallet.
|
|
121
|
-
|
|
121
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
122
|
+
transaction: tx,
|
|
122
123
|
});
|
|
123
124
|
return {
|
|
124
125
|
ixs: [],
|
|
@@ -130,14 +131,14 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
130
131
|
*/
|
|
131
132
|
async cancel(cancelData, { senderWallet, tokenId }) {
|
|
132
133
|
const wallet = new SuiWalletWrapper(senderWallet, this.client);
|
|
133
|
-
const
|
|
134
|
-
|
|
134
|
+
const tx = new Transaction();
|
|
135
|
+
tx.moveCall({
|
|
135
136
|
target: `${this.programId}::protocol::cancel`,
|
|
136
137
|
typeArguments: [tokenId],
|
|
137
|
-
arguments: [
|
|
138
|
+
arguments: [tx.object(cancelData.id), tx.object(this.configId), tx.object(SUI_CLOCK_OBJECT_ID)],
|
|
138
139
|
});
|
|
139
|
-
const { digest } = await wallet.
|
|
140
|
-
|
|
140
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
141
|
+
transaction: tx,
|
|
141
142
|
});
|
|
142
143
|
return {
|
|
143
144
|
ixs: [],
|
|
@@ -149,14 +150,14 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
149
150
|
*/
|
|
150
151
|
async transfer(transferData, { senderWallet, tokenId }) {
|
|
151
152
|
const wallet = new SuiWalletWrapper(senderWallet, this.client);
|
|
152
|
-
const
|
|
153
|
-
|
|
153
|
+
const tx = new Transaction();
|
|
154
|
+
tx.moveCall({
|
|
154
155
|
target: `${this.programId}::protocol::transfer`,
|
|
155
156
|
typeArguments: [tokenId],
|
|
156
|
-
arguments: [
|
|
157
|
+
arguments: [tx.object(transferData.id), tx.pure.address(transferData.newRecipient)],
|
|
157
158
|
});
|
|
158
|
-
const { digest } = await wallet.
|
|
159
|
-
|
|
159
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
160
|
+
transaction: tx,
|
|
160
161
|
});
|
|
161
162
|
return {
|
|
162
163
|
ixs: [],
|
|
@@ -168,25 +169,25 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
168
169
|
*/
|
|
169
170
|
async topup(topupData, { senderWallet, tokenId }) {
|
|
170
171
|
const wallet = new SuiWalletWrapper(senderWallet, this.client);
|
|
171
|
-
const
|
|
172
|
+
const tx = new Transaction();
|
|
172
173
|
const coins = await this.getAllCoins(wallet.address, tokenId);
|
|
173
174
|
const stream = await this.getOne({ id: topupData.id });
|
|
174
175
|
const totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
|
|
175
|
-
const coinObject = this.splitCoinObjectForAmount(
|
|
176
|
-
|
|
176
|
+
const coinObject = this.splitCoinObjectForAmount(tx, topupData.amount, tokenId, coins, totalFee);
|
|
177
|
+
tx.moveCall({
|
|
177
178
|
target: `${this.programId}::protocol::topup`,
|
|
178
179
|
typeArguments: [tokenId],
|
|
179
180
|
arguments: [
|
|
180
|
-
|
|
181
|
-
|
|
181
|
+
tx.object(topupData.id),
|
|
182
|
+
tx.object(this.configId),
|
|
182
183
|
coinObject,
|
|
183
|
-
|
|
184
|
-
|
|
184
|
+
tx.gas,
|
|
185
|
+
tx.pure.u64(topupData.amount.toString()),
|
|
185
186
|
],
|
|
186
187
|
});
|
|
187
|
-
this.returnSplittedCoinObject(
|
|
188
|
-
const { digest } = await wallet.
|
|
189
|
-
|
|
188
|
+
this.returnSplittedCoinObject(tx, tokenId, coins, coinObject);
|
|
189
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
190
|
+
transaction: tx,
|
|
190
191
|
});
|
|
191
192
|
return {
|
|
192
193
|
ixs: [],
|
|
@@ -220,22 +221,28 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
220
221
|
*/
|
|
221
222
|
async update(updateData, { senderWallet, tokenId }) {
|
|
222
223
|
const wallet = new SuiWalletWrapper(senderWallet, this.client);
|
|
223
|
-
const
|
|
224
|
-
|
|
224
|
+
const tx = new Transaction();
|
|
225
|
+
tx.moveCall({
|
|
225
226
|
target: `${this.programId}::protocol::update`,
|
|
226
227
|
typeArguments: [tokenId],
|
|
227
228
|
arguments: [
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
229
|
+
tx.object(updateData.id),
|
|
230
|
+
tx.object(this.configId),
|
|
231
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
232
|
+
tx.gas,
|
|
233
|
+
bcs
|
|
234
|
+
.vector(bcs.bool())
|
|
235
|
+
.serialize(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : []),
|
|
236
|
+
bcs
|
|
237
|
+
.vector(bcs.u64())
|
|
238
|
+
.serialize(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : []),
|
|
239
|
+
bcs
|
|
240
|
+
.vector(bcs.u64())
|
|
241
|
+
.serialize(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : []),
|
|
235
242
|
],
|
|
236
243
|
});
|
|
237
|
-
const { digest } = await wallet.
|
|
238
|
-
|
|
244
|
+
const { digest } = await wallet.signAndExecuteTransaction({
|
|
245
|
+
transaction: tx,
|
|
239
246
|
});
|
|
240
247
|
return {
|
|
241
248
|
ixs: [],
|
|
@@ -309,45 +316,45 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
309
316
|
const totalAmount = multipleStreamData.recipients
|
|
310
317
|
.map((recipiient) => recipiient.amount)
|
|
311
318
|
.reduce((prev, current) => current.add(prev));
|
|
312
|
-
const
|
|
313
|
-
const coinObject = this.splitCoinObjectForAmount(
|
|
319
|
+
const tx = new Transaction();
|
|
320
|
+
const coinObject = this.splitCoinObjectForAmount(tx, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
314
321
|
coins = [coins[0]];
|
|
315
322
|
let firstIndex = null;
|
|
316
323
|
multipleStreamData.recipients.forEach((recipient) => {
|
|
317
|
-
const result =
|
|
324
|
+
const result = tx.moveCall({
|
|
318
325
|
target: `${this.programId}::protocol::create`,
|
|
319
326
|
typeArguments: [multipleStreamData.tokenId],
|
|
320
327
|
arguments: [
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
328
|
+
tx.object(this.configId),
|
|
329
|
+
tx.object(this.feeTableId),
|
|
330
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
324
331
|
coinObject,
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
332
|
+
tx.gas,
|
|
333
|
+
tx.pure.u64(recipient.amount.toString()),
|
|
334
|
+
tx.pure.u64(multipleStreamData.period),
|
|
335
|
+
tx.pure.u64(recipient.amountPerPeriod.toString()),
|
|
336
|
+
tx.pure.u64(multipleStreamData.start),
|
|
337
|
+
tx.pure.u64(recipient.cliffAmount.toString()),
|
|
338
|
+
tx.pure.bool(multipleStreamData.cancelableBySender),
|
|
339
|
+
tx.pure.bool(multipleStreamData.cancelableByRecipient),
|
|
340
|
+
tx.pure.bool(multipleStreamData.transferableBySender),
|
|
341
|
+
tx.pure.bool(multipleStreamData.transferableByRecipient),
|
|
342
|
+
tx.pure.bool(multipleStreamData.canTopup),
|
|
343
|
+
tx.pure.bool(!!multipleStreamData.canPause),
|
|
344
|
+
tx.pure.bool(!!multipleStreamData.canUpdateRate),
|
|
345
|
+
tx.pure.bool(!!multipleStreamData.automaticWithdrawal),
|
|
346
|
+
tx.pure.u64(multipleStreamData.withdrawalFrequency || 0),
|
|
347
|
+
tx.pure.string(recipient.name),
|
|
348
|
+
tx.pure.address(recipient.recipient),
|
|
349
|
+
tx.pure.address(multipleStreamData.partner || walletAddress),
|
|
343
350
|
],
|
|
344
351
|
});
|
|
345
|
-
if (result
|
|
346
|
-
firstIndex = result.
|
|
352
|
+
if (result.$kind === "Result" && firstIndex === null) {
|
|
353
|
+
firstIndex = result.Result;
|
|
347
354
|
}
|
|
348
355
|
});
|
|
349
|
-
this.returnSplittedCoinObject(
|
|
350
|
-
return [
|
|
356
|
+
this.returnSplittedCoinObject(tx, multipleStreamData.tokenId, coins, coinObject);
|
|
357
|
+
return [tx, firstIndex];
|
|
351
358
|
}
|
|
352
359
|
/**
|
|
353
360
|
* Returns all coins owned by a Wallet
|
|
@@ -375,29 +382,30 @@ export default class SuiStreamClient extends BaseStreamClient {
|
|
|
375
382
|
* Utility function to split Coin object and use splitted object for stream operations.
|
|
376
383
|
* We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
|
|
377
384
|
* This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
|
|
378
|
-
* @param
|
|
385
|
+
* @param tx current transanction block
|
|
379
386
|
* @param amount minimal amount of coins requried
|
|
380
387
|
* @param coinType coin type
|
|
381
388
|
* @param coins array of owned coins of the same type
|
|
389
|
+
* @param totalFee partner and treasury fees
|
|
382
390
|
* @returns Coin Object to use in a Move Call
|
|
383
391
|
*/
|
|
384
|
-
splitCoinObjectForAmount(
|
|
385
|
-
const coinObject = coinType === SUI_TYPE_ARG ?
|
|
392
|
+
splitCoinObjectForAmount(tx, amount, coinType, coins, totalFee) {
|
|
393
|
+
const coinObject = coinType === SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
|
|
386
394
|
if (coins.length > 1) {
|
|
387
|
-
|
|
395
|
+
tx.mergeCoins(coinObject, coins.slice(1).map((item) => tx.object(item.coinObjectId)));
|
|
388
396
|
}
|
|
389
397
|
const totalAmount = calculateTotalAmountToDeposit(amount, totalFee);
|
|
390
|
-
return
|
|
398
|
+
return tx.splitCoins(coinObject, [tx.pure.u64(totalAmount.toString())])[0];
|
|
391
399
|
}
|
|
392
400
|
/**
|
|
393
401
|
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
|
394
|
-
* @param
|
|
402
|
+
* @param tx current transaction
|
|
395
403
|
* @param coinType coin type
|
|
396
404
|
* @param coinObject splitted object
|
|
397
405
|
* @param coins array of objects used in
|
|
398
406
|
*/
|
|
399
|
-
returnSplittedCoinObject(
|
|
400
|
-
const firstCoinObject = coinType === SUI_TYPE_ARG ?
|
|
401
|
-
|
|
407
|
+
returnSplittedCoinObject(tx, coinType, coins, coinObject) {
|
|
408
|
+
const firstCoinObject = coinType === SUI_TYPE_ARG ? tx.gas : tx.object(coins[0].coinObjectId);
|
|
409
|
+
tx.mergeCoins(firstCoinObject, [coinObject]);
|
|
402
410
|
}
|
|
403
411
|
}
|
package/dist/esm/sui/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Keypair } from "@mysten/sui
|
|
1
|
+
import { Keypair } from "@mysten/sui/cryptography";
|
|
2
2
|
import { WalletContextState } from "@suiet/wallet-kit";
|
|
3
|
-
import {
|
|
4
|
-
import { ExecuteTransactionRequestType, SuiTransactionBlockResponseOptions } from "@mysten/sui
|
|
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
|
-
|
|
164
|
+
transaction: Transaction;
|
|
165
165
|
requestType?: ExecuteTransactionRequestType;
|
|
166
166
|
options?: SuiTransactionBlockResponseOptions;
|
|
167
167
|
}
|
package/dist/esm/sui/wallet.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Keypair } from "@mysten/sui
|
|
1
|
+
import { Keypair } from "@mysten/sui/cryptography";
|
|
2
2
|
import { WalletContextState } from "@suiet/wallet-kit";
|
|
3
|
-
import { SuiClient, SuiTransactionBlockResponse } from "@mysten/sui
|
|
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
|
-
|
|
16
|
+
signAndExecuteTransaction(input: SuiSignAndExecuteTransactionBlockInput): Promise<SuiTransactionBlockResponse>;
|
|
17
17
|
}
|
package/dist/esm/sui/wallet.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Keypair } from "@mysten/sui
|
|
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
|
-
"
|
|
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
|
|
27
|
+
async signAndExecuteTransaction(input) {
|
|
28
28
|
if (isSignerKeypair(this.wallet)) {
|
|
29
|
-
return this.client.
|
|
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.
|
|
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.
|
|
3
|
+
"version": "7.3.0",
|
|
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": "
|
|
45
|
+
"gitHead": "3c9abdd18e875a64cbd7d1ba4b14ee4bcb094b11",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@streamflow/eslint-config": "7.
|
|
47
|
+
"@streamflow/eslint-config": "7.3.0",
|
|
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,13 @@
|
|
|
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
|
|
57
|
+
"@mysten/sui": "1.12.0",
|
|
58
58
|
"@solana/buffer-layout": "4.0.1",
|
|
59
59
|
"@solana/spl-token": "0.4.9",
|
|
60
60
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
61
61
|
"@solana/web3.js": "1.95.4",
|
|
62
|
-
"@streamflow/common": "7.
|
|
63
|
-
"@suiet/wallet-kit": "0.
|
|
62
|
+
"@streamflow/common": "7.3.0",
|
|
63
|
+
"@suiet/wallet-kit": "^0.3.3",
|
|
64
64
|
"aptos": "1.21.0",
|
|
65
65
|
"bn.js": "5.2.1",
|
|
66
66
|
"borsh": "^2.0.0",
|