@streamflow/stream 7.2.0 → 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/solana/StreamClient.js +21 -14
- package/dist/cjs/sui/StreamClient.js +93 -85
- package/dist/cjs/sui/wallet.js +5 -5
- package/dist/esm/common/types.d.ts +18 -10
- package/dist/esm/solana/StreamClient.d.ts +1 -1
- package/dist/esm/solana/StreamClient.js +22 -15
- 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
|
@@ -59,18 +59,25 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
59
59
|
this.commitment = commitment;
|
|
60
60
|
this.connection = new web3_js_1.Connection(optionsOrClusterUrl, this.commitment);
|
|
61
61
|
this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_js_1.PROGRAM_ID[cluster]);
|
|
62
|
-
this.
|
|
62
|
+
this.schedulingParams = {
|
|
63
|
+
sendThrottler: sendThrottler ?? (0, solana_1.buildSendThrottler)(sendRate),
|
|
64
|
+
};
|
|
63
65
|
}
|
|
64
66
|
else {
|
|
65
67
|
const { clusterUrl, cluster = types_js_2.ICluster.Mainnet, commitment = "confirmed", programId = "", sendScheduler, } = optionsOrClusterUrl;
|
|
66
68
|
this.commitment = commitment;
|
|
67
69
|
this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
|
|
68
70
|
this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_js_1.PROGRAM_ID[cluster]);
|
|
69
|
-
|
|
71
|
+
const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : undefined;
|
|
72
|
+
const sendThrottler = !sendScheduler
|
|
70
73
|
? (0, solana_1.buildSendThrottler)(1)
|
|
71
74
|
: "sendRate" in sendScheduler
|
|
72
75
|
? (0, solana_1.buildSendThrottler)(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval)
|
|
73
76
|
: sendScheduler;
|
|
77
|
+
this.schedulingParams = {
|
|
78
|
+
...schedulingOptions,
|
|
79
|
+
sendThrottler,
|
|
80
|
+
};
|
|
74
81
|
}
|
|
75
82
|
const alignedUnlocksProgram = {
|
|
76
83
|
...streamflow_aligned_unlocks_json_1.default,
|
|
@@ -114,7 +121,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
114
121
|
hash,
|
|
115
122
|
context,
|
|
116
123
|
commitment: this.getCommitment(),
|
|
117
|
-
},
|
|
124
|
+
}, this.schedulingParams);
|
|
118
125
|
return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
|
|
119
126
|
}
|
|
120
127
|
async prepareCreateInstructions(streamParams, extParams) {
|
|
@@ -271,7 +278,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
271
278
|
hash,
|
|
272
279
|
context,
|
|
273
280
|
commitment: this.getCommitment(),
|
|
274
|
-
},
|
|
281
|
+
}, this.schedulingParams);
|
|
275
282
|
return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
|
|
276
283
|
}
|
|
277
284
|
/**
|
|
@@ -414,7 +421,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
414
421
|
const signedBatch = await (0, utils_js_1.signAllTransactionWithRecipients)(sender, batch);
|
|
415
422
|
if (prepareInstructions.length > 0) {
|
|
416
423
|
const prepareTx = signedBatch.pop();
|
|
417
|
-
await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context },
|
|
424
|
+
await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context }, this.schedulingParams);
|
|
418
425
|
}
|
|
419
426
|
const responses = [];
|
|
420
427
|
if (metadataPubKeys.length > 0) {
|
|
@@ -422,7 +429,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
422
429
|
//ephemeral signer need to be used first before proceeding with the next
|
|
423
430
|
for (const batchTx of signedBatch) {
|
|
424
431
|
responses.push(...(await Promise.allSettled([
|
|
425
|
-
(0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context },
|
|
432
|
+
(0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context }, this.schedulingParams),
|
|
426
433
|
])));
|
|
427
434
|
}
|
|
428
435
|
}
|
|
@@ -430,7 +437,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
430
437
|
//send all transactions in parallel and wait for them to settle.
|
|
431
438
|
//it allows to speed up the process of sending transactions
|
|
432
439
|
//we then filter all promise responses and handle failed transactions
|
|
433
|
-
responses.push(...(await (0, solana_1.executeMultipleTransactions)(this.connection, signedBatch.map((item) => item.tx), { hash, context },
|
|
440
|
+
responses.push(...(await (0, solana_1.executeMultipleTransactions)(this.connection, signedBatch.map((item) => item.tx), { hash, context }, this.schedulingParams)));
|
|
434
441
|
}
|
|
435
442
|
responses.forEach((item, index) => {
|
|
436
443
|
if (item.status === "fulfilled") {
|
|
@@ -521,12 +528,12 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
521
528
|
const signedBatch = await (0, utils_js_1.signAllTransactionWithRecipients)(sender, batch);
|
|
522
529
|
if (prepareInstructions.length > 0) {
|
|
523
530
|
const prepareTx = signedBatch.shift();
|
|
524
|
-
await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context },
|
|
531
|
+
await (0, utils_js_1.sendAndConfirmStreamRawTransaction)(this.connection, prepareTx, { hash, context }, this.schedulingParams);
|
|
525
532
|
}
|
|
526
533
|
const responses = [];
|
|
527
534
|
for (const batchTx of signedBatch) {
|
|
528
535
|
responses.push(...(await Promise.allSettled([
|
|
529
|
-
(0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context },
|
|
536
|
+
(0, solana_1.executeTransaction)(this.connection, batchTx.tx, { hash, context }, this.schedulingParams),
|
|
530
537
|
])));
|
|
531
538
|
}
|
|
532
539
|
responses.forEach((item, index) => {
|
|
@@ -553,7 +560,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
553
560
|
hash,
|
|
554
561
|
context,
|
|
555
562
|
commitment: this.getCommitment(),
|
|
556
|
-
},
|
|
563
|
+
}, this.schedulingParams);
|
|
557
564
|
return { ixs, txId: signature };
|
|
558
565
|
}
|
|
559
566
|
/**
|
|
@@ -603,7 +610,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
603
610
|
hash,
|
|
604
611
|
context,
|
|
605
612
|
commitment: this.getCommitment(),
|
|
606
|
-
},
|
|
613
|
+
}, this.schedulingParams);
|
|
607
614
|
return { ixs, txId: signature };
|
|
608
615
|
}
|
|
609
616
|
async prepareCancelInstructions(cancelData, extParams) {
|
|
@@ -703,7 +710,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
703
710
|
hash,
|
|
704
711
|
context,
|
|
705
712
|
commitment: this.getCommitment(),
|
|
706
|
-
},
|
|
713
|
+
}, this.schedulingParams);
|
|
707
714
|
return { ixs, txId: signature };
|
|
708
715
|
}
|
|
709
716
|
/**
|
|
@@ -750,7 +757,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
750
757
|
hash,
|
|
751
758
|
context,
|
|
752
759
|
commitment: this.getCommitment(),
|
|
753
|
-
},
|
|
760
|
+
}, this.schedulingParams);
|
|
754
761
|
return { ixs, txId: signature };
|
|
755
762
|
}
|
|
756
763
|
/**
|
|
@@ -918,7 +925,7 @@ class SolanaStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
|
918
925
|
hash,
|
|
919
926
|
context,
|
|
920
927
|
commitment: this.getCommitment(),
|
|
921
|
-
},
|
|
928
|
+
}, this.schedulingParams);
|
|
922
929
|
return {
|
|
923
930
|
ixs,
|
|
924
931
|
txId: signature,
|
|
@@ -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;
|
|
@@ -287,6 +287,23 @@ export declare enum SolanaAlignedProxyErrorCode {
|
|
|
287
287
|
/** All funds are already unlocked */
|
|
288
288
|
AllFundsUnlocked = "AllFundsUnlocked"
|
|
289
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* @interface
|
|
292
|
+
*/
|
|
293
|
+
export interface SolanaTransactionSchedulingOptions {
|
|
294
|
+
/**
|
|
295
|
+
* concurrency rate for scheduling
|
|
296
|
+
*/
|
|
297
|
+
sendRate: number;
|
|
298
|
+
/**
|
|
299
|
+
* time interval between consecutive sends
|
|
300
|
+
*/
|
|
301
|
+
sendInterval?: number;
|
|
302
|
+
/**
|
|
303
|
+
* time interval before confirming the transaction
|
|
304
|
+
*/
|
|
305
|
+
waitBeforeConfirming?: number;
|
|
306
|
+
}
|
|
290
307
|
/**
|
|
291
308
|
* @interface
|
|
292
309
|
*/
|
|
@@ -298,16 +315,7 @@ export interface SolanaStreamClientOptions {
|
|
|
298
315
|
commitment?: Commitment | ConnectionConfig;
|
|
299
316
|
sendRate?: number;
|
|
300
317
|
sendThrottler?: PQueue;
|
|
301
|
-
sendScheduler?: PQueue |
|
|
302
|
-
/**
|
|
303
|
-
* concurrency rate for scheduling
|
|
304
|
-
*/
|
|
305
|
-
sendRate: number;
|
|
306
|
-
/**
|
|
307
|
-
* time interval between consecutive sends
|
|
308
|
-
*/
|
|
309
|
-
sendInterval?: number;
|
|
310
|
-
};
|
|
318
|
+
sendScheduler?: PQueue | SolanaTransactionSchedulingOptions;
|
|
311
319
|
}
|
|
312
320
|
/**
|
|
313
321
|
* @interface
|
|
@@ -15,8 +15,8 @@ export declare class SolanaStreamClient extends BaseStreamClient {
|
|
|
15
15
|
private connection;
|
|
16
16
|
private programId;
|
|
17
17
|
private commitment;
|
|
18
|
-
private sendThrottler;
|
|
19
18
|
private alignedProxyProgram;
|
|
19
|
+
private schedulingParams;
|
|
20
20
|
/**
|
|
21
21
|
* Create Stream instance with flat arguments
|
|
22
22
|
*/
|
|
@@ -24,8 +24,8 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
24
24
|
connection;
|
|
25
25
|
programId;
|
|
26
26
|
commitment;
|
|
27
|
-
sendThrottler;
|
|
28
27
|
alignedProxyProgram;
|
|
28
|
+
schedulingParams;
|
|
29
29
|
/**
|
|
30
30
|
* Create Stream instance
|
|
31
31
|
*/
|
|
@@ -35,18 +35,25 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
35
35
|
this.commitment = commitment;
|
|
36
36
|
this.connection = new Connection(optionsOrClusterUrl, this.commitment);
|
|
37
37
|
this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(PROGRAM_ID[cluster]);
|
|
38
|
-
this.
|
|
38
|
+
this.schedulingParams = {
|
|
39
|
+
sendThrottler: sendThrottler ?? buildSendThrottler(sendRate),
|
|
40
|
+
};
|
|
39
41
|
}
|
|
40
42
|
else {
|
|
41
43
|
const { clusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendScheduler, } = optionsOrClusterUrl;
|
|
42
44
|
this.commitment = commitment;
|
|
43
45
|
this.connection = new Connection(clusterUrl, this.commitment);
|
|
44
46
|
this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(PROGRAM_ID[cluster]);
|
|
45
|
-
|
|
47
|
+
const schedulingOptions = sendScheduler && "sendRate" in sendScheduler ? sendScheduler : undefined;
|
|
48
|
+
const sendThrottler = !sendScheduler
|
|
46
49
|
? buildSendThrottler(1)
|
|
47
50
|
: "sendRate" in sendScheduler
|
|
48
51
|
? buildSendThrottler(sendScheduler.sendRate ?? 1, sendScheduler.sendInterval)
|
|
49
52
|
: sendScheduler;
|
|
53
|
+
this.schedulingParams = {
|
|
54
|
+
...schedulingOptions,
|
|
55
|
+
sendThrottler,
|
|
56
|
+
};
|
|
50
57
|
}
|
|
51
58
|
const alignedUnlocksProgram = {
|
|
52
59
|
...StreamflowAlignedUnlocksIDL,
|
|
@@ -90,7 +97,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
90
97
|
hash,
|
|
91
98
|
context,
|
|
92
99
|
commitment: this.getCommitment(),
|
|
93
|
-
},
|
|
100
|
+
}, this.schedulingParams);
|
|
94
101
|
return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
|
|
95
102
|
}
|
|
96
103
|
async prepareCreateInstructions(streamParams, extParams) {
|
|
@@ -247,7 +254,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
247
254
|
hash,
|
|
248
255
|
context,
|
|
249
256
|
commitment: this.getCommitment(),
|
|
250
|
-
},
|
|
257
|
+
}, this.schedulingParams);
|
|
251
258
|
return { ixs, txId: signature, metadataId: metadataPubKey.toBase58() };
|
|
252
259
|
}
|
|
253
260
|
/**
|
|
@@ -390,7 +397,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
390
397
|
const signedBatch = await signAllTransactionWithRecipients(sender, batch);
|
|
391
398
|
if (prepareInstructions.length > 0) {
|
|
392
399
|
const prepareTx = signedBatch.pop();
|
|
393
|
-
await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context },
|
|
400
|
+
await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
|
|
394
401
|
}
|
|
395
402
|
const responses = [];
|
|
396
403
|
if (metadataPubKeys.length > 0) {
|
|
@@ -398,7 +405,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
398
405
|
//ephemeral signer need to be used first before proceeding with the next
|
|
399
406
|
for (const batchTx of signedBatch) {
|
|
400
407
|
responses.push(...(await Promise.allSettled([
|
|
401
|
-
executeTransaction(this.connection, batchTx.tx, { hash, context },
|
|
408
|
+
executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams),
|
|
402
409
|
])));
|
|
403
410
|
}
|
|
404
411
|
}
|
|
@@ -406,7 +413,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
406
413
|
//send all transactions in parallel and wait for them to settle.
|
|
407
414
|
//it allows to speed up the process of sending transactions
|
|
408
415
|
//we then filter all promise responses and handle failed transactions
|
|
409
|
-
responses.push(...(await executeMultipleTransactions(this.connection, signedBatch.map((item) => item.tx), { hash, context },
|
|
416
|
+
responses.push(...(await executeMultipleTransactions(this.connection, signedBatch.map((item) => item.tx), { hash, context }, this.schedulingParams)));
|
|
410
417
|
}
|
|
411
418
|
responses.forEach((item, index) => {
|
|
412
419
|
if (item.status === "fulfilled") {
|
|
@@ -497,12 +504,12 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
497
504
|
const signedBatch = await signAllTransactionWithRecipients(sender, batch);
|
|
498
505
|
if (prepareInstructions.length > 0) {
|
|
499
506
|
const prepareTx = signedBatch.shift();
|
|
500
|
-
await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context },
|
|
507
|
+
await sendAndConfirmStreamRawTransaction(this.connection, prepareTx, { hash, context }, this.schedulingParams);
|
|
501
508
|
}
|
|
502
509
|
const responses = [];
|
|
503
510
|
for (const batchTx of signedBatch) {
|
|
504
511
|
responses.push(...(await Promise.allSettled([
|
|
505
|
-
executeTransaction(this.connection, batchTx.tx, { hash, context },
|
|
512
|
+
executeTransaction(this.connection, batchTx.tx, { hash, context }, this.schedulingParams),
|
|
506
513
|
])));
|
|
507
514
|
}
|
|
508
515
|
responses.forEach((item, index) => {
|
|
@@ -529,7 +536,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
529
536
|
hash,
|
|
530
537
|
context,
|
|
531
538
|
commitment: this.getCommitment(),
|
|
532
|
-
},
|
|
539
|
+
}, this.schedulingParams);
|
|
533
540
|
return { ixs, txId: signature };
|
|
534
541
|
}
|
|
535
542
|
/**
|
|
@@ -579,7 +586,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
579
586
|
hash,
|
|
580
587
|
context,
|
|
581
588
|
commitment: this.getCommitment(),
|
|
582
|
-
},
|
|
589
|
+
}, this.schedulingParams);
|
|
583
590
|
return { ixs, txId: signature };
|
|
584
591
|
}
|
|
585
592
|
async prepareCancelInstructions(cancelData, extParams) {
|
|
@@ -679,7 +686,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
679
686
|
hash,
|
|
680
687
|
context,
|
|
681
688
|
commitment: this.getCommitment(),
|
|
682
|
-
},
|
|
689
|
+
}, this.schedulingParams);
|
|
683
690
|
return { ixs, txId: signature };
|
|
684
691
|
}
|
|
685
692
|
/**
|
|
@@ -726,7 +733,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
726
733
|
hash,
|
|
727
734
|
context,
|
|
728
735
|
commitment: this.getCommitment(),
|
|
729
|
-
},
|
|
736
|
+
}, this.schedulingParams);
|
|
730
737
|
return { ixs, txId: signature };
|
|
731
738
|
}
|
|
732
739
|
/**
|
|
@@ -894,7 +901,7 @@ export class SolanaStreamClient extends BaseStreamClient {
|
|
|
894
901
|
hash,
|
|
895
902
|
context,
|
|
896
903
|
commitment: this.getCommitment(),
|
|
897
|
-
},
|
|
904
|
+
}, this.schedulingParams);
|
|
898
905
|
return {
|
|
899
906
|
ixs,
|
|
900
907
|
txId: signature,
|
|
@@ -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",
|