@streamflow/stream 7.0.0-alpha.1 → 7.0.0-alpha.11
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/README.md +65 -68
- package/dist/cjs/__tests__/aptos/streamClient.spec.js +83 -134
- package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +9 -9
- package/dist/cjs/aptos/StreamClient.js +162 -367
- package/dist/cjs/aptos/constants.js +7 -8
- package/dist/cjs/aptos/index.js +3 -3
- package/dist/cjs/aptos/types.js +32 -41
- package/dist/cjs/aptos/utils.js +4 -4
- package/dist/cjs/aptos/wallet.js +20 -75
- package/dist/cjs/common/BaseStreamClient.js +11 -59
- package/dist/cjs/common/GenericStreamClient.js +46 -72
- package/dist/cjs/common/constants.js +2 -2
- package/dist/cjs/common/contractUtils.js +16 -17
- package/dist/cjs/common/utils.js +34 -84
- package/dist/cjs/evm/StreamClient.js +198 -456
- package/dist/cjs/evm/constants.js +19 -20
- package/dist/cjs/evm/types.js +25 -34
- package/dist/cjs/evm/utils.js +2 -2
- package/dist/cjs/index.js +10 -10
- package/dist/cjs/solana/StreamClient.js +608 -1090
- package/dist/cjs/solana/constants.js +16 -11
- package/dist/cjs/solana/instructions.js +76 -80
- package/dist/cjs/solana/layout.js +7 -8
- package/dist/cjs/solana/types.js +15 -25
- package/dist/cjs/solana/utils.js +77 -154
- package/dist/cjs/sui/StreamClient.js +325 -571
- package/dist/cjs/sui/constants.js +19 -20
- package/dist/cjs/sui/types.js +28 -62
- package/dist/cjs/sui/utils.js +7 -7
- package/dist/cjs/sui/wallet.js +13 -63
- package/dist/esm/__tests__/aptos/streamClient.spec.js +4 -4
- package/dist/esm/aptos/index.d.ts +3 -3
- package/dist/esm/aptos/index.js +3 -3
- package/dist/esm/aptos/types.d.ts +12 -12
- package/dist/esm/aptos/types.js +13 -13
- package/dist/esm/common/GenericStreamClient.d.ts +4 -4
- package/dist/esm/common/GenericStreamClient.js +4 -4
- package/dist/esm/common/constants.d.ts +2 -2
- package/dist/esm/common/constants.js +2 -2
- package/dist/esm/common/contractUtils.d.ts +14 -14
- package/dist/esm/common/contractUtils.js +6 -6
- package/dist/esm/common/types.d.ts +19 -19
- package/dist/esm/common/utils.d.ts +11 -11
- package/dist/esm/common/utils.js +16 -19
- package/dist/esm/evm/StreamClient.d.ts +2 -2
- package/dist/esm/evm/StreamClient.js +7 -7
- package/dist/esm/evm/types.d.ts +37 -37
- package/dist/esm/evm/types.js +13 -13
- package/dist/esm/index.d.ts +9 -9
- package/dist/esm/index.js +9 -9
- package/dist/esm/solana/StreamClient.d.ts +3 -1
- package/dist/esm/solana/StreamClient.js +38 -22
- package/dist/esm/solana/constants.d.ts +3 -0
- package/dist/esm/solana/constants.js +6 -0
- package/dist/esm/solana/instructions.d.ts +17 -17
- package/dist/esm/solana/instructions.js +19 -18
- package/dist/esm/solana/types.d.ts +41 -36
- package/dist/esm/solana/types.js +2 -2
- package/dist/esm/solana/utils.d.ts +2 -0
- package/dist/esm/solana/utils.js +32 -26
- package/dist/esm/sui/StreamClient.js +1 -1
- package/dist/esm/sui/types.d.ts +12 -12
- package/dist/esm/sui/types.js +13 -13
- package/package.json +10 -11
|
@@ -1,619 +1,374 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
-
function step(op) {
|
|
42
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
44
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
-
switch (op[0]) {
|
|
47
|
-
case 0: case 1: t = op; break;
|
|
48
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
-
default:
|
|
52
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
-
if (t[2]) _.ops.pop();
|
|
57
|
-
_.trys.pop(); continue;
|
|
58
|
-
}
|
|
59
|
-
op = body.call(thisArg, _);
|
|
60
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
65
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
66
|
-
if (!m) return o;
|
|
67
|
-
var i = m.call(o), r, ar = [], e;
|
|
68
|
-
try {
|
|
69
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
70
|
-
}
|
|
71
|
-
catch (error) { e = { error: error }; }
|
|
72
|
-
finally {
|
|
73
|
-
try {
|
|
74
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
75
|
-
}
|
|
76
|
-
finally { if (e) throw e.error; }
|
|
77
|
-
}
|
|
78
|
-
return ar;
|
|
79
|
-
};
|
|
80
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
81
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
82
|
-
if (ar || !(i in from)) {
|
|
83
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
84
|
-
ar[i] = from[i];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
88
|
-
};
|
|
89
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
_this.feeTableId = (ids === null || ids === void 0 ? void 0 : ids.feeTable) ? ids.feeTable : constants_js_1.SUI_FEE_TABLE_IDS[cluster];
|
|
109
|
-
_this.client = new client_1.SuiClient({ url: clusterUrl });
|
|
110
|
-
return _this;
|
|
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");
|
|
6
|
+
const BaseStreamClient_js_1 = require("../common/BaseStreamClient.js");
|
|
7
|
+
const types_js_1 = require("../common/types.js");
|
|
8
|
+
const constants_js_1 = require("./constants.js");
|
|
9
|
+
const types_js_2 = require("./types.js");
|
|
10
|
+
const utils_js_1 = require("./utils.js");
|
|
11
|
+
const wallet_js_1 = require("./wallet.js");
|
|
12
|
+
const utils_js_2 = require("../common/utils.js");
|
|
13
|
+
const constants_js_2 = require("../common/constants.js");
|
|
14
|
+
class SuiStreamClient extends BaseStreamClient_js_1.BaseStreamClient {
|
|
15
|
+
constructor(clusterUrl, cluster = types_js_1.ICluster.Mainnet, ids) {
|
|
16
|
+
super();
|
|
17
|
+
this.programId = ids?.program ? ids.program : constants_js_1.SUI_PROGRAM_IDS[cluster];
|
|
18
|
+
this.configId = ids?.config ? ids.config : constants_js_1.SUI_CONFIG_IDS[cluster];
|
|
19
|
+
this.feeTableId = ids?.feeTable ? ids.feeTable : constants_js_1.SUI_FEE_TABLE_IDS[cluster];
|
|
20
|
+
this.client = new client_1.SuiClient({ url: clusterUrl });
|
|
111
21
|
}
|
|
112
22
|
/**
|
|
113
23
|
* Creates a new stream/vesting contract.
|
|
114
24
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
case 1:
|
|
128
|
-
totalFee = _e.sent();
|
|
129
|
-
return [4 /*yield*/, this.generateCreateBlock(wallet.address, __assign(__assign({}, streamData), { recipients: [__assign({}, streamData)] }), totalFee)];
|
|
130
|
-
case 2:
|
|
131
|
-
_c = __read.apply(void 0, [_e.sent(), 1]), txb = _c[0];
|
|
132
|
-
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
133
|
-
transactionBlock: txb,
|
|
134
|
-
options: { showEvents: true },
|
|
135
|
-
})];
|
|
136
|
-
case 3:
|
|
137
|
-
_d = _e.sent(), digest = _d.digest, events = _d.events;
|
|
138
|
-
return [2 /*return*/, {
|
|
139
|
-
ixs: [],
|
|
140
|
-
txId: digest,
|
|
141
|
-
metadataId: events[0].parsedJson.address,
|
|
142
|
-
}];
|
|
143
|
-
}
|
|
144
|
-
});
|
|
25
|
+
async create(streamData, { senderWallet }) {
|
|
26
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
27
|
+
const totalFee = await this.getTotalFee({
|
|
28
|
+
address: streamData.partner ?? wallet.address,
|
|
29
|
+
});
|
|
30
|
+
const [txb] = await this.generateCreateBlock(wallet.address, {
|
|
31
|
+
...streamData,
|
|
32
|
+
recipients: [{ ...streamData }],
|
|
33
|
+
}, totalFee);
|
|
34
|
+
const { digest, events } = await wallet.signAndExecuteTransactionBlock({
|
|
35
|
+
transactionBlock: txb,
|
|
36
|
+
options: { showEvents: true },
|
|
145
37
|
});
|
|
146
|
-
|
|
38
|
+
return {
|
|
39
|
+
ixs: [],
|
|
40
|
+
txId: digest,
|
|
41
|
+
metadataId: events[0].parsedJson.address,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
147
44
|
/**
|
|
148
45
|
* Creates multiple stream/vesting contracts.
|
|
149
46
|
* We don't chain transactions in one Block so that one failed transaction does not revert all others.
|
|
150
47
|
*/
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
metadataToRecipient[metadataId] = recipient;
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
return [3 /*break*/, 6];
|
|
199
|
-
case 5:
|
|
200
|
-
e_1 = _f.sent();
|
|
201
|
-
errorInfo_1 = (0, utils_js_1.extractSuiErrorInfo)((_c = e_1.toString()) !== null && _c !== void 0 ? _c : "Unknown error!");
|
|
202
|
-
multipleStreamData.recipients.forEach(function (recipient, index) {
|
|
203
|
-
var _a;
|
|
204
|
-
if (errorInfo_1.index === undefined ||
|
|
205
|
-
errorInfo_1.index < index + firstIndex ||
|
|
206
|
-
errorInfo_1.index >= multipleStreamData.recipients.length + firstIndex ||
|
|
207
|
-
errorInfo_1.index === index + firstIndex) {
|
|
208
|
-
errors.push({
|
|
209
|
-
error: errorInfo_1.text,
|
|
210
|
-
recipient: recipient.recipient,
|
|
211
|
-
contractErrorCode: (_a = errorInfo_1.parsed) === null || _a === void 0 ? void 0 : _a.name,
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
return [3 /*break*/, 6];
|
|
216
|
-
case 6: return [2 /*return*/, {
|
|
217
|
-
txs: txs,
|
|
218
|
-
metadatas: metadatas,
|
|
219
|
-
metadataToRecipient: metadataToRecipient,
|
|
220
|
-
errors: errors,
|
|
221
|
-
}];
|
|
48
|
+
async createMultiple(multipleStreamData, { senderWallet }) {
|
|
49
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
50
|
+
const totalFee = await this.getTotalFee({
|
|
51
|
+
address: multipleStreamData.partner ?? wallet.address,
|
|
52
|
+
});
|
|
53
|
+
const [txb, firstIndex] = await this.generateCreateBlock(wallet.address, multipleStreamData, totalFee);
|
|
54
|
+
const txs = [];
|
|
55
|
+
const metadatas = [];
|
|
56
|
+
const metadataToRecipient = {};
|
|
57
|
+
const errors = [];
|
|
58
|
+
try {
|
|
59
|
+
const { digest, events, effects } = await wallet.signAndExecuteTransactionBlock({
|
|
60
|
+
transactionBlock: txb,
|
|
61
|
+
options: { showEffects: true, showEvents: true },
|
|
62
|
+
});
|
|
63
|
+
txs.push(digest);
|
|
64
|
+
if (effects.status.status === "failure") {
|
|
65
|
+
multipleStreamData.recipients.forEach((recipient) => {
|
|
66
|
+
errors.push({
|
|
67
|
+
error: effects.status.error ?? "Unknown error!",
|
|
68
|
+
recipient: recipient.recipient,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
multipleStreamData.recipients.forEach((recipient, index) => {
|
|
74
|
+
const metadataId = events[index].parsedJson.address;
|
|
75
|
+
metadatas.push(metadataId);
|
|
76
|
+
metadataToRecipient[metadataId] = recipient;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
const errorInfo = (0, utils_js_1.extractSuiErrorInfo)(e.toString() ?? "Unknown error!");
|
|
82
|
+
multipleStreamData.recipients.forEach((recipient, index) => {
|
|
83
|
+
if (errorInfo.index === undefined ||
|
|
84
|
+
errorInfo.index < index + firstIndex ||
|
|
85
|
+
errorInfo.index >= multipleStreamData.recipients.length + firstIndex ||
|
|
86
|
+
errorInfo.index === index + firstIndex) {
|
|
87
|
+
errors.push({
|
|
88
|
+
error: errorInfo.text,
|
|
89
|
+
recipient: recipient.recipient,
|
|
90
|
+
contractErrorCode: errorInfo.parsed?.name,
|
|
91
|
+
});
|
|
222
92
|
}
|
|
223
93
|
});
|
|
224
|
-
}
|
|
225
|
-
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
txs,
|
|
97
|
+
metadatas,
|
|
98
|
+
metadataToRecipient,
|
|
99
|
+
errors,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
226
102
|
/**
|
|
227
103
|
* Attempts withdrawing from the specified stream.
|
|
228
104
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
typeArguments: [tokenId],
|
|
242
|
-
arguments: [
|
|
243
|
-
txb.object(id),
|
|
244
|
-
txb.object(this.configId),
|
|
245
|
-
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
246
|
-
txb.pure(amount.toString()),
|
|
247
|
-
],
|
|
248
|
-
});
|
|
249
|
-
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
250
|
-
transactionBlock: txb,
|
|
251
|
-
})];
|
|
252
|
-
case 1:
|
|
253
|
-
digest = (_d.sent()).digest;
|
|
254
|
-
return [2 /*return*/, {
|
|
255
|
-
ixs: [],
|
|
256
|
-
txId: digest,
|
|
257
|
-
}];
|
|
258
|
-
}
|
|
259
|
-
});
|
|
105
|
+
async withdraw({ id, amount = constants_js_2.WITHDRAW_AVAILABLE_AMOUNT }, { senderWallet, tokenId }) {
|
|
106
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
107
|
+
const txb = new transactions_1.TransactionBlock();
|
|
108
|
+
txb.moveCall({
|
|
109
|
+
target: `${this.programId}::protocol::withdraw`,
|
|
110
|
+
typeArguments: [tokenId],
|
|
111
|
+
arguments: [
|
|
112
|
+
txb.object(id),
|
|
113
|
+
txb.object(this.configId),
|
|
114
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
115
|
+
txb.pure(amount.toString()),
|
|
116
|
+
],
|
|
260
117
|
});
|
|
261
|
-
|
|
118
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
119
|
+
transactionBlock: txb,
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
ixs: [],
|
|
123
|
+
txId: digest,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
262
126
|
/**
|
|
263
127
|
* Attempts canceling the specified stream.
|
|
264
128
|
*/
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
273
|
-
txb = new transactions_1.TransactionBlock();
|
|
274
|
-
txb.moveCall({
|
|
275
|
-
target: "".concat(this.programId, "::protocol::cancel"),
|
|
276
|
-
typeArguments: [tokenId],
|
|
277
|
-
arguments: [txb.object(cancelData.id), txb.object(this.configId), txb.object(utils_1.SUI_CLOCK_OBJECT_ID)],
|
|
278
|
-
});
|
|
279
|
-
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
280
|
-
transactionBlock: txb,
|
|
281
|
-
})];
|
|
282
|
-
case 1:
|
|
283
|
-
digest = (_b.sent()).digest;
|
|
284
|
-
return [2 /*return*/, {
|
|
285
|
-
ixs: [],
|
|
286
|
-
txId: digest,
|
|
287
|
-
}];
|
|
288
|
-
}
|
|
289
|
-
});
|
|
129
|
+
async cancel(cancelData, { senderWallet, tokenId }) {
|
|
130
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
131
|
+
const txb = new transactions_1.TransactionBlock();
|
|
132
|
+
txb.moveCall({
|
|
133
|
+
target: `${this.programId}::protocol::cancel`,
|
|
134
|
+
typeArguments: [tokenId],
|
|
135
|
+
arguments: [txb.object(cancelData.id), txb.object(this.configId), txb.object(utils_1.SUI_CLOCK_OBJECT_ID)],
|
|
290
136
|
});
|
|
291
|
-
|
|
137
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
138
|
+
transactionBlock: txb,
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
ixs: [],
|
|
142
|
+
txId: digest,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
292
145
|
/**
|
|
293
146
|
* Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
|
|
294
147
|
*/
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
target: "".concat(this.programId, "::protocol::transfer"),
|
|
306
|
-
typeArguments: [tokenId],
|
|
307
|
-
arguments: [txb.object(transferData.id), txb.pure(transferData.newRecipient)],
|
|
308
|
-
});
|
|
309
|
-
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
310
|
-
transactionBlock: txb,
|
|
311
|
-
})];
|
|
312
|
-
case 1:
|
|
313
|
-
digest = (_b.sent()).digest;
|
|
314
|
-
return [2 /*return*/, {
|
|
315
|
-
ixs: [],
|
|
316
|
-
txId: digest,
|
|
317
|
-
}];
|
|
318
|
-
}
|
|
319
|
-
});
|
|
148
|
+
async transfer(transferData, { senderWallet, tokenId }) {
|
|
149
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
150
|
+
const txb = new transactions_1.TransactionBlock();
|
|
151
|
+
txb.moveCall({
|
|
152
|
+
target: `${this.programId}::protocol::transfer`,
|
|
153
|
+
typeArguments: [tokenId],
|
|
154
|
+
arguments: [txb.object(transferData.id), txb.pure(transferData.newRecipient)],
|
|
155
|
+
});
|
|
156
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
157
|
+
transactionBlock: txb,
|
|
320
158
|
});
|
|
321
|
-
|
|
159
|
+
return {
|
|
160
|
+
ixs: [],
|
|
161
|
+
txId: digest,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
322
164
|
/**
|
|
323
165
|
* Tops up stream account with specified amount.
|
|
324
166
|
*/
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
txb.object(topupData.id),
|
|
347
|
-
txb.object(this.configId),
|
|
348
|
-
coinObject,
|
|
349
|
-
txb.gas,
|
|
350
|
-
txb.pure(topupData.amount.toString()),
|
|
351
|
-
],
|
|
352
|
-
});
|
|
353
|
-
this.returnSplittedCoinObject(txb, tokenId, coins, coinObject);
|
|
354
|
-
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
355
|
-
transactionBlock: txb,
|
|
356
|
-
})];
|
|
357
|
-
case 3:
|
|
358
|
-
digest = (_b.sent()).digest;
|
|
359
|
-
return [2 /*return*/, {
|
|
360
|
-
ixs: [],
|
|
361
|
-
txId: digest,
|
|
362
|
-
}];
|
|
363
|
-
}
|
|
364
|
-
});
|
|
167
|
+
async topup(topupData, { senderWallet, tokenId }) {
|
|
168
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
169
|
+
const txb = new transactions_1.TransactionBlock();
|
|
170
|
+
const coins = await this.getAllCoins(wallet.address, tokenId);
|
|
171
|
+
const stream = await this.getOne({ id: topupData.id });
|
|
172
|
+
const totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
|
|
173
|
+
const coinObject = this.splitCoinObjectForAmount(txb, topupData.amount, tokenId, coins, totalFee);
|
|
174
|
+
txb.moveCall({
|
|
175
|
+
target: `${this.programId}::protocol::topup`,
|
|
176
|
+
typeArguments: [tokenId],
|
|
177
|
+
arguments: [
|
|
178
|
+
txb.object(topupData.id),
|
|
179
|
+
txb.object(this.configId),
|
|
180
|
+
coinObject,
|
|
181
|
+
txb.gas,
|
|
182
|
+
txb.pure(topupData.amount.toString()),
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
this.returnSplittedCoinObject(txb, tokenId, coins, coinObject);
|
|
186
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
187
|
+
transactionBlock: txb,
|
|
365
188
|
});
|
|
366
|
-
|
|
189
|
+
return {
|
|
190
|
+
ixs: [],
|
|
191
|
+
txId: digest,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
367
194
|
/**
|
|
368
195
|
* Fetch stream data by its id (address).
|
|
369
196
|
*/
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
case 0: return [4 /*yield*/, this.client.getObject({
|
|
377
|
-
id: id,
|
|
378
|
-
options: {
|
|
379
|
-
showContent: true,
|
|
380
|
-
},
|
|
381
|
-
})];
|
|
382
|
-
case 1:
|
|
383
|
-
response = _b.sent();
|
|
384
|
-
if (!response.data) {
|
|
385
|
-
throw new Error("Contract with id ".concat(id, " could not be found!"));
|
|
386
|
-
}
|
|
387
|
-
content = response.data.content;
|
|
388
|
-
if (content.dataType !== "moveObject") {
|
|
389
|
-
throw new Error("Not a Move Object!");
|
|
390
|
-
}
|
|
391
|
-
return [2 /*return*/, new types_js_2.Contract(content.fields, "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2::strmt::STRMT")];
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
});
|
|
395
|
-
};
|
|
396
|
-
SuiStreamClient.prototype.get = function () {
|
|
397
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
398
|
-
return __generator(this, function (_a) {
|
|
399
|
-
throw new Error("Get all method is not supported for Sui chain!");
|
|
400
|
-
});
|
|
197
|
+
async getOne({ id }) {
|
|
198
|
+
const response = await this.client.getObject({
|
|
199
|
+
id,
|
|
200
|
+
options: {
|
|
201
|
+
showContent: true,
|
|
202
|
+
},
|
|
401
203
|
});
|
|
402
|
-
|
|
204
|
+
if (!response.data) {
|
|
205
|
+
throw new Error(`Contract with id ${id} could not be found!`);
|
|
206
|
+
}
|
|
207
|
+
const content = response.data.content;
|
|
208
|
+
if (content.dataType !== "moveObject") {
|
|
209
|
+
throw new Error(`Not a Move Object!`);
|
|
210
|
+
}
|
|
211
|
+
return new types_js_2.Contract(content.fields, "0x97e9a9fb1392e9785319f5512d0bfde6ecf7757b09c6de41cec89e798dd361f2::strmt::STRMT");
|
|
212
|
+
}
|
|
213
|
+
async get() {
|
|
214
|
+
throw new Error("Get all method is not supported for Sui chain!");
|
|
215
|
+
}
|
|
403
216
|
/**
|
|
404
217
|
* Attempts updating the stream auto withdrawal params and amount per period
|
|
405
218
|
*/
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
422
|
-
txb.gas,
|
|
423
|
-
txb.pure(updateData.enableAutomaticWithdrawal !== undefined ? [updateData.enableAutomaticWithdrawal] : [], "vector<bool>"),
|
|
424
|
-
txb.pure(updateData.withdrawFrequency !== undefined ? [updateData.withdrawFrequency.toString()] : [], "vector<u64>"),
|
|
425
|
-
txb.pure(updateData.amountPerPeriod !== undefined ? [updateData.amountPerPeriod.toString()] : [], "vector<u64>"),
|
|
426
|
-
],
|
|
427
|
-
});
|
|
428
|
-
return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
|
|
429
|
-
transactionBlock: txb,
|
|
430
|
-
})];
|
|
431
|
-
case 1:
|
|
432
|
-
digest = (_b.sent()).digest;
|
|
433
|
-
return [2 /*return*/, {
|
|
434
|
-
ixs: [],
|
|
435
|
-
txId: digest,
|
|
436
|
-
}];
|
|
437
|
-
}
|
|
438
|
-
});
|
|
219
|
+
async update(updateData, { senderWallet, tokenId }) {
|
|
220
|
+
const wallet = new wallet_js_1.SuiWalletWrapper(senderWallet, this.client);
|
|
221
|
+
const txb = new transactions_1.TransactionBlock();
|
|
222
|
+
txb.moveCall({
|
|
223
|
+
target: `${this.programId}::protocol::update`,
|
|
224
|
+
typeArguments: [tokenId],
|
|
225
|
+
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>"),
|
|
233
|
+
],
|
|
439
234
|
});
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
var _a, _b;
|
|
443
|
-
var errorInfo = (0, utils_js_1.extractSuiErrorInfo)((_a = err.toString()) !== null && _a !== void 0 ? _a : "Unknown error!");
|
|
444
|
-
return ((_b = errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.parsed) === null || _b === void 0 ? void 0 : _b.name) || null;
|
|
445
|
-
};
|
|
446
|
-
SuiStreamClient.prototype.getFees = function (_a) {
|
|
447
|
-
var address = _a.address;
|
|
448
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
449
|
-
var response, content, fields, fieldsResponse, partnerDynamicField, valueResponse, valueContent, valueFields;
|
|
450
|
-
return __generator(this, function (_b) {
|
|
451
|
-
switch (_b.label) {
|
|
452
|
-
case 0: return [4 /*yield*/, this.client.getObject({
|
|
453
|
-
id: this.feeTableId,
|
|
454
|
-
options: {
|
|
455
|
-
showContent: true,
|
|
456
|
-
},
|
|
457
|
-
})];
|
|
458
|
-
case 1:
|
|
459
|
-
response = _b.sent();
|
|
460
|
-
content = response.data.content;
|
|
461
|
-
if (content.dataType !== "moveObject") {
|
|
462
|
-
throw new Error("Not a Move Object!");
|
|
463
|
-
}
|
|
464
|
-
fields = content.fields;
|
|
465
|
-
return [4 /*yield*/, this.client.getDynamicFields({
|
|
466
|
-
parentId: fields.values.fields.id.id,
|
|
467
|
-
})];
|
|
468
|
-
case 2:
|
|
469
|
-
fieldsResponse = _b.sent();
|
|
470
|
-
partnerDynamicField = fieldsResponse.data.filter(function (item) { return item.name.value === address; })[0];
|
|
471
|
-
if (!partnerDynamicField) {
|
|
472
|
-
return [2 /*return*/, null];
|
|
473
|
-
}
|
|
474
|
-
return [4 /*yield*/, this.client.getObject({
|
|
475
|
-
id: partnerDynamicField.objectId,
|
|
476
|
-
options: {
|
|
477
|
-
showContent: true,
|
|
478
|
-
},
|
|
479
|
-
})];
|
|
480
|
-
case 3:
|
|
481
|
-
valueResponse = _b.sent();
|
|
482
|
-
valueContent = valueResponse.data.content;
|
|
483
|
-
if (valueContent.dataType !== "moveObject") {
|
|
484
|
-
throw new Error("Not a Move Object!");
|
|
485
|
-
}
|
|
486
|
-
valueFields = valueContent.fields.value.fields;
|
|
487
|
-
return [2 /*return*/, {
|
|
488
|
-
streamflowFee: Number(valueFields.streamflow_fee) / 100,
|
|
489
|
-
partnerFee: Number(valueFields.partner_fee) / 100,
|
|
490
|
-
}];
|
|
491
|
-
}
|
|
492
|
-
});
|
|
235
|
+
const { digest } = await wallet.signAndExecuteTransactionBlock({
|
|
236
|
+
transactionBlock: txb,
|
|
493
237
|
});
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
238
|
+
return {
|
|
239
|
+
ixs: [],
|
|
240
|
+
txId: digest,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
extractErrorCode(err) {
|
|
244
|
+
const errorInfo = (0, utils_js_1.extractSuiErrorInfo)(err.toString() ?? "Unknown error!");
|
|
245
|
+
return errorInfo?.parsed?.name || null;
|
|
246
|
+
}
|
|
247
|
+
async getFees({ address }) {
|
|
248
|
+
const response = await this.client.getObject({
|
|
249
|
+
id: this.feeTableId,
|
|
250
|
+
options: {
|
|
251
|
+
showContent: true,
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
const content = response.data.content;
|
|
255
|
+
if (content.dataType !== "moveObject") {
|
|
256
|
+
throw new Error(`Not a Move Object!`);
|
|
257
|
+
}
|
|
258
|
+
const fields = content.fields;
|
|
259
|
+
const fieldsResponse = await this.client.getDynamicFields({
|
|
260
|
+
parentId: fields.values.fields.id.id,
|
|
516
261
|
});
|
|
517
|
-
|
|
262
|
+
const partnerDynamicField = fieldsResponse.data.filter((item) => item.name.value === address)[0];
|
|
263
|
+
if (!partnerDynamicField) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
const valueResponse = await this.client.getObject({
|
|
267
|
+
id: partnerDynamicField.objectId,
|
|
268
|
+
options: {
|
|
269
|
+
showContent: true,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
const valueContent = valueResponse.data.content;
|
|
273
|
+
if (valueContent.dataType !== "moveObject") {
|
|
274
|
+
throw new Error(`Not a Move Object!`);
|
|
275
|
+
}
|
|
276
|
+
const valueFields = valueContent.fields.value.fields;
|
|
277
|
+
return {
|
|
278
|
+
streamflowFee: Number(valueFields.streamflow_fee) / 100,
|
|
279
|
+
partnerFee: Number(valueFields.partner_fee) / 100,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
async getDefaultStreamflowFee() {
|
|
283
|
+
const response = await this.client.getObject({
|
|
284
|
+
id: this.configId,
|
|
285
|
+
options: {
|
|
286
|
+
showContent: true,
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
const content = response.data.content;
|
|
290
|
+
if (content.dataType !== "moveObject") {
|
|
291
|
+
throw new Error(`Not a Move Object!`);
|
|
292
|
+
}
|
|
293
|
+
const fields = content.fields;
|
|
294
|
+
return Number(fields.streamflow_fee) / 100;
|
|
295
|
+
}
|
|
518
296
|
/**
|
|
519
297
|
* Returns StreamClient protocol program ID.
|
|
520
298
|
*/
|
|
521
|
-
|
|
299
|
+
getProgramId() {
|
|
522
300
|
return this.programId;
|
|
523
|
-
}
|
|
301
|
+
}
|
|
524
302
|
/**
|
|
525
303
|
* Utility function to generate Transaction Block to create streams
|
|
526
304
|
*/
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
txb.pure(!!multipleStreamData.canUpdateRate),
|
|
565
|
-
txb.pure(!!multipleStreamData.automaticWithdrawal),
|
|
566
|
-
txb.pure(multipleStreamData.withdrawalFrequency || 0),
|
|
567
|
-
txb.pure(recipient.name),
|
|
568
|
-
txb.pure(recipient.recipient),
|
|
569
|
-
txb.pure(multipleStreamData.partner || walletAddress),
|
|
570
|
-
],
|
|
571
|
-
});
|
|
572
|
-
if (result.kind === "Result" && firstIndex === null) {
|
|
573
|
-
firstIndex = result.index;
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
this.returnSplittedCoinObject(txb, multipleStreamData.tokenId, coins, coinObject);
|
|
577
|
-
return [2 /*return*/, [txb, firstIndex]];
|
|
578
|
-
}
|
|
305
|
+
async generateCreateBlock(walletAddress, multipleStreamData, totalFee) {
|
|
306
|
+
let coins = await this.getAllCoins(walletAddress, multipleStreamData.tokenId);
|
|
307
|
+
const totalAmount = multipleStreamData.recipients
|
|
308
|
+
.map((recipiient) => recipiient.amount)
|
|
309
|
+
.reduce((prev, current) => current.plus(prev));
|
|
310
|
+
const txb = new transactions_1.TransactionBlock();
|
|
311
|
+
const coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
|
|
312
|
+
coins = [coins[0]];
|
|
313
|
+
let firstIndex = null;
|
|
314
|
+
multipleStreamData.recipients.forEach((recipient) => {
|
|
315
|
+
const result = txb.moveCall({
|
|
316
|
+
target: `${this.programId}::protocol::create`,
|
|
317
|
+
typeArguments: [multipleStreamData.tokenId],
|
|
318
|
+
arguments: [
|
|
319
|
+
txb.object(this.configId),
|
|
320
|
+
txb.object(this.feeTableId),
|
|
321
|
+
txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
322
|
+
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),
|
|
341
|
+
],
|
|
579
342
|
});
|
|
343
|
+
if (result.kind === "Result" && firstIndex === null) {
|
|
344
|
+
firstIndex = result.index;
|
|
345
|
+
}
|
|
580
346
|
});
|
|
581
|
-
|
|
347
|
+
this.returnSplittedCoinObject(txb, multipleStreamData.tokenId, coins, coinObject);
|
|
348
|
+
return [txb, firstIndex];
|
|
349
|
+
}
|
|
582
350
|
/**
|
|
583
351
|
* Returns all coins owned by a Wallet
|
|
584
352
|
* @param walletAddress wallet address
|
|
585
353
|
* @param coinType coin type
|
|
586
354
|
* @returns Array of Coin Structs
|
|
587
355
|
*/
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
switch (_a.label) {
|
|
593
|
-
case 0: return [4 /*yield*/, this.client.getCoins({
|
|
594
|
-
owner: walletAddress,
|
|
595
|
-
coinType: coinType,
|
|
596
|
-
})];
|
|
597
|
-
case 1:
|
|
598
|
-
coinsResponse = _a.sent();
|
|
599
|
-
coins = coinsResponse.data;
|
|
600
|
-
_a.label = 2;
|
|
601
|
-
case 2:
|
|
602
|
-
if (!coinsResponse.hasNextPage) return [3 /*break*/, 4];
|
|
603
|
-
return [4 /*yield*/, this.client.getCoins({
|
|
604
|
-
owner: walletAddress,
|
|
605
|
-
coinType: coinType,
|
|
606
|
-
cursor: coinsResponse.nextCursor,
|
|
607
|
-
})];
|
|
608
|
-
case 3:
|
|
609
|
-
coinsResponse = _a.sent();
|
|
610
|
-
coins.push.apply(coins, __spreadArray([], __read(coinsResponse.data), false));
|
|
611
|
-
return [3 /*break*/, 2];
|
|
612
|
-
case 4: return [2 /*return*/, coins];
|
|
613
|
-
}
|
|
614
|
-
});
|
|
356
|
+
async getAllCoins(walletAddress, coinType) {
|
|
357
|
+
let coinsResponse = await this.client.getCoins({
|
|
358
|
+
owner: walletAddress,
|
|
359
|
+
coinType: coinType,
|
|
615
360
|
});
|
|
616
|
-
|
|
361
|
+
const coins = coinsResponse.data;
|
|
362
|
+
while (coinsResponse.hasNextPage) {
|
|
363
|
+
coinsResponse = await this.client.getCoins({
|
|
364
|
+
owner: walletAddress,
|
|
365
|
+
coinType: coinType,
|
|
366
|
+
cursor: coinsResponse.nextCursor,
|
|
367
|
+
});
|
|
368
|
+
coins.push(...coinsResponse.data);
|
|
369
|
+
}
|
|
370
|
+
return coins;
|
|
371
|
+
}
|
|
617
372
|
/**
|
|
618
373
|
* Utility function to split Coin object and use splitted object for stream operations.
|
|
619
374
|
* We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
|
|
@@ -624,14 +379,14 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
624
379
|
* @param coins array of owned coins of the same type
|
|
625
380
|
* @returns Coin Object to use in a Move Call
|
|
626
381
|
*/
|
|
627
|
-
|
|
628
|
-
|
|
382
|
+
splitCoinObjectForAmount(txb, amount, coinType, coins, totalFee) {
|
|
383
|
+
const coinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
629
384
|
if (coins.length > 1) {
|
|
630
|
-
txb.mergeCoins(coinObject, coins.slice(1).map(
|
|
385
|
+
txb.mergeCoins(coinObject, coins.slice(1).map((item) => txb.object(item.coinObjectId)));
|
|
631
386
|
}
|
|
632
|
-
|
|
387
|
+
const totalAmount = (0, utils_js_2.calculateTotalAmountToDeposit)(amount, totalFee);
|
|
633
388
|
return txb.splitCoins(coinObject, [txb.pure(totalAmount.toString())])[0];
|
|
634
|
-
}
|
|
389
|
+
}
|
|
635
390
|
/**
|
|
636
391
|
* Return previously splitted Coin Object to owner and merge it to to rebate storage fees
|
|
637
392
|
* @param txb current transanction block
|
|
@@ -639,10 +394,9 @@ var SuiStreamClient = /** @class */ (function (_super) {
|
|
|
639
394
|
* @param coinObject splitted object
|
|
640
395
|
* @param coins array of objects used in
|
|
641
396
|
*/
|
|
642
|
-
|
|
643
|
-
|
|
397
|
+
returnSplittedCoinObject(txb, coinType, coins, coinObject) {
|
|
398
|
+
const firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
|
|
644
399
|
txb.mergeCoins(firstCoinObject, [coinObject]);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
}(BaseStreamClient_js_1.BaseStreamClient));
|
|
400
|
+
}
|
|
401
|
+
}
|
|
648
402
|
exports.default = SuiStreamClient;
|