@streamflow/stream 6.5.0 → 7.0.0-alpha.10

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.
Files changed (137) hide show
  1. package/README.md +17 -22
  2. package/dist/cjs/__tests__/aptos/streamClient.spec.js +111 -0
  3. package/dist/cjs/__tests__/common/GenericStreamClient.spec.js +45 -0
  4. package/dist/cjs/aptos/StreamClient.js +226 -0
  5. package/dist/cjs/aptos/constants.js +27 -0
  6. package/dist/{aptos → cjs/aptos}/index.js +6 -6
  7. package/dist/cjs/aptos/types.js +69 -0
  8. package/dist/{aptos → cjs/aptos}/utils.js +4 -4
  9. package/dist/cjs/aptos/wallet.js +34 -0
  10. package/dist/cjs/common/BaseStreamClient.js +23 -0
  11. package/dist/cjs/common/GenericStreamClient.js +102 -0
  12. package/dist/{common → cjs/common}/constants.js +2 -2
  13. package/dist/{common → cjs/common}/contractUtils.js +19 -20
  14. package/dist/cjs/common/utils.js +66 -0
  15. package/dist/cjs/evm/StreamClient.js +238 -0
  16. package/dist/cjs/evm/constants.js +38 -0
  17. package/dist/{evm → cjs/evm}/index.js +8 -8
  18. package/dist/{evm → cjs/evm}/types.js +26 -35
  19. package/dist/{evm → cjs/evm}/utils.js +2 -2
  20. package/dist/{index.js → cjs/index.js} +10 -10
  21. package/dist/cjs/solana/StreamClient.js +737 -0
  22. package/dist/{solana → cjs/solana}/constants.js +33 -33
  23. package/dist/cjs/solana/index.js +39 -0
  24. package/dist/{solana → cjs/solana}/instructions.js +83 -83
  25. package/dist/{solana → cjs/solana}/layout.js +8 -9
  26. package/dist/{solana → cjs/solana}/types.js +16 -26
  27. package/dist/cjs/solana/utils.js +134 -0
  28. package/dist/cjs/sui/StreamClient.js +402 -0
  29. package/dist/cjs/sui/constants.js +42 -0
  30. package/dist/{sui → cjs/sui}/index.js +5 -5
  31. package/dist/cjs/sui/types.js +68 -0
  32. package/dist/{sui → cjs/sui}/utils.js +7 -7
  33. package/dist/cjs/sui/wallet.js +40 -0
  34. package/dist/esm/__tests__/aptos/streamClient.spec.js +106 -0
  35. package/dist/esm/__tests__/common/GenericStreamClient.spec.js +40 -0
  36. package/dist/{aptos → esm/aptos}/StreamClient.d.ts +3 -3
  37. package/dist/esm/aptos/StreamClient.js +226 -0
  38. package/dist/{aptos → esm/aptos}/constants.d.ts +1 -1
  39. package/dist/esm/aptos/constants.js +24 -0
  40. package/dist/esm/aptos/index.d.ts +4 -0
  41. package/dist/esm/aptos/index.js +4 -0
  42. package/dist/{aptos → esm/aptos}/types.d.ts +13 -13
  43. package/dist/esm/aptos/types.js +105 -0
  44. package/dist/esm/aptos/utils.js +30 -0
  45. package/dist/esm/aptos/wallet.js +33 -0
  46. package/dist/{common → esm/common}/BaseStreamClient.d.ts +1 -1
  47. package/dist/esm/common/BaseStreamClient.js +19 -0
  48. package/dist/{common → esm/common}/GenericStreamClient.d.ts +6 -6
  49. package/dist/esm/common/GenericStreamClient.js +101 -0
  50. package/dist/esm/common/constants.d.ts +3 -0
  51. package/dist/esm/common/constants.js +3 -0
  52. package/dist/{common → esm/common}/contractUtils.d.ts +15 -15
  53. package/dist/esm/common/contractUtils.js +42 -0
  54. package/dist/{common → esm/common}/types.d.ts +19 -19
  55. package/dist/esm/common/types.js +106 -0
  56. package/dist/{common → esm/common}/utils.d.ts +11 -12
  57. package/dist/esm/common/utils.js +56 -0
  58. package/dist/{evm → esm/evm}/StreamClient.d.ts +4 -4
  59. package/dist/esm/evm/StreamClient.js +237 -0
  60. package/dist/esm/evm/abi.js +1255 -0
  61. package/dist/{evm → esm/evm}/constants.d.ts +1 -1
  62. package/dist/esm/evm/constants.js +35 -0
  63. package/dist/esm/evm/ercAbi.js +222 -0
  64. package/dist/esm/evm/index.d.ts +5 -0
  65. package/dist/esm/evm/index.js +5 -0
  66. package/dist/{evm → esm/evm}/types.d.ts +38 -38
  67. package/dist/esm/evm/types.js +102 -0
  68. package/dist/esm/evm/utils.js +8 -0
  69. package/dist/esm/index.d.ts +9 -0
  70. package/dist/esm/index.js +9 -0
  71. package/dist/{solana → esm/solana}/StreamClient.d.ts +4 -4
  72. package/dist/esm/solana/StreamClient.js +711 -0
  73. package/dist/{solana → esm/solana}/constants.d.ts +3 -1
  74. package/dist/esm/solana/constants.js +62 -0
  75. package/dist/esm/solana/index.d.ts +6 -0
  76. package/dist/esm/solana/index.js +6 -0
  77. package/dist/esm/solana/instructionTypes.js +1 -0
  78. package/dist/{solana → esm/solana}/instructions.d.ts +18 -18
  79. package/dist/esm/solana/instructions.js +257 -0
  80. package/dist/{solana → esm/solana}/layout.d.ts +2 -1
  81. package/dist/esm/solana/layout.js +155 -0
  82. package/dist/esm/solana/timelockIDL.js +420 -0
  83. package/dist/{solana → esm/solana}/types.d.ts +38 -37
  84. package/dist/esm/solana/types.js +101 -0
  85. package/dist/{solana → esm/solana}/utils.d.ts +4 -1
  86. package/dist/esm/solana/utils.js +123 -0
  87. package/dist/{sui → esm/sui}/StreamClient.d.ts +3 -3
  88. package/dist/esm/sui/StreamClient.js +403 -0
  89. package/dist/{sui → esm/sui}/constants.d.ts +1 -1
  90. package/dist/esm/sui/constants.js +39 -0
  91. package/dist/esm/sui/index.d.ts +4 -0
  92. package/dist/esm/sui/index.js +4 -0
  93. package/dist/{sui → esm/sui}/types.d.ts +13 -13
  94. package/dist/esm/sui/types.js +104 -0
  95. package/dist/{sui → esm/sui}/utils.d.ts +1 -1
  96. package/dist/esm/sui/utils.js +23 -0
  97. package/dist/{sui → esm/sui}/wallet.d.ts +1 -1
  98. package/dist/esm/sui/wallet.js +38 -0
  99. package/package.json +37 -35
  100. package/dist/__tests__/aptos/streamClient.spec.js +0 -161
  101. package/dist/__tests__/common/GenericStreamClient.spec.js +0 -44
  102. package/dist/aptos/StreamClient.js +0 -431
  103. package/dist/aptos/constants.js +0 -28
  104. package/dist/aptos/index.d.ts +0 -4
  105. package/dist/aptos/types.js +0 -77
  106. package/dist/aptos/wallet.js +0 -89
  107. package/dist/common/BaseStreamClient.js +0 -71
  108. package/dist/common/GenericStreamClient.js +0 -128
  109. package/dist/common/constants.d.ts +0 -3
  110. package/dist/common/utils.js +0 -118
  111. package/dist/evm/StreamClient.js +0 -496
  112. package/dist/evm/constants.js +0 -39
  113. package/dist/evm/index.d.ts +0 -5
  114. package/dist/index.d.ts +0 -9
  115. package/dist/solana/StreamClient.js +0 -1253
  116. package/dist/solana/index.d.ts +0 -7
  117. package/dist/solana/index.js +0 -43
  118. package/dist/solana/utils.js +0 -211
  119. package/dist/sui/StreamClient.js +0 -648
  120. package/dist/sui/constants.js +0 -43
  121. package/dist/sui/index.d.ts +0 -4
  122. package/dist/sui/types.js +0 -102
  123. package/dist/sui/wallet.js +0 -90
  124. /package/dist/{common → cjs/common}/types.js +0 -0
  125. /package/dist/{evm → cjs/evm}/abi.js +0 -0
  126. /package/dist/{evm → cjs/evm}/ercAbi.js +0 -0
  127. /package/dist/{solana → cjs/solana}/instructionTypes.js +0 -0
  128. /package/dist/{solana → cjs/solana}/timelockIDL.js +0 -0
  129. /package/dist/{__tests__ → esm/__tests__}/aptos/streamClient.spec.d.ts +0 -0
  130. /package/dist/{__tests__ → esm/__tests__}/common/GenericStreamClient.spec.d.ts +0 -0
  131. /package/dist/{aptos → esm/aptos}/utils.d.ts +0 -0
  132. /package/dist/{aptos → esm/aptos}/wallet.d.ts +0 -0
  133. /package/dist/{evm → esm/evm}/abi.d.ts +0 -0
  134. /package/dist/{evm → esm/evm}/ercAbi.d.ts +0 -0
  135. /package/dist/{evm → esm/evm}/utils.d.ts +0 -0
  136. /package/dist/{solana → esm/solana}/instructionTypes.d.ts +0 -0
  137. /package/dist/{solana → esm/solana}/timelockIDL.d.ts +0 -0
@@ -1,648 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
90
- var client_1 = require("@mysten/sui.js/client");
91
- var transactions_1 = require("@mysten/sui.js/transactions");
92
- var utils_1 = require("@mysten/sui.js/utils");
93
- var BaseStreamClient_1 = require("../common/BaseStreamClient");
94
- var types_1 = require("../common/types");
95
- var constants_1 = require("./constants");
96
- var types_2 = require("./types");
97
- var utils_2 = require("./utils");
98
- var wallet_1 = require("./wallet");
99
- var utils_3 = require("../common/utils");
100
- var constants_2 = require("../common/constants");
101
- var SuiStreamClient = /** @class */ (function (_super) {
102
- __extends(SuiStreamClient, _super);
103
- function SuiStreamClient(clusterUrl, cluster, ids) {
104
- if (cluster === void 0) { cluster = types_1.ICluster.Mainnet; }
105
- var _this = _super.call(this) || this;
106
- _this.programId = (ids === null || ids === void 0 ? void 0 : ids.program) ? ids.program : constants_1.SUI_PROGRAM_IDS[cluster];
107
- _this.configId = (ids === null || ids === void 0 ? void 0 : ids.config) ? ids.config : constants_1.SUI_CONFIG_IDS[cluster];
108
- _this.feeTableId = (ids === null || ids === void 0 ? void 0 : ids.feeTable) ? ids.feeTable : constants_1.SUI_FEE_TABLE_IDS[cluster];
109
- _this.client = new client_1.SuiClient({ url: clusterUrl });
110
- return _this;
111
- }
112
- /**
113
- * Creates a new stream/vesting contract.
114
- */
115
- SuiStreamClient.prototype.create = function (streamData, _a) {
116
- var _b;
117
- var senderWallet = _a.senderWallet;
118
- return __awaiter(this, void 0, void 0, function () {
119
- var wallet, totalFee, _c, txb, _d, digest, events;
120
- return __generator(this, function (_e) {
121
- switch (_e.label) {
122
- case 0:
123
- wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
124
- return [4 /*yield*/, this.getTotalFee({
125
- address: (_b = streamData.partner) !== null && _b !== void 0 ? _b : wallet.address,
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
- });
145
- });
146
- };
147
- /**
148
- * Creates multiple stream/vesting contracts.
149
- * We don't chain transactions in one Block so that one failed transaction does not revert all others.
150
- */
151
- SuiStreamClient.prototype.createMultiple = function (multipleStreamData, _a) {
152
- var _b, _c;
153
- var senderWallet = _a.senderWallet;
154
- return __awaiter(this, void 0, void 0, function () {
155
- var wallet, totalFee, _d, txb, firstIndex, txs, metadatas, metadataToRecipient, errors, _e, digest, events_1, effects_1, e_1, errorInfo_1;
156
- return __generator(this, function (_f) {
157
- switch (_f.label) {
158
- case 0:
159
- wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
160
- return [4 /*yield*/, this.getTotalFee({
161
- address: (_b = multipleStreamData.partner) !== null && _b !== void 0 ? _b : wallet.address,
162
- })];
163
- case 1:
164
- totalFee = _f.sent();
165
- return [4 /*yield*/, this.generateCreateBlock(wallet.address, multipleStreamData, totalFee)];
166
- case 2:
167
- _d = __read.apply(void 0, [_f.sent(), 2]), txb = _d[0], firstIndex = _d[1];
168
- txs = [];
169
- metadatas = [];
170
- metadataToRecipient = {};
171
- errors = [];
172
- _f.label = 3;
173
- case 3:
174
- _f.trys.push([3, 5, , 6]);
175
- return [4 /*yield*/, wallet.signAndExecuteTransactionBlock({
176
- transactionBlock: txb,
177
- options: { showEffects: true, showEvents: true },
178
- })];
179
- case 4:
180
- _e = _f.sent(), digest = _e.digest, events_1 = _e.events, effects_1 = _e.effects;
181
- txs.push(digest);
182
- if (effects_1.status.status === "failure") {
183
- multipleStreamData.recipients.forEach(function (recipient) {
184
- var _a;
185
- errors.push({
186
- error: (_a = effects_1.status.error) !== null && _a !== void 0 ? _a : "Unknown error!",
187
- recipient: recipient.recipient,
188
- });
189
- });
190
- }
191
- else {
192
- multipleStreamData.recipients.forEach(function (recipient, index) {
193
- var metadataId = events_1[index].parsedJson.address;
194
- metadatas.push(metadataId);
195
- metadataToRecipient[metadataId] = recipient;
196
- });
197
- }
198
- return [3 /*break*/, 6];
199
- case 5:
200
- e_1 = _f.sent();
201
- errorInfo_1 = (0, utils_2.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
- }];
222
- }
223
- });
224
- });
225
- };
226
- /**
227
- * Attempts withdrawing from the specified stream.
228
- */
229
- SuiStreamClient.prototype.withdraw = function (_a, _b) {
230
- var id = _a.id, _c = _a.amount, amount = _c === void 0 ? constants_2.WITHDRAW_AVAILABLE_AMOUNT : _c;
231
- var senderWallet = _b.senderWallet, tokenId = _b.tokenId;
232
- return __awaiter(this, void 0, void 0, function () {
233
- var wallet, txb, digest;
234
- return __generator(this, function (_d) {
235
- switch (_d.label) {
236
- case 0:
237
- wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
238
- txb = new transactions_1.TransactionBlock();
239
- txb.moveCall({
240
- target: "".concat(this.programId, "::protocol::withdraw"),
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
- });
260
- });
261
- };
262
- /**
263
- * Attempts canceling the specified stream.
264
- */
265
- SuiStreamClient.prototype.cancel = function (cancelData, _a) {
266
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
267
- return __awaiter(this, void 0, void 0, function () {
268
- var wallet, txb, digest;
269
- return __generator(this, function (_b) {
270
- switch (_b.label) {
271
- case 0:
272
- wallet = new wallet_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
- });
290
- });
291
- };
292
- /**
293
- * Attempts changing the stream/vesting contract's recipient (effectively transferring the stream/vesting contract).
294
- */
295
- SuiStreamClient.prototype.transfer = function (transferData, _a) {
296
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
297
- return __awaiter(this, void 0, void 0, function () {
298
- var wallet, txb, digest;
299
- return __generator(this, function (_b) {
300
- switch (_b.label) {
301
- case 0:
302
- wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
303
- txb = new transactions_1.TransactionBlock();
304
- txb.moveCall({
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
- });
320
- });
321
- };
322
- /**
323
- * Tops up stream account with specified amount.
324
- */
325
- SuiStreamClient.prototype.topup = function (topupData, _a) {
326
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
327
- return __awaiter(this, void 0, void 0, function () {
328
- var wallet, txb, coins, stream, totalFee, coinObject, digest;
329
- return __generator(this, function (_b) {
330
- switch (_b.label) {
331
- case 0:
332
- wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
333
- txb = new transactions_1.TransactionBlock();
334
- return [4 /*yield*/, this.getAllCoins(wallet.address, tokenId)];
335
- case 1:
336
- coins = _b.sent();
337
- return [4 /*yield*/, this.getOne({ id: topupData.id })];
338
- case 2:
339
- stream = _b.sent();
340
- totalFee = (stream.partnerFeePercent + stream.streamflowFeePercent) / 100;
341
- coinObject = this.splitCoinObjectForAmount(txb, topupData.amount, tokenId, coins, totalFee);
342
- txb.moveCall({
343
- target: "".concat(this.programId, "::protocol::topup"),
344
- typeArguments: [tokenId],
345
- arguments: [
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
- });
365
- });
366
- };
367
- /**
368
- * Fetch stream data by its id (address).
369
- */
370
- SuiStreamClient.prototype.getOne = function (_a) {
371
- var id = _a.id;
372
- return __awaiter(this, void 0, void 0, function () {
373
- var response, content;
374
- return __generator(this, function (_b) {
375
- switch (_b.label) {
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_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
- });
401
- });
402
- };
403
- /**
404
- * Attempts updating the stream auto withdrawal params and amount per period
405
- */
406
- SuiStreamClient.prototype.update = function (updateData, _a) {
407
- var senderWallet = _a.senderWallet, tokenId = _a.tokenId;
408
- return __awaiter(this, void 0, void 0, function () {
409
- var wallet, txb, digest;
410
- return __generator(this, function (_b) {
411
- switch (_b.label) {
412
- case 0:
413
- wallet = new wallet_1.SuiWalletWrapper(senderWallet, this.client);
414
- txb = new transactions_1.TransactionBlock();
415
- txb.moveCall({
416
- target: "".concat(this.programId, "::protocol::update"),
417
- typeArguments: [tokenId],
418
- arguments: [
419
- txb.object(updateData.id),
420
- txb.object(this.configId),
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
- });
439
- });
440
- };
441
- SuiStreamClient.prototype.extractErrorCode = function (err) {
442
- var _a, _b;
443
- var errorInfo = (0, utils_2.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
- });
493
- });
494
- };
495
- SuiStreamClient.prototype.getDefaultStreamflowFee = function () {
496
- return __awaiter(this, void 0, void 0, function () {
497
- var response, content, fields;
498
- return __generator(this, function (_a) {
499
- switch (_a.label) {
500
- case 0: return [4 /*yield*/, this.client.getObject({
501
- id: this.configId,
502
- options: {
503
- showContent: true,
504
- },
505
- })];
506
- case 1:
507
- response = _a.sent();
508
- content = response.data.content;
509
- if (content.dataType !== "moveObject") {
510
- throw new Error("Not a Move Object!");
511
- }
512
- fields = content.fields;
513
- return [2 /*return*/, Number(fields.streamflow_fee) / 100];
514
- }
515
- });
516
- });
517
- };
518
- /**
519
- * Returns StreamClient protocol program ID.
520
- */
521
- SuiStreamClient.prototype.getProgramId = function () {
522
- return this.programId;
523
- };
524
- /**
525
- * Utility function to generate Transaction Block to create streams
526
- */
527
- SuiStreamClient.prototype.generateCreateBlock = function (walletAddress, multipleStreamData, totalFee) {
528
- return __awaiter(this, void 0, void 0, function () {
529
- var coins, totalAmount, txb, coinObject, firstIndex;
530
- var _this = this;
531
- return __generator(this, function (_a) {
532
- switch (_a.label) {
533
- case 0: return [4 /*yield*/, this.getAllCoins(walletAddress, multipleStreamData.tokenId)];
534
- case 1:
535
- coins = _a.sent();
536
- totalAmount = multipleStreamData.recipients
537
- .map(function (recipiient) { return recipiient.amount; })
538
- .reduce(function (prev, current) { return current.add(prev); });
539
- txb = new transactions_1.TransactionBlock();
540
- coinObject = this.splitCoinObjectForAmount(txb, totalAmount, multipleStreamData.tokenId, coins, totalFee);
541
- coins = [coins[0]];
542
- firstIndex = null;
543
- multipleStreamData.recipients.forEach(function (recipient) {
544
- var result = txb.moveCall({
545
- target: "".concat(_this.programId, "::protocol::create"),
546
- typeArguments: [multipleStreamData.tokenId],
547
- arguments: [
548
- txb.object(_this.configId),
549
- txb.object(_this.feeTableId),
550
- txb.object(utils_1.SUI_CLOCK_OBJECT_ID),
551
- coinObject,
552
- txb.gas,
553
- txb.pure(recipient.amount.toString()),
554
- txb.pure(multipleStreamData.period),
555
- txb.pure(recipient.amountPerPeriod.toString()),
556
- txb.pure(multipleStreamData.start),
557
- txb.pure(recipient.cliffAmount.toString()),
558
- txb.pure(multipleStreamData.cancelableBySender),
559
- txb.pure(multipleStreamData.cancelableByRecipient),
560
- txb.pure(multipleStreamData.transferableBySender),
561
- txb.pure(multipleStreamData.transferableByRecipient),
562
- txb.pure(multipleStreamData.canTopup),
563
- txb.pure(!!multipleStreamData.canPause),
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
- }
579
- });
580
- });
581
- };
582
- /**
583
- * Returns all coins owned by a Wallet
584
- * @param walletAddress wallet address
585
- * @param coinType coin type
586
- * @returns Array of Coin Structs
587
- */
588
- SuiStreamClient.prototype.getAllCoins = function (walletAddress, coinType) {
589
- return __awaiter(this, void 0, void 0, function () {
590
- var coinsResponse, coins;
591
- return __generator(this, function (_a) {
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
- });
615
- });
616
- };
617
- /**
618
- * Utility function to split Coin object and use splitted object for stream operations.
619
- * We do it like thid to mitigate risk of Transaction reverting in case Stream is created for Sui Coin object.
620
- * This way we can safely pass splitted Sui Coin object in Stream payload and use another object for gas/withdrawal fees.
621
- * @param txb current transanction block
622
- * @param amount minimal amount of coins requried
623
- * @param coinType coin type
624
- * @param coins array of owned coins of the same type
625
- * @returns Coin Object to use in a Move Call
626
- */
627
- SuiStreamClient.prototype.splitCoinObjectForAmount = function (txb, amount, coinType, coins, totalFee) {
628
- var coinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
629
- if (coins.length > 1) {
630
- txb.mergeCoins(coinObject, coins.slice(1).map(function (item) { return txb.object(item.coinObjectId); }));
631
- }
632
- var totalAmount = (0, utils_3.calculateTotalAmountToDeposit)(amount, totalFee);
633
- return txb.splitCoins(coinObject, [txb.pure(totalAmount.toString())])[0];
634
- };
635
- /**
636
- * Return previously splitted Coin Object to owner and merge it to to rebate storage fees
637
- * @param txb current transanction block
638
- * @param coinType coin type
639
- * @param coinObject splitted object
640
- * @param coins array of objects used in
641
- */
642
- SuiStreamClient.prototype.returnSplittedCoinObject = function (txb, coinType, coins, coinObject) {
643
- var firstCoinObject = coinType === utils_1.SUI_TYPE_ARG ? txb.gas : txb.object(coins[0].coinObjectId);
644
- txb.mergeCoins(firstCoinObject, [coinObject]);
645
- };
646
- return SuiStreamClient;
647
- }(BaseStreamClient_1.BaseStreamClient));
648
- exports.default = SuiStreamClient;